Climode rescan

This commit is contained in:
Diego Najar 2017-07-05 19:59:51 +02:00
parent 2aa992034b
commit 556e5a2f73
7 changed files with 179 additions and 131 deletions

View File

@ -218,7 +218,7 @@ class Plugin {
return $this->directoryName;
}
// Return TRUE if the installation success, otherwise FALSE
// Return TRUE if the installation success, otherwise FALSE.
public function install($position=0)
{
if($this->installed()) {
@ -237,7 +237,14 @@ class Plugin {
public function uninstall()
{
Filesystem::deleteRecursive(PATH_PLUGINS_DATABASES.$this->directoryName);
// Delete all files.
$files = Filesystem::listFiles( $this->phpPathDB() );
foreach($files as $file) {
unlink($file);
}
// Delete the directory.
rmdir(PATH_PLUGINS_DATABASES.$this->directoryName);
}
public function installed()
@ -263,7 +270,28 @@ class Plugin {
$this->db[$key] = $value;
}
}
return $this->save();
}
public function webhook($URI=false)
{
global $Url;
if(empty($URI)) {
return false;
}
// Check URI start with the webhook
$startString = HTML_PATH_ROOT.$URI;
$URI = $Url->uri();
$length = mb_strlen($startString, CHARSET);
if( mb_substr($URI, 0, $length)!=$startString ) {
return false;
}
Log::set(__METHOD__.LOG_SEP.'Webhook requested.');
return true;
}
}

View File

@ -13,56 +13,7 @@ if($Login->role()!=='admin') {
// Functions
// ============================================================================
function addUser($args) {
global $dbUsers;
global $Language;
// Check empty username
if( Text::isEmpty($args['new_username']) ) {
Alert::set($Language->g('username-field-is-empty'), ALERT_STATUS_FAIL);
return false;
}
// Check already exist username
if( $dbUsers->userExists($args['new_username']) ) {
Alert::set($Language->g('username-already-exists'), ALERT_STATUS_FAIL);
return false;
}
// Password length
if( strlen($args['new_password']) < 6 ) {
Alert::set($Language->g('Password must be at least 6 characters long'), ALERT_STATUS_FAIL);
return false;
}
// Check new password and confirm password are equal
if( $args['new_password'] != $args['confirm_password'] ) {
Alert::set($Language->g('The password and confirmation password do not match'), ALERT_STATUS_FAIL);
return false;
}
// Filter form fields
$tmp = array();
$tmp['username'] = $args['new_username'];
$tmp['password'] = $args['new_password'];
$tmp['role'] = $args['role'];
$tmp['email'] = $args['email'];
// Add the user to the database
if( $dbUsers->add($tmp) ) {
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'new-user',
'notes'=>$tmp['username']
));
// Create an alert
Alert::set($Language->g('user-has-been-added-successfully'), ALERT_STATUS_OK);
return true;
}
return false;
}
// ============================================================================
// Main before POST

View File

@ -23,6 +23,8 @@ $plugins = array(
'adminSidebar'=>array(),
'beforeRulesLoad'=>array(),
'beforeAll'=>array(),
'afterAll'=>array(),
'afterPageCreate'=>array(),
'afterPageModify'=>array(),

View File

@ -3,8 +3,8 @@
// Load plugins rules
include(PATH_RULES.'60.plugins.php');
// Plugins before rules loaded
Theme::plugins('beforeRulesLoad');
// Plugins before all
Theme::plugins('beforeAll');
// Load rules
include(PATH_RULES.'69.pages.php');
@ -30,3 +30,6 @@ else {
// Plugins after site loaded
Theme::plugins('afterSiteLoad');
// Plugins after all
Theme::plugins('afterAll');

View File

@ -32,14 +32,8 @@ class dbPages extends dbJSON
$dataForDb = array(); // This data will be saved in the database
$dataForFile = array(); // This data will be saved in the file
// The user is always the one loggued
$args['username'] = Session::get('username');
if( Text::isEmpty($args['username']) ) {
return false;
}
// Generate key
$key = $this->generateKey($args['slug'], $args['parent']);
$key = $this->generateKey($args['slug']);
// Generate UUID
$args['uuid'] = $this->generateUUID();
@ -48,7 +42,7 @@ class dbPages extends dbJSON
$currentDate = Date::current(DB_DATE_FORMAT);
// Validate date
if(!Valid::date($args['date'], DB_DATE_FORMAT)) {
if( !Valid::date($args['date'], DB_DATE_FORMAT) ) {
$args['date'] = $currentDate;
}
@ -103,6 +97,9 @@ class dbPages extends dbJSON
return false;
}
// Checksum MD5
$dataForDb['md5file'] = md5_file(PATH_PAGES.$key.DS.FILENAME);
// Insert in database
$this->db[$key] = $dataForDb;
@ -110,10 +107,7 @@ class dbPages extends dbJSON
$this->sortBy();
// Save database
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
$this->save();
return $key;
}
@ -123,15 +117,9 @@ class dbPages extends dbJSON
$dataForDb = array();
$dataForFile = array();
// The user is always the one loggued
$args['username'] = Session::get('username');
if( Text::isEmpty($args['username']) ) {
return false;
}
$newKey = $this->generateKey($args['slug'], NO_PARENT_CHAR, false, $args['key']);
$newKey = $this->generateKey($args['slug'], $args['parent'], false, $args['key']);
// If the page is draft then the time created is now
// If the page is draft then the created time is the current
if( $this->db[$args['key']]['status']=='draft' ) {
$args['date'] = Date::current(DB_DATE_FORMAT);
}
@ -196,6 +184,9 @@ class dbPages extends dbJSON
// Remove the old key
unset( $this->db[$args['key']] );
// Checksum MD5
$dataForDb['md5file'] = md5_file(PATH_PAGES.$newKey.DS.FILENAME);
// Insert in database
$this->db[$newKey] = $dataForDb;
@ -203,10 +194,7 @@ class dbPages extends dbJSON
$this->sortBy();
// Save database
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
$this->save();
return $newKey;
}
@ -465,28 +453,7 @@ class dbPages extends dbJSON
return false;
}
// ----- OLD
public function parentKeyList()
{
return $this->parentKeyList;
}
public function parentKeyExists($key)
{
return isset( $this->parentKeyList[$key] );
}
public function addParentKey($key)
{
$this->parentKeyList[$key] = $key;
}
// Generate a valid Key/Slug.
// Generate a valid Key/Slug
public function generateKey($text, $parent=NO_PARENT_CHAR, $returnSlug=false, $oldKey='')
{
if(Text::isEmpty($text)) {
@ -526,6 +493,59 @@ class dbPages extends dbJSON
return $newKey;
}
public function rescanClimode()
{
$pagesDirectories = Filesystem::listDirectories(PATH_PAGES, $regex='*', $sortByDate=false);
foreach($pagesDirectories as $directory) {
if( Sanitize::pathFile($directory.DS.FILENAME) ) {
// Page key
$pageKey = basename($directory);
// Checksum
$checksum = md5_file($directory.DS.FILENAME);
if( !isset($this->db[$pageKey]) ) {
insertClimode($pageKey);
} elseif($this->db[$pageKey]['checksum']!=$checksum) {
updateClimode($pageKey);
}
}
}
}
public function insertClimode($key)
{
}
public function updateClimode($key)
{
}
// ----- OLD
public function parentKeyList()
{
return $this->parentKeyList;
}
public function parentKeyExists($key)
{
return isset( $this->parentKeyList[$key] );
}
public function addParentKey($key)
{
$this->parentKeyList[$key] = $key;
}
// Returns the database
public function getDB()
{

View File

@ -46,39 +46,24 @@ class dbUsers extends dbJSON
{
$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];
}
// Verify arguments with the database fields
foreach($this->dbFields as $field=>$options) {
if( isset($args[$field]) ) {
$value = Sanitize::html($args[$field]);
}
// Uses a default value for the field.
else
{
$tmpValue = $options['value'];
// Use the default value for the field
else {
$value = $options['value'];
}
// Set type
settype($tmpValue, gettype($options['value']));
settype($value, gettype($options['value']));
// Save on database
$dataForDb[$field] = $tmpValue;
$dataForDb[$field] = $value;
}
// Check if the user alredy exists.
if( $this->userExists($dataForDb['username']) ) {
return false;
}
// Current date.
// Current date
$dataForDb['registered'] = Date::current(DB_DATE_FORMAT);
// Password
@ -87,12 +72,7 @@ class dbUsers extends dbJSON
// 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;
return $this->save();
}
// Set the parameters of a user

View File

@ -164,10 +164,16 @@ function printDebug($array) {
echo '</pre>';
}
function createNewPage($args) {
function createPage($args) {
global $dbPages;
global $Syslog;
// The user is always the one loggued
$args['username'] = Session::get('username');
if( Text::isEmpty($args['username']) ) {
return false;
}
$key = $dbPages->add($args);
if($key) {
// Call the plugins after page created
@ -199,6 +205,12 @@ function editPage($args) {
global $dbPages;
global $Syslog;
// The user is always the one loggued
$args['username'] = Session::get('username');
if( Text::isEmpty($args['username']) ) {
return false;
}
if(!isset($args['parent'])) {
$args['parent'] = NO_PARENT_CHAR;
}
@ -327,3 +339,55 @@ function deleteUser($args, $deleteContent=false)
return false;
}
function addUser($args) {
global $dbUsers;
global $Language;
global $Syslog;
// Check empty username
if( Text::isEmpty($args['new_username']) ) {
Alert::set($Language->g('username-field-is-empty'), ALERT_STATUS_FAIL);
return false;
}
// Check already exist username
if( $dbUsers->userExists($args['new_username']) ) {
Alert::set($Language->g('username-already-exists'), ALERT_STATUS_FAIL);
return false;
}
// Password length
if( strlen($args['new_password']) < 6 ) {
Alert::set($Language->g('Password must be at least 6 characters long'), ALERT_STATUS_FAIL);
return false;
}
// Check new password and confirm password are equal
if( $args['new_password'] != $args['confirm_password'] ) {
Alert::set($Language->g('The password and confirmation password do not match'), ALERT_STATUS_FAIL);
return false;
}
// Filter form fields
$tmp = array();
$tmp['username'] = $args['new_username'];
$tmp['password'] = $args['new_password'];
$tmp['role'] = $args['role'];
$tmp['email'] = $args['email'];
// Add the user to the database
if( $dbUsers->add($tmp) ) {
// Add to syslog
$Syslog->add(array(
'dictionaryKey'=>'new-user',
'notes'=>$tmp['username']
));
// Create an alert
Alert::set($Language->g('user-has-been-added-successfully'), ALERT_STATUS_OK);
return true;
}
return false;
}