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

<channel>
	<title>piouPiouM&#039;s dev&#187; Archives de la catégorie Développement Web &#8211; piouPiouM&#039;s dev</title>
	<atom:link href="http://pioupioum.fr/developpement/feed/" rel="self" type="application/rss+xml" />
	<link>http://pioupioum.fr</link>
	<description>Bloc-note d&#039;un développeur web</description>
	<lastBuildDate>Thu, 29 Jul 2010 16:47:44 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JavaScript&#160;: optimiser le calcul de l&#8217;intersection de tableaux de grandes tailles</title>
		<link>http://pioupioum.fr/developpement/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/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</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/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></ul>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/javascript-array-intersection.html/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Une console JSLint pour aider vos validations JavaScript</title>
		<link>http://pioupioum.fr/developpement/jslint-console-rhino.html</link>
		<comments>http://pioupioum.fr/developpement/jslint-console-rhino.html#comments</comments>
		<pubDate>Thu, 03 Jun 2010 20:07:49 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JSLint]]></category>
		<category><![CDATA[licence MIT]]></category>
		<category><![CDATA[Rhino]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=395</guid>
		<description><![CDATA[J&#8217;ai pris l&#8217;habitude de valider mon code JavaScript à l&#8217;aide de JSLint. Outil d&#8217;analyse statique de code, JSLint permet de m&#8217;assurer du niveau de qualité de mon code avant toute déploiement en production.

Cependant la console accompagnant l&#8217;outil ne me convenait pas, et ce pour plusieurs raisons&#160;:


L&#8217;élément window n&#8217;est pas défini via les options passées à [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>J&#8217;ai pris l&#8217;habitude de valider mon code <a href="http://pioupioum.fr/tag/javascript/" title="Archives pour le tag JavaScript – piouPiouM&#039;s dev">JavaScript</a> à l&#8217;aide de <strong><a href="http://www.jslint.com/" title="JSLint, The JavaScript Code Quality Tool">JSLint</a></strong>. Outil d&#8217;<a href="http://fr.wikipedia.org/wiki/Analyse_statique_de_programmes" title="Analyse statique de programmes - Wikipédia">analyse statique</a> de code, <strong>JSLint</strong> permet de m&#8217;assurer du niveau de qualité de mon code avant toute déploiement en production.</p>

<p>Cependant la <a href="http://www.jslint.com/rhino/rhino.js">console</a> accompagnant l&#8217;outil ne me convenait pas, et ce pour plusieurs raisons&#160;:</p>

<ol>
<li>L&#8217;élément <code>window</code> n&#8217;est pas défini <em>via</em> les options passées à <code>JSLINT</code> ce qui m&#8217;oblige à le déclarer, à l&#8217;aide de l&#8217;instruction <code>/*@global</code>, dans une majorité de mes scripts.</li>
<li>Dans le même esprit, j&#8217;utilise couramment certaines options — comme <code>browser: true</code> — non présentes dans l&#8217;appel à <code>JSLINT</code>.</li>
<li>La présentation du résultat ne me convient guère.</li>
</ol>

<p>Vous trouverez dans les lignes qui suivent la console que j&#8217;utilise en remplacement.</p>

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

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

<ol>
<li><a href="#source">Code source</a></li>
<li><a href="#prerequis">Prérequis</a></li>
<li><a href="#usage">Usage</a></li>
<li><a href="changelog">Historique des versions et changelog</a></li>
</ol>

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

<div class="box file-js">
    <a href="http://static.pioupioum.fr/code/jslint-console.js" title="Télécharger"><span>jslint-console.js (4&nbsp;Ko)</span></a>
</div>


<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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/*global JSLINT */</span>
<span style="color: #009966; font-style: italic;">/*jslint white: true, rhino: true */</span>
<span style="color: #006600; font-style: italic;">/**
 * @fileOverview Provides a JSLint console for Rhino.
 * &lt;p&gt;Usage: &lt;code&gt;java -jar lib/js.jar lib/jslint-console.js lib/fulljslint.js src/testFile1.js src/testFile2.js&lt;/code&gt;&lt;/p&gt;
 * @author Mehdi Kabab &lt;http://pioupioum.fr/&gt;
 * @version 0.1.1 (2010-06-24)
 */</span>
<span style="color: #006600; font-style: italic;">/**
 * @license Copyright (c) 2010 Mehdi Kabab &lt;http://pioupioum.fr/&gt;.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the &quot;Software&quot;), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */</span>
&nbsp;
<span style="color: #006600; font-style: italic;">// Loads the JSLint script given as first argument.</span>
load<span style="color: #009900;">&#40;</span>arguments.<span style="color: #660066;">splice</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>scripts<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>
        indentLen <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Returns the string repeated multiplier times.
     * @param {Number} multiplier Number of time the string should be repeated.
     * @this {String}
     * @return Returns the repeated string.
     * @type String
     * @addon
     */</span>
    String.<span style="color: #660066;">prototype</span>.<span style="color: #660066;">repeat</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>multiplier<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><span style="color: #CC0000;">0</span> <span style="color: #339933;">&gt;</span> multiplier<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            multiplier <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">new</span> Array<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span> <span style="color: #339933;">+</span> multiplier<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Cleans evidence message and assign &lt;code&gt;identLen&lt;/code&gt;.
     * @private
     * @param {String} str The full message.
     * @param {String} p1 Possible identation.
     * @param {String} p2 The message content.
     * @returns The message content
     * @type String
     */</span>
    <span style="color: #003366; font-weight: bold;">function</span> cleanEvidence<span style="color: #009900;">&#40;</span>str<span style="color: #339933;">,</span> p1<span style="color: #339933;">,</span> p2<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        indentLen <span style="color: #339933;">=</span> p1.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">return</span> p2<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// cleanEvidence</span>
&nbsp;
    <span style="color: #006600; font-style: italic;">/**
     * Check quality code of the given script.
     * @private
     * @param {String} jsfile File to check.
     * @requires JSLINT
     * @requires String#repeat()
     */</span>
    <span style="color: #003366; font-weight: bold;">function</span> lint<span style="color: #009900;">&#40;</span>jsfile<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>
            input<span style="color: #339933;">,</span>
            e<span style="color: #339933;">,</span>
            errLen<span style="color: #339933;">,</span>
            errTag <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;[ERROR] &quot;</span><span style="color: #339933;">,</span>
            found <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Running JSLint on: &quot;</span> <span style="color: #339933;">+</span> jsfile<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        input <span style="color: #339933;">=</span> readFile<span style="color: #009900;">&#40;</span>jsfile<span style="color: #009900;">&#41;</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>input<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span>errTag <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;Couldn't open file.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            quit<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><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;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>JSLINT<span style="color: #009900;">&#40;</span>input<span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span> browser<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> rhino<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> laxbreak<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
            onevar<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> undef<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> nomen<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> eqeqeq<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> bitwise<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
            regexp<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span> newcap<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span>
            predef<span style="color: #339933;">:</span> <span style="color: #009900;">&#91;</span><span style="color: #3366CC;">'window'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'escape'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'unescape'</span><span style="color: #009900;">&#93;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <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> errLen <span style="color: #339933;">=</span> JSLINT.<span style="color: #660066;">errors</span>.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> errLen<span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                e <span style="color: #339933;">=</span> JSLINT.<span style="color: #660066;">errors</span><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>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    found <span style="color: #339933;">+=</span> <span style="color: #CC0000;">1</span><span style="color: #339933;">;</span>
                    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;% scanned).&quot;</span> <span style="color: #339933;">!==</span> e.<span style="color: #660066;">reason</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #CC0000;">11</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span>errTag <span style="color: #339933;">+</span> e.<span style="color: #660066;">reason</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\.$/</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                            <span style="color: #3366CC;">&quot; on line &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">line</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; character &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #660066;">character</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;&quot;</span> <span style="color: #339933;">!==</span> e.<span style="color: #660066;">evidence</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                            <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; &quot;</span>.<span style="color: #660066;">repeat</span><span style="color: #009900;">&#40;</span>errTag.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                                <span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">evidence</span> <span style="color: #339933;">||</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^(\s*)(\S*(\s+\S+)*)\s*$/</span><span style="color: #339933;">,</span> cleanEvidence<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                            <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot; &quot;</span>.<span style="color: #660066;">repeat</span><span style="color: #009900;">&#40;</span>errTag.<span style="color: #660066;">length</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span>
                                <span style="color: #3366CC;">&quot;.&quot;</span>.<span style="color: #660066;">repeat</span><span style="color: #009900;">&#40;</span>e.<span style="color: #660066;">character</span> <span style="color: #339933;">-</span> indentLen <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;^&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        <span style="color: #009900;">&#125;</span>
                    <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
                        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span>errTag <span style="color: #339933;">+</span> e.<span style="color: #660066;">reason</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;=&gt; &quot;</span> <span style="color: #339933;">+</span> found <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; error(s) found.<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            quit<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;OK<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #006600; font-style: italic;">// lint</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>scripts<span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066;">print</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Usage: jslint-console.js fulljslint.js file1.js[ file2.js]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        quit<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">1</span><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> i <span style="color: #339933;">&lt;</span> scripts.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        lint<span style="color: #009900;">&#40;</span>scripts<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<h2 id="prerequis">Prérequis</h2>

<p>Les prérequis sont simples&#160;:</p>

<ul>
<li><a href="http://www.mozilla.org/rhino/download.html" title="Rhino Downloads">Télécharger Rhino</a> et récupérer le fichier <code>js.jar</code>.</li>
<li>Récupérer la version <a href="http://www.jslint.com/rhino/fulljslint.js">complète</a> ou <a href="http://www.jslint.com/rhino/jslint.js">minifiée</a> de JSLint. Attention cependant, il vous faudra supprimer la fonction anonyme embarquée <code>rhino.js</code> (en fin de script).</li>
</ul>

<h2 id="usage">Usage</h2>

<p>Dans un shell, exécutez <code>jslint-console.js</code> à l&#8217;aide de <strong><a href="http://www.mozilla.org/rhino/" title="Rhino - JavaScript for Java">Rhino</a></strong>, comme suis&#160;:</p>

<pre>$ java -jar lib/rhino/js.jar lib/jslint/jslint-console.js lib/jslint/fulljslint.js src/*.js</pre>

<p>Ici, deux arguments sont passés à la <strong>console jslint</strong>&#160;:</p>

<ul>
<li>Le script JSLint, <code>lib/jslint/fulljslint.js</code>, à fournir en premier argument. Je ne le charge pas en dur dans <code>jslint-console.js</code> afin de conserver une souplesse d&#8217;implémentation (<em>via</em> une tâche <a href="http://pioupioum.fr/tag/ant/" title="Archives pour le tag ant – piouPiouM&#039;s dev">Ant</a> par exemple).</li>
<li>La liste des fichiers sources <strong>JavaScript</strong> à analyser.</li>
</ul>

<p>Voici un exemple de sortie de la console&#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
</pre></td><td class="code"><pre class="" style="font-family:monospace;">$ java -jar lib/rhino/js-1.7R2.jar lib/jslint/jslint-console.js lib/jslint/fulljslint.js src/*.js
Running JSLint on: src/jsfile1.js
OK
&nbsp;
Running JSLint on: src/jsfile2.js
<span class="br0">&#91;</span>ERROR<span class="br0">&#93;</span> Expected '===' and instead saw '==' on line <span style="">52</span> character 23.
        if <span class="br0">&#40;</span>false == test<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        ..........^
<span class="br0">&#91;</span>ERROR<span class="br0">&#93;</span> Unexpected dangling '_' in '_ob' on line <span style="">74</span> character 17.
        var _ob = window.ob;
        ....^
<span class="br0">&#91;</span>ERROR<span class="br0">&#93;</span> 'ob' is not defined on line <span style="">80</span> character 39.
        if <span class="br0">&#40;</span>'function' !== typeof ob.getVariables<span class="br0">&#41;</span> <span class="br0">&#123;</span>
        ..........................^
<span class="br0">&#91;</span>ERROR<span class="br0">&#93;</span> 'ob' is not defined on line <span style="">83</span> character 26.
        params = ob.getVariables<span class="br0">&#40;</span><span class="br0">&#41;</span>.sequence;
        .........^
=&gt; <span style="">4</span> error<span class="br0">&#40;</span>s<span class="br0">&#41;</span> found.</pre></td></tr></table></div>


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

<h3>0.1.1 (2010-06-24)</h3>

<ul>
<li>Forcer un multiplieur positif dans String.prototype.repeat</li>
</ul>

<h3>0.1 (2010-06-03)</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/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/outils-astuces/license-helper-textmate-bundle.html' title='Bundle License Helper pour TextMate'>Bundle License Helper pour TextMate</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/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/optimiser-rapidite-chargement-adsense-jquery.html' title='Optimiser le chargement des AdSense'>Optimiser le chargement des AdSense</a></li></ul>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/jslint-console-rhino.html/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Optimiser le chargement des AdSense</title>
		<link>http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html</link>
		<comments>http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html#comments</comments>
		<pubDate>Thu, 11 Mar 2010 16:48:57 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[astuces]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[optimiser]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=357</guid>
		<description><![CDATA[Il n&#8217;y a rien de plus horripilant que d&#8217;attendre que des publicités chargent pour accéder au contenu d&#8217;un article. C&#8217;est malheureusement une situation que l&#8217;on rencontre fréquemment. La faute en incombe au fonctionnement des blocs AdSense des publicitaires.

En effet, ils nécessitent que nous insérerions le code correspondant à un bloc à l&#8217;endroit où il sera [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Il n&#8217;y a rien de plus horripilant que d&#8217;attendre que des publicités chargent pour accéder au contenu d&#8217;un article. C&#8217;est malheureusement une situation que l&#8217;on rencontre fréquemment. La faute en incombe au fonctionnement des blocs <strong>AdSense</strong> des publicitaires.</p>

<p>En effet, ils nécessitent que nous insérerions le code correspondant à un bloc à l&#8217;endroit où il sera affiché. Cela pour deux raisons notamment&#160;:</p>

<ol>
<li>Des variables globales identifiants l&#8217;annonce sont déclarées.</li>
<li>Le script qui va charger l&#8217;annonce est immédiatement exécuté et fait appel à des actions d&#8217;écriture dans le flux <em>via</em> <a href="https://developer.mozilla.org/fr/DOM/document.write">write</a>.</li>
</ol>

<p>Le deuxième point oblige le navigateur à traiter le code de l&#8217;adsense dès qu&#8217;il le rencontre puisque ce dernier n&#8217;utilise pas de gestionnaire de chargement. En plus d&#8217;écrire dans le flux courant, le système du publicitaire va charger des éléments extérieurs. Pour peu que la latence des réponses soit élevée, l&#8217;impression de <strong>ralentissement du chargement de la page</strong> augmente.</p>

<p>S&#8217;est ainsi que si un article est précédé d&#8217;un encart publicitaire, l&#8217;utilisateur devra patiemment attendre le chargement de ce dernier avant de pouvoir accéder au contenu désiré.<br />
L&#8217;expérience utilisateur s&#8217;en trouve dégradée.</p>

<h2>En finir avec les ralentissements de chargement des pages</h2>

<p>Vous l&#8217;aurez peut-être remarqué, mais sur <a href="http://pioupioum.fr/" title="piouPiouM&#8217;s dev : bloc-note d&#8217;un développeur web. PHP, git, shell, plugins WordPress, SPIP, jQuery">piouPiouM&#8217;s dev</a>, le <strong>chargement des blocs publicitaires</strong> est comme <strong>temporisé</strong>, ne gênant ainsi en rien la navigation sur le site.<br />
Voyons dans la suite du billet comment y parvenir, en prenant pour exemple le service <a href="https://www.google.com/adsense/">Google Adsense</a>.
<span id="more-357"></span></p>

<h2 id="integration-maquette">Intégration dans une maquette</h2>

<p>On commence par définir les emplacements des encarts publicitaires. Cela vous permet ainsi d&#8217;intégrer les annonces dans vos maquettes <abbr title="Hyper Text Markup Language">HTML</abbr>, tout en vous assurant que cette apparence sera conservée pour les utilisateurs n&#8217;ayant pas JavaScript d&#8217;activé, ou qui bloquent les annonces publicitaires.<br />
Je prend ici le parti d&#8217;annoncer la couleur, en précisant la mention <em>Publicité</em>.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;ads-[ads_id]&quot;</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;ads [ads_format]&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    Publicité
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>


<p>En sommes, il s&#8217;agit d&#8217;un simple élément <code>&lt;div&gt;</code> ayant pour attributs&#160;:</p>

<ul>
<li>un identifiant <strong>[ads_id]</strong>&#160;: un identifiant unique qui va servir de point d&#8217;ancrage au contenu de l&#8217;adsense. Vous pouvez par exemple, dans le cas de Google Adsense, utiliser le nom du critère personnalisé en notation CamelCase.</li>
<li>une classe <strong>ads</strong>&#160;: le style des encarts de pub lorsque celles-ci sont en attente de chargement.</li>
<li>une classe <strong>[ads_format]</strong>&#160;: le format de l&#8217;encart publicitaire. Par exemple, <code>square250</code> pour une annonce de 250px de côtés ou encore <code>banner468</code> pour une bannière au format 468 x 60.</li>
</ul>

<p>Appliquez les styles <abbr title="Cascading Style Sheets">CSS</abbr> qui suivent.</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
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* @group Tools */</span>
&nbsp;
<span style="color: #6666ff;">.hide</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;">none</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* @end   Tools */</span>
<span style="color: #808080; font-style: italic;">/* @group Adsense */</span>
&nbsp;
<span style="color: #6666ff;">.ads</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#F4F4F4</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#666666</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;">11px</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;">text-transform</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">uppercase</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.square250</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">250px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.banner468</span> <span style="color: #00AA00;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">60px</span><span style="color: #00AA00;">;</span>
  <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">468px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* @end   Adsense */</span></pre></td></tr></table></div>


<h2 id="ads-code-annonceur">Insertion du code de l&#8217;annonceur</h2>

<p>Insérez en fin de page les différents codes donnés par votre annonceur (ici, Google Adsense).</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">&quot;hide&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- Ads --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;div</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">&quot;adsref-[ads_id]&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
google_ad_client = &quot;pub-[client_id]&quot;;
google_ad_slot   = &quot;[slot_id]&quot;;
google_ad_width  = 250;
google_ad_height = 250;
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;script</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span>=<span style="color: #ff0000;">&quot;http://pagead2.googlesyndication.com/pagead/show_ads.js&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/script<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/div<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>


<p><strong>Chaque annonce</strong> est incluse dans un élément ayant pour identifiant <code>adsref-[ads_id]</code> (voir <a href="#integration-maquette">Intégration de la maquette</a>) qui fait le lien avec l&#8217;emplacement final de la publicité.</p>

<p>Le tout étant masqué à l&#8217;aide d&#8217;un <code>div.hide</code>. Il serait en effet désagréable d&#8217;afficher les annonces publicitaires en bas de page, même si ce n&#8217;est que pour une poignée de [micro]secondes.</p>

<h2 id="jquery-ads-loader">Un Adsense Loader avec jQuery</h2>

<p>Il ne reste plus qu&#8217;à déplacer à l&#8217;aide de JavaScript les blocs AdSense aux endroits souhaités. Avec <a href="http://pioupioum.fr/tag/jquery/" title="Archives pour le tag jQuery – piouPiouM&#039;s dev">jQuery</a> cela donne&#160;:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> $ads<span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'div[id^=&quot;adsref-&quot;]'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">each</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>          <span style="color: #006600; font-style: italic;">// pour chaque bloc d'annonce #adsref-[ads_id]</span>
        $ads <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#ads-'</span> <span style="color: #339933;">+</span> <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #660066;">id</span>.<span style="color: #660066;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">7</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// supprimer de #ads-[ads_id] tout éventuel contenu</span>
        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'ins:first'</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span>$ads<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>           <span style="color: #006600; font-style: italic;">// déplacer l'annonce dans #ads-[ads_id]</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>Bien évidemment, et comme vous êtes sensible aux bonnes pratiques liées à la <a href="http://performance.survol.fr/" title="Performance web">performance web</a>, vous insérerez naturellement ce code en fin de page <img src='http://pioupioum.fr/wp/wp-includes/images/smilies/icon_wink.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/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/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><li><a href='http://pioupioum.fr/developpement/javascript-detecter-support-rgba.html' title='JavaScript : tester le support des couleurs RGBA'>JavaScript&#160;: tester le support des couleurs RGBA</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></ul>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/optimiser-rapidite-chargement-adsense-jquery.html/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Du RGBA dans vos animations avec le plugin jQuery Color</title>
		<link>http://pioupioum.fr/developpement/jquery-color-plugin-animation-rgba-support.html</link>
		<comments>http://pioupioum.fr/developpement/jquery-color-plugin-animation-rgba-support.html#comments</comments>
		<pubDate>Sat, 20 Feb 2010 14:13:32 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[couleur]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rgba]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=332</guid>
		<description><![CDATA[J&#8217;ai récemment eu à (ré)utiliser le plugin jQuery Color mais je me suis heurté à une limitation. Je travaillais sur un jeu de couleurs RGBA et malheureusement le plugin ne supportait pas ce mode colorimétrique (il se contente de travailler sur des couleurs RGB).

Qu&#8217;à cela ne tienne, en attendant que ma modification soit intégrée1 au [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>J&#8217;ai récemment eu à (ré)utiliser le plugin <a href="http://plugins.jquery.com/project/color" title="Plugins Color Animations | jQuery Plugins">jQuery Color</a> mais je me suis heurté à une limitation. Je travaillais sur un jeu de couleurs RGBA et malheureusement le plugin ne supportait pas ce mode colorimétrique (il se contente de travailler sur des couleurs RGB).</p>

<p>Qu&#8217;à cela ne tienne, en attendant que <a href="http://github.com/piouPiouM/jquery-color/commit/92ee455320d7e32e0bccdd09166087c1ba5555e2" title="Voir le commit sur mon fork GitHub">ma modification</a> soit intégrée<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup> au plugin, voici une version de <strong>jQuery Color</strong> pourvu du <strong><a href="http://pioupioum.fr/developpement/javascript-detecter-support-rgba.html" title="JavaScript : tester le support des couleurs RGBA &#8211; DOM, jQuery CSS3 RGBA &#8211; piouPiouM&#039;s dev">support des couleurs RGBA</a></strong>&#160;:</p>

<div class="box file-js">
    <a href="http://static.pioupioum.fr/code/jquery.color.js" title="Télécharger"><span>jquery.color.js (6&#160;Ko)</span></a>
</div>

<p>La <a href="http://pioupioum.fr/sandbox/jquery-color/" title="RBGA support for jQuery Color – jQuery Color test page – piouPiouM’s dev">page de démonstration</a> qui va bien.</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/javascript-detecter-support-rgba.html' title='JavaScript : tester le support des couleurs RGBA'>JavaScript&#160;: tester le support des couleurs RGBA</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/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/supprimer-neige-scripts-greasemonkey.html' title='Supprimer les effets de neige avec Greasemonkey'>Supprimer les effets de neige avec Greasemonkey</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></ul>

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

<li id="fn:1">
<p>enfin, je l&#8217;espère :]&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/jquery-color-plugin-animation-rgba-support.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript&#160;: tester le support des couleurs RGBA</title>
		<link>http://pioupioum.fr/developpement/javascript-detecter-support-rgba.html</link>
		<comments>http://pioupioum.fr/developpement/javascript-detecter-support-rgba.html#comments</comments>
		<pubDate>Sun, 14 Feb 2010 22:09:31 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[couleur]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[rgba]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=322</guid>
		<description><![CDATA[CSS3 introduit le support des couleurs en mode RGBA. Ce dernier permet de définir une valeur d&#8217;alpha à une couleur RGB. Voici comment détecter via JavaScript si un navigteur supporte la fonctionnalité1.

Comment détecter qu&#8217;un navigateur supporte RGBA&#160;?

Le principe est simple&#160;:


Atteindre le premier élément script2 du document.
Mémoriser sa couleur de police (ou de fond).
Tester si la [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>CSS3 introduit le support des <strong>couleurs en mode RGBA</strong>. Ce dernier permet de définir une valeur d&#8217;alpha à une couleur RGB. Voici comment <strong>détecter <em>via</em> JavaScript</strong> si un navigteur supporte la fonctionnalité<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>.</p>

<h2>Comment détecter qu&#8217;un navigateur supporte <strong>RGBA</strong>&#160;?</h2>

<p>Le principe est simple&#160;:</p>

<ol>
<li>Atteindre le premier élément <code>script</code><sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> du document.</li>
<li>Mémoriser sa couleur de police (ou de fond).</li>
<li>Tester si la couleur n&#8217;est pas déjà en RGBA.</li>
<li>Oui&#160;? Sauter à 7. Non&#160;? Modifier la couleur de l&#8217;élément script en <code>rgba(0, 0, 0, 0.5)</code>. Si le navigateur ne supporte pas le mode de couleur RGBA, l&#8217;action n&#8217;aura aucun effet.</li>
<li>Tester la non correspondance de la couleur initiale et de la nouvelle.</li>
<li>Réinitialiser la couleur de l&#8217;élément script.</li>
<li>Retourner le résultat du test.
<span id="more-322"></span></li>
</ol>

<h2>Tester le support de RGBA <em>via</em> le <strong>DOM</strong></h2>

<p>L&#8217;implémentation DOM de l&#8217;algorithme n&#8217;a rien de complexe. Cependant, pour éviter de réitérer les manipulations DOM en cas de tests multiples, on assigne à la fonction une propriété <code>result</code> à l&#8217;aide de <a href="https://developer.mozilla.org/fr/Référence_de_JavaScript_1.5_Core/Fonctions/arguments/callee">arguments.callee</a>.</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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">/**
 * Check whether the browser supports RGBA color mode.
 *
 * @author Mehdi Kabab &lt;http://pioupioum.fr&gt;
 * @type Boolean
 * @return True if the browser support RGBA. False otherwise.
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> isRGBACapable<span style="color: #009900;">&#40;</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><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'result'</span> <span style="color: #000066; font-weight: bold;">in</span> arguments.<span style="color: #660066;">callee</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> dScript <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementsByTagName</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span>
            color   <span style="color: #339933;">=</span> dScript.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span><span style="color: #339933;">;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^rgba/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>color<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            arguments.<span style="color: #660066;">callee</span>.<span style="color: #660066;">result</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: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
                dScript.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'rgba(0, 0, 0, 0.5)'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
            arguments.<span style="color: #660066;">callee</span>.<span style="color: #660066;">result</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>dScript.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span> <span style="color: #339933;">!=</span> color<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            dScript.<span style="color: #660066;">style</span>.<span style="color: #660066;">color</span>     <span style="color: #339933;">=</span>  color<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> arguments.<span style="color: #660066;">callee</span>.<span style="color: #660066;">result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<h2>Tester le support de RGBA <em>via</em> <strong>jQuery</strong></h2>

<p>Avec jQuery, il peut être utile d&#8217;initialiser une proprité <code>jQuery.support.rgba</code> pour éviter de lancer le test à de multiples reprises.</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
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'rgba'</span> <span style="color: #000066; font-weight: bold;">in</span> jQuery.<span style="color: #660066;">support</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    jQuery.<span style="color: #660066;">extend</span><span style="color: #009900;">&#40;</span>jQuery.<span style="color: #660066;">support</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #3366CC;">'rgba'</span><span style="color: #339933;">:</span> isRGBACapable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #006600; font-style: italic;">/**
 * Check whether the browser supports RGBA color mode.
 *
 * @author Mehdi Kabab &lt;http://pioupioum.fr&gt;
 * @type Boolean
 * @return True if the browser support RGBA. False otherwise.
 */</span>
<span style="color: #003366; font-weight: bold;">function</span> isRGBACapable<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> $script <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'script:first'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        color   <span style="color: #339933;">=</span> $script.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'color'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        result  <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/^rgba/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>color<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            result <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: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            result <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> color <span style="color: #339933;">!=</span> $script.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'color'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'rgba(0, 0, 0, 0.5)'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'color'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            $script.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'color'</span><span style="color: #339933;">,</span> color<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000066; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">return</span> result<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</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/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><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/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/supprimer-neige-scripts-greasemonkey.html' title='Supprimer les effets de neige avec Greasemonkey'>Supprimer les effets de neige avec Greasemonkey</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></ul>

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

<li id="fn:1">
<p>toute autre propriété CSS3 peut être testée sur le même modèle, comme <a href="http://www.css3.info/preview/hsla/" title="HSLA Colors - CSS3 . Info">HSLA</a> ou encore <a href="http://www.css3.info/preview/box-shadow/" title="Box-shadow, one of CSS3&#8217;s best new features - CSS3 . Info">box-shadow</a>.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>nous utilisons JavaScript, il est naturel de trouver au moins un élément <code>script</code>.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/javascript-detecter-support-rgba.html/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Git&#160;: des alias pour aller plus vite</title>
		<link>http://pioupioum.fr/developpement/git-alias-productivite.html</link>
		<comments>http://pioupioum.fr/developpement/git-alias-productivite.html#comments</comments>
		<pubDate>Wed, 30 Dec 2009 09:18:24 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[astuces]]></category>
		<category><![CDATA[cheat sheets]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[productivité]]></category>
		<category><![CDATA[scm]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=295</guid>
		<description><![CDATA[Les alias sont des raccourcis vers des commandes de Git. Fini les répétitions et autres saisies de commandes rébarbatives&#160;! Pour ajouter de nouveaux alias, créez ou éditez la section [alias] de l&#8217;un des fichiers qui suivent (voir les exemples du billet pour avoir une information sur la syntaxe)&#160;:


~/.gitconfig pour en bénéficier dans tous vos dépôts.
.git/config [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Les <strong>alias</strong> sont des <strong>raccourcis</strong> vers des commandes de <strong>Git</strong>. Fini les répétitions et autres saisies de commandes rébarbatives&#160;! Pour ajouter de nouveaux alias, créez ou éditez la section <code>[alias]</code> de l&#8217;un des fichiers qui suivent (voir les exemples du billet pour avoir une information sur la syntaxe)&#160;:</p>

<ul>
<li><code>~/.gitconfig</code> pour en bénéficier dans tous vos dépôts.</li>
<li><code>.git/config</code> d&#8217;un projet pour restreindre son accès à cet unique projet.</li>
</ul>

<p>Il est également possible de recourir à la commande <a href="http://www.kernel.org/pub/software/scm/git/docs/git-config.html" title="git-config(1) Manual Page">git config</a>&#160;:</p>

<pre><code>$ git config --global alias.st 'status'
</code></pre>

<p>Ici, la commande <code>git st</code> devient un alias de <a href="http://www.kernel.org/pub/software/scm/git/docs/git-status.html" title="git-status(1) Manual Page">git status</a>.</p>

<p><strong>Note&#160;:</strong> supprimer le flag <code>--global</code> va ajouter l&#8217;alias dans le scope du projet courant.
<span id="more-295"></span></p>

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

<ol>
<li><a href="#mes-alias">Mes alias</a></li>
<li><a href="#alias-utilisateurs-svn">Des raccourcis pour les utilisateurs de SVN</a></li>
<li><a href="#annuler-dernier-commit">Annuler le dernier commit</a></li>
<li><a href="#editer-dernier-commit">Éditer le dernier commit</a></li>
<li><a href="#speed-diff">Faire le point rapidement</a></li>
<li><a href="#historique-sexy">Afficher un historique condensé des commits</a></li>
<li><a href="#derniers-changements-pull">Afficher les changements réalisés depuis le dernier pull</a></li>
<li><a href="#ajouter-rapidement-commit">Ajouter rapidement des fichiers à commiter</a></li>
<li><a href="#ouvrir-dans-textmate">Ouvrir dans TextMate les fichiers non commités</a></li>
</ol>

<h2 id="mes-alias">Mes alias</h2>

<p>Voici les alias que j&#8217;utilise dans le scope global, en provenance donc de mon fichier <code>~/.gitconfig</code>&#160;:</p>

<pre><code>[alias]
    amend = commit --amend
    st = status
    who = shortlog -sne
    oneline = log --pretty=oneline --abbrev-commit --graph
    changes = diff --name-status
    dic = diff --cached
    diffstat = diff --stat
    svnpull = svn rebase
    svnpush = svn dcommit
    lc = !git oneline ORIG_HEAD.. --stat --no-merges
    addm = !git-ls-files -m -z | xargs -0 git-add &amp;&amp; git status
    addu = !git-ls-files -o --exclude-standard -z | xargs -0 git-add &amp;&amp; git status
    rmm = !git ls-files -d -z | xargs -0 git-rm &amp;&amp; git status
    mate = !git-ls-files -m -z | xargs -0 mate
    mateall = !git-ls-files -m -o --exclude-standard -z | xargs -0 mate
</code></pre>

<h2 id="alias-utilisateurs-svn">Des raccourcis pour les utilisateurs de SVN</h2>

<pre><code>[alias]
    st = status
    df = diff
    co = checkout
    ci = commit
    br = branch
    svnpull = svn rebase
    svnpush = svn dcommit
</code></pre>

<p><strong>Attention&#160;:</strong> la commande <a href="http://www.kernel.org/pub/software/scm/git/docs/git-checkout.html" title="git-checkout(1) Manual Page">git checkout</a> n&#8217;a pas la même utilité dans Git que dans Subversion&#160;!</p>

<h2 id="annuler-dernier-commit">Annuler le dernier commit</h2>

<p>Le flag <code>--soft</code> va conserver les modifications dans le répertoire de travail.</p>

<pre><code>[alias]
    undo = git reset --soft HEAD^
</code></pre>

<p><strong>Important&#160;:</strong> nous travaillons ici en local. Il est malvenu d&#8217;annuler un commit sur le dépôt distant (désynchro, arbre cassé, etc). On assume ses erreurs <img src='http://pioupioum.fr/wp/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<h2 id="editer-dernier-commit">Éditer le dernier commit</h2>

<pre><code>[alias]
    amend = commit --amend
</code></pre>

<h2 id="speed-diff">Faire le point rapidement</h2>

<pre><code>[alias]
    changes = diff --name-status
    dic = diff --cached
    diffstat = diff --stat
</code></pre>

<h2 id="historique-sexy">Afficher un historique condensé des commits</h2>

<pre><code>[alias]
    oneline = log --pretty=oneline --abbrev-commit --graph
</code></pre>

<h2 id="derniers-changements-pull">Afficher les changements réalisés depuis le dernier pull</h2>

<pre><code>[alias]
    lc = !git oneline ORIG_HEAD.. --stat --no-merges
</code></pre>

<h2 id="ajouter-rapidement-commit">Ajouter rapidement des fichiers à commiter</h2>

<p>Les alias qui suivent vont lister les fichiers d&#8217;un certain type pour les ajouter à l&#8217;index avant commit. J&#8217;affiche ensuite l&#8217;état du projet pour valider qu&#8217;aucune erreur ne s&#8217;est produite.</p>

<p>On peut donc chaîner les commandes à condition de préfixer l&#8217;alias par un point d&#8217;exclamation&nbsp;<code>!</code>.</p>

<pre><code>[alias]
    addm = !git-ls-files -m -z | xargs -0 git-add &amp;&amp; git status                     # ajouter les fichiers modifiés.
    addu = !git-ls-files -o --exclude-standard -z | xargs -0 git-add &amp;&amp; git status  # ajouter les fichiers inconnus.
    rmm  = !git ls-files -d -z | xargs -0 git-rm &amp;&amp; git status                      # supprimer les fichiers marqués
                                                                                    # comme effacés.
</code></pre>

<h2 id="ouvrir-dans-textmate">Ouvrir dans TextMate les fichiers non commités</h2>

<p>Pratique pour reprendre son travail là où l&#8217;avait arrêté (poke <a href="http://jeremy.wordpress.com/2009/12/01/ouvrir-tous-les-fichiers-modifies-git/" title="Ouvrir tous les fichiers modifiés (git) &laquo;  Jérémy Lecour">Jérémy Lecour</a>), <code>git mate</code> permet d&#8217;ouvrir dans <a href="http://macromates.com/" title="TextMate — The Missing Editor for Mac OS X">mon éditeur de code préféré</a> les fichiers modifiés depuis le dernier commit.<br />
L&#8217;alias <code>git mateall</code> tiendra compte des fichiers inconnus de l&#8217;index du projet.</p>

<pre><code>[alias]
    mate = !git-ls-files -m -z | xargs -0 mate
    mateall = !git-ls-files -m -o --exclude-standard -z | xargs -0 mate
</code></pre>

<div class="updated">

<h5>Mises à jour</h5>

<ul>
<li>
<strong>2 juin 2010</strong><br />
Mise à jour des alias d&#8217;<a href="#ajouter-rapidement-commit">ajout rapide de fichiers à commiter</a> et d&#8217;<a href="#ouvrir-dans-textmate">édition dans TextMate</a>. Les chemins contenant des espaces provoquaient une erreur fatale.</li>
</ul>

</div>

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

<ul class='related_post'><li><a href='http://pioupioum.fr/developpement/git-10-commandes-utiles.html' title='Git : 10 commandes utiles'>Git&#160;: 10 commandes utiles</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/git-ignore-projet-flex-builder.html' title='Git ignore pour un projet Flex Builder'>Git ignore pour un projet Flex Builder</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>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/git-alias-productivite.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Git&#160;: 10 commandes utiles</title>
		<link>http://pioupioum.fr/developpement/git-10-commandes-utiles.html</link>
		<comments>http://pioupioum.fr/developpement/git-10-commandes-utiles.html#comments</comments>
		<pubDate>Wed, 23 Dec 2009 09:36:46 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[astuces]]></category>
		<category><![CDATA[cheat sheets]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[scm]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=285</guid>
		<description><![CDATA[Cela fait plus d&#8217;un an et demi que j&#8217;utilise Git dans mes environnements de travail personnel et professionnel. Jamais je ne l&#8217;échangerai contre SVN&#160;! Oups, je m&#8217;égare  

Git c&#8217;est bien, mais encore faut-il retenir son nombre croissant de commandes pour l&#8217;utiliser au mieux. Ce billet va être le premier d&#8217;une série qui va m&#8217;aider [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Cela fait plus d&#8217;un an et demi que j&#8217;utilise <a href="http://git-scm.com/" title="Git - Fast Version Control System">Git</a> dans mes environnements de travail personnel et professionnel. Jamais je ne l&#8217;échangerai contre <a href="http://subversion.tigris.org/" title="subversion.tigris.org">SVN</a>&#160;! Oups, je m&#8217;égare <img src='http://pioupioum.fr/wp/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<p><strong>Git c&#8217;est bien</strong>, mais encore faut-il retenir son nombre croissant de commandes pour l&#8217;utiliser au mieux. Ce billet va être le premier d&#8217;une série qui va m&#8217;aider à mettre sur &#8220;papier&#8221; les commandes qui me sont le plus utiles.<span id="more-285"></span></p>

<h2 id="toc">Liste des commandes utiles</h2>

<ol>
<li><a href="#editer-commentaire-dernier-commit">Éditer le commentaire du dernier commit</a></li>
<li><a href="#supprimer-branche-serveur">Supprimer une branche distante</a></li>
<li><a href="#supprimer-tag-serveur">Supprimer un tag du repository distant</a></li>
<li><a href="#compter-commit-utilisateur">Compter le nombre de commits par utilisateur</a></li>
<li><a href="#commit-autre-identite">Commiter sous une autre identité</a></li>
<li><a href="#antidater-commit">Antidater un commit</a></li>
<li><a href="#abandonner-suivi-fichiers">Abandonner le suivi de fichiers</a></li>
<li><a href="#copier-untracked-files-hors-reposity">Copier les fichiers inconnus de Git en dehors du répertoire de travail</a></li>
<li><a href="#supprimer-fichiers-non-suivis">Supprimer les fichiers inconnus de Git</a></li>
<li><a href="#exporter-archive-zip-tar-gz">Exporter son projet dans une archive ZIP ou TAR.GZ</a></li>
</ol>

<h2 id="editer-commentaire-dernier-commit">Éditer le commentaire du dernier commit</h2>

<p>Une commande qui se passe d&#8217;explications.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git commit <span style="color: #660033;">--amend</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;Le nouveau commentaire.&quot;</span></pre></div></div>


<p><strong>Edit&#160;:</strong><br />
Comme le précise <a href="http://jeremy.wordpress.com/">Jérémy</a> dans les commentaires, cette commande n&#8217;est à utiliser que sur un commit qui n&#8217;a pas été diffusé sur un autre repository. Autrement, cela casserait l&#8217;historique et des divergences peuvent apparaître.</p>

<h2 id="supprimer-branche-serveur">Supprimer une branche distante</h2>

<p>Effacer une branche du dépôt distant s&#8217;effectue de la même manière que si vous la publiez à l&#8217;aide de la commande <code>git push</code>, mais en précédant le nom de la branche d&#8217;un double point.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git push origin :ma_branche</pre></div></div>


<h2 id="supprimer-tag-serveur">Supprimer un tag du repository distant</h2>

<p>La commande <code>git push --tags</code> ne pousse pas les tags supprimés localement. Afin de supprimer un tag sur le serveur distant, il faut reprendre la syntaxe de suppression d&#8217;une branche&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git push origin :my_tag</pre></div></div>


<p>Il est également possible d&#8217;utiliser la commande <a href="http://www.kernel.org/pub/software/scm/git/docs/git-tag.html" title="git-tag(1) Manual Page">git tag</a> et son flag <code>-d</code>&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git tag <span style="color: #660033;">-d</span> my_tag</pre></div></div>


<h2 id="compter-commit-utilisateur">Compter le nombre de commits par utilisateur</h2>

<p>Avec <a href="http://www.kernel.org/pub/software/scm/git/docs/git-shortlog.html" title="git-shortlog(1) Manual Page">git shortlog</a> et ses flags <code>-n</code> et <code>-s</code> on obtient la sortie suivante pour le dépôt du <a href="http://www.pluf.org/" title="Pluf : Pluf, PHP WebApp Framework">framework PHP Pluf</a>&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">git shortlog <span style="color: #660033;">-sn</span>
   <span style="color: #000000;">163</span>  Loic d<span style="color: #ff0000;">'Anterroches
     4  Jürgen Hörmann
     2  Mehdi Kabab
     1  Baptiste Durand-Bret
     1  Jakub Vitak</span></pre></div></div>


<p>Ajoutez l&#8217;option <code>-e</code> pour afficher les adresses e-mails.</p>

<h2 id="commit-autre-identite">Commiter sous une autre identité</h2>

<p>Un contributeur vous a envoyé un patch et vous souhaitez lui attribuer le commit<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>&#160;? Le flag <code>--author</code> est là pour ça&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git commit <span style="color: #660033;">--author</span> <span style="color: #ff0000;">&quot;Prénom Nom &lt;email@address.com&gt;&quot;</span></pre></div></div>


<h2 id="antidater-commit">Antidater un commit</h2>

<p>Très pratique pour maintenir à jour son historique de commits, la définition de la variable <code>GIT_AUTHOR_DATE</code> permet de préciser la date et heure du commit.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #007800;">GIT_AUTHOR_DATE</span>=<span style="color: #ff0000;">&quot;2009-11-26 08:32 +100&quot;</span> git commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;Un commit antidaté.&quot;</span></pre></div></div>


<h2 id="abandonner-suivi-fichiers">Abandonner le suivi de fichiers</h2>

<p>Lors d&#8217;une phase de débogage, il est généralement peu utile de suivre les modifications de certains fichiers. La commande <a href="http://www.kernel.org/pub//software/scm/git/docs/git-update-index.html" title="git-update-index(1) Manual Page">git update-index</a> et son flag <code>--assume-unchanged</code> va permettre d&#8217;ignorer les changements du ou des fichiers précisés.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git update-index <span style="color: #660033;">--assume-unchanged</span> README.md</pre></div></div>


<p>Pour revenir à la normale, utilisez le flag <code>--no-assume-unchanged</code>&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git update-index <span style="color: #660033;">--no-assume-unchanged</span> README.md</pre></div></div>


<h2 id="copier-untracked-files-hors-reposity">Copier les fichiers inconnus de Git en dehors du répertoire de travail</h2>

<p>Sous Mac <abbr title="Operating System">OS</abbr> X<sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> la commande est&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git ls-files <span style="color: #660033;">--others</span> <span style="color: #660033;">--exclude-standard</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cpio</span> <span style="color: #660033;">-pmd</span> <span style="color: #000000; font-weight: bold;">/</span>chemin<span style="color: #000000; font-weight: bold;">/</span>de<span style="color: #000000; font-weight: bold;">/</span>destination</pre></div></div>


<p>Retirez l&#8217;option <code>--exclude-standard</code> si vous désirez exporter les fichiers ignorés par Git.</p>

<h2 id="supprimer-fichiers-inconnus">Supprimer les fichiers inconnus de Git</h2>

<p>Il m&#8217;arrive de créer des fichiers qui ne seront finalement pas ajoutés à l&#8217;index de ma copie locale. Ces fichiers apparaissent donc inlassablement dans la liste des fichiers <em>untracked</em>. Au lieu de les supprimer manuellement, je charge Git de le faire&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git clean <span style="color: #660033;">-n</span> <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">&lt;</span>path<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>


<p>Ici, la commande <a href="http://www.kernel.org/pub/software/scm/git/docs/git-clean.html" title="git-clean(1) Manual Page">git clean</a> ne va rien supprimer. En effet, le flag <code>-n</code> réalise un <strong>dry run</strong> pour lister les fichiers et répertoires concernés par le nettoyage du répertoire de travail, ou du chemin <code>&lt;path&gt;</code> si ce dernier est précisé.</p>

<p>Si vous souhaitez supprimer uniquement les fichiers et conserver les répertoires vides, enlevez l&#8217;option <code>-d</code>.</p>

<p>Ajoutez le flag <code>-x</code> pour inclure les fichiers ignorés par Git (cf. le fichier .gitignore). Pour ne supprimer que les fichiers ignorés, optez pour l&#8217;option <code>-X</code>.</p>

<p>Dernière astuce, tant que l&#8217;option <code>clean.requireForce</code> n&#8217;est pas définie à <code>false</code> dans votre fichier de configuration, Git contraindra <code>git clean</code> à ne fonctionner qu&#8217;avec les flags <code>-n</code> et <code>-f</code>. Autrement dit, soit vous réalisez un test <em>dry run</em>, soit vous forcez l&#8217;action du nettoyage de votre arbre de travail. Et c&#8217;est une bonne chose, personne n&#8217;est à l&#8217;abri d&#8217;une erreur&#160;!</p>

<h2 id="exporter-archive-zip-tar-gz">Exporter son projet dans une archive ZIP ou TAR.GZ</h2>

<p>Si vous souhaitez fournir une archive d&#8217;une version précise de votre projet, <a href="http://www.kernel.org/pub/software/scm/git/docs/git-archive.html" title="git-archive(1) Manual Page">git archive</a> va pouvoir vous aider. En considérant que la version visée est marquée par le tag 1.0&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git archive <span style="color: #660033;">--format</span>=<span style="color: #c20cb9; font-weight: bold;">zip</span> <span style="color: #660033;">--prefix</span>=mon_projet-<span style="color: #000000;">1.0</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-9</span> <span style="color: #000000;">1.0</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>chemin<span style="color: #000000; font-weight: bold;">/</span>de<span style="color: #000000; font-weight: bold;">/</span>destination<span style="color: #000000; font-weight: bold;">/</span>mon-projet-1.0.zip</pre></div></div>


<p>Détail sur les options&#160;:</p>

<ul>
<li><code>--format</code> pour spécifier le format de l&#8217;archive. <code>git archive --list</code> pour connaître la liste des formats supportés.</li>
<li><code>--prefix</code> va préfixer tous les noms de fichiers et dossiers. <strong>N&#8217;oubliez pas le slash terminal</strong> si vous souhaitez regrouper les documents dans un dossier.</li>
<li><code>-9</code> est une option spécifique du format d&#8217;exportation ZIP. De 0 à 9, il détermine le niveau de compression.</li>
<li><code>1.0</code> est le nom du tag. Vous pouvez également exporter des branches, le HEAD et autres <em>tree-ish</em>.</li>
<li>pour finir on redirige le tout dans un fichier.</li>
</ul>

<p>Pour exporter les fichiers contenu dans le répertoire d&#8217;une branche donnée la commande devient&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git archive <span style="color: #660033;">--format</span>=<span style="color: #c20cb9; font-weight: bold;">zip</span> <span style="color: #660033;">--prefix</span>=mon_projet-dev<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-9</span> dev:src<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>chemin<span style="color: #000000; font-weight: bold;">/</span>de<span style="color: #000000; font-weight: bold;">/</span>destination<span style="color: #000000; font-weight: bold;">/</span>mon_projet-dev.zip</pre></div></div>


<p>Enfin, l&#8217;export au format TAR.GZ se fait de la manière suivante&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ git archive <span style="color: #660033;">--format</span>=<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">--prefix</span>=mon_projet-<span style="color: #000000;">1.0</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1.0</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">gzip</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>chemin<span style="color: #000000; font-weight: bold;">/</span>de<span style="color: #000000; font-weight: bold;">/</span>destination<span style="color: #000000; font-weight: bold;">/</span>mon-projet-1.0.tar.gz</pre></div></div>


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

<ul class='related_post'><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 />
<ol>

<li id="fn:1">
<p>une bonne pratique a encourager&#160;!&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>si la commande <code>cpio</code> fonctionne différemment sur d&#8217;autres <abbr title="Operating System">OS</abbr>, merci de me le signaler en commentaire. Je mettrai à jour en conséquence le snippet.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/git-10-commandes-utiles.html/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Phing Header&#160;: une tâche pour ajouter un en-tête aux fichiers</title>
		<link>http://pioupioum.fr/developpement/phing-header-task.html</link>
		<comments>http://pioupioum.fr/developpement/phing-header-task.html#comments</comments>
		<pubDate>Sun, 30 Aug 2009 19:54:24 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[automatisation]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[phing]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[projet]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=215</guid>
		<description><![CDATA[Une des tâches les plus rébarbatives est bien l&#8217;ajout d&#8217;une licence d&#8217;utilisation à tous les fichiers sources de ses projets. Ajoutez à cela que, comme tout bon développeur, je n&#8217;aime pas répéter la même opération plus de deux fois, je me suis codé l&#8217;an dernier une tâche Phing pour automatiser cela1&#160;: Header.

Présentation

Phing Header se découpe [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Une des tâches les plus rébarbatives est bien l&#8217;ajout d&#8217;une licence d&#8217;utilisation à tous les fichiers sources de ses projets. Ajoutez à cela que, comme tout bon développeur, je n&#8217;aime pas répéter la même opération plus de deux fois, je me suis codé l&#8217;an dernier une tâche <a href="http://phing.info/" title="Phing"><strong>Phing</strong></a> pour <strong>automatiser</strong> cela<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>&#160;: <em>Header</em>.</p>

<h2>Présentation</h2>

<p><strong>Phing Header</strong> se découpe en deux tâches&#160;: <strong>HeaderTask</strong> et <strong>HeaderPhpTask</strong>.</p>

<p>La tâche <strong>HeaderTask</strong> permet d&#8217;ajouter un en-tête à n&#8217;importe quel fichier. Elle peut être comparée au paramètre imbriqué <em>header</em> de la tâche <a href="http://ant.apache.org/manual/CoreTasks/concat.html" title="Concat">Concat</a> d&#8217;<a href="http://ant.apache.org/" title="Apache Ant - Welcome">Ant</a><sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup>.</p>

<p>Plus spécifique, la tâche <strong>HeaderPhpTask</strong> est à utiliser pour ajouter un en-tête aux fichiers PHP. Le tag PHP <code>&lt;?php</code> précédera ainsi le contenu à concaténer&#160;; le premier tag PHP étant supprimé.
<span id="more-215"></span></p>

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

<ol>
<li><a href="#presentation">Présentation</a></li>
<li><a href="#telecharger">Téléchargement</a></li>
<li><a href="#installation">Installation</a></li>
<li><a href="#attributs">Attributs</a></li>
<li><a href="#nested-tags">Tags imbriquées supportées</a></li>
<li><a href="#utilisation">Exemples d&#8217;utilisation</a></li>
<li><a href="#licence">Licence</a></li>
<li><a href="#todo">Tâches à faire</a></li>
<li><a href="#changelog">Historique des versions et changelog</a></li>
</ol>

<h2 id="telecharger">Téléchargement</h2>

<div class="download box">
    <a href="http://cloud.github.com/downloads/piouPiouM/phing-header/phing-header-1.0.zip" title="Téléchargement depuis les serveurs de GitHub"><span>Télécharger la dernière version de la tâche <strong>Phing Header</strong> (8&#160;Ko)</span></a>
</div>

<p>Vous pouvez également cloner le projet depuis son <a href="http://github.com/piouPiouM/phing-header/" title="piouPiouM's phing-header at master - GitHub">dépôt GitHub</a>.</p>

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

<p>Si vous suivez la <a href="http://phing.info/docs/guide/current/chapters/ExtendingPhing.html#CreatingATask" title="Phing Guide - Extending Phing">documentation</a> de Phing, il vous faut copier le répertoire<sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup> <code>header</code> contenu dans l&#8217;archive dans le dossier <code>classes/phing/tasks/my</code> de votre installation Phing.</p>

<p>Personnellement je préfère utiliser un chemin externe à l&#8217;installation de base de Phing. Pour ce faire, il suffit de créer l&#8217;arborescence <code>phing/tasks/my</code> à l&#8217;endroit désiré (par exemple <code>/Library/WebServer/share/php</code>) et de déclarer ce dernier <em>via</em> la propriété <code>include_path</code> de votre fichier <code>php.ini</code>. Ce qui nous donne ici&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">include_path</span> <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;.:/Library/WebServer/share/php:/usr/local/php5/lib/php&quot;</span></pre></div></div>


<p>et l&#8217;arborescence suivante&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/Library/WebServer/share/php/
  `-- phing/
       `-- tasks/
            `-- my/
                 `-- header/
                      |-- HeaderPhpTask.php
                      `-- HeaderTask.php</pre></div></div>


<p>Vous devrez déclarer ces nouvelles tâches à l&#8217;aide de la tâche <a href="http://phing.info/docs/guide/current/chapters/appendixes/AppendixB-CoreTasks.html#TaskdefTask" title="Phing Guide - Core Tasks">Taskdef</a> dans vos fichiers de build. Par exemple&#160;:</p>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;header&quot;</span> <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;phing.tasks.my.header.HeaderTask&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>


<h2>Attributs</h2>

<p>Les tâches <strong>HeaderTask</strong> et <strong>HeaderPhpTask</strong> se partagent la liste d&#8217;attributs qui suit&#160;:</p>

<table>
<thead>
<tr>
  <th>Nom</th>
  <th>Type</th>
  <th>Description</th>
  <th align="center">Defaut</th>
  <th align="center">Requis</th>
</tr>
</thead>
<tbody>
<tr>
  <td>file</td>
  <td>String</td>
  <td>Le chemin du fichier en-tête à charger.</td>
  <td align="center">n/a</td>
  <td align="center">Oui</td>
</tr>
<tr>
  <td>eol</td>
  <td>String</td>
  <td>Préciser le <a href="#eol">caractère de fin de ligne</a>.</td>
  <td align="center"><code>PHP_EOL</code></td>
  <td align="center">Non</td>
</tr>
<tr>
  <td>preservelastmodified</td>
  <td>Boolean</td>
  <td>Conserver la date de dernière modification de tous les fichiers.</td>
  <td align="center">false</td>
  <td align="center">Non</td>
</tr>
<tr>
  <td>failonerror</td>
  <td>Boolean</td>
  <td>Stopper le processus à la première erreur survenue.</td>
  <td align="center">true</td>
  <td align="center">Non</td>
</tr>
<tr>
  <td>verbose</td>
  <td>Boolean</td>
  <td>Activer le mode verbeu.</td>
  <td align="center">false</td>
  <td align="center">Non</td>
</tr>
<tr>
  <td>encoding</td>
  <td>String</td>
  <td>Préciser l&#8217;encodage du fichier en-tête.</td>
  <td align="center">UTF-8</td>
  <td align="center">Non</td>
</tr>
<tr>
  <td>toencoding</td>
  <td>String</td>
  <td>Préciser l&#8217;encodage des fichiers de destination.</td>
  <td align="center">UTF-8</td>
  <td align="center">Non</td>
</tr>
</tbody>
</table>

<h3 id="eol">Caractères de fin de ligne valides</h3>

<ul>
<li>cr&#160;: un unique CR.</li>
<li>lf&#160;: un unique LF.</li>
<li>crlf&#160;: la paire CRLF.</li>
<li>mac&#160;: un unique CR.</li>
<li>unix&#160;: un unique LF.</li>
<li>dos&#160;: la paire CRLF.</li>
</ul>

<p>La valeur par défaut est dépendante de la plateforme utilisée. Pour les système Unix, le caractère de fin de ligne par défaut est <code>LF</code>. Pour les systèmes de types DOS (incluant Windows), il s&#8217;agit de <code>CRLF</code>. Enfin, <code>CR</code> est la caractère utilisé par défaut sur les systèmes Mac OS.</p>

<h2 id="nested-tags">Tags imbriquées supportées</h2>

<ul>
<li><a href="http://phing.info/docs/guide/current/chapters/appendixes/AppendixD-CoreTypes.html#Fileset" title="Phing Guide - Core Types">FileSet</a>.</li>
</ul>

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

<h3>Ajouter un en-tête à un fichier PHP</h3>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- load the header php task --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;phpheader&quot;</span> <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;phing.tasks.my.header.HeaderPhpTask&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phpheader</span></span>
<span style="color: #009900;">    <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${project.basedir}/LICENSE&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">tofile</span>=<span style="color: #ff0000;">&quot;${project.basedir}/build/foo.php&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phpheader<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<h3>Ajouter un en-tête à un ensemble de fichiers PHP</h3>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- load the header php task --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;phpheader&quot;</span> <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;phing.tasks.my.header.HeaderPhpTask&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;phpheader</span> <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${project.basedir}/LICENSE&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">&quot;${project.basedir}/build&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;**/*.php&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;exclude</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;**/foo*.php&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fileset<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/phpheader<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<h3>Ajouter un en-tête encodé en ISO-8859-1 à un fichier encodé en UTF-8</h3>


<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!-- load the header task --&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;taskdef</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;header&quot;</span> <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">&quot;phing.tasks.my.header.HeaderTask&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;header</span></span>
<span style="color: #009900;">    <span style="color: #000066;">file</span>=<span style="color: #ff0000;">&quot;${project.basedir}/LICENSE&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;ISO-8859-1&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">tofile</span>=<span style="color: #ff0000;">&quot;${project.basedir}/build/foo.txt&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>


<h2 id="licence">Licence</h2>

<p>Copyright (C) 2008 Mehdi Kabab, distribué sous licence <a href="http://www.gnu.org/licenses/lgpl.html" title="GNU Lesser General Public License - GNU Project - Free Software Foundation (FSF)"><abbr title="GNU Lesser Public General License">LGPL</abbr></a> version 3 ou supérieure.</p>

<h2 id="todo">Tâches à faire</h2>

<p>Fonctionnalités en attente de développement.</p>

<ul>
<li>[HeaderPhpTask] Optimiser la détection des tags PHP.</li>
<li>[Projet] Améliorer l&#8217;aspect POO.</li>
</ul>

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

<h3>1.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/ant-bookmarklet-macrodef.html' title='Générer des bookmarklets via Ant'>Générer des bookmarklets via Ant</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><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-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/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 />
<ol>

<li id="fn:1">
<p>nous travaillons par conséquent sur des projets PHP. Cependant, la tâche est utilisable pour tout type de fichier non binaire.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>la tâche <em>Concat</em> n&#8217;est malheureusement pas encore disponible dans Phing.&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:3">
<p>ou directement les fichiers <code>HeaderTask.php</code> et <code>HeaderPhpTask.php</code>. Il vous suffira d&#8217;adapter en conséquence le chemin d&#8217;accès lors de leur déclaration <em>via</em> <code>taskdef</code>.&#160;<a href="#fnref:3" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/phing-header-task.html/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP&#160;: supprimer récursivement un répertoire</title>
		<link>http://pioupioum.fr/developpement/php-spl-supprimer-repertoire-recursif.html</link>
		<comments>http://pioupioum.fr/developpement/php-spl-supprimer-repertoire-recursif.html#comments</comments>
		<pubDate>Fri, 17 Jul 2009 17:47:02 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RecursiveDirectoryIterator]]></category>
		<category><![CDATA[RecursiveIteratorIterator]]></category>
		<category><![CDATA[SPL]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=95</guid>
		<description><![CDATA[Voici une petite fonction pour supprimer un répertoire et toute son arborescence. J&#8217;utilise ici la Standard PHP Library (SPL) et notamment son itérateur RecursiveDirectoryIterator qui permet de traverser récursivement un répertoire.

Il est important de noter l&#8217;utilisation de la constante RecursiveIteratorIterator::CHILD_FIRST. Grâce à elle, l&#8217;itérateur, instance de la classe RecursiveIteratorIterator, va parcourir récursivevement les fichiers des [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Voici une petite fonction pour supprimer un répertoire et toute son arborescence. J&#8217;utilise ici la <a href="http://fr.php.net/spl" title="PHP: SPL - Manual">Standard PHP Library</a> (SPL) et notamment son itérateur <strong>RecursiveDirectoryIterator</strong> qui permet de traverser récursivement un répertoire.</p>

<p>Il est important de noter l&#8217;utilisation de la constante <code>RecursiveIteratorIterator::CHILD_FIRST</code>. Grâce à elle, l&#8217;itérateur, instance de la classe <strong>RecursiveIteratorIterator</strong>, va parcourir récursivevement les fichiers des dossiers. Après avoir supprimés les fichiers, l&#8217;itérateur passe au dossier parent qui pourra être à son tour détruit. En effet, la fonction <a href="http://fr.php.net/manual/fr/function.rmdir.php" title="PHP: rmdir - Manual"><code>rmdir</code></a> ne peut qu&#8217;effacer un dossier vide.
<span id="more-95"></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
</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;">/**
 * Attempts to remove recursively the directory named by dirname.
 *
 * @author Mehdi Kabab &lt;http://pioupioum.fr&gt;
 * @copyright Copyright (C) 2009 Mehdi Kabab
 * @license http://www.gnu.org/licenses/gpl.html  GNU GPL version 3 or later
 *
 * @param string $dirname Path to the directory.
 * @param boolean $followLinks Removes symbolic links if set to TRUE.
 * @return boolean Returns TRUE on success or FALSE on failure.
 * @throws Exception
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> recursive_rmdir<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$followLinks</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: #990000;">is_dir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirname</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_link</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirname</span><span style="color: #009900;">&#41;</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: #990000;">is_writable</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirname</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            throw <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'You do not have renaming permissions!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$iterator</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> RecursiveIteratorIterator<span style="color: #009900;">&#40;</span>
            <span style="color: #000000; font-weight: bold;">new</span> RecursiveDirectoryIterator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirname</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            RecursiveIteratorIterator<span style="color: #339933;">::</span><span style="color: #004000;">CHILD_FIRST</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">valid</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>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isDot</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>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isWritable</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;">'Permission Denied: %s.'</span><span style="color: #339933;">,</span>
                        <span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPathName</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>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isLink</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">===</span> <span style="color: #009900;">&#40;</span>boolean<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$followLinks</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isFile</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>
                    <span style="color: #990000;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPathName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isDir</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>
                    <span style="color: #990000;">rmdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getPathName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
&nbsp;
            <span style="color: #000088;">$iterator</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iterator</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Fix for Windows.</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">rmdir</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dirname</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>
        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;">'Directory %s does not exist!'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dirname</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<p><strong>Mis à jour du 02/08/2009</strong><br />
Suppression de la levée d&#8217;exception sur la suppression du lien symbolique. Le script passe au fichier suivant. Merci à <a href="#comment-21" title="Voir le commentaire">Oncle Tom</a>.</p>

<p><strong>Mis à jour du 03/08/2009</strong><br />
Patch pour Windows. Libération de l&#8217;itérateur qui ferme correctement le répertoire à supprimer. Merci à <a href="#comment-30" title="Voir le commentaire">Yho</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/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-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/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><li><a href='http://pioupioum.fr/snippets/php-valider-url-domaine.html' title='PHP : valider qu&#8217;une URL pointe sur un domaine donné'>PHP&#160;: valider qu&#8217;une URL pointe sur un domaine donné</a></li></ul>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/php-spl-supprimer-repertoire-recursif.html/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Shortcode WordPress&#160;: intégrer un flux RSS</title>
		<link>http://pioupioum.fr/developpement/shortcode-wordpress-integrer-flux-rss.html</link>
		<comments>http://pioupioum.fr/developpement/shortcode-wordpress-integrer-flux-rss.html#comments</comments>
		<pubDate>Fri, 17 Jul 2009 01:02:36 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Développement Web]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[patch]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=70</guid>
		<description><![CDATA[Dans son article Mastering WordPress Shortcodes, Smashing Magazine nous invite dans son 4ème exemple à intégrer le contenu d&#8217;un flux RSS dans vos billets WordPress à l&#8217;aide d&#8217;un shortcode.

Houston, on a un problème

Reprenons le code donné dans l&#8217;article&#160;:


1
2
3
4
5
6
7
8
9
10
11
12
13
//This file is needed to be able to use the wp_rss() function.
include_once&#40;ABSPATH.WPINC.'/rss.php'&#41;;
&#160;
function readRss&#40;$atts&#41; &#123;
    extract&#40;shortcode_atts&#40;array&#40;
 [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>Dans son article <a href="http://www.smashingmagazine.com/2009/02/02/mastering-wordpress-shortcodes/" title="Mastering WordPress Shortcodes | Developer&#039;s Toolbox | Smashing Magazine">Mastering WordPress Shortcodes</a>, <a href="http://www.smashingmagazine.com/" title="Smashing Magazine">Smashing Magazine</a> nous invite dans son 4<sup>ème</sup> exemple à intégrer le contenu d&#8217;un flux <abbr title="Really Simple Syndication">RSS</abbr> dans vos billets <a href="http://www.wordpress-fr.net/" title="WordPress Francophone – La communauté du CMS Opensource">WordPress</a> à l&#8217;aide d&#8217;un <a href="http://codex.wordpress.org/Shortcode_API" title="Shortcode API » WordPress Codex">shortcode</a>.</p>

<h2>Houston, on a un problème</h2>

<p>Reprenons le code donné dans l&#8217;article&#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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//This file is needed to be able to use the wp_rss() function.</span>
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span>ABSPATH<span style="color: #339933;">.</span>WPINC<span style="color: #339933;">.</span><span style="color: #0000ff;">'/rss.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> readRss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&quot;feed&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">&quot;num&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</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> wp_rss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num</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: #0000ff;">'rss'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'readRss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>


<p>Si vous le testez, comme <a href="http://twitter.com/Fran6/status/2671399288" title="sur twitter">@Fran6</a> par exemple, vous constaterez que le résultat n&#8217;est pas celui escompté&#160;: le flux de syndication précède le contenu de votre article au lieu d&#8217;être inséré là où vous l&#8217;attendiez.<span id="more-70"></span></p>

<p>La raison&#160;? À la <code>ligne 10</code>, le résultat de la fonction <code>wp_rss()</code> est retourné au moteur de WordPress pour remplacer le shortcode dans le contenu du billet. Or, la fonction <code>wp_rss()</code> <strong>ne retourne rien</strong> mais <strong>affiche directement</strong> le résultat. Ainsi, tout appel du shortcode entraîne l&#8217;envoi au client du flux <abbr title="Really Simple Syndication">RSS</abbr> (sous la forme d&#8217;une liste non-ordonnée) suivi du contenu du billet.</p>

<h2>Solution</h2>

<p>On corrige le <a href="http://codex.wordpress.org/Shortcode_API" title="Shortcode API » WordPress Codex">shortcode</a> en capturant la sortie de la fonction <code>wp_rss()</code> à l&#8217;aide d&#8217;une <a href="http://fr.php.net/manual/fr/intro.outcontrol.php" title="PHP: Contrôle de l'affichage - Introduction - Manual">tamporisation de sortie</a>.</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//This file is needed to be able to use the wp_rss() function.</span>
<span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span>ABSPATH<span style="color: #339933;">.</span>WPINC<span style="color: #339933;">.</span><span style="color: #0000ff;">'/rss.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> readRss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span>shortcode_atts<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">&quot;feed&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">&quot;num&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    wp_rss<span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #339933;">,</span> <span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #990000;">ob_get_clean</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;
add_shortcode<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rss'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'readRss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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-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/outils-astuces/faille-wordpress-mot-passe-correctif.html' title='Correctif pour la faille WordPress de réinitialisation de mot de passe'>Correctif pour la faille WordPress de réinitialisation de mot de passe</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/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-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></ul>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/developpement/shortcode-wordpress-integrer-flux-rss.html/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
