Index: units/widgets/widget_eh.php =================================================================== --- units/widgets/widget_eh.php (revision 13128) +++ units/widgets/widget_eh.php (working copy) @@ -180,65 +180,96 @@ function WidgetRewriteListener($rewrite_mode = REWRITE_MODE_BUILD, $prefix, &$params, &$url_parts, $keep_events = false) { if ($rewrite_mode == REWRITE_MODE_BUILD) { - 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; - } + return $this->WidgetRewriteBuilder($rewrite_mode, $prefix, $params, $url_parts, $keep_events); + } - $mod_rewrite_helper =& $this->Application->recallObject('ModRewriteHelper'); - /* @var $mod_rewrite_helper kModRewriteHelper */ + if ($rewrite_mode == REWRITE_MODE_PARSE) { + return $this->WidgetRewriteParser($rewrite_mode, $prefix, $params, $url_parts); + } - $processed_params = $mod_rewrite_helper->getProcessedParams($prefix, $params, $keep_events); + return true; + } - if ($processed_params === false) { - return ''; - } + /** + * 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; + } - $ret = Array ('', ''); + $mod_rewrite_helper =& $this->Application->recallObject('ModRewriteHelper'); + /* @var $mod_rewrite_helper kModRewriteHelper */ - if ($processed_params[$prefix . '_id'] > 0) { - // add id - $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'] . '/'; - } + $processed_params = $mod_rewrite_helper->getProcessedParams($prefix, $params, $keep_events); - $ret[0] = rtrim($ret[0], '/'); - $ret[1] = rtrim($ret[1], '/'); + if ($processed_params === false) { + return ''; + } - return array_map('mb_strtolower', $ret); + $ret = Array ('', ''); + + if ($processed_params[$prefix . '_id'] > 0) { + // add id + $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'] . '/'; } - if ($rewrite_mode == REWRITE_MODE_PARSE) { - 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], '/'); - if ($id > 0) { - // id found - $params[$prefix . '_id'] = $id; - $to_parse = array_slice($to_parse, 2); // cut off first two parts - "widgets/" - $params['pass'][] = $prefix; // otherwise this prefix won't passed when pass="all" parameter used - } + return array_map('mb_strtolower', $ret); + } - $template = implode('/', $to_parse); + /** + * 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; - if ($template) { - // let others guess what template is - return true; - } + if ($id > 0) { + // id found + $params[$prefix . '_id'] = $id; + $to_parse = array_slice($to_parse, 2); // cut off first two parts - "widgets/" + $params['pass'][] = $prefix; // otherwise this prefix won't passed when pass="all" parameter used + } - // template missing -> set default - $params['t'] = 'widgets/widget_detail'; - return false; + $template = implode('/', $to_parse); + + if ($template) { + // let others guess what template is + return true; } + + // template missing -> set default + $params['t'] = 'widgets/widget_detail'; + return false; } return true; Index: units/widgets/widgets_config.php =================================================================== --- units/widgets/widgets_config.php (revision 13128) +++ units/widgets/widgets_config.php (working copy) @@ -7,7 +7,7 @@ * @package Development Kit */ -defined('FULL_PATH') or die('restricted access!'); + defined('FULL_PATH') or die('restricted access!'); $config = Array( @@ -28,8 +28,12 @@ 4 => 'mode', ), + // in case, when one method does everything 'RewriteListener' => 'WidgetRewriteListener', + // in case, when building and parsing is done by separate methods +// 'RewriteListener' => Array ('WidgetRewriteBuilder', 'WidgetRewriteParser'), + 'IDField' => 'WidgetId', 'StatusField' => Array ('Status'), @@ -43,7 +47,7 @@ 'AutoDelete' => true, // delete these items when parent is being deleted 'AutoClone' => true, // clone these items when parent is being cloned */ - + // used to build editing links in admin grids 'AdminTemplatePath' => 'widgets', 'AdminTemplatePrefix' => 'widget_', @@ -65,9 +69,9 @@ 'toolbar_buttons' => Array ('select', 'cancel', 'reset_edit', 'prev', 'next'), ), ), - - + + 'PermSection' => Array('main' => 'custom:widgets'), 'Sections' => Array ( @@ -101,8 +105,8 @@ 'Sorting' => Array ('Title' => 'asc'), ) ), - - 'VirtualFields' => Array ( + + 'VirtualFields' => Array ( 'VirtualActionField' => Array ('type' => 'string', 'default' => ''), ), @@ -179,7 +183,7 @@ // 'Icons' => Array ('default' => 'icon16_custom.gif'), 'Fields' => Array ( 'WidgetId' => Array ('title' => 'la_col_Id', 'data_block' => 'grid_checkbox_td', 'filter_block' => 'grid_range_filter'), - 'Title' => Array ('title' => 'la_col_Name', 'data_block' => 'grid_custom_td'), + 'Title' => Array ('title' => 'la_col_Name', 'data_block' => 'grid_custom_td'), 'Image' => Array ('title' => 'la_col_Image', 'data_block' => 'grid_image_td'), 'Type' => Array ('title' => 'la_col_Type', 'filter_block' => 'grid_options_filter'), 'Status' => Array ('title' => 'la_col_Status', 'filter_block' => 'grid_options_filter'),