PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/zpip-1.7.9/z_pipelines.php

https://bitbucket.org/pombredanne/spip-zone-treemap
PHP | 305 lines | 193 code | 32 blank | 80 comment | 33 complexity | 1993f4d8e31ade7a58aa0ddf08a38463 MD5 | raw file
  1. <?php
  2. /*
  3. * Plugin Zpip
  4. * (c) 2008-2010 Cedric MORIN Yterium.net
  5. * Distribue sous licence GPL
  6. *
  7. */
  8. if (!defined("_ECRIRE_INC_VERSION")) return;
  9. // demander a SPIP de definir 'type' dans le contexte du premier squelette
  10. define('_DEFINIR_CONTEXTE_TYPE',true);
  11. // verifier une seule fois que l'on peut utiliser APL si demande
  12. if (defined('_Z_AJAX_PARALLEL_LOAD')) {
  13. if (_request('var_zapl')=='non') {
  14. include_spip('inc/cookie');
  15. spip_setcookie('no_zapl',$_COOKIE['no_zapl']='no_zapl');
  16. }
  17. if (!isset($_COOKIE['no_zapl'])
  18. AND !_IS_BOT
  19. AND !_request('var_zajax')
  20. AND _request('var_mode')!=="debug"
  21. AND $_SERVER['REQUEST_METHOD'] == 'GET'
  22. ) {
  23. define('_Z_AJAX_PARALLEL_LOAD_OK',true);
  24. $GLOBALS['marqueur'] .= ":Zapl";
  25. }
  26. }
  27. /**
  28. * Inutilise mais permet le chargement de ce fichier avant le decodage des urls
  29. * et l'utilisation de _DEFINIR_CONTEXTE_TYPE
  30. * @param <type> $flux
  31. * @return <type>
  32. */
  33. function Z_declarer_url_objets($flux){
  34. return $flux;
  35. }
  36. /**
  37. * Fonction Page automatique a partir de contenu/page-xx
  38. *
  39. * @param array $flux
  40. * @return array
  41. */
  42. function Z_styliser($flux){
  43. $z_blocs = isset($GLOBALS['z_blocs'])?$GLOBALS['z_blocs']:array('contenu','navigation','extra','head');
  44. $z_contenu = reset($z_blocs); // contenu par defaut
  45. $squelette = $flux['data'];
  46. $fond = $flux['args']['fond'];
  47. $ext = $flux['args']['ext'];
  48. // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera an ajax
  49. if (defined('_Z_AJAX_PARALLEL_LOAD_OK')
  50. AND $dir = explode('/',$fond)
  51. AND count($dir)==2 // pas un sous repertoire
  52. AND $dir = reset($dir)
  53. AND in_array($dir,$z_blocs) // verifier deja qu'on est dans un bloc Z
  54. AND in_array($dir,explode(',',_Z_AJAX_PARALLEL_LOAD)) // et dans un demande en APL
  55. AND $pipe = find_in_path("$dir/z_apl.$ext") // et qui contient le squelette APL
  56. ){
  57. $flux['data'] = substr($pipe, 0, - strlen(".$ext"));
  58. return $flux;
  59. }
  60. // gerer les squelettes non trouves
  61. // -> router vers les /dist.html
  62. // ou scaffolding ou page automatique les contenus
  63. if (!$squelette){
  64. // si on est sur un ?page=XX non trouve
  65. if ($flux['args']['contexte'][_SPIP_PAGE] == $fond OR $flux['args']['contexte']['type'] == $fond) {
  66. // si c'est un objet spip, associe a une table, utiliser le fond homonyme
  67. if (z_scaffoldable($fond)){
  68. $flux['data'] = substr(find_in_path("objet.$ext"), 0, - strlen(".$ext"));
  69. }
  70. // sinon, brancher sur contenu/page-xx si elle existe
  71. // si on est sur un ?page=XX non trouve
  72. elseif ($flux['args']['contexte'][_SPIP_PAGE] == $fond) {
  73. $base = "$z_contenu/page-".$fond.".".$ext;
  74. if ($base = find_in_path($base)){
  75. $flux['data'] = substr(find_in_path("page.$ext"), 0, - strlen(".$ext"));
  76. }
  77. }
  78. }
  79. // scaffolding :
  80. // si c'est un fond de contenu d'un objet en base
  81. // generer un fond automatique a la volee pour les webmestres
  82. elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu)+1)==0
  83. AND include_spip('inc/autoriser')
  84. AND isset($GLOBALS['visiteur_session']['id_auteur']) // performance
  85. AND autoriser('webmestre')){
  86. $type = substr($fond,strlen($z_contenu)+1);
  87. if ($is = z_scaffoldable($type))
  88. $flux['data'] = z_scaffolding($type,$is[0],$is[1],$is[2],$ext);
  89. }
  90. // sinon, si on demande un fond non trouve dans un des autres blocs
  91. // et si il y a bien un contenu correspondant ou scaffoldable
  92. // se rabbatre sur le dist.html du bloc concerne
  93. else{
  94. if ( $dir = explode('/',$fond)
  95. AND $dir = reset($dir)
  96. AND $dir !== $z_contenu
  97. AND in_array($dir,$z_blocs)){
  98. $type = substr($fond,strlen("$dir/"));
  99. if (find_in_path("$z_contenu/$type.$ext") OR z_scaffoldable($type))
  100. $flux['data'] = substr(find_in_path("$dir/dist.$ext"), 0, - strlen(".$ext"));
  101. }
  102. }
  103. $squelette = $flux['data'];
  104. }
  105. if ($fond=='body' AND substr($squelette,-strlen($fond))==$fond){
  106. if (isset($flux['args']['contexte']['type'])
  107. AND (
  108. (isset($flux['args']['contexte']['composition'])
  109. AND file_exists(($f=$squelette."-".$flux['args']['contexte']['type']."-".$flux['args']['contexte']['composition']).".$ext"))
  110. OR
  111. file_exists(($f=$squelette."-".$flux['args']['contexte']['type']).".$ext")
  112. ))
  113. $flux['data'] = $f;
  114. }
  115. // chercher le fond correspondant a la composition
  116. elseif (isset($flux['args']['contexte']['composition'])
  117. AND substr($squelette,-strlen($fond))==$fond
  118. AND $dir = explode('/',$fond)
  119. AND $dir = reset($dir)
  120. AND in_array($dir,$z_blocs)
  121. AND $f=find_in_path($fond."-".$flux['args']['contexte']['composition'].".$ext")){
  122. $flux['data'] = substr($f,0,-strlen(".$ext"));
  123. }
  124. return $flux;
  125. }
  126. /**
  127. * Tester si un type est scaffoldable
  128. * cad si il correspond bien a un objet en base
  129. *
  130. * @staticvar array $scaffoldable
  131. * @param string $type
  132. * @return bool
  133. */
  134. function z_scaffoldable($type){
  135. static $scaffoldable = array();
  136. if (isset($scaffoldable[$type]))
  137. return $scaffoldable[$type];
  138. if (preg_match(',[^\w],',$type))
  139. return $scaffoldable[$type] = false;
  140. if ($table = table_objet($type)
  141. AND $type == objet_type($table)
  142. AND $trouver_table = charger_fonction('trouver_table','base')
  143. AND
  144. ($desc = $trouver_table($table)
  145. OR $desc = $trouver_table($table_sql = $GLOBALS['table_prefix']."_$table"))
  146. )
  147. return $scaffoldable[$type] = array($table,$desc['table'],$desc);
  148. else
  149. return $scaffoldable[$type] = false;
  150. }
  151. /**
  152. * Generer a la volee un fond a partir d'une table de contenu
  153. *
  154. * @param string $type
  155. * @param string $table
  156. * @param string $table_sql
  157. * @param array $desc
  158. * @param string $ext
  159. * @return string
  160. */
  161. function z_scaffolding($type,$table,$table_sql,$desc,$ext){
  162. include_spip('public/interfaces');
  163. $primary = id_table_objet($type);
  164. if (!$primary AND isset($desc['key']["PRIMARY KEY"])){
  165. $primary = $desc['key']["PRIMARY KEY"];
  166. }
  167. // reperer un titre
  168. $titre = 'titre';
  169. if (isset($GLOBALS['table_titre'][$table])){
  170. $titre = explode(' ',$GLOBALS['table_titre'][$table]);
  171. $titre = explode(',',reset($titre));
  172. $titre = reset($titre);
  173. }
  174. if (isset($desc['field'][$titre])){
  175. unset($desc['field'][$titre]);
  176. $titre="<h1 class='h1 #EDIT{titre}'>#".strtoupper($titre)."</h1>";
  177. }
  178. else $titre="";
  179. // reperer une date
  180. $date = "date";
  181. if (isset($GLOBALS['table_date'][$table]))
  182. $date = $GLOBALS['table_date'][$table];
  183. if (isset($desc['field'][$date])){
  184. unset($desc['field'][$date]);
  185. $date = strtoupper($date);
  186. $date="<p class='info-publi'>[(#$date|nom_jour) ][(#$date|affdate)][, <span class='auteurs'><:par_auteur:> (#LESAUTEURS)</span>]</p>";
  187. }
  188. else $date = "";
  189. $content = array();
  190. foreach($desc['field'] as $champ=>$z){
  191. if (!in_array($champ,array('maj','statut','idx',$primary))){
  192. $content[] = "[<div><strong>$champ</strong><div class='#EDIT{".$champ."} $champ'>(#".strtoupper($champ)."|image_reduire{500,0})</div></div>]";
  193. }
  194. }
  195. $content = implode("\n\t",$content);
  196. $scaffold = "#CACHE{0}
  197. <BOUCLE_contenu($table_sql){".$primary."}>
  198. [(#REM) Fil d'Ariane ]
  199. <p id='hierarchie'><a href='#URL_SITE_SPIP/'><:accueil_site:></a>[ &gt; <strong class='on'>(#TITRE|couper{80})</strong>]</p>
  200. <div class='contenu-principal'>
  201. <div class='cartouche'>
  202. $titre
  203. $date
  204. </div>
  205. $content
  206. </div>
  207. [<div class='notes surlignable'><h2 class='h2 pas_surlignable'><:info_notes:></h2>(#NOTES)</div>]
  208. </BOUCLE_contenu>";
  209. $dir = sous_repertoire(_DIR_CACHE,"scaffold",false);
  210. $dir = sous_repertoire($dir,"contenu",false);
  211. $f = $dir."$type";
  212. ecrire_fichier("$f.$ext",$scaffold);
  213. return $f;
  214. }
  215. /**
  216. * Surcharger les intertires avant que le core ne les utilise
  217. * pour y mettre la class h3
  218. * une seule fois suffit !
  219. *
  220. * @param string $flux
  221. * @return string
  222. */
  223. function Z_pre_propre($flux){
  224. static $init = false;
  225. if (!$init){
  226. $intertitre = $GLOBALS['debut_intertitre'];
  227. $class = extraire_attribut($GLOBALS['debut_intertitre'],'class');
  228. $class = ($class ? " $class":"");
  229. $GLOBALS['debut_intertitre'] = inserer_attribut($GLOBALS['debut_intertitre'], 'class', "h3$class");
  230. foreach($GLOBALS['spip_raccourcis_typo'] as $k=>$v){
  231. $GLOBALS['spip_raccourcis_typo'][$k] = str_replace($intertitre,$GLOBALS['debut_intertitre'],$GLOBALS['spip_raccourcis_typo'][$k]);
  232. }
  233. $init = true;
  234. }
  235. return $flux;
  236. }
  237. /**
  238. * Ajouter le inc-insert-head du theme si il existe
  239. *
  240. * @param string $flux
  241. * @return string
  242. */
  243. function Z_insert_head($flux){
  244. if (find_in_path('inc-insert-head.html')){
  245. $flux .= recuperer_fond('inc-insert-head',array());
  246. }
  247. return $flux;
  248. }
  249. //
  250. // fonction standard de calcul de la balise #INTRODUCTION
  251. // mais retourne toujours dans un <p> comme propre
  252. //
  253. // http://doc.spip.org/@filtre_introduction_dist
  254. function filtre_introduction($descriptif, $texte, $longueur, $connect) {
  255. include_spip('public/composer');
  256. $texte = filtre_introduction_dist($descriptif, $texte, $longueur, $connect);
  257. if ($GLOBALS['toujours_paragrapher'] AND strpos($texte,"</p>")===FALSE)
  258. // Fermer les paragraphes ; mais ne pas en creer si un seul
  259. $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']);
  260. return $texte;
  261. }
  262. /**
  263. * Tester la presence sur une page
  264. * @param <type> $p
  265. * @return <type>
  266. */
  267. function balise_SI_PAGE_dist($p) {
  268. $_page = interprete_argument_balise(1,$p);
  269. $p->code = "(((\$Pile[0][_SPIP_PAGE]==(\$zp=$_page)) OR (\$Pile[0]['composition']==\$zp AND \$Pile[0]['type']=='page'))?' ':'')";
  270. $p->interdire_scripts = false;
  271. return $p;
  272. }
  273. ?>