Plugin configuration

This commit is contained in:
dignajar 2015-07-13 23:16:28 -03:00
parent 4877006946
commit 13a5386265
18 changed files with 241 additions and 64 deletions

View File

@ -0,0 +1,36 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Functions
// ============================================================================
// ============================================================================
// Main before POST
// ============================================================================
$_Plugin = false;
foreach($plugins['all'] as $P)
{
if($P->className()==$layout['parameters']) {
$_Plugin = $P;
}
}
// Check if the plugin exists.
if($_Plugin===false) {
Redirect::page('admin', 'plugins');
}
// ============================================================================
// POST Method
// ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{
Alert::set('Configuration saved successfuly');
$_Plugin->setDb($_POST);
}
// ============================================================================
// Main after POST
// ============================================================================

View File

@ -165,8 +165,13 @@ p.advOptions {
font-size: 0.8em; font-size: 0.8em;
} }
a.btn:hover {
color: rgba(255, 255, 255, 0.5) !important;
}
a.btn-red { a.btn-red {
color: rgba(255, 255, 255, 0.9) !important; color: rgba(255, 255, 255, 0.9) !important;
margin-right: 10px;
} }
a.btn-red:hover { a.btn-red:hover {
@ -189,6 +194,31 @@ div.pluginBox p {
margin-bottom: 10px; margin-bottom: 10px;
} }
/* ----------- PLUGINS FORM ----------- */
#jsformplugin div {
margin-bottom: 1.1em;
}
#jsformplugin label {
margin: 0 0 5px 0 !important;
}
#jsformplugin input[type=text] {
width: 70%;
}
#jsformplugin input[type="checkbox"] {
vertical-align: middle;
margin-left: 0px;
}
#jsformplugin label.forCheckbox {
margin-left: 3px;
margin-bottom: 10px;
display: inline-block;
}
/* ----------- SUB-NAVBAR ----------- */ /* ----------- SUB-NAVBAR ----------- */
.sublinks a { .sublinks a {
color: #2672ec; color: #2672ec;

View File

@ -0,0 +1,15 @@
<h2 class="title"><i class="fa fa-rocket"></i> <?php echo $_Plugin->name() ?></h2>
<form id="jsformplugin" method="post" action="" class="forms">
<input type="hidden" id="jskey" name="key" value="">
<?php
echo $_Plugin->form();
?>
<div>
<button class="btn btn-blue" name="publish"><i class="fa fa-sun-o fa-right"></i><?php echo $Language->p('Save') ?></button>
</div>
</form>

View File

@ -11,7 +11,7 @@
<label> <label>
<?php $Language->p('Content') ?> <span class="forms-desc"><?php $Language->p('HTML and Markdown code supported') ?></span> <?php $Language->p('Content') ?> <span class="forms-desc"><?php $Language->p('HTML and Markdown code supported') ?></span>
<textarea name="content" rows="10" class="width-70"><?php echo $_Page->contentRaw(false) ?></textarea> <textarea name="content" rows="10" class="width-70"><?php echo $_Page->contentRaw(true, false) ?></textarea>
</label> </label>
<?php <?php

View File

@ -11,7 +11,7 @@
<label> <label>
<?php $Language->p('Content') ?> <span class="forms-desc"><?php $Language->p('HTML and Markdown code supported') ?></span> <?php $Language->p('Content') ?> <span class="forms-desc"><?php $Language->p('HTML and Markdown code supported') ?></span>
<textarea id="jscontent" name="content" rows="10" class="width-70"><?php echo $_Post->contentRaw(false) ?></textarea> <textarea id="jscontent" name="content" rows="10" class="width-70"><?php echo $_Post->contentRaw(true, false) ?></textarea>
</label> </label>
<?php <?php

View File

@ -10,6 +10,7 @@
if($Plugin->installed()) { if($Plugin->installed()) {
echo '<a href="'.HTML_PATH_ADMIN_ROOT.'uninstall-plugin/'.$Plugin->className().'" class="btn btn-red btn-small">'.$Language->g('Uninstall plugin').'</a>'; echo '<a href="'.HTML_PATH_ADMIN_ROOT.'uninstall-plugin/'.$Plugin->className().'" class="btn btn-red btn-small">'.$Language->g('Uninstall plugin').'</a>';
echo '<a href="'.HTML_PATH_ADMIN_ROOT.'configure-plugin/'.$Plugin->className().'" class="btn btn-small">'.$Language->g('Configure plugin').'</a>';
} }
else { else {
echo '<a href="'.HTML_PATH_ADMIN_ROOT.'install-plugin/'.$Plugin->className().'" class="btn btn-blue btn-small">'.$Language->g('Install plugin').'</a>'; echo '<a href="'.HTML_PATH_ADMIN_ROOT.'install-plugin/'.$Plugin->className().'" class="btn btn-blue btn-small">'.$Language->g('Install plugin').'</a>';

View File

@ -6,7 +6,8 @@ class dbJSON
public $file; public $file;
public $firstLine; public $firstLine;
// $firstLine, TRUE if you want to remove the first line. // $file, the JSON file.
// $firstLine, TRUE if you want to remove the first line, FALSE otherwise.
function __construct($file, $firstLine=true) function __construct($file, $firstLine=true)
{ {
$this->file = $file; $this->file = $file;
@ -15,15 +16,18 @@ class dbJSON
if(file_exists($file)) if(file_exists($file))
{ {
// Read JSON file.
$lines = file($file); $lines = file($file);
// Remove the first line, the first line is for security reasons.
if($firstLine) { if($firstLine) {
// Remove the first line.
unset($lines[0]); unset($lines[0]);
} }
// Regenerate the JSON file.
$implode = implode($lines); $implode = implode($lines);
// Unserialize, JSON to Array.
$this->db = $this->unserialize($implode); $this->db = $this->unserialize($implode);
} }
else else
@ -32,17 +36,35 @@ class dbJSON
} }
} }
// Get database.
public function get()
{
return $this->db;
}
// Set and save database.
public function set($db)
{
$this->db = $db;
return $this->save();
}
// Returns the amount of database items.
public function count() public function count()
{ {
return count($this->db); return count($this->db);
} }
// Save the JSON file.
public function save() public function save()
{ {
if($this->firstLine) if($this->firstLine) {
$data = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>".PHP_EOL; $data = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>".PHP_EOL;
else }
else {
$data = ''; $data = '';
}
$data .= $this->serialize($this->db); $data .= $this->serialize($this->db);
@ -53,8 +75,9 @@ class dbJSON
private function serialize($data) private function serialize($data)
{ {
// DEBUG: La idea es siempre serializar en json, habria que ver si siempre esta cargado json_enconde y decode // DEBUG: La idea es siempre serializar en json, habria que ver si siempre esta cargado json_enconde y decode
if(JSON) if(JSON) {
return json_encode($data, JSON_PRETTY_PRINT); return json_encode($data, JSON_PRETTY_PRINT);
}
return serialize($data); return serialize($data);
} }
@ -62,29 +85,11 @@ class dbJSON
private function unserialize($data) private function unserialize($data)
{ {
// DEBUG: La idea es siempre serializar en json, habria que ver si siempre esta cargado json_enconde y decode // DEBUG: La idea es siempre serializar en json, habria que ver si siempre esta cargado json_enconde y decode
if(JSON) if(JSON) {
return json_decode($data, true); return json_decode($data, true);
}
return unserialize($data); return unserialize($data);
} }
// DEBUG, ver si sirve para la instalacion, sino borrar
public function set($db)
{
$this->db = $db;
return $this->save();
}
public function get()
{
return $this->db;
}
// DEBUG, se puede borrar
public function show()
{
var_dump($this->db);
}
} }

View File

@ -6,22 +6,22 @@ class Plugin {
public $directoryName; public $directoryName;
// (string) Database path and filename // (string) Database path and filename
public $fileDb; public $filenameDb;
// (array) Database // (array) Database unserialized
public $db; public $db;
// (array) Database fields, only for initialize. // (array) Database fields, only for initialize.
public $dbFields; public $dbFields;
// (string) Plugin's class name.
public $className; public $className;
// (array) Plugin's information.
public $data; public $data;
function __construct() function __construct()
{ {
$reflector = new ReflectionClass(get_class($this));
$this->data = array( $this->data = array(
'name'=>'', 'name'=>'',
'description'=>'', 'description'=>'',
@ -29,6 +29,8 @@ class Plugin {
'email'=>'', 'email'=>'',
'website'=>'' 'website'=>''
); );
$reflector = new ReflectionClass(get_class($this));
// Directory name // Directory name
$this->directoryName = basename(dirname($reflector->getFileName())).DS; $this->directoryName = basename(dirname($reflector->getFileName())).DS;
@ -42,16 +44,17 @@ class Plugin {
// Init empty database // Init empty database
$this->db = $this->dbFields; $this->db = $this->dbFields;
$this->fileDb = PATH_PLUGINS_DATABASES.$this->directoryName.'db.php'; $this->filenameDb = PATH_PLUGINS_DATABASES.$this->directoryName.'db.php';
// If the plugin installed then get the database. // If the plugin installed then get the database.
if($this->installed()) if($this->installed())
{ {
$Tmp = new dbJSON($this->fileDb); $Tmp = new dbJSON($this->filenameDb);
$this->db = $Tmp->db; $this->db = $Tmp->db;
} }
} }
// Returns the item from plugin-data.
public function getData($key) public function getData($key)
{ {
if(isset($this->data[$key])) { if(isset($this->data[$key])) {
@ -66,6 +69,32 @@ class Plugin {
$this->data = $array; $this->data = $array;
} }
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();
}
public function name() public function name()
{ {
return $this->getData('name'); return $this->getData('name');
@ -114,7 +143,7 @@ class Plugin {
if( !empty($this->dbFields) ) if( !empty($this->dbFields) )
{ {
// DEBUG: NO ME GUSTA LLAMAR A UNA CLASE // DEBUG: NO ME GUSTA LLAMAR A UNA CLASE
$Tmp = new dbJSON($this->fileDb); $Tmp = new dbJSON($this->filenameDb);
$Tmp->set($this->dbFields); $Tmp->set($this->dbFields);
} }
@ -123,13 +152,13 @@ class Plugin {
public function uninstall() public function uninstall()
{ {
unlink($this->fileDb); unlink($this->filenameDb);
rmdir(PATH_PLUGINS_DATABASES.$this->directoryName); rmdir(PATH_PLUGINS_DATABASES.$this->directoryName);
} }
public function installed() public function installed()
{ {
return file_exists($this->fileDb); return file_exists($this->filenameDb);
} }
public function init() public function init()
@ -138,14 +167,13 @@ class Plugin {
// The user can define your own dbFields. // The user can define your own dbFields.
} }
// DEBUG: Ver si se usa
public function showdb()
{
print_r( $this->db );
}
// EVENTS // EVENTS
public function form()
{
return false;
}
// Before the posts load. // Before the posts load.
public function beforePostsLoad() public function beforePostsLoad()
{ {

View File

@ -37,6 +37,9 @@ if(!defined('JSON_PRETTY_PRINT')) {
// Salt length // Salt length
define('SALT_LENGTH', 8); define('SALT_LENGTH', 8);
// Page brake string
define('PAGE_BRAKE', '<!-- pagebreak -->');
// Bludit version // Bludit version
define('BLUDIT_VERSION', 'githubVersion'); define('BLUDIT_VERSION', 'githubVersion');
define('BLUDIT_CODENAME', ''); define('BLUDIT_CODENAME', '');

View File

@ -61,6 +61,7 @@ function build_plugins()
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().'language'.DS.'en_US.json'; $languageFilename = PATH_PLUGINS.$Plugin->directoryName().'language'.DS.'en_US.json';
$database = new dbJSON($languageFilename, false); $database = new dbJSON($languageFilename, false);
} }
$databaseArray = $database->get(); $databaseArray = $database->get();
$Plugin->setData( $databaseArray['plugin-data'] ); $Plugin->setData( $databaseArray['plugin-data'] );

View File

@ -71,7 +71,7 @@ class dbLanguage extends dbJSON
public function add($array) public function add($array)
{ {
$this->db[] = $array; $this->db += $array;
} }
} }

View File

@ -16,13 +16,21 @@ class Page extends fileContent
return $this->getField('title'); return $this->getField('title');
} }
// Returns the post content. // Returns the content.
// This content is markdown parser. // This content is markdown parser.
public function content($html=true) // $fullContent, TRUE returns all content, if FALSE returns the first part of the content.
// $html, TRUE returns the content without satinize, FALSE otherwise.
public function content($fullContent=true, $html=true)
{ {
// This content is not sanitized. // This content is not sanitized.
$content = $this->getField('content'); $content = $this->getField('content');
if(!$fullContent)
{
$explode = explode(PAGE_BRAKE, $content);
$content = $explode[0];
}
if($html) { if($html) {
return $content; return $content;
} }
@ -30,18 +38,26 @@ class Page extends fileContent
return Sanitize::html($content); return Sanitize::html($content);
} }
// Returns the post content. // Returns the content.
// This content is not markdown parser. // This content is not markdown parser.
public function contentRaw($html=true) // $fullContent, TRUE returns all content, if FALSE returns the first part of the content.
// $html, TRUE returns the content without satinize, FALSE otherwise.
public function contentRaw($fullContent=true, $html=true)
{ {
// This content is not sanitized. // This content is not sanitized.
$contentRaw = $this->getField('contentRaw'); $content = $this->getField('contentRaw');
if($html) { if(!$fullContent)
return $contentRaw; {
$explode = explode(PAGE_BRAKE, $content);
$content = $explode[0];
} }
return Sanitize::html($contentRaw); if($html) {
return $content;
}
return Sanitize::html($content);
} }
public function description() public function description()

View File

@ -16,13 +16,21 @@ class Post extends fileContent
return $this->getField('title'); return $this->getField('title');
} }
// Returns the post content. // Returns the content.
// This content is markdown parser. // This content is markdown parser.
public function content($html=true) // $fullContent, TRUE returns all content, if FALSE returns the first part of the content.
// $html, TRUE returns the content without satinize, FALSE otherwise.
public function content($fullContent=true, $html=true)
{ {
// This content is not sanitized. // This content is not sanitized.
$content = $this->getField('content'); $content = $this->getField('content');
if(!$fullContent)
{
$explode = explode(PAGE_BRAKE, $content);
$content = $explode[0];
}
if($html) { if($html) {
return $content; return $content;
} }
@ -30,18 +38,26 @@ class Post extends fileContent
return Sanitize::html($content); return Sanitize::html($content);
} }
// Returns the post content. // Returns the content.
// This content is not markdown parser. // This content is not markdown parser.
public function contentRaw($html=true) // $fullContent, TRUE returns all content, if FALSE returns the first part of the content.
// $html, TRUE returns the content without satinize, FALSE otherwise.
public function contentRaw($fullContent=true, $html=true)
{ {
// This content is not sanitized. // This content is not sanitized.
$contentRaw = $this->getField('contentRaw'); $content = $this->getField('contentRaw');
if($html) { if(!$fullContent)
return $contentRaw; {
$explode = explode(PAGE_BRAKE, $content);
$content = $explode[0];
} }
return Sanitize::html($contentRaw); if($html) {
return $content;
}
return Sanitize::html($content);
} }
public function key() public function key()

View File

@ -49,6 +49,7 @@
"dasbhoard": "Dasbhoard", "dasbhoard": "Dasbhoard",
"manage": "Manage", "manage": "Manage",
"themes": "Themes", "themes": "Themes",
"configure-plugin": "Configure plugin",
"confirm-delete-this-action-cannot-be-undone": "Confirm delete, this action cannot be undone.", "confirm-delete-this-action-cannot-be-undone": "Confirm delete, this action cannot be undone.",
"site-title": "Site title", "site-title": "Site title",
"site-slogan": "Site slogan", "site-slogan": "Site slogan",

View File

@ -8,5 +8,7 @@
"website": "" "website": ""
}, },
"pages": "Pages" "pages": "Pages",
"home": "Home",
"show-home-link": "Show home link"
} }

View File

@ -5,14 +5,27 @@ class pluginPages extends Plugin {
public function init() public function init()
{ {
$this->dbFields = array( $this->dbFields = array(
'test'=>'' 'homeLink'=>true
); );
} }
public function form()
{
global $Language;
$html = '<div>';
$html .= '<input name="homeLink" id="jshomeLink" type="checkbox" value="true" '.($this->getDbField('homeLink')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jshomeLink">'.$Language->get('Show home link').'</label>';
$html .= '</div>';
return $html;
}
public function onSiteSidebar() public function onSiteSidebar()
{ {
global $Language; global $Language;
global $pagesParents; global $pagesParents;
global $Site;
$html = '<div class="plugin plugin-pages">'; $html = '<div class="plugin plugin-pages">';
$html .= '<h2>'.$Language->get('Pages').'</h2>'; $html .= '<h2>'.$Language->get('Pages').'</h2>';
@ -22,10 +35,12 @@ class pluginPages extends Plugin {
$html .= '<ul>'; $html .= '<ul>';
if($this->getDbField('homeLink')) {
$html .= '<li><a class="parent" href="'.$Site->homeLink().'">'.$Language->get('Home').'</a></li>';
}
foreach($parents as $parent) foreach($parents as $parent)
{ {
// Print the parent // Print the parent
$html .= '<li><a class="parent" href="'.$parent->permalink().'">'.$parent->title().'</a></li>'; $html .= '<li><a class="parent" href="'.$parent->permalink().'">'.$parent->title().'</a></li>';

View File

@ -207,6 +207,10 @@ div.plugin-content {
padding: 0 10px; padding: 0 10px;
} }
div.plugin-content li {
margin-top: 5px;
}
div.plugin-content ul { div.plugin-content ul {
display: block; display: block;
list-style-type: none; list-style-type: none;
@ -214,6 +218,10 @@ div.plugin-content ul {
padding: 0; padding: 0;
} }
div.plugin-content ul > li > ul > li {
margin: 0;
}
div.plugin-content ul > li > ul > li > a { div.plugin-content ul > li > ul > li > a {
color: #777; color: #777;
} }

View File

@ -33,7 +33,7 @@
<!-- Post content --> <!-- Post content -->
<div class="post-content"> <div class="post-content">
<?php echo $Post->content() ?> <?php echo $Post->content(false) // FALSE to get the first part of the post ?>
</div> </div>
</section> </section>