// Hook modules exceptions now works with new dispatcher

This commit is contained in:
rMalie committed 2011-07-11 15:16:16 +00:00
1 parent 139bb84f87
commit 502942002d
3 files changed
+68 -24

No files matched your search

+57 -12
View File
@@ -126,7 +126,7 @@ class AdminModulesPositions extends AdminTab
$this->_errors[] = Tools::displayError('No valid value for field exceptions'); $this->_errors[] = Tools::displayError('No valid value for field exceptions');
// Add files exceptions // Add files exceptions
if (!$module->editExceptions($id_hook, $exception, array($id))) if (!$module->editExceptions($id_hook, $exception, Shop::getListFromContext()))
$this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.'); $this->_errors[] = Tools::displayError('An error occurred while transplanting module to hook.');
} }
@@ -320,7 +320,6 @@ class AdminModulesPositions extends AdminTab
'.($instance->version ? ' v'.((int)($instance->version) == $instance->version? sprintf('%.1f', $instance->version) : (float)($instance->version)) : '').'<br />'.$instance->description.' '.($instance->version ? ' v'.((int)($instance->version) == $instance->version? sprintf('%.1f', $instance->version) : (float)($instance->version)) : '').'<br />'.$instance->description.'
</label></td> </label></td>
<td width="60">'; <td width="60">';
if ($canMove)
echo ' echo '
<a href="'.$currentIndex.'&id_module='.$instance->id.'&id_hook='.$hook['id_hook'].'&editGraft'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token.'"><img src="../img/admin/edit.gif" border="0" alt="'.$this->l('Edit').'" title="'.$this->l('Edit').'" /></a> <a href="'.$currentIndex.'&id_module='.$instance->id.'&id_hook='.$hook['id_hook'].'&editGraft'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token.'"><img src="../img/admin/edit.gif" border="0" alt="'.$this->l('Edit').'" title="'.$this->l('Edit').'" /></a>
<a href="'.$currentIndex.'&id_module='.$instance->id.'&id_hook='.$hook['id_hook'].'&deleteGraft'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token.'"><img src="../img/admin/delete.gif" border="0" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a> <a href="'.$currentIndex.'&id_module='.$instance->id.'&id_hook='.$hook['id_hook'].'&deleteGraft'.($this->displayKey ? '&show_modules='.$this->displayKey : '').'&token='.$this->token.'"><img src="../img/admin/delete.gif" border="0" alt="'.$this->l('Delete').'" title="'.$this->l('Delete').'" /></a>
@@ -409,15 +408,44 @@ class AdminModulesPositions extends AdminTab
echo ' echo '
</select><sup> *</sup> </select><sup> *</sup>
</div>'; </div>';
echo <<<EOF
<script type="text/javascript">
//<![CDATA
function position_exception_add(shopID)
{
var listValue = $('#em_list_'+shopID).val();
var inputValue = $('#em_text_'+shopID).val();
var r = new RegExp('(^|,) *'+listValue+' *(,|$)');
if (!r.test(inputValue))
$('#em_text_'+shopID).val(inputValue + ((inputValue.trim()) ? ', ' : '') + listValue);
}
function position_exception_remove(shopID)
{
var listValue = $('#em_list_'+shopID).val();
var inputValue = $('#em_text_'+shopID).val();
var r = new RegExp('(^|,) *'+listValue+' *(,|$)');
if (r.test(inputValue))
{
var rep = '';
if (new RegExp(listValue+' *,').test(inputValue))
rep = ',';
$('#em_text_'+shopID).val(inputValue.replace(r, rep));
}
}
//]]>
</script>
EOF;
// Manage exceptions // Manage exceptions
if (!$exceptsDiff) if (!$exceptsDiff)
{ {
echo '<label>'.$this->l('Exceptions').' :</label> echo '<label>'.$this->l('Exceptions').' :</label>
<div class="margin-form"> <div class="margin-form">';
<input type="text" name="exceptions" size="40" '.(!empty($excepts) ? 'value="'.$excepts.'"' : '').'><br />Ex: identity.php, history.php, order.php, product.php<br /><br /> $this->displayModuleExceptionList($excepts, 0);
'.$this->l('Please specify those files for which you do not want the module to be displayed').'.<br />
'.$this->l('These files are located in your base directory').', '.$this->l('e.g., ').' <b>identity.php</b>.<br /> echo $this->l('Please specify those files for which you do not want the module to be displayed').'.<br />
'.$this->l('Please type each filename separated by a comma').'. '.$this->l('Please type each filename separated by a comma').'.
<br /><br /> <br /><br />
</div>'; </div>';
@@ -428,13 +456,9 @@ class AdminModulesPositions extends AdminTab
<div class="margin-form">'; <div class="margin-form">';
foreach ($exceptsList as $shopID => $fileList) foreach ($exceptsList as $shopID => $fileList)
{ {
echo '<input type="text" name="exceptions['.$shopID.']" size="40" value="' . implode(', ', $fileList) . '">'; $this->displayModuleExceptionList($fileList, $shopID);
$shop = new Shop($shopID);
echo ' ('.htmlspecialchars($shop->name).')<br /><br />';
} }
echo 'Ex: identity.php, history.php, order.php, product.php<br /><br /> echo $this->l('Please specify those files for which you do not want the module to be displayed').'.<br />
'.$this->l('Please specify those files for which you do not want the module to be displayed').'.<br />
'.$this->l('These files are located in your base directory').', '.$this->l('e.g., ').' <b>identity.php</b>.<br />
'.$this->l('Please type each filename separated by a comma').'. '.$this->l('Please type each filename separated by a comma').'.
<br /><br /> <br /><br />
</div>'; </div>';
@@ -456,4 +480,25 @@ class AdminModulesPositions extends AdminTab
</fieldset> </fieldset>
</form>'; </form>';
} }
public function displayModuleExceptionList($fileList, $shopID)
{
if (!is_array($fileList))
$fileList = ($fileList) ? array($fileList) : array();
echo '<input type="text" name="exceptions['.$shopID.']" size="40" value="' . implode(', ', $fileList) . '" id="em_text_'.$shopID.'">';
if ($shopID)
echo ' ('.Shop::getInstance($shopID)->name.')';
echo '<br /><select id="em_list_'.$shopID.'">';
// @todo do something better with controllers
Dispatcher::loadControllers();
ksort(Dispatcher::$controllers);
foreach (Dispatcher::$controllers as $k => $v)
{
echo '<option value="'.$k.'">'.$k.'</option>';
}
echo '</select> <input type="button" class="button" value="'.$this->l('Add').'" onclick="position_exception_add('.$shopID.')" />
<input type="button" class="button" value="'.$this->l('Remove').'" onclick="position_exception_remove('.$shopID.')" /><br /><br />';
}
} }
+9 -9
View File
@@ -2,7 +2,7 @@
class DispatcherCore class DispatcherCore
{ {
public $controllers; public static $controllers = array();
public static $controller; public static $controller;
function __construct() function __construct()
@@ -15,24 +15,24 @@ class DispatcherCore
self::$controller = $this->getController(); self::$controller = $this->getController();
self::$controller = str_replace('-', '', strtolower(self::$controller)); self::$controller = str_replace('-', '', strtolower(self::$controller));
if (!isset($this->controllers[self::$controller])) if (!isset(self::$controllers[self::$controller]))
self::$controller = 'index'; self::$controller = 'index';
ControllerFactory::getController($this->controllers[self::$controller])->run(); ControllerFactory::getController(self::$controllers[self::$controller])->run();
} }
protected function loadControllers() public static function loadControllers()
{ {
$controller_files = scandir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'controllers'); $controller_files = scandir(_PS_ROOT_DIR_.DIRECTORY_SEPARATOR.'controllers');
foreach($controller_files as $controller_filename) foreach ($controller_files as $controller_filename)
{ {
if (substr($controller_filename, -14, 14) == 'Controller.php') if (substr($controller_filename, -14, 14) == 'Controller.php')
$this->controllers[strtolower(substr($controller_filename, 0, -14))] = basename($controller_filename, '.php'); self::$controllers[strtolower(substr($controller_filename, 0, -14))] = basename($controller_filename, '.php');
} }
// add default controller // add default controller
$this->controllers['index'] = 'IndexController'; self::$controllers['index'] = 'IndexController';
$this->controllers['authentication'] = $this->controllers['auth']; self::$controllers['authentication'] = self::$controllers['auth'];
$this->controllers['productscomparison'] = $this->controllers['compare']; self::$controllers['productscomparison'] = self::$controllers['compare'];
} }
public function getController() public function getController()
+2 -3
View File
@@ -783,9 +783,8 @@ abstract class ModuleCore
continue; continue;
$exceptions = $moduleInstance->getExceptions($array['id_hook']); $exceptions = $moduleInstance->getExceptions($array['id_hook']);
foreach ($exceptions AS $exception) if (in_array(Dispatcher::$controller, $exceptions))
if (strstr(basename($_SERVER['PHP_SELF']).'?'.$_SERVER['QUERY_STRING'], $exception)) continue;
continue 2;
if (is_callable(array($moduleInstance, 'hook'.$hook_name))) if (is_callable(array($moduleInstance, 'hook'.$hook_name)))
{ {