Plugin configuration

This commit is contained in:
dignajar 2015-07-14 01:41:32 -03:00
parent 13a5386265
commit 3339d4ec01
16 changed files with 105 additions and 68 deletions

View File

@ -1,5 +1,14 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); <?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Check role
// ============================================================================
if($Login->role()!=='admin') {
Alert::set('You do not have sufficient permissions to access this page, contact the administrator.');
Redirect::page('admin', 'dashboard');
}
// ============================================================================ // ============================================================================
// Functions // Functions
// ============================================================================ // ============================================================================
@ -21,14 +30,19 @@ if($_Plugin===false) {
Redirect::page('admin', 'plugins'); Redirect::page('admin', 'plugins');
} }
// Check if the plugin has the method form.
if($_Plugin->form()===false) {
Redirect::page('admin', 'plugins');
}
// ============================================================================ // ============================================================================
// POST Method // POST Method
// ============================================================================ // ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{ {
Alert::set('Configuration saved successfuly');
$_Plugin->setDb($_POST); $_Plugin->setDb($_POST);
Alert::set('Configuration has been saved successfully');
} }
// ============================================================================ // ============================================================================

View File

@ -22,7 +22,6 @@ function editUser($args)
{ {
return $dbUsers->set($args); return $dbUsers->set($args);
} }
} }
// ============================================================================ // ============================================================================

View File

@ -11,6 +11,6 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' )
} }
else else
{ {
Alert::set('Login failed'); Alert::set('Username or password incorrect');
} }
} }

View File

@ -1,5 +1,9 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); <?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Functions
// ============================================================================
function addPage($args) function addPage($args)
{ {
global $dbPages; global $dbPages;
@ -24,6 +28,10 @@ function addPage($args)
} }
} }
// ============================================================================
// POST Method
// ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{ {
addPage($_POST); addPage($_POST);

View File

@ -1,5 +1,9 @@
<?php defined('BLUDIT') or die('Bludit CMS.'); <?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Functions
// ============================================================================
function addPost($args) function addPost($args)
{ {
global $dbPosts; global $dbPosts;
@ -24,6 +28,10 @@ function addPost($args)
} }
} }
// ============================================================================
// POST Method
// ============================================================================
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) if( $_SERVER['REQUEST_METHOD'] == 'POST' )
{ {
addPost($_POST); addPost($_POST);

View File

@ -9,7 +9,7 @@
?> ?>
<div> <div>
<button class="btn btn-blue" name="publish"><i class="fa fa-sun-o fa-right"></i><?php echo $Language->p('Save') ?></button> <button class="btn btn-blue" name="publish"><?php echo $Language->p('Save') ?></button>
</div> </div>
</form> </form>

View File

@ -78,11 +78,11 @@
</div> </div>
<button class="btn btn-blue" name="publish"><i class="fa fa-sun-o fa-right"></i><?php echo ($_Page->published()?$Language->p('Save'):$Language->p('Publish now')) ?></button> <button class="btn btn-blue" name="publish"><?php echo ($_Page->published()?$Language->p('Save'):$Language->p('Publish now')) ?></button>
<?php if(count($_Page->children())===0) { ?> <?php if(count($_Page->children())===0) { ?>
<button class="btn" name="draft"><i class="fa fa-circle-o fa-right"></i><?php $Language->p('Draft') ?></button> <button class="btn" name="draft"><?php $Language->p('Draft') ?></button>
<button id="jsdelete" class="btn" name="delete"><i class="fa fa-remove fa-right"></i><?php $Language->p('Delete') ?></button> <button id="jsdelete" class="btn" name="delete"><?php $Language->p('Delete') ?></button>
<?php } ?> <?php } ?>
</form> </form>

View File

@ -49,9 +49,9 @@
</label> </label>
</div> </div>
<button class="btn btn-blue" name="publish"><i class="fa fa-sun-o fa-right"></i><?php echo ($_Post->published()?$Language->p('Save'):$Language->p('Publish now')) ?></button> <button class="btn btn-blue" name="publish"><?php echo ($_Post->published()?$Language->p('Save'):$Language->p('Publish now')) ?></button>
<button class="btn" name="draft"><i class="fa fa-circle-o fa-right"></i><?php $Language->p('Draft') ?></button> <button class="btn" name="draft"><?php $Language->p('Draft') ?></button>
<button id="jsdelete" class="btn" name="delete"><i class="fa fa-remove fa-right"></i><?php $Language->p('Delete') ?></button> <button id="jsdelete" class="btn" name="delete"><?php $Language->p('Delete') ?></button>
</form> </form>

View File

@ -67,8 +67,8 @@
</div> </div>
<button class="btn btn-blue" name="publish"><i class="fa fa-sun-o fa-right"></i><?php $Language->p('Publish now') ?></button> <button class="btn btn-blue" name="publish"><?php $Language->p('Publish now') ?></button>
<button class="btn" name="draft"><i class="fa fa-circle-o fa-right"></i><?php $Language->p('Draft') ?></button> <button class="btn" name="draft"><?php $Language->p('Draft') ?></button>
</form> </form>

View File

@ -48,8 +48,8 @@
</div> </div>
<button class="btn btn-blue" name="publish"><i class="fa fa-sun-o fa-right"></i><?php $Language->p('Publish now') ?></button> <button class="btn btn-blue" name="publish"><?php $Language->p('Publish now') ?></button>
<button class="btn" name="draft"><i class="fa fa-circle-o fa-right"></i><?php $Language->p('Draft') ?></button> <button class="btn" name="draft"><?php $Language->p('Draft') ?></button>
</form> </form>

View File

@ -10,8 +10,10 @@
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>';
if($Plugin->form()) {
echo '<a href="'.HTML_PATH_ADMIN_ROOT.'configure-plugin/'.$Plugin->className().'" class="btn btn-small">'.$Language->g('Configure 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

@ -39,7 +39,7 @@
<div class="forms-desc"><?php $Language->p('you-can-add-a-small-text-on-the-bottom') ?></div> <div class="forms-desc"><?php $Language->p('you-can-add-a-small-text-on-the-bottom') ?></div>
</label> </label>
<input type="submit" class="btn" value="<?php $Language->p('Save') ?>" name="form-general"> <input type="submit" class="btn btn-blue" value="<?php $Language->p('Save') ?>" name="form-general">
</form> </form>
</div> </div>
@ -99,7 +99,7 @@
</div> </div>
</label> </label>
<input type="submit" class="btn" value="<?php $Language->p('Save') ?>" name="form-advanced"> <input type="submit" class="btn btn-blue" value="<?php $Language->p('Save') ?>" name="form-advanced">
</form> </form>
</div> </div>
@ -142,7 +142,7 @@
<div class="forms-desc"><?php $Language->p('you-can-use-this-field-to-define-a-set-of') ?></div> <div class="forms-desc"><?php $Language->p('you-can-use-this-field-to-define-a-set-of') ?></div>
</label> </label>
<input type="submit" class="btn" value="<?php $Language->p('Save') ?>" name="form-regional"> <input type="submit" class="btn btn-blue" value="<?php $Language->p('Save') ?>" name="form-regional">
</form> </form>
</div> </div>

View File

@ -30,6 +30,8 @@ class Plugin {
'website'=>'' 'website'=>''
); );
$this->dbFields = array();
$reflector = new ReflectionClass(get_class($this)); $reflector = new ReflectionClass(get_class($this));
// Directory name // Directory name
@ -140,12 +142,9 @@ class Plugin {
// Create plugin directory for databases and others files. // Create plugin directory for databases and others files.
mkdir(PATH_PLUGINS_DATABASES.$this->directoryName, 0755, true); mkdir(PATH_PLUGINS_DATABASES.$this->directoryName, 0755, true);
if( !empty($this->dbFields) ) // Create database
{
// DEBUG: NO ME GUSTA LLAMAR A UNA CLASE
$Tmp = new dbJSON($this->filenameDb); $Tmp = new dbJSON($this->filenameDb);
$Tmp->set($this->dbFields); $Tmp->set($this->dbFields);
}
return true; return true;
} }

View File

@ -2,32 +2,75 @@
class dbLanguage extends dbJSON class dbLanguage extends dbJSON
{ {
public $en_US; public $data;
private $data; public $db;
function __construct($language) function __construct($language)
{ {
$this->data = array(); $this->data = array();
$this->db = array();
// Default language en_US // Default language en_US
$filename = PATH_LANGUAGES.'en_US.json'; $filename = PATH_LANGUAGES.'en_US.json';
if(file_exists($filename)) if(file_exists($filename))
{ {
parent::__construct($filename, false); $Tmp = new dbJSON($filename, false);
$this->en_US = $this->db; $this->db += $Tmp->db;
} }
// User language // User language
$filename = PATH_LANGUAGES.$language.'.json'; $filename = PATH_LANGUAGES.$language.'.json';
if(file_exists($filename)) if(file_exists($filename))
{ {
parent::__construct($filename, false); $Tmp = new dbJSON($filename, false);
$this->data = $this->db['language-data']; $this->db += $Tmp->db;
} }
$this->data = $this->db['language-data'];
unset($this->db['language-data']); unset($this->db['language-data']);
} }
// Return the translation, if the translation does'n exist then return the English translation.
public function get($string)
{
$key = Text::lowercase($string);
$key = Text::replace(' ', '-', $key);
if(isset($this->db[$key])) {
return $this->db[$key];
}
return '';
}
// Returns translation.
public function g($string)
{
return $this->get($string);
}
// Print translation.
public function p($string)
{
echo $this->get($string);
}
public function add($array)
{
$this->db += $array;
}
// Returns the item from plugin-data.
public function getData($key)
{
if(isset($this->data[$key])) {
return $this->data[$key];
}
return '';
}
// Returns an array with all dictionaries.
public function getLanguageList() public function getLanguageList()
{ {
$files = glob(PATH_LANGUAGES.'*.json'); $files = glob(PATH_LANGUAGES.'*.json');
@ -45,33 +88,4 @@ class dbLanguage extends dbJSON
return $tmp; return $tmp;
} }
// Return the translation, if the translation does'n exist then return the English translation.
public function get($string)
{
$key = Text::lowercase($string);
$key = Text::replace(' ', '-', $key);
if(isset($this->db[$key]))
return $this->db[$key];
// If the key is not translated then return the English translation.
return $this->en_US[$key];
}
public function g($string)
{
return $this->get($string);
}
// Print the translation.
public function p($string)
{
echo $this->get($string);
}
public function add($array)
{
$this->db += $array;
}
} }

View File

@ -1,7 +1,7 @@
{ {
"language-data": "language-data":
{ {
"native": "Español (España)", "native": "Español (Argentina)",
"english-name": "Spanish", "english-name": "Spanish",
"last-update": "2015-06-28", "last-update": "2015-06-28",
"author": "Diego", "author": "Diego",

View File

@ -2,13 +2,6 @@
class pluginOpenGraph extends Plugin { class pluginOpenGraph extends Plugin {
public function init()
{
$this->dbFields = array(
'test'=>''
);
}
public function onSiteHead() public function onSiteHead()
{ {
global $Url, $Site; global $Url, $Site;