Advertisement
Guest User

Untitled

a guest
Jul 8th, 2015
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.88 KB | None | 0 0
  1. <?php
  2.  
  3. class Hook extends HookCore
  4. {
  5.     public static function getHookModuleExecList($hook_name = null)
  6.     {
  7.         $context = Context::getContext();
  8.         $cache_id = 'hook_module_exec_list_'.(isset($context->shop->id) ? '_'.$context->shop->id : '' ).((isset($context->customer)) ? '_'.$context->customer->id : '');
  9.         if (!Cache::isStored($cache_id) || $hook_name == 'displayPayment' || $hook_name == 'displayBackOfficeHeader')
  10.         {
  11.             $frontend = true;
  12.             $groups = array();
  13.             $use_groups = Group::isFeatureActive();
  14.             if (isset($context->employee))
  15.                 $frontend = false;
  16.             else
  17.             {
  18.                 // Get groups list
  19.                 if ($use_groups)
  20.                 {
  21.                     if (isset($context->customer) && $context->customer->isLogged())
  22.                         $groups = $context->customer->getGroups();
  23.                     elseif (isset($context->customer) && $context->customer->isLogged(true))
  24.                         $groups = array((int)Configuration::get('PS_GUEST_GROUP'));
  25.                     else
  26.                         $groups = array((int)Configuration::get('PS_UNIDENTIFIED_GROUP'));
  27.                 }
  28.             }
  29.            
  30.             // SQL Request
  31.             $sql = new DbQuery();
  32.             $sql->select('h.`name` as hook, m.`id_module`, h.`id_hook`, m.`name` as module, h.`live_edit`');
  33.             $sql->from('module', 'm');
  34.             if ($hook_name != 'displayBackOfficeHeader')
  35.             {
  36.                 $sql->join(Shop::addSqlAssociation('module', 'm', true, 'module_shop.enable_device & '.(int)Context::getContext()->getDevice()));
  37.                 $sql->innerJoin('module_shop', 'ms', 'ms.`id_module` = m.`id_module`');
  38.             }
  39.             $sql->innerJoin('hook_module', 'hm', 'hm.`id_module` = m.`id_module`');
  40.             $sql->innerJoin('hook', 'h', 'hm.`id_hook` = h.`id_hook`');
  41.             if ($hook_name != 'displayPayment')
  42.                 $sql->where('h.name != "displayPayment"');
  43.             // For payment modules, we check that they are available in the contextual country
  44.             elseif ($frontend)
  45.             {
  46.                 // ShipToPay remove fix (override still exists but module not)
  47.                 if(Module::getInstanceByName('shiptopay')->active)
  48.                     $sql->innerJoin('shiptopay', 'stp', 'stp.`id_payment` = m.`id_module` AND stp.`id_carrier` = ' . (int)$context->cart->id_carrier . ' AND stp.`id_shop` = ' . (int)$context->shop->id);
  49.  
  50.                 if (Validate::isLoadedObject($context->country))
  51.                     $sql->where('(h.name = "displayPayment" AND (SELECT id_country FROM '._DB_PREFIX_.'module_country mc WHERE mc.id_module = m.id_module AND id_country = '.(int)$context->country->id.' AND id_shop = '.(int)$context->shop->id.' LIMIT 1) = '.(int)$context->country->id.')');
  52.                 if (Validate::isLoadedObject($context->currency))
  53.                     $sql->where('(h.name = "displayPayment" AND (SELECT id_currency FROM '._DB_PREFIX_.'module_currency mcr WHERE mcr.id_module = m.id_module AND id_currency IN ('.(int)$context->currency->id.', -1, -2) LIMIT 1) IN ('.(int)$context->currency->id.', -1, -2))');
  54.             }
  55.             if (Validate::isLoadedObject($context->shop))
  56.                 $sql->where('hm.id_shop = '.(int)$context->shop->id);
  57.  
  58.             if ($frontend)
  59.             {
  60.                 if ($use_groups)
  61.                 {
  62.                     $sql->leftJoin('module_group', 'mg', 'mg.`id_module` = m.`id_module`');
  63.                     if (Validate::isLoadedObject($context->shop))
  64.                         $sql->where('mg.id_shop = '.((int)$context->shop->id).' AND  mg.`id_group` IN ('.implode(', ', $groups).')');
  65.                     else
  66.                         $sql->where('mg.`id_group` IN ('.implode(', ', $groups).')');
  67.                 }
  68.             }
  69.  
  70.             $sql->groupBy('hm.id_hook, hm.id_module');
  71.             $sql->orderBy('hm.`position`');
  72.  
  73.             $list = array();
  74.             if ($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
  75.                 foreach ($result as $row)
  76.                 {
  77.                     $row['hook'] = strtolower($row['hook']);
  78.                     if (!isset($list[$row['hook']]))
  79.                         $list[$row['hook']] = array();
  80.  
  81.                     $list[$row['hook']][] = array(
  82.                         'id_hook' => $row['id_hook'],
  83.                         'module' => $row['module'],
  84.                         'id_module' => $row['id_module'],
  85.                         'live_edit' => $row['live_edit'],
  86.                     );
  87.                 }
  88.             if ($hook_name != 'displayPayment' && $hook_name != 'displayBackOfficeHeader')
  89.             {
  90.                 Cache::store($cache_id, $list);
  91.                 // @todo remove this in 1.6, we keep it in 1.5 for retrocompatibility
  92.                 self::$_hook_modules_cache_exec = $list;
  93.             }
  94.         }
  95.         else
  96.             $list = Cache::retrieve($cache_id);
  97.  
  98.         // If hook_name is given, just get list of modules for this hook
  99.         if ($hook_name)
  100.         {
  101.             $retro_hook_name = strtolower(Hook::getRetroHookName($hook_name));
  102.             $hook_name = strtolower($hook_name);
  103.  
  104.             $return = array();
  105.             $inserted_modules = array();
  106.             if (isset($list[$hook_name]))
  107.                 $return = $list[$hook_name];
  108.             foreach ($return as $module)
  109.                 $inserted_modules[] = $module['id_module'];
  110.             if (isset($list[$retro_hook_name]))
  111.                 foreach ($list[$retro_hook_name] as $retro_module_call)
  112.                     if (!in_array($retro_module_call['id_module'], $inserted_modules))
  113.                         $return[] = $retro_module_call;
  114.  
  115.             return (count($return) > 0 ? $return : false);
  116.         }
  117.         else
  118.             return $list;
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement