PEEL Shopping
Open source ecommerce : PEEL Shopping
Module.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: Module.php 47154 2015-10-05 07:55:09Z sdelaporte $
14 if (!defined('IN_PEEL')) {
15  die();
16 }
17 
27 abstract class Module {
28  // Technical data
31  // Administration data
32  public $name_by_lang;
33  public $name;
35  public $vendor;
36  // Version data
37  public $dependencies;
38  public $version;
41  // Other
42  private $_errors;
43  private $_messages;
44 
49  public function __construct()
50  {
51  if (empty($this->name_by_lang[$_SESSION['session_langue']])) {
52  $this->name_by_lang[$_SESSION['session_langue']] = vb($this->name_by_lang['en'], vb($this->name_by_lang['fr'], $this->technical_code));
53  }
54  $this->name = $this->name_by_lang[$_SESSION['session_langue']];
55  if ($this->activation_variable === null) {
56  $this->activation_variable = 'module_'.$this->technical_code;
57  }
58  }
59 
65  public function get_messages()
66  {
67  $output = '';
68  if(!empty($this->_errors)) {
69  foreach($this->_errors as $this_error) {
70  $output .= $GLOBALS['tplEngine']->createTemplate('global_error.tpl', array('message' => $this_error))->fetch();
71  }
72  }
73  if(!empty($this->_messages)) {
74  foreach($this->_messages as $this_message) {
75  $output .= $GLOBALS['tplEngine']->createTemplate('global_success.tpl', array('message' => $this_message))->fetch();
76  }
77  }
78  return $output;
79  }
80 
86  static public function check_install()
87  {
88  return null;
89  }
90 
96  public function install()
97  {
98  // Hook de début d'installation
99  call_module_hook('module_install_pre', array('object' => $this));
100 
101  // Vérifie si module déjà installé
102  if ($this::check_install()) {
103  $this->_errors['installed'] = $this->name . ' déjà installé';
104  return true;
105  }
106  // Vérifie la version du module
107  if (!$this->check_compatibility()) {
108  $this->_errors['version'] = $this->name . ' - version incompatible';
109  }
110  // Vérifie les dependences avec d'autres modules
111  if (!empty($this->dependencies) && count($this->dependencies) > 0) {
112  foreach ($this->dependencies as $this_dependency) {
113  if (!in_array($this_dependency, $GLOBALS['modules_installed'])) {
114  $this->_errors['dependency'] = $this->name . ' - module required: ' . $this_dependency;
115  }
116  }
117  }
118  // Réaliser l'installation
119  $this->execute('install');
120 
121  // Activer le module pour tous les sites
122  $this->enable();
123 
124  // Hook de fin d'installation
125  call_module_hook('module_install_post', array('object' => $this));
126 
127  return true;
128  }
129 
135  public function uninstall()
136  {
137  // Hook de début de désinstallation
138  call_module_hook('module_uninstall_pre', array('object' => $this));
139 
140  // Vérifie si module déjà installé
141  if (!in_array($this->technical_code, $GLOBALS['modules_installed'])) {
142  return true;
143  }
144 
145  // Réaliser la désinstallation
146  $this->execute('uninstall');
147 
148  // Hook de fin de désinstallation
149  call_module_hook('module_uninstall_post', array('object' => $this));
150 
151  return true;
152  }
153 
160  public function execute($mode = null)
161  {
162  return null;
163  }
164 
171  public function enable($site_id = 0)
172  {
173  return set_configuration_variable(array('technical_code' => $this->activation_variable, 'string' => 1, 'type' => 'integer', 'site_id' => $site_id, 'origin' => $this->technical_code), true);
174  }
175 
182  public function disable($site_id = 0)
183  {
184  return set_configuration_variable(array('technical_code' => $this->activation_variable, 'string' => 0, 'type' => 'integer', 'site_id' => $site_id, 'origin' => $this->technical_code), true);
185  }
186 
193  public function check_compatibility()
194  {
195  if ((!empty($this->peel_versions_compatibility['min']) && version_compare(PEEL_VERSION, $this->peel_versions_compatibility_infos['min'], '<')) || (!empty($this->peel_versions_compatibility_infos['max']) && version_compare(PEEL_VERSION, $this->peel_versions_compatibility_infos['max'], '>'))) {
196  return false;
197  } else {
198  return true;
199  }
200  }
201 }
202 
$vendor
Definition: Module.php:35
$name_by_lang
Definition: Module.php:32
static check_install()
Vérifie l'installation du module.
Definition: Module.php:86
$name
Definition: Module.php:33
$dependencies
Definition: Module.php:37
$mode
$technical_code
Definition: Module.php:29
disable($site_id=0)
Désactive le module.
Definition: Module.php:182
vb(&$var, $default=null)
Variable blanche if $var n'est pas défini, retourne $default, sinon retourne $var.
Definition: format.php:97
$activation_variable
Definition: Module.php:30
check_compatibility()
Désactive le module.
Definition: Module.php:193
__construct()
Constructor.
Definition: Module.php:49
call_module_hook($hook, $params, $mode= 'boolean')
Appelle la fonction correspondant au $hook pour chaque module installé La fonction doit s'appeler : [...
$GLOBALS['page_columns_count']
const PEEL_VERSION(version_compare(PHP_VERSION, '5.1.2', '<'))
execute($mode=null)
Exécute une action.
Definition: Module.php:160
enable($site_id=0)
Active le module.
Definition: Module.php:171
set_configuration_variable($frm, $update_if_technical_code_exists=false, $allow_create=true)
Ajoute la zone HTML dans la table peel_configuration.
Definition: fonctions.php:4199
$peel_versions_compatibility_infos
Definition: Module.php:40
get_messages()
Renvoie les erreurs formattées.
Definition: Module.php:65
$description_by_lang
Definition: Module.php:34
$version
Definition: Module.php:38
$database_version
Definition: Module.php:39
install()
Installe le module.
Definition: Module.php:96
uninstall()
Désinstalle un module.
Definition: Module.php:135
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:30:03 - Peel ecommerce is a product of Agence web Advisto SAS. All rights reserved.