<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4060951526192778689</id><updated>2025-03-11T01:31:20.917-06:00</updated><category term="PostSystem"/><category term="código"/><category term="php"/><category term="posteo"/><category term="reutilizable"/><category term="sistema"/><category term="clase"/><category term="compatible"/><category term="css"/><category term="custom"/><category term="documentación"/><category term="file"/><category term="input"/><category term="introduccion"/><category term="manual"/><category term="personalizar"/><category term="solamente"/><title type='text'>ACY: Diseño y Programación Web: Tutoriales, Tips, Código reutilizable y Herramientas.</title><subtitle type='html'>Aprende como programar y diseñar páginas web desde básico hasta avanzado.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://aprendecomoyo.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4060951526192778689/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://aprendecomoyo.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Angel</name><uri>http://www.blogger.com/profile/17672315673365813323</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4060951526192778689.post-5284255019495533772</id><published>2012-01-31T16:20:00.001-06:00</published><updated>2012-02-04T16:17:39.713-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="código"/><category scheme="http://www.blogger.com/atom/ns#" term="documentación"/><category scheme="http://www.blogger.com/atom/ns#" term="manual"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="posteo"/><category scheme="http://www.blogger.com/atom/ns#" term="PostSystem"/><category scheme="http://www.blogger.com/atom/ns#" term="reutilizable"/><category scheme="http://www.blogger.com/atom/ns#" term="sistema"/><title type='text'>Sistema de posteo en PHP - Código y Documentación</title><content type='html'>&lt;div class=&quot;spoiler&quot;&gt;
&lt;div class=&quot;spoiler-title&quot;&gt;
Spoiler - Código clase PostSystem&lt;/div&gt;
&lt;div class=&quot;spoiler-content&quot;&gt;
&lt;textarea class=&quot;codigo&quot; readonly=&quot;readonly&quot; cols=&quot;75&quot; rows=&quot;30&quot; wrap=&quot;off&quot; style=&quot;max-height: none&quot;&gt;
&lt;?php
/*
    AngelFcM - Domingo, 29 de enero de 2012.
*/
class PostSystem {
    # Propiedades públicas
    var $dblink= &quot;&quot;;
    var $last_post= &quot;&quot;;
    var $last_error= &quot;&quot;;
    # /Propiedades públicas
    # Propiedades privadas
    private $pvt_tbposts_info= array(
        &quot;name&quot; =&gt; &quot;tb_posts&quot;,
        &quot;fields&quot; =&gt; array(
            &quot;id&quot;,
            &quot;author&quot;,
            &quot;title&quot;,
            &quot;snippet&quot;,
            &quot;content&quot;,
            &quot;type&quot;,
            &quot;parent_id&quot;,
            &quot;date_created&quot;,
            &quot;date_modified&quot;
        ),
        &quot;script&quot; =&gt; &quot;
            CREATE TABLE IF NOT EXISTS tb_posts(
                id INT NOT NULL AUTO_INCREMENT,
                author VARCHAR(50),
                title VARCHAR(100),
                snippet VARCHAR(255),
                content TEXT,
                type VARCHAR(20),
                parent_id INT,
                date_created DATETIME,
                date_modified DATETIME,
                PRIMARY KEY(id, author, parent_id)
            )
        &quot;
    );
    private $pvt_config_select= array(
        &quot;mode&quot; =&gt; 0
        ,&quot;fields&quot; =&gt; &quot;*&quot;
        ,&quot;get_children&quot;=&gt; true 
        ,&quot;limit&quot; =&gt; &quot;&quot;
        ,&quot;limit_children&quot; =&gt; &quot;&quot;
    );
    private $pvt_req_data= array(
        &quot;author&quot; =&gt; &quot;&quot;
        ,&quot;title&quot; =&gt; &quot;&quot;
        ,&quot;snippet&quot; =&gt; &quot;&quot;  
        ,&quot;content&quot; =&gt; &quot;&quot;
        ,&quot;type&quot; =&gt; &quot;&quot;
    );
    # /Propiedades privadas
    # Funciones privadas
    private function recursive_select($q, $config) {
        $data= array();
        while( $r= mysql_fetch_array($q) ) {
            $subq= mysql_query(&quot;
                SELECT &quot;.$config[fields].&quot; FROM tb_posts WHERE parent_id= &#39;&quot;.$r[id].&quot;&#39; &quot;.$config[q2_limit].&quot; ORDER BY date_created
            &quot;);
            if( !$subq ) {
                $this-&gt;last_error= &quot;Error en la consulta. En private recursive_select().&lt;br&gt;&quot;.mysql_error();
                return false;
            }
            if( mysql_num_rows($subq) &amp;&amp; $config[get_children] ) {
                $r[&quot;children&quot;]= $this-&gt;recursive_select($subq, $config);
            }
            $data[]= $r;
        }
            return $data;
    }
    private function recursive_foreachPost($children, $user_func, $user_var= &quot;&quot;) {
        foreach( $children as $post ) {
            $html= array();
            $html[container][0]= &#39;&lt;div class=&quot;&#39;.$post[type].&#39;&quot;&gt;&#39;;
            $html[container][1]= &#39;&lt;/div&gt;&#39;;
            $keys= array_keys($post);
            for($i=0; $i&lt;count($keys); $i++) {
                $k= $keys[$i];
                if( $k!=$post[type] ) {
                    $css_class= $post[type].&quot;-&quot;.preg_replace(&quot;/_/&quot;, &quot;-&quot;, $k);
                    $html[$k][0]= &#39;&lt;div class=&quot;&#39;.$css_class.&#39;&quot;&gt;&#39;;
                    $html[$k][1]= &#39;&lt;/div&gt;&#39;;
                }
            }
            call_user_func($user_func, $post, true, $html, &amp;$user_var);
            if( $post[children] ) {
                $this-&gt;recursive_foreachPost($post[children], $user_func, &amp;$user_var);
            }
            call_user_func($user_func, $post, false, $html, &amp;$user_var);
        }
    }
    private function recursive_delete($parent_id) {
        $q= mysql_query(&quot;
            SELECT id FROM tb_posts WHERE parent_id=&#39;$parent_id&#39;
        &quot;, $this-&gt;dblink);
        if ( mysql_num_rows($q) ) {
            mysql_query(&quot;
                DELETE FROM tb_posts WHERE parent_id=&#39;$parent_id&#39;
            &quot;, $this-&gt;dblink);
            while( $r= mysql_fetch_array($q) ) {
                $this-&gt;recursive_delete($r[id]);
            }
        }
    }
    private function joinKeyValue($arr) {
        function joinKeyValue($value, $key, $result) {
            $result.= &quot; &quot;.$key.&quot;=&quot;.($value?&quot;&#39;&quot;.$value.&quot;&#39;&quot;:&quot;default&quot;).&quot;, &quot;;
        }
        $result= &quot;&quot;;
        array_walk($arr, &quot;joinKeyValue&quot;, &amp;$result);
        $result= preg_replace(&quot;/(, )$/&quot;, &quot; &quot;, $result);
        return $result;
    }
    private function checkDB() {
        $q= mysql_query( $this-&gt;pvt_tbposts_info[script], $this-&gt;dblink);
        if( !$q ) {
            echo &quot;Error al conectar con la base de datos o el host de la misma.&lt;br /&gt;&quot;.mysql_error();
            exit;
        }
    }
    # /Funciones privadas
    # Constructor
    function __construct($dblink) {
        $this-&gt;dblink= $dblink;
        $this-&gt;checkDB();
    }
    # /Constructor
    # Funciones públicas
    function insert( $data ) {
        $pvtdata= $this-&gt;pvt_req_data;
        if( !is_array($data) || (count(array_intersect_key($data, $pvtdata)) &lt; count($pvtdata)) ) {
            $this-&gt;last_error= &quot;No hay matriz de datos o faltan datos. Parametro1 En insert().&quot;;
            return false;
        }
        if( !$data[date_created] ) {
            $data[date_created]= date(&quot;Y-m-d H:i:s&quot;);
        }
        if( !$data[date_modified] ) {
            $data[date_modified]= &quot;0000-00-00 00:00:00&quot;;
        }
        $qdata= $this-&gt;joinKeyValue($data);
        if( !isset($data[id]) ) {
            $qdata.= &quot;, id= default &quot;;
        }
        if( !isset($data[parent_id]) ) {
            $data[parent_id]= &quot;&quot;;
            $qdata.= &quot;, parent_id=default &quot;;
        }
        $q= mysql_query(&quot;INSERT INTO tb_posts SET $qdata&quot;, $this-&gt;dblink);
        if( !$q ) {
             $this-&gt;last_error= &quot;Error en la primera consulta. En insert().&lt;br /&gt;&quot;.mysql_error();
             return false;
        }
        $q= mysql_query(&quot;SELECT max(id) FROM tb_posts&quot;, $this-&gt;dblink);
        if( !$q ) {
            $this-&gt;last_error= &quot;Error en la última consulta en insert().&lt;br /&gt;&quot;.mysql_error();
            return false;
        }
        $data[id]= mysql_result($q, 0);
        $this-&gt;last_post= $data;
        return true;
    }
    function select( $id_or_type, $config= &quot;&quot; ) {
        if( !$config ) {
            $config= $this-&gt;pvt_config_select;
        }
        if( !is_string($id_or_type) &amp;&amp; !is_int($id_or_type) ) {
            $this-&gt;last_error= &quot;El indentificador es incorrecto o no hay. Parametro1 en select().&quot;;
            return false;
        }
        if( count(array_intersect_key($config, $this-&gt;pvt_config_select)) != count($this-&gt;pvt_config_select) ) {
            $this-&gt;last_error= &quot;La configuración es incorrecta, faltan datos en select().&quot;;
            return false;
        }
        if ( $config[limit] &amp;&amp; !($config[limit]&gt;0) || $config[limit_children] &amp;&amp; !($config[limit_children]&gt;0) ) {
            $this-&gt;last_error= &quot;El limite de posts padres/hijos establecido es incorrecto en select().&quot;;
            return false;
        }
        switch($config[mode]) {
            case 0: $q_mode= &quot; WHERE id=&#39;$id_or_type&#39;&quot;;break;
            case 1: $q_mode= &quot; WHERE parent_id=&#39;$id_or_type&#39;&quot;;break;
            case 2: $q_mode= &quot; WHERE type=&#39;$id_or_type&#39;&quot;;break;
        }
        $config[q_limit]= $config[limit]? &quot;LIMIT &quot;.$config[limit] :  &quot;&quot;;
        $config[q2_limit]= $config[limit_children]? &quot;LIMIT &quot;.$config[limit_children] : &quot;&quot;;
        $q= mysql_query(&quot;
            SELECT &quot;.$config[fields].&quot; FROM tb_posts $q_mode &quot;.$config[q_limit].&quot; ORDER BY date_created
        &quot;);
        if( !$q ) {
            $this-&gt;last_error= &quot;Error en la consulta. En select().&lt;br /&gt;&quot;.mysql_error();
            return false;
        }
        if( !mysql_num_rows($q) ) {
            return false;
        }
        $post_data= $this-&gt;recursive_select($q, $config);
        return $post_data;
    }
    function foreachPost($post_data, $user_func= &quot;&quot;, $user_var= &quot;&quot;) {
        if( !function_exists($user_func) ) {
            $this-&gt;last_error= &quot;La función para recibir los datos no es válida, debe pasarse como cadena. Parametro2 en foreachPost().&quot;;
            return false;
        }
        if( !is_array($post_data) ) {
            $this-&gt;last_error= &quot;No hay matriz de datos. Parametro 1 en foreachPost().&quot;;
            return false;
        }
        if( count(array_intersect_key($post_data, $this-&gt;pvt_tbposts_info[fields])) == 0 ) {
                $this-&gt;last_error= &quot;La matriz de datos es incorrecta. Parametro1 En foreachPost().&quot;;
                return false;
        }
        $this-&gt;recursive_foreachPost($post_data, $user_func, &amp;$user_var);
        return true;
    }
    function delete($id, $delete_children= false) {
        $q= mysql_query(&quot;
            DELETE FROM tb_posts WHERE id=&#39;$id&#39;
        &quot;, $this-&gt;dblink);
        if( !$delete_children ) {
            return true;
        }
        $this-&gt;recursive_delete($id);
        return true;
    }
    function update($id, $data) {
        $pvtdata= $this-&gt;pvt_req_data;
        $pvtdata[id]=&quot;&quot;;
        if( !is_array($data) ) {
            $this-&gt;last_error= &quot;No hay matriz o faltan datos. Parametro1 En update().&quot;;
            return false;
        }
        if( !$data[date_modified] ) {
            $data[date_modified]=  date(&quot;Y-m-d H:i:s&quot;);
        }
        $result= $this-&gt;joinKeyValue($data);
        $q= mysql_query(&quot;UPDATE tb_posts SET&quot;.$result.&quot; WHERE id=&#39;&quot;.$id.&quot;&#39;&quot;, $this-&gt;dblink);
        if( !$q ) {
            $this-&gt;last_error= &quot;Error en la primera consulta de update().&lt;br /&gt;&quot;.mysql_error();
            return false;
        }
        if( !$data[id] ) {
            return true;
        }
        $q= mysql_query(&quot;UPDATE tb_posts SET parent_id=&#39;&quot;.$data[id].&quot;&#39; WHERE parent_id=&#39;&quot;.$id.&quot;&#39;&quot;, $this-&gt;dblink);
        if( !$q ) {
            $this-&gt;last_error= &quot;Error en la segunda consulta de update().&lt;br /&gt;&quot;.mysql_error();
            return false;
        }
        return true;
    }
    function selectParent($parent_id, $parent_type, $fields=&quot;*&quot;) {
        if ( empty($parent_id) || !is_int($parent_id) &amp;&amp; !is_string($parent_id) ) {
            $this-&gt;last_error= &quot;Parámetro1 incorrecto, debe ser un número o cadena. En selectParent().&quot;;
            return false;
        }
        $q= mysql_query(&quot;SELECT type, id, parent_id FROM tb_posts WHERE id=&#39;&quot;.$parent_id.&quot;&#39;&quot;, $this-&gt;dblink);
        if( !q ) {
            return &quot;&quot;;
        }
        $post= mysql_fetch_array($q);
        if( $post[type]==$parent_type ) {
            $q= mysql_query(&quot;SELECT &quot;.$fields.&quot; FROM tb_posts WHERE id=&#39;&quot;.$parent_id.&quot;&#39;&quot;, $this-&gt;dblink);
            if( !$q ) {
                $this-&gt;last_error(&quot;Error en consulta2 en selectParent().&lt;br/&gt;&quot;.mysql_error());
                return false;
            }
            $parent_post= mysql_fetch_array($q);
            return $parent_post;
        } else {
            return $this-&gt;selectParent($post[parent_id], $parent_type, $fields);
        }
    }
    # /Funciones públicas
}
?&gt;&lt;/textarea&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;spoiler&quot;&gt;
&lt;div class=&quot;spoiler-title&quot;&gt;
Spoiler - Documentación de PostSystem&lt;/div&gt;
&lt;div class=&quot;spoiler-content&quot;&gt;&lt;div class=&quot;codigo&quot; style=&quot;max-height: none;&quot;&gt;
&lt;br /&gt;
AngelFcM - Domingo, 29 de enero de 2012.&lt;br /&gt;
&lt;br /&gt;
Creación de un sistema de posteo en una sola clase PHP.&lt;br /&gt;
&lt;br /&gt;
Introducción&lt;br /&gt;
&lt;br /&gt;
Me he dedicado a realizar una clase llamada PostSystem en PHP que funciona con MySQL, con el fin&lt;br /&gt;
de facilitar el desarrollo de una interfaz para un sistema de posteo.&lt;br /&gt;
&lt;br /&gt;
Con esta clase pueden ingeniarselas para realizar desde una simple página de comentarios, un blog,&lt;br /&gt;
hasta uno o &amp;nbsp;más foros llenos de temas que responder o comentar, depende tu dedicación y&lt;br /&gt;
experiencia.&lt;br /&gt;
&lt;br /&gt;
Esta clase cuenta con cuatro funciones y tres propiedades, las funciones básicamente se encargan de&lt;br /&gt;
realizar INSERT, SELECT, UPDATE y DELETE pero de forma más compleja.&lt;br /&gt;
&lt;br /&gt;
Los posts se guardan en una tabla de la base de datos creada automáticamente si esque no existe.&lt;br /&gt;
La forma como funciona el sistema de posteo es familiarizando a los posts como padres e hijos y &quot;los&lt;br /&gt;
hijos de los hijos...&quot; usando dos indentificadores por post, uno el cuál identifica al post y otro para&lt;br /&gt;
hacer referencia a un post superior (si es que lo hay). En resumen, usa métodos recursivos para llegar&lt;br /&gt;
hasta el final de cada nodo.&lt;br /&gt;
&lt;br /&gt;
Requiere de la conexión y selección a una base de datos MySQL previamente. La tabla es llamada&lt;br /&gt;
&quot;tb_posts&quot;, las columnas son: &quot;id&quot;, &quot;author&quot;, &quot;title&quot;, &quot;snippet&quot;, &quot;content&quot;, &quot;type&quot;, &quot;parent_id&quot;,&lt;br /&gt;
&quot;date_created&quot; y &quot;date_modified&quot;.&lt;br /&gt;
&lt;br /&gt;
Debería entenderse el propósito de cada columna logicamente por el nombre de ellas. Explicaré la&lt;br /&gt;
columna &quot;parent_id&quot; ya que es la base en como trabaja este sistema de posteo.&lt;br /&gt;
&lt;br /&gt;
La columna &quot;parent_id&quot; es un identificador el cual hace referencia al &quot;id&quot; de otro post, así es como se&lt;br /&gt;
familiarizan como padres e hijos.&lt;br /&gt;
&lt;br /&gt;
Si tengo un post con id=1 y parent_id=2, entonces el post con id=1 es &quot;hijo&quot; del post con id=2.&lt;br /&gt;
&lt;br /&gt;
Documentación&lt;br /&gt;
&lt;br /&gt;
- Tabla MySQL&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - tbposts&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Es la única tabla necesaria para que trabaje la clase, en la cual se guardan los datos de los posts.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; El script para crear la tabla se puede notar al inicio del código de la clase.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Columnas&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - id: Identificador del post.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - author: Nombre del creador del post.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - title: Título del post.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - snippet: Fragmento del contenido del post.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - content: Contenido del post.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - type: Tipo del post definido por el desarrollador. Ejemplo de tipos: entrada, comentario, cita.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - parent_id: Identificador al que se enlaza el post jerárquicamente. Ejemplo: el id de &quot;X&quot; entrada es 12, el parent_id de &quot;Y&quot; comentario es 12.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - date_create: fecha de creación del post, la fecha es establecida por PHP no por MySQL.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - date_modified: fecha de modificación del post, igualmente establecida por PHP.&lt;br /&gt;
&lt;br /&gt;
- Clase&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - SystemPost($dblink)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Nombre para llamar a la clase del sistema de posteo.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Parámetros&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $dblink: enlace al origen de la base de datos creada con mysql_connect(). Importante seleccionar la base de datos antes de crear el objeto de la clase.&lt;br /&gt;
&lt;br /&gt;
- Propiedades&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - dblink&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Enlace al origen de la base de datos creada con mysql_connect().&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - last_post&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Contiene toda la información del último post creado en el objeto al llamar -&amp;gt;create() en un array asociativo a las columnas de la tabla de la db.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - last_error&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Guarda el último error generado al llamar un método. Si el método retorna false se almacena la causa del error en esta propiedad.&lt;br /&gt;
&lt;br /&gt;
- Métodos&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - insert($data)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Crea un nuevo post en la tabla tb_posts basados en los valores dados en $data. Devuelve true en caso de exito y false en caso de error, el cual se guarda en la propiedad last_error.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Parámetros&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $data: debe ser un array asociativo que contiene los datos del nuevo post, debe contener al menos el título, contenido, fragmento y tipo de post si no se definen las fechas e identificadores, se crean automáticamente.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Los vectores tienen el mismo nombre que las columnas de la tabla tb_posts.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - select($id_or_type, $config)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Selecciona uno o más posts en base a la información pasada como parámetros ordenados del primero al último creado. Devuelve un array asociativo con los datos de posts en arrays separados, si hubo un error devuelve false.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Los posts pueden contener posts jeraquicamente inferiores, por lo tanto son introducidos dentro del array del post &quot;padre&quot; en un array asociado como &quot;children&quot;. Un ejemplo al seleccionar dos posts que contienen más posts es:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; array(&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; array(&quot;id&quot;=&amp;gt;&quot;1&quot;, &quot;title&quot;=&amp;gt;&quot;&quot;, &quot;children&quot;=&amp;gt;array(...)),&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; array(&quot;id&quot;=&amp;gt;&quot;2&quot;, &quot;title&quot;=&amp;gt;&quot;&quot;, &quot;children&quot;=&amp;gt;array(...)),&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Puede definirse como nodos que contienen más nodos los cuales son posts.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Parámetros&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $id_or_type: puede ir el identificador del post o el tipo de posts que se quieren seleccionar&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $config: es un array asociativo que indica como se obtendran los posts, si no se pone nada, se establece de forma predeterminada, pero si se establece, debe contener todos los valores asociativos. A continuación se explican.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;mode&quot;:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Puede ser 0, 1 o 2.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Al establecer 0, se selecciona el post con el id pasado en $id_or_type.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Si es 1, se seleccionan todos los posts que sean hijos al post con id igual al pasado en $id_or_type, es decir, &quot;WHERE parent_id=$id_or_type&quot;.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Si se establece 2, obtendrá todos los posts de un mismo tipo que sea igual al valor de $id_or_type.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;fields&quot;:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Son los campos que se obtendran de la tabla tb_posts los cuales serán devueltos asotiativamente en un array, deben estar separados por coma, pueden usarse selectores como &quot;*&quot; ya que &quot;fields&quot; es parte de la consulta, es decir, va despues de &quot;SELECT&quot;.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;get_children&quot;:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Puede ser true o false.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Si se pasa true, obtendrá todos los posts &quot;hijos&quot; del post o posts solicitados, también obtendrá los hijos de los hijos recursivamente. Si se pone false, solo seleccionará los posts con el indentificador pasado en $id_or_type. Ya sea por id, parent_id o type.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;limit&quot;:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Establece el límite de posts a seleccionar. Pero si el post seleccionado contiene &quot;hijos&quot;, obtendrá todos.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &quot;limit_children&quot;:&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Establece el límite de posts hijos en caso de haber. También aplica a los hijos de los hijos.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;br /&gt;
&amp;nbsp; &amp;nbsp; - update($id, $data)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Actualiza/modifica la información de un post existente.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Parámetros&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $id: Es el indentificador del post a actualizar/modificar.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $data: Es un array asociativo con los datos que serán modificados, si se modifica el identificador del post, automaticamente a los posts &quot;hijos&quot; se les cambiará el parent_id por el nuevo id del post.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - delete($id, $delete_children)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Borra el post con el identificador asignado y puede borrar a todos los posts hijos.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Parámetros&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $id: Indentificador del post a borrar.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $delete_children: booleano, si es true, se borraran todos los posts hijos y los hijos de los hijos. Si es false o no se pone nada, entonces solo se borra el post con el identificador asignado y sus hijos quedarán intactos.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - selectParent($id, $type, $fields)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Selecciona el post padre del post con el id definido con el tipo de post definido.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Parámetros&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $id: Indetificador del post, para obtener el post padre del mismo.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $type: Tipo de post padre que se obtendrá.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $fields: campos o datos que se obtendrán del post padre, separados por coma&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprendecomoyo.blogspot.com/feeds/5284255019495533772/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://aprendecomoyo.blogspot.com/2012/01/sistema-de-posteo-en-php-codigo-y.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4060951526192778689/posts/default/5284255019495533772'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4060951526192778689/posts/default/5284255019495533772'/><link rel='alternate' type='text/html' href='http://aprendecomoyo.blogspot.com/2012/01/sistema-de-posteo-en-php-codigo-y.html' title='Sistema de posteo en PHP - Código y Documentación'/><author><name>Angel</name><uri>http://www.blogger.com/profile/17672315673365813323</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4060951526192778689.post-6020236983493755451</id><published>2012-01-29T18:19:00.002-06:00</published><updated>2012-01-31T15:36:16.000-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="clase"/><category scheme="http://www.blogger.com/atom/ns#" term="código"/><category scheme="http://www.blogger.com/atom/ns#" term="introduccion"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="posteo"/><category scheme="http://www.blogger.com/atom/ns#" term="PostSystem"/><category scheme="http://www.blogger.com/atom/ns#" term="reutilizable"/><category scheme="http://www.blogger.com/atom/ns#" term="sistema"/><title type='text'>Sistema de posteo en PHP - Introducción</title><content type='html'>&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;float: left; margin-right: 1em; text-align: left;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;http://angelfcm.my-place.us/sistema_posteo&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;302&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeU2s-k0ltSgMRh3oCxdtUqGKObQzJzZYT1nGHOyGbrcgRntZXpDIoluJD3l1ruzSuM2wpHzB6lbh6_9rUGc42DEwqaTrvOJEfOtpzbf4QvXokYVRq6fjLNVEGe9oQZvVjpZaXdRCZjOc/s320/PostSystem_example.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;Ejemplo usando PostSystem&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
Les quiero compartir este código reutilizable que realizé en PHP en una clase, este tema está hecho para personas con conocimientos intermedios en PHP y MySQL.&lt;br /&gt;
Antes de comenzar con este rollo, quisiera que observarán un ejemplo que muestra las funcionalidades que tiene esta clase, el ejemplo se realizó de forma muy fácil utilizando la clase. Pueden ver el ejemplo, &lt;a href=&quot;http://angelfcm.my-place.us/sistema_posteo&quot; target=&quot;_blank&quot;&gt;AQUÍ&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;INTRODUCCIÓN&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Me he dedicado a realizar una clase  llamada PostSystem en PHP que funciona con MySQL, con el fin de facilitar el desarrollo de una interfaz para un sistema de posteo.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Con esta clase pueden ingeniarselas para realizar desde una simple página de comentarios, un blog, hasta uno o&amp;nbsp; más foros llenos de temas que responder o comentar, depende tu dedicación y experiencia.&lt;br /&gt;
&lt;br /&gt;
La forma como funciona el sistema de posteo es familiarizando a los 
posts como padres e hijos y &quot;los hijos de los hijos...&quot; usando dos 
indentificadores por post, uno el cuál identifica al post y otro para 
hacer referencia a un post superior (si es que lo hay). En resumen, usa 
métodos recursivos para llegar hasta el final de cada nodo mediante la jerarquía entre padres e hijos.&lt;br /&gt;
&lt;br /&gt;
Esta clase básicamente se encarga de realizar &lt;code&gt;INSERT, SELECT, UPDATE y DELETE&lt;/code&gt; usando métodos recursivos.&lt;br /&gt;
&lt;br /&gt;
Los posts se guardan en una tabla de la base de datos creada automáticamente si esque no existe.&lt;br /&gt;
Requiere de la conexión y selección a una base de datos MySQL previamente. La tabla es llamada &quot;tb_posts&quot;, las columnas son: &lt;code&gt;&quot;id&quot;, &quot;author&quot;, &quot;title&quot;, &quot;snippet&quot;, &quot;content&quot;, &quot;type&quot;, &quot;parent_id&quot;, &quot;date_created&quot; y &quot;date_modified&quot;&lt;/code&gt;.&lt;br /&gt;
&lt;br /&gt;
Logicamente debería entenderse el propósito de cada columna por el nombre que tienen. A excepción, explicaré la columna &quot;parent_id&quot; y &quot;type&quot; ya que son la base de como trabaja este sistema de posteo.&lt;br /&gt;
&lt;br /&gt;
La columna &quot;parent_id&quot; es un identificador el cual hace referencia al &quot;id&quot; de otro post, así es como se familiarizan como padres e hijos.&lt;br /&gt;
Ejemplo:&lt;br /&gt;
Si tengo un post con id=1 y parent_id=2, entonces el post con id=1 es &quot;hijo&quot; del post con id=2.&lt;br /&gt;
&lt;br /&gt;
La columan &quot;type&quot; representa el tipo de post que se está publicando. Por ejemplo, en un blog generalmente hay: entrada, comentario y cita; En un foro: tema, respuesta y cita.&lt;br /&gt;
Puede ponerse cualquier cosa en &quot;type&quot;, ya que ustedes son los que decidirán que tipos de post habrá.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;spoiler&quot;&gt;
&lt;div class=&quot;spoiler-title&quot;&gt;
Spoiler - Información detallada de la tabla y sus columnas.&lt;/div&gt;
&lt;div class=&quot;spoiler-content&quot;&gt;
- Tabla MySQL&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - tbposts&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Descripción&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Es la única tabla necesaria para que trabaje la clase, en la cual se guardan los datos de los posts.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; El script para la creación de la tabla es:&lt;br /&gt;
&lt;div class=&quot;codigo&quot;&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CREATE TABLE IF NOT EXISTS tb_posts(&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; id INT NOT NULL AUTO_INCREMENT,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; author VARCHAR(50),&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; title VARCHAR(100),&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; snippet VARCHAR(255),&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; content TEXT,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; type VARCHAR(20),&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; parent_id INT,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date_created DATETIME,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; date_modified DATETIME,&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PRIMARY KEY(id, author, parent_id)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; )&lt;/div&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp; Columnas&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - id: Identificador del post.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - author: Nombre del creador del post.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - title: Título del post.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - snippet: Fragmento del contenido del post.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - content: Contenido del post.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - type: Tipo del post definido por el desarrollador. Ejemplo de tipos: entrada, comentario, cita.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - parent_id: Identificador al que se enlaza el post jerárquicamente. Ejemplo: el id de &quot;X&quot; entrada es 12, el parent_id de &quot;Y&quot; comentario es 12.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - date_create: fecha de creación del post, la fecha es establecida por PHP no por MySQL.&lt;br /&gt;
&amp;nbsp; &amp;nbsp; - date_modified: fecha de modificación del post, igualmente establecida por PHP.&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
La clase cuenta con cuatro funciones y tres propiedades, se explica muy genericamente a continuación.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Métodos&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;insert($datos)&lt;/b&gt;: crea un post llenando con el parámetro $datos que es un array asociativo a las columnas de &quot;tb_posts&quot;. Las columnas id, date_created y date_modified, pueden dejarse en blanco para ahorrar código ya que se crean automáticamente si no estan definidas. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;select($id_tipo, $config)&lt;/b&gt;: selecciona uno o más posts devolviendolos en u array asociativo, dependiendo de que información haya en $id_tipo y en $config. $id_tipo puede representar un valor a la columna &quot;id&quot;, &quot;parent_id&quot; o &quot;type&quot; y con $config se puede saber si se va a identificar por &quot;id&quot;, &quot;parent_id&quot; o &quot;type. $config es un array asociativo con el cual se sabrá como obtener los posts. Por ejemplo, se puede exigir que se obtengan todos los posts &quot;hijos&quot; a el post requerido.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;update($id, $data)&lt;/b&gt;: modifica el post con el id pasado en $id con los datos de un array asociativo pasado en $data, si no se pone nada en &quot;date_modified&quot; atomáticamente asigna un fecha. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;delete($id, $borrar_hijos)&lt;/b&gt;: con esta función se puede borrar un post con el id asignado en $id y también borra a toda su descendencia de posts si $borrar_hijos es pasado como &quot;true&quot;.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;selectParent($id, $parent_type, $campos)&lt;/b&gt;: devuelve el primer post padre con el tipo pasado en $parent_type en un array asociativo con los campos deseados en $campos, siendo el hijo del post con el id pasado en $id. Si tengo esta jerarquía: post1_tipoA&amp;gt;post2_tipoB&amp;gt;post3_tipoC, y hago un selectParent(3, &quot;A&quot;, &quot;*&quot;), entonces me entregará &quot;post1_tipoA&quot;.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;foreachPost($datos_posts, $funcion, &amp;amp;$variable)&lt;/b&gt;: está función es muy útil, ya que puede procesar recursivamente todos los datos que haya en un array devuelto por select o selectParent. $datos_post es el array con los datos de los posts, $funcion es el nombre de una función la cual se ejecutará cada vez que se mueva a otro post y &amp;amp;$variable es por si se quiere guardar el resultado en una variable antes de ser imprimidas. Notar que se está usando un &quot;&amp;amp;&quot; antes de la variable ya que asi se guardaran los cambios en $variable.&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;div class=&quot;spoiler&quot;&gt;
&lt;div class=&quot;spoiler-title&quot;&gt;
Spoiler - Sobre &amp;amp;$variable
&lt;/div&gt;
&lt;div class=&quot;spoiler-content&quot;&gt;
Supongo que algunos no saben para que es el ampersand(&quot;&amp;amp;&quot;) antes de una variable, bueno es como hacer un global pero en ocasiones no es posible hacer un global, aquí un ejemplo de &quot;&amp;amp;&quot;$variable.&lt;br /&gt;
Ejemplo usando &quot;&amp;amp;&quot; antes de una variable:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;codigo&quot;&gt;
$A= 1;&lt;br /&gt;
function f($parametro) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ++$parametro;&lt;br /&gt;
}&lt;br /&gt;
$f($A);&lt;br /&gt;
echo $A; // Resultado: 1&lt;br /&gt;
$f(&amp;amp;$A);&lt;br /&gt;
echo $A; // Resultado: 2&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;u&gt;Propiedades&lt;/u&gt;&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;dblink&lt;/b&gt;:&amp;nbsp;Enlace al origen de la base de datos creada con mysql_connect().&lt;/li&gt;
&lt;li&gt;&lt;b&gt;last_post&lt;/b&gt;:&amp;nbsp;Contiene toda la información del último post creado en el objeto al llamar -&amp;gt;create() en un array asociativo a las columnas de la tabla de la db.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;last_error&lt;/b&gt;: &amp;nbsp;Guarda el último error generado al llamar un método. Si el método retorna false se almacena la causa del error en esta propiedad.&lt;/li&gt;
&lt;/ul&gt;
Aquí termina la introducción, en las siguientes entradas de este tema se explicará el uso de cada método. &lt;a href=&quot;http://aprendecomoyo.blogspot.com/2012/01/sistema-de-posteo-en-php-inicializando.html&quot;&gt;Comencemos por insert(), click aquí.&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://aprendecomoyo.blogspot.com/feeds/6020236983493755451/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://aprendecomoyo.blogspot.com/2012/01/sistema-de-posteo-en-php-introduccion.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4060951526192778689/posts/default/6020236983493755451'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4060951526192778689/posts/default/6020236983493755451'/><link rel='alternate' type='text/html' href='http://aprendecomoyo.blogspot.com/2012/01/sistema-de-posteo-en-php-introduccion.html' title='Sistema de posteo en PHP - Introducción'/><author><name>Angel</name><uri>http://www.blogger.com/profile/17672315673365813323</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgeU2s-k0ltSgMRh3oCxdtUqGKObQzJzZYT1nGHOyGbrcgRntZXpDIoluJD3l1ruzSuM2wpHzB6lbh6_9rUGc42DEwqaTrvOJEfOtpzbf4QvXokYVRq6fjLNVEGe9oQZvVjpZaXdRCZjOc/s72-c/PostSystem_example.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4060951526192778689.post-7274342258288695960</id><published>2012-01-15T10:19:00.014-06:00</published><updated>2012-01-31T01:06:08.233-06:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="compatible"/><category scheme="http://www.blogger.com/atom/ns#" term="css"/><category scheme="http://www.blogger.com/atom/ns#" term="custom"/><category scheme="http://www.blogger.com/atom/ns#" term="file"/><category scheme="http://www.blogger.com/atom/ns#" term="input"/><category scheme="http://www.blogger.com/atom/ns#" term="personalizar"/><category scheme="http://www.blogger.com/atom/ns#" term="solamente"/><title type='text'>Personalizar INPUT FILE solamente con CSS, Custom Input File!!!</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://jsfiddle.net/angelfcm/nETSD/&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot; target=&quot;_blank&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbZFpalXXLlF1y9vXRGqtTyda-wR5MeK_2qwP-FNyttxmuGt65r2PETFj7glHUZlZMQ03QQfBuP3itkwanF09aYA51XlWlQ5pzoEV5TdIJe6-JQwDJA54_MoZlafFJLhkvu6YvdQQMPaA/s1600/custominputfile_example.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Muchos diseñadores web, hemos tenido el problema de personalizar al 100% un botón tipo archivo de HTML, es decir, &lt;code&gt;&amp;lt;input type=&quot;file&quot; /&amp;gt;&lt;/code&gt;.&lt;br /&gt;
En internet podemos encontrar posibles formas de hacerlo, pero la mayoría de ellas requieren utilizar API’s de flash o de librerías como jQuery y Mootools. Puede ser una buena opción pero solomente deseamos un simple botón que tenga la funcionalidad para subir archivos sin tanto código. También hay códigos creados por usuarios en foros o blogs, pero lamentablemente la mayoría usan Javascript y/o CSS y no suelen funcionar bien en los principales navegadores: Firefox, IE, Chrome, Safari y Opera.&lt;br /&gt;
Bueno, pues logré crear un custom input file mediante un par de lineas usando solamente CSS y sus respectivas etiquetas HTML.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
El código CSS es:&lt;br /&gt;
&lt;div class=&quot;codigo&quot;&gt;
.custom-input-file {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; overflow: hidden;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; position: relative;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor: pointer;&lt;br /&gt;
}&lt;br /&gt;
.custom-input-file .input-file {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; margin: 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; padding: 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; outline: 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; font-size: 10000px;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; border: 10000px solid transparent;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; opacity: 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; filter: alpha(opacity=0);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; position: absolute;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; right: -1000px;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; top: -1000px;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; cursor: pointer;&lt;br /&gt;
}
&lt;/div&gt;
EL código HTML es:&lt;br /&gt;
&lt;div class=&quot;codigo&quot;&gt;
&amp;lt;div class=&quot;custom-input-file&quot;&amp;gt;&amp;lt;input type=&quot;file&quot; size=&quot;1&quot; class=&quot;input-file&quot; /&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Subir archivo&lt;br /&gt;
&amp;lt;/div&amp;gt;
&lt;/div&gt;
Con este par de lineas de código pueden personalizar un input file a su gusto, como agregar imagen de fondo, efectos visuales al pasar el mouse, bordes, etc. Es compatible con todos los principales navegadores.&lt;br /&gt;
Ahora, ¿cómo personalizar un input file usando este código?&lt;br /&gt;
Muy fácil, pueden modificar o agregar estilos a su gusto a excepción de lo siguiente:&lt;br /&gt;
&lt;ul class=&quot;lista1&quot;&gt;
&lt;li&gt;No modificar nada en &lt;code&gt;.custom-input-file .input-file&lt;/code&gt; a excepción del cursor.
&lt;/li&gt;
&lt;li&gt;No modificar &lt;code&gt;overflow: hidden; position: relative;&lt;/code&gt; en &lt;code&gt;.custom-input-file&lt;/code&gt;, pueden agregar más estilos.
&lt;/li&gt;
&lt;li&gt;Todo el contenido que agreguen dentro del div custom-input-file, debe ir despues de la etiqueta &lt;code&gt;&amp;lt;input type=&quot;file&quot;&amp;gt;&lt;/code&gt;, no antes.
&lt;/li&gt;
&lt;li&gt;Cuando cambien el cursor, deben cambiarlo en &lt;code&gt;.custom-input-file&lt;/code&gt; y &lt;code&gt;.custom-input-file .input-file.&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
Eso es todo, un ejemplo usando este código es el siguiente:&lt;br /&gt;
&lt;iframe allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot; src=&quot;http://jsfiddle.net/angelfcm/nETSD/embedded/result&quot; style=&quot;border: 1px solid #000; height: 120px; width: 100%;&quot;&gt;&lt;/iframe&gt;


&lt;br /&gt;
Pueden ver el ejemplo más detallado aquí:&lt;br /&gt;
&lt;a href=&quot;http://jsfiddle.net/angelfcm/nETSD/&quot; target=&quot;_blank&quot;&gt;http://jsfiddle.net/angelfcm/nETSD/&lt;/a&gt;

&lt;br /&gt;
Publiquen sus comentarios, gracias.</content><link rel='replies' type='application/atom+xml' href='http://aprendecomoyo.blogspot.com/feeds/7274342258288695960/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://aprendecomoyo.blogspot.com/2012/01/window.html#comment-form' title='28 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4060951526192778689/posts/default/7274342258288695960'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4060951526192778689/posts/default/7274342258288695960'/><link rel='alternate' type='text/html' href='http://aprendecomoyo.blogspot.com/2012/01/window.html' title='Personalizar INPUT FILE solamente con CSS, Custom Input File!!!'/><author><name>Angel</name><uri>http://www.blogger.com/profile/17672315673365813323</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgbZFpalXXLlF1y9vXRGqtTyda-wR5MeK_2qwP-FNyttxmuGt65r2PETFj7glHUZlZMQ03QQfBuP3itkwanF09aYA51XlWlQ5pzoEV5TdIJe6-JQwDJA54_MoZlafFJLhkvu6YvdQQMPaA/s72-c/custominputfile_example.png" height="72" width="72"/><thr:total>28</thr:total></entry></feed>