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 $this->directoryName;
} }
// Return TRUE if the installation success, otherwise FALSE // Return TRUE if the installation success, otherwise FALSE.
public function install($position=0) public function install($position=0)
{ {
if($this->installed()) { if($this->installed()) {
@ -237,7 +237,14 @@ class Plugin {
public function uninstall() 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() public function installed()
@ -263,7 +270,28 @@ class Plugin {
$this->db[$key] = $value; $this->db[$key] = $value;
} }
} }
return $this->save(); 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 // 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 // Main before POST

View File

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

View File

@ -3,8 +3,8 @@
// Load plugins rules // Load plugins rules
include(PATH_RULES.'60.plugins.php'); include(PATH_RULES.'60.plugins.php');
// Plugins before rules loaded // Plugins before all
Theme::plugins('beforeRulesLoad'); Theme::plugins('beforeAll');
// Load rules // Load rules
include(PATH_RULES.'69.pages.php'); include(PATH_RULES.'69.pages.php');
@ -30,3 +30,6 @@ else {
// Plugins after site loaded // Plugins after site loaded
Theme::plugins('afterSiteLoad'); 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 $dataForDb = array(); // This data will be saved in the database
$dataForFile = array(); // This data will be saved in the file $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 // Generate key
$key = $this->generateKey($args['slug'], $args['parent']); $key = $this->generateKey($args['slug']);
// Generate UUID // Generate UUID
$args['uuid'] = $this->generateUUID(); $args['uuid'] = $this->generateUUID();
@ -48,7 +42,7 @@ class dbPages extends dbJSON
$currentDate = Date::current(DB_DATE_FORMAT); $currentDate = Date::current(DB_DATE_FORMAT);
// Validate date // Validate date
if(!Valid::date($args['date'], DB_DATE_FORMAT)) { if( !Valid::date($args['date'], DB_DATE_FORMAT) ) {
$args['date'] = $currentDate; $args['date'] = $currentDate;
} }
@ -103,6 +97,9 @@ class dbPages extends dbJSON
return false; return false;
} }
// Checksum MD5
$dataForDb['md5file'] = md5_file(PATH_PAGES.$key.DS.FILENAME);
// Insert in database // Insert in database
$this->db[$key] = $dataForDb; $this->db[$key] = $dataForDb;
@ -110,10 +107,7 @@ class dbPages extends dbJSON
$this->sortBy(); $this->sortBy();
// Save database // Save database
if( $this->save() === false ) { $this->save();
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
return $key; return $key;
} }
@ -123,15 +117,9 @@ class dbPages extends dbJSON
$dataForDb = array(); $dataForDb = array();
$dataForFile = array(); $dataForFile = array();
// The user is always the one loggued $newKey = $this->generateKey($args['slug'], NO_PARENT_CHAR, false, $args['key']);
$args['username'] = Session::get('username');
if( Text::isEmpty($args['username']) ) {
return false;
}
$newKey = $this->generateKey($args['slug'], $args['parent'], false, $args['key']); // If the page is draft then the created time is the current
// If the page is draft then the time created is now
if( $this->db[$args['key']]['status']=='draft' ) { if( $this->db[$args['key']]['status']=='draft' ) {
$args['date'] = Date::current(DB_DATE_FORMAT); $args['date'] = Date::current(DB_DATE_FORMAT);
} }
@ -196,6 +184,9 @@ class dbPages extends dbJSON
// Remove the old key // Remove the old key
unset( $this->db[$args['key']] ); unset( $this->db[$args['key']] );
// Checksum MD5
$dataForDb['md5file'] = md5_file(PATH_PAGES.$newKey.DS.FILENAME);
// Insert in database // Insert in database
$this->db[$newKey] = $dataForDb; $this->db[$newKey] = $dataForDb;
@ -203,10 +194,7 @@ class dbPages extends dbJSON
$this->sortBy(); $this->sortBy();
// Save database // Save database
if( $this->save() === false ) { $this->save();
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
return $newKey; return $newKey;
} }
@ -465,28 +453,7 @@ class dbPages extends dbJSON
return false; return false;
} }
// ----- OLD // Generate a valid Key/Slug
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.
public function generateKey($text, $parent=NO_PARENT_CHAR, $returnSlug=false, $oldKey='') public function generateKey($text, $parent=NO_PARENT_CHAR, $returnSlug=false, $oldKey='')
{ {
if(Text::isEmpty($text)) { if(Text::isEmpty($text)) {
@ -526,6 +493,59 @@ class dbPages extends dbJSON
return $newKey; 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 // Returns the database
public function getDB() public function getDB()
{ {

View File

@ -46,39 +46,24 @@ class dbUsers extends dbJSON
{ {
$dataForDb = array(); $dataForDb = array();
// Verify arguments with the database fields. // Verify arguments with the database fields
foreach($this->dbFields as $field=>$options) foreach($this->dbFields as $field=>$options) {
{ if( isset($args[$field]) ) {
// If the user send the field. $value = Sanitize::html($args[$field]);
if( isset($args[$field]) )
{
// Sanitize if will be saved on database.
if( !$options['inFile'] ) {
$tmpValue = Sanitize::html($args[$field]);
} }
// Use the default value for the field
else { else {
$tmpValue = $args[$field]; $value = $options['value'];
}
}
// Uses a default value for the field.
else
{
$tmpValue = $options['value'];
} }
// Set type // Set type
settype($tmpValue, gettype($options['value'])); settype($value, gettype($options['value']));
// Save on database // Save on database
$dataForDb[$field] = $tmpValue; $dataForDb[$field] = $value;
} }
// Check if the user alredy exists. // Current date
if( $this->userExists($dataForDb['username']) ) {
return false;
}
// Current date.
$dataForDb['registered'] = Date::current(DB_DATE_FORMAT); $dataForDb['registered'] = Date::current(DB_DATE_FORMAT);
// Password // Password
@ -87,12 +72,7 @@ class dbUsers extends dbJSON
// Save the database // Save the database
$this->db[$dataForDb['username']] = $dataForDb; $this->db[$dataForDb['username']] = $dataForDb;
if( $this->save() === false ) { return $this->save();
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
return true;
} }
// Set the parameters of a user // Set the parameters of a user

View File

@ -164,10 +164,16 @@ function printDebug($array) {
echo '</pre>'; echo '</pre>';
} }
function createNewPage($args) { function createPage($args) {
global $dbPages; global $dbPages;
global $Syslog; 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); $key = $dbPages->add($args);
if($key) { if($key) {
// Call the plugins after page created // Call the plugins after page created
@ -199,6 +205,12 @@ function editPage($args) {
global $dbPages; global $dbPages;
global $Syslog; 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'])) { if(!isset($args['parent'])) {
$args['parent'] = NO_PARENT_CHAR; $args['parent'] = NO_PARENT_CHAR;
} }
@ -327,3 +339,55 @@ function deleteUser($args, $deleteContent=false)
return 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;
}