Index: trunk/core/kernel/processors/main_processor.php =================================================================== --- trunk/core/kernel/processors/main_processor.php (revision 949) +++ trunk/core/kernel/processors/main_processor.php (revision 950) @@ -1,557 +1,575 @@ <?php class MainProcessor extends TagProcessor { function Init($prefix,$special) { parent::Init($prefix,$special); $actions =& $this->Application->recallObject('kActions'); $actions->Set('t', $this->Application->GetVar('t')); $actions->Set('sid', $this->Application->GetSID()); } /** * 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); } /** * Creates <base href ..> HTML tag for all templates * affects future css, js files and href params of links * * @param Array $params * @return string * @access public */ function Base_Ref($params) { $templates_path = substr(THEMES_PATH,1); return "<base href='".$this->Application->BaseURL().$templates_path."/'>"; } /*function Base_URL($params) { $templates_path = substr(THEMES_PATH,1); return $this->Application->BaseURL().$templates_path; } 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) { - if(!isset($params['pass'])) $params['pass']=''; - $t = (isset($params['t']) && $params['t']) ? $params['t'] : $this->Application->GetVar('t'); - $this->Application->SetVar('t_pass',$params['pass']); - return $this->Application->HREF($t, isset($params['prefix']) ? $params['prefix'] : ''); + $t=isset($params['t'])&&$params['t']?$params['t']:$this->Application->GetVar('t'); unset($params['t']); + $prefix=isset($params['prefix'])?$params['prefix']:''; unset($params['prefix']); + + $pass=isset($params['pass'])?$params['pass']:$this->Application->GetVar('t_pass'); unset($params['pass']); + $this->Application->SetVar('t_pass',$pass); + + $pass_events=isset($params['pass_events'])&&$params['pass_events']?1:0; unset($params['pass_events']); + $this->Application->SetVar('t_pass_events',$pass_events); + + $this->Set($params); // set other params as application vars + return $this->Application->HREF($t,$prefix); } /*// 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; } /** * Compares block parameter with value specified * * @param Array $params * @return bool * @access public */ function Param_Equals($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']; } */ /** * Not tag, method for parameter * selection from list in this TagProcessor * * @param Array $params * @param string $possible_names * @return string * @access public */ function SelectParam($params, $possible_names) { if (!is_array($params)) return; if (!is_array($possible_names)) $possible_names = explode(',', $possible_names); foreach ($possible_names as $name) { if( isset($params[$name]) ) return $params[$name]; } return false; } /** * Returns session variable value by name * * @param Array $params * @return string * @access public */ function Recall($params) { $res = $this->Application->RecallVar( $this->SelectParam($params,'name,var,param') ); return ($res === false && isset($params['no_null']))?'':$res; } // 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) { return $this->Application->GetVar($this->SelectParam($params, 'name,var,param'), EMPTY_ON_NULL); } /*function Config_Equals($params) { foreach ($params as $name => $val) { if (in_array($name, Array( 'prefix', 'function'))) continue; return $this->Application->ConfigOption($name) == $val; } return false; }*/ /** * 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 Odd_Even($params) { $odd = $params['odd']; $even = $params['even']; if ($this->Session->GetProperty('odd_even') == 'even') { $this->Session->SetProperty('odd_even', 'odd'); return $even; } else { $this->Session->SetProperty('odd_even', '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 return $this->Application->Phrase($this->SelectParam($params, 'label,name,title')); } // for tabs function is_active($params) { $test_templ = $params["templ"]; if (!$params['allow_empty']) { $if_true = $params["true"] != '' ? $params["true"] : 1; $if_false = $params["false"] != '' ? $params["false"] : 0; } else { $if_true = $params["true"]; $if_false = $params["false"]; } if ( eregi("^$test_templ", $this->Application->GetVar('t'))) return $if_true; else return $if_false; } function is_t_active($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 Recall_Equals($params) { $name = $params['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 Get_Equals($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->Factory->makeClass('TemplateParser'); $BlockParser->SetParams($params); $parser =& $this->Application->Parser; $t = $params['t']; $t = eregi_replace("\.tpl$", '', $t); $templates_cache =& $this->Application->recallObject('TemplatesCache'); $res = $BlockParser->Parse( $templates_cache->GetTemplateBody($t) ); $this->Application->Parser =& $parser; return $res; } /*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); } + /** + * Find out what object were in link + * used to move here and copy them to + * form submit url + * + * @param unknown_type $params + */ + function PrepareSubmitURL($params) + { + $this->Application->ReBuildENV(); + } /* function Login($params) { $user_prefix = 'users'; $this->parser->registerprefix($user_prefix); $user_class = $this->parser->processors[$user_prefix]->item_class; $candidate = new $user_class(NULL, $this->parser->processors[$user_prefix]); //print_pre($this->Session->Property); $special = array_shift($params); //echo"$special<br>"; $candidate_id = $candidate->Login($this->Session->GetProperty('username'), $this->Session->GetProperty('password'), $special); if ($candidate_id !== false) { $this->Session->SetField('user_id', $candidate_id); $this->Session->Update(); $this->Session->AfterLogin(); $this->parser->register_prefix('m'); $template = array_shift($params); if ($template == '') $template = 'index'; $location = $this->parser->do_process_tag('m', 't', Array($template)); header("Location: $location"); exit; } elseif ($this->Session->GetProperty('username') != '') { $this->Session->SetProperty('login_error', 'Incorrect username or password'); } } */ } global $suite; if (isset($suite)) { class TestMainProcessor extends TestCase { function testParam_Equals() { global $application; $mp =& new MainProcessor($application, 'm'); $mp->Application->Parser->SetParams( Array('test' => 1)); $this->assertTrue($mp->Param_Equals( Array('param' => 'test', 'value' => 1 ))); $this->assertFalse($mp->Param_Equals( Array('param' => 'test', 'value' => 2 ))); $this->assertFalse($mp->Param_Equals( Array('param' => 'test1', 'value' => 2 ))); } function testParam() { global $application; $mp =& new MainProcessor($application, 'm'); $mp->Application->Parser->SetParams( Array('test' => 2)); $this->assertEquals(2, $mp->Param( Array('name' => 'test'))); $this->assertEquals(5, $mp->Param( Array('name' => 'test', 'plus' => 3 ))); $this->assertEquals(1, $mp->Param( Array('name' => 'test', 'plus' => -1 ))); } function testSetGet() { global $application; $mp =& new MainProcessor($application, 'm'); $mp->Set( Array('test_var' => 7, 'another_var' => 'abc') ); $this->assertEquals(7, $mp->Get( Array('param' => 'test_var'))); $this->assertEquals('abc', $mp->Get( Array('param' => 'another_var'))); } function testConfig() { global $application; $mp =& new MainProcessor($application, 'm'); $application->Session->Config->SetOption('test_config_var', '1'); $this->assertEquals(true, $mp->Config_Equals( Array('test_config_var' => '1'))); } function testOddEven() { global $application; $mp =& new MainProcessor($application, 'm');; $this->assertEquals('odd_value', $mp->Odd_Even(Array('odd' => 'odd_value', 'even' => 'even_value'))); $this->assertEquals('even_value', $mp->Odd_Even(Array('odd' => 'odd_value', 'even' => 'even_value'))); $this->assertEquals('odd_value', $mp->Odd_Even(Array('odd' => 'odd_value', 'even' => 'even_value'))); } function testApplicationProcessTag() { global $application; $this->assertEquals($application->GetSID(), $application->ProcessTag('m:sid')); } } $suite->addTest(new TestSuite("TestMainProcessor")); } ?> \ No newline at end of file Property changes on: trunk/core/kernel/processors/main_processor.php ___________________________________________________________________ Modified: cvs2svn:cvs-rev ## -1 +1 ## -1.3 \ No newline at end of property +1.4 \ No newline at end of property Index: trunk/core/kernel/application.php =================================================================== --- trunk/core/kernel/application.php (revision 949) +++ trunk/core/kernel/application.php (revision 950) @@ -1,807 +1,829 @@ <?php //include_once(KERNEL_PATH."/base.php"); //include_once(KERNEL_PATH."/mvc/models/dbitem.php"); //include_once(KERNEL_PATH."/mvc/models/dblist.php"); include_once(KERNEL_PATH."/kbase.php"); include_once(KERNEL_PATH.'/processors/tag_processor.php'); include_once(KERNEL_PATH."/event_handler.php"); include_once(KERNEL_PATH."/utility/factory.php"); include_once(KERNEL_PATH."/utility/iterator.php"); include_once(KERNEL_PATH."/languages/phrases_cache.php"); include_once(KERNEL_PATH."/db/dblist.php"); include_once(KERNEL_PATH."/db/dbitem.php"); include_once(KERNEL_PATH."/db/db_tag_processor.php"); include_once(KERNEL_PATH."/utility/event.php"); $profiler = null; /** * Basic class for Kernel3-based Application * * This class is a Facade for any other class which needs to deal with Kernel3 framework.<br> * The class incapsulates the main run-cycle of the script, provide access to all other objects in the framework.<br> * <br> * The class is a singleton, which means that there could be only one instance of KernelApplication in the script.<br> * 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.<br> * 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; /** * 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 connection to database * * @var DBConnection */ 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: * <code> * $application =& kApplication::Instance(); * </code> * or in an object: * <code> * $this->Application =& kApplication::Instance(); * </code> * 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() { $this->DB = new DBConnection(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) ); $this->ValidateLogin(); // TODO: write that method } /** * 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('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('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('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('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); } /** * 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() { $event_manager =& $this->recallObject('EventManager'); $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) ); } /** * 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() { //eval("?".">".$this->HTML); echo $this->HTML; $this->Phrases->UpdateCache(); $session =& $this->recallObject('Session'); $session->SaveData(); } // 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->DestroySession(); } /** * 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.<br> * * 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); } function RemoveVar($var) { $session =& $this->recallObject('Session'); return $session->RemoveVar($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='') { $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).<br> * 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 &GetProcessor($prefix) { $this->KernelDie('GetProcessor is DEPRICATED, use recallObject'); // return $this->Processors->GetProcessor($prefix, new Tag('empty', $this->Parser)); }*/ /* 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 "<pre>"; echo " from : $from <br>"; echo " to : $to <br>"; echo " replay : $replay <br>"; echo " subject : $subject <br>"; echo " this->email_body : $this->email_body <br>"; echo " headers : $headers <br>"; echo "</pre>"; } 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) { return $this->Parser->ParseBlock($params,$pass_params); } 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='') { 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 : ''; $session =& $this->recallObject('Session'); $sid = $session->NeedQueryString()?$this->GetSID():''; $ret = $this->BaseURL($prefix).$index_file.'?'.ENV_VAR_NAME.'='.$sid.':'.$t; $t_pass=$this->GetVar('t_pass'); + $t_pass_events=$this->GetVar('t_pass_events'); // pass events with url + if($t_pass) { $pass_info=explode(',',$t_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($query_vars) { $tmp_string=Array(0=>$pass_element); foreach($query_vars as $index => $var_name) { $tmp_string[$index]=$this->GetVar($pass_element.'_'.$var_name); } $ret.=implode('-',$tmp_string); } } } - + $this->SetVar('t_pass_events',0); // don't pass events in url by default return $ret; } function BaseURL($prefix='') { return PROTOCOL.SERVER_NAME.(defined('PORT')?':'.PORT : '').BASE_PATH.$prefix.'/'; } + /** + * Build enviroment variable based on + * data submitted from previous template + * + * @access public + */ + function ReBuildENV() + { + $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'); + + // pass prefixes and special from previous url + $this->ReBuildENV(); + $location = $this->HREF($t, $prefix); $a_location = $location; $location = sprintf("Location: %s".($params ? "&" : '')."%s",$location, $params); //echo " location : $location <br>"; if (headers_sent() != '') { echo "<b>Debug output above!!!</b> Proceed to redirect: <a href=\"$a_location\">$a_location</a><br>"; } else header("$location"); $session =& $this->recallObject('Session'); $session->SaveData(); exit; } /*function UserError($msg) { error_reporting(E_ALL); trigger_error($msg, E_USER_WARNING ); }*/ function Phrase($label) { if (ereg("^!.+!$", $label) > 0) { $label = substr($label, 1, -1); //cut exclamation marks } return $this->Phrases->GetPhrase($label); } /** * Validtates user in session if required * */ function ValidateLogin() { if (defined('LOGIN_REQUIRED')) { // Original Kostja call //$login_controller =& $this->Factory->MakeClass(LOGIN_CONTROLLER, Array('model' => USER_MODEL, 'prefix' => 'login')); // Call proposed by Alex //$login_controller =& $this->RecallObject(LOGIN_CONTROLLER, Array('model' => USER_MODEL, 'prefix' => 'login')); //$login_controller->CheckLogin(); } } function KernelDie($message) { echo "<b>KernelApplication died</b>: $message<br>Debug backtrace follows:<br>"; print_pre(debug_backtrace()); echo "</pre>"; } function trigerError($message,$error_type=E_USER_WARNING) { trigger_error($message,$error_type); } /** * Allows to process any type of event * * @param kEvent $event * @access public */ function HandleEvent(&$event) { $event_manager =& $this->recallObject('EventManager'); $event_manager->HandleEvent(&$event); } /** * Registers new class in the factory * * @param string $real_class * @param string $file * @param string $pseudo_class * @access public */ function registerClass($real_class,$file,$pseudo_class=null) { $this->Factory->registerClass($real_class,$file,$pseudo_class); } /** * Returns object using params specified, * creates it if is required * * @param string $name * @param string $pseudo_class * @param Array $event_params * @return Object */ function &recallObject($name,$pseudo_class=null,$event_params=Array()) { return $this->Factory->getObject($name,$pseudo_class,$event_params); } /** * Checks if application is in debug mode * * @return bool * @access public */ function isDebugMode() { return defined('DEBUG_MODE')&&DEBUG_MODE; } /** * Reads unit (specified by $prefix) * option specified by $option * * @param string $prefix * @param string $option * @return string * @access public */ function getUnitOption($prefix,$option) { $unit_config_reader =& $this->recallObject('kUnitConfigReader'); return $unit_config_reader->getUnitOption($prefix,$option); } /** * Set's new unit option value * * @param string $prefix * @param string $name * @param string $value * @access public */ function setUnitOption($prefix,$option,$value) { $unit_config_reader =& $this->recallObject('kUnitConfigReader'); return $unit_config_reader->setUnitOption($prefix,$option,$value); } /** * Splits any mixing of prefix and * special into correct ones * * @param string $prefix_special * @return Array * @access public */ function processPrefix($prefix_special) { return $this->Factory->processPrefix($prefix_special); } /** * Set's new event for $prefix_special * passed * * @param string $prefix_special * @param string $event_name * @access public */ function setEvent($prefix_special,$event_name) { $event_manager =& $this->recallObject('EventManager'); $event_manager->setEvent($prefix_special,$event_name); } /** * SQL Error Handler * * @param int $code * @param string $msg * @param string $sql * @return bool * @access private */ function handleSQLError($code,$msg,$sql) { global $debugger; if($debugger) { $errorLevel=defined('DBG_SQL_FAILURE')&&DBG_SQL_FAILURE?E_USER_ERROR:E_USER_WARNING; $debugger->dumpVars($_REQUEST); $debugger->appendTrace(); trigger_error('<span class="debug_error">'.$msg.' ('.$code.')</span><br><a href="javascript:SetClipboard(\''.addslashes($sql).'\');"><b>SQL</b></a>: '.$debugger->highlightString($sql),$errorLevel); return true; } else { echo '<b>xProcessing SQL</b>: '.$sql.'<br>'; echo '<b>Error ('.$code.'):</b> '.$msg.'<br>'; return false; } } } ?> \ No newline at end of file Property changes on: trunk/core/kernel/application.php ___________________________________________________________________ Modified: cvs2svn:cvs-rev ## -1 +1 ## -1.6 \ No newline at end of property +1.7 \ No newline at end of property