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;
}
a.btn:hover {
color: rgba(255, 255, 255, 0.5) !important;
}
a.btn-red {
color: rgba(255, 255, 255, 0.9) !important;
margin-right: 10px;
}
a.btn-red:hover {
@ -189,6 +194,31 @@ div.pluginBox p {
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 ----------- */
.sublinks a {
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>
<?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>
<?php

View File

@ -11,7 +11,7 @@
<label>
<?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>
<?php

View File

@ -10,6 +10,7 @@
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.'configure-plugin/'.$Plugin->className().'" class="btn btn-small">'.$Language->g('Configure plugin').'</a>';
}
else {
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 $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)
{
$this->file = $file;
@ -15,15 +16,18 @@ class dbJSON
if(file_exists($file))
{
// Read JSON file.
$lines = file($file);
// Remove the first line, the first line is for security reasons.
if($firstLine) {
// Remove the first line.
unset($lines[0]);
}
// Regenerate the JSON file.
$implode = implode($lines);
// Unserialize, JSON to Array.
$this->db = $this->unserialize($implode);
}
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()
{
return count($this->db);
}
// Save the JSON file.
public function save()
{
if($this->firstLine)
if($this->firstLine) {
$data = "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>".PHP_EOL;
else
}
else {
$data = '';
}
$data .= $this->serialize($this->db);
@ -53,8 +75,9 @@ class dbJSON
private function serialize($data)
{
// 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 serialize($data);
}
@ -62,29 +85,11 @@ class dbJSON
private function unserialize($data)
{
// 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 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;
// (string) Database path and filename
public $fileDb;
public $filenameDb;
// (array) Database
// (array) Database unserialized
public $db;
// (array) Database fields, only for initialize.
public $dbFields;
// (string) Plugin's class name.
public $className;
// (array) Plugin's information.
public $data;
function __construct()
{
$reflector = new ReflectionClass(get_class($this));
$this->data = array(
'name'=>'',
'description'=>'',
@ -30,6 +30,8 @@ class Plugin {
'website'=>''
);
$reflector = new ReflectionClass(get_class($this));
// Directory name
$this->directoryName = basename(dirname($reflector->getFileName())).DS;
@ -42,16 +44,17 @@ class Plugin {
// Init empty database
$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($this->installed())
{
$Tmp = new dbJSON($this->fileDb);
$Tmp = new dbJSON($this->filenameDb);
$this->db = $Tmp->db;
}
}
// Returns the item from plugin-data.
public function getData($key)
{
if(isset($this->data[$key])) {
@ -66,6 +69,32 @@ class Plugin {
$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()
{
return $this->getData('name');
@ -114,7 +143,7 @@ class Plugin {
if( !empty($this->dbFields) )
{
// DEBUG: NO ME GUSTA LLAMAR A UNA CLASE
$Tmp = new dbJSON($this->fileDb);
$Tmp = new dbJSON($this->filenameDb);
$Tmp->set($this->dbFields);
}
@ -123,13 +152,13 @@ class Plugin {
public function uninstall()
{
unlink($this->fileDb);
unlink($this->filenameDb);
rmdir(PATH_PLUGINS_DATABASES.$this->directoryName);
}
public function installed()
{
return file_exists($this->fileDb);
return file_exists($this->filenameDb);
}
public function init()
@ -138,14 +167,13 @@ class Plugin {
// The user can define your own dbFields.
}
// DEBUG: Ver si se usa
public function showdb()
{
print_r( $this->db );
}
// EVENTS
public function form()
{
return false;
}
// Before the posts load.
public function beforePostsLoad()
{

View File

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

View File

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

View File

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

View File

@ -16,13 +16,21 @@ class Page extends fileContent
return $this->getField('title');
}
// Returns the post content.
// Returns the content.
// 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.
$content = $this->getField('content');
if(!$fullContent)
{
$explode = explode(PAGE_BRAKE, $content);
$content = $explode[0];
}
if($html) {
return $content;
}
@ -30,18 +38,26 @@ class Page extends fileContent
return Sanitize::html($content);
}
// Returns the post content.
// Returns the content.
// 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.
$contentRaw = $this->getField('contentRaw');
$content = $this->getField('contentRaw');
if($html) {
return $contentRaw;
if(!$fullContent)
{
$explode = explode(PAGE_BRAKE, $content);
$content = $explode[0];
}
return Sanitize::html($contentRaw);
if($html) {
return $content;
}
return Sanitize::html($content);
}
public function description()

View File

@ -16,13 +16,21 @@ class Post extends fileContent
return $this->getField('title');
}
// Returns the post content.
// Returns the content.
// 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.
$content = $this->getField('content');
if(!$fullContent)
{
$explode = explode(PAGE_BRAKE, $content);
$content = $explode[0];
}
if($html) {
return $content;
}
@ -30,18 +38,26 @@ class Post extends fileContent
return Sanitize::html($content);
}
// Returns the post content.
// Returns the content.
// 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.
$contentRaw = $this->getField('contentRaw');
$content = $this->getField('contentRaw');
if($html) {
return $contentRaw;
if(!$fullContent)
{
$explode = explode(PAGE_BRAKE, $content);
$content = $explode[0];
}
return Sanitize::html($contentRaw);
if($html) {
return $content;
}
return Sanitize::html($content);
}
public function key()

View File

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

View File

@ -8,5 +8,7 @@
"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()
{
$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()
{
global $Language;
global $pagesParents;
global $Site;
$html = '<div class="plugin plugin-pages">';
$html .= '<h2>'.$Language->get('Pages').'</h2>';
@ -22,10 +35,12 @@ class pluginPages extends Plugin {
$html .= '<ul>';
if($this->getDbField('homeLink')) {
$html .= '<li><a class="parent" href="'.$Site->homeLink().'">'.$Language->get('Home').'</a></li>';
}
foreach($parents as $parent)
{
// Print the parent
$html .= '<li><a class="parent" href="'.$parent->permalink().'">'.$parent->title().'</a></li>';

View File

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

View File

@ -33,7 +33,7 @@
<!-- 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>
</section>