/** * @param mixed $account * @return moswar_lib */ function __construct($account) { if (!$account) { throw new moswar_exception('moswar lib constructor: invalid account'); } $this->_acc = $account; if ($account->browser) { $this->_ua = $account->browser; } // DEBUG IN SHELL if (!loader::in_shell()) { $this->_debug = false; } }
/** * Is enabled */ function is_enabled() { return $this->_enabled && !loader::in_ajax() && !loader::in_shell() && core::lib('auth')->get_user()->is_anonymous(); }
/** кэш только для основного домена. на алиасах не работает! */ 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()); } } }
/** * DisplayError */ function display_error() { $title = $this->getMessage(); $err_no = $this->getCode(); // notify interactive user if (!class_exists('loader', 0) || class_exists('loader', 0) && !loader::in_ajax() && !($err_no == router_exception::NOT_FOUND && $this instanceof router_exception)) { if (!headers_sent()) { header('', true, 500); } $message = '<style>* {font: 0.97em verdana;} a {text-decoration:none;background:#EFEFEF;padding:4px;} a:hover{background: red;}</style><h1>Ups! We have an error here.</h1>'; $subject = "Error " . ($this->log_id ? "#{$this->log_id}" : '') . " at " . (loader::in_shell() ? 'console' : $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); $message .= "Please send report to <a href='mailto:" . $this->bugs_email . "?subject={$subject}'>Bugs mail</a>.<br/>"; $message .= 'Thank you.<br/><br/>'; $message .= 'Visit <a href="/">index</a> page.<br/><br/>'; echo $message; // if debug if (class_exists('core', 0) && core::is_debug()) { echo '<br/>Error : ' . $title . ' : ' . $err_no; echo '<br/><br/>' . nl2br($this->getTraceAsString()); } } }
static function nl($s = '') { return $s . (loader::in_shell() ? "\n" : "<br/>\n"); }
/** * вывод текста (::) * @param string message * @param bool need return or echo */ public static function cprint($buff, $ret = false) { if (self::$_mute_console) { return; } $level = false; $color = null; if (is_array($buff)) { $color = $buff['color']; $level = $buff['name']; $buff = $buff['text']; } // $buff = text_proc_c::message_bbdecode($text); // $buff = highlight_string($text, true); if (loader::in_shell()) { echo "console> {$buff}\n"; return; } if (!$ret && ($con = self::lib('console'))) { $con->out($buff, $level, $color); } return $buff; }
/** * Test bootstrap */ error_reporting(E_ALL); ini_set('display_errors', 'on'); test_assertions::$start_time = microtime(1); // this prevent init10 on modules! register_shutdown_function('test_done'); require dirname(__FILE__) . "/../loader.php"; $BOOT_OPTIONS = array(loader::OPTION_TESTING => true, loader::OPTION_CORE_PARAMS => array('config' => array('database' => 'test'))); loader::bootstrap($BOOT_OPTIONS); if (!loader::in_shell()) { die('Tests available only from console' . PHP_EOL); } // fix unicode if (loader::is_windows() && loader::in_shell()) { system('chcp 65001 > NUL'); } /** * Tests api: * * test_head(title) * test_print(var, var, ...) * * test_assert($assert, $title) * test_except(closure, $title) * * test_done - called on shutdown */ /** * Print test head
/** * Final output * called from @see core::shutdown */ public function output() { /** give up if in crontab */ if (loader::in_shell()) { return false; } $core = core::get_instance(); if (!empty($this->_content_type) && !headers_sent()) { header('Content-Type: ' . $this->_content_type . '; charset=' . $core->get_cfg_var('charset')); } // disabled if ($this->_disable_output) { return false; } $cfg_data = array(); // initial $this->output_begin(); if (core::in_editor()) { $this->output_editor($tpl); } else { $tpl = $this->page_template; } // check message if ($msg = $core->get_message()) { if ($temp_tpl = $this->render_message($msg)) { $tpl = $temp_tpl; } } // no template if (empty($tpl)) { core::dprint('render with empty page template assigned'); //throw new renderer_exception('render with empty page template assigned'); } /* Throwing exception here Will result in Fatal error: Exception thrown without a stack frame in Unknown on line 0 */ if (false == $this->get_main_template()) { core::dprint('render with empty main template assigned'); // throw new renderer_exception('render with empty main template assigned'); } // append $tpl .= loader::DOT_TPL; $this->output_end($tpl); }
/** * Final output * called from @see core::shutdown */ public function output() { if (loader::in_ajax()) { return $this->output_ajax(); } /** give up if in crontab */ if (loader::in_shell()) { return false; } $core = core::get_instance(); core::dprint('renderer::ouput', core::E_DEBUG0); $this->content_type_header(); // disabled if ($this->_disable_output) { return false; } $cfg_data = array(); // initial $this->output_begin(); if (core::in_editor()) { $this->output_editor(); } $tpl = $this->page_template; // check message if ($msg = $core->get_message()) { $this->render_message($msg, $core->get_message_data()); } elseif (!empty($this->_message)) { $this->render_message($this->_message['message'], @$this->_message['data']); } // no template if (empty($tpl)) { core::dprint('render with empty page template assigned'); //throw new renderer_exception('render with empty page template assigned'); } /* Throwing exception here Will result in Fatal error: Exception thrown without a stack frame in Unknown on line 0 */ if (false == $this->get_main_template()) { core::dprint('render with empty main template assigned'); // throw new renderer_exception('render with empty main template assigned'); } $this->output_end($tpl); }