Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F773333
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Feb 2, 8:33 AM
Size
15 KB
Mime Type
text/x-diff
Expires
Tue, Feb 4, 8:33 AM (45 m, 17 s)
Engine
blob
Format
Raw Data
Handle
556573
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/core/kernel/processors/main_processor.php
===================================================================
--- trunk/core/kernel/processors/main_processor.php (revision 933)
+++ trunk/core/kernel/processors/main_processor.php (revision 934)
@@ -1,459 +1,557 @@
<?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)
+ /*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'];
- }
-
+ }*/
+
/**
- * Returns sid of current object
+ * 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 int
- * @todo Is really called ?
+ * @return string
+ * @access public
*/
- /*function Sid($params)
- {
- $session =& $this->Application->recallObject('Session');
- return $session->GetId();
- }*/
-
- //NEEDS TEST
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
+ /*// 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);
}
- /**
- * Returns hidden field for template name
- *
- * @param Array $params
- * @return string
- * @todo Is really called ?
- */
- /*function Hidden_t($params)
+ /*function PHP_Self($params)
{
- return "<input type=hidden name='t' value='".$this->Application->GetVar('t')."'>";
- }*/
+ return $HTTP_SERVER_VARS['PHP_SELF'];
+ }
+ */
/**
- * Returns hidden field for SID
+ * Not tag, method for parameter
+ * selection from list in this TagProcessor
*
* @param Array $params
+ * @param string $possible_names
* @return string
- * @todo Is really called ?
+ * @access public
*/
- /*function Hidden_SID($params)
- {
- $session =& $this->Application->recallObject('Session');
- return "<input type=hidden name='sid' value='".$session->GetID()."'>";
- }*/
-
- function PHP_Self($params)
- {
- return $HTTP_SERVER_VARS['PHP_SELF'];
- }
-
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 (array_key_exists($name, $params)) return $params[$name];
+
+ $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'));
- if ($res === false && isset($params['no_null']))
- return '';
- else
- return $res;
+ $res = $this->Application->RecallVar( $this->SelectParam($params,'name,var,param') );
+ return ($res === false && isset($params['no_null']))?'':$res;
}
- function Store($params)
+ // bad style to store something from template to session !!! (by Alex)
+ /*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)
+ /*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='';
+ foreach ($params AS $name => $val)
+ {
$o .= "<input type='hidden' name='$name' id='$name' value='$val'>\n";
}
return $o;
}
- function Odd_Even($params)
+ /*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)
{
// echo " is_active <br> ";
$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)
+ /*function Kernel_Scripts($params)
{
return '<script type="text/javascript" src="'.PROTOCOL.SERVER_NAME.BASE_PATH.'/kernel3/js/grid.js"></script>';
- }
+ }*/
- function GetUserPermission($params)
+ /*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];
}
- }
-
- function t_url($params)
- {
- $url = $this->Application->HREF($this->Application->GetVar('t'));
- return $url;
- }
+ }*/
+
+ /**
+ * 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)
+ /*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)
+ /*function TagNotEmpty($params)
{
$tagdata = $params['tag'];
$res = $this->Application->ProcessTag($tagdata);
return $res != '';
- }
+ }*/
- function TagEmpty($params)
+ /*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<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.1
\ No newline at end of property
+1.2
\ No newline at end of property
Event Timeline
Log In to Comment