예제 #1
0
 private function checkConnection()
 {
     if (!$this->connection instanceof PDO) {
         $this->connection = Backend::getDB();
     }
     return $this->connection instanceof PDO;
 }
예제 #2
0
 public static function adminLinks()
 {
     if (!Backend::getDB('default')) {
         return false;
     }
     return array(array('href' => '?q=value/admin', 'text' => 'Values'));
 }
예제 #3
0
 public static function install(array $options = array())
 {
     $result = parent::install($options);
     if (!Backend::getDB('default')) {
         return $result;
     }
     $result = Permission::add('anonymous', 'index', 'home') && $result;
     $result = Permission::add('anonymous', 'error', 'home') && $result;
     //TODO Keep this here until we have role hierarchies
     $result = Permission::add('authenticated', 'index', 'home') && $result;
     $result = Permission::add('authenticated', 'error', 'home') && $result;
     return $result;
 }
예제 #4
0
 /**
  * Perhaps subject can be omitted, and defaults to a value that will allow the an action
  * for all subjects? Eg, display.
  */
 public static function add($role, $action, $subject, $subject_id = 0, array $options = array())
 {
     if (!Backend::getDB('default')) {
         return false;
     }
     //Loop through arrays
     if (is_array($role)) {
         $result = 0;
         foreach ($role as $one_role) {
             if (self::add($one_role, $action, $subject, $subject_id, $options)) {
                 $result++;
             }
         }
         return $result;
     }
     if (is_array($action)) {
         $result = 0;
         foreach ($action as $one_action) {
             if (self::add($role, $one_action, $subject, $subject_id, $options)) {
                 $result++;
             }
         }
         return $result;
     }
     if (is_array($subject)) {
         $result = 0;
         foreach ($subject as $one_subject) {
             if (self::add($role, $role, $one_subject, $subject_id, $options)) {
                 $result++;
             }
         }
         return $result;
     }
     if (is_array($subject_id)) {
         $options = $subject_id;
         $subject_id = 0;
     }
     $control = array_key_exists('control', $options) ? $options['control'] : '100';
     $system = array_key_exists('system', $options) ? $options['system'] : 0;
     $data = array('role' => $role, 'action' => $action, 'subject' => class_for_url($subject), 'subject_id' => $subject_id, 'control' => $control, 'system' => $system, 'active' => 1);
     $permission = new PermissionObj();
     if ($permission->replace($data) !== false) {
         Backend::addSuccess('Added permission to ' . $action . ' for ' . $role);
         $result = true;
     } else {
         Backend::addError('Could not add permission to ' . $action . ' for ' . $role);
         $result = false;
     }
     return $result;
 }
예제 #5
0
 private function checkConnection()
 {
     $this->error_msg = false;
     if (!$this->db instanceof PDO) {
         try {
             $this->db = Backend::getDB($this->meta['database']);
         } catch (Exception $e) {
             Backend::addError($e->getMessage());
         }
         if (!$this->db instanceof PDO) {
             $this->error_msg = 'No Database setup';
             if (class_exists('BackendError', false)) {
                 BackendError::add(get_class($this) . ': No Database setup', 'checkConnection');
             }
             return false;
         }
     }
     return $this->db instanceof PDO;
 }
예제 #6
0
 public static function install(array $options = array())
 {
     if (!Backend::getDB('default')) {
         return true;
     }
     $install_model = array_key_exists('install_model', $options) ? $options['install_model'] : true;
     $toret = parent::install($options);
     $class = get_called_class();
     if ($class && class_exists($class, true)) {
         if ($install_model) {
             $toret = call_user_func(array(get_called_class(), 'installModel'), $class . 'Obj', $options);
         }
     }
     return $toret;
 }
예제 #7
0
 public static function install(array $options = array())
 {
     $result = parent::install($options);
     if (!Backend::getDB('default')) {
         return $result;
     }
     $result = Hook::add('init', 'pre', get_called_class(), array('global' => true)) && $result;
     $result = Hook::add('table_display', 'pre', get_called_class()) && $result;
     $result = Permission::add('anonymous', TableCtl::$P_READONLY, get_called_class()) && $result;
     $result = Permission::add('authenticated', TableCtl::$P_READONLY, get_called_class()) && $result;
     return $result;
 }
예제 #8
0
 public static function install(array $options = array())
 {
     $options['install_model'] = array_key_exists('install_model', $options) ? $options['install_model'] : true;
     $result = parent::install($options);
     if (!Backend::getDB('default')) {
         return $result;
     }
     $result = Hook::add('init', 'post', get_called_class(), array('global' => true, 'sequence' => 0)) && $result;
     $result = Hook::add('start', 'pre', get_called_class(), array('global' => true)) && $result;
     $result = Hook::add('finish', 'post', get_called_class(), array('global' => true)) && $result;
     $result = Permission::add('anonymous', 'super_signup', get_called_class()) && $result;
     $result = Permission::add('anonymous', 'signup', get_called_class()) && $result;
     $result = Permission::add('anonymous', 'confirm', get_called_class()) && $result;
     $result = Permission::add('anonymous', 'login', get_called_class()) && $result;
     $result = Permission::add('authenticated', 'login', get_called_class()) && $result;
     $result = Permission::add('authenticated', 'logout', get_called_class()) && $result;
     $result = Permission::add('authenticated', 'display', get_called_class()) && $result;
     $result = Permission::add('authenticated', 'update', get_called_class()) && $result;
     $result = Permission::add('authenticated', 'change_password', get_called_class()) && $result;
     return $result;
 }
예제 #9
0
 public static function install(array $options = array())
 {
     $result = parent::install($options);
     if (!Backend::getDB('default')) {
         return $result;
     }
     $result = Hook::add('display', 'post', __CLASS__, array('global' => true, 'mode' => 'html')) && $result;
     $result = Permission::add('anonymous', 'continual', 'admin') && $result;
     $result = Permission::add('anonymous', 'daily', 'admin') && $result;
     $result = Permission::add('anonymous', 'weekly', 'admin') && $result;
     $result = Permission::add('authenticated', 'continual', 'admin') && $result;
     $result = Permission::add('authenticated', 'daily', 'admin') && $result;
     $result = Permission::add('authenticated', 'weekly', 'admin') && $result;
     return $result;
 }
예제 #10
0
 public static function install(array $options = array())
 {
     if (!Backend::getDB('default')) {
         return true;
     }
     $class = get_called_class();
     if (!$class || !class_exists($class, true)) {
         return false;
     }
     //Purge permissions first
     $query = new DeleteQuery('Permission');
     $query->filter('`subject` = :subject')->filter('`system` = 0');
     $query->execute(array(':subject' => class_for_url($class)));
     $methods = get_class_methods($class);
     $methods = array_filter($methods, create_function('$var', '$temp = explode(\'_\', $var, 2); return count($temp) == 2 && in_array(strtolower($temp[0]), array(\'action\', \'get\', \'post\', \'put\', \'delete\'));'));
     $methods = array_map(create_function('$var', 'return preg_replace(\'/^(action|get|post|put|delete)_/\', \'\', $var);'), $methods);
     $result = true;
     foreach ($methods as $action) {
         $result = Permission::add('nobody', $action, class_for_url($class)) && $result;
     }
     return $result;
 }
예제 #11
0
 /**
  * Make sure the hooks table exists so that other components can add hooks with installation
  */
 public static function pre_install()
 {
     if (!Backend::getDB('default')) {
         return true;
     }
     $result = self::installModel(__CLASS__ . 'Obj');
     return $result;
 }
예제 #12
0
 public static function adminLinks()
 {
     if (!Backend::getDB('default')) {
         return false;
     }
     return array(array('text' => 'Manage Components', 'href' => '?q=component/manage'), array('text' => 'Check Components', 'href' => '?q=component/check'));
 }
예제 #13
0
 public static function install()
 {
     if (!Backend::getDB('default')) {
         return true;
     }
     $result = true;
     return $result;
 }
예제 #14
0
 public static function action()
 {
     if (self::$whoopsed) {
         return array(null, null);
     }
     $control_name = class_name(self::$area);
     if (Controller::$debug) {
         Backend::addNotice('Trying Controller ' . $control_name);
     }
     $controller = class_exists($control_name, true) ? new $control_name() : false;
     if (!($controller instanceof AreaCtl && Component::isActive($control_name))) {
         if (Backend::getDB('default')) {
             //We have a DB
             Controller::whoops('Component ' . $control_name . ' is Inactive or Invalid', array('message' => 'The requested component doesn\'t exist or is inactive.', 'code_hint' => 404));
             self::$area = ConfigValue::get('DefaultErrorController', 'home');
             self::$action = ConfigValue::get('DefaultErrorAction', 'error');
             $control_name = class_name(self::$area);
         } else {
             //No DB, allow Content to check if the template exists
             self::$parameters[0] = self::$area . '/' . self::$action;
             if (count(self::$parameters[0]) > 1) {
                 self::$parameters = array(self::$parameters[0]);
             }
             self::$area = ConfigValue::get('DefaultErrorController', 'content');
             self::$action = ConfigValue::get('DefaultErrorAction', 'display');
             $control_name = class_name(self::$area);
         }
     }
     $controller = class_exists($control_name, true) ? new $control_name() : false;
     if (!($controller instanceof AreaCtl && Component::isActive($control_name))) {
         Controller::whoops('Invalid Error Area Controller', 'The DefaultErrorController is invalid or inactive.');
         return null;
     }
     Backend::add('Area', self::$area);
     Backend::add('Action', self::$action);
     if (Controller::$debug) {
         Backend::addNotice('Code for this page is in the ' . get_class($controller) . ' Controller');
     }
     $result = null;
     $run_action = Hook::run('action', 'pre', array(), array('toret' => true));
     if ($run_action) {
         $result = $controller->action();
     }
     Hook::run('action', 'post');
     return array($controller, $result);
 }