Esempio n. 1
0
 private static function shouldAdd($one, $two = false, $three = false, $four = false, $five = false)
 {
     //Controller not initiated yet.
     if (!Controller::getInit()) {
         return false;
     }
     //Some low level utilities only checks if the class exists, not if it is active
     if (!Component::isActive('BackendError')) {
         return false;
     }
     //Busy with something?
     if (self::$adding) {
         if (Controller::$debug) {
             var_dump($one, $two, $three, $four, $five);
             print_stacktrace();
             die('Recursive Backend Errors');
         }
         return false;
     }
     //Probably addBE
     if (!is_string($three) || !file_exists($three)) {
         return true;
     }
     if (Controller::$mode == Controller::MODE_EXECUTE) {
         //Check if the error originated in our realm
         if (stripos(BACKEND_FOLDER, $three) === false && stripos(APP_FOLDER, $three) === false && stripos(WEB_FOLDER, $three) === false && (!defined('SITE_FOLDER') || stripos(SITE_FOLDER, $three) === false)) {
             return false;
         }
     }
     return true;
 }
Esempio n. 2
0
 public function action_check_defines()
 {
     if (!Component::isActive('BackendError')) {
         return false;
     }
     $query = new SelectQuery('BackendError');
     $query->distinct()->field('query')->filter("`string` LIKE 'Undefined index: %'")->filter("`file` LIKE '%\\\\Render.obj.php(%) : eval()\\'d code'")->filter("`query` LIKE 'a_p_i/define/%'");
     return $query->fetchAll(array(), array('column' => 0));
 }
Esempio n. 3
0
 private function loadRelation($class, $options, $load_mode)
 {
     $class_name = array_key_exists('model', $options) ? $options['model'] . 'Obj' : $class . 'Obj';
     if (!Component::isActive($class_name)) {
         return null;
     }
     $conds = array();
     $params = array();
     $relation = new $class_name(array('name' => $options['name']));
     $conditions = array_key_exists('conditions', $options) ? $options['conditions'] : false;
     $type = array_key_exists('type', $options) ? $options['type'] : 'single';
     $order = array_key_exists('order', $options) ? $options['order'] : $relation->getMeta('order');
     if ($conditions) {
         foreach ($conditions as $field => $name) {
             if (is_array($name)) {
                 $operator = key($name);
                 $name = current($name);
             } else {
                 $operator = '=';
             }
             if ($this->array) {
                 $value = array_key_exists($name, $this->array) ? $this->array[$name] : $name;
             } else {
                 if ($this->object) {
                     $value = array_key_exists($name, $this->object) ? $this->object->{$name} : $name;
                 } else {
                     continue;
                 }
             }
             switch ($operator) {
                 case '=':
                     $conds[] = '`' . $field . '` = :' . $name;
                     break;
                 case 'FIND_IN_SET':
                 case 'in_set':
                     $conds[] = 'FIND_IN_SET(:' . $name . ', `' . $field . '`)';
                     break;
                 case 'IN':
                     $conds[] = '`' . $field . '` IN (' . $value . ')';
                     break;
             }
             $params[':' . $name] = $value;
         }
     }
     if ($type == 'multiple') {
         $mode = 'list';
     } else {
         $mode = $load_mode;
     }
     if (Controller::$debug >= 2) {
         var_dump(get_class($relation), $mode, $conds, $params, $order);
     }
     $relation->read(array('mode' => $mode, 'conditions' => $conds, 'parameters' => $params, 'order' => $order));
     return $relation;
 }
 public function get($name = false, $type = BackendLock::LOCK_CUSTOM, $expire = null, $password = null)
 {
     if (empty($password)) {
         if (Component::isActive('BackendError')) {
             BackendError::add('Missing BackendSystemLock Password', 'No password was supplied for the system lock named ' . $name);
         }
         return null;
     }
     $result = parent::get($name, $type, $expire);
     if ($result) {
         ConfigValue::set('LockPassword_' . $this->array['name'], $password);
     }
 }
Esempio n. 5
0
 public static function set($name, $value)
 {
     self::$cache[$name] = $value;
     if (Component::isActive('Value')) {
         return Value::set($name, $value);
     }
     $name = explode('.', $name);
     if (count($name) == 1) {
         array_unshift($name, 'application');
     }
     //Update the config file
     return Backend::setConfig($name, $value);
 }
Esempio n. 6
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;
 }
 public function html_display($result)
 {
     $result = parent::html_display($result);
     if (Value::get(get_class($this) . '_commented', true) && Component::isActive('Comment')) {
         if ($result instanceof DBObject) {
             $comments = Comment::getComments($result->getMeta('table'), $result->getMeta('id'));
             Backend::addContent(Render::renderFile('comments.tpl.php', array('comment_list' => $comments)));
             if (Permission::check('create', 'comment')) {
                 $values = array('foreign_table' => $result->getMeta('table'), 'foreign_id' => $result->getMeta('id'));
                 Backend::addContent(Render::renderFile('comment.add.tpl.php', $values));
             }
         }
     }
     return $result;
 }
Esempio n. 8
0
 public static function hook_view_name($view_name)
 {
     //TODO Check for a Theme here
     //Check for a Mobile version of the View
     $mobile = false;
     if (Component::isActive('Wurfl')) {
         $device = Wurfl::getDevice();
         if ($device && $device->getCapability('mobile_browser') != '' || array_key_exists('mobile', $_REQUEST)) {
             $mobile = true;
         }
     }
     if ($mobile && Component::isActive('Mobile' . $view_name)) {
         $view_name = 'Mobile' . $view_name;
     }
     return $view_name;
 }
Esempio n. 9
0
 public static function run($hookName, $type, array $parameters = array(), array $options = array())
 {
     //Specify what should be returned if the result of the hook is NULL
     //This ensures that hooks return what they should, even if the hook doesn't run
     $result = null;
     if (count($parameters)) {
         $returnIndex = array_key_exists('return_index', $options) ? $options['return_index'] : null;
         if (is_null($returnIndex)) {
             //Default to the first parameter passed
             $result = reset($parameters);
         } else {
             $result = $parameters[$returnIndex];
         }
     }
     //If the result was specified, return that
     $result = array_key_exists('toret', $options) ? $options['toret'] : $result;
     if ($hooks = self::get($hookName, $type)) {
         foreach ($hooks as $hook) {
             //Check if the hook is active and callable
             if (Component::isActive($hook['class'])) {
                 if (is_callable(array($hook['class'], $hook['method']))) {
                     if (Controller::$debug >= 2) {
                         $notice = 'Running ' . $hook['class'] . '::' . $hook['method'] . ' for hook ' . $hookName . '-' . $type;
                         Backend::addNotice($notice);
                     }
                     //Run it
                     $toret = call_user_func_array(array($hook['class'], $hook['method']), $parameters);
                     if (!is_null($toret)) {
                         $result = $toret;
                         if (count($parameters) && !is_null($returnIndex)) {
                             $parameters[$returnIndex] = $toret;
                         }
                     }
                 } else {
                     if (Controller::$debug) {
                         Backend::addNotice('Undefined Hook: ' . $hook['class'] . '::' . $hook['method']);
                     }
                 }
             }
         }
     }
     return $result;
 }
Esempio n. 10
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);
     }
     $to_print = Render::renderFile('styles.area.tpl.php');
     $to_print .= Render::renderFile('maincontent.tpl.php');
     $to_print .= Render::renderFile('scripts.tpl.php');
     $to_print = HtmlView::addLastContent($to_print);
     $to_print = HtmlView::replace($to_print);
     $to_print = HtmlView::rewriteLinks($to_print);
     $to_print = HtmlView::addLinks($to_print);
     $to_print = HtmlView::formsAcceptCharset($to_print);
     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);
             }
         }
     }
     return $to_print;
 }
Esempio n. 11
0
 public static function __exception_handler($exception)
 {
     if (Controller::$debug) {
         $trace = array_reverse($exception->getTrace());
         echo '<ol>';
         foreach ($trace as $item) {
             echo '<li>';
             if (isset($item['file'])) {
                 echo $item['file'];
             }
             if (isset($item['line'])) {
                 echo '(' . $item['line'] . ') called ';
             }
             if (isset($item['class'])) {
                 echo '<strong>' . $item['class'] . '</strong>->';
             }
             if (isset($item['function'])) {
                 echo '<i>' . $item['function'] . '</i>';
             }
             echo '</li>';
         }
         echo '</ol>';
     }
     echo "Uncaught exception: ", $exception->getMessage(), ' in ', $exception->getFile(), ' line ', $exception->getLine(), "\n";
     if (Component::isActive('BackendError')) {
         BackendError::add($exception->getCode(), "Uncaught exception: " . $exception->getMessage(), $exception->getFile(), $exception->getLine());
     }
     //Execution ends here
 }
Esempio n. 12
0
 public static function check($action = '*', $subject = '*', $subject_id = 0)
 {
     if (!BACKEND_WITH_DATABASE) {
         return true;
     }
     static $cache = array();
     if (is_object($subject)) {
         $subject = get_class($subject);
     }
     $key = serialize(array($action, $subject, $subject_id));
     if (array_key_exists($key, $cache)) {
         //return $cache[$key];
     }
     $roles = GateKeeper::permittedRoles($action, class_for_url($subject), $subject_id);
     $user = BackendUser::check();
     $user = !$user && !empty($_SESSION['BackendUser']) ? $_SESSION['BackendUser'] : $user;
     if (!$user && !in_array('anonymous', $roles)) {
         if (Controller::$debug) {
             Backend::addNotice('Anonymous User');
         }
         $cache[$key] = true;
         return true;
     }
     if ($subject != '*' && !Component::isActive(class_name($subject))) {
         if (Controller::$debug) {
             Backend::addNotice('Invalid Component: ' . class_name($subject));
         }
         $cache[$key] = false;
         return false;
     }
     if (empty($user->roles)) {
         if (Controller::$debug) {
             Backend::addNotice('No User Roles');
         }
         $cache[$key] = false;
         return false;
     }
     $intersect = is_array($roles) ? array_intersect($user->roles, $roles) : $user->roles;
     if (Controller::$debug >= 2) {
         Backend::addNotice('Valid roles found: ' . json_encode($intersect));
     }
     $result = count($intersect) ? true : false;
     $cache[$key] = $result;
     return $result;
 }
Esempio n. 13
0
 public function daily($options)
 {
     if (Component::isActive('BackendSearch')) {
         BackendSearch::doIndex($this, array('name', 'title', 'markdown'));
     }
     return true;
 }
Esempio n. 14
0
 private static function getViewName()
 {
     //Check the mode parameter
     $query_vars = Controller::getQueryVars();
     if (array_key_exists('mode', $query_vars)) {
         $view_name = ucwords($query_vars['mode']) . 'View';
         return $view_name;
     }
     //No View found, check the accept header
     $default_precedence = array('text/html' => (double) 1, 'application/xhtml+xml' => 0.9, 'application/xml' => 0);
     $mime_ranges = Parser::accept_header(false, $default_precedence);
     if (!$mime_ranges) {
         return ConfigValue::get('DefaultView', 'HtmlView');
     }
     $types = array();
     $main_types = array();
     $view_name = false;
     foreach ($mime_ranges as $mime_type) {
         $types[] = $mime_type['main_type'] . '/' . $mime_type['sub_type'];
         $main_types[] = $mime_type['main_type'];
         if (!$view_name) {
             $name = class_name(str_replace('+', ' ', $mime_type['main_type']) . ' ' . str_replace('+', ' ', $mime_type['sub_type'])) . 'View';
             if (Component::isActive($name)) {
                 $view_name = $name;
             } else {
                 $name = class_name(str_replace('+', ' ', $mime_type['main_type'])) . 'View';
                 if (Component::isActive($name)) {
                     $view_name = $name;
                 } else {
                     $name = class_name(str_replace('+', ' ', $mime_type['sub_type'])) . 'View';
                     if (Component::isActive($name)) {
                         $view_name = $name;
                     }
                 }
             }
         }
     }
     if (in_array('image', $main_types) && in_array('application', $main_types)) {
         //Probably IE
         $view_name = 'HtmlView';
     } else {
         if (in_array('application/xml', $types) && in_array('application/xhtml+xml', $types) && in_array('text/html', $types)) {
             //Maybe another confused browser that asks for XML and HTML
             $view_name = 'HtmlView';
         } else {
             if (count($mime_ranges) == 1 && $mime_ranges[0]['main_type'] == '*' && $mime_ranges[0]['sub_type'] == '*') {
                 $view_name = ConfigValue::get('DefaultView', 'HtmlView');
             }
         }
     }
     return $view_name;
 }
Esempio n. 15
0
 /**
  * @todo Refactor this so that an admin user can do backend_user/change_password/$username/$new_password
  */
 public function post_change_password()
 {
     $current = Controller::getVar('current_password');
     $password = Controller::getVar('password');
     $confirm = Controller::getVar('confirm_password');
     if ($confirm != $password) {
         Backend::addError('New password doesn\'t match');
         return false;
     }
     if (!($user = self::check())) {
         Backend::addError('Invalid User (Anonymous)');
         return false;
     }
     $userObj = self::getObject(get_class($this), $user->id);
     if (!$userObj->array) {
         Backend::addError('Invalid User');
         return false;
     }
     list($query, $params) = self::authenticate($user->username, $current, true);
     if (!$query->fetchAssoc($params)) {
         Backend::addError('Incorrect current password provided');
         return false;
     }
     if (!$userObj->update(array('password' => $password))) {
         Backend::addError('Could not update password');
         return false;
     }
     //Reread the user
     $userObj->read(array('query' => $query, 'parameters' => $params, 'mode' => 'object'));
     if ($userObj->object) {
         session_regenerate_id();
         $_SESSION['BackendUser'] = $userObj->object;
         if (Component::isActive('PersistUser')) {
             PersistUser::remember($userObj->object);
         }
     }
     return true;
 }
Esempio n. 16
0
 private function generateSitemap($component)
 {
     if (!method_exists($component, 'getSitemap')) {
         return false;
     }
     if (!Component::isActive($component)) {
         Backend::addError('Could not generate sitemap: Component inactive. (' . $component . ')');
         return false;
     }
     $controller = new $component();
     $object = $component::retrieve();
     if (!$controller instanceof TableCtl) {
         Backend::addError('Could not generate sitemap: Invalid Area. (' . $component . ')');
         return false;
     }
     $filename = WEB_FOLDER . '/sitemap_' . $component . '.xml';
     if (file_exists($filename) && !is_writable($filename)) {
         Backend::addError('Could not generate sitemap: Cannot open sitemap file. (' . $filename . ')');
         return false;
     }
     $fp = fopen($filename, 'w');
     if (!$fp) {
         Backend::addError('Could not generate sitemap: Could not open sitemap file. (' . $component . ')');
         return false;
     }
     $sitemap = $controller->getSitemap();
     if (count($sitemap) == 2 && array_key_exists('list', $sitemap) && array_key_exists('options', $sitemap)) {
         $list = $sitemap['list'];
         $options = $sitemap['options'];
     } else {
         $list = $sitemap;
         $options = array();
     }
     if (!$list) {
         Backend::addError('Could not generate sitemap: Could not generate list. (' . $component . ')');
         return false;
     }
     if (Controller::$debug) {
         Backend::addNotice('Generating sitemap for ' . $component . ' at ' . WEB_FOLDER . '/sitemap_' . $component . '.xml found at ' . SITE_LINK . basename($filename));
     }
     $last_date = 0;
     $links = array();
     //Compile Links
     foreach ($list as $row) {
         $last_date = strtotime($row['modified']) > $last_date ? strtotime($row['modified']) : $last_date;
         if (empty($options['id_field'])) {
             $id = !empty($row['name']) ? $row['name'] : $row[$object->getMeta('id_field')];
         } else {
             $id = $row[$options['id_field']];
         }
         if (empty($id)) {
             var_dump($id, $row, $object->getMeta('id_field'), $object->getMeta('id'));
             die;
         }
         if (ConfigValue::get('CleanURLs', false)) {
             $url = SITE_LINK . '/' . class_for_url($component) . '/' . $id;
         } else {
             $url = SITE_LINK . '/?q=' . class_for_url($component) . '/' . $id;
         }
         $row['url'] = $url;
         $row = array_merge($row, $options);
         $links[] = $row;
     }
     //Add link to area
     //TODO Make this configurable
     if (ConfigValue::get('CleanURLs', false)) {
         $url = SITE_LINK . '/' . class_for_url($component);
     } else {
         $url = SITE_LINK . '/?q=' . class_for_url($component);
     }
     $link = array('url' => $url, 'modified' => date('Y-m-d H:i:s', $last_date));
     $link['priority'] = array_key_exists('area_priority', $options) ? $options['area_priority'] : 0.8;
     $link['frequency'] = array_key_exists('frequency', $options) ? $options['frequency'] : 'daily';
     $links[] = $link;
     fwrite($fp, Render::file('backend_sitemap/sitemap.tpl.php', array('links' => $links)));
     return $filename;
 }
Esempio n. 17
0
	<?php 
if (Component::isActive('Style')) {
    ?>
		<link rel="stylesheet" href="<?php 
    echo SITE_LINK;
    ?>
/?q=style/#Area#/#Action#.css" type="text/css">
	<?php 
}
if (!empty($Styles)) {
    ?>
	<?php 
    foreach ($Styles as $style) {
        ?>
		<link type="text/css" rel="stylesheet" href="<?php 
        echo $style;
        ?>
">
	<?php 
    }
}
Esempio n. 18
0
 public function execute(array $parameters = array(), array $options = array())
 {
     $toret = false;
     $this->error_msg = false;
     $this->error_code = 0;
     if (empty($this->query)) {
         $this->last_stmt = false;
         $this->query = $this->buildQuery();
     }
     if ($this->checkConnection() && !empty($this->query)) {
         $parameters = array_merge($this->parameters, $parameters);
         //Check if we've already executed this query, and that the parameters are the same
         $check_cache = array_key_exists('check_cache', $options) ? $options['check_cache'] : true;
         if ($check_cache && $this->last_stmt && !count(array_diff_assoc($parameters, $this->last_params))) {
             if (Controller::$debug >= 2) {
                 var_dump('Executing Cached statement');
             }
             $toret = $this->last_stmt;
         } else {
             $stmt = $this->connection->prepare($this->query);
             if ($stmt) {
                 $this->last_stmt = $stmt;
                 $this->last_params = $parameters;
                 if ($stmt->execute($parameters)) {
                     $toret = $stmt;
                 } else {
                     $error_info = $stmt->errorInfo();
                     if ($error_info[0] == 'HY093') {
                         $error_info[1] = 'HY093';
                         $error_info[2] = 'Invalid Parameters passed to statement';
                     }
                     $verbose_error = array('Query::execute Error:');
                     if (!empty($error_info[2])) {
                         $verbose_error[] = $error_info[2];
                     }
                     if (!empty($error_info[1])) {
                         $verbose_error[] = '(' . $error_info[1] . ')';
                     }
                     $verbose_error = implode(' ', $verbose_error);
                     if (Component::isActive('BackendError') && empty($options['dont_moan'])) {
                         BackendError::add($verbose_error, 'execute');
                     }
                     if (Controller::$debug) {
                         print_stacktrace();
                         echo 'Error Info:';
                         var_dump($error_info);
                         if (Controller::$debug >= 2) {
                             echo 'Query:<pre>' . PHP_EOL . $stmt->queryString . '</pre>';
                         }
                         $this->error_msg = $verbose_error;
                     } else {
                         $this->error_msg = 'Error executing statement';
                         if (!empty($error_info[1])) {
                             $this->error_msg .= '(' . $error_info[1] . ')';
                         }
                     }
                     $this->error_code = $error_info[1];
                 }
             } else {
                 $this->error_msg = 'Could not prepare statement';
             }
         }
     } else {
         $this->error_msg = 'Could not execute query';
     }
     return $toret;
 }
Esempio n. 19
0
 public static function getObject($obj_name = false, $id = false)
 {
     $obj_name = $obj_name ? class_name($obj_name) : class_name(get_called_class());
     if (!Component::isActive($obj_name)) {
         return null;
     }
     if ($id) {
         return call_user_func(array($obj_name, 'retrieve'), $id, 'dbobject');
     } else {
         $obj_name .= 'Obj';
         return new $obj_name();
     }
 }
Esempio n. 20
0
 public static function whoops($title = 'Whoops!', $extra = 'Looks like something went wrong...')
 {
     self::$whoopsed = true;
     if (is_array($extra)) {
         $code_hint = array_key_exists('code_hint', $extra) ? $extra['code_hint'] : false;
         $message = array_key_exists('message', $extra) ? $extra['message'] : false;
     } else {
         if (is_numeric($extra)) {
             $code_hint = $extra;
             $message = 'Looks like something went wrong...';
         } else {
             $code_hint = false;
             $message = $extra;
         }
     }
     if (Component::isActive('BackendError')) {
         BackendError::add($title, $message);
     }
     if (is_callable(array(self::$view, 'whoops'))) {
         call_user_func_array(array(self::$view, 'whoops'), array($title, $message, $code_hint));
     } else {
         if (self::$view instanceof View) {
             self::$view->whoops($title, $message, $code_hint);
         }
     }
     if (array_key_exists('debug', self::$query_vars)) {
         var_dump($title, $message);
         print_stacktrace();
     }
 }
Esempio n. 21
0
<?php

if (!empty($secondary_links)) {
    ?>
	{tpl:secondary_links.tpl.php}
<?php 
}
if (!empty($HelpBoxContent)) {
    ?>
	<div class="box loud clear" id="helpbox">
		#HelpBoxContent#
	</div>
<?php 
}
if (Component::isActive('BackendUser')) {
    ?>
	{tpl:loginout.tpl.php}
<?php 
}