<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Qu&#039;une petite étincelle brille au fond de vos yeux ! &#187; VDigital</title>
	<atom:link href="http://www.vdigital.org/sharing/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vdigital.org/sharing</link>
	<description>Savoirs et partages</description>
	<lastBuildDate>Sat, 21 Aug 2010 20:36:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Plus smart que Smarty &#8230;</title>
		<link>http://www.vdigital.org/sharing/2010/08/plus-smart-que-smarty/</link>
		<comments>http://www.vdigital.org/sharing/2010/08/plus-smart-que-smarty/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 19:40:19 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=1158</guid>
		<description><![CDATA[Pourquoi ne peut-on pas insérer du code Smarty dans la bannière des pages de Piwigo ? Hors-sujet : Indiquer l&#8217;url de la galerie est un peu étrange, devoir coder soi-même des balises en réutilisant en général ces mêmes informations relève d&#8217;une logique perturbante. Revenons à la question initiale : vos indications sont d&#8217;abord enregistrées dans [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Pourquoi ne peut-on pas insérer du code Smarty dans la bannière des pages de Piwigo ?</p></blockquote>
<p><img src="http://www.vdigital.org/sharing/wp-content/uploads/2010/08/Sharing.png" alt="" title="Bannière de Piwigo" width="560" height="150" class="aligncenter size-full wp-image-1159" /></p>
<p><sub>Hors-sujet : Indiquer l&#8217;url de la galerie est un peu étrange, devoir coder soi-même des balises en réutilisant en général ces mêmes informations relève d&#8217;une logique perturbante.</sub></p>
<p>Revenons à la question initiale : <span id="more-1158"></span>vos indications sont d&#8217;abord enregistrées dans la base de données, puis lors de la publication d&#8217;une page publique ces données seront placées dans une variable Smarty : $PAGE_BANNER et c&#8217;est cette variable qui se retrouve dans le header.tpl utilisé par le thème de votre site.</p>
<p><strong>Comment pourrions-nous simplifier ceci ? </strong><br />
Nous avons déjà évoqué la solution, mais elle est passée inaperçue, je ne cherchais pas à la mettre en évidence.<br />
Dans &laquo;&nbsp;<a href="http://www.vdigital.org/sharing/2010/07/concevoir-des-templates-evolutifs/">Concevoir des templates évolutifs</a>&nbsp;&raquo; c&#8217;est presque la même solution.<br />
Voyons cela avec un cas précis.<br />
Imaginons que nous voulions coder:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$TITLE}</span>&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$GALLERY_TITLE}</span>&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$GALLERY_TITLE}</span>&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$GALLERY_TITLE</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>h1<span style="color: #339933;">&gt;</span></div></div>
<p><strong>En utilisant des templates-extensions.</strong><br />
Dans ./template-extension/ nous allons créer un page_banner.tpl avec :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>h1<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$TITLE}</span>&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$GALLERY_TITLE}</span>&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$GALLERY_TITLE}</span>&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$GALLERY_TITLE</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>h1<span style="color: #339933;">&gt;</span></div></div>
<p>Et toujours dans ./template-extension/ nous allons créer un header.tpl avec :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">'../../../template-extension/page_banner.tpl'</span> assign<span style="color: #339933;">=</span>BANNER<span style="color: #009900;">&#125;</span> <br />
&nbsp; <span style="color: #009900;">&#123;</span>assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span>TEXT_BANNER value<span style="color: #339933;">=</span><span style="color: #000088;">$PAGE_BANNER</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;../../default/template/header.tpl&quot;</span> PAGE_BANNER<span style="color: #339933;">=</span><span style="color: #000088;">$BANNER</span><span style="color: #009900;">&#125;</span> <br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span> quel que soit le template<span style="color: #339933;">,</span> le path doit être relatif depuis themes<span style="color: #339933;">/</span>xxxx<span style="color: #339933;">/</span>template<span style="color: #339933;">/</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span></div></div>
<p>Bien entendu on activera le template-extension/header.tpl</p>
<p><strong>Comment ça fonctionne ?</strong><br />
Quand la page sera demandée, l&#8217;header.tpl sera sollicité. Celui-ci étant substitué par celui du répertoire template-extension, la première chose réalisée sera l&#8217;include de page_banner.tpl. Cependant au lieu de présenter immédiatement le résultat sera affecté à la variable BANNER (assign=BANNER).<br />
Ensuite nous avons un assign var= (facultatif) qui n&#8217;est là que pour le cas où nous voudrions utiliser le texte initial de la &laquo;&nbsp;Bannière des pages&nbsp;&raquo; ultérieurement dans un autre template.<br />
Enfin on sollicite le header par défaut (pour rester évolutif) mais cette fois nous indiquons PAGE_BANNER=$BANNER, c&#8217;est à dire que nous changeons le contenu de $PAGE_BANNER par ce que nous avions obtenu de l&#8217;include de page_banner.tpl.</p>
<p>Ce n&#8217;est que du Smarty tout à fait standard. C&#8217;est simple et sympa, bref c&#8217;est Smarty.</p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=1158';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/08/plus-smart-que-smarty/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Saluer nos inscrits ou les surprendre</title>
		<link>http://www.vdigital.org/sharing/2010/08/saluer-nos-inscrits-ou-les-surprendre/</link>
		<comments>http://www.vdigital.org/sharing/2010/08/saluer-nos-inscrits-ou-les-surprendre/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 16:50:37 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[Fonctions]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Piwigo]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=1130</guid>
		<description><![CDATA[Avec Piwigo, dans votre thème personnel, vous aurez peut-être pris soin déjà de coder : include_once&#40;PHPWG_ROOT_PATH .'themes/mon_theme/include/functions.inc.php'&#41;; ou include_once&#40;PHPWG_ROOT_PATH .'local/php/functions.inc.php'&#41;; Alors sans le moindre plugin, vous pouvez compléter votre galerie de fonctions diverses et variées. Exemple : if &#40; !function_exists&#40; 'getRegisteredName' &#41;&#41; &#123; &#160; function getRegisteredName&#40;$default = ' '&#41; &#123; &#160; &#160; global $user; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Avec Piwigo, dans votre thème personnel, vous aurez peut-être pris soin déjà de coder :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span>PHPWG_ROOT_PATH <span style="color: #339933;">.</span><span style="color: #0000ff;">'themes/mon_theme/include/functions.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>ou</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span>PHPWG_ROOT_PATH <span style="color: #339933;">.</span><span style="color: #0000ff;">'local/php/functions.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Alors sans le moindre plugin, vous pouvez compléter votre galerie de fonctions diverses et variées.<br />
<span id="more-1130"></span><br />
Exemple :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/function_exists"><span style="color: #990000;">function_exists</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'getRegisteredName'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">function</span> getRegisteredName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$default</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$user</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_a_guest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$default</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">' '</span> <span style="color: #339933;">.</span> <a href="http://www.php.net/stripslashes"><span style="color: #990000;">stripslashes</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$user</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Voyons comment utiliser cette fonction.<br />
En premier lieu, dans une <strong>version statique</strong> c&#8217;est à dire dans n&#8217;importe quel template, vous pouvez coder par exemple :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Bonjour<span style="color: #009900;">&#123;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">|</span>getRegisteredName<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span></div></div>
<p>Cette solution sera statique car quelque soit le template choisi, la présentation sera toujours identique.</p>
<p><strong>Regardons maintenant une solution dynamique</strong>, en d&#8217;autres termes vous souhaitez disposer du nom du membre dans un contenu (description d&#8217;une catégorie, page additionnelle, bloc de PWG Stuffs), alors au niveau d&#8217;un template, vous devrez coder (1ère solution) :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span>html_head<span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span> <span style="color: #000000; font-weight: bold;">var</span> PSEUDO <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;{' '|getRegisteredName},&quot;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span><span style="color: #0000ff;">',<br />
{/html_head}</span></div></div>
<p>Et maintenant à chaque fois, où vous voulez voir apparaitre le nom du membre, vous coderez :</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span>&gt;</span> document.write( PSEUDO ); <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/script.html"><span style="color: #000000; font-weight: bold;">script</span></a>&gt;</span></div></div>
<p><strong>L&#8217;autre solution dynamique</strong> (ma préférée) est à base de jQuery, et consiste en un remplacement de toute occurrence de &lt;label class=&#34;pseudo&#34;>&lt;/label> par le nom du membre. Pour cela, au niveau d&#8217;un template, vous devrez coder (2nde solution) :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span>known_script id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;jquery&quot;</span> src<span style="color: #339933;">=</span><span style="color: #000088;">$ROOT_URL</span><span style="color: #339933;">|@</span>cat<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;themes/default/js/jquery.packed.js&quot;</span><span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #009900;">&#123;</span>html_head<span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span><br />
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>ldelim<span style="color: #009900;">&#125;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.pseudo&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>text<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'{&quot;&quot;|getRegisteredName}'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span>html_head<span style="color: #009900;">&#125;</span></div></div>
<p>Cette fois, quand vous aurez besoin du pseudo du membre, vous devrez coder :</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;pseudo&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/label.html"><span style="color: #000000; font-weight: bold;">label</span></a>&gt;</span></div></div>
<p>Un seul inconvénient commun à nos deux solutions dynamiques, Javascript doit être actif.<br />
Bon usage à tous et, saluez vos membres de ma part.</p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=1130';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/08/saluer-nos-inscrits-ou-les-surprendre/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Un été de fête &#8230;</title>
		<link>http://www.vdigital.org/sharing/2010/08/un-ete-de-fete/</link>
		<comments>http://www.vdigital.org/sharing/2010/08/un-ete-de-fete/#comments</comments>
		<pubDate>Sat, 07 Aug 2010 06:12:47 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Animations]]></category>
		<category><![CDATA[Dicton]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=1123</guid>
		<description><![CDATA[De fête à la grenouille, vous diraient bien des gens. En tant photographe amateur, je vous invite à découvrir mon dicton très personnel : Quand la météo est à la pluie, laisse ton appareil dans son étui. Quand le temps se joue de nous, il nous reste la chanson: Señor Météo Quando dit qu&#8217;il fait [...]]]></description>
			<content:encoded><![CDATA[<p>De fête à la grenouille, vous diraient bien des gens.<br />
En tant photographe amateur, je vous invite à découvrir mon dicton très personnel :</p>
<blockquote><p>
Quand la météo est à la pluie, laisse ton appareil dans son étui.</p></blockquote>
<p>Quand le <a href="http://meteovilliers.fr/" alt="Le temps qu'il fait ici, selon la station de Señor météo (mon ami Jean)">temps</a> se joue de nous, il nous reste la chanson:</p>
<blockquote><p>
Señor Météo<br />
Quando dit qu&#8217;il fait beau<br />
Señor Météo<br />
A glagla quel frigo !<br />
Quando mi transistor esperansa calor<br />
Il a tort !<br />
Que dolor </p></blockquote>
<p><sub>Claude Lemesle / Joe Dassin en 1974</sub><br />
Depuis la météorologie a fait beaucoup de progrès, il faut bien le reconnaître.</p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=1123';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/08/un-ete-de-fete/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Utiliser Ajax avec WordPress</title>
		<link>http://www.vdigital.org/sharing/2010/08/utiliser-ajax-avec-wordpress/</link>
		<comments>http://www.vdigital.org/sharing/2010/08/utiliser-ajax-avec-wordpress/#comments</comments>
		<pubDate>Fri, 06 Aug 2010 21:20:17 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=1094</guid>
		<description><![CDATA[<div class="img-shadow"><img width="200" height="150" title="ajaxwordpress" alt="Ajax and WordPress" class="attachment-thumbnail wp-post-image" src="http://bavotasan.com/wp-content/uploads/2010/08/ajaxwordpress.jpg"></img>]]></description>
			<content:encoded><![CDATA[<p><sub>Traduit et adapté de l&#8217;article <a href="http://bavotasan.com/tutorials/using-ajax-with-wordpress/">Using Ajax with WordPress</a> de C. Bavota (avec son aimable autorisation).</sub></p>
<p>Il y a quelques temps, C. Bavota a publié une révision du thème &laquo;&nbsp;<a href="http://wordpress.org/extend/themes/magazine-basic">Magazine Basic</a>&nbsp;&raquo; incluant une fonction d&#8217;enregistrement en Ajax. Dans l&#8217;attente de réactions suite à sa publication sur WordPress, il a obtenu des informations sur la façon d&#8217;intégrer Ajax en utilisant le module admin-ajax.php au lieu du code qu&#8217;il avait utilisé. Toutes les fonctions principales en Ajax de WordPress s&#8217;appuient sur admin-ajax.php, et sa mise en œuvre pour des scripts personnalisés est extrêmement simple.<br />
<span id="more-1094"></span><br />
Regardons les éléments dont vous aurez besoin pour que cela fonctionne. Dans l&#8217;exemple ci-dessous, nous allons coder une petite fonction de mailing-list qui notifiera l&#8217;administrateur par courriel lors d&#8217;une nouvelle inscription.</p>
<p><strong>Voyons le formulaire :</strong></p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mailinglist&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;message&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mailinglistemail&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mailinglistemail&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/input.html"><span style="color: #000000; font-weight: bold;">input</span></a> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mailinglistsubmit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;S'abonner&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<a href="http://december.com/html/4/element/img.html"><span style="color: #000000; font-weight: bold;">img</span></a> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&lt;?php admin_url(); ?&gt;</span></span>/wp-admin/images/wpspin_light.gif&quot; alt=&quot;&quot; class=&quot;ajaxsave&quot; style=&quot;display: none;&quot; /&gt;<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/form.html"><span style="color: #000000; font-weight: bold;">form</span></a>&gt;</span></div></div>
<p><strong>Voici le jQuery :</strong></p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>&nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistemail&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Merci d'indiquer votre adresse email.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mailinglistemail'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;@&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">||</span> email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Merci de saisir une adresse email valide.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; action<span style="color: #339933;">:</span> <span style="color: #3366CC;">'join_mailinglist'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; email<span style="color: #339933;">:</span> email<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; jQuery.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;?php echo admin_url('admin-ajax.php'); ?&gt;&quot;</span><span style="color: #339933;">,</span> data<span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <br />
&nbsp;<br />
&nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Permettez-moi de vous expliquer chaque composant.</p>
<p>Quand un utilisateur clique sur &laquo;&nbsp;S&#8217;abonner&nbsp;&raquo; (Envoyer), nous devons vérifier que le champ e-mail n&#8217;est pas vide. S&#8217;il est vide, nous en informerons le visiteur en lui indiquant &laquo;&nbsp;Merci d&#8217;indiquer votre adresse email.&nbsp;&raquo; et nous arrêtons le processus en incluant l&#8217;instruction &laquo;&nbsp;return false;&nbsp;&raquo;.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistemail&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Merci d'indiquer votre adresse email.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Ensuite, nous ferons une simple validation pour s&#8217;assurer que l&#8217;adresse e-mail contient au moins une arrobe (@) et un point. Si ce n&#8217;est pas le cas, nous renverrons un message d&#8217;erreur suivi de &laquo;&nbsp;return false;&nbsp;&raquo;.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mailinglistemail'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">val</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;@&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">||</span> email.<span style="color: #660066;">indexOf</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Merci de saisir une adresse email valide.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Une fois ces contrôles élémentaires effectués et passés avec succès, nous pouvons traiter le formulaire. C&#8217;est maintenant qu&#8217;admin-ajax.php entre en jeu. Lors l&#8217;utilisation d&#8217;admin-ajax.php, vous devez ajouter une action WordPress (<a href="http://codex.wordpress.org/Function_Reference/add_action">add_action</a>) incluant une fonction de rappel (callback function) pour que ça fonctionne. Notre fonction de rappel sera join_mailinglist. Notre fonction PHP rendra l&#8217;ensemble fonctionnel en tâche de fond. Mais avant, nous allons créer une variable pour stocker l&#8217;action et l&#8217;adresse email du nouvel abonné.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; action<span style="color: #339933;">:</span> <span style="color: #3366CC;">'join_mailinglist'</span><span style="color: #339933;">,</span><br />
&nbsp; email<span style="color: #339933;">:</span> email<br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>Maintenant, nous allons cacher le bouton d&#8217;envoi et présenter un graphique animé pour indiquer qu&#8217;une tâche de fond s&#8217;exécute. Puis nous utiliserons la fonction .post de jQuery pour envoyer ces informations au module admin-ajax.php. Une fois la fonction terminée et la réponse transmise, l&#8217;animation va disparaître, le bouton &laquo;&nbsp;S&#8217;abonner&nbsp;&raquo; sera de retour avec un message de succès, ou un message d&#8217;erreur.</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
jQuery.<span style="color: #660066;">post</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&lt;?php echo admin_url('admin-ajax.php'); ?&gt;&quot;</span><span style="color: #339933;">,</span> data<span style="color: #339933;">,</span><br />
<span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ajaxsave&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglistsubmit&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#mailinglist #message&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>response<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp; <br />
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span></div></div>
<p>Avec le formulaire et le jQuery, vous aurez besoin encore d&#8217;un peu de PHP.<br />
Le module admin-ajax.php requiert deux ancrages d&#8217;action (<a href="http://codex.wordpress.org/Function_Reference/add_action">add_action</a>).</p>
<p>La première action ne fonctionnera que pour les utilisateurs connectés. La seconde le sera pour les autres. Les visiteurs n&#8217;ont pas à être connectés pour notre besoin, et dans notre cas l&#8217;action devrait ressembler à ceci :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_ajax_join_mailinglist'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'join_mailinglist_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_ajax_nopriv_join_mailinglist'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'join_mailinglist_callback'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p><strong><br />
Voici la fonction join_mailinglist_callback, qui devra être ajoutée à votre functions.php :</strong></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> join_mailinglist_callback<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$yourEmail</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'vpiwigo@gmail.com'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Abonnez-vous à la lettre d\'information'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$success</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/mail"><span style="color: #990000;">mail</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$yourEmail</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$success</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Votre adresse email a été ajoutée à notre lettre d\'information.'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Un problème a été rencontré. Veuillez réessayer.'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Une fois tout en place, vous obtiendrez un formulaire fonctionnant comme ci-dessous. </p>
<p><script type='text/javascript' src='http://www.vdigital.org/sharing/wp-content/local/js/nl-subscription.js'></script></p>
<form method="post" id="mailinglist" action="">
<div id="message"></div>
<input type="text" name="mailinglistemail" id="mailinglistemail" />
<input type="submit" name="submit" id="mailinglistsubmit" value="S'abonner" /><img src="http://www.vdigital.org/sharing/wp-admin/images/wpspin_light.gif" alt="runing" class="ajaxsave" style="display: none;" /><br />
</form>
<p><sub>En réalité, aucune lettre d&#8217;information ne vous sera adressée suite à votre inscription sur ce formulaire de démonstration (les adresses fournies peuvent être fictives, elles ne seront pas enregistrées).</p>
<p><sub>Translated and adapted from &laquo;&nbsp;<a href="http://bavotasan.com/tutorials/using-ajax-with-wordpress/">Using Ajax with WordPress</a>&nbsp;&raquo; article by C. Bavota (with his kind authorization).</sub></p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=1094';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/08/utiliser-ajax-avec-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Éviter les icones sous forme de balise img</title>
		<link>http://www.vdigital.org/sharing/2010/08/eviter-les-icones-sous-forme-de-balise-img/</link>
		<comments>http://www.vdigital.org/sharing/2010/08/eviter-les-icones-sous-forme-de-balise-img/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 15:08:47 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[Icones]]></category>
		<category><![CDATA[Piwigo]]></category>
		<category><![CDATA[Templates]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=1042</guid>
		<description><![CDATA[Piwigo jusqu&#8217;à présent propose des icones sous la forme de balises &#60;img &#8230;>, c&#8217;est pourtant ce qu&#8217;il conviendrait d&#8217;éviter pour plusieurs raisons. Pourquoi est-ce une erreur? 1 &#8211; En cas d&#8217;erreur lors du transfert de l&#8217;image, la balise est affichée sous forme d&#8217;une petite croix rouge par la majorité des navigateurs. 2 &#8211; Les moteurs [...]]]></description>
			<content:encoded><![CDATA[<p>Piwigo jusqu&#8217;à présent propose des icones sous la forme de balises &lt;img &#8230;>, c&#8217;est pourtant ce qu&#8217;il conviendrait d&#8217;éviter pour plusieurs raisons.</p>
<p><strong>Pourquoi est-ce une erreur?</strong></p>
<blockquote><p>1 &#8211; En cas d&#8217;erreur lors du transfert de l&#8217;image, la balise est affichée sous forme d&#8217;une petite croix rouge par la majorité des navigateurs.<br />
2 &#8211; Les moteurs de référencement cherchent à référencer les images, or trouver des petites images identiques sur des milliers de sites conduit immanquablement à appliquer une décote sur l&#8217;intérêt de nos sites.</p></blockquote>
<p><strong>Quelle est la portée de cette erreur?</strong><br />
Les templates du thème par défaut devraient être une fois encore révisés, car ceux-ci entrainent dans la même erreur les autres thèmes et leurs templates, sans compter les plugins qui ajoutent d&#8217;autres templates répétant tous ou presque cette même erreur.<br />
Au moins une vingtaine de fichiers sont concernés, il vous suffit d&#8217;effectuer une recherche de class=&#34;button&#34; ou de &#34;icon&#34; ou encore de &#34;navButton&#34; dans le répertoire themes/default/template/ pour vous en convaincre.<br />
<span id="more-1042"></span><br />
<strong>Comment l&#8217;équipe Piwigo pourrait-elle résoudre proprement cette erreur?</strong><br />
Un exemple simple :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ROOT_URL}</span>{<span style="color: #006699; font-weight: bold;">$themeconf</span>.icon_dir}/delete.png&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;button&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;[delete]&quot;</span><span style="color: #339933;">&gt;</span></div></div>
<p>En :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>span <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;button {<span style="color: #006699; font-weight: bold;">$themeconf</span>.button} {<span style="color: #006699; font-weight: bold;">$button</span>.status}&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$button</span><span style="color: #339933;">.</span>name<span style="color: #339933;">|</span>translate<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span></div></div>
<p>En tenant compte du billet suivant : <a href="http://www.vdigital.org/sharing/2010/08/afficher-une-image-au-lieu-dun-texte-en-css/" alt="">Afficher une image au lieu d’un texte (en CSS)</a> et les quelques idées suivantes :<br />
- L&#8217;élément déclencheur pourrait être : class=&#34;button&#34;,<br />
- le {$themeconf.button} permettrait de passer la font en 0/0, ce qui permet d&#8217;avoir des thèmes avec icones et d&#8217;autres avec textes, sans que les plugins aient à se poser des questions métaphysiques s&#8217;ils doivent/peuvent ajouter des boutons ou pas en fonction du thème.<br />
- Quant au {$button.status}, il assurerait un décalage de l&#8217;image en fonction de :hover, :active, etc&#8230; Une technique déjà employée pour l&#8217;évaluation (rating) des images mais qui demande une révision de toutes les icones actuel(le)s ce qui pourrait fortement contrarier les créateurs de thèmes.</p>
<p><strong>A titre individuel, pourrions-nous déjà anticiper un tel changement ?</strong><br />
Oui, c&#8217;est réalisable avec un thème personnel, en concentrant nos efforts ne serait-ce que sur trois templates :</p>
<ul>
<li>index.tpl</li>
<li>picture.tpl</li>
<li>picture_nav_buttons.tpl</li>
</ul>
<p>Soit des templates pour lesquels vous devrez vous limiter à :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>span <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;button nom_du_bouton&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'nom du bouton'</span><span style="color: #339933;">|</span>translate<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span></div></div>
<p>Exemple du niveau de complexité du changement :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$last</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>a <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;navButton&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$last</span>.U_IMG}&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{'Last'|@translate} : {<span style="color: #006699; font-weight: bold;">$last</span>.TITLE}&quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;last&quot;</span><span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ROOT_URL}</span>{<span style="color: #006699; font-weight: bold;">$themeconf</span>.icon_dir}/last.png&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;button&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{'Last'|@translate}&quot;</span><span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>a <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;navButton&quot;</span><span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ROOT_URL}</span>{<span style="color: #006699; font-weight: bold;">$themeconf</span>.icon_dir}/last_unactive.png&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;button&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span></div></div>
<p>en :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$last</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>a <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;navButton icon_last&quot;</span> href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$last</span>.U_IMG}&quot;</span> title<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{'Last'|@translate} : {<span style="color: #006699; font-weight: bold;">$last</span>.TITLE}&quot;</span> rel<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;last&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'Last'</span><span style="color: #339933;">|@</span>translate<span style="color: #009900;">&#125;</span><span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>a <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;navButton icon_last_unactive&quot;</span><span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span></div></div>
<p>Un changement qui doit être accompagné dans votre theme.css de :</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.navButton</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span> <span style="color: #933;">0pt</span>/<span style="color: #933;">0px</span> Arial<span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">24px</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">2px</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* pour maintenir l'espacement entre les icones - A ajuster */</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">24px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #6666ff;">.icon_last</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../default/icon/last.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">scroll</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #6666ff;">.icon_last_unactive</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../default/icon/last_unactive.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">scroll</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<p>En guise d&#8217;épilogue, et pour ne pas focaliser sur Piwigo lequel présente de nombreux avantages, j&#8217;attirerai votre attention sur d&#8217;autres applications. Par exemple Contao, lequel n&#8217;utilise pas un moteur de template et présente la même erreur. Par contre, Gallery 3, zenphoto, WordPress ou Dotclear ne semblent pas concernés sauf si un thème externe ne respecte pas leurs standards.<br />
Dernier point, quelque soit l&#8217;application, les pages d&#8217;administration peuvent utiliser des balises img car les moteurs de recherche n&#8217;accèdent pas dans ces pages. </p>
<p>Conclusion : Si vous devez changer de thème ou faire votre thème personnel, quelque soit votre application évitez les icones basées sur des balises img. </p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=1042';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/08/eviter-les-icones-sous-forme-de-balise-img/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Afficher une image au lieu d&#8217;un texte (en CSS)</title>
		<link>http://www.vdigital.org/sharing/2010/08/afficher-une-image-au-lieu-dun-texte-en-css/</link>
		<comments>http://www.vdigital.org/sharing/2010/08/afficher-une-image-au-lieu-dun-texte-en-css/#comments</comments>
		<pubDate>Wed, 04 Aug 2010 17:46:35 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=1044</guid>
		<description><![CDATA[Remarque liminaire : La technique suivante ne devrait être utilisée que dans des cas très précis, nous aurons l&#8217;occasion d&#8217;en aborder certains prochainement. Condition : Le texte doit être délimité par une balise HTML (&#60;span> ou une autre). Exemple: &#60;div class=&#34;headerMain&#34;&#62; &#160; &#60;h1&#62;&#60;a href=&#34;http://www.vdigital.org/sharing&#34;&#62;Qu&#38;#039;une petite étincelle brille au fond de vos yeux !&#60;/a&#62;&#60;/h1&#62; &#60;/div&#62; Quelques [...]]]></description>
			<content:encoded><![CDATA[<p>Remarque liminaire : La technique suivante ne devrait être utilisée que dans des cas très précis, nous aurons l&#8217;occasion d&#8217;en aborder certains prochainement.</p>
<p><strong>Condition </strong>: Le texte doit être délimité par une balise HTML (&lt;span> ou une autre).</p>
<p>Exemple:</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;headerMain&quot;</span>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.vdigital.org/sharing&quot;</span>&gt;</span>Qu<span style="color: #ddbb00;">&amp;#039;</span>une petite étincelle brille au fond de vos yeux !<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/h1.html"><span style="color: #000000; font-weight: bold;">h1</span></a>&gt;</span><br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></div>
<p><strong>Quelques uns des avantages de cette astuce </strong>:</p>
<blockquote><p>- L&#8217;absence de script assure un affichage immédiat avec les autres éléments de la page.<br />
- Le HTML d&#8217;origine reste simple, sans aucune modification.<br />
- S&#8217;il s&#8217;agit d&#8217;un lien, il demeure utilisable.<br />
- Pour les moteurs de recherche, le texte étant présent c&#8217;est lui qui est analysé et référencé.<br />
- En contre partie, l&#8217;image ne sera pas référencée.
</p></blockquote>
<p><span id="more-1044"></span></p>
<p><strong>Cas de remplacement</strong> :</p>
<div class="codecolorer-container css default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.headerMain</span> h1 a<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.headerMain</span> h1 a<span style="color: #3333ff;">:visited</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.headerMain</span> h1 a<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">../../local/images/blog_entete.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span> <span style="color: #993333;">scroll</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #993333;">transparent</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">font</span><span style="color: #00AA00;">:</span><span style="color: #993333;">bold</span> <span style="color: #933;">0pt</span>/<span style="color: #933;">0px</span> Arial<span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">185px</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">388px</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></div>
<p>Explications:</p>
<ol>
<li>  background:url(../../local/images/blog_entete.png) no-repeat scroll 0 0 transparent;<br />
Indique l&#8217;image à utiliser. Éventuellement des &laquo;&nbsp;class&nbsp;&raquo; différentes permettront de changer une image par une autre, n&#8217;abusez pas de ces changements dans vos pages pour autant ou assurez vous que le poids de celles-ci reste raisonnable.
</li>
<li>  display:block;<br />
Transforme l&#8217;affichage en ligne (inline) en affichage par bloc (block).
</li>
<li>  font:bold <strong>0pt/0px</strong> Arial;<br />
L&#8217;élément principal de l&#8217;astuce : la <strong>police des caractères</strong> (font) aura une <strong>taille nulle</strong> et la <strong>hauteur des lignes</strong> sera également à <strong>zéro</strong>.
</li>
<li>  height:185px;<br />
Hauteur de l&#8217;image.
</li>
<li>  outline:0px;<br />
Dans le cas d&#8217;un lien, ce paramètre élimine le contour en pointillé lors du clic.
</li>
<li>  width:388px;<br />
Largeur de l&#8217;image.
</li>
</ol>
<p>Démonstrations :</p>
<div class="codecolorer-container html4strict default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;example-img-iso-text&quot;</span>&gt;&lt;<a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;</span><br />
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in vehicula lorem. Morbi bibendum viverra sem id malesuada. Fusce eros velit, aliquet id fringilla at, adipiscing vitae quam. Praesent pretium malesuada egestas. Vivamus blandit aliquet quam, at pellentesque ante dignissim non. Mauris id nisi magna, eget fermentum metus. Mauris varius tristique turpis vitae dignissim. Phasellus tempor eleifend diam nec mollis! Ut ornare lorem vel augue molestie sodales. Lorem ipsum dolor sit amet, consectetur adipiscing elit.<br />
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/p.html"><span style="color: #000000; font-weight: bold;">p</span></a>&gt;&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></div>
<p>Exemple concret :</p>
<p style="background:url(http://www.vdigital.org/sharing/wp-content/local/images/blog_entete.png) no-repeat scroll 0 0 transparent;  display:block; font:bold 0pt/0px Arial; height:185px; width:388px; margin-bottom:5px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in vehicula lorem. Morbi bibendum viverra sem id malesuada. Fusce eros velit, aliquet id fringilla at, adipiscing vitae quam. Praesent pretium malesuada egestas. Vivamus blandit aliquet quam, at pellentesque ante dignissim non. Mauris id nisi magna, eget fermentum metus. Mauris varius tristique turpis vitae dignissim. Phasellus tempor eleifend diam nec mollis! Ut ornare lorem vel augue molestie sodales. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
</p>
<p>Plus classique, le même texte avec en arrière plan une autre image (<strong>sans </strong>le paramètre <strong>font:bold 0pt/0px Arial;</strong>) :</p>
<p style="background:url(http://www.vdigital.org/sharing/wp-content/local/images/blueMountain.jpg) no-repeat scroll 0 0 transparent;  height:200px; margin-bottom:5px; outline:0; padding:5px 136px 10px 15px; width:440px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce in vehicula lorem. Morbi bibendum viverra sem id malesuada. Fusce eros velit, aliquet id fringilla at, adipiscing vitae quam. Praesent pretium malesuada egestas. Vivamus blandit aliquet quam, at pellentesque ante dignissim non. Mauris id nisi magna, eget fermentum metus. Mauris varius tristique turpis vitae dignissim. Phasellus tempor eleifend diam nec mollis! Ut ornare lorem vel augue molestie sodales. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=1044';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/08/afficher-une-image-au-lieu-dun-texte-en-css/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>S&#8217;affranchir des templates-extensions</title>
		<link>http://www.vdigital.org/sharing/2010/08/saffranchir-des-templates-extensions/</link>
		<comments>http://www.vdigital.org/sharing/2010/08/saffranchir-des-templates-extensions/#comments</comments>
		<pubDate>Sun, 01 Aug 2010 08:35:56 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[Piwigo]]></category>
		<category><![CDATA[Templates]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=1030</guid>
		<description><![CDATA[Piwigo par le biais de son prédécesseur PhpWebGallery avait intégré un principe assez mal compris, celui des templates-extensions (T-E.). Le principe était alors simplement décrit et devait encore être codé, ce que j&#8217;ai réalisé dans Piwigo 2.0. Les T-E. de Piwigo étaient sensés permettre vos adaptations tout en autorisant les évolutions des templates standards. Donc [...]]]></description>
			<content:encoded><![CDATA[<p>Piwigo par le biais de son prédécesseur PhpWebGallery avait intégré un principe assez mal compris, celui des templates-extensions (T-E.).<br />
Le principe était alors simplement décrit et devait encore être codé, ce que j&#8217;ai réalisé dans Piwigo 2.0.</p>
<blockquote><p>Les T-E. de Piwigo étaient sensés permettre vos adaptations tout en autorisant les évolutions des templates standards. Donc de permettre d&#8217;identifier rapidement les différences. Afin que les évolutions puissent être également appliquées à vos adaptations.<br />
Les T-E. sont ni plus ni moins que des templates qui sous certaines conditions remplacent les templates standards.</p></blockquote>
<p>Pour identifier rapidement les différences, il aurait été nécessaire de proposer un outil de comparaison entre chaque T-E. et son template d&#8217;origine. Ceci afin que les évolutions soient rapidement prises en compte.<span id="more-1030"></span><br />
De l&#8217;absence de comparateur et pour la raison évoquée ci-après, nous assisterons à la fin programmée des T-E.<br />
La logique de thème parent a tendance à se généraliser dans bon nombre d&#8217;applications et surtout elle a pris le pas sur l&#8217;orientation template de Piwigo.<br />
Il s&#8217;en suit des incohérences entre les templates fournis par les thèmes, incohérences devenant bloquantes parfois pour certains plugins.<br />
Prenons un exemple récent :  RV Maps and Earth (un fabuleux plugin de rvelices) ne fonctionne pas actuellement avec le thème Luciano.<br />
Même si cela sera sans doute vite corrigé, ce type d&#8217;incohérences conduit :<br />
- soit à multiplier les plugins afin de répondre aux problématiques créées par un thème (et parfois tous les thèmes enfants) et pour s&#8217;en convaincre il suffit de chercher un plugin de WordPress;<br />
- soit à faire évoluer le thème et vous faire perdre vos adaptations.</p>
<p>Si les thèmes parents/enfants se généralisent, il semble évident que les T-E. n&#8217;auront plus lieu d&#8217;être. Cependant, ceux-ci permettaient de présenter vos pages sur la base de conditions totalement originales comme une catégorie spéciale ou un lien permanent (permalink).<br />
C&#8217;est là qu&#8217;intervient la <a href="http://www.vdigital.org/sharing/2010/07/la-mise-en-oeuvre-de-getparam/" title="La mise en œuvre de getParam()">fonction getParam()</a>.<br />
Exemples:<br />
- getParam(&#8216;most_recent&#8217;) permettra de sélectionner un template particulier aux images récentes peut-être,<br />
- getParam(&#8216;category/Paris&#8217;) permettra d&#8217;ajouter un script particulier,<br />
etc.</p>
<p>Comment coder un tel template (<a href="http://www.vdigital.org/sharing/2010/07/concevoir-des-templates-evolutifs/" title="Concevoir des templates évolutifs" target="_blank">évolutif</a>) dans son thème ?<br />
Dans mon_theme/template/ par exemple pour créer un header.tpl évolutif&#8230;</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'recent_pics'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">'recent.tpl'</span> assign<span style="color: #339933;">=</span>RECENT_BANNER<span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;../../default/template/header.tpl&quot;</span> PAGE_BANNER<span style="color: #339933;">=</span><span style="color: #000088;">$RECENT_BANNER</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span> le path doit être relatif depuis themes<span style="color: #339933;">/</span>mon_theme<span style="color: #339933;">/</span>template<span style="color: #339933;">/</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;../../default/template/header.tpl&quot;</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category/Paris'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#123;</span>known_script id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;jquery&quot;</span> src<span style="color: #339933;">=</span><span style="color: #000088;">$ROOT_URL</span><span style="color: #339933;">|@</span>cat<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;themes/default/js/jquery.packed.js&quot;</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#123;</span>known_script id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;topbar&quot;</span> src<span style="color: #339933;">=</span><span style="color: #000088;">$ROOT_URL</span><span style="color: #339933;">|@</span>cat<span style="color: #339933;">:</span><span style="color: #0000ff;">&quot;local/js/topbar.js&quot;</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span></div></div>
<p>Explications du code ci-dessus:<br />
- si l&#8217;url contient recent_pics, on génèrera une bannière spécifique.<br />
- si l&#8217;url contient un lien permanent de catégorie vers « Paris » un script sera ajouté à la page&#8230; avant le &lt;/head> (Page de miniatures et page picture).</p>
<p>Cette astuce permet de traiter la grande majorité des cas de figure traités par les T-E actuels de Piwigo.</p>
<blockquote><p>
En attendant, la fin programmée des T-E. les points restants en leur faveur sont:<br />
1 &#8211; La sécurité (les curieux ne pourront pas découvrir l&#8217;emplacement de votre T-E. et, du fait, son contenu avant inclusion dans la page).<br />
2 &#8211; La modification globale (Ajout d&#8217;éléments communs à toutes les pages et quel que soit le thème).<br />
3 &#8211; La réduction du besoin de plugin (pour tous ceux qui ne maîtrisent pas assez le php), la modification globale (sans critère) permet de s&#8217;éviter d&#8217;avoir à coder un plugin personnel (lequel serait plus complexe à maintenir).</p></blockquote>
<p>Pour la grande majorité des débutants, espérons que les T-E. (templates-extensions) aient la vie dure, même si leur utilisation semble complexe au début.</p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=1030';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/08/saffranchir-des-templates-extensions/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Concevoir des templates évolutifs</title>
		<link>http://www.vdigital.org/sharing/2010/07/concevoir-des-templates-evolutifs/</link>
		<comments>http://www.vdigital.org/sharing/2010/07/concevoir-des-templates-evolutifs/#comments</comments>
		<pubDate>Sat, 31 Jul 2010 07:34:53 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[Piwigo]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=1006</guid>
		<description><![CDATA[Piwigo utilise un système de templates pour générer des pages web. Un template est un morceau de code HTML dans lequel seuls quelques éléments d&#8217;information seront modifiés d&#8217;une utilisation à l&#8217;autre. Un template simplifie la plupart des adaptations. Par contre, ce système pourrait vous priver d&#8217;une partie des évolutions de Piwigo. Si vous adaptez une [...]]]></description>
			<content:encoded><![CDATA[<p>Piwigo utilise un système de templates pour générer des pages web. Un template est un morceau de code HTML dans lequel seuls quelques éléments d&#8217;information seront modifiés d&#8217;une utilisation à l&#8217;autre. Un template simplifie la plupart des adaptations.<br />
Par contre, ce système pourrait vous priver d&#8217;une partie des évolutions de Piwigo. Si vous adaptez une partie d&#8217;une page web, et si celle-ci a besoin d&#8217;être complétée ou transformée par l&#8217;équipe de conception, alors votre adaptation pourrait masquer les nouveautés. </p>
<p>En comparaison, une application comme WordPress sans template vous privera des évolutions de thème, ou les évolutions effaceront toutes vos adaptations. En général les applications, qui n&#8217;utilisent pas de templates, auront beaucoup de thèmes mais ceux-ci resteront sans évolution.</p>
<p>Assurément, il n&#8217;y aurait pas de solution idéale.<br />
Nous allons voir pour Piwigo comment coder un template évolutif dans un thème personnel.<span id="more-1006"></span><br />
Ci-dessous vous trouverez un exemple d&#8217;un header.tpl évolutif&#8230;</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">'hello.inc.tpl'</span> assign<span style="color: #339933;">=</span>BANNER<span style="color: #009900;">&#125;</span> <br />
&nbsp; <span style="color: #009900;">&#123;</span>assign <span style="color: #000000; font-weight: bold;">var</span><span style="color: #339933;">=</span>HOME_BANNER value<span style="color: #339933;">=</span><span style="color: #000088;">$PAGE_BANNER</span><span style="color: #339933;">|</span>cat<span style="color: #339933;">:</span><span style="color: #000088;">$BANNER</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">'topbar.inc.tpl'</span> assign<span style="color: #339933;">=</span>TOPBAR<span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;../../default/template/header.tpl&quot;</span> theSwiftHeader<span style="color: #339933;">=</span><span style="color: #000088;">$TOPBAR</span> PAGE_BANNER<span style="color: #339933;">=</span><span style="color: #000088;">$HOME_BANNER</span><span style="color: #009900;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span> le path doit être relatif depuis themes<span style="color: #339933;">/</span>xxxx<span style="color: #339933;">/</span>template<span style="color: #339933;">/</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span>html_head<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>style type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text/css&quot;</span> src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">{$ROOT_URL}</span>themes/{<span style="color: #006699; font-weight: bold;">$themeconf</span>.id}/css/extension.css&quot;</span><span style="color: #009900;">&#125;</span><span style="color: #0000ff;">&quot;&gt;<br />
&nbsp; {/html_head}</span></div></div>
<p><strong><br />
Explications du code ci-dessus :</strong></p>
<p>  {include file=&#8217;hello.inc.tpl&#8217; assign=BANNER}<br />
Le code html contenu dans votre thème ./template/hello.inc.tpl sera affecté à la variable BANNER (Un logo par exemple).</p>
<p>  {assign var=HOME_BANNER value=$PAGE_BANNER|cat:$BANNER}<br />
La variable HOME_BANNER va recevoir la concaténation (cat) de la bannière standard ($PAGE_BANNER) avec celle produite par hello.inc.tpl</p>
<p>  {include file=&#8217;topbar.inc.tpl&#8217; assign=TOPBAR}<br />
Là encore, du code html contenu dans votre thème ./template/topbar.inc.tpl sera affecté à la variable TOPBAR (Des liens du site vers votre forum, votre blog, etc).</p>
<p>{include file=&nbsp;&raquo;../../default/template/header.tpl&nbsp;&raquo; theSwiftHeader=$TOPBAR PAGE_BANNER=$HOME_BANNER} </p>
<blockquote><p>C&#8217;est là l&#8217;essentiel, au lieu de copier le header standard, le thème va l&#8217;inclure et ainsi profiter de ses évolutions.<br />
Mais également la variable theSwiftHeader va prendre la valeur de TOPBAR (nos liens)<br />
et la variable PAGE_BANNER prendra la valeur de HOME_BANNER (notre bannière avec son logo).<br />
En incluant le header standard, le thème continuera à bénéficier des évolutions du header standard, tout en pouvant être différent.
</p></blockquote>
<p>C&#8217;est assez simple, mais surtout cela fonctionne bien.</p>
<p>Une seule réserve: lors de l&#8217;include du template d&#8217;origine faites attention à décrire le chemin relatif à partir de themes/xxxx/template/</p>
<p>  {html_head}<br />
    &lt;style type=&nbsp;&raquo;text/css&nbsp;&raquo; src=&nbsp;&raquo;{$ROOT_URL}themes/{$themeconf.id}/css/extension.css&nbsp;&raquo;}&nbsp;&raquo;><br />
  {/html_head}<br />
Ajout d&#8217;un style complémentaire ou plus avant la balise &lt;/head> (Cf. <a href="http://www.vdigital.org/sharing/2010/07/javascript-interprete-inutilement/" title="Javascript interprété inutilement" target="_blank">Javascript interprété inutilement</a>)</p>
<blockquote><p>Remarque: Cette astuce n&#8217;est qu&#8217;une application des fonctionnalités de Smarty (le moteur de templates utilisé par Piwigo)</p></blockquote>
<p>.</p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=1006';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/07/concevoir-des-templates-evolutifs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>La mise en œuvre de getParam()</title>
		<link>http://www.vdigital.org/sharing/2010/07/la-mise-en-oeuvre-de-getparam/</link>
		<comments>http://www.vdigital.org/sharing/2010/07/la-mise-en-oeuvre-de-getparam/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 20:57:44 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[Fonctions]]></category>
		<category><![CDATA[getParam]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Piwigo]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=993</guid>
		<description><![CDATA[Dans le cadre de Piwigo, la fonction getParam() expliquée dans cet autre billet va nous permettre de présenter des images en fonction de différents paramètres. Avant tout, nous allons étudier où introduire cette fonction dans Piwigo. Cette fonction pourrait avoir sa place à plusieurs endroits, essentiellement dans : - un plugin, et plus précisément plugins/PersonalPlugin/main.inc.php [...]]]></description>
			<content:encoded><![CDATA[<p>Dans le cadre de Piwigo, la fonction getParam() expliquée dans cet <a href="http://www.vdigital.org/sharing/2010/07/bons-arguments/" title="Avec de bons arguments">autre billet</a> va nous permettre de présenter des images en fonction de différents paramètres.</p>
<p>Avant tout, nous allons étudier où introduire cette fonction dans Piwigo. Cette fonction pourrait avoir sa place à plusieurs endroits, essentiellement dans :<br />
- un plugin, et plus précisément plugins/PersonalPlugin/main.inc.php (également éditable en ligne par LocalFiles Editor), ou<br />
- un thème, et plus précisément dans un themeconf.inc.php (mais ceux-ci ne sont pas éditables en ligne à ce jour).</p>
<p>Avec de bons arguments, je considère que sa place est dans le themeconf.inc.php, car l&#8217;appel de cette fonction concerne l&#8217;affichage final.<br />
Si nous placions cette fonction dans un plugin, il ne faudrait jamais perdre de vue que le plugin devrait rester actif.<br />
En le plaçant dans la configuration du thème, nous n&#8217;aurons qu&#8217;à créer des templates sur lesquels nous souhaitons agir différement.</p>
<p>Exemples dans un thème personnel.<span id="more-993"></span></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #666666; font-style: italic;">/*<br />
Theme Name: Mon thème<br />
*/</span><br />
<span style="color: #000088;">$themeconf</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><br />
&nbsp; <span style="color: #0000ff;">'theme'</span> &nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mon_theme'</span><span style="color: #339933;">,</span><br />
&nbsp; <span style="color: #0000ff;">'parent'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">,</span><br />
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span>PHPWG_ROOT_PATH <span style="color: #339933;">.</span><span style="color: #0000ff;">'themes/mon_theme/include/functions.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>dès lors dans themes/mon_theme/include/functions.inc.php</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/function_exists"><span style="color: #990000;">function_exists</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'getParam'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">function</span> getParam<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$def</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IN_ADMIN'</span><span style="color: #009900;">&#41;</span> and IN_ADMIN<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$def</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_REQUEST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/is_string"><span style="color: #990000;">is_string</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#41;</span> and <a href="http://www.php.net/stripos"><span style="color: #990000;">stripos</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$k</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[^0-9a-z\-_\.]+/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$k</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Remove anything but 0-9,a-z,-_</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// permalink, category_url_style in 'id-name', picture_url_style in id-file</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$def</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span> <br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>Ensuite il suffira de copier et de modifier les templates standards que l&#8217;on souhaite modifier venant de themes/default/template/ dans themes/mon_theme/template/<br />
par exemple: <strong>thumbnails.tpl</strong> afin d&#8217;y remplacer</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$thumbnail</span><span style="color: #339933;">.</span>NB_COMMENTS<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>span <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{if 0==<span style="color: #006699; font-weight: bold;">$thumbnail</span>.NB_COMMENTS}zero {/if}nb-comments&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>br<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #000088;">$pwg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">l10n_dec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%d comments'</span><span style="color: #339933;">,</span><span style="color: #000088;">$thumbnail</span><span style="color: #339933;">.</span>NB_COMMENTS<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span></div></div>
<p>par</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category'</span><span style="color: #009900;">&#41;</span> and <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$thumbnail</span><span style="color: #339933;">.</span>NB_COMMENTS<span style="color: #009900;">&#41;</span> and <span style="color: #000088;">$thumbnail</span><span style="color: #339933;">.</span>NB_COMMENTS <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;</span>span <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;nb-comments&quot;</span><span style="color: #339933;">&gt;&lt;</span>br<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #000088;">$pwg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">l10n_dec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%d comments'</span><span style="color: #339933;">,</span><span style="color: #000088;">$thumbnail</span><span style="color: #339933;">.</span>NB_COMMENTS<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #339933;">&lt;/</span>span<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span></div></div>
<p>Ainsi le nombre de commentaires ne sera plus indiqué que sur les pages de catégories. Ce nombre ne figurera donc pas dans les résultats de recherches, les pages de miniatures découvertes par les tags, ou les pages des catégories spéciales.</p>
<p>Autre exemple, <strong>picture.tpl</strong> afin d&#8217;y remplacer</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339933;">&lt;</span>hr <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;separation&quot;</span><span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$COMMENT_COUNT</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;comments&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <span style="color: #000088;">$COMMENT_COUNT</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$pwg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">l10n_dec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%d comments'</span><span style="color: #339933;">,</span><span style="color: #000088;">$COMMENT_COUNT</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>h3<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$navbar</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">'navigation_bar.tpl'</span><span style="color: #339933;">|@</span>get_extent<span style="color: #339933;">:</span><span style="color: #0000ff;">'navbar'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">'comment_list.tpl'</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_add</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>form &nbsp;method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$comment_add</span>.F_ACTION}&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;filter&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;addComment&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>fieldset<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>legend<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'Add a comment'</span><span style="color: #339933;">|@</span>translate<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>legend<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <span style="color: #000088;">$comment_add</span><span style="color: #339933;">.</span>SHOW_AUTHOR<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'Author'</span><span style="color: #339933;">|@</span>translate<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;author&quot;</span><span style="color: #339933;">&gt;&lt;/</span>label<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'Comment'</span><span style="color: #339933;">|@</span>translate<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;</span>textarea name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contentid&quot;</span> rows<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;5&quot;</span> cols<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;80&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$comment_add</span><span style="color: #339933;">.</span>CONTENT<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>textarea<span style="color: #339933;">&gt;&lt;/</span>label<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;key&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$comment_add</span>.KEY}&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>input <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{'Submit'|@translate}&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;/</span>fieldset<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span>comments<span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span></div></div>
<p>par</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category'</span><span style="color: #009900;">&#41;</span> and <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$COMMENT_COUNT</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span> comments only within a category<span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;</span>hr <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;separation&quot;</span><span style="color: #339933;">&gt;</span><br />
<br />
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;comments&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <span style="color: #000088;">$COMMENT_COUNT</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$pwg</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">l10n_dec</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%d comment'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%d comments'</span><span style="color: #339933;">,</span><span style="color: #000088;">$COMMENT_COUNT</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>h3<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$navbar</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">'navigation_bar.tpl'</span><span style="color: #339933;">|@</span>get_extent<span style="color: #339933;">:</span><span style="color: #0000ff;">'navbar'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">include</span> <a href="http://www.php.net/file"><span style="color: #990000;">file</span></a><span style="color: #339933;">=</span><span style="color: #0000ff;">'comment_list.tpl'</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment_add</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>form &nbsp;method<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post&quot;</span> action<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$comment_add</span>.F_ACTION}&quot;</span> <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;filter&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;addComment&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;</span>fieldset<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>legend<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'Add a comment'</span><span style="color: #339933;">|@</span>translate<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>legend<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #b1b100;">if</span> <span style="color: #000088;">$comment_add</span><span style="color: #339933;">.</span>SHOW_AUTHOR<span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'Author'</span><span style="color: #339933;">|@</span>translate<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;text&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;author&quot;</span><span style="color: #339933;">&gt;&lt;/</span>label<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>label<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'Comment'</span><span style="color: #339933;">|@</span>translate<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;</span>textarea name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;content&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;contentid&quot;</span> rows<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;5&quot;</span> cols<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;80&quot;</span><span style="color: #339933;">&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #000088;">$comment_add</span><span style="color: #339933;">.</span>CONTENT<span style="color: #009900;">&#125;</span><span style="color: #339933;">&lt;/</span>textarea<span style="color: #339933;">&gt;&lt;/</span>label<span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;hidden&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;key&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{<span style="color: #006699; font-weight: bold;">$comment_add</span>.KEY}&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; &nbsp; <span style="color: #339933;">&lt;</span>input <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;submit&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;{'Submit'|@translate}&quot;</span><span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;/</span>fieldset<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #339933;">&lt;/</span>form<span style="color: #339933;">&gt;</span><br />
&nbsp; <span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span><br />
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span><br />
<span style="color: #009900;">&#123;</span><span style="color: #339933;">/</span><span style="color: #b1b100;">if</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#123;</span><span style="color: #339933;">*</span>category<span style="color: #339933;">*</span><span style="color: #009900;">&#125;</span></div></div>
<p>Et cette fois, il ne s&#8217;agira pas du nombre mais des commentaires eux-mêmes qui ne seront pas affichés sur la page picture dès lors que l&#8217;image n&#8217;est pas présentée au travers de sa catégorie.</p>
<p>Ces 2 exemples simples de l&#8217;utilisation de getParam() ne sont que des préludes à d&#8217;autres usages également très intéressants que nous découvrirons prochainement.</p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=993';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/07/la-mise-en-oeuvre-de-getparam/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Avec de bons arguments</title>
		<link>http://www.vdigital.org/sharing/2010/07/bons-arguments/</link>
		<comments>http://www.vdigital.org/sharing/2010/07/bons-arguments/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 17:29:27 +0000</pubDate>
		<dc:creator>VDigital</dc:creator>
				<category><![CDATA[Astuces]]></category>
		<category><![CDATA[Fonctions]]></category>
		<category><![CDATA[getParam]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Piwigo]]></category>

		<guid isPermaLink="false">http://www.vdigital.org/sharing/?p=972</guid>
		<description><![CDATA[Pour une utilisation dans Piwigo, mais cela pourrait également convenir à d&#8217;autres logiciels, je vous propose de découvrir une petite fonction PHP toute simple. if &#40; !function_exists&#40; 'getParam' &#41;&#41; &#123; &#160; function getParam&#40;$name, $def = false&#41; &#123; &#160; &#160; if &#40;defined&#40;'IN_ADMIN'&#41; and IN_ADMIN&#41; return $def; &#160; &#160; foreach &#40; $_REQUEST as $k =&#62; $v &#41; [...]]]></description>
			<content:encoded><![CDATA[<p>Pour une utilisation dans Piwigo, mais cela pourrait également convenir à d&#8217;autres logiciels, je vous propose de découvrir une petite fonction PHP toute simple.</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><a href="http://www.php.net/function_exists"><span style="color: #990000;">function_exists</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'getParam'</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">function</span> getParam<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$def</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/defined"><span style="color: #990000;">defined</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'IN_ADMIN'</span><span style="color: #009900;">&#41;</span> and IN_ADMIN<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$def</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_REQUEST</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$k</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$v</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <a href="http://www.php.net/is_string"><span style="color: #990000;">is_string</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$k</span><span style="color: #009900;">&#41;</span> and <a href="http://www.php.net/stripos"><span style="color: #990000;">stripos</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$k</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">return</span> <a href="http://www.php.net/trim"><span style="color: #990000;">trim</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[^0-9a-z\-_\.]+/i&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$k</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Remove anything but 0-9,a-z,-_ </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// permalink, category_url_style in 'id-name', picture_url_style in id-file</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$def</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Avant de l&#8217;utiliser, je me propose une explication minimaliste.<br />
Cette fonction PHP fait appel à un preg_replace et une expression rationnelle.<br />
L&#8217;objectif est de conserver uniquement les caractères comme le point, la virgule, les 2 tirets (- et _), les lettres (minuscules ou majuscules, mais pas les lettres accentuées) et les chiffres.<br />
Par exemple, supposons que nous ayons ceci :</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'avant'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Quel 1er_paramètre ? Un argument'</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> getParam<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'avant'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>alors nous devrions avoir en retour :</p>
<blockquote><p>Quel 1er_paramtre &nbsp; Un argument</p></blockquote>
<p>L&#8217;intérêt sera de sécuriser votre site lors de l&#8217;appel à cette fonction.</p>
<p>Découvrir la <a href="http://www.vdigital.org/sharing/2010/07/la-mise-en-oeuvre-de-getparam/" title="La mise en œuvre de getParam()">mise en œuvre</a> de cette fonction.</p>
<div style="float:right; margin-left:10px;">	
			<a class="LikeBotButton" />
				<script type="text/javascript">
					likebot_bgcolor = '';
					likebot_url = 'http://www.vdigital.org/sharing/?p=972';
					likebot_type = 'horizontal_thumbs';
				</script>
				<script src="http://i.likebot.com/button.js" type="text/javascript"></script>
			</a>
			
			</div>]]></content:encoded>
			<wfw:commentRss>http://www.vdigital.org/sharing/2010/07/bons-arguments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

