Index: custom/units/widgets/widget_eh.php
===================================================================
--- custom/units/widgets/widget_eh.php (revision 15331)
+++ custom/units/widgets/widget_eh.php (working copy)
@@ -1,310 +1,319 @@
<?php
+defined('FULL_PATH') or die('restricted access!');
- defined('FULL_PATH') or die('restricted access!');
+/**
+ * Widgets Event Handler (sample)
+ *
+ */
+class WidgetEventHandler extends kDBEventHandler {
/**
- * Widgets Event Handler (sample)
+ * Allows to override standard permission mapping
*
+ * @return void
+ * @access protected
+ * @see kEventHandler::$permMapping
*/
- class WidgetEventHandler extends kDBEventHandler {
+ protected function mapPermissions()
+ {
+ parent::mapPermissions();
- /**
- * Allows to override standard permission mapping
- *
- * @return void
- * @access protected
- * @see kEventHandler::$permMapping
- */
- protected function mapPermissions()
- {
- parent::mapPermissions();
+ $permissions = Array (
+ 'OnItemBuild' => Array ('self' => true),
+ 'OnCustomEvent' => Array ('self' => true),
+ );
- $permissions = Array (
- 'OnItemBuild' => Array ('self' => true),
- 'OnCustomEvent' => Array ('self' => true),
- );
+ $this->permMapping = array_merge($this->permMapping, $permissions);
+ }
- $this->permMapping = array_merge($this->permMapping, $permissions);
+ /**
+ * Checks user permission to execute given $event
+ *
+ * @param kEvent $event
+ * @return bool
+ * @access public
+ */
+ public function CheckPermission(kEvent $event)
+ {
+ $skip_permissions_check_events = Array (
+ 'OnAnotherCustomEvent',
+ );
+
+ if ( in_array($event->Name, $skip_permissions_check_events) ) {
+ return true;
}
- /**
- * Checks user permission to execute given $event
- *
- * @param kEvent $event
- * @return bool
- * @access public
- */
- public function CheckPermission(kEvent $event)
- {
- $skip_permissions_check_events = Array (
- 'OnAnotherCustomEvent',
- );
+ return parent::CheckPermission($event);
+ }
- if ( in_array($event->Name, $skip_permissions_check_events) ) {
- return true;
- }
+ /**
+ * Set custom query for the list
+ *
+ * @param kEvent $event
+ */
+ function OnCustomEvent($event)
+ {
+ $object = $event->getObject();
+ /* @var $object kDBList */
- return parent::CheckPermission($event);
- }
+ }
- /**
- * Set custom query for the list
- *
- * @param kEvent $event
- */
- function OnCustomEvent($event)
- {
- $object = $event->getObject();
- /* @var $object kDBList */
+ /**
+ * Apply any custom changes to list's sql query
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ * @see kDBEventHandler::OnListBuild()
+ */
+ protected function SetCustomQuery(kEvent $event)
+ {
+ parent::SetCustomQuery($event);
- }
+ $object = $event->getObject();
+ /* @var $object kDBList */
- /**
- * Apply any custom changes to list's sql query
- *
- * @param kEvent $event
- * @return void
- * @access protected
- * @see kDBEventHandler::OnListBuild()
- */
- protected function SetCustomQuery(kEvent $event)
- {
- parent::SetCustomQuery($event);
-
- $object = $event->getObject();
- /* @var $object kDBList */
-
- # identifying event based on special and setting filter
- if ( $event->Special == 'custom-special' ) {
+ # identifying event based on special and setting filter
+ if ( $event->Special == 'custom-special' ) {
// $object->addFilter('primary_filter', '%1$s.Status = ' . STATUS_DISABLED);
- }
}
+ }
- /**
- * Occurs before creating item
- *
- * @param kEvent $event
- * @return void
- * @access protected
- */
- protected function OnBeforeItemCreate(kEvent $event)
- {
- parent::OnBeforeItemCreate($event);
+ /**
+ * Occurs before creating item
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnBeforeItemCreate(kEvent $event)
+ {
+ parent::OnBeforeItemCreate($event);
- }
+ }
- /**
- * Occurs before updating item
- *
- * @param kEvent $event
- * @return void
- * @access protected
- */
- protected function OnBeforeItemUpdate(kEvent $event)
- {
- parent::OnBeforeItemUpdate($event);
+ /**
+ * Occurs before updating item
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnBeforeItemUpdate(kEvent $event)
+ {
+ parent::OnBeforeItemUpdate($event);
- }
+ }
- /**
- * Occurs before deleting item, id of item being
- * deleted is stored as 'id' event param
- *
- * @param kEvent $event
- * @return void
- * @access protected
- */
- protected function OnBeforeItemDelete(kEvent $event)
- {
- parent::OnBeforeItemDelete($event);
+ /**
+ * Occurs before deleting item, id of item being
+ * deleted is stored as 'id' event param
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnBeforeItemDelete(kEvent $event)
+ {
+ parent::OnBeforeItemDelete($event);
- }
+ }
- /**
- * Occurs before loading item, 'id' parameter
- * allows to get id of item being loaded
- *
- * @param kEvent $event
- * @return void
- * @access protected
- */
- protected function OnBeforeItemLoad(kEvent $event)
- {
- parent::OnBeforeItemLoad($event);
+ /**
+ * Occurs before loading item, 'id' parameter
+ * allows to get id of item being loaded
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnBeforeItemLoad(kEvent $event)
+ {
+ parent::OnBeforeItemLoad($event);
- }
+ }
- /**
- * Occurs after creating item
- *
- * @param kEvent $event
- * @return void
- * @access protected
- */
- protected function OnAfterItemCreate(kEvent $event)
- {
- parent::OnAfterItemCreate($event);
+ /**
+ * Occurs after creating item
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnAfterItemCreate(kEvent $event)
+ {
+ parent::OnAfterItemCreate($event);
- }
+ }
- /**
- * Occurs after updating item
- *
- * @param kEvent $event
- * @return void
- * @access protected
- */
- protected function OnAfterItemUpdate(kEvent $event)
- {
- parent::OnAfterItemUpdate($event);
+ /**
+ * Occurs after updating item
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnAfterItemUpdate(kEvent $event)
+ {
+ parent::OnAfterItemUpdate($event);
- }
+ }
- /**
- * Occurs after deleting item, id of deleted item
- * is stored as 'id' param of event
- *
- * @param kEvent $event
- * @return void
- * @access protected
- */
- protected function OnAfterItemDelete(kEvent $event)
- {
- parent::OnAfterItemDelete($event);
+ /**
+ * Occurs after deleting item, id of deleted item
+ * is stored as 'id' param of event
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnAfterItemDelete(kEvent $event)
+ {
+ parent::OnAfterItemDelete($event);
- }
+ }
- /**
- * Loads user images
- *
- * @param kEvent $event
- * @return void
- * @access protected
- */
- protected function OnAfterItemLoad(kEvent $event)
- {
- parent::OnAfterItemLoad($event);
+ /**
+ * Loads user images
+ *
+ * @param kEvent $event
+ * @return void
+ * @access protected
+ */
+ protected function OnAfterItemLoad(kEvent $event)
+ {
+ parent::OnAfterItemLoad($event);
+ }
+
+ /**
+ * Builds/parses widget part of url
+ *
+ * @param int $rewrite_mode Mode in what rewrite listener was called. Possbile two modes: REWRITE_MODE_BUILD, REWRITE_MODE_PARSE.
+ * @param string $prefix Prefix, that listener uses for system integration
+ * @param Array $params Params, that are used for url building or created during url parsing.
+ * @param Array $url_parts Url parts to parse (only for parsing).
+ * @param bool $keep_events Keep event names in resulting url (only for building).
+ * @return bool Return true to continue to next listener; return false (when building) not to rewrite given prefix; return false (when parsing) to stop processing at this listener.
+ */
+ function WidgetRewriteListener($rewrite_mode = REWRITE_MODE_BUILD, $prefix, &$params, &$url_parts, $keep_events = false)
+ {
+ if ($rewrite_mode == REWRITE_MODE_BUILD) {
+ return $this->WidgetRewriteBuilder($rewrite_mode, $prefix, $params, $url_parts, $keep_events);
}
- /**
- * Builds/parses widget part of url
- *
- * @param int $rewrite_mode Mode in what rewrite listener was called. Possbile two modes: REWRITE_MODE_BUILD, REWRITE_MODE_PARSE.
- * @param string $prefix Prefix, that listener uses for system integration
- * @param Array $params Params, that are used for url building or created during url parsing.
- * @param Array $url_parts Url parts to parse (only for parsing).
- * @param bool $keep_events Keep event names in resulting url (only for building).
- * @return bool Return true to continue to next listener; return false (when building) not to rewrite given prefix; return false (when parsing) to stop processing at this listener.
- */
- function WidgetRewriteListener($rewrite_mode = REWRITE_MODE_BUILD, $prefix, &$params, &$url_parts, $keep_events = false)
- {
- if ($rewrite_mode == REWRITE_MODE_BUILD) {
- return $this->WidgetRewriteBuilder($rewrite_mode, $prefix, $params, $url_parts, $keep_events);
- }
+ if ($rewrite_mode == REWRITE_MODE_PARSE) {
+ return $this->WidgetRewriteParser($rewrite_mode, $prefix, $params, $url_parts);
+ }
- if ($rewrite_mode == REWRITE_MODE_PARSE) {
- return $this->WidgetRewriteParser($rewrite_mode, $prefix, $params, $url_parts);
- }
+ return true;
+ }
- return true;
+ /**
+ * Builds/parses widget part of url
+ *
+ * @param int $rewrite_mode Mode in what rewrite listener was called. Possbile two modes: REWRITE_MODE_BUILD, REWRITE_MODE_PARSE.
+ * @param string $prefix Prefix, that listener uses for system integration
+ * @param Array $params Params, that are used for url building or created during url parsing.
+ * @param Array $url_parts Url parts to parse (only for parsing).
+ * @param bool $keep_events Keep event names in resulting url (only for building).
+ * @return bool Return true to continue to next listener; return false (when building) not to rewrite given prefix; return false (when parsing) to stop processing at this listener.
+ */
+ function WidgetRewriteBuilder($rewrite_mode = REWRITE_MODE_BUILD, $prefix, &$params, &$url_parts, $keep_events = false)
+ {
+ $template = $this->Application->getPhysicalTemplate($params['t']);
+
+ if ( $template == 'widgets/widget_detail' ) {
+ // this is default template for this prefix, so don't add it to resulting url
+ $params['pass_template'] = false;
}
- /**
- * Builds/parses widget part of url
- *
- * @param int $rewrite_mode Mode in what rewrite listener was called. Possbile two modes: REWRITE_MODE_BUILD, REWRITE_MODE_PARSE.
- * @param string $prefix Prefix, that listener uses for system integration
- * @param Array $params Params, that are used for url building or created during url parsing.
- * @param Array $url_parts Url parts to parse (only for parsing).
- * @param bool $keep_events Keep event names in resulting url (only for building).
- * @return bool Return true to continue to next listener; return false (when building) not to rewrite given prefix; return false (when parsing) to stop processing at this listener.
- */
- function WidgetRewriteBuilder($rewrite_mode = REWRITE_MODE_BUILD, $prefix, &$params, &$url_parts, $keep_events = false)
- {
- if ($params['t'] == 'widgets/widget_detail') {
- // this is default template for this prefix, so don't add it to resulting url
- $params['pass_template'] = false;
- }
+ $rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor');
+ /* @var $rewrite_processor kRewriteUrlProcessor */
- $rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor');
- /* @var $rewrite_processor kRewriteUrlProcessor */
+ $processed_params = $rewrite_processor->getProcessedParams($prefix, $params, $keep_events);
- $processed_params = $rewrite_processor->getProcessedParams($prefix, $params, $keep_events);
+ if ( $processed_params === false ) {
+ return '';
+ }
- if ($processed_params === false) {
- return '';
- }
+ $ret = Array ('', '');
- $ret = Array ('', '');
+ $filename = isset($params[$prefix . '_filename']) ? $params[$prefix . '_filename'] : $this->Application->GetVar($prefix . '_filename');
+ unset($params[$prefix . '_filename']);
- if ($processed_params[$prefix . '_id'] > 0) {
- // add id
+ if ( $processed_params[$prefix . '_id'] > 0 ) {
+ // add id
+ if ( !$filename ) {
$sql = 'SELECT Title
FROM ' . TABLE_PREFIX . 'Widgets
WHERE WidgetId = ' . $processed_params[$prefix . '_id'];
- $ret[0] .= 'widgets/' . $this->Conn->GetOne($sql) . '/';
- } elseif ($processed_params[$prefix . '_Page'] > 1) {
- // add page, only when ID is missing
- $ret[1] .= $processed_params[$prefix . '_Page'] . '/';
+ $filename = $this->Conn->GetOne($sql);
}
- $ret[0] = rtrim($ret[0], '/');
- $ret[1] = rtrim($ret[1], '/');
-
- return array_map('mb_strtolower', $ret);
+ $ret[0] .= 'widgets/' . $filename . '/';
}
+ elseif ( $processed_params[$prefix . '_Page'] > 1 ) {
+ // add page, only when ID is missing
+ $ret[1] .= $processed_params[$prefix . '_Page'] . '/';
+ }
- /**
- * Builds/parses widget part of url
- *
- * @param int $rewrite_mode Mode in what rewrite listener was called. Possbile two modes: REWRITE_MODE_BUILD, REWRITE_MODE_PARSE.
- * @param string $prefix Prefix, that listener uses for system integration
- * @param Array $params Params, that are used for url building or created during url parsing.
- * @param Array $url_parts Url parts to parse (only for parsing).
- * @return bool Return true to continue to next listener; return false (when building) not to rewrite given prefix; return false (when parsing) to stop processing at this listener.
- */
- function WidgetRewriteParser($rewrite_mode = REWRITE_MODE_BUILD, $prefix, &$params, &$url_parts)
- {
- if ($url_parts[0] == 'widgets') {
- $sql = 'SELECT WidgetId
- FROM ' . TABLE_PREFIX . 'Widgets
- WHERE Title = ' . $this->Conn->qstr($url_parts[1]);
- $id = $this->Conn->GetOne($sql);
- $to_parse = $url_parts;
+ $ret[0] = rtrim($ret[0], '/');
+ $ret[1] = rtrim($ret[1], '/');
- $rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor');
- /* @var $rewrite_processor kRewriteUrlProcessor */
+ return array_map('mb_strtolower', $ret);
+ }
- if ($id > 0) {
- // id found
- $rewrite_processor->partParsed($url_parts[0]);
- $rewrite_processor->partParsed($url_parts[1]);
+ /**
+ * Builds/parses widget part of url
+ *
+ * @param int $rewrite_mode Mode in what rewrite listener was called. Possbile two modes: REWRITE_MODE_BUILD, REWRITE_MODE_PARSE.
+ * @param string $prefix Prefix, that listener uses for system integration
+ * @param Array $params Params, that are used for url building or created during url parsing.
+ * @param Array $url_parts Url parts to parse (only for parsing).
+ * @return bool Return true to continue to next listener; return false (when building) not to rewrite given prefix; return false (when parsing) to stop processing at this listener.
+ */
+ function WidgetRewriteParser($rewrite_mode = REWRITE_MODE_BUILD, $prefix, &$params, &$url_parts)
+ {
+ $widget_id = 0;
+ $widget_filename = '';
+ $widget_index = array_search('widgets', $url_parts);
- $params[$prefix . '_id'] = $id;
- $to_parse = array_slice($to_parse, 2); // cut off first two parts - "widgets/<widget+name>"
- $params['pass'][] = $prefix; // otherwise this prefix won't passed when pass="all" parameter used
- }
+ if ( $widget_index !== false && isset($url_parts[$widget_index + 1]) ) {
+ $widget_filename = $url_parts[$widget_index + 1];
+ }
- $template = implode('/', $to_parse);
+ $rewrite_processor = $this->Application->recallObject('kRewriteUrlProcessor');
+ /* @var $rewrite_processor kRewriteUrlProcessor */
- if ($template) {
- // let others guess what template is
- return true;
- }
+ if ( $widget_filename ) {
+ $sql = 'SELECT WidgetId
+ FROM ' . TABLE_PREFIX . 'Widgets
+ WHERE Title = ' . $this->Conn->qstr($widget_filename);
+ $widget_id = $this->Conn->GetOne($sql);
- // template missing -> set default
- $params['t'] = 'widgets/widget_detail';
- return false;
+ if ( $widget_id ) {
+ $params[$this->Prefix . '_id'] = $widget_id;
+ $params[$this->Prefix . '_filename'] = $widget_filename;
+ $params['pass'][] = $this->Prefix;
+
+ $rewrite_processor->partParsed('widgets');
+ $rewrite_processor->partParsed($widget_filename);
}
+ }
- return true;
+ if ( $widget_id && !$rewrite_processor->moreToParse() ) {
+ // widget was last url part - use default template
+ $params['t'] = 'widgets/widget_detail';
}
- }
\ No newline at end of file
+
+ return true;
+ }
+}
\ No newline at end of file
Index: custom/units/widgets/widget_tp.php
===================================================================
--- custom/units/widgets/widget_tp.php (revision 15331)
+++ custom/units/widgets/widget_tp.php (working copy)
@@ -1,47 +1,66 @@
<?php
+defined('FULL_PATH') or die('restricted access!');
- defined('FULL_PATH') or die('restricted access!');
+/**
+ * Widgets Tag Processor (sample)
+ *
+ */
+class WidgetTagProcessor extends kDBTagProcessor {
/**
- * Widgets Tag Processor (sample)
+ * Custom tag to output "Hello World!"
*
+ * @param Array $params
+ * @return string
*/
- class WidgetTagProcessor extends kDBTagProcessor {
+ function NewTag($params)
+ {
+ return 'Hello world!';
+ }
- /**
- * Custom tag to output "Hello World!"
- *
- * @param Array $params
- * @return string
- */
- function NewTag($params)
- {
- return 'Hello world!';
- }
+ /**
+ * Returns a link for editing product
+ *
+ * @param Array $params
+ * @return string
+ */
+ function ItemEditLink($params)
+ {
+ $object = $this->getObject($params);
+ /* @var $object kDBList */
- /**
- * Returns a link for editing product
- *
- * @param Array $params
- * @return string
- */
- function ItemEditLink($params)
- {
- $object = $this->getObject($params);
- /* @var $object kDBList */
+ $edit_template = $this->Application->getUnitOption($this->Prefix, 'AdminTemplatePath') . '/' . $this->Application->getUnitOption($this->Prefix, 'AdminTemplatePrefix') . 'edit';
- $edit_template = $this->Application->getUnitOption($this->Prefix, 'AdminTemplatePath') . '/' . $this->Application->getUnitOption($this->Prefix, 'AdminTemplatePrefix') . 'edit';
+ $url_params = Array (
+ 'm_opener' => 'd',
+ $this->Prefix.'_mode' => 't',
+ $this->Prefix.'_event' => 'OnEdit',
+ $this->Prefix.'_id' => $object->GetID(),
+ 'pass' => 'all,'.$this->Prefix,
+ 'no_pass_through' => 1,
+ );
- $url_params = Array (
- 'm_opener' => 'd',
- $this->Prefix.'_mode' => 't',
- $this->Prefix.'_event' => 'OnEdit',
- $this->Prefix.'_id' => $object->GetID(),
- 'pass' => 'all,'.$this->Prefix,
- 'no_pass_through' => 1,
- );
+ return $this->Application->HREF($edit_template, '', $url_params);
+ }
- return $this->Application->HREF($edit_template, '', $url_params);
- }
- }
\ No newline at end of file
+ /**
+ * Creates link to an item including only it's id
+ *
+ * @param Array $params
+ * @return string
+ * @access protected
+ */
+ protected function ItemLink($params)
+ {
+ $object = $this->getObject($params);
+ /* @var $object kDBItem */
+
+ $params['pass'] = 'm,' . $this->Prefix;
+ $params[$object->Prefix . '_id'] = $object->GetID();
+ $params[$object->Prefix . '_filename'] = $object->GetDBField('Title');
+
+ return $this->Application->ProcessParsedTag('m', 'Link', $params);
+ }
+
+}
\ No newline at end of file