<?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>labs</title>
	<atom:link href="http://labs.freretuc.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.freretuc.info</link>
	<description>knowloedge is power</description>
	<lastBuildDate>Sun, 01 Jan 2012 11:03:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>liste des codes arrêts de la ville de Strasbourg</title>
		<link>http://labs.freretuc.info/experience/liste-des-codes-arrets-de-la-ville-de-strasbourg/</link>
		<comments>http://labs.freretuc.info/experience/liste-des-codes-arrets-de-la-ville-de-strasbourg/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 11:01:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[opendata]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[csv strasbourg tram bus code arrêt arret]]></category>

		<guid isPermaLink="false">http://labs.freretuc.info/?p=154</guid>
		<description><![CDATA[Parce que ça me sert dans un énorme projet, voici la liste des codes arrêts bus et tram de Strasbourg (format CSV) https://gist.github.com/1546998]]></description>
			<content:encoded><![CDATA[<p>Parce que ça me sert dans un énorme projet, voici la liste des codes arrêts bus et tram de Strasbourg (format CSV) https://gist.github.com/1546998</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.freretuc.info/experience/liste-des-codes-arrets-de-la-ville-de-strasbourg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>plugin et rel=&#160;&#187;me&#160;&#187; [wordpress]</title>
		<link>http://labs.freretuc.info/experience/plugin-et-relme-wordpress/</link>
		<comments>http://labs.freretuc.info/experience/plugin-et-relme-wordpress/#comments</comments>
		<pubDate>Thu, 14 Jul 2011 20:07:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rel]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://labs.freretuc.info/?p=147</guid>
		<description><![CDATA[Je me suis mis assez récemment à faire des plugins sous WordPress dans le cadre du freelance. Développer un plugin c&#8217;est pas mal, il faut avoir des connaissances, comprendre ce que WordPress permet (chaud) et avoir une connexion sur codex.wordpress.com histoire d&#8217;avoir la documentation à portée de main (limite copier toute la doc en local&#8230;) <a href="http://labs.freretuc.info/experience/plugin-et-relme-wordpress/"> lire la suite <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Je me suis mis assez récemment à faire des plugins sous WordPress dans le cadre du freelance. Développer un plugin c&#8217;est pas mal, il faut avoir des connaissances, comprendre ce que WordPress permet (chaud) et avoir une connexion sur codex.wordpress.com histoire d&#8217;avoir la documentation à portée de main (limite copier toute la doc en local&#8230;)</p>
<p>Là je vais vous poster un plugin d&#8217;une page, vous permettant de modifier :<br />
- les données personnelles de l&#8217;utilisateur (du rédacteur), rajouter un champ<br />
- modifier l&#8217;affichage (lors de la récupération) du champ par un autre champ<br />
<span id="more-147"></span> Pour la première partie, il existe 2 possibilités :<br />
- passer par un filtre<br />
- passer par une fonction</p>
<p>Le filtre rajoute le champ là où il est absent :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> add_googleplus_profile<span style="color: #009900;">&#40;</span><span style="color: #000088;">$contactmethods</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$contactmethods</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'google_profile'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Google+ ID'</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$contactmethods</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'user_contactmethods'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_googleplus_profile'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>La seconde doit être exécutée à 2 moments :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'show_user_profile'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'GP_user_profile_fields'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'edit_user_profile'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'GP_user_profile_fields'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> GP_user_profile_fields<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$s</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;h3&gt;Extra profile information&lt;/h3&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;table&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;tr&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;th&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;label for=&quot;google_profile&quot;&gt;Google+ ID&lt;/label&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/th&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;td&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;input type=&quot;text&quot; name=&quot;google_profile&quot; id=&quot;google_profile&quot; value=&quot;'</span><span style="color: #339933;">.</span>get_the_author_meta<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'google_profile'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user</span><span style="color: #339933;">-&amp;</span>gt<span style="color: #339933;">;</span>ID<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; /&gt;&lt;br /&gt;&lt;span&gt;https://plus.google.com/xxx -&amp;gt; only the xxx&lt;/span&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/td&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/tr&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #000088;">$s</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;/table&gt;'</span><span style="color: #339933;">.</span>PHP_EOL<span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$s</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'personal_options_update'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'GP_save_user_profile_fields'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'edit_user_profile_update'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'GP_save_user_profile_fields'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> GP_save_user_profile_fields<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user_id</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>current_user_can<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'edit_user'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_id</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
    update_usermeta<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$user_id</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'google_profile'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'google_profile'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>On remarquera que dans le second cas, il faut penser à enregistrer les modifications du profil (alors que le premier, tout se passe tout seul&#8230;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.freretuc.info/experience/plugin-et-relme-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>le format motorola (SREC, S19) : récupération des données</title>
		<link>http://labs.freretuc.info/experience/le-format-motorola-srec-s19-recuperation-des-donnees/</link>
		<comments>http://labs.freretuc.info/experience/le-format-motorola-srec-s19-recuperation-des-donnees/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 17:00:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[adresse]]></category>
		<category><![CDATA[controleur]]></category>
		<category><![CDATA[données]]></category>
		<category><![CDATA[motorola]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[S-Record]]></category>
		<category><![CDATA[S19]]></category>
		<category><![CDATA[SREC]]></category>
		<category><![CDATA[trame]]></category>

		<guid isPermaLink="false">http://labs.freretuc.info/?p=134</guid>
		<description><![CDATA[Pour mon boulot, une grande partie des données utiles sont dans des fichiers au format motorola (wikipedia). Une belle jambe me direz vous. Le problème rencontré chez nous est de pouvoir vérifier rapidement les différences entre deux fichiers. Un simple coup de diff ne suffit pas. En effet, les données dans le fichier sont positionnées <a href="http://labs.freretuc.info/experience/le-format-motorola-srec-s19-recuperation-des-donnees/"> lire la suite <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Pour mon boulot, une grande partie des données utiles sont dans des fichiers au format <a href="http://fr.wikipedia.org/wiki/S-Record" target="_blank">motorola</a> (wikipedia).</p>
<p>Une belle jambe me direz vous. Le problème rencontré chez nous est de pouvoir vérifier rapidement les différences entre deux fichiers.</p>
<p><span id="more-134"></span></p>
<p>Un simple coup de diff ne suffit pas. En effet, les données dans le fichier sont positionnées par adresses mémoire, et le format de la ligne peut varier (longueur de la ligne, quantité de données). Cette solution n&#8217;est donc pas à retenir.</p>
<p>Il faut donc reconstruire les valeurs mémoires des deux fichiers et de les comparer. Un tableau, avec comme index les adresses, peut faire ça, mais une chaine c&#8217;est encore plus simple et le tout en php.</p>
<p>Ici, nous ne nous intéresserons qu&#8217;aux trames ayant un format S2, les autres ne seront pas utilisées.</p>
<p>Le but est de lire le fichier de données, lignes par ligne. Si une ligne commence par S2, on traite, sinon ligne suivante.</p>
<p>On récupère la première adresse et on la garde dans une variable.</p>
<p>On récupère les données utiles de la ligne et on compte l&#8217;adresse suivante. Si, à la ligne suivante, l&#8217;adresse est identique, alors c&#8217;est qu&#8217;il n&#8217;y a pas de &laquo;&nbsp;trous&nbsp;&raquo; dans le source, sinon on complète (par des -). De même, nous allons vérifier que les longueurs annoncées dans l&#8217;entête de la trame S2 sont conformes (mais on ne traitera pas du CRC).</p>
<p>Une fois les 2 fichiers lus, on s&#8217;assure que les 2 adresses de départ soient identiques, sinon on a déjà un problème à cet endroit; puis on compare, octet par octet, que le contenu de la zone est strictement similaire.</p>
<p>La source complète pourrait être celle ci</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.freretuc.info/experience/le-format-motorola-srec-s19-recuperation-des-donnees/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[php] classe MySQL PDO singelton</title>
		<link>http://labs.freretuc.info/experience/php-classe-mysql-pdo-singelton/</link>
		<comments>http://labs.freretuc.info/experience/php-classe-mysql-pdo-singelton/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 10:31:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[pdo]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://labs.freretuc.info/?p=126</guid>
		<description><![CDATA[&#171;&#160;singleton&#160;&#187; est un patron de conception (design pattern) dont l&#8217;objet est de restreindre l&#8217;instanciation d&#8217;une classe à un seul objet ou bien à quelques objets seulement (wikipedia). Dans une structure web assez complexe, il peut être grandement utile de regrouper les éléments, comme déclarer qu&#8217;une seule fois une connexion à une base de données&#8230; En utilisant <a href="http://labs.freretuc.info/experience/php-classe-mysql-pdo-singelton/"> lire la suite <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>&laquo;&nbsp;singleton&nbsp;&raquo; est un patron de conception <em>(design pattern)</em> dont l&#8217;objet est de restreindre l&#8217;instanciation d&#8217;une classe à un seul objet ou bien à quelques objets seulement (<a href="http://fr.wikipedia.org/wiki/Singleton_(patron_de_conception)" target="_blank">wikipedia</a>).</p>
<p>Dans une structure web assez complexe, il peut être grandement utile de regrouper les éléments, comme déclarer qu&#8217;une seule fois une connexion à une base de données&#8230; En utilisant mysql_connect, aucun problème, par contre, avec PDO, c&#8217;est une autre histoire.</p>
<p><span id="more-126"></span>Dans la réalité, avec PDO, il n&#8217;est pas possible de déclarer la connexion à la base dans un fichier et de faire un include de ce fichier.</p>
<p>L&#8217;objet, et c&#8217;est bien là la différence avec la fonction mysql_connect, ne fonctionne plus. Il faut donc passer par une classe singleton : la classe va définir l&#8217;objet une première fois, puis, à chaque fois qu&#8217;on en aura besoin, au lieu de re-créer l&#8217;objet, elle réutilisera l&#8217;instance précédemment utilisée.<br />
En php, avec PDO, une telle classe peut être définie de la manière suivante :</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ServeurMySQL <span style="color: #000000; font-weight: bold;">extends</span> PDO <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// variable interne</span>
    <span style="color: #000000; font-weight: bold;">private</span> static <span style="color: #000088;">$_instance</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// fonction de construction</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// fonction de clonage</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> __clone <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// récupération de l'instance courante</span>
    <span style="color: #666666; font-style: italic;">// ou création d'une nouvelle si non existante</span>
    <span style="color: #000000; font-weight: bold;">public</span> static <span style="color: #000000; font-weight: bold;">function</span> getInstance <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$_instance</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
            <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$_instance</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PDO<span style="color: #009900;">&#40;</span>DB_CONN<span style="color: #339933;">,</span> DB_USER<span style="color: #339933;">,</span> DB_PASS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$_instance</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Bien sûr, on utilisera un define() pour définir les informations de connexion dans un autre fichier.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.freretuc.info/experience/php-classe-mysql-pdo-singelton/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[php] datamatrix avec php_zint</title>
		<link>http://labs.freretuc.info/experience/php-datamatrix-avec-php_zint/</link>
		<comments>http://labs.freretuc.info/experience/php-datamatrix-avec-php_zint/#comments</comments>
		<pubDate>Sat, 26 Mar 2011 12:08:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[data matrix]]></category>
		<category><![CDATA[aztec]]></category>
		<category><![CDATA[datamatrix]]></category>
		<category><![CDATA[pdf417]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://labs.freretuc.info/?p=16</guid>
		<description><![CDATA[Pour générer des datamatix, une bibliothèque qui peut faire ça c&#8217;est bien, la trouver libre c&#8217;est mieux. Pour php j&#8217;ai trouvé php_zint. Le mieux est de la récupérer et de la compiler soit même pour le système. Il faut d&#8217;abord récupérer le programme parent zint. On extrait le tout et puis un petit coup de apt-get <a href="http://labs.freretuc.info/experience/php-datamatrix-avec-php_zint/"> lire la suite <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Pour générer des datamatix, une bibliothèque qui peut faire ça c&#8217;est bien, la trouver libre c&#8217;est mieux. Pour php j&#8217;ai trouvé <a title="php_zint" href="http://dev.naver.com/projects/phpzint/" target="_blank">php_zint</a>.</p>
<p><span id="more-16"></span>Le mieux est de la récupérer et de la compiler soit même pour le système. Il faut d&#8217;abord récupérer le programme parent <a href="http://sourceforge.net/projects/zint/">zint</a>. On extrait le tout et puis un petit coup de</p>
<blockquote><p>apt-get install make cmake gcc g++<br />
cmake CMakeLists.txt<br />
make<br />
make install</p></blockquote>
<p>Maintenant on va dans le dossier de l&#8217;extension php :</p>
<blockquote><p>phpize<br />
./configure<br />
make<br />
make install</p></blockquote>
<p>Pour finir : on rajoute l&#8217;extension phpzint.so dans php.ini et un apache2 restart et on peut tester.</p>
<blockquote><p>&lt;?<br />
zint_imagepng(&laquo;&nbsp;-o bar01.png -b 1 &#8211;height=50 &#8211;border=10 -d 87654321 &#8211;out=file&nbsp;&raquo;);<br />
?&gt;</p></blockquote>
<p>Paramètres</p>
<p>-o, &#8211;output=FILE Write image to FILE. (default is out.png)<br />
-d, &#8211;data=DATA Barcode content.<br />
-b, &#8211;barcode=NUMBER Number of barcode type (default is 20 (=Code128))<br />
&#8211;height=NUMBER Height of symbol in multiples of x-dimension<br />
-w, &#8211;whitesp=NUMBER Width of whitespace in multiples of x-dimension<br />
&#8211;border=NUMBER Width of border in multiples of x-dimension<br />
&#8211;box Add a box<br />
&#8211;bind Add boundary bars<br />
-r, &#8211;reverse Reverse colours (white on black)<br />
&#8211;fg=COLOUR Specify a foreground colour<br />
&#8211;bg=COLOUR Specify a background colour<br />
&#8211;scale=NUMBER Adjust size of output image<br />
&#8211;rotate=NUMBER Rotate symbol (PNG output only)<br />
&#8211;cols=NUMBER (PDF417) Number of columns<br />
&#8211;vers=NUMBER (QR Code) Version<br />
&#8211;secure=NUMBER (PDF417 and QR Code) Error correction level<br />
&#8211;primary=STRING (Maxicode and Composite) Structured primary message<br />
&#8211;mode=NUMBER (Maxicode and Composite) Set encoding mode<br />
&#8211;gs1 Treat input as GS1 data<br />
&#8211;binary Treat input as Binary data<br />
&#8211;notext Remove human readable text<br />
&#8211;square Force Data Matrix symbols to be square<br />
&#8211;out=[file,print,return], default:print</p>
<p>Pour la liste des codes qui peuvent être générés</p>
<ul>
<li>1	Code 11</li>
<li>2	Standard Code 2 of 5</li>
<li>3	Interleaved 2 of 5</li>
<li>4	Code 2 of 5 IATA</li>
<li>6	Code 2 of 5 Data Logic</li>
<li>7	Code 2 of 5 Industrial</li>
<li>8	Code 3 of 9 (Code 39)</li>
<li>9	Extended Code 3 of 9 (Code 39+)</li>
<li>13	EAN</li>
<li>16	GS1-12818	Codabar</li>
<li>20	Code 128 (automatic subset switching)</li>
<li>21	Deutshe Post Leitcode</li>
<li>22	Deutshe Post Identcode</li>
<li>23	Code 16K</li>
<li>24	Code 49</li>
<li>25	Code 93</li>
<li>28	Flattermarken</li>
<li>29	GS1 DataBar-14</li>
<li>30	GS1 DataBar Limited</li>
<li>31	GS1 DataBar Expanded</li>
<li>32	Telepen Alpha</li>
<li>34	UPC A</li>
<li>37	UPC E</li>
<li>40	PostNet</li>
<li>47	MSI Plessey</li>
<li>49	FIM</li>
<li>50	LOGMARS</li>
<li>51	Pharmacode One-Track</li>
<li>52	PZN</li>
<li>53	Pharmacode Two-Track</li>
<li>55	PDF417</li>
<li>56	PDF417 Truncated</li>
<li>57	Maxicode</li>
<li>58	QR Code60	Code 128 (Subset B)</li>
<li>63	Australia Post Standard Customer</li>
<li>66	Australia Post Reply Paid</li>
<li>67	Australia Post Routing</li>
<li>68	Australia Post Redirection</li>
<li>69	ISBN (EAN-13 with verification stage)</li>
<li>70	Royal Mail 4 State (RM4SCC)</li>
<li>71	Data Matrix</li>
<li>72	EAN-14</li>
<li>75	NVE-18</li>
<li>76	Japanese Post</li>
<li>77	Korea Post</li>
<li>79	GS1 DataBar-14 Stacked</li>
<li>80	GS1 DataBar-14 Stacked Omnidirectional</li>
<li>81	GS1 DataBar Expanded Stacked</li>
<li>82	PLANET</li>
<li>84	MicroPDF417</li>
<li>85	USPS OneCode</li>
<li>86	Plessey Code</li>
<li>87	Telepen Numeric</li>
<li>89	ITF-14</li>
<li>90	Dutch Post KIX Code</li>
<li>92	Aztec Code</li>
<li>93	DAFT Code</li>
<li>97	Micro QR Code</li>
<li>98	HIBC Code 128</li>
<li>99	HIBC Code 39</li>
<li>102	HIBC Data Matrix</li>
<li>104	HIBC QR Code</li>
<li>106	HIBC PDF417</li>
<li>108	HIBC MicroPDF417</li>
<li>112	HIBC Aztec Code</li>
<li>128	Aztec Runes</li>
<li>129	Code 32</li>
<li>130	Composite Symbol with EAN linear component</li>
<li>131	Composite Symbol with GS1-128 linear component</li>
<li>132	Composite Symbol with GS1 DataBar-14 linear component</li>
<li>133	Composite Symbol with GS1 DataBar Limited component</li>
<li>134	Composite Symbol with GS1 DataBar Extended component</li>
<li>135	Composite Symbol with UPC A linear component</li>
<li>136	Composite Symbol with UPC E linear component</li>
<li>137	Composite Symbol with GS1 DataBar-14 Stacked component</li>
<li>138	Composite Symbol with GS1 DataBar-14 Stacked Omnidirectional component</li>
<li>139	Composite Symbol with GS1 DataBar Expanded Stacked component</li>
<li>140	Channel Code</li>
<li>141	Code One</li>
<li>142	Grid Matrix</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.freretuc.info/experience/php-datamatrix-avec-php_zint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[php] gérer facilement ses utilisateurs</title>
		<link>http://labs.freretuc.info/experience/php-gerer-facilement-ses-utilisateurs/</link>
		<comments>http://labs.freretuc.info/experience/php-gerer-facilement-ses-utilisateurs/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 12:13:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[utilisateurs]]></category>

		<guid isPermaLink="false">http://codex.echap.net/?p=89</guid>
		<description><![CDATA[Pour gérer facilement des utilisateurs pour un acces à un portail (ou à un site), il y a plusieurs possibilités, dont les fichiers htaccess ou les utilisateurs enregistrés dans une base de données. Pour ce qui est des utilisateurs dans un .htaccess (couplé à un .htpasswd), la solution est robuste mais comporte des inconvéniants : <a href="http://labs.freretuc.info/experience/php-gerer-facilement-ses-utilisateurs/"> lire la suite <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Pour gérer facilement des utilisateurs pour un acces à un portail (ou à un site), il y a plusieurs possibilités, dont les fichiers htaccess ou les utilisateurs enregistrés dans une base de données.<br />
<span id="more-89"></span></p>
<p>Pour ce qui est des utilisateurs dans un .htaccess (couplé à un .htpasswd), la solution est robuste mais comporte des inconvéniants :</p>
<li>il n&#8217;y a pas de &laquo;&nbsp;niveau&nbsp;&raquo; d&#8217;utilisateurs, tout le monde identifié a les mêmes droits</li>
<li>quand on ferme le navigateur, on ferme également la session</li>
<p>D&#8217;un point de vue php, l&#8217;idée est identique, sauf que là on peut gérer les &laquo;&nbsp;niveau&nbsp;&raquo; d&#8217;utilisateurs ou encore enregistrer une session pour une utilisation future.</p>
<p>Le php/mysql est donc une solution à envisager.</p>
<p>Maintenant, la sauvegarde des mots de passe est quelque chose de complexe : il ne faut jamais le stocker en clair et jamais avec un algorithme qui peut le deviner (exemple : le base64 est à déconseiller).</p>
<p>md5 est pas mal, même si certains disent qu&#8217;il est vulnérable (ce qui est vrai) ou encore le sha1 (grandement utile pour les cas courants). Il est aussi possible d&#8217;utiliser le AES-256 ou d&#8217;autres encryptions plus approfondies.</p>
<p>Il ne faut pas stocker le mot de passe encrypté seul, il est conseillé d&#8217;utiliser le couple md5($email.$mdp) ou sha1($email.$mdp). Cela permet de limiter les injection SQL dans le formulaire et de bien vérifier que c&#8217;est l&#8217;interaction de ces 2 champs qui est utilisé.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.freretuc.info/experience/php-gerer-facilement-ses-utilisateurs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sncf &amp; data matrix</title>
		<link>http://labs.freretuc.info/experience/sncf-data-matrix/</link>
		<comments>http://labs.freretuc.info/experience/sncf-data-matrix/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 09:58:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[data matrix]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[aztec]]></category>
		<category><![CDATA[datamatrix]]></category>
		<category><![CDATA[pdf417]]></category>
		<category><![CDATA[sncf]]></category>
		<category><![CDATA[voyage]]></category>

		<guid isPermaLink="false">http://labs.freretuc.info/?p=7</guid>
		<description><![CDATA[Vous avez sans doute déjà remarqué la formidable avancée de la SNCF en matière de data matrix, ces petits carrés noirs et blancs juxtaposés pour former des dessins bizarres&#8230; Il en existait une sorte à la SNCF, le pdf417, depuis quelques années, puis est venu le e-billet le le code Aztec. Alors vous allez me dire, ok c&#8217;est <a href="http://labs.freretuc.info/experience/sncf-data-matrix/"> lire la suite <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Vous avez sans doute déjà remarqué la formidable avancée de la SNCF en matière de data matrix, ces petits carrés noirs et blancs juxtaposés pour former des dessins bizarres&#8230;</p>
<p>Il en existait une sorte à la SNCF, le pdf417, depuis quelques années, puis est venu le e-billet le le code Aztec. Alors vous allez me dire, ok c&#8217;est beau mais à quoi ça sert ? Ca sert à automatiser les contrôles et les échanges de billets.</p>
<p><span id="more-7"></span></p>
<p>Je m&#8217;explique : pour les billets standards (en carton), le pdf417 est encore inscrit, il contient des informations (voir plus bas) sur votre voyage notamment. Lors d&#8217;un échange, le code pdf417 est lu (et j&#8217;espère que la piste magnétique sert encore) et permet de retrouver rapidement votre dossier. L&#8217;avantage, c&#8217;est que vous aussi pouvez lire ce qui est indiqué dessus.</p>
<p>Pour le e-billet, c&#8217;est différent, la SNCF vous laisse le soin de l&#8217;imprimer vous même et le code Aztec contient lui aussi des informations.</p>
<p>Une fois que vous avez votre billet, vous pouvez monter dans le train avec une pièce d&#8217;identité et hop, vous confirmez votre voyage.</p>
<p>Je me suis posé 2 questions : qu&#8217;est ce qu&#8217;il y a dans le code et comment était validé un e-billet auprès d&#8217;un contrôleur (il y a t il une vérification &laquo;&nbsp;online&nbsp;&raquo; de l&#8217;état de la commande par exemple) ? Alors pour le contenu c&#8217;est en dessous, et pour le contrôle : il n&#8217;y en a aucun. Le contrôleur doit juste vérifier que les informations du code Aztec correspondent à votre identité (et que le numéro du train correspond à celui ci), pour le reste, aucune vérification rapide n&#8217;est possible.</p>
<p>Pour le contenu, à la lecture, il est le suivant (il n&#8217;y a pas d&#8217;espaces, c&#8217;est juste pour améliorer la lecture):</p>
<p><!-- p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Helvetica} --><strong>i0CV aaaaaa bbbbbbbbb cccc dd/dd/dddd eeeee fffff ggggg hh/hh iiiiiiiiiiiiiiiiiii jjjjjjjjjjjjjjjjjjj kkkkkkkkkkkkkkkkkkk l mmmm n ooooo ppppp qqqqq</strong></p>
<p>ça vous fait une belle jambe hein :p</p>
<p>Décomposons tout ça :</p>
<ul>
<li><strong>ioCV</strong> : c&#8217;est l&#8217;entête, le début du code (une identification pour la SNCF ?)</li>
<li><strong>aaa</strong> (6 caractères) : votre numéro de dossier</li>
<li><strong>bbb</strong> (9 caractères) : le numéro de votre e-billet</li>
<li><strong>ccc</strong> (4 caractères) : aucune idée, possiblement une date (mm/yy)</li>
<li><strong>ddd</strong> (8 caractères) : votre date de naissance au format jj/mm/aaaa</li>
<li><strong>eee</strong> et <strong>fff</strong> (5 caractères chacuns) : votre gare de départ et d&#8217;arrivée, du premier train, au format SNCF : FRPNO pour Paris Gare du Nord, FRPST pour Paris Gare de l&#8217;Est&#8230;</li>
<li><strong>ggg</strong> (5 caractères) : le numéro de votre premier train sur 5 caractères (avec des 0 devant si le numéro est plus court).</li>
<li><strong>hhh</strong> (4 caractères) : la date de votre voyage (jj/mm)</li>
<li> <strong>iii</strong> (19 caractères) : votre numéro de carte de réduction (référence client)</li>
<li><strong>jjj</strong> (19 caractères) : votre nom, en majuscule, aligné à droite, avec des espaces avant pour combler le vide</li>
<li><strong>kkk</strong> (19 caractères) : votre prénom, affichage identique au nom</li>
<li><strong>l</strong> (1 caractère) : la classe de voyage du premier train (1ère ou 2ème)</li>
<li><strong>mmm</strong> (4 caractères) : votre carte de réduction si vous en avez une (CJ11 pour une carte 12/25 ans par exemple)</li>
<li><strong>n</strong> (1 caractère) : la classe pour le second train</li>
<li><strong>ooo</strong> et <strong>ppp</strong> (5 caractères) : la gare de départ et d&#8217;arrivée pour la seconde partie du trajet</li>
<li><strong>qqq</strong> (5 caractères) : le numéro du train pour la seconde partie du trajet</li>
</ul>
<p>Si vous n&#8217;avez qu&#8217;un voyage : <strong>n</strong> vaut 0, <strong>ooo</strong> et <strong>ppp</strong> sont des espaces (10 caractères), <strong>qqq</strong> est nul (0 sur 5 caractères)</p>
<p>Dans l&#8217;idée, que je n&#8217;encourage pas mais qui reste du domaine du possible, si vous maitrisez photoshop, il vous est possible de faire votre propre billet de train&#8230; mais là n&#8217;est pas le but.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.freretuc.info/experience/sncf-data-matrix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[iPhone] créer un message d&#8217;alerte</title>
		<link>http://labs.freretuc.info/experience/iphone-creer-un-message-dalerte/</link>
		<comments>http://labs.freretuc.info/experience/iphone-creer-un-message-dalerte/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 09:49:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://codex.echap.net/?p=85</guid>
		<description><![CDATA[UIAlertView *alert = &#91;&#91;UIAlertView alloc&#93; initWithTitle:@&#34;Titre&#34; message:@&#34;Message&#34; delegate:self cancelButtonTitle:@&#34;Ok&#34; otherButtonTitles:nil&#93;; &#91;alert show&#93;; &#91;alert release&#93;;]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;">UIAlertView <span style="color: #002200;">*</span>alert <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>UIAlertView alloc<span style="color: #002200;">&#93;</span>
	initWithTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Titre&quot;</span>
	message<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Message&quot;</span>
	delegate<span style="color: #002200;">:</span>self cancelButtonTitle<span style="color: #002200;">:</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Ok&quot;</span> otherButtonTitles<span style="color: #002200;">:</span><span style="color: #a61390;">nil</span><span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>alert show<span style="color: #002200;">&#93;</span>;
<span style="color: #002200;">&#91;</span>alert release<span style="color: #002200;">&#93;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://labs.freretuc.info/experience/iphone-creer-un-message-dalerte/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[iPhone] récupérer le DeviceID</title>
		<link>http://labs.freretuc.info/experience/iphone-recuperer-le-deviceid/</link>
		<comments>http://labs.freretuc.info/experience/iphone-recuperer-le-deviceid/#comments</comments>
		<pubDate>Sun, 13 Jun 2010 09:43:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[DeviceID]]></category>

		<guid isPermaLink="false">http://codex.echap.net/?p=80</guid>
		<description><![CDATA[Dans une fonction 1 2 UIDevice *myDevice = &#91;UIDevice currentDevice&#93;; NSString *deviceUDID = &#91;myDevice uniqueIdentifier&#93;;]]></description>
			<content:encoded><![CDATA[<p>Dans une fonction</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="objc" style="font-family:monospace;">UIDevice <span style="color: #002200;">*</span>myDevice <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>UIDevice currentDevice<span style="color: #002200;">&#93;</span>;
<span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>deviceUDID <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>myDevice uniqueIdentifier<span style="color: #002200;">&#93;</span>;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://labs.freretuc.info/experience/iphone-recuperer-le-deviceid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[php sql] trouver les POI dans un rayon donné autour d&#8217;un point&#8230;</title>
		<link>http://labs.freretuc.info/experience/trouver-les-poi-dans-un-rayon-donne-autour-dun-point/</link>
		<comments>http://labs.freretuc.info/experience/trouver-les-poi-dans-un-rayon-donne-autour-dun-point/#comments</comments>
		<pubDate>Sun, 30 May 2010 21:05:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[géolocalisation]]></category>
		<category><![CDATA[reverse engineering]]></category>
		<category><![CDATA[Haversine]]></category>
		<category><![CDATA[localisation]]></category>
		<category><![CDATA[maps]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[poi]]></category>
		<category><![CDATA[points]]></category>

		<guid isPermaLink="false">http://codex.echap.net/?p=74</guid>
		<description><![CDATA[Vous avez une carte, un point sur cette carte, des POI (points d&#8217;intérêt) rangés dans une base de données. Comment faire pour trouver tous les points d&#8217;intérêts dans une distance de x km autour du point ? Facile, on utilise la formule de Haversine ! On va utiliser une SQL pour faire la recherche finale, <a href="http://labs.freretuc.info/experience/trouver-les-poi-dans-un-rayon-donne-autour-dun-point/"> lire la suite <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Vous avez une carte, un point sur cette carte, des POI (points d&#8217;intérêt) rangés dans une base de données. Comment faire pour trouver tous les points d&#8217;intérêts dans une distance de x km autour du point ?</p>
<p>Facile, on utilise la formule de <a href="http://en.wikipedia.org/wiki/Haversine_formula">Haversine</a> !<br />
<span id="more-74"></span></p>
<p>On va utiliser une SQL pour faire la recherche finale, mais on va d&#8217;abord décortiquer la formule en php.</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;">// la formule calcule la distance entre 2 points</span>
<span style="color: #000000; font-weight: bold;">function</span> Haversine<span style="color: #009900;">&#40;</span><span style="color: #000088;">$p1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$p2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// $p1['lat'], $p1['lon'], $p2['lat'], $p2['lon']</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// le rayon de la terre : 6371 km ou 3960 Miles</span>
        <span style="color: #000088;">$ray</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">6371</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// le delta des distances</span>
        <span style="color: #000088;">$dlat</span> <span style="color: #339933;">=</span> <span style="color: #990000;">deg2rad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p2</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lat'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$p1</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lat'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$dlon</span> <span style="color: #339933;">=</span> <span style="color: #990000;">deg2rad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p2</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lon'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$p1</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lon'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$calc</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dlat</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #990000;">sin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dlat</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #990000;">cos</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">deg2rad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p1</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lat'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #990000;">cos</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">deg2rad</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$p2</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lat'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #990000;">sin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dlon</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #990000;">sin</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dlon</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// on multiplie par le rayon de la terre et on obtient le rayon dans l'unité voulue.</span>
        <span style="color: #b1b100;">return</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span> <span style="color: #339933;">*</span> <span style="color: #990000;">asin</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">sqrt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$calc</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: #000088;">$ray</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Bon, maintenant avec MySQL</p>
<p>Tout d&#8217;abord, il nous faut une base avec &laquo;&nbsp;id&nbsp;&raquo;, &laquo;&nbsp;lat&nbsp;&raquo;, &laquo;&nbsp;lon&nbsp;&raquo;, &laquo;&nbsp;poi&nbsp;&raquo;<br />
&laquo;&nbsp;id&nbsp;&raquo; représente l&#8217;id unique de la base, &laquo;&nbsp;lat&nbsp;&raquo; et &laquo;&nbsp;lon&nbsp;&raquo; les coordonnées des poi en FLOAT et &laquo;&nbsp;poi&nbsp;&raquo; du texte par exemple pour identifier votre POI. Rien ne vous empêche de rajouter des éléments.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span>  <span style="color: #ff0000;">`labs`</span><span style="color: #66cc66;">.</span><span style="color: #ff0000;">`liste`</span> <span style="color: #66cc66;">&#40;</span>
	<span style="color: #ff0000;">`id`</span> <span style="color: #993333; font-weight: bold;">BIGINT</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span> <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">,</span>
	<span style="color: #ff0000;">`lat`</span> <span style="color: #993333; font-weight: bold;">FLOAT</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
	<span style="color: #ff0000;">`lon`</span> <span style="color: #993333; font-weight: bold;">FLOAT</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">6</span><span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">6</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #66cc66;">,</span>
	<span style="color: #ff0000;">`poi`</span> <span style="color: #993333; font-weight: bold;">VARCHAR</span><span style="color: #66cc66;">&#40;</span> <span style="color: #cc66cc;">40</span> <span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>
<span style="color: #66cc66;">&#41;</span> ENGINE <span style="color: #66cc66;">=</span> MYISAM <span style="color: #993333; font-weight: bold;">CHARACTER</span> <span style="color: #993333; font-weight: bold;">SET</span> utf8 <span style="color: #993333; font-weight: bold;">COLLATE</span> utf8_unicode_ci</pre></td></tr></table></div>

<p>pour la requête qui va bien, on va utiliser &laquo;&nbsp;plat&nbsp;&raquo; et &laquo;&nbsp;plon&nbsp;&raquo; pour les coordonnées du centre de notre cercle et &laquo;&nbsp;dist&nbsp;&raquo; pour la distance cherchée (en km) et limiter le nombre des résultats aux 20 premiers les plus proches.</p>
<p>On déclare donc une variable &laquo;&nbsp;distance&nbsp;&raquo; virtuelle qui va contenir la distance en km calculée avec les coordonnées de notre point central et chaque POI.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> id<span style="color: #66cc66;">,</span> lat<span style="color: #66cc66;">,</span> lng<span style="color: #66cc66;">,</span> poi<span style="color: #66cc66;">,</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">6371</span> <span style="color: #66cc66;">*</span> acos<span style="color: #66cc66;">&#40;</span>cos<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>plat<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> cos<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>lat<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> cos<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>lng<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">-</span> radians<span style="color: #66cc66;">&#40;</span>plon<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">+</span> sin<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>plat<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> sin<span style="color: #66cc66;">&#40;</span>radians<span style="color: #66cc66;">&#40;</span>lat<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">AS</span> distance <span style="color: #993333; font-weight: bold;">FROM</span> locations <span style="color: #993333; font-weight: bold;">HAVING</span> distance <span style="color: #66cc66;">&lt;</span> dist <span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> distance <span style="color: #993333; font-weight: bold;">LIMIT</span> <span style="color: #cc66cc;">0</span> <span style="color: #66cc66;">,</span> <span style="color: #cc66cc;">20</span>;</pre></td></tr></table></div>

<p>Il ne vous reste plus qu&#8217;a prendre chaque &laquo;&nbsp;lat&nbsp;&raquo; et chaque &laquo;&nbsp;lon&nbsp;&raquo; de chaque POI pour l&#8217;afficher sur la carte et le tour est joué !</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.freretuc.info/experience/trouver-les-poi-dans-un-rayon-donne-autour-dun-point/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

