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 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 ""; } /*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'] : ''); } /*// 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
"; } else echo "Object $name does not exist in the appliaction
"; }*/ /** * 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]
"; $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 .= "\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 ''; }*/ /*function GetUserPermission($params) { // echo"GetUserPermission $params[name]"; if ($this->Application->RecallVar('user_type') == 1) return 1; else { $perm_name = $params[name]; $aPermissions = unserialize($this->Application->RecallVar('user_permissions')); if ($aPermissions) return $aPermissions[$perm_name]; } }*/ /** * Set's parser block param value * * @param Array $params * @access public */ function AddParam($params) { $parser =& $this->Application->Parser; // recallObject('TemplateParser'); foreach ($params as $param => $value) { $this->Application->SetVar($param, $value); $parser->SetParam($param, $value); $parser->AddParam('/\$'.$param.'/', $value); } } /*function ParseToVar($params) { $var = $params['var']; $tagdata = $params['tag']; $parser =& $this->Application->Parser; //recallObject('TemplateParser'); $res = $this->Application->ProcessTag($tagdata); $parser->SetParam($var, $res); $parser->AddParam('/\$'.$var.'/', $res); return ''; }*/ /*function TagNotEmpty($params) { $tagdata = $params['tag']; $res = $this->Application->ProcessTag($tagdata); return $res != ''; }*/ /*function TagEmpty($params) { return !$this->TagNotEmpty($params); }*/ /** * Parses block and returns result * * @param Array $params * @return string * @access public */ function ParseBlock($params) { $parser =& $this->Application->Parser; // recallObject('TemplateParser'); return $parser->ParseBlock($params); } /* function 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
"; $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")); } ?>