| Server IP : 216.238.66.20 / Your IP : 216.73.216.31 Web Server : nginx/1.30.4 System : Linux woropds 5.15.0-187-generic #197-Ubuntu SMP Fri Jul 17 19:17:01 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.2.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/blushrubor.com/htdocs/wp-content/plugins/GmxCore/ |
Upload File : |
<?php
/**
* Esta clase provee de una estructura sencilla para la creación de Plugins de Wordpress
*
* Esta clase debe ser extendida para poder ser utilizada en el desarrollo de Plugins de Wordpress.
* Provee de una estructura similar al MVC de Codeigniter permitiendo tener múltiples vistas y modelos de datos.
*
* @copyright 2012 Gmx http://www.Gmx.com.mx/
*
* @version 1.2
*
* Changelog:
*
* Versión 1.2
* - Bugfix. Soporte para multiples callbacks para un mismo action.
* - Bugfix. Ahora instancia correctamente los filters.
*
* Versión 1.1
* - Añade soporte para señalar la ubicación del plugin usando la variable $plugin_path
* - Añade soporte para usar FirePHP con Firebug + Firefox - http://www.firephp.org/HQ/Use.htm
*
* Versión 1.0
* - Primer Release
*
*/
define('EXT', '.php');
define('IT_WPBASE_PATH', plugin_dir_path(__FILE__));
define('IT_WPBASE_URL', plugin_dir_url(__FILE__));
require_once('FirePHP.class.php');
/**
* Clase Base. Implementa el Registro de los recursos de la aplicación.
*
* @author Gamaliel
* @version 1.0
*
*/
class Gmx_Registry
{
private static $objects = array();
private static $frameworkName = 'Gmx WP DevCore';
private static $instance;
private function __construct(){}
public function __clone()
{
trigger_error('No esta permitido clonar el Objecto Gmx_Registry de Gmx Core', E_USER_ERROR);
}
public static function singleton()
{
if( !isset( self::$instance ) )
{
$obj = __CLASS__;
self::$instance = new $obj;
}
return self::$instance;
}
protected function get( $key = FALSE )
{
if( $key )
{
if( isset( $this->objects[$key] ) )
{
return $this->objects[$key];
}
}
}
protected function set( $key = FALSE, $val = FALSE )
{
if( $key ) $this->objects[$key] = $val;
}
static function getObject( $key = FALSE )
{
if( $key )
{
return self::singleton()->get( $key );
}
}
static function storeObject( $key = FALSE, $val = FALSE )
{
if( $key )
{
return self::singleton()->set( $key, $val );
}
}
}
/**
* Clase encargada de cargar recursos en el contexto de la aplicación.
*
* @author Gamaliel
* @version 1.0
*
*/
class Loader
{
protected $filepath;
protected $__FILE__;
protected $lang_domain = FALSE;
public function __construct(){}
/**
* Carga una Clase Modelo (Model) para ser utiliza en el contexto de la aplicación.
* Las Clases Modelo deben ser nombradas con la primera letra en mayúscula y el nombre del archivo en minúscula coincidiendo con el nombre de la Clase.
*
* @param String $class Nombre de la Clase Modelo a cargar
*/
public function model( $class = FALSE )
{
if( !$class ) return FALSE;
$classname = ucfirst(strtolower($class));
$PublicVar = strtolower($class);
$Gmx =& Gmx_Instance();
$Gmx->$PublicVar = Gmx_Register($class, 'models', $this->filepath);
}
/**
* Carga una archivo de Vista (View). Este archivo contendrá el HTML a ser renderizado por el navegador.
*
* @param String $file Nombre de la Vista
* @param Array $data Datos a procesar en la vista. El array se destruye, los índices se convierten en variables.
* @param Boolean $return Determina si el contenido de la Vista es retornado o enviado al navegador.
*/
public function view( $file = FALSE, $data = FALSE, $return = FALSE )
{
if( $file )
{
$html = FALSE;
$file = strtolower($file);
ob_start();
if( $data && is_array( $data ) ) extract($data, EXTR_OVERWRITE);
if( file_exists($this->filepath . 'views' . DIRECTORY_SEPARATOR . $file . EXT) )
{
include($this->filepath . 'views' . DIRECTORY_SEPARATOR . $file . EXT);
}
else if( file_exists( IT_WPBASE_PATH . 'views' . DIRECTORY_SEPARATOR . $file . EXT ) )
{
include(IT_WPBASE_PATH . 'views' . DIRECTORY_SEPARATOR . $file . EXT);
}
else
{
trigger_error('No se encuentra la vista <strong>' . $file . '</strong>. Las vistas deben ubicarse en la carpeta <strong>views</strong>. <br />Advertencia ', E_USER_WARNING);
}
$html .= ob_get_contents();
ob_end_clean();
if( !$return )
{
echo $html;
}
else
{
return $html;
}
}
}
/**
* Carga archivos con Funciones de Ayuda (Helpers).
*
* @param String $file Nombre del archivo con Funciones de Ayuda
*/
public function helper( $file = FALSE )
{
if( $file )
{
$file = strtolower($file);
if( file_exists($this->filepath . 'helpers' . DIRECTORY_SEPARATOR . $file . EXT) )
{
include_once($this->filepath . 'helpers' . DIRECTORY_SEPARATOR . $file . EXT);
}
else if( file_exists( IT_WPBASE_PATH . 'helpers' . DIRECTORY_SEPARATOR . $file . EXT ) )
{
include_once(IT_WPBASE_PATH . 'helpers' . DIRECTORY_SEPARATOR . $file . EXT);
}
else
{
trigger_error('No se encuentra el helper <strong>' . $file . '</strong>. Los helpers deben ubicarse en la carpeta <strong>helpers</strong>. <br />Advertencia ', E_USER_WARNING);
}
}
}
/**
* Carga un archivo de idioma PO/MO. Wrapper de la función de Wordpress load_plugin_textdomain
*
* @param String $txt_domain Textdomain del Lenguaje
*/
public function language( $txt_domain = FALSE )
{
if( $txt_domain )
{
$this->lang_domain = $txt_domain;
add_action('init', array(&$this, 'init_language'));
}
}
public function init_language()
{
if( $this->lang_domain )
{
load_plugin_textdomain( $this->lang_domain, false, basename( dirname( $this->__FILE__ ) ) . DIRECTORY_SEPARATOR . 'languages' . DIRECTORY_SEPARATOR );
}
}
}
/**
* Clase encargada de retornar las URI absolutas de recursos.
*
* @author Gamaliel
* @version 1.0
*
*/
class Gmx_Resources
{
protected $path;
protected $url;
public function __construct( $filepath = FALSE )
{
if( !$filepath ) trigger_error('No se ha definido la ruta de los recursos. <br /> Advertencia ', E_USER_WARNING);
$this->path = plugin_dir_path($filepath);
$this->url = plugin_dir_url($filepath);
}
/**
* Retorna la URI absoluta de un recurso CSS ubicado en la ruta relativa resources/css
*
* @param String $css Nombre del archivo CSS sin la extensión
*/
function css( $css = FALSE )
{
if( $css && file_exists($this->path . 'resources' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . $css . '.css') )
{
return $this->url . 'resources' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . $css . '.css';
}
else if( $css && file_exists( IT_WPBASE_PATH . 'resources' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . $css . '.css' ) )
{
return IT_WPBASE_URL . 'resources' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . $css . '.css';
}
else
{
trigger_error('No se encuentra el archivo css <strong>' . $css . '.css</strong>. Los archivos css deben ubicarse en la carpeta <strong>resources/css</strong>. <br />Advertencia ', E_USER_WARNING);
}
}
/**
* Retorna la URI absoluta de un recurso JS ubicado en la ruta relativa resources/js
*
* @param String $js Nombre del archivo JS sin la extensión
*/
function js( $js = FALSE )
{
if( $js && file_exists($this->path . 'resources' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $js . '.js') )
{
return $this->url . 'resources' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $js . '.js';
}
else if( $js && file_exists( IT_WPBASE_PATH . 'resources' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $js . '.js' ) )
{
return IT_WPBASE_URL . 'resources' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . $js . '.js';
}
else
{
trigger_error('No se encuentra el archivo js <strong>' . $js . '.js</strong>. Los archivos js deben ubicarse en la carpeta <strong>resources/js</strong>. <br />Advertencia ', E_USER_WARNING);
}
}
/**
* Retorna la URI absoluta de un recurso de imagen ubicado en la ruta relativa resources/img
*
* @param String $img Nombre del archivo de imagen con la extensión
*/
function img( $img = FALSE )
{
if( $img && file_exists($this->path . 'resources' . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $img) )
{
return $this->url . 'resources' . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $img;
}
else if( $img && file_exists( IT_WPBASE_PATH . 'resources' . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $img ) )
{
return IT_WPBASE_URL . 'resources' . DIRECTORY_SEPARATOR . 'img' . DIRECTORY_SEPARATOR . $img;
}
else
{
trigger_error('No se encuentra el archivo de imagen <strong>' . $img . '</strong>. Los archivos de imagen deben ubicarse en la carpeta <strong>resources/img</strong>. <br />Advertencia ', E_USER_WARNING);
}
}
}
/**
* Clase de Limpieza. Utiliza los Filters de PHP para limpiar inputs
*
* @author Gamaliel
* @version 1.0
*
*/
class Gmx_Sanitizer
{
public function __construct()
{
if( !function_exists('filter_var') )
{
trigger_error('No hay soporte para la función <strong>filter_var</strong>. Error de Seguridad.', E_USER_ERROR );
}
}
public function email( $data = FALSE )
{
if( is_array($data) )
return filter_var_array($data, FILTER_SANITIZE_EMAIL);
else
return filter_var($data, FILTER_SANITIZE_EMAIL);
}
public function encoded( $data = FALSE )
{
if( is_array($data) )
return filter_var_array($data, FILTER_SANITIZE_ENCODED);
else
return filter_var($data, FILTER_SANITIZE_ENCODED);
}
public function magic_quotes( $data = FALSE )
{
if( is_array($data) )
return filter_var_array($data, FILTER_SANITIZE_MAGIC_QUOTES);
else
return filter_var($data, FILTER_SANITIZE_MAGIC_QUOTES);
}
public function float( $data = FALSE )
{
if( is_array($data) )
return filter_var_array($data, FILTER_SANITIZE_NUMBER_FLOAT);
else
return filter_var($data, FILTER_SANITIZE_NUMBER_FLOAT);
}
public function int( $data = FALSE )
{
if( is_array($data) )
return filter_var_array($data, FILTER_SANITIZE_NUMBER_INT);
else
return filter_var($data, FILTER_SANITIZE_NUMBER_INT);
}
public function special_chars( $data = FALSE )
{
if( is_array($data) )
return filter_var_array($data, FILTER_SANITIZE_SPECIAL_CHARS);
else
return filter_var($data, FILTER_SANITIZE_SPECIAL_CHARS);
}
public function full_special_chars( $data = FALSE )
{
if( is_array($data) )
return filter_var_array($data, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
else
return filter_var($data, FILTER_SANITIZE_FULL_SPECIAL_CHARS);
}
public function string( $data = FALSE )
{
if( is_array($data) )
return filter_var_array($data, FILTER_SANITIZE_STRING);
else
return filter_var($data, FILTER_SANITIZE_STRING);
}
public function stripped( $data = FALSE )
{
if( is_array($data) )
return filter_var_array($data, FILTER_SANITIZE_STRIPPED);
else
return filter_var($data, FILTER_SANITIZE_STRIPPED);
}
public function url( $data = FALSE )
{
if( is_array($data) )
return filter_var_array($data, FILTER_SANITIZE_URL);
else
return filter_var($data, FILTER_SANITIZE_URL);
}
}
/**
* Clase Base. Esta clase provee de un singleton para evitar duplicar el core de la aplicación. Extiende la clase Loader.
*
* @see Loader
* @author Gamaliel
* @version 1.0
*
*/
class Gmx extends Loader
{
public $load;
private static $instance;
public function __construct()
{
parent::__construct();
$this->load = $this;
self::$instance = $this->load;
}
public static function getInstance()
{
return self::$instance;
}
}
/**
* Clase Base. Sobre esta clase se contruye la aplicación. Extiende la clase Gmx que a su vez extiende la clase Loader.
*
* @see Loader
* @see Gmx
* @author Gamaliel
* @version 1.0
*
*/
class GmxCore extends Gmx
{
protected $resources;
protected $sanitizer;
protected $db;
protected $plugin_path;
public $debug;
/**
* Inicializa el plugin.
*
* @param String $plugin Ruta del plugin. Use __FILE__
* @param Boolean $debug Determina si el plugin usará FirePHP para mostrar mensajes de debugging
*/
public function __construct( $plugin = FALSE, $debug = FALSE)
{
global $wpdb;
$this->db = $wpdb;
$this->debug = FirePHP::getInstance(true);
$this->debug->setEnabled($debug);
if( !$plugin )
{
trigger_error('No se ha definido la ubicación del plugin, la instalación/desinstalación del plugin no funcionará. <br /> Advertencia ', E_USER_WARNING );
$plugin = __FILE__;
}
$this->filepath = plugin_dir_path( $plugin );
$this->__FILE__ = $plugin;
$this->plugin_path = dirname( $plugin );
$this->resources = new Gmx_Resources($plugin);
$this->sanitizer = new Gmx_Sanitizer();
$this->it_init();
parent::__construct();
add_action('admin_menu', array(&$this, 'add_menu'));
add_action('wp_enqueue_scripts', array(&$this, 'add_css'));
add_action('admin_enqueue_scripts', array(&$this, 'add_js'));
add_action('wp_enqueue_scripts', array(&$this, 'add_frontend_css'), 90);
add_action('wp_enqueue_scripts', array(&$this, 'add_frontend_js'), 90);
register_activation_hook($plugin, array(&$this, 'install'));
register_deactivation_hook($plugin, array(&$this, 'uninstall'));
$this->__add_shortcode($this->shortcodes());
$this->__add_action($this->actions());
$this->__add_filter($this->filters());
}
/**
* Inicializa Clases Modelo (Models) por defecto. Estos recursos deben definirse en el array interno $internal_classes
*/
public function it_init()
{
$internal_classes = array(
//'session'
);
foreach( $internal_classes as $class )
{
$this->$class = Gmx_Register($class);
}
}
/**
* Envia el contenido HTML al navegador para su renderizado
*/
public function render()
{
echo $this->html;
}
/**
* Inicializa Shortcodes de Wordpress
*
* @access Private
* @param Array $shortcodes Definiciones de WP Shortcodes
*/
private function __add_shortcode( $shortcodes = FALSE )
{
if( $shortcodes && is_array($shortcodes) && count($shortcodes) > 0 )
{
$keys = array_keys( $shortcodes );
foreach( $keys as $k )
{
add_shortcode($k, array(&$this, $shortcodes[$k]));
}
}
}
/**
* Inicializa Actions de Wordpress
*
* @access Private
* @param Array $actions Definiciones de WP Actions
*/
private function __add_action( $actions = FALSE )
{
if( $actions && is_array($actions) && count($actions) > 0 )
{
$keys = array_keys( $actions );
foreach( $keys as $k )
{
if( is_array($actions[$k] ) )
{
foreach( $actions[$k] as $_value )
{
add_action($k, array(&$this, $_value));
}
}
else
{
add_action($k, array(&$this, $actions[$k]));
}
}
}
}
/**
* Inicializa Filters de Wordpress
*
* @access Private
* @param Array $actions Definiciones de WP Filters
*/
private function __add_filter( $filters = FALSE )
{
if( $filters && is_array($filters) && count($filters) > 0 )
{
$keys = array_keys( $filters );
foreach( $keys as $k )
{
if( is_array($filters[$k] ) )
{
foreach( $filters[$k] as $_value )
{
add_filter($k, array(&$this, $_value));
}
}
else
{
add_filter($k, array(&$this, $filters[$k]));
}
}
}
}
/**
* Añade Menus de Wordpress.
* Dentro de esta función deben definirse las funciones para añadir los menus.
*
* Ejemplo.
*
* add_theme_page( $titulo, $menu, $capabilidad, $identificador, $callback )
*
*/
public function add_menu(){}
/**
* Añade JS a las páginas del plugin.
* Dentro de esta función deben definirse los registros y cargas de los archivos JS. La ubicación de los archivos puede obtenerse a través de la función Gmx_Resources::js referenciada en $this->resources->js
*
* Ejemplo.
*
* wp_register_script( $scriptname, $ubicacion, $dependencias );
*
* wp_enqueue_script( $scriptname );
*
* @see Gmx_Resources::js()
*/
public function add_js(){}
/**
* Añade CSS a las páginas del plugin
* Dentro de esta función deben definirse los registros y cargas de los archivos CSS. La ubicación de los archivos puede obtenerse a través de la función Gmx_Resources::css referenciada en $this->resources->css
*
* Ejemplo.
*
* wp_register_style( $stylename, $ubicacion );
*
* wp_enqueue_style( $stylename );
*
* @see Gmx_Resources::css()
*/
public function add_css(){}
/**
* Añade JS a las páginas del tema del sitio web.
* Dentro de esta función deben definirse los registros y cargas de los archivos JS. La ubicación de los archivos puede obtenerse a través de la función Gmx_Resources::js referenciada en $this->resources->js
*
* Ejemplo.
*
* wp_register_script( $scriptname, $ubicacion, $dependencias );
*
* wp_enqueue_script( $scriptname );
*
* @see Gmx_Resources::js()
*/
public function add_frontend_js(){}
/**
* Añade CSS a las páginas del tema del sitio web.
* Dentro de esta función deben definirse los registros y cargas de los archivos CSS. La ubicación de los archivos puede obtenerse a través de la función Gmx_Resources::css referenciada en $this->resources->css
*
* Ejemplo.
*
* wp_register_style( $stylename, $ubicacion );
*
* wp_enqueue_style( $stylename );
*
* @see Gmx_Resources::css()
*/
public function add_frontend_css(){}
/**
* Ejecuta las instrucciones contenidas al instalarse el Plugin en el Registro de Wordpress
*/
public function install(){
$this->debug->log('init install...');
}
/**
* Ejecuta las instrucciones contenidas al desinstalarse el Plugin en el Registro de Wordpress
*/
public function uninstall(){}
/**
* Define y retorna un array de WP Shortcodes para ser inicializados.
*
* Ejemplo.
*
* return array('shortcode', 'shortcode_callback');
*
* @see GmxCore::__add_shortcode()
* @return Array
*
*/
public function shortcodes(){ return array(); }
/**
* Define y retorna un array de WP Actions para ser inicializados.
*
* Ejemplo.
*
* return array('action', 'action_callback');
*
* @see GmxCore::__add_action()
* @return Array
*
*/
public function actions(){ return array(); }
/**
* Define y retorna un array de WP Filters para ser inicializados.
*
* Ejemplo.
*
* return array('filter', 'filter_callback');
*
* @see GmxCore::__add_filter()
* @return Array
*
*/
public function filters(){ return array(); }
}
/**
* Devuelve la Instancia de la Aplicación
*
* @return Gmx
*/
function Gmx_Instance()
{
return Gmx::getInstance();
}
/**
* Registra recursos en la aplicación
*
* @param String $class Clase a ser registrada
* @param String $folder Carpeta de la clase a registrar
* @param String $filepath Ubicación absoluta de la clase a registrar
*/
function Gmx_Register( $class = FALSE, $folder = FALSE, $filepath = FALSE )
{
if( $class && $folder && $filepath )
{
$Obj = Gmx_Registry::singleton();
$class = strtolower($class);
if( $Obj->getObject( $class ) !== NULL )
{
return $Obj->getObject( $class );
}
if( file_exists( $filepath . $folder . DIRECTORY_SEPARATOR . $class . EXT ) )
{
require_once( $filepath . $folder . DIRECTORY_SEPARATOR . $class . EXT );
}
else if( file_exists( IT_WPBASE_PATH . $folder . DIRECTORY_SEPARATOR . $class . EXT ) )
{
require_once( IT_WPBASE_PATH . $folder . DIRECTORY_SEPARATOR . $class . EXT );
}
else
{
trigger_error('No se encuentra el modelo <strong>' . $class . '</strong>. Los modelos deben ubicarse en la carpeta <strong>models</strong>. <br />Error ', E_USER_ERROR);
}
$classname = ucfirst($class);
if( class_exists( $classname ) )
{
$Obj->storeObject($class, new $classname());
$object = $Obj->getObject($class);
if( is_object($object) ) return $object;
}
else
{
trigger_error('La clase <strong>' . $classname . '</strong> no se ha encontrado. <br /> Error ', E_USER_ERROR);
}
}
}
?>