PEEL Shopping
Open source ecommerce : PEEL Shopping
SmartyEngine.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: SmartyEngine.php 46935 2015-09-18 08:49:48Z gboussin $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 
18 require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'smarty' . DIRECTORY_SEPARATOR . 'Smarty.class.php';
19 require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'SmartyTemplate.php';
20 
30 class SmartyEngine extends EngineTpl {
31  private $smarty;
32 
33  public function __construct($templadeDir, $forceCompile = false, $debugging = false)
34  {
35  $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'smarty' . DIRECTORY_SEPARATOR;
36  $this->smarty = new Smarty();
37  $this->smarty->setCompileDir($dir . 'compile' . DIRECTORY_SEPARATOR);
38  $this->smarty->setCacheDir($dir . 'cache' . DIRECTORY_SEPARATOR);
39  $this->smarty->setTemplateDir($templadeDir);
40  $this->smarty->caching = Smarty::CACHING_OFF;
41  $this->smarty->compile_check = (bool)$forceCompile;
42  $this->smarty->force_compile = false;
43  $this->smarty->debugging = (bool)$debugging;
44  $this->smarty->_file_perms = vb($GLOBALS['site_parameters']['chmod_new_files'], null);
45  $this->smarty->registerPlugin("modifier", "filtre_javascript", "filtre_javascript");
46  $this->smarty->registerPlugin("modifier", "html_entity_decode_if_needed", "String::html_entity_decode_if_needed");
47  $this->smarty->registerPlugin("modifier", "str_shorten", "String::str_shorten");
48  $this->smarty->registerPlugin("modifier", "nl2br_if_needed", "String::nl2br_if_needed");
49  $this->smarty->registerPlugin("modifier", "str_form_value", "String::str_form_value");
50  $this->smarty->registerPlugin("modifier", "strtoupper", "String::strtoupper");
51  $this->smarty->registerPlugin("modifier", "html_entity_decode", "String::html_entity_decode");
52  $this->smarty->registerPlugin("modifier", "htmlentities", "String::htmlentities");
53  $this->smarty->registerPlugin("modifier", "textEncode", "String::textEncode");
54  $this->smarty->registerPlugin("modifier", "highlight_found_text", "highlight_found_text");
55  $this->smarty->registerDefaultTemplateHandler('SmartyDefaultTemplateHandler');
56  }
57 
58  public function addTemplateDir($templadeDir)
59  {
60  $this->smarty->addTemplateDir($templadeDir);
61  }
62 
63  public function assign($tpl_var, $value = null)
64  {
65  $this->smarty->assign($tpl_var, $value);
66  }
67 
68  public function display($template)
69  {
70  $this->smarty->display($template);
71  }
72 
73  public function fetch($template)
74  {
75  return $this->smarty->fetch($template);
76  }
77 
78  public function createTemplate($template, array $data = null)
79  {
80  // Variables générales disponibles dans Smarty, et variables de compatibilité partielle avec certains modèles de templates
81  $data['LANG'] = $GLOBALS['LANG'];
82  $data['site_parameters'] = $GLOBALS['site_parameters'];
83  if(!isset($data['site_id'])) {
84  $data['site_id'] = $GLOBALS['site_id'];
85  }
86  if(!isset($data['wwwroot'])) {
87  $data['wwwroot'] = $GLOBALS['wwwroot'];
88  }
89  $data['base_dir'] = $GLOBALS['wwwroot'];
90  $data['content_dir'] = $GLOBALS['wwwroot'] . $GLOBALS['apparent_folder'];
91  $data['dirroot'] = $GLOBALS['dirroot'];
92  $data['img_ps_dir'] = $GLOBALS['wwwroot'] . '/images';
93  $data['repertoire_images'] = $GLOBALS['repertoire_images'];
94  $data['repertoire_upload'] = $GLOBALS['repertoire_upload'];
95  $data['img_dir'] = $GLOBALS['repertoire_images'];
96  $data['repertoire_css'] = $GLOBALS['repertoire_css'];
97  $data['css_dir'] = $GLOBALS['repertoire_css'];
98  $data['js_dir'] = $GLOBALS['wwwroot'] . '/js';
99  $data['tpl_dir'] = $GLOBALS['repertoire_modele'];
100  $data['modules_dir'] = $GLOBALS['wwwroot'] . '/modules';
101  $data['mail_dir'] = null;
102  $data['come_from'] = vb($_SERVER['HTTP_REFERER']);
103  $data['languages'] = $GLOBALS['lang_codes'];
104  $data['lang_names'] = $GLOBALS['lang_names'];
105  $data['lang_iso'] = $_SESSION['session_langue'];
106  $data['shop_name'] = vb($GLOBALS['site_parameters']['nom_' . $_SESSION['session_langue']]);
107  if(!empty($_SESSION['session_caddie'])) {
108  $data['cart_qties'] = $_SESSION['session_caddie']->count_products();
109  $data['cart'] = $_SESSION['session_caddie']->articles;
110  }
111  $data['currencies'] = array($_SESSION['session_devise']['code']);
112  $data['id_currency_cookie'] = $_SESSION['session_devise']['code'];
113  $data['logged'] = (!empty($_SESSION['session_utilisateur']['id_utilisateur']));
114  $data['page_name'] = null; // Non disponible systématiquement ici
115  $data['customerName'] = (!empty($_SESSION['session_utilisateur']['id_utilisateur'])?vb($_SESSION['session_utilisateur']['prenom']) . ' '. vb($_SESSION['session_utilisateur']['nom_famille']):null);
116  $data['priceDisplay'] = null;
117  return new SmartyTemplate($this->smarty->createTemplate($template, null, null, $data));
118  }
119 }
120 
121 function SmartyDefaultTemplateHandler($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
122 {
123  if($resource_type == 'file' ) {
124  return $GLOBALS['dirroot'] . "/modeles/peel7/smarty/".$resource_name;
125  } else {
126  // pas un fichier
127  return false;
128  }
129 }
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
Definition: chart-data.php:29
addTemplateDir($templadeDir)
SmartyDefaultTemplateHandler($resource_type, $resource_name, &$template_source, &$template_timestamp, Smarty $smarty)
assign($tpl_var, $value=null)
const CACHING_OFF
define caching modes
fetch($template)
__construct($templadeDir, $forceCompile=false, $debugging=false)
Smarty plugin to format text blocks.
createTemplate($template, array $data=null)
vb(&$var, $default=null)
Variable blanche if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:97
$GLOBALS['page_columns_count']
display($template)
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:41:18 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.