Blog du grouik - Mot-clé - template
Le blog du grouik. Memos d'un Admin sys linux windows, logiciels libres, imprimante 3D
2024-01-16T12:12:27+00:00
Gnieark
urn:md5:87c2396a7331cd5cd18f8751d216ec7b
Dotclear
Balises META description en double, sous dotclear
urn:md5:9855c9918f1996f9da0124d6975d6657
2011-01-08T18:53:00+01:00
2011-01-09T15:10:06+01:00
gnieark
dev web
dotclear
google
template
<p><strong>Note:</strong> Ce petit problème mineur (mon blog a très bien vécu pendant plus de deux ans comme ça) a été corrigé avec une grande réactivité par les mainteneurs de dotclear, il y a quelques mois. Il ne s’applique ni aux thèmes utilisant le template par défaut, ni aux thèmes récents. Mais il est encore présent dans une grande partie des thèmes proposés sur dotaddict.</p>
<p>Dans les outils pour les Webmasters de google, il me signale qu'il existe des balises META description en double sur ce blog:
Exactement la même description sur différentes pages.</p>
<p><img src="https://blog-du-grouik.tinad.fr/public/.webmastertoolsmeta_m.jpg" alt="webmastertoolsmeta.jpg" style="display:block; margin:0 auto;" title="webmastertoolsmeta.jpg, janv. 2011" /></p>
<p>Il s'agit en fait des pages d'accueil,:</p>
<ul>
<li>index.php</li>
<li>index.php?/page/2</li>
<li>index.php?/page/3</li>
<li>etc...</li>
</ul>
<p>Sur la page d'accueil ou lorsque on passe aux billets précédents, la description du site (rédigée dans le tableau de bord de dotclear) sert à toutes les pages. Tandis que sur un billet à proprement parler, c'est un extrait de ce dernier qui sert à la description<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2011/01/08/Balises-META-description-en-double%2C-sous-dotclear#pnote-791-1" id="rev-pnote-791-1">1</a>]</sup>.</p>
<p>Si Google dit que c'est mal d'avoir des balises méta en double c'est sûrement que c'est vrai. Je me prosterne.</p>
<p>Pour avoir des descriptions légèrement différentes, le plus simple est d'y ajouter le numéro de la page.
Le code dans le template qui va ajouter <em>Page x</em> sauf sur la première page (autant ne pas allourdir la description de la homepage) est le suivant:</p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:PaginationIf</span> <span style="color: #000066;">start</span>=<span style="color: #ff0000;">"0"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:lang page}} {{tpl:PaginationCurrent}} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:PaginationIf<span style="color: #000000; font-weight: bold;">></span></span></span></div></li></ol></pre>
<h3>Pour éliminer les métas en double.</h3>
<p>Dans le fichier home.html du template, remplacer:</p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><meta</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"description"</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">"{{tpl:BlogLanguage}}"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"{{tpl:BlogDescription cut_string="</span>180<span style="color: #ff0000;">" encode_html="</span>1<span style="color: #ff0000;">"}}"</span> <span style="color: #000000; font-weight: bold;">/></span></span></div></li></ol></pre>
<p>par:</p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><meta</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"description"</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">"{{tpl:BlogLanguage}}"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"<tpl:PaginationIf start="</span>0<span style="color: #ff0000;">"></span></span>{{tpl:lang page}} {{tpl:PaginationCurrent}} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:PaginationIf<span style="color: #000000; font-weight: bold;">></span></span></span>{{tpl:BlogDescription cut_string="180" encode_html="1"}}" /></div></li></ol></pre>
<p>Remplacez aussi:</p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><meta</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"dc.description"</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">"{{tpl:BlogLanguage}}"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"{{tpl:BlogDescription encode_html="</span>1<span style="color: #ff0000;">"}}"</span> <span style="color: #000000; font-weight: bold;">/></span></span></div></li></ol></pre>
<p>Par</p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><meta</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"dc.description"</span> <span style="color: #000066;">lang</span>=<span style="color: #ff0000;">"{{tpl:BlogLanguage}}"</span> <span style="color: #000066;">content</span>=<span style="color: #ff0000;">"<tpl:PaginationIf start="</span>0<span style="color: #ff0000;">"></span></span>{{tpl:lang page}} {{tpl:PaginationCurrent}} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:PaginationIf<span style="color: #000000; font-weight: bold;">></span></span></span> {{tpl:BlogDescription encode_html="1"}}" /></div></li></ol></pre>
<div class="footnotes"><h4>Notes</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2011/01/08/Balises-META-description-en-double%2C-sous-dotclear#rev-pnote-791-1" id="pnote-791-1">1</a>] C'est une généralité, mais c'est géré au niveau du template ça, ça dépend de ce dernier</p></div>
Faites F5!
urn:md5:c2ccb4320f6bd3998ba520027fdfe8a8
2011-01-05T04:38:00+01:00
2011-01-05T05:00:49+01:00
gnieark
dev web
dotclear
template
<p><img src="https://blog-du-grouik.tinad.fr/public/.gedit-template_m.jpg" alt="gedit-template.jpg" style="display:block; margin:0 auto;" title="gedit-template.jpg, janv. 2011" />
Ah vous pouvez faire F5 pour recharger les images et le CSS de ce site.!</p>
<p>C'est un billet qui revient à rythme assez régulier. Enfin à chaque fois qu'il me prend l'envie de chambouler un peu la présentation du blog.</p>
<p>En nouveautés: il y a une troisième colonne.</p>
<p>La modification de la largeur de la colonne des billets a pour conséquence de faire que les miniatures des images qui étaient dimensionnées pile poil ne le sont plus. La technique pour toutes les régénérer (avec les nouvelles largeurs définies dans les préférences du blog) sans trop en baver est décrite par <a href="http://forum.dotclear.net/viewtopic.php?pid=261252#p261252" hreflang="fr">erational dans le forum de dotclear</a>.</p>
<h3>Sur la page d’accueil</h3>
<p>La colonne du milieu affiche les billets de la catégorie "brèves". C'est ça la nouveauté. Sans non plus tomber dans du twittage, je souhaitais pouvoir écrire des trucs courts sans avoir l'impression de flooder.</p>
<p>Techniquement dans le template pour n'afficher qu'une catégorie, on fait comme ça:</p>
<pre class="xml xml" style="font-family:inherit"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tpl:Entries</span> <span style="color: #000066;">category</span>=<span style="color: #ff0000;">"breves"</span> <span style="color: #000066;">lastn</span>=<span style="color: #ff0000;">"15"</span> <span style="color: #000066;">ignore_pagination</span>=<span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">...intérieur d'un post</div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tpl:Entries<span style="color: #000000; font-weight: bold;">></span></span></span></div></li></ol></pre>
<p>ignore_pagination="1" permet de ne pas prendre en compte que l'utilisateur soit à la Xème page</p>
<p>La documentation est là: <a href="http://fr.dotclear.org/documentation/2.0/resources/themes/tags/entries" hreflang="fr">http://fr.dotclear.org/documentation/2.0/resources/themes/tags/entries</a></p>
<h3>Sur un billet (post.html dans le template)</h3>
<p>La colonne du milieu affiche un aperçu des billets de la même catégorie, à l'exclusion de de celui en cours. (Logique).
J'avais presque réussi, il ne me manquait plus que l'exclusion du billet à mettre en place, lorsque je suis tombé sur ce <a href="http://tips.dotaddict.org/fiche/Afficher-les-billets-de-la-m%C3%AAme-cat%C3%A9gorie-que-le-billet-courant-en-excluant-celui-ci-de-la-liste" hreflang="fr">tips and sheats</a> de dotclear qui expliquait toute la manip à faire.</p>
<h3>Pages tags et catégories.</h3>
<p>J'y affiche (dans la colonne du milieu la liste des billets au complet).</p>
<h3>Pour finir</h3>
<p>Bah quelques fignolages qui restent à faire et quelques brèves à écrire pour remplir la colonne du milieu.
J'espère que ça rendra mon blog plus fonctionnel; et peut être augmenter le nombre de pages vues par visite. Ah et oui, faut qu' j'aille redimensionner les trucs inclus un peu à l’arraché dans les billets.</p>
Exclure des articles de la page d'accueil sous wordpress
urn:md5:b2ff95e40d9902e218578dfb06e8deb0
2010-09-01T10:07:00+02:00
2010-09-08T22:54:34+02:00
gnieark
dev web
template
wordpress
<p><img src="https://blog-du-grouik.tinad.fr/public/logo/wordpress-logo-stacked-rgb.png" alt="wordpress-logo-stacked-rgb.png" style="float: left; margin: 0 1em 1em 0;" title="wordpress-logo-stacked-rgb.png, août 2010" />
Ce blog est dotclear, mais bon, ça ne m'empèche pas de devoir attaquer du wordpress de temps en temps. Le but ici est d'exclure de la page principale d'un blog des articles. Le plus simple est de le faire au niveau du template.</p>
<p style="text-decoration:line-through;">Dans l'éditeur:</p>
<p style="text-decoration:line-through;">Ouvrir le fichier index.php nommé "modèle pour la page d'accueil", vous trouverez rapidement une ligne dans ce genre:</p>
<pre style="text-decoration:line-through;"><?php if (have_posts()) : ?></pre>
<p style="text-decoration:line-through;">Juste avant on ajoute les conditions pour exclure certains articles.
Ceux de la catégorie 208 dans l'exemple.
je rajoute la ligne</p>
<pre style="text-decoration:line-through;"><?php query_posts('cat=-208'); ?> </pre>
<p style="text-decoration:line-through;">Pour exclure le post 486:</p>
<pre style="text-decoration:line-through;"><?php query_posts('p=-486'); ?></pre></del>
<p>Hum désolé.</p>
<p>comme ça c'est mieux:</p>
<p>apres:</p>
<code><?php while (have_posts()) : the_post(); ?></code><br />Insérer:<br /><code><?php if (in_category('208') && is_home() ) continue; ?></code><br />(...)<br /><br />pour exclure les articles de la catégorie 208<br /><br />La solution à présent rayée présentait l'inconvéniant de bloquer la passage à une autre page du blog. La solution non rayée présente un inconvéniant mineur. C'est que si l'index est censée accueillir x articles et que dans le tas il y a n articles de la catégorie à exclure, l'index ne présentera que x-n articles.<br />
<p>Enfin pour connaitre le numéro d'une catégorie, le plus simple est de regarder dans la base de données. Les catégories sont enregistrées dans la table term_taxonomy.
Sinon il y a un plugin qui permet d'afficher les catégories dans une liste déroulante. L'affichage du code source du blog avec ce plugin vous donnera le numéro recherché. (value)</p>
<pre class="html"><span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><select</span> <span style="color: rgb(0, 0, 102);">name</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"cat"</span> <span style="color: rgb(0, 0, 102);">id</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"cat"</span> <span style="color: rgb(0, 0, 102);">class</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"postform"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">></span></span><br /> <span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><option</span> <span style="color: rgb(0, 0, 102);">value</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"-1"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">></span></span>Choisir une catégorie<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"></option></span></span><br /> <span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><option</span> <span style="color: rgb(0, 0, 102);">class</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"level-0"</span> <span style="color: rgb(0, 0, 102);">value</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"208"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">></span></span>NOM DE LA CATEGORIE<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"></option></span></span><br /><span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"></select></span></span></pre>
<p>Voici <a href="http://www.fran6art.com/webdesign/wordpress-query_posts-la-requete-a-tout-faire/" hreflang="fr">un lien chez Fran6art</a> qui résume bien la manip.</p>
<br />
Ça ne me convient pas
urn:md5:4def1dad2c8d5c837b1c388ea6acf28f
2010-08-28T14:32:00+02:00
2010-08-29T03:20:16+02:00
gnieark
Vie (ou non) du site
template
<img src="http://www.tinaderp.com/travaux.jpg" alt="site en développement"/>
<p>J'ai un peu de temps pour continuer ma recherche vers le thème parfait :p</p>
<p>Bref aujourd'hui, si l'affichage saute ou autre, c'est parce que je ne fais pas les modifications en local mais direct sur le serveur :p</p>
PDF sur une page WEB, conversion auto en swf
urn:md5:ef16979fb559daa86467f56675ba8c2e
2010-08-15T22:43:00+02:00
2010-08-15T22:43:00+02:00
gnieark
dev web
batch
flash
pdf
PHP
serveur
template
<p>Dans la Gestion électronique de documents de mon intranet. j'affiche les documents en PDF sur la page web.
J'utilise la balise HTML objet. comme ceci</p>
<pre class="html"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"height: 600px; width: 800px;"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><object</span> <span style="color: #000066;">data</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"fichiers.php?filename=PRC-SOI-001.pdf"</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/html"</span> <span style="color: #000066;">codetype</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"application/pdf"</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"height: 600px; width: 800px;"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></object></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span></pre>
<p>C'est moche mais ça marche bien sur tous les windows (que le navigateur soit internet explorer ou firefox) tant que Adobe reader est installé. Au travail, ça marche bien sur tous les postes sauf le mien buhaaaa (linux). C'est assez frustrant d'avoir développé un truc (tout l'intranet) et de ne pas pouvoir l'utiliser.</p>
<p>Il y a d'autres solutions plus simples, mais qui font passer les documents par un service tiers. je souhaite assurer une certaine confidentialité de ces derniers.</p>
<p>Ce tutoriel/mémo va donc aborder l'installation un convertisseur pdf2swf sur le serveur, puis un "exec()" en php pour les convertir des leur upload.
Enfin, on verra vite fait l'utilisation de FlexPaperViewer pour les visionner sur une page web.</p>
<h2>Les prérequis</h2>
<ul>
<li>Avoir la main sur le serveur. Un hébergement mutualisé ne suffira pas car on va devoir installer des paquets. A moins que l'hébergeur soit sympa. <a href="https://blog-du-grouik.tinad.fr/post/2010/08/15/index.php?contact" hreflang="fr">Me contacter</a> pour un devis.</li>
<li>J'utilise une debian 5 sur le serveur de production, avec apache2 mysql, php5. Cependant les premiers essais, je les ai fait sur une fedora, ça marchera aussi très bien là dessus.</li>
</ul>
<h2>Installation de swftools à partir des sources</h2>
<p>swftools contient les outils pour convertir un pdf en swf en ligne de commande.</p>
<p>En root sur le serveur, télécharger, extraire, compiler. la dernière version de swftools (à la date d'écriture de ce billet c'est la 0.9.1)</p>
<h4>Télécharger et extraire</h4>
<pre class="bash"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.swftools.org<span style="color: #000000; font-weight: bold;">/</span>swftools<span style="color: #000000;">-0.9</span><span style="color: #000000;">.1</span>.<span style="color: #c20cb9; font-weight: bold;">tar</span>.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> -zxvf swftools<span style="color: #000000;">-0.9</span><span style="color: #000000;">.1</span>.<span style="color: #c20cb9; font-weight: bold;">tar</span>.gz
<span style="color: #c20cb9; font-weight: bold;">rm</span> swftools<span style="color: #000000;">-0.9</span><span style="color: #000000;">.1</span>.<span style="color: #c20cb9; font-weight: bold;">tar</span>.gz</pre>
<h4>Préparer la compilation</h4>
<pre class="bash"><span style="color: #7a0874; font-weight: bold;">cd</span> swftools<span style="color: #000000;">-0.9</span><span style="color: #000000;">.1</span><span style="color: #000000; font-weight: bold;">/</span>
.<span style="color: #000000; font-weight: bold;">/</span>configure</pre>
<p>Dans les retours du script configure, il faut vérifier que ça c'est bien passé. Dans mon cas il me prévient qu'il manque des dépendances:</p>
<pre>
***************************************************
* The following headers/libraries are missing: jpeglib ungif jpeglib.h freetype gif_lib.h
* Disabling pdf2swf tool...
* Disabling jpeg2swf tool...
* Disabling gif2swf tool...
***************************************************
</pre>
<p>et du coup il désactive justement le truc qui m'intéressait</p>
<p>Installer les dépendances manquantes (adaptez en fonction du retour de ./configure) Dans mon cas:</p>
<pre class="bash">apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> libjpeg62-dev
apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> libgif-dev
apt-get <span style="color: #c20cb9; font-weight: bold;">install</span> libfreetype6-dev</pre>
<p>et réexutez le ./configure</p>
<pre class="bash">.<span style="color: #000000; font-weight: bold;">/</span>configure</pre>
<h4>Compiler:</h4>
<pre class="bash"><span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre>
<h4>tester pdf2wfs</h4>
<p>la conversion du fichier "fichier.pdf" en swf "fichier.swf" se fait pas la ligne de commande suivante:</p>
<pre class="bash">pdf2swf fichier.pdf -o fichier.swf</pre>
<p>Vous pouvez le tester en déposant le fichier sur un site web.</p>
<p>On sait donc à présent convertir un pdf en swf. Je vais me refaire du café avant d'attaquer la modification de mon script d'upload. Au passage, le script bash pour appliquer ce traitement à tous les pdf d'un repertoire:</p>
<pre class="bash"><span style="color: #808080; font-style: italic;">#!/bin/bash</span>
<span style="color: #808080; font-style: italic;"># </span>
<span style="color: #000000; font-weight: bold;">for</span> element <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*</span>
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">[</span> <span style="color: #ff0000;">"${element##*.}"</span> = <span style="color: #ff0000;">"pdf"</span> <span style="color: #7a0874; font-weight: bold;">]</span>
<span style="color: #000000; font-weight: bold;">then</span>
pdf2swf <span style="color: #007800;">$element</span> -o $<span style="color: #7a0874; font-weight: bold;">{</span>element<span style="color: #000000; font-weight: bold;">%</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">}</span>.swf
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span></pre>
<h2>Modification du script d'upload en php<sup>[<a href="https://blog-du-grouik.tinad.fr/post/2010/08/15/PDF-sur-une-page-WEB-moulinette-pour-transformer-en-swf#pnote-632-1" id="rev-pnote-632-1">1</a>]</sup></h2>
<p>J'ajoute simplement la commande suivante à la fin pour que le script execute pdf2swf:</p>
<pre class="php"><span style="color: #000066;">exec</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'pdf2swf '</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$content_dir</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$name_file</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">' -o '</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$content_dir</span><span style="color: #66cc66;">.</span><span style="color: #000066;">basename</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$content_dir</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$name_file</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'.pdf'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">'.swf'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span></pre>
<p>Ci dessous un exemple vite fait (que j'ai quand même pris le temps de valider au w3c validator). Cliquez sur le bouton pour le voir, je ne souhaitais pas alourdir ce billet <sup>[<a href="https://blog-du-grouik.tinad.fr/post/2010/08/15/PDF-sur-une-page-WEB-moulinette-pour-transformer-en-swf#pnote-632-2" id="rev-pnote-632-2">2</a>]</sup> Sur l'intranet, il y a bien évidemment les vérifications comme qui l'utilisateur est identifié et a bien les droits.</p>
<div class="smallfont" style="margin-bottom: 2px;"><input value="Voir" style="width: 45px; font-size: 10px; margin: 0px; padding: 0px;" onclick="if (document.getElementById('divtohide').style.display != '') {
document.getElementById('divtohide').style.display = '';this.innerText = ''; this.value = 'Cacher'; } else {document.getElementById('divtohide').style.display = 'none'; this.innerText = ''; this.value = 'Voir'; }" type="button"><b> l'exemple complet :</b> </div>
<div id="divtohide" style="display: none;">
<p>Vite fait un exemple (que j'ai quand même pris le temps de valider au w3c validator). Sur l'intranet, il y a bien évidemment les vérifications comme qui l'utilisateur est identifié et a bien les droits.
Le formulaire html basique</p>
<pre class="html"><span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><</span>!doctype html></span>
<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><head></span></span>
<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><meta</span> <span style="color: rgb(0, 0, 102);">http-equiv</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"Content-Type"</span> <span style="color: rgb(0, 0, 102);">content</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"text/html; charset=UTF-8"</span> <span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">></span></span>
<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><title></span></span>Test d'upload<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"></title></span></span>
<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"></head></span></span>
<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><body></span></span>
<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><form</span> <span style="color: rgb(0, 0, 102);">method</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"post"</span> <span style="color: rgb(0, 0, 102);">action</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"testupload.php"</span> <span style="color: rgb(0, 0, 102);">enctype</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"multipart/form-data"</span><span style="color: rgb(0, 0, 0); font-weight: bold;">></span></span>
<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><input</span> <span style="color: rgb(0, 0, 102);">name</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"file"</span> <span style="color: rgb(0, 0, 102);">type</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"file"</span><span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">></span></span><span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"><input</span> <span style="color: rgb(0, 0, 102);">type</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"submit"</span> <span style="color: rgb(0, 0, 102);">value</span><span style="color: rgb(102, 204, 102);">=</span><span style="color: rgb(255, 0, 0);">"uploader"</span> <span style="color: rgb(102, 204, 102);">/</span><span style="color: rgb(0, 0, 0); font-weight: bold;">></span></span>
<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"></form></span></span>
<span style="color: rgb(0, 153, 0);"><span style="color: rgb(0, 0, 0); font-weight: bold;"></body></span></span></pre>
<p>Le fichier testupload.php qui est appelé lors de la validation du formulaire.</p>
<pre class="php"><span style="color: rgb(0, 0, 0); font-weight: bold;"><?php</span>
<span style="color: rgb(128, 128, 128); font-style: italic;">//name="fichieroriginal</span>
<span style="color: rgb(255, 0, 0);">$content_dir</span> <span style="color: rgb(102, 204, 102);">=</span> <span style="color: rgb(255, 0, 0);">$_SERVER</span><span style="color: rgb(102, 204, 102);">[</span><span style="color: rgb(255, 0, 0);">"DOCUMENT_ROOT"</span><span style="color: rgb(102, 204, 102);">]</span><span style="color: rgb(102, 204, 102);">.</span><span style="color: rgb(255, 0, 0);">"/documents/"</span><span style="color: rgb(102, 204, 102);">;</span> <span style="color: rgb(128, 128, 128); font-style: italic;">// dossier où sera déplacé le fichier</span>
<span style="color: rgb(255, 0, 0);">$tmp_file</span> <span style="color: rgb(102, 204, 102);">=</span> <span style="color: rgb(255, 0, 0);">$_FILES</span><span style="color: rgb(102, 204, 102);">[</span><span style="color: rgb(255, 0, 0);">'file'</span><span style="color: rgb(102, 204, 102);">]</span><span style="color: rgb(102, 204, 102);">[</span><span style="color: rgb(255, 0, 0);">'tmp_name'</span><span style="color: rgb(102, 204, 102);">]</span><span style="color: rgb(102, 204, 102);">;</span> <span style="color: rgb(128, 128, 128); font-style: italic;">//le nom du fichier temporaire qui vient d'etre uploadé (il sera supprimé automatiquement à la fin du script)</span>
<span style="color: rgb(177, 177, 0);">if</span><span style="color: rgb(102, 204, 102);">(</span> <span style="color: rgb(102, 204, 102);">!</span><span style="color: rgb(0, 0, 102);">is_uploaded_file</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">$tmp_file</span><span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(102, 204, 102);">)</span>
<span style="color: rgb(102, 204, 102);">{</span>
<span style="color: rgb(0, 0, 102);">echo</span> <span style="color: rgb(255, 0, 0);">"Le fichier est introuvable"</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(0, 0, 102);">die</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(102, 204, 102);">}</span>
<span style="color: rgb(128, 128, 128); font-style: italic;">// on vérifie maintenant l'extension</span>
<span style="color: rgb(255, 0, 0);">$type_file</span> <span style="color: rgb(102, 204, 102);">=</span> <span style="color: rgb(255, 0, 0);">$_FILES</span><span style="color: rgb(102, 204, 102);">[</span><span style="color: rgb(255, 0, 0);">'file'</span><span style="color: rgb(102, 204, 102);">]</span><span style="color: rgb(102, 204, 102);">[</span><span style="color: rgb(255, 0, 0);">'type'</span><span style="color: rgb(102, 204, 102);">]</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(177, 177, 0);">if</span><span style="color: rgb(102, 204, 102);">(</span> <span style="color: rgb(102, 204, 102);">!</span><span style="color: rgb(0, 0, 102);">strstr</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">$type_file</span><span style="color: rgb(102, 204, 102);">,</span> <span style="color: rgb(255, 0, 0);">'pdf'</span><span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(102, 204, 102);">&&</span> <span style="color: rgb(102, 204, 102);">!</span><span style="color: rgb(0, 0, 102);">strstr</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">$type_file</span><span style="color: rgb(102, 204, 102);">,</span> <span style="color: rgb(255, 0, 0);">'PDF'</span><span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(102, 204, 102);">)</span>
<span style="color: rgb(102, 204, 102);">{</span>
<span style="color: rgb(0, 0, 102);">exit</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">"Le fichier n'est pas un PDF"</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(102, 204, 102);">}</span>
<span style="color: rgb(128, 128, 128); font-style: italic;">// on copie le fichier dans le dossier de destination</span>
<span style="color: rgb(255, 0, 0);">$name_file</span> <span style="color: rgb(102, 204, 102);">=</span> <span style="color: rgb(255, 0, 0);">$_FILES</span><span style="color: rgb(102, 204, 102);">[</span><span style="color: rgb(255, 0, 0);">'file'</span><span style="color: rgb(102, 204, 102);">]</span><span style="color: rgb(102, 204, 102);">[</span><span style="color: rgb(255, 0, 0);">'name'</span><span style="color: rgb(102, 204, 102);">]</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(177, 177, 0);">if</span><span style="color: rgb(102, 204, 102);">(</span> <span style="color: rgb(102, 204, 102);">!</span><span style="color: rgb(0, 0, 102);">move_uploaded_file</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">$tmp_file</span><span style="color: rgb(102, 204, 102);">,</span> <span style="color: rgb(255, 0, 0);">$content_dir</span> <span style="color: rgb(102, 204, 102);">.</span> <span style="color: rgb(255, 0, 0);">$name_file</span><span style="color: rgb(102, 204, 102);">)</span> <span style="color: rgb(102, 204, 102);">)</span>
<span style="color: rgb(102, 204, 102);">{</span>
<span style="color: rgb(0, 0, 102);">exit</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">"Impossible de copier le fichier dans $content_dir"</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(102, 204, 102);">}</span>
<span style="color: rgb(0, 0, 102);">exec</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">'pdf2swf '</span><span style="color: rgb(102, 204, 102);">.</span><span style="color: rgb(255, 0, 0);">$content_dir</span><span style="color: rgb(102, 204, 102);">.</span><span style="color: rgb(255, 0, 0);">$name_file</span><span style="color: rgb(102, 204, 102);">.</span><span style="color: rgb(255, 0, 0);">' -o '</span><span style="color: rgb(102, 204, 102);">.</span><span style="color: rgb(255, 0, 0);">$content_dir</span><span style="color: rgb(102, 204, 102);">.</span><span style="color: rgb(0, 0, 102);">basename</span><span style="color: rgb(102, 204, 102);">(</span><span style="color: rgb(255, 0, 0);">$content_dir</span><span style="color: rgb(102, 204, 102);">.</span><span style="color: rgb(255, 0, 0);">$name_file</span><span style="color: rgb(102, 204, 102);">,</span> <span style="color: rgb(255, 0, 0);">'.pdf'</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">.</span><span style="color: rgb(255, 0, 0);">'.swf'</span><span style="color: rgb(102, 204, 102);">)</span><span style="color: rgb(102, 204, 102);">;</span>
<span style="color: rgb(0, 0, 0); font-weight: bold;">?></span></pre>
</div>
<p>Maintenant nos fichier sont tansformés lors de l'upload. Plus qu'à installer la visionneuse.</p>
<h2>Integration de FlexPaperviewer dans une page html</h2>
<ul>
<li>Telechargez FlexPaperviewer <a href="http://flexpaper.devaldi.com/" hreflang="fr">http://flexpaper.devaldi.com/</a></li>
<li>Et poussez tous les fichiers sur la racine de votre site.</li>
</ul>
<p>Dans la page ou vous voulez visionner un document, débrouillez vous :p pour que le header (entre <head> et </head>) contienne:</p>
<pre class="html"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><style</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/css"</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"screen"</span><span style="color: #000000; font-weight: bold;">></span></span>
#flashContent { display:none; }
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></style></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/javascript"</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"js/swfobject/swfobject.js"</span><span style="color: #000000; font-weight: bold;">></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></script></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/javascript"</span><span style="color: #000000; font-weight: bold;">></span></span>
if(window.addEventListener)
window.addEventListener('DOMMouseScroll', handleWheel, false);
window.onmousewheel = document.onmousewheel = handleWheel;
if (window.attachEvent)
window.attachEvent("onmousewheel", handleWheel);
function handleWheel(event){
try{
if(!window.document.FlexPaperViewer.hasFocus()){return true;}
window.document.FlexPaperViewer.setViewerFocus(true);
window.document.FlexPaperViewer.focus();
if(navigator.appName == "Netscape"){
if (event.detail)
delta = 0;
if (event.preventDefault){
event.preventDefault();
event.returnValue = false;
}
}
return false;
}catch(err){return true;}
}
function onExternalLinkClicked(link){
window.location.href = link;
}
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></script></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/javascript"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- For version detection, set to min. required Flash Player version, or 0 (or 0.0.0), for no version detection. --></span></span>
var swfVersionStr = "9.0.124";
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- To use express install, set to playerProductInstall.swf, otherwise the empty string. --></span></span>
var xiSwfUrlStr = "${expressInstallSwf}";
var flashvars = {
SwfFile : escape("http://www.tinaderp.com/tinaderp/fichiers.php?filename=CRA-BLA-003.swf"),
Scale : 0.6,
ZoomTransition : "easeOut",
ZoomTime : 0.5,
ZoomInterval : 0.1,
FitPageOnLoad : false,
FitWidthOnLoad : true,
PrintEnabled : true,
FullScreenAsMaxWindow : false,
ProgressiveLoading : true,
localeChain: "fr_FR"
};
var params = {
}
params.quality = "high";
params.bgcolor = "#ffffff";
params.allowscriptaccess = "sameDomain";
params.allowfullscreen = "true";
var attributes = {};
attributes.id = "FlexPaperViewer";
attributes.name = "FlexPaperViewer";
swfobject.embedSWF(
"FlexPaperViewer.swf", "flashContent",
"100%", "600",
swfVersionStr, xiSwfUrlStr,
flashvars, params, attributes);
swfobject.createCSS("#flashContent", "display:block;text-align:left;");
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></script></span></span></pre>
<p>Et oui c'est dans le header qu'on définit le fichier qui sera visualisé. ça oblige de le générer en php pour pourvoir adapter la variable SwfFile : escape("votre fichier"),</p>
<p>Ensuite pour le placer sur la page, dans le body:</p>
<pre class="html"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"flashContent"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p></span></span>
To view this page ensure that Adobe Flash Player version
9.0.124 or greater is installed.
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></p></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/javascript"</span><span style="color: #000000; font-weight: bold;">></span></span>
var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
document.write("<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'http://www.adobe.com/go/getflashplayer'</span><span style="color: #000000; font-weight: bold;">></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'"
+ pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif'</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'Get Adobe Flash player'</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></a></span></span>" );
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></script></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span></pre>
<p>Comme indiqué dans le fichier d'exemple de FlexPaperviewer</p>
<p>Un screen soot du bouzin sur tinaderp (qui avance)
<a href="https://blog-du-grouik.tinad.fr/public/tinaderpgestdoc.jpg" title="tinaderpgestdoc.jpg"><img src="https://blog-du-grouik.tinad.fr/public/.tinaderpgestdoc_m.jpg" alt="tinaderpgestdoc.jpg" style="display:block; margin:0 auto;" title="tinaderpgestdoc.jpg, août 2010" /></a></p>
<div class="footnotes"><h4>Notes</h4>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2010/08/15/PDF-sur-une-page-WEB-moulinette-pour-transformer-en-swf#rev-pnote-632-1" id="pnote-632-1">1</a>] source: <a href="http://phpcodeur.net/articles/php/upload" hreflang="fr">php-codeur Upload de fichiers</a></p>
<p>[<a href="https://blog-du-grouik.tinad.fr/post/2010/08/15/PDF-sur-une-page-WEB-moulinette-pour-transformer-en-swf#rev-pnote-632-2" id="pnote-632-2">2</a>] Je progresse en javascript hein?</p></div>
Fin de la modification du template
urn:md5:bd6f343fe31893045aa72aeeea74d01f
2010-08-08T01:23:00+02:00
2010-08-08T00:26:11+02:00
gnieark
Vie (ou non) du site
template
<p>La modif du template est finie (pour le moment)</p>
<p>Zut, c'est presque trop bien, je me suis même créé une palette de couleurs presque cohérente, ça manque de charme à présent.</p>
<p>Finalement, J'ai trouvé un screen de mon blog juste avant:
<a href="https://blog-du-grouik.tinad.fr/public/blogdegrouik8-8-10.jpg" title="blogdegrouik8-8-10.jpg"><img src="https://blog-du-grouik.tinad.fr/public/.blogdegrouik8-8-10_m.jpg" alt="blogdegrouik8-8-10.jpg" style="display:block; margin:0 auto;" title="blogdegrouik8-8-10.jpg, août 2010" /></a></p>
Modification du thème du blog.
urn:md5:b6f79a2d556804db1d8a8cf1c6858bef
2010-08-07T21:35:00+02:00
2010-08-07T21:35:00+02:00
gnieark
Vie (ou non) du site
template
<p>Je précise que j'ai volontairement rajouté du bordel avant de faire la photo qui m'a servie de base au header.</p>
<p>Arf, comme d'habitude j'ai oublié oublié de faire une impression d'écran avant de commencer les modifications..</p>
Avant quand je n'avais pas de blog,
urn:md5:f31d718d827912faf3c6353053837a8e
2010-06-27T17:27:00+02:00
2010-06-27T16:30:58+02:00
gnieark
Vie (ou non) du site
dotclear
template
<p>Avant quand je n'avais pas de blog, les petits pétages de plomb "je sature" concernaient mon appart. Je déplaçais les meubles à la recherche d'une disposition encore mieux (parfois à 2 heures du matin). Mais à Force de faire ça tous les 3 mois, j'ai trouvé la disposition optimisée de mon intérieur.</p>
<p>C'est pour ça que pour le bonheur des oreilles de mes voisins, depuis presque deux ans, je tiens ce blog,sur lequel je peux m’amuser à tout chambouler sans me péter le dos.
Un petit tour dans les CSS, dans les templates, sur gimp... Dotclear est sympa (comparé à wp ou joomla) pour aller bidouiller dedans.</p>
<p>Là ça devient pas mal.</p>
le template dans une variable string et pas en echo
urn:md5:d16be9ab6fc4fe39fddc0902ffca09da
2010-05-06T19:58:00+02:00
2010-05-06T19:34:06+02:00
gnieark
dev web
PHP
template
<p>Pour placer les choses, j'utilise encore le moteur de template de phpBB1 (enfin, je crois, celui qui a été fait en 2001), comme indiqué dans<a href="http://phpcodeur.net/articles/php/templates" hreflang="fr">ce tutoriel</a>.</p>
<p>la fonction pparse de la classe template imprime (affiche sur la page web) le résultat de la génération d'un template. j'avais besoin de générer un template mais pas de l'afficher, de l'envoyer dans une variable de type string (pour préparer un mail en fait).</p>
<p>Tout est prévu dans la fonction compile. Encore faut-il l'utiliser.</p>
<p>je me suis donc écrit la function pstring qui est une pale copie de la function pparse.</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">function</span> pstring<span style="color: #66cc66;">(</span><span style="color: #ff0000">$handle</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
<span style="color: #ff0000">$plop</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">""</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #66cc66;">!</span><span style="color: #ff0000">$this</span><span style="color: #66cc66;">-></span><span style="color: #006600;">loadfile</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$handle</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
<span style="color: #000066;">die</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Template->pparse(): Impossible de charger le fichier template pour le modèle $handle"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span>
<span style="color: #808080; font-style: italic;">// actually compile the template now.</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #66cc66;">!</span><span style="color: #000066;">isset</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$this</span><span style="color: #66cc66;">-></span><span style="color: #006600;">compiled_code</span><span style="color: #66cc66;">[</span><span style="color: #ff0000">$handle</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">||</span> <span style="color: #000066;">empty</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$this</span><span style="color: #66cc66;">-></span><span style="color: #006600;">compiled_code</span><span style="color: #66cc66;">[</span><span style="color: #ff0000">$handle</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
<span style="color: #808080; font-style: italic;">// Actually compile the code now.</span>
<span style="color: #ff0000">$this</span><span style="color: #66cc66;">-></span><span style="color: #006600;">compiled_code</span><span style="color: #66cc66;">[</span><span style="color: #ff0000">$handle</span><span style="color: #66cc66;">]</span> <span style="color: #66cc66;">=</span> <span style="color: #ff0000">$this</span><span style="color: #66cc66;">-></span><span style="color: #006600;">compile</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$this</span><span style="color: #66cc66;">-></span><span style="color: #006600;">uncompiled_code</span><span style="color: #66cc66;">[</span><span style="color: #ff0000">$handle</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">,</span><span style="color: #000000; font-weight: bold;">true</span><span style="color: #66cc66;">,</span><span style="color: #ff0000;">'plop'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span>
<span style="color: #808080; font-style: italic;">// Run the compiled code.</span>
<span style="color: #808080; font-style: italic;">//eval($this->compiled_code[$handle]);</span>
<span style="color: #000066;">eval</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$this</span><span style="color: #66cc66;">-></span><span style="color: #006600;">compiled_code</span><span style="color: #66cc66;">[</span><span style="color: #ff0000">$handle</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #ff0000">$plop</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span></pre>
<p>Je l'utilise presque de la même façon que pparse aussi.</p>
<pre class="php"><span style="color: #000000; font-weight: bold;"><?php</span>
<span style="color: #b1b100;">include</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'template.php'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">// on créé une nouvelle instance de la classe Template</span>
<span style="color: #808080; font-style: italic;">// et on indique en argument le chemin vers les modèles</span>
<span style="color: #ff0000">$template</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Template<span style="color: #66cc66;">(</span><span style="color: #ff0000;">'./'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">// modèle à utiliser auquel on adjoint un nom arbitraire</span>
<span style="color: #ff0000">$template</span><span style="color: #66cc66;">-></span><span style="color: #006600;">set_filenames</span><span style="color: #66cc66;">(</span><span style="color: #000066;">array</span><span style="color: #66cc66;">(</span>
<span style="color: #ff0000;">'body'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000;">'template1.tpl'</span>
<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">// Assignation des variables</span>
<span style="color: #ff0000">$template</span><span style="color: #66cc66;">-></span><span style="color: #006600;">assign_vars</span><span style="color: #66cc66;">(</span><span style="color: #000066;">array</span><span style="color: #66cc66;">(</span>
<span style="color: #ff0000;">'PSEUDO'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000">$row</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'pseudo'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">'EMAIL'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000">$row</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'email'</span><span style="color: #66cc66;">]</span>
<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">// evoie des données dans une variable des données</span>
<span style="color: #ff0000">$variable</span><span style="color: #66cc66;">=</span> <span style="color: #ff0000">$template</span><span style="color: #66cc66;">-></span><span style="color: #006600;">pstring</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'body'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?></span></pre>
<p><a href="https://blog-du-grouik.tinad.fr/public/template.php.txt">Télécharger le template.php v1.10 avec la function pstring by gniearkt</a></p>
Dotclear include dans les templates
urn:md5:9da261d29bcca1d908b50b24348a02d9
2010-04-27T12:59:00+02:00
2010-04-27T20:58:39+02:00
gnieark
dev web
dotclear
template
<p>Il existe une méthode pour se simplifier la vie lors de la création (ou adaptation) d'un template sous dotclear. Le morceau de code concernant juste le billet. On retrouve la même dans les fichiers suivants:</p>
<ul>
<li>category.html</li>
<li>post.html</li>
<li>tag.html</li>
<li>home.html</li>
<li>page.html</li>
<li>search.html</li>
</ul>
<p>Et ça me gonflait à chaque modification, juste sur la présentation du billet en lui même de devoir la répercuter dans tous ces fichiers.</p>
<p>La solution:
Se créer un fichier contenant le template partiel, juste le billet. Je l'ai nommé _justunpost.html
Puis on remplace ce qu'il y a entre <tpl:Entries> et <tpl:EntriesFooter> par <q>tpl:include src="https://blog-du-grouik.tinad.fr/post/2010/04/27/_justunpost.html"</q>. Comme ceci:</p>
<pre class="html"><span style="color: #009900;"><tpl:Entries></span>
{{tpl:include src="_justunpost.html"}}
<span style="color: #009900;"><tpl:EntriesFooter></span></pre>
<p>Quand à mon fichier _justunpost.html (personnalisé blog du grouik :p), il a cette tête là:</p>
<pre class="html"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"p{{tpl:EntryID}}"</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"post {{tpl:EntryIfOdd}} {{tpl:EntryIfFirst}}"</span> <span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{{tpl:EntryLang}}"</span> xml:<span style="color: #000066;">lang</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{{tpl:EntryLang}}"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"post-title"</span><span style="color: #000000; font-weight: bold;">></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><a</span>
<span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{{tpl:EntryURL}}"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryTitle encode_html="1"}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></a></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"post-info"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><table></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tr></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"gncalendar"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><center></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><em</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"gndate"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryDate format="%A"}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></em></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><br</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span>
{{tpl:EntryDate format="%d %B"}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><br</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><em</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"gndate"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryDate format="%G"}} <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></em></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><br</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span>
{{tpl:EntryTime}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></center></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></td></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"gninfos"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><center></span></span>Auteur:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><br</span><span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><em</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"gndate"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryAuthorLink}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></em></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><br</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><tpl:EntryIf has_category<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span>
Cat<span style="color: #ddbb00;">&eacute;</span>gorie:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><br</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{{tpl:EntryCategoryURL}}"</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"gndate"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryCategory encode_html="1"}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></a></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><</span><span style="color: #66cc66;">/</span>tpl:EntryIf></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></center></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></td></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><td</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"gntags"</span><span style="color: #000000; font-weight: bold;">></span></span>
Tags:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><br</span><span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><tpl:EntryTags></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{{tpl:TagURL}}"</span><span style="color: #000000; font-weight: bold;">></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"themes/aorakit-2D/images/tag.png"</span><span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:TagID}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></a></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><br</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><</span><span style="color: #66cc66;">/</span>tpl:EntryTags></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></td></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tr></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></table></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- # --BEHAVIOR-- publicEntryBeforeContent --></span></span>
{{tpl:SysBehavior behavior="publicEntryBeforeContent"}}
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- # Entry with an excerpt --></span></span>
<span style="color: #009900;"><tpl:EntryIf extended<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"post-content"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryExcerpt}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><br</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span><span style="color: #ddbb00;">&nbsp;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"read-it"</span><span style="color: #000000; font-weight: bold;">></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{{tpl:EntryURL}}"</span>
<span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{{tpl:lang Continue reading}} {{tpl:EntryTitle encode_html="</span><span style="color: #cc66cc;">1</span><span style="color: #ff0000;">"}}"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:lang Continue
reading}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></a></span></span>...<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></p></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><</span><span style="color: #66cc66;">/</span>tpl:EntryIf></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- # Entry without excerpt --></span></span>
<span style="color: #009900;"><tpl:EntryIf extended<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"0"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"post-content"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryContent}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><br</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span><span style="color: #ddbb00;">&nbsp;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><</span><span style="color: #66cc66;">/</span>tpl:EntryIf></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- # --BEHAVIOR-- publicEntryAfterContent --></span></span>
{{tpl:SysBehavior behavior="publicEntryAfterContent"}}
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- # Number of comments, trackbacks and attachments --></span></span>
<span style="color: #009900;"><tpl:EntryIf operator<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"or"</span> show_comments<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span> show_pings<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span> has_attachment<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"post-info-co"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"themes/aorakit-2D/images/comments.png"</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"icone commentaires"</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><</span><span style="color: #66cc66;">/</span>tpl:EntryIf></span>
<span style="color: #009900;"><tpl:EntryIf show_comments<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{{tpl:EntryURL}}#comments"</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"comment_count"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryCommentCount}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></a></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><</span><span style="color: #66cc66;">/</span>tpl:EntryIf></span>
<span style="color: #009900;"><tpl:EntryIf show_pings<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{{tpl:EntryURL}}#pings"</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"ping_count"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryPingCount}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></a></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><</span><span style="color: #66cc66;">/</span>tpl:EntryIf></span>
<span style="color: #009900;"><tpl:EntryIf has_attachment<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{{tpl:EntryURL}}#attachments"</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"attach_count"</span><span style="color: #000000; font-weight: bold;">></span></span>{{tpl:EntryAttachmentCount}}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></a></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><</span><span style="color: #66cc66;">/</span>tpl:EntryIf></span>
<span style="color: #009900;"><tpl:EntryIf operator<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"or"</span> show_comments<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span> show_pings<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span> has_attachment<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"1"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><</span><span style="color: #66cc66;">/</span>tpl:EntryIf></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span></pre>
Programer via un moteur de template.
urn:md5:03ec550a121be8c90759ff3fd32427bc
2010-04-06T17:50:00+02:00
2010-04-18T22:15:35+02:00
gnieark
dev web
PHP
template
<p>Je passerai l'explication du comment qu'on fait, tout simplement parceque je ne ferai pas mieux que <a href="http://phpcodeur.net/articles/php/templates" hreflang="fr">ce tutoriel</a>.</p>
<p>ça fait changer l'approche de la programmation PHP puis celle de débogage.
A titre perso, je suis sur deux projets de sites web, actuellement. Dont un est la bascule de tinai (VB) (sorte d'ERP, GED) en vrai intranet, extranetisable.</p>
<p>Comment je m'y prenais avant et comment je fais avec les templates?</p>
<p>Généralement, on découpe son site en plusieurs éléments qu'on appelle avec des include (ça, ça ne change pas).Lorsqu'on code on a une idée de ce qu'on va y mettre, et on le fait apparaître sur la page au fur et à mesure du code en PHP pur par des <em>echo'<code html>';</em>. Et comme l'ordre des echo définit l'ordre d'apparition du code html. Le script php se lit dans le même sens que la page web. (vous m'avez compris.) ça peut être gênant d'ailleurs lorsque l'on doit remettre à plusieurs endroits des portions de code identiques à plusieurs endroits. dans la page: dans le cas du résultat d'une requête mysql remplissant des listes déroulantes de choix par exemple. En ce cas là soit on est prévoyant, on met tout dans une variable pour le réutiliser, soit on a gardé la variable $result soit on refait la requette mysql.
Pas super optimisé dans tous les cas (et au fond, les templates, ce n'est pas beaucoup mieux, mais ça ne se voit pas).</p>
<h3>Exemple de code: un annuaire tout bête:</h3>
<p>Juste un petit moteur de recherche dans une base de données en fait.</p>
<h4>Sans template:</h4>
<p>Cet exemple attaque la base de données qui est mise à jour par un script qui attaque notre autocommutateur.
<img src="https://blog-du-grouik.tinad.fr/public/.annuaire1_m.jpg" alt="annuaire1.jpg" style="display:block; margin:0 auto;" title="annuaire1.jpg, avr. 2010" /></p>
<pre class="php"><span style="color: #66cc66;"><!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #ff0000;">"-//W3C//DTD XHTML 1.0 Strict//EN"</span> <span style="color: #ff0000;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"</span><span style="color: #66cc66;">></span>
<span style="color: #66cc66;"><</span>html xmlns<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"http://www.w3.org/1999/xhtml"</span> <span style="color: #000066;">dir</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"ltr"</span> lang<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"fr"</span> xml<span style="color: #66cc66;">:</span>lang<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"fr"</span><span style="color: #66cc66;">></span>
<span style="color: #66cc66;"><</span>head<span style="color: #66cc66;">></span>
<span style="color: #66cc66;"><</span>meta http<span style="color: #66cc66;">-</span>equiv<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"Content-type"</span> content<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text/html;charset=ISO_8859-1"</span> <span style="color: #66cc66;">/></span>
<span style="color: #66cc66;"><</span>meta name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"keywords"</span> content<span style="color: #66cc66;">=</span><span style="color: #ff0000;">""</span> <span style="color: #66cc66;">/></span>
<span style="color: #66cc66;"><</span>meta name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"description"</span> content<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"Annuaire"</span> <span style="color: #66cc66;">/></span>
<span style="color: #66cc66;"><</span>meta name<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"author"</span> content<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"Gnieark http://blog-du-grouik.tinad.fr"</span> <span style="color: #66cc66;">/></span>
<span style="color: #66cc66;"><</span>title<span style="color: #66cc66;">></span> Annuaires t<span style="color: #66cc66;">&</span>eacute<span style="color: #66cc66;">;</span>l<span style="color: #66cc66;">&</span>eacute<span style="color: #66cc66;">;</span>phone et mail<span style="color: #66cc66;"></</span>title<span style="color: #66cc66;">></span>
<span style="color: #66cc66;"></</span>head<span style="color: #66cc66;">></span>
<span style="color: #66cc66;"><</span>body<span style="color: #66cc66;">></span>
<span style="color: #66cc66;"><</span>div id<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"all"</span><span style="color: #66cc66;">></span>
<span style="color: #66cc66;"><</span>div id<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"telephone"</span> style<span style="color: #66cc66;">=</span><span style="color: #ff0000;">"position: absolute; width 50%; left: 0px; top: 0px;"</span><span style="color: #66cc66;">></span>
<span style="color: #000000; font-weight: bold;"><?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #ff0000">$_POST</span><span style="color: #66cc66;">[</span>nomtel<span style="color: #66cc66;">]</span><span style="color: #66cc66;"><></span><span style="color: #ff0000;">''</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #66cc66;">!</span><span style="color: #000066;">mysql_connect</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'localhost'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Usermysql'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Password)) {
echo '</span>Impossible de se connecter à <span style="color: #000066;">MySQL</span><span style="color: #ff0000;">';
exit;
}
mysql_query("USE database");
$sql = "SELECT
Noannuaire,
Nomannuaire,
Prenomannuaire
FROM
annuairePABX
WHERE
Nomannuaire LIKE '</span><span style="color: #ff0000;">".$_POST['nomtel']."</span><span style="color: #66cc66;">%</span><span style="color: #ff0000;">'
OR Prenomannuaire LIKE '</span><span style="color: #ff0000;">".$_POST['nomtel']."</span><span style="color: #66cc66;">%</span><span style="color: #ff0000;">'
ORDER BY
Noannuaire ASC";
$result = mysql_query($sql);
if (!$result) {
echo "Erreur DB, impossible de lister les tables<span style="color: #000099; font-weight: bold;">\n</span>";
echo '</span>Erreur <span style="color: #000066;">MySQL</span> <span style="color: #66cc66;">:</span> <span style="color: #ff0000;">' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
echo "{$row[0]} {$row[1]} {$row[2]} |<span style="color: #000099; font-weight: bold;">\n</span>";
}
}
?>
<h3>Num&eacute;ros de t&eacute;l&eacute;phone:</h3>
<form method="post" action="annuaireinterne.php">
<p>D&eacute;but du nom:<input type="text" name="nomtel"/> <input type="submit" value="Valider" /></p>
</form>
</div><!-- Fin div telephone -->
<div id="mails" style="position: absolute; width 50%; left: 50%; top: 0px;">
<?php
if ($_POST[nommail]<>'</span><span style="color: #ff0000;">'){
if (!mysql_connect('</span>localhost<span style="color: #ff0000;">', '</span>rpasserieu<span style="color: #ff0000;">', '</span>a239373<span style="color: #ff0000;">')) {
echo '</span>Impossible de se connecter à <span style="color: #000066;">MySQL</span><span style="color: #ff0000;">';
exit;
}
mysql_query("USE postfix");
$sql = "SELECT
username,
name
FROM
mailbox
WHERE
name LIKE '</span><span style="color: #66cc66;">%</span><span style="color: #ff0000;">".$_POST[nommail]."</span><span style="color: #66cc66;">%</span><span style="color: #ff0000;">'
ORDER BY
name ASC";
$result = mysql_query($sql);
if (!$result) {
echo "Erreur DB, impossible de lister les tables<span style="color: #000099; font-weight: bold;">\n</span>";
echo '</span>Erreur <span style="color: #000066;">MySQL</span> <span style="color: #66cc66;">:</span> <span style="color: #ff0000;">' . mysql_error();
exit;
}
while ($row = mysql_fetch_row($result)) {
echo "<a href=<span style="color: #000099; font-weight: bold;">\"</span>mailto:".$row[0]."<span style="color: #000099; font-weight: bold;">\"</span>>".$row[0]."</a> : ".$row[1]."<br /><span style="color: #000099; font-weight: bold;">\n</span>";
}
}
?>
<h3>E-mail:</h3>
<form method="post" action="annuaireinterne.php">
<p>Partie du nom:<input type="text" name="nommail"/> <input type="submit" value="Valider" /></p>
</form>
</div><!-- Fin div mails -->
</div><!-- Fin div all -->
</body>
</html></span></pre>
<h4>Avec template:</h4>
<p>Là cet exemple se base sur une base de donées users plus classique.
Il y a donc deux fichiers: le template et le script php.
<img src="https://blog-du-grouik.tinad.fr/public/.annuaire2_m.jpg" alt="annuaire2.jpg" style="display:block; margin:0 auto;" title="annuaire2.jpg, avr. 2010" />
Le template:</p>
<pre class="html"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"main"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"telephone"</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"position: absolute; width 50%; left: 0px; top: 0px; background: #F7F7F7;"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><h3></span></span>Num<span style="color: #ddbb00;">&eacute;</span>ros de t<span style="color: #ddbb00;">&eacute;</span>l<span style="color: #ddbb00;">&eacute;</span>phone:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></h3></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><form</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"post"</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{acturltel}"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p></span></span>D<span style="color: #ddbb00;">&eacute;</span>but du nom:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text"</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"nomtel"</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{nomtel}"</span><span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"submit"</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"Valider"</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></p></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></form></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><table></span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- BEGIN tel --></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tr></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><td></span></span>{tel.nom}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></td></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><td></span></span>{tel.numero}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></td></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tr></span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- END tel --></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></table></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span><span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- Fin div telephone --></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"mails"</span> <span style="color: #000066;">style</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"position: absolute; width 50%; left: 50%; top: 0px; background: #F7F7F7;"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><h3></span></span>E-mail:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></h3></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><form</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"post"</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{acturlmail}"</span><span style="color: #000000; font-weight: bold;">></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><p></span></span>Partie du nom:<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"text"</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"nommail"</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"{nommail}"</span><span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span> <span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"submit"</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"Valider"</span> <span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></p></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></form></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><table></span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- BEGIN mail --></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><tr></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><td></span></span>{mail.nom}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></td></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><td></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"><a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">"mailto:{mail.mail}"</span><span style="color: #000000; font-weight: bold;">></span></span>{mail.mail}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></a></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></td></span></span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></tr></span></span>
<span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- END mail --></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></table></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span><span style="color: #009900;"><span style="color: #808080; font-style: italic;"><!-- fin div mails --></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;"></div></span></span></pre>
<p>Le script php:</p>
<pre class="php"><span style="color: #000000; font-weight: bold;"><?php</span>
<span style="color: #66cc66;">@</span><span style="color: #000066;">session_start</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">if</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$_SESSION</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'is_registered'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">!=</span><span style="color: #ff0000;">"1"</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">"You need be logged in"</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">die</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span>
<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'./config.php'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">//sql</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #66cc66;">!</span><span style="color: #000066;">mysql_connect</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$config</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'mysql_host'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$config</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'mysql_user'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000">$config</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'mysql_password'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
<span style="color: #000066;">echo</span> <span style="color: #ff0000;">'Impossible de se connecter à MySQL'</span><span style="color: #66cc66;">;</span>
<span style="color: #000066;">exit</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span>
<span style="color: #000066;">mysql_query</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"USE "</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$config</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'mysql_database'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$template</span> <span style="color: #66cc66;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Template<span style="color: #66cc66;">(</span><span style="color: #ff0000;">'./annuaire/template/'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$template</span><span style="color: #66cc66;">-></span><span style="color: #006600;">set_filenames</span><span style="color: #66cc66;">(</span><span style="color: #000066;">array</span><span style="color: #66cc66;">(</span>
<span style="color: #ff0000;">'annuaire'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000;">'annuaire.tpl'</span>
<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$template</span><span style="color: #66cc66;">-></span><span style="color: #006600;">assign_vars</span><span style="color: #66cc66;">(</span> <span style="color: #000066;">array</span><span style="color: #66cc66;">(</span>
<span style="color: #ff0000;">'acturltel'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000;">'./index.php?menu=annuaire'</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">'acturlmail'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000;">'./index.php?menu=annuaire'</span>
<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #808080; font-style: italic;">//afficher les mails</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #000066;">isset</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$_POST</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'nommail'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
<span style="color: #ff0000">$cdt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">" AND username LIKE '%"</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$_POST</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'nommail'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">"%'"</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span>
<span style="color: #b1b100;">else</span>
<span style="color: #66cc66;">{</span>
<span style="color: #ff0000">$cdt</span> <span style="color: #66cc66;">=</span><span style="color: #ff0000;">""</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span>
<span style="color: #ff0000">$result</span><span style="color: #66cc66;">=</span><span style="color: #000066;">mysql_query</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"SELECT username, mail FROM users WHERE mail IS NOT NULL AND mail <> ''"</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$cdt</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">" ORDER BY username"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$row</span><span style="color: #66cc66;">=</span><span style="color: #000066;">mysql_fetch_row</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$result</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
<span style="color: #ff0000">$template</span><span style="color: #66cc66;">-></span><span style="color: #006600;">assign_block_vars</span><span style="color: #66cc66;">(</span> <span style="color: #ff0000;">'mail'</span><span style="color: #66cc66;">,</span><span style="color: #000066;">array</span><span style="color: #66cc66;">(</span>
<span style="color: #ff0000;">'nom'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000">$row</span><span style="color: #66cc66;">[</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">'mail'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000">$row</span><span style="color: #66cc66;">[</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">]</span>
<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span>
<span style="color: #808080; font-style: italic;">//les tels</span>
<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #000066;">isset</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$_POST</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'nomtel'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
<span style="color: #ff0000">$cdt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">" AND username LIKE '%"</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$_POST</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'nomtel'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">"%'"</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span>
<span style="color: #b1b100;">else</span>
<span style="color: #66cc66;">{</span>
<span style="color: #ff0000">$cdt</span> <span style="color: #66cc66;">=</span><span style="color: #ff0000;">""</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span>
<span style="color: #ff0000">$result</span><span style="color: #66cc66;">=</span><span style="color: #000066;">mysql_query</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"SELECT username, telephone FROM users WHERE telephone IS NOT NULL AND telephone <> ''"</span><span style="color: #66cc66;">.</span><span style="color: #ff0000">$cdt</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">" ORDER BY username"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$row</span><span style="color: #66cc66;">=</span><span style="color: #000066;">mysql_fetch_row</span><span style="color: #66cc66;">(</span><span style="color: #ff0000">$result</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
<span style="color: #ff0000">$template</span><span style="color: #66cc66;">-></span><span style="color: #006600;">assign_block_vars</span><span style="color: #66cc66;">(</span> <span style="color: #ff0000;">'tel'</span><span style="color: #66cc66;">,</span><span style="color: #000066;">array</span><span style="color: #66cc66;">(</span>
<span style="color: #ff0000;">'nom'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000">$row</span><span style="color: #66cc66;">[</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">'numero'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000">$row</span><span style="color: #66cc66;">[</span><span style="color: #cc66cc;">1</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">,</span>
<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #66cc66;">}</span>
<span style="color: #ff0000">$template</span><span style="color: #66cc66;">-></span><span style="color: #006600;">assign_vars</span><span style="color: #66cc66;">(</span><span style="color: #000066;">array</span><span style="color: #66cc66;">(</span>
<span style="color: #ff0000;">'nomtel'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000">$_POST</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'nomtel'</span><span style="color: #66cc66;">]</span><span style="color: #66cc66;">,</span>
<span style="color: #ff0000;">'nommail'</span> <span style="color: #66cc66;">=></span> <span style="color: #ff0000">$_POST</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'nommail'</span><span style="color: #66cc66;">]</span>
<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #ff0000">$template</span><span style="color: #66cc66;">-></span><span style="color: #006600;">pparse</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'annuaire'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">;</span>
<span style="color: #000000; font-weight: bold;">?></span></pre>
<h3>Conclusion,</h3>
<p>Dans les deux cas, j'ai fait un truc moche. Mais je vais moins galérer à améliorer l'aspect de celui avec template.
Je sens que je vais avoir du mal à m'en passer dans les développements à venir.</p>