Index: trunk/core/kernel/application.php
===================================================================
diff -u -r966 -r1339
--- trunk/core/kernel/application.php (.../application.php) (revision 966)
+++ trunk/core/kernel/application.php (.../application.php) (revision 1339)
@@ -1,29 +1,5 @@
DB = new DBConnection(SQL_TYPE, Array(&$this,'handleSQLError') );
+ $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();
- setcookie('CookiesOn', 1, time()+600);
-
$this->Factory = new kFactory();
-
+
$this->registerDefaultClasses();
// 1. to read configs before doing any recallObject
$config_reader =& $this->recallObject('kUnitConfigReader');
- $this->Phrases = new PhrasesCache( $this->RecallVar('LanguageId', DEFAULT_LANGUAGE_ID) );
+ if (!$this->GetVar('m_lang')) $this->SetVar('m_lang', $this->GetDefaultLanguageId());
+ $this->Phrases = new PhrasesCache( $this->GetVar('m_lang') );
+ $language =& $this->recallObject('lang');
+ $language->Load($this->GetVar('m_lang'));
+
$this->ValidateLogin(); // TODO: write that method
+
+ if (defined('DEBUG_MODE')) {
+ global $debugger;
+ $debugger->profileFinish('kernel4_startup');
+ }
+
}
+ function GetDefaultLanguageId()
+ {
+ return 1;
+ }
+
/**
* Registers default classes such as ItemController, GridController and LoginController
*
@@ -182,18 +171,33 @@
//$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('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('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');
@@ -233,12 +237,21 @@
function Run()
{
$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->Parser =& $this->recallObject('TemplateParser');
$template_cache =& $this->recallObject('TemplatesCache');
$t = $this->GetVar('t');
- $this->HTML = $this->Parser->Parse( $template_cache->GetTemplateBody($t) );
+ $this->HTML = $this->Parser->Parse( $template_cache->GetTemplateBody($t), $t );
}
/**
@@ -256,8 +269,18 @@
$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
/**
@@ -326,8 +349,20 @@
$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.
@@ -338,7 +373,7 @@
* @param mixed $default Default value to return if no $var variable found in session
* @return mixed
*/
- function RecallVar($var,$default='')
+ function RecallVar($var,$default=false)
{
$session =& $this->recallObject('Session');
return $session->RecallVar($var,$default);
@@ -382,11 +417,14 @@
function LinkVar($var, $ses_var=null, $default='')
{
if (!isset($ses_var)) $ses_var = $var;
- if ($this->GetVar($var) !== false) {
+ if ($this->GetVar($var) !== false)
+ {
$this->StoreVar($ses_var, $this->GetVar($var));
}
else
+ {
$this->SetVar($var, $this->RecallVar($ses_var, $default));
+ }
}
/**
@@ -471,6 +509,15 @@
return $a_tag->DoProcessTag();
}
+ function ProcessParsedTag($prefix, $tag, $params)
+ {
+ $a_tag = new Tag('',$this->Parser);
+ $a_tag->Tag = $tag;
+ $a_tag->Processor = $prefix.'_TagProcessor';
+ $a_tag->NamedParams = $params;
+ return $a_tag->DoProcessTag();
+ }
+
/*function &GetProcessor($prefix)
{
$this->KernelDie('GetProcessor is DEPRICATED, use recallObject');
@@ -545,9 +592,9 @@
return $this->DB;
}
- function ParseBlock($params,$pass_params=0)
+ function ParseBlock($params,$pass_params=0,$as_template=false)
{
- return $this->Parser->ParseBlock($params,$pass_params);
+ return $this->Parser->ParseBlock($params, $pass_params, $as_template);
}
function &GetXMLFactory()
@@ -562,47 +609,94 @@
* @param string $t Template path
* @var string $prefix index.php prefix - could be blank, 'admin'
*/
- function HREF($t, $prefix='')
+ 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 = defined('INDEX_FILE') ? INDEX_FILE : 'index.php';
- $t_path = !empty($t) ? 't='.$t : '';
+ $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);
+ list($index_file, $env) = explode('|', $opener_stack[count($opener_stack)-1]);
+ $ret = $this->BaseURL($prefix).$index_file.'?'.ENV_VAR_NAME.'='.$env;
+ return $ret;
+ }
+ }
+
+ $pass = isset($params['pass']) ? $params['pass'] : '';
+ $pass_events = isset($params['pass_events']) ? $params['pass_events'] : false; // pass events with url
+
+ $ret = $this->BaseURL($prefix).$index_file.'?'.$this->BuildEnv($t, $params, $pass, $pass_events);
+
+ return $ret;
+ }
+
+ function BuildEnv($t, $params, $pass='all', $pass_events=false)
+ {
$session =& $this->recallObject('Session');
$sid = $session->NeedQueryString()?$this->GetSID():'';
+ if (defined('INPORTAL_ENV')) {
+ $ret = ENV_VAR_NAME.'='.$sid.'-'.$t;
+ }
+ else {
+ $ret = ENV_VAR_NAME.'='.$sid.':'.$t;
+ }
- $ret = $this->BaseURL($prefix).$index_file.'?'.ENV_VAR_NAME.'='.$sid.':'.$t;
+ $pass = str_replace('all', trim($this->GetVar('passed'), ','), $pass);
- $t_pass=$this->GetVar('t_pass');
- $t_pass_events=$this->GetVar('t_pass_events'); // pass events with url
-
- if($t_pass)
+ if(strlen($pass) > 0)
{
- $pass_info=explode(',',$t_pass); // array( prefix[.special], prefix[.special] ...
+ $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(!$t_pass_events) $this->SetVar($pass_element.'_event',''); // remove event from url if requested
+ //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)
{
- $tmp_string[$index]=$this->GetVar($pass_element.'_'.$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] );
+ }
}
- $ret.=implode('-',$tmp_string);
+ $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);
+ }
}
}
}
- $this->SetVar('t_pass',''); // don't pass any prefixes_specials in url by default
- $this->SetVar('t_pass_events',0); // don't pass events in url by default
+ unset($params['pass']);
+ unset($params['opener']);
+ unset($params['m_event']);
+ foreach ($params as $param => $value) {
+ $ret .= '&'.$param.'='.$value;
+ }
+ if( getArrayValue($params,'escape') ) $ret = addslashes($ret);
return $ret;
}
@@ -611,40 +705,28 @@
return PROTOCOL.SERVER_NAME.(defined('PORT')?':'.PORT : '').BASE_PATH.$prefix.'/';
}
- /**
- * Build enviroment variable based on
- * data submitted from previous template
- *
- * @access public
- */
- function ReBuildENV()
+ function Redirect($t='', $params=null, $prefix='', $index_file=null)
{
- $event_manager =& $this->recallObject('EventManager');
- $prefix_specials = array_keys($event_manager->queryMaps);
- $this->SetVar('t_pass', implode(',',$prefix_specials) );
- }
-
- function Redirect($t='', $params='', $prefix='')
- {
- if ($t == '') $t = $this->GetVar('t');
+ if ($t == '' || $t === true) $t = $this->GetVar('t');
// pass prefixes and special from previous url
- $this->ReBuildENV();
+ if (!isset($params['pass'])) $params['pass'] = 'all';
- $location = $this->HREF($t, $prefix);
+ $location = $this->HREF($t, $prefix, $params, $index_file);
$a_location = $location;
- $location = sprintf("Location: %s".($params ? "&" : '')."%s",$location, $params);
+ $location = "Location: $location";
//echo " location : $location
";
-
- if (headers_sent() != '') {
+ if (headers_sent() != '' || ($this->isDebugMode() && dbg_ConstOn('DBG_REDIRECT')) ) {
echo "Debug output above!!! Proceed to redirect: $a_location
";
}
- else
+ else {
header("$location");
-
+ }
+
$session =& $this->recallObject('Session');
$session->SaveData();
+ $this->SaveBlocksCache();
exit;
}
@@ -656,13 +738,22 @@
function Phrase($label)
{
- if (ereg("^!.+!$", $label) > 0) {
- $label = substr($label, 1, -1); //cut exclamation marks
- }
return $this->Phrases->GetPhrase($label);
}
/**
+ * Replace language tags in exclamation marks found in text
+ *
+ * @param string $text
+ * @return string
+ * @access public
+ */
+ function ReplaceLanguageTags($text)
+ {
+ return $this->Phrases->ReplaceLanguageTags($text);
+ }
+
+ /**
* Validtates user in session if required
*
*/
@@ -700,7 +791,7 @@
function HandleEvent(&$event)
{
$event_manager =& $this->recallObject('EventManager');
- $event_manager->HandleEvent(&$event);
+ $event_manager->HandleEvent($event);
}
/**
@@ -716,6 +807,18 @@
$this->Factory->registerClass($real_class,$file,$pseudo_class);
}
+ function registerHook($hookto_prefix, $hookto_special, $hookto_event, $mode, $do_prefix, $do_special, $do_event, $conditional)
+ {
+ $event_manager =& $this->recallObject('EventManager');
+ $event_manager->registerHook($hookto_prefix, $hookto_special, $hookto_event, $mode, $do_prefix, $do_special, $do_event, $conditional);
+ }
+
+ function registerAggregateTag($tag_info)
+ {
+ $aggregator =& $this->recallObject('TagsAggregator', 'kArray');
+ $aggregator->SetArrayValue($tag_info['AggregateTo'], $tag_info['AggregatedTagName'], Array($tag_info['LocalPrefix'], $tag_info['LocalTagName']));
+ }
+
/**
* Returns object using params specified,
* creates it if is required
@@ -727,10 +830,48 @@
*/
function &recallObject($name,$pseudo_class=null,$event_params=Array())
{
- return $this->Factory->getObject($name,$pseudo_class,$event_params);
+ $o1 =& $this->Factory->getObject($name,$pseudo_class,$event_params);
+ //$o1->param1 = 'one';
+
+ /*$func_args = func_get_args();
+ $factory =& $this->Factory;
+ $o2 =& call_user_func_array( Array(&$factory, 'getObject'), $func_args );*/
+
+ //$o2->param1 = 'two';
+ return $o1;
}
+ function &hasObject($name)
+ {
+ return isset($this->Factory->Storage[$name]);
+ }
+
/**
+ * Removes object from storage by given name
+ *
+ * @param string $name Object's name in the Storage
+ */
+ function removeObject($name)
+ {
+ return $this->Factory->DestroyObject($name);
+ }
+
+ /**
+ * Get's real class name for pseudo class,
+ * includes class file and creates class
+ * instance
+ *
+ * @param string $pseudo_class
+ * @return Object
+ * @access private
+ */
+ function &makeClass($pseudo_class)
+ {
+ $func_args = func_get_args();
+ return call_user_func_array( Array(&$this->Factory, 'makeClass'), $func_args);
+ }
+
+ /**
* Checks if application is in debug mode
*
* @return bool
@@ -771,6 +912,19 @@
}
/**
+ * Read all unit with $prefix options
+ *
+ * @param string $prefix
+ * @return Array
+ * @access public
+ */
+ function getUnitOptions($prefix)
+ {
+ $unit_config_reader =& $this->recallObject('kUnitConfigReader');
+ return $unit_config_reader->getUnitOptions($prefix);
+ }
+
+ /**
* Splits any mixing of prefix and
* special into correct ones
*
@@ -812,7 +966,7 @@
global $debugger;
if($debugger)
{
- $errorLevel=defined('DBG_SQL_FAILURE')&&DBG_SQL_FAILURE?E_USER_ERROR:E_USER_WARNING;
+ $errorLevel=defined('DBG_SQL_FAILURE') && DBG_SQL_FAILURE ? E_USER_ERROR : E_USER_WARNING;
$debugger->dumpVars($_REQUEST);
$debugger->appendTrace();
@@ -828,6 +982,23 @@
return false;
}
}
+
+ function NextResourceId()
+ {
+ $this->DB->Query('LOCK TABLES '.TABLE_PREFIX.'IdGenerator WRITE');
+ $this->DB->Query('UPDATE '.TABLE_PREFIX.'IdGenerator SET lastid = lastid+1');
+ $id = $this->DB->GetOne("SELECT lastid FROM ".TABLE_PREFIX."IdGenerator");
+ $this->DB->Query('UNLOCK TABLES');
+ return $id;
+ }
+
+ function GetTopmostPrefix($current_prefix)
+ {
+ while ( $parent_prefix = $this->getUnitOption($current_prefix, 'ParentPrefix') ) {
+ $current_prefix = $parent_prefix;
+ }
+ return $current_prefix;
+ }
}
?>
\ No newline at end of file