<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>znBlog v4.0 - PHP</title>
    <link>http://znblog.athoim.com/</link>
    <description>Hielo en la Red</description>
    <dc:language>es</dc:language>
    <generator>Serendipity 1.3.1 - http://www.s9y.org/</generator>
    <pubDate>Sat, 23 Feb 2008 21:46:16 GMT</pubDate>

    <image>
        <url>img/rss_big.png</url>
        <title>RSS: znBlog v4.0 - PHP - Hielo en la Red</title>
        <link>http://znblog.athoim.com/</link>
        <width>128</width>
        <height>128</height>
    </image>

<item>
    <title>Serendipity Atom Bug</title>
    <link>http://znblog.athoim.com/archives/61-Serendipity-Atom-Bug.html</link>
            <category>PHP</category>
    
    <comments>http://znblog.athoim.com/archives/61-Serendipity-Atom-Bug.html#comments</comments>
    <wfw:comment>http://znblog.athoim.com/wfwcomment.php?cid=61</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://znblog.athoim.com/rss.php?version=2.0&amp;type=comments&amp;cid=61</wfw:commentRss>
    

    <author>nospam@example.com (th1nk3r)</author>
    <content:encoded>
    Parece ser que el creador de feeds Atom del serendipity tiene unos cuantos bugs. Tengo que mirarlo más en profundidad, pero si podéis procurad usar el RSS2.0 en vez del ATOM, por lo que he comprobado funciona mejor y da menos problemas. &lt;img src=&quot;http://znblog.athoim.com/templates/znblue/img/emoticons/drop.gif&quot; alt=&quot;:drop:&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;  
    </content:encoded>

    <pubDate>Sat, 23 Feb 2008 16:46:16 -0500</pubDate>
    <guid isPermaLink="false">http://znblog.athoim.com/archives/61-guid.html</guid>
    
</item>
<item>
    <title>Serendipity plugin bug</title>
    <link>http://znblog.athoim.com/archives/59-Serendipity-plugin-bug.html</link>
            <category>PHP</category>
    
    <comments>http://znblog.athoim.com/archives/59-Serendipity-plugin-bug.html#comments</comments>
    <wfw:comment>http://znblog.athoim.com/wfwcomment.php?cid=59</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://znblog.athoim.com/rss.php?version=2.0&amp;type=comments&amp;cid=59</wfw:commentRss>
    

    <author>nospam@example.com (th1nk3r)</author>
    <content:encoded>
    Como algún lector perspicaz habrá visto en las últimas horas, el blog ha salido con un bug. No se mostraban correctamente los enlaces para ver la entrada anterior y la siguiente.&lt;br /&gt;
&lt;br /&gt;
Para los que no conozcan &lt;a href=&quot;http://www.s9y.org&quot; title=&quot;Serendipity&quot;&gt;serendipity&lt;/a&gt;, les diré que casi todo en este CMS funciona mediante plugins. Es una de las cosas que me gusta de él, ya que a diferencia de otros &lt;a href=&quot;http://wordpress.org/&quot; title=&quot;Wordpress&quot;&gt;CMSs&lt;/a&gt; más prepotentes y caprichosos, no toma decisiones por ti. Si quieres un editor WYSIWYG puedes elegir entre 3 o 4, y si no quieres uno de esos bichos, pues lo descartas.&lt;br /&gt;
&lt;br /&gt;
La funcionalidad para mostrar el link que te permite pasar a la entrada anterior y la siguiente también es un plugin, en este caso: &lt;strong&gt;serendipity_event_entrypaging&lt;/strong&gt;. El bug que impedía pasar al post siguiente venía de la consulta a la base de datos y la diferencia horaria con el servidor (&lt;em&gt;+9 horas&lt;/em&gt;). En lugar de sumar 9 horas a la hora del servidor, las restaba.&lt;br /&gt;
&lt;br /&gt;
Si usáis serendipity y sufrís el mismo problema, revisad el fichero &lt;em&gt;serendipity_event_entrypaging.php&lt;/em&gt;, buscad la definición de la función &lt;strong&gt;timeOffset&lt;/strong&gt; y quitad el &lt;em&gt;true&lt;/em&gt; de la llamada a la función &lt;em&gt;serendipity_serverOffsetHour&lt;/em&gt;. Ese valor booleano define si se debe aplicar un offset negativo o no al tiempo. No se porque extraño motivo los creadores del plugin querían aplicar un tiempo negativo al offset, ya que con configurar la variable a &quot;-9&quot; el cambio estaría hecho.&lt;br /&gt;
&lt;br /&gt;
La nueva función quedará de esta forma.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;geshiCode&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt; timeOffset&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$timestamp&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/function_exists&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;function_exists&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;serendipity_serverOffsetHour&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; serendipity_serverOffsetHour&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$timestamp&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: #0000ff;&quot;&gt;$timestamp&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;  
    </content:encoded>

    <pubDate>Fri, 22 Feb 2008 04:42:17 -0500</pubDate>
    <guid isPermaLink="false">http://znblog.athoim.com/archives/59-guid.html</guid>
    
</item>
<item>
    <title>firma.php v2.0</title>
    <link>http://znblog.athoim.com/archives/30-firma.php-v2.0.html</link>
            <category>PHP</category>
    
    <comments>http://znblog.athoim.com/archives/30-firma.php-v2.0.html#comments</comments>
    <wfw:comment>http://znblog.athoim.com/wfwcomment.php?cid=30</wfw:comment>

    <slash:comments>6</slash:comments>
    <wfw:commentRss>http://znblog.athoim.com/rss.php?version=2.0&amp;type=comments&amp;cid=30</wfw:commentRss>
    

    <author>nospam@example.com (th1nk3r)</author>
    <content:encoded>
    Esta tarde, en 15 minutillos que tenía aburridos, me he puesto a rehacer mi script de firma para foros &lt;img src=&quot;http://znblog.athoim.com/templates/znblue/img/emoticons/smile.png&quot; alt=&quot;:)&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;&lt;br /&gt;
Creo que ya comenté hace algún tiempo lo de este script, es muy sencillo. Recoge información del sistema, y la monta junto con una imagen aleatoria, lo mete en un JPG y lo envía al solicitante.&lt;br /&gt;
&lt;br /&gt;
Hasta ahora solo mostraba la versión del kernel, el uptime, el número de usuarios en el sistema y la cantidad de ram y swap libres. Me he cansado un poco de toda esa información, y he decidido cambiar lo que se muestra. Ahora aparece la versión del kernel de mi servidor, el uptime y la ram libre, y como extra la última canción escuchada (información sacada de audioscrobber &lt;img src=&quot;http://znblog.athoim.com/templates/znblue/img/emoticons/laugh.png&quot; alt=&quot;:D&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;).&lt;br /&gt;
Aun me falta darle algunos retoques a ese script, de momento es bastante cutre, pero hace muy bien su función. Mi principal problema es que la mayoría de canciones tienen o el title o el autor en caracteres asiáticos (japoneses, chinos o coreanos), así que no se muestran bien. A petición de Kebrantador, pongo parte del código, aunque no esperéis demasiado.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;geshiCode&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; &amp;#160;$rs&amp;#160; es&amp;#160; un&amp;#160; objeto&amp;#160; que uso&amp;#160; para&amp;#160; acceder a&amp;#160; la&amp;#160; base&amp;#160; de&amp;#160; datos&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; &amp;#160;en este caso ya he leido&amp;#160; los datos. Cada firma&amp;#160; tiene&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; &amp;#160;un formato&amp;#160; diferente,&amp;#160; por eso&amp;#160; guardo&amp;#160; la&amp;#160; info&amp;#160; en&amp;#160; una tabla.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; &amp;#160;Entre&amp;#160; la&amp;#160; info&amp;#160; estan las&amp;#160; coordenadas donde&amp;#160; va&amp;#160; a ir el texto&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; &amp;#160;el color, la fuente,&amp;#160; el&amp;#160; nivel de compresion de la imagen,&amp;#160; etc&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$rs&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;fields&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;image&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$compress&lt;/span&gt; =&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$rs&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;fields&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;compress&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$fotn_name&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$rs&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;fields&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;text_font&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$acolor&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/explode&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;explode&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;:&#039;&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$rs&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;fields&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;text_color&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x_pos&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$rs&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;fields&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;text_x&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$y_pos&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$rs&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;fields&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;text_y&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$altura&lt;/span&gt; =&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$rs&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;fields&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;altura&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$special&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$rs&lt;/span&gt;-&amp;gt;&lt;span style=&quot;color: #006600;&quot;&gt;fields&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;special&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagedir&lt;/span&gt; =&amp;#160; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;/dir/dir/dir/imagenes/firmas/&#039;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagepath&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$imagedir&lt;/span&gt;&amp;#160; . &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/getimagesize&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;getimagesize&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagepath&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; &amp;gt;&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/die&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;switch&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;&amp;#160; = imagecreatefromgif&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagepath&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;:&amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;&amp;#160; = imagecreatefromjpeg&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagepath&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;:&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;&amp;#160; = imagecreatefrompng&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagepath&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Color del&amp;#160; texto&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$color&lt;/span&gt;&amp;#160; = imagecolorallocate&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$acolor&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$acolor&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$acolor&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Seleccionar fuente&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$font&lt;/span&gt; =&amp;#160; imageloadfont&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagedir&lt;/span&gt; .&amp;#160; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;fonts/&#039;&lt;/span&gt;&amp;#160; . &lt;span style=&quot;color: #0000ff;&quot;&gt;$font_name&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Version&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; En&amp;#160; el&amp;#160; cron&amp;#160; he&amp;#160; indicado&amp;#160; que a&amp;#160; los 5&amp;#160; minutos &lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; de&amp;#160; reiniciar se ejecute:&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; /usr/bin/uname&amp;#160; -r&amp;#160; &amp;gt; /dir/dir/firma_kernel.txt&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$version&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/file_get_contents&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file_get_contents&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;/firma_kernel.txt&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$text&lt;/span&gt; =&amp;#160; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Gentoo GNU/Linux&amp;#160; &#039;&lt;/span&gt; .&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$version&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$special&lt;/span&gt;==&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;center&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$x_pos&lt;/span&gt; +&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;40&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$x_pos&lt;/span&gt;;&lt;br /&gt;&amp;#160;imagestring&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$font&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$y_pos&lt;/span&gt;&amp;#160; + &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt; &amp;lt;strong&amp;gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$altura&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$text&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; RAM y&amp;#160; Uptime&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Se&amp;#160; obtienen&amp;#160; de&amp;#160; forma muy&amp;#160; parecida, los&amp;#160; omito&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; lastsong&amp;#160; played&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Mediante&amp;#160; un&amp;#160; script&amp;#160; shell que&amp;#160; se&amp;#160; ejecuta cada minuto&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; en&amp;#160; el&amp;#160; crontab,&amp;#160; descargo&amp;#160; el&amp;#160; ficherito:&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; http://ws.audioscrobbler.com/txt/recent/th1nk3r&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; y lo renombro como &amp;quot;firma_audio.txt&amp;quot;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$trackData&lt;/span&gt;&amp;#160; = @&lt;a href=&quot;http://www.php.net/file&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;file&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;/dir/dir/firma_audio.txt&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$trackData&lt;/span&gt; != &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;null&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$trackData&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/trim&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;trim&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$trackData&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Comprobamos si se esta escuchando ahora, aunque es&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; una tonteria con&amp;#160; el&amp;#160; lag tan&amp;#160; tremendo&amp;#160; que hay&amp;#160; entre&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; que audioscrobbler publica&amp;#160; los cambios&amp;#160; y el script los&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; descarga...&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$trackData&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&amp;#160; !=&amp;#160; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$track&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;[&#039;&lt;/span&gt;&amp;#160; . &lt;span style=&quot;color: #0000ff;&quot;&gt;$trackData&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&amp;#160; . &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;]&#039;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$track&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;[&#039;&lt;/span&gt;&amp;#160; . &lt;span style=&quot;color: #0000ff;&quot;&gt;$trackData&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&amp;#160; . &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;]&#039;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$track&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/html_entity_decode&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;html_entity_decode&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$track&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$track&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/trim&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;trim&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$track&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$track&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Audioscrobbler&amp;#160; data&amp;#160; error&#039;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Este&amp;#160; error se produce&amp;#160; cuando&amp;#160; se&amp;#160; esta&amp;#160; actualizando&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; el&amp;#160; fichero firma_audio.txt...&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$special&lt;/span&gt;==&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;center&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$x_pos&lt;/span&gt; +&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;25&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$x_pos&lt;/span&gt;&amp;gt;;&lt;br /&gt;&amp;#160;imagestring&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$font&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$y_pos&lt;/span&gt;&amp;#160; + &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt; &amp;lt;/strong&amp;gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$altura&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$track&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Enviamos&amp;#160; la&amp;#160; imagen&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;a href=&quot;http://www.php.net/header&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;header&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Content-Type: image/jpeg&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt; =&amp;#160; imagecreatetruecolor&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;500&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;imagecopyresampled&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;500&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;150&lt;/span&gt;,&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;imageinterlace&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;imagejpeg&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&#039;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$compress&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;imagedestroy&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;imagedestroy&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Este código forma parte del script que genera las imágenes. Los directorios y alguna otra info es inventada, pero cambiando esos datos debería funcionar. Como ya he dicho, son firmas dinámicas y algunos foros no las admiten. Sin embargo, es fácil saltarse esa protección, lo dejo a vuestra imaginación. 
    </content:encoded>

    <pubDate>Wed, 24 Aug 2005 02:58:00 -0400</pubDate>
    <guid isPermaLink="false">http://znblog.athoim.com/archives/30-guid.html</guid>
    
</item>
<item>
    <title>Transparencias con GD</title>
    <link>http://znblog.athoim.com/archives/26-Transparencias-con-GD.html</link>
            <category>PHP</category>
    
    <comments>http://znblog.athoim.com/archives/26-Transparencias-con-GD.html#comments</comments>
    <wfw:comment>http://znblog.athoim.com/wfwcomment.php?cid=26</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://znblog.athoim.com/rss.php?version=2.0&amp;type=comments&amp;cid=26</wfw:commentRss>
    

    <author>nospam@example.com (th1nk3r)</author>
    <content:encoded>
    Me he pasado el día peleando con las librerías &lt;a href=&quot;http://es.php.net/gd&quot; title=&quot;Image Functions&quot;&gt;GD de PHP&lt;/a&gt;. ¿Cual es el problema?&lt;br /&gt;
Tengo un script que comprueba la dirección IP del referer cada vez que se solicita una imagen, para evitar el robo de estas. También me permite manipular imágenes, re-dimensionarlas, re-comprimirlas, etc, sin tener que tener varias versiones guardadas a la vez.&lt;br /&gt;
&lt;br /&gt;
El script lo tenía terminado, pero me di cuenta de un bug muy grabe, terrible. Al re-dimensionar las imágenes no se conservan las transparencias ni en GIF ni en PNG. Es posible, que tampoco se pillen bien los GIFs animados (tengo que comprobarlo aun &lt;img src=&quot;http://znblog.athoim.com/templates/znblue/img/emoticons/drop.gif&quot; alt=&quot;:drop:&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;), ya veremos...&lt;br /&gt;
Después de mucho leer y probar he conseguido solucionar el problema. Os copio la función que he creado y que permite re-dimensionar imágenes GIF, PNG y JPG, re-comprimiendolas y usando transparencias (y por supuesto, sin hacer uso de programas externos tipo imagemagick &lt;img src=&quot;http://znblog.athoim.com/templates/znblue/img/emoticons/tongue.png&quot; alt=&quot;:P&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;). Me ha costado, pero al fin he solucionado el bug (la batalla con los gifs animados lo doy por perdida &lt;img src=&quot;http://znblog.athoim.com/templates/znblue/img/emoticons/cry.png&quot; alt=&quot;:&#039;(&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt; ). Disfrutad la función.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;geshiCode&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;/**&lt;br /&gt;&amp;#160; &amp;#160;$imagepath =&amp;#160; ruta&amp;#160; y nombre de la imagen&lt;br /&gt;&amp;#160; &amp;#160;$compress&amp;#160; = nivel&amp;#160; de&amp;#160; compresion&amp;#160; para&amp;#160; la&amp;#160; img resultado&lt;br /&gt;&amp;#160; &amp;#160;$x =&amp;#160; anchura deseada&amp;#160; para&amp;#160; la&amp;#160; img resultado&lt;br /&gt;&amp;#160; &amp;#160;$y =&amp;#160; altura&amp;#160; deseada para la img&amp;#160; resultado&lt;br /&gt;&amp;#160; &amp;#160;&lt;br /&gt;&amp;#160; &amp;#160;Anteriormente&amp;#160; ya&amp;#160; se&amp;#160; ha&amp;#160; calculado la anchura&amp;#160; y altura&lt;br /&gt;&amp;#160; &amp;#160;para esa&amp;#160; imagen&amp;#160; en&amp;#160; concreto&amp;#160; (de forma&amp;#160; que se mantengan&lt;br /&gt;&amp;#160; &amp;#160;las&amp;#160; proporciones).&lt;br /&gt;&amp;#160; &amp;#160;*/&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt;&amp;#160; readImg&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagepath&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$compress&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/getimagesize&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;getimagesize&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagepath&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;switch&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;:&amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; GIF&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;&amp;#160; = imagecreatefromgif&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagepath&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/header&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;header&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Content-Type: image/gif&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/header&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;header&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Content-transfer-encoding:&amp;#160; binary&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Pixels&amp;#160; esquina&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$tr_color&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$tl_color&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$br_color&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$bl_color&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt; =&amp;#160; imagecreate&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; pixel con&amp;#160; color negro&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagepalettecopy&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecopyresampled&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$ptr_over_black&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$ptl_over_black&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$pbr_over_black&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$pbl_over_black&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; pixel con&amp;#160; color blanco&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$bg&lt;/span&gt; =&amp;#160; imagecolorallocate&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;255&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;255&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagefilledrectangle&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$bg&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecopyresampled&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$ptr_over_white&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$ptl_over_white&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$pbr_over_white&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$pbl_over_white&lt;/span&gt; =&amp;#160; imagecolorat&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$ptr_over_black&lt;/span&gt;&amp;#160; !=&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$ptr_over_white&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagefilledrectangle&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$tr_color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecopyresampled&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecolortransparent&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tr_color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$ptl_over_black&lt;/span&gt;&amp;#160; !=&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$ptl_over_white&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagefilledrectangle&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$tl_color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecopyresampled&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecolortransparent&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$tl_color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$pbr_over_black&lt;/span&gt;&amp;#160; !=&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$pbr_over_white&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagefilledrectangle&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$br_color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecopyresampled&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecolortransparent&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$br_color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$pbl_over_black&lt;/span&gt;&amp;#160; !=&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$pbl_over_white&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagefilledrectangle&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$bl_color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecopyresampled&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecolortransparent&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$bl_color&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imageinterlace&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagegif&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt;:&amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; JPEG&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;&amp;#160; = imagecreatefromjpeg&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagepath&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/header&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;header&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Content-Type: image/jpeg&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/header&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;header&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Content-transfer-encoding:&amp;#160; binary&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt; =&amp;#160; imagecreatetruecolor&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;,&lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecopyresampled&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imageinterlace&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagejpeg&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;,&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&#039;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$compress&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;case&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt;:&amp;#160; &lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; PNG&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;&amp;#160; = imagecreatefrompng&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$imagepath&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/header&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;header&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Content-Type: image/png&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/header&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;header&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;Content-transfer-encoding:&amp;#160; binary&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt; =&amp;#160; imagecreatetruecolor&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;,&lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imageAlphaBlending&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagecopyresampled&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;,&amp;#160; &lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$x&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$y&lt;/span&gt;,&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$attr&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imageinterlace&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagesavealpha&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;,&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;imagepng&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;break&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;imagedestroy&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$image&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;imagedestroy&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$newimage&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt; 
    </content:encoded>

    <pubDate>Sat, 16 Jul 2005 21:09:00 -0400</pubDate>
    <guid isPermaLink="false">http://znblog.athoim.com/archives/26-guid.html</guid>
    
</item>
<item>
    <title>Árbol de categorías</title>
    <link>http://znblog.athoim.com/archives/25-rbol-de-categorias.html</link>
            <category>PHP</category>
    
    <comments>http://znblog.athoim.com/archives/25-rbol-de-categorias.html#comments</comments>
    <wfw:comment>http://znblog.athoim.com/wfwcomment.php?cid=25</wfw:comment>

    <slash:comments>2</slash:comments>
    <wfw:commentRss>http://znblog.athoim.com/rss.php?version=2.0&amp;type=comments&amp;cid=25</wfw:commentRss>
    

    <author>nospam@example.com (th1nk3r)</author>
    <content:encoded>
    Ademas de estudiar y jugar al Dynasty Warriors 5, me he vuelto a poner con la programación del nuevo CMS. Aun estoy esperando que Ally termine con los diseños de su weblog y el mio, pero yo ya estoy a saco con la programación de la sección de administración. Aun falta para que este todo listo, pero espero tenerlo todo para la Euskal. Últimamente he codificado las categorías de los posts. Ahora ya no habrá unas categorías fijas guardadas en el código php, sino que serán accesibles a través de un complejo árbol extensible (categorías y sub-categorías infinitas) dentro de una tabla de mysql.&lt;br /&gt;
 Para complacer un poco a BenKo voy a explicar un poco como he creado todo el tema del árbol. No es fácil, así que cuidado con perderse.&lt;br /&gt;
La tabla en la base de datos solo tiene 6 campos:&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;id -&gt; Identificador&lt;br /&gt;
parent -&gt; Nodo padre (categoria de la que depende)&lt;br /&gt;
title -&gt; Nombre de la categoria&lt;br /&gt;
lft -&gt; lo explicare luego&lt;br /&gt;
rgt -&gt; tambien lo explicare luego xD&lt;br /&gt;
active -&gt; 1 para categoria activa, 0 para inactiva&lt;/blockquote&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a  class=&#039;serendipity_image_link&#039;  rel=&#039;lightbox&#039; href=&#039;http://znblog.athoim.com/uploads/arbol_categorias.png&#039;&gt;&lt;!-- s9ymdb:33 --&gt;&lt;img width=&quot;200&quot; height=&quot;156&quot; style=&quot;float: right; border: 0px; padding-left: 5px; padding-right: 5px;&quot; src=&quot;http://znblog.athoim.com/uploads/arbol_categorias.s9yThumb.png&quot; alt=&quot;&quot;  /&gt;&lt;/a&gt;Los datos fundamentales son el id, el id del padre, y lft/rgt. ¿Pero qué demonios son lft y rgt? Vamos a verlo con un ejemplo:&lt;br /&gt;
En la imagen podéis ver un árbol de ejemplo, con sus valores lft en rojo y rgt en verde. lft y rgt son índices que nos ayudan a comprender la estructura del árbol y a mostrarlo con una sola consulta a la base de datos. Si solo guardáramos el valor de &lt;em&gt;pid&lt;/em&gt; y &lt;em&gt;pid padre&lt;/em&gt;, tendríamos que recorrer todo el árbol con llamadas recursivas, lo que sería una perdida absoluta de recursos y tiempo.&lt;br /&gt;
&lt;br /&gt;
¿Qué sub-categorías pertenecen a Informática? Fácil, ¿no?. Solo hay que preguntarle a la base de datos que categorías tienen su lft entre 10 y 21, es decir:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;geshiCode&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;SELECT&lt;/span&gt;&amp;#160; id&amp;#160; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;FROM&lt;/span&gt;&amp;#160; nombretabla &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;WHERE&lt;/span&gt;&amp;#160; lft &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;BETWEEN&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;10&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;AND&lt;/span&gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;21&lt;/span&gt; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;ORDER&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;BY&lt;/span&gt;&amp;#160; lft &lt;span style=&quot;color: #993333; font-weight: bold;&quot;&gt;ASC&lt;/span&gt;;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Sencillo, ¿verdad? Con esos IDs devueltos podemos borrar, buscar o hacer lo que necesitemos. Voy a explicar algunas operaciones:&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Imprimir arbol a partir del nodo xxx&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;geshiCode&quot; style=&quot;text-align: left&quot;&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt;&amp;#160; print_tree&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$root&lt;/span&gt;=&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Obtenemos de la BD el valor&amp;#160; lft y&amp;#160; rgt del&amp;#160; nodo&amp;#160; $root&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;SELECT&amp;#160; lft,&amp;#160; rgt FROM `tabla_categ`&amp;#160; WHERE id=&#039;$root&#039; &quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/mysql_fetch_array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_fetch_array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$lft&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;lft&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$rgt&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;rgt&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; obtenemos todos&amp;#160; los hijos&amp;#160; del nodo $root&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;SELECT&amp;#160; id, title, lft, rgt, active FROM `tabla_categ`&amp;#160; WHERE `lft`&amp;#160; BETWEEN $lft AND&amp;#160; $rgt&amp;#160; ORDER BY lft&amp;#160; ASC&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;while&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/mysql_fetch_array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_fetch_array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; solo&amp;#160; comprobar el vector $right si existe)&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/count&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;count&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&amp;gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;while&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;a href=&quot;http://www.php.net/count&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;count&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;rgt&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/array_pop&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;array_pop&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;lft&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;==&lt;span style=&quot;color: #0000ff;&quot;&gt;$lft&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$str&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/str_repeat&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;str_repeat&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&#039;&lt;/span&gt;,&lt;a href=&quot;http://www.php.net/count&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;count&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;else&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$str&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/str_repeat&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;str_repeat&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;&amp;amp;#160;&amp;amp;#160;&amp;amp;#160;&amp;amp;#160;&amp;amp;#160;&#039;&lt;/span&gt;,&lt;a href=&quot;http://www.php.net/count&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;count&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;-&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;|--&amp;gt; &#039;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$str&lt;/span&gt;&amp;#160; .&lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;title&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;&amp;#160; &quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;!&lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;active&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt;&amp;#160; &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot; (Inactiva)&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/echo&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;echo&lt;/span&gt;&lt;/a&gt;&amp;#160; &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;&lt;span style=&quot;color: #000099; font-weight: bold;&quot;&gt;\n&lt;/span&gt;&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;rgt&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Reconstruir valores rgt&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Muy útil porque después de mover valores, tendremos los &lt;em&gt;lft&lt;/em&gt; correctos, pero no los &lt;em&gt;rgt&lt;/em&gt;. Esta función recursiva reescribirá los valores &lt;em&gt;rgt&lt;/em&gt; (una gran ayuda &lt;img src=&quot;http://znblog.athoim.com/templates/znblue/img/emoticons/tongue.png&quot; alt=&quot;:P&quot; style=&quot;display: inline; vertical-align: bottom;&quot; class=&quot;emoticon&quot; /&gt;)&lt;br /&gt;
&lt;div class=&quot;geshiCode&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt;&amp;#160; rebuild_tree&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$parent&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$left&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;!&lt;a href=&quot;http://www.php.net/is_numeric&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_numeric&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$parent&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; || !&lt;a href=&quot;http://www.php.net/is_numeric&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;is_numeric&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$left&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;a href=&quot;http://www.php.net/die&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;die&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; el&amp;#160; valor rgt&amp;#160; de&amp;#160; un&amp;#160; nodo&amp;#160; final es lft+1&amp;#160; &amp;#160; &lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$left&lt;/span&gt;&amp;#160; + &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; obtener todos&amp;#160; los hijos&amp;#160; de&amp;#160; ese nodo&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;SELECT&amp;#160; id, title&amp;#160; FROM&amp;#160; `tabla_categ` WHERE&amp;#160; parent=&#039;$parent&#039;&amp;#160; ORDER BY title&amp;#160; ASC&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;while&lt;/span&gt; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/mysql_fetch_array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_fetch_array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; Viva&amp;#160; la&amp;#160; recursividad!!! xD&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&amp;#160; = rebuild_tree&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;id&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;,&lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;UPDATE&amp;#160; `tabla_categ` SET&amp;#160; `lft` =&amp;#160; &#039;$left&#039;,&amp;#160; `rgt` =&amp;#160; &#039;$right&#039;&amp;#160; WHERE `id`=&#039;$parent&#039;&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; devolver&amp;#160; right+1&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;return&lt;/span&gt;&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$right&lt;/span&gt;+&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Mover un nodo&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;geshiCode&quot; style=&quot;text-align: left&quot;&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// $idOrigen&amp;#160; -&amp;gt;&amp;#160; El&amp;#160; nodo&amp;#160; a mover&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;// $idDentroDe&amp;#160; -&amp;gt;&amp;#160; Dentro&amp;#160; de&amp;#160; que nodo (=nodo padre)&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; queremos moverlo&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #000000; font-weight: bold;&quot;&gt;function&lt;/span&gt;&amp;#160; moveNode&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$idOrigen&lt;/span&gt;, &lt;span style=&quot;color: #0000ff;&quot;&gt;$idDentroDe&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; obtenemos lft&amp;#160; y rgt&amp;#160; del elemento a&amp;#160; mover&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;SELECT&amp;#160; `lft`,`rgt` FROM `tabla_categ`&amp;#160; WHERE `id`=&#039;$idOrigen&#039;&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/mysql_fetch_array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_fetch_array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$lftorigen&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;lft&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$rgtorigen&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;rgt&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; obtenemos lft&amp;#160; del padre&amp;#160; destino&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;SELECT&amp;#160; `lft` FROM `tabla_categ`&amp;#160; WHERE `id`=&#039;$idDentroDe&#039;&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&amp;#160; = &lt;a href=&quot;http://www.php.net/mysql_fetch_array&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_fetch_array&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; el&amp;#160; nodo&amp;#160; movido&amp;#160; terminara teniendo lft&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; igual a&amp;#160; la&amp;#160; del padre&amp;#160; + 1&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$lftdestino&lt;/span&gt; =&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$row&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span style=&quot;color: #ff0000;&quot;&gt;&#039;lft&#039;&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#93;&lt;/span&gt;+&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; $distancia&amp;#160; a mover&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$distancia&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #0000ff;&quot;&gt;$lftdestino&lt;/span&gt;&amp;#160; - &lt;span style=&quot;color: #0000ff;&quot;&gt;$lftorigen&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; amplitud&amp;#160; del intervalo&amp;#160; a mover&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; (el nodo a&amp;#160; mover puede&amp;#160; tener hijos!)&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$amplitud&lt;/span&gt; =&amp;#160; &lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$rgtorigen&lt;/span&gt; -&amp;#160; &lt;span style=&quot;color: #0000ff;&quot;&gt;$lftorigen&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt; +&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #b1b100;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$distancia&lt;/span&gt;&amp;#160; &amp;gt; &lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; desplazamos nodos&amp;#160; para&amp;#160; dejar hueco&amp;#160; en&amp;#160; destino&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;UPDATE&amp;#160; `tabla_categ` SET&amp;#160; `lft`=&amp;#160; &#039;lft+$amplitud&#039;,&amp;#160; `rgt`=&amp;#160; &#039;rgt+$amplitud&#039; WHERE&amp;#160; `lft` &amp;gt;=$lftdestino&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; cambiamos lft&amp;#160; y rgt&amp;#160; a los&amp;#160; del destino&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;UPDATE&amp;#160; `tabla_categ` SET&amp;#160; `lft`=&amp;#160; &#039;lft+$distancia&#039;, `rgt`= &#039;rgt+$distancia&#039; WHERE&amp;#160; `lft` BETWEEN&amp;#160; $lftorigen&amp;#160; AND $rgtorigen&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; quitamos&amp;#160; el&amp;#160; hueco dejado en el origen&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; tras&amp;#160; el&amp;#160; desplazamiento&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;UPDATE&amp;#160; `tabla_categ` SET&amp;#160; `lft`=&amp;#160; &#039;lft-$amplitud&#039;,&amp;#160; `rgt`=&amp;#160; &#039;rgt-$amplitud&#039; WHERE&amp;#160; `lft` &amp;gt;$rgtorigen&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #b1b100;&quot;&gt;elseif&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$distancia&lt;/span&gt;&amp;lt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#123;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; desplazamos nodos&amp;#160; para&amp;#160; dejar hueco&amp;#160; en&amp;#160; destino&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;UPDATE&amp;#160; `tabla_categ` SET&amp;#160; `lft`=&amp;#160; &#039;lft+$amplitud&#039;,&amp;#160; `rgt`=&amp;#160; &#039;rgt+$amplitud&#039; WHERE&amp;#160; `lft` &amp;gt;=$lftdestino&quot;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; cambiamos lft&amp;#160; yrgt&amp;#160; a los&amp;#160; del destino&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; NOTA: en este caso los&amp;#160; lft y&amp;#160; rgt han&amp;#160; sido&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; desplazados por&amp;#160; el&amp;#160; UPDATE&amp;#160; anterior&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;UPDATE&amp;#160; `tabla_categ` SET&amp;#160; `lft`=&amp;#160; &#039;lft-&quot;&lt;/span&gt;.&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$distancia&lt;/span&gt;+&lt;span style=&quot;color: #0000ff;&quot;&gt;$amplitud&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;&#039;, `rgt`= &#039;rgt-&quot;&lt;/span&gt;.&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$distancia&lt;/span&gt;+&lt;span style=&quot;color: #0000ff;&quot;&gt;$amplitud&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;&#039; WHERE&amp;#160; `lft` BETWEEN&amp;#160; &quot;&lt;/span&gt;.&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$lftorigen&lt;/span&gt;+&lt;span style=&quot;color: #0000ff;&quot;&gt;$amplitud&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;.&lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;&amp;#160; AND &quot;&lt;/span&gt;.&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$rgtorigen&lt;/span&gt;+&lt;span style=&quot;color: #0000ff;&quot;&gt;$amplitud&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; quitamos&amp;#160; el&amp;#160; hueco dejado en el origen&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; tras&amp;#160; el&amp;#160; desplazamiento&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;UPDATE&amp;#160; `tabla_categ` SET&amp;#160; `lft`=&amp;#160; &#039;lft-$amplitud&#039;,&amp;#160; `rgt`=&amp;#160; &#039;rgt-$amplitud&#039; WHERE&amp;#160; `lft` &amp;gt;&quot;&lt;/span&gt;.&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$rgtorigen&lt;/span&gt;+&lt;span style=&quot;color: #0000ff;&quot;&gt;$amplitud&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&amp;#160; = &lt;span style=&quot;color: #ff0000;&quot;&gt;&quot;UPDATE&amp;#160; `tabla_categ` SET&amp;#160; `parent`=&#039;$idDentroDe&#039;&amp;#160; WHERE `id`=&quot;&lt;/span&gt;.&lt;span style=&quot;color: #0000ff;&quot;&gt;$idOrigen&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #0000ff;&quot;&gt;$result&lt;/span&gt; =&amp;#160; &lt;a href=&quot;http://www.php.net/mysql_query&quot;&gt;&lt;span style=&quot;color: #000066;&quot;&gt;mysql_query&lt;/span&gt;&lt;/a&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #0000ff;&quot;&gt;$sql&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;&lt;span style=&quot;color: #808080; font-style: italic;&quot;&gt;//&amp;#160; ¡¡IMPORTANTE!!&lt;/span&gt;&lt;br /&gt;&amp;#160; &amp;#160; &amp;#160;rebuild_tree&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;,&lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#41;&lt;/span&gt;;&lt;br /&gt;&amp;#160;&lt;span style=&quot;color: #66cc66;&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
¿Como lo enlazamos con los mensajes? Bien, dependiendo de la base de datos, y de como guardemos los mensajes, cada uno de estos tendrá asociado un id de categoría. Si estamos dispuestos a hacer uso de otra tabla, podemos guardar en otra tabla:&lt;br /&gt;
&lt;br /&gt;
id -&gt; Índice único de la tabla (no nos interesa)&lt;br /&gt;
id_msg -&gt; Identificador de la entrada del weblog&lt;br /&gt;
id_categ -&gt; Identificador de categoría&lt;br /&gt;
&lt;br /&gt;
¿Qué conseguimos con esto? Pues que con una consulta sencilla podamos obtener todas las posibles categorías a las que pertenezca un mensaje. Un poco complicado, ¿no? Imaginad este trozo de tabla:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;geshiCode&quot; style=&quot;text-align: left&quot;&gt;|----------------------|&lt;br /&gt;| id | id_msg | id_cat |&lt;br /&gt;|----------------------|&lt;br /&gt;|&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;1&lt;/span&gt; |&amp;#160; &amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;100&lt;/span&gt; |&amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;6&lt;/span&gt; |&lt;br /&gt;|&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt; |&amp;#160; &amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;100&lt;/span&gt; |&amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt; |&lt;br /&gt;|&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;3&lt;/span&gt; |&amp;#160; &amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;101&lt;/span&gt; |&amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt; |&lt;br /&gt;|&amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;4&lt;/span&gt; |&amp;#160; &amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;102&lt;/span&gt; |&amp;#160; &amp;#160; &amp;#160; &lt;span style=&quot;color: #cc66cc;&quot;&gt;2&lt;/span&gt; |&lt;br /&gt;|----------------------|&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Es fácil hacer una consulta que nos diga a que categorías pertenece el mensaje 100, ¿verdad? Gracias a esta estructura de árbol, también sabemos que todos los mensajes de KDE pertenecen también a Linux y a su vez a Informática, por lo que al realizar la búsqueda en la base de datos de un mensaje con categoría informática, podríamos buscar (una consulta compleja pero posible) todos los mensajes que tengan una categoría cuyo valor lft este entre 10 y 21 (el lft y el rgt de Informática).&lt;br /&gt;
&lt;br /&gt;
El mayor problema con el que me he encontrado es a la hora de borrar categorías. ¿Que pasa con los mensajes huérfanos (=sin categoría)? No me apetece comerme la cabeza con este asunto de poca importancia, así que lo que he decidido es que no se pueden borrar categorías. Se les puede cambiar el nombre, mover y se pueden desactivar (al desactivar un nodo, se desactiva también toda la rama que cuelga de el), pero no se pueden borrar (para evitar un caos con los IDs). Si nos sobra una categoría podemos cambiarle el nombre, el padre y la posición y emplearla para otra cosa (habrá que cambiar las categorías de los mensajes que dependan de esa categoría, pero es un problema menor).Creo que me ha quedado un tutorial un poco complicado... espero que alguien pueda entender algo. Voy a rehacerlo unas cuantas veces para ver si queda mas útil.... 
    </content:encoded>

    <pubDate>Sun, 26 Jun 2005 19:53:00 -0400</pubDate>
    <guid isPermaLink="false">http://znblog.athoim.com/archives/25-guid.html</guid>
    
</item>

</channel>
</rss>