2015-05-05 03:00:01 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
2015-03-08 18:02:59 +01:00
|
|
|
|
|
|
|
class Plugin {
|
|
|
|
|
|
|
|
// (string) Plugin's directory
|
|
|
|
public $directoryName;
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-03-08 18:02:59 +01:00
|
|
|
// (string) Database path and filename
|
2015-07-14 04:16:28 +02:00
|
|
|
public $filenameDb;
|
2015-05-05 03:00:01 +02:00
|
|
|
|
2015-07-14 04:16:28 +02:00
|
|
|
// (array) Database unserialized
|
2015-03-08 18:02:59 +01:00
|
|
|
public $db;
|
|
|
|
|
|
|
|
// (array) Database fields, only for initialize.
|
|
|
|
public $dbFields;
|
|
|
|
|
2015-07-14 04:16:28 +02:00
|
|
|
// (string) Plugin's class name.
|
2015-03-08 18:02:59 +01:00
|
|
|
public $className;
|
|
|
|
|
2015-07-14 04:16:28 +02:00
|
|
|
// (array) Plugin's information.
|
2015-07-03 22:44:26 +02:00
|
|
|
public $data;
|
|
|
|
|
2015-03-08 18:02:59 +01:00
|
|
|
function __construct()
|
|
|
|
{
|
2015-07-03 22:44:26 +02:00
|
|
|
$this->data = array(
|
|
|
|
'name'=>'',
|
|
|
|
'description'=>'',
|
|
|
|
'author'=>'',
|
|
|
|
'email'=>'',
|
|
|
|
'website'=>''
|
|
|
|
);
|
2015-07-14 04:16:28 +02:00
|
|
|
|
2015-07-14 06:41:32 +02:00
|
|
|
$this->dbFields = array();
|
|
|
|
|
2015-07-14 04:16:28 +02:00
|
|
|
$reflector = new ReflectionClass(get_class($this));
|
2015-07-03 22:44:26 +02:00
|
|
|
|
2015-03-08 18:02:59 +01:00
|
|
|
// Directory name
|
2015-07-03 22:44:26 +02:00
|
|
|
$this->directoryName = basename(dirname($reflector->getFileName())).DS;
|
2015-03-08 18:02:59 +01:00
|
|
|
|
|
|
|
// Class Name
|
|
|
|
$this->className = $reflector->getName();
|
|
|
|
|
2015-06-11 04:27:04 +02:00
|
|
|
// Initialize dbFields from the children.
|
|
|
|
$this->init();
|
|
|
|
|
2015-03-08 18:02:59 +01:00
|
|
|
// Init empty database
|
2015-06-11 04:27:04 +02:00
|
|
|
$this->db = $this->dbFields;
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-07-14 04:16:28 +02:00
|
|
|
$this->filenameDb = PATH_PLUGINS_DATABASES.$this->directoryName.'db.php';
|
2015-03-08 18:02:59 +01:00
|
|
|
|
|
|
|
// If the plugin installed then get the database.
|
|
|
|
if($this->installed())
|
|
|
|
{
|
2015-07-14 04:16:28 +02:00
|
|
|
$Tmp = new dbJSON($this->filenameDb);
|
2015-05-05 03:00:01 +02:00
|
|
|
$this->db = $Tmp->db;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-14 04:16:28 +02:00
|
|
|
// Returns the item from plugin-data.
|
2015-07-03 22:44:26 +02:00
|
|
|
public function getData($key)
|
2015-06-11 04:27:04 +02:00
|
|
|
{
|
2015-07-03 22:44:26 +02:00
|
|
|
if(isset($this->data[$key])) {
|
|
|
|
return $this->data[$key];
|
2015-06-12 06:00:04 +02:00
|
|
|
}
|
|
|
|
|
2015-07-03 22:44:26 +02:00
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setData($array)
|
|
|
|
{
|
|
|
|
$this->data = $array;
|
|
|
|
}
|
|
|
|
|
2015-07-14 04:16:28 +02:00
|
|
|
public function getDbField($key)
|
|
|
|
{
|
|
|
|
if(isset($this->db[$key])) {
|
|
|
|
return $this->db[$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setDb($array)
|
|
|
|
{
|
|
|
|
$tmp = array();
|
|
|
|
|
|
|
|
// All fields will be sanitize before save.
|
|
|
|
foreach($array as $key=>$value) {
|
|
|
|
$tmp[$key] = Sanitize::html($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->db = $tmp;
|
|
|
|
|
|
|
|
// Save db on file
|
|
|
|
$Tmp = new dbJSON($this->filenameDb);
|
|
|
|
$Tmp->db = $tmp;
|
|
|
|
$Tmp->save();
|
|
|
|
}
|
|
|
|
|
2015-07-03 22:44:26 +02:00
|
|
|
public function name()
|
|
|
|
{
|
|
|
|
return $this->getData('name');
|
2015-06-12 06:00:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function description()
|
|
|
|
{
|
2015-07-03 22:44:26 +02:00
|
|
|
return $this->getData('description');
|
|
|
|
}
|
2015-06-12 06:00:04 +02:00
|
|
|
|
2015-07-03 22:44:26 +02:00
|
|
|
public function author()
|
|
|
|
{
|
|
|
|
return $this->getData('author');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function email()
|
|
|
|
{
|
|
|
|
return $this->getData('email');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function website()
|
|
|
|
{
|
|
|
|
return $this->getData('website');
|
2015-06-12 06:00:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function className()
|
|
|
|
{
|
|
|
|
return $this->className;
|
2015-06-11 04:27:04 +02:00
|
|
|
}
|
|
|
|
|
2015-07-03 22:44:26 +02:00
|
|
|
public function directoryName()
|
|
|
|
{
|
|
|
|
return $this->directoryName;
|
|
|
|
}
|
|
|
|
|
2015-03-08 18:02:59 +01:00
|
|
|
// Return TRUE if the installation success, otherwise FALSE.
|
|
|
|
public function install()
|
|
|
|
{
|
2015-06-11 04:27:04 +02:00
|
|
|
if($this->installed()) {
|
2015-03-08 18:02:59 +01:00
|
|
|
return false;
|
2015-06-11 04:27:04 +02:00
|
|
|
}
|
2015-03-08 18:02:59 +01:00
|
|
|
|
|
|
|
// Create plugin directory for databases and others files.
|
2015-06-11 04:27:04 +02:00
|
|
|
mkdir(PATH_PLUGINS_DATABASES.$this->directoryName, 0755, true);
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-07-14 06:41:32 +02:00
|
|
|
// Create database
|
|
|
|
$Tmp = new dbJSON($this->filenameDb);
|
|
|
|
$Tmp->set($this->dbFields);
|
2015-03-08 18:02:59 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function uninstall()
|
|
|
|
{
|
2015-07-14 04:16:28 +02:00
|
|
|
unlink($this->filenameDb);
|
2015-06-11 04:27:04 +02:00
|
|
|
rmdir(PATH_PLUGINS_DATABASES.$this->directoryName);
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function installed()
|
|
|
|
{
|
2015-07-14 04:16:28 +02:00
|
|
|
return file_exists($this->filenameDb);
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2015-06-11 04:27:04 +02:00
|
|
|
// This method is used on childre classes.
|
|
|
|
// The user can define your own dbFields.
|
2015-05-05 03:00:01 +02:00
|
|
|
}
|
2015-03-08 18:02:59 +01:00
|
|
|
|
2015-07-14 04:16:28 +02:00
|
|
|
// EVENTS
|
|
|
|
|
|
|
|
public function form()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-07-14 04:16:28 +02:00
|
|
|
return false;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Before the posts load.
|
|
|
|
public function beforePostsLoad()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// After the posts load.
|
|
|
|
public function afterPostsLoad()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before the pages load.
|
|
|
|
public function beforePagesLoad()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// After the pages load.
|
|
|
|
public function afterPagesLoad()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onSiteHead()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onSiteBody()
|
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
return false;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-06-03 03:17:09 +02:00
|
|
|
public function onAdminHead()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onAdminBody()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-06-27 00:12:26 +02:00
|
|
|
public function onSiteSidebar()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onAdminSidebar()
|
2015-03-08 18:02:59 +01:00
|
|
|
{
|
2015-05-05 03:00:01 +02:00
|
|
|
return false;
|
2015-03-08 18:02:59 +01:00
|
|
|
}
|
|
|
|
|
2015-05-31 03:06:55 +02:00
|
|
|
}
|