Index: trunk/admin/editor/cmseditor/editor/filemanager/browser/default/connectors/php/commands.php
===================================================================
diff -u -r1488 -r1595
--- trunk/admin/editor/cmseditor/editor/filemanager/browser/default/connectors/php/commands.php (.../commands.php) (revision 1488)
+++ trunk/admin/editor/cmseditor/editor/filemanager/browser/default/connectors/php/commands.php (.../commands.php) (revision 1595)
@@ -65,12 +65,37 @@
function GetCmsTree()
{
+ global $Config;
$ret = "
-*
-* The class is a singleton, which means that there could be only one instance of KernelApplication in the script.
-* This could be guranteed by NOT calling the class constuctor directly, but rather calling KernelApplication::Instance() method,
-* which returns an instance of the application. The method gurantees that it will return exactly the same instance for any call.
-* See singleton pattern by GOF.
-* @package kernel4
-*/
-
-class kApplication {
-
- /**
- * Holds internal TemplateParser object
- * @access private
- * @var TemplateParser
- */
- var $Parser;
-
- var $Profiler;
-
- /**
- * Holds parser output buffer
- * @access private
- * @var string
- */
- var $HTML;
-
- var $DocRoot;
- var $BasePath;
- var $KernelPath;
- var $Server;
-
-
- /**
- * Prevents request from beeing proceeded twice in case if application init is called mere then one time
- *
- * @var bool
- * @todo This is not good anyway (by Alex)
- */
- var $RequestProcessed = false;
-
- /**
- * The main Factory used to create
- * almost any class of kernel and
- * modules
- *
- * @access private
- * @var kFactory
- */
- var $Factory;
-
- var $XMLFactory; // in use?
-
- /**
- * Holds all phrases used
- * in code and template
- *
- * @var PhrasesCache
- */
- var $Phrases;
-
- /**
- * Holds DBConnection
- *
- * @var kDBConnection
- */
- var $DB;
-
- /**
- * Constucts KernelApplication - constructor is PRIVATE
- *
- * The constuructor of KernelApplication should NOT be called directly
- * To create KernelApplication, call its Instance() method
- * @see KerenelApplication::Instance
- * @access private
- */
- function kApplication()
- {
- global $doc_root, $base_path, $kernel_path, $protocol, $server;
- $this->DocRoot = $doc_root;
- $this->BasePath = $base_path;
- $this->KernelPath = $kernel_path;
- $this->Protocol = $protocol;
- $this->Server = $server;
- }
-
- /**
- * Returns kApplication instance anywhere in the script.
- *
- * This method should be used to get single kApplication object instance anywhere in the
- * Kernel-based application. The method is guranteed to return the SAME instance of kApplication.
- * Anywhere in the script you could write:
- *
- * $application =& kApplication::Instance();
- *
- * or in an object:
- *
- * $this->Application =& kApplication::Instance();
- *
- * to get the instance of kApplication. Note that we call the Instance method as STATIC - directly from the class.
- * To use descendand of standard kApplication class in your project you would need to define APPLICATION_CLASS constant
- * BEFORE calling kApplication::Instance() for the first time. If APPLICATION_CLASS is not defined the method would
- * create and return default KernelApplication instance.
- * @static
- * @access public
- * @return kApplication
- */
- function &Instance()
- {
- static $instance = false;
-
- if (!$instance) {
- if (!defined('APPLICATION_CLASS')) define('APPLICATION_CLASS', 'kApplication');
- $class = APPLICATION_CLASS;
- $instance = new $class();
- }
- return $instance;
- }
-
- /**
- * Initializes the Application
- *
- * Creates Utilites instance, HTTPQuery, Session, Profiler, TemplatesCache, Parser
- * @access public
- * @see HTTPQuery
- * @see Session
- * @see TemplatesCache
- * @return void
- */
- function Init()
- {
- if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
- global $debugger;
- $debugger->appendMemoryUsage('Application before Init:');
- }
-
- if( !$this->isDebugMode() ) set_error_handler( Array(&$this,'handleError') );
-
- $this->DB = new kDBConnection(SQL_TYPE, Array(&$this,'handleSQLError') );
- $this->DB->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB);
- $this->DB->debugMode = $this->isDebugMode();
-
- $this->SetDefaultConstants();
-
- $this->Factory = new kFactory();
-
- $this->registerDefaultClasses();
-
- // 1. to read configs before doing any recallObject
- $config_reader =& $this->recallObject('kUnitConfigReader');
-
- if( !$this->GetVar('m_lang') ) $this->SetVar('m_lang', $this->GetDefaultLanguageId() );
- if( !$this->GetVar('m_theme') ) $this->SetVar('m_theme', $this->GetDefaultThemeId());
- $this->Phrases = new PhrasesCache( $this->GetVar('m_lang') );
-
- $this->SetVar('lang.current_id', $this->GetVar('m_lang') );
- $language =& $this->recallObject('lang.current', null, Array('live_table'=>true) );
-
- if( !$this->GetVar('m_theme') ) $this->SetVar('m_theme', $this->GetDefaultThemeId() );
- $this->SetVar('theme.current_id', $this->GetVar('m_theme') );
-
- if ( $this->GetVar('m_cat_id') === false ) $this->SetVar('m_cat_id', 2); //need to rewrite
-
- if( !$this->RecallVar('UserGroups') )
- {
- $this->StoreVar('UserGroups', $this->ConfigValue('User_GuestGroup'));
- }
-
- if( !$this->RecallVar('curr_iso') ) $this->StoreVar('curr_iso', $this->GetPrimaryCurrency() );
-
- $this->ValidateLogin(); // TODO: write that method
-
- if( $this->isDebugMode() )
- {
- global $debugger;
- $debugger->profileFinish('kernel4_startup');
- }
- }
-
- function GetDefaultLanguageId()
- {
- $table = $this->getUnitOption('lang','TableName');
- $id_field = $this->getUnitOption('lang','IDField');
- return $this->DB->GetOne('SELECT '.$id_field.' FROM '.$table.' WHERE PrimaryLang = 1');
- }
-
- function GetDefaultThemeId()
- {
- if (defined('DBG_FORCE_THEME') && DBG_FORCE_THEME){
- return DBG_FORCE_THEME;
- }
- $table = $this->getUnitOption('theme','TableName');
- $id_field = $this->getUnitOption('theme','IDField');
- return $this->DB->GetOne('SELECT '.$id_field.' FROM '.$table.' WHERE PrimaryTheme = 1');
- }
-
- function GetPrimaryCurrency()
- {
- $this->setUnitOption('mod','AutoLoad',false);
- $module =& $this->recallObject('mod');
- $this->setUnitOption('mod','AutoLoad',true);
-
- if( $module->Load('In-Commerce') )
- {
- $table = $this->getUnitOption('curr','TableName');
- return $this->DB->GetOne('SELECT ISO FROM '.$table.' WHERE IsPrimary = 1');
- }
- else
- {
- return 'USD';
- }
- }
-
- /**
- * Registers default classes such as ItemController, GridController and LoginController
- *
- * Called automatically while initializing Application
- * @access private
- * @return void
- */
- function RegisterDefaultClasses()
- {
- //$this->registerClass('Utilites',KERNEL_PATH.'/utility/utilities.php');
- $this->registerClass('HTTPQuery',KERNEL_PATH.'/utility/http_query.php');
- $this->registerClass('Session',KERNEL_PATH.'/session/session.php');
- $this->registerClass('SessionStorage',KERNEL_PATH.'/session/session.php');
- $this->registerClass('LoginEventHandler',KERNEL_PATH.'/session/login_event_handler.php','login_EventHandler');
- $this->registerClass('kEventManager',KERNEL_PATH.'/event_manager.php','EventManager');
-
- $this->registerClass('kUnitConfigReader',KERNEL_PATH.'/utility/unit_config_reader.php');
-
-
- $this->registerClass('Params',KERNEL_PATH.'/utility/params.php','kActions');
- $this->registerClass('kArray',KERNEL_PATH.'/utility/params.php','kArray');
- $this->registerClass('kFormatter', KERNEL_PATH.'/utility/formatters.php');
- $this->registerClass('kOptionsFormatter', KERNEL_PATH.'/utility/formatters.php');
- $this->registerClass('kPictureFormatter', KERNEL_PATH.'/utility/formatters.php');
- $this->registerClass('kDateFormatter', KERNEL_PATH.'/utility/formatters.php');
- $this->registerClass('kLEFTFormatter', KERNEL_PATH.'/utility/formatters.php');
- $this->registerClass('kMultiLanguage', KERNEL_PATH.'/utility/formatters.php');
- $this->registerClass('kPasswordFormatter', KERNEL_PATH.'/utility/formatters.php');
- $this->registerClass('kCCDateFormatter', KERNEL_PATH.'/utility/formatters.php');
-
- $this->registerClass('kTempTablesHandler', KERNEL_PATH.'/utility/temp_handler.php');
-
- $event_manager =& $this->recallObject('EventManager');
- $event_manager->registerBuildEvent('kTempTablesHandler','OnTempHandlerBuild');
- //$this->registerClass('Configuration',KERNEL_PATH.'/utility/configuration.php');
-
- $this->registerClass('TemplatesCache',KERNEL_PATH.'/parser/template.php');
- $this->registerClass('Template',KERNEL_PATH.'/parser/template.php');
- $this->registerClass('TemplateParser',KERNEL_PATH.'/parser/template_parser.php');
-
- $this->registerClass('MainProcessor', KERNEL_PATH.'/processors/main_processor.php','m_TagProcessor');
-
- $this->registerClass('kMultipleFilter', KERNEL_PATH.'/utility/filters.php');
- $this->registerClass('kDBList', KERNEL_PATH.'/db/dblist.php');
- $this->registerClass('kDBItem', KERNEL_PATH.'/db/dbitem.php');
- $this->registerClass('kDBEventHandler', KERNEL_PATH.'/db/db_event_handler.php');
- $this->registerClass('kDBTagProcessor', KERNEL_PATH.'/db/db_tag_processor.php');
-
- $this->registerClass('kTagProcessor', KERNEL_PATH.'/processors/tag_processor.php');
- $this->registerClass('kEmailMessage',KERNEL_PATH.'/utility/email.php');
- $this->registerClass('kSmtpClient',KERNEL_PATH.'/utility/smtp_client.php');
-
- if (file_exists(MODULES_PATH.'/in-commerce/units/rates/currency_rates.php')) {
- $this->registerClass('kCurrencyRates',MODULES_PATH.'/in-commerce/units/rates/currency_rates.php');
- }
-
- /*$this->RegisterClass('LoginController', KERNEL_PATH.'/users/login_controller.php');*/
- }
-
- /**
- * Defines default constants if it's not defined before - in config.php
- *
- * Called automatically while initializing Application and defines:
- * LOGIN_CONTROLLER, XML_FACTORY etc.
- * @access private
- * @return void
- */
- function SetDefaultConstants()
- {
- if (!defined('SERVER_NAME')) define('SERVER_NAME', $_SERVER['SERVER_NAME']);
- if (!defined('LOGIN_CONTROLLER')) define('LOGIN_CONTROLLER', 'LoginController');
- if (!defined('XML_FACTORY')) define('XML_FACTORY', 'XMLFactory');
- if (!defined('ADMINS_LIST')) define('ADMINS_LIST', '/users/users.php');
- if (!defined('USER_MODEL')) define('USER_MODEL', 'Users');
- if (!defined('DEFAULT_LANGUAGE_ID')) define('DEFAULT_LANGUAGE_ID', 1);
- }
-
- function ProcessRequest()
- {
- $event_manager =& $this->recallObject('EventManager');
-
- if( $this->isDebugMode() && dbg_ConstOn('DBG_SHOW_HTTPQUERY') )
- {
- global $debugger;
- $http_query =& $this->recallObject('HTTPQuery');
- $debugger->appendHTML('HTTPQuery:');
- $debugger->dumpVars($http_query->_Params);
- }
-
- $event_manager->ProcessRequest();
- $this->RequestProcessed = true;
- }
-
- /**
- * Actually runs the parser against current template and stores parsing result
- *
- * This method gets t variable passed to the script, loads the template given in t variable and
- * parses it. The result is store in {@link $this->HTML} property.
- * @access public
- * @return void
- */
- function Run()
- {
- if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
- global $debugger;
- $debugger->appendMemoryUsage('Application before Run:');
- }
-
- if (!$this->RequestProcessed) $this->ProcessRequest();
-
- $this->InitParser();
- $template_cache =& $this->recallObject('TemplatesCache');
- $t = $this->GetVar('t');
-
-
- if (defined('CMS') && CMS) {
- if (!$template_cache->TemplateExists($t)) {
- $cms_handler =& $this->recallObject('cms_EventHandler');
- $t = $cms_handler->GetDesignTemplate();
- }
- }
-
- if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
- global $debugger;
- $debugger->appendMemoryUsage('Application before Parsing:');
- }
-
- $this->HTML = $this->Parser->Parse( $template_cache->GetTemplateBody($t), $t );
-
- if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
- global $debugger;
- $debugger->appendMemoryUsage('Application after Parsing:');
- }
- }
-
- function InitParser()
- {
- if( !is_object($this->Parser) ) $this->Parser =& $this->recallObject('TemplateParser');
- }
-
- /**
- * Send the parser results to browser
- *
- * Actually send everything stored in {@link $this->HTML}, to the browser by echoing it.
- * @access public
- * @return void
- */
- function Done()
- {
- if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
- global $debugger;
- $debugger->appendMemoryUsage('Application before Done:');
- }
-
- //eval("?".">".$this->HTML);
- echo $this->HTML;
- $this->Phrases->UpdateCache();
-
- $session =& $this->recallObject('Session');
- $session->SaveData();
- //$this->SaveBlocksCache();
- }
-
- function SaveBlocksCache()
- {
- if (defined('EXPERIMENTAL_PRE_PARSE')) {
- $data = serialize($this->PreParsedCache);
-
- $this->DB->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("blocks_cache", '.$this->DB->qstr($data).', '.time().')');
- }
- }
-
- // Facade
-
- /**
- * Returns current session id (SID)
- * @access public
- * @return longint
- */
- function GetSID()
- {
- $session =& $this->recallObject('Session');
- return $session->GetID();
- }
-
- function DestroySession()
- {
- $session =& $this->recallObject('Session');
- $session->Destroy();
- }
-
- /**
- * Returns variable passed to the script as GET/POST/COOKIE
- *
- * @access public
- * @param string $var Variable name
- * @return mixed
- */
- function GetVar($var,$mode=FALSE_ON_NULL)
- {
- $http_query =& $this->recallObject('HTTPQuery');
- return $http_query->Get($var,$mode);
- }
-
- /**
- * Returns ALL variables passed to the script as GET/POST/COOKIE
- *
- * @access public
- * @return array
- */
- function GetVars()
- {
- $http_query =& $this->recallObject('HTTPQuery');
- return $http_query->GetParams();
- }
-
- /**
- * Set the variable 'as it was passed to the script through GET/POST/COOKIE'
- *
- * This could be useful to set the variable when you know that
- * other objects would relay on variable passed from GET/POST/COOKIE
- * or you could use SetVar() / GetVar() pairs to pass the values between different objects.
- *
- * This method is formerly known as $this->Session->SetProperty.
- * @param string $var Variable name to set
- * @param mixed $val Variable value
- * @access public
- * @return void
- */
- function SetVar($var,$val)
- {
- $http_query =& $this->recallObject('HTTPQuery');
- $http_query->Set($var,$val);
- }
-
- /**
- * Deletes Session variable
- *
- * @param string $var
- */
- function RemoveVar($var)
- {
- $session =& $this->recallObject('Session');
- return $session->RemoveVar($var);
- }
-
- /**
- * Deletes HTTPQuery variable
- *
- * @param string $var
- * @todo think about method name
- */
- function DeleteVar($var)
- {
- $http_query =& $this->recallObject('HTTPQuery');
- return $http_query->Remove($var);
- }
-
- /**
- * Returns session variable value
- *
- * Return value of $var variable stored in Session. An optional default value could be passed as second parameter.
- *
- * @see SimpleSession
- * @access public
- * @param string $var Variable name
- * @param mixed $default Default value to return if no $var variable found in session
- * @return mixed
- */
- function RecallVar($var,$default=false)
- {
- $session =& $this->recallObject('Session');
- return $session->RecallVar($var,$default);
- }
-
- /**
- * Stores variable $val in session under name $var
- *
- * Use this method to store variable in session. Later this variable could be recalled.
- * @see RecallVar
- * @access public
- * @param string $var Variable name
- * @param mixed $val Variable value
- */
- function StoreVar($var, $val)
- {
- $session =& $this->recallObject('Session');
- $session->StoreVar($var, $val);
- }
-
- function StoreVarDefault($var, $val)
- {
- $session =& $this->recallObject('Session');
- $session->StoreVarDefault($var, $val);
- }
-
- /**
- * Links HTTP Query variable with session variable
- *
- * If variable $var is passed in HTTP Query it is stored in session for later use. If it's not passed it's recalled from session.
- * This method could be used for making sure that GetVar will return query or session value for given
- * variable, when query variable should overwrite session (and be stored there for later use).
- * This could be used for passing item's ID into popup with multiple tab -
- * in popup script you just need to call LinkVar('id', 'current_id') before first use of GetVar('id').
- * After that you can be sure that GetVar('id') will return passed id or id passed earlier and stored in session
- * @access public
- * @param string $var HTTP Query (GPC) variable name
- * @param mixed $ses_var Session variable name
- * @param mixed $default Default variable value
- */
- function LinkVar($var, $ses_var=null, $default='')
- {
- if (!isset($ses_var)) $ses_var = $var;
- if ($this->GetVar($var) !== false)
- {
- $this->StoreVar($ses_var, $this->GetVar($var));
- }
- else
- {
- $this->SetVar($var, $this->RecallVar($ses_var, $default));
- }
- }
-
- /**
- * Returns variable from HTTP Query, or from session if not passed in HTTP Query
- *
- * The same as LinkVar, but also returns the variable value taken from HTTP Query if passed, or from session if not passed.
- * Returns the default value if variable does not exist in session and was not passed in HTTP Query
- *
- * @see LinkVar
- * @access public
- * @param string $var HTTP Query (GPC) variable name
- * @param mixed $ses_var Session variable name
- * @param mixed $default Default variable value
- * @return mixed
- */
- function GetLinkedVar($var, $ses_var=null, $default='')
- {
- if (!isset($ses_var)) $ses_var = $var;
- $this->LinkVar($var, $ses_var, $default);
- return $this->GetVar($var);
- }
-
- /*function ExtractByMask($array, $mask, $key_id=1, $ret_mode=1)
- {
- $utils =& $this->recallObject('Utilities');
- return $utils->ExtractByMask($array, $mask, $key_id, $ret_mode);
- }
-
- function GetSelectedIDs($mask, $format)
- {
- $http_query =& $this->recallObject('HTTPQuery');
- return $http_query->GetSelectedIDs($mask, $format);
- }
-
- function GetSelectedIDsArray($mask, $value_mask="%s,")
- {
- $http_query =& $this->recallObject('HTTPQuery');
- return $http_query->GetSelectedIDsArray($mask, $value_mask);
- }*/
-
- /**
- * Returns configurtion option
- *
- * @param string $option
- * @return string
- * @access public
- */
- /*function ConfigOption($option)
- {
- $config =& $this->recallObject('Configuration');
- return $config->Get($option);
- }*/
-
- /**
- * Sets configuration option
- *
- * @param string $option
- * @param string $value
- * @return bool
- * @access public
- */
- /*function SetConfigOption($option,$value)
- {
- $config =& $this->recallObject('Configuration');
- return $config->Set($option, $value);
- }*/
-
- function AddBlock($name, $tpl)
- {
- $this->cache[$name] = $tpl;
- }
-
- function SetTemplateBody($title,$body)
- {
- $templates_cache =& $this->recallObject('TemplatesCache');
- $templates_cache->SetTemplateBody($title,$body);
- }
-
- function ProcessTag($tag_data)
- {
- $a_tag = new Tag($tag_data,$this->Parser);
- return $a_tag->DoProcessTag();
- }
-
- function ProcessParsedTag($prefix, $tag, $params)
- {
- $a_tag = new Tag('',$this->Parser);
- $a_tag->Tag = $tag;
- $a_tag->Processor = $prefix;
- $a_tag->NamedParams = $params;
- return $a_tag->DoProcessTag();
- }
-
- /* DEFINETLY NEEDS TO BE MOVED AWAY!!!!! */
- /*var $email_body;
- function Email($params)
- {
- $this->email_body = $this->ParseBlock($params);
- $from = $this->GetVar('email_from');
- $to = $this->GetVar('email_to');
- $replay = $this->GetVar('email_replay');
- if ( $replay == "" ) $replay = $from;
- $subject = $this->GetVar('email_subject');
- $charset = $this->GetVar('email_charset');
- // $display = $this->GetVar('email_display');
- $display = 0;
- if (!isset($charset) || $charset == '') $charset = 'US-ASCII';
- $mime = $this->GetVar('email_mime');
-
- if ($mime == 'yes') {
- $mime_mail = new MIMEMail($to, $from, $subject, $charset);
- $mime_mail->mailbody($this->email_body);
-
- if ($f_name = $this->GetVar('email_attach')) {
- $full_path = DOC_ROOT.BASE_PATH.'/'.$f_name;
- $data = '';
- if(file_exists($full_path)) {
- $fd = fopen($full_path, "r");
- $data = fread($fd, filesize($full_path));
- fclose($fd);
- }
- else exit;
-
- $filename = $this->GetVar('email_attach_filename');
- $type = $this->GetVar('email_attach_type');
-
- $mime_mail->attachfile_raw($data, $filename, $type);
- $mime_mail->send();
- }
- }
- else {
- $headers.="From: $from\n";
- $headers.="Reply-To: $replay\n";
- $headers.="Content-Type: text/html; charset=\"$charset\"\n";
- if ( $display == 1 ) {
- echo "
"; - echo " from : $from"; - } - mail($to, $subject, $this->email_body, $headers); - } - }*/ - - /** - * Return ADODB Connection object - * - * Returns ADODB Connection object already connected to the project database, configurable in config.php - * @access public - * @return ADODBConnection - */ - function &GetADODBConnection() - { - return $this->DB; - } - - function ParseBlock($params,$pass_params=0,$as_template=false) - { - if (substr($params['name'], 0, 5) == 'html:') return substr($params['name'], 6); - return $this->Parser->ParseBlock($params, $pass_params, $as_template); - } - - function &GetXMLFactory() - { - return $this->XMLFactory; - } - - /** - * Return href for template - * - * @access public - * @param string $t Template path - * @var string $prefix index.php prefix - could be blank, 'admin' - */ - function HREF($t, $prefix='', $params=null, $index_file=null) - { - global $HTTP_SERVER_VARS; - if (defined('ADMIN') && $prefix == '') $prefix='/admin'; - if (defined('ADMIN') && $prefix == '_FRONT_END_') $prefix = ''; - $index_file = isset($index_file) ? $index_file : (defined('INDEX_FILE') ? INDEX_FILE : basename($_SERVER['PHP_SELF'])); - - if( isset($params['index_file']) ) $index_file = $params['index_file']; - - if (getArrayValue($params, 'opener') == 'u') { - $opener_stack=$this->RecallVar('opener_stack'); - if($opener_stack) { - $opener_stack=unserialize($opener_stack); - if (count($opener_stack) > 0) { - list($index_file, $env) = explode('|', $opener_stack[count($opener_stack)-1]); - $ret = $this->BaseURL($prefix).$index_file.'?'.ENV_VAR_NAME.'='.$env; - if( getArrayValue($params,'escape') ) $ret = addslashes($ret); - return $ret; - } - else { - //define('DBG_REDIRECT', 1); - $t = $this->GetVar('t'); - } - } - else { - //define('DBG_REDIRECT', 1); - $t = $this->GetVar('t'); - } - } - - $pass = isset($params['pass']) ? $params['pass'] : ''; - $pass_events = isset($params['pass_events']) ? $params['pass_events'] : false; // pass events with url - - - - if (defined('MOD_REWRITE') && MOD_REWRITE) { - $env = $this->BuildEnv('', $params, $pass, $pass_events, false); - $env = ltrim($env, ':-'); - - $session =& $this->recallObject('Session'); - $sid = $session->NeedQueryString() ? '?sid='.$this->GetSID() : ''; -// $env = str_replace(':', '/', $env); - $ret = $this->BaseURL($prefix).$t.'.html/'.$env.'/'.$sid; - - } - else { - $env = $this->BuildEnv($t, $params, $pass, $pass_events); - $ret = $this->BaseURL($prefix).$index_file.'?'.$env; - } - - return $ret; - } - - function BuildEnv($t, $params, $pass='all', $pass_events=false, $env_var=true) - { - $session =& $this->recallObject('Session'); - $sid = $session->NeedQueryString() && !(defined('MOD_REWRITE') && MOD_REWRITE) ? $this->GetSID() : ''; - $ret = ''; - if ($env_var) { - $ret = ENV_VAR_NAME.'='; - } - $ret .= defined('INPORTAL_ENV') ? $sid.'-'.$t : $sid.':'.$t; - - $pass = str_replace('all', trim($this->GetVar('passed'), ','), $pass); - - if(strlen($pass) > 0) - { - $pass_info = array_unique( explode(',',$pass) ); // array( prefix[.special], prefix[.special] ... - foreach($pass_info as $pass_element) - { - $ret.=':'; - list($prefix)=explode('.',$pass_element); - $query_vars = $this->getUnitOption($prefix,'QueryString'); - - //if pass events is off and event is not implicity passed - if(!$pass_events && !isset($params[$pass_element.'_event'])) { - $params[$pass_element.'_event'] = ''; // remove event from url if requested - //otherwise it will use value from get_var - } - - if($query_vars) - { - $tmp_string=Array(0=>$pass_element); - foreach($query_vars as $index => $var_name) - { - //if value passed in params use it, otherwise use current from application - $tmp_string[$index] = isset( $params[$pass_element.'_'.$var_name] ) ? $params[$pass_element.'_'.$var_name] : $this->GetVar($pass_element.'_'.$var_name); - if ( isset($params[$pass_element.'_'.$var_name]) ) { - unset( $params[$pass_element.'_'.$var_name] ); - } - } - - $escaped = array(); - foreach ($tmp_string as $tmp_val) { - $escaped[] = str_replace(Array('-',':'), Array('\-','\:'), $tmp_val); - } - - if ($this->getUnitOption($prefix, 'PortalStyleEnv') == true) { - $ret.= array_shift($escaped).array_shift($escaped).'-'.implode('-',$escaped); - } - else { - $ret.=implode('-',$escaped); - } - } - } - } - unset($params['pass']); - unset($params['opener']); - unset($params['m_event']); - - if ($this->GetVar('admin') && !isset($params['admin'])) { - $params['admin'] = 1; - } - - foreach ($params as $param => $value) - { - $ret .= '&'.$param.'='.$value; - } - if( getArrayValue($params,'escape') ) $ret = addslashes($ret); - return $ret; - } - - function BaseURL($prefix='') - { - return PROTOCOL.SERVER_NAME.(defined('PORT')?':'.PORT : '').BASE_PATH.$prefix.'/'; - } - - function Redirect($t='', $params=null, $prefix='', $index_file=null) - { - if ($t == '' || $t === true) $t = $this->GetVar('t'); - - // pass prefixes and special from previous url - if (!isset($params['pass'])) $params['pass'] = 'all'; - - $location = $this->HREF($t, $prefix, $params, $index_file); - $a_location = $location; - $location = "Location: $location"; - //echo " location : $location
"; - echo " to : $to
"; - echo " replay : $replay
"; - echo " subject : $subject
"; - echo " this->email_body : $this->email_body
"; - echo " headers : $headers
"; - echo "
+ * $application =& kApplication::Instance();
+ *
+ * or in an object:
+ *
+ * $this->Application =& kApplication::Instance();
+ *
+ * to get the instance of kApplication. Note that we call the Instance method as STATIC - directly from the class.
+ * To use descendand of standard kApplication class in your project you would need to define APPLICATION_CLASS constant
+ * BEFORE calling kApplication::Instance() for the first time. If APPLICATION_CLASS is not defined the method would
+ * create and return default KernelApplication instance.
+ * @static
+ * @access public
+ * @return kApplication
+ */
+ function &Instance()
+ {
+ static $instance = false;
+
+ if (!$instance) {
+ if (!defined('APPLICATION_CLASS')) define('APPLICATION_CLASS', 'kApplication');
+ $class = APPLICATION_CLASS;
+ $instance = new $class();
+ }
+ return $instance;
+ }
+
+ /**
+ * Initializes the Application
+ *
+ * Creates Utilites instance, HTTPQuery, Session, Profiler, TemplatesCache, Parser
+ * @access public
+ * @see HTTPQuery
+ * @see Session
+ * @see TemplatesCache
+ * @return void
+ */
+ function Init()
+ {
+ if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
+ global $debugger;
+ $debugger->appendMemoryUsage('Application before Init:');
+ }
+
+ if( !$this->isDebugMode() ) set_error_handler( Array(&$this,'handleError') );
+
+ $this->DB = new kDBConnection(SQL_TYPE, Array(&$this,'handleSQLError') );
+ $this->DB->Connect(SQL_SERVER, SQL_USER, SQL_PASS, SQL_DB);
+ $this->DB->debugMode = $this->isDebugMode();
+
+ $this->SetDefaultConstants();
+
+ $this->Factory = new kFactory();
+
+ $this->registerDefaultClasses();
+
+ // 1. to read configs before doing any recallObject
+ $config_reader =& $this->recallObject('kUnitConfigReader');
+
+ if( !$this->GetVar('m_lang') ) $this->SetVar('m_lang', $this->GetDefaultLanguageId() );
+ if( !$this->GetVar('m_theme') ) $this->SetVar('m_theme', $this->GetDefaultThemeId());
+ $this->Phrases = new PhrasesCache( $this->GetVar('m_lang') );
+
+ $this->SetVar('lang.current_id', $this->GetVar('m_lang') );
+ $language =& $this->recallObject('lang.current', null, Array('live_table'=>true) );
+
+ if( !$this->GetVar('m_theme') ) $this->SetVar('m_theme', $this->GetDefaultThemeId() );
+ $this->SetVar('theme.current_id', $this->GetVar('m_theme') );
+
+ if ( $this->GetVar('m_cat_id') === false ) $this->SetVar('m_cat_id', 2); //need to rewrite
+
+ if( !$this->RecallVar('UserGroups') )
+ {
+ $this->StoreVar('UserGroups', $this->ConfigValue('User_GuestGroup'));
+ }
+
+ if (!defined('ADMIN') && !$this->GetVar('admin')) {
+ define('MOD_REWRITE', 1);
+ }
+
+ if( !$this->RecallVar('curr_iso') ) $this->StoreVar('curr_iso', $this->GetPrimaryCurrency() );
+
+ $this->ValidateLogin(); // TODO: write that method
+
+ if( $this->isDebugMode() )
+ {
+ global $debugger;
+ $debugger->profileFinish('kernel4_startup');
+ }
+ }
+
+ function GetDefaultLanguageId()
+ {
+ $table = $this->getUnitOption('lang','TableName');
+ $id_field = $this->getUnitOption('lang','IDField');
+ return $this->DB->GetOne('SELECT '.$id_field.' FROM '.$table.' WHERE PrimaryLang = 1');
+ }
+
+ function GetDefaultThemeId()
+ {
+ if (defined('DBG_FORCE_THEME') && DBG_FORCE_THEME){
+ return DBG_FORCE_THEME;
+ }
+ $table = $this->getUnitOption('theme','TableName');
+ $id_field = $this->getUnitOption('theme','IDField');
+ return $this->DB->GetOne('SELECT '.$id_field.' FROM '.$table.' WHERE PrimaryTheme = 1');
+ }
+
+ function GetPrimaryCurrency()
+ {
+ $this->setUnitOption('mod','AutoLoad',false);
+ $module =& $this->recallObject('mod');
+ $this->setUnitOption('mod','AutoLoad',true);
+
+ if( $module->Load('In-Commerce') )
+ {
+ $table = $this->getUnitOption('curr','TableName');
+ return $this->DB->GetOne('SELECT ISO FROM '.$table.' WHERE IsPrimary = 1');
+ }
+ else
+ {
+ return 'USD';
+ }
+ }
+
+ /**
+ * Registers default classes such as ItemController, GridController and LoginController
+ *
+ * Called automatically while initializing Application
+ * @access private
+ * @return void
+ */
+ function RegisterDefaultClasses()
+ {
+ //$this->registerClass('Utilites',KERNEL_PATH.'/utility/utilities.php');
+ $this->registerClass('HTTPQuery',KERNEL_PATH.'/utility/http_query.php');
+ $this->registerClass('Session',KERNEL_PATH.'/session/session.php');
+ $this->registerClass('SessionStorage',KERNEL_PATH.'/session/session.php');
+ $this->registerClass('LoginEventHandler',KERNEL_PATH.'/session/login_event_handler.php','login_EventHandler');
+ $this->registerClass('kEventManager',KERNEL_PATH.'/event_manager.php','EventManager');
+
+ $this->registerClass('kUnitConfigReader',KERNEL_PATH.'/utility/unit_config_reader.php');
+
+
+ $this->registerClass('Params',KERNEL_PATH.'/utility/params.php','kActions');
+ $this->registerClass('kArray',KERNEL_PATH.'/utility/params.php','kArray');
+ $this->registerClass('kFormatter', KERNEL_PATH.'/utility/formatters.php');
+ $this->registerClass('kOptionsFormatter', KERNEL_PATH.'/utility/formatters.php');
+ $this->registerClass('kPictureFormatter', KERNEL_PATH.'/utility/formatters.php');
+ $this->registerClass('kDateFormatter', KERNEL_PATH.'/utility/formatters.php');
+ $this->registerClass('kLEFTFormatter', KERNEL_PATH.'/utility/formatters.php');
+ $this->registerClass('kMultiLanguage', KERNEL_PATH.'/utility/formatters.php');
+ $this->registerClass('kPasswordFormatter', KERNEL_PATH.'/utility/formatters.php');
+ $this->registerClass('kCCDateFormatter', KERNEL_PATH.'/utility/formatters.php');
+
+ $this->registerClass('kTempTablesHandler', KERNEL_PATH.'/utility/temp_handler.php');
+
+ $event_manager =& $this->recallObject('EventManager');
+ $event_manager->registerBuildEvent('kTempTablesHandler','OnTempHandlerBuild');
+ //$this->registerClass('Configuration',KERNEL_PATH.'/utility/configuration.php');
+
+ $this->registerClass('TemplatesCache',KERNEL_PATH.'/parser/template.php');
+ $this->registerClass('Template',KERNEL_PATH.'/parser/template.php');
+ $this->registerClass('TemplateParser',KERNEL_PATH.'/parser/template_parser.php');
+
+ $this->registerClass('MainProcessor', KERNEL_PATH.'/processors/main_processor.php','m_TagProcessor');
+
+ $this->registerClass('kMultipleFilter', KERNEL_PATH.'/utility/filters.php');
+ $this->registerClass('kDBList', KERNEL_PATH.'/db/dblist.php');
+ $this->registerClass('kDBItem', KERNEL_PATH.'/db/dbitem.php');
+ $this->registerClass('kDBEventHandler', KERNEL_PATH.'/db/db_event_handler.php');
+ $this->registerClass('kDBTagProcessor', KERNEL_PATH.'/db/db_tag_processor.php');
+
+ $this->registerClass('kTagProcessor', KERNEL_PATH.'/processors/tag_processor.php');
+ $this->registerClass('kEmailMessage',KERNEL_PATH.'/utility/email.php');
+ $this->registerClass('kSmtpClient',KERNEL_PATH.'/utility/smtp_client.php');
+
+ if (file_exists(MODULES_PATH.'/in-commerce/units/rates/currency_rates.php')) {
+ $this->registerClass('kCurrencyRates',MODULES_PATH.'/in-commerce/units/rates/currency_rates.php');
+ }
+
+ /*$this->RegisterClass('LoginController', KERNEL_PATH.'/users/login_controller.php');*/
+ }
+
+ /**
+ * Defines default constants if it's not defined before - in config.php
+ *
+ * Called automatically while initializing Application and defines:
+ * LOGIN_CONTROLLER, XML_FACTORY etc.
+ * @access private
+ * @return void
+ */
+ function SetDefaultConstants()
+ {
+ if (!defined('SERVER_NAME')) define('SERVER_NAME', $_SERVER['SERVER_NAME']);
+ if (!defined('LOGIN_CONTROLLER')) define('LOGIN_CONTROLLER', 'LoginController');
+ if (!defined('XML_FACTORY')) define('XML_FACTORY', 'XMLFactory');
+ if (!defined('ADMINS_LIST')) define('ADMINS_LIST', '/users/users.php');
+ if (!defined('USER_MODEL')) define('USER_MODEL', 'Users');
+ if (!defined('DEFAULT_LANGUAGE_ID')) define('DEFAULT_LANGUAGE_ID', 1);
+ }
+
+ function ProcessRequest()
+ {
+ $event_manager =& $this->recallObject('EventManager');
+
+ if( $this->isDebugMode() && dbg_ConstOn('DBG_SHOW_HTTPQUERY') )
+ {
+ global $debugger;
+ $http_query =& $this->recallObject('HTTPQuery');
+ $debugger->appendHTML('HTTPQuery:');
+ $debugger->dumpVars($http_query->_Params);
+ }
+
+ $event_manager->ProcessRequest();
+ $this->RequestProcessed = true;
+ }
+
+ /**
+ * Actually runs the parser against current template and stores parsing result
+ *
+ * This method gets t variable passed to the script, loads the template given in t variable and
+ * parses it. The result is store in {@link $this->HTML} property.
+ * @access public
+ * @return void
+ */
+ function Run()
+ {
+ if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
+ global $debugger;
+ $debugger->appendMemoryUsage('Application before Run:');
+ }
+
+ if (!$this->RequestProcessed) $this->ProcessRequest();
+
+ $this->InitParser();
+ $template_cache =& $this->recallObject('TemplatesCache');
+ $t = $this->GetVar('t');
+
+
+ if (defined('CMS') && CMS) {
+ if (!$template_cache->TemplateExists($t)) {
+ $cms_handler =& $this->recallObject('cms_EventHandler');
+ $t = $cms_handler->GetDesignTemplate();
+ }
+ }
+
+ if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
+ global $debugger;
+ $debugger->appendMemoryUsage('Application before Parsing:');
+ }
+
+ $this->HTML = $this->Parser->Parse( $template_cache->GetTemplateBody($t), $t );
+
+ if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
+ global $debugger;
+ $debugger->appendMemoryUsage('Application after Parsing:');
+ }
+ }
+
+ function InitParser()
+ {
+ if( !is_object($this->Parser) ) $this->Parser =& $this->recallObject('TemplateParser');
+ }
+
+ /**
+ * Send the parser results to browser
+ *
+ * Actually send everything stored in {@link $this->HTML}, to the browser by echoing it.
+ * @access public
+ * @return void
+ */
+ function Done()
+ {
+ if (defined('DEBUG_MODE') && DEBUG_MODE && dbg_ConstOn('DBG_PROFILE_MEMORY') ) {
+ global $debugger;
+ $debugger->appendMemoryUsage('Application before Done:');
+ }
+
+ if ($this->GetVar('admin')) {
+ $reg = '/('.preg_quote(BASE_PATH, '/').'.*\.html)(#.*){0,1}(")/sU';
+ $this->HTML = preg_replace($reg, "$1?admin=1$2$3", $this->HTML);
+ }
+
+ //eval("?".">".$this->HTML);
+ echo $this->HTML;
+ $this->Phrases->UpdateCache();
+
+ $session =& $this->recallObject('Session');
+ $session->SaveData();
+ //$this->SaveBlocksCache();
+ }
+
+ function SaveBlocksCache()
+ {
+ if (defined('EXPERIMENTAL_PRE_PARSE')) {
+ $data = serialize($this->PreParsedCache);
+
+ $this->DB->Query('REPLACE '.TABLE_PREFIX.'Cache (VarName, Data, Cached) VALUES ("blocks_cache", '.$this->DB->qstr($data).', '.time().')');
+ }
+ }
+
+ // Facade
+
+ /**
+ * Returns current session id (SID)
+ * @access public
+ * @return longint
+ */
+ function GetSID()
+ {
+ $session =& $this->recallObject('Session');
+ return $session->GetID();
+ }
+
+ function DestroySession()
+ {
+ $session =& $this->recallObject('Session');
+ $session->Destroy();
+ }
+
+ /**
+ * Returns variable passed to the script as GET/POST/COOKIE
+ *
+ * @access public
+ * @param string $var Variable name
+ * @return mixed
+ */
+ function GetVar($var,$mode=FALSE_ON_NULL)
+ {
+ $http_query =& $this->recallObject('HTTPQuery');
+ return $http_query->Get($var,$mode);
+ }
+
+ /**
+ * Returns ALL variables passed to the script as GET/POST/COOKIE
+ *
+ * @access public
+ * @return array
+ */
+ function GetVars()
+ {
+ $http_query =& $this->recallObject('HTTPQuery');
+ return $http_query->GetParams();
+ }
+
+ /**
+ * Set the variable 'as it was passed to the script through GET/POST/COOKIE'
+ *
+ * This could be useful to set the variable when you know that
+ * other objects would relay on variable passed from GET/POST/COOKIE
+ * or you could use SetVar() / GetVar() pairs to pass the values between different objects."; + echo " from : $from"; + } + mail($to, $subject, $this->email_body, $headers); + } + }*/ + + /** + * Return ADODB Connection object + * + * Returns ADODB Connection object already connected to the project database, configurable in config.php + * @access public + * @return ADODBConnection + */ + function &GetADODBConnection() + { + return $this->DB; + } + + function ParseBlock($params,$pass_params=0,$as_template=false) + { + if (substr($params['name'], 0, 5) == 'html:') return substr($params['name'], 6); + return $this->Parser->ParseBlock($params, $pass_params, $as_template); + } + + function &GetXMLFactory() + { + return $this->XMLFactory; + } + + /** + * Return href for template + * + * @access public + * @param string $t Template path + * @var string $prefix index.php prefix - could be blank, 'admin' + */ + function HREF($t, $prefix='', $params=null, $index_file=null) + { + global $HTTP_SERVER_VARS; + if (defined('ADMIN') && $prefix == '') $prefix='/admin'; + if (defined('ADMIN') && $prefix == '_FRONT_END_') $prefix = ''; + $index_file = isset($index_file) ? $index_file : (defined('INDEX_FILE') ? INDEX_FILE : basename($_SERVER['PHP_SELF'])); + + if( isset($params['index_file']) ) $index_file = $params['index_file']; + + if (getArrayValue($params, 'opener') == 'u') { + $opener_stack=$this->RecallVar('opener_stack'); + if($opener_stack) { + $opener_stack=unserialize($opener_stack); + if (count($opener_stack) > 0) { + list($index_file, $env) = explode('|', $opener_stack[count($opener_stack)-1]); + $ret = $this->BaseURL($prefix).$index_file.'?'.ENV_VAR_NAME.'='.$env; + if( getArrayValue($params,'escape') ) $ret = addslashes($ret); + return $ret; + } + else { + //define('DBG_REDIRECT', 1); + $t = $this->GetVar('t'); + } + } + else { + //define('DBG_REDIRECT', 1); + $t = $this->GetVar('t'); + } + } + + $pass = isset($params['pass']) ? $params['pass'] : ''; + $pass_events = isset($params['pass_events']) ? $params['pass_events'] : false; // pass events with url + + + + if (defined('MOD_REWRITE') && MOD_REWRITE) { + $env = $this->BuildEnv('', $params, $pass, $pass_events, false); + $env = ltrim($env, ':-'); + + $session =& $this->recallObject('Session'); + $sid = $session->NeedQueryString() ? '?sid='.$this->GetSID() : ''; +// $env = str_replace(':', '/', $env); + $ret = rtrim($this->BaseURL($prefix).$t.'.html/'.$env.'/'.$sid, '/'); + + } + else { + $env = $this->BuildEnv($t, $params, $pass, $pass_events); + $ret = $this->BaseURL($prefix).$index_file.'?'.$env; + } + + return $ret; + } + + function BuildEnv($t, $params, $pass='all', $pass_events=false, $env_var=true) + { + $session =& $this->recallObject('Session'); + $sid = $session->NeedQueryString() && !(defined('MOD_REWRITE') && MOD_REWRITE) ? $this->GetSID() : ''; + $ret = ''; + if ($env_var) { + $ret = ENV_VAR_NAME.'='; + } + $ret .= defined('INPORTAL_ENV') ? $sid.'-'.$t : $sid.':'.$t; + + $pass = str_replace('all', trim($this->GetVar('passed'), ','), $pass); + + if(strlen($pass) > 0) + { + $pass_info = array_unique( explode(',',$pass) ); // array( prefix[.special], prefix[.special] ... + foreach($pass_info as $pass_element) + { + $ret.=':'; + list($prefix)=explode('.',$pass_element); + $query_vars = $this->getUnitOption($prefix,'QueryString'); + + //if pass events is off and event is not implicity passed + if(!$pass_events && !isset($params[$pass_element.'_event'])) { + $params[$pass_element.'_event'] = ''; // remove event from url if requested + //otherwise it will use value from get_var + } + + if($query_vars) + { + $tmp_string=Array(0=>$pass_element); + foreach($query_vars as $index => $var_name) + { + //if value passed in params use it, otherwise use current from application + $tmp_string[$index] = isset( $params[$pass_element.'_'.$var_name] ) ? $params[$pass_element.'_'.$var_name] : $this->GetVar($pass_element.'_'.$var_name); + if ( isset($params[$pass_element.'_'.$var_name]) ) { + unset( $params[$pass_element.'_'.$var_name] ); + } + } + + $escaped = array(); + foreach ($tmp_string as $tmp_val) { + $escaped[] = str_replace(Array('-',':'), Array('\-','\:'), $tmp_val); + } + + if ($this->getUnitOption($prefix, 'PortalStyleEnv') == true) { + $ret.= array_shift($escaped).array_shift($escaped).'-'.implode('-',$escaped); + } + else { + $ret.=implode('-',$escaped); + } + } + } + } + unset($params['pass']); + unset($params['opener']); + unset($params['m_event']); + + if ($this->GetVar('admin') && !isset($params['admin'])) { + $params['admin'] = 1; + } + + foreach ($params as $param => $value) + { + $ret .= '&'.$param.'='.$value; + } + if( getArrayValue($params,'escape') ) $ret = addslashes($ret); + return $ret; + } + + function BaseURL($prefix='') + { + return PROTOCOL.SERVER_NAME.(defined('PORT')?':'.PORT : '').BASE_PATH.$prefix.'/'; + } + + function Redirect($t='', $params=null, $prefix='', $index_file=null) + { + if ($t == '' || $t === true) $t = $this->GetVar('t'); + + // pass prefixes and special from previous url + if (!isset($params['pass'])) $params['pass'] = 'all'; + + $location = $this->HREF($t, $prefix, $params, $index_file); + $a_location = $location; + $location = "Location: $location"; + //echo " location : $location
"; + echo " to : $to
"; + echo " replay : $replay
"; + echo " subject : $subject
"; + echo " this->email_body : $this->email_body
"; + echo " headers : $headers
"; + echo "