Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Wed, Jun 18, 3:47 PM

in-portal

Index: branches/unlabeled/unlabeled-1.69.2/core/kernel/processors/main_processor.php
===================================================================
--- branches/unlabeled/unlabeled-1.69.2/core/kernel/processors/main_processor.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.69.2/core/kernel/processors/main_processor.php (revision 8100)
@@ -0,0 +1,984 @@
+<?php
+
+class kMainTagProcessor extends TagProcessor {
+
+ function Init($prefix, $special, $event_params = null)
+ {
+ parent::Init($prefix, $special, $event_params);
+
+ $actions =& $this->Application->recallObject('kActions');
+ $actions->Set('t', $this->Application->GetVar('t'));
+ $actions->Set('sid', $this->Application->GetSID());
+ $actions->Set('m_opener', $this->Application->GetVar('m_opener') );
+ }
+
+ /**
+ * Used to handle calls where tag name
+ * match with existing php function name
+ *
+ * @param Tag $tag
+ * @return string
+ */
+ function ProcessTag(&$tag)
+ {
+ if ($tag->Tag=='include') $tag->Tag='MyInclude';
+ return parent::ProcessTag($tag);
+ }
+
+ /**
+ * Base folder for all template includes
+ *
+ * @param Array $params
+ * @return string
+ */
+ function TemplatesBase($params)
+ {
+ if ($this->Application->IsAdmin()) {
+ $module = isset($params['module']) ? $params['module'] : 'core';
+ if ($module == 'in-portal') {
+ $module = 'kernel';
+ }
+ $path = preg_replace('/\/(.*?)\/(.*)/', $module.'/\\2', THEMES_PATH); // remove leading slash + substitute module
+ }
+ else {
+ $path = substr(THEMES_PATH, 1);
+ }
+ return $this->Application->BaseURL().$path;
+ }
+
+ /**
+ * Creates <base href ..> HTML tag for all templates
+ * affects future css, js files and href params of links
+ *
+ * @return string
+ * @access public
+ */
+ function Base_Ref($params)
+ {
+ return '<base href="'.$this->TemplatesBase($params).'/" />';
+ }
+
+ /**
+ * Returns base url for web-site
+ *
+ * @return string
+ * @access public
+ */
+ function BaseURL()
+ {
+ return $this->Application->BaseURL();
+ }
+
+ //for compatability with K3 tags
+ function Base($params)
+ {
+ return $this->TemplatesBase($params).'/';
+ }
+
+ function ProjectBase($params)
+ {
+ return $this->Application->BaseURL();
+ }
+
+ /*function Base($params)
+ {
+ return $this->Application->BaseURL().$params['add'];
+ }*/
+
+ /**
+ * Used to create link to any template.
+ * use "pass" paramter if "t" tag to specify
+ * prefix & special of object to be represented
+ * in resulting url
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function T($params)
+ {
+ //by default link to current template
+ $t = $this->SelectParam($params, 't,template');
+ unset($params['t']);
+ unset($params['template']);
+ $prefix=isset($params['prefix']) ? $params['prefix'] : ''; unset($params['prefix']);
+ $index_file = isset($params['index_file']) ? $params['index_file'] : null; unset($params['index_file']);
+
+ return $this->Application->HREF($t, $prefix, $params, $index_file);
+ }
+
+ function Link($params)
+ {
+ if (isset($params['template'])) {
+ $params['t'] = $params['template'];
+ unset($params['template']);
+ }
+ if (!isset($params['pass']) && !isset($params['no_pass'])) $params['pass'] = 'm';
+ if (isset($params['no_pass'])) unset($params['no_pass']);
+
+ if( $this->Application->GetVar('admin') ) $params['admin'] = 1;
+
+ return $this->T($params);
+ }
+
+ function Env($params)
+ {
+ $t = $params['template'];
+ unset($params['template']);
+ return $this->Application->BuildEnv($t, $params, 'm', null, false);
+ }
+
+ function FormAction($params)
+ {
+ $pass_category = true;
+ $category_id = $this->Application->GetVar('m_cat_id');
+
+ if ($category_id > 0) {
+ $category = $this->Application->recallObject('c');
+ /* @var $category kDBItem */
+
+ $t = $this->Application->GetVar('t');
+ if (preg_match('/Content\/'.preg_quote($t, '/').'/i', $category->GetDBField('NamedParentPath'))) {
+ // category name matches template name -> Proj-CMS/In-Edit tricks
+ $pass_category = false;
+ }
+ }
+
+ $params['pass'] = 'all,m';
+ if ($pass_category) {
+ $params['pass_category'] = 1;
+ }
+ return $this->Application->HREF('', '', $params);
+ }
+
+ /*// NEEDS TEST
+ function Config($params)
+ {
+ return $this->Application->ConfigOption($params['var']);
+ }
+
+ function Object($params)
+ {
+ $name = $params['name'];
+ $method = $params['method'];
+
+ $tmp =& $this->Application->recallObject($name);
+ if ($tmp != null) {
+ if (method_exists($tmp, $method))
+ return $tmp->$method($params);
+ else
+ echo "Method $method does not exist in object ".get_class($tmp)." named $name<br>";
+ }
+ else
+ echo "Object $name does not exist in the appliaction<br>";
+ }*/
+
+ /**
+ * Tag, that always returns true.
+ * For parser testing purposes
+ *
+ * @param Array $params
+ * @return bool
+ * @access public
+ */
+ function True($params)
+ {
+ return true;
+ }
+
+ /**
+ * Tag, that always returns false.
+ * For parser testing purposes
+ *
+ * @param Array $params
+ * @return bool
+ * @access public
+ */
+ function False($params)
+ {
+ return false;
+ }
+
+ /**
+ * Returns block parameter by name
+ *
+ * @param Array $params
+ * @return stirng
+ * @access public
+ */
+ function Param($params)
+ {
+ //$parser =& $this->Application->recallObject('TemplateParser');
+ $res = $this->Application->Parser->GetParam($params['name']);
+ if ($res === false) $res = '';
+ if (isset($params['plus']))
+ $res += $params['plus'];
+ return $res;
+ }
+
+ function DefaultParam($params)
+ {
+ foreach ($params as $key => $val) {
+ if ($this->Application->Parser->GetParam($key) === false) {
+ $this->Application->Parser->SetParam($key, $val);
+ }
+ }
+ }
+
+ /**
+ * Gets value of specified field from specified prefix_special and set it as parser param
+ *
+ * @param Array $params
+ */
+ /*function SetParam($params)
+ {
+ // <inp2:m_SetParam param="custom_name" src="cf:FieldName"/>
+ list($prefix_special, $field_name) = explode(':', $params['src']);
+
+ $object =& $this->Application->recallObject($prefix_special);
+ $name = $this->SelectParam($params, 'param,name,var');
+
+ $this->Application->Parser->SetParam($name, $object->GetField($field_name) );
+ }*/
+
+ /**
+ * Compares block parameter with value specified
+ *
+ * @param Array $params
+ * @return bool
+ * @access public
+ */
+ function ParamEquals($params)
+ {
+ //$parser =& $this->Application->recallObject('TemplateParser');
+ $name = $this->SelectParam($params, 'name,var,param');
+ $value = $params['value'];
+ return ($this->Application->Parser->GetParam($name) == $value);
+ }
+
+ /*function PHP_Self($params)
+ {
+ return $HTTP_SERVER_VARS['PHP_SELF'];
+ }
+ */
+
+ /**
+ * Returns session variable value by name
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function Recall($params)
+ {
+ $ret = $this->Application->RecallVar( $this->SelectParam($params,'name,var,param') );
+ $ret = ($ret === false && isset($params['no_null'])) ? '' : $ret;
+ if( getArrayValue($params,'special') || getArrayValue($params,'htmlchars')) $ret = htmlspecialchars($ret);
+
+ if ( getArrayValue($params, 'urlencode') ) $ret = urlencode($ret);
+
+ return $ret;
+ }
+
+ function RemoveVar($params)
+ {
+ $this->Application->RemoveVar( $this->SelectParam($params,'name,var,param') );
+ }
+
+ // bad style to store something from template to session !!! (by Alex)
+ // Used here only to test how session works, nothing more
+ function Store($params)
+ {
+ //echo"Store $params[name]<br>";
+ $name = $params['name'];
+ $value = $params['value'];
+ $this->Application->StoreVar($name,$value);
+ }
+
+ /**
+ * Sets application variable value(-s)
+ *
+ * @param Array $params
+ * @access public
+ */
+ function Set($params)
+ {
+ foreach ($params as $param => $value) {
+ $this->Application->SetVar($param, $value);
+ }
+ }
+
+ /**
+ * Increment application variable
+ * specified by number specified
+ *
+ * @param Array $params
+ * @access public
+ */
+ function Inc($params)
+ {
+ $this->Application->SetVar($params['param'], $this->Application->GetVar($params['param']) + $params['by']);
+ }
+
+ /**
+ * Retrieves application variable
+ * value by name
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function Get($params)
+ {
+ $ret = $this->Application->GetVar($this->SelectParam($params, 'name,var,param'), '');
+ return getArrayValue($params, 'htmlchars') ? htmlspecialchars($ret) : $ret;
+ }
+
+ /**
+ * Retrieves application constant
+ * value by name
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function GetConst($params)
+ {
+ return defined($this->SelectParam($params, 'name,const')) ? constant($this->SelectParam($params, 'name,const,param')) : '';
+ }
+
+ /**
+ * Retrieves configuration variable value by name
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function GetConfig($params)
+ {
+ $config_name = $this->SelectParam($params, 'name,var');
+ $ret = $this->Application->ConfigValue($config_name);
+ if( getArrayValue($params, 'escape') ) $ret = addslashes($ret);
+ return $ret;
+ }
+
+ function ConfigEquals($params)
+ {
+ $option = $this->SelectParam($params, 'name,option,var');
+ return $this->Application->ConfigValue($option) == getArrayValue($params, 'value');
+ }
+
+ /**
+ * Creates all hidden fields
+ * needed for kernel_form
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function DumpSystemInfo($params)
+ {
+ $actions =& $this->Application->recallObject('kActions');
+ $actions->Set('t', $this->Application->GetVar('t') );
+
+ $params = $actions->GetParams();
+ $o='';
+ foreach ($params AS $name => $val)
+ {
+ $o .= "<input type='hidden' name='$name' id='$name' value='$val'>\n";
+ }
+ return $o;
+ }
+
+ function GetFormHiddens($params)
+ {
+ $sid = $this->Application->GetSID();
+ $t = $this->SelectParam($params, 'template,t');
+ unset($params['template']);
+ $env = $this->Application->BuildEnv($t, $params, 'm', null, false);
+ $o = '';
+ if ( $this->Application->RewriteURLs() )
+ {
+ $session =& $this->Application->recallObject('Session');
+ if ($session->NeedQueryString()) {
+ $o .= "<input type='hidden' name='sid' id='sid' value='$sid'>\n";
+ }
+ }
+ else {
+ $o .= "<input type='hidden' name='env' id='env' value='$env'>\n";
+ }
+ if ($this->Application->GetVar('admin') == 1) {
+ $o .= "<input type='hidden' name='admin' id='admin' value='1'>\n";
+ }
+ return $o;
+ }
+
+ function Odd_Even($params)
+ {
+ $odd = $params['odd'];
+ $even = $params['even'];
+ if (!isset($params['var'])) {
+ $var = 'odd_even';
+ }
+ else {
+ $var = $params['var'];
+ }
+
+ if ($this->Application->GetVar($var) == 'even') {
+ if (!isset($params['readonly']) || !$params['readonly']) {
+ $this->Application->SetVar($var, 'odd');
+ }
+ return $even;
+ }
+ else {
+ if (!isset($params['readonly']) || !$params['readonly']) {
+ $this->Application->SetVar($var, 'even');
+ }
+ return $odd;
+ }
+ }
+
+ /**
+ * Returns phrase translation by name
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function Phrase($params)
+ {
+ // m:phrase name="phrase_name" default="Tr-alala" updated="2004-01-29 12:49"
+ if (array_key_exists('default', $params)) return $params['default']; //backward compatibility
+ $translation = $this->Application->Phrase($this->SelectParam($params, 'label,name,title'));
+ if (getArrayValue($params, 'escape')) {
+ $translation = htmlspecialchars($translation);
+ $translation = str_replace('\'', '&#39;', $translation);
+ $translation = addslashes($translation);
+ }
+ return $translation;
+ }
+
+ // for tabs
+ function is_active($params)
+ {
+ $test_templ = $this->SelectParam($params, 'templ,template,t');
+ if ( !getArrayValue($params,'allow_empty') )
+ {
+ $if_true=getArrayValue($params,'true') ? $params['true'] : 1;
+ $if_false=getArrayValue($params,'false') ? $params['false'] : 0;
+ }
+ else
+ {
+ $if_true=$params['true'];
+ $if_false=$params['false'];
+ }
+
+ if ( preg_match("/^".str_replace('/', '\/', $test_templ)."/i", $this->Application->GetVar('t'))) {
+ return $if_true;
+ }
+ else {
+ return $if_false;
+ }
+ }
+
+ function IsNotActive($params)
+ {
+ return !$this->is_active($params);
+ }
+
+ function IsActive($params)
+ {
+ return $this->is_active($params);
+ }
+
+ function is_t_active($params)
+ {
+ return $this->is_active($params);
+ }
+
+ function CurrentTemplate($params)
+ {
+ return $this->is_active($params);
+ }
+
+ /**
+ * Checks if session variable
+ * specified by name value match
+ * value passed as parameter
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function RecallEquals($params)
+ {
+ $name = $this->SelectParam($params, 'name,var');
+ $value = $params['value'];
+ return ($this->Application->RecallVar($name) == $value);
+ }
+
+ /**
+ * Checks if application variable
+ * specified by name value match
+ * value passed as parameter
+ *
+ * @param Array $params
+ * @return bool
+ * @access public
+ */
+ function GetEquals($params)
+ {
+ $name = $this->SelectParam($params, 'var,name,param');
+ $value = $params['value'];
+ if ($this->Application->GetVar($name) == $value) {
+ return 1;
+ }
+ }
+
+ /**
+ * Includes template
+ * and returns it's
+ * parsed version
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function MyInclude($params)
+ {
+ $BlockParser =& $this->Application->makeClass('TemplateParser');
+// $BlockParser->SetParams($params);
+ $parser =& $this->Application->Parser;
+ $this->Application->Parser =& $BlockParser;
+
+ // this is for the parser to know the master template in case an error occurs,
+ // ParseTemplate will reset it anyway, but this will allow error handler to display the tempalte
+ // which tries to include missing template for example
+ $this->Application->Parser->TemplateName = $parser->TemplateName;
+
+ $t = $this->SelectParam($params, 't,template,block,name');
+ $t = eregi_replace("\.tpl$", '', $t);
+
+ if (!$t) {
+ trigger_error('Template name not specified in <b>&lt;inp2:m_include .../&gt;</b> tag', E_USER_ERROR);
+ }
+
+ $res = $BlockParser->ParseTemplate( $t, 1, $params, isset($params['is_silent']) ? 1 : 0 );
+
+ if ( !$BlockParser->DataExists && (isset($params['data_exists']) || isset($params['block_no_data'])) ) {
+ if ($block_no_data = getArrayValue($params, 'block_no_data')) {
+ $res = $BlockParser->Parse(
+ $this->Application->TemplatesCache->GetTemplateBody($block_no_data, getArrayValue($params, 'is_silent') ),
+ $t
+ );
+ }
+ else {
+ $res = '';
+ }
+ }
+ $this->Application->Parser =& $parser;
+ $this->Application->Parser->DataExists = $this->Application->Parser->DataExists || $BlockParser->DataExists;
+ return $res;
+ }
+
+ function ModuleInclude($params)
+ {
+ $ret = '';
+ $block_params = array_merge($params, Array('is_silent' => 2)); // don't make fatal errors in case if template is missing
+ $current_template = $this->Application->GetVar('t');
+ $skip_prefixes = isset($params['skip_prefixes']) ? explode(',', $params['skip_prefixes']) : Array();
+ foreach ($this->Application->ModuleInfo as $module_name => $module_data) {
+ $module_key = strtolower($module_name);
+
+ if ($module_name == 'In-Portal') {
+ $module_prefix = $this->Application->IsAdmin() ? 'in-portal/' : '';
+ }
+ else {
+ $module_prefix = $this->Application->IsAdmin() ? $module_key.'/' : $module_data['TemplatePath'].'/';
+ }
+
+ $block_params['t'] = $module_prefix.$this->SelectParam($params, $module_key.'_template,'.$module_key.'_t,template,t');
+ if ($block_params['t'] == $current_template || in_array($module_data['Var'], $skip_prefixes)) continue;
+
+ $no_data = $this->SelectParam($params, $module_key.'_block_no_data,block_no_data');
+ if ($no_data) {
+ $block_params['block_no_data'] = $module_prefix.'/'.$no_data;
+ }
+ $ret .= $this->MyInclude($block_params);
+ }
+ return $ret;
+ }
+
+ function ModuleEnabled($params)
+ {
+ return $this->Application->isModuleEnabled( $params['module'] );
+ }
+
+ /*function Kernel_Scripts($params)
+ {
+ return '<script type="text/javascript" src="'.PROTOCOL.SERVER_NAME.BASE_PATH.'/kernel3/js/grid.js"></script>';
+ }*/
+
+
+ /*function GetUserPermission($params)
+ {
+ // echo"GetUserPermission $params[name]";
+ if ($this->Application->RecallVar('user_type') == 1)
+ return 1;
+ else {
+ $perm_name = $params[name];
+ $aPermissions = unserialize($this->Application->RecallVar('user_permissions'));
+ if ($aPermissions)
+ return $aPermissions[$perm_name];
+ }
+ }*/
+
+
+ /**
+ * Set's parser block param value
+ *
+ * @param Array $params
+ * @access public
+ */
+ function AddParam($params)
+ {
+ $parser =& $this->Application->Parser; // recallObject('TemplateParser');
+ foreach ($params as $param => $value) {
+ $this->Application->SetVar($param, $value);
+ $parser->SetParam($param, $value);
+ $parser->AddParam('/\$'.$param.'/', $value);
+ }
+ }
+
+ /*function ParseToVar($params)
+ {
+ $var = $params['var'];
+ $tagdata = $params['tag'];
+ $parser =& $this->Application->Parser; //recallObject('TemplateParser');
+ $res = $this->Application->ProcessTag($tagdata);
+
+ $parser->SetParam($var, $res);
+ $parser->AddParam('/\$'.$var.'/', $res);
+ return '';
+ }*/
+
+ /*function TagNotEmpty($params)
+ {
+ $tagdata = $params['tag'];
+ $res = $this->Application->ProcessTag($tagdata);
+ return $res != '';
+ }*/
+
+ /*function TagEmpty($params)
+ {
+ return !$this->TagNotEmpty($params);
+ }*/
+
+ /**
+ * Parses block and returns result
+ *
+ * @param Array $params
+ * @return string
+ * @access public
+ */
+ function ParseBlock($params)
+ {
+ $parser =& $this->Application->Parser; // recallObject('TemplateParser');
+ return $parser->ParseBlock($params);
+ }
+
+ function RenderElement($params)
+ {
+ return $this->ParseBlock($params);
+ }
+
+ function RenderElements($params)
+ {
+ if (!isset($params['elements']) || !$params['elements']) return;
+ $elements = explode(',',$params['elements']);
+ if (isset($params['skip']) && $params['skip']) {
+ $tmp_skip = explode(',',$params['skip']);
+ foreach ($tmp_skip as $elem) {
+ $skip[] = trim($elem);
+ }
+ }
+ else {
+ $skip = array();
+ }
+ unset($params['elements']);
+ $o = '';
+ foreach ($elements as $an_element)
+ {
+ $cur = trim($an_element);
+ if (in_array($cur,$skip)) continue;
+ $pass_params = $params;
+ $pass_params['name'] = $cur;
+ $o .= $this->ParseBlock($pass_params);
+ }
+ return $o;
+
+ }
+
+ /**
+ * Checks if debug mode is on
+ *
+ * @return bool
+ * @access public
+ */
+ function IsDebugMode()
+ {
+ return $this->Application->isDebugMode();
+ }
+
+ function MassParse($params)
+ {
+ $qty = $params['qty'];
+ $block = $params['block'];
+ $mode = $params['mode'];
+
+ $o = '';
+ if ($mode == 'func') {
+ $func = create_function('$params', '
+ $o = \'<tr>\';
+ $o.= \'<td>a\'.$params[\'param1\'].\'</td>\';
+ $o.= \'<td>a\'.$params[\'param2\'].\'</td>\';
+ $o.= \'<td>a\'.$params[\'param3\'].\'</td>\';
+ $o.= \'<td>a\'.$params[\'param4\'].\'</td>\';
+ $o.= \'</tr>\';
+ return $o;
+ ');
+ for ($i=1; $i<$qty; $i++) {
+ $block_params['param1'] = rand(1, 10000);
+ $block_params['param2'] = rand(1, 10000);
+ $block_params['param3'] = rand(1, 10000);
+ $block_params['param4'] = rand(1, 10000);
+ $o .= $func($block_params);
+ }
+ return $o;
+ }
+
+ $block_params['name'] = $block;
+
+ for ($i=0; $i<$qty; $i++) {
+ $block_params['param1'] = rand(1, 10000);
+ $block_params['param2'] = rand(1, 10000);
+ $block_params['param3'] = rand(1, 10000);
+ $block_params['param4'] = rand(1, 10000);
+ $block_params['passed'] = $params['passed'];
+ $block_params['prefix'] = 'm';
+
+ $o.= $this->Application->ParseBlock($block_params, 1);
+ }
+ return $o;
+ }
+
+ function LoggedIn($params)
+ {
+ return $this->Application->LoggedIn();
+ }
+
+ /**
+ * Allows to check if permission exists directly in template and perform additional actions if required
+ *
+ * @param Array $params
+ * @return bool
+ */
+ function CheckPermission($params)
+ {
+ $perm_helper =& $this->Application->recallObject('PermissionsHelper');
+ return $perm_helper->TagPermissionCheck($params, 'm_CheckPermission');
+ }
+
+ /**
+ * Checks if user is logged in and if not redirects it to template passed
+ *
+ * @param Array $params
+ */
+ function RequireLogin($params)
+ {
+ $t = $this->Application->GetVar('t');
+ if ($next_t = getArrayValue($params, 'next_template')) {
+ $t = $next_t;
+ }
+
+ // check by permissions: begin
+ if ((isset($params['perm_event']) && $params['perm_event']) ||
+ (isset($params['perm_prefix']) && $params['perm_prefix']) ||
+ (isset($params['permissions']) && $params['permissions'])) {
+
+ $perm_helper =& $this->Application->recallObject('PermissionsHelper');
+ /* @var $perm_helper kPermissionsHelper */
+
+ $perm_status = $perm_helper->TagPermissionCheck($params, 'm_RequireLogin');
+ if (!$perm_status) {
+ list($redirect_template, $redirect_params) = $perm_helper->getPermissionTemplate($params);
+ $this->Application->Redirect($redirect_template, $redirect_params);
+ }
+ else {
+ return ;
+ }
+ }
+ // check by permissions: end
+
+ // check by configuration value: begin
+ $condition = getArrayValue($params, 'condition');
+ if (!$condition) {
+ $condition = true;
+ }
+ else {
+ if (substr($condition, 0, 1) == '!') {
+ $condition = !$this->Application->ConfigValue(substr($condition, 1));
+ }
+ else {
+ $condition = $this->Application->ConfigValue($condition);
+ }
+ }
+ // check by configuration value: end
+
+ // check by belonging to group: begin
+ $group = $this->SelectParam($params, 'group');
+ $group_access = true;
+ if ($group) {
+ $conn =& $this->Application->GetADODBConnection();
+ $group_id = $conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'PortalGroup WHERE Name = '.$conn->qstr($group));
+ if ($group_id) {
+ $groups = explode(',', $this->Application->RecallVar('UserGroups'));
+ $group_access = in_array($group_id, $groups);
+ }
+ }
+ // check by belonging to group: end
+
+ if ((!$this->Application->LoggedIn() || !$group_access) && $condition) {
+ if ( $this->Application->LoggedIn() && !$group_access) {
+ $this->Application->Redirect( $params['no_group_perm_template'], Array('next_template'=>$t) );
+ }
+
+ $redirect_params = $this->Application->HttpQuery->getRedirectParams();
+ $redirect_params['next_template'] = $t;
+ $this->Application->Redirect($params['login_template'], $redirect_params);
+ }
+ }
+
+ function IsMember($params)
+ {
+ $group = getArrayValue($params, 'group');
+ $conn =& $this->Application->DB;
+ $group_id = $conn->GetOne('SELECT GroupId FROM '.TABLE_PREFIX.'PortalGroup WHERE Name = '.$conn->qstr($group));
+ if ($group_id) {
+ $groups = explode(',', $this->Application->RecallVar('UserGroups'));
+ $group_access = in_array($group_id, $groups);
+ }
+ return $group_access;
+ }
+
+ /**
+ * Checks if SSL is on and redirects to SSL URL if needed
+ * If SSL_URL is not defined in config - the tag does not do anything
+ * If for_logged_in_only="1" exits if user is not logged in.
+ * If called without params forces https right away. If called with by_config="1" checks the
+ * Require SSL setting from General Config and if it is ON forces https
+ *
+ * @param unknown_type $params
+ */
+ function CheckSSL($params)
+ {
+ $ssl = $this->Application->ConfigValue('SSL_URL');
+ if (!$ssl) return; //SSL URL is not set - no way to require SSL
+
+ $require = false;
+
+ if (isset($params['mode']) && $params['mode'] == 'required') {
+ $require = true;
+ if (isset($params['for_logged_in_only']) && $params['for_logged_in_only'] && !$this->Application->LoggedIn()) {
+ $require = false;
+ }
+
+ if (isset($params['condition'])) {
+ if (!$this->Application->ConfigValue($params['condition'])) {
+ $require = false;
+ }
+ }
+ }
+
+ $http_query =& $this->Application->recallObject('HTTPQuery');
+ $pass = $http_query->getRedirectParams();
+
+ if ($require) {
+ if (PROTOCOL == 'https://') {
+ $this->Application->SetVar('__KEEP_SSL__', 1);
+ return;
+ }
+ $this->Application->Redirect('', array_merge_recursive2($pass, Array('__SSL__' => 1)));
+ }
+ else {
+ if (PROTOCOL == 'https://' && $this->Application->ConfigValue('Force_HTTP_When_SSL_Not_Required')) {
+ if ($this->Application->GetVar('__KEEP_SSL__')) return;
+ $pass = array('pass'=>'m', 'm_cat_id'=>0);
+ $this->Application->Redirect('', array_merge_recursive2($pass, Array('__SSL__' => 0)));
+ }
+ }
+ }
+
+ function ConstOn($params)
+ {
+ $name = $this->SelectParam($params,'name,const');
+ return constOn($name);
+ }
+
+ function SetDefaultCategory($params)
+ {
+ $module_name = $params['module'];
+ $module =& $this->Application->recallObject('mod.'.$module_name);
+ $this->Application->SetVar('m_cat_id', $module->GetDBField('RootCat') );
+ }
+
+ function XMLTemplate($params)
+ {
+ safeDefine('DBG_SKIP_REPORTING', 1);
+ $lang =& $this->Application->recallObject('lang.current');
+ header('Content-type: text/xml; charset='.$lang->GetDBField('Charset'));
+ }
+
+ function Header($params)
+ {
+ header($params['data']);
+ }
+
+ function NoDebug($params)
+ {
+ define('DBG_SKIP_REPORTING', 1);
+ }
+
+ function RootCategoryName($params)
+ {
+ $root_phrase = $this->Application->ConfigValue('Root_Name');
+ return $this->Application->Phrase($root_phrase);
+ }
+
+ /**
+ * Allows to attach file directly from email event template
+ *
+ * @param Array $params
+ */
+ function AttachFile($params)
+ {
+ $esender =& $application->recallObject('EmailSender'.(isset($params['special']) ? '.'.$params['special'] : ''));
+ /* @var $esender kEmailSendingHelper */
+
+ $path = FULL_PATH.'/'.$params['path'];
+ if (file_exists($path)) {
+ $esender->AddAttachment($path);
+ }
+ }
+
+ function CaptchaImage($params){
+ $captcha_helper =& $this->Application->recallObject('CaptchaHelper');
+ /* @var $captcha_helper kCaptchaHelper */
+ $captcha_helper->GenerateCaptchaImage(
+ $this->Application->RecallVar($this->Application->GetVar('var')),
+ $this->Application->GetVar('w'),
+ $this->Application->GetVar('h'),
+ true
+ );
+ }
+}
Property changes on: branches/unlabeled/unlabeled-1.69.2/core/kernel/processors/main_processor.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.69
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.69.2/core/kernel/utility/debugger.php
===================================================================
--- branches/unlabeled/unlabeled-1.69.2/core/kernel/utility/debugger.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.69.2/core/kernel/utility/debugger.php (revision 8100)
@@ -0,0 +1,1222 @@
+<?php
+
+ if( !class_exists('Debugger') ) {
+ class Debugger {
+
+ /**
+ * Set to true if fatal error occured
+ *
+ * @var bool
+ */
+ var $IsFatalError = false;
+
+ /**
+ * Debugger data for building report
+ *
+ * @var Array
+ */
+ var $Data = Array();
+
+ var $ProfilerData = Array();
+ var $ProfilerTotals = Array();
+ var $ProfilerTotalCount = Array();
+
+ /**
+ * Prevent recursion when processing debug_backtrace() function results
+ *
+ * @var Array
+ */
+ var $RecursionStack = Array();
+
+ var $scrollbarWidth = 0;
+
+ /**
+ * Long errors are saved here, because trigger_error doesn't support error messages over 1KB in size
+ *
+ * @var Array
+ */
+ var $longErrors = Array();
+
+ var $IncludesData = Array();
+ var $IncludeLevel = 0;
+
+ var $reportDone = false;
+
+ /**
+ * Transparent spacer image used in case of none spacer image defined via SPACER_URL contant.
+ * Used while drawing progress bars (memory usage, time usage, etc.)
+ *
+ * @var string
+ */
+ var $dummyImage = '';
+
+ /**
+ * Temporary files created by debugger will be stored here
+ *
+ * @var string
+ */
+ var $tempFolder = '';
+
+ /**
+ * Debug rows will be separated using this string before writing to debug file
+ *
+ * @var string
+ */
+ var $rowSeparator = '@@';
+
+ /**
+ * Base URL for debugger includes
+ *
+ * @var string
+ */
+ var $baseURL = '';
+
+ function Debugger()
+ {
+ global $start, $dbg_options;
+ // check if user haven't defined DEBUG_MODE contant directly
+ if (defined('DEBUG_MODE') && DEBUG_MODE) {
+ die('error: contant DEBUG_MODE defined directly, please use <strong>$dbg_options</strong> array instead');
+ }
+
+ // check IP before enabling debug mode
+ $ip_match = $this->ipMatch(isset($dbg_options['DBG_IP']) ? $dbg_options['DBG_IP'] : '');
+
+ if (!$ip_match) {
+ define('DEBUG_MODE', 0);
+ return ;
+ }
+
+ // debug is allowed for user, continue initialization
+ $this->InitDebugger();
+ $this->profileStart('kernel4_startup', 'Startup and Initialization of kernel4', $start);
+ $this->profileStart('script_runtime', 'Script runtime', $start);
+
+ error_reporting(E_ALL);
+ ini_set('display_errors', $this->constOn('DBG_ZEND_PRESENT') ? 0 : 1); // show errors on screen in case if not in Zend Studio debugging
+
+ $this->scrollbarWidth = $this->isGecko() ? 22 : 25; // vertical scrollbar width differs in Firefox and other browsers
+ $this->appendRequest();
+ }
+
+ /**
+ * Checks, that user IP address is within allowed range
+ *
+ * @param string $ip_list semi-column (by default) separated ip address list
+ * @param string $separator ip address separator (default ";")
+ *
+ * @return bool
+ */
+ function ipMatch($ip_list, $separator = ';')
+ {
+ $ip_match = false;
+ $ip_addresses = $ip_list ? explode($separator, $ip_list) : Array ();
+ foreach ($ip_addresses as $ip_address) {
+ if ($this->netMatch($ip_address, $_SERVER['REMOTE_ADDR'])) {
+ $ip_match = true;
+ break;
+ }
+ }
+
+ return $ip_match;
+ }
+
+ /**
+ * Set's default values to constants debugger uses
+ *
+ */
+ function InitDebugger()
+ {
+ global $dbg_options;
+
+ unset($_REQUEST['debug_host'], $_REQUEST['debug_fastfile'], $dbg_options['DBG_IP']); // this var messed up whole detection stuff :(
+
+ // Detect fact, that this session beeing debugged by Zend Studio
+ foreach ($_REQUEST as $rq_name => $rq_value) {
+ if (substr($rq_name, 0, 6) == 'debug_') {
+ $this->safeDefine('DBG_ZEND_PRESENT', 1);
+ break;
+ }
+ }
+
+ $this->safeDefine('DBG_ZEND_PRESENT', 0); // set this constant value to 0 (zero) to debug debugger using Zend Studio
+
+ // set default values for debugger constants
+ $dbg_constMap = Array(
+ 'DBG_USE_HIGHLIGHT' => 1, // highlight output same as php code using "highlight_string" function
+ 'DBG_WINDOW_WIDTH' => 700, // set width of debugger window (in pixels) for better viewing large amount of debug data
+ 'DBG_USE_SHUTDOWN_FUNC' => DBG_ZEND_PRESENT ? 0 : 1, // use shutdown function to include debugger code into output
+ 'DBG_HANDLE_ERRORS' => DBG_ZEND_PRESENT ? 0 : 1, // handle all allowed by php (see php manual) errors instead of default handler
+ 'DBG_IGNORE_STRICT_ERRORS' => 1, // ignore PHP5 errors about private/public view modified missing in class declarations
+ 'DBG_DOMVIEWER' => '/temp/domviewer.html', // path to DOMViewer on website
+ 'DOC_ROOT' => str_replace('\\', '/', realpath($_SERVER['DOCUMENT_ROOT']) ), // windows hack
+ 'DBG_LOCAL_BASE_PATH' => 'w:', // replace DOC_ROOT in filenames (in errors) using this path
+ );
+
+ // only for IE, in case if no windows php script editor defined
+ if (!defined('DBG_EDITOR')) {
+// $dbg_constMap['DBG_EDITOR'] = 'c:\Program Files\UltraEdit\uedit32.exe %F/%L';
+ $dbg_constMap['DBG_EDITOR'] = 'c:\Program Files\Zend\ZendStudio-5.2.0\bin\ZDE.exe %F';
+ }
+
+ if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] && constOn('DBG_SKIP_AJAX')) {
+ $this->safeDefine('DBG_SKIP_REPORTING', 1);
+ }
+
+ // user defined options override debugger defaults
+ $dbg_constMap = $this->array_merge_recursive2($dbg_constMap, $dbg_options);
+
+ foreach ($dbg_constMap as $dbg_constName => $dbg_constValue) {
+ $this->safeDefine($dbg_constName, $dbg_constValue);
+ }
+ }
+
+ function constOn($const_name)
+ {
+ return defined($const_name) && constant($const_name);
+ }
+
+ function safeDefine($const_name, $const_value) {
+ if (!defined($const_name)) {
+ define($const_name, $const_value);
+ }
+ }
+
+ function array_merge_recursive2($paArray1, $paArray2)
+ {
+ if (!is_array($paArray1) or !is_array($paArray2)) {
+ return $paArray2;
+ }
+
+ foreach ($paArray2 AS $sKey2 => $sValue2) {
+ $paArray1[$sKey2] = isset($paArray1[$sKey2]) ? array_merge_recursive2($paArray1[$sKey2], $sValue2) : $sValue2;
+ }
+
+ return $paArray1;
+ }
+
+ function netMatch($network, $ip) {
+
+ $network = trim($network);
+ $ip = trim($ip);
+
+ if ($network == $ip) {
+ // comparing 2 ip addresses directly
+ return true;
+ }
+
+ $d = strpos($network, '-');
+ if ($d === false) {
+ // sigle subnet specified
+ $ip_arr = explode('/', $network);
+
+ if (!preg_match("@\d*\.\d*\.\d*\.\d*@", $ip_arr[0], $matches)) {
+ $ip_arr[0] .= '.0'; // Alternate form 194.1.4/24
+ }
+
+ $network_long = ip2long($ip_arr[0]);
+ $x = ip2long($ip_arr[1]);
+
+ $mask = long2ip($x) == $ip_arr[1] ? $x : (0xffffffff << (32 - $ip_arr[1]));
+ $ip_long = ip2long($ip);
+
+ return ($ip_long & $mask) == ($network_long & $mask);
+ }
+ else {
+ // ip address range specified
+ $from = ip2long(trim(substr($network, 0, $d)));
+ $to = ip2long(trim(substr($network, $d + 1)));
+
+ $ip = ip2long($ip);
+ return ($ip >= $from && $ip <= $to);
+ }
+ }
+
+ function InitReport()
+ {
+ if (!class_exists('kApplication')) return false;
+
+ $application =& kApplication::Instance();
+
+ // string used to separate debugger records while in file (used in debugger dump filename too)
+ $this->rowSeparator = '@'.(is_object($application->Factory) ? $application->GetSID() : 0).'@';
+
+ // include debugger files from this url
+ $reg_exp = '/^'.preg_quote(FULL_PATH, '/').'/';
+ $kernel_path = preg_replace($reg_exp, '', KERNEL_PATH, 1);
+ $this->baseURL = PROTOCOL.SERVER_NAME.rtrim(BASE_PATH, '/').$kernel_path.'/utility/debugger';
+
+ // save debug output in this folder
+ $this->tempFolder = defined('WRITEABLE') ? WRITEABLE.'/cache' : FULL_PATH.'/kernel/cache';
+ }
+
+ function mapLongError($msg)
+ {
+ $key = $this->generateID();
+ $this->longErrors[$key] = $msg;
+ return $key;
+ }
+
+ /**
+ * Appends all passed variable values (wihout variable names) to debug output
+ *
+ */
+ function dumpVars()
+ {
+ $dump_mode = 'var_dump';
+ $dumpVars = func_get_args();
+
+ if ($dumpVars[count($dumpVars) - 1] === 'STRICT') {
+ $dump_mode = 'strict_var_dump';
+ array_pop($dumpVars);
+ }
+
+ foreach ($dumpVars as $varValue) {
+ $this->Data[] = Array('value' => $varValue, 'debug_type' => $dump_mode);
+ }
+
+ }
+
+ function prepareHTML($dataIndex)
+ {
+ $Data =& $this->Data[$dataIndex];
+ if ($Data['debug_type'] == 'html') {
+ return $Data['html'];
+ }
+
+ switch ($Data['debug_type']) {
+ case 'error':
+ $fileLink = $this->getFileLink($Data['file'], $Data['line']);
+ $ret = '<b class="debug_error">'.$this->getErrorNameByCode($Data['no']).'</b>: '.$Data['str'];
+ $ret .= ' in <b>'.$fileLink.'</b> on line <b>'.$Data['line'].'</b>';
+ return $ret;
+ break;
+
+ case 'var_dump':
+ return $this->highlightString( $this->print_r($Data['value'], true) );
+ break;
+
+ case 'strict_var_dump':
+ return $this->highlightString( var_export($Data['value'], true) );
+ break;
+
+ case 'trace':
+ ini_set('memory_limit', '500M');
+ $trace =& $Data['trace'];
+
+ $i = 0; $traceCount = count($trace);
+ $ret = '';
+ while ($i < $traceCount) {
+ $traceRec =& $trace[$i];
+ $argsID = 'trace_args_'.$dataIndex.'_'.$i;
+
+ $has_args = isset($traceRec['args']);
+
+ if (isset($traceRec['file'])) {
+ $func_name = isset($traceRec['class']) ? $traceRec['class'].$traceRec['type'].$traceRec['function'] : $traceRec['function'];
+ $args_link = $has_args ? '<a href="javascript:$Debugger.ToggleTraceArgs(\''.$argsID.'\');" title="Show/Hide Function Arguments"><b>Function</b></a>' : '<b>Function</b>';
+
+ $ret .= $args_link.': '.$this->getFileLink($traceRec['file'], $traceRec['line'], $func_name);
+ $ret .= ' in <b>'.basename($traceRec['file']).'</b> on line <b>'.$traceRec['line'].'</b><br>';
+ }
+ else {
+ $ret .= 'no file information available';
+ }
+
+ if ($has_args) {
+ // if parameter value is longer then 200 symbols, then leave only first 50
+ $args = $this->highlightString($this->print_r($traceRec['args'], true, 50, 200));
+ $ret .= '<div id="'.$argsID.'" style="display: none;">'.$args.'</div>';
+ }
+ $i++;
+ }
+ return $ret;
+ break;
+
+ case 'profiler':
+ $profileKey = $Data['profile_key'];
+ $Data =& $this->ProfilerData[$profileKey];
+ $runtime = ($Data['ends'] - $Data['begins']); // in seconds
+
+ $totals_key = getArrayValue($Data, 'totalsKey');
+ if ($totals_key) {
+ $total_before = $Data['totalsBefore'];
+ $total = $this->ProfilerTotals[$totals_key];
+
+ $div_width = Array();
+ $total_width = ($this->getWindowWidth()-10);
+ $div_width['before'] = round(($total_before / $total) * $total_width);
+ $div_width['current'] = round(($runtime / $total) * $total_width);
+ $div_width['left'] = round((($total - $total_before - $runtime) / $total) * $total_width);
+
+ $ret = '<b>Name</b>: '.$Data['description'].'<br />';
+
+ if (isset($Data['file'])) {
+ $ret .= '[<b>Runtime</b>: '.$runtime.'s] [<b>File</b>: '.$this->getFileLink($Data['file'], $Data['line'], basename($Data['file']).':'.$Data['line']).']<br />';
+ }
+ else {
+ $ret .= '<b>Runtime</b>: '.$runtime.'s<br />';
+ }
+
+ $ret .= '<div class="dbg_profiler" style="width: '.$div_width['before'].'px; border-right: 0px; background-color: #298DDF;"><img src="'.$this->dummyImage.'" width="1" height="1"/></div>';
+ $ret .= '<div class="dbg_profiler" style="width: '.$div_width['current'].'px; border-left: 0px; border-right: 0px; background-color: #EF4A4A;"><img src="'.$this->dummyImage.'" width="1" height="1"/></div>';
+ $ret .= '<div class="dbg_profiler" style="width: '.$div_width['left'].'px; border-left: 0px; background-color: #DFDFDF;"><img src="'.$this->dummyImage.'" width="1" height="1"/></div>';
+
+ return $ret;
+ }
+ else {
+ return '<b>Name</b>: '.$Data['description'].'<br><b>Runtime</b>: '.$runtime.'s';
+ }
+ break;
+
+ default:
+ return 'incorrect debug data';
+ break;
+ }
+ }
+
+ function getWindowWidth()
+ {
+ return DBG_WINDOW_WIDTH - $this->scrollbarWidth - 8;
+ }
+
+ /**
+ * Tells debugger to skip objects that are heavy in plan of memory usage while printing debug_backtrace results
+ *
+ * @param Object $object
+ * @return bool
+ */
+ function IsBigObject(&$object)
+ {
+ $skip_classes = Array(
+ defined('APPLICATION_CLASS') ? APPLICATION_CLASS : 'kApplication',
+ 'kFactory',
+ 'kUnitConfigReader',
+ 'TemplateParser',
+ );
+
+ foreach ($skip_classes as $class_name) {
+ if (strtolower(get_class($object)) == strtolower($class_name)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Advanced version of print_r (for debugger only). Don't print objects recursively
+ *
+ * @param Array $array
+ * @param bool $return_output return output or print it out
+ * @param int $cut_first cut first N symbols, don't cut anything if -1 specified
+ * @package int $cut_min_length cut only of this length of string or greather
+ * @return string
+ */
+ function print_r(&$array, $return_output = false, $cut_first = -1, $cut_min_length = -1)
+ {
+ static $first_line = true, $tab_count = -1;
+
+ if (is_null($array)) {
+ return 'NULL';
+ }
+ elseif (!is_array($array)) {
+ if ($cut_min_length != -1 && strlen($array) > $cut_min_length) {
+ $array = substr($array, 0, $cut_first).' ...';
+ }
+ return $array;
+ }
+
+ $output = '';
+
+ $tab_count++;
+ $output .= "Array\n".str_repeat(' ', $tab_count)."(\n";
+
+ $tab_count++;
+ $tabsign = $tab_count ? str_repeat(' ', $tab_count) : '';
+
+ $array_keys = array_keys($array);
+
+ foreach ($array_keys as $key) {
+ switch (gettype($array[$key])) {
+ case 'array':
+ $output .= $tabsign.'['.$key.'] = '.$this->print_r($array[$key], true, 50, 200);
+ break;
+
+ case 'boolean':
+ $output .= $tabsign.'['.$key.'] = '.($array[$key] ? 'true' : 'false')."\n";
+ break;
+
+ case 'integer':
+ case 'double':
+ case 'string':
+ if ($cut_min_length != -1 && strlen($array[$key]) > $cut_min_length) {
+ $array[$key] = substr($array[$key], 0, $cut_first).' ...';
+ }
+ $output .= $tabsign.'['.$key.'] = '.$array[$key]."\n";
+ break;
+
+ case 'NULL':
+ $output .= $tabsign.'['.$key."] = NULL\n";
+ break;
+
+ case 'object':
+ $attribute_names = get_class_vars( get_class($array[$key]) );
+ if (!$attribute_names) {
+ $output .= $tabsign.'['.$key."] = NO_ATTRIBUTES\n";
+ }
+ else {
+ if ($this->IsBigObject($array[$key])) {
+ $output .= $tabsign.'['.$key.'] = SKIPPED (class: '.get_class($array[$key]).")\n";
+ break;
+ }
+
+ // $attribute_value - default value for this attribute, not used here
+ foreach ($attribute_names as $attribute_name => $attribute_value) {
+ if (is_object($array[$key]->$attribute_name)) {
+ // it is object
+ $object_class = get_class($array[$key]->$attribute_name);
+ if (!in_array($object_class, $this->RecursionStack)) {
+ // object [not in recursion stack]
+ if ($this->IsBigObject($array[$key]->$attribute_name)) {
+ $output .= $tabsign.'['.$attribute_name.'] = SKIPPED (class: '.$object_class.")\n";
+ continue;
+ }
+
+ array_push($this->RecursionStack, $object_class);
+ $output .= $this->print_r($array[$key]->$attribute_name, true, 50, 200);
+ array_pop($this->RecursionStack);
+ }
+ else {
+ // object [in recursion stack]
+ $output .= $tabsign.'['.$attribute_name.'] = *** RECURSION *** (class: '.$object_class.")\n";
+ }
+ }
+ else {
+ $output .= $tabsign.'['.$attribute_name.'] = '.$this->print_r($array[$key]->$attribute_name, true, 50, 200)."\n";
+ }
+ }
+ }
+ break;
+
+ default:
+ $output .= $tabsign.'['.$key.'] unknown = '.gettype($array[$key])."\n";
+ break;
+ }
+ }
+
+ $tab_count--;
+ $output .= str_repeat(' ', $tab_count).")\n";
+
+ if ($first_line) {
+ $first_line = false;
+ $output .= "\n";
+ }
+
+ $tab_count--;
+
+ if ($return_output) {
+ return $output;
+ }
+ else {
+ echo $output;
+ }
+
+ return true;
+ }
+
+ /**
+ * Returns only first 200 chars of string, this allow to save amount of data sent to browser
+ *
+ * @param string $string
+ * @return string
+ */
+ function cutStringForHTML($string)
+ {
+ if (strlen($string) > 200) {
+ $string = substr($string,0,50).' ...';
+ }
+ return $string;
+ }
+
+ /**
+ * Format SQL Query using predefined formatting
+ * and highlighting techniques
+ *
+ * @param string $sql
+ * @return string
+ */
+ function formatSQL($sql)
+ {
+ $sql = preg_replace('/(\n|\t| )+/is', ' ', $sql);
+ $sql = preg_replace('/(CREATE TABLE|DROP TABLE|SELECT|UPDATE|SET|REPLACE|INSERT|DELETE|VALUES|FROM|LEFT JOIN|INNER JOIN|LIMIT|WHERE|HAVING|GROUP BY|ORDER BY) /is', "\n\t$1 ", $sql);
+ return $this->highlightString($sql);
+ }
+
+ function highlightString($string)
+ {
+ if (!$this->constOn('DBG_USE_HIGHLIGHT')) {
+ return $string;
+ }
+
+ $string = str_replace( Array('\\', '/') , Array('_no_match_string_', '_n_m_s_'), $string);
+ $string = highlight_string('<?php'.$string.'?>', true);
+ $string = str_replace( Array('_no_match_string_', '_n_m_s_'), Array('\\', '/'), $string);
+ return preg_replace('/&lt;\?(.*)php(.*)\?&gt;/Us', '\\2', $string);
+ }
+
+ /**
+ * Determine by php type of browser used to show debugger
+ *
+ * @return bool
+ */
+ function isGecko()
+ {
+ return strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'firefox') !== false;
+ }
+
+ /**
+ * Returns link for editing php file (from error) in external editor
+ *
+ * @param string $file filename with path from root folder
+ * @param int $lineno line number in file where error is found
+ * @param string $title text to show on file edit link
+ * @return string
+ */
+ function getFileLink($file, $lineno = 1, $title = '')
+ {
+ if (!$title) {
+ $title = str_replace('/', '\\', $this->getLocalFile($file));
+ }
+
+ if ($this->isGecko()) {
+ return '<a href="file://'.$this->getLocalFile($file).'">'.$title.'</a>';
+ }
+ else {
+ return '<a href="javascript:$Debugger.editFile(\''.$this->getLocalFile($file).'\', '.$lineno.');" title="'.$file.'">'.$title.'</a>';
+ }
+
+ }
+
+ /**
+ * Converts filepath on server to filepath in mapped DocumentRoot on developer pc
+ *
+ * @param string $remoteFile
+ * @return string
+ */
+ function getLocalFile($remoteFile)
+ {
+ return preg_replace('/^'.preg_quote(DOC_ROOT, '/').'/', DBG_LOCAL_BASE_PATH, $remoteFile, 1);
+ }
+
+ /**
+ * Appends call trace till this method call
+ *
+ */
+ function appendTrace()
+ {
+ $trace = debug_backtrace();
+ array_shift($trace);
+
+ $this->Data[] = Array('trace' => $trace, 'debug_type' => 'trace');
+ }
+
+ function appendMemoryUsage($msg, $used = null)
+ {
+ if (!isset($used)) {
+ $used = round(memory_get_usage() / 1024);
+ }
+ $this->appendHTML('<b>Memory usage</b> '.$msg.' '.$used.'Kb');
+ }
+
+ /**
+ * Appends HTML code whithout transformations
+ *
+ * @param string $html
+ */
+ function appendHTML($html)
+ {
+ $this->Data[] = Array('html' => $html, 'debug_type' => 'html');
+ }
+
+ /**
+ * Change debugger info that was already generated before.
+ * Returns true if html was set.
+ *
+ * @param int $index
+ * @param string $html
+ * @param string $type = {'append','prepend','replace'}
+ * @return bool
+ */
+ function setHTMLByIndex($index, $html, $type = 'append')
+ {
+ if (!isset($this->Data[$index]) || $this->Data[$index]['debug_type'] != 'html') {
+ return false;
+ }
+
+ switch ($type) {
+ case 'append':
+ $this->Data[$index]['html'] .= '<br>'.$html;
+ break;
+
+ case 'prepend':
+ $this->Data[$index]['html'] = $this->Data[$index]['html'].'<br>'.$html;
+ break;
+
+ case 'replace':
+ $this->Data[$index]['html'] = $html;
+ break;
+ }
+ return true;
+ }
+
+ /**
+ * Move $debugLineCount lines of input from debug output
+ * end to beginning.
+ *
+ * @param int $debugLineCount
+ */
+ function moveToBegin($debugLineCount)
+ {
+ $lines = array_splice($this->Data,count($this->Data)-$debugLineCount,$debugLineCount);
+ $this->Data = array_merge($lines,$this->Data);
+ }
+
+ function moveAfterRow($new_row, $debugLineCount)
+ {
+ $lines = array_splice($this->Data,count($this->Data)-$debugLineCount,$debugLineCount);
+ $rows_before = array_splice($this->Data,0,$new_row,$lines);
+ $this->Data = array_merge($rows_before,$this->Data);
+ }
+
+ function appendRequest()
+ {
+ if (isset($_SERVER['SCRIPT_FILENAME'])) {
+ $script = $_SERVER['SCRIPT_FILENAME'];
+ }
+ else {
+ $script = $_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF'];
+ }
+
+ $this->appendHTML('ScriptName: <b>'.$this->getFileLink($script, 1, basename($script)).'</b> (<b>'.dirname($script).'</b>)');
+ if (isset($_REQUEST['ajax']) && $_REQUEST['ajax'] == 'yes') {
+ $this->appendHTML('RequestURI: '.$_SERVER['REQUEST_URI'].' (QS Length:'.strlen($_SERVER['QUERY_STRING']).')');
+ }
+ $this->appendHTML('<a href="http://www.brainjar.com/dhtml/domviewer/" target="_blank">DomViewer</a>: <input id="dbg_domviewer" type="text" value="window" style="border: 1px solid #000000;"/>&nbsp;<button class="button" onclick="return $Debugger.OpenDOMViewer();">Show</button>');
+
+ ob_start();
+ ?>
+ <table border="0" cellspacing="0" cellpadding="0" class="dbg_flat_table" style="width: <?php echo $this->getWindowWidth(); ?>px;">
+ <thead style="font-weight: bold;">
+ <td width="20">Src</td><td>Name</td><td>Value</td>
+ </thead>
+ <?php
+ foreach ($_REQUEST as $key => $value) {
+ if(!is_array($value) && trim($value) == '') {
+ $value = '<b class="debug_error">no value</b>';
+ }
+ else {
+ $value = htmlspecialchars($this->print_r($value, true));
+ }
+
+ $in_cookie = isset($_COOKIE[$key]);
+ $src = isset($_GET[$key]) && !$in_cookie ? 'GE' : (isset($_POST[$key]) && !$in_cookie ? 'PO' : ($in_cookie ? 'CO' : '?') );
+ echo '<tr><td>'.$src.'</td><td>'.$key.'</td><td>'.$value.'</td></tr>';
+ }
+ ?>
+ </table>
+ <?php
+ $this->appendHTML(ob_get_contents());
+ ob_end_clean();
+ }
+
+ /**
+ * Appends php session content to debugger output
+ *
+ */
+ function appendSession()
+ {
+ if (isset($_SESSION) && $_SESSION) {
+ $this->appendHTML('PHP Session: [<b>'.ini_get('session.name').'</b>]');
+ $this->dumpVars($_SESSION);
+ $this->moveToBegin(2);
+ }
+ }
+
+ function profileStart($key, $description = null, $timeStamp = null)
+ {
+ if (!isset($timeStamp)) {
+ $timeStamp = $this->getMoment();
+ }
+ $this->ProfilerData[$key] = Array('begins' => $timeStamp, 'ends' => 5000, 'debuggerRowID' => count($this->Data));
+ if (isset($description)) {
+ $this->ProfilerData[$key]['description'] = $description;
+ }
+
+ if (substr($key, 0, 4) == 'sql_') {
+ // append place from what was called
+ $trace_results = debug_backtrace();
+ $trace_count = count($trace_results);
+ $i = 0;
+ while ($i < $trace_count) {
+ $trace_file = basename($trace_results[$i]['file']);
+ if ($trace_file != 'db_connection.php' && $trace_file != 'adodb.inc.php') {
+ break;
+ }
+ $i++;
+ }
+ $this->ProfilerData[$key]['file'] = $trace_results[$i]['file'];
+ $this->ProfilerData[$key]['line'] = $trace_results[$i]['line'];
+ unset($trace_results);
+ }
+
+ $this->Data[] = Array('profile_key' => $key, 'debug_type' => 'profiler');
+ }
+
+ function profileFinish($key, $description = null, $timeStamp = null)
+ {
+ if (!isset($timeStamp)) {
+ $timeStamp = $this->getMoment();
+ }
+ $this->ProfilerData[$key]['ends'] = $timeStamp;
+
+ if (isset($description)) {
+ $this->ProfilerData[$key]['description'] = $description;
+ }
+ }
+
+ function profilerAddTotal($total_key, $key = null, $value = null)
+ {
+ if (!isset($this->ProfilerTotals[$total_key])) {
+ $this->ProfilerTotals[$total_key] = 0;
+ $this->ProfilerTotalCount[$total_key] = 0;
+ }
+
+ if (!isset($value)) {
+ $value = $this->ProfilerData[$key]['ends'] - $this->ProfilerData[$key]['begins'];
+ }
+
+ if (isset($key)) {
+ $this->ProfilerData[$key]['totalsKey'] = $total_key;
+ $this->ProfilerData[$key]['totalsBefore'] = $this->ProfilerTotals[$total_key];
+ }
+
+ $this->ProfilerTotals[$total_key] += $value;
+ $this->ProfilerTotalCount[$total_key]++;
+ }
+
+ function getMoment()
+ {
+ list($usec, $sec) = explode(' ', microtime());
+ return ((float)$usec + (float)$sec);
+ }
+
+ function generateID()
+ {
+ list($usec, $sec) = explode(' ', microtime());
+
+ $id_part_1 = substr($usec, 4, 4);
+ $id_part_2 = mt_rand(1,9);
+ $id_part_3 = substr($sec, 6, 4);
+ $digit_one = substr($id_part_1, 0, 1);
+ if ($digit_one == 0) {
+ $digit_one = mt_rand(1,9);
+ $id_part_1 = ereg_replace("^0",'',$id_part_1);
+ $id_part_1=$digit_one.$id_part_1;
+ }
+ return $id_part_1.$id_part_2.$id_part_3;
+ }
+
+
+ function getErrorNameByCode($error_code)
+ {
+ $error_map = Array(
+ 'Fatal Error' => Array(E_USER_ERROR),
+ 'Warning' => Array(E_WARNING, E_USER_WARNING),
+ 'Notice' => Array(E_NOTICE, E_USER_NOTICE),
+ );
+
+ if (defined('E_STRICT')) {
+ $error_map['PHP5 Strict'] = Array(E_STRICT);
+ }
+
+ foreach ($error_map as $error_name => $error_codes) {
+ if (in_array($error_code, $error_codes)) {
+ return $error_name;
+ }
+ }
+
+ return '';
+ }
+
+ /**
+ * Returns profile total key (check against unexisting key too)
+ *
+ * @param string $key
+ * @return int
+ */
+ function getProfilerTotal($key)
+ {
+ if (isset($this->ProfilerTotalCount[$key])) {
+ return (int)$this->ProfilerTotalCount[$key];
+ }
+ return 0;
+ }
+
+ /**
+ * Generates report
+ *
+ */
+ function printReport($returnResult = false, $clean_output_buffer = true)
+ {
+ if ($this->reportDone) {
+ // don't print same report twice (in case if shutdown function used + compression + fatal error)
+ return '';
+ }
+
+ $this->profileFinish('script_runtime');
+ $this->breakOutofBuffering();
+
+ $debugger_start = memory_get_usage();
+
+ if (defined('SPACER_URL')) {
+ $this->dummyImage = SPACER_URL;
+ }
+
+ $this->InitReport(); // set parameters required by AJAX
+
+ // defined here, because user can define this contant while script is running, not event before debugger is started
+ $this->safeDefine('DBG_RAISE_ON_WARNINGS', 0);
+ $this->safeDefine('DBG_TOOLBAR_BUTTONS', 1);
+
+ $this->appendSession(); // show php session if any
+
+ // ensure, that 1st line of debug output always is this one:
+ $top_line = '<table cellspacing="0" cellpadding="0" style="width: '.$this->getWindowWidth().'px; margin: 0px;"><tr><td align="left" width="50%">[<a href="javascript:window.location.reload();">Reload Frame</a>] [<a href="javascript:$Debugger.Toggle(27);">Hide Debugger</a>]</td><td align="right" width="50%">[Current Time: <b>'.date('H:i:s').'</b>] [File Size: <b>#DBG_FILESIZE#</b>]</td></tr></table>';
+
+ $this->appendHTML($top_line);
+ $this->moveToBegin(1);
+
+ if ($this->constOn('DBG_SQL_PROFILE') && isset($this->ProfilerTotals['sql'])) {
+ // sql query profiling was enabled -> show totals
+ $this->appendHTML('<b>SQL Total time:</b> '.$this->ProfilerTotals['sql'].' <b>Number of queries</b>: '.$this->ProfilerTotalCount['sql']);
+ }
+
+ if ($this->constOn('DBG_PROFILE_INCLUDES') && isset($this->ProfilerTotals['includes'])) {
+ // included file profiling was enabled -> show totals
+ $this->appendHTML('<b>Included Files Total time:</b> '.$this->ProfilerTotals['includes'].' Number of includes: '.$this->ProfilerTotalCount['includes']);
+ }
+
+ if ($this->constOn('DBG_PROFILE_MEMORY')) {
+ // detailed memory usage reporting by objects was enabled -> show totals
+ $this->appendHTML('<b>Memory used by Objects:</b> '.round($this->ProfilerTotals['objects'] / 1024, 2).'Kb');
+ }
+
+ if ($this->constOn('DBG_INCLUDED_FILES')) {
+ $files = get_included_files();
+ $this->appendHTML('<b>Included files:</b>');
+ foreach ($files as $file) {
+ $this->appendHTML($this->getFileLink($this->getLocalFile($file)).' ('.round(filesize($file) / 1024, 2).'Kb)');
+ }
+ }
+
+ /*if ($this->constOn('DBG_PROFILE_INCLUDES')) {
+ $this->appendHTML('<b>Included files statistics:</b>'.( $this->constOn('DBG_SORT_INCLUDES_MEM') ? ' (sorted by memory usage)':''));
+ $totals = Array( 'mem' => 0, 'time' => 0);
+ $totals_configs = Array( 'mem' => 0, 'time' => 0);
+ if (is_array($this->IncludesData['mem'])) {
+ if ( $this->constOn('DBG_SORT_INCLUDES_MEM') ) {
+ array_multisort($this->IncludesData['mem'], SORT_DESC, $this->IncludesData['file'], $this->IncludesData['time'], $this->IncludesData['level']);
+ }
+ foreach ($this->IncludesData['file'] as $key => $file_name) {
+ $this->appendHTML( str_repeat('&nbsp;->&nbsp;', ($this->IncludesData['level'][$key] >= 0 ? $this->IncludesData['level'][$key] : 0)).$file_name.' Mem: '.sprintf("%.4f Kb", $this->IncludesData['mem'][$key]/1024).' Time: '.sprintf("%.4f", $this->IncludesData['time'][$key]));
+ if ($this->IncludesData['level'][$key] == 0) {
+ $totals['mem'] += $this->IncludesData['mem'][$key];
+ $totals['time'] += $this->IncludesData['time'][$key];
+ }
+ else if ($this->IncludesData['level'][$key] == -1) {
+ $totals_configs['mem'] += $this->IncludesData['mem'][$key];
+ $totals_configs['time'] += $this->IncludesData['time'][$key];
+ }
+ }
+ $this->appendHTML('<b>Sub-Total classes:</b> '.' Mem: '.sprintf("%.4f Kb", $totals['mem']/1024).' Time: '.sprintf("%.4f", $totals['time']));
+ $this->appendHTML('<b>Sub-Total configs:</b> '.' Mem: '.sprintf("%.4f Kb", $totals_configs['mem']/1024).' Time: '.sprintf("%.4f", $totals_configs['time']));
+ $this->appendHTML('<span class="error"><b>Grand Total:</b></span> '.' Mem: '.sprintf("%.4f Kb", ($totals['mem']+$totals_configs['mem'])/1024).' Time: '.sprintf("%.4f", $totals['time']+$totals_configs['time']));
+ }
+ }*/
+
+ $is_ajax = isset($_GET['ajax']) && $_GET['ajax'] == 'yes';
+ $skip_reporting = $this->constOn('DBG_SKIP_REPORTING') || $this->constOn('DBG_ZEND_PRESENT');
+
+ if (($is_ajax && !constOn('DBG_SKIP_AJAX')) || !$skip_reporting) {
+ $debug_file = $this->tempFolder.'/debug_'.$this->rowSeparator.'.txt';
+ if (file_exists($debug_file)) unlink($debug_file);
+
+ $i = 0;
+ $fp = fopen($debug_file, 'a');
+ $lineCount = count($this->Data);
+ while ($i < $lineCount) {
+ fwrite($fp, $this->prepareHTML($i).$this->rowSeparator);
+ $i++;
+ }
+ fclose($fp);
+ }
+
+ if ($skip_reporting) {
+ // let debugger write report and then don't output anything
+ $this->reportDone = true;
+ return '';
+ }
+
+ $dbg_path = str_replace(FULL_PATH, '', $this->tempFolder);
+ ob_start();
+ ?>
+ <html><body></body></html>
+ <script type="text/javascript" src="<?php echo $this->baseURL; ?>/debugger.js"></script>
+ <link rel="stylesheet" rev="stylesheet" href="<?php echo $this->baseURL; ?>/debugger.css" type="text/css" media="screen" />
+ <div id="debug_layer" class="debug_layer_container" style="display: none; width: <?php echo DBG_WINDOW_WIDTH; ?>px;">
+ <div class="debug_layer" style="width: <?php echo $this->getWindowWidth(); ?>px;">
+ <table width="100%" cellpadding="0" cellspacing="1" border="0" class="debug_layer_table" style="width: <?php echo $this->getWindowWidth(); ?>px;" align="left">
+ <tbody id="debug_table"></tbody>
+ </table>
+ </div>
+ </div>
+
+ <script type="text/javascript">
+ var $Debugger = new Debugger(<?php echo "'".$this->rowSeparator."', ".$this->getProfilerTotal('error_handling').', '.($this->IsFatalError ? 'true' : 'false').', '.$this->getProfilerTotal('sql'); ?>);
+ $Debugger.DOMViewerURL = '<?php echo constant('DBG_DOMVIEWER'); ?>';
+ $Debugger.EditorPath = '<?php echo defined('DBG_EDITOR') ? addslashes(DBG_EDITOR) : '' ?>';
+ $Debugger.DebugURL = '<?php echo $this->baseURL.'/debugger_responce.php?sid='.$this->rowSeparator.'&path='.urlencode($dbg_path); ?>';
+
+ <?php
+ if ($this->IsFatalError || DBG_RAISE_ON_WARNINGS) {
+ echo '$Debugger.Toggle();';
+ }
+ if (DBG_TOOLBAR_BUTTONS) {
+ echo '$Debugger.AddToolbar("$Debugger");';
+ }
+ ?>
+ window.focus();
+ </script>
+ <?php
+ if (!isset($this->ProfilerTotals['error_handling'])) {
+ $memory_used = $debugger_start;
+ $this->ProfilerTotalCount['error_handling'] = 0;
+ }
+ else {
+ $memory_used = $debugger_start - $this->ProfilerTotals['error_handling'];
+ }
+
+ if ($returnResult) {
+ $ret = ob_get_contents();
+ if ($clean_output_buffer) {
+ ob_end_clean();
+ }
+ $ret .= $this->getShortReport($memory_used);
+
+ $this->reportDone = true;
+ return $ret;
+ }
+ else {
+ if (!$this->constOn('DBG_HIDE_FULL_REPORT')) {
+ $this->breakOutofBuffering();
+ }
+ elseif ($clean_output_buffer) {
+ ob_clean();
+ }
+ echo $this->getShortReport($memory_used);
+
+ $this->reportDone = true;
+ }
+ }
+
+ /**
+ * Format's memory usage report by debugger
+ *
+ * @return string
+ * @access private
+ */
+ function getShortReport($memory_used)
+ {
+ if ($this->constOn('DBG_TOOLBAR_BUTTONS')) {
+ // we have sql & error count in toolbar, don't duplicate here
+ $info = Array(
+ 'Script Runtime' => 'PROFILE:script_runtime',
+ );
+ }
+ else {
+ // toolbar not visible, then show sql & error count too
+ $info = Array (
+ 'Script Runtime' => 'PROFILE:script_runtime',
+ '-' => 'SEP:-',
+ 'Notice / Warning' => 'PROFILE_TC:error_handling',
+ 'SQLs Count' => 'PROFILE_TC:sql',
+ );
+ }
+
+ $ret = '<tr><td>Application:</td><td><b>'.$this->formatSize($memory_used).'</b> ('.$memory_used.')</td></tr>';
+ foreach ($info as $title => $value_key) {
+ list ($record_type, $record_data) = explode(':', $value_key, 2);
+ switch ($record_type) {
+ case 'PROFILE': // profiler totals value
+ $Data =& $this->ProfilerData[$record_data];
+ $profile_time = ($Data['ends'] - $Data['begins']); // in seconds
+ $ret .= '<tr><td>'.$title.':</td><td><b>'.sprintf('%.5f', $profile_time).' s</b></td></tr>';
+ break;
+
+ case 'PROFILE_TC': // profile totals record count
+ $record_cell = '<td>';
+ if ($record_data == 'error_handling' && $this->ProfilerTotalCount[$record_data] > 0) {
+ $record_cell = '<td class="debug_error">';
+ }
+ $ret .= '<tr>'.$record_cell.$title.':</td>'.$record_cell.'<b>'.$this->ProfilerTotalCount[$record_data].'</b></td></tr>';
+ break;
+
+ case 'SEP':
+ $ret .= '<tr><td colspan="2" style="height: 1px; background-color: #000000; padding: 0px;"><img src="'.$this->dummyImage.'" height="1" alt=""/></td></tr>';
+ break;
+ }
+ }
+
+ return '<br /><table class="dbg_stats_table"><tr><td style="border-color: #FFFFFF;"><table class="dbg_stats_table" align="left">'.$ret.'</table></td></tr></table>';
+ }
+
+ /**
+ * User-defined error handler
+ *
+ * @param int $errno
+ * @param string $errstr
+ * @param string $errfile
+ * @param int $errline
+ * @param array $errcontext
+ */
+ function saveError($errno, $errstr, $errfile = '', $errline = '', $errcontext = '')
+ {
+ $this->ProfilerData['error_handling']['begins'] = memory_get_usage();
+
+ $errorType = $this->getErrorNameByCode($errno);
+ if (!$errorType) {
+ trigger_error('Unknown error type ['.$errno.']', E_USER_ERROR);
+ return false;
+ }
+
+ if ($this->constOn('DBG_IGNORE_STRICT_ERRORS') && defined('E_STRICT') && ($errno == E_STRICT)) return;
+
+ if (preg_match('/(.*)#([\d]+)$/', $errstr, $rets) ) {
+ // replace short message with long one (due triger_error limitations on message size)
+ $long_id = $rets[2];
+ $errstr = $this->longErrors[$long_id];
+ unset($this->longErrors[$long_id]);
+ }
+
+ if (strpos($errfile,'eval()\'d code') !== false) {
+ $errstr = '[<b>EVAL</b>, line <b>'.$errline.'</b>]: '.$errstr;
+ $tmpStr = $errfile;
+ $pos = strpos($tmpStr,'(');
+ $errfile = substr($tmpStr, 0, $pos);
+ $pos++;
+ $errline = substr($tmpStr,$pos,strpos($tmpStr,')',$pos)-$pos);
+ }
+
+ $this->Data[] = Array('no' => $errno, 'str' => $errstr, 'file' => $errfile, 'line' => $errline, 'context' => $errcontext, 'debug_type' => 'error');
+ $this->ProfilerData['error_handling']['ends'] = memory_get_usage();
+ $this->profilerAddTotal('error_handling', 'error_handling');
+ if (substr($errorType, 0, 5) == 'Fatal') {
+ $this->IsFatalError = true;
+ // append debugger report to data in buffer & clean buffer afterwards
+ die( $this->breakOutofBuffering(false) . $this->printReport(true) );
+ }
+ }
+
+ function breakOutofBuffering($flush = true)
+ {
+ $buffer_content = Array();
+ while (ob_get_level()) {
+ $buffer_content[] = ob_get_clean();
+ }
+ $ret = implode('', array_reverse($buffer_content));
+ if ($flush) {
+ echo $ret;
+ flush();
+ }
+ return $ret;
+ }
+
+ function saveToFile($msg)
+ {
+ $fp = fopen($_SERVER['DOCUMENT_ROOT'].'/vb_debug.txt', 'a');
+ fwrite($fp, $msg."\n");
+ fclose($fp);
+ }
+
+ /**
+ * Formats file/memory size in nice way
+ *
+ * @param int $bytes
+ * @return string
+ * @access public
+ */
+ function formatSize($bytes)
+ {
+ if ($bytes >= 1099511627776) {
+ $return = round($bytes / 1024 / 1024 / 1024 / 1024, 2);
+ $suffix = "TB";
+ } elseif ($bytes >= 1073741824) {
+ $return = round($bytes / 1024 / 1024 / 1024, 2);
+ $suffix = "GB";
+ } elseif ($bytes >= 1048576) {
+ $return = round($bytes / 1024 / 1024, 2);
+ $suffix = "MB";
+ } elseif ($bytes >= 1024) {
+ $return = round($bytes / 1024, 2);
+ $suffix = "KB";
+ } else {
+ $return = $bytes;
+ $suffix = "Byte";
+ }
+ $return .= ' '.$suffix;
+ return $return;
+ }
+
+ function printConstants($constants)
+ {
+ if (!is_array($constants)) {
+ $constants = explode(',', $constants);
+ }
+ $contant_tpl = '<tr><td>%s</td><td><b>%s</b></td></tr>';
+ $ret = '<table class="dbg_flat_table" style="width: '.$this->getWindowWidth().'px;">';
+ foreach ($constants as $constant_name) {
+ $ret .= sprintf($contant_tpl, $constant_name, constant($constant_name));
+ }
+ $ret .= '</table>';
+ $this->appendHTML($ret);
+ }
+
+ function AttachToApplication() {
+ if (!$this->constOn('DBG_HANDLE_ERRORS')) return true;
+
+ if (class_exists('kApplication')) {
+ restore_error_handler();
+ $application =& kApplication::Instance();
+ $application->Debugger =& $this;
+ $application->errorHandlers[] = Array(&$this, 'saveError');
+ }
+ else {
+ set_error_handler(Array(&$this, 'saveError'));
+ }
+ }
+ }
+
+ if (!function_exists('memory_get_usage')) {
+ function memory_get_usage(){ return -1; }
+ }
+
+ if (!Debugger::constOn('DBG_ZEND_PRESENT')) {
+ $debugger = new Debugger();
+ }
+
+ if (Debugger::constOn('DBG_USE_SHUTDOWN_FUNC')) {
+ register_shutdown_function( Array(&$debugger, 'printReport') );
+ }
+ }
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.69.2/core/kernel/utility/debugger.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.69
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline