PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/class/class_assemblage.php

http://malleo-cms.googlecode.com/
PHP | 368 lines | 291 code | 28 blank | 49 comment | 57 complexity | 9aef5becda143260800efa8c0805b3c4 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. |------------------------------------------------------------------------------------------------------------
  4. | Software: Malleo ( CMS )
  5. | Contact: SP - http://www.malleo-cms.com
  6. | Support: http://www.malleo-cms.com?module=forum
  7. | Documentation : Support: http://www.malleo-cms.com?module=wiki
  8. |------------------------------------------------------------------------------------------------------------
  9. | Author: Stephane RAJALU
  10. | Copyright (c) 2008-2009, Stephane RAJALU All Rights Reserved
  11. |------------------------------------------------------------------------------------------------------------
  12. | License: Distributed under the CECILL V2 License
  13. | This program is distributed in the hope that it will be useful - WITHOUT
  14. | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. | FITNESS FOR A PARTICULAR PURPOSE.
  16. |
  17. | Please read Licence_CeCILL_V2-en.txt
  18. | SVP lisez Licence_CeCILL_V2-fr.txt
  19. |------------------------------------------------------------------------------------------------------------
  20. */
  21. if ( !defined('PROTECT') )
  22. {
  23. die("Tentative de Hacking");
  24. }
  25. function charge_blocs($retour){
  26. global $tpl,$root,$lang;
  27. $bloc = preg_replace('/{|}/','',$retour[0]);
  28. if (preg_match('/HTML_/',$bloc))
  29. {
  30. // BLOC HTML
  31. $id_bloc_html = intval(preg_replace('/HTML_/','',$bloc));
  32. include_once($root.'plugins/blocs/html/mod.php');
  33. $tpl->pparse('HTML_'.$id_bloc_html,true);
  34. }elseif (file_exists($root.'plugins/blocs/'.$bloc.'/mod.php'))
  35. {
  36. include_once($root.'plugins/blocs/'.$bloc.'/mod.php');
  37. $tpl->pparse($bloc,true);
  38. }
  39. if (trim($tpl->buffer) == '')
  40. {
  41. $tpl->set_filenames(array(
  42. 'body_admin' => $root.'html/admin_modele_bloc_vide.html'
  43. ));
  44. $tpl->assign_vars(array(
  45. 'L_TITRE' => $_POST['RequeteAjax'],
  46. 'L_MESSAGE' => $lang['L_ALERTE_BLOC_VIDE']
  47. ));
  48. $tpl->pparse('body_admin',true);
  49. return $tpl->buffer;
  50. }else{
  51. return $tpl->buffer;
  52. }
  53. }
  54. function charge_zones(){
  55. global $i;
  56. $i++;
  57. return '<div id="dragableBoxesColumn'.$i.'"></div>';
  58. }
  59. function charge_blocs_apercu(){
  60. global $i,$root,$tpl,$cf,$c,$lang,$map,$user,$session,$id_bloc_html,$cache,$liste_plugins,$cache;
  61. $i++;
  62. if (array_key_exists($i,$map->data['map']))
  63. {
  64. $colonne='';
  65. $map->data['map'][$i] = array_reverse($map->data['map'][$i]);
  66. foreach($map->data['map'][$i] as $key=>$value)
  67. {
  68. if ($value == 'module')
  69. {
  70. $colonne .= '<table class="standard"><tr><td class="row1">'.$lang['L_MODULE_PRINCIPAL'].'</td></tr></table>';
  71. }elseif(preg_match('/HTML_/',$value)){
  72. $id_bloc_html = intval(preg_replace('/HTML_/','',$value));
  73. include($root.'plugins/blocs/html/mod.php');
  74. $tpl->pparse($value,true);
  75. $colonne .= $tpl->buffer;
  76. }else{
  77. include_once($root.'plugins/blocs/'.$value.'/mod.php');
  78. $tpl->pparse($value,true);
  79. $colonne .= $tpl->buffer;
  80. }
  81. }
  82. return $colonne;
  83. }else{
  84. return '';
  85. }
  86. }
  87. function charge_handle()
  88. {
  89. global $i,$map;
  90. $i++;
  91. if (array_key_exists($i,$map->data['map']))
  92. {
  93. $colonne='';
  94. // Les résultats doivent ?tre classés dans le sens inverse
  95. // Ceci est du ? un prérequis de la class javascript qui "fait tomber les blocs par le haut"
  96. $map->data['map'][$i] = array_reverse($map->data['map'][$i]);
  97. foreach($map->data['map'][$i] as $key=>$value)
  98. {
  99. $colonne .= '<div id="zone_'.$value.'">{'.$value.'}</div>';
  100. }
  101. return $colonne;
  102. }else{
  103. return '';
  104. }
  105. }
  106. function tester_modele($gabaris,$map,$fichier=false)
  107. {
  108. global $lang,$root;
  109. if ($fichier == true && file_exists($fichier))return $lang['L_ETAT_OK'];
  110. // Test d'existence du gabaris
  111. if (!file_exists($root.'data/modeles/'.$gabaris.'/squelette.txt')) return $lang['L_GABARIS_INDISPONIBLE'];
  112. // Test de cohérence de la map
  113. if (!is_string($map)) return $lang['L_ENREGISTREMENT_MAP_FAILED'];
  114. $map = unserialize($map);
  115. if (!is_array($map) || (sizeof($map)==0)) return $lang['L_ENREGISTREMENT_MAP_FAILED'];
  116. // Test d'existence de chaque bloc
  117. foreach ($map as $key=>$val)
  118. {
  119. foreach($val as $k=>$v)
  120. {
  121. if (!file_exists($root.'plugins/blocs/'.$v.'/mod.php') && $v != 'module'&& !preg_match('/HTML_/',$v)) return sprintf($lang['BLOC_SUPPRIME'],$v);
  122. }
  123. }
  124. return $lang['L_ETAT_OK'];
  125. }
  126. class Assemblage
  127. {
  128. var $map;
  129. var $id_modele;
  130. var $chemin_blocs;
  131. var $nbre_zones;
  132. var $data = '';
  133. var $data_file = ''; // contenu du fichier .html
  134. var $html_file; // nom du fichier html
  135. var $module;
  136. var $listing_pages;
  137. function Assemblage()
  138. {
  139. $this->chemin_blocs = 'plugins/blocs/';
  140. }
  141. //
  142. // Enregistre un nouveau mod?le en base
  143. function insert_modele()
  144. {
  145. global $c;
  146. $sql = 'INSERT INTO '.TABLE_MODELES.' (gabaris, titre_modele)
  147. VALUES (\''.$this->data['gabaris'].'\',\''.$this->data['titre_modele'].'\')';
  148. if (!$res=$c->sql_query($sql)) message_die(E_ERROR,7,__FILE__,__LINE__,$sql);
  149. $this->id_modele = $c->sql_nextid();
  150. return true;
  151. }
  152. //
  153. // Enregistre un nouveau mod?le de type fichier en base
  154. function insert_modele_fichier($titre,$fichier)
  155. {
  156. global $c;
  157. $sql = 'INSERT INTO '.TABLE_MODELES.' (titre_modele, fichier)
  158. VALUES (\''.$titre.'\',\''.$fichier.'\')';
  159. if (!$res=$c->sql_query($sql)) message_die(E_ERROR,7,__FILE__,__LINE__,$sql);
  160. $this->id_modele = $c->sql_nextid();
  161. return true;
  162. }
  163. //
  164. // Lecture des infos sur le mod?le demandé
  165. function lecture_modele()
  166. {
  167. global $c;
  168. $sql = 'SELECT id_modele, gabaris, titre_modele, map, fichier FROM '.TABLE_MODELES.' WHERE id_modele='.$this->id_modele;
  169. if (!$resultat=$c->sql_query($sql)) message_die(E_ERROR,8,__FILE__,__LINE__,$sql);
  170. $this->data = $c->sql_fetchrow($resultat);
  171. }
  172. //
  173. //
  174. function supprimer_modele()
  175. {
  176. global $c;
  177. $this->lecture_modele();
  178. if ($this->data['fichier']!= null && file_exists($this->data['fichier'])){
  179. @unlink($this->data['fichier']);
  180. }
  181. $sql = 'DELETE FROM '.TABLE_MODELES.' WHERE id_modele='.$this->id_modele;
  182. if (!$resultat=$c->sql_query($sql)) message_die(E_ERROR,9,__FILE__,__LINE__,$sql);
  183. }
  184. //
  185. // lecture du fichier squelette
  186. function lecture_squelette()
  187. {
  188. global $root;
  189. $file = $root.'data/modeles/'.$this->data['gabaris'].'/squelette.txt';
  190. if (!file_exists($file ) || !$this->map = @file_get_contents($file )) error404(10);
  191. return true;
  192. }
  193. //
  194. // Prépare la map pour les blocs dynamiques
  195. function prepare_map_apercu()
  196. {
  197. global $i;
  198. if (!$this->lecture_squelette()) return false;
  199. $i=0;
  200. $this->map = preg_replace_callback("/BLOC/",'charge_blocs_apercu',$this->map);
  201. $this->map = preg_replace_callback("|\{[a-z0-9_-]+\}|",'charge_blocs',$this->map);
  202. $this->nbre_zones = $i;
  203. return true;
  204. }
  205. //
  206. // Prépare la map pour les blocs dynamiques
  207. function prepare_map_dynamique()
  208. {
  209. global $i;
  210. if (!$this->lecture_squelette()) return false;
  211. $i=0;
  212. $this->map = preg_replace('/<td/i','<td class="zones"',$this->map);
  213. $this->map = preg_replace_callback("/BLOC/",'charge_zones',$this->map);
  214. $this->map = preg_replace_callback("|\{[a-z0-9_-]+\}|",'charge_blocs',$this->map);
  215. $this->nbre_zones = $i;
  216. return true;
  217. }
  218. //
  219. // Lis le fichier .html
  220. function Lire_Fichier_HTML()
  221. {
  222. if ($this->data_file == '') $this->data_file = file_get_contents($this->html_file);
  223. return $this->data_file;
  224. }
  225. //
  226. // Renvoie le nom du fichier .html ? utiliser
  227. function Cache_Template($module,$force=false)
  228. {
  229. global $root,$cache,$cf;
  230. if (defined('IPHONE') && $cf->config['imposer_modele_iphones']!=''){
  231. $this->html_file = $cache->cache_tpl($root.'cache/modeles/_modele_iphone_.html','global $map; return $map->monter_template_via_modele(\''.$cf->config['imposer_modele_iphones'].'\');', 86400);
  232. }else{
  233. $this->html_file = $root.'cache/modeles/'.$module.'.html';
  234. if (!file_exists($this->html_file) || $force==true){
  235. $tps = ($force==true)?0:86400;
  236. $this->html_file = $cache->cache_tpl($this->html_file,'global $map; return $map->monter_template(\''.$module.'\');', $tps);
  237. }
  238. }
  239. return $this->html_file;
  240. }
  241. function monter_template($module)
  242. {
  243. global $c,$i;
  244. $sql = 'SELECT id_modele, gabaris, map, fichier
  245. FROM '.TABLE_MODULES.' as P LEFT JOIN '.TABLE_MODELES.' as M
  246. ON (P.modele=M.id_modele)
  247. WHERE P.module="'.$module.'" OR P.id_module="'.$module.'" LIMIT 1';
  248. if (!$resultat=$c->sql_query($sql)) message_die(E_ERROR,11,__FILE__,__LINE__,$sql);
  249. $this->data = $c->sql_fetchrow($resultat);
  250. if ($this->data['fichier'] != null){
  251. return file_get_contents($this->data['fichier']);
  252. }elseif(is_string($this->data['map'])){
  253. $this->data['map'] = unserialize($this->data['map']);
  254. $this->lecture_squelette();
  255. $i=0;
  256. $this->map = preg_replace_callback("/BLOC/",'charge_handle',$this->map);
  257. return $this->map;
  258. }else{
  259. error404(11);
  260. }
  261. }
  262. function monter_template_via_modele($modele)
  263. {
  264. global $c,$i;
  265. $sql = 'SELECT id_modele, gabaris, map, fichier
  266. FROM '.TABLE_MODELES.'
  267. WHERE titre_modele="'.$modele.'" LIMIT 1';
  268. if (!$resultat=$c->sql_query($sql)) message_die(E_ERROR,11,__FILE__,__LINE__,$sql);
  269. $this->data = $c->sql_fetchrow($resultat);
  270. if ($this->data['fichier'] != null){
  271. return file_get_contents($this->data['fichier']);
  272. }else{
  273. $this->data['map'] = unserialize($this->data['map']);
  274. $this->lecture_squelette();
  275. $i=0;
  276. $this->map = preg_replace_callback("/BLOC/",'charge_handle',$this->map);
  277. return $this->map;
  278. }
  279. }
  280. //
  281. // Crée les options d'un menu déroulants de blocs, le parametre exlus permet de sortir du listing les blocs déj? utilisés
  282. function lister_blocs_dispo($exclus=array())
  283. {
  284. global $liste_plugins,$root,$cache,$lang;
  285. include_once($root.'class/class_plugins.php');
  286. $plugin = new plugins();
  287. $liste_blocs = '<option value="">'.$lang['L_SELECTIONNER_BLOC'].'</option>';
  288. if(!$ch = @opendir($this->chemin_blocs))
  289. message_die(E_ERROR,12,__FILE__,__LINE__);
  290. while ($bloc = @readdir($ch))
  291. {
  292. if ($bloc != '.' && $bloc != '..' && is_dir($this->chemin_blocs.$bloc)
  293. && $bloc != 'menu_horizontal'&& $bloc != 'html' && !in_array($bloc,$exclus))
  294. {
  295. if (!array_key_exists($bloc,$liste_plugins)){
  296. $plugin->install_plugin($bloc,1);
  297. }
  298. $liste_blocs .= '<option value="'.$bloc.'">'.$bloc.'</option>';
  299. }
  300. }
  301. @closedir($ch);
  302. return $liste_blocs;
  303. }
  304. //
  305. // Crée les options d'un menu déroulants de blocs HTML, le parametre exlus permet de sortir du listing les blocs déj? utilisés
  306. function lister_blocs_html_dispo($exclus=array())
  307. {
  308. global $c,$lang,$root,$lang;
  309. include_once($root.'plugins/blocs/html/prerequis.php');
  310. $liste_blocs = '<option value="">'.$lang['L_SELECTIONNER_BLOC'].'</option>';
  311. $sql = 'SELECT id, titre FROM '.TABLE_HTML.' ORDER BY TITRE ASC';
  312. if (!$resultat = $c->sql_query($sql)) message_die(E_ERROR,1020,__FILE__,__LINE__,$sql);
  313. while ($row = $c->sql_fetchrow($resultat))
  314. {
  315. if (!in_array($row['id'],$exclus))
  316. {
  317. $liste_blocs .= '<option value="HTML_'.$row['id'].'">'.$row['titre'].'</option>';
  318. }
  319. }
  320. return $liste_blocs;
  321. }
  322. //
  323. // Liste les modules existants
  324. function lister_modules()
  325. {
  326. global $c;
  327. $liste = array();
  328. $sql = 'SELECT module, virtuel, modele, style FROM '.TABLE_MODULES;
  329. if (!$resultat = $c->sql_query($sql)) message_die(E_ERROR,13,__FILE__,__LINE__,$sql);
  330. if ($c->sql_numrows($resultat) > 0)
  331. {
  332. while($res = $c->sql_fetchrow($resultat))
  333. {
  334. $liste[$res['module']] = $res;
  335. }
  336. }
  337. return $liste;
  338. }
  339. }
  340. ?>