Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F773407
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, 10:06 AM
Size
25 KB
Mime Type
text/x-diff
Expires
Tue, Feb 4, 10:06 AM (2 h, 1 m)
Engine
blob
Format
Raw Data
Handle
556636
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 935)
+++ trunk/core/kernel/processors/main_processor.php (revision 936)
@@ -1,557 +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)
{
$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<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)
- /*function Store($params)
+ // 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)
{
- // 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)
{
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);
}
/*
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.2
\ No newline at end of property
+1.3
\ No newline at end of property
Index: trunk/core/kernel/db/db_event_handler.php
===================================================================
--- trunk/core/kernel/db/db_event_handler.php (revision 935)
+++ trunk/core/kernel/db/db_event_handler.php (revision 936)
@@ -1,409 +1,409 @@
<?php
/**
* Note:
* 1. When adressing variables from submit containing
* Prefix_Special as part of their name use
* $event->getPrefixSpecial(true) instead of
* $event->Prefix_Special as usual. This is due PHP
* is converting "." symbols in variable names during
* submit info "_". $event->getPrefixSpecial optional
* 1st parameter returns correct corrent Prefix_Special
* for variables beeing submitted such way (e.g. variable
* name that will be converted by PHP: "users.read_only_id"
* will be submitted as "users_read_only_id".
*
* 2. When using $this->Application-LinkVar on variables submitted
* from form which contain $Prefix_Special then note 1st item. Example:
* LinkVar($event->getPrefixSpecial(true).'_varname',$event->Prefix_Special.'_varname')
*
*/
/**
* EventHandler that is used to process
* any database related events
*
*/
class kDBEventHandler extends kEventHandler {
/**
* Loads item only
*
* @param kEvent $event
* @access protected
*/
function OnLoad(&$event)
{
$object =& $this->createObject(&$event);
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnUpdate');
$event->redirect=false;
}
/**
* Get's ID of item to be edited.
* Returns 1st id in case if many
* items were selected.
*
* @param kEvent $event
* @return int
*/
function getPassedID(&$event)
{
$ret=$this->Application->GetVar($event->getPrefixSpecial().'_id');
if($ret===false)
{
$ids=$this->Application->GetVar($event->getPrefixSpecial().'_selected_ids');
$ids=explode(',',$ids);
if($ids) $ret=array_shift($ids);
}
return $ret;
}
/**
* Builds item (loads if needed)
*
* @param kEvent $event
* @access protected
*/
function OnItemBuild(&$event)
{
$object =& $this->createObject(&$event);
$this->dbBuild(&$object,&$event);
$sql=$this->getSelectSQL($event,'OnItemPrepareQuery');
$object->setSelectSQL($sql);
// 1. set from config what needed
$fields = $this->Application->getUnitOption($event->Prefix,'Fields');
$object->setConfigFields( array_keys($fields) );
// 2. loads if allowed
$auto_load = $this->Application->getUnitOption($event->Prefix,'AutoLoad');
if($auto_load)
{
$id = $this->getPassedID(&$event);
$object->Load($id);
}
}
/**
* Builds list
*
* @param kEvent $event
* @access protected
*/
function OnListBuild(&$event)
{
$event->setPseudoClass('_List');
$object =& $this->createObject(&$event);
$this->dbBuild(&$object,&$event);
$sql=$this->getSelectSQL($event,'OnListPrepareQuery');
$object->setSelectSQL($sql);
$t=$this->Application->GetVar('t');
$this->Application->StoreVar('redirect_to',$t);
$this->SetPagination(&$event);
$this->SetSorting(&$event);
}
/**
* Set's correct page for list
* based on data provided with event
*
* @param kEvent $event
* @access private
* @see OnListBuild
*/
function SetPagination(&$event)
{
$per_page = $event->getEventParam('per_page');
if(!$per_page)
{
$per_page=$this->Application->RecallVar($event->Prefix_Special.'_PerPage');
if(!$per_page)
{
$per_page=10;
}
}
$event->setPseudoClass('_List');
$object =& $this->createObject(&$event);
$object->SetPerPage($per_page);
$object->CountRecs();
$object->SetPage( $this->Application->GetLinkedVar( $event->Prefix_Special.'_Page' ) );
}
/**
* Set's correct sorting for list
* based on data provided with event
*
* @param kEvent $event
* @access private
* @see OnListBuild
*/
function SetSorting(&$event)
{
$event->setPseudoClass('_List');
$object =& $this->createObject(&$event);
$cur_sort1 = $this->Application->RecallVar($event->Prefix_Special.'_Sort1');
$cur_sort1_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort1_Dir');
$cur_sort2 = $this->Application->RecallVar($event->Prefix_Special.'_Sort2');
$cur_sort2_dir = $this->Application->RecallVar($event->Prefix_Special.'_Sort2_Dir');
//Use default if not specified
/*if ( $cur_sort1 === false || $cur_sort1_dir == false ) {
$cur_sort1 = $this->Application->ConfigOption($event->Prefix_Special.'_Sort1');
$cur_sort1_dir = $this->Application->ConfigOption($event->Prefix_Special.'_Sort1_Dir');
$cur_sort2 = $this->Application->ConfigOption($event->Prefix_Special.'_Sort2');
$cur_sort2_dir = $this->Application->ConfigOption($event->Prefix_Special.'_Sort2_Dir');
}*/
if($cur_sort1 != '' && $cur_sort1_dir != '')
{
$object->AddOrderField($cur_sort1, $cur_sort1_dir);
}
if($cur_sort2 != '' && $cur_sort2_dir != '')
{
$object->AddOrderField($cur_sort2, $cur_sort2_dir);
}
}
/**
* Some kind of filter processing stuff.
* Not in use by now
*
*/
function AddFilters()
{
}
/**
* Set's new page for list
*
* @param kEvent $event
* @access protected
*/
function OnSetPage(&$event)
{
$event->setPseudoClass('_List');
$object =& $this->createObject(&$event);
$new_page =& $this->Application->GetVar($event->Prefix_Special.'_page');
$object->SetPage($new_page);
}
/**
* Set's new sorting for list
*
* @param kEvent $event
* @access protected
*/
function OnSetSorting(&$event)
{
$this->Application->LinkVar($event->getPrefixSpecial(true).'_Sort1',$event->Prefix_Special.'_Sort1');
$this->Application->LinkVar($event->getPrefixSpecial(true).'_Sort1_Dir',$event->Prefix_Special.'_Sort1_Dir');
//$event->setPseudoClass('_List');
//$object =& $this->createObject(&$event);
}
/**
* Common builder part for Item & List
*
* @param Object $object
* @access private
*/
function dbBuild(&$object,&$event)
{
// set Item & List common parameters from config
$table = $this->Application->getUnitOption($event->Prefix,'TableName');
$object->setTableName($table);
$id_field = $this->Application->getUnitOption($event->Prefix,'IDField');
$object->setIDField($id_field);
// get selected ids from post & save them to session
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
- $ids=array_keys($items_info);
- if($ids)
+ if($items_info)
{
+ $ids=array_keys($items_info);
$this->Application->SetVar($event->getPrefixSpecial().'_selected_ids',implode(',',$ids));
}
$this->Application->LinkVar($event->getPrefixSpecial().'_selected_ids');
// set's any possible hidden fields needed for both Item & List
$current_event = $this->Application->GetVar($event->Prefix_Special.'_event');
$this->Application->setEvent($event->Prefix_Special,$current_event);
}
/**
* Returns select query for loading item/list
*
* @param kEvent $event
* @param string $event_name
* @return string
* @access protected
*/
function getSelectSQL(&$event,$event_name)
{
$new_event =& $this->inheritEvent(&$event);
$new_event->Name=$event_name;
$this->Application->HandleEvent(&$new_event);
return $event->getEventParam('SQLQuery');
}
/**
* Creates needed sql query to load item,
* if no query is defined in config for
* special requested, then use default
* query
*
* @param kEvent $event
* @access protected
*/
function OnItemPrepareQuery(&$event)
{
$sqls = $this->Application->getUnitOption($event->Prefix,'ItemSQLs');
$sql = isset($sqls[$event->Special])?$sqls[$event->Special]:$sqls[''];
$event->MasterEvent->setEventParam('SQLQuery',$sql);
}
/**
* Creates needed sql query to load list,
* if no query is defined in config for
* special requested, then use default
* query
*
* @param kEvent $event
* @access protected
*/
function OnListPrepareQuery(&$event)
{
$sqls = $this->Application->getUnitOption($event->Prefix,'ListSQLs');
$sql = isset($sqls[$event->Special])?$sqls[$event->Special]:$sqls[''];
$event->MasterEvent->setEventParam('SQLQuery',$sql);
}
/**
* Creates new kDBItem
*
* @param kEvent $event
* @access protected
*/
function OnCreate(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
$object =& $this->createObject(&$event);
$this->prepareObject(&$object,&$event);
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info) $field_values = array_shift($items_info);
$object->SetFieldsFromHash($field_values);
if( $object->Create() )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFATAL;
$event->redirect=false;
}
}
/**
* Updates kDBItem
*
* @param kEvent $event
* @access protected
*/
function OnUpdate(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
$object =& $this->createObject(&$event);
$this->prepareObject(&$object,&$event);
$items_info = $this->Application->GetVar( $event->getPrefixSpecial(true) );
if($items_info)
{
foreach($items_info as $id => $field_values)
{
//$object->Load($id);
$object->SetFieldsFromHash($field_values);
if( $object->Update($id) )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFATAL;
$event->redirect=false;
break;
}
}
}
}
/**
* Delete's kDBItem object
*
* @param kEvent $event
* @access protected
*/
function OnDelete(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
$object =& $this->createObject(&$event);
$object->ID=$this->Application->GetVar($event->Prefix_Special.'_id');
if( $object->Delete() )
{
$event->status=erSUCCESS;
}
else
{
$event->status=erFATAL;
$event->redirect=false;
break;
}
}
/**
* Prepares new kDBItem object
*
* @param kEvent $event
* @access protected
*/
function OnNew(&$event)
{
$this->Application->setUnitOption($this->getPrefixSpecial(),'AutoLoad',false);
$object =& $this->createObject(&$event);
$this->prepareObject(&$object,&$event);
$object->setID(0);
$this->Application->SetVar($event->Prefix_Special.'_SaveEvent','OnCreate');
$event->redirect=false;
}
/**
* Cancel's kDBItem Editing/Creation
*
* @param kEvent $event
* @access protected
*/
function OnCancel(&$event)
{
}
}
?>
\ No newline at end of file
Property changes on: trunk/core/kernel/db/db_event_handler.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