예제 #1
0
 public static function install_check()
 {
     //Check the cache folder
     if (!Backend::checkConfigFile()) {
         if (function_exists('posix_getgrgid') && function_exists('posix_getegid')) {
             if ($group = posix_getgrgid(posix_getegid())) {
                 $group = $group['name'];
             }
         }
         $values = array('file' => Backend::getConfigFileLocation(), 'group' => isset($group) ? $group : false);
         Backend::addContent(Render::file('config_value.fix_config.tpl.php', $values));
         return false;
     }
     if (self::get('settings.ConfigValueSet')) {
         return true;
     }
     if (is_post()) {
         $result = true;
         foreach ($_POST as $name => $value) {
             $name = str_replace('_', '.', $name);
             if (in_array($name, array('application.Title', 'application.Moto', 'application.HelpBoxContent', 'application.Description', 'author.Name', 'author.Email', 'author.Website'))) {
                 if (!self::set($name, $value)) {
                     Backend::addError('Could not set ' . $name);
                     $result = false;
                 }
             } else {
                 var_dump('Rejected:', $name);
             }
         }
         self::set('settings.ConfigValueSet', $result);
         Controller::redirect();
     }
     Backend::addContent(Render::file('config_value.values.tpl.php'));
     return false;
 }
예제 #2
0
 public function action_test()
 {
     /*$lock = BackendLock::get('testing', BackendLock::LOCK_CUSTOM);
     		if (!$lock) {
     			Backend::addError('Could not aquire lock');
     		} else {
     			Backend::addSuccess('Testing is ' . ($lock->check() ? 'Available' : 'Not Available'));
     		}
     		$lock = BackendLock::release('testing');
     		Backend::addSuccess('Testing is ' . ($lock->check() ? 'Available' : 'Not Available'));
     		if ($lock = BackendLock::get('testing_expiry', BackendLock::LOCK_CUSTOM, '2010-01-01')) {
     			Backend::addSuccess('Testing Expiry is ' . ($lock->check() ? 'Available' : 'Not Available'));
     		}
     		if ($lock = BackendLock::get('testing_type', 5)) {
     			Backend::addSuccess('Testing Type is ' . ($lock->check() ? 'Available' : 'Not Available'));
     		}*/
     if ($lock = BackendLock::get('testing_system', BackendLock::LOCK_SYSTEM)) {
         Backend::addSuccess('Testing Type is ' . ($lock->check() ? 'Available' : 'Not Available'));
     } else {
         Backend::addSuccess('Should not get System lock (no expiry or password)');
     }
     if ($lock = BackendLock::get('testing_system', BackendLock::LOCK_SYSTEM, 'now + 1 minutes', 'Abc123')) {
         Backend::addSuccess('Testing Type is ' . ($lock->check() ? 'Available' : 'Not Available'));
     } else {
         Backend::addError('Could not get System lock');
     }
     return false;
 }
예제 #3
0
 public static function add($hook, $type, $class, array $options = array())
 {
     if (!Backend::getDB('default')) {
         return false;
     }
     $mode = array_key_exists('mode', $options) ? $options['mode'] : '*';
     $name = array_key_exists('name', $options) ? $options['name'] : ucwords($class . ' ' . $type . ' ' . $hook);
     $description = array_key_exists('description', $options) ? $options['description'] : '';
     $method = array_key_exists('method', $options) ? $options['method'] : 'hook_' . ($type == 'post' ? 'post_' : '') . strtolower($hook);
     $global = array_key_exists('global', $options) ? $options['global'] : 0;
     $sequence = array_key_exists('sequence', $options) ? $options['sequence'] : 0;
     //Certain hooks should be global
     if (in_array($hook, array('init'))) {
         $global = 1;
     }
     $data = array('class' => $class, 'hook' => $hook, 'type' => $type, 'mode' => $mode, 'name' => $name, 'description' => $description, 'method' => $method, 'global' => $global, 'sequence' => $sequence);
     $hook = new HookObj();
     if ($hook->replace($data)) {
         Backend::addSuccess('Added hook ' . $name . '(' . $class . '::' . $method . ')');
         $toret = true;
     } else {
         Backend::addError('Could not add hook ' . $name . '(' . $class . '::' . $method . ')');
         $toret = false;
     }
     return $toret;
 }
예제 #4
0
 private static function checkAliases($query)
 {
     if (file_exists(APP_FOLDER . '/configs/queries.php')) {
         $aliases = (include APP_FOLDER . '/configs/queries.php');
     }
     if (empty($aliases)) {
         if (Controller::$debug) {
             Backend::addError('Invalid query aliases');
         }
         return $query;
     }
     if (array_key_exists($query, $aliases)) {
         return $aliases[$query];
     }
     foreach ($aliases as $test => $new_query) {
         if ($test == $query) {
             return $new_query;
         } else {
             $search = array('/', ':any', ':num', ':controller', ':area_ctl', ':table_ctl');
             //TODO Get the controllers from the Component table, remove area and table
             $replace = array('\\/', '([^\\/]+)', '([0-9]+)', '(home)', '(admin)', '(content|comment|content_revision|tag|image|backend_user|hook)');
             $pattern = '/^' . str_replace($search, $replace, $test) . '\\/?$/';
             preg_match_all($pattern, $query, $matches);
             if (count($matches[0])) {
                 foreach ($matches as $key => $match) {
                     $new_query = str_replace('$' . $key, current($match), $new_query);
                 }
                 return $new_query;
             }
         }
     }
     return $query;
 }
예제 #5
0
 public function action_authorized()
 {
     $auth_t = array_key_exists('OAuthAuthToken', $_SESSION) ? $_SESSION['OAuthAuthToken'] : false;
     if ($auth_t) {
         $access_t = $this->oauth->getAccessToken($auth_t);
         if ($access_t) {
             Backend::addSuccess('Sucessfully logged into Twitter');
             $data = array('screen_name' => $access_t['screen_name'], 'twitter_id' => $access_t['user_id'], 'oauth_token' => $access_t['oauth_token'], 'oauth_secret' => $access_t['oauth_token_secret'], 'active' => 1);
             $twit = new TwitterObj();
             if ($twit->replace($data)) {
             } else {
                 Backend::addError('Could not record Twitter Auth information');
             }
             if (!empty($_SESSION['TwitterRedirect'])) {
                 $url = $_SESSION['TwitterRedirect'];
                 unset($_SESSION['TwitterRedirect']);
                 Controller::redirect($url);
             }
         } else {
             Backend::addError('Could not get Access Token');
         }
     } else {
         Backend::addError('No Authentication Token');
     }
     return true;
 }
예제 #6
0
 private static function execute($search_string)
 {
     self::$error_msg = false;
     if (Controller::$debug) {
         var_dump(self::$url . '?' . $search_string);
     }
     $returned = curl_request(self::$url . '?' . $search_string);
     if (!$returned) {
         self::$error_msg = 'Invalid Twitter API request';
         if (Controller::$debug) {
             var_dump(self::$url . '?' . $search_string);
         }
         return false;
     } else {
         if (!($result = json_decode($returned))) {
             self::$error_msg = 'Invalid JSON returned: ' . $returned;
             return false;
         }
     }
     if (array_key_exists('error', $result)) {
         self::$error_msg = $result->error;
     } else {
         return is_object($result) && isset($result->results) ? $result->results : false;
     }
     if (!empty(self::$error_msg) && Controller::$debug) {
         Backend::addError('TwitterSearch: ' . self::$error_msg);
     }
     return false;
 }
예제 #7
0
 public static function check()
 {
     if (!empty($_COOKIE['remembered'])) {
         $query = new SelectQuery('PersistUser');
         $persist = $query->filter('MD5(CONCAT(`id`, `user_id`, `random`)) = :hash')->fetchAssoc(array(':hash' => $_COOKIE['remembered']));
         if ($persist) {
             //Get User
             $User = self::getObject('BackendUser');
             if (!$User instanceof DBObject) {
                 return false;
             }
             $query = BackendUser::getQuery();
             $query->filter('`backend_users`.`id` = :id');
             $params = array(':id' => $persist['user_id']);
             $User->read(array('query' => $query, 'parameters' => $params, 'mode' => 'object'));
             if ($User->object) {
                 $_SESSION['BackendUser'] = $User->object;
                 //Remove, and reremember
                 if (self::remember($User->object)) {
                     $query = new DeleteQuery('PersistUser');
                     $query->filter('`id` = :id')->limit(1);
                     $query->execute(array(':id' => $persist['id']));
                 } else {
                     Backend::addError('Could not reremember');
                 }
                 return $User->object;
             } else {
                 //Backend::addError('Invalid remembered user');
             }
         }
     }
     return false;
 }
예제 #8
0
 public static function hook_post_update($data, $object)
 {
     if ($object instanceof ContentObj && !$object->array['from_file']) {
         if (!self::createNewRevision($object->array['id'], $object->array['markdown'], array_key_exists('revision_summary', $data) ? $data['revision_summary'] : false)) {
             Backend::addError('Could not add Content Revision');
         }
     }
     return true;
 }
예제 #9
0
 public static function hook_output($to_print)
 {
     if (empty($to_print['values']) || empty($to_print['options'])) {
         Backend::addError('Values and options are required');
         return false;
     } else {
         $to_print = self::make_bandwidth_chart($to_print['values'], $to_print['options']);
     }
     return $to_print;
 }
예제 #10
0
 /**
  * @todo Make this a POST only
  */
 public function action_toggle($id, $field)
 {
     $result = parent::action_toggle($id, $field, false);
     if ($result && $result->array['active']) {
         if (call_user_func(array($result->array['name'], 'install'))) {
         } else {
             Backend::addError('Could not install component');
         }
     }
     return $result;
 }
예제 #11
0
 function validate($data, $action, $options = array())
 {
     $toret = true;
     $data = parent::validate($data, $action, $options);
     if ($data) {
         if (empty($data['expire'])) {
             Backend::addError('System Locks must expire');
             $toret = false;
         }
     }
     return $toret ? $data : false;
 }
예제 #12
0
 public static function hook_output($to_print)
 {
     Backend::add('BackendErrors', Backend::getError());
     Backend::add('BackendSuccess', Backend::getSuccess());
     Backend::add('BackendNotices', Backend::getNotice());
     Backend::add('BackendInfo', Backend::getInfo());
     Backend::setError();
     Backend::setSuccess();
     Backend::setNotice();
     Backend::setInfo();
     $content = Backend::getContent();
     if (empty($content)) {
         ob_start();
         var_dump($to_print);
         $content = ob_get_clean();
         if (substr($content, 0, 4) != '<pre') {
             $content = '<pre>' . $content . '</pre>';
         }
         Backend::addContent($content);
     }
     $layout = Backend::get('HTMLLayout', 'index');
     if (!Render::checkTemplateFile($layout . '.tpl.php')) {
         if (SITE_STATE != 'production') {
             Backend::addError('Missing Layout ' . $layout);
         }
         $layout = 'index';
     }
     $to_print = Render::file($layout . '.tpl.php');
     $to_print = self::addLastContent($to_print);
     $to_print = self::replace($to_print);
     $to_print = self::rewriteLinks($to_print);
     $to_print = self::addLinks($to_print);
     $to_print = self::formsAcceptCharset($to_print);
     //TODO fix this
     if (Component::isActive('BackendFilter')) {
         $BEFilter = new BEFilterObj();
         $BEFilter->read();
         $filters = $BEFilter->list ? $BEFilter->list : array();
         foreach ($filters as $row) {
             if (class_exists($row['class'], true) && is_callable(array($row['class'], $row['function']))) {
                 $to_print = call_user_func(array($row['class'], $row['function']), $to_print);
             }
         }
     }
     //TODO Make this configurable
     if (ConfigValue::get('html_view.TidyHTML') && function_exists('tidy_repair_string')) {
         $to_print = tidy_repair_string($to_print);
     }
     return $to_print;
 }
예제 #13
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;
 }
예제 #14
0
 public static function install(array $options = array())
 {
     $options['drop_table'] = array_key_exists('drop_table', $options) ? $options['drop_table'] : true;
     $toret = parent::install($options);
     foreach (self::getDefaults() as $assignment) {
         if (GateKeeper::assign($assignment['role'], $assignment['access_type'], $assignment['access_id'])) {
             Backend::addSuccess('Added assignment to ' . $assignment['role']);
             $toret = $toret && true;
         } else {
             Backend::addError('Could not add assignment to ' . $assignment['role']);
             $toret = false;
         }
     }
     return $toret;
 }
예제 #15
0
 function validate($data, $action, $options = array())
 {
     $data = parent::validate($data, $action, $options);
     if (!$data) {
         return $data;
     }
     switch ($action) {
         case 'create':
             $data['active'] = array_key_exists('active', $data) ? $data['active'] : true;
             //We need either an email, mobile number or username to register a user
             //Lower ASCII only
             if (!empty($data['username'])) {
                 $data['username'] = filter_var(trim($data['username']), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
                 //TODO Make the banned usernames configurable
                 $banned_usernames = array('root', 'admin', 'superadmin', 'superuser', 'webadmin', 'postmaster', 'webdeveloper', 'webmaster', 'administrator', 'sysadmin');
                 if (in_array($data['username'], $banned_usernames) && BackendUser::hasSuperUser()) {
                     Backend::addError('Please choose a valid username');
                     return false;
                 }
             }
             if (empty($data['username']) && empty($data['email']) && empty($data['mobile'])) {
                 Backend::addError('Please provide a username');
             }
             //If the username is an email address, make it the email address
             if (!empty($data['username']) && filter_var($data['username'], FILTER_VALIDATE_EMAIL)) {
                 if (!empty($data['email'])) {
                     list($data['username'], $data['email']) = array($data['email'], $data['username']);
                 } else {
                     $data['email'] = $data['username'];
                     unset($data['username']);
                 }
             }
             $data['salt'] = get_random('numeric');
             $data['password'] = md5($data['salt'] . $data['password'] . Controller::$salt);
             if (ConfigValue::get('application.confirmUser')) {
                 $data['confirmed'] = false;
             } else {
                 $data['confirmed'] = array_key_exists('confirmed', $data) ? $data['confirmed'] : true;
             }
             break;
         case 'update':
             if (!empty($data['password'])) {
                 $data['password'] = md5($this->array['salt'] . $data['password'] . Controller::$salt);
             }
             break;
     }
     return $data;
 }
예제 #16
0
 /**
  * The standard action for an Area
  */
 public final function action()
 {
     $toret = null;
     $error_number = Controller::getVar('err');
     if (!empty($error_number)) {
         Backend::addError(self::getError($error_number));
     }
     if (Controller::$debug) {
         Backend::addNotice('Checking Method ' . Controller::$action . ' for ' . get_class($this));
     }
     $request_method = strtolower(Controller::getMethod()) . '_' . Controller::$action;
     $action_method = 'action_' . Controller::$action;
     $view_method = Controller::$view->mode . '_' . Controller::$action;
     //Determine / check method
     $method = false;
     if (method_exists($this, $request_method)) {
         $method = $request_method;
     } else {
         if (method_exists($this, $action_method)) {
             $method = $action_method;
         } else {
             if (method_exists($this, $view_method)) {
                 $method = true;
             }
         }
     }
     if (!$method) {
         Controller::whoops('Unknown Method', array('message' => 'Method ' . Controller::$area . '::' . Controller::$action . ' does not exist'));
         return null;
     }
     //Check permissions on existing method
     if (Controller::getCheckPermissions() && !$this->checkPermissions()) {
         //TODO Add a permission denied hook to give the controller a chance to handle the permission denied
         Controller::whoops('Permission Denied', array('message' => 'You do not have permission to ' . Controller::$action . ' ' . get_class($this)));
         return null;
     }
     if ($method === true) {
         //View method, return null;
         return null;
     }
     if (Controller::$debug) {
         Backend::addNotice('Running ' . get_class($this) . '::' . $method);
     }
     return call_user_func_array(array($this, $method), Controller::$parameters);
 }
예제 #17
0
 public static function add($name, $description, array $options = array())
 {
     $id = array_key_exists('id', $options) ? $options['id'] : null;
     $active = array_key_exists('active', $options) ? $options['active'] : null;
     $data = array('name' => $name, 'description' => $description, 'active' => $active);
     if (!is_null($active)) {
         $data['id'] = $id;
     }
     $RoleObj = new RoleObj();
     if ($RoleObj->replace($data)) {
         Backend::addSuccess('Added role ' . $data['name']);
         $toret = true;
     } else {
         Backend::addError('Could not add role ' . $data['name']);
         $toret = false;
     }
     return $toret;
 }
예제 #18
0
 public static function doIndex(TableCtl $controller, $fields = array('content'))
 {
     if (!is_array($fields)) {
         $fields = array($fields);
     }
     //TODO This is a bad idea. rather use a query and while
     $object = $controller->get_list('all', 0);
     $total = false;
     if ($object->list) {
         $total = 0;
         $first = current($object->list);
         foreach ($fields as $field) {
             if (array_key_exists($field, $first)) {
                 $result = 0;
                 foreach ($object->list as $row) {
                     $info = str_word_count($row[$field], 1);
                     $counts = array_count_values($info);
                     $sequence = 0;
                     foreach ($counts as $word => $count) {
                         unset($counts[$word]);
                         if ($word = self::filter($word, $count)) {
                             $data = array('table' => $object->getSource(), 'table_id' => $row[$object->getMeta('id_field')], 'word' => $word, 'count' => $count, 'sequence' => $sequence++);
                             $b_search = new BackendSearchObj();
                             if ($b_search->replace($data)) {
                                 $result++;
                                 $total++;
                             } else {
                                 if ($b_search->error_msg != 'Error executing statement(1062)') {
                                     Backend::addError('Could not add ' . $word . ' to ' . get_class($controller) . '::' . $field . ' index');
                                 }
                             }
                         }
                     }
                 }
                 if ($result > 0) {
                     Backend::addSuccess($result . ' words were indexed for ' . get_class($controller) . '::' . $field);
                 }
             } else {
                 Backend::addError($field . ' does not exist in ' . get_class($object));
             }
         }
     }
     return $total;
 }
예제 #19
0
 function validate($data, $action, $options = array())
 {
     $toret = true;
     $data = parent::validate($data, $action, $options);
     if ($data) {
         if (array_key_exists('type', $data)) {
             if (!in_array($data['type'], BackendLock::$types)) {
                 Backend::addError('Invalid Lock Type');
                 $toret = false;
             }
         }
         if (!empty($data['expire'])) {
             if (strtotime($data['expire']) < time()) {
                 Backend::addError('Expiry date in the past');
                 $toret = false;
             }
         }
     }
     return $toret ? $data : false;
 }
예제 #20
0
 public static function getDevice()
 {
     if (!is_null(self::$device)) {
         return self::$device;
     }
     if (RESOURCES_DIR && class_exists('WURFL_WURFLManagerProvider')) {
         $wurflConfigFile = RESOURCES_DIR . 'wurfl-config.xml';
         try {
             $wurflManager = WURFL_WURFLManagerProvider::getWURFLManager($wurflConfigFile);
             self::$device = $wurflManager->getDeviceForHttpRequest($_SERVER);
         } catch (Exception $e) {
             if (Controller::$debug) {
                 Backend::addError('Wurfl Error: ' . $e->getMessage());
             }
             return false;
         }
         return self::$device ? self::$device : false;
     } else {
         Backend::addError('Could not find WURFL resources');
         return false;
     }
 }
예제 #21
0
 public function action_execute()
 {
     $return_boolean = empty($_REQUEST['return_boolean']) ? false : true;
     $components = Component::getActive();
     if (!$components) {
         return false;
     }
     $end_result = true;
     $results = array();
     foreach (Component::getActive() as $component) {
         $results[$component['name']] = array();
         if (method_exists($component['name'], 'test')) {
             $results[$component['name']]['component'] = call_user_func(array($component['name'], 'test'));
         }
         $methods = get_class_methods($component['name']);
         if (!$methods) {
             continue;
         }
         $component_obj = new $component['name']();
         foreach ($methods as $method) {
             if (substr($method, 0, 7) == 'action_') {
                 $test_method = preg_replace('/^action_/', 'test_', $method);
                 if (in_array($test_method, $methods)) {
                     set_time_limit(30);
                     if ($result = $component_obj->{$test_method}()) {
                     } else {
                         Backend::addError($component['name'] . '::' . $method . ' Failed');
                         $end_result = false;
                     }
                     $results[$component['name']][$method] = $result;
                 }
             }
         }
     }
     $results = array_filter($results, 'count');
     ksort($results);
     return $return_boolean ? $end_result : $results;
 }
예제 #22
0
 /**
  * @todo get a better way to report warnings and errors in eval code
  */
 private static function evalContent($be_template_name, $be_content, array $be_vars = array())
 {
     //Prepare Variables
     $be_vars = array_merge(Backend::getAll(), $be_vars);
     $be_keys = array_keys($be_vars);
     //Convert spaces to underscores in Backend Variables
     $be_keys = array_map(create_function('$elm', "return str_replace(' ', '_', \$elm);"), $be_keys);
     extract(array_combine($be_keys, array_values($be_vars)));
     //Evaluate Extra Variables in Templates
     if (preg_match_all('/{var:\\|(.*)\\|}/', $be_content, $variable_strings, PREG_SET_ORDER)) {
         foreach ($variable_strings as $var_string) {
             //Eval any PHP in the variables
             ob_start();
             eval('?>' . $var_string[1]);
             $variable_string = ob_get_clean();
             $variables = @json_decode($variable_string, true);
             if (is_null($variables)) {
                 if (SITE_STATE != 'production') {
                     Backend::addError('Invalid Variables passed in ' . $be_template_name);
                     if (Controller::$debug) {
                         echo 'Invalid Variable String: ' . PHP_EOL . $var_string[1];
                     }
                 }
             } else {
                 $var_content = array();
                 foreach ($variables as $name => $value) {
                     $var_content[] = "\${$name} = " . var_export($value, true) . ';';
                 }
                 $var_content = '<?php' . PHP_EOL . implode($var_content, PHP_EOL) . PHP_EOL . '?>' . PHP_EOL;
                 $be_content = str_replace('{var:|' . $var_string[1] . '|}', $var_content, $be_content);
                 $did_something = true;
             }
         }
     }
     //Evaluate PHP in Templates
     ob_start();
     if (Controller::$debug) {
         $be_result = eval('?>' . $be_content);
     } else {
         $be_result = @eval('?>' . $be_content);
     }
     if ($be_result === false) {
         Backend::addError('Error evaluating template ' . $be_template_name);
     }
     $result = ob_get_clean();
     return $result;
 }
예제 #23
0
 public function fromRequest()
 {
     $toret = array();
     foreach ($this->meta['fields'] as $name => $options) {
         $toret[$name] = null;
         $options = is_array($options) ? $options : array('type' => $options);
         $type = array_key_exists('type', $options) ? $options['type'] : 'string';
         $filter = array_key_exists('filter', $options) ? $options['filter'] : FILTER_DEFAULT;
         $filter_options = array_key_exists('filter_options', $options) ? $options['filter_options'] : array();
         //Files
         if (in_array($type, array('tiny_blob', 'blob', 'medium_blob', 'long_blob'))) {
             if (!empty($_FILES)) {
                 if ($_FILES[$name]['error']) {
                     switch ($_FILES[$name]['error']) {
                         case 1:
                         case 2:
                             $message = 'File too large to be uploaded';
                             break;
                         case 3:
                             $message = 'File only partially uploaded';
                             break;
                         case 4:
                             $message = 'No file was uploaded';
                             break;
                         case 6:
                             $message = 'Could not upload file. No tmp folder';
                             break;
                         case 7:
                             $message = 'Could not upload file. Can\'t write to tmp folder';
                             break;
                         case 8:
                             $message = 'Could not upload file. Invalid extension';
                             break;
                         default:
                             $message = 'Unknown file upload error (' . $_FILES[$name]['error'] . ')';
                             break;
                     }
                     Backend::addError($message);
                 } else {
                     $toret[$name] = file_get_contents($_FILES[$name]['tmp_name']);
                 }
             }
             //Other Types
         } else {
             $value = Controller::getVar($name);
             if (!is_null($value)) {
                 $toret[$name] = filter_var($value, $filter, $filter_options);
                 if ($toret[$name] === false) {
                     $toret[$name] = null;
                     Backend::addError('Invalid input');
                 }
             }
         }
     }
     return $toret;
 }
예제 #24
0
 public static function installModel($model, array $options = array())
 {
     $toret = false;
     if (class_exists($model, true)) {
         $model = new $model();
         $toret = $model->install($options);
         if (!$toret) {
             Backend::addError('Could not install ' . get_class($model) . ' Model: ' . $model->error_msg);
         }
     } else {
         Backend::addError($model . ' does not exist');
     }
     return $toret;
 }
예제 #25
0
 public function html_permissions($result)
 {
     if (is_post()) {
         if ($result === false) {
             Backend::addError('Could not update Permissions');
         } else {
             Backend::addSuccess($result . ' Permissions Updated');
         }
         Controller::redirect('previous');
     }
     //GET
     if (!empty(Controller::$parameters[0])) {
         Backend::add('Sub Title', class_name(Controller::$parameters[0]) . ' Permissions');
         Links::add('All Permissions', '?q=gate_manager/permissions', 'secondary');
     } else {
         Backend::add('Sub Title', ConfigValue::get('Title') . ' Permissions');
     }
     Backend::addContent(Render::renderFile('gate_manager.permissions.tpl.php', (array) $result));
 }
예제 #26
0
 public static function __error_handler($number, $string, $file = false, $line = false, $context = false)
 {
     if (!class_exists('Component', false)) {
         self::__autoload('Component');
     }
     if (!class_exists('BackendError', false)) {
         self::__autoload('BackendError');
     }
     if (!class_exists('BackendErrorObj', false)) {
         self::__autoload('BackendErrorObj');
     }
     //Record Errors
     switch ($number) {
         case E_STRICT:
             break;
         case E_DEPRECATED:
             if (SITE_STATE == 'production') {
                 break;
             } else {
                 //Go through to the DEFAULT
             }
         default:
             if (Component::isActive('BackendError')) {
                 BackendError::add($number, $string, $file, $line, $context);
             }
             break;
     }
     //Interpret or Bypass Errors
     switch ($number) {
         case E_WARNING:
             preg_match_all('/Missing argument ([0-9]+) for ([\\S]+)::([^\\(\\)]+)\\(\\), called in ([\\S]+) on line ([0-9]+)/', $string, $vars, PREG_SET_ORDER);
             if (!empty($vars)) {
                 list($matches, $arg_num, $class, $method, $call_file, $call_line) = current($vars);
                 if (SITE_STATE != 'production') {
                     Backend::addError("Missing parameter {$arg_num} for {$class}::{$method}, called in {$call_file} line {$call_line}, defined in {$file} line {$line}");
                 } else {
                     Backend::addError('Invalid Parameters');
                 }
                 return true;
             }
             preg_match_all('/Missing argument ([0-9]+) for ([\\S]+)::([^\\(\\)]+)\\(\\)/', $string, $vars, PREG_SET_ORDER);
             if (!empty($vars)) {
                 list($matches, $arg_num, $class, $method) = current($vars);
                 if (SITE_STATE != 'production') {
                     Backend::addError("Missing parameter {$arg_num} for {$class}::{$method}, defined in {$file} line {$line}");
                 } else {
                     Backend::addError('Invalid Parameters');
                 }
                 return true;
             }
             preg_match_all("/[\\S]+\\/classes\\/Render.obj.php\\([0-9]+\\) : eval\\(\\)'d code/", $file, $vars, PREG_SET_ORDER);
             if (!empty($vars)) {
                 $template_name = empty($context['be_template_name']) ? 'Unknown' : $context['be_template_name'];
                 if (SITE_STATE != 'production') {
                     Backend::addError('Error in template: ' . $template_name . ' on line ' . $line . ': ' . $string);
                 } else {
                     Backend::addError('Template Error');
                 }
                 return true;
             }
             break;
         case E_STRICT:
             if (SITE_STATE == 'production') {
                 return true;
             }
             break;
         case E_DEPRECATED:
             if (SITE_STATE == 'production') {
                 return true;
             }
             break;
         case E_RECOVERABLE_ERROR:
             if (SITE_STATE == 'production') {
                 return true;
             }
             break;
     }
     return false;
 }
예제 #27
0
 private static function installComponents($with_db = false)
 {
     $components = Component::getCoreComponents($with_db);
     if (!$components) {
         Backend::addError('Could not get components to pre install');
         return false;
     }
     //Save original LogToFile setting
     $original = ConfigValue::get('LogToFile', false);
     $install_log_file = 'install_log_' . date('Ymd_His') . '.txt';
     ConfigValue::set('LogToFile', $install_log_file);
     //Pre Install components
     Backend::addNotice(PHP_EOL . PHP_EOL . 'Installation started at ' . date('Y-m-d H:i:s'));
     $components = array_flatten($components, null, 'name');
     foreach ($components as $component) {
         if (class_exists($component, true) && method_exists($component, 'pre_install')) {
             Backend::addNotice('Pre Installing ' . $component);
             if (!call_user_func_array(array($component, 'pre_install'), array())) {
                 Backend::addError('Error on pre install for ' . $component);
                 return false;
             }
         }
     }
     //Install Components
     foreach ($components as $component) {
         if (class_exists($component, true) && method_exists($component, 'install')) {
             Backend::addNotice('Installing ' . $component);
             if (!call_user_func_array(array($component, 'install'), array())) {
                 Backend::addError('Error on installing ' . $component);
                 return false;
             }
         }
     }
     //Install Application Components
     if (is_callable(array('Application', 'getComponents'))) {
         $app_components = Application::getComponents();
         if (is_array($app_components)) {
             foreach ($components as $component) {
                 if (class_exists($component, true) && method_exists($component, 'install')) {
                     Backend::addNotice('Installing ' . $component);
                     if (!call_user_func_array(array($component, 'install'), array())) {
                         Backend::addError('Error on installing ' . $component);
                         return false;
                     }
                 }
             }
         }
     }
     //Restore Original
     ConfigValue::set('LogToFile', $original);
     return true;
 }
예제 #28
0
 public function html_confirm($result)
 {
     if ($result) {
         Backend::addSuccess('Your user account has been confirmed. Please login.');
         Controller::redirect('?q=' . class_for_url(get_called_class()) . '/login');
     } else {
         Backend::addError('Could not confirm your account at the moment. Please try again later');
         Controller::redirect('?q=');
     }
     return $result;
 }
예제 #29
0
 public function action_define($class, $function = false)
 {
     if ($function) {
         if (!is_callable(array($class, 'define_' . $function))) {
             Backend::addError('Unknown function: ' . $class . '::' . $function);
             return false;
         }
         $definition = call_user_func(array($class, 'define_' . $function));
         if (!$definition) {
             return false;
         }
     } else {
         $methods = get_class_methods($class);
         if (!$methods) {
             return false;
         }
         $definition = array();
         foreach ($methods as $method) {
             if (substr($method, 0, 7) == 'define_') {
                 $method_name = substr($method, 7);
                 $definition[$method_name] = call_user_func(array($class, $method));
             }
         }
         if (count($definition)) {
             ksort($definition);
         } else {
             $definition = false;
         }
     }
     return array('class' => $class, 'function' => $function, 'definition' => $definition);
 }
예제 #30
0
 public function action_search($term, $start, $count, array $options = array())
 {
     if (Component::isActive('BackendSearch')) {
         $result = array('term' => $term);
         if ($term) {
             $result['results'] = BackendSearch::search($this, $term, array('`contents`.`active` = 1'));
         }
         return $result;
     } else {
         //TODO Use normal table search
         Backend::addError('Backend Search is not enabled');
     }
     return false;
 }