<?xml version="1.0" encoding="UTF-8"?>
<rss 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/" xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>piouPiouM's dev</title>
	
	<link>http://pioupioum.fr</link>
	<description>Bloc-note d'un développeur web</description>
	<lastBuildDate>Fri, 23 Dec 2011 23:41:36 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.pioupioum.fr/pioupioum-dev-blog" /><feedburner:info uri="pioupioum-dev-blog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><creativeCommons:license>http://creativecommons.org/licenses/by/2.0/</creativeCommons:license><item>
		<title>Bookmarklet : ajout rapide d’application onglet à vos pages fan Facebook</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/onrXMct_vhw/facebook-application-add-page-tab-bookmarklet.html</link>
		<comments>http://pioupioum.fr/outils-astuces/facebook-application-add-page-tab-bookmarklet.html#comments</comments>
		<pubDate>Fri, 23 Dec 2011 20:53:42 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Outils, trucs et astuces]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=562</guid>
		<description><![CDATA[Facebook a annoncé la suppression des profils d&#8217;applications au 1er février 2012. Vous ne pourrez plus associer une application onglet à une page fan comme vous le faisiez actuellement. En effet, la page de profil d&#8217;une application mettait à disposition un lien pour ajouter cette dernière à/aux page(s) fan de votre choix.

Facebook propose bien de [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p><strong>Facebook</strong> a annoncé la <strong><a href="https://developers.facebook.com/blog/post/611/">suppression des profils d&#8217;applications</a></strong> au 1er février 2012. Vous ne pourrez plus associer une application onglet à une page fan comme vous le faisiez actuellement. En effet, la page de profil d&#8217;une application mettait à disposition un lien pour ajouter cette dernière à/aux page(s) fan de votre choix.</p>

<p>Facebook propose bien de créer manuellement une page associée à votre application, mais vu son utilité autant s&#8217;en passer. À la place, et pour éviter 50 clics supplémentaires, je vous propose, amis <em>Community manager</em>, un <strong>bookmarklet</strong> qui permet d&#8217;associer aisément vos applications à des <strong>pages fan Facebook</strong>.<span id="more-562"></span></p>

<h2>Mise en place du bookmarklet</h2>

<p>Glissez-déposez simplement le lien ci-dessous dans les favoris de votre navigateur&#160;; dans votre barre personnelle par exemple.</p>

<div class="box bookmarklet">
    <a href="javascript:(function(a,b,c,d,e,f,g){c=a.location,f=%22developers.facebook.com%22;if(f!==c.hostname||!a[b]){alert(%22Veuillez%20vous%20placer%20sur%20le%20profil%20d%27une%20application%20Facebook.%22);return}try{g=new%20RegExp(f.replace(/\./g,%22\\.%22)+%22/apps/(\\d+)(?:/[^$]*)?$%22,%22i%22),d=g.exec(c.href)[1]}catch(h){d=prompt(%22Veuillez%20saisir%20l%27identifiant%20de%20l%27application%22,%22%22);if(d==null)return}e=a[b].getDomain(%22https_www%22),c.href=e+%22/dialog/pagetab?app_id=%22+d+%22&#038;display=page&#038;redirect_uri=%22+e})(window,%22FB%22);" title='Adding an app to a Page – Facebook'><span>FB Add Page Tab</span></a>
</div>

<h2>Utilisation du bookmarklet <em>Facebook Add Page Tab</em></h2>

<p>Rendez-vous sur la page de configuration de votre application<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> puis cliquez sur le <strong>bookmarklet</strong>. Ce dernier vous redirige vers une page Facebook vous demandant les pages qui accueilleront votre application. L&#8217;association faite, vous serez redirigés sur l&#8217;accueil de Facebook, et pourrez accéder à votre/vos page(s) mise(s) à jour <em>via</em> le moteur de recherche ou le manager de pages.</p>

<p><div id="attachment_561" class="wp-caption aligncenter" style="width: 513px"><a href="http://assets1.pioupioum.fr/uploads/2011/12/facebook-configuration-application.jpg"><img src="http://assets1.pioupioum.fr/uploads/2011/12/facebook-configuration-application-503x350.jpg" alt="Page de configuration d&#039;une application Facebook" title="facebook-configuration-application" width="503" height="350" class="size-medium wp-image-561" /></a><p class="wp-caption-text">Page de configuration d&#8217;une application Facebook</p></div></p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/outils-astuces/dailymotion-download-bookmarklet.html' title='Dailymotion Download Bookmarklet'>Dailymotion Download Bookmarklet</a></li><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li><li><a href='http://pioupioum.fr/developpement/jslint-console-rhino.html' title='Une console JSLint pour aider vos validations JavaScript'>Une console JSLint pour aider vos validations JavaScript</a></li><li><a href='http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html' title='Optimiser le chargement des AdSense'>Optimiser le chargement des AdSense</a></li><li><a href='http://pioupioum.fr/developpement/jquery-color-plugin-animation-rgba-support.html' title='Du RGBA dans vos animations avec le plugin jQuery Color'>Du RGBA dans vos animations avec le plugin jQuery Color</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>il s&#8217;agit de la page sur laquelle vous récupérez l&#8217;ID de l&#8217;application.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=onrXMct_vhw:sZQ4xZmhFeo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=onrXMct_vhw:sZQ4xZmhFeo:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=onrXMct_vhw:sZQ4xZmhFeo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=onrXMct_vhw:sZQ4xZmhFeo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=onrXMct_vhw:sZQ4xZmhFeo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=onrXMct_vhw:sZQ4xZmhFeo:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=onrXMct_vhw:sZQ4xZmhFeo:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=onrXMct_vhw:sZQ4xZmhFeo:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=onrXMct_vhw:sZQ4xZmhFeo:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/onrXMct_vhw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/outils-astuces/facebook-application-add-page-tab-bookmarklet.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/outils-astuces/facebook-application-add-page-tab-bookmarklet.html</feedburner:origLink></item>
		<item>
		<title>Compass : supprimer le cache buster des sprites</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/fAm-y5Al7Xk/compass-sprites-supprimer-cache-buster.html</link>
		<comments>http://pioupioum.fr/developpement/compass-sprites-supprimer-cache-buster.html#comments</comments>
		<pubDate>Wed, 15 Jun 2011 18:22:54 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[astuces]]></category>
		<category><![CDATA[compass]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=543</guid>
		<description><![CDATA[Le générateur de sprites de Compass 0.11.31 crée des images dont le nom a pour format &#60;map>-&#60;hash>.png où &#60;map> correspond au nom du répertoire qui contient les images du sprite et -&#60;hash> à un hash qui&#160;:


assure l&#8217;unicité du fichier généré&#160;;
fait office de cache buster.


Seulement voilà, chaque modification de sprite (par un ajout ou décalage d&#8217;image [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Le générateur de <strong>sprites de Compass 0.11.3</strong><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> crée des images dont le nom a pour format <code>&lt;map>-&lt;hash>.png</code> où <code>&lt;map></code> correspond au nom du répertoire qui contient les images du sprite et <code>-&lt;hash></code> à un hash qui&#160;:</p>

<ul>
<li>assure l&#8217;unicité du fichier généré&#160;;</li>
<li>fait office de <strong><span lang="en">cache buster</span></strong>.</li>
</ul>

<p>Seulement voilà, chaque modification de sprite (par un ajout ou décalage d&#8217;image par exemple) va générer une image avec un hash différent<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup>, ce qui rend la gestion du dépôt d&#8217;un projet versionné assez prise de tête.<br />
Heureusement, il est possible de ruser.<span id="more-543"></span></p>

<p>Pour ce faire, il suffit d&#8217;implémenter les <span lang="en">callbacks <strong><code>on_sprite_saved</code></strong> et <strong><code>on_stylesheet_saved</code></strong></span> dans le fichier de configuration du projet, comme suit&#160;:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#</span>
<span style="color:#008000; font-style:italic;"># config.rb</span>
<span style="color:#008000; font-style:italic;">#</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Réaliser une copie des sprites avec un nom dépourvu du hash d'unicité.</span>
on_sprite_saved <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>filename<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>filename<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC00FF; font-weight:bold;">FileUtils</span>.<span style="color:#9900CC;">cp</span> filename, filename.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">-</span>s<span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>z0<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#125;</span>\.<span style="color:#9900CC;">png</span>$<span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#996600;">'.png'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Remplacer dans les feuilles de styles générés les références aux sprites par</span>
<span style="color:#008000; font-style:italic;"># leurs équivalents dépourvus du hash d'unicité.</span>
on_stylesheet_saved <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>filename<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>filename<span style="color:#006600; font-weight:bold;">&#41;</span>
    css = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">read</span> filename
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>filename, <span style="color:#996600;">'w+'</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
      f <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> css.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">-</span>s<span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>z0<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#125;</span>\.<span style="color:#9900CC;">png</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#996600;">'.png'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>


<p>Ainsi, après chaque génération de sprite par <a href="http://compass-style.org/" title="Compass Home | Compass Documentation">Compass</a>, une copie de l&#8217;image dépourvue du hash d&#8217;unicité est réalisée. Cela s&#8217;accompagne bien évidemment par un remplacement de leurs appels dans les feuilles de styles.<br />
Il ne reste plus qu&#8217;à ignorer les images ayant un hash au niveau de votre <span lang="en">repository</span> pour ne pas polluer ce dernier.</p>

<p>Je suis conscient qu&#8217;il y aurait plus <span lang="en">secure</span> (je pense notamment aux substitutions dans les feuilles de style), mais disons que cela me convient dans l&#8217;immédiat, et qu&#8217;accessoirement je ne fais pas de ruby <img src='http://pioupioum.fr/wp/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/compass-rvm-multiple-instances.html' title='Instances multiples de Compass avec Ruby Version Manager (rvm)'>Instances multiples de Compass avec Ruby Version Manager (rvm)</a></li><li><a href='http://pioupioum.fr/developpement/drupal-iframe-page.html' title='Drupal 6 : utiliser une iframe comme contenu de page'>Drupal 6&#160;: utiliser une iframe comme contenu de page</a></li><li><a href='http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html' title='Optimiser le chargement des AdSense'>Optimiser le chargement des AdSense</a></li><li><a href='http://pioupioum.fr/snippets/wordpress-autoriser-upload-media-format-inconnu.html' title='WordPress : autoriser l&#8217;upload de fichiers au format non-supporté'>WordPress&#160;: autoriser l&#8217;upload de fichiers au format non-supporté</a></li><li><a href='http://pioupioum.fr/snippets/apache-rotation-logs.html' title='Rotation des logs Apache'>Rotation des logs Apache</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p><strong>attention&#160;:</strong> les versions de Compass inférieures à 0.11.3 souffrent de bugs qui empêchent cette astuce de fonctionner.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>les fichiers obsolètes étants automatiquement supprimés, à moins que la variable de configuration <code>$&lt;map&gt;-clean-up</code> soit positionnée à <code>false</code>.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=fAm-y5Al7Xk:mdhHQdONZrA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=fAm-y5Al7Xk:mdhHQdONZrA:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=fAm-y5Al7Xk:mdhHQdONZrA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=fAm-y5Al7Xk:mdhHQdONZrA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=fAm-y5Al7Xk:mdhHQdONZrA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=fAm-y5Al7Xk:mdhHQdONZrA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=fAm-y5Al7Xk:mdhHQdONZrA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=fAm-y5Al7Xk:mdhHQdONZrA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=fAm-y5Al7Xk:mdhHQdONZrA:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/fAm-y5Al7Xk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/compass-sprites-supprimer-cache-buster.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/developpement/compass-sprites-supprimer-cache-buster.html</feedburner:origLink></item>
		<item>
		<title>Drupal 6 : utiliser une iframe comme contenu de page</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/O8--qFuMo5k/drupal-iframe-page.html</link>
		<comments>http://pioupioum.fr/developpement/drupal-iframe-page.html#comments</comments>
		<pubDate>Sun, 29 May 2011 18:17:22 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[astuces]]></category>
		<category><![CDATA[drupal]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=529</guid>
		<description><![CDATA[Vous devez intégrer sous Drupal 6 des pages en provenance d&#8217;un site externe. Le web scraping est à exclure et de ce fait le chargement en iframe des pages externes a été retenu.
Marche à suivre.

Déclarer un menu de type callback

En premier lieu, il vous faut créer la page virtuelle qui aura la charge de faire [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Vous devez intégrer sous <strong><a href="http://drupal.org/" title="Drupal - Open Source CMS | drupal.org">Drupal</a> 6</strong> des pages en provenance d&#8217;un site externe. Le <strong><a href="http://fr.wikipedia.org/wiki/Web_scraping" title="Web scraping - Wikipédia">web scraping</a></strong> est à exclure et de ce fait le <strong>chargement en iframe</strong> des pages externes a été retenu.<br />
Marche à suivre.<span id="more-529"></span></p>

<h2>Déclarer un menu de type callback</h2>

<p>En premier lieu, il vous faut créer la page virtuelle qui aura la charge de faire appel au service externe <em>via</em> une iframe. Cela se fait en implémentant le <a href="http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_menu/6" title="hook_menu | Drupal API">hook_menu</a> pour y déclarer une entrée de type <a href="http://api.drupal.org/api/drupal/includes--menu.inc/constant/MENU_CALLBACK/6" title="MENU_CALLBACK | Drupal API">MENU_CALLBACK</a>. La fonction callback associée, <code>_mytheme_load_iframe()</code> ici<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>, prendra 3 arguments&#160;:</p>

<ol>
<li><strong>url</strong>&#160;: l&#8217;URL de la ressource externe à charger dans l&#8217;iframe&#160;;</li>
<li><strong>width</strong>&#160;: la largeur en pixels de l&#8217;iframe, de <strong>type <code>String</code> obligatoirement</strong>&#160;;</li>
<li><strong>height</strong>&#160;: la hauteur en pixels de l&#8217;iframe, obligatoirement de type <code>String</code>.</li>
</ol>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * template.php
 */</span>
<span style="color: #009933; font-style: italic;">/**
 * @implements hook_menu()
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> mytheme_menu<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;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'drupal/page/path'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'title'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Mon contenu externe'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'page callback'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'_mytheme_load_iframe'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'page arguments'</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: #0000ff;">'http://example.com/service'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'width'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'700'</span><span style="color: #339933;">,</span>
              <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1000'</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'access arguments'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'access content'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'type'</span>             <span style="color: #339933;">=&gt;</span> MENU_CALLBACK<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: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Loads an external resource into an iframe.
 *
 * @param string $url   URL to load in the iframe.
 * @param string $width The width of the iframe.
 * @param string $height The height of the iframe.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> _mytheme_load_iframe<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> theme<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mytheme_simple_iframe'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$iframe_url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$height</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;">?&gt;</span></pre></td></tr></table></div>


<p>Comme vous pouvez le lire, la méthode de callback fait appel à la fonction <a href="http://api.drupal.org/api/drupal/includes--theme.inc/function/theme/6" title="theme | Drupal API">theme()</a> sur un hook <code>mytheme_simple_iframe</code> qui n&#8217;existe pas.</p>

<h2>Création d&#8217;un hook de thème</h2>

<p>La création d&#8217;un hook permettant de faire appel à un fichier template est des plus simple, grâce au <a href="http://api.drupal.org/api/drupal/developer--hooks--core.php/function/hook_theme/6" title="hook_theme | Drupal API">hook_theme</a>. Définissez dans votre fichier <code>template.php</code> (ou dans un fichier de module) le hook <code>mytheme_simple_iframe</code>&#160;:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * template.php
 */</span>
<span style="color: #009933; font-style: italic;">/**
 * @implements hook_theme()
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> mytheme_theme<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;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">'mytheme_simple_iframe'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'template'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'simple_iframe'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'arguments'</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: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'width'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'700'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'500'</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</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;">?&gt;</span></pre></td></tr></table></div>


<p>Simple de compréhension, on déclare un fichier de template <code>simple_iframe</code> auquel 3 variables seront passées. Les arguments <code>width</code> et <code>height</code> ont une valeur par défaut de précisée, ce qui permet de les omettre dans la définition de la ressource externe dans le hook_menu.</p>

<p>Enfin, créez le fichier de template qui affichera une iframe.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * simple_iframe.tpl.php
 */</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div class=&quot;iframe&quot;&gt;
  &lt;iframe src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">print</span> <span style="color: #000088;">$url</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; width=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">print</span> <span style="color: #000088;">$width</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; height=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">print</span> <span style="color: #000088;">$height</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; frameborder=&quot;0&quot; align=&quot;left&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;</pre></td></tr></table></div>


<p>Désormais, tout accès à l&#8217;URL <code>/drupal/page/path</code> chargera le template <code>simple_iframe.tpl.php</code> lorsque <strong>Drupal</strong> effectuera le rendu de la variable <code>$content</code> du fichier <code>page.tpl.php</code>.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/compass-sprites-supprimer-cache-buster.html' title='Compass : supprimer le cache buster des sprites'>Compass&#160;: supprimer le cache buster des sprites</a></li><li><a href='http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html' title='Optimiser le chargement des AdSense'>Optimiser le chargement des AdSense</a></li><li><a href='http://pioupioum.fr/snippets/wordpress-autoriser-upload-media-format-inconnu.html' title='WordPress : autoriser l&#8217;upload de fichiers au format non-supporté'>WordPress&#160;: autoriser l&#8217;upload de fichiers au format non-supporté</a></li><li><a href='http://pioupioum.fr/snippets/apache-rotation-logs.html' title='Rotation des logs Apache'>Rotation des logs Apache</a></li><li><a href='http://pioupioum.fr/developpement/git-alias-productivite.html' title='Git : des alias pour aller plus vite'>Git&#160;: des alias pour aller plus vite</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>où <code>my_hook</code> correspond au nom du thème ou du module qui sert à enregistrer ces définitions.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=O8--qFuMo5k:GbwmjdWwmg8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=O8--qFuMo5k:GbwmjdWwmg8:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=O8--qFuMo5k:GbwmjdWwmg8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=O8--qFuMo5k:GbwmjdWwmg8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=O8--qFuMo5k:GbwmjdWwmg8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=O8--qFuMo5k:GbwmjdWwmg8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=O8--qFuMo5k:GbwmjdWwmg8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=O8--qFuMo5k:GbwmjdWwmg8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=O8--qFuMo5k:GbwmjdWwmg8:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/O8--qFuMo5k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/drupal-iframe-page.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/developpement/drupal-iframe-page.html</feedburner:origLink></item>
		<item>
		<title>Instances multiples de Compass avec Ruby Version Manager (rvm)</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/7dGgEbR4QN8/compass-rvm-multiple-instances.html</link>
		<comments>http://pioupioum.fr/developpement/compass-rvm-multiple-instances.html#comments</comments>
		<pubDate>Mon, 23 May 2011 19:56:22 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[compass]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=519</guid>
		<description><![CDATA[Dans le cadre de mon travail à Clever Age j&#8217;utilise dans plusieurs projets Compass, le framework Sass, dans sa version 0.10.6. Mais voilà, cette version a laissé place à la branche 0.11 qui, malheureusement, s&#8217;accompagne de son lot de mixins obsolètes voire de bugs avec certaines extensions.

Mes nouveaux projets feront appels à la dernière version [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Dans le cadre de mon travail à <a href="http://www.clever-age.com/" title="Clever Age, digital architecture">Clever Age</a> j&#8217;utilise dans plusieurs projets <strong><a href="http://compass-style.org/" title="Compass Home | Compass Documentation">Compass</a>, le framework <a href="http://sass-lang.com/" title="Sass - Syntactically Awesome Stylesheets">Sass</a></strong>, dans sa version 0.10.6. Mais voilà, cette version a laissé place à la branche 0.11 qui, malheureusement, s&#8217;accompagne de son lot de mixins obsolètes voire <a href="https://github.com/chriseppstein/compass/issues/306">de bugs</a> avec certaines extensions.</p>

<p>Mes nouveaux projets feront appels à la dernière version en date de Compass mais il me faut conserver une branche 0.10 sur mon poste pour assurer le support des anciens projets. Il est actuellement inconcevable de proposer aux clients une mise à jour des fichiers SCSS vers la branche 0.11.</p>

<p>Comment faire cohabiter les deux versions de Compass et leurs dépendances&#160;? C&#8217;est là qu&#8217;intervient <strong><a href="https://rvm.beginrescueend.com/" title="RVM: Ruby Version Manager">Ruby Version Manager</a></strong>, un gestionnaire d&#8217;environnements pour <a href="http://www.ruby-lang.org/fr/" title="Le langage Ruby">Ruby</a>.<span id="more-519"></span></p>

<h2>Installer RVM</h2>

<p>L&#8217;<a href="http://www.clever-age.com/veille/blog/ruby-version-manager-rvm.html" title="Ruby Version Manager (RVM) - Blog - Veille - Clever Age">installation de RVM</a> est des plus simples&#160;: il suffit de suivre la documentation.<br />
Je préfère installer RVM pour l&#8217;utilisateur courant (moi) et non pour tous les utilisateurs du poste, qui n&#8217;auront pas les mêmes besoins. Accessoirement, cela me permet de manipuler les gem sans invoquer <code>sudo</code>.</p>

<pre><code>$ cd
$ bash &lt; &lt;(curl -sk https://rvm.beginrescueend.com/install/rvm)
$ echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] &amp;&amp; . "$HOME/.rvm/scripts/rvm" # Load RVM function' &gt;&gt; ~/.bash_profile
$ source .bash_profile
$ type rvm | head -1
rvm is a function
</code></pre>

<p>J&#8217;en profite pour installer la dernière version stable de Ruby&#160;:</p>

<pre><code>$ rvm install 1.9.2
Installing Ruby from source to: /Users/mehdi/.rvm/rubies/ruby-1.9.2-p180, this may take a while depending on your cpu(s)...

ruby-1.9.2-p180 - #fetching 
ruby-1.9.2-p180 - #downloading ruby-1.9.2-p180, this may take a while depending on your connection...
…
Installing rubygems dedicated to ruby-1.9.2-p180...
…
Installation of rubygems completed successfully.
ruby-1.9.2-p180 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ruby-1.9.2-p180 - #importing default gemsets (/Users/mehdi/.rvm/gemsets/)
Install of ruby-1.9.2-p180 - #complete 
</code></pre>

<p>À ce point, la version de Ruby active sur le système est pourtant celle fournie par Apple (je suis toujours sous OSX :p)&#160;:</p>

<pre><code>$ ruby -v
ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0]
</code></pre>

<p>En effet, RVM a bien réalisé l&#8217;installation de Ruby 1.9.2 mais il faut déclarer explicitement notre souhait de l&#8217;utiliser en remplacement de la version système<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>&#160;:</p>

<pre><code>$ rvm use 1.9.2 --default
Using /Users/mehdi/.rvm/gems/ruby-1.9.2-p180
$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.7.0]
</code></pre>

<h2>Installation de la dernière version en date de Compass</h2>

<p>Classique, l&#8217;installation de Compass se fait <em>via</em> gem&#160;:</p>

<pre><code>$ gem install compass
Fetching: sass-3.1.1.gem (100%)
Fetching: chunky_png-1.2.0.gem (100%)
Fetching: fssm-0.2.7.gem (100%)
Fetching: compass-0.11.1.gem (100%)
Successfully installed sass-3.1.1
Successfully installed chunky_png-1.2.0
Successfully installed fssm-0.2.7
Successfully installed compass-0.11.1
4 gems installed
Installing ri documentation for sass-3.1.1...
Installing ri documentation for chunky_png-1.2.0...
Installing ri documentation for fssm-0.2.7...
Installing ri documentation for compass-0.11.1...
Installing RDoc documentation for sass-3.1.1...
Installing RDoc documentation for chunky_png-1.2.0...
Installing RDoc documentation for fssm-0.2.7...
Installing RDoc documentation for compass-0.11.1...
$ gem list

*** LOCAL GEMS ***

chunky_png (1.2.0)
compass (0.11.1)
fssm (0.2.7)
rake (0.9.0)
sass (3.1.1)
</code></pre>

<p>Une petite vérification d&#8217;usage&#160;:</p>

<pre><code>$ compass version 
Compass 0.11.1 (Antares)
Copyright (c) 2008-2011 Chris Eppstein
Released under the MIT License.
Compass is charityware.
Please make a tax deductable donation for a worthy cause: http://umdf.org/compass
</code></pre>

<p>Ok, mon environnement par défaut est prêt. Voyons comment faire cohabiter une ancienne version de Compass.</p>

<h2>Création d&#8217;un Gemset dédié à l&#8217;ancienne version de Compass</h2>

<p>En premier lieu, je me positionne sur l&#8217;environnement ruby voulu. Ici, il s&#8217;agit du Ruby que j&#8217;ai défini par défaut.</p>

<pre><code>$ rvm default
$ rvm gemset name
/Users/mehdi/.rvm/gems/ruby-1.9.2-p180
</code></pre>

<p>Recherchons la dernière version de la branche qui m&#8217;intéresse<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> (0.10 pour rappel)&#160;:</p>

<pre><code>$ gem query -ran ^compass$

*** REMOTE GEMS ***

compass (0.11.1, 0.11.0, 0.10.6, 0.10.5, 0.10.4, 0.10.3, 0.10.2, 0.10.1, 0.10.0, 0.8.17, 0.8.16)
</code></pre>

<p>Ok, il me faut la 0.10.6.<br />
RVM donne accès à des <strong>gemsets</strong> qui sont des espaces cloisonnés de gems pour une version de Ruby donnée. Pratique, j&#8217;ai justement besoin d&#8217;isoler les gems de la version 0.10.6 de Compass à celles de la dernière version en date.</p>

<p>Je crée un gemset au nom assez explicite et l&#8217;utilise&#160;:</p>

<pre><code>$ rvm gemset create compass0.10.6
$ rvm gemset use !$
$ rvm gemset name
compass0.10.6
</code></pre>

<p>La création d&#8217;un gemset fourni un nouvel environnement vierge de gems (ou presque, rake restant disponible)&#160;:</p>

<pre><code>$ gem list

*** LOCAL GEMS ***

rake (0.9.0)
</code></pre>

<p>Je peux maintenant installer Compass 0.10.6<sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup>, ses dépendances et autres extensions en toute tranquillité.</p>

<pre><code>$ gem install compass --version 0.10.6 --no-rdoc --no-ri
Fetching: haml-3.1.1.gem (100%)
Fetching: compass-0.10.6.gem (100%)
Successfully installed haml-3.1.1
Successfully installed compass-0.10.6
2 gems installed
$ gem list

*** LOCAL GEMS ***

compass (0.10.6)
haml (3.1.1)
rake (0.9.0)
</code></pre>

<p>La petite vérification d&#8217;usage&#160;:</p>

<pre><code>$ compass version
Compass 0.10.6
Copyright (c) 2008-2009 Chris Eppstein
Released under the MIT License.
</code></pre>

<h3>Installer l&#8217;extension Lemonade pour Compass 0.10.6</h3>

<p>Il ne me reste plus  qu&#8217;à installer l&#8217;extension <a href="http://www.hagenburger.net/BLOG/Lemonade-CSS-Sprites-for-Sass-Compass.html" title="Generate CSS Sprites on the Fly with Lemonade">lemonade</a> que j&#8217;utilise dans mes projets&#160;:</p>

<pre><code>$ gem install lemonade --version '&lt; 0.3.5' --no-rdoc --no-ri
…
4 gems installed
</code></pre>

<p>J&#8217;installe ici la version strictement inférieur à 0.3.5 de lemonade car cette dernière lève directement une erreur pour indiquer que la gem lemonade est désormais dépréciée au profit de Compass Sprites. Le hic étant que ce dernier n&#8217;existe pas dans Compass 0.10.6.</p>

<p>Malheureusement, la gem de lemonade ne précise pas les bonnes versions de ses dépendances, et, de ce fait, on se retrouve avec un environnement incapable de générer les images des sprites. Pour corriger cela, on commence par downgrader la version de <strong><a href="http://rubygems.org/gems/chunky_png">chunky_png</a></strong>&#160;:</p>

<pre><code>$ gem uninstall chunky_png --version 1.2.0
$ gem install chunky_png --version '&lt; 1.0.0' --no-rdoc --no-ri
…
1 gem installed  
</code></pre>

<p>La gem <strong>haml</strong> installée avec l&#8217;extension <em>lemonade</em> est incompatible avec Compass 0.10.6 et risque de générer une erreur du genre&#160;:</p>

<pre><code>compile scss/screen.scss
  error scss/screen.scss (Line 2087: Not a valid color stop: #bcd712 74%)
</code></pre>

<p>Il suffit donc d&#8217;installer la dernière version de la branche 3.0&#160;:</p>

<pre><code>$ gem install haml --version '&lt; 3.1' --no-rdoc --no-ri
$ gem uninstall haml --version 3.1.1
$ gem list

*** LOCAL GEMS ***

chunky_png (0.12.0)
compass (0.10.6)
fssm (0.2.7)
haml (3.0.25)
lemonade (0.3.4)
rake (0.9.0)
sass (3.1.1)
</code></pre>

<h2>Utilisation</h2>

<p>Par défaut, en ouvrant un shell, Compass sera disponible en version 0.11. Si j&#8217;ai à travailler sur un projet en 0.10 il me suffit d&#8217;ouvrir un nouveau shell et d&#8217;activer temporairement le <strong>gemset compass0.10.6</strong>&#160;:</p>

<pre><code>$ rvm gemset use compass0.10.6
</code></pre>

<p>À l&#8217;avenir, je maintiendrai à jour la version de Compass dans l&#8217;environnement par défaut et, si besoin est, je figerai dans un nouveau gemset la version de Compass devenu obsolète.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/compass-sprites-supprimer-cache-buster.html' title='Compass : supprimer le cache buster des sprites'>Compass&#160;: supprimer le cache buster des sprites</a></li><li><a href='http://pioupioum.fr/snippets/php-installer-apc-macosx.html' title='PHP : installer APC sous Mac OS X Leopard'>PHP&#160;: installer APC sous Mac OS X Leopard</a></li><li><a href='http://pioupioum.fr/snippets/apache-rotation-logs.html' title='Rotation des logs Apache'>Rotation des logs Apache</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-css-selection-unicode.html' title='TextMate : bundle CSS, commande &quot;Convertir la sélection en Unicode&quot;'>TextMate&#160;: bundle CSS, commande &quot;Convertir la sélection en Unicode&quot;</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>vous pouvez activer ponctuellement (le temps de vie du shell) un autre environnement à l&#8217;aide de la commande <code>rvm use</code> en omettant l&#8217;option <code>--default</code>. Pour revenir à l&#8217;environnement par défaut, un petit <code>rvm default</code> suffit.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>j&#8217;aurai très bien pu directement invoquer la commande <code>gem install compass --version '&lt; 0.11'</code> et me passer de la recherche <em>via</em> <code>gem query</code>. Je laisse en l&#8217;état pour donner un exemple d&#8217;utilisation de la commande <code>query</code>.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:3">
<p>Je fais l&#8217;impasse sur l&#8217;installation des documentations pour ce gemset, d&#8217;où les arguments <code>--no-rdoc</code> et <code>--no-ri</code>.&#160;<a href="#fnref:3" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=7dGgEbR4QN8:yE7dNUIuYZA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=7dGgEbR4QN8:yE7dNUIuYZA:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=7dGgEbR4QN8:yE7dNUIuYZA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=7dGgEbR4QN8:yE7dNUIuYZA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=7dGgEbR4QN8:yE7dNUIuYZA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=7dGgEbR4QN8:yE7dNUIuYZA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=7dGgEbR4QN8:yE7dNUIuYZA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=7dGgEbR4QN8:yE7dNUIuYZA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=7dGgEbR4QN8:yE7dNUIuYZA:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/7dGgEbR4QN8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/compass-rvm-multiple-instances.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/developpement/compass-rvm-multiple-instances.html</feedburner:origLink></item>
		<item>
		<title>Photon : guide d’installation sur Mac OS X Snow Leopard</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/4Tz74cL3esw/photon-php-installer-mac-os-x-snow-leopard.html</link>
		<comments>http://pioupioum.fr/developpement/photon-php-installer-mac-os-x-snow-leopard.html#comments</comments>
		<pubDate>Sun, 27 Feb 2011 18:58:43 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Photon]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=507</guid>
		<description><![CDATA[Créé par Loïc d&#8217;Anterroches, Photon1 est un micro framework PHP distribué sous licence LGPL qui fonctionne au-dessus du serveur web Mongrel2 et du service de messagerie asynchrone ØMQ2.
Voici un petit guide d&#8217;installation pour ce framework PHP pas comme les autres.

Pré-requis

Je considère que vous disposez sur votre système d&#8217;une version de PHP 5.3 installée via macports, [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Créé par <a href="http://xhtml.net/" title="XHTML.net by Loïc d'Anterroches">Loïc d&#8217;Anterroches</a>, <strong><a href="http://www.photon-project.com/" title="Photon, High Performance PHP Framework">Photon</a></strong><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> est un <strong>micro framework PHP</strong> distribué sous licence <a href="http://www.gnu.org/licenses/lgpl.html" title="GNU Lesser General Public License v3.0 - GNU Project - Free Software Foundation (FSF)">LGPL</a> qui fonctionne au-dessus du serveur web <strong><a href="http://mongrel2.org/" title="Mongrel2: The Language Agnostic Web Server">Mongrel2</a></strong> et du service de messagerie asynchrone <strong><a href="http://www.zeromq.org/" title="Less is More - zeromq">ØMQ</a></strong><sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup>.<br />
Voici un petit guide d&#8217;installation pour ce framework PHP pas comme les autres.<span id="more-507"></span></p>

<h2>Pré-requis</h2>

<p>Je considère que vous disposez sur votre système d&#8217;une version de <strong>PHP 5.3</strong> installée <em>via</em> <strong>macports</strong>, à l&#8217;aide du port <code>php5</code>.</p>

<p>Photon effectue des contrôles de processus. Pour ce faire, la présence de l&#8217;extension PHP <a href="http://www.php.net/manual/fr/book.pcntl.php">PCNTL</a> est obligatoire.<br />
Vérifiez que vous la possédez&#160;:</p>

<pre><code>$ php -i | grep pcntl
/opt/local/var/db/php5/pcntl.ini,
pcntl
pcntl support =&gt; enabled
</code></pre>

<p>Si ce n&#8217;est pas le cas, lancez une installation macports&#160;:</p>

<pre><code>$ sudo port install php5-pcntl
</code></pre>

<p><strong>Mongrel2</strong> requiert SQLite et ZeroMQ. Aussi, s&#8217;il n&#8217;est pas encore présent dans votre environnement de développement, il sera bon d&#8217;installer XDebug.<br />
Vérifiez la présence de ces pré-requis sur votre poste&#160;:</p>

<pre><code>$ port installed sqlite3 zmq php5-xdebug
The following ports are currently installed:
  php5-xdebug @2.1.0_0 (active)
  sqlite3 @3.7.5_0 (active)
  zmq @2.0.10_0 (active)
</code></pre>

<p>S&#8217;il vient à manquer des ports dans la liste ainsi générée, installez-les avec la commande <code>port install</code>&#160;:</p>

<pre><code>sudo port install zmq
</code></pre>

<p>Dans le cas où vous ne possédez aucune de ces libraires, vous pouvez les installer en une unique commande</p>

<pre><code>sudo port install sqlite3 zmq php5-xdebug php5-pcnt
</code></pre>

<h2>Installer Mongrel2 sous Mac OS X Snow Leopard</h2>

<p>Contre toute attente, au moment où cet article est rédigé, <strong>Mongrel2</strong> n&#8217;est pas disponible dans <strong>macports</strong>. Qu&#8217;à cela ne tienne, procédez à son installation depuis les sources&#160;:</p>

<pre><code>sudo port install wget
wget http://mongrel2.org/static/downloads/mongrel2-1.5.tar.bz2
tar xjvf mongrel2-1.5.tar.bz2
cd mongrel2-1.5/
sudo make clean macports install
</code></pre>

<p>L&#8217;option <code>macports</code> du Makefile ne signifie par que <strong>Mongrel2</strong> s&#8217;installera dans l&#8217;environnement de macports, mais qu&#8217;il va utiliser les libraires disponibles depuis cet environnement (soit généralement <code>/opt/local/</code>). Le binaire est généré dans le répertoire <code>/usr/local/bin/</code>&#160;:</p>

<pre><code>which m2sh
/usr/local/bin/m2sh
</code></pre>

<h2>Installer Photon</h2>

<p>L&#8217;installation de <strong>Photon</strong> est des plus simple. En effet, tout passe par <a href="http://dist.photon-project.com/" title="Photon Distribution Channel">PEAR</a>.</p>

<p>Commencez par déclarer les canaux du projet Photon, de l&#8217;extension PHP pour <strong>ØMQ</strong> puis ceux de PHPUnit
et ses dépendances&#160;:</p>

<pre><code>sudo pear channel-discover dist.photon-project.com
sudo pear channel-discover pear.zero.mq
sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover pear.symfony-project.com
sudo pear channel-discover components.ez.no
</code></pre>

<p>N&#8217;ayez aucune inquiétude quant à la présence des dépendances Symfony et eZ Publish. Ces dernières sont requises par <strong>PHPUnit</strong> qui n&#8217;y récupérera qu&#8217;un nombre limité de composants (comme le parser YAML de Symfony) et n&#8217;ira pas vous installer les 2 solutions dans leur intégralité.</p>

<p>Il ne vous reste plus qu&#8217;à lancer l&#8217;installation proprement dite de <strong>Photon</strong>&#160;:</p>

<pre><code>sudo pear install --alldeps photon/photon-alpha
sudo sh -c 'echo "extension=http.so" &gt; /opt/local/var/db/php5/http.ini'
sudo sh -c 'echo "extension=zmq.so" &gt; /opt/local/var/db/php5/zmq.ini'    
</code></pre>

<h3>Tester votre installation de Photon</h3>

<p>L&#8217;installation terminée, Photon est accessible par la commande <code>hnu</code><sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup>. Afin de vous en assurer, lancez simplement sa propre batterie de tests unitaires, comme suit&#160;:</p>

<pre><code>hnu selftest
</code></pre>

<h3>Could not open input file: /usr/share/php/photon.php</h3>

<p>Si vous rencontrez l&#8217;erreur <code>Could not open input file: /usr/share/php/photon.php</code> c&#8217;est que vous utilisez une version de Photon inférieure ou égale à 0.0.5. Si à l&#8217;heure où je rédige ces lignes la version 0.0.6 de Photon n&#8217;est pas disponible, exécutez l&#8217;ensemble des commandes ci-dessous pour fixer le problème&#160;:</p>

<pre><code>cd ~/Downloads/
wget -O hnu.diff http://projects.ceondo.com/p/photon/source/ddiff/9acba649ae355aaf4b365a1f639961336ae6a323/
sudo patch --no-backup-if-mismatch -i hnu.diff `pear config-get bin_dir`/hnu
rm hnu.diff
cd -
</code></pre>

<h2>Mettre à jour Photon</h2>

<p>Encore une fois, la procédure est des plus simple grâce à PEAR&#160;:</p>

<pre><code>$ sudo pear update-channels
Update of Channel "dist.photon-project.com" succeeded
$ sudo pear upgrade photon/photon-alpha
downloading photon-0.0.5.tgz ...
Starting to download photon-0.0.5.tgz (3,937,334 bytes)
...........................................................................done: 3,937,334 bytes
upgrade ok: channel://dist.photon-project.com/photon-0.0.5
</code></pre>

<h2>Accéder aux sources de Photon</h2>

<p>Vous pouvez accéder en local aux sources de Photon dans le répertoire <code>/opt/local/lib/php</code>. Avec TextMate par exemple&#160;:</p>

<pre><code>mate -a `pear config-get php_dir`/photon*
</code></pre>

<p>Autrement, vous pouvez directement accéder aux sources du projet par la <a href="http://projects.ceondo.com/p/photon/source/tree/develop/" title="Photon Git Source Tree - The High Speed PHP Framework">forge Indefero du projet</a>.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/php-installer-apc-macosx.html' title='PHP : installer APC sous Mac OS X Leopard'>PHP&#160;: installer APC sous Mac OS X Leopard</a></li><li><a href='http://pioupioum.fr/snippets/wordpress-create-shortcode-class.html' title='WordPress : une classe abstraite pour aider la création de shortcodes'>WordPress&#160;: une classe abstraite pour aider la création de shortcodes</a></li><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li><li><a href='http://pioupioum.fr/snippets/php-uncamel-fonction-convertir-camel-case.html' title='PHP : fonction uncamel() pour inverser une notation en CamelCase'>PHP&#160;: fonction uncamel() pour inverser une notation en CamelCase</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>Pour la petite histoire, j&#8217;ai donné son petit nom au framework \o/&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>Lire ZeroMQ. S&#8217;écrit également ZeroMQ, 0MQ ou ZMQ.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:3">
<p>le nom de la commande <code>hnu</code> vient de &#x210E;&nu;, la notation des <a href="http://fr.wikipedia.org/wiki/Photon" title="Photon - Wikipédia">photons</a> en chimie et en optique.&#160;<a href="#fnref:3" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=4Tz74cL3esw:RydeucOUbq8:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=4Tz74cL3esw:RydeucOUbq8:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=4Tz74cL3esw:RydeucOUbq8:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=4Tz74cL3esw:RydeucOUbq8:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=4Tz74cL3esw:RydeucOUbq8:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=4Tz74cL3esw:RydeucOUbq8:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=4Tz74cL3esw:RydeucOUbq8:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=4Tz74cL3esw:RydeucOUbq8:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=4Tz74cL3esw:RydeucOUbq8:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/4Tz74cL3esw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/photon-php-installer-mac-os-x-snow-leopard.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/developpement/photon-php-installer-mac-os-x-snow-leopard.html</feedburner:origLink></item>
		<item>
		<title>Shortcode WordPress : afficher les documents liés aux billets</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/4lv6Y1LKGEI/wordpress-shortcode-afficher-fichiers-joints.html</link>
		<comments>http://pioupioum.fr/outils-astuces/wordpress-shortcode-afficher-fichiers-joints.html#comments</comments>
		<pubDate>Thu, 23 Sep 2010 06:55:29 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Outils, trucs et astuces]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=453</guid>
		<description><![CDATA[J&#8217;ai récemment eu besoin d&#8217;afficher de manière élégante les pièces jointes à des articles et des pages. Seulement, avec un WordPress qui autorise l&#8217;ajout de documents autres que des images/vidéos et rien pour les insérer proprement dans un contenu, la tâche est loin d&#8217;être aisée.


  Un coup de XHTML et roule ma poule&#160;!


Oui&#160;! Si [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>J&#8217;ai récemment eu besoin d&#8217;afficher de manière élégante les <strong>pièces jointes</strong> à des articles et des pages. Seulement, avec un <strong>WordPress</strong> qui autorise l&#8217;ajout de documents autres que des images/vidéos et rien pour les insérer proprement dans un contenu, la tâche est loin d&#8217;être aisée.</p>

<blockquote>
  <p>Un coup de XHTML et roule ma poule&#160;!</p>
</blockquote>

<p>Oui&#160;! Si j&#8217;étais le rédacteur du site (comme ici). Mais il n&#8217;en est rien. Il fallait une solution utilisable depuis l&#8217;éditeur WYSIWYG, sans avoir à intervenir sur la source XHTML (genre pour ajouter un div, une image, des classes CSS, etc).</p>

<p>Voici donc un <strong><a href="http://codex.wordpress.org/Shortcode_API" title="Shortcode API &laquo; WordPress Codex">shortcode</a> WordPress</strong> qui <strong>affiche la liste des pièces jointes</strong>.</p>

<p><div id="attachment_468" class="wp-caption aligncenter" style="width: 620px"><img src="http://assets1.pioupioum.fr/uploads/2010/09/wp-shortcode-attachments.png" alt="Le shortcode en action" title="Shortcode attachments - Illustration" width="610" height="255" class="size-full wp-image-468"/><p class="wp-caption-text">Le shortcode en action</p></div><span id="more-453"></span></p>

<h2>Table des matières</h2>

<ol>
<li><a href="#telecharger">Code source</a></li>
<li><a href="#styles">Différents styles d&#8217;affichage</a></li>
<li><a href="#exemples">Exemples d&#8217;utilisation</a></li>
<li><a href="#parametres">Liste des paramètres</a></li>
<li><a href="#personnaliser">Personnaliser le shortcode</a></li>
<li><a href="#changelog">Historique des versions et changelog</a></li>
</ol>

<h2 id="telecharger">Code source</h2>

<p>Le shortcode présenté dans ce billet nécessite la présence de la <a href="http://pioupioum.fr/snippets/wordpress-create-shortcode-class.html" title="WordPress : une classe abstraite pour aider la création de shortcodes &#8211; PHP abstract class to create shortcodes in WordPress – piouPiouM&#039;s dev">classe abstraite d&#8217;aide à la création de shortcode</a> <strong>PPM_Shortcode</strong>. Si ce n&#8217;est pas déjà fait, récupérez-là et rendez-la disponible pour la classe <code>AttachmentsListShortCode</code>.</p>

<p>Copiez le code qui suit dans le fichier <code>functions.php</code> de votre thème<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Add the new shortcode `attachments`.
 */</span>
<span style="color: #000088;">$attachments_list</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AttachmentsListShortCode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'attachments'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachments_list</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Shortcode to display a list of attachments of the current post.
 *
 * Attributes to use as follows:
 *     'exclude' - Default is none. List of IDs of the attachments to exclude of search.
 *     'orderby' - Default is 'title ASC'. How to order the attachments.
 *     'style'   - Default is 'large'. Presentation style to use.
 *
 * @author Mehdi Kabab &lt;http://pioupioum.fr/&gt;
 * @copyright Copyright (C) 2010 Mehdi Kabab
 * @license http://www.gnu.org/licenses/gpl.html  GNU GPL version 3 or later
 * @version 1.0.0
 * @link http://pioupioum.fr/outils-astuces/wordpress-shortcode-afficher-fichiers-joints.html
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> AttachmentsListShortCode <span style="color: #000000; font-weight: bold;">extends</span> PPM_Shortcode
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Default options.
     *
     * @var array
     **/</span>
    protected <span style="color: #000088;">$_default_options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'exclude'</span> <span style="color: #339933;">=&gt;</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;">'orderby'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'title ASC'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'style'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Keys allowed in the query ORDER BY clause.
     *
     * @param array
     */</span>
    protected <span style="color: #000088;">$_allowed_orderby</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'mime_type'</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Directory of MIME icons.
     * The path is relative to the current theme.
     *
     * @var string
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_icons_dir</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Clause ORDER BY to be applied to sorting.
     *
     * @var string
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_orderby</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Stack of the presentation styles for the attachments.
     *
     * @var ArrayObject
     **/</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_styles</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Constructor.
     *
     * @param string $tag Shortcode tag to be searched in post content.
     * @param string $icons_dir Directory of MIME icons.
     */</span>
    <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;">$tag</span><span style="color: #339933;">,</span> <span style="color: #000088;">$icons_dir</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'images/mime'</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag</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;">setIconsDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$icons_dir</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>_styles <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayObject<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>
                                         ArrayObject<span style="color: #339933;">::</span><span style="color: #004000;">ARRAY_AS_PROPS</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;">$this</span><span style="color: #339933;">-&gt;</span>_getDefaultStyles<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tpl</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$data</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;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</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;">$default</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>boolean<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
                <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'default'</span><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: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$default</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tpl</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$default</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: #009933; font-style: italic;">/**
     * Retrieve directory of MIME icons.
     *
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getIconsDirectory<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>_icons_dir<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Set the directory of MIME icons.
     *
     * @return PPM_Shortcode
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setIconsDirectory<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</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>_icons_dir <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Retrieve the stack of the presentation styles.
     *
     * @return ArrayObject
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getStyles<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>_styles<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Set a presentation style of the attachments.
     *
     * @param string $name Presentation style name.
     * @param array $data Style data.
     * @param boolean $default True for set this style as default style.
     * @return PPM_Shortcode
     * @throws Exception If the data are not valid.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setStyle<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$data</span><span style="color: #339933;">,</span> <span style="color: #000088;">$default</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: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_isValidStyle<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Data for the style `%s` are not valid!'</span><span style="color: #339933;">,</span>
                                        <span style="color: #000088;">$name</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_styles<span style="color: #009900;">&#91;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayObject<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #339933;">,</span>
                                                   ArrayObject<span style="color: #339933;">::</span><span style="color: #004000;">ARRAY_AS_PROPS</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;">true</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$default</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><span style="color: #004000;">setStyleByDefault</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Retrieve name of the presentation style used by default.
     *
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getStyleByDefault<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>_default_options<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'style'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Set name of the presentation style to use by default.
     *
     * @param string $name
     * @return PPM_Shortcode
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setStyleByDefault<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</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>_default_options<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'style'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * [filter] Edit the clause ORDER BY to allow sorting by mime_type.
     *
     * @param string $orderby The ORDER BY clause.
     * @return string The new ORDER BY clause.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> filterOrderby<span style="color: #009900;">&#40;</span><span style="color: #000088;">$orderby</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;">$this</span><span style="color: #339933;">-&gt;</span>_orderby <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">in_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_orderby<span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_allowed_orderby<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$orderby</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#^([^\.]+\.)(\w+)(\s+ASC|DESC)$#i'</span><span style="color: #339933;">,</span>
                                    <span style="color: #0000ff;">'$1post_'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_orderby <span style="color: #339933;">.</span> <span style="color: #0000ff;">'$3'</span><span style="color: #339933;">,</span>
                                    <span style="color: #000088;">$orderby</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$orderby</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * @see PPM_Shortcode::_process()
     */</span>
    protected <span style="color: #000000; font-weight: bold;">function</span> _process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">offsetExists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'style'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$style</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'style'</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;">$style</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStyleByDefault</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: #666666; font-style: italic;">// Order and Order by clauses</span>
        <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$orderby</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order</span><span style="color: #009900;">&#41;</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;">$this</span><span style="color: #339933;">-&gt;</span>_default_options<span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'orderby'</span><span style="color: #009900;">&#93;</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;">false</span> <span style="color: #339933;">!==</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'orderby'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">list</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$orderby</span><span style="color: #339933;">,</span> <span style="color: #000088;">$order</span><span style="color: #009900;">&#41;</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'orderby'</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;">$orderby</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'orderby'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_orderby <span style="color: #339933;">=</span> <span style="color: #000088;">$orderby</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Retrieve the attachments</span>
        <span style="color: #000088;">$attachments</span> <span style="color: #339933;">=</span> get_children<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'post_parent'</span> <span style="color: #339933;">=&gt;</span> get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'post_type'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'attachment'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'numberposts'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'exclude'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'exclude'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'orderby'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_orderby<span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'order'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ASC'</span> <span style="color: #339933;">===</span> <span style="color: #990000;">strtoupper</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'ASC'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'DESC'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'exclude'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getOption</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'exclude'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'suppress_filters'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #666666; font-style: italic;">// Allows to edit the query</span>
        <span style="color: #009900;">&#41;</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;">false</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$attachments</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// Edit the query</span>
        add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'posts_orderby'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'filterOrderby'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$tpl</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$style</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$attachment</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">// Do not display image attachments</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span> <span style="color: #339933;">===</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_mime_type</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'image/'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Determine the filename</span>
            <span style="color: #000088;">$file_type</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_mime_type</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'/-'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'__'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$file_name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getIconsDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file_type</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.png'</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">file_exists</span><span style="color: #009900;">&#40;</span>get_stylesheet_directory<span style="color: #009900;">&#40;</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;">$file_name</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$icon_file</span> <span style="color: #339933;">=</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_directory'</span><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: #0000ff;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$file_name</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;">$icon_file</span> <span style="color: #339933;">=</span> wp_mime_type_icon<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</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;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'getimagesize'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$size_attr</span> <span style="color: #339933;">=</span>  <span style="color: #990000;">getimagesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$icon_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$size_attr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$size_attr</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</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;">$size_attr</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$file_path</span> <span style="color: #339933;">=</span> get_attached_file<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$context</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'ID'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'filename'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'file_date'</span> <span style="color: #339933;">=&gt;</span> mysql2date<span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'date_format'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                                          <span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_date</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'file_size'</span> <span style="color: #339933;">=&gt;</span> esc_attr<span style="color: #009900;">&#40;</span>size_format<span style="color: #009900;">&#40;</span><span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file_path</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'file_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_mime_type</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'file_url'</span>  <span style="color: #339933;">=&gt;</span> esc_attr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'icon_atts'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$size_attr</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'icon_path'</span> <span style="color: #339933;">=&gt;</span> esc_attr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$icon_file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'title'</span>     <span style="color: #339933;">=&gt;</span> esc_attr<span style="color: #009900;">&#40;</span>get_the_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attachment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'label_filename'</span>  <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'File name:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'label_file_date'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Upload date:'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'label_file_size'</span> <span style="color: #339933;">=&gt;</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Size:'</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// Hook for customize the context</span>
            <span style="color: #000088;">$context</span> <span style="color: #339933;">=</span> apply_filters<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'attachments_list_context'</span><span style="color: #339933;">,</span>
                                     <span style="color: #000088;">$context</span><span style="color: #339933;">,</span>
                                     <span style="color: #000088;">$attachment</span><span style="color: #339933;">,</span>
                                     <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStyles</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$style</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #000088;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_compileMarkup<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tpl</span><span style="color: #339933;">,</span> <span style="color: #000088;">$context</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">before</span> <span style="color: #339933;">.</span> do_shortcode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$result</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">after</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Performs substitutions in the markup of the selected presentation style.
     *
     * @param ArrayObject $tpl
     * @param array $context
     * @return string The markup after substitutions.
     */</span>
    protected <span style="color: #000000; font-weight: bold;">function</span> _compileMarkup<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tpl</span><span style="color: #339933;">,</span> <span style="color: #000088;">$context</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$markup</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tpl</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">markup</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$context</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$markup</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'%'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$markup</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$markup</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Retrieve the default stack of the presentation styles.
     *
     * Declare the `medium`, `small` and `large` presentation styles.
     *
     * @return array
     */</span>
    protected <span style="color: #000000; font-weight: bold;">function</span> _getDefaultStyles<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;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'medium'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;attachments-list-medium&quot;&gt;'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'after'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'markup'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;attachment-item attachment-%ID%&quot;&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'&lt;a href=&quot;%file_url%&quot; title=&quot;%title% (%file_size%)&quot; rel=&quot;attachment&quot;&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'&lt;img src=&quot;%icon_path%&quot;%icon_atts% alt=&quot;&quot;/&gt;&lt;small&gt;%title%&lt;/small&gt;&lt;/a&gt;'</span> <span style="color: #339933;">.</span> 
                            <span style="color: #0000ff;">'&lt;/div&gt;'</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'small'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;attachments-list-small&quot;&gt;'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'after'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'markup'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;attachment-small-icon attachment-%ID%&quot;&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'&lt;img src=&quot;%icon_path%&quot;%icon_atts% alt=&quot;&quot;/&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'&lt;a href=&quot;%file_url%&quot; title=&quot;%title%&quot; rel=&quot;attachment&quot;&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'%title%&lt;/a&gt;&amp;nbsp;(%file_size%)'</span> <span style="color: #339933;">.</span> 
                            <span style="color: #0000ff;">'&lt;/div&gt;'</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'large'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;attachments-list-large&quot;&gt;'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'after'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'markup'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;dl class=&quot;attachment-item attachment-%ID%&quot;&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'&lt;dt&gt;&lt;a href=&quot;%file_url%&quot; title=&quot;%title%&quot; rel=&quot;attachment&quot;&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'&lt;img class=&quot;alignleft&quot; src=&quot;%icon_path%&quot;%icon_atts% alt=&quot;&quot;/&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'%title%&lt;/a&gt;&lt;/dt&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'&lt;dd&gt;&lt;span&gt;%label_filename%&lt;/span&gt; %filename%&lt;/dd&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'&lt;dd&gt;&lt;span&gt;%label_file_date%&lt;/span&gt; %file_date%&lt;/dd&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'&lt;dd&gt;&lt;span&gt;%label_file_size%&lt;/span&gt; %file_size%&lt;/dd&gt;'</span> <span style="color: #339933;">.</span>
                            <span style="color: #0000ff;">'&lt;/dl&gt;'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'default'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</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;">/**
     * Test if the data of a presentation style are well formed.
     *
     * @param array $data
     * @return boolean
     */</span>
    protected <span style="color: #000000; font-weight: bold;">function</span> _isValidStyle<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$ok</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</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;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>
              <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'before'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>
              <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'after'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>
              <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'markup'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$ok</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<p>Il vous faut également intégrer à votre thème les styles CSS qui suivent. Ceux-ci demeurant être une suggestion.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.attachments-list-large</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.attachments-list-medium</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.attachments-list-small</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-large</span> <span style="color: #6666ff;">.attachment-item</span> img<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.attachments-list-medium</span> <span style="color: #6666ff;">.attachment-item</span> img<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.attachments-list-small</span> <span style="color: #6666ff;">.attachment-item</span> img <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-large</span> <span style="color: #6666ff;">.attachment-item</span> dl <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">1.5em</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-large</span> <span style="color: #6666ff;">.attachment-item</span> dt <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-large</span> <span style="color: #6666ff;">.attachment-item</span> dd <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0.85em</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.5em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-large</span> <span style="color: #6666ff;">.attachment-item</span> img <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-large</span> <span style="color: #6666ff;">.attachment-item</span> img <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-medium</span> <span style="color: #6666ff;">.attachment-item</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline-table</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.5em</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">0.15em</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-medium</span> <span style="color: #6666ff;">.attachment-item</span> a <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-medium</span> <span style="color: #6666ff;">.attachment-item</span> small <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0.85em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-small</span> img <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> text-<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>


<p>Ou si vous utilisez SCSS&#160;:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.attachments-list-large</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.attachments-list-medium</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.attachments-list-small</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
    <span style="color: #6666ff;">.attachment-item</span> <span style="color: #00AA00;">&#123;</span>
        img <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-large</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #6666ff;">.attachment-item</span> <span style="color: #00AA00;">&#123;</span>
        $space<span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">;</span>
        dl <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #00AA00;">&#40;</span>$space <span style="color: #00AA00;">+</span> <span style="color: #933;">0.5em</span><span style="color: #00AA00;">&#41;</span> $space<span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        dt <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        dd <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0.85em</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #00AA00;">&#40;</span>$space <span style="color: #00AA00;">+</span> <span style="color: #933;">0.5em</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        img <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #00AA00;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> $space<span style="color: #00AA00;">;</span>
            <span style="color: #00AA00;">&#125;</span>
        <span style="color: #00AA00;">&#125;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-medium</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #6666ff;">.attachment-item</span> <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline-table</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1.5em</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">0.15em</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10em</span><span style="color: #00AA00;">;</span>
        a <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        small <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
            <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0.85em</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.attachments-list-small</span> <span style="color: #00AA00;">&#123;</span>
    img <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> text-<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>


<h2 id="styles">Différents styles d&#8217;affichage</h2>

<p>Le <strong>shortcode attachments</strong> propose trois formats d&#8217;affichage des pièces jointes&#160;: <em>medium</em>, <em>large</em> (par défaut) et <em>small</em>.</p>

<p><img src="http://assets1.pioupioum.fr/uploads/2010/09/attachment-shortcode-small.png" alt="Shortcode attachments - Style small" title="Shortcode attachments - Style small" width="600" height="200" class="aligncenter size-full wp-image-479" /></p>

<pre><code>[attachments style="small"]
</code></pre>

<p><img src="http://assets1.pioupioum.fr/uploads/2010/09/attachment-shortcode-medium.png" alt="Shortcode attachments - Style medium" title="Shortcode attachments - Style medium" width="600" height="310" class="aligncenter size-full wp-image-482" /></p>

<pre><code>[attachments style="medium"]
</code></pre>

<p><img src="http://assets1.pioupioum.fr/uploads/2010/09/attachment-shortcode-large.png" alt="Shortcode attachments - Style large" title="Shortcode attachments - Style large" width="600" height="345" class="aligncenter size-full wp-image-483" /></p>

<pre><code>[attachments style="large"]
</code></pre>

<h2 id="exemples">Exemples d&#8217;utilisation</h2>

<h3>Usage basique</h3>

<pre><code>[attachments]
</code></pre>

<h3>Exclure des documents de la liste</h3>

<p>Ici, nous excluons de la liste les documents ayant les identifiants <code>53</code> et <code>56</code>.</p>

<pre><code>[attachments exclude="53,56"]
</code></pre>

<h3>Liste des documents triés par date de mise en ligne</h3>

<pre><code>[attachments orderby="date"]
</code></pre>

<h3>Liste des documents triés par date, les plus récents en premier</h3>

<pre><code>[attachments orderby="date DESC"]
</code></pre>

<h3>Liste des documents triés par type de document</h3>

<pre><code>[attachments orderby="mime_type"]
</code></pre>

<h3>Cumul des paramètres</h3>

<p>Les paramètres peuvent être cumulés, sans ordre précis.</p>

<pre><code>[attachments style="large" exclude="53" orderby="date"]
</code></pre>

<h3>Ajouter un titre à la liste</h3>

<p>Le <strong>shortcode attachments</strong> existe aussi en forme englobante. Tout contenu englobé préfixera la liste des pièces jointes générées.</p>

<p><img src="http://assets1.pioupioum.fr/uploads/2010/09/attachment-shortcode-large-content.png" alt="Shortcode attachments - Avec contenu" title="Shortcode attachments - Avec contenu" width="600" height="195" class="aligncenter size-full wp-image-484" /></p>

<pre><code>[attachments]
&lt;h2&gt;Avec un contenu&lt;/h2&gt;
&lt;p&gt;Ce shortcode englobe le titre qui précède et ce paragraphe.&lt;/p&gt;
[/attachments]
</code></pre>

<h2 id="parametres">Liste des paramètres</h2>

<p>Voici la liste des paramètres acceptés par le shortcode <code>attachments</code>&#160;:</p>

<p><strong>exclude</strong><br />
<em>(optionnel)</em> La liste des ID séparés par des virgules des documents à exclure de la liste. Vide par défaut. Toutes les pièces jointes au contenu sont affichées.</p>

<p><strong>orderby</strong><br />
<em>(optionnel)</em> Le type de tri appliqué à la liste. Par défaut <em>title ASC</em>, les document sont triés par titre et par ordre alphabétique.</p>

<p><strong>style</strong>
<em>(optionnel)</em> Le type de présentation de la liste. Trois formats sont disponibles&#160;: <code>small</code>, <code>medium</code> et <code>large</code> (par défaut). Se reporter aux <a href="#exemples">exemples</a> pour avoir des aperçus.</p>

<h2 id="personnaliser">Personnaliser le shortcode</h2>

<p>Afin de correspondre aux besoins du plus grand nombre, le <strong>shortcode attachments</strong> offre diverses possibilités de personnalisation.</p>

<h3>Ajouter un type de présentation</h3>

<p>Si vous souhaitez afficher une simple liste ordonnée des pièces jointes, déclarez un nouveau style au shortcode comme suit&#160;:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$attachments_list</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AttachmentsListShortCode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'attachments'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$ol_style</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'before'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;ol class=&quot;attachments-list-ol&quot;&gt;'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'after'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/ol&gt;'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'markup'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;li&gt;&lt;a href=&quot;%file_url%&quot; rel=&quot;attachment&quot;&gt;%title%&lt;/a&gt;&lt;/li&gt;'</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachments_list</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setStyle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ol'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$ol_style</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<p>Puis, appelez-le dans un billet&#160;:</p>

<pre><code>[attachments style="ol"]
</code></pre>

<p><img src="http://assets1.pioupioum.fr/uploads/2010/09/attachment-shortcode-customized.png" alt="Shortcode attachments - Style personnalisé" title="Shortcode attachments - Style personnalisé" width="600" height="215" class="aligncenter size-full wp-image-491" /></p>

<p>Notez que la déclaration d&#8217;un style peut se faire après l&#8217;enregistrement du shortcode. La seule contrainte étant de la faire avant l&#8217;appel au shortcode par WordPress.</p>

<p>Si vous souhaitez définir un style de présentation à utiliser par défaut, deux possibilités&#160;:</p>

<ul>
<li>Lors de la déclaration d&#8217;un style, préciser la clé <code>'default' =&gt; true</code>.</li>
<li>À l&#8217;aide de la méthode <code>setStyleByDefault($name)</code>&#160;: <code>$attachments_list-&gt;setStyleByDefault('ol);</code>.</li>
</ul>

<p>Ci-après, la liste des différentes tags disponibles pour vos styles&#160;:</p>

<ul>
<li><strong>ID</strong>. L&#8217;identifiant de la pièce jointe.</li>
<li><strong>title</strong>. Le titre de la pièce jointe.</li>
<li><strong>filename</strong>. Le nom de fichier de la pièce jointe.</li>
<li><strong>file_date</strong>. La date de transfert de la pièce jointe.</li>
<li><strong>file_size</strong>. La taille de la pièce jointe, en [K|M]Bytes.</li>
<li><strong>file_type</strong>. Le type MIME du fichier.</li>
<li><strong>file_url</strong>. L&#8217;URL de téléchargement de la pièce jointe.</li>
<li><strong>icon_atts</strong>. D&#8217;éventuels attributs ajoutés à la balise <code>&lt;img/&gt;</code>.</li>
<li><strong>icon_path</strong>. L&#8217;URL de l&#8217;icône illustrative.</li>
<li><strong>label_filename</strong>. Label annonçant le titre du fichier.</li>
<li><strong>label&#95;file_date</strong>. Label annonçant la date de transfert du document.</li>
<li><strong>label&#95;file_size</strong>. Label annonçant la taille de la pièce jointe.</li>
</ul>

<h3>Personnaliser les icônes</h3>

<p>Par défaut le shortcode affiche les icônes disponibles dans WordPress. Le shortcode permet d&#8217;utiliser un set d&#8217;icône personnalisé.</p>

<p>Il suffit pour cela de déclarer un chemin d&#8217;accès aux icônes des différents types MIME. Par défaut <em>images/mime</em>. Ce chemin <strong>doit être</strong> <em>relatif au dossier du thème</em>.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$attachments_list</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> AttachmentsListShortCode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pièces jointes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$attachments_list</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setIconsDirectory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'img/icons'</span><span style="color: #009900;">&#41;</span>
                 <span style="color: #339933;">-&gt;</span><span style="color: #004000;">register</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<p>Afin que les icônes soient récupérées, les fichiers images des types MIME doivent être de la forme <code>type_mime.png</code>.<br />
C&#8217;est à dire qu&#8217;un document PDF de type MIME <code>application/pdf</code> aura pour icône le fichier <code>application_pdf.png</code>. Un document ODT de type MIME <code>application/vnd.oasis.opendocument.text</code> se référera quand à lui à l&#8217;image <code>application_vnd.oasis.opendocument.text.png</code>.</p>

<p>J&#8217;utilise le pack d&#8217;<a href="http://kde-look.org/content/show.php/Oxygen+Icons?content=74184" title="Oxygen Icons KDE-Look.org">icônes Oxygen</a> dans les exemples présentés de cette page.</p>

<h3>Filtre <code>attachments_list_context</code></h3>

<p>Le filtre <code>attachments_list_context</code> permet de modifier le contexte qui sera utilisé pour réaliser les substitions dans le style de présentation.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> filter_attachments_list_context<span style="color: #009900;">&#40;</span><span style="color: #000088;">$context</span><span style="color: #339933;">,</span> <span style="color: #000088;">$attachment</span><span style="color: #339933;">,</span> <span style="color: #000088;">$size</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// WordPress ne comportant pas de chaîne 'Size:', cette</span>
    <span style="color: #666666; font-style: italic;">// dernière ne peut être localisée automatiquement.</span>
    <span style="color: #666666; font-style: italic;">// Travaillant sur un site exclusivement localisé en français</span>
    <span style="color: #666666; font-style: italic;">// on peut se permettre les deux traitements qui suivent.</span>
    <span style="color: #000088;">$context</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'label_file_size'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Taille&amp;nbsp;:'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$context</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file_size'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$context</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file_size'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'B'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'o'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$context</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'attachments_list_context'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'filter_attachments_list_context'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<h2 id="changelog">Historique des versions et changelog</h2>

<h3>1.0.0</h3>

<ul>
<li>Version initiale.</li>
</ul>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/wordpress-create-shortcode-class.html' title='WordPress : une classe abstraite pour aider la création de shortcodes'>WordPress&#160;: une classe abstraite pour aider la création de shortcodes</a></li><li><a href='http://pioupioum.fr/snippets/wordpress-autoriser-upload-media-format-inconnu.html' title='WordPress : autoriser l&#8217;upload de fichiers au format non-supporté'>WordPress&#160;: autoriser l&#8217;upload de fichiers au format non-supporté</a></li><li><a href='http://pioupioum.fr/outils-astuces/wordpress-recuperation-avancee-images-article.html' title='WordPress : récupération avancée des images d&#8217;un article'>WordPress&#160;: récupération avancée des images d&#8217;un article</a></li><li><a href='http://pioupioum.fr/outils-astuces/afficher-images-article-page-media.html' title='WordPress : lister les images d&#8217;un article sur une page media'>WordPress&#160;: lister les images d&#8217;un article sur une page media</a></li><li><a href='http://pioupioum.fr/outils-astuces/wordpress-smartypants-shortcode-caption.html' title='WordPress et SmartyPants : des légendes qui disparaissent'>WordPress et SmartyPants&#160;: des légendes qui disparaissent</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>ou dans un fichier à part, à inclure dans le fichier <code>functions.php</code>.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=4lv6Y1LKGEI:40j1fVjXyhA:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=4lv6Y1LKGEI:40j1fVjXyhA:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=4lv6Y1LKGEI:40j1fVjXyhA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=4lv6Y1LKGEI:40j1fVjXyhA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=4lv6Y1LKGEI:40j1fVjXyhA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=4lv6Y1LKGEI:40j1fVjXyhA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=4lv6Y1LKGEI:40j1fVjXyhA:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=4lv6Y1LKGEI:40j1fVjXyhA:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=4lv6Y1LKGEI:40j1fVjXyhA:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/4lv6Y1LKGEI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/outils-astuces/wordpress-shortcode-afficher-fichiers-joints.html/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/outils-astuces/wordpress-shortcode-afficher-fichiers-joints.html</feedburner:origLink></item>
		<item>
		<title>WordPress : une classe abstraite pour aider la création de shortcodes</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/DtWyHtt6m5Y/wordpress-create-shortcode-class.html</link>
		<comments>http://pioupioum.fr/snippets/wordpress-create-shortcode-class.html#comments</comments>
		<pubDate>Wed, 22 Sep 2010 16:58:43 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=456</guid>
		<description><![CDATA[Une petite classe PHP abstraite pour aider la création de shortcodes dans WordPress.

Pour un exemple d&#8217;utilisation, se reporter au shortcode attachments.




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
&#60;?php
/**
 * Abstract class to create shortcodes in WordPress.
 *
 * @author Mehdi Kabab &#60;http://pioupioum.fr/&#62;
 * @copyright Copyright (C) 2010 Mehdi Kabab
 * @license http://www.gnu.org/licenses/gpl.html  GNU GPL version 3 or later
 * @version 1.0.0
 [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Une petite classe PHP abstraite pour aider la création de <strong>shortcodes dans WordPress</strong>.</p>

<p>Pour un exemple d&#8217;utilisation, se reporter au <a href="http://pioupioum.fr/outils-astuces/wordpress-shortcode-afficher-fichiers-joints.html" title="Shortcode WordPress : afficher les documents liés aux billets &#8211; Attachments shortcode – piouPiouM&#039;s dev">shortcode attachments</a>.</p>

<p><span id="more-456"></span></p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Abstract class to create shortcodes in WordPress.
 *
 * @author Mehdi Kabab &lt;http://pioupioum.fr/&gt;
 * @copyright Copyright (C) 2010 Mehdi Kabab
 * @license http://www.gnu.org/licenses/gpl.html  GNU GPL version 3 or later
 * @version 1.0.0
 * @link http://pioupioum.fr/snippets/wordpress-create-shortcode-class.html
 */</span>
abstract <span style="color: #000000; font-weight: bold;">class</span> PPM_Shortcode
<span style="color: #009900;">&#123;</span>
    <span style="color: #009933; font-style: italic;">/**
     * Default options.
     *
     * @var array
     **/</span>
    protected <span style="color: #000088;">$_default_options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Options after initialization of shortcode.
     *
     * @var ArrayObject
     */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_options</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Tag name of shortcode.
     *
     * @var string
     **/</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_name</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Constructor.
     *
     * @param string $tag Shortcode tag to be searched in post content.
     */</span>
    <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;">$tag</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><span style="color: #004000;">setTagName</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_options <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ArrayObject<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>
                                          ArrayObject<span style="color: #339933;">::</span><span style="color: #004000;">ARRAY_AS_PROPS</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;">/**
     * Excecute the shortcode.
     *
     * Called by the shortcode API.
     *
     * @param array $attributes Attributes used in the call of the shortcode.
     * @param string $content The content of the shortcode. Default to null.
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> run<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</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;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setOptions</span><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_default_options<span style="color: #339933;">,</span> <span style="color: #000088;">$attributes</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</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;">/**
     * Check if the current shortcode tag already registered.
     *
     * @global array $shortcode_tags
     * @return boolean
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> isRegistered<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;">global</span> <span style="color: #000088;">$shortcode_tags</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">array_key_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTagName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$shortcode_tags</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;">/**
     * Register the shortcode.
     *
     * @return PPM_Shortcode
     * @throws Exception If the shortcode already exists.
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> register<span style="color: #009900;">&#40;</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;">-&gt;</span><span style="color: #004000;">isRegistered</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'The shortcode `%s` already exists!'</span><span style="color: #339933;">,</span>
                                        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTagName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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;
        add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTagName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'run'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Unregister the shortcode.
     *
     * @return PPM_Shortcode
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> unregister<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        remove_shortcode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTagName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Retrieve the name of shortcode.
     *
     * @return string
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getTagName<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>_name<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Set the name of shortcode.
     *
     * @param string $name Shortcode tag to be searched in post content.
     * @return PPM_Shortcode
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setTagName<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</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>_name <span style="color: #339933;">=</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Retrieve the requested option.
     *
     * @param string $name The option to search.
     * @return mixed
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getOption<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</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>_options<span style="color: #339933;">-&gt;</span><span style="color: #004000;">offsetGet</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</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;">/**
     * Test if an option exists for the shortcode.
     *
     * @param string $name
     * @return boolean
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> hasOption<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</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>_options<span style="color: #339933;">-&gt;</span><span style="color: #004000;">offsetExists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</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;">/**
     * Set an option.
     *
     * @param string $name
     * @param mixed $value
     * @return PPM_Shortcode
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setOption<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</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>_options<span style="color: #339933;">-&gt;</span><span style="color: #004000;">offsetSet</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Retrieve the options.
     *
     * @return ArrayObject
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getOptions<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>_options<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Set the options.
     *
     * @param array $options
     * @return PPM_Shortcode
     */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> setOptions<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$options</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</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><span style="color: #004000;">setOption</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #009933; font-style: italic;">/**
     * Concrete excecution of the shortcode.
     *
     * @param array $attributes Attributes used in the call of the shortcode.
     * @param string $content The content of the shortcode. Default to null.
     * @return string
     */</span>
    abstract protected <span style="color: #000000; font-weight: bold;">function</span> _process<span style="color: #009900;">&#40;</span><span style="color: #000088;">$attributes</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/outils-astuces/wordpress-shortcode-afficher-fichiers-joints.html' title='Shortcode WordPress : afficher les documents liés aux billets'>Shortcode WordPress&#160;: afficher les documents liés aux billets</a></li><li><a href='http://pioupioum.fr/outils-astuces/wordpress-smartypants-shortcode-caption.html' title='WordPress et SmartyPants : des légendes qui disparaissent'>WordPress et SmartyPants&#160;: des légendes qui disparaissent</a></li><li><a href='http://pioupioum.fr/developpement/shortcode-wordpress-integrer-flux-rss.html' title='Shortcode WordPress : intégrer un flux RSS'>Shortcode WordPress&#160;: intégrer un flux RSS</a></li><li><a href='http://pioupioum.fr/developpement/photon-php-installer-mac-os-x-snow-leopard.html' title='Photon : guide d&#8217;installation sur Mac OS X Snow Leopard'>Photon&#160;: guide d&#8217;installation sur Mac OS X Snow Leopard</a></li><li><a href='http://pioupioum.fr/snippets/wordpress-forcer-chargement-jquery-footer.html' title='WordPress : forcer le chargement de jQuery en bas de page'>WordPress&#160;: forcer le chargement de jQuery en bas de page</a></li></ul>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=DtWyHtt6m5Y:ahxgzvsR44c:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=DtWyHtt6m5Y:ahxgzvsR44c:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=DtWyHtt6m5Y:ahxgzvsR44c:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=DtWyHtt6m5Y:ahxgzvsR44c:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=DtWyHtt6m5Y:ahxgzvsR44c:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=DtWyHtt6m5Y:ahxgzvsR44c:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=DtWyHtt6m5Y:ahxgzvsR44c:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=DtWyHtt6m5Y:ahxgzvsR44c:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=DtWyHtt6m5Y:ahxgzvsR44c:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/DtWyHtt6m5Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/wordpress-create-shortcode-class.html/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/snippets/wordpress-create-shortcode-class.html</feedburner:origLink></item>
		<item>
		<title>WordPress : forcer le chargement de jQuery en bas de page</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/q8Ec9i4OB9Y/wordpress-forcer-chargement-jquery-footer.html</link>
		<comments>http://pioupioum.fr/snippets/wordpress-forcer-chargement-jquery-footer.html#comments</comments>
		<pubDate>Thu, 09 Sep 2010 13:45:08 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Snippets]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=442</guid>
		<description><![CDATA[Le snippet qui suit ne se limite pas à forcer le chargement de jQuery en pied de page. Il permet également de remplacer la version locale à l&#8217;installion WordPress par une version équivalente, mais servie par le service Google Libraries API.

Si un script tierce remplace la version jQuery, son chargement sera forcé en bas de [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Le snippet qui suit ne se limite pas à forcer le <strong>chargement de jQuery</strong> en pied de page. Il permet également de remplacer la version locale à l&#8217;installion WordPress par une version équivalente, mais servie par le service <strong><a href="http://code.google.com/intl/fr-FR/apis/libraries/devguide.html#jquery" title="Google Libraries API - Developer&#39;s Guide - Google Libraries API - Google Code">Google Libraries API</a></strong>.</p>

<p>Si un script tierce remplace la version jQuery, son <strong>chargement</strong> sera <strong>forcé</strong> en <strong>bas de page</strong>.</p>

<p>Bien évidemment, il est aisé d&#8217;adapter ce snippet pour n&#8217;importe quel autre fichier JavaScript.
<span id="more-442"></span></p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Force load jQuery in the footer.
 *
 * @param boolean $google Set to true for load jQuery from the
 *                        Google Libraries Api servers. Default to false.
 * @global WP_Scripts $wp_scripts
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> forcejQueryInFooter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$google</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: #666666; font-style: italic;">// Do not apply in the WordPress admin Panel.</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>is_admin<span style="color: #009900;">&#40;</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: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_scripts</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;">is_a</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wp_scripts</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'WP_Scripts'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$wp_scripts</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Scripts<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: #000088;">$jquery</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_scripts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'registered'</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;">false</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$jquery</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$jquery_google</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://ajax.googleapis.com/ajax/libs/jquery/%s/jquery.min.js'</span><span style="color: #339933;">;</span>
        wp_deregister_script<span style="color: #009900;">&#40;</span><span style="color: #000088;">$jquery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">handle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        wp_register_script<span style="color: #009900;">&#40;</span>
            <span style="color: #000088;">$jquery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">handle</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#40;</span><span style="color: #000088;">$google</span><span style="color: #009900;">&#41;</span> ? <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$jquery_google</span><span style="color: #339933;">,</span> <span style="color: #000088;">$jquery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ver</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$jquery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">src</span><span style="color: #339933;">,</span>
            <span style="color: #000088;">$jquery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">deps</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#40;</span><span style="color: #000088;">$google</span><span style="color: #009900;">&#41;</span> ? <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$jquery</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ver</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: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Force load jQuery in the footer from the Google Libraries Api servers.
 *
 * @see forcejQueryInFooter()
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> forcejQueryGoogleLibrariesApiInFooter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    forcejQueryInFooter<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;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_enqueue_scripts'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'forcejQueryGoogleLibrariesApiInFooter'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">101</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>Remplacez <code>forcejQueryGoogleLibrariesApiInFooter</code> par <code>forcejQueryInFooter</code> dans l&#8217;ajout d&#8217;action à <code>wp_enqueue_scripts</code> pour utiliser la version de jQuery livrée avec <strong>WordPress</strong>.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/plugins-wordpress/wordpress-jquery-ui-effects.html' title='WordPress jQuery UI Effects'>WordPress jQuery UI Effects</a></li><li><a href='http://pioupioum.fr/outils-astuces/wordpress-shortcode-afficher-fichiers-joints.html' title='Shortcode WordPress : afficher les documents liés aux billets'>Shortcode WordPress&#160;: afficher les documents liés aux billets</a></li><li><a href='http://pioupioum.fr/snippets/wordpress-create-shortcode-class.html' title='WordPress : une classe abstraite pour aider la création de shortcodes'>WordPress&#160;: une classe abstraite pour aider la création de shortcodes</a></li><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li><li><a href='http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html' title='Optimiser le chargement des AdSense'>Optimiser le chargement des AdSense</a></li></ul>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=q8Ec9i4OB9Y:kPIT1RdK-gc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=q8Ec9i4OB9Y:kPIT1RdK-gc:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=q8Ec9i4OB9Y:kPIT1RdK-gc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=q8Ec9i4OB9Y:kPIT1RdK-gc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=q8Ec9i4OB9Y:kPIT1RdK-gc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=q8Ec9i4OB9Y:kPIT1RdK-gc:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=q8Ec9i4OB9Y:kPIT1RdK-gc:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=q8Ec9i4OB9Y:kPIT1RdK-gc:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=q8Ec9i4OB9Y:kPIT1RdK-gc:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/q8Ec9i4OB9Y" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/snippets/wordpress-forcer-chargement-jquery-footer.html/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/snippets/wordpress-forcer-chargement-jquery-footer.html</feedburner:origLink></item>
		<item>
		<title>Bundle License Helper pour TextMate</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/hVh3seY_ZSA/license-helper-textmate-bundle.html</link>
		<comments>http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html#comments</comments>
		<pubDate>Thu, 29 Jul 2010 16:29:29 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Outils, trucs et astuces]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[projet]]></category>
		<category><![CDATA[TextMate]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=426</guid>
		<description><![CDATA[Parce que j&#8217;en avais ma claque de chercher le texte des licences à ajouter en en-tête de mes sources1, voici un bundle TextMate pour palier à cette répétitive perte de temps.



Table des matières


Installation
Utilisation du bundle
Personnaliser le sélecteur des licences
Corriger le formatage de la licence
Licences supportées
Développement


Installation

Depuis les sources, avec Git

cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/piouPiouM/license-helper.tmbundle.git "License Helper.tmbundle"
osascript [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Parce que j&#8217;en avais ma claque de chercher le texte des licences à ajouter en en-tête de mes sources<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>, voici un <strong><a href="http://pioupioum.fr/tag/textmate/" title="Archives pour le tag TextMate – piouPiouM&#039;s dev">bundle TextMate</a></strong> pour palier à cette répétitive perte de temps.</p>

<p><img src="http://assets1.pioupioum.fr/uploads/2010/07/License-Helper-Textmate-Bundle.png" alt="License Helper Textmate Bundle" title="License Helper Textmate Bundle" width="610" height="385" class="aligncenter size-full wp-image-431" /><span id="more-426"></span></p>

<h2 id="toc">Table des matières</h2>

<ol>
<li><a href="#installer">Installation</a></li>
<li><a href="#usage">Utilisation du bundle</a></li>
<li><a href="#personnaliser">Personnaliser le sélecteur des licences</a></li>
<li><a href="#formatage">Corriger le formatage de la licence</a></li>
<li><a href="#licenses">Licences supportées</a></li>
<li><a href="#developpement">Développement</a></li>
</ol>

<h2 id="installer">Installation</h2>

<h3>Depuis les sources, avec Git</h3>

<pre><code>cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/piouPiouM/license-helper.tmbundle.git "License Helper.tmbundle"
osascript -e 'tell app "TextMate" to reload bundles'
</code></pre>

<h3>Depuis les sources, sans Git</h3>

<pre><code>cd ~/Library/Application\ Support/TextMate/Bundles
wget http://github.com/piouPiouM/license-helper.tmbundle/tarball/master
tar zxf license-helper.tmbundle.tar.gz
rm license-helper.tmbundle.tar.gz
mv license-helper.tmbundle "License Helper.tmbundle"
osascript -e 'tell app "TextMate" to reload bundles'
</code></pre>

<h3>Téléchargement direct</h3>

<div class="download box">
    <a href="http://github.com/piouPiouM/license-helper.tmbundle/tarball/master" title="Téléchargement depuis les serveurs de GitHub"><span>Télécharger la dernière version du bundle License Helper pour TextMate</span></a>
</div>

<p>Après récupération, décompressez l&#8217;archive, renommez le dossier en <code>License Helper.tmbundle</code>. Acceptez le changement d&#8217;extension. Il ne reste plus qu&#8217;à installer le bundle d&#8217;un double-clic sur le fichier.</p>

<h2 id="usage">Utilisation du bundle</h2>

<p>Utilisez le lanceur <code>license⇥</code> pour <strong>sélectionner une licence</strong> <em>via</em> la boîte de dialogue qui s&#8217;affiche.</p>

<p><div id="attachment_427" class="wp-caption aligncenter" style="width: 349px"><img src="http://assets1.pioupioum.fr/uploads/2010/07/license-helper-textmate-bundle-dialog.png" alt="Choix d&#039;une licence – License Helper Textmate Bundle" title="license-helper-textmate-bundle-dialog" width="339" height="384" class="size-full wp-image-427" /><p class="wp-caption-text">Choix d&#8217;une licence – License Helper Textmate Bundle</p></div></p>

<p>Un bloc de licence est inséré en tant que Snippet. Utilisez la touche de tabulation pour vous déplacez sur les différents placeholders.</p>

<h3>Liste des variables d&#8217;environnement utilisées</h3>

<p>Déclarez dans votre projet les variables d&#8217;environnement qui suivent pour auto-compléter les blocs de licence à insérer&#160;:</p>

<ul>
<li><code>TM_PROJECT_YEAR</code>. L&#8217;année de production. Par défaut&#160;: l&#8217;année courante.</li>
<li><code>TM_PROJECT_COPYRIGHT_HOLDERS</code> ou <code>TM_AUTHOR</code> ou <code>TM_ORGANIZATION_NAME</code>. Les détenteurs du copyright.</li>
<li><code>TM_ORGANIZATION_EMAIL</code>. Adresse mail de l&#8217;organisation détentrice du copyright.</li>
<li><code>TM_PROJECT_DESCRIPTION</code>. Description brève du projet.</li>
</ul>

<p>Notez que les variables sont utilisées en fonction de la licence choisie et qu&#8217;il n&#8217;est pas nécessaire de toutes les renseigner si vous n&#8217;en avez pas l&#8217;usage.</p>

<p>Vous pouvez fixer la licence de votre projet en ajoutant la variable d&#8217;environnement de projet <code>TM_PROJECT_LICENSE</code>. Ainsi, vous n&#8217;aurez plus à la sélectionner.</p>

<h2 id="personnaliser">Personnaliser le sélecteur des licences</h2>

<p>La commande accessible depuis le menu <em>License Helper → Edit licenses order</em> lance l&#8217;édition du fichier de configuration du bundle.<br />
Modifiez l&#8217;ordre des licences déclarées selon vos préférences d&#8217;apparition dans le sélecteur de licences.</p>

<h2 id="formatage">Corriger le formatage de la licence</h2>

<p>Il est possible qu&#8217;avec certains langages, le rendu des blocs de licences ne corresponde pas à vos attentes. Si tel est le cas, définissez votre propre format&#160;:</p>

<ol>
<li>Bundles → Bundle Editor</li>
<li>Dans l&#8217;entrée <strong>License Helper</strong>, créez une nouvelle Preference et donnez-lui le nom du langage.</li>
<li>Remplissez le champ Scope Selector avec le scope approprié – i.e. <code>source.java</code> pour les sources java.</li>
<li>Définissez les shellVariables <code>TM_LICENSE_HELPER_HEADER</code> (début du bloc de commentaire) et <code>TM_LICENSE_HELPER_FOOTER</code> (fin du bloc de commentaire), comme suit&#160;:</li>
</ol>

<pre>{  shellVariables = (
        {   name = 'TM_LICENSE_HELPER_HEADER';
            value = '/*';
        },
        {   name = 'TM_LICENSE_HELPER_FOOTER';
            value = '*/';
        },
    );
}</pre>

<p><strong>Note&#160;:</strong> chacune des lignes de la licence peut être préfixée de la variable <code>TM_LICENSE_HELPER_LINE</code>.</p>

<h2 id="licenses">Licences supportées</h2>

<p>La liste des licences prises en charge par le plugin n&#8217;est pas figée. N&#8217;hésitez pas à me <a href="#developpement">soumettre</a> celles qui vous font défaut.</p>

<ul>
<li><a href="http://www.opensource.org/licenses/agpl-v3.html" title="GNU AFFERO GENERAL PUBLIC LICENSE v3 | Open Source Initiative">Affero GNU Public License 3.0</a></li>
<li><a href="http://www.opensource.org/licenses/apache2.0.php" title="Open Source Initiative OSI - Apache License, Version 2.0:Licensing | Open Source Initiative">Apache license 2.0</a></li>
<li><a href="http://www.cecill.info/" title="CeCILL">CeCILL license</a></li>
<li><a href="http://sam.zoy.org/wtfpl/" title="WTFPL - Do What The Fuck You Want To Public License">Do What The Fuck You Want To Public License</a></li>
<li><a href="http://www.gnu.org/licenses/old-licenses/gpl-2.0.html" title="GNU General Public License v2.0 - GNU Project - Free Software Foundation (FSF)">GNU General Public License version 2</a></li>
<li><a href="http://www.gnu.org/licenses/gpl-3.0.html" title="The GNU General Public License - GNU Project - Free Software Foundation (FSF)">GNU General Public License version 3</a></li>
<li><a href="http://www.gnu.org/licenses/lgpl.html" title="GNU Lesser General Public License - GNU Project - Free Software Foundation (FSF)">GNU Lesser General Public License version 3</a></li>
<li><a href="http://www.opensource.org/licenses/mit-license.html" title="Open Source Initiative OSI - The MIT License:Licensing | Open Source Initiative">MIT license</a></li>
<li><a href="http://www.opensource.org/licenses/bsd-license.php" title="Open Source Initiative OSI - The BSD License:Licensing | Open Source Initiative">New and Simplified BSD licenses</a></li>
<li><a href="http://www.opensource.org/licenses/bsd-license.php" title="Open Source Initiative OSI - The BSD License:Licensing | Open Source Initiative">Original BSD license</a></li>
<li><a href="http://www.opensource.org/licenses/postgresql" title="The PostgreSQL Licence (TPL) | Open Source Initiative">PostgreSQL license</a></li>
</ul>

<h2 id="developpement">Développement</h2>

<p>Distribué sous <a href="http://www.opensource.org/licenses/mit-license.html" title="Open Source Initiative OSI - The MIT License:Licensing | Open Source Initiative">license MIT</a>, le <a href="http://github.com/piouPiouM/license-helper.tmbundle" title="piouPiouM's license-helper.tmbundle at master - GitHub">code source du bundle</a> est accessible sur GitHub.</p>

<p>Une suggestion, une amélioration, une critique ou un bug à me soumettre&#160;? Ça se passe du côté du <a href="http://github.com/piouPiouM/license-helper.tmbundle/issues" title="Issues - piouPiouM/license-helper.tmbundle - GitHub">bugtracker</a> associé.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/textmate-commande-exporter-mots-word-wrap.html' title='TextMate : commande &laquo;&nbsp;Export words&nbsp;&raquo;'>TextMate&#160;: commande &laquo;&nbsp;Export words&nbsp;&raquo;</a></li><li><a href='http://pioupioum.fr/outils-astuces/textmate-convertir-couleur-hexadecimale-html-rgba.html' title='TextMate : convertir une couleur hexadécimale en notation RGBA'>TextMate&#160;: convertir une couleur hexadécimale en notation RGBA</a></li><li><a href='http://pioupioum.fr/developpement/javascript-array-intersection.html' title='JavaScript : optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles'>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</a></li><li><a href='http://pioupioum.fr/developpement/jslint-console-rhino.html' title='Une console JSLint pour aider vos validations JavaScript'>Une console JSLint pour aider vos validations JavaScript</a></li><li><a href='http://pioupioum.fr/snippets/php-convertir-datetime-unix-timestamp.html' title='PHP : convertir un DATETIME en un timestamp UNIX'>PHP&#160;: convertir un DATETIME en un timestamp UNIX</a></li></ul>

<div class="footnotes">
<hr />
<h4>Notes</h4>
<ol>

<li id="fn:1">
<p>exception faite des projets pour lesquels j&#8217;utilise un builder qui l&#8217;ajoute comme un grand à ma place.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVh3seY_ZSA:1ZqGNfxfOdY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVh3seY_ZSA:1ZqGNfxfOdY:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVh3seY_ZSA:1ZqGNfxfOdY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVh3seY_ZSA:1ZqGNfxfOdY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVh3seY_ZSA:1ZqGNfxfOdY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVh3seY_ZSA:1ZqGNfxfOdY:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVh3seY_ZSA:1ZqGNfxfOdY:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=hVh3seY_ZSA:1ZqGNfxfOdY:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=hVh3seY_ZSA:1ZqGNfxfOdY:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/hVh3seY_ZSA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html</feedburner:origLink></item>
		<item>
		<title>JavaScript : optimiser le calcul de l’intersection de tableaux de grandes tailles</title>
		<link>http://feeds.pioupioum.fr/~r/pioupioum-dev-blog/~3/MhVIsCsiVuc/javascript-array-intersection.html</link>
		<comments>http://pioupioum.fr/developpement/javascript-array-intersection.html#comments</comments>
		<pubDate>Tue, 13 Jul 2010 13:31:38 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=408</guid>
		<description><![CDATA[Trouver sur la toile une fonction JavaScript de calcul d&#8217;intersection de tableaux qui soit efficace sur des tableaux dépassant les 50 entrées relève de l&#8217;impossible. C&#8217;est bien simple, les différentes solutions que j&#8217;ai pu rencontrer réalisent des calculs linéaires donc autant dire qu&#8217;à partir d&#8217;un certain seuil leurs performances deviennent catastrophiques.

C&#8217;est pourquoi je vous propose [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Trouver sur la toile une fonction <strong>JavaScript</strong> de calcul d&#8217;<strong>intersection de tableaux</strong> qui soit efficace sur des tableaux dépassant les 50 entrées relève de l&#8217;impossible. C&#8217;est bien simple, les différentes solutions que j&#8217;ai pu rencontrer réalisent des calculs linéaires donc autant dire qu&#8217;à partir d&#8217;un certain seuil <em>leurs performances deviennent catastrophiques</em>.</p>

<p>C&#8217;est pourquoi je vous propose ici une fonction de recherche des intersections pour un nombre arbitraire de grands tableaux plus efficace que ce que j&#8217;ai pu tester,  <a href="http://pioupioum.fr/sandbox/javascript-array-intersect-benchmark/" title="JavaScript Big Arrays Intersection - JSpeedmus Benchmark Suite">benchmarks</a> à l&#8217;appui. Est également disponible la suite des <a href="http://pioupioum.fr/sandbox/javascript-array-intersect-benchmark/qunit.html" title="JavaScript Big Arrays Intersection - Unit tests">tests unitaires</a>.</p>

<p><div id="attachment_418" class="wp-caption aligncenter" style="width: 620px"><a href="http://assets1.pioupioum.fr/uploads/2010/07/JavaScript-Big-Arrays-Intersection-JSpeedmus-Benchmark-Suite.png"><img src="http://assets1.pioupioum.fr/uploads/2010/07/JavaScript-Big-Arrays-Intersection-JSpeedmus-Benchmark-Suite-610x238.png" alt="Benchmark réalisé sous Google Chrome 5.0.375.99 / Mac Pro 2 x 3 Ghz Quad-Core Intel Xeon / Mac OS X 10.5.8" title="JavaScript Big Arrays Intersection - JSpeedmus Benchmark Suite" width="610" height="238" class="size-medium wp-image-418" /></a><p class="wp-caption-text">Benchmark réalisé sous Google Chrome 5.0.375.99 / Mac Pro 2 x 3 Ghz Quad-Core Intel Xeon sous Mac OS X 10.5.8</p></div>
<span id="more-408"></span></p>

<h2>La fonction array_big_intersect()</h2>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Compute the intersection of big arrays.
 *
 * @author  Mehdi Kabab &lt;http://pioupioum.fr/&gt;
 * @license http://www.opensource.org/licenses/mit-license.php MIT License.
 * @see     http://pioupioum.fr/developpement/javascript-array-intersection.html
 * @version 1.0.1
 *
 * @param  {Array} arr1 First array.
 * @param  {Array} arr2 Second array.
 * @param  {Array} [arr3[, arr4[, ...]]] Optional arrays.
 * @return {Array} A new array containing elements common to the arrays passed
 *                 in arguments, with no duplicates.
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> array_big_intersect <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #003366; font-weight: bold;">var</span> args <span style="color: #339933;">=</span> Array.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">slice</span>.<span style="color: #660066;">call</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
      aLower <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      aStack <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
      count<span style="color: #339933;">,</span>
      i<span style="color: #339933;">,</span>
      nArgs<span style="color: #339933;">,</span>
      nLower<span style="color: #339933;">,</span>
      oRest <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      oTmp <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      value<span style="color: #339933;">,</span>
      compareArrayLength <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>a<span style="color: #339933;">,</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>a.<span style="color: #660066;">length</span> <span style="color: #339933;">-</span> b.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
      indexes <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>array<span style="color: #339933;">,</span> oStack<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
            value<span style="color: #339933;">,</span>
            nArr <span style="color: #339933;">=</span> array.<span style="color: #660066;">length</span><span style="color: #339933;">,</span>
            oTmp <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">;</span> nArr <span style="color: #339933;">&gt;</span> i<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          value <span style="color: #339933;">=</span> array<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
          <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>oTmp<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            oStack<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #CC0000;">1</span> <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>oStack<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span> <span style="color: #339933;">||</span> <span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// counter</span>
            oTmp<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">return</span> oStack<span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  args.<span style="color: #660066;">sort</span><span style="color: #009900;">&#40;</span>compareArrayLength<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  aLower <span style="color: #339933;">=</span> args.<span style="color: #660066;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  nLower <span style="color: #339933;">=</span> aLower.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span> <span style="color: #339933;">===</span> nLower<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> aStack<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  nArgs <span style="color: #339933;">=</span> args.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
  i <span style="color: #339933;">=</span> nArgs<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span>i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    oRest <span style="color: #339933;">=</span> indexes<span style="color: #009900;">&#40;</span>args.<span style="color: #660066;">shift</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> oRest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> nLower <span style="color: #339933;">&gt;</span> i<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    value <span style="color: #339933;">=</span> aLower<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    count <span style="color: #339933;">=</span> oRest<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>oTmp<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>nArgs <span style="color: #339933;">===</span> count<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        aStack.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        oTmp<span style="color: #009900;">&#91;</span>value<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #003366; 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: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">return</span> aStack<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>


<h2>Un gain de performances</h2>

<p>Le gain de performances tient à peu de choses. En premier lieu, l&#8217;ordre d&#8217;analyse des tableaux est un point à ne pas négliger. Par définition, l&#8217;ensemble des valeurs constituant l&#8217;intersection se retrouve dans le plus petit des tableaux. De ce fait, je me base sur le plus petit d&#8217;entre-eux pour effectuer les comparaisons de présence d&#8217;une valeur dans les ensembles restants.</p>

<p>Aussi, la fonction crée un Hash de toutes les valeurs uniques et stocke leur fréquence d&#8217;apparition. Si une valeur apparaît autant de fois qu&#8217;il y a de tableaux, c&#8217;est qu&#8217;une intersection est trouvée.</p>

<p>Et c&#8217;est tout <img src='http://pioupioum.fr/wp/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

<p>Petit avertissement, si vous avez à travailler sur des tableaux de petites tailles, je vous conseille plutôt d&#8217;utiliser la fonction <a href="http://www.jslab.dk/library/Array.intersect" title="JavaScript Lab - Library - Array.intersect">Array#intersect()</a> de la librairie <a href="http://www.jslab.dk/library/" title="JavaScript Lab - Library">JSLab</a> qui s&#8217;avère être des plus performantes.</p>

<h2>Anecdote</h2>

<p>Anecdote (ou pas), mon benchmark met en évidence des erreurs de calcul de la part des librairies <a href="http://prototypejs.org/" title="Prototype JavaScript framework: Easy Ajax and DOM manipulation for dynamic web applications">Prototype</a> et <a href="http://www.thegrubbsian.com/2009/01/25/useful-javascript-extensions/" title="Useful JavaScript Extensions &mdash; The Grubbsian">Extensions</a>. La seconde ayant moins d&#8217;impact car peu propagée, il en est tout autre pour Prototype. En effet, cette dernière exclue <strong>systématiquement</strong> la valeur <code>0</code> (zéro) du tableau résultant. Ce qui est plus qu&#8217;embarrassant, pourtant le <a href="https://prototype.lighthouseapp.com/projects/8886/tickets/841-arrayintersect-return-wrong-result-if-array-values-has-0">bug</a> est connu depuis fin 2009.</p>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/jslint-console-rhino.html' title='Une console JSLint pour aider vos validations JavaScript'>Une console JSLint pour aider vos validations JavaScript</a></li><li><a href='http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html' title='Optimiser le chargement des AdSense'>Optimiser le chargement des AdSense</a></li><li><a href='http://pioupioum.fr/outils-astuces/facebook-application-add-page-tab-bookmarklet.html' title='Bookmarklet : ajout rapide d&#8217;application onglet à vos pages fan Facebook'>Bookmarklet&#160;: ajout rapide d&#8217;application onglet à vos pages fan Facebook</a></li><li><a href='http://pioupioum.fr/snippets/wordpress-forcer-chargement-jquery-footer.html' title='WordPress : forcer le chargement de jQuery en bas de page'>WordPress&#160;: forcer le chargement de jQuery en bas de page</a></li><li><a href='http://pioupioum.fr/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</a></li></ul>
<!-- google_ad_section_end --><div class="feedflare">
<a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=MhVIsCsiVuc:NbpUsUu4tZg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=MhVIsCsiVuc:NbpUsUu4tZg:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=MhVIsCsiVuc:NbpUsUu4tZg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=MhVIsCsiVuc:NbpUsUu4tZg:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=MhVIsCsiVuc:NbpUsUu4tZg:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=MhVIsCsiVuc:NbpUsUu4tZg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=MhVIsCsiVuc:NbpUsUu4tZg:V_sGLiPBpWU" border="0"></img></a> <a href="http://feeds.pioupioum.fr/~ff/pioupioum-dev-blog?a=MhVIsCsiVuc:NbpUsUu4tZg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/pioupioum-dev-blog?i=MhVIsCsiVuc:NbpUsUu4tZg:gIN9vFwOqvQ" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/pioupioum-dev-blog/~4/MhVIsCsiVuc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/javascript-array-intersection.html/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://pioupioum.fr/developpement/javascript-array-intersection.html</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 2.373 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-01-01 19:15:52 -->

