Plugins engine :)
parent
fd69f73e66
commit
18b7d22368
|
|
@ -12,9 +12,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
||||||
=========================== */
|
=========================== */
|
||||||
?>
|
?>
|
||||||
<?php
|
<?php
|
||||||
require_once("lang.functions.php");
|
class configuration {
|
||||||
require_once('mysql_connection.class.php');
|
|
||||||
class configuration extends Conexion_Mysql {
|
|
||||||
|
|
||||||
var $urlGelato;
|
var $urlGelato;
|
||||||
var $tablePrefix;
|
var $tablePrefix;
|
||||||
|
|
@ -31,14 +29,14 @@ class configuration extends Conexion_Mysql {
|
||||||
var $shorten_links;
|
var $shorten_links;
|
||||||
var $rssImportFrec;
|
var $rssImportFrec;
|
||||||
var $check_version;
|
var $check_version;
|
||||||
|
var $plugins = array();
|
||||||
|
|
||||||
function configuration() {
|
function configuration() {
|
||||||
parent::Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
|
|
||||||
|
|
||||||
global $isFeed;
|
global $isFeed;
|
||||||
|
global $db;
|
||||||
|
|
||||||
if ($this->ejecutarConsulta("SELECT * FROM ".Table_prefix."config")) {
|
if ($db->ejecutarConsulta("SELECT * FROM ".Table_prefix."config")) {
|
||||||
$row=$this->obtenerRegistro();
|
$row=$db->obtenerRegistro();
|
||||||
$this->tablePrefix = Table_prefix;
|
$this->tablePrefix = Table_prefix;
|
||||||
$this->urlGelato = $row['url_installation'];
|
$this->urlGelato = $row['url_installation'];
|
||||||
$this->postLimit = $row['posts_limit'];
|
$this->postLimit = $row['posts_limit'];
|
||||||
|
|
@ -58,6 +56,16 @@ class configuration extends Conexion_Mysql {
|
||||||
$this->rssImportFrec = $this->get_option("rss_import_frec");
|
$this->rssImportFrec = $this->get_option("rss_import_frec");
|
||||||
$this->check_version = $this->get_option("check_version");
|
$this->check_version = $this->get_option("check_version");
|
||||||
|
|
||||||
|
//TODO: Soporte de los plugins desde BD activar/desactivar
|
||||||
|
if ($handle = opendir("plugins")) {
|
||||||
|
while (false !== ($file = readdir($handle))) {
|
||||||
|
if (substr($file, strlen($file)-3, 3) == "php") {
|
||||||
|
require_once("plugins/{$file}");
|
||||||
|
$this->plugins[] = substr($file, 0, strlen($file)-4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir($handle);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if($isFeed) {
|
if($isFeed) {
|
||||||
header("HTTP/1.0 503 Service Unavailable");
|
header("HTTP/1.0 503 Service Unavailable");
|
||||||
|
|
@ -73,10 +81,11 @@ class configuration extends Conexion_Mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_option($name){
|
function get_option($name){
|
||||||
|
global $db;
|
||||||
$sql = "SELECT * FROM ".Table_prefix."options WHERE name='".$name."' LIMIT 1";
|
$sql = "SELECT * FROM ".Table_prefix."options WHERE name='".$name."' LIMIT 1";
|
||||||
$this->ejecutarConsulta($sql);
|
$db->ejecutarConsulta($sql);
|
||||||
if ($this->contarRegistros()>0) {
|
if ($db->contarRegistros()>0) {
|
||||||
$row=$this->obtenerRegistro();
|
$row=$db->obtenerRegistro();
|
||||||
return $row['val'];
|
return $row['val'];
|
||||||
} else {
|
} else {
|
||||||
return "0";
|
return "0";
|
||||||
|
|
|
||||||
|
|
@ -646,4 +646,32 @@ if(!defined('entry') || !entry) die('Not a valid page');
|
||||||
}
|
}
|
||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
function init_plugins() {
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
foreach ($conf->plugins as $index => $plugin) {
|
||||||
|
//echo "[".$index."] => ".$plugin."<br />";
|
||||||
|
if (!file_exists("plugins/".$plugin.".php")) {
|
||||||
|
//echo "\tNo existe el archivo<br />";
|
||||||
|
unset($config->plugins[$index]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//echo "\tSi existe el archivo<br />";
|
||||||
|
|
||||||
|
if (!class_exists($plugin)) {
|
||||||
|
//echo "\tNo existe la clase<br />";
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//echo "\tSi existe la clase<br />";
|
||||||
|
|
||||||
|
plugins::$instances[$plugin] = new $plugin;
|
||||||
|
/*print_r(plugins::$instances[$plugin]);
|
||||||
|
echo "<br />";*/
|
||||||
|
}
|
||||||
|
/*echo "<br /><br />";
|
||||||
|
print_r(plugins::$instances);
|
||||||
|
echo "<br />";
|
||||||
|
die();*/
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
@ -0,0 +1,74 @@
|
||||||
|
<?php
|
||||||
|
if(!defined('entry') || !entry) die('Not a valid page');
|
||||||
|
/* ===========================
|
||||||
|
|
||||||
|
gelato CMS - A PHP based tumblelog CMS
|
||||||
|
development version
|
||||||
|
http://www.gelatocms.com/
|
||||||
|
|
||||||
|
gelato CMS is a free software licensed under the GPL 2.0
|
||||||
|
Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
|
||||||
|
|
||||||
|
=========================== */
|
||||||
|
?>
|
||||||
|
<?php
|
||||||
|
class plugin {
|
||||||
|
|
||||||
|
var $actions = array();
|
||||||
|
var $exists = array();
|
||||||
|
|
||||||
|
function call($name) {
|
||||||
|
|
||||||
|
if (!$this->exists($name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*echo "<br />==========<br />";
|
||||||
|
echo $name;
|
||||||
|
echo "<br />";*/
|
||||||
|
|
||||||
|
$index = 0;
|
||||||
|
foreach (plugins::$instances as $plugin) {
|
||||||
|
$action = $this->actions[$name][$index][1];
|
||||||
|
if (is_callable(array($plugin, $action))) {
|
||||||
|
$plugin->$action();
|
||||||
|
}
|
||||||
|
$index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function exists($name) {
|
||||||
|
if (isset($this->exists[$name])) {
|
||||||
|
return $this->exists[$name];
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (plugins::$instances as $plugin) {
|
||||||
|
/*print_r(plugins::$instances);
|
||||||
|
echo "<br />";
|
||||||
|
print_r($plugin);
|
||||||
|
echo "<br />";
|
||||||
|
print_r($this->actions[$name]);
|
||||||
|
echo "<br />";
|
||||||
|
echo $this->actions[$name][0][1];
|
||||||
|
echo "<br />";*/
|
||||||
|
if (is_callable(array($plugin, $this->actions[$name][0][1]))) {
|
||||||
|
return $this->exists[$name] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->exists[$name] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function & instance()
|
||||||
|
{
|
||||||
|
static $instance;
|
||||||
|
|
||||||
|
if( !isset($instance) ) {
|
||||||
|
$instance = new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
if(!defined('entry') || !entry) die('Not a valid page');
|
||||||
|
/* ===========================
|
||||||
|
|
||||||
|
gelato CMS - A PHP based tumblelog CMS
|
||||||
|
development version
|
||||||
|
http://www.gelatocms.com/
|
||||||
|
|
||||||
|
gelato CMS is a free software licensed under the GPL 2.0
|
||||||
|
Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
|
||||||
|
|
||||||
|
=========================== */
|
||||||
|
?>
|
||||||
|
<?php
|
||||||
|
class plugins {
|
||||||
|
|
||||||
|
static $instances = array();
|
||||||
|
|
||||||
|
function addAction($name, $function) {
|
||||||
|
$plugEngine = plugin::instance();
|
||||||
|
$plugEngine->actions[$name][] = array($this, $function);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
?>
|
||||||
29
entry.php
29
entry.php
|
|
@ -1,12 +1,13 @@
|
||||||
<?php
|
<?php
|
||||||
ob_start();
|
ob_start();
|
||||||
if(!defined('entry') || !entry) die('Not a valid page');
|
if(!defined('entry') || !entry) die('Not a valid page');
|
||||||
/*
|
/*
|
||||||
* Created on Sep 15, 2007
|
* Created on Sep 15, 2007
|
||||||
* Modified on Sep 22, 2007
|
* Modified on Oct 30, 2008
|
||||||
*
|
*
|
||||||
* Known Entry Points
|
* Known Entry Points
|
||||||
* api.php
|
* api.php
|
||||||
|
* archive.php
|
||||||
* install.php
|
* install.php
|
||||||
* index.php
|
* index.php
|
||||||
* login.php
|
* login.php
|
||||||
|
|
@ -56,6 +57,7 @@ if($installed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'configuration.class.php');
|
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'configuration.class.php');
|
||||||
|
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'functions.php');
|
||||||
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'gelato.class.php');
|
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'gelato.class.php');
|
||||||
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'templates.class.php');
|
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'templates.class.php');
|
||||||
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'themes.class.php');
|
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'themes.class.php');
|
||||||
|
|
@ -67,16 +69,35 @@ require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'mysql_connection.class
|
||||||
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'streams.class.php');
|
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'streams.class.php');
|
||||||
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'gettext.class.php');
|
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'gettext.class.php');
|
||||||
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'lang.functions.php');
|
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'lang.functions.php');
|
||||||
|
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'plugin.class.php');
|
||||||
|
require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'plugins.class.php');
|
||||||
|
|
||||||
if($installed){
|
if($installed){
|
||||||
|
|
||||||
// Globals to be used throughout the application
|
// Globals to be used throughout the application
|
||||||
|
$db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
|
||||||
$user = new user();
|
$user = new user();
|
||||||
$tumble = new gelato();
|
$tumble = new gelato();
|
||||||
$conf = new configuration();
|
$conf = new configuration();
|
||||||
$db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
|
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
|
||||||
|
//print_r($conf->plugins);
|
||||||
|
//die();
|
||||||
|
init_plugins();
|
||||||
|
$trigger = plugin::instance();
|
||||||
|
|
||||||
|
//echo "plugins.instances: ";
|
||||||
|
//print_r(plugins::$instances);
|
||||||
|
//echo "<br />";
|
||||||
|
//die();
|
||||||
|
|
||||||
|
//echo "plugin.actions: ";
|
||||||
|
//$plugEngine = plugin::instance();
|
||||||
|
//print_r($plugEngine->actions);
|
||||||
|
//die();
|
||||||
|
|
||||||
|
$trigger->call('add_post');
|
||||||
|
|
||||||
$feeds = new feeds();
|
$feeds = new feeds();
|
||||||
$feeds->updateFeeds();
|
$feeds->updateFeeds();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class cinco extends plugins {
|
||||||
|
|
||||||
|
function cinco() {
|
||||||
|
$this->addAction('add_post', 'dameCinco');
|
||||||
|
}
|
||||||
|
|
||||||
|
function dameCinco() {
|
||||||
|
echo "Este es el plugin 5<br />";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class hola extends plugins {
|
||||||
|
|
||||||
|
function hola() {
|
||||||
|
$this->addAction('add_post', 'saluda');
|
||||||
|
}
|
||||||
|
|
||||||
|
function saluda() {
|
||||||
|
echo "Hola mundo desde plugin en gelato<br />";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
Loading…
Reference in New Issue