Plugins improves

This commit is contained in:
Diego Najar 2017-07-02 22:46:05 +02:00
parent 3504f2e6e7
commit 2aa992034b
8 changed files with 90 additions and 63 deletions

View File

@ -263,7 +263,6 @@ class Plugin {
$this->db[$key] = $value;
}
}
return $this->save();
}

View File

@ -30,6 +30,12 @@ $pluginClassName = $layout['parameters'];
if( isset($plugins['all'][$pluginClassName]) ) {
$plugin = $plugins['all'][$pluginClassName];
// Plugins for Bludit PRO
$blackList = array('pluginTimeMachine', 'pluginRemoteContent');
if( in_array($pluginClassName, $blackList) && !defined('BLUDIT_PRO') ) {
Redirect::page('plugins');
}
// Install plugin
if( $plugin->install() ) {
// Add to syslog

View File

@ -114,6 +114,16 @@ if($Login->role()==='admin') {
</div>
</div>';
HTML::legend(array('value'=>$L->g('Authentication Token')));
HTML::formInputText(array(
'name'=>'tokenAuth',
'label'=>$L->g('Token'),
'value'=>$User->tokenAuth(),
'class'=>'uk-width-1-2 uk-form-medium',
'tip'=>$L->g('This token is similar to your password, do not share this token.')
));
HTML::legend(array('value'=>$L->g('Status')));
HTML::formInputText(array(

View File

@ -41,6 +41,60 @@ class dbUsers extends dbJSON
return isset($this->db[$username]);
}
// Create a new user
public function add($args)
{
$dataForDb = array();
// Verify arguments with the database fields.
foreach($this->dbFields as $field=>$options)
{
// If the user send the field.
if( isset($args[$field]) )
{
// Sanitize if will be saved on database.
if( !$options['inFile'] ) {
$tmpValue = Sanitize::html($args[$field]);
}
else {
$tmpValue = $args[$field];
}
}
// Uses a default value for the field.
else
{
$tmpValue = $options['value'];
}
// Set type
settype($tmpValue, gettype($options['value']));
// Save on database
$dataForDb[$field] = $tmpValue;
}
// Check if the user alredy exists.
if( $this->userExists($dataForDb['username']) ) {
return false;
}
// Current date.
$dataForDb['registered'] = Date::current(DB_DATE_FORMAT);
// Password
$dataForDb['salt'] = Text::randomText(SALT_LENGTH);
$dataForDb['password'] = sha1($dataForDb['password'].$dataForDb['salt']);
// Save the database
$this->db[$dataForDb['username']] = $dataForDb;
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
return true;
}
// Set the parameters of a user
public function set($args)
{
@ -170,57 +224,6 @@ class dbUsers extends dbJSON
public function add($args)
{
$dataForDb = array();
// Verify arguments with the database fields.
foreach($this->dbFields as $field=>$options)
{
// If the user send the field.
if( isset($args[$field]) )
{
// Sanitize if will be saved on database.
if( !$options['inFile'] ) {
$tmpValue = Sanitize::html($args[$field]);
}
else {
$tmpValue = $args[$field];
}
}
// Uses a default value for the field.
else
{
$tmpValue = $options['value'];
}
// Set type
settype($tmpValue, gettype($options['value']));
// Save on database
$dataForDb[$field] = $tmpValue;
}
// Check if the user alredy exists.
if( $this->userExists($dataForDb['username']) ) {
return false;
}
// Current date.
$dataForDb['registered'] = Date::current(DB_DATE_FORMAT);
// Password
$dataForDb['salt'] = Text::randomText(SALT_LENGTH);
$dataForDb['password'] = sha1($dataForDb['password'].$dataForDb['salt']);
// Save the database
$this->db[$dataForDb['username']] = $dataForDb;
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
return true;
}
}

View File

@ -36,6 +36,11 @@ class User
return $this->getField('lastName');
}
public function tokenAuth()
{
return $this->getField('tokenAuth');
}
public function role()
{
return $this->getField('role');

View File

@ -25,8 +25,8 @@ class pluginCategories extends Plugin {
$html .= '<div>';
$html .= '<label>'.$Language->get('Categories without content').'</label>';
$html .= '<select name="showCero">';
$html .= '<option value="true" '.($this->getValue('showCero')?'checked':'').'>Enabled</option>';
$html .= '<option value="false" '.($this->getValue('showCero')?'checked':'').'>Disabled</option>';
$html .= '<option value="true" '.($this->getValue('showCero')===true?'selected':'').'>Enabled</option>';
$html .= '<option value="false" '.($this->getValue('showCero')===false?'selected':'').'>Disabled</option>';
$html .= '</select>';
$html .= '<span class="tip">'.$Language->get('Show the categories without content').'</span>';
$html .= '</div>';

View File

@ -14,8 +14,8 @@ class pluginsimpleMDE extends Plugin {
$this->dbFields = array(
'tabSize'=>'2',
'toolbar'=>'"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen", "guide"',
'autosave'=>0,
'spellChecker'=>0
'autosave'=>true,
'spellChecker'=>true
);
}
@ -34,15 +34,19 @@ class pluginsimpleMDE extends Plugin {
$html .= '</div>';
$html .= '<div>';
$html .= '<input type="hidden" name="autosave" value="0">';
$html .= '<input name="autosave" id="jsautosave" type="checkbox" value="1" '.($this->getDbField('autosave')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jsautosave">'.$Language->get('Autosave').'</label>';
$html .= '<label>'.$Language->get('Autosave').'</label>';
$html .= '<select name="autosave">';
$html .= '<option value="true" '.($this->getValue('autosave')===true?'selected':'').'>Enabled</option>';
$html .= '<option value="false" '.($this->getValue('autosave')===false?'selected':'').'>Disabled</option>';
$html .= '</select>';
$html .= '</div>';
$html .= '<div>';
$html .= '<input type="hidden" name="spellChecker" value="0">';
$html .= '<input name="spellChecker" id="jsspellChecker" type="checkbox" value="1" '.($this->getDbField('spellChecker')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jsspellChecker">'.$Language->get('spell-checker').'</label>';
$html .= '<label>'.$Language->get('Spell Checker').'</label>';
$html .= '<select name="spellChecker">';
$html .= '<option value="true" '.($this->getValue('spellChecker')===true?'selected':'').'>Enabled</option>';
$html .= '<option value="false" '.($this->getValue('spellChecker')===false?'selected':'').'>Disabled</option>';
$html .= '</select>';
$html .= '</div>';
return $html;

View File

@ -39,7 +39,7 @@ class pluginVersion extends Plugin {
if( version_compare(Session::get('latestVersion'), BLUDIT_VERSION, '>') ) {
$html = '<div id="plugin-version"><a href="https://www.bludit.com">New version available</a></div>';
} else {
if(BLUDIT_PRO) {
if(defined('BLUDIT_PRO')) {
$html = '<div id="plugin-version">Bludit PRO v'.BLUDIT_VERSION.'</div>';
} else {
$html = '<div id="plugin-version">Bludit v'.BLUDIT_VERSION.'<a href="">Upgrade to Bludit PRO</a></div>';