PEEL Shopping
Open source ecommerce : PEEL Shopping
TwigEngine.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: TwigEngine.php 46935 2015-09-18 08:49:48Z gboussin $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'TwigTemplate.php';
18 
28 class TwigEngine extends EngineTpl {
29  private $twig;
30  private $context = array();
31 
32  public function __construct($templadeDir, $forceCompile = false, $debugging = false)
33  {
34  $twigConf = array();
35  $twigConf['cache'] = $GLOBALS['dirroot'] . '/cache';
36  $twigConf['debug'] = $debugging;
37  $twigConf['auto_reload'] = $forceCompile;
38  $twigConf['autoescape'] = false;
39  $loader = new Twig_Loader_Filesystem($GLOBALS['repertoire_modele'] . '/' . $GLOBALS['site_parameters']['template_engine']);
40  $this->twig = new Twig_Environment($loader, $twigConf);
41  // Ajout de fonctionnalités
42  $this->twig->addFilter(new Twig_SimpleFilter("filtre_javascript", "filtre_javascript"));
43  $this->twig->addFilter(new Twig_SimpleFilter("html_entity_decode_if_needed", "String::html_entity_decode_if_needed"));
44  $this->twig->addFilter(new Twig_SimpleFilter("str_shorten", "String::str_shorten"));
45  $this->twig->addFilter(new Twig_SimpleFilter("nl2br_if_needed", "String::nl2br_if_needed"));
46  $this->twig->addFilter(new Twig_SimpleFilter("str_form_value", "String::str_form_value"));
47  $this->twig->addFilter(new Twig_SimpleFilter("strtoupper", "String::strtoupper"));
48  $this->twig->addFilter(new Twig_SimpleFilter("html_entity_decode", "String::html_entity_decode"));
49  $this->twig->addFilter(new Twig_SimpleFilter("htmlentities", "String::htmlentities"));
50  $this->twig->addFilter(new Twig_SimpleFilter("textEncode", "String::textEncode"));
51  $this->twig->addFilter(new Twig_SimpleFilter("htmlspecialchars", "htmlspecialchars"));
52  $this->twig->addFilter(new Twig_SimpleFilter("addslashes", "addslashes"));
53  $this->twig->addFilter(new Twig_SimpleFilter("intval", "intval"));
54  $this->twig->addFilter(new Twig_SimpleFilter("round", "round"));
55  $this->twig->addFilter(new Twig_SimpleFilter("strip_tags", "strip_tags"));
56  /*$title = new Twig_Function_Function(getTitle, array('is_safe' => array('html')));
57  $this->twig->addFunction('getTitle', $title);
58  //
59 
60  $filters = array();
61  $ignoredMethods = array(
62  'getFilters' => true,
63  'getName' => true,
64  'initRuntime' => true,
65  'getTokenParsers' => true,
66  'getNodeVisitors' => true
67  );
68  foreach (get_class_methods($this) as $methodName) {
69  if (!array_key_exists($methodName, $ignoredMethods)) {
70  $filters[$methodName] = new Twig_Filter_Method($this, $methodName);
71  }
72  }
73  */
74  }
75 
76  public function assign($tpl_var, $value = null)
77  {
78  $this->context[$tpl_var] = $value;
79  }
80 
81  public function display($template)
82  {
83  $this->twig->display($template, $this->context);
84  }
85 
86  public function fetch($template)
87  {
88  return $this->twig->render($templat, $this->context);
89  }
90 
91  public function createTemplate($template, array $data = null)
92  {
93  // Variables générales disponibles dans Smarty, et variables de compatibilité partielle avec certains modèles de templates
94  $data['LANG'] = $GLOBALS['LANG'];
95  $data['site_parameters'] = $GLOBALS['site_parameters'];
96  if(!isset($data['site_id'])) {
97  $data['site_id'] = $GLOBALS['site_id'];
98  }
99  if(!isset($data['wwwroot'])) {
100  $data['wwwroot'] = $GLOBALS['wwwroot'];
101  }
102  $data['base_dir'] = $GLOBALS['wwwroot'];
103  $data['content_dir'] = $GLOBALS['wwwroot'] . $GLOBALS['apparent_folder'];
104  $data['dirroot'] = $GLOBALS['dirroot'];
105  $data['img_ps_dir'] = $GLOBALS['wwwroot'] . '/images';
106  $data['repertoire_images'] = $GLOBALS['repertoire_images'];
107  $data['repertoire_upload'] = $GLOBALS['repertoire_upload'];
108  $data['img_dir'] = $GLOBALS['repertoire_images'];
109  $data['repertoire_css'] = $GLOBALS['repertoire_css'];
110  $data['css_dir'] = $GLOBALS['repertoire_css'];
111  $data['js_dir'] = $GLOBALS['wwwroot'] . '/js';
112  $data['tpl_dir'] = $GLOBALS['repertoire_modele'];
113  $data['modules_dir'] = $GLOBALS['wwwroot'] . '/modules';
114  $data['mail_dir'] = null;
115  $data['come_from'] = vb($_SERVER['HTTP_REFERER']);
116  $data['languages'] = $GLOBALS['lang_codes'];
117  $data['lang_names'] = $GLOBALS['lang_names'];
118  $data['lang_iso'] = $_SESSION['session_langue'];
119  $data['shop_name'] = vb($GLOBALS['site_parameters']['nom_' . $_SESSION['session_langue']]);
120  if(!empty($_SESSION['session_caddie'])) {
121  $data['cart_qties'] = $_SESSION['session_caddie']->count_products();
122  $data['cart'] = $_SESSION['session_caddie']->articles;
123  }
124  $data['currencies'] = array($_SESSION['session_devise']['code']);
125  $data['id_currency_cookie'] = $_SESSION['session_devise']['code'];
126  $data['logged'] = (!empty($_SESSION['session_utilisateur']['id_utilisateur']));
127  $data['page_name'] = null; // Non disponible systématiquement ici
128  $data['customerName'] = (!empty($_SESSION['session_utilisateur']['id_utilisateur'])?vb($_SESSION['session_utilisateur']['prenom']) . ' '. vb($_SESSION['session_utilisateur']['nom_famille']):null);
129  $data['priceDisplay'] = null;
130  $this->context = array_merge($this->context, $data);
131  try{
132  //try {
133  return new TwigTemplate($this->twig->loadTemplate($template), $this->context);
134  //} catch (Twig_Error_Syntax $e) {
135  // return new TwigTemplate($this->twig->loadTemplate('void.tpl'), $this->context);
136  //}
137  } catch (Twig_Error_Loader $e) {
138  $this->context['missing_template_name'] = $template;
139  return new TwigTemplate($this->twig->loadTemplate('void.tpl'), $this->context);
140  }
141  }
142 }
143 
foreach(array('date1', 'date2', 'type', 'renewals', 'width') as $item) $data
Definition: chart-data.php:29
Loads template from the filesystem.
Definition: Filesystem.php:17
createTemplate($template, array $data=null)
Definition: TwigEngine.php:91
display($template)
Definition: TwigEngine.php:81
vb(&$var, $default=null)
Variable blanche if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:97
__construct($templadeDir, $forceCompile=false, $debugging=false)
Definition: TwigEngine.php:32
$GLOBALS['page_columns_count']
Stores the Twig configuration.
Definition: Environment.php:17
assign($tpl_var, $value=null)
Definition: TwigEngine.php:76
Represents a template filter.
Exception thrown when an error occurs during template loading.
Definition: Loader.php:25
fetch($template)
Definition: TwigEngine.php:86
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:19 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.