<?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>Grummfy&#039;s project &#187; Développement</title>
	<atom:link href="http://grummfy.be/blog/cat/dev/feed" rel="self" type="application/rss+xml" />
	<link>http://grummfy.be/blog</link>
	<description>Mes projets, mes rêves, mes envies, ...</description>
	<lastBuildDate>Mon, 02 Jan 2012 00:03:47 +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>Git fusion de sous répertoire et de l&#8217;historique dans un autre dépôt</title>
		<link>http://grummfy.be/blog/389#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/389#comments</comments>
		<pubDate>Mon, 02 Jan 2012 00:03:47 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[FSB]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[trucs et astuces]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=389</guid>
		<description><![CDATA[Cet article explique comment fusionner des sous répertoire d'un dépôt existant dans un autre en en gardant l'historique.]]></description>
			<content:encoded><![CDATA[<p>Dans le cadre du projet <a title="Fire Soft Board" href="http://grummfy.be/blog/key/fsb">Fire Soft Board</a> il a été décidé de créer un dépôts git dédié aux traductions. Pour ce faire il a fallut reprendre els fichiers mais aussi les placer dans des sous répertoires spécifiques. Voici la démarche effectuée.<br />
<span id="more-389"></span><br />
On désire prendre certaines sous répertoires et les transposer dans le nouveau dépôts.<br />
/Fire-Soft-Board-2/tpl/WhiteSummer/img/fr &#8211;&gt; pack/fr/tpl/WhiteSummer/img/fr<br />
/Fire-Soft-Board-2/lang/fr &#8211;&gt; pack/fr/lang/fr</p>
<ol>
<li>Clone du dépôt principal<br />
<code>git clone https://github.com/FSB/Fire-Soft-Board-2.git<br />
cd Fire-Soft-Board-2</code></li>
<li>Nous avons deux sous répertoires, nous créons donc deux clone local<br />
<code>cd ..<br />
git clone Fire-Soft-Board-2 fsb2-tpl-fr<br />
git clone Fire-Soft-Board-2 fsb2-lang-fr</code></li>
<li>Il faut désormais nettoyer les fichiers mais aussi l&#8217;historique des commits dont nous n&#8217;avons plus besoin. Pour cela, nous allons simplement dire à git de ne garder que les sous répertories dont nous avons besoin.<br />
<code>cd fsb2-lang-fr<br />
git checkout dev<br />
git filter-branch --subdirectory-filter lang/fr HEAD<br />
git gc --prune --aggressive<br />
cd ..<br />
cd fsb2-tpl-fr<br />
git checkout dev<br />
git filter-branch --subdirectory-filter tpl/WhiteSummer/img/fr HEAD<br />
git gc --prune --aggressive<br />
cd ..<br />
</code><br />
git gc permet de nettoyer l&#8217;historique et de compacter l&#8217;index. Cela évite ainsi de potentiel mauvaises surprise dans les logs.</li>
<li>Il faut désormais fusionner ces fichiers ainsi que l&#8217;historique qui va avec dans le dépôt des traductions. Commençons par cloner celui-ci.<code>git clone https://github.com/FSB/FSB2-language-packs.git<br />
cd FSB2-language-packs/</code></li>
<li>Fusionnons les ressources lié au templates<code>git remote add -f tpl ../FSB2-tpl-fr/<br />
git merge -s ours --no-commit tpl/dev<br />
git read-tree --prefix=pack/fr/tpl/WhiteSummer/img/fr -u tpl/dev<br />
git commit -m'Ajout des sources et de l''historique du pack de langue fr des templates'<br />
</code>On effectue un merge mais sans commiter. En mode de merging, on dit que le merge doit s&#8217;effectuer non pas sur la base mais sur un sous répertoire précis.</li>
<li>Ensuite, on fait de même pour la traductions en elle-même.<code>git remote add -f lang ../FSB2-lang-fr/<br />
git merge -s ours --no-commit lang/dev<br />
git read-tree --prefix=pack/fr/lang/fr -u lang/dev<br />
git commit -m'Ajout des sources et de l''historique du pack de langue fr'<br />
</code></li>
<li>On finit par un petit nettoyage<code>git gc<br />
git remote rm lang<br />
git remote rm tpl</code></li>
</ol>
<p>Pour aller plus loin :</p>
<p>http://progit.org/book/fr/ch6-4.html</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/389/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Création de nouveau formulaire facilement avec Zend Form Maker</title>
		<link>http://grummfy.be/blog/381#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/381#comments</comments>
		<pubDate>Sat, 29 Oct 2011 22:29:52 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=381</guid>
		<description><![CDATA[La création de formulaire avec zend framework peut être facilitée grâce à un petit développement : Zend Form Maker. Projet disponible sur github. À la base créer pour des besoins scolaires, sarlak a eu la bonne idée de rendre le dev open source sous licence GPL 3.0. Le but du logiciel est de permettre via [...]]]></description>
			<content:encoded><![CDATA[<p>La création de formulaire avec zend framework peut être facilitée grâce à un petit développement : Zend Form Maker. Projet disponible sur github. À la base créer pour des besoins scolaires, sarlak a eu la bonne idée de rendre le dev open source sous licence GPL 3.0.</p>
<p>Le but du logiciel est de permettre via une interface très simple d&#8217;accès, de créer des formulaires et ensuite de forger une classe PHP, basé sur zend framework afin d&#8217;obtenir un formulaire tout frais moulu. Ultra pratique, et ultra simple, et surtout cela fait gagner un temps de dingue!</p>
<p>Pour l&#8217;installer, il vous faut de quoi faire fonctionner zend framework (celui-ci doit être installé). Sous Unix cela donnera ceci :<br />
<code><br />
git clone https://github.com/sarlak/Zend-Form-Maker.git<br />
ln -s pathToYourZFLibrary<br />
chmod 0777 Zend-Form-Maker/public/resources/xml<br />
chmod 0777 Zend-Form-Maker/public/resources/form_made<br />
</code></p>
<p>Bien entendu, à peu de choses près ceci est adaptable sous MS-Windows</p>
<p>Pour créer votre premier formulaire, il vous suffit de vous rendre sur l&#8217;URL adéquate, aller sur &laquo;&nbsp;form list&nbsp;&raquo; et &laquo;&nbsp;Bazinga!&nbsp;&raquo;. Une <a href="http://demo.zfm.matthieudiblasio.ch/" title="démo" target="_blank">démo</a> existe en ligne!</p>
<p>Une petite capture d&#8217;écran :<br />
<a href="http://grummfy.be/blog/381/capture-zend-form-maker-v1-0-mozilla-firefox" rel="attachment wp-att-383"><img src="http://grummfy.be/blog/wp/wp-content/uploads/2011/10/Capture-Zend-Form-Maker-v1.0-Mozilla-Firefox-300x185.png" alt="" title="Capture-Zend Form Maker v1.0" width="300" height="185" class="aligncenter size-medium wp-image-383" /></a></p>
<p>À noter que j&#8217;ai corrigé un ou deux petits trucs qui me dérangeaient, il y a un bout de temps.</p>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;linkname=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F381&amp;title=Cr%C3%A9ation%20de%20nouveau%20formulaire%20facilement%20avec%20Zend%20Form%20Maker" id="wpa2a_2"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/381/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git, gitolite et mutualisé OVH</title>
		<link>http://grummfy.be/blog/368#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/368#comments</comments>
		<pubDate>Wed, 10 Aug 2011 21:46:37 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[OVH]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=368</guid>
		<description><![CDATA[Pouvoir utilisé gitolite sur un hébergement mutualisé OVH.]]></description>
			<content:encoded><![CDATA[<p>Hello,<br />
Sur les mutualisés OVH, la version fournie de git est plus qu’out-of-date : version 1.4.4. Ceci signifie impossibilité d&#8217;installé des outils tels que gitolite ou inferno. Ce billet est l&#8217;occasion d&#8217;un guide pour installer gitolite.</p>
<p>Le guide suivant a été rédigé sur un compte OVH pro, donc avec accès un ssh. En utilisant git 1.7.6 et gitolite 2.0.3. L&#8217;ensemble exécuter sur une machine Linux.</p>
<h2>Téléchargement</h2>
<p>La première étape, consiste a récupérer les différentes archives nécessaires, a savoir git et gitolite.</p>
<p>Pour git, il vous suffit de prendre la dernière version http://git-scm.com/download.</p>
<p>Pour gitolite, il suffit d&#8217;utiliser git!</p>
<pre>git clone https://github.com/sitaramc/gitolite.git</pre>
<h2>Préparation de l&#8217;environnement</h2>
<p>Nous allons installer les exécutables de git dans ~/opt/bin. De ce fait ajoutons le path a l&#8217;utilisateur ssh.<br />
Ouvrir ~/.bash_profile et modifier le path. Pour ce faire ajouter, avant le export :</p>
<pre>PATH=$HOME/opt/bin:$PATH</pre>
<h2>Installation de git</h2>
<p>Uploader votre archive dans un dossier (ici ~/opt/src/). En mode console par ssh, donc sur le serveur, ouvrir l&#8217;archive et compiler les sources.</p>
<pre>tar -xvzf git-1.7.6.tar.gz
cd git-1.7.6
./configure --prefix=$HOME/opt --without-tcltk
make
make install</pre>
<p>Une fois compilé, les exécutables seront présents dans ~/opt/bin. Pour vérifier, que tout est bien en place :</p>
<pre>git --version</pre>
<h2>Gitolite</h2>
<p>Il faut se rendre dans le répertoire du clone du repository. <strong>Tout s&#8217;exécute uniquement sur la machine cliente (donc pas chez ovh)</strong>. Si l&#8217;utilisateur est &laquo;&nbsp;toto&nbsp;&raquo;, l&#8217;host &laquo;&nbsp;tata.com&nbsp;&raquo; et le futur administrateur &laquo;&nbsp;moiadmin&nbsp;&raquo;</p>
<pre>./src/gl-easy-install toto tata.com moiadmin</pre>
<p>Il suffit de faire enter. Dans tous les cas (mise à jour du script compris!), le fait de réexecuter la commande permet de rectifier les erreurs éventuelles. À l&#8217;étape de l&#8217;édition du fichier de configuration, il faut modifier la variable $GIT_PATH pour quelle pointe vers le répertoire contenant notre git. Dans notre cas :</p>
<pre>$GIT_PATH = $ENV{HOME} . "/opt/bin/";</pre>
<h2>Configuration de Gitolite</h2>
<p>La configuration de gitolite est simple et s&#8217;exécute avec &#8230; git! En principe, un répertoire reprenant la config a été créé sur votre home dans ~/gitolite-admin, dans le cas contraire, il vous suffit de faire</p>
<pre>git clone gitolite:gitolite-admin.git</pre>
<p>Pour ajouter des clefs ssh, il suffit de les mettre dans le dossier keys. Pour ce qui est de la config, il vous suffit d&#8217;éditer le fichier gitolite.conf et puis de faire</p>
<pre>git add conf/gitolite.conf
git commit -m 'update config'
git push</pre>
<p>Et c&#8217;est tout!</p>
<p>Sources :<br />
<a href="http://forum.ovh.com/showthread.php?t=71543" target="_blank">http://forum.ovh.com/showthread.php?t=71543</a><br />
<a href="http://blog.lyrixx.info/admin-sys/installer-gitolite-sur-une-machine-debian-5/" target="_blank">http://blog.lyrixx.info/admin-sys/installer-gitolite-sur-une-machine-debian-5/</a><br />
<a href="http://sitaramc.github.com/gitolite/doc/gitolite.rc.html" target="_blank" class="broken_link">http://sitaramc.github.com/gitolite/doc/gitolite.rc.html</a><br />
<a href="http://sitaramc.github.com/gitolite/doc/gitolite.conf.html#_groups" target="_blank" class="broken_link">http://sitaramc.github.com/gitolite/doc/gitolite.conf.html#_groups</a></p>
<p>Pour vos interfaces web, trois solutions correctes :<br />
<a href="http://hjemli.net/git/cgit/" target="_blank">CGit</a><br />
<a href="http://viewgit.sourceforge.net/" target="_blank">View Git</a><br />
<a href="http://projects.ceondo.com/p/indefero/" target="_blank">Indefero</a></p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/368/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ZF : ACL et ressources multiple</title>
		<link>http://grummfy.be/blog/360#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/360#comments</comments>
		<pubDate>Wed, 13 Oct 2010 21:19:21 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=360</guid>
		<description><![CDATA[Utiliser les ACL dans Zend Framework en ajoutant le support de ressource multiple via '*'.]]></description>
			<content:encoded><![CDATA[<p>Lorsque l&#8217;on utilise des ACL dans Zend Framework, une chose assez embêtante est de devoir tout mettre en place<sup class='footnote'><a href='#fn-360-1' id='fnref-360-1'>1</a></sup>. Pour ma part, j&#8217;ai par facilité voulu ajouté le support de ressource multiple.</p>
<p>Avant de commencer, il convient de contextualisé les choses, les ACL de ZF pouvant être utilisé de bien des manière.</p>
<p>Dans le cas qui nous intéresse, j&#8217;ai simplement défini ceci :</p>
<ul>
<li>les ressources<sup class='footnote'><a href='#fn-360-2' id='fnref-360-2'>2</a></sup> = module.controller</li>
<li>les privilèges<sup class='footnote'><a href='#fn-360-3' id='fnref-360-3'>3</a></sup> = action</li>
</ul>
<p>Ce que je voulait c&#8217;est pouvoir définir une ressource pour tous les contrôleurs. La syntaxe évidente qu&#8217;il m&#8217;est venu est la suivante : module.*</p>
<p>Dans ma classe qui étend Zend_ACL j&#8217;ai simplement fait ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isAllowed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$privilege</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span>
    		<span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">isAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #339933;">,</span> <span style="color: #000088;">$privilege</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    	<span style="color: #000088;">$resources</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getResourcesPossibility<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resources</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span>
    	<span style="color: #009900;">&#123;</span>
    		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>has<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> parent<span style="color: #339933;">::</span><span style="color: #004000;">isAllowed</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$role</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #339933;">,</span> <span style="color: #000088;">$privilege</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    		<span style="color: #009900;">&#123;</span>
    			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    		<span style="color: #009900;">&#125;</span>
    	<span style="color: #009900;">&#125;</span>
    	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getResourcesPossibility<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    	<span style="color: #000088;">$ret</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span>
    	<span style="color: #009900;">&#123;</span>
    		<span style="color: #000088;">$resources</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resource</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    		<span style="color: #000088;">$cptRessources</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$resources</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cptRessources</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
    		<span style="color: #009900;">&#123;</span>
    			<span style="color: #000088;">$resources</span><span style="color: #009900;">&#91;</span> <span style="color: #000088;">$cptRessources</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'*'</span><span style="color: #339933;">;</span>
    		<span style="color: #009900;">&#125;</span>
    		<span style="color: #000088;">$ret</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$resources</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    	<span style="color: #009900;">&#125;</span>
    	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$ret</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ceci peut bien entendu être enrichi mais permet au moins de profiter de l&#8217;utilisation des ACL dans le menu et sur des aides de vue qui serait éventuellement définie comme expliqué dans la plupart des tutoriaux.</p>
<p>Pour en savoir plus sur les ACL et Zend Framework, je vous renvoi a un très bon <a href="http://julien-pauli.developpez.com/tutoriels/zend-framework/atelier/aclmvc/" target="_blank">article</a>.</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-360-1'>surtout si on utilise l&#8217;aide de vue pour généré un menu (Zend_navigation) <span class='footnotereverse'><a href='#fnref-360-1'>&#8617;</a></span></li>
<li id='fn-360-2'>resource <span class='footnotereverse'><a href='#fnref-360-2'>&#8617;</a></span></li>
<li id='fn-360-3'>privilege <span class='footnotereverse'><a href='#fnref-360-3'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/360/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZF : module et autoloader</title>
		<link>http://grummfy.be/blog/343#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/343#comments</comments>
		<pubDate>Sun, 22 Aug 2010 22:00:55 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=343</guid>
		<description><![CDATA[Avec Zend Framework, lorsque l&#8217;on travail un projet conséquent il devient vite utile de travailler avec le mécanisme des modules. Celui-ci permet d&#8217;étendre pas mal de chose et surtout une séparation poussée en &#8230; module. Le problème de ce mécanisme1 est qu&#8217;il faut définir le chemin pour le chargement automatique à l&#8217;aide de ceci : [...]]]></description>
			<content:encoded><![CDATA[<p>Avec Zend Framework, lorsque l&#8217;on travail un projet conséquent il devient vite utile de travailler avec le mécanisme des <a href="http://framework.zend.com/manual/fr/zend.controller.modular.html" target="_blank">modules</a>. Celui-ci permet d&#8217;étendre pas mal de chose et surtout une séparation poussée en &#8230; module.</p>
<p>Le problème de ce mécanisme<sup class='footnote'><a href='#fn-343-1' id='fnref-343-1'>1</a></sup> est qu&#8217;il faut définir le chemin pour le chargement automatique à l&#8217;aide de ceci :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$autoloader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application_Module_Autoloader<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'namespace'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'SuperModule'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'basePath'</span>  <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'path to super module'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Je vous propose donc de faire une petite amélioration afin que ce chargement soit fait automatiquement.</p>
<p>Avant tout, dans votre configuration (ici en .ini) vous devez au moins avoir ceci de présent :</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">resources.frontController.moduleDirectory <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> APPLICATION_PATH </span><span style="color: #933;">&quot;/modules&quot;</span>
resources.modules <span style="color: #000066; font-weight:bold;">=</span></pre></div></div>

<p>Ensuite, à la base de chaque dossier module créer un fichier Bootstrap.php<sup class='footnote'><a href='#fn-343-2' id='fnref-343-2'>2</a></sup> :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #000000; font-weight: bold;">class</span> SuperModule_Bootstrap <span style="color: #000000; font-weight: bold;">extends</span> Grummfy_Bootstrap<span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>Et pour finir créer le fichier<sup class='footnote'><a href='#fn-343-3' id='fnref-343-3'>3</a></sup> library/Grummfy/Bootstrap.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
&nbsp;
abstract <span style="color: #000000; font-weight: bold;">class</span> Grummfy_Bootstrap <span style="color: #000000; font-weight: bold;">extends</span> Zend_Application_Bootstrap_Bootstrap
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initAutoload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$className</span> <span style="color: #339933;">=</span> <span style="color: #990000;">get_class</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$zf_namespace</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'_'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$reflector</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ReflectionClass<span style="color: #009900;">&#40;</span><span style="color: #000088;">$className</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$autoloader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application_Module_Autoloader<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'namespace'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$zf_namespace</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'basePath'</span>  <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$reflector</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getFileName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$autoloader</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-343-1'>sauf si j&#8217;ai loupé un truc&#8230; <span class='footnotereverse'><a href='#fnref-343-1'>&#8617;</a></span></li>
<li id='fn-343-2'>ne pas oublier de changer le nom du module &#8230; <span class='footnotereverse'><a href='#fnref-343-2'>&#8617;</a></span></li>
<li id='fn-343-3'>n&#8217;oubliez pas de déclarer le &laquo;&nbsp;namespace&nbsp;&raquo; Grummfy ou bien d&#8217;inclure le fichier <span class='footnotereverse'><a href='#fnref-343-3'>&#8617;</a></span></li>
</ol>
</div>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;linkname=ZF%20%3A%20module%20et%20autoloader" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F343&amp;title=ZF%20%3A%20module%20et%20autoloader" id="wpa2a_4"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/343/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZF : génération automatique du fichier de navigation et ACL</title>
		<link>http://grummfy.be/blog/333#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/333#comments</comments>
		<pubDate>Mon, 16 Aug 2010 20:47:14 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[délire]]></category>
		<category><![CDATA[jouons]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=333</guid>
		<description><![CDATA[Lors de l&#8217;utilisation du mécanisme d&#8217;ACL et de génération de menu dans Zend Framework, il est intéressant de limiter l&#8217;affichage de ce menu en utilisant les ressources et privilèges associer. Pour ma part, j&#8217;utilise un fichier XML pour construire mon menu, mon sitemap, &#8230; 1. Et comme beaucoup je génère mon projet ZF à l&#8217;aide [...]]]></description>
			<content:encoded><![CDATA[<p>Lors de l&#8217;utilisation du mécanisme d&#8217;ACL et de génération de menu dans Zend Framework, il est intéressant de limiter l&#8217;affichage de ce menu en utilisant les ressources et privilèges associer.</p>
<p>Pour ma part, j&#8217;utilise un fichier XML pour construire mon menu, mon sitemap, &#8230; <sup class='footnote'><a href='#fn-333-1' id='fnref-333-1'>1</a></sup>. Et comme beaucoup je génère mon projet ZF à l&#8217;aide de Zend_Tool. Je trouvais donc dommage de devoir réécrire pratiquement la même chose que ce que j&#8217;avais déclaré dans Zend_Tool pour reconstruire mon menu. J&#8217;ai donc décidé de <em>rapidement</em> écrire un petit script qui reprendrait le fichier XML du projet et le transformerait en menu &#8230;</p>
<p>À noter que le script devrait certainement être amélioré, mais que cela permet un gain de temps considérable &#8230;</p>
<p><a href="http://grummfy.com/download/PlusScript/zfProject2Navigation.phps" target="_blank">Téléchargement</a></p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-333-1'>Comme expliquer dans le manuel http://framework.zend.com/manual/fr/zend.navigation.html <span class='footnotereverse'><a href='#fnref-333-1'>&#8617;</a></span></li>
</ol>
</div>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;linkname=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F333&amp;title=ZF%20%3A%20g%C3%A9n%C3%A9ration%20automatique%20du%20fichier%20de%20navigation%20et%20ACL" id="wpa2a_6"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/333/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Réécriture d’URL, alias et plusieurs développeurs sur Apache</title>
		<link>http://grummfy.be/blog/321#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/321#comments</comments>
		<pubDate>Thu, 12 Aug 2010 21:07:55 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[url rewriting]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=321</guid>
		<description><![CDATA[Une solution à la problématique des réécritures d'url sans rewriteBase tout en étant utilisable par plusieurs développeurs]]></description>
			<content:encoded><![CDATA[<p>Lorsque l&#8217;on travaille à plusieurs sur un projet, c&#8217;est toujours intéressant. Malheureusement, cela peut aussi entrainer divers problèmes. Je vais tenter de vous expliquer un ﻿﻿obstacle qui peut vite devenir très chi*nt&#8230;</p>
<p>Pour présenter cette problématique, je vais prendre exemple sur ce que je développe actuellement. Le site en cours de création se base sur zend framework et nécessite une réécriture d&#8217;URL. Il faut savoir qu&#8217;Apache utilise le chemin physique<sup class='footnote'><a href='#fn-321-1' id='fnref-321-1'>1</a></sup> comme base pour calculer le chemin vers le fichier réécrit sauf si on lui précise une directive RewriteBase différente. Le problème survient à cet endroit, plusieurs développeurs entrainent plusieurs machines et donc plusieurs configurations différentes!</p>
<p>La solution de base est que chaque personne utilisant un alias Apache définit un RewriteBase. Cependant, cela veut dire qu’a chaque nouvelle version du fichier .htaccess il faut redéfinir celui-ci.</p>
<p>La réponse la plus simple consiste à utiliser un RewriteCond sur l&#8217;hostname du serveur et bien entendu à l&#8217;utiliser lors de l&#8217;accès aux tests locaux ou non &#8230;</p>
<p>Exemple de configuration :</p>
<ul>
<li> nom du serveur : grummfy</li>
<li>URL appelée : http://grummfy/serveur/dev/projet/example.com/&#8230; (Si vous utilise http://localhost/ la directive HTTP_HOST vaudra localhost)</li>
<li>ALIAS : /serveur/ =&gt; /media/data/serveur/</li>
</ul>
<p>Le fichier .htacccess contiendra ceci :<br />
<code>SetEnv APPLICATION_ENV development<br />
php_value session.auto_start 0<br />
php_flag magic_quotes_gpc off<br />
RewriteEngine On<br />
RewriteCond %{REQUEST_FILENAME} -s [OR]<br />
RewriteCond %{REQUEST_FILENAME} -l [OR]<br />
RewriteCond %{REQUEST_FILENAME} -d<br />
RewriteRule ^.*$ - [NC,L]<br />
RewriteCond %{HTTP_HOST} grummfy<br />
RewriteRule ^.*$ /serveur/dev/projet/example.com/index.php [NC,L]<br />
RewriteRule ^.*$ index.php [NC,L]</code></p>
<p>Le fait d&#8217;utiliser le rewrite flag &laquo;&nbsp;L&nbsp;&raquo; permet de sortir de la réécriture d&#8217;URL. Si le hostname du serveur n&#8217;est pas grummfy il appliquera la règle par défaut, à savoir tenter de trouver index.php dans /media/data/serveur/dev/projet/example.com/ comme si on avait effectuer un appel depuis http://media/data/serveur/dev/projet/example.com/</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-321-1'>physical-directory-path <span class='footnotereverse'><a href='#fnref-321-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/321/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Android : Tri d&#8217;une ListView tout en gardant les ids</title>
		<link>http://grummfy.be/blog/312#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/312#comments</comments>
		<pubDate>Sat, 19 Jun 2010 22:50:19 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[trucs et astuces]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=312</guid>
		<description><![CDATA[Menu ListView dans une ListActivity, trié selon un ordre alphabétique. Récupération de l'élément cliqué...]]></description>
			<content:encoded><![CDATA[<p>Durant le développement du projet <a title="Projet B-Box" href="http://code.google.com/p/b-box/" target="_blank">b-box</a> j&#8217;ai rencontré un problème avec mon menu. Ce menu est présent sous forme de ListActivity (comprenant une ListView), était trié selon un ordre alphabétique qui est susceptible de changer puisque l&#8217;application peut-être traduite.</p>
<p>Au début, j&#8217;ai essayé diverses méthodes, mais les id de position étant perdus&#8230; pas moyen de savoir à quoi correspond quoi.</p>
<p>J&#8217;ai donc du trouver <a href="http://forum.frandroid.com/forum/viewtopic.php?id=15727" target="_blank" class="broken_link">une solution</a>, solution que je vous présente.</p>
<h2>But</h2>
<p>Le but est de créer un menu sous forme de liste (ListView) dont chaque élément est cliquable et permet de récupérer l&#8217;id du clic. Cet id servant à lancer une autre Activity, par exemple.</p>
<h2>Exemple</h2>
<p>Tout d&#8217;abord la classe Menu :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">org.android.bbox</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Comparator</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> <span style="color: #003399;">Menu</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> id<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> label<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Menu</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> id, <span style="color: #003399;">String</span> label<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span> <span style="color: #339933;">=</span> id<span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">label</span> <span style="color: #339933;">=</span> label<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getLabel<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">label</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> getId<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">id</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Menu</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> factory<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> menus<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">Menu</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> menu <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Menu</span><span style="color: #009900;">&#91;</span>menus.<span style="color: #006633;">length</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> menus.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			menu<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Menu</span><span style="color: #009900;">&#40;</span>i, menus<span style="color: #009900;">&#91;</span> i <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">return</span> menu<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Comparator</span> getComparator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Comparator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			@Override
			<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">int</span> compare<span style="color: #009900;">&#40;</span><span style="color: #003399;">Menu</span> m1, <span style="color: #003399;">Menu</span> m2<span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">return</span> m1.<span style="color: #006633;">getLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">compareTo</span><span style="color: #009900;">&#40;</span>m2.<span style="color: #006633;">getLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">getLabel</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Et la classe de l&#8217;activité :</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// ...</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//...</span>
		<span style="color: #003399;">Menu</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> m <span style="color: #339933;">=</span> <span style="color: #003399;">Menu</span>.<span style="color: #006633;">factory</span><span style="color: #009900;">&#40;</span>getResources<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getStringArray</span><span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">array</span>.<span style="color: #006633;">main_list_array</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;">//récupération d'un tableau de string et création d'un tableau de Menu</span>
		ArrayAdapter adapter <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayAdapter<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span>, android.<span style="color: #006633;">R</span>.<span style="color: #006633;">layout</span>.<span style="color: #006633;">simple_list_item_1</span>, m<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//création de l'adaptateur permettant l'affichage</span>
		adapter.<span style="color: #006633;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Menu</span>.<span style="color: #006633;">getComparator</span><span style="color: #009900;">&#40;</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;">//tri du menu</span>
		<span style="color: #003399;">ListView</span> myList <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">ListView</span><span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>android.<span style="color: #006633;">R</span>.<span style="color: #006633;">id</span>.<span style="color: #006633;">list</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		myList.<span style="color: #006633;">setAdapter</span><span style="color: #009900;">&#40;</span>adapter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//ajotu du menu à la ListView</span>
		myList.<span style="color: #006633;">setOnItemClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//...</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onItemClick<span style="color: #009900;">&#40;</span>AdapterView parent, <span style="color: #003399;">View</span> view, <span style="color: #000066; font-weight: bold;">int</span> position, <span style="color: #000066; font-weight: bold;">long</span> id<span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; | &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>parent.<span style="color: #006633;">getItemAtPosition</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; | &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>parent.<span style="color: #006633;">getItemAtPosition</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getClass</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; | &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Menu</span><span style="color: #009900;">&#41;</span>parent.<span style="color: #006633;">getItemAtPosition</span><span style="color: #009900;">&#40;</span>position<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; | &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>id<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">//...</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// ...</span></pre></div></div>

<p><strong>Remarque</strong> : la méthode toString permet l&#8217;affichage de l&#8217;élément dans la liste.</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/312/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebHook Google Code &#8211; recevoir un mail à chaque commit</title>
		<link>http://grummfy.be/blog/310#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/310#comments</comments>
		<pubDate>Fri, 18 Jun 2010 23:58:59 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=310</guid>
		<description><![CDATA[Google code et webhook : envoyer un email a chaque commit]]></description>
			<content:encoded><![CDATA[<p>Dans Google code il y a la possibilité d&#8217;utiliser un gestionnaire de version tel que subversion (svn) ou mercurial (hg). C&#8217;est bien pratique, mais malheureusement, de base, rien n&#8217;est prévu pour prévenir (excepté par flux RSS) les gens de ces mises à jour. Cependant, Google code permet d&#8217;utiliser un webhook en post commit.</p>
<h2>Qu&#8217;est-ce qu&#8217;un webhook?</h2>
<p>Un webhook c&#8217;est un &laquo;&nbsp;crochet web&nbsp;&raquo;, c&#8217;est-à-dire une URL a appelée après (avant ou pendant) une action X. Dans notre cas, après chaque commit une URL est appelée.</p>
<h2>Utilisation</h2>
<p>Voici un exemple de code que j&#8217;utilise pour plusieurs de mes projets :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// project name</span>
<span style="color: #000088;">$projects</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mon-super-projet'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// google code webhook key</span>
<span style="color: #000088;">$keys</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'b-box'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Top-Secret_key_fourni_par_google-dans-l-adminsitration'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//user agent from google code</span>
<span style="color: #000088;">$useragent</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Google Code Project Hosting (+http://code.google.com/p/support/wiki/PostCommitWebHooks)'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//email of all owner (eg. project chief)</span>
<span style="color: #000088;">$owners</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'vous@example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//email of all team members except owners</span>
<span style="color: #000088;">$users</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'toi@example.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//sender of email</span>
<span style="color: #000088;">$sender</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'WebHook mailer&lt;webmaster@exemple.com&gt;'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//----------------------------------------------------------------------</span>
<span style="color: #000088;">$project</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'p'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'p'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$revision</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:-</span><span style="color: #cc66cc;">99</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'php://input'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$digest</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_GOOGLE_CODE_PROJECT_HOSTING_HOOK_HMAC'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//----------------------------------------------------------------------</span>
<span style="color: #009933; font-style: italic;">/**
 * Send a mail
 * @param string $from email of the sender : sample@example.com or &quot;name&quot;&lt;sample@example.com&gt;;
 * @param array $to [a] =&gt; list of email [cc], [bcc] (hidden), ...
 * @param string $subject
 * @param string $body
 * @return bool true if success
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> mailer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$from</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span> <span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'From: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$from</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bcc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bcc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Bcc: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bcc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> <span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Cc: '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">','</span><span style="color: #339933;">,</span> <span style="color: #000088;">$to</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'cc'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'MIME-Version: 1.0'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Content-Type: text/plain; charset=&quot;UTF-8&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Content-Transfer-Encoding: 8bit'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'X-Mailer: PHP/'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">phpversion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$a</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'[webhook]'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> failed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$test_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$sender</span><span style="color: #339933;">,</span> <span style="color: #000088;">$owners</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$msg</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>--<span style="color: #000099; font-weight: bold;">\n</span>WebHook mail from the Google code project&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	mailer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sender</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bcc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$owners</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'failed test #'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$test_id</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'KO'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> get_ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span> 
	<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_X_FORWARDED_FOR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_X_FORWARDED_FOR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_CLIENT_IP'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_CLIENT_IP'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">:</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//----------------------------------------------------------------------</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$useragent</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// failed 1</span>
	failed<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'User agent is bad : '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_USER_AGENT'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>From : &quot;</span> <span style="color: #339933;">.</span> get_ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$project</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$project</span><span style="color: #339933;">,</span> <span style="color: #000088;">$projects</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// failed 2</span>
	failed<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'No project set : '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlspecialchars</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$project</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>From : &quot;</span> <span style="color: #339933;">.</span> get_ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$hmac</span> <span style="color: #339933;">=</span> <span style="color: #990000;">hash_hmac</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'md5'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keys</span><span style="color: #009900;">&#91;</span> <span style="color: #000088;">$project</span> <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">json_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$digest</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$digest</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$hmac</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// failed 3</span>
		failed<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Bad digest : '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$digest</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' vs '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$hmac</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>From : &quot;</span> <span style="color: #339933;">.</span> get_ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revision_count'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revisions'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// failed 4</span>
		failed<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Bad count : '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revisions'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' vs '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revision_count'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>From : &quot;</span> <span style="color: #339933;">.</span> get_ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">else</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revisions'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$_revision</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Revision : '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'revision'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' from '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'author'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' at '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d H:i'</span><span style="color: #339933;">,</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'timestamp'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Added : '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'added'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Modified : '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'modified'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Removed : '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'removed'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//			$mail_body .= 'URL : ' . &quot;\t\t&quot; . htmlentities($_revision['url']) . &quot;\n\n&quot;;</span>
			<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Message : '</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">htmlentities</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_revision</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//			$_revision['path_count'];</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$mail_body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>--<span style="color: #000099; font-weight: bold;">\n</span>WebHook mail from the Google code project : &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$project</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>http://code.google.com/p/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$project</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;/<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		mailer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sender</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bcc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$owners</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$users</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'['</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$project</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">']New revision #'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$revision</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mail_body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'OK'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

</p>
<p>Plus d&#8217;info : <a href="http://code.google.com/p/support/wiki/PostCommitWebHooks">PostCommitWebHooks</a></p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/310/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Réécriture d&#8217;url et erreur interne à Apache</title>
		<link>http://grummfy.be/blog/289#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/289#comments</comments>
		<pubDate>Fri, 04 Jun 2010 13:15:29 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[deboguage]]></category>
		<category><![CDATA[serveur]]></category>
		<category><![CDATA[url rewriting]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=289</guid>
		<description><![CDATA[Il arrive que lors de l'écriture d'un nombre complexe de règle de réécriture d'URL, des erreurs se produisent. Passons au débogage de celles-ci.]]></description>
			<content:encoded><![CDATA[<p>Il arrive que lors de l&#8217;écriture d&#8217;un nombre complexe de règle de réécriture d&#8217;URL (URL rewriting), des erreurs se produisent sans pour autant être compréhensibles. Je vous propose donc de regarder comment déboguer cela à travers un exemple pratique.</p>
<h2>Exemple</h2>
<p>Prenons une règles qui vérifierait que seul certains type de caractère sont autorisés.<br />
La réécriture quant à elle se fait sur toute URL.<br />
Ajoutons un document 403 personnalisé<br />
<code>RewriteEngine on<br />
#<br />
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/ [NC]<br />
RewriteRule .* - [F,NS,L]<br />
#<br />
#if not a dir or a file<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
#<br />
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]<br />
ErrorDocument 403 /erreur/403<br />
</code><br />
Testons l&#8217;URL http://localhost/test:s et on obtient un beau :</p>
<blockquote><p>Forbidden</p>
<p>You don&#8217;t have permission to access /test:s on this server.</p>
<p>Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.</p></blockquote>
<p>Les logs d&#8217;erreurs d&#8217;Apache vous diront certainement quelque chose du genre :</p>
<blockquote><p>[error] [client 127.0.0.1] Request exceeded the limit of 10 internal  redirects due to probable configuration error. Use  &#8216;LimitInternalRecursion&#8217; to increase the limit if necessary. Use  &#8216;LogLevel debug&#8217; to get a backtrace.</p></blockquote>
<h2>Passage en mode debug de Apache</h2>
<p>Modifions la règle de log du site courant (soit dans /etc/apache2/sites-available/default soit dans /etc/apache2/apache.conf ou l&#8217;équivalent suivant votre configuration ou OS) et modifions la directive <em>&laquo;&nbsp;LogLevel warn&nbsp;&raquo;</em> en <em>&laquo;&nbsp;LogLevel debug&nbsp;&raquo;</em>. Ceci ne change rien dans notre cas, mais parfois cela s&#8217;avère utile&#8230;</p>
<p>Ajoutons ensuite les log<sup class='footnote'><a href='#fn-289-1' id='fnref-289-1'>1</a></sup> de réécriture d&#8217;url (moi je l&#8217;ai ajouter dans /etc/apache2/mods-available/rewrite.conf puis j&#8217;ai fait un a2enmod rewrite (car le fichier .conf n&#8217;existait pas) et enfin j&#8217;ai relancer Apache) :<br />
<code>&lt;IfModule mod_rewrite.c&gt;<br />
RewriteLog "/var/log/apache2/rewrite.log"<br />
RewriteLogLevel 9<br />
&lt;/IfModule&gt;</code></p>
<p>Maintenant si vous aller voir dans error.log vous aurez :</p>
<blockquote><p>[error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use &#8216;LimitInternalRecursion&#8217; to increase the limit if necessary. Use &#8216;LogLevel debug&#8217; to get a backtrace.<br />
[debug] core.c(3063): [client 127.0.0.1] r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/erreur/403<br />
[debug] core.c(3069): [client 127.0.0.1] redirected from r-&gt;uri = /&#8230;/test:s</p></blockquote>
<p>Donc on voit que la redirection s&#8217;effectue correctement mais qu&#8217;il &laquo;&nbsp;<em>n&#8217;accroche</em>&nbsp;&raquo; pas. Regardons donc les logs de la réécriture d&#8217;URL (rewrite.log) :</p>
<blockquote><p>/initial] (3) [perdir /.../] strip per-dir prefix: /&#8230;/test:s -&gt; test:s<br />
/initial] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;test:s&#8217;<br />
/initial] (4) [perdir /.../] RewriteCond: input=&nbsp;&raquo; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial] (3) [perdir /.../] strip per-dir prefix: /&#8230;/test:s -&gt; test:s<br />
/initial] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;test:s&#8217;<br />
/initial] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/test:s<br />
/initial/redir#1] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#1] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#1] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#1] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#1] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#1] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#1] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#1] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#1] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#2] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#2] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#2] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#2] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#2] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#2] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#2] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#2] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#2] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#3] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#3] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#3] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#3] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#3] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#3] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#3] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#3] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#3] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#4] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#4] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#4] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#4] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#4] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#4] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#4] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#4] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#4] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#5] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#5] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#5] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#5] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#5] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#5] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#5] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#5] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#5] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#6] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#6] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#6] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#6] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#6] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#6] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#6] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#6] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#6] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#7] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#7] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#7] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#7] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#7] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#7] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#7] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#7] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#7] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#8] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#8] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#8] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#8] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#8] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#8] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#8] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#8] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#8] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#9] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#9] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#9] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#9] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#9] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#9] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#9] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#9] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#9] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur<br />
/initial/redir#10] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#10] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#10] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#10] (4) [perdir /.../] RewriteCond: input=&#8217;403&#8242; pattern=&#8217;200&#8242; =&gt; not-matched<br />
/initial/redir#10] (3) [perdir /.../] add path info postfix: /&#8230;/erreur -&gt; /&#8230;/erreur/403<br />
/initial/redir#10] (3) [perdir /.../] strip per-dir prefix: /&#8230;/erreur/403 -&gt; erreur/403<br />
/initial/redir#10] (3) [perdir /.../] applying pattern &#8216;.*&#8217; to uri &#8216;erreur/403&#8242;<br />
/initial/redir#10] (4) [perdir /.../] RewriteCond: input=&#8217;GET /&#8230;/test:s HTTP/1.1&#8242; pattern=&#8217;!^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/&#8217; [NC] =&gt; matched<br />
/initial/redir#10] (2) [perdir /.../] forcing responsecode 403 for /&#8230;/erreur</p></blockquote>
<p>En gros, nous avions une boucle de redirection. Pour l&#8217;éviter ajoutons,d ans le .htaccess, une condition qui dira de ne pas rentrer dans le bloc, s&#8217;il y a une erreur 403 :<br />
<code>RewriteEngine on<br />
#<br />
RewriteCond %{ENV:REDIRECT_STATUS} !403<br />
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;]+\ HTTP/ [NC]<br />
RewriteRule .* - [F,NS,L]<br />
#<br />
#if not a dir or a file<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
#<br />
RewriteRule ^(.*)$ index.php?p=$1 [QSA,L]<br />
ErrorDocument 403 /erreur/403<br />
</code><br />
Maintenant tout fonctionne comme prévu!</p>
<h2>La fin</h2>
<p>Pour finir, ceci montre encore l&#8217;importance des logs lors de la rencontre de problème. S&#8217;il y a moyen penser a les activer, cela simplifie franchement la tâche de débogage que cela soit pour Apache mais aussi pour tout projet informatique.</p>
<p>Un dernier conseil, pensez a désactiver le mode debug de Apache une fois fini!</p>
<p>S&#8217;il y avait un site a conseiller sur ce sujet (en dehors du manuel Apache) je vous renverrait vers <a href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html" target="_blank">askapache</a></p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-289-1'>Si le fichier ne se créer pas tout seul penser à le créer <span class='footnotereverse'><a href='#fnref-289-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/289/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>URL rewriting et SEO : duplication de contenu</title>
		<link>http://grummfy.be/blog/268#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/268#comments</comments>
		<pubDate>Wed, 02 Jun 2010 20:09:53 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[référencement]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[url rewriting]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=268</guid>
		<description><![CDATA[Article présentant l'URL rewriting et ce qu'est SEO pour arriver à la problématique de la réécriture d'URL : la duplication de contenu et comment l'éviter.]]></description>
			<content:encoded><![CDATA[<p>Cet article présente rapidement l&#8217;<acronym title="Uniform Resource Locators">URL</acronym> rewriting et ce qu&#8217;est SEO pour arriver au cœur du sujet, à savoir, la problématique de la réécriture d&#8217;URL : la duplication de contenu. Pourquoi la duplication de contenu est gênante et surtout comment l&#8217;éviter sont expliqué dans la suite!<span id="more-268"></span></p>
<h2>Mise en bouche</h2>
<p>L&#8217;URL rewriting ou réécriture d&#8217;<acronym title="Uniform Resource Locators">URL</acronym><sup class='footnote'><a href='#fn-268-1' id='fnref-268-1'>1</a></sup> permet de réécrire de manière plus ou moins dynamique des URL (par exemple transformer http://www.example.com/ en http://example.com/ avec une redirection ou encore http://example.com/contact/moi/par/formulaire en http://example.com/contact.php).</p>
<p>SEO ou Search Engine Optimization consiste à optimiser le référencement d&#8217;un site.</p>
<h2>Exemple</h2>
<p>Afin de débuter, il convient de donner un exemple fonctionnel. Reprenons donc un fichier .htaccess de base :<code><br />
&lt;IfModule mod_rewrite.c&gt;<br />
RewriteEngine on<br />
#si votre fichier se trouve dans /chemin vers votre répertoire de base de votre serveur/test/<br />
RewriteBase /test/<br />
#<br />
#On élimine les fichiers et répertoires qui existent déjà de la réécriture<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
#réécrit l'url<br />
RewriteRule ^(.+)$ index.php?path=$1 [QSA,L]<br />
&lt;/IfModule&gt;<br />
</code><br />
Je suppose que vous tester votre script localement, que vous êtes dans le dossier test et que le fichier php est index.php (qui suit).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">#
</span><span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_FILENAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REDIRECT_QUERY_STRING'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REDIRECT_URL'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SCRIPT_NAME'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'QUERY_STRING'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_REQUEST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/ pre&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>Si vous testez le script, essayez d&#8217;y accéder par http://localhost/test/ceci-est_un-test?toto=tata puis par http://127.0.0.1/ceci-est_un-test?toto=tata . Dans le deuxième cas, une redirection 301 (fichier bouger de manière permanente) est effectuée. Concernant, l&#8217;explication en détail de la réécriture d&#8217;URL je vous renvoi vers votre moteur de recherche favoris.</p>
<h2>Double accès</h2>
<p>Maintenant, un  problème se pose. En effet, votre site est accessible par plusieurs URL différentes pour un même contenu, les moteurs de recherche interpréteront cela comme du duplicata de contenu <sup class='footnote'><a href='#fn-268-2' id='fnref-268-2'>2</a></sup>! Pour résoudre ce problème, il faut simplement faire en sorte que seule une seule et unique adresse soit accessible.</p>
<p>Premièrement, vérifier que l&#8217;on provient du bon domaine (par exemple : n&#8217;autoriser que example.com et non pas www.example.com ou uniquement localhost et non pas 127.0.0.1), le fichier .htaccess devient :<br />
<code><br />
&lt;IfModule mod_rewrite.c&gt;<br />
RewriteEngine on<br />
#si votre fichier se trouve dans /chemin vers votre répertoire de base de votre serveur/test/<br />
RewriteBase /test/<br />
#<br />
#test si on est bien sur le domaine localhost et non 127.0.0.1 ou autre chose<br />
RewriteCond %{HTTP_HOST} !^localhost<br />
#QSA pour transmettre le query string<br />
#L pour dire de sortir de la boucle de réécriture<br />
#R pour rediriger avec le code HTTP 301<br />
RewriteRule ^(.*) http://localhost/test/$1 [QSA,L,R=301]<br />
#<br />
#On élimine les fichiers et répertoires qui existent déjà de la réécriture<br />
RewriteCond %{REQUEST_FILENAME} !-f<br />
RewriteCond %{REQUEST_FILENAME} !-d<br />
#réécrit l'url<br />
RewriteRule ^(.+)$ index.php?path=$1 [QSA,L]<br />
&lt;/IfModule&gt;<br />
</code></p>
<p>Ensuite, il faut dire aux moteurs de recherche de ne pas indexer les URL du genre index.php?mesparametres. Pour cela, on créé ou modifie le fichier robots.txt<sup class='footnote'><a href='#fn-268-3' id='fnref-268-3'>3</a></sup> :<br />
<code>User-agent: *<br />
Disallow: /test/index.php<br />
Allow: /test/</code></p>
<p>Maintenant, si vous testez le script, que cela soit par  http://localhost/test/ceci-est_un-test?toto=tata ou par  http://127.0.0.1/ceci-est_un-test?toto=tata seul localhost est accessible, l&#8217;autre effectue une redirection HTTP 301.</p>
<h2>Le mot de la fin</h2>
<p>Dans le cadre de la réécriture d&#8217;URL, il faut se méfier des possibilités d&#8217;inversion de paramètre. En effet, avec <a href="http://grummfy.be/blog/zend-framework">ZF</a> par exemple, une URL telle que http://example.com/test/controller/action/param1/var1/param2/var2 est équivalente à http://example.com/test/controller/action/param2/var2/param1/var1 mais les moteurs de recherche marqueront le contenu comme dupliqué. Dans ce cas-là, ce n&#8217;est plus du côté d’apache qu&#8217;il faut regarder mais bien du côté du moteur de votre site &#8230;</p>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-268-1'>On devrait dire <acronym title="Uniform Resource Identifiers">URI</acronym> selon la RFC 3986 mais <acronym title="Tout Le Monde S'En Fout">TLMSF</acronym> <span class='footnotereverse'><a href='#fnref-268-1'>&#8617;</a></span></li>
<li id='fn-268-2'>au pire vous serez blacklinker, au mieux votre référencement en pâtira <span class='footnotereverse'><a href='#fnref-268-2'>&#8617;</a></span></li>
<li id='fn-268-3'>Pour rappel, ce fichier se place à la base de votre URL, soit pour que dans notre exemple (http://www.example.com/test/) le fichier soit accessible via http://www.example.com/robots.txt <span class='footnotereverse'><a href='#fnref-268-3'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/268/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wampserver : quick switch xdebug menu</title>
		<link>http://grummfy.be/blog/250#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/250#comments</comments>
		<pubDate>Wed, 24 Mar 2010 22:22:42 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[deboguage]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[jouons]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[XDebug]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=250</guid>
		<description><![CDATA[Activer et désactiver XDebug sur Wampserver à souhait! Ceci via un menu supplémentaire.]]></description>
			<content:encoded><![CDATA[<p>Pour une fois, un article sous Ms Windows. Stage oblige, je passe du temps sous celui-ci (XP <img src='http://grummfy.be/blog/wp/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  ). Afin d&#8217;optimiser son travail, il y a parfois des petites choses bien pratiques, telles que ce que je vais vous présenter.</p>
<p>XDebug est un outil merveilleux, parfois capricieux, certes, mais très utile. Il permet, notamment<sup class='footnote'><a href='#fn-250-1' id='fnref-250-1'>1</a></sup> :</p>
<ul>
<li>Affichage de tracé d&#8217;erreur</li>
<li>Meilleures lectures des exceptions</li>
<li>Débogage pas-à-pas</li>
<li>Profiling d&#8217;application</li>
<li>&#8230;</li>
</ul>
<p>Bref, des choses essentielles en développement. Et, contrairement à ce que certains IDE<sup class='footnote'><a href='#fn-250-2' id='fnref-250-2'>2</a></sup> font, il permet surtout de le faire sur un serveur &laquo;&nbsp;réel&nbsp;&raquo;, donc avec une utilisation &laquo;&nbsp;réel&nbsp;&raquo;.</p>
<p>Le but de ce billet n&#8217;est pas de présenter XDebug, d&#8217;autres le font mieux que moi <sup class='footnote'><a href='#fn-250-3' id='fnref-250-3'>3</a></sup>, mais bien de vous présenter un petit script vous permettant d&#8217;activer et désactiver XDebug sur wampserver.</p>
<h2>Installation</h2>
<ol>
<li>Téléchargez le fichier <sup class='footnote'><a href='#fn-250-4' id='fnref-250-4'>4</a></sup> et décompressez-le.</li>
<li>Suivez les instructions d&#8217;installation décrite dans le fichier installe. Il y a seulement 1 fichier à modifier + 1 fichier par version de PHP installée.</li>
<li>Relancer wampserver et tester!</li>
</ol>
<p>Si vous avez des questions, n&#8217;hésitez pas.</p>
<h2>Plus d&#8217;informations</h2>
<ul>
<li><a href="http://blog.pascal-martin.fr/post/xdebug-installation-premiers-pas" target="_blank">Xdebug : Installation et premier pas</a></li>
<li><a href="http://blog.wampserver.com/index.php/2009/08/28/debugger-avec-wampserver-xdebug-et-pdt/" target="_self" class="broken_link">Débugger avec WampServer, Xdebug et PDT</a></li>
<li><a href="http://evoilliot.u7n.org/2010/02/installer-xdebug-avec-xampp/" target="_blank" class="broken_link">Installer Xdebug avec XAMPP</a></li>
<li><a href="http://www.wampserver.com" target="_blank">Wampserver</a></li>
<li><a href="http://xdebug.com/" target="_blank">XDebug</a></li>
<li>Pièce jointe : <a href="http://grummfy.be/blog/250/xdebug-tar">XDebug quick switch menu for wampserver</a></li>
</ul>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-250-1'>On parle de serveur web avec PHP &#8230; <span class='footnotereverse'><a href='#fnref-250-1'>&#8617;</a></span></li>
<li id='fn-250-2'>Par exemple, Zend Studio permet un débogage pas à pas mais en interne donc réduit &#8230;  <span class='footnotereverse'><a href='#fnref-250-2'>&#8617;</a></span></li>
<li id='fn-250-3'>cf. plus d&#8217;informations <span class='footnotereverse'><a href='#fnref-250-3'>&#8617;</a></span></li>
<li id='fn-250-4'><a href="http://grummfy.be/blog/250/xdebug-tar">XDebug quick switch menu for wampserver</a> <span class='footnotereverse'><a href='#fnref-250-4'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/250/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Future &#8230; et projets</title>
		<link>http://grummfy.be/blog/240#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/240#comments</comments>
		<pubDate>Fri, 19 Mar 2010 23:03:52 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[Grummfy grrrrumf, ou comment raller]]></category>
		<category><![CDATA[Réflexion du jour]]></category>
		<category><![CDATA[actualité]]></category>
		<category><![CDATA[FSB]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[sortie]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=240</guid>
		<description><![CDATA[Mon blog va évoluer d'ici quelques mois, des changements sont en perspectives.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Mon blog va évoluer d&#8217;ici quelques mois, des changements sont en perspectives.</p>
<p style="text-align: justify;">Tout d&#8217;abord, passons en revue les sujets qui seront abordés. Encore et toujours Zend Framework, je compte continuer de publier. C&#8217;est un sujet qui m&#8217;intéresse et qui je trouve est très intéressant. Par ailleurs, je compte faire une série d&#8217;articles sur CMIS. Si vous ignorez ce que c&#8217;est &#8230; alors tant mieux!<br />
En dehors de ces sujets principaux, seront aussi abordés des projets. Dans ceux-ci on pourra citer principalement deux choses : FSB dont le développement va reprendre (enfin &#8230;) et des projets sous Android.</p>
<p style="text-align: justify;">Bref, des choses intéressantes et alléchantes, mais ce n&#8217;est pas tout! Je compte faire du nettoyage. Hé oui, le printemps arrive, les oiseaux chantent, et certains sortes les balais et les caisses pour le « nettoyage de printemps », ce sera donc mon cas. Depuis trop longtemps, je remet a plus tard de me faire un vrai site avec un contenu qui me correspondent et non des « machins » accumulés et qui date &#8230;</p>
<p>Donc :</p>
<ul>
<li> des projets a réalisé</li>
<li> des sujets à aborder</li>
<li> un site renouvelé</li>
</ul>
<p style="text-align: justify;">Voilà le programme!</p>
<p style="text-align: justify;">Mais aussi, et c&#8217;est une idée qui me trotte dans la tête depuis longtemps, éventuellement un nouveau blog ou site consacré à la cuisine.</p>
<p style="text-align: justify;">Vous avez le menu, reste à savoir si le chef sera dans les temps.</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/240/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Activation, désactivation du wifi sur un D-Link DSL-2640B via PHP</title>
		<link>http://grummfy.be/blog/233#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/233#comments</comments>
		<pubDate>Wed, 17 Mar 2010 23:06:52 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[Logiciel]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Réflexion du jour]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[réseaux]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[wifi]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=233</guid>
		<description><![CDATA[Un script PHP en ligne de commande pour activer // désactiver le wifi sur un modem D-Link DSL-2640B. Cela permet d&#8217;illustrer un peu l&#8217;intérêt de faire du scripting &#8230; Je ne ferais pas de commentaires, mais n&#8217;hésitez pas à poser des questions &#8230; #!/usr/bin/php &#60;?php &#160; //Variable definition // //router $login = 'admin'; $password = [...]]]></description>
			<content:encoded><![CDATA[<p>Un script PHP en ligne de commande pour activer // désactiver le wifi sur un modem D-Link DSL-2640B. Cela permet d&#8217;illustrer un peu l&#8217;intérêt de faire du scripting &#8230;</p>
<p>Je ne ferais pas de commentaires, mais n&#8217;hésitez pas à poser des questions &#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">#!/usr/bin/php
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Variable definition</span>
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//router</span>
<span style="color: #000088;">$login</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'admin'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ip</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'192.168.1.1'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//</span>
<span style="color: #666666; font-style: italic;">//wifi</span>
<span style="color: #000088;">$wifi</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #666666; font-style: italic;">// /!\ don't touch this /!\</span>
	<span style="color: #0000ff;">'wlSsidIdx'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlEnbl'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlCountry'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'GB'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlBasicRate'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//ssid name</span>
	<span style="color: #0000ff;">'wlSsid'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'monSuperRéseauxWifi'</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//0 = visible, 1 = hide</span>
	<span style="color: #0000ff;">'wlHide'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//number of chanel or 0 for auto selection</span>
	<span style="color: #0000ff;">'wlChannel'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//Transmission Speed</span>
	<span style="color: #0000ff;">'wlRate'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//wifi mode 0=802.11b only, 1=Mixed 802.11g and 802.11b, 4=802.11g only</span>
	<span style="color: #0000ff;">'wlgMode'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
&nbsp;
	<span style="color: #0000ff;">'wlWpaGTKRekey'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">750</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlWpa'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'aes'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlAuthMode'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'psk2'</span><span style="color: #339933;">,</span>
	<span style="color: #666666; font-style: italic;">//authentification mode : 0 = none, 1 = wep, 2 = auto (wpa or wpa2), 3 = wpa2 only, 4 = wpa only</span>
	<span style="color: #0000ff;">'wlAuth'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlWpaPsk'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'masuperclefdelamortquitue'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlWep'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'disabled'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'wlPreauth'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/////////////////////</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> cli
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">const</span> LINE_BREAK <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> LINE_NO_BREAK <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> LINE_RETURN <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">const</span> LINE_NOTHING <span style="color: #339933;">=</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_TEMP</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">250000</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//1/4 of seconds</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_MULTIPLICATOR</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//1/4 -&gt; 4</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_LENGTH</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">60</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _write_empty_space<span style="color: #009900;">&#40;</span><span style="color: #000088;">$lng</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lng</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_LENGTH<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$lng</span><span style="color: #339933;">++;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _echo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$break</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$break</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$break</span> <span style="color: #339933;">==</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NO_BREAK</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_write_empty_space<span style="color: #009900;">&#40;</span><span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _sleep<span style="color: #009900;">&#40;</span><span style="color: #000088;">$second</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$second</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$second</span> <span style="color: #339933;">*</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_MULTIPLICATOR<span style="color: #339933;">;</span>
		<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$j</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$second</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">usleep</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_TEMP<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'.'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NOTHING</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">else</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$j</span> <span style="color: #339933;">%</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_RETURN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_write_empty_space<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_RETURN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span>
				<span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Please wait'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NOTHING</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$j</span><span style="color: #339933;">++;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_RETURN</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> wifi <span style="color: #000000; font-weight: bold;">extends</span> cli
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_ch</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_baseUrl</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> <span style="color: #000088;">$login</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$activation</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_baseUrl <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$ip</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$login</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$activation</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$activation</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$activation</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_activation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_disactivation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _activation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Activation ...'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NO_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$wifi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wlBasicRate'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wlgMode'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'wifi2'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'default'</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_doQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_baseUrl <span style="color: #339933;">.</span> <span style="color: #0000ff;">'wirelesssetting.wl?'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_sleep<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _disactivation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Disactivation ...'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NO_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$wifiDown</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'wlEnbl'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'wlSsidIdx'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$wifi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wlSsidIdx'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'wlCountry'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$wifi</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wlCountry'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_doQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_baseUrl <span style="color: #339933;">.</span> <span style="color: #0000ff;">'wirelesssetting.wl?'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifiDown</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_sleep<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _doQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #339933;">,</span> CURLOPT_HTTPGET<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_ch<span style="color: #009900;">&#41;</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>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error Curl : '</span> <span style="color: #339933;">.</span> <span style="color: #990000;">curl_error</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'DONE'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _auth<span style="color: #009900;">&#40;</span><span style="color: #000088;">$login</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_echo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Authentification ...'</span><span style="color: #339933;">,</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">LINE_NO_BREAK</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$post</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'username'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$login</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'password'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$password</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_doQuery<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_baseUrl <span style="color: #339933;">.</span> <span style="color: #0000ff;">'index.html'</span><span style="color: #339933;">,</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$argc</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">' synthaxe : scriptname.php 1 for activation or 0 for desactivation '</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">new</span> wifi<span style="color: #009900;">&#40;</span><span style="color: #000088;">$wifi</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ip</span><span style="color: #339933;">,</span> <span style="color: #000088;">$login</span><span style="color: #339933;">,</span> <span style="color: #000088;">$password</span><span style="color: #339933;">,</span> <span style="color: #000088;">$argv</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>Certes, le script ne gère pas tout, mais le but était de jouer avec la ligne de commande tout en n’allant pas dans les extensions exotiques de gestion de celle-ci &#8230;.</p>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;linkname=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F233&amp;title=Activation%2C%20d%C3%A9sactivation%20du%20wifi%20sur%20un%20D-Link%20DSL-2640B%20via%20PHP" id="wpa2a_8"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/233/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tri de listing sql via des liens dans Zend Framework</title>
		<link>http://grummfy.be/blog/222#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/222#comments</comments>
		<pubDate>Sun, 10 Jan 2010 02:23:44 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=222</guid>
		<description><![CDATA[Dans la plupart des cas lorsque l'on affiche un listing provenant d'une requête sql on aimerait pouvoir offrir le tri à l'utilisateur. Dans l'article qui suit, je vous propose de découvrir une manière de le faire assez facilement.]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Dans la plupart des cas lorsque l&#8217;on affiche un listing provenant d&#8217;une requête sql on aimerait pouvoir offrir le tri à l&#8217;utilisateur. Dans l&#8217;article qui suit, je vous propose de découvrir une manière de le faire assez facilement.</p>
<p><span id="more-222"></span></p>
<p style="text-align: justify;">Comme exemple nous prendrons le cas d&#8217;une liste via l&#8217;appelle du contrôleur membres et de l&#8217;action liste.</p>
<p style="text-align: justify;">Dans le fichier <em>MembresController.php</em> nous aurons donc une méthode <em>listeAction()</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> listeAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$membres</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_DbTable_Membres<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$membres</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Et dans la vue <em>membres/liste.phtml</em> nous aurons :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$rowCount</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rowCount</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;table&gt;
	&lt;tr&gt;
		&lt;th&gt;Nom&lt;/th&gt;
		&lt;th&gt;Adresse&lt;/th&gt;
		&lt;th&gt;Code postal&lt;/th&gt;
		&lt;th&gt;Ville&lt;/th&gt;
		&lt;th&gt;Email&lt;/th&gt;
	&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entrie</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entry</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;tr&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addrese</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postCode</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cityName</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/table&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div&gt;Aucun membre n\'est enregistré!&lt;br /&gt;;)&lt;br /&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Jusque là, normalement, rien de bien complexe pour celui qui connait ZF.</p>
<p style="text-align: justify;">Ajoutons deux fichiers (cf <a rel="attachment wp-att-223" href="http://grummfy.be/blog/222/zf-tuto-order-by">pièce jointe</a>) dans le dossier librairy/Gru.</p>
<p style="text-align: justify;">
Nous devons ensuite les charger de manière automatique. Pour ce faire, dans le bootstrap.php (dont un extrait possible est présent ci-dessous) ajoutons les informations nécessaires au chargement des fichiers :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initAutoload<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// nos deux lignes ajoutées</span>
		<span style="color: #000088;">$autoloader</span> <span style="color: #339933;">=</span> Zend_Loader_Autoloader<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$autoloader</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">registerNamespace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Gru'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// fin de l'ajout</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Exemple de ce qu'il pourrait y avoir en plus!</span>
		<span style="color: #000088;">$autoloader</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Application_Module_Autoloader<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'namespace'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Default'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'basePath'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$autoloader</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initView<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_View<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$viewRenderer</span> <span style="color: #339933;">=</span> Zend_Controller_Action_HelperBroker<span style="color: #339933;">::</span><span style="color: #004000;">getStaticHelper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ViewRenderer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$viewRenderer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setView</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//début ajout</span>
		<span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addHelperPath</span><span style="color: #009900;">&#40;</span>APPLICATION_PATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/../library/Gru/View/Helper/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Gru_View_Helper_'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// fin de l'ajout</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$view</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Maintenant, modifions notre application pour ajouter le tri. Reprenons notre contrôleur et modifions la méthode <em>listeAction().</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> listeAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Gestion du tri</span>
	<span style="color: #000088;">$order</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Gru_OrderBy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'membre'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Ajout des clefs de tri</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Nom'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'add'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Adresse'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'postCode'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Code postal'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cityName'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Ville'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addKey</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Courriel'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'asc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// injection des requêtes get</span>
	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertRequestParams</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'order'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRequest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParam</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'by'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderKeys</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getKeys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #000088;">$membres</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_DbTable_Membres<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//ne pas oubleir d'ajouter les champs trier au moment de la requête sql</span>
	<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$membres</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSqlKeys</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Et pour finir notre vue :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000088;">$rowCount</span> <span style="color: #339933;">=</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$rowCount</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;table&gt;
	&lt;tr&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderBy</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">th</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">orderKeys</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/themes/images/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entrie</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$entry</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;tr&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addrese</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postCode</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cityName</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
		&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entry</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;/tr&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/table&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div&gt;Aucun membre n\'est enregistré!&lt;br /&gt;;)&lt;br /&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Dans l&#8217;exemple, nous afficherons des icônes suivant le sens du tri, icônes se trouvant dans le répertoire spécifié. Un clic sur les titres permet de trier suivant la colonne cliquée. A noter qu&#8217;ici Adresse ne sera pas triable du au fait de la non précision de l&#8217;ordre.</p>
<p style="text-align: justify;">Il y aurait moyen d&#8217;améliorer le script :</p>
<ul>
<li>utilisations de décorateurs</li>
<li>utilisation de traduction</li>
<li>Gru_OrderBy devrait être un plugins</li>
<li>&#8230;</li>
</ul>
<p style="text-align: justify;">En attendant, j&#8217;espère que ce bout de code vous facilitera la vie!</p>
<p style="text-align: justify;">Des remarques, des questions? Postez un commentaire!</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/222/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>[note]Zend Framework et dojo : auto-complétion</title>
		<link>http://grummfy.be/blog/216#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/216#comments</comments>
		<pubDate>Sat, 02 Jan 2010 15:32:29 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=216</guid>
		<description><![CDATA[Ceci est une note rapide ... j'espère produire un article plus intéressant une autre fois ...
Nous allons regarder les bases de l'auto-complétion  avec ZF et Dojo. Dojo simplement parce qu'il est le mieux intégré des frameworks javascript. Sachant que pour l'instant seul jQuery et Dojo sont intégré...]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Ceci est une note rapide &#8230; j&#8217;espère produire un article plus intéressant une autre fois &#8230;</p>
<p style="text-align: justify;">Nous allons regarder les bases de l&#8217;auto-complétion  avec <a href="./?tag=zf#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed">ZF</a> et Dojo. Dojo simplement parce qu&#8217;il est le mieux intégré des frameworks javascript. Sachant que pour l&#8217;instant seul jQuery et Dojo sont intégré</p>
<h2>Le code</h2>
<p><em>application/views/scripts/test/index.phtml</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">enable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	<span style="color: #666666; font-style: italic;">//activation de dojo</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comboBox</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'toto'</span><span style="color: #339933;">,</span>	<span style="color: #666666; font-style: italic;">//id html de l'élément</span>
	<span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>	<span style="color: #666666; font-style: italic;">//valeur par défaut</span>
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'autocomplete'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>								<span style="color: #666666; font-style: italic;">//activation de l'auto-complétion</span>
		<span style="color: #0000ff;">'store'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'stateStore'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'storeType'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'dojo.data.ItemFileReadStore'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'storeParams'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/test/records'</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;">//url où les données JSON sont récupérée</span>
		<span style="color: #0000ff;">'searchAttr'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span>								<span style="color: #666666; font-style: italic;">//donnée recherchée pour remplir le combobox</span>
	<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><em>application/layoutes/scripts/layout.phtml</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// ...</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isEnabled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>	<span style="color: #666666; font-style: italic;">//Évite les chargement inutile ....</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDjConfigOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'isDebug'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span>APPLICATION_ENV <span style="color: #339933;">==</span> <span style="color: #0000ff;">'development'</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;">//affiche une console de deboguage si on est en mode dev</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDjConfigOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'usePlainJson'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>						<span style="color: #666666; font-style: italic;">//utilise du json texte</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLocalPath</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">baseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/themes/js/dojo/dojo/dojo.js'</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;">//chemin vers les fichier dojo</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addStyleSheetModule</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dijit.themes.tundra'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>					<span style="color: #666666; font-style: italic;">//thème à chargé</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dojo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>												<span style="color: #666666; font-style: italic;">//affichage du tout ...</span>
		<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// viennent ensuite nos jabvascript, css, etc</span>
<span style="color: #666666; font-style: italic;">//...</span>
<span style="color: #666666; font-style: italic;">//&lt;/head&gt;</span>
<span style="color: #666666; font-style: italic;">// ne pas oublier la class tundra dans le body</span>
<span style="color: #339933;">&lt;</span>body <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;tundra&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #666666; font-style: italic;">//...</span></pre></div></div>

<p><em>application/Bootstrap.php</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//...</span>
<span style="color: #666666; font-style: italic;">//dans _initView()</span>
		<span style="color: #666666; font-style: italic;">//dojo</span>
		Zend_Dojo<span style="color: #339933;">::</span><span style="color: #004000;">enableView</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$view</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//...</span></pre></div></div>

<p><em>application/controllers/TestController.php</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> TestController <span style="color: #000000; font-weight: bold;">extends</span> Zend_Controller_Action
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> recordsAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// on désactive l'affichage</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_helper<span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">disableLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//on va cherchée les données et les met dans un objet Zend_Dojo_Data</span>
		<span style="color: #000088;">$book</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Default_Model_DbTable_Book<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$dojo</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Dojo_Data<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$book</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$dojo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toJson</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// on sort ... c'est pas joli mais en attendant cela fonctionne!</span>
		<span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<h2>Choses à <span style="text-decoration: line-through;">retenir</span> comprendre</h2>
<p>Les choses à retenir :</p>
<ul>
<li><em>storeParams</em> est l&#8217;url où les donnée au format JSON seront prise</li>
<li><em>searchAttr</em> est l&#8217;élément qui va servir pour recherchée les données dans la masse de donnée JSON</li>
<li>ne pas oublier de mettre la class css &#8216;tundra&#8217;</li>
<li>Dojo peut, via ses styles css modifier votre rendu &#8230;</li>
</ul>
<h2>Remarque</h2>
<p>Version de ZF : 1.9.6</p>
<p>Version de Dojo (fourni avec zf dans extras) : 1.3</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/216/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zend Framework aide de vue partialLoop et cycle</title>
		<link>http://grummfy.be/blog/199#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/199#comments</comments>
		<pubDate>Wed, 30 Dec 2009 14:16:39 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=199</guid>
		<description><![CDATA[Il y a des moment où l&#8217;on se dit que la doc est vraiment incomplète &#8230; Voici un exemple assez tordu&#8230; Rappel L&#8217;aide de vue (view helper)  cycle permet d&#8217;alterner des valeurs dans la vue, L&#8217;aide de vue partialLoop permet de faire une boucle sur une vue (fichier) afin de l&#8217;incorporer dans un autre fichier&#8230; [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;">Il y a des moment où l&#8217;on se dit que la doc est vraiment incomplète &#8230; Voici un exemple assez tordu&#8230;</p>
<h2>Rappel</h2>
<ul>
<li>L&#8217;aide de vue (view helper)  <a href="http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.cycle">cycle</a> permet d&#8217;alterner des valeurs dans la vue,</li>
<li>L&#8217;aide de vue <a href="http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.partial">partialLoop</a> permet de faire une boucle sur une vue (fichier) afin de l&#8217;incorporer dans un autre fichier&#8230;</li>
</ul>
<h2>Utilisation</h2>
<p style="text-align: justify;">Pour utiliser les deux ensembles, par exemple dans le cas d&#8217;un listing dont la sortie serait dans un tableau, il vous suffit de définir les valeurs assigner au cycle <strong><em>avant</em></strong> de faire le partialLoop.<br />
Exemple :<br />
Vue <em>views/scripts/membres/listing.phtml</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;table class=&quot;table&quot;&gt;
	&lt;thead&gt;
		&lt;tr&gt;
			&lt;th&gt;Nom&lt;/th&gt;
			&lt;th&gt;Prénom&lt;/th&gt;
			&lt;th&gt;Adresse&lt;/th&gt;
			&lt;th&gt;Code postal&lt;/th&gt;
			&lt;th&gt;Ville&lt;/th&gt;
			&lt;th&gt;Pays&lt;/th&gt;
			&lt;th&gt;Téléphone&lt;/th&gt;
		&lt;/tr&gt;
	&lt;/thead&gt;
	&lt;tbody&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cycle</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">assign</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tr_1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tr_2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'tr_3'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_user_listing'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">partialLoop</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'utilisateurs/_user_list_listing.phtml'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">entries</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/tbody&gt;
&lt;/table&gt;</pre></div></div>

<p>Vue <em>views/scripts/utilisateurs/_user_list_listing.phtml</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;tr class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cycle</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'_user_listing'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
	&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">firstName</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Addrese</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">postCode</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cityName</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">countryName</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
	&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tel_prefix</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;
&lt;/tr&gt;</pre></div></div>
</p>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F199&amp;linkname=Zend%20Framework%20aide%20de%20vue%20partialLoop%20et%20cycle" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F199&amp;linkname=Zend%20Framework%20aide%20de%20vue%20partialLoop%20et%20cycle" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F199&amp;linkname=Zend%20Framework%20aide%20de%20vue%20partialLoop%20et%20cycle" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F199&amp;linkname=Zend%20Framework%20aide%20de%20vue%20partialLoop%20et%20cycle" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F199&amp;linkname=Zend%20Framework%20aide%20de%20vue%20partialLoop%20et%20cycle" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F199&amp;linkname=Zend%20Framework%20aide%20de%20vue%20partialLoop%20et%20cycle" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F199&amp;title=Zend%20Framework%20aide%20de%20vue%20partialLoop%20et%20cycle" id="wpa2a_10"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/199/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utilisation de FlashMessenger via un view helper dans Zend Framework</title>
		<link>http://grummfy.be/blog/191#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/191#comments</comments>
		<pubDate>Sun, 27 Dec 2009 18:21:56 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[trucs et astuces]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=191</guid>
		<description><![CDATA[FlashMessanger est à la base un action helper, donc confiné au contrôleur. Cependant, c'est tellement pratique qu'il est dommage de ne pas pouvoir l'utiliser a travers les vue (view)... Je vous propose donc de l'utiliser via un view helper!]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><a title="Manuel Zend Framework sur FlashMessenger" href="http://framework.zend.com/manual/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.flashmessenger">FlashMessanger</a> est à la base un action helper, donc confiné au contrôleur. Celui-ci permet de passer un message d&#8217;une page à l&#8217;autre via le mécanisme des sessions . Après un formulaire on doit souvent ajouter un message de confirmation, on peux par exemple utilisé le FlashMessenger pour le faire et ainsi au ré-affichage suivant  afficher ce message!  C&#8217;est tellement pratique qu&#8217;il est dommage de ne pas pouvoir l&#8217;utiliser a travers les vue (view) de manière automatique&#8230;</p>
<p>Je vous propose donc de l&#8217;utiliser via un view helper!</p>
<p><span id="more-191"></span></p>
<h2>L&#8217;aide de vue</h2>
<p style="text-align: justify;">Voici l&#8217;aide de vue (view helper) FlashMessenger (du même nom que l&#8217;action helper). Il est à placer dans application/views/helpers/FlashMessenger.php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * @see Zend_Controller_Action_Helper_FlashMessenger
 */</span>
<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Zend/Controller/Action/Helper/FlashMessenger.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * @author grummfy
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> Zend_View_Helper_FlashMessenger <span style="color: #000000; font-weight: bold;">extends</span> Zend_View_Helper_Abstract implements IteratorAggregate<span style="color: #339933;">,</span> Countable
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000088;">$_fm</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_fm <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Controller_Action_Helper_FlashMessenger<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> flashMessenger<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cur</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>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cur</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">else</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessages</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Return currents FlashMessegenr object
	 * @return Zend_Controller_Action_Helper_FlashMessenger
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getFlasMessenger<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_fm<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Return previous emmited messages
	 * @return array
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getMessages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_fm<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessages</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Renvoi le nombre de messages passé
	 * @return int
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hasMessages<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_fm<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getIterator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_fm<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIterator</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_fm<span style="color: #339933;">-&gt;</span><span style="color: #004000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

</p>
<h2>Utilisation</h2>
<p style="text-align: justify;">
Pour l&#8217;utiliser rien de plus simple, par exemple dans le layout :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
		<span style="color: #666666; font-style: italic;">// flashmessage</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashMessenger</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hasMessages</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;div id=&quot;flashMessengers&quot;&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span>
			<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashMessenger</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$msg</span><span style="color: #009900;">&#41;</span>
			<span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;flashMessenger&quot;&gt;'</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$msg</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$msg</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">else</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$msg</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/div&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span>
		<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// fin flashmessage</span>
	<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Ceci peut très bien être utilisé dans votre vue (view) avec exactement le même code!</p>
<p style="text-align: justify;">Pour envoyer le message il vous suffit de simplement faire, dans votre contrôleur :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_helper<span style="color: #339933;">-&gt;</span><span style="color: #004000;">flashMessenger</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mise à jour du truc effectuées avec succès!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</p>
<p></p>
<p style="text-align: justify;">
Et c&#8217;est tout!</p>
]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/191/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Créer et ajouter un validateur de session dans Zend Framework</title>
		<link>http://grummfy.be/blog/186#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/186#comments</comments>
		<pubDate>Sat, 19 Dec 2009 16:30:17 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Projet]]></category>
		<category><![CDATA[programmation]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[ZF]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=186</guid>
		<description><![CDATA[Zend Framework possède divers mécanismes de sécurisation, parmi ceux-ci l&#8217;on trouvent les validateurs. Ces validateurs vérifie que la ou les données à validées sont valide et par là même sécurise celle-ci. Dans notre cas nous allons nous intéresser aux sessions et plus particulièrement à la validation de celle-ci au moment de sont démarrage, ceci afin [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: justify;">
<p>Zend Framework possède divers mécanismes de sécurisation, parmi ceux-ci l&#8217;on trouvent les validateurs. Ces validateurs vérifie que la ou les données à validées sont valide et par là même sécurise celle-ci.</p>
<p>Dans notre cas nous allons nous intéresser aux sessions et plus particulièrement à la validation de celle-ci au moment de sont démarrage, ceci afin de, par exemple, <span style="text-decoration: line-through;">empêcher le</span> diminuer les possibilités de vol de celle-ci. Nous allons créer un validateur d&#8217;ip &#8230; (oui je sais y a moyen de passer outre, si on derrière un proxy gnagnagna &#8230;. mais ici c&#8217;est un exemple!).</p>
<p><span id="more-186"></span></p>
<h2>Rermarque</h2>
<p>Nous utiliserons Zend Framework en version 1.9.<br />
De plus, nous allons créer notre librairie qui se nomera &laquo;&nbsp;Biblio&nbsp;&raquo;. Donc, il faudra penser à créer dasn votre répertoire library le dossier Biblio!</p>
<h2>Les sessions</h2>
<p>Tout d&#8217;abord mettons en place le mécanisme de session. Dans le Bootstrap nous ajoutons la méthode suivante :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	Zend_Session<span style="color: #339933;">::</span><span style="color: #004000;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>Le validateur</h2>
<p>Passons à la création proporement dite, créons le fichier /library/Biblio/Session/Validator/Ip.php, dont le contenu sera</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">setValidData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>? <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Validate() - this method will determine if the ip matches the
	 * ip we stored when we initialized this variable.
	 *
	 * @return bool
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> validate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>getValidData<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>?<span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># EOF</span></pre></div></div>

<p>Ensuite, il nous faut ajouter ce validateur à la session. Donc, on réédite le Bootstrap et on modifie la méthode _initSession() :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _initSession<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'Biblio/Session/Validator/Ip.php'</span><span style="color: #339933;">;</span>
	Zend_Session<span style="color: #339933;">::</span><span style="color: #004000;">registerValidator</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> Biblio_Session_Validator_Ip<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	Zend_Session<span style="color: #339933;">::</span><span style="color: #004000;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<h2>conclusion</h2>
<p>Encore une fois Zend nous montre sa puissance et sa facilité d&#8217;ajout de fonctionnalité. A noter qu&#8217;il existe déjà un validateur pour els session qui contrôle l&#8217;user agent (Zend_Session_Validator_HttpUserAgent()).<br />
N&#8217;hésitez pas a en ajouter!</p>
</div>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F186&amp;linkname=Cr%C3%A9er%20et%20ajouter%20un%20validateur%20de%20session%20dans%20Zend%20Framework" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F186&amp;linkname=Cr%C3%A9er%20et%20ajouter%20un%20validateur%20de%20session%20dans%20Zend%20Framework" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F186&amp;linkname=Cr%C3%A9er%20et%20ajouter%20un%20validateur%20de%20session%20dans%20Zend%20Framework" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F186&amp;linkname=Cr%C3%A9er%20et%20ajouter%20un%20validateur%20de%20session%20dans%20Zend%20Framework" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F186&amp;linkname=Cr%C3%A9er%20et%20ajouter%20un%20validateur%20de%20session%20dans%20Zend%20Framework" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F186&amp;linkname=Cr%C3%A9er%20et%20ajouter%20un%20validateur%20de%20session%20dans%20Zend%20Framework" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F186&amp;title=Cr%C3%A9er%20et%20ajouter%20un%20validateur%20de%20session%20dans%20Zend%20Framework" id="wpa2a_12"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/186/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Openvibe everywhere in the future?</title>
		<link>http://grummfy.be/blog/182#utm_source=feed&#038;utm_medium=feed&#038;utm_campaign=feed</link>
		<comments>http://grummfy.be/blog/182#comments</comments>
		<pubDate>Sat, 14 Nov 2009 23:22:56 +0000</pubDate>
		<dc:creator>Grummfy</dc:creator>
				<category><![CDATA[Développement]]></category>
		<category><![CDATA[Grummfy grrrrumf, ou comment raller]]></category>
		<category><![CDATA[My comment]]></category>
		<category><![CDATA[Réflexion du jour]]></category>
		<category><![CDATA[découverte]]></category>
		<category><![CDATA[future]]></category>

		<guid isPermaLink="false">http://grummfy.be/blog/?p=182</guid>
		<description><![CDATA[Pour le titre j&#8217;aurais pu mieux faire Donc commençons ma réflexion du jour &#8230; Openvibe est un logiciel permettant de faire du BCI c&#8217;est-à-dire un logiciel permettant d&#8217;utiliser sont cerveaux comme interface d&#8217;accès à un ordinateur remplaçant ainsi une souris ou un clavier&#8230; Les ondes qu&#8217;émet le cerveau sont captés par des capteurs et traité [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: justify;"><strong>Pour le titre j&#8217;aurais pu mieux faire <img src='http://grummfy.be/blog/wp/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Donc commençons ma réflexion du jour &#8230;</strong></p>
<p style="text-align: justify;">Openvibe est un logiciel permettant de faire du <acronym title="Brain Computer Interface">BCI </acronym> c&#8217;est-à-dire un logiciel permettant d&#8217;utiliser sont cerveaux comme interface d&#8217;accès à un ordinateur remplaçant ainsi une souris ou un clavier&#8230; Les ondes qu&#8217;émet le cerveau sont captés par des capteurs et traité en un signal utilisable pour le logiciel d&#8217;interphasage. Ce genre de logiciel permet le contrôle -expérimental- de chaise roulante ou d&#8217;un tas d&#8217;autres trucs &#8230;. (suffit de chercher et youtube regorge de vidéo à ce sujet).</p>
<p style="text-align: justify;">Ceci fait très sciences-fiction mais c&#8217;est la réalité d&#8217;aujourd&#8217;hui et se sera le quotidien de demain, sachant qu&#8217;il existe déjà des produits commerciaux pour jouer! Mais côté sciences-fiction cela n&#8217;est rien comparé à l&#8217;ordinateur biologique! Ordinateur fonctionnant avec une interaction d&#8217;enzyme et d&#8217;ADN. D&#8217;après ce que j&#8217;ai lu, les dernières recherches en était &laquo;&nbsp;seulement&nbsp;&raquo; à la conception de puce mémoire stockant l&#8217;information sur l&#8217;ADN.</p>
<p style="text-align: justify;">À force de voir ce genre de choses j&#8217;en vient à me dire que dans le futur les interfaces BCI devrait se généraliser et permettre ainsi d&#8217;imaginer un téléphone dont le clavier serait supprimé et où il ne resterait que : un haut parleur et un micro &#8230; ou encore, avec la bio-informatique, l&#8217;homme bio-informatisé, et pourquoi pas tel qu&#8217;on le voit dans les livres de Hamilton (L&#8217;étoile de pandore), des &laquo;&nbsp;tatouage&nbsp;&raquo; informatique permettant d&#8217;étendre les possibilités de l&#8217;homme!</p>
<p style="text-align: justify;">Voilà c&#8217;était la petite réflexion du jour, le délire futuris d&#8217;un fou, maintenant j&#8217;attends vos commentaires &#8230; ou alors j&#8217;écouterai vos ricanements ou vos pas lorsque vous vous encourerez.</p>
<p style="text-align: justify;">ps : oui je sais aucune référence &#8230;. mais j&#8217;ai la flemme &#8230;.</p>
<p><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F182&amp;linkname=Openvibe%20everywhere%20in%20the%20future%3F" title="Delicious" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F182&amp;linkname=Openvibe%20everywhere%20in%20the%20future%3F" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F182&amp;linkname=Openvibe%20everywhere%20in%20the%20future%3F" title="Twitter" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F182&amp;linkname=Openvibe%20everywhere%20in%20the%20future%3F" title="Facebook" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F182&amp;linkname=Openvibe%20everywhere%20in%20the%20future%3F" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_netvibes_share" href="http://www.addtoany.com/add_to/netvibes_share?linkurl=http%3A%2F%2Fgrummfy.be%2Fblog%2F182&amp;linkname=Openvibe%20everywhere%20in%20the%20future%3F" title="Netvibes Share" rel="nofollow" target="_blank"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/icons/netvibes.png" width="16" height="16" alt="Netvibes Share"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fgrummfy.be%2Fblog%2F182&amp;title=Openvibe%20everywhere%20in%20the%20future%3F" id="wpa2a_14"><img src="http://grummfy.be/blog/wp/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://grummfy.be/blog/182/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 4.391 seconds -->

