Index: trunk/core/kernel/event_handler.php
===================================================================
diff -u -r4840 -r5219
--- trunk/core/kernel/event_handler.php (.../event_handler.php) (revision 4840)
+++ trunk/core/kernel/event_handler.php (.../event_handler.php) (revision 5219)
@@ -1,7 +1,7 @@
getPrefixSpecial(true) instead of
@@ -25,50 +25,50 @@
*
*/
class kEventHandler extends kBase {
-
+
/**
* In case if event should be handled with mehod,
* which name differs from event name, then it
* should be specified here.
- * key - event name, value - event method
+ * key - event name, value - event method
*
* @var Array
* @access protected
*/
var $eventMethods = Array();
-
+
/**
* Defines mapping vs event names and permission names
*
* @var Array
*/
var $permMapping = Array();
-
+
/**
* Define alternative event processing method names
- *
+ *
* @see $eventMethods
* @access protected
*/
function mapEvents()
{
-
+
}
-
+
/**
* Allows to override standart permission mapping
*
*/
function mapPermissions()
{
-
+
}
-
+
function getPrefixSpecial()
{
trigger_error('Usage of getPrefixSpecial() this method is forbidden in kEventHandler class children. Use $event->getPrefixSpecial(true); instead', E_USER_ERROR);
}
-
+
/**
* Set's prefix and special
*
@@ -82,7 +82,7 @@
$this->mapEvents();
$this->mapPermissions();
}
-
+
/**
* Process Event
*
@@ -93,17 +93,17 @@
{
$event_name=$event->Name;
if( isset($this->eventMethods[$event_name]) ) $event_name=$this->eventMethods[$event_name];
-
+
if( method_exists($this,$event_name) )
{
$this->$event_name($event);
}
- else
+ else
{
trigger_error('event '.$event->Name.' not implemented in class '.get_class($this).'', E_USER_ERROR);
}
}
-
+
/**
* Sample dummy event
*
@@ -115,7 +115,7 @@
/*echo 'building:
';
print_pre($event);*/
}
-
+
/**
* Returns to previous template in opener stack
*
@@ -125,7 +125,7 @@
{
$event->SetRedirectParam('opener', 'u');
}
-
+
/**
* Apply some special processing to
* object beeing recalled before using
@@ -139,7 +139,7 @@
{
// processing here
}
-
+
/**
* Creates new event as child of
* event passed as $event param
@@ -157,7 +157,7 @@
$child_event->Name = $name;
return $child_event;
}
-
+
/**
* Created url part for this module
*
@@ -168,29 +168,29 @@
$prefix_special = $event->getPrefixSpecial();
$url_params = $event->getEventParam('url_params');
$pass_events = $event->getEventParam('pass_events');
-
+
$query_vars = $this->Application->getUnitOption($event->Prefix, 'QueryString');
-
+
$event_key = array_search('event', $query_vars);
if ($event_key) {
// pass through event of this prefix
unset($query_vars[$event_key]);
}
-
+
if (!getArrayValue($url_params, $prefix_special.'_event')) {
// if empty event, then remove it from url
unset( $url_params[$prefix_special.'_event'] );
}
-
+
//if pass events is off and event is not implicity passed
if ( !$pass_events && !isset($url_params[$prefix_special.'_event']) )
{
unset($url_params[$prefix_special.'_event']); // remove event from url if requested
//otherwise it will use value from get_var
}
-
+
if(!$query_vars) return true;
-
+
$processed_params = Array();
foreach($query_vars as $index => $var_name)
{
@@ -199,42 +199,42 @@
$processed_params[$var_name] = isset( $url_params[$var_name] ) ? $url_params[$var_name] : $this->Application->GetVar($var_name);
if ( isset($url_params[$var_name]) ) unset( $url_params[$var_name] );
}
-
+
$ret = '';
-
+
if($processed_params[$prefix_special.'_Page'] > 1)
{
$ret .= $processed_params[$prefix_special.'_Page'].'/';
}
-
+
if ($processed_params[$prefix_special.'_id']) {
-
+
// this allows to fill 3 cache records with one query (see this method for details)
$category_id = isset($url_params['m_cat_id']) ? $url_params['m_cat_id'] : $this->Application->GetVar('m_cat_id');
$category_filename = $this->Application->getFilename('c', $category_id);
-
+
// if template is also item template of category, then remove template
$template = getArrayValue($url_params, 't');
$item_template = $this->Application->getCache('item_templates', $category_id);
if ($template == $item_template || strtolower($template) == '__default__') {
unset($url_params['t']);
}
-
+
// get item's filename
$filename = $this->Application->getFilename($event->Prefix, $processed_params[$prefix_special.'_id'] );
if($filename !== false) $ret .= $filename.'/';
}
-
+
if( getArrayValue($processed_params, $prefix_special.'_Reviews_Page') > 1)
{
if($processed_params[$prefix_special.'_id']) $ret = rtrim($ret, '/');
$ret .= '_'.$processed_params[$prefix_special.'_Reviews_Page'].'/';
}
-
+
$event->setEventParam('url_params', $url_params);
$event->setEventParam('env_string', strtolower($ret) );
}
-
+
/**
* Process mod_rewrite url part left after previous parser
*
@@ -243,9 +243,9 @@
function ParseEnv(&$event)
{
// /_
-
+
$url_parts = $event->getEventParam('url_parts');
-
+
$defaults = Array('id' => 0, 'Page' => 1, 'Reviews_Page' => 1);
foreach ($defaults as $var_name => $var_value)
{
@@ -255,30 +255,30 @@
// $event->status = erFAIL;
return false;
}
-
+
$ret = '';
$url_part = array_shift($url_parts);
-
+
// match module page
if( is_numeric($url_part) )
{
$this->Application->SetVar( $event->getPrefixSpecial().'_Page', $url_part);
$url_part = $url_parts ? array_shift($url_parts) : '';
}
-
+
if (!$url_part) {
$event->setEventParam('url_parts', $url_parts);
// $event->status = erFAIL;
return true;
}
-
+
// match module reviews page
if( preg_match('/(.*)_([\d]+)$/', $url_part, $rets) )
{
$url_part = $rets[1];
$this->Application->SetVar( $event->getPrefixSpecial().'_Reviews_Page', $rets[2]);
}
-
+
// match item's filename
$db =& $this->Application->GetADODBConnection();
$id_field = $this->Application->getUnitOption($event->Prefix, 'IDField');
@@ -288,19 +288,19 @@
LEFT JOIN '.TABLE_PREFIX.'CategoryItems cat_items ON item_table.ResourceId = cat_items.ItemResourceId
WHERE (item_table.Filename = '.$db->qstr($url_part).') AND (cat_items.CategoryId = '.$this->Application->GetVar('m_cat_id').')';
$item_id = $db->GetOne($sql);
- if($item_id !== false)
+ if($item_id !== false)
{
$this->Application->SetVar($event->getPrefixSpecial().'_id', $item_id);
}
- else
+ elseif ($url_part !== 'index') // otherwise category/index.html is parsed as /index.tpl
{
array_unshift($url_parts, $url_part);
$event->status = erFAIL;
}
-
+
$event->setEventParam('url_parts', $url_parts);
}
-
+
/**
* Checks permissions of user
*
@@ -311,7 +311,7 @@
$perm_helper =& $this->Application->recallObject('PermissionsHelper');
return $perm_helper->CheckEventPermission($event, $this->permMapping);
}
-
+
/**
* Occurs, when config was parsed, allows to change config data dynamically
*
@@ -321,7 +321,7 @@
{
// readonly, for hooking only!
}
-
+
}