Exemplo n.º 1
0
 public static function hook_output($to_print)
 {
     //Construct the object to output
     $object = new StdClass();
     $object->result = $to_print;
     $object->error = Backend::getError();
     $object->notice = Backend::getNotice();
     $object->success = Backend::getSuccess();
     $object->content = Backend::getContent();
     $last = '';
     while (ob_get_level() > self::$ob_level) {
         //Ending the ob_start from __construct
         $last .= ob_get_clean();
     }
     $object->output = $last;
     //Clean up
     Backend::setError();
     Backend::setNotice();
     Backend::setSuccess();
     //Return the XML
     $options = array(XML_SERIALIZER_OPTION_INDENT => "\t", XML_SERIALIZER_OPTION_RETURN_RESULT => true, XML_SERIALIZER_OPTION_DEFAULT_TAG => 'item', XML_SERIALIZER_OPTION_XML_DECL_ENABLED => true, XML_SERIALIZER_OPTION_XML_ENCODING => Controller::$view->charset, XML_SERIALIZER_OPTION_ROOT_NAME => 'XmlResult', XML_SERIALIZER_OPTION_TYPEHINTS => true);
     $serializer = new XML_Serializer($options);
     if ($result = @$serializer->serialize($object)) {
         return $result;
     } else {
         return null;
     }
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 public static function hook_output($to_print)
 {
     //Construct the object to output
     $object = new stdClass();
     $object->result = $to_print;
     $object->error = Backend::getError();
     $object->notice = Backend::getNotice();
     $object->success = Backend::getSuccess();
     $object->info = Backend::getInfo();
     $object->content = Backend::getContent();
     $last = '';
     while (ob_get_level() > self::$ob_level) {
         //Ending the ob_start from __construct
         $last .= ob_get_clean();
     }
     $object->output = $last;
     //Clean up
     Backend::setError();
     Backend::setNotice();
     Backend::setSuccess();
     Backend::setInfo();
     //$result_only = Controller::getVar('result_only');
     return json_encode($object);
 }
Exemplo n.º 5
0
 /**
  * This function get's called via register_shutdown_function when the script finishes or exit is called
  */
 public static function finish()
 {
     if (self::$init) {
         Hook::run('finish', 'pre');
         $_SESSION['error'] = Backend::getError();
         $_SESSION['notice'] = Backend::getNotice();
         $_SESSION['success'] = Backend::getSuccess();
         if (!empty(self::$view)) {
             if (empty($_SESSION['previous_url']) || !is_array($_SESSION['previous_url'])) {
                 $_SESSION['previous_url'] = array();
             }
             if (array_key_exists('REQUEST_URI', $_SERVER)) {
                 $_SESSION['previous_url'][self::$view->mode] = $_SERVER['REQUEST_URI'];
             }
             if (empty($_SESSION['previous_area']) || !is_array($_SESSION['previous_area'])) {
                 $_SESSION['previous_area'] = array();
             }
             $_SESSION['previous_area'][self::$view->mode] = self::$area;
             if (empty($_SESSION['previous_action']) || !is_array($_SESSION['previous_action'])) {
                 $_SESSION['previous_action'] = array();
             }
             $_SESSION['previous_action'][self::$view->mode] = self::$action;
             if (empty($_SESSION['previous_parameters']) || !is_array($_SESSION['previous_parameters'])) {
                 $_SESSION['previous_parameters'] = array();
             }
             $_SESSION['previous_parameters'][self::$view->mode] = self::$parameters;
         }
         //Check if we encountered a fatal error
         if ($last_error = error_get_last()) {
             if ($last_error['type'] === E_ERROR && SITE_STATE == 'production') {
                 $id = send_email(ConfigValue::get('author.Email', ConfigValue::get('Email', 'info@' . SITE_DOMAIN)), 'Fatal PHP Error in ' . ConfigValue::get('Title', 'Application'), 'Error: ' . var_export($last_error, true) . PHP_EOL . 'Query: ' . self::$query_string . PHP_EOL . 'Payload: ' . var_export(self::$payload, true));
             }
         }
         //Clean up
         self::$query_string = false;
         self::$query_vars = array();
         self::$method = null;
         self::$payload = false;
         self::$area = 'home';
         self::$action = 'index';
         self::$parameters = array();
         self::$salt = false;
         self::$view = false;
         self::$started = false;
         self::$init = false;
         self::$firephp = false;
         self::$whoopsed = false;
         Backend::shutdown();
         Hook::run('finish', 'post');
         while (ob_get_level() > self::$ob_level) {
             ob_end_flush();
         }
     }
     self::$init = false;
 }