Example #1
0
 public function getImageLink($name, $ids, $type = null, $overimage = null)
 {
     $not_default = false;
     $theme = Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_ . $ids . ($type ? '-' . $type : '') . '-' . (int) Context::getContext()->shop->id_theme . '.jpg') ? '-' . Context::getContext()->shop->id_theme : '';
     if (Configuration::get('PS_LEGACY_IMAGES') && file_exists(_PS_PROD_IMG_DIR_ . $ids . ($type ? '-' . $type : '') . $theme . '.jpg') || ($not_default = strpos($ids, 'default') !== false)) {
         if ($this->allow == 1 && !$not_default) {
             $uri_path = __PS_BASE_URI__ . $ids . ($type ? '-' . $type : '') . $theme . '/' . $name . '.jpg';
         } else {
             $uri_path = _THEME_PROD_DIR_ . $ids . ($type ? '-' . $type : '') . $theme . '.jpg';
         }
     } else {
         $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 . '.jpg') ? '-' . Context::getContext()->shop->id_theme : '';
         if (isset($overimage)) {
             $sql = "SELECT id_image FROM  `" . _DB_PREFIX_ . "image` WHERE  `id_product` =  '{$overimage}' AND position = 2";
             $getoverimage = Db::getInstance()->getRow($sql);
             if ($getoverimage) {
                 $id_image = array_shift($getoverimage);
             } else {
                 return false;
             }
         }
         if ($this->allow == 1) {
             $uri_path = __PS_BASE_URI__ . $id_image . ($type ? '-' . $type : '') . $theme . '/' . $name . '.jpg';
         } else {
             $uri_path = _THEME_PROD_DIR_ . Image::getImgFolderStatic($id_image) . $id_image . ($type ? '-' . $type : '') . $theme . '.jpg';
         }
     }
     return $this->protocol_content . Tools::getMediaServer($uri_path) . $uri_path;
 }
Example #2
0
 /**
  * Returns a link to a product image for display
  * Note: the new image filesystem stores product images in subdirectories of img/p/
  *
  * @param string $name rewrite link of the image
  * @param string $ids id part of the image filename - can be "id_product-id_image" (legacy support, recommended) or "id_image" (new)
  * @param string $type
  */
 public function getImageLink($name, $ids, $type = null)
 {
     $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(_MODULE_SMARTBLOG_DIR_ . $ids . ($type ? '-' . $type : '') . '-' . (int) Context::getContext()->shop->id_theme . '.jpg') ? '-' . Context::getContext()->shop->id_theme : '';
     if (Configuration::get('PS_LEGACY_IMAGES') && file_exists(_MODULE_SMARTBLOG_DIR_ . $ids . ($type ? '-' . $type : '') . $theme . '.jpg') || ($not_default = strpos($ids, 'default') !== false)) {
         if ($this->allow == 1 && !$not_default) {
             $uri_path = __PS_BASE_URI__ . 'blog/' . $ids . ($type ? '-' . $type : '') . $theme . '/' . $name . '.jpg';
         } else {
             $uri_path = _THEME_PROD_DIR_ . $ids . ($type ? '-' . $type : '') . $theme . '.jpg';
         }
     } 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(_MODULE_SMARTBLOG_DIR_ . Image::getImgFolderStatic($id_image) . $id_image . ($type ? '-' . $type : '') . '-' . (int) Context::getContext()->shop->id_theme . '.jpg') ? '-' . Context::getContext()->shop->id_theme : '';
         if ($this->allow == 1) {
             $uri_path = __PS_BASE_URI__ . 'blog/' . $id_image . ($type ? '-' . $type : '') . $theme . '/' . $name . '.jpg';
         } else {
             $uri_path = __PS_BASE_URI__ . 'modules/smartblog/images/' . $id_image . ($type ? '-' . $type : '') . $theme . '.jpg';
         }
     }
     return $this->protocol_content . Tools::getMediaServer($uri_path) . $uri_path;
 }
 public function getImageLink($name, $ids, $type = null)
 {
     global $protocol_content;
     if (empty($protocol_content)) {
         $protocol_content = _PS_SSL_ENABLED_ ? 'https://' : 'http://';
     }
     // legacy mode or default image
     if (Configuration::get('PS_LEGACY_IMAGES') && file_exists(_PS_PROD_IMG_DIR_ . $ids . ($type ? '-' . $type : '') . '.jpg') || strpos($ids, 'default') !== false) {
         // if ($this->allow == 1)
         // 	$uri_path = __PS_BASE_URI__.$ids.($type ? '-'.$type : '').'/'.$name.'.jpg';
         // else
         // 	$uri_path = _THEME_PROD_DIR_.$ids.($type ? '-'.$type : '').'.jpg';
         $uri_path = _THEME_PROD_DIR_ . $ids . ($type ? '-' . $type : '') . '.jpg';
     } 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];
         // if ($this->allow == 1)
         // 	$uri_path = __PS_BASE_URI__.$id_image.($type ? '-'.$type : '').'/'.$name.'.jpg';
         // else
         // 	$uri_path = _THEME_PROD_DIR_.Image::getImgFolderStatic($id_image).$id_image.($type ? '-'.$type : '').'.jpg';
         $uri_path = _THEME_PROD_DIR_ . Image::getImgFolderStatic($id_image) . $id_image . ($type ? '-' . $type : '') . '.jpg';
     }
     return $protocol_content . Tools::getMediaServer($uri_path) . $uri_path;
 }
Example #4
0
 public static function batchDeleteProduct($id_products = array())
 {
     $ids_string = implode(",", $id_products);
     Db::getInstance()->exec('DELETE FROM `' . DB_PREFIX . 'product` WHERE `id_product` IN(' . pSQL($ids_string) . ')');
     Db::getInstance()->exec('DELETE FROM `' . DB_PREFIX . 'rule` WHERE `entity`="Product" AND `id_entity` IN(' . pSQL($ids_string) . ')');
     Db::getInstance()->exec('DELETE FROM `' . DB_PREFIX . 'product_to_category` WHERE `id_product` IN(' . pSQL($ids_string) . ')');
     Db::getInstance()->exec('DELETE FROM `' . DB_PREFIX . 'product_to_tag` WHERE `id_product` IN(' . pSQL($ids_string) . ')');
     Db::getInstance()->exec('DELETE FROM `' . DB_PREFIX . 'product_to_attribute` WHERE `id_product` IN(' . pSQL($ids_string) . ')');
     $result = Db::getInstance()->getAll('SELECT `id_image` FROM `' . DB_PREFIX . 'image` WHERE `id_product` IN(' . pSQL($ids_string) . ')');
     if ($result) {
         foreach ($result as $row) {
             Image::deleteAllImages(Image::getImgFolderStatic($row['id_image']));
         }
     }
     Db::getInstance()->exec('DELETE FROM `' . DB_PREFIX . 'image` WHERE `id_product` IN(' . pSQL($ids_string) . ')');
     return true;
 }
 /**
  * Returns the path to the folder containing the image in the new filesystem
  *
  * @return string path to folder
  */
 public function getImgFolder()
 {
     if (!$this->id) {
         return false;
     }
     if (!$this->folder) {
         $this->folder = Image::getImgFolderStatic($this->id);
     }
     return $this->folder;
 }
Example #6
0
 /**
  * Returns a link to a product image for display
  * Note: the new image filesystem stores product images in subdirectories of img/p/
  *
  * @param string $name rewrite link of the image
  * @param string $ids id part of the image filename - can be "id_product-id_image" (legacy support, recommended) or "id_image" (new)
  * @param string $type
  */
 public function getImageLink($name, $ids, $type = null)
 {
     $not_default = false;
     // legacy mode or default image
     $theme = Shop::isFeatureActive() && file_exists(_PS_PROD_IMG_DIR_ . $ids . ($type ? '-' . $type : '') . '-' . (int) Context::getContext()->shop->id_theme . '.jpg') ? '-' . Context::getContext()->shop->id_theme : '';
     if (Configuration::get('PS_LEGACY_IMAGES') && file_exists(_PS_PROD_IMG_DIR_ . $ids . ($type ? '-' . $type : '') . $theme . '.jpg') || ($not_default = strpos($ids, 'default') !== false)) {
         if ($this->allow == 1 && !$not_default) {
             $uri_path = __PS_BASE_URI__ . $ids . ($type ? '-' . $type : '') . $theme . '/' . $name . '.jpg';
         } else {
             $uri_path = _THEME_PROD_DIR_ . $ids . ($type ? '-' . $type : '') . $theme . '.jpg';
         }
     } 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 . '.jpg') ? '-' . Context::getContext()->shop->id_theme : '';
         if ($this->allow == 1) {
             $uri_path = __PS_BASE_URI__ . $id_image . ($type ? '-' . $type : '') . $theme . '/' . $name . '.jpg';
         } else {
             $uri_path = _THEME_PROD_DIR_ . Image::getImgFolderStatic($id_image) . $id_image . ($type ? '-' . $type : '') . $theme . '.jpg';
         }
     }
     return $this->protocol_content . Tools::getMediaServer($uri_path) . $uri_path;
 }
Example #7
0
 public function processExport($text_delimiter = '"')
 {
     // clean buffer
     if (ob_get_level() && ob_get_length() > 0) {
         ob_clean();
     }
     $this->getList($this->context->language->id, null, null, 0, false);
     if (!count($this->_list)) {
         return;
     }
     header('Content-type: text/csv');
     header('Content-Type: application/force-download; charset=UTF-8');
     header('Cache-Control: no-store, no-cache');
     header('Content-disposition: attachment; filename="' . $this->table . '_' . date('Y-m-d_His') . '.csv"');
     $headers = array();
     foreach ($this->fields_list as $key => $datas) {
         if ($datas['title'] == 'PDF') {
             unset($this->fields_list[$key]);
         } else {
             $headers[] = Tools::htmlentitiesDecodeUTF8($datas['title']);
         }
     }
     $content = array();
     foreach ($this->_list as $i => $row) {
         $content[$i] = array();
         $path_to_image = false;
         foreach ($this->fields_list as $key => $params) {
             $field_value = isset($row[$key]) ? Tools::htmlentitiesDecodeUTF8(Tools::nl2br($row[$key])) : '';
             if ($key == 'image') {
                 if ($params['image'] != 'p' || Configuration::get('PS_LEGACY_IMAGES')) {
                     $path_to_image = Tools::getShopDomain(true) . _PS_IMG_ . $params['image'] . '/' . $row['id_' . $this->table] . (isset($row['id_image']) ? '-' . (int) $row['id_image'] : '') . '.' . $this->imageType;
                 } else {
                     $path_to_image = Tools::getShopDomain(true) . _PS_IMG_ . $params['image'] . '/' . Image::getImgFolderStatic($row['id_image']) . (int) $row['id_image'] . '.' . $this->imageType;
                 }
                 if ($path_to_image) {
                     $field_value = $path_to_image;
                 }
             }
             if (isset($params['callback'])) {
                 $callback_obj = isset($params['callback_object']) ? $params['callback_object'] : $this->context->controller;
                 if (!preg_match('/<([a-z]+)([^<]+)*(?:>(.*)<\\/\\1>|\\s+\\/>)/ism', call_user_func_array(array($callback_obj, $params['callback']), array($field_value, $row)))) {
                     $field_value = call_user_func_array(array($callback_obj, $params['callback']), array($field_value, $row));
                 }
             }
             $content[$i][] = $field_value;
         }
     }
     $this->context->smarty->assign(array('export_precontent' => "", 'export_headers' => $headers, 'export_content' => $content, 'text_delimiter' => $text_delimiter));
     $this->layout = 'layout-export.tpl';
 }
Example #8
0
 public function displayListContent()
 {
     if ($this->position_identifier) {
         $id_category = (int) Tools::getValue('id_' . ($this->is_cms ? 'cms_' : '') . 'category', '1');
     } else {
         $id_category = Category::getRootCategory()->id;
     }
     if (isset($this->fields_list['position'])) {
         $positions = array_map(create_function('$elem', 'return (int)($elem[\'position\']);'), $this->_list);
         sort($positions);
     }
     // key_to_get is used to display the correct product category or cms category after a position change
     $identifier = in_array($this->identifier, array('id_category', 'id_cms_category')) ? '_parent' : '';
     if ($identifier) {
         $key_to_get = 'id_' . ($this->is_cms ? 'cms_' : '') . 'category' . $identifier;
     }
     foreach ($this->_list as $index => $tr) {
         $id = $tr[$this->identifier];
         $name = isset($tr['name']) ? $tr['name'] : null;
         if ($this->shopLinkType) {
             $this->_list[$index]['short_shop_name'] = Tools::strlen($tr['shop_name']) > 15 ? Tools::substr($tr['shop_name'], 0, 15) . '...' : $tr['shop_name'];
         }
         // Check all available actions to add to the current list row
         foreach ($this->actions as $action) {
             //Check if the action is available for the current row
             if (!array_key_exists($action, $this->list_skip_actions) || !in_array($id, $this->list_skip_actions[$action])) {
                 $method_name = 'display' . ucfirst($action) . 'Link';
                 if (method_exists($this->context->controller, $method_name)) {
                     $this->_list[$index][$action] = $this->context->controller->{$method_name}($this->token, $id, $name);
                 } elseif (method_exists($this, $method_name)) {
                     $this->_list[$index][$action] = $this->{$method_name}($this->token, $id, $name);
                 }
             }
         }
         // @todo skip action for bulk actions
         // $this->_list[$index]['has_bulk_actions'] = true;
         foreach ($this->fields_list as $key => $params) {
             $tmp = explode('!', $key);
             $key = isset($tmp[1]) ? $tmp[1] : $tmp[0];
             if (isset($params['active'])) {
                 // If method is defined in calling controller, use it instead of the Helper method
                 if (method_exists($this->context->controller, 'displayEnableLink')) {
                     $calling_obj = $this->context->controller;
                 } else {
                     $calling_obj = $this;
                 }
                 $this->_list[$index][$key] = $calling_obj->displayEnableLink($this->token, $id, $tr[$key], $params['active'], Tools::getValue('id_category'), Tools::getValue('id_product'));
             } elseif (isset($params['activeVisu'])) {
                 $this->_list[$index][$key] = (bool) $tr[$key];
             } elseif (isset($params['position'])) {
                 $this->_list[$index][$key] = array('position' => $tr[$key], 'position_url_down' => $this->currentIndex . (isset($key_to_get) ? '&' . $key_to_get . '=' . (int) $id_category : '') . '&' . $this->position_identifier . '=' . $id . '&way=1&position=' . ((int) $tr['position'] + 1) . '&token=' . $this->token, 'position_url_up' => $this->currentIndex . (isset($key_to_get) ? '&' . $key_to_get . '=' . (int) $id_category : '') . '&' . $this->position_identifier . '=' . $id . '&way=0&position=' . ((int) $tr['position'] - 1) . '&token=' . $this->token);
             } elseif (isset($params['image'])) {
                 // item_id is the product id in a product image context, else it is the image id.
                 $item_id = isset($params['image_id']) ? $tr[$params['image_id']] : $id;
                 if ($params['image'] != 'p' || Configuration::get('PS_LEGACY_IMAGES')) {
                     $path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . $item_id . (isset($tr['id_image']) ? '-' . (int) $tr['id_image'] : '') . '.' . $this->imageType;
                 } else {
                     $path_to_image = _PS_IMG_DIR_ . $params['image'] . '/' . Image::getImgFolderStatic($tr['id_image']) . (int) $tr['id_image'] . '.' . $this->imageType;
                 }
                 $this->_list[$index][$key] = ImageManager::thumbnail($path_to_image, $this->table . '_mini_' . $item_id . '.' . $this->imageType, 45, $this->imageType);
             } elseif (isset($params['icon']) && (isset($params['icon'][$tr[$key]]) || isset($params['icon']['default']))) {
                 if (isset($params['icon'][$tr[$key]]) && is_array($params['icon'][$tr[$key]])) {
                     $this->_list[$index][$key] = array('src' => $params['icon'][$tr[$key]]['src'], 'alt' => $params['icon'][$tr[$key]]['alt']);
                 } else {
                     $this->_list[$index][$key] = array('src' => isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default'], 'alt' => isset($params['icon'][$tr[$key]]) ? $params['icon'][$tr[$key]] : $params['icon']['default']);
                 }
             } elseif (isset($params['type']) && $params['type'] == 'float') {
                 $this->_list[$index][$key] = rtrim(rtrim($tr[$key], '0'), '.');
             } elseif (isset($params['type']) && $params['type'] == 'price') {
                 $currency = isset($params['currency']) && $params['currency'] ? Currency::getCurrencyInstance($tr['id_currency']) : $this->context->currency;
                 $this->_list[$index][$key] = Tools::displayPrice($tr[$key], $currency, false);
             } elseif (isset($params['type']) && $params['type'] == 'date') {
                 $this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id);
             } elseif (isset($params['type']) && $params['type'] == 'datetime') {
                 $this->_list[$index][$key] = Tools::displayDate($tr[$key], $this->context->language->id, true);
             } elseif (isset($tr[$key])) {
                 $echo = $tr[$key];
                 if (isset($params['callback'])) {
                     $callback_obj = isset($params['callback_object']) ? $params['callback_object'] : $this->context->controller;
                     $this->_list[$index][$key] = call_user_func_array(array($callback_obj, $params['callback']), array($echo, $tr));
                 } else {
                     $this->_list[$index][$key] = $echo;
                 }
             }
         }
     }
     $this->content_tpl->assign(array_merge($this->tpl_vars, array('shop_link_type' => $this->shopLinkType, 'name' => isset($name) ? $name : null, 'position_identifier' => $this->position_identifier, 'identifier' => $this->identifier, 'table' => $this->table, 'token' => $this->token, 'color_on_bg' => $this->colorOnBackground, 'id_category' => $id_category, 'bulk_actions' => $this->bulk_actions, 'positions' => isset($positions) ? $positions : null, 'order_by' => $this->orderBy, 'order_way' => $this->orderWay, 'is_cms' => $this->is_cms, 'fields_display' => $this->fields_list, 'list' => $this->_list, 'actions' => $this->actions, 'no_link' => $this->no_link, 'current_index' => $this->currentIndex, 'view' => in_array('view', $this->actions), 'edit' => in_array('edit', $this->actions), 'has_actions' => !empty($this->actions), 'has_bulk_actions' => !empty($this->bulk_actions), 'list_skip_actions' => $this->list_skip_actions, 'row_hover' => $this->row_hover)));
     return $this->content_tpl->fetch();
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     header('HTTP/1.1 404 Not Found');
     header('Status: 404 Not Found');
     if (preg_match('/\\.(gif|jpe?g|png|ico)$/i', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
         $this->context->cookie->disallowWriting();
         if (!isset($_SERVER['REDIRECT_URL'])) {
             $_SERVER['REDIRECT_URL'] = '';
             if (preg_match('@^' . __PS_BASE_URI__ . '([0-9]+)\\-([_a-zA-Z0-9-]+)(/[_a-zA-Z0-9-]+)?\\.jpg$@', $_SERVER['REQUEST_URI'], $matches)) {
                 $_SERVER['REDIRECT_URL'] = __PS_BASE_URI__ . 'p/' . Image::getImgFolderStatic($matches[0]) . '/' . $matches[0] . '-' . $matches[1] . '.jpg';
             }
         }
         if (preg_match('#/p[0-9/]*/([0-9]+)\\-([_a-zA-Z]*)\\.(png|jpe?g|gif)$#', $_SERVER['REDIRECT_URL'], $matches)) {
             // Backward compatibility since we suffixed the template image with _default
             if (Tools::strtolower(substr($matches[2], -8)) != '_default') {
                 header('Location: ' . $this->context->link->getImageLink('', $matches[1], $matches[2]), true, 302);
                 exit;
             } else {
                 $image_type = ImageType::getByNameNType($matches[2], 'products');
                 if ($image_type && count($image_type)) {
                     $root = _PS_PROD_IMG_DIR_;
                     $folder = Image::getImgFolderStatic($matches[1]);
                     $file = $matches[1];
                     $ext = '.' . $matches[3];
                     if (file_exists($root . $folder . $file . $ext)) {
                         if (ImageManager::resize($root . $folder . $file . $ext, $root . $folder . $file . '-' . $matches[2] . $ext, (int) $image_type['width'], (int) $image_type['height'])) {
                             header('HTTP/1.1 200 Found');
                             header('Status: 200 Found');
                             header('Content-Type: image/jpg');
                             readfile($root . $folder . $file . '-' . $matches[2] . $ext);
                             exit;
                         }
                     }
                 }
             }
         } elseif (preg_match('#/c/([0-9]+)\\-([_a-zA-Z]*)\\.(png|jpe?g|gif)$#', $_SERVER['REDIRECT_URL'], $matches)) {
             $image_type = ImageType::getByNameNType($matches[2], 'categories');
             if ($image_type && count($image_type)) {
                 $root = _PS_CAT_IMG_DIR_;
                 $file = $matches[1];
                 $ext = '.' . $matches[3];
                 if (file_exists($root . $file . $ext)) {
                     if (ImageManager::resize($root . $file . $ext, $root . $file . '-' . $matches[2] . $ext, (int) $image_type['width'], (int) $image_type['height'])) {
                         header('HTTP/1.1 200 Found');
                         header('Status: 200 Found');
                         header('Content-Type: image/jpg');
                         readfile($root . $file . '-' . $matches[2] . $ext);
                         exit;
                     }
                 }
             }
         }
         header('Content-Type: image/gif');
         readfile(_PS_IMG_DIR_ . '404.gif');
         exit;
     } elseif (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('.js', 'css'))) {
         $this->context->cookie->disallowWriting();
         exit;
     }
     parent::initContent();
     $this->setTemplate(_PS_THEME_DIR_ . '404.tpl');
 }
Example #10
0
 public function processExport()
 {
     // clean buffer
     if (ob_get_level() && ob_get_length() > 0) {
         ob_clean();
     }
     $this->getList($this->context->language->id);
     if (!count($this->_list)) {
         return;
     }
     header('Content-type: text/csv');
     header('Content-Type: application/force-download; charset=UTF-8');
     header('Cache-Control: no-store, no-cache');
     header('Content-disposition: attachment; filename="' . $this->table . '_' . date('Y-m-d_His') . '.csv"');
     $headers = array();
     foreach ($this->fields_list as $datas) {
         $headers[] = Tools::htmlentitiesDecodeUTF8($datas['title']);
     }
     $content = array();
     foreach ($this->_list as $i => $row) {
         $content[$i] = array();
         $path_to_image = false;
         foreach ($this->fields_list as $key => $params) {
             $field_value = isset($row[$key]) ? Tools::htmlentitiesDecodeUTF8($row[$key]) : '';
             if ($key == 'image') {
                 if ($params['image'] != 'p' || Configuration::get('PS_LEGACY_IMAGES')) {
                     $path_to_image = Tools::getShopDomain(true) . _PS_IMG_ . $params['image'] . '/' . $row['id_' . $this->table] . (isset($row['id_image']) ? '-' . (int) $row['id_image'] : '') . '.' . $this->imageType;
                 } else {
                     $path_to_image = Tools::getShopDomain(true) . _PS_IMG_ . $params['image'] . '/' . Image::getImgFolderStatic($row['id_image']) . (int) $row['id_image'] . '.' . $this->imageType;
                 }
                 if ($path_to_image) {
                     $field_value = $path_to_image;
                 }
             }
             $content[$i][] = $field_value;
         }
     }
     $this->context->smarty->assign(array('export_precontent' => "", 'export_headers' => $headers, 'export_content' => $content));
     $this->layout = 'layout-export.tpl';
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     $category_rewrite = explode('/', $_SERVER['REQUEST_URI']);
     if (isset($category_rewrite[1]) && !empty($category_rewrite[1])) {
         $id_category = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
                 SELECT `id_category`
                 FROM `' . _DB_PREFIX_ . 'category_lang`
                 WHERE `link_rewrite` = \'' . $category_rewrite[1] . '\'');
         if ($id_category > 0) {
             $category = new Category($id_category);
             if (is_object($category) && isset($category->id, $this->context->language->id)) {
                 $url = _PS_BASE_URL_ . __PS_BASE_URI__ . $category_rewrite[1] . '/';
                 $redirect_type = Configuration::get('PS_CANONICAL_REDIRECT') == 2 ? '301' : '302';
                 header('HTTP/1.0 ' . $redirect_type . ' Moved');
                 header('Cache-Control: no-cache');
                 Tools::redirectLink($url);
             }
         }
     }
     header('HTTP/1.1 404 Not Found');
     header('Status: 404 Not Found');
     if (preg_match('/\\.(gif|jpe?g|png|ico)$/i', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
         $this->context->cookie->disallowWriting();
         if (!isset($_SERVER['REDIRECT_URL'])) {
             $_SERVER['REDIRECT_URL'] = '';
             if (preg_match('@^' . __PS_BASE_URI__ . '([0-9]+)\\-([_a-zA-Z0-9-]+)(/[_a-zA-Z0-9-]+)?\\.jpg$@', $_SERVER['REQUEST_URI'], $matches)) {
                 $_SERVER['REDIRECT_URL'] = __PS_BASE_URI__ . 'p/' . Image::getImgFolderStatic($matches[0]) . '/' . $matches[0] . '-' . $matches[1] . '.jpg';
             }
         }
         if (preg_match('#/p[0-9/]*/([0-9]+)\\-([_a-zA-Z]*)\\.(png|jpe?g|gif)$#', $_SERVER['REDIRECT_URL'], $matches)) {
             // Backward compatibility since we suffixed the template image with _default
             if (Tools::strtolower(substr($matches[2], -8)) != '_default') {
                 header('Location: ' . $this->context->link->getImageLink('', $matches[1], $matches[2]), true, 302);
                 exit;
             } else {
                 $image_type = ImageType::getByNameNType($matches[2], 'products');
                 if ($image_type && count($image_type)) {
                     $root = _PS_PROD_IMG_DIR_;
                     $folder = Image::getImgFolderStatic($matches[1]);
                     $file = $matches[1];
                     $ext = '.' . $matches[3];
                     if (file_exists($root . $folder . $file . $ext)) {
                         if (ImageManager::resize($root . $folder . $file . $ext, $root . $folder . $file . '-' . $matches[2] . $ext, (int) $image_type['width'], (int) $image_type['height'])) {
                             header('HTTP/1.1 200 Found');
                             header('Status: 200 Found');
                             header('Content-Type: image/jpg');
                             readfile($root . $folder . $file . '-' . $matches[2] . $ext);
                             exit;
                         }
                     }
                 }
             }
         } elseif (preg_match('#/c/([0-9]+)\\-([_a-zA-Z]*)\\.(png|jpe?g|gif)$#', $_SERVER['REDIRECT_URL'], $matches)) {
             $image_type = ImageType::getByNameNType($matches[2], 'categories');
             if ($image_type && count($image_type)) {
                 $root = _PS_CAT_IMG_DIR_;
                 $file = $matches[1];
                 $ext = '.' . $matches[3];
                 if (file_exists($root . $file . $ext)) {
                     if (ImageManager::resize($root . $file . $ext, $root . $file . '-' . $matches[2] . $ext, (int) $image_type['width'], (int) $image_type['height'])) {
                         header('HTTP/1.1 200 Found');
                         header('Status: 200 Found');
                         header('Content-Type: image/jpg');
                         readfile($root . $file . '-' . $matches[2] . $ext);
                         exit;
                     }
                 }
             }
         }
         header('Content-Type: image/gif');
         readfile(_PS_IMG_DIR_ . '404.gif');
         exit;
     } elseif (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('.js', 'css'))) {
         $this->context->cookie->disallowWriting();
         exit;
     }
     parent::initContent();
     $this->setTemplate(_PS_THEME_DIR_ . '404.tpl');
 }
Example #12
0
 public function getImageLink($name, $ids, $type = NULL)
 {
     global $protocol_content;
     // legacy mode or default image
     if (Configuration::get('PS_LEGACY_IMAGES') && file_exists(_PS_PROD_IMG_DIR_ . $ids . ($type ? '-' . $type : '') . '.jpg') || strpos($ids, 'default') !== false) {
         $uri_path = _THEME_PROD_DIR_ . $ids . ($type ? '-' . $type : '') . '.jpg';
     } 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];
         $uri_path = _THEME_PROD_DIR_ . Image::getImgFolderStatic($id_image) . $id_image . ($type ? '-' . $type : '') . '.jpg';
     }
     return $protocol_content . Tools::getMediaServer($uri_path) . $uri_path;
 }
Example #13
0
         if (!$productHasImage) {
             $db->insert('image', array('id_image' => $imageId, 'id_product' => $id));
         }
         $imgFile = IMAGE_IMPORT_FOLDER . $filepath;
         $fileExists = file_exists($imgFile);
         if (!$fileExists && !$productHasImage) {
             logResponse('Image not found ' . $imgFile);
         } else {
             $image = new Image();
             $image->id_product = (int) $id;
             $image->cover = (int) $cover;
             $image->id = $imageId;
             $image->id_image = $imageId;
             $image->save();
             $db->update('image_lang', array('legend' => addslashes($imageDesc)), "id_image = '" . $db->escape($image->id_image) . "'");
             $imgFolder = Image::getImgFolderStatic($imageId);
             if ($fileExists && !is_dir(_PS_IMG_DIR_ . 'p' . DIRECTORY_SEPARATOR . $imgFolder)) {
                 $new_path = $image->getPathForCreation();
                 if (file_exists($imgFile)) {
                     $imagesTypes = ImageType::getImagesTypes('products');
                     foreach ($imagesTypes as $imageType) {
                         if (!ImageManager::resize($imgFile, $new_path . '-' . stripslashes($imageType['name']) . '.' . $image->image_format, $imageType['width'], $imageType['height'], $image->image_format)) {
                             logResponse('An error occurred while copying image:' . ' ' . stripslashes($imageType['name']));
                         }
                     }
                 }
             }
         }
     }
 }
 logResponse("Product {$id} saved");