Example #1
0
 function __construct($title, $err_no = 0, $http = null)
 {
     // auto close on exception
     if ($http) {
         $http->Close();
     }
     return parent::__construct($title, $err_no);
 }
Example #2
0
 function __construct($title, $err_no = 0)
 {
     if (!defined('TF_TEST_INFECTED')) {
         $this->log_id = false;
         if ($err_no == self::CRITICAL) {
             echo "<h1 style='color:darkred'>Danger! {$title} </h1>";
         } else {
             // log if logger available
             if ($this->logable && class_exists('core') && ($libs = core::get_libs()) && $libs->is_registered('logger') && ($logger = core::lib('logger'))) {
                 $this->log_id = $logger->error_log($title, $err_no, $this->getTraceAsString());
             }
         }
         // display?
     }
     // var_dump($title, $err_no, $this->getTraceAsString());
     parent::__construct($title, $err_no);
     self::$last_exception = $this;
 }
Example #3
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...');
 }
Example #4
0
 function __construct($title, $err_no = 0)
 {
     if (is_array($err_no)) {
         $title .= sprintf(' (%d : %s)', $err_no['code'], $err_no['message']);
         $err_no = $err_no['code'];
     }
     parent::__construct($title, $err_no);
 }
Example #5
0
 /**
     кэш только для основного домена.
     на алиасах не работает! 
 */
 function init91()
 {
     if (core::in_editor() || loader::in_ajax() || loader::in_shell()) {
         return;
     }
     // @todo cancel on errors!
     if (tf_exception::get_last_exception()) {
         return;
     }
     // check current site
     if (!($tsite = $this->get_current_site()) || !$tsite->is_staticable()) {
         return;
     }
     /* save static cache!
           skip logged in users, debug mode
        */
     if ($this->get_core()->cfg('sat_use_static') && !core::lib('auth')->logged_in() && !core::is_debug()) {
         $file = $this->get_static_node_path($tnode = $this->get_router()->get_current_node());
         $pagination_filter = $this->get_router()->get_filter('pagination');
         if ($pagination_filter && ($page = $pagination_filter->get_start())) {
             $file = str_replace('/index.html', "/page/{$page}/index.html", $file);
         }
         core::dprint(array('generate staic : %s', $file), core::E_DEBUG4);
         if (!file_exists($file)) {
             $dir = dirname($file);
             if (!is_dir($dir)) {
                 mkdir($dir, 0777, true);
             }
             file_put_contents($file, core::lib('renderer')->get_buffer());
         }
     }
 }
Example #6
0
 /**
  * Function called on most end of script execution
  * and flush all output to user,
  * close connections and make cleanups
  *
  * Shutdown
  *
  * calls renderer::output
  */
 public function shutdown()
 {
     if (!$this->_from_cache) {
         // send headers if any
         $this->check_last_modified();
         // shutdown
         $this->init(9);
         // in critical errors we have no valid renderer
         if ($r = self::lib('renderer')) {
             if (loader::in_ajax()) {
                 $r->output_ajax();
             } else {
                 $cacher = $this->lib_enabled('page_cacher') ? $this->lib('page_cacher') : false;
                 // Cache if no exceptions and cacher ready
                 if ($cacher && !tf_exception::get_last_exception() && $cacher->is_enabled()) {
                     ob_start();
                     $r->output();
                     $buffer = ob_get_contents();
                     ob_end_clean();
                     echo $buffer;
                     // Alright? Cache it
                     $_url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                     $cacher->cache_page($_url, $buffer);
                 } else {
                     $r->output();
                 }
             }
         }
     }
     // cache
     // shutdown_after
     $this->init(91);
     if ($this->db) {
         $this->db->close();
     }
     $time = self::time_check('core-boot', true);
     if (self::is_debug()) {
         self::cprint('core shutdown : ' . ($this->_from_cache ? 'CACHE : ' : '') . $time . ' ms, mem : ' . memory_get_usage());
     }
     if (!loader::in_ajax()) {
         echo "\n\n<!--\n\tPowered by : " . self::NAME . "\n\tTime elapsed : " . $time . "\n-->\n";
     }
     $this->halt();
 }
Example #7
0
// chained in core::init0
if (!defined('TF_TEST_INFECTED') && !loader::$_debug) {
    set_error_handler(create_function('$x, $y', 'if (0 != ini_get("error_reporting")) throw new Exception($y, $x);'), E_ALL & ~E_NOTICE);
}
//
// boot up
//
try {
    loader::bootstrap();
} catch (Exception $e) {
    if (is_callable(array($e, 'display_error'))) {
        $e->display_error();
    } else {
        // No dispaly error in exception
        if (class_exists('tf_exception')) {
            echo tf_exception::generic_display_error($e);
        } else {
            printf("Unknown error : %s\n", $e->getMessage());
        }
    }
}
//
/**
 * Loader
 */
class loader
{
    public static $_debug = 0;
    const DIR_EDITOR = 'editor/';
    const DIR_MODULES = 'modules/';
    const DIR_TEMPLATES = 'templates/';