PEEL Shopping
Open source ecommerce : PEEL Shopping
fonctions.php
Go to the documentation of this file.
1 <?php
2 // This file should be in UTF8 without BOM - Accents examples: éèê
3 // +----------------------------------------------------------------------+
4 // | Copyright (c) 2004-2015 Advisto SAS, service PEEL - contact@peel.fr |
5 // +----------------------------------------------------------------------+
6 // | This file is part of PEEL Shopping 8.0.0, which is subject to an |
7 // | opensource GPL license: you are allowed to customize the code |
8 // | for your own needs, but must keep your changes under GPL |
9 // | More information: https://www.peel.fr/lire/licence-gpl-70.html |
10 // +----------------------------------------------------------------------+
11 // | Author: Advisto SAS, RCS 479 205 452, France, https://www.peel.fr/ |
12 // +----------------------------------------------------------------------+
13 // $Id: fonctions.php 46935 2015-09-18 08:49:48Z gboussin $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 
25 function echo_rss_and_die($category_id = null, $seller_id = null) {
26  if (!empty($_GET['encoding'])) {
27  $page_encoding = $_GET['encoding'];
28  } else {
29  $page_encoding = 'utf-8';
30  }
31 
32  if (empty($_GET['limit'])) {
33  $limit = 10;
34  } else {
35  $limit = min(intval($_GET['limit']), 500);
36  }
37  if(empty($GLOBALS['meta_title'])){
38  if (!check_if_module_active('annonces')) {
39  $GLOBALS['meta_title'] = $GLOBALS['STR_RSS_TITLE'];
40  } else {
41  // Si le module annonce existe alors, on n'affiche ces dernières annonces
42  $ad_categories = get_ad_categories();
43  if (!empty($category_id)) {
44  $Cat4XML = vb($ad_categories[$category_id]);
45  } else {
46  $Cat4XML = "" ;
47  }
48  $GLOBALS['meta_title'] = $GLOBALS['STR_MODULE_RSS_META_RSS'] . ' ' . $Cat4XML;
49  }
50  }
51  if(empty($GLOBALS['meta_description'])){
52  if (check_if_module_active('annonces')) {
53  $GLOBALS['meta_description'] = $GLOBALS['STR_MODULE_ANNONCES_LAST_ADS_PUBLISHED'];
54  } else {
55  $GLOBALS['meta_description'] = $GLOBALS['STR_MODULE_RSS_DESCRIPTION'];
56  }
57  }
58  header('Content-type: application/rss+xml; charset=' . $page_encoding);
59  // En-tête
60  $output = '';
61  $image_xml = '';
62  // Recherche du logo du site
63  if (!empty($GLOBALS['site_parameters']['logo_' . $_SESSION['session_langue']]) && $GLOBALS['site_parameters']['on_logo'] == 1) {
64  $image_thumb = thumbs($GLOBALS['site_parameters']['logo_' . $_SESSION['session_langue']], 144, 144, 'fit');
65  $size_array = @getimagesize($GLOBALS['uploaddir'] . '/thumbs/' . String::rawurldecode($image_thumb));
66  $image_xml .= '
67  <image>
68  <url>' . String::htmlentities($GLOBALS['repertoire_upload'] . '/thumbs/' . $image_thumb, ENT_COMPAT, GENERAL_ENCODING, false, true, true) . '</url>
69  <title>' . String::htmlentities($GLOBALS['meta_title'], ENT_COMPAT, GENERAL_ENCODING, false, true, true) . '</title>
70  <link>' . String::htmlentities($GLOBALS['wwwroot'], ENT_COMPAT, GENERAL_ENCODING, false, true, true) . '</link>
71  <width>' . vn($size_array[0]) . '</width>
72  <height>' . vn($size_array[1]) . '</height>
73  <description>' . $GLOBALS['meta_description'] .'</description>
74  </image>';
75  }
76  $tpl = $GLOBALS['tplEngine']->createTemplate('modules/rss.tpl');
77  $tpl->assign('page_encoding', $page_encoding);
78  $tpl->assign('wwwroot', String::htmlentities($GLOBALS['wwwroot'], ENT_COMPAT, GENERAL_ENCODING, false, true, true));
79  $tpl->assign('link', String::htmlentities(get_current_url(true), ENT_COMPAT, GENERAL_ENCODING, false, true, true));
80  $tpl->assign('image_xml', String::htmlentities($image_xml, ENT_COMPAT, GENERAL_ENCODING, false, true, true));
81  $tpl->assign('STR_RSS_TITLE', String::htmlentities($GLOBALS['meta_title'], ENT_COMPAT, GENERAL_ENCODING, false, true, true));
82  $tpl->assign('STR_MODULE_RSS_DESCRIPTION', String::htmlentities($GLOBALS['meta_description'], ENT_COMPAT, GENERAL_ENCODING, false, true, true));
83  $tpl->assign('language', String::htmlentities($_SESSION['session_langue'], ENT_COMPAT, GENERAL_ENCODING, false, true, true));
84  $tpl->assign('pubDate', String::htmlentities(gmdate("r"), ENT_COMPAT, GENERAL_ENCODING, false, true, true));
85  $tpl->assign('generator', String::htmlentities('Advisto RSS Generator 2.1', ENT_COMPAT, GENERAL_ENCODING, false, true, true));
86  $tpl_items = array();
87  if (!check_if_module_active('annonces')) {
88  // Récupération et affichage des données
89  $sql = "SELECT p.id, p.prix, p.tva, p.nom_".(!empty($GLOBALS['site_parameters']['product_name_forced_lang'])?$GLOBALS['site_parameters']['product_name_forced_lang']:$_SESSION['session_langue'])." AS nom, p.date_maj, p.description_" . (!empty($GLOBALS['site_parameters']['product_description_forced_lang'])?$GLOBALS['site_parameters']['product_description_forced_lang']:$_SESSION['session_langue']) . " AS description, p.promotion, c.id AS categorie_id, c.nom_" . $_SESSION['session_langue'] . " AS categorie
90  FROM peel_produits p
91  INNER JOIN peel_produits_categories pc ON p.id = pc.produit_id
92  INNER JOIN peel_categories c ON c.id = pc.categorie_id AND " . get_filter_site_cond('categories', 'c') . "
93  WHERE p.etat='1' AND " . get_filter_site_cond('produits', 'p') . " " . (!empty($category_id)?" AND pc.categorie_id='" . intval($category_id) . "'":"") . "
94  GROUP BY p.id
95  ORDER BY p.date_maj DESC, p.id DESC
96  LIMIT " . intval($limit);
97  $result = query($sql);
98  while ($prod = fetch_assoc($result)) {
99  $product_object = new Product($prod['id'], $prod, false, null, true, !check_if_module_active('micro_entreprise'));
100  $desc_rss = trim(str_replace(array(" ", " ", " ", " \r", " \n", "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "\r\n\r\n\r\n", "\r\n\r\n", "\n\n\n\n\n\n", "\n\n\n", "\n\n"), array(" ", " ", " ", "\r", "\n", "\r\n", "\r\n", "\r\n", "\n", "\n", "\n"), strip_tags(String::html_entity_decode_if_needed(String::htmlspecialchars_decode($product_object->description, ENT_QUOTES)))));
101  $promotion_rss = $product_object->get_all_promotions_percentage(false, 0, true);
102  $dateRFC = gmdate("r", strtotime($product_object->date_maj));
103  if ($product_object->on_estimate) {
104  $product_affiche_prix = display_on_estimate_information(true);
105  } elseif ($product_object->on_gift) {
106  $product_affiche_prix = $product_object->on_gift_points . ' ' . $GLOBALS['STR_GIFT_POINTS'];
107  } else {
108  $product_affiche_prix = $product_object->get_final_price(0, display_prices_with_taxes_active(), check_if_module_active('reseller') && is_reseller(), true);
109  }
110  $this_item = array('title' => String::htmlentities($product_object->name . $GLOBALS['STR_BEFORE_TWO_POINTS'] . ': ' . $product_affiche_prix, ENT_COMPAT, GENERAL_ENCODING, false, true, true), 'promotion_rss' => String::htmlentities($promotion_rss, ENT_COMPAT, GENERAL_ENCODING, false, true, true),
111  'guid' => String::htmlentities($product_object->get_product_url(), ENT_COMPAT, GENERAL_ENCODING, false, true, true),
112  'pubDate' => String::htmlentities($dateRFC, ENT_COMPAT, GENERAL_ENCODING, false, true, true),
113  'description' => String::htmlentities($desc_rss, ENT_COMPAT, GENERAL_ENCODING, false, true, true));
114  $imagename = $product_object->get_product_main_picture();
115  if(!empty($imagename)) {
116  $this_thumb = thumbs($imagename, $GLOBALS['site_parameters']['small_width'], $GLOBALS['site_parameters']['small_height'], 'fit');
117  if (!empty($this_thumb)) {
118  $image_infos = getimagesize($GLOBALS['uploaddir'] . '/thumbs/' . String::rawurldecode($this_thumb));
119  $this_item['image']['length'] = filesize($GLOBALS['uploaddir'] . '/thumbs/' . String::rawurldecode($this_thumb));
120  $this_item['image']['url'] = $GLOBALS['repertoire_upload'] . '/thumbs/' . $this_thumb;
121  $this_item['image']['mime'] = $image_infos['mime'];
122  }
123  }
124  $tpl_items[] = $this_item;
125  unset($product_object);
126  }
127  } else {
128  // Définit les limites des annonces à afficher
129  // date_insertion NOT LIKE '0000%' : la date d'insertion est vide si l'affichage de l'annonce a été désactivé par le propriétaire de l'annonce
130  $sql_cond = "enligne='OK' " . (!empty($GLOBALS['site_parameters']['extra_ad_database_fields_array']) && in_array('date_end', $GLOBALS['site_parameters']['extra_ad_database_fields_array']) ?" AND (date_end LIKE '0000%' OR date_end>'" . date('Y-m-d H:i:00', time()) . "')":'') . " AND (date_insertion NOT LIKE '0000%' AND date_insertion<'" . date('Y-m-d H:i:00', time() + 60) . "')";
131  if (!empty($category_id)) {
132  $sql_cond .= " AND id_categorie=" . intval($category_id);
133  }
134  if (!empty($seller_id)) {
135  $sql_cond .= " AND id_personne=" . intval($seller_id);
136  }
137  $sql = "SELECT *
138  FROM peel_lot_vente
139  WHERE " . $sql_cond . " AND " . get_filter_site_cond('lot_vente') . "
140  ORDER BY date_insertion DESC
141  LIMIT 10";
142  $rs = query($sql);
143  // Génération des derniéres annonces
144  while ($row_rs = fetch_assoc($rs)) {
145  $IDP = $row_rs['id_personne'];
146  if (empty($category_id) && !empty($row_rs['categorie_id'])) {
147  // On n'affiche la catégorie dans le titre que si on n'a pas demandé cette catégorie explicitement
148  $category_text = ucfirst($ad_categories[$row_rs['categorie_id']]) . ' - ';
149  }
150  $dateRFC = gmdate("r", strtotime($row_rs['date_insertion']));
151  $annonce_object = new Annonce($row_rs['ref'], null, false, true);
152  $desc_rss = trim(str_replace(array(" ", " ", " ", " \r", " \n", "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n", "\r\n\r\n\r\n", "\r\n\r\n", "\n\n\n\n\n\n", "\n\n\n", "\n\n"), array(" ", " ", " ", "\r", "\n", "\r\n", "\r\n", "\r\n", "\n", "\n", "\n"), String::strip_tags(String::html_entity_decode_if_needed(String::htmlspecialchars_decode($annonce_object->get_description(), ENT_QUOTES)))));
153  $promotion_rss = '';
154  $this_item = array('title' => String::htmlentities(vb($category_text) . String::str_shorten_words(String::str_shorten(String::ucfirst($annonce_object->get_titre()), 120, '', '...', 100), 40), ENT_COMPAT, GENERAL_ENCODING, false, true, true),
155  'promotion_rss' => $promotion_rss,
156  'guid' => String::htmlentities($annonce_object->get_annonce_url(), ENT_COMPAT, GENERAL_ENCODING, false, true, true),
157  'pubDate' => String::htmlentities($dateRFC, ENT_COMPAT, GENERAL_ENCODING, false, true, true),
158  'description' => String::htmlentities(String::str_shorten(String::strip_tags(trim($desc_rss)), 250), ENT_COMPAT, GENERAL_ENCODING, false, true, true));
159  $image_url = $annonce_object->get_annonce_picture(true, $GLOBALS['site_parameters']['medium_width'], $GLOBALS['site_parameters']['medium_height']);
160  if(!empty($image_url)) {
161  $image_infos = getimagesize(String::rawurldecode(str_replace($GLOBALS['repertoire_upload'], $GLOBALS['uploaddir'], $image_url)));
162  $this_item['image']['length'] = filesize(String::rawurldecode(str_replace($GLOBALS['repertoire_upload'], $GLOBALS['uploaddir'], $image_url)));
163  $this_item['image']['url'] = $image_url;
164  $this_item['image']['mime'] = $image_infos['mime'];
165  }
166  $tpl_items[] = $this_item;
167  unset($annonce_object);
168  }
169  }
170  // Fin d'affichage
171  $tpl->assign('items', $tpl_items);
172  $output .= $tpl->fetch();
173 
174  $output = str_replace(array('&euro;'), array('&#8364;'), $output);
175  echo String::convert_encoding($output, $page_encoding, GENERAL_ENCODING);
176 
177  // Si on veut activer tracking Analytics de cette page :
178  // il faut renseigner $GLOBALS['site_parameters']['google_analytics_site_code_for_nohtml_pages'] via la page de configuration de variables de l'administration
179  close_page_generation(false);
180  die();
181 }
if(!function_exists('desinscription_newsletter')) close_page_generation($html_page=true)
Fonction à appeler à la fin de la génération d'une page, afin d'exécuter certaines requêtes SQL qui n...
Definition: fonctions.php:3797
static strip_tags($string, $allowed_tags=null)
String::strip_tags()
Definition: String.php:548
static htmlentities($string, $flags=ENT_COMPAT, $charset=GENERAL_ENCODING, $suppr_endline=false, $encode_only_isolated_amperstands=false, $decode_html_entities_first=false)
Convert all applicable characters to HTML entities Cette fonction sert si on veut afficher du contenu...
Definition: String.php:411
static htmlspecialchars_decode($string, $style=ENT_COMPAT)
This function is String::htmlspecialchars_decode with php4 compatibility.
Definition: String.php:500
$result
static convert_encoding($string, $new_encoding, $original_encoding=null)
Converts the character encoding of string $string to $new_encoding from optionally $original_encoding...
Definition: String.php:375
get_current_url($with_get=true, $get_short_url=false, $take_away_get_args_array=null)
get_current_url()
Definition: fonctions.php:1743
static rawurldecode($string, $avoid_slash=false)
Returns rawurldecode.
Definition: String.php:909
static html_entity_decode_if_needed($string)
String::html_entity_decode_if_needed()
Definition: String.php:533
if(!defined('IN_PEEL')) echo_rss_and_die($category_id=null, $seller_id=null)
echo_rss_and_die()
Definition: fonctions.php:25
if(!empty($_GET['id'])) if(isset($_POST['form_name'], $_POST['form_subject'], $_POST['form_text'], $_POST['form_lang'])&&empty($_GET['id'])) if(empty($_GET['id'])) $tpl
if(!defined('IN_PEEL')) $GLOBALS['page_types_array']
Definition: fonctions.php:19
if(empty($_GET['id'])) if(!empty($GLOBALS['site_parameters']['allow_multiple_product_url_with_category'])) $product_object
if(!defined('IN_PEEL')) thumbs($source_filename, $width, $height, $method= 'fit', $source_folder=null, $thumb_folder=null, $thumb_rename=true, $return_absolute_path=false)
Charge l'image dont le nom est $source_filename dans le répertoire d'upload, et crée une vignette pou...
Definition: fonctions.php:33
static str_shorten_words($string, $length_limit=100, $separator=" ", $force_shorten_if_special_content=false, $add_separator_instead_of_cutting=true)
On rajoute des espaces à l'intérieur des mots trop longs => à utiliser pour éviter de casser une mise...
Definition: String.php:305
get_filter_site_cond($table_technical_code, $table_alias=null, $use_strict_rights_if_in_admin=false, $specific_site_id=null, $exclude_public_items=false, $admin_force_multisite_if_allowed=false)
Retourne la condition SQL permettant de filtrer les données pour une table.
Definition: fonctions.php:4643
if(!defined('IN_PEEL')) display_prices_with_taxes_active()
display_prices_with_taxes_active()
Definition: fonctions.php:23
query($query, $die_if_error=false, $database_object=null, $silent_if_error=false, $security_sql_filter=true)
The query() function is meant to be called anywhere you want to make a query.
Definition: database.php:158
vb(&$var, $default=null)
Variable blanche if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:97
if(strlen($date2)== '10') if($type== 'users-by-age'&&a_priv('admin_users', true)) elseif($type== 'forums-count'&&a_priv('admin_content', true)) elseif($type== 'forums-categories'&&a_priv('admin_content', true)) elseif($type== 'users-count'&&a_priv('admin_users', true)) elseif($type== 'product-categories'&&a_priv('admin_products', true)) elseif($type== 'users-by-sex'&&a_priv('admin_users', true)) elseif($type== 'users-by-country'&&a_priv('admin_users', true)) elseif($type== 'sales'&&a_priv('admin_sales', true))
Definition: chart-data.php:160
fetch_assoc($query_result)
fetch_assoc()
Definition: database.php:283
if(!check_if_module_active('search')) $page_encoding
Definition: produit.php:23
vn(&$var, $default=0)
Variable nulle if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:110
check_if_module_active($module_name, $specific_file_name=null)
Renvoie si un module est présent et activé ou non - Peut être appelé avant ou après le chargement d'u...
static str_shorten($string, $length_limit, $middle_separator= '', $ending_if_no_middle_separator= '...', $ideal_length_with_clean_cut_if_possible=null)
Raccourcit une chaine de caractère en insérant au milieu ou à la fin un séparateur.
Definition: String.php:233
static ucfirst($string)
Returns string with first letter uppercase.
Definition: String.php:173
if(defined('IN_PEEL_ADMIN')||IN_INSTALLATION) $_SESSION['session_langue']

This documentation for Open ecommerce PEEL Shopping and PEEL.fr has been generated by Doxygen on Thu Oct 15 2015 14:31:03 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.