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

<channel>
	<title>reweb Labs</title>
	<atom:link href="http://labs.reweb.com.ar/feed" rel="self" type="application/rss+xml" />
	<link>http://labs.reweb.com.ar</link>
	<description>Donde la magia sucede</description>
	<lastBuildDate>Thu, 25 Feb 2010 11:37:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Custom Tags en J2EE con NetBeans</title>
		<link>http://labs.reweb.com.ar/46-custom-tags-en-j2ee-con-netbeans</link>
		<comments>http://labs.reweb.com.ar/46-custom-tags-en-j2ee-con-netbeans#comments</comments>
		<pubDate>Thu, 25 Feb 2010 11:37:46 +0000</pubDate>
		<dc:creator>joarobles</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[custom tags]]></category>
		<category><![CDATA[J2EE]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[NetBeans]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=46</guid>
		<description><![CDATA[La creación de Custom Tags (etiquetas personalizadas) en Java EE con NetBeans es sumamente fácil. Para ello debemos crear un nuevo proyecto desde Archivo -&#62; Nuevo Proyecto y luego seleccionamos la opción Java Web -&#62; Web Application. A continuación especificamos los datos relativos a la ubicación del proyecto en disco y luego sobre el servidor [...]]]></description>
			<content:encoded><![CDATA[<p>La creación de Custom Tags (etiquetas personalizadas) en Java EE con NetBeans es sumamente fácil. Para ello debemos crear un nuevo proyecto desde Archivo -&gt; Nuevo Proyecto y luego seleccionamos la opción <strong>Java Web</strong> -&gt; <strong>Web Application</strong>. A continuación especificamos los datos relativos a la ubicación del proyecto en disco y luego sobre el servidor de aplicaciones a utilizar (en nuestro caso Glassfish).</p>
<p>A continuación procedemos a crear un archivo Tag Library Descriptor, que vendría a ser la especificación de las etiquetas que contendrá nuestra librería. Allí iremos agregando las nuevas relaciones a etiquetas que vayamos creado, de forma tal que luego podamos importar este archivo TLD a nuestro JSP para poder comenzar a utilizar sus tags. Para crearlo simplemente seleccionamos Archivo -&gt; Nuevo Archivo y luego la opción <strong>Tag Library Descriptor</strong> dentro de la carpeta <strong>Web</strong>. A continación le asignamos un nombre (como ejemplo usaremos <em>funcionesMatematicas</em>) y seleccionamos como localización nuestra carpeta WEB-INF, creada automáticamente por el NetBeans al iniciar el Proyecto.</p>
<p>A continuación veremos creado un archivo como el siguiente:</p>
<p><strong>Archivo:</strong> <em>funcionesMatematicas.tld</em></p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">&nbsp;
  1.0
  funcionesmatematicas
  /WEB-INF/funcionesMatematicas
  <span style="color: #808080; font-style: italic;">&lt;!-- A validator verifies that the tags are used correctly at JSP</span>
<span style="color: #808080; font-style: italic;">         translation time. Validator entries look like this:</span>
<span style="color: #808080; font-style: italic;">      &lt;validator&gt;</span>
<span style="color: #808080; font-style: italic;">          &lt;validator-class&gt;com.mycompany.TagLibValidator&lt;/validator-class&gt;</span>
<span style="color: #808080; font-style: italic;">          &lt;init-param&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;span -name class=&quot;mceItemParam&quot;&gt;&lt;/span&gt;parameter&lt;/param-name&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;span -value class=&quot;mceItemParam&quot;&gt;&lt;/span&gt;value&lt;/param-value&gt;</span>
<span style="color: #808080; font-style: italic;">	  &lt;/init-param&gt;</span>
<span style="color: #808080; font-style: italic;">      &lt;/validator&gt;</span>
<span style="color: #808080; font-style: italic;">   --&gt;</span>
  <span style="color: #808080; font-style: italic;">&lt;!-- A tag library can register Servlet Context event listeners in</span>
<span style="color: #808080; font-style: italic;">        case it needs to react to such events. Listener entries look</span>
<span style="color: #808080; font-style: italic;">        like this:</span>
<span style="color: #808080; font-style: italic;">	&lt;listener&gt;</span>
<span style="color: #808080; font-style: italic;">	&lt;listener-class&gt;com.mycompany.TagLibListener&lt;/listener-class&gt;</span>
<span style="color: #808080; font-style: italic;">     &lt;/listener&gt;</span>
<span style="color: #808080; font-style: italic;">   --&gt;</span>
&nbsp;
    Suma
    misTags.Suma
    scriptless
&nbsp;
      a
      true
      true
      int
&nbsp;
      b
      true
      true
      int</pre></div></div>

<p>Que no es nada más y nada menos que un archivo XML en el que se describen las características de la librería de etiquetas personalizadas. Dentro de este archivo, dentro de la etiqueta <em>taglib</em>, es que especificaremos nuestras custom tags para vincularlas a métodos de clases que extiendan a Tag (veremos esto a continuación).</p>
<p>Dentro de los paquetes fuente (source packages) creamos uno nuevo llamado <em>misTags</em>. Y dentro de este paquete creamos un nuevo archivo del tipo <em>Tag Handler</em>. A continuación, NetBeans nos solicitará los datos de la etiqueta personalizada a crear, tales como el nombre, la descripción y la clase <em>Tag Support</em> a la que extenderá. De esta selección dependerá la cantidad de métodos que tengamos que redefinir para que nuestra tag funcione, además del control que obtendremos en cuanto a libertad de modificación. Para simplificarlo seleccionamos <em>SimpleTagSupport</em> (por defecto).</p>
<p>En nuestro caso crearemos la etiqueta <em>suma</em>, cuyo objetivo será retornar la suma entre dos números enteros pasados por parámetro. Luego seleccionamos el archivo TLD (descriptor de etiquetas) al cual se vinculará la etiqueta actual, en nuestro caso será <em>funcionesMatematicas.tld</em>. Para finalizar especificaremos los parámetros que utilizará nuestra etiqueta, usando el botón <em>New &#8230;</em> en la parte inferior derecha del formulario.</p>
<p>Agregamos dos parámetros, <strong><em>a</em></strong> y <strong><em>b</em></strong> del tipo int, ambos requeridos y seleccionamos <em>Terminar</em>. De esta forma obtendremos una clase Java con un contenido similar al siguiente:</p>
<p><strong>Archivo:</strong> <em>Suma.java</em></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">misTags</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.jsp.JspWriter</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.jsp.JspException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.jsp.tagext.JspFragment</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.jsp.tagext.SimpleTagSupport</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 *
 * @author Joaquin L. Robles
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Suma <span style="color: #000000; font-weight: bold;">extends</span> SimpleTagSupport <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> a<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> b<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #008000; font-style: italic; font-weight: bold;">/**
     * Called by the container to invoke this tag.
     * The implementation of this method is provided by the tag library developer,
     * and handles all tag processing, body iteration, etc.
     */</span>
    @Override
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doTag<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> JspException <span style="color: #009900;">&#123;</span>
        JspWriter out <span style="color: #339933;">=</span> getJspContext<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getOut</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            JspFragment f <span style="color: #339933;">=</span> getJspBody<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>f <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> f.<span style="color: #006633;">invoke</span><span style="color: #009900;">&#40;</span>out<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            <span style="color: #666666; font-style: italic;">// NUESTRO CODIGO ACA</span>
&nbsp;
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>java.<span style="color: #006633;">io</span>.<span style="color: #003399;">IOException</span> ex<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> JspException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error in Suma tag&quot;</span>, ex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setA<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> a<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">a</span> <span style="color: #339933;">=</span> a<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setB<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> b<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">b</span> <span style="color: #339933;">=</span> b<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/46-custom-tags-en-j2ee-con-netbeans/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple AJAX Shoutbox para Wordpress en español</title>
		<link>http://labs.reweb.com.ar/72-simple-ajax-shoutbox-para-wordpress-en-espanol</link>
		<comments>http://labs.reweb.com.ar/72-simple-ajax-shoutbox-para-wordpress-en-espanol#comments</comments>
		<pubDate>Fri, 04 Dec 2009 13:04:01 +0000</pubDate>
		<dc:creator>joarobles</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/72-simple-ajax-shoutbox-para-wordpress-en-espanol</guid>
		<description><![CDATA[Versión del plugin traducida al español.
Descargar Simple AJAX Shoutbox en espa&#241;ol
]]></description>
			<content:encoded><![CDATA[<p>Versión del plugin traducida al español.</p>
<p><a href='http://labs.reweb.com.ar/wp-content/uploads/2009/12/simple-ajax-shoutbox-es_es.zip'>Descargar Simple AJAX Shoutbox en espa&ntilde;ol</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/72-simple-ajax-shoutbox-para-wordpress-en-espanol/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flickr Gallery para Wordpress en español</title>
		<link>http://labs.reweb.com.ar/67-flickr-gallery-para-wordpress-en-espanol</link>
		<comments>http://labs.reweb.com.ar/67-flickr-gallery-para-wordpress-en-espanol#comments</comments>
		<pubDate>Thu, 03 Dec 2009 16:06:27 +0000</pubDate>
		<dc:creator>joarobles</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=67</guid>
		<description><![CDATA[Así es, la versión de este excelente plugin para mostrar fotos, galerias y videos de Flickr en Wordpress usando shortcodes está disponible en español.
Descargar Flickr Gallery para Wordpress
]]></description>
			<content:encoded><![CDATA[<p>Así es, la versión de este excelente plugin para mostrar fotos, galerias y videos de Flickr en Wordpress usando shortcodes está disponible en español.</p>
<p><a href="http://labs.reweb.com.ar/wp-content/uploads/2009/12/flickr-gallery.zip">Descargar Flickr Gallery para Wordpress</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/67-flickr-gallery-para-wordpress-en-espanol/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitor de Servidor en PHP</title>
		<link>http://labs.reweb.com.ar/60-monitor-de-servidor-en-php</link>
		<comments>http://labs.reweb.com.ar/60-monitor-de-servidor-en-php#comments</comments>
		<pubDate>Fri, 20 Nov 2009 15:10:01 +0000</pubDate>
		<dc:creator>joarobles</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=60</guid>
		<description><![CDATA[Hace unos días me surgió la necesidad de monitorear el estado de un servidor (si esta UP o DOWN) y recibir notificaciones via e-mail cuando se cayera. Probe un par de servicios gratuitos, pero sólo realizaban comprobaciones cada 30 minutos, por ejemplo.
Entonces se me ocurrió hacerlo por mí mismo, y conseguí realizarlo utilizando un servidor [...]]]></description>
			<content:encoded><![CDATA[<p>Hace unos días me surgió la necesidad de monitorear el estado de un servidor (si esta UP o DOWN) y recibir notificaciones via e-mail cuando se cayera. Probe un par de servicios gratuitos, pero sólo realizaban comprobaciones cada 30 minutos, por ejemplo.</p>
<p>Entonces se me ocurrió hacerlo por mí mismo, y conseguí realizarlo utilizando un servidor de hosting gratuito como 00webhost realizando comprobaciones cada 5 minutos y notificando las caídas via e-mail al instante.</p>
<p>Acá les muestro cómo hacerlo:</p>
<p>1. Debemos crear una cuenta de usuario gratuita en <a href="http://www.000webhost.com/" target="_blank">00webhost.com</a>. No es necesario que registremos un dominio .com personalizado, simplemente utilizamos un subdominio de los que nos proveen.</p>
<p>2. Una vez creada la cuenta, vamos a generar un archivo PHP llamado monitor.php con el siguiente contenido:</p>
<p><strong>Archivo: </strong><em>monitor.php</em></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
	<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Libmail.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Function to check response time</span>
	<span style="color: #000000; font-weight: bold;">function</span> pingDomain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$starttime</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$file</span>      <span style="color: #339933;">=</span> <span style="color: #990000;">fsockopen</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stoptime</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$status</span>    <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Site is down</span>
		<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stoptime</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$starttime</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$status</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// notificamos via email</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pingDomain<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'www.cordobalquila.com.ar'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">Mail</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">From</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mailDesde@mail.com.ar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">To</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mailPara@mail.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Subject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;El sitio www.cordobalquila.com.ar esta caido&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$message</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;El sitio esta caido&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Ahora vamos a explicar un poco el código anterior:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Libmail.class.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Esta es una clase de PHP de distribución gratuita disponible en PHPClasses para modelar el envío de e-mails con PHP, pueden descargarla desde <a href='http://labs.reweb.com.ar/wp-content/uploads/2009/11/libmail.rar'>acá</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Function to check response time</span>
	<span style="color: #000000; font-weight: bold;">function</span> pingDomain<span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$starttime</span> <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$file</span>      <span style="color: #339933;">=</span> <span style="color: #990000;">fsockopen</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$stoptime</span>  <span style="color: #339933;">=</span> <span style="color: #990000;">microtime</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$status</span>    <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">// Site is down</span>
		<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$stoptime</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$starttime</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$status</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$status</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$status</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Esta funcion devuelve el tiempo de acceso a la URL pasada por parametro (en milisegundos), devolviendo -1 si el sitio está caído (esto nos permitirá comprobar luego el estado).</p>
<p>Y por último:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// notificamos via email</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>pingDomain<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'www.cordobalquila.com.ar'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">Mail</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">From</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;contacto@cordobalquila.com.ar&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">To</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;joarobles89@gmail.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Subject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;El sitio www.cordobalquila.com.ar esta caido&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$message</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;El sitio esta caido&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$m</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Realizamos una comprobacion si el sitio está caído, en caso positivo notificamos via e-mail a la direccion que corresponda.</p>
<p>Ahora bien, la parte mas importante, planificar la tarea para que el servidor realice esta comprobacion cada cierto período de tiempo. Lo positivo es que 00webhost nos permite planificar tareas hasta en intervalos de 5 minutos, que es lo que considero bastante apropiado.</p>
<p>Desde nuestro panel de administración de la cuenta, vamos a la opción <strong>Cron Jobs</strong> y asignamos intervalos de 5 minutos a la ejecucion del comando <em>php -f RUTA_DEL_ARCHIVO/monitor.php</em>.</p>
<p>Listo, eso es todo! Ahora bien, podemos jugar un poco con este modelo para comprobar el estado de múltiples sitio, guardar Stats en una base de datos, etc, etc, etc&#8230;<br />
Suerte, y hasta la próxima!</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/60-monitor-de-servidor-en-php/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>MySQL result to KML file output &#8211; PHP</title>
		<link>http://labs.reweb.com.ar/37-mysql-result-to-kml-file-output-php</link>
		<comments>http://labs.reweb.com.ar/37-mysql-result-to-kml-file-output-php#comments</comments>
		<pubDate>Sun, 16 Aug 2009 17:42:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[KML]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=37</guid>
		<description><![CDATA[Description
This package offers a function called mysqlAKML (resource $mysqlResult, string $documentName=&#8217;kml&#8217;, string $itemName=&#8217;Placemark&#8217;); used to output a Mysql result with the following fields:
name: TEXTVALUE &#8211; The Name of the marker
description: TEXTVALUE &#8211; The description shown in the info window when marker clicked
coordinates: TEXTVALUE as (DOUBLE + &#8216;, &#8216; + DOUBLE) like &#8220;longitude, latitude&#8221;
Usage
So an easy [...]]]></description>
			<content:encoded><![CDATA[<h2>Description</h2>
<p>This package offers a function called <strong>mysqlAKML</strong> (resource $mysqlResult, string $documentName=&#8217;kml&#8217;, string $itemName=&#8217;Placemark&#8217;); used to output a Mysql result with the following fields:</p>
<p><em>name</em>: TEXTVALUE &#8211; The Name of the marker<br />
<em>description</em>: TEXTVALUE &#8211; The description shown in the info window when marker clicked<br />
<em>coordinates</em>: TEXTVALUE as (DOUBLE + &#8216;, &#8216; + DOUBLE) like &#8220;longitude, latitude&#8221;</p>
<h2>Usage</h2>
<p>So an easy way to obtain the KML would be:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$qString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT
markerName AS name,
myText AS description,
CONCAT (latitude, ', ', longitude) AS coordinates
FROM myTable&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$qString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$myKML</span> <span style="color: #339933;">=</span> mysql_KML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>A complete example:</p>
<h3>File getPoints.php</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">require</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'connetion.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysqlAKML-1.1.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// obtain the MySQL resutl</span>
<span style="color: #000088;">$makers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// KML Content-Type (application/vnd.google-earth.kml+xml)</span>
<span style="color: #990000;">header</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: application/vnd.google-earth.kml+xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Disposition: attachment; filename=&quot;markers.kml&quot;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Display the file content</span>
<span style="color: #b1b100;">echo</span> mysql_KML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$markers</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Then, if we want to load this KML in a Google Map with the Google Maps API with JavaScript, we shoul add the following code to our load() function:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// JavaScript</span>
<span style="color: #003366; font-weight: bold;">function</span> load<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
...
...
<span style="color: #006600; font-style: italic;">// add Markers fetched from the DB to the map</span>
<span style="color: #003366; font-weight: bold;">var</span> geoXml <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> GGeoXml<span style="color: #009900;">&#40;</span>PATH_TO_FILE <span style="color: #339933;">+</span> <span style="color: #3366CC;">'getPoints.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
map.<span style="color: #660066;">addOverlay</span><span style="color: #009900;">&#40;</span>geoXml<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
...
...
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Thats all! Feel free to modify the file but remember to leave my name! See the working example in the link below</p>
<h2>Working Example</h2>
<p><a href='http://www.cordobalquila.com.ar/inmobiliarias'>Example</a></p>
<h2>Downloads</h2>
<p><a href="http://labs.reweb.com.ar/wp-content/uploads/2009/08/mysqlakml-11.rar">Download Package File (mysqlAKML-1.1.php)</a></p>
<h2>Usefull Links</h2>
<p><a href='http://code.google.com/intl/es-AR/apis/maps/documentation/reference.html#GGeoXml'>GGeoXML in Google Maps API Reference</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/37-mysql-result-to-kml-file-output-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>wp-polls con opción de ocultar los resultados a los votantes</title>
		<link>http://labs.reweb.com.ar/19-wp-polls-con-opcion-de-ocultar-los-resultados-a-los-votantes</link>
		<comments>http://labs.reweb.com.ar/19-wp-polls-con-opcion-de-ocultar-los-resultados-a-los-votantes#comments</comments>
		<pubDate>Mon, 20 Jul 2009 15:29:17 +0000</pubDate>
		<dc:creator>joarobles</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=19</guid>
		<description><![CDATA[Introducción
Buscando en Google, no encontré ningún add-on, hack o tip para hacer que mi wp-polls me permitiera ocultar los resultados de las encuestas a los votantes (por ejemplo, para hacer un plebiscito o una votación cerrada) con el objetivo de evitar tendencias&#8230;
Así, desarrollé una variación del wp-polls que incluye esta funcionalidad (en inglés todavía para [...]]]></description>
			<content:encoded><![CDATA[<h2>Introducción</h2>
<p>Buscando en Google, no encontré ningún add-on, hack o tip para hacer que mi wp-polls me permitiera ocultar los resultados de las encuestas a los votantes (por ejemplo, para hacer un plebiscito o una votación cerrada) con el objetivo de evitar tendencias&#8230;</p>
<p>Así, desarrollé una variación del wp-polls que incluye esta funcionalidad (en inglés todavía para posibilitar la internacionalización luego) incluyendo un par de modificaciones, tanto en la interfaz como en la estructura de la base de datos, agregando un nuevo campo&#8230;</p>
<p>Pueden descargarlo desde aquí, su instalación es exactamente igual a la del wp-polls normal&#8230; Pueden hacer update si lo desean.</p>
<h2>Requisitos</h2>
<ul>
<li>Require Wordpress 2.8 al menos.</li>
</ul>
<h2>Downloads</h2>
<ul>
<li><a href="http://labs.reweb.com.ar/wp-content/uploads/2009/07/wp-polls.zip">Descargar wp-polls 2.50 modificado, con opción de ocultar los resultados a los votantes</a></li>
</ul>
<h2>Screenshots</h2>
<div id="attachment_31" class="wp-caption aligncenter" style="width: 310px"><a href="http://labs.reweb.com.ar/wp-content/uploads/2009/07/poll-agregar.jpg"><img class="size-medium wp-image-31" title="poll-agregar" src="http://labs.reweb.com.ar/wp-content/uploads/2009/07/poll-agregar-300x187.jpg" alt="Al agregar una Encuesta" width="300" height="187" /></a><p class="wp-caption-text">Al agregar una Encuesta</p></div>
<div id="attachment_32" class="wp-caption aligncenter" style="width: 310px"><a href="http://labs.reweb.com.ar/wp-content/uploads/2009/07/poll-opciones.jpg"><img class="size-medium wp-image-32" title="poll-opciones" src="http://labs.reweb.com.ar/wp-content/uploads/2009/07/poll-opciones-300x187.jpg" alt="Opciones de la Encuesta" width="300" height="187" /></a><p class="wp-caption-text">Opciones de la Encuesta</p></div>
<div id="attachment_33" class="wp-caption aligncenter" style="width: 310px"><a href="http://labs.reweb.com.ar/wp-content/uploads/2009/07/poll-votado.jpg"><img class="size-medium wp-image-33" title="poll-votado" src="http://labs.reweb.com.ar/wp-content/uploads/2009/07/poll-votado-300x187.jpg" alt="Al votar en una Encuesta con la opción &quot;Ocultar Resultados&quot; activada" width="300" height="187" /></a><p class="wp-caption-text">Al votar en una Encuesta con la opción &quot;Ocultar Resultados&quot; activada</p></div>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/19-wp-polls-con-opcion-de-ocultar-los-resultados-a-los-votantes/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pasar resultado MySQL a archivo XML o E4X para AJAX</title>
		<link>http://labs.reweb.com.ar/20-pasar-resultado-mysql-a-archivo-xml-o-e4x-para-ajax</link>
		<comments>http://labs.reweb.com.ar/20-pasar-resultado-mysql-a-archivo-xml-o-e4x-para-ajax#comments</comments>
		<pubDate>Thu, 16 Jul 2009 14:13:13 +0000</pubDate>
		<dc:creator>joarobles</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[E4X]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=20</guid>
		<description><![CDATA[Gente, acá les acerco una función de mi autoría que convierte un resultado de consulta MySQL en un archivo XML, veamos un ejemplo:
Si tuvieramos la siguiente tabla usuarios:



id
nombre
email










1
Pablo
pablo@mail.com


2
Marcos
marcos@mail.com




Con la consulta SQL dada por:

SELECT * FROM usuarios;

Y queremos obtener el siguiente archivo XML:

&#60;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&#62;
&#60;resultados&#62;
&#60;item&#62;
&#60;id&#62;1&#60;/id&#62;
&#60;nombre&#62;Pablo&#60;/nombre&#62;
&#60;mail&#62;pablo@mail.com&#60;/mail&#62;
&#60;/item&#62;
&#60;item&#62;
&#60;id&#62;2&#60;/id&#62;
&#60;nombre&#62;Marcos&#60;/nombre&#62;
&#60;mail&#62;marcos@mail.com&#60;/mail&#62;
&#60;/item&#62;

Simplemente debemos ejecutar la siguiente instrucción en PHP:

&#60;?
require &#40;'conexion.php'&#41;;
require &#40;'mysqlAXML-1.0.php'&#41;;
&#160;
header&#40;&#34;Content-type: text/xml&#34;&#41;;
&#160;
$consulta = [...]]]></description>
			<content:encoded><![CDATA[<p>Gente, acá les acerco una función de mi autoría que convierte un resultado de consulta MySQL en un archivo XML, veamos un ejemplo:</p>
<p>Si tuvieramos la siguiente tabla <em>usuarios</em>:</p>
<table border="0">
<tbody>
<tr>
<td>id</td>
<td>nombre</td>
<td>email</td>
</tr>
<tr>
<td>
<hr /></td>
<td>
<hr /></td>
<td>
<hr /></td>
</tr>
<tr>
<td>1</td>
<td>Pablo</td>
<td>pablo@mail.com</td>
</tr>
<tr>
<td>2</td>
<td>Marcos</td>
<td>marcos@mail.com</td>
</tr>
</tbody>
</table>
<p>
Con la consulta SQL dada por:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> usuarios;</pre></div></div>

<p>Y queremos obtener el siguiente archivo XML:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resultados<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nombre<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Pablo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nombre<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pablo@mail.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;nombre<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Marcos<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/nombre<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>marcos@mail.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mail<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/item<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Simplemente debemos ejecutar la siguiente instrucción en PHP:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">require</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'conexion.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysqlAXML-1.0.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-type: text/xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$consulta</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT * FROM usuarios&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$resultado</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #990000;">die</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error en '<span style="color: #006699; font-weight: bold;">$consulta</span>' &amp;lt;br /&amp;gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">mysql_error</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> mysql_XML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultado</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>O para obtener el resultado en formato E4X:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #b1b100;">echo</span> mysql_E4X<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultado</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>La sintaxis general es la siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>
mysql_XML<span style="color: #009900;">&#40;</span><span style="color: #000088;">$resultado</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#91;</span> <span style="color: #000088;">$nombreDoc</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'resultados'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$nombreItem</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'item'</span> <span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Pueden descargar el archivo ZIP con la libreria desde aquí: <a href="http://labs.reweb.com.ar/wp-content/uploads/2009/07/mysqlaxml-10.zip">mysqlaxml-1.0</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/20-pasar-resultado-mysql-a-archivo-xml-o-e4x-para-ajax/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Función Factorial en una sola línea de código &#8211; Python</title>
		<link>http://labs.reweb.com.ar/14-funcion-factorial-en-una-sola-linea-python</link>
		<comments>http://labs.reweb.com.ar/14-funcion-factorial-en-una-sola-linea-python#comments</comments>
		<pubDate>Thu, 02 Jul 2009 15:24:14 +0000</pubDate>
		<dc:creator>joarobles</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=14</guid>
		<description><![CDATA[Utilizando funciones integradas y reduce:

def facto&#40;n&#41;: return reduce&#40;operator.mul, range&#40;1, n+1&#41;&#41;

Utilizando definición por operadores:

def fact&#40;x&#41;: return &#40;1 if x==0 else x * fact&#40;x-1&#41;&#41;

Resumen de performance en http://importantshock.wordpress.com/2006/11/03/one-line-factorial-function-in-python/
]]></description>
			<content:encoded><![CDATA[<p>Utilizando funciones integradas y reduce:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> facto<span style="color: black;">&#40;</span>n<span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">reduce</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">operator</span>.<span style="color: black;">mul</span>, <span style="color: #008000;">range</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span>, n+<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Utilizando definición por operadores:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> fact<span style="color: black;">&#40;</span>x<span style="color: black;">&#41;</span>: <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: black;">&#40;</span><span style="color: #ff4500;">1</span> <span style="color: #ff7700;font-weight:bold;">if</span> x==<span style="color: #ff4500;">0</span> <span style="color: #ff7700;font-weight:bold;">else</span> x <span style="color: #66cc66;">*</span> fact<span style="color: black;">&#40;</span>x-<span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Resumen de performance en <a href="http://importantshock.wordpress.com/2006/11/03/one-line-factorial-function-in-python/" target="_blank">http://importantshock.wordpress.com/2006/11/03/one-line-factorial-function-in-python/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/14-funcion-factorial-en-una-sola-linea-python/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Paginar Vector de Resultados en PHP</title>
		<link>http://labs.reweb.com.ar/3-paginar-vector-de-resultados-en-php</link>
		<comments>http://labs.reweb.com.ar/3-paginar-vector-de-resultados-en-php#comments</comments>
		<pubDate>Wed, 13 May 2009 02:56:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://labs.reweb.com.ar/?p=3</guid>
		<description><![CDATA[Hace un tiempo me surgió el problema de paginar un vector (Array) de resultados de una búsqueda, por lo que busqué la forma de crear una función que me permitiera listar los items correspondientes, pasandole por parámetros el vector en cuestión, el límite de resultados a mostrar y la página solicitada.
He aquí mi solución (es [...]]]></description>
			<content:encoded><![CDATA[<p>Hace un tiempo me surgió el problema de paginar un vector (Array) de resultados de una búsqueda, por lo que busqué la forma de crear una función que me permitiera listar los items correspondientes, pasandole por parámetros el vector en cuestión, el límite de resultados a mostrar y la página solicitada.</p>
<p>He aquí mi solución (es una base, que necesita ser pulida, eso les dejo a ustedes <img src="http://www.cristalab.com/foros/images/smiles/icon_wink.gif" border="0" alt=";)" /> )</p>
<p><strong>paginar.php</strong></p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php"><span class="php_fx__keyword">function</span> paginar(<span class="php_fx__keyword">$</span><span class="php_fx__variable">v</span>, <span class="php_fx__keyword">$</span><span class="php_fx__variable">l</span>, <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>) {</pre>
<p>Primero que nada definimos la función junto con las variables que se han de pasar como parámetro, ahora bien, necesitamos saber cuales son las condiciones de inicio de nuestro paginador, tales como la cantidad de páginas a mostrar, en función de la longitud del vector y del límite de items a desplegar:</p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php"><span class="php_fx__com">// DEFINIMOS LA CANTIDAD DE PÁGINAS</span> 
<span class="php_fx__keyword">$</span><span class="php_fx__variable">paginas</span> = <span class="php_fx__func">ceil</span>(<span class="php_fx__func">count</span>(<span class="php_fx__keyword">$</span><span class="php_fx__variable">v</span>) / <span class="php_fx__keyword">$</span><span class="php_fx__variable">l</span>);</pre>
<p>Ahora bien, si queremos mostrar cada item del vector $v necesitaremos recorrerlo con un bucle, pero&#8230; ¿desde dónde empezaríamos a mostrar y hasta dónde? Para ello necesitamos definir las condiciones de nuestro bucle recorredor como sigue:</p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php"><span class="php_fx__com">// CONDICION DE INICIO</span> 
<span class="php_fx__keyword">$</span><span class="php_fx__variable">inicio</span> = (<span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span><span class="php_fx__number">-1</span>)*<span class="php_fx__keyword">$</span><span class="php_fx__variable">l</span>; 

<span class="php_fx__com">// CONDICION DE FINAL</span> 
<span class="php_fx__keyword">$</span><span class="php_fx__variable">final</span> = <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>*<span class="php_fx__keyword">$</span><span class="php_fx__variable">l</span>;</pre>
<p>Y ya estamos listos para empezar a recorrer el vector mostrando cada resultado dentro de un div de id=&#8221;item&#8221; dentro del div de resultados. Debemos tener en cuenta que, si no existiera el item i-ésimo dentro del vector $v tenemos que dejar de listar items:</p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php"><span class="php_fx__com">// MOSTRAMOS LOS ITEMS RESPECTIVOS</span> 
      <span class="php_fx__keyword">echo</span> <span class="php_fx__string1">'&lt;div id="resultados"&gt;'</span>; 
      <span class="php_fx__keyword">for</span> (<span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>=<span class="php_fx__keyword">$</span><span class="php_fx__variable">inicio</span>; <span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>&lt;<span class="php_fx__keyword">$</span><span class="php_fx__variable">final</span>; <span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>++) { 
         <span class="php_fx__keyword">if</span> (<span class="php_fx__keyword">isset</span>(<span class="php_fx__keyword">$</span><span class="php_fx__variable">v</span>[<span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>])) 
            <span class="php_fx__keyword">echo</span> <span class="php_fx__string2">"&lt;div id=\"item\"&gt;$i.- $v[$i]&lt;/div&gt;"</span>; 
         <span class="php_fx__keyword">else</span>  
            <span class="php_fx__keyword">break</span>; 
      } 
      <span class="php_fx__keyword">echo</span> <span class="php_fx__string1">'&lt;/div&gt;'</span>;</pre>
<p>Listo, tenemos los resultados correspondientes a la página $p, pero necesitaríamos mostrar el total de páginas a modo de menú de hipervínculos para poder navegar entre los ítems. Para ello comprobaremos si nos encontramos en la primera pagina para no mostrar &#8220;Página anterior&#8221; o en la última para no mostrar &#8220;Página siguiente&#8221;, además de no crear un vínculo a la misma página:</p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php"><span class="php_fx__com">// LISTAMOS LAS PÁGINAS</span> 
      <span class="php_fx__keyword">echo</span> <span class="php_fx__string1">'&lt;div id="paginas"&gt;'</span>; 
      <span class="php_fx__keyword">if</span> (<span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>&gt;<span class="php_fx__number">1</span>) 
         <span class="php_fx__keyword">echo</span> <span class="php_fx__string2">"&lt;a href=\"index.php?p="</span> . (<span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span><span class="php_fx__number">-1</span>) . <span class="php_fx__string2">"\"&gt;P&amp;aacute;gina Anterior&lt;/a&gt;&amp;nbsp;-&amp;nbsp;"</span>; 

      <span class="php_fx__keyword">for</span> (<span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>=<span class="php_fx__number">1</span>; <span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>&lt;=<span class="php_fx__keyword">$</span><span class="php_fx__variable">paginas</span>; <span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span>++) { 
         <span class="php_fx__keyword">if</span> (<span class="php_fx__keyword">$</span><span class="php_fx__variable">i</span> == <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>) 
            <span class="php_fx__keyword">echo</span> <span class="php_fx__string2">"&lt;strong&gt;$i&lt;/strong&gt;&amp;nbsp;"</span>; 
         <span class="php_fx__keyword">else</span>  
            <span class="php_fx__keyword">echo</span> <span class="php_fx__string2">"&lt;a href=\"index.php?p=$i\"&gt;$i&lt;/a&gt;&amp;nbsp;"</span>; 
      } 

      <span class="php_fx__keyword">if</span> (<span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>&lt;<span class="php_fx__keyword">$</span><span class="php_fx__variable">paginas</span>) 
         <span class="php_fx__keyword">echo</span> <span class="php_fx__string2">"&amp;nbsp;-&amp;nbsp;&lt;a href=\"index.php?p="</span> . (<span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span><span class="php_fx__number">+1</span>) . <span class="php_fx__string2">"\"&gt;P&amp;aacute;gina Siguiente&amp;nbsp;&lt;/a&gt;"</span>; 
      <span class="php_fx__keyword">echo</span> <span class="php_fx__string1">'&lt;/div&gt;'</span>; 
<span class="php_fx__keyword">return</span>; 
   }</pre>
<p>Eso sería todo, para llamar a la función simplemente realizamos:</p>
<p><strong>index.php</strong></p>
<p class="datos_bloque"><strong>Código :</strong></p>
<pre language="PHP" class="codigo php">
<div class="php_code_block"><span class="php_fx__phpopentag">&lt;?php</span> 
   <span class="php_fx__keyword">$</span><span class="php_fx__variable">vector</span> = <span class="php_fx__keyword">array</span>(<span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span>, <span class="php_fx__string2">"hola"</span>, <span class="php_fx__string2">"chau"</span> ); 

   <span class="php_fx__keyword">require</span> (<span class="php_fx__string2">"paginar.php"</span>); 

   <span class="php_fx__keyword">if</span> (<span class="php_fx__keyword">isset</span>(<span class="php_fx__global">$_GET</span>[p])) 
      <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span> = <span class="php_fx__global">$_GET</span>[p]; 
   <span class="php_fx__keyword">else</span>  
      <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>=<span class="php_fx__number">1</span>; 

   paginar(<span class="php_fx__keyword">$</span><span class="php_fx__variable">vector</span>, <span class="php_fx__number">10</span>, <span class="php_fx__keyword">$</span><span class="php_fx__variable">p</span>); 
<span class="php_fx__phpclosetag">?&gt;</span></div>
</pre>
<p>Espero que les sirva de base para un desarrollo más complejo, saludos!</p>
<p>Pueden ver el ejemplo funcionando en <a class="arti_link" href="http://www.reweb.com.ar/labs/paginarVector/">http://www.reweb.com.ar/labs/paginarVector/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.reweb.com.ar/3-paginar-vector-de-resultados-en-php/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
