/** * Create a link to a photo * * @param mixed $photo Photos object (can be an ID supplier, but deprecated) * @param string $alias * @param int $id_lang * @return string */ public static function getPhotosLink($photo, $alias = null, $id_lang = null, $id_shop = null) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } if ($id_shop === null) { $shop = Context::getContext()->shop; } else { $shop = new Shop($id_shop); } $url = 'http://' . $shop->domain . $shop->getBaseURI() . $this->getLangLink($id_lang, null, $id_shop); $dispatcher = Dispatcher::getInstance(); if (!is_object($photo)) { if ($alias !== null && !$dispatcher->hasKeyword('photo_rule', $id_lang, 'meta_keywords', $id_shop) && !$dispatcher->hasKeyword('photo_rule', $id_lang, 'meta_title', $id_shop)) { return $url . $dispatcher->createUrl('photo_rule', $id_lang, array('id' => (int) $photo, 'rewrite' => (string) $alias), $this->allow, '', $id_shop); } $photo = new Photos($photo, $id_lang); } // Set available keywords $params = array(); $params['id'] = $photo->id; $params['rewrite'] = !$alias ? $photo->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($photo->meta_keywords); $params['meta_title'] = Tools::str2url($photo->meta_title); return $url . $dispatcher->createUrl('photo_rule', $id_lang, $params, $this->allow, '', $id_shop); }
function add_missing_rewrite_value() { $pages = Db::getInstance()->ExecuteS(' SELECT * FROM `' . _DB_PREFIX_ . 'meta` m LEFT JOIN `' . _DB_PREFIX_ . 'meta_lang` ml ON (m.`id_meta` = ml.`id_meta`) WHERE ml.`url_rewrite` = \'\' AND m.`page` != "index" '); foreach ($pages as $page) { Db::getInstance()->Execute(' UPDATE `' . _DB_PREFIX_ . 'meta_lang` SET `url_rewrite` = "' . pSQL(Tools::str2url($page['title'])) . '" WHERE `id_meta` = ' . (int) $page['id_meta'] . ' AND `id_lang` = ' . (int) $page['id_lang']); } }
/** * Create a link to a category * * @param mixed $category Category object (can be an ID category, but deprecated) * @param string $alias * @param int $id_lang * @param string $selected_filters Url parameter to autocheck filters of the module blocklayered * @return string */ public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } if ($id_shop === null) { $shop = Context::getContext()->shop; } else { $shop = new Shop($id_shop); } $url = 'http://' . $shop->domain . $shop->getBaseURI() . $this->getLangLink($id_lang, null, $id_shop); if (!is_object($category)) { $category = new Category($category, $id_lang); } // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = !$alias ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->meta_keywords); $params['meta_title'] = Tools::str2url($category->meta_title); // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) { $rule = 'category_rule'; } else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } //$params['category'] = $category->link_rewrite; $cats = array(); $subCategories = $this->_getParentsCategories($category->id); $subCategories = is_array($subCategories) === TRUE ? array_reverse($subCategories) : $subCategories; $skip_list = Link::$category_disable_rewrite; $skip_list[] = $category->id; foreach ($subCategories as $cat) { if (!in_array($cat['id_category'], $skip_list)) { //remove root and home category from the URL $cats[] = $cat['link_rewrite']; } } $params['categories'] = implode('/', $cats); return $url . Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow); }
public function getCategoryLink($category, $alias = NULL, $id_lang = NULL, $selected_filters = NULL, $id_shop = NULL) { $dispatcher = Dispatcher::getInstance(); if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = _PS_BASE_URL_ . __PS_BASE_URI__ . $this->getLangLink($id_lang); if (!is_object($category)) { $category = new Category($category, $id_lang); } // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = !$alias ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->meta_keywords); $params['meta_title'] = Tools::str2url($category->meta_title); // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) { $rule = 'category_rule'; } else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } if ($dispatcher->hasKeyword('category_rule', $id_lang, 'parent_categories')) { //RETRIEVING ALL THE PARENT CATEGORIES $cats = array(); foreach ($category->getParentsCategories() as $cat) { if (!in_array($cat['id_category'], array(1, 2, $category->id))) { //remove root, home and current category from the URL $cats[] = $cat['link_rewrite']; } } //THE CATEGORIES ARE BEING ASSIGNED IN THE WRONG ORDER (?) $params['parent_categories'] = implode('/', array_reverse($cats)); //ADD THE URL SLASHES TO THE CATEGORIES IN REVERSE ORDER } return $url . Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow); }
/** * Create a link to a category * * @param mixed $category Category object (can be an ID category, but deprecated) * @param string $alias * @param int $id_lang * @param string $selected_filters Url parameter to autocheck filters of the module blocklayered * @return string */ public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null, $relative_protocol = false) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = $this->getBaseLink($id_shop, null, $relative_protocol) . $this->getLangLink($id_lang, null, $id_shop); if (!is_object($category)) { $category = new Category($category, $id_lang); } // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = !$alias ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->getFieldByLang('meta_keywords')); $params['meta_title'] = Tools::str2url($category->getFieldByLang('meta_title')); // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) { $rule = 'category_rule'; } else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } $dispatcher = Dispatcher::getInstance(); if ($dispatcher->hasKeyword('category_rule', $id_lang, 'parent_categories')) { // Retrieve all parent categories $p_cats = array(); foreach ($category->getParentsCategories($id_lang) as $p_cat) { // remove root and current category from the URL if (!in_array($p_cat['id_category'], array_merge(self::$category_disable_rewrite, array($category->id)))) { $p_cats[] = $p_cat['link_rewrite']; } } // add the URL slashes among categories, in reverse order $params['parent_categories'] = implode('/', array_reverse($p_cats)); } return $url . $dispatcher->createUrl($rule, $id_lang, $params, $this->allow, '', $id_shop); }
/** * Create a link to a manufacturer * * @param mixed $manufacturer Manufacturer object (can be an ID supplier, but deprecated) * @param string $alias * @param int $id_lang * @return string */ public function getManufacturerLink($manufacturer, $alias = null, $id_lang = null, $id_shop = null, $relative_protocol = false) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = $this->getBaseLink($id_shop, null, $relative_protocol) . $this->getLangLink($id_lang, null, $id_shop); $dispatcher = Dispatcher::getInstance(); if (!is_object($manufacturer)) { if ($alias !== null && !$dispatcher->hasKeyword('manufacturer_rule', $id_lang, 'meta_keywords', $id_shop) && !$dispatcher->hasKeyword('manufacturer_rule', $id_lang, 'meta_title', $id_shop)) { return $url . $dispatcher->createUrl('manufacturer_rule', $id_lang, array('id' => (int) $manufacturer, 'rewrite' => (string) $alias), $this->allow, '', $id_shop); } $manufacturer = new Manufacturer($manufacturer, $id_lang); } // Set available keywords $params = array(); $params['id'] = $manufacturer->id; $params['rewrite'] = !$alias ? $manufacturer->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($manufacturer->meta_keywords); $params['meta_title'] = Tools::str2url($manufacturer->meta_title); return $url . $dispatcher->createUrl('manufacturer_rule', $id_lang, $params, $this->allow, '', $id_shop); }
/** * Return the friendly url from the provided string * * @param string $str * @param bool $utf8_decode => needs to be marked as deprecated * @return string */ public static function link_rewrite($str, $utf8_decode = false) { return Tools::str2url($str); }
public function generateXML($cron) { $shop_url = 'http://' . Tools::getHttpHost(false, true) . __PS_BASE_URI__; $id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); $currency_default = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $this->currency_iso = $currency_default->iso_code; $country = new Country(Configuration::get('PS_COUNTRY_DEFAULT')); $this->country_name = $country->name; $currencies = Currency::getCurrencies(); $categories = Category::getCategories($id_lang, false, false); $yamarket_set_combinations = Configuration::get('YA_MARKET_SET_COMBINATIONS'); $this->yamarket_availability = Configuration::get('YA_MARKET_DOSTUPNOST'); $this->gzip = Configuration::get('YA_MARKET_SET_GZIP'); /*-----------------------------------------------------------------------------*/ $cats = array(); if ($c = Configuration::get('YA_MARKET_CATEGORIES')) { $uc = unserialize($c); if (is_array($uc)) { $cats = $uc; } } $yml = new Yml(); $yml->yml('utf-8'); $yml->setShop(Configuration::get('PS_SHOP_NAME'), Configuration::get('YA_MARKET_NAME'), $shop_url); if (Configuration::get('YA_MARKET_SET_ALLCURRENCY')) { foreach ($currencies as $currency) { $yml->addCurrency($currency['iso_code'], (double) $currency_default->conversion_rate / (double) $currency['conversion_rate']); } unset($currencies); } else { $yml->addCurrency($currency_default->iso_code, (double) $currency_default->conversion_rate); } foreach ($categories as $category) { if (!in_array($category['id_category'], $cats) || $category['id_category'] == 1) { continue; } if (Configuration::get('YA_MARKET_SET_NACTIVECAT')) { if (!$category['active']) { continue; } } if (Configuration::get('YA_MARKET_CATALL')) { if (in_array($category['id_category'], $cats)) { $yml->addCategory($category['name'], $category['id_category'], $category['id_parent']); } } else { $yml->addCategory($category['name'], $category['id_category'], $category['id_parent']); } } foreach ($yml->categories as $cat) { $category_object = new Category($cat['id']); $products = $category_object->getProducts($id_lang, 1, 10000); if ($products) { foreach ($products as $product) { if ($product['id_category_default'] != $cat['id']) { continue; } $data = array(); if ($yamarket_set_combinations && !Configuration::get('YA_MARKET_SHORT')) { $product_object = new Product($product['id_product'], false, $id_lang); $combinations = $product_object->getAttributeCombinations($id_lang); } else { $combinations = false; } if (is_array($combinations) && count($combinations) > 0) { $comb_array = array(); foreach ($combinations as $combination) { $comb_array[$combination['id_product_attribute']]['id_product_attribute'] = $combination['id_product_attribute']; $comb_array[$combination['id_product_attribute']]['price'] = Product::getPriceStatic($product['id_product'], true, $combination['id_product_attribute']); $comb_array[$combination['id_product_attribute']]['reference'] = $combination['reference']; $comb_array[$combination['id_product_attribute']]['ean13'] = $combination['ean13']; $comb_array[$combination['id_product_attribute']]['quantity'] = $combination['quantity']; $comb_array[$combination['id_product_attribute']]['minimal_quantity'] = $combination['minimal_quantity']; $comb_array[$combination['id_product_attribute']]['weight'] = $combination['weight']; $comb_array[$combination['id_product_attribute']]['attributes'][$combination['group_name']] = $combination['attribute_name']; if (!isset($comb_array[$combination['id_product_attribute']]['comb_url'])) { $comb_array[$combination['id_product_attribute']]['comb_url'] = ''; } $comb_array[$combination['id_product_attribute']]['comb_url'] .= '/' . Tools::str2url($combination['group_name']) . '-' . str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::str2url(str_replace(array(',', '.'), '-', $combination['attribute_name']))); } foreach ($comb_array as $combination) { $data = $this->makeData($product, $combination); $available = $data['available']; unset($data['available']); if (!empty($data) && $data['price'] != 0) { $yml->addOffer($data['id'], $data, $available); } } } else { $data = $this->makeData($product); $available = $data['available']; unset($data['available']); if (!empty($data) && (int) $data['price'] != 0) { $yml->addOffer($data['id'], $data, $available); } } unset($data); } } unset($product); } unset($categories); $xml = $yml->getXml(); if ($cron) { if ($fp = fopen(_PS_UPLOAD_DIR_ . 'yml.' . $this->context->shop->id . '.xml' . ($this->gzip ? '.gz' : ''), 'w')) { fwrite($fp, $xml); fclose($fp); $this->logSave('market_generate: Cron ' . $this->l('Generate price')); } } else { if ($this->gzip) { header('Content-type:application/x-gzip'); header('Content-Disposition: attachment; filename=yml.' . $this->context->shop->id . '.xml.gz'); $this->logSave('market_generate: gzip view ' . $this->l('Generate price')); } else { header('Content-type:application/xml; charset=windows-1251'); } $this->logSave('market_generate: view ' . $this->l('Generate price')); echo $xml; exit; } }
public function getCMSLink($cms, $alias = null, $ssl = null, $id_lang = null, $id_shop = null, $relative_protocol = false) { if (!Module::isInstalled('agilemultipleshop')) { return parent::getCMSLink($cms, $alias = null, $ssl = null, $id_lang = null, $id_shop, $relative_protocol); } $url_choice_cms = (int) Configuration::get('ASP_URL_CHOICE_CMS'); if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $id_seller = AgileSellerManager::getObjectOwnerID('cms', is_object($cms) ? $cms->id : (int) $cms); $url = $this->getAgileBaseUrl($url_choice_cms == 2, $id_seller, $ssl, $relative_protocol) . $this->getLangLink($id_lang, null, $id_shop); $dispatcher = Dispatcher::getInstance(); if (!is_object($cms)) { if ($alias !== null && !$dispatcher->hasKeyword('cms_rule', $id_lang, 'meta_keywords', $id_shop) && !$dispatcher->hasKeyword('cms_rule', $id_lang, 'meta_title', $id_shop)) { return $url . $dispatcher->createUrl('cms_rule', $id_lang, array('id' => (int) $cms, 'rewrite' => (string) $alias), $this->allow, '', $id_shop); } $cms = new CMS($cms, $id_lang); } $params = array(); $params['id'] = $cms->id; $params['rewrite'] = !$alias ? is_array($cms->link_rewrite) ? $cms->link_rewrite[(int) $id_lang] : $cms->link_rewrite : $alias; $params['meta_keywords'] = ''; if (isset($cms->meta_keywords) && !empty($cms->meta_keywords)) { $params['meta_keywords'] = is_array($cms->meta_keywords) ? Tools::str2url($cms->meta_keywords[(int) $id_lang]) : Tools::str2url($cms->meta_keywords); } $params['meta_title'] = ''; if (isset($cms->meta_title) && !empty($cms->meta_title)) { $params['meta_title'] = is_array($cms->meta_title) ? Tools::str2url($cms->meta_title[(int) $id_lang]) : Tools::str2url($cms->meta_title); } return $url . $dispatcher->createUrl('cms_rule', $id_lang, $params, $this->allow, '', $id_shop); }
public static function getValidEvidence($index, $transaction) { $ret_valid_evidence = array(); switch ($index) { case 'by_tax_number': if (isset($transaction['evidence']['by_tax_number'])) { if (!(bool) $transaction['evidence']['by_tax_number']['used']) { $ret_valid_evidence['error'] = 'We Need To Verify Your Billing Address As The Vat Number Is From A Different Country.'; $ret_valid_evidence['error'] .= ' Please Update Your Billing Address'; } } else { $ret_valid_evidence['error'] = 'We Need More Information To Verify Your Billing Address, Enter Your Vat Number On Your Billing Address'; } break; case 'by_cc': if (isset($transaction['evidence']['by_cc'])) { if (!(bool) $transaction['evidence']['by_cc']['used']) { $ret_valid_evidence['error'] = 'We Need To Verify Your Billing Address, Your Credit Card Prefix Does Not Match'; $ret_valid_evidence['error'] .= ' The Indicated Billing Country, Please Update Your User Data'; } } else { $ret_valid_evidence['error'] = 'We Need More Information To Verify Your Billing Address, Please Enter Your Credit Card'; $ret_valid_evidence['error'] .= ' Prefix In Your User Data <strong><a href="' . Tools::str2url('identity') . '" class="alert-link">Click here.</a></strong>'; } break; case 'forced': if (isset($transaction['evidence']['forced'])) { if (!(bool) $transaction['evidence']['forced']['used']) { $ret_valid_evidence['error'] = 'We Need To Verify Your Billing Address, Your Country Of Residence Does Not Match'; $ret_valid_evidence['error'] .= ' The Billing Country Indicated, Please Update Your User Data'; } } else { $ret_valid_evidence['error'] = 'We Need More Information To Verify Your Billing Address, Please Enter Your Country Of'; $ret_valid_evidence['error'] = ' Residence In Your User Data <strong><a href="' . Tools::str2url('identity') . '" class="alert-link">Click here.</a></strong>'; } break; } return $ret_valid_evidence; }
/** * Create a link to a CMS page * * @param mixed $cms CMS object (can be an ID CMS, but deprecated) * @param string $alias * @param bool $ssl * @param int $id_lang * @return string */ public function getCMSLink($cms, $alias = null, $ssl = null, $id_lang = null, $id_shop = null) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = $this->getBaseLink($id_shop, $ssl) . $this->getLangLink($id_lang, null, $id_shop); $dispatcher = Dispatcher::getInstance(); if (!is_object($cms)) { $cms = new CMS($cms, $id_lang); if (!Validate::isLoadedObject($cms) && !$dispatcher->hasKeyword('cms_rule', $id_lang, 'meta_keywords', $id_shop) && !$dispatcher->hasKeyword('cms_rule', $id_lang, 'meta_title', $id_shop)) { return $url . $dispatcher->createUrl('cms_rule', $id_lang, array('id' => (int) $cms, 'rewrite' => (string) $alias), $this->allow, '', $id_shop); } $cms = new CMS($cms, $id_lang); } // Set available keywords $params = array(); $params['id'] = $cms->id; $params['rewrite'] = !$alias ? is_array($cms->link_rewrite) ? $cms->link_rewrite[(int) $id_lang] : $cms->link_rewrite : $alias; $params['meta_keywords'] = ''; if (isset($cms->meta_keywords) && !empty($cms->meta_keywords)) { $params['meta_keywords'] = is_array($cms->meta_keywords) ? Tools::str2url($cms->meta_keywords[(int) $id_lang]) : Tools::str2url($cms->meta_keywords); } $params['meta_title'] = ''; if (isset($cms->meta_title) && !empty($cms->meta_title)) { $params['meta_title'] = is_array($cms->meta_title) ? Tools::str2url($cms->meta_title[(int) $id_lang]) : Tools::str2url($cms->meta_title); } $params['category_cms_rewrite'] = ''; if (isset($cms->id_cms_category) && !empty($cms->id_cms_category)) { $params['category_cms_rewrite'] = Tools::str2url(CMSCategory::getLinkRewrite($cms->id_cms_category, $id_lang)); } return $url . $dispatcher->createUrl('cms_rule', $id_lang, $params, $this->allow, '', $id_shop); }
public function saveBlog() { // Validate $this->validateBlog(); $languages = Language::getLanguages(0); // insert new data $title = Tools::getValue('title'); $link_rewrite = Tools::str2url($title); $short_description = Tools::getValue('short_description'); $content = Tools::getValue('content'); // Insert into smart_blog_post table $query_blog = "INSERT INTO " . _DB_PREFIX_ . "smart_blog_post (`id_author`, `id_category`, `position`, `active`, `available`, `created`, `post_type`, `comment_status`,`viewed`, `is_featured`)\n\t\t\t\t VALUES ('" . $this->context->controller->seller->id . "', 1, 0, 1, 1, '" . date('Y-m-d H:i:s') . "', 0, 1,0,0)"; Db::getInstance()->execute($query_blog); $last_id = Db::getInstance()->Insert_ID(); // insert into smart_blog_post_lang table $insert_data = array(); foreach ($languages as $key => $value) { $id_lang = $value['id_lang']; $insert_data[] = '(' . $last_id . ', ' . $id_lang . ', "' . pSQL($title) . '", "' . pSQL($short_description) . '", "' . pSQL($short_description) . '", "' . pSQL($content) . '", "' . pSQL($link_rewrite) . '")'; } $flat_data = implode(",", $insert_data); $query_blog_lang = "INSERT INTO " . _DB_PREFIX_ . "smart_blog_post_lang (`id_smart_blog_post`, `id_lang`, `meta_title`, `meta_description`, `short_description`, `content`, `link_rewrite`) VALUES \n\t\t" . $flat_data; Db::getInstance()->execute($query_blog_lang); // insert into smart_blog_post_shop $blog_shop = "INSERT INTO " . _DB_PREFIX_ . "smart_blog_post_shop (`id_smart_blog_post`,`id_shop`) VALUES(" . $last_id . ",1)"; Db::getInstance()->execute($blog_shop); return $last_id; // die('<pre>'.print_r($query, true)); }
public function catchUrls() { if (Tools::getValue('ajax') && (bool) Tools::getValue('ajax') == true) { return; } // Setup $uri_var = $this->formatLink($_SERVER['REQUEST_URI']); $id_shop = Shop::getContextShopID(); $db = Db::getInstance(); $redir = array(); $cache_enabled = (bool) Configuration::get('MGRT_URLCACHE'); $cache_name = 'MR1_' . $id_shop . '_' . Tools::str2url($uri_var); $cache_file = $this->cache_folder . md5($cache_name); // Better checking this before if ($cache_enabled === true && is_writable(_PS_CACHE_DIR_) && file_exists($this->cache_folder)) { $time_cache = (int) Configuration::get('MGRT_CACHETIME'); if (file_exists($cache_file) && filemtime($cache_file) > time() - $time_cache * 60) { $datas = Tools::file_get_contents($cache_file); $redir = unserialize($datas); return $this->makeRedirection($redir); } } $sql_redir = $db->getRow('SELECT * FROM ' . _DB_PREFIX_ . 'redirect r, ' . _DB_PREFIX_ . 'redirect_shop rs WHERE rs.id_redirect = r.id_redirect AND r.old = "' . pSQL($uri_var) . '" AND rs.id_shop = ' . (int) $id_shop . ' AND r.active = 1 AND r.regex = 0 ORDER BY date_upd DESC'); if (empty($sql_redir)) { $sql_regex = $db->executeS('SELECT * FROM ' . _DB_PREFIX_ . 'redirect r, ' . _DB_PREFIX_ . 'redirect_shop rs WHERE rs.id_redirect = r.id_redirect AND rs.id_shop = ' . (int) $id_shop . ' AND r.active = 1 AND r.regex = 1 ORDER BY date_upd DESC'); $before = '/\\'; $after = '/i'; if (!empty($sql_regex)) { foreach ($sql_regex as $value) { $test = preg_match($before . $value['old'] . $after, $uri_var); if ((bool) $test === true) { $redir['new'] = preg_replace($before . $value['old'] . $after, $value['new'], $uri_var); $redir['type'] = $value['type']; break; } } } } else { // Match $redir = $sql_redir; } if ($cache_enabled === true && is_writable(_PS_CACHE_DIR_) && file_exists($this->cache_folder)) { try { file_put_contents($cache_file, serialize($redir), LOCK_EX); } catch (Exception $e) { PrestaShopLogger::addLog('Redirect Cache folder not writable, please check your modules folder permissions.'); } } $this->makeRedirection($redir); }
public static function getCategory($categ, $categParent = 0, $idShop, $type) { $idCategory = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_category` FROM `' . _DB_PREFIX_ . 'ec_ecopresto_category_shop` WHERE `name` = "' . pSQL(base64_encode($categ)) . '" AND `id_shop` = ' . (int) self::getInfoEco('ID_SHOP')); if (!$idCategory) { if ($categParent == 0) { if (version_compare(_PS_VERSION_, '1.5', '>=')) { $categParent = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category` WHERE `is_root_category` = 1'); } else { $categParent = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category` WHERE `id_parent` = 0'); } $level = 1; } else { $categLevel = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT `level_depth` FROM `' . _DB_PREFIX_ . 'category` WHERE `id_category` = ' . (int) $categParent); $level = $categLevel + 1; } $posCateg = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT max(`position`) FROM `' . _DB_PREFIX_ . 'category` WHERE `id_parent` = ' . (int) $categParent); if (version_compare(_PS_VERSION_, '1.4', '>=') && version_compare(_PS_VERSION_, '1.5', '<')) { Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'category` (`id_parent`,`active`,`level_depth`,`date_add`,`date_upd`,`position`) VALUES (' . (int) $categParent . ',1,' . (int) $level . ',"' . pSQL(date("Y-m-d H:i:s")) . '","' . pSQL(date("Y-m-d H:i:s")) . '",' . (int) ($posCateg + 1) . ')'); } else { Db::getInstance()->insert('category', array('id_parent' => (int) $categParent, 'id_shop_default' => (int) $idShop, 'active' => 1, 'level_depth' => (int) $level, 'date_add' => pSQL(date('Y-m-d H:i:s')), 'date_upd' => pSQL(date('Y-m-d H:i:s')), 'position' => (int) $posCateg + 1)); } $idCategory = Db::getInstance()->Insert_ID(); $all_lang = Language::getLanguages(true); foreach ($all_lang as $lang) { if (version_compare(_PS_VERSION_, '1.5', '>=')) { Db::getInstance()->insert('category_lang', array('id_category' => (int) $idCategory, 'id_shop' => (int) $idShop, 'id_lang' => (int) $lang['id_lang'], 'name' => pSQL(self::getIdLangEcoCateg($categ, $lang['id_lang'], $idShop, $type)), 'link_rewrite' => Tools::str2url(self::getIdLangEcoCateg($categ, $lang['id_lang'], $idShop, $type)))); } else { Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'category_lang` (`id_category`,`id_lang`,`name`,`link_rewrite`) VALUES (' . (int) $idCategory . ',' . (int) $lang['id_lang'] . ',"' . pSQL(self::getIdLangEcoCateg($categ, $lang['id_lang'], $idShop, $type)) . '","' . Tools::str2url(self::getIdLangEcoCateg($categ, $lang['id_lang'], $idShop, $type)) . '")'); } } if (version_compare(_PS_VERSION_, '1.5', '>=')) { $posCategShop = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT max(`position`) FROM `' . _DB_PREFIX_ . 'category_shop` WHERE `id_shop`=' . (int) $idShop); Db::getInstance()->insert('category_shop', array('id_category' => (int) $idCategory, 'id_shop' => (int) $idShop, 'position' => (int) $posCategShop + 1)); } $all_group = Group::getGroups(self::getInfoEco('ID_LANG')); foreach ($all_group as $group) { Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'category_group` (`id_category`,`id_group`) VALUES (' . (int) $idCategory . ',' . (int) $group['id_group'] . ')'); } if (version_compare(_PS_VERSION_, '1.5', '>=')) { Db::getInstance()->insert('ec_ecopresto_category_shop', array('name' => pSQL(base64_encode($categ)), 'id_category' => (int) $idCategory, 'id_shop' => (int) $idShop)); } else { Db::getInstance()->execute('INSERT INTO `' . _DB_PREFIX_ . 'ec_ecopresto_category_shop` (`name`,`id_category`,`id_shop`) VALUES ("' . pSQL(base64_encode($categ)) . '",' . (int) $idCategory . ',' . (int) $idShop . ')'); } Category::regenerateEntireNtree(); } return $idCategory; }
/** * Return the friendly url from the provided string * * @param string $str * @param bool $utf8_decode (deprecated) * * @return string */ public static function link_rewrite($str, $utf8_decode = null) { if ($utf8_decode !== null) { Tools::displayParameterAsDeprecated('utf8_decode'); } return Tools::str2url($str); }
protected function uploadImage($image, $image_w = '', $image_h = '') { $res = false; if (is_array($image) && ImageManager::validateUpload($image, $this->max_image_size) === false && ($tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS')) && move_uploaded_file($image['tmp_name'], $tmp_name)) { $salt = sha1(microtime()); $pathinfo = pathinfo($image['name']); $img_name = $salt . '_' . Tools::str2url($pathinfo['filename']) . '.' . $pathinfo['extension']; if (ImageManager::resize($tmp_name, dirname(__FILE__) . '/img/' . $img_name, $image_w, $image_h)) { $res = true; } } if (!$res) { $this->context->smarty->assign('error', $this->l('An error occurred during the image upload.')); return false; } return $img_name; }
/** * Create a link to a manufacturer * * @param mixed $manufacturer Manufacturer object (can be an ID supplier, but deprecated) * @param string $alias * @param int $id_lang * @return string */ public function getManufacturerLink($manufacturer, $alias = null, $id_lang = null) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = _PS_BASE_URL_ . __PS_BASE_URI__ . $this->getLangLink($id_lang); if (!is_object($manufacturer)) { $manufacturer = new Manufacturer($manufacturer, $id_lang); } // Set available keywords $params = array(); $params['id'] = $manufacturer->id; $params['rewrite'] = !$alias ? $manufacturer->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($manufacturer->meta_keywords); $params['meta_title'] = Tools::str2url($manufacturer->meta_title); return $url . Dispatcher::getInstance()->createUrl('manufacturer_rule', $id_lang, $params, $this->allow); }