<?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>Johan de Bruin &#187; Programacion</title>
	<atom:link href="http://www.johandebruin.com/c/programacion/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johandebruin.com</link>
	<description>Programación en php, tutorial de api wordpress y posicionamiento en buscadores seo.</description>
	<lastBuildDate>Wed, 30 Jun 2010 11:33:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Configurar el loop de wordpress</title>
		<link>http://www.johandebruin.com/configurar-el-loop-de-wordpress/</link>
		<comments>http://www.johandebruin.com/configurar-el-loop-de-wordpress/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 11:26:26 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[API wordpress]]></category>
		<category><![CDATA[Custom loop]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=609</guid>
		<description><![CDATA[Hoy os traigo otro artículo para incorporarlo en la api de wordpress, el loop de wordpress es invocado cada vez que solicitamos articulos o páginas, en el index por ejemplo sale por defecto la solicitud de los últimos artículos publicados, en el archivo los articulos de cierto mes o cierta categoria, etc&#8230; La api de [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy os traigo otro artículo para incorporarlo en la <a href="http://www.johandebruin.com/tutorial-api-wordpress/">api de wordpress</a>, el <strong>loop de wordpress </strong>es invocado cada vez que solicitamos articulos o páginas, en el index por ejemplo sale por defecto la solicitud de los últimos artículos publicados, en el archivo los articulos de cierto mes o cierta categoria, etc&#8230;</p>
<p>La <strong>api de wordpress nos permite una configuración bastante intensa </strong>de la forma de solicitar y mostrar contenido en los loops de wordpress, lo primero de todo es establecer los posts que queramos mostrar en el loop, se puede hacer usando la función <a href="http://codex.wordpress.org/Function_Reference/query_posts">query_posts()</a>;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat=4,5'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Todos los que esten en la categoria 4 y 5</span>
query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tag=mitag'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Los que tengan cierto tag...</span>
query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'meta_key=nombrekey&amp;amp;meta_value=valorkey'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Tenga un campo personalizado con dichos valores</span>
&nbsp;
 <span style="color: #000088;">$categoria</span><span style="color: #339933;">=</span><span style="color: #000088;">$cat</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// asignamos la actual categoria</span>
 <span style="color: #000088;">$query</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'cat='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$categoria</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;amp;orderby=date&amp;amp;order=ASC'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//ordenacion ascendente por fecha</span>
 query_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-609"></span><br />
Como veis, tenemos mucho con que jugar a la hora de configurar el contenido del loop de wordpress, una vez hecho podemos crear el loop, tiene la siguiente estructura:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//...</span>
<span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span>
<span style="color: #666666; font-style: italic;">//...</span>
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
wp_reset_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Importante reiniciar loop para que wordpress funcione como habitualmente</span></pre></div></div>

<p>Una vez dentro del loop podemos llamar a muchos valores de los posts, como por ejemplo el contenido, los tags, fecha, titulos, extracto, campos personalizados, la categoria&#8230; Aquí un ejemplo de como seria el código completo</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">query_posts('cat='.get_cat_ID('miCategoria')); //Establecemos el query con los posts de &quot;miCategoria&quot;
if (have_posts()) : while (have_posts()) : the_post();
     &lt;p&gt;&lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<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>&lt;/h1&gt;&lt;/p&gt;
     &lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_excerpt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> ?<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php the_content<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>&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$postMeta</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'metaKey'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$postMeta</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;<span style="color: #006699; font-weight: bold;">$key</span>  =&gt; <span style="color: #006699; font-weight: bold;">$value</span> ('metaKey')&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
endwhile; else:
    echo &quot;No se encontraron articulos relacionados, puede que le interese alguna de las siguientes categorias&quot;
&lt;ul&gt;
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_categories<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>
&lt;/ul&gt;
endif;
wp_reset_query();</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/configurar-el-loop-de-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Crear Plantillas de themes para post en WordPress</title>
		<link>http://www.johandebruin.com/crear-plantillas-de-themes-para-post-en-wordpress/</link>
		<comments>http://www.johandebruin.com/crear-plantillas-de-themes-para-post-en-wordpress/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 20:42:28 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Custom Values]]></category>
		<category><![CDATA[Plantilla]]></category>
		<category><![CDATA[Post meta]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[Wordpress API]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=599</guid>
		<description><![CDATA[Podemos crear una plantilla para publicar post especificos en wordpress de la misfa forma que ocurre con las páginas gracias a la combinación del uso de la API de wordpress y del plugin Custom Post Template. Lo que queremos conseguir es mostrar posts de distintas maneras en función a que plantilla seleccionamos en el menu [...]]]></description>
			<content:encoded><![CDATA[<p>Podemos crear una plantilla para publicar post especificos en wordpress de la misfa forma que ocurre con las páginas gracias a la combinación del uso de la API de wordpress y del plugin <a title="Plantilla Post WordPress" href="http://wordpress.org/extend/plugins/custom-post-template/">Custom Post Template</a>. Lo que queremos conseguir es mostrar posts de distintas maneras en función a que plantilla seleccionamos en el menu de post:</p>
<p><a href="http://www.johandebruin.com/wp-content/uploads/2010/06/post-template.jpg"><img src="http://www.johandebruin.com/wp-content/uploads/2010/06/post-template.jpg" alt="" title="post template" width="296" height="365" class="aligncenter size-full wp-image-600" /></a></p>
<p>Gracias a eso, y a un formato de recognición de templates de post, con que añadamos el siguiente comentario en el .php del theme de wordpress podremos definir un formato especifico para ese tipo de post (como añadir metas especificos, imagenes, colores, opciones etc&#8230; especifico), explotando más las posibilidades de wordpress.</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>
<span style="color: #666666; font-style: italic;">/*
Template Name Posts: nombrePlantilla
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><span id="more-599"></span><br />
Aqui un ejemplo de como podriamos adaptar esta plantilla usando comandos de la API de wordpress (lo tipico, llamada al header, titulos, contenido, campos personalizados.. ).</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>
<span style="color: #666666; font-style: italic;">/*
Template Name Posts: nombrePlantilla
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_header<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<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>
   &lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<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>&lt;/h1&gt;
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;p class=&quot;serif&quot;&gt;Leer el resto del post;&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   $postMeta = get_post_custom_values('metaKey');
   foreach ( $postMeta as $key =&gt; $value ) {
      echo &quot;$key  =&gt; $value ('metaKey')&lt;br /&gt;&quot;; 
   }
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/crear-plantillas-de-themes-para-post-en-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mostrar elementos ocultados con javascript</title>
		<link>http://www.johandebruin.com/mostrar-elementos-ocultados-con-javascript/</link>
		<comments>http://www.johandebruin.com/mostrar-elementos-ocultados-con-javascript/#comments</comments>
		<pubDate>Sat, 05 Jun 2010 17:55:26 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mostrar contenido]]></category>
		<category><![CDATA[ocultar contenido]]></category>
		<category><![CDATA[snnipet]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=593</guid>
		<description><![CDATA[Aquí una rápida pieza de código que permitira ocultar contenido para luego mostrarlo si así lo quiere el usuario. Empleamos javascript junto al reconocimiento DOM de elementos html para definir el contenido de un div. &#60;head&#62; &#60;script type=&#34;text/javascript&#34;&#62; function mostrar() { document.getElementById(&#34;contenedor&#34;).innerHTML = 'hola mundo'; } &#60;/script&#62; &#60;/head&#62; &#60;body&#62; &#60;a href=&#34;javascript://&#34; onclick=&#34;mostrar()&#34;&#62;Mostrar contenido del contenedor&#60;/a&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>Aquí una rápida pieza de código que permitira ocultar contenido para luego mostrarlo si así lo quiere el usuario. Empleamos javascript junto al reconocimiento DOM de elementos html para definir el contenido de un div.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;head&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
function mostrar()
{
	document.getElementById(&quot;contenedor&quot;).innerHTML = 'hola mundo';
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;a href=&quot;javascript://&quot; onclick=&quot;mostrar()&quot;&gt;Mostrar contenido del contenedor&lt;/a&gt;
&lt;div id=&quot;contenedor&gt;
&lt;!-- Este contenedo ahora mismo esta vacio --&gt;
&lt;/div&gt;</pre></div></div>

<p><span id="more-593"></span><br />
Y así de facil, únicamente tenemos que hacer referencia con el atributo de onclick a la función que insertara contenido al elemento que queramos mostrar, también sirve para cambiar de imagen, únicamente deberiamos usar el atributo de javascript document.getElementById(&#8220;contenedor&#8221;).src al hacer click a la imagen&#8230; </p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/mostrar-elementos-ocultados-con-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programacion orientada a objetos y diagramas UML en PHP</title>
		<link>http://www.johandebruin.com/programacion-orientada-a-objetos-y-diagramas-uml-en-php/</link>
		<comments>http://www.johandebruin.com/programacion-orientada-a-objetos-y-diagramas-uml-en-php/#comments</comments>
		<pubDate>Tue, 11 May 2010 06:10:48 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[clases]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[poo]]></category>
		<category><![CDATA[programacion orientada a objetos]]></category>
		<category><![CDATA[uml]]></category>
		<category><![CDATA[uml php]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=525</guid>
		<description><![CDATA[Una recopilación de como construir clases en PHP junto a un diagrama de la relación UML. Útil para ir obteniendo nociones sobre el modelado del código. Herencia Indica que una clase hereda todos los atributos y métodos de otra, hay que tener en cuenta que en el diagrama UML el triangulo toca al padre: class [...]]]></description>
			<content:encoded><![CDATA[<p>Una recopilación de como construir clases en PHP junto a un diagrama de la relación UML. Útil para ir obteniendo nociones sobre el modelado del código.</p>
<h3>Herencia</h3>
<p>Indica que una clase hereda todos los atributos y métodos de otra, hay que tener en cuenta que en el diagrama UML el triangulo toca al padre:</p>
<pre lang="php" style="float:left;width:420px">
class Senior {

}
class Junior extends Senior {

}
</pre>
<p><img style="float:right" src="http://www.johandebruin.com/wp-content/uploads/2010/05/herencia.gif" alt="herencia php" title="herencia php" width="102" height="179" class="aligncenter size-full wp-image-527" /><br />
<br style="clear: both" /><br />
<span id="more-525"></span></p>
<h3>Agregación</h3>
<p>Es cuando una clase puede es parte de otra, con lo cual esta primera clase tendrá acceso a los métodos de la segunda. Al haber sido instanciada fuera de la segunda, aunque esta muera la primera seguira viviendo. Se les conoce como clases &#8220;Data Access&#8221;, y se dice que la primera clase controla parte de la segunda. Se relacionan con un diamante que toca la clase controlada</p>
<pre lang="php" style="float:left;width:420px">
class Dao {
    function getSomething() {
    }
}
class Model {
    var $dao;
    function Model (&#038; $dao) {
        $this->dao=&#038; $dao;
    }
    function doSomething () {
        $this->dao->getSomething();
    }
}
$dao=new Dao;
$model=new Model($dao);
$model->doSomething();
</pre>
<p><img style="float:right" src="http://www.johandebruin.com/wp-content/uploads/2010/05/agregacionpoo.gif" alt="herencia php" title="herencia php" width="102" height="179" class="aligncenter size-full wp-image-527" /></p>
<p><br style="clear: both" /></p>
<h3>Composición</h3>
<p>Es cuando una clase instancia a otra, esta segunda instancia moriria con la primera, esto significa que la primera clase controla a toda la segunda, se representa con un solido diamante tocando a la clase controlada.</p>
<pre lang="php" style="float:left;width:420px">
class LinkWidget {
}
class View {
    var $linkWidget;
    var $page;
    function View () {
        $this->linkWidget=new LinkWidget;
    }
    function renderPage () {
        $this->page=$this->linkWidget->display()
    }
}
</pre>
<p><img style="float:right" src="http://www.johandebruin.com/wp-content/uploads/2010/05/composicionpooo.gif" alt="herencia php" title="herencia php" width="102" height="179" class="aligncenter size-full wp-image-527" /></p>
<p><br style="clear: both" /></p>
<h3>Mensajes</h3>
<p>Es cuando una clase comunica a otra que está controlando una instancia suya. En php suele emplearse el <a href="http://www.php.net/manual/en/keyword.paamayim-nekudotayim.php">operador scope</a>. Que sirve para hacer referencias a métodos de clases que no estan instanciadas.</p>
<pre lang="php" style="float:left;width:420px">
class HtmlUtils {
    function unHtmlEntities ($str) {
        $trans_tbl =
get_html_translation_table (HTML_ENTITIES);
        $trans_tbl = array_flip ($trans_tbl);
        return strtr ($str, $trans_tbl);
    }
}
class View {
    function renderPage {
        $text=HtmlUtils::unHtmlEntities($text);
    }
}
</pre>
<p><img style="float:right" src="http://www.johandebruin.com/wp-content/uploads/2010/05/mensajeUnidireccionalpoo.gif" alt="herencia php" title="herencia php" width="102" height="179" class="aligncenter size-full wp-image-527" /></p>
<p><br style="clear: both" /><br />
Existe otra variante de esta relación, donde el mensaje se envia mutuamente entre las dos clases, un ejemplo de código:</p>
<pre lang="php" style="float:left;width:420px">
class Debug {
    function display () {
        echo ($this->errorMsg);
    }
}
class SomeClass {
    var $errorMsg='This is an error message';
    function someFunction () {
        if ( DEBUG == 1 ) {
            Debug::display();
        }
    }
}
define ('DEBUG',1);
$someClass= &#038;new SomeClass;
$someClass->someFunction();
</pre>
<p><img style="float:right" src="http://www.johandebruin.com/wp-content/uploads/2010/05/bidireccionalpoo.gif" alt="bidireccional php" title="herencia php" width="102" height="179" class="aligncenter size-full wp-image-527" /></p>
<p><br style="clear: both" /></p>
<p>Fuente, <a href="http://www.phppatterns.com/docs/design/php_and_uml_class_diagrams">phppatterns</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/programacion-orientada-a-objetos-y-diagramas-uml-en-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Subir un archivo usando ftp con php</title>
		<link>http://www.johandebruin.com/subir-un-archivo-usando-ftp-con-php/</link>
		<comments>http://www.johandebruin.com/subir-un-archivo-usando-ftp-con-php/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 20:22:30 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Archivo]]></category>
		<category><![CDATA[ftp]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=433</guid>
		<description><![CDATA[Bueno, rebuscando entre mis códigos olvidados he encontrado este pequeño snnipet que puede salvarte la vida en más de una ocasión. Usar el ftp con php puede ser muy sencillo gracias a esta función, sus parametros son: $dir: ftp del servidor. $user: usuario del ftp $pass: contraseña $desde: ruta donde se localiza el archivo que [...]]]></description>
			<content:encoded><![CDATA[<p>Bueno, rebuscando entre mis códigos olvidados he encontrado este pequeño snnipet que puede salvarte la vida en más de una ocasión. Usar el ftp con php puede ser muy sencillo gracias a esta función, sus parametros son:</p>
<ul>
<li>$dir: ftp del servidor.</li>
<li>$user: usuario del ftp</li>
<li>$pass: contraseña</li>
<li>$desde: ruta donde se localiza el archivo que se desea subir</li>
<li>$hacia: ruta donde quieres alojar el archivo</li>
</ul>
<p><span id="more-433"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> subirFTP<span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #339933;">,</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span><span style="color: #000088;">$pass</span><span style="color: #339933;">,</span><span style="color: #000088;">$desde</span><span style="color: #339933;">,</span><span style="color: #000088;">$hacia</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	try
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idConn</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ftp_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">ftp_login</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConn</span><span style="color: #339933;">,</span><span style="color: #000088;">$user</span><span style="color: #339933;">,</span><span style="color: #000088;">$pass</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">ftp_put</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConn</span><span style="color: #339933;">,</span><span style="color: #000088;">$hacia</span><span style="color: #339933;">,</span><span style="color: #000088;">$desde</span><span style="color: #339933;">,</span>FTP_BINARY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">ftp_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConn</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	catch<span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$e</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</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: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/subir-un-archivo-usando-ftp-con-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrar jquery con wordpress</title>
		<link>http://www.johandebruin.com/integrar-jquery-con-wordpress/</link>
		<comments>http://www.johandebruin.com/integrar-jquery-con-wordpress/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 20:01:13 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[API wordpress]]></category>
		<category><![CDATA[header hook wordpress]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=312</guid>
		<description><![CDATA[WordPress permite gracias a su api usar códigos de jquery, con esta libreria de javascript permitirás establecer una nueva forma de funcionamiento de las páginas web. Para usar jquery tendremos que invocar su código contenido en un archivo .js gracias a una serie de funciones que wordpress nos proporciona. Para poder invocar el directorio del [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress permite gracias a su api usar códigos de jquery, con esta libreria de javascript permitirás establecer una nueva forma de funcionamiento de las páginas web. Para usar jquery tendremos que invocar su código contenido en un archivo .js gracias a una serie de funciones que wordpress nos proporciona.</p>
<p><a href="http://www.johandebruin.com/wp-content/uploads/2010/01/jquerybasico.gif"><img class="size-full wp-image-384 alignnone" title="jquery basico" src="http://www.johandebruin.com/wp-content/uploads/2010/01/jquerybasico.gif" alt="" width="806" height="387" /></a></p>
<p><span id="more-312"></span><br />
Para poder invocar el directorio del plugin, podemos usar el siguiente snnipet de wordpress:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$root_codigo</span> <span style="color: #339933;">=</span> trailingslashit<span style="color: #009900;">&#40;</span> WP_PLUGIN_URL<span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span> plugin_basename<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ahora que ya tenemos establecida la url de la base donde se mantendrán distintos códigos, (como el .js con el jquery), podemos decir a wordpress que incluya susodicho código entre sus códigos:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> codigo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'un_nombre_script'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$root_codigo</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/codigojquery.js'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//Linea de código para pasar parametros al jquery</span>
wp_localize_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'un_nombre_script'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'clase'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'algun_parametro'</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000ff;">'valor'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_print_scripts'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'codigo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Usamos wp_localize_script para pasar los parámetros a la función jquery, en este caso la ruta del plugin, si quisieramos acceder en el jquery a dicho parámetro podemos usar la clase que enviamos asi: <em>clase.algun_parametro</em>.</p>
<p>Por último, un ejemplo de la estructura que podria tener codigojquery.js:</p>

<div class="wp_syntax"><div class="code"><pre class="javascritp" style="font-family:monospace;">$(document).ready(function())
{
     $(&quot;a&quot;).click(function()
     {
          alert(&quot;Gracias por tu visita!&quot;);
     });
});</pre></div></div>

<p>Por último, aquí un video de introducción sobre jquery:<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="344" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/Hk5oXFtYLwE&amp;hl=es_ES&amp;fs=1" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="344" src="http://www.youtube.com/v/Hk5oXFtYLwE&amp;hl=es_ES&amp;fs=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/integrar-jquery-con-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actualizar tu feed de twitter con AJAX</title>
		<link>http://www.johandebruin.com/actualizar-tu-feed-de-twitter-con-ajax/</link>
		<comments>http://www.johandebruin.com/actualizar-tu-feed-de-twitter-con-ajax/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 12:43:13 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Programacion]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=183</guid>
		<description><![CDATA[Hoy con la nueva categoria AJAX os mostrare un código en AJAX que os permitira actualizar los mensajes de twitter sin tener que actualizar la página. Para ello, tendremos que dividir el código de programación en 2 archivos. el código de AJAX se mostrará en el archivo cliente, mientras que el código twitterfeed.php será de [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy con la nueva categoria AJAX os mostrare un código en AJAX que os permitira actualizar los mensajes de twitter sin tener que actualizar la página. Para ello, tendremos que dividir el código de programación en 2 archivos. el código de AJAX se mostrará en el <strong>archivo cliente</strong>, mientras que el código <strong>twitterfeed.php </strong>será de donde obtendrá los nuevos feed el código en AJAX.<br />
<span id="more-183"></span><br />
Primero definiremos el código javascript necesario para poder actualizar el feed de twitter. Emplazaremos este código junto al resto de código javascript de la página (orden porfavor).</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #006600; font-style: italic;">//Primero creamos el objeto XMLHttpRequest que nos permite establecer conexiones HTTP</span>
xmlhttp <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> XMLHttpRequest<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #006600; font-style: italic;">//Con esta función actualizamos el contenido de cualquier div con el de algún archivo</span>
<span style="color: #003366; font-weight: bold;">function</span> makerequest<span style="color: #009900;">&#40;</span>serverPage<span style="color: #339933;">,</span> objID<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> obj <span style="color: #339933;">=</span> document.<span style="color: #660066;">getElementById</span><span style="color: #009900;">&#40;</span>objID<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    xmlhttp.<span style="color: #000066;">open</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;GET&quot;</span><span style="color: #339933;">,</span> serverPage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    xmlhttp.<span style="color: #660066;">onreadystatechange</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>xmlhttp.<span style="color: #660066;">readyState</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">4</span> <span style="color: #339933;">&amp;&amp;</span> xmlhttp.<span style="color: #000066;">status</span> <span style="color: #339933;">==</span> <span style="color: #CC0000;">200</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            obj.<span style="color: #660066;">innerHTML</span> <span style="color: #339933;">=</span> xmlhttp.<span style="color: #660066;">responseText</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    xmlhttp.<span style="color: #660066;">send</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Ahora, debemos definir el código HTML, la primera vez que mostremos el feed de twitter lo haremos con PHP con tal de que los buscadores puedan rastrearlo, luego usaremos un botón para actualizar el feed usando AJAX y el usuario no tenga que estar refresando la página web.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;ul&gt;
    &lt;div id=&quot;twitterfeed&quot;&gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;twitterfeed.php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/div&gt;
&lt;/ul&gt;
&lt;center&gt;&lt;input type=&quot;button&quot; onclick=&quot;makerequest('twitterfeed.php','twitterfeed')&quot; value=&quot;Actualizar&quot;&gt;&lt;/center&gt;</pre></div></div>

<p>Ahora solo nos queda crear <strong>twitterfeed.php</strong>, para ello usaremos una función que ya publique con anterioridad: <a title="feed twitter php" href="http://www.johandebruin.com/mostrar-feed-de-busqueda-en-twitter/">Mostrar feed de busqueda en twitter</a></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> twitterfeed<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;li&gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'johandebruin'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'5'</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>Y con esto queda terminado el código, podeis verlo funcionando en esta página web: <a href="http://www.blognexusone.es">Blog nexus one</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/actualizar-tu-feed-de-twitter-con-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clase de conexión a Bases datos php</title>
		<link>http://www.johandebruin.com/clase-de-conexion-a-bases-datos-php/</link>
		<comments>http://www.johandebruin.com/clase-de-conexion-a-bases-datos-php/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 23:38:16 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Bases datos]]></category>
		<category><![CDATA[Clases php]]></category>
		<category><![CDATA[Programacion]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=176</guid>
		<description><![CDATA[Con esta clase de php, te facilitará la tarea de conectarte a las bases de datos, resumiendo en unas pocas líneas de código la interconexión con la base de datos en mysql. La forma de uso es la siguiente: //Parametros del constructor: host, user, pass, tabla $bd = new datos&#40;&#34;localhost&#34;,&#34;root&#34;,&#34;&#34;,&#34;bd&#34;&#41;; //la función obtener uno extrae [...]]]></description>
			<content:encoded><![CDATA[<p>Con esta <strong>clase de php</strong>, te facilitará la tarea de conectarte a las <strong>bases de datos</strong>, resumiendo en unas pocas líneas de código la interconexión con la base de datos en mysql. La forma de uso es la siguiente:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//Parametros del constructor: host, user, pass, tabla</span>
<span style="color: #000088;">$bd</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> datos<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;bd&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//la función obtener uno extrae un string directamente con el primer resultado</span>
<span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">obtenerUno</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT MAX(columna) FROM tabla&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//La función obtener devuelve una matriz de mysql</span>
<span style="color: #000088;">$matriz</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">obtener</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT columna FROM tabla&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fila</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$matriz</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$fila</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'columna'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//La función insertar es para insertar o editar columnas, devuelve el numero de filas afectadas</span>
<span style="color: #000088;">$filasAfectadas</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$bd</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insertar</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;INSERT INTO tabla VALUES ('a','b')&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-176"></span><br />
La clase de php en cuestión 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>
<span style="color: #000000; font-weight: bold;">class</span> datos
<span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">/* Clase de conexion a bases de datos con php
Creado por johandebruin.com en 02-01-2010 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$server</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$user</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$pass</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$bd</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Funcion generica que devuelve una conexion a la BD</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> conectar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idConexion</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span><span style="color: #339933;">,</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pass</span><span style="color: #009900;">&#41;</span>
			or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No fue posible conectar con la base de datos, intentelo mÃ¡s tarde&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bd</span><span style="color: #339933;">,</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #339933;">@</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SET NAMES 'utf8'&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$idConexion</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Establecemos los parametros</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$servidor</span><span style="color: #339933;">,</span><span style="color: #000088;">$usuario</span><span style="color: #339933;">,</span><span style="color: #000088;">$contra</span><span style="color: #339933;">,</span><span style="color: #000088;">$baseDatos</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">server</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$servidor</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$usuario</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">pass</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$contra</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bd</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$baseDatos</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Obtenemos una matriz de datos, false si no existen</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> obtener<span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idConexion</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conectar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$datos</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: #339933;">,</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$datos</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$datos</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Obtenemos un solo resultado, o en su mayorecto el primero, false en su defecto</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> obtenerUno<span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idConexion</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conectar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$datos</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: #339933;">,</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$datos</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_result</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$datos</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//Devuelve el numero de filas afectadas</span>
	<span style="color: #000000; font-weight: bold;">function</span> insertar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$consulta</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$idConexion</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">conectar</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$respuesta</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: #339933;">,</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_affected_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$idConexion</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$i</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/clase-de-conexion-a-bases-datos-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Funcion extraer subcadena php</title>
		<link>http://www.johandebruin.com/funcion-extraer-subcadena-php/</link>
		<comments>http://www.johandebruin.com/funcion-extraer-subcadena-php/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 10:47:02 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cadena]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[subcadena]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=167</guid>
		<description><![CDATA[Esta función de PHP la cree hace tiempo, su finalidad es la de extraer una subcadena de una cadena o string en PHP. Además, puedes indicar la itineración para que no extraiga la primera subcadena que encuentre. Es extremadamente útil a la hora de manejar strings en HTML. Los parámetros son los siguientes: $cadena: la [...]]]></description>
			<content:encoded><![CDATA[<p>Esta función de PHP la cree hace tiempo, su finalidad es la de extraer una <strong>subcadena </strong>de una cadena o string en PHP. Además, puedes indicar la itineración para que no extraiga la primera <strong>subcadena </strong>que encuentre. Es extremadamente útil a la hora de manejar strings en <strong>HTML</strong>. Los parámetros son los siguientes:</p>
<ul>
<li>$<strong>cadena</strong>: la cadena que se va a evaluar</li>
<li>$<strong>antes</strong>: lo que aparece antes de la subcadena que se quiere extraer</li>
<li>$<strong>despues</strong>: lo que aparece después de la subcadena que se quiere extraer</li>
<li>$<strong>cuenta</strong>: el número de veces que se tiene que repetir la coincidencia hasta devolver la subcadena</li>
</ul>
<p>Ejemplo:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$cadena</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Esto es una lista..&lt;ul&gt;&lt;li&gt;Hola mundo&lt;/li&gt; &lt;li&gt;Hola mundo2&lt;/li&gt;&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Primera subcadena: &quot;</span> <span style="color: #339933;">.</span>extraer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&lt;li&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Segunda subcadena: &quot;</span> <span style="color: #339933;">.</span>extraer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&lt;li&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&lt;/li&gt;&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-167"></span><br />
Y aquí esta la función deseada:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> extraer<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #000088;">$antes</span><span style="color: #339933;">,</span><span style="color: #000088;">$despues</span><span style="color: #339933;">,</span><span style="color: #000088;">$cuenta</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">/*Función para obtener extraer una subcadena
	Creado por johandebruin.com el 29-12-2009*/</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$cuenta</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">//Ponemos en minuscula todo para optimizar el algoritmo;</span>
	<span style="color: #000088;">$cadena</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$antes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$antes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$despues</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$despues</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$localizacion1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$localizacion2</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">do</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$localizacion1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #000088;">$antes</span><span style="color: #339933;">,</span><span style="color: #000088;">$localizacion1</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$localizacion1</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$cuenta</span><span style="color: #339933;">--;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$cuenta</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$localizacion2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span> <span style="color: #000088;">$despues</span><span style="color: #339933;">,</span> <span style="color: #000088;">$localizacion1</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$localizacion2</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$localizacion1</span> <span style="color: #339933;">+=</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$antes</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cadena</span><span style="color: #339933;">,</span><span style="color: #000088;">$localizacion1</span><span style="color: #339933;">,</span><span style="color: #000088;">$localizacion2</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$localizacion1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/funcion-extraer-subcadena-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redireccionar url sin www con php</title>
		<link>http://www.johandebruin.com/redireccionar-url-sin-www-con-php/</link>
		<comments>http://www.johandebruin.com/redireccionar-url-sin-www-con-php/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 19:45:34 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[SEO]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=50</guid>
		<description><![CDATA[Bueno, el contenido duplicado es uno de mis mayores problemas como SEO. He pasado muchas horas buscando nuevos métodos para intentar reducir el número de páginas indexadas de algunos portales. Uno de los códigos que más he buscado ha sido para redireccionar las páginas sin www a uno que si lo lleve: De http://url.com a [...]]]></description>
			<content:encoded><![CDATA[<p>Bueno, el <strong>contenido duplicado </strong>es uno de mis mayores problemas como <strong>SEO</strong>. He pasado muchas horas buscando nuevos métodos para intentar <strong>reducir el número de páginas indexadas </strong>de algunos portales. Uno de los códigos que más he buscado ha sido para redireccionar las páginas sin www a uno que si lo lleve:</p>
<p style="text-align: center;">
<em>De http://url.com a http://www.url.com</em></p>
<p><span id="more-50"></span><br />
En fin, leyendo el libro &#8220;guia de referencia SEO&#8221; de <strong><a href="http://www.ojobuscador.com/">ojobuscador </a></strong>encontre un código que me gusto mucho, este se concentra en detectar si la url contiene el www y si no redirecciona a la URL correcta con una <strong>redirección 301</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span>“HTTP_HOST”<span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> “www<span style="color: #339933;">.</span>dominio<span style="color: #339933;">.</span>ext”<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> “http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.dominio.ext”.$_SERVER[“REQUEST_URI”];</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span>“HTTP<span style="color: #339933;">/</span><span style="color:#800080;">1.1</span> <span style="color: #cc66cc;">301</span> Moved Permanently”<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span>“Location<span style="color: #339933;">:</span> <span style="color: #000088;">$url</span>”<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/redireccionar-url-sin-www-con-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
