public static function getPost($id_post, $id_lang = null)
 {
     $result = array();
     if ($id_lang == null) {
         $id_lang = (int) Context::getContext()->language->id;
     }
     preg_match('/^[\\d]+/', $id_post, $id_post);
     $id_post = $id_post[0];
     $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'smart_blog_post p INNER JOIN 
             ' . _DB_PREFIX_ . 'smart_blog_post_lang pl ON p.id_smart_blog_post=pl.id_smart_blog_post INNER JOIN 
             ' . _DB_PREFIX_ . 'smart_blog_post_shop ps ON pl.id_smart_blog_post = ps.id_smart_blog_post 
             WHERE pl.id_lang=' . $id_lang . '
             AND p.active= 1 AND p.id_smart_blog_post = ' . $id_post;
     if (!($post = Db::getInstance()->executeS($sql))) {
         return false;
     }
     $result['id_post'] = $post[0]['id_smart_blog_post'];
     $result['meta_title'] = $post[0]['meta_title'];
     $result['meta_description'] = $post[0]['meta_description'];
     $result['short_description'] = $post[0]['short_description'];
     $result['meta_keyword'] = $post[0]['meta_keyword'];
     if (Module::isEnabled('smartshortcode') == 1 && Module::isInstalled('smartshortcode') == 1) {
         require_once _PS_MODULE_DIR_ . 'smartshortcode/smartshortcode.php';
         $smartshortcode = new SmartShortCode();
         $result['content'] = $smartshortcode->parse($post[0]['content']);
     } else {
         $result['content'] = $post[0]['content'];
     }
     $result['active'] = $post[0]['active'];
     $result['created'] = $post[0]['created'];
     $result['comment_status'] = $post[0]['comment_status'];
     $result['viewed'] = $post[0]['viewed'];
     $result['is_featured'] = $post[0]['is_featured'];
     $result['post_type'] = $post[0]['post_type'];
     $result['id_category'] = $post[0]['id_category'];
     $employee = new Employee($post[0]['id_author']);
     $result['id_author'] = $post[0]['id_author'];
     $result['lastname'] = $employee->lastname;
     $result['firstname'] = $employee->firstname;
     $result['youtube'] = $post[0]['youtube'];
     if (file_exists(_PS_MODULE_DIR_ . 'smartblog/images/' . $post[0]['id_smart_blog_post'] . '.jpg')) {
         $image = $post[0]['id_smart_blog_post'] . '.jpg';
         $result['post_img'] = $image;
     } else {
         $result['post_img'] = NULL;
     }
     return $result;
 }
Example #2
0
 public function postProcess()
 {
     if (!Module::isInstalled('aplazame') || !Module::isEnabled('aplazame')) {
         $this->error('Aplazame is not enabled');
     }
     $cartId = $mid = Tools::getValue('checkout_token');
     $secureKey = Tools::getValue('key', false);
     if (!$mid || !$secureKey) {
         $this->error('Missing required fields');
     }
     $cart = new Cart((int) $mid);
     if (!Validate::isLoadedObject($cart)) {
         $this->error('Cart does not exists or does not have an order');
     }
     $response = $this->module->callToRest('POST', '/orders/' . $mid . '/authorize');
     if ($response['is_error']) {
         $message = 'Aplazame Error #' . $response['code'];
         if (isset($response['payload']['error']['message'])) {
             $message .= ' ' . $response['payload']['error']['message'];
         }
         $this->module->validateOrder($cartId, Configuration::get('PS_OS_ERROR'), $cart->getOrderTotal(true), $this->module->displayName, $message, null, null, false, $secureKey);
         $this->error('Authorization error');
     }
     $cartAmount = AplazameSerializers::formatDecimals($cart->getOrderTotal(true));
     if ($response['payload']['amount'] !== $cartAmount) {
         $this->error('Invalid');
     }
     $aplazameAmount = AplazameSerializers::decodeDecimals($response['payload']['amount']);
     if (!$this->module->validateOrder($cartId, Configuration::get('PS_OS_PAYMENT'), $aplazameAmount, $this->module->displayName, null, null, null, false, $secureKey)) {
         $this->error('Cannot validate order');
     }
     exit('success');
 }
 public static function getBlockContent($params, &$smarty)
 {
     //use in template as {getBelvgBlockContent id="block_identifier"}
     if (!Module::isEnabled('belvg_staticblocks')) {
         return FALSE;
     }
     if (isset($params['id'])) {
         $block_identifier = $params['id'];
         $sql = '
         SELECT `id_belvg_staticblocks`
         FROM `' . _DB_PREFIX_ . 'belvg_staticblocks`
         WHERE `block_identifier` = "' . pSQL($block_identifier) . '" AND `status` = "1"';
         if (Shop::isFeatureActive()) {
             $sql .= ' AND `id_belvg_staticblocks` IN (
                 SELECT sa.`id_belvg_staticblocks`
                 FROM `' . _DB_PREFIX_ . 'belvg_staticblocks_shop` sa
                 WHERE sa.id_shop IN (' . implode(', ', Shop::getContextListShopID()) . ')
             )';
         }
         $block_id = (int) Db::getInstance()->getValue($sql);
         if ($block_id) {
             $id_lang = Context::getContext()->cookie->id_lang;
             $block = new self($block_id);
             if (isset($block->content[$id_lang])) {
                 return $block->content[$id_lang];
             }
         }
     }
 }
Example #4
0
 public function getImageLink($name, $ids, $type = null)
 {
     $context = Context::getContext();
     // check if WebP support is enabled.
     if ($context->cookie->exists() && $context->cookie->WebPSupport) {
         $extension = '.webp';
     } else {
         $extension = '.jpg';
     }
     $not_default = false;
     // Check if module is installed, enabled, customer is logged in and watermark logged option is on
     if (Configuration::get('WATERMARK_LOGGED') && (Module::isInstalled('watermark') && Module::isEnabled('watermark')) && isset(Context::getContext()->customer->id)) {
         $type .= '-' . Configuration::get('WATERMARK_HASH');
     }
     // legacy mode or default image
     $theme = Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_ . $ids . ($type ? '-' . $type : '') . '-' . (int) Context::getContext()->shop->id_theme . $extension) ? '-' . Context::getContext()->shop->id_theme : '';
     if (Configuration::get('PS_LEGACY_IMAGES') && file_exists(_PS_PROD_IMG_DIR_ . $ids . ($type ? '-' . $type : '') . $theme . $extension) || ($not_default = strpos($ids, 'default') !== false)) {
         if ($this->allow == 1 && !$not_default) {
             $uri_path = __PS_BASE_URI__ . $ids . ($type ? '-' . $type : '') . $theme . '/' . $name . $extension;
         } else {
             $uri_path = _THEME_PROD_DIR_ . $ids . ($type ? '-' . $type : '') . $theme . $extension;
         }
     } else {
         // if ids if of the form id_product-id_image, we want to extract the id_image part
         $split_ids = explode('-', $ids);
         $id_image = isset($split_ids[1]) ? $split_ids[1] : $split_ids[0];
         $theme = Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_ . Image::getImgFolderStatic($id_image) . $id_image . ($type ? '-' . $type : '') . '-' . (int) Context::getContext()->shop->id_theme . $extension) ? '-' . Context::getContext()->shop->id_theme : '';
         if ($this->allow == 1) {
             $uri_path = __PS_BASE_URI__ . $id_image . ($type ? '-' . $type : '') . $theme . '/' . $name . $extension;
         } else {
             $uri_path = _THEME_PROD_DIR_ . Image::getImgFolderStatic($id_image) . $id_image . ($type ? '-' . $type : '') . $theme . $extension;
         }
     }
     return $this->protocol_content . Tools::getMediaServer($uri_path) . $uri_path;
 }
Example #5
0
 public function init()
 {
     parent::init();
     if (Module::isEnabled('aimultidimensions')) {
         if (Tools::getIsset('add') && $this->context->cart->id) {
             require_once _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'aimultidimensions' . DIRECTORY_SEPARATOR . 'aimultidimensions.php';
             require_once _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'aimultidimensions' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'config.php';
             require_once _PS_ROOT_DIR_ . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'aimultidimensions' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'functions' . $GLOBALS['aimd_config_suffix'] . '.php';
             $add = 1;
             $idProduct = (int) Tools::getValue('id_product', NULL);
             if (checkLink($idProduct)) {
                 $idProductAttribute = (int) Tools::getValue('id_product_attribute', Tools::getValue('ipa'));
                 $customizationId = (int) Tools::getValue('id_customization', 0);
                 $qty = (int) abs(Tools::getValue('qty', 1));
                 if ($add && $qty >= 0 && getProducts($idProduct)) {
                     $quantity = (int) Db::getInstance()->getValue('SELECT quantity FROM ' . _DB_PREFIX_ . 'cart_product WHERE id_cart = ' . $this->context->cart->id . ' AND id_product = ' . $idProduct . ' AND ' . 'id_product_attribute = ' . $idProductAttribute);
                     if (Tools::getValue('op', 'up') == 'up') {
                         $quantity += (int) $qty;
                     } else {
                         $quantity -= (int) $qty;
                     }
                     $cookie = $this->context->cookie;
                     $cart = $this->context->cart;
                     include_once 'modules/aimultidimensions/includes/cart.php';
                     Product::flushPriceCache();
                 }
             }
         }
     }
 }
 public static function getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute = null, $id_customer = 0, $id_cart = 0, $real_quantity = 0)
 {
     $specific_price = parent::getSpecificPrice($id_product, $id_shop, $id_currency, $id_country, $id_group, $quantity, $id_product_attribute, $id_customer, $id_cart, $real_quantity);
     if (Module::isEnabled('loyaltydiscount')) {
         include_once _PS_MODULE_DIR_ . DIRECTORY_SEPARATOR . 'loyaltydiscount' . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . 'LoyaltyDiscount.php';
         LoyaltyDiscountModel::applyPossibleDiscount($id_product, $id_shop, $specific_price);
     }
     return $specific_price;
 }
Example #7
0
 public function init()
 {
     if (Module::isInstalled('magicredirect') && Module::isEnabled('magicredirect')) {
         require_once _PS_MODULE_DIR_ . 'magicredirect/magicredirect.php';
         $mod = new MagicRedirect();
         $mod->catchUrls();
     }
     return parent::init();
 }
 public function initContent()
 {
     parent::initContent();
     $_legal = Module::getInstanceByName('eu_legal');
     if (Validate::isLoadedObject($_legal) && Module::isInstalled($_legal->name) && Module::isEnabled($_legal->name)) {
         if ($tpl = $_legal->getThemeOverride('order-detail')) {
             $this->setTemplate($tpl);
         }
     }
 }
 public function __construct()
 {
     /*
      * EU-Legal
      * instantiate EU Legal Module
      */
     parent::__construct();
     $instance = Module::getInstanceByName('eu_legal');
     if (Validate::isLoadedObject($instance) && Module::isInstalled($instance->name) && Module::isEnabled($instance->name)) {
         $this->_legal = $instance;
     }
 }
Example #10
0
 public static function isExpeditorCarrier($id_carrier)
 {
     if (!Module::isEnabled('expeditor')) {
         return false;
     }
     foreach (explode(',', ConfigurationCore::get('EXPEDITOR_CARRIER')) as $carrier) {
         if ($carrier == $id_carrier) {
             return true;
         }
     }
     return false;
 }
 public function postProcess()
 {
     if (Module::isInstalled('aplazame') && Module::isEnabled('aplazame')) {
         if (Tools::isSubmit('id_order') && Tools::getValue('id_order') > 0) {
             $order = new Order(Tools::getValue('id_order'));
             if (Validate::isLoadedObject($order)) {
                 if (Tools::isSubmit('partialRefund') && isset($order)) {
                     if ($this->tabAccess['edit'] == '1') {
                         if (is_array($_POST['partialRefundProduct'])) {
                             $amount = 0;
                             $order_detail_list = array();
                             foreach ($_POST['partialRefundProduct'] as $id_order_detail => $amount_detail) {
                                 $order_detail_list[$id_order_detail] = array('quantity' => (int) $_POST['partialRefundProductQuantity'][$id_order_detail], 'id_order_detail' => (int) $id_order_detail);
                                 $order_detail = new OrderDetail((int) $id_order_detail);
                                 if (empty($amount_detail)) {
                                     $order_detail_list[$id_order_detail]['unit_price'] = $order_detail->unit_price_tax_excl;
                                     $order_detail_list[$id_order_detail]['amount'] = $order_detail->unit_price_tax_incl * $order_detail_list[$id_order_detail]['quantity'];
                                 } else {
                                     $order_detail_list[$id_order_detail]['unit_price'] = (double) str_replace(',', '.', $amount_detail / $order_detail_list[$id_order_detail]['quantity']);
                                     $order_detail_list[$id_order_detail]['amount'] = (double) str_replace(',', '.', $amount_detail);
                                 }
                                 $amount += $order_detail_list[$id_order_detail]['amount'];
                             }
                             $choosen = false;
                             $voucher = 0;
                             if ((int) Tools::getValue('refund_voucher_off') == 1) {
                                 $amount -= $voucher = (double) Tools::getValue('order_discount_price');
                             } elseif ((int) Tools::getValue('refund_voucher_off') == 2) {
                                 $choosen = true;
                                 $amount = $voucher = (double) Tools::getValue('refund_voucher_choose');
                             }
                             $shipping_cost_amount = (double) str_replace(',', '.', Tools::getValue('partialRefundShippingCost')) ? (double) str_replace(',', '.', Tools::getValue('partialRefundShippingCost')) : false;
                             if ($shipping_cost_amount > 0) {
                                 $amount += $shipping_cost_amount;
                             }
                             if ($amount > 0) {
                                 if (!Tools::isSubmit('generateDiscountRefund') && $order->module == 'aplazame') {
                                     $aplazame = ModuleCore::getInstanceByName('aplazame');
                                     $aplazame->refundAmount($order, $amount);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     parent::postProcess();
 }
Example #12
0
 public function __construct($request, $origin)
 {
     $this->loadClasses();
     parent::__construct($request);
     // Abstracted out for example
     $APIKey = new PowaTagAPIKey();
     if (!Module::isInstalled('powatag') || !Module::isEnabled('powatag')) {
         throw new Exception('Module not enable');
     }
     /*
     		if (!array_key_exists('HTTP_HMAC', $_SERVER))
     			throw new Exception('No API Key provided');
     		else if (!$APIKey->verifyKey($_SERVER['HTTP_HMAC'], $this->data))
     			throw new Exception('Invalid API Key');
     */
     $this->data = Tools::jsonDecode($this->data);
 }
Example #13
0
 public function preparePosts($nb = 4, $cat = null)
 {
     $featured = false;
     if ($cat == 9999) {
         $cat = 0;
         $featured = true;
     }
     if (!Module::isInstalled('ph_simpleblog') || !Module::isEnabled('ph_simpleblog')) {
         return false;
     }
     if (!isset($nb) || !isset($cat)) {
         return false;
     }
     require_once _PS_MODULE_DIR_ . 'ph_simpleblog/models/SimpleBlogPost.php';
     $id_lang = $this->context->language->id;
     $posts = SimpleBlogPost::getPosts($id_lang, $nb, $cat, null, true, 'sbp.date_add', 'DESC', null, $featured);
     return $posts;
 }
Example #14
0
 public function initContent()
 {
     $this->context->controller->addJqueryPlugin('cooki-plugin');
     $this->context->controller->addJqueryPlugin('cookie-plugin');
     $this->context->controller->addjqueryPlugin('fancybox');
     $this->context->controller->addCSS(array(_THEME_CSS_DIR_ . 'category.css' => 'all', _THEME_CSS_DIR_ . 'product_list.css' => 'all'));
     parent::initContent();
     $this->SimpleBlogPost->increaseViewsNb();
     /**
     
             Support for SmartShortcode module from CodeCanyon
     
             **/
     if (file_exists(_PS_MODULE_DIR_ . 'smartshortcode/smartshortcode.php')) {
         require_once _PS_MODULE_DIR_ . 'smartshortcode/smartshortcode.php';
     }
     if (Module::isEnabled('smartshortcode')) {
         $smartshortcode = new SmartShortCode();
         $this->SimpleBlogPost->content = $smartshortcode->parse($this->SimpleBlogPost->content);
     }
     $this->context->smarty->assign('post', $this->SimpleBlogPost);
     $this->context->smarty->assign('is_16', version_compare(_PS_VERSION_, '1.6.0', '>=') === true ? true : false);
     $this->context->smarty->assign('gallery_dir', _MODULE_DIR_ . 'ph_simpleblog/galleries/');
     // Comments
     if ($this->SimpleBlogPost->allow_comments == 1) {
         $allow_comments = true;
     } elseif ($this->SimpleBlogPost->allow_comments == 2) {
         $allow_comments = false;
     } elseif ($this->SimpleBlogPost->allow_comments == 3) {
         $allow_comments = Configuration::get('PH_BLOG_COMMENT_ALLOW');
     } else {
         $allow_comments = false;
     }
     $this->context->smarty->assign('allow_comments', $allow_comments);
     if ($allow_comments) {
         $comments = SimpleBlogComment::getComments($this->SimpleBlogPost->id_simpleblog_post);
         $this->context->smarty->assign('comments', $comments);
     }
     if (Configuration::get('PH_BLOG_DISPLAY_RELATED')) {
         $related_products = SimpleBlogPost::getRelatedProducts($this->SimpleBlogPost->id_product);
         $this->context->smarty->assign('related_products', $related_products);
     }
     $this->setTemplate('single.tpl');
 }
 /**
  * Disables a module.
  *
  * @param $slug
  *
  * @return \Illuminate\Http\Response
  */
 public function disable($slug)
 {
     Audit::log(Auth::user()->id, trans('admin/modules/general.audit-log.category'), trans('admin/modules/general.audit-log.msg-disable', ['slug' => $slug]));
     $module = \Module::where('slug', $slug)->first();
     if ($module) {
         if (\Module::isInitialized($slug)) {
             if (\Module::isEnabled($slug)) {
                 \Module::disable($slug);
                 Flash::success(trans('admin/modules/general.status.disabled', ['name' => $module['name']]));
             } else {
                 Flash::warning(trans('admin/modules/general.status.not-enabled', ['name' => $module['name']]));
             }
         } else {
             Flash::warning(trans('admin/modules/general.status.not-initialized', ['name' => $module['name']]));
         }
     } else {
         Flash::error(trans('admin/modules/general.status.not-found', ['slug' => $slug]));
     }
     Flash::success(trans('admin/modules/general.status.disabled'));
     return redirect('/admin/modules');
 }
 /**
  * Perform post-registration booting of services.
  *
  * @return void
  */
 public function boot()
 {
     $installed_modules = \Illuminato\Module::getInstalledModules();
     foreach ($installed_modules as $key => $module) {
         $module_dir = _PS_MODULE_DIR_ . $module['name'];
         if (\Module::isEnabled($module['name'])) {
             if (is_dir($module_dir . '/resources/views')) {
                 $this->loadViewsFrom($module_dir . '/resources/views', $module['namespace']);
             }
             if (is_dir($module_dir . '/resources/lang')) {
                 $this->loadTranslationsFrom($module_dir . '/resources/lang', $module['namespace']);
             }
             if (is_dir($module_dir . '/config')) {
                 $this->loadConfigsFrom($module_dir . '.config', $module['namespace']);
             }
         }
     }
     //Now we can load the module's config files
     $configLoader = new LoadConfiguration();
     $configLoader->loadModuleConfigurationFiles(app());
 }
Example #17
0
    /**
     * Check if enabled
     *
     * @param   integer  $uid
     * @return  boolean
     */
    public function isEnabled($uid = NULL)
    {
        $dbg = isset($_GET['dbg']);
        if (!$uid) {
            $uid = (int) User::get('id');
        }
        if (!$uid || !Module::isEnabled('incremental_registration')) {
            return false;
        }
        $dbh = App::get('db');
        $dbh->setQuery('SELECT emailConfirmed FROM `#__xprofiles` WHERE uidNumber = ' . $uid);
        if ($dbh->loadResult() < 0) {
            return false;
        }
        $cur = self::getCurrent();
        if (!$cur['test_group']) {
            return true;
        }
        $dbh->setQuery('SELECT 1 FROM `#__xgroups_members` xme WHERE xme.gidNumber = ' . $cur['test_group'] . ' AND xme.uidNumber = ' . $uid . '
			UNION SELECT 1 FROM #__xgroups_managers xma WHERE xma.gidNumber = ' . $cur['test_group'] . ' AND xma.uidNumber = ' . $uid . ' LIMIT 1');
        return (bool) $dbh->loadResult();
    }
Example #18
0
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     $this->context->smarty->assign('categoriesTree', Category::getRootCategory()->recurseLiteCategTree(0));
     $this->context->smarty->assign('categoriescmsTree', CMSCategory::getRecurseCategory($this->context->language->id, 1, 1, 1));
     $this->context->smarty->assign('voucherAllowed', (int) CartRule::isFeatureActive());
     if (Module::isInstalled('blockmanufacturer') && Module::isEnabled('blockmanufacturer')) {
         $blockmanufacturer = Module::getInstanceByName('blockmanufacturer');
         $this->context->smarty->assign('display_manufacturer_link', isset($blockmanufacturer->active) ? (bool) $blockmanufacturer->active : false);
     } else {
         $this->context->smarty->assign('display_manufacturer_link', 0);
     }
     if (Module::isInstalled('blocksupplier') && Module::isEnabled('blocksupplier')) {
         $blocksupplier = Module::getInstanceByName('blocksupplier');
         $this->context->smarty->assign('display_supplier_link', isset($blocksupplier->active) ? (bool) $blocksupplier->active : false);
     } else {
         $this->context->smarty->assign('display_supplier_link', 0);
     }
     $this->context->smarty->assign('PS_DISPLAY_SUPPLIERS', Configuration::get('PS_DISPLAY_SUPPLIERS'));
     $this->context->smarty->assign('PS_DISPLAY_BEST_SELLERS', Configuration::get('PS_DISPLAY_BEST_SELLERS'));
     $this->context->smarty->assign('display_store', Configuration::get('PS_STORES_DISPLAY_SITEMAP'));
     $this->setTemplate(_PS_THEME_DIR_ . 'sitemap.tpl');
 }
 public static function getFrontFeaturesStatic($id_lang, $id_product)
 {
     if (!Feature::isFeatureActive()) {
         return array();
     }
     if (!array_key_exists($id_product . '-' . $id_lang, self::$_frontFeaturesCache)) {
         if (Module::isInstalled('blocklayered') && Module::isEnabled('blocklayered')) {
             Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('SET @@group_concat_max_len = 4096');
             self::$_frontFeaturesCache[$id_product . '-' . $id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
                 SELECT `name`, GROUP_CONCAT(value ORDER BY `fv`.`position` SEPARATOR ", ") AS `value`, `pf`.`id_feature`, `liflv`.`url_name`, `liflv`.`meta_title`
                 FROM `' . _DB_PREFIX_ . 'feature_product` `pf`
                 LEFT JOIN `' . _DB_PREFIX_ . 'feature_lang` `fl` ON (`fl`.`id_feature` = `pf`.`id_feature` AND `fl`.`id_lang` = ' . (int) $id_lang . ')
                 LEFT JOIN `' . _DB_PREFIX_ . 'feature_value_lang` `fvl` ON (`fvl`.`id_feature_value` = `pf`.`id_feature_value` AND `fvl`.`id_lang` = ' . (int) $id_lang . ')
                 LEFT JOIN `' . _DB_PREFIX_ . 'feature` `f` ON (`f`.`id_feature` = `pf`.`id_feature` AND `fl`.`id_lang` = ' . (int) $id_lang . ')
                 LEFT JOIN ' . _DB_PREFIX_ . 'feature_value `fv` ON `fv`.`id_feature_value` = `pf`.`id_feature_value`
                 LEFT JOIN `' . _DB_PREFIX_ . 'layered_indexable_feature_lang_value` `liflv` ON (`f`.`id_feature` = `liflv`.`id_feature` AND `liflv`.`id_lang` = ' . (int) $id_lang . ')
                 ' . Shop::addSqlAssociation('feature', 'f') . '
                 WHERE pf.`id_product` = ' . (int) $id_product . '
                 GROUP BY `name`, pf.`id_feature`
                 ORDER BY f.`position` ASC');
         } else {
             Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('SET @@group_concat_max_len = 4096');
             self::$_frontFeaturesCache[$id_product . '-' . $id_lang] = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
                 SELECT `name`, GROUP_CONCAT(value ORDER BY `fv`.`position` SEPARATOR ", ") AS `value`, `pf`.`id_feature`
                 FROM ' . _DB_PREFIX_ . 'feature_product `pf`
                 LEFT JOIN ' . _DB_PREFIX_ . 'feature_lang `fl` ON (`fl`.`id_feature` = `pf`.`id_feature` AND `fl`.`id_lang` = ' . (int) $id_lang . ')
                 LEFT JOIN ' . _DB_PREFIX_ . 'feature_value_lang `fvl` ON (`fvl`.`id_feature_value` = `pf`.`id_feature_value` AND `fvl`.`id_lang` = ' . (int) $id_lang . ')
                 LEFT JOIN ' . _DB_PREFIX_ . 'feature `f` ON `f`.`id_feature` = `pf`.`id_feature`
                 LEFT JOIN ' . _DB_PREFIX_ . 'feature_value `fv` ON `fv`.`id_feature_value` = `pf`.`id_feature_value`
                 ' . Shop::addSqlAssociation('feature', 'f') . '
                 WHERE pf.id_product = ' . (int) $id_product . '
                 GROUP BY `name`, pf.`id_feature`
                 ORDER BY f.`position` ASC');
         }
     }
     return self::$_frontFeaturesCache[$id_product . '-' . $id_lang];
 }
Example #20
0
 /**
  * Initialize product controller
  * @see FrontController::init()
  */
 public function init()
 {
     parent::init();
     if ($id_product = (int) Tools::getValue('id_product')) {
         $this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
     }
     if (!Validate::isLoadedObject($this->product)) {
         header('HTTP/1.1 404 Not Found');
         header('Status: 404 Not Found');
         $this->errors[] = Tools::displayError('Product not found');
     } else {
         $this->canonicalRedirection();
         /*
          * If the product is associated to the shop
          * and is active or not active but preview mode (need token + file_exists)
          * allow showing the product
          * In all the others cases => 404 "Product is no longer available"
          */
         if (!$this->product->isAssociatedToShop() || !$this->product->active) {
             if (Tools::getValue('adtoken') == Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) && $this->product->isAssociatedToShop()) {
                 // If the product is not active, it's the admin preview mode
                 $this->context->smarty->assign('adminActionDisplay', true);
             } else {
                 $this->context->smarty->assign('adminActionDisplay', false);
                 if (!$this->product->id_product_redirected || $this->product->id_product_redirected == $this->product->id) {
                     $this->product->redirect_type = '404';
                 }
                 switch ($this->product->redirect_type) {
                     case '301':
                         header('HTTP/1.1 301 Moved Permanently');
                         header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected));
                         exit;
                         break;
                     case '302':
                         header('HTTP/1.1 302 Moved Temporarily');
                         header('Cache-Control: no-cache');
                         header('Location: ' . $this->context->link->getProductLink($this->product->id_product_redirected));
                         exit;
                         break;
                     case '404':
                     default:
                         header('HTTP/1.1 404 Not Found');
                         header('Status: 404 Not Found');
                         $this->errors[] = Tools::displayError('This product is no longer available.');
                         break;
                 }
             }
         } elseif (!$this->product->checkAccess(isset($this->context->customer->id) && $this->context->customer->id ? (int) $this->context->customer->id : 0)) {
             header('HTTP/1.1 403 Forbidden');
             header('Status: 403 Forbidden');
             $this->errors[] = Tools::displayError('You do not have access to this product.');
         } else {
             // Load category
             $id_category = false;
             if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] == Tools::secureReferrer($_SERVER['HTTP_REFERER']) && preg_match('~^.*(?<!\\/content)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_(category|product)=([0-9]+)(.*)$~', $_SERVER['HTTP_REFERER'], $regs)) {
                 // If the previous page was a category and is a parent category of the product use this category as parent category
                 $id_object = false;
                 if (isset($regs[1]) && is_numeric($regs[1])) {
                     $id_object = (int) $regs[1];
                 } elseif (isset($regs[5]) && is_numeric($regs[5])) {
                     $id_object = (int) $regs[5];
                 }
                 if ($id_object) {
                     $referers = array($_SERVER['HTTP_REFERER'], urldecode($_SERVER['HTTP_REFERER']));
                     if (in_array($this->context->link->getCategoryLink($id_object), $referers)) {
                         $id_category = (int) $id_object;
                     } elseif (isset($this->context->cookie->last_visited_category) && (int) $this->context->cookie->last_visited_category && in_array($this->context->link->getProductLink($id_object), $referers)) {
                         $id_category = (int) $this->context->cookie->last_visited_category;
                     }
                 }
             }
             if (!$id_category || !Category::inShopStatic($id_category, $this->context->shop) || !Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => $id_category)))) {
                 $id_category = (int) $this->product->id_category_default;
             }
             $this->category = new Category((int) $id_category, (int) $this->context->cookie->id_lang);
             if (isset($this->context->cookie) && isset($this->category->id_category) && !(Module::isInstalled('blockcategories') && Module::isEnabled('blockcategories'))) {
                 $this->context->cookie->last_visited_category = (int) $this->category->id_category;
             }
         }
     }
 }
Example #21
0
 public function hookDisplayAdminProductsExtra()
 {
     if (!Module::isInstalled('ph_simpleblog') || !Module::isEnabled('ph_simpleblog')) {
         return;
     }
     $product = new Product(Tools::getValue('id_product'), false, $this->context->cookie->id_lang);
     $posts = SimpleBlogPost::getSimplePosts($this->context->language->id);
     $selected_posts = array();
     $related_posts = array();
     foreach (SimpleBlogRelatedPost::getByProductId($product->id) as $key => $post) {
         $related_posts[] = $post['id_simpleblog_post'];
     }
     if (sizeof($related_posts) > 0) {
         $posts = SimpleBlogPost::getSimplePosts($this->context->language->id, null, null, 'NOT IN', $related_posts);
         $selected_posts = SimpleBlogPost::getSimplePosts($this->context->language->id, null, null, 'IN', $related_posts);
     }
     $this->context->smarty->assign(array('product' => $product, 'posts' => $posts, 'selected_posts' => $selected_posts, 'module_path' => $this->_path, 'secure_key' => $this->secure_key, 'is_16' => (bool) (version_compare(_PS_VERSION_, '1.6.0', '>=') === true)));
     return $this->display(__FILE__, 'admin-tab.tpl');
 }
Example #22
0
 /**
  * hook home to display generate the product list associated to home featured, news products and best sellers Modules
  */
 public function isModuleEnabled($name)
 {
     if (version_compare(_PS_VERSION_, '1.5', '>=')) {
         if (Module::isEnabled($name)) {
             $module = Module::getInstanceByName($name);
             return $module->isRegisteredInHook('home');
         } else {
             return false;
         }
     } else {
         $module = Module::getInstanceByName($name);
         return $module && $module->active === true;
     }
 }
Example #23
0
 public static function getThemeInfo($id_theme)
 {
     $theme = new Theme($id_theme);
     $theme_arr = array();
     if (file_exists(_PS_ROOT_DIR_ . '/config/xml/themes/' . $theme->directory . '.xml')) {
         $config_file = _PS_ROOT_DIR_ . '/config/xml/themes/' . $theme->directory . '.xml';
     } elseif ($theme->name == 'default-bootstrap') {
         $config_file = _PS_ROOT_DIR_ . '/config/xml/themes/default.xml';
     } else {
         $config_file = false;
     }
     if ($config_file) {
         $theme_arr['theme_id'] = $theme->id;
         $xml_theme = @simplexml_load_file($config_file);
         if ($xml_theme !== false) {
             foreach ($xml_theme->attributes() as $key => $value) {
                 $theme_arr['theme_' . $key] = (string) $value;
             }
             foreach ($xml_theme->author->attributes() as $key => $value) {
                 $theme_arr['author_' . $key] = (string) $value;
             }
             if ($theme_arr['theme_name'] == 'default-bootstrap') {
                 $theme_arr['tc'] = Module::isEnabled('themeconfigurator');
             }
         }
     } else {
         // If no xml we use data from database
         $theme_arr['theme_id'] = $theme->id;
         $theme_arr['theme_name'] = $theme->name;
         $theme_arr['theme_directory'] = $theme->directory;
     }
     return $theme_arr;
 }
Example #24
0
 public function getContent()
 {
     // If we try to update the settings
     $output = '';
     if (isset($_POST['submitModule'])) {
         Configuration::updateValue('iqitsearch_hook', Tools::getValue('iqitsearch_hook'));
         Configuration::updateValue('iqitsearch_categories', Tools::getValue('iqitsearch_categories'));
         Configuration::updateValue('iqitsearch_depth', Tools::getValue('iqitsearch_depth'));
         Configuration::updateValue('iqitsearch_shower', Tools::getValue('iqitsearch_shower'));
         $message_trads = array();
         foreach ($_POST as $key => $value) {
             if (preg_match('/iqitsearch_text_/i', $key)) {
                 $id_lang = preg_split('/iqitsearch_text_/i', $key);
                 $message_trads[(int) $id_lang[1]] = $value;
             }
         }
         Configuration::updateValue('iqitsearch_text', $message_trads, true);
         $this->_clearCache('blocksearch-top_modm.tpl');
         $this->_clearCache('blocksearch-top_mod.tpl');
         if ((bool) Module::isEnabled('iqitmegamenu')) {
             $iqitmegamenu = Module::getInstanceByName('iqitmegamenu');
             $iqitmegamenu->clearMenuCache();
         }
         $output .= $this->displayConfirmation($this->l('Configuration updated'));
     }
     $output .= $this->renderForm();
     return $output;
 }
Example #25
0
 /**
  * If widget and blog load owl carousel twice -> error
  * 
  */
 public function loadOwlCarouselLib()
 {
     if (file_exists(_PS_MODULE_DIR_ . 'leomanagewidgets/assets/owl-carousel/owl.carousel.js') && Module::isEnabled('leomanagewidgets')) {
         # validate
         $this->context->controller->addJS($this->_path . '../assets/assets/owl-carousel/owl.carousel.js');
     } elseif (file_exists(_PS_THEME_DIR_ . 'js/modules/blockleoblogs/assets/owl-carousel/owl.carousel.js')) {
         # validate module
         $this->context->controller->addJS($this->_path . 'assets/owl-carousel/owl.carousel.js');
     } else {
         # validate
         $this->context->controller->addJS($this->_path . 'views/js/owl-carousel/owl.carousel.js');
     }
     if (file_exists(_PS_MODULE_DIR_ . 'leomanagewidgets/assets/owl-carousel/owl.carousel.css') && Module::isEnabled('leomanagewidgets')) {
         # validate
         $this->context->controller->addCSS($this->_path . '../assets/owl-carousel/owl.carousel.css');
     } elseif (file_exists(_PS_THEME_DIR_ . 'css/modules/blockleoblogs/assets/owl-carousel/owl.carousel.css')) {
         # validate module
         $this->context->controller->addCSS($this->_path . 'assets/owl-carousel/owl.carousel.css', 'all');
     } else {
         # validate
         $this->context->controller->addCSS($this->_path . 'views/css/owl-carousel/owl.carousel.css', 'all');
     }
     if (file_exists(_PS_MODULE_DIR_ . 'leomanagewidgets/assets/owl-carousel/owl.theme.css') && Module::isEnabled('leomanagewidgets')) {
         # validate
         $this->context->controller->addCSS($this->_path . '../assets/owl-carousel/owl.theme.css');
     } elseif (file_exists(_PS_THEME_DIR_ . 'css/modules/blockleoblogs/assets/owl-carousel/owl.theme.css')) {
         # validate module
         $this->context->controller->addCSS($this->_path . 'assets/owl-carousel/owl.theme.css', 'all');
     } else {
         # validate
         $this->context->controller->addCSS($this->_path . 'views/css/owl-carousel/owl.theme.css', 'all');
     }
 }
Example #26
0
 public function processThemeInstall()
 {
     if (Shop::isFeatureActive() && !Tools::getIsset('checkBoxShopAsso_theme')) {
         $this->errors[] = $this->l('You must choose at least one shop.');
         $this->display = 'ChooseThemeModule';
         return;
     }
     $theme = new Theme((int) Tools::getValue('id_theme'));
     $shops = array(Configuration::get('PS_SHOP_DEFAULT'));
     if (Tools::isSubmit('checkBoxShopAsso_theme')) {
         $shops = Tools::getValue('checkBoxShopAsso_theme');
     }
     $xml = false;
     if (file_exists(_PS_ROOT_DIR_ . '/config/xml/themes/' . $theme->directory . '.xml')) {
         $xml = simplexml_load_file(_PS_ROOT_DIR_ . '/config/xml/themes/' . $theme->directory . '.xml');
     } elseif (file_exists(_PS_ROOT_DIR_ . '/config/xml/themes/default.xml')) {
         $xml = simplexml_load_file(_PS_ROOT_DIR_ . '/config/xml/themes/default.xml');
     }
     if ($xml) {
         $module_hook = array();
         foreach ($xml->modules->hooks->hook as $row) {
             $name = strval($row['module']);
             $exceptions = isset($row['exceptions']) ? explode(',', strval($row['exceptions'])) : array();
             if (Hook::getIdByName(strval($row['hook']))) {
                 $module_hook[$name]['hook'][] = array('hook' => strval($row['hook']), 'position' => strval($row['position']), 'exceptions' => $exceptions);
             }
         }
         $this->img_error = $this->updateImages($xml);
         $this->modules_errors = array();
         foreach ($shops as $id_shop) {
             foreach ($_POST as $key => $value) {
                 if (strncmp($key, 'to_install', strlen('to_install')) == 0) {
                     $module = Module::getInstanceByName($value);
                     if ($module) {
                         $is_installed_success = true;
                         if (!Module::isInstalled($module->name)) {
                             $is_installed_success = $module->install();
                         }
                         if ($is_installed_success) {
                             if (!Module::isEnabled($module->name)) {
                                 $module->enable();
                             }
                             if ((int) $module->id > 0 && isset($module_hook[$module->name])) {
                                 $this->hookModule($module->id, $module_hook[$module->name], $id_shop);
                             }
                         } else {
                             $this->modules_errors[] = array('module_name' => $module->name, 'errors' => $module->getErrors());
                         }
                         unset($module_hook[$module->name]);
                     }
                 } else {
                     if (strncmp($key, 'to_enable', strlen('to_enable')) == 0) {
                         $module = Module::getInstanceByName($value);
                         if ($module) {
                             $is_installed_success = true;
                             if (!Module::isInstalled($module->name)) {
                                 $is_installed_success = $module->install();
                             }
                             if ($is_installed_success) {
                                 if (!Module::isEnabled($module->name)) {
                                     $module->enable();
                                 }
                                 if ((int) $module->id > 0 && isset($module_hook[$module->name])) {
                                     $this->hookModule($module->id, $module_hook[$module->name], $id_shop);
                                 }
                             } else {
                                 $this->modules_errors[] = array('module_name' => $module->name, 'errors' => $module->getErrors());
                             }
                             unset($module_hook[$module->name]);
                         }
                     } else {
                         if (strncmp($key, 'to_disable', strlen('to_disable')) == 0) {
                             $key_exploded = explode('_', $key);
                             $id_shop_module = (int) substr($key_exploded[2], 4);
                             if ((int) $id_shop_module > 0 && $id_shop_module != (int) $id_shop) {
                                 continue;
                             }
                             $module_obj = Module::getInstanceByName($value);
                             if (Validate::isLoadedObject($module_obj)) {
                                 if (Module::isEnabled($module_obj->name)) {
                                     $module_obj->disable();
                                 }
                                 unset($module_hook[$module_obj->name]);
                             }
                         }
                     }
                 }
             }
             $shop = new Shop((int) $id_shop);
             $shop->id_theme = (int) Tools::getValue('id_theme');
             $this->context->shop->id_theme = $shop->id_theme;
             $this->context->shop->update();
             $shop->save();
             if (Shop::isFeatureActive()) {
                 Configuration::updateValue('PS_PRODUCTS_PER_PAGE', (int) $theme->product_per_page, false, null, (int) $id_shop);
             } else {
                 Configuration::updateValue('PS_PRODUCTS_PER_PAGE', (int) $theme->product_per_page);
             }
         }
         $this->doc = array();
         foreach ($xml->docs->doc as $row) {
             $this->doc[strval($row['name'])] = __PS_BASE_URI__ . 'themes/' . $theme->directory . '/docs/' . basename(strval($row['path']));
         }
     }
     Tools::clearCache($this->context->smarty);
     $this->theme_name = $theme->name;
     $this->display = 'view';
 }
Example #27
0
 public function autoregisterhook($hook_name = 'moduleRoutes', $module_name = 'smartblog', $shop_list = null)
 {
     if (Module::isEnabled($module_name) == 1 && Module::isInstalled($module_name) == 1) {
         $return = true;
         $id_sql = 'SELECT `id_module` FROM `' . _DB_PREFIX_ . 'module` WHERE `name` = "' . $module_name . '"';
         $id_module = Db::getInstance()->getValue($id_sql);
         if (is_array($hook_name)) {
             $hook_names = $hook_name;
         } else {
             $hook_names = array($hook_name);
         }
         foreach ($hook_names as $hook_name) {
             if (!Validate::isHookName($hook_name)) {
                 throw new PrestaShopException('Invalid hook name');
             }
             if (!isset($id_module) || !is_numeric($id_module)) {
                 return false;
             }
             //$hook_name_bak = $hook_name;
             if ($alias = Hook::getRetroHookName($hook_name)) {
                 $hook_name = $alias;
             }
             $id_hook = Hook::getIdByName($hook_name);
             //$live_edit = Hook::getLiveEditById((int) Hook::getIdByName($hook_name_bak));
             if (!$id_hook) {
                 $new_hook = new Hook();
                 $new_hook->name = pSQL($hook_name);
                 $new_hook->title = pSQL($hook_name);
                 $new_hook->live_edit = (bool) preg_match('/^display/i', $new_hook->name);
                 $new_hook->position = (bool) $new_hook->live_edit;
                 $new_hook->add();
                 $id_hook = $new_hook->id;
                 if (!$id_hook) {
                     return false;
                 }
             }
             if (is_null($shop_list)) {
                 $shop_list = Shop::getShops(true, null, true);
             }
             foreach ($shop_list as $shop_id) {
                 $sql = 'SELECT hm.`id_module`
                     FROM `' . _DB_PREFIX_ . 'hook_module` hm, `' . _DB_PREFIX_ . 'hook` h
                     WHERE hm.`id_module` = ' . (int) $id_module . ' AND h.`id_hook` = ' . $id_hook . '
                     AND h.`id_hook` = hm.`id_hook` AND `id_shop` = ' . (int) $shop_id;
                 if (Db::getInstance()->getRow($sql)) {
                     continue;
                 }
                 $sql = 'SELECT MAX(`position`) AS position
                     FROM `' . _DB_PREFIX_ . 'hook_module`
                     WHERE `id_hook` = ' . (int) $id_hook . ' AND `id_shop` = ' . (int) $shop_id;
                 if (!($position = Db::getInstance()->getValue($sql))) {
                     $position = 0;
                 }
                 $return &= Db::getInstance()->insert('hook_module', array('id_module' => (int) $id_module, 'id_hook' => (int) $id_hook, 'id_shop' => (int) $shop_id, 'position' => (int) ($position + 1)));
             }
         }
         return $return;
     } else {
         return false;
     }
 }
Example #28
0
 public static function print_module_list($status = 'all', $onDiskOnly = true)
 {
     $_GET['controller'] = 'AdminModules';
     $_GET['tab'] = 'AdminModules';
     $modulesOnDisk = Module::getModulesOnDisk();
     switch ($status) {
         case 'all':
             $table = new cli\Table();
             $table->setHeaders(array('ID', 'Name', 'Installed', 'Active', 'Upgradable'));
             foreach ($modulesOnDisk as $module) {
                 if ($onDiskOnly && isset($module->not_on_disk)) {
                     continue;
                 }
                 Module::isInstalled($module->name) ? $iStat = 'Yes' : ($iStat = 'No');
                 Module::isEnabled($module->name) ? $aStat = 'Yes' : ($aStat = 'No');
                 // check for updates
                 if (isset($module->version_addons) && $module->version_addons) {
                     $uStat = 'Yes';
                 } else {
                     $uStat = 'No';
                 }
                 $table->addRow(array($module->id, $module->name, $iStat, $aStat, $uStat));
             }
             break;
         case 'installed':
             foreach ($modulesOnDisk as $module) {
                 if ($module->installed) {
                     echo "{$module->id};" . "{$module->name};" . "{$module->installed};" . "{$module->active}\n";
                 }
             }
             break;
         case 'active':
             foreach ($modulesOnDisk as $module) {
                 if ($module->active) {
                     echo "{$module->id};" . "{$module->name};" . "{$module->installed};" . "{$module->active}\n";
                 }
             }
             break;
         default:
             return false;
             break;
     }
     $interface = PS_CLI_Interface::getInterface();
     if ($table) {
         //$table->display();
         $interface->add_table($table);
     }
     return true;
 }
Example #29
0
 public static function getPlugin($name, $base = null)
 {
     $cache_id = 'psm.plugin:' . $name . '!' . $base;
     if (!Cache::isStored($cache_id)) {
         if ($base == null && !Module::isEnabled($name)) {
             Cache::store($cache_id, false);
         } else {
             $classname = Tools::toCamelCase($name, true) . 'Plugin';
             $basedir = $base == null ? $name : $base . '/plugins/' . Tools::strtolower($name);
             $file = _PS_MODULE_DIR_ . $basedir . '/' . $classname . '.php';
             $file = self::normalizePath($file);
             if (is_file($file)) {
                 require_once $file;
                 Cache::store($cache_id, new $classname());
             } else {
                 Cache::store($cache_id, false);
             }
         }
     }
     return Cache::retrieve($cache_id);
 }
 /**
  * Method is used to check the current status of the module whether its active or not.
  */
 private function checkModuleStatus()
 {
     return Module::isEnabled('labsmobile');
 }