displayContent(); class Catalog { private $_xml; private $_debug; public $id_lang; public $currentTime; public $versions; const FIELD_EXTRA = 2; public function __construct() { $this->_xml =""; $this->versions = array( 'es' => 3, 'fr' => 2 ); } public function setContent($version = 'fr') { // Flush to load the good sales CacheRedis::getInstance()->clear('sale*'); $test_for_tomorrow = (int)Tools::getValue('tomorrow',0); $sales_today = array(); $sales_last_day = array(); $sale_current = array(); $id_lang = (int) $this->versions[$version]; if($test_for_tomorrow) { $sales_today = Sale::getSales(TRUE, NULL, NULL, 'tomorrow', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $version); $sales_last_day = Sale::getSales(TRUE, NULL, NULL, 'ended_tomorrow', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $version); $sale_current = self::getSales(TRUE, NULL, NULL, 'forward_tomorrow', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $version); } else { $sales_today = Sale::getSales(TRUE, NULL, NULL, 'today', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $version); $sales_last_day = Sale::getSales(TRUE, NULL, NULL, 'last', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $version); $sale_current = self::getSales(TRUE, NULL, NULL, 'forward', FALSE, Configuration::get('PRIVATESALES_SHOW_PUBLIC'), '`position` DESC', NULL, NULL, $version); } foreach ($sales_today as &$sale) { $sql = ' SELECT `value` FROM `'._DB_PREFIX_.'privatesale_extrafield_sale` WHERE `id_field` = '.(int) self::FIELD_EXTRA .' AND `id_lang` = '.(int) $id_lang.' AND id_sale = '.(int) $sale->id ; if ($value = Db::getInstance()->getValue($sql)) { $sale->reduction = $value; } else { $sale->reduction = 'Non défini'; } $desc = new html2text($sale->description[(int) $id_lang]); $sale->description[(int) $id_lang] = $desc->get_text(); } foreach ($sales_last_day as &$sale) { $sql = ' SELECT `value` FROM `'._DB_PREFIX_.'privatesale_extrafield_sale` WHERE `id_field` = '.(int) self::FIELD_EXTRA .' AND `id_lang` ='.(int) $id_lang.' AND `id_sale` ='.(int) $sale->id ; if ($value = Db::getInstance()->getValue($sql)) { $sale->reduction = $value; } else { $sale->reduction = 'Non défini'; } $desc = new html2text($sale->description[(int) $id_lang]); $sale->description[(int) $id_lang] = $desc->get_text(); } foreach ($sale_current as &$sale) { $sql = ' SELECT `value` FROM `'._DB_PREFIX_.'privatesale_extrafield_sale` WHERE `id_field` = '.(int) self::FIELD_EXTRA .' AND `id_lang` = '.(int) $id_lang.' AND `id_sale` = ' . (int) $sale->id ; if ($value = Db::getInstance()->getValue($sql)) { $sale->reduction = $value; } else { $sale->reduction = 'Non défini'; } $desc = new html2text($sale->description[(int) $id_lang]); $sale->description[(int) $id_lang] = $desc->get_text(); } $this->setXml($sales_today, $sales_last_day, $sale_current, false, $version, $test_for_tomorrow); } public function displayContent() { foreach ($this->versions as $version => $id_lang) { $this->setContent($version); } echo 'Fichier généré'; } public function setXml($sales_today, $sales_last_day, $sale_current, $rss=false, $version, $tomorrow=false) { $id_lang = (int) $this->versions[$version]; $this->_xml = ''; $this->_xml .= ''; if ($version == 'es') { $flux = fopen("flux_".$version.".xml", "w"); // Catalog $this->_xml .= ''; //Shop details $this->_xml .= 'Bebeboutik.es'; $this->_xml .= ''; $this->_xml .= 'Bebeboutik.es'; $this->_xml .= 'http://www.bebeboutik.es/img/logo_3.png'; $title_sunday = Configuration::get('TITLE_NEWS_DIMANCHE_ES'); $link_sale = 'https://www.bebeboutik.es'; $all_sales = 'Todas las ventas'; } else { $flux = fopen("flux.xml", "w"); // Catalog $this->_xml .= ''; //Shop details $this->_xml .= 'Bebeboutik.com'; $this->_xml .= 'https://www.bebeboutik.com'; $this->_xml .= 'Bebeboutik.com'; $this->_xml .= 'http://www.bebeboutik.com/img/logo.png'; $title_sunday = Configuration::get('TITLE_NEWS_DIMANCHE'); $link_sale = 'https://www.bebeboutik.com'; $all_sales = 'Toutes les ventes'; } $sql_title = ' SELECT `title`, `preheader` FROM `ps_privatesale_newsletter` WHERE `date_pub` = '.($tomorrow?'CURDATE() + INTERVAL 1 day':'CURDATE()').' AND `version` = "'.$version.'"' ; $info_newsletter = Db::getInstance()->getRow($sql_title); if (empty($info_newsletter)) { $info_newsletter['title'] = Configuration::get('PRIVATESALES_TITLE_NEWSLETTER'); $info_newsletter['preheader'] = ''; } $this->_xml.=''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml.=''; foreach ($sales_today as $item) { $link = new Link(); $category = new Category($item->id_category); $sale_link = $link->getCategoryLink($category->id, $category->link_rewrite[(int) $id_lang]); if ($version == 'es') { $sale_link = str_replace('bebeboutik.com', 'bebeboutik.es', $sale_link); } $sale_link = str_replace('http://','https://', $sale_link); $sql = ' SELECT `value` FROM `'._DB_PREFIX_.'privatesale_extrafield_sale` WHERE `id_field` = 1 AND `id_lang` = '.(int) $id_lang.' AND `id_sale` = '.(int) $item->id ; if ($value = Db::getInstance()->getValue($sql)) { $item->small_title = $value; } else { $item->small_title = 'Non défini'; } $this->_xml.=''; $this->_xml .= '<![CDATA['.$item->title[(int) $id_lang].']]>|<![CDATA['.$item->reduction.']]>'; $this->_xml .= 'small_title.']]>'; //$this->_xml .= ''; //$this->_xml .= 'name[(int) $id_lang].']]>'; $this->_xml .= ''; $this->_xml .= ''.$sale_link.''; $this->_xml .= 'reduction.']]>'; $this->_xml .= ''; $this->_xml .= '<![CDATA['.$item->title[(int) $id_lang].']]> <![CDATA['.$item->reduction.']]>'; $this->_xml .= 'http://static.bebeboutik.com/modules/privatesales/img/'.$item->id.'/liston_'.(int) $id_lang.'.jpg'; $this->_xml .= ''; $this->_xml.=''; } if (count($sales_today)%2 == 1){ $this->_xml.=''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''.$link_sale.''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= 'Bebeboutik.com'; $this->_xml .= 'http://www.bebeboutik.com/img/newsletter_'.(int) $id_lang.'.png'; $this->_xml .= ''; $this->_xml.=''; } foreach ($sales_last_day as $item) { $link = new Link(); $category = new Category($item->id_category); $sale_link = $link->getCategoryLink($category->id, $category->link_rewrite[(int) $id_lang]); if ($version == 'es') { $sale_link = str_replace('bebeboutik.com', 'bebeboutik.es', $sale_link); } $sale_link = str_replace('http://','https://', $sale_link); $sql = ' SELECT `value` FROM `'._DB_PREFIX_.'privatesale_extrafield_sale` WHERE `id_field` = 1 AND `id_lang` = '.(int) $id_lang.' AND `id_sale` = '.(int) $item->id ; if ($value = Db::getInstance()->getValue($sql)) { $item->small_title = $value; } else { $item->small_title = 'Non défini'; } $this->_xml.=''; $this->_xml .= '<![CDATA['.$item->title[(int) $id_lang].']]>|<![CDATA['.$item->reduction.']]>'; $this->_xml .= 'small_title.']]>'; //$this->_xml .= ''; //$this->_xml .= 'name[(int) $id_lang].']]>'; $this->_xml .= ''; $this->_xml .= ''.$sale_link.''; $this->_xml .= 'reduction.']]>'; $this->_xml .= ''; $this->_xml .= '<![CDATA['.$item->title[(int) $id_lang].']]> <![CDATA['.$item->reduction.']]>'; $this->_xml .= 'http://static.bebeboutik.com/modules/privatesales/img/'.$item->id.'/liston_'.(int) $id_lang.'.jpg'; $this->_xml .= ''; $this->_xml.=''; } if (count($sales_last_day)%2 == 1){ $this->_xml.=''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''.$link_sale.''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= 'Bebeboutik.com'; $this->_xml .= 'http://www.bebeboutik.com/img/newsletter_'.(int) $id_lang.'.png'; $this->_xml .= ''; $this->_xml.=''; } foreach ($sale_current as $item) { $link = new Link(); $category = new Category($item->id_category); $sale_link = $link->getCategoryLink($category->id, $category->link_rewrite[(int) $id_lang]); if ($version == 'es') { $sale_link = str_replace('bebeboutik.com', 'bebeboutik.es', $sale_link); } $sale_link = str_replace('http://','https://', $sale_link); $sql = ' SELECT `value` FROM `'._DB_PREFIX_.'privatesale_extrafield_sale` WHERE `id_field` = 1 AND `id_lang` = '.(int) $id_lang.' AND `id_sale` = '. (int)$item->id ; if ($value = Db::getInstance()->getValue($sql)) { $item->small_title = $value; } else { $item->small_title = 'Non défini'; } $this->_xml.=''; $this->_xml .= '<![CDATA['.$item->title[(int) $id_lang].']]>|<![CDATA['.$item->reduction.']]>'; $this->_xml .= 'small_title.']]>'; //$this->_xml .= ''; //$this->_xml .= 'name[(int) $id_lang].']]>'; $this->_xml .= ''; $this->_xml .= ''.$sale_link.''; $this->_xml .= 'reduction.']]>'; $this->_xml .= ''; $this->_xml .= '<![CDATA['.$item->title[(int) $id_lang].']]> <![CDATA['.$item->reduction.']]>'; $this->_xml .= 'http://static.bebeboutik.com/modules/privatesales/img/'.$item->id.'/liston_'.(int) $id_lang.'.jpg'; $this->_xml .= ''; $this->_xml.=''; } if (count($sale_current)%2 == 1){ $this->_xml.=''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''.$link_sale.''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= 'Bebeboutik.com'; $this->_xml .= 'http://www.bebeboutik.com/img/newsletter_'.(int) $id_lang.'.png'; $this->_xml .= ''; $this->_xml.=''; } foreach ($sales_last_day as $item) { $link = new Link(); $category = new Category($item->id_category); $sale_link = $link->getCategoryLink($category->id, $category->link_rewrite[(int) $id_lang]); if ($version == 'es') { $sale_link = str_replace('bebeboutik.com', 'bebeboutik.es', $sale_link); } $sale_link = str_replace('http://','https://', $sale_link); $sql = ' SELECT `value` FROM `'._DB_PREFIX_.'privatesale_extrafield_sale` WHERE `id_field` = 1 AND `id_lang` = '.(int) $id_lang.' AND `id_sale` = '. (int)$item->id ; if ($value = Db::getInstance()->getValue($sql)) { $item->small_title = $value; } else { $item->small_title = 'Non défini'; } $this->_xml.=''; // $this->_xml .= ''.$item->id.''; $this->_xml .= '<![CDATA['.$item->title[(int) $id_lang].']]>|<![CDATA['.$item->reduction.']]>'; $this->_xml .= 'small_title.']]>'; //$this->_xml .= ''; //$this->_xml .= 'name[(int) $id_lang].']]>'; $this->_xml .= ''; $this->_xml .= ''.$sale_link.''; $this->_xml .= 'reduction.']]>'; $this->_xml .= ''; $this->_xml .= '<![CDATA['.$item->title[(int) $id_lang].']]> <![CDATA['.$item->reduction.']]>'; $this->_xml .= 'http://static.bebeboutik.com/modules/privatesales/img/'.$item->id.'/liston_'.(int) $id_lang.'.jpg'; $this->_xml .= ''; $this->_xml.=''; } if (count($sales_last_day)%2 == 1){ $this->_xml.=''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= ''.$link_sale.''; $this->_xml .= ''; $this->_xml .= ''; $this->_xml .= 'Bebeboutik.com'; $this->_xml .= 'http://www.bebeboutik.com/img/newsletter_'.(int) $id_lang.'.png'; $this->_xml .= ''; $this->_xml.=''; } $this->_xml .= ''; $this->_xml .= ''; fwrite($flux, $this->_xml); fclose($flux); } public static function getSales($enabled=NULL, $logout=NULL, $featured=NULL, $future=NULL, $lite=FALSE, $pub=FALSE, $order_by='`date_end` ASC', $limit=NULL, $sale_type=NULL, $site_version=FALSE) { $result = array(); $where = array(); $query = ' SELECT p.`id_sale` FROM `'._DB_PREFIX_.'privatesale` p '; if($sale_type !== NULL){ $query.= ' LEFT JOIN `'._DB_PREFIX_.'privatesale_type` pt ON(pt.id_sale = p.id_sale AND pt.id_sale_type = '. $sale_type.')'; } if($site_version !== FALSE) { $query .= ' LEFT JOIN `'._DB_PREFIX_.'privatesale_site_version` sv ON p.`id_sale` = sv.`id_sale` '; $where[] = 'sv.`version` = "'.pSQL($site_version).'"'; } if($enabled !== NULL OR $logout !== NULL OR $featured !== NULL OR $future !== NULL) { $enabled !== null? $where[] = '`enabled` = '.(int) $enabled: TRUE; $logout !== null? $where[] = '`logout` = '.(int) $logout: TRUE; $pub != FALSE? '': $where[] = '`public` = 0'; $featured !== null? $where[] = '`featured` = '.(int) $featured: TRUE; // $sale_type !== NULL? $where[] = '`sale_type` = '.(int) $sale_type: TRUE; if($future === 'current') { $where[] = '`date_start` < NOW() AND `date_end` > NOW()'; } elseif($future === 'not_ended') { $where[] = '`date_end` > NOW()'; } elseif($future === 'forward') { $where[] = '`date_start` < NOW() AND `date_end` > NOW() AND forward_news = 1'; } elseif($future === 'forward_tomorrow') { $where[] = '`date_start` < NOW() AND `date_end` > DATE_ADD(NOW(), INTERVAL 1 DAY) AND forward_news = 1'; } elseif($future === 'all') { $where[] = ' 1 = 1'; } elseif ($future === 'today') { $where[] = 'CAST(`date_start` AS DATE) = CAST(NOW() AS DATE)'; } elseif ($future === 'last') { $where[] = 'CAST(`date_end` AS DATE) = CAST(NOW() AS DATE)'; } elseif(is_int($future)) { $where[] = '(`date_start` > NOW() AND `date_start` < DATE_ADD(NOW(), INTERVAL '.$future.' DAY))'; } elseif($future === TRUE) { $where[] = '`date_start` > NOW()'; } elseif($future === FALSE) { $where[] = '`date_start` < NOW() AND `date_end` < NOW()'; } $query.= 'WHERE '.implode(' AND ', $where); } if($sale_type !== NULL){ $query.= ' AND pt.id_sale_type = '. $sale_type; } $query .= ' ORDER BY '.$order_by; if($limit !== NULL) { $query .= ' LIMIT '.$limit; } if($sales = Db::getInstance()->ExecuteS($query)) { if($lite) { foreach($sales AS $sale) { $result[] = $sale['id_sale']; } } else { foreach($sales AS $sale) { $result[] = new Sale($sale['id_sale']); } } } return $result; } }