diff --git a/classes/ORM.php b/classes/ORM.php new file mode 100644 index 0000000..f73f0c9 --- /dev/null +++ b/classes/ORM.php @@ -0,0 +1,4 @@ + diff --git a/classes/URL.php b/classes/URL.php new file mode 100644 index 0000000..572fed8 --- /dev/null +++ b/classes/URL.php @@ -0,0 +1,4 @@ + diff --git a/classes/lnApp/Controller/Login.php b/classes/lnApp/Controller/Login.php index 095a0e9..bb5342f 100644 --- a/classes/lnApp/Controller/Login.php +++ b/classes/lnApp/Controller/Login.php @@ -40,7 +40,11 @@ class lnApp_Controller_Login extends Controller_TemplateDefault { } } - $oauthlogin = is_null($x=Session::instance()->get_once('login-no-oauth',NULL)) ? TRUE : ! $x; + if (array_key_exists('oauth',Kohana::modules())) + $oauthlogin = is_null($x=Session::instance()->get_once('login-no-oauth',NULL)) ? TRUE : ! $x; + else + $oauthlogin = FALSE; + $output .= View::factory('pages/login') ->set('oauth',$oauthlogin); diff --git a/classes/lnApp/Controller/TemplateDefault.php b/classes/lnApp/Controller/TemplateDefault.php index 28774ea..b726431 100644 --- a/classes/lnApp/Controller/TemplateDefault.php +++ b/classes/lnApp/Controller/TemplateDefault.php @@ -35,6 +35,13 @@ abstract class lnApp_Controller_TemplateDefault extends Kohana_Controller_Templa */ protected $secure_actions = array(); + public function __construct(Request $request, Response $response) { + if (Config::theme()) + $this->template = Config::theme().'/page'; + + return parent::__construct($request,$response); + } + /** * Check and see if this controller needs authentication * diff --git a/classes/lnApp/ORM.php b/classes/lnApp/ORM.php new file mode 100644 index 0000000..3c1f793 --- /dev/null +++ b/classes/lnApp/ORM.php @@ -0,0 +1,129 @@ +_display_filters as $column => $formats) + $this->_object_formated[$column] = $this->run_filter($column,$this->__get($column),array($column=>$formats)); + + $this->_formated = TRUE; + } + + /** + * Overrides Kohana cache so that it can be globally disabled. + */ + public function cached($lifetime=NULL) { + return $this->_db->caching($this->_table_name) ? parent::cached($lifetime) : $this; + } + + /** + * Return a formated columns, as per the model definition + */ + public function display($column) { + // Trigger a load of the record. + $value = $this->__get($column); + + // If some of our fields need to be formated for display purposes. + if (! $this->_formated AND $this->_display_filters) + $this->_format(); + + if (isset($this->_object_formated[$column])) + return $this->_object_formated[$column]; + else + return is_array($value) ? join(', ',$value) : $value; + } + + public function display_filters(array $filters) { + $this->_display_filters = Arr::merge($this->_display_filters,$filters); + } + + public function dump() { + $result = array(); + + $result['this'] = $this->object(); + + foreach ($this->_sub_items as $o) + $result['sub'][] = $o->dump(); + + return $result; + } + + /** + * Return an array of data that can be used in a SELECT statement. + * The ID and VALUE is defined in the model for the select. + */ + public function list_select($blank=FALSE) { + $result = array(); + + if ($blank) + $result[] = ''; + + if ($this->_form AND array_intersect(array('id','value'),$this->_form)) + foreach ($this->find_all() as $o) + $result[$o->{$this->_form['id']}] = $o->resolve($this->_form['value']); + + return $result; + } + + /** + * This function is used so that methods can be called via variables + */ + public function resolve($key) { + eval("\$x = \$this->$key;"); + + return $x; + } + + public function save(Validation $validation=NULL) { + parent::save(); + + if ($this->saved() AND $this->_save_message AND (PHP_SAPI !== 'cli')) + SystemMessage::factory() + ->title('Record Updated') + ->type('success') + ->body(sprintf('Record %s:%s Updated',$this->_table_name,$this->id)); + + return $this; + } + + /** + * We override this function, because we do set our own primary key value + */ + public function values(array $values, array $expected = NULL) { + parent::values($values,$expected); + + if (isset($values[$this->_primary_key])) + $this->{$this->_primary_key} = $values[$this->_primary_key]; + + return $this; + } +} +?> diff --git a/classes/lnApp/URL.php b/classes/lnApp/URL.php new file mode 100644 index 0000000..234d1d9 --- /dev/null +++ b/classes/lnApp/URL.php @@ -0,0 +1,80 @@ +'a', + 'reseller'=>'r', + 'affiliate'=>'f', + 'user'=>'u', + ); + + public static function admin_url() { + return (Request::current() AND ( + (Auth::instance()->logged_in() AND ! empty(URL::$method_directory[strtolower(Request::current()->directory())])) + OR in_array(strtolower(Request::current()->controller()),array('login','oauth')))); + } + + /** + * Function to reveal the real directory for a URL + */ + public static function dir($dir) { + // Quick check if we can do something here + if (! in_array(strtolower($dir),URL::$method_directory)) + return $dir; + + // OK, we can, find it. + foreach (URL::$method_directory as $k=>$v) + if (strtolower($dir) == $v) + return ucfirst($k); + + // If we get here, we didnt have anything. + return $dir; + } + + /** + * Wrapper to provide a URL::site() link based on function + */ + public static function link($dir,$src,$site=FALSE) { + if (! $dir) + return $src; + + if (! array_key_exists($dir,URL::$method_directory)) + throw new Kohana_Exception('Unknown directory :dir for :src',array(':dir'=>$dir,':src'=>$src)); + + $x = URL::$method_directory[$dir].'/'.$src; + + return $site ? URL::site($x) : $x; + } + + public static function navbar() { + $result = array(); + + foreach (array_reverse(self::$method_directory) as $k=>$v) + switch ($k) { + case 'admin': $result[$k] = array('name'=>'Administrator','icon'=>'icon-globe'); + break; + + case 'affiliate': + case 'reseller': $result[$k] = array('name'=>'Reseller','icon'=>'icon-th-list'); + break; + + case 'user': $result[$k] = array('name'=>Auth::instance()->get_user()->name(),'icon'=>'icon-user'); + break; + + default: $result[$k] = array('name'=>$k,'icon'=>'icon-question-sign'); + } + + return $result; + } +} +?>