Beispiel #1
0
 /**
  * Render
  * @return array|bool|void
  */
 function render()
 {
     $attachs = $this->get_attachs();
     \core::time_check('comments-tree', 1, 1);
     $attachs->make_tree();
     \core::time_check('comments-tree');
     return $attachs->render();
 }
Beispiel #2
0
 /**
  * BootStrap kernel
  */
 protected static function _bootstrap()
 {
     // check for php version
     if (intval(phpversion()) < 5) {
         die('Unsupported PHP version.<br/>Require PHP version 5 or greater.<br/>Time to upgrade?');
     }
     self::$framework_path = self::fix_path(dirname(__FILE__) . '/../../');
     /*
     if (empty($_SERVER['DOCUMENT_ROOT'])) {    
        self::set_root(dirname(__FILE__) . '/../../');   // from shell?
        self::$_in_shell = true;
     }
     else {
        // header('Content-Type: text/html; charset=' . $config['charset']);
        self::set_root($_SERVER['DOCUMENT_ROOT']);   
     }
     */
     if (empty($_SERVER['DOCUMENT_ROOT'])) {
         self::$_in_shell = true;
     }
     $root = self::_option(self::OPTION_ROOT);
     if (!empty($root)) {
         self::set_root($root);
     } else {
         // assume TF_ROOT is ./
         self::set_root(dirname(__FILE__) . '/../../../');
     }
     // append include_path, app has more priority to overrides framework files
     set_include_path(get_include_path() . PATH_SEPARATOR . self::$framework_path);
     // ajax check
     if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' || isset($_REQUEST['with_ajax'])) {
         if ('json' === @$_REQUEST['with_ajax']) {
             self::$_in_ajax = 'json';
         } else {
             // 1 - emulated
             self::$_in_ajax = isset($_REQUEST['with_ajax']) ? 1 : true;
         }
     }
     self::autoload();
     // kick core
     self::core();
     if (self::_option(self::OPTION_NO_INIT)) {
         return;
     }
     /* Functions registered with register_shutdown_function are called before deconstructors, at least as of PHP 5.2.1.
        This contradicts an earlier commenter who claims that objects cannot be utilized in functions called from register_shutdown_function. */
     // register_shutdown_function(array($core, 'shutdown'));
     // @todo  test env
     if (!self::_option(self::OPTION_TESTING) && class_exists('\\Whoops\\Run')) {
         self::core()->init();
     } else {
         try {
             self::core()->init();
         } catch (Exception $e) {
             if (is_callable(array($e, 'display_error'))) {
                 $e->display_error();
             } else {
                 // No dispaly error in exception
                 if (class_exists('tf_exception', 0)) {
                     echo tf_exception::generic_display_error($e);
                 } else {
                     printf("Unknown error : %s\n", $e->getMessage());
                 }
             }
         }
     }
     if (self::_option(self::OPTION_AUTORUN)) {
         self::main();
     }
     core::time_check('core', true, true);
     core::dprint('mount / from ' . self::get_root());
     core::dprint('booting done...');
 }
Beispiel #3
0
 /**
  * Run block
  * Called from module::run_block
  * 
  * Params passed to 'block.data' 
  * action converted to object!
  * 
  * Extended params passed to {$block.params}
  * 
  * @param string $action action-name
  * @param array $params passed to {satblock}
  * @return bool|string
  * @throws modules_exception
  */
 function run($action, $params)
 {
     $modname = $this->get_context()->get_name();
     core::time_check('block', 1, 1);
     core::dprint('[BLOCK ' . $modname . '.' . $action . ']', core::E_DEBUG);
     // get block builtin properties
     $props = $this->get_block($action);
     // no block description found, try from file
     if (!$props) {
         $props = array('class' => true);
     }
     // assign params
     $props['params'] = $params;
     $_params = new aregistry($params);
     if (is_callable(array($this, $action))) {
         $data = call_user_func(array($this, $action), $_params);
     } elseif (!empty($props['class'])) {
         $action = is_string($props['class']) ? $props['class'] : $action;
         // try external file
         $file = $this->get_context()->get_root() . 'blocks/' . $action . loader::DOT_PHP;
         if (file_exists($file)) {
             require $file;
             $class = core_modules::ns($this->get_context()->get_name(), $action . '_block');
             if (!class_exists($class)) {
                 throw new module_exception('Class not exists - ' . $class);
             } else {
                 $data = with(new $class($this->get_context(), $props, $_params))->run();
             }
         } else {
             throw new module_exception('Block file not found - ' . $action);
         }
     } else {
         throw new module_exception('Not callable action supplied - ' . $action);
     }
     $return = $this->get_context()->renderer->render_block($props, $data);
     core::dprint('[/BLOCK]' . ' ' . core::time_check('block', 1), core::E_DEBUG);
     return $return;
 }
Beispiel #4
0
 /**
  * @param mixed $site_id
  * @param mixed $type tree|map
  * 
  * tree[url] =>
  * map[id]   =>
  */
 function get_tree($site_id = 0, $type = self::TREE_URL)
 {
     if (!isset($this->_trees[$site_id])) {
         core::time_check('sat_get_tree', false, true);
         $from_cache = false;
         // config: sat_tree_cacher = "apc"
         if (($scacher = $this->cfg('tree_cacher')) && ($ccacher = core::lib('cache')->get_engine($scacher))) {
             $data = $ccacher->get('site_tree_' . $site_id);
             $from_cache = isset($data) ? true : false;
         } else {
             /** @var sape_cacher */
             $sc = core::lib('sape_cacher');
             $data = $sc->get('tree', $site_id);
             $from_cache = $sc->is_from_cache();
         }
         $this->_trees[$site_id] = $from_cache ? $data : array('map' => array(), 'tree' => array());
         if ($from_cache && !$this->is_tree_cached($site_id)) {
             $this->_trees_cached[] = $site_id;
         }
         core::time_check('sat_get_tree', false);
     }
     return $type == self::TREE_ALL ? $this->_trees[$site_id] : $this->_trees[$site_id][$type];
 }
Beispiel #5
0
 /**
  * BootStrap kernel
  */
 static function bootstrap()
 {
     // check for php version
     if (intval(phpversion()) < 5) {
         die('Unsupported PHP version.<br/>Require PHP version 5 or greater.<br/>Time to upgrade?');
     }
     self::$framework_path = self::fix_path(dirname(__FILE__) . '/../../');
     /*
     if (empty($_SERVER['DOCUMENT_ROOT'])) {    
        self::set_root(dirname(__FILE__) . '/../../');   // from shell?
        self::$_in_shell = true;
     }
     else {
        // header('Content-Type: text/html; charset=' . $config['charset']);
        self::set_root($_SERVER['DOCUMENT_ROOT']);   
     }
     */
     if (empty($_SERVER['DOCUMENT_ROOT'])) {
         self::$_in_shell = true;
     }
     if (defined('TF_ROOT')) {
         self::set_root(TF_ROOT);
     } else {
         // assume TF_ROOT is ./
         self::set_root(dirname(__FILE__) . '/../../');
     }
     // append include_path, app has more priority to overrides framework files
     set_include_path(get_include_path() . PATH_SEPARATOR . self::$framework_path);
     // ajax check
     if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' || isset($_REQUEST['with_ajax'])) {
         self::$_in_ajax = true;
     }
     self::autoload();
     // assume core created!
     core::get_instance()->init();
     core::time_check('core', true, true);
     core::dprint('mount / from ' . self::get_root());
     core::dprint('booting done...');
     /* Functions registered with register_shutdown_function are called before deconstructors, at least as of PHP 5.2.1. 
        This contradicts an earlier commenter who claims that objects cannot be utilized in functions called from register_shutdown_function. */
     // register_shutdown_function(array($core, 'shutdown'));
     if (defined('TF_AUTORUN')) {
         core::get_instance()->main();
     }
 }