protected function _regenerateNewImagesOfOffers($dir, $type)
 {
     $dir = '/home/towers/sites/aphrodinet/img/offers/';
     if (!is_dir($dir)) {
         return false;
     }
     $generate_hight_dpi_images = (bool) Configuration::get('PS_HIGHT_DPI');
     include_once __DIR__ . '/../../../modules/aphrodinet/classes/AphOfferImage.php';
     error_log(var_export(AphOfferImage::getAllImages(), true));
     foreach (AphOfferImage::getAllImages() as $image) {
         $imageObj = new AphOfferImage($image['id_image']);
         $existing_img = $dir . $imageObj->getExistingImgPath() . '.jpg';
         if (file_exists($existing_img) && filesize($existing_img)) {
             foreach ($type as $imageType) {
                 unlink($dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg');
                 //if (!file_exists($dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg')) {
                 if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) {
                     $this->errors[] = sprintf(Tools::displayError('Original image is corrupt (%s) for product ID %2$d or bad permission on folder'), $existing_img, (int) $imageObj->id_product);
                 }
                 if ($generate_hight_dpi_images) {
                     if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) {
                         $this->errors[] = sprintf(Tools::displayError('Original image is corrupt (%s) for product ID %2$d or bad permission on folder'), $existing_img, (int) $imageObj->id_product);
                     }
                 }
                 //}
             }
         } else {
             $this->errors[] = sprintf(Tools::displayError('Original image is missing or empty (%1$s) for product ID %2$d'), $existing_img, (int) $imageObj->id_product);
         }
         if (time() - $this->start_time > $this->max_execution_time - 4) {
             // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
             return 'timeout';
         }
     }
     return (bool) count($this->errors);
 }
Example #2
0
 public function initContent()
 {
     parent::initContent();
     $shop = NULL;
     $alias_offer = (int) Tools::getValue('aof');
     if (!empty($alias_offer)) {
         $_o = AphOffer::getByAlias($alias_offer, Context::getContext()->language->id);
         $id_offer = $_o['id_offer'];
     } else {
         $id_offer = (int) Tools::getValue('ido');
     }
     $offer = new AphOffer($id_offer, Context::getContext()->language->id);
     $offer->new_price = $offer->price_wt < 0 ? $offer->reduction_type == 'percentage' ? '-' . intval($offer->reduction * 100) . '%' : '-' . Tools::displayPrice($offer['reduction'], (int) Context::getContext()->currency->id) : Tools::displayPrice($offer->price_wt, (int) Context::getContext()->currency->id) . ' ';
     $cover = NULL;
     $images = AphOfferImage::getImages(Context::getContext()->language->id, $id_offer);
     foreach ($images as &$image) {
         if (!empty($image['cover'])) {
             $cover = $image;
         }
     }
     if (empty($cover) && !empty($images)) {
         $cover = $images[0];
     }
     $this->context->smarty->tpl_vars['meta_title']->value = $offer->name;
     $this->context->smarty->tpl_vars['meta_description']->value = $offer->meta_description;
     $shops = AphOffer::getShopsLight(Context::getContext()->language->id, $offer->id);
     foreach ($shops as &$shop) {
         $shop['link'] = Context::getContext()->link->getModuleLink('blockshops', 'shop', array('ash' => $shop['uri'], 'ids' => $shop['id_shop']));
     }
     /*$products = AphOffer::getProductsLight(Context::getContext()->language->id, $offer->id);
     		foreach ($products as &$product) {
     			$product['link'] = Context::getContext()->link->getProductLink((int)$product['id_product'], $product['link_rewrite']);
     		}*/
     $products_by_category = array();
     $ps = AphOffer::getProductsLight(Context::getContext()->language->id, $offer->id);
     foreach ($ps as &$p) {
         $product = new Product($p['id_product'], false, Context::getContext()->language->id);
         $category = new Category($product->id_category_default, Context::getContext()->language->id);
         if (empty($products_by_category[$category->id])) {
             $products_by_category[$category->id] = array('id_category' => $category->id, 'name' => $category->name, 'class' => Tools::link_rewrite($category->name), 'products' => array());
         }
         $products_by_category[$category->id]['products'][$product->id] = array('id_product' => $product->id, 'name' => $product->name, 'link' => Context::getContext()->link->getProductLink((int) $product->id, $product->link_rewrite, $category->id, $product->ean13));
     }
     $this->context->smarty->assign(array('offer' => $offer, 'cover' => $cover, 'images' => $images, 'shops' => $shops, 'products_by_category' => $products_by_category));
     $this->setTemplate('offer.tpl');
 }
Example #3
0
 /**
  * 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 = AphOfferImage::getImgFolderStatic($this->id);
     }
     return $this->folder;
 }
    /**
     * @param Offer $obj
     * @throws Exception
     * @throws SmartyException
     */
    public function initFormImages($obj)
    {
        $data = $this->createTemplate($this->tpl_form);
        if ((bool) $obj->id) {
            // if ($this->offer_exists_in_shop) {
            $data->assign('offer', $this->loadObject());
            $count_images = Db::getInstance()->getValue('
					SELECT COUNT(id_offer)
					FROM ' . _DB_PREFIX_ . 'offer_image
					WHERE id_offer = ' . (int) $obj->id);
            $images = AphOfferImage::getImages($this->context->language->id, $obj->id);
            foreach ($images as $k => $image) {
                $images[$k] = new AphOfferImage($image['id_image']);
            }
            if ($this->context->shop->getContext() == Shop::CONTEXT_SHOP) {
                $current_shop_id = (int) $this->context->shop->id;
            } else {
                $current_shop_id = 0;
            }
            $language = Language::getLanguage(Configuration::get('PS_LANG_DEFAULT'));
            $image_uploader = new HelperImageUploader('file');
            $image_uploader->setTemplateDirectory($this->tpl_dir . 'helpers/uploader/')->setMultiple(!(Tools::getUserBrowser() == 'Apple Safari' && Tools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl(Context::getContext()->link->getAdminLink('AdminAphOffers') . '&ajax=1&id_offer=' . (int) $obj->id . '&action=addOfferImage')->setTemplate('ajax.tpl');
            $data->assign(array('countImages' => $count_images, 'id_offer' => (int) Tools::getValue('id_offer'), 'images' => $images, 'iso_lang' => $language['iso_code'], 'token' => $this->token, 'table' => $this->table, 'max_image_size' => $this->max_image_size / 1024 / 1024, 'currency' => $this->context->currency, 'current_shop_id' => $current_shop_id, 'languages' => $this->_languages, 'default_language' => (int) Configuration::get('PS_LANG_DEFAULT'), 'image_uploader' => $image_uploader->render()));
            $type = ImageType::getByNameNType('%', 'products', 'height');
            if (isset($type['name'])) {
                $data->assign('imageType', $type['name']);
            } else {
                $data->assign('imageType', ImageType::getFormatedName('small'));
            }
            // } else {
            //     $this->displayWarning($this->l('You must save the offer in this shop before adding images.'));
            // }
        } else {
            $this->displayWarning($this->l('You must save this offer before adding images.'));
        }
        $this->tpl_form_vars['custom_form'] = $data->fetch();
    }