Attached Files |
event_redirect_settings_works_with_opener_stack.patch [^] (6,202 bytes) 2011-10-15 13:41
[Show Content]
Index: kernel/application.php
===================================================================
--- kernel/application.php (revision 14664)
+++ kernel/application.php (working copy)
@@ -49,12 +49,13 @@
var $HTML;
/**
- * Prevents request from beeing proceeded twice in case if application init is called mere then one time
+ * Prevents request from being proceeded twice in case if application init is called mere then one time
*
* @var bool
+ * @access protected
* @todo This is not good anyway (by Alex)
*/
- var $RequestProcessed = false;
+ protected $RequestProcessed = false;
/**
* The main Factory used to create
@@ -946,11 +947,11 @@
*/
function Run()
{
- if (defined('DEBUG_MODE') && $this->isDebugMode() && kUtil::constOn('DBG_PROFILE_MEMORY')) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() && kUtil::constOn('DBG_PROFILE_MEMORY') ) {
$this->Debugger->appendMemoryUsage('Application before Run:');
}
- if ($this->isAdminUser) {
+ if ( $this->isAdminUser ) {
// for permission checking in events & templates
$this->LinkVar('module'); // for common configuration templates
$this->LinkVar('module_key'); // for common search templates
@@ -966,7 +967,7 @@
kUtil::safeDefine('DBG_SKIP_REPORTING', 1); // safeDefine, because debugger also defines it
}
}
- elseif ($this->GetVar('admin')) {
+ elseif ( $this->GetVar('admin') ) {
// viewing front-end through admin's frame
$admin_session =& $this->recallObject('Session.admin');
/* @var $admin_session Session */
@@ -976,7 +977,7 @@
$perm_helper =& $this->recallObject('PermissionsHelper');
/* @var $perm_helper kPermissionsHelper */
- if ($perm_helper->CheckUserPermission($user, 'CATEGORY.MODIFY', 0, $this->getBaseCategory())) {
+ if ( $perm_helper->CheckUserPermission($user, 'CATEGORY.MODIFY', 0, $this->getBaseCategory()) ) {
// user can edit cms blocks
$editing_mode = $this->GetVar('editing_mode');
define('EDITING_MODE', $editing_mode ? $editing_mode : EDITING_MODE_BROWSE);
@@ -986,18 +987,20 @@
kUtil::safeDefine('EDITING_MODE', ''); // user can't edit anything
$this->Phrases->setPhraseEditing();
- if (!$this->RequestProcessed) $this->ProcessRequest();
+ if ( !$this->RequestProcessed ) {
+ $this->ProcessRequest();
+ }
$this->InitParser();
$t = $this->GetVar('t');
- if (!$this->TemplatesCache->TemplateExists($t) && !$this->isAdmin) {
+ if ( !$this->TemplatesCache->TemplateExists($t) && !$this->isAdmin ) {
$cms_handler =& $this->recallObject('st_EventHandler');
/* @var $cms_handler CategoriesEventHandler */
$t = ltrim($cms_handler->GetDesignTemplate(), '/');
- if (defined('DEBUG_MODE') && $this->isDebugMode()) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() ) {
$this->Debugger->appendHTML('<strong>Design Template</strong>: ' . $t . '; <strong>CategoryID</strong>: ' . $this->GetVar('m_cat_id'));
}
}
@@ -1005,13 +1008,13 @@
$cms_handler->SetCatByTemplate();
}*/
- if (defined('DEBUG_MODE') && $this->isDebugMode() && kUtil::constOn('DBG_PROFILE_MEMORY')) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() && kUtil::constOn('DBG_PROFILE_MEMORY') ) {
$this->Debugger->appendMemoryUsage('Application before Parsing:');
}
$this->HTML = $this->Parser->Run($t);
- if (defined('DEBUG_MODE') && $this->isDebugMode() && kUtil::constOn('DBG_PROFILE_MEMORY')) {
+ if ( defined('DEBUG_MODE') && $this->isDebugMode() && kUtil::constOn('DBG_PROFILE_MEMORY') ) {
$this->Debugger->appendMemoryUsage('Application after Parsing:');
}
}
Index: kernel/event_manager.php
===================================================================
--- kernel/event_manager.php (revision 14664)
+++ kernel/event_manager.php (working copy)
@@ -326,18 +326,6 @@
}
/**
- * Allows to change last element in opener stack
- *
- * @param string $new_template
- * @param Array $new_params
- * @access public
- */
- public function openerStackChange($new_template = null, $new_params = null)
- {
- $this->Request->openerStackChange($new_template, $new_params);
- }
-
- /**
* Set's new event for $prefix_special
* passed
*
Index: kernel/managers/request_manager.php
===================================================================
--- kernel/managers/request_manager.php (revision 14664)
+++ kernel/managers/request_manager.php (working copy)
@@ -167,15 +167,22 @@
protected function performRedirect(&$event)
{
// we need to pass category if the action was submitted to self-template, with the category passed
- // and it has not explicitly set redirect template or pass_cateogry param
+ // and it has not explicitly set redirect template or pass_category param
if ( $this->samePageRedirect($event) && ($event->getEventParam('pass_category') === false) && $this->Application->GetVar('m_cat_id') ) {
$event->SetRedirectParam('pass_category', 1);
}
$wid = $this->Application->GetVar('m_wid');
+ $redirect_params = $event->getRedirectParams();
- if ($wid && $event->getRedirectParam('opener') == 'u') {
- $event->SetRedirectParam('opener', 's'); // because Application->HREF will react differently when 'opener' = 'u'
+ if ( $wid && $event->getRedirectParam('opener') == 'u' ) {
+ // update last element in current opener stack
+ unset($redirect_params['opener']);
+ $redirect_template = is_string($event->redirect) ? $event->redirect : null;
+ $this->openerStackChange($redirect_template, $redirect_params);
+
+ // reset opener, because kApplication::HREF will react differently when 'opener' => 'u'
+ $event->SetRedirectParam('opener', 's');
$event->redirect = defined('CLOSE_POPUP_TPL') ? CLOSE_POPUP_TPL : 'incs/close_popup';
}
@@ -413,9 +420,9 @@
*
* @param string $new_template
* @param Array $new_params
- * @access public
+ * @access protected
*/
- public function openerStackChange($new_template = null, $new_params = null)
+ protected function openerStackChange($new_template = null, $new_params = null)
{
$opener_stack =& $this->Application->makeClass('kOpenerStack');
/* @var $opener_stack kOpenerStack */
event_redirect_settings_works_with_opener_stack_addon.patch [^] (9,055 bytes) 2011-10-19 03:22
[Show Content]
Index: cat_event_handler.php
===================================================================
--- cat_event_handler.php (revision 14653)
+++ cat_event_handler.php (working copy)
@@ -17,7 +17,7 @@
class kCatDBEventHandler extends kDBEventHandler {
/**
- * Allows to override standart permission mapping
+ * Allows to override standard permission mapping
*
*/
function mapPermissions()
@@ -324,8 +324,9 @@
$ids = $this->StoreSelectedIDs($event);
$to_delete = Array ();
+ $recycle_bin = $this->Application->ConfigValue('RecycleBinFolder');
- if ( $recycle_bin = $this->Application->ConfigValue('RecycleBinFolder') ) {
+ if ( $recycle_bin ) {
$rb =& $this->Application->recallObject('c.recycle', null, array ('skip_autoload' => true));
/* @var $rb CategoriesItem */
@@ -420,9 +421,10 @@
'advanced' => 'OnAdvancedSearch'
);
+ $keywords = $event->getEventParam('keyword_string');
$type = $this->Application->GetVar('search_type', 'simple');
- if ($keywords = $event->getEventParam('keyword_string')) {
+ if ( $keywords ) {
// processing keyword_string param of ListProducts tag
$this->Application->SetVar('keywords', $keywords);
$type = 'simple';
@@ -521,7 +523,7 @@
$related_ids_array = $this->Conn->Query($sql);
$related_ids = Array();
- foreach ($related_ids_array as $key => $record) {
+ foreach ($related_ids_array as $record) {
$related_ids[] = $record[ $record['SourceId'] == $p_resource_id ? 'TargetId' : 'SourceId' ];
}
@@ -1145,7 +1147,9 @@
}
// processing fields from other tables
- if ($foreign_field = $search_config[$field]['ForeignField']) {
+ $foreign_field = $search_config[$field]['ForeignField'];
+
+ if ( $foreign_field ) {
$exploded = explode(':', $foreign_field, 2);
if ($exploded[0] == 'CALC') {
// ignoring having type clauses in simple search
@@ -1327,7 +1331,7 @@
WHERE '.$where_clause.'
GROUP BY '.$items_table.'.'.$this->Application->getUnitOption($event->Prefix, 'IDField').' ORDER BY Relevance DESC';
- $res = $this->Conn->Query($sql);
+ $this->Conn->Query($sql);
if ( !$search_table_exists ) {
$sql = 'ALTER TABLE ' . $search_table . '
@@ -1344,13 +1348,16 @@
*/
function OnSubSearch(&$event)
{
- $search_table = TABLE_PREFIX.'ses_'.$this->Application->GetSID().'_'.TABLE_PREFIX.'Search';
- $sql = 'SHOW TABLES LIKE "'.$search_table.'"';
- if($this->Conn->Query($sql))
- {
- $sql = 'SELECT DISTINCT ResourceId FROM '.$search_table;
+ $ids = Array ();
+ $search_table = TABLE_PREFIX . 'ses_' . $this->Application->GetSID() . '_' . TABLE_PREFIX . 'Search';
+ $sql = 'SHOW TABLES LIKE "' . $search_table . '"';
+
+ if ( $this->Conn->Query($sql) ) {
+ $sql = 'SELECT DISTINCT ResourceId
+ FROM ' . $search_table;
$ids = $this->Conn->GetCol($sql);
}
+
$event->setEventParam('ResultIds', $ids);
$event->CallSubEvent('OnSimpleSearch');
}
@@ -1434,7 +1441,9 @@
}
// processing fields from other tables
- if ($foreign_field = $record['ForeignField']) {
+ $foreign_field = $record['ForeignField'];
+
+ if ( $foreign_field ) {
$exploded = explode(':', $foreign_field, 2);
if($exploded[0] == 'CALC')
{
@@ -1642,7 +1651,7 @@
case 'boolean':
if ($keywords[$field] != -1) {
$property_mappings = $this->Application->getUnitOption($this->Prefix, 'ItemPropertyMappings');
- $items_table = $this->Application->getUnitOption($event->Prefix, 'TableName');
+ $items_table = $this->Application->getUnitOption($this->Prefix, 'TableName');
switch ($field) {
case 'HotItem':
@@ -1904,14 +1913,12 @@
if ($field_values['start_from'] == $field_values['total_records']) {
if ($event->Special == 'import') {
$this->Application->StoreVar('PermCache_UpdateRequired', 1);
- $url_params = Array(
- 't' => 'catalog/catalog',
- 'm_cat_id' => $this->Application->RecallVar('ImportCategory'),
- 'anchor' => 'tab-' . $event->Prefix,
- );
- $this->Application->EventManager->openerStackChange($url_params);
+ $event->SetRedirectParam('m_cat_id', $this->Application->RecallVar('ImportCategory'));
+ $event->SetRedirectParam('anchor', 'tab-' . $event->Prefix);
$event->SetRedirectParam('opener', 'u');
+
+ $event->redirect = 'catalog/catalog';
}
elseif ($event->Special == 'export') {
$event->redirect = $export_object->getModuleName($event) . '/' . $event->Special . '_finish';
@@ -2008,7 +2015,14 @@
}
}
- function isURL($path)
+ /**
+ * Detects if image url is specified in a given path (instead of path on disk)
+ *
+ * @param string $path
+ * @return bool
+ * @access protected
+ */
+ protected function isURL($path)
{
return preg_match('#(http|https)://(.*)#', $path);
}
@@ -2055,12 +2069,8 @@
// Tools -> Import -> Item Import -> Select Import Category
$this->Application->StoreVar('ImportCategory', $selected_ids['c']);
- $url_params = Array (
- $event->getPrefixSpecial() . '_id' => 0,
- $event->getPrefixSpecial() . '_event' => 'OnExportBegin',
- );
-
- $this->Application->EventManager->openerStackChange($url_params);
+ $event->SetRedirectParam($event->getPrefixSpecial() . '_id', 0);
+ $event->SetRedirectParam($event->getPrefixSpecial() . '_event', 'OnExportBegin');
}
$event->SetRedirectParam('opener', 'u');
@@ -2368,6 +2378,7 @@
* Adds new and removes old additional categories from category item
*
* @param kCatDBItem $object
+ * @param int $mode
*/
function processAdditionalCategories(&$object, $mode)
{
@@ -2501,16 +2512,18 @@
*/
function SetFrontRedirectTemplate(&$event, $template_key)
{
- if ($this->Application->isAdminUser || $event->status != kEvent::erSUCCESS) {
- return ;
+ if ( $this->Application->isAdminUser || $event->status != kEvent::erSUCCESS ) {
+ return;
}
// prepare redirect template
$object =& $event->getObject();
+ /* @var $object kDBItem */
+
$is_active = ($object->GetDBField('Status') == STATUS_ACTIVE);
$next_template = $is_active ? 'confirm_template' : 'pending_confirm_template';
- $event->redirect = $this->Application->GetVar($template_key.'_'.$next_template);
+ $event->redirect = $this->Application->GetVar($template_key . '_' . $next_template);
$event->SetRedirectParam('opener', 's');
// send email events
@@ -2518,18 +2531,18 @@
$owner_field = $this->getOwnerField($event->Prefix);
$owner_id = $object->GetDBField($owner_field);
- switch ($event->Name) {
+ switch ( $event->Name ) {
case 'OnCreate':
$event_suffix = $is_active ? 'ADD' : 'ADD.PENDING';
- $this->Application->EmailEventAdmin($perm_prefix.'.'.$event_suffix); // there are no ADD.PENDING event for admin :(
- $this->Application->EmailEventUser($perm_prefix.'.'.$event_suffix, $owner_id);
+ $this->Application->EmailEventAdmin($perm_prefix . '.' . $event_suffix); // there are no ADD.PENDING event for admin :(
+ $this->Application->EmailEventUser($perm_prefix . '.' . $event_suffix, $owner_id);
break;
case 'OnUpdate':
$event_suffix = $is_active ? 'MODIFY' : 'MODIFY.PENDING';
- $user_id = is_numeric( $object->GetDBField('ModifiedById') ) ? $object->GetDBField('ModifiedById') : $owner_id;
- $this->Application->EmailEventAdmin($perm_prefix.'.'.$event_suffix); // there are no ADD.PENDING event for admin :(
- $this->Application->EmailEventUser($perm_prefix.'.'.$event_suffix, $user_id);
+ $user_id = is_numeric($object->GetDBField('ModifiedById')) ? $object->GetDBField('ModifiedById') : $owner_id;
+ $this->Application->EmailEventAdmin($perm_prefix . '.' . $event_suffix); // there are no ADD.PENDING event for admin :(
+ $this->Application->EmailEventUser($perm_prefix . '.' . $event_suffix, $user_id);
break;
}
}
@@ -2607,7 +2620,9 @@
function checkItemStatus(&$event)
{
$object =& $event->getObject();
- if (!$object->isLoaded()) {
+ /* @var $object kDBItem */
+
+ if ( !$object->isLoaded() ) {
$this->_errorNotFound($event);
return true;
@@ -2617,7 +2632,7 @@
$user_id = $this->Application->RecallVar('user_id');
$owner_field = $this->getOwnerField($event->Prefix);
- if (($status == STATUS_PENDING_EDITING || $status == STATUS_PENDING) && ($object->GetDBField($owner_field) == $user_id)) {
+ if ( ($status == STATUS_PENDING_EDITING || $status == STATUS_PENDING) && ($object->GetDBField($owner_field) == $user_id) ) {
return true;
}
@@ -2656,14 +2671,16 @@
return parent::getPerPage($event);
}
- function getOwnerField($prefix)
+ /**
+ * Returns owner field for given prefix
+ *
+ * @param $prefix
+ * @return string
+ * @access protected
+ */
+ protected function getOwnerField($prefix)
{
- $owner_field = $this->Application->getUnitOption($prefix, 'OwnerField');
- if (!$owner_field) {
- $owner_field = 'CreatedById';
- }
-
- return $owner_field;
+ return $this->Application->getUnitOption($prefix, 'OwnerField', 'CreatedById');
}
/**
opener_stack_change_fix.patch [^] (2,008 bytes) 2011-11-04 13:02
[Show Content]
Index: kernel/managers/request_manager.php
===================================================================
--- kernel/managers/request_manager.php (revision 14705)
+++ kernel/managers/request_manager.php (working copy)
@@ -152,6 +152,7 @@
return $false;
}
+ $event->SetRedirectParam('opener', 's'); // stay on same page after event is called
$event->setEventParam('top_prefix', $this->Application->GetTopmostPrefix($event->Prefix, true));
$event_handler =& $this->Application->recallObject($event->Prefix . '_EventHandler');
@@ -217,6 +218,11 @@
$event->redirect = defined('CLOSE_POPUP_TPL') ? CLOSE_POPUP_TPL : 'incs/close_popup';
}
+ if ( $event->getRedirectParam('pass') === false ) {
+ // pass all discovered units to redirected page unless developer decided otherwise
+ $event->SetRedirectParam('pass', 'all');
+ }
+
$this->Application->Redirect($event->redirect, $event->getRedirectParams(), '', $event->redirectScript);
}
@@ -468,6 +474,11 @@
$params = array_merge($params, $new_params);
}
+ if ( !isset($params['pass_events']) ) {
+ // don't pass events, unless requested
+ $params['pass_events'] = false;
+ }
+
$opener_stack->push($template, $params, $index_file);
$opener_stack->save();
}
Index: kernel/utility/event.php
===================================================================
--- kernel/utility/event.php (revision 14705)
+++ kernel/utility/event.php (working copy)
@@ -89,15 +89,12 @@
public $redirect = true;
/**
- * Params, used during redirect url building after event succsessfull processing
+ * Params, used during redirect url building after event successful processing
*
* @var bool
* @access private
*/
- private $redirectParams = Array (
- 'opener' => 's', // redirect to given template
- 'pass' => 'all' // pass all discovered units to redirected page
- );
+ private $redirectParams = Array ();
/**
* PHP file to redirect to. Defaults to "index.php"
opener_stack_change_another_fix.patch [^] (2,911 bytes) 2011-12-21 06:33
[Show Content]
Index: admin_templates/incs/close_popup.tpl
===================================================================
--- admin_templates/incs/close_popup.tpl (revision 14888)
+++ admin_templates/incs/close_popup.tpl (working copy)
@@ -12,7 +12,7 @@
var $modal_windows = <inp2:m_if check="adm_UsePopups" mode="modal">true<inp2:m_else/>false</inp2:m_if>;
if ($is_debug) {
- document.write('<a href="#" onclick="proceed_redirect()">' + $redirect_url.replace('%5C', '\\') + '</a>');
+ document.write('<a href="#" onclick="proceed_redirect()">' + $redirect_url.replace(/%5C/g, '\\') + '</a>');
}
else {
proceed_redirect();
@@ -43,7 +43,7 @@
}
else if (!$use_popups) {
// not using popups (for editing), but close_popup called (e.g. from selector)
- window.location.href = $redirect_url.replace('%5C', '\\');
+ window.location.href = $redirect_url.replace(/%5C/g, '\\');
}
}
Index: admin_templates/js/script.js
===================================================================
--- admin_templates/js/script.js (revision 14888)
+++ admin_templates/js/script.js (working copy)
@@ -1817,7 +1817,7 @@
// setTimeout allows to call method indirectly. Without it whole idea won't work 2nd time (try adding 2 relations one after another)
setTimeout(
function() {
- openSelector('adm', $ru.replace('%5C', '\\') + '&merge_opener_stack=1');
+ openSelector('adm', $ru.replace(/%5C/g, '\\') + '&merge_opener_stack=1');
},
200
);
@@ -1828,7 +1828,7 @@
window.focus();
if ( !(($force_skip_refresh === true) || (typeof $skip_refresh != 'undefined' && $skip_refresh)) ) {
- window.location.href = $redirect_url.replace('%5C', '\\');
+ window.location.href = $redirect_url.replace(/%5C/g, '\\');
}
}
Index: kernel/utility/opener_stack.php
===================================================================
--- kernel/utility/opener_stack.php (revision 14888)
+++ kernel/utility/opener_stack.php (working copy)
@@ -130,12 +130,14 @@
return $this->data[$index];
}
- list ($index_file, $env) = explode('|', $this->data[$index], 2);
- $params = $this->Application->processQueryString($env, 'pass');
+ list ($index_file, $original_env) = explode('|', $this->data[$index], 2);
+ $fixed_env = str_replace(Array ('&', '%5C'), Array ('&', '\\'), $original_env);
+ $params = $this->Application->processQueryString($fixed_env, 'pass');
+
// detect "__URLENCODE__" parameter value, used when opener stack element was built
// without it rebuilding opener stack element will convert all "&" to "&" elements
- $params['__URLENCODE__'] = (strpos($env, '&') !== false && strpos($env, '&') === false) || (strpos($env, '\\') !== false && strpos($env, '%5C') === false) ? 1 : 0;
+ $params['__URLENCODE__'] = $original_env != $fixed_env ? 1 : 0;
$template = kUtil::popParam('t', $params, '');
opener_stack_urlencode_fix.patch [^] (862 bytes) 2011-12-28 14:22
[Show Content]
Index: opener_stack.php
===================================================================
--- opener_stack.php (revision 14917)
+++ opener_stack.php (working copy)
@@ -131,13 +131,12 @@
}
list ($index_file, $original_env) = explode('|', $this->data[$index], 2);
-
$fixed_env = str_replace(Array ('&', '%5C'), Array ('&', '\\'), $original_env);
+
$params = $this->Application->processQueryString($fixed_env, 'pass');
- // detect "__URLENCODE__" parameter value, used when opener stack element was built
- // without it rebuilding opener stack element will convert all "&" to "&" elements
- $params['__URLENCODE__'] = $original_env != $fixed_env ? 1 : 0;
+ // opener stack is used from JavaScript / redirecting, so any "&" could break it
+ $params['__URLENCODE__'] = 1;
$template = kUtil::popParam('t', $params, '');
|