Bug fixes

This commit is contained in:
Diego Najar 2018-07-17 23:58:01 +02:00
parent 47e5994c94
commit 35694980ab
9 changed files with 136 additions and 62 deletions

View File

@ -5,13 +5,21 @@
// ============================================================================ // ============================================================================
if (!checkRole(array('admin','moderator'), false)) { if (!checkRole(array('admin','moderator'), false)) {
try {
$pageKey = isset($_POST['key']) ? $_POST['key'] : $layout['parameters']; $pageKey = isset($_POST['key']) ? $_POST['key'] : $layout['parameters'];
$page = buildPage($pageKey); $page = new PageX($pageKey);
if (!$page || $page->username()!==$login->username()) { } catch (Exception $e) {
Alert::set($Language->g('You do not have sufficient permissions'));
Redirect::page('dashboard');
}
if ($page->username()!==$login->username()) {
// Add to syslog
$syslog->add(array( $syslog->add(array(
'dictionaryKey'=>'access-deny', 'dictionaryKey'=>'access-deny',
'notes'=>$login->username() 'notes'=>$login->username()
)); ));
Alert::set($Language->g('You do not have sufficient permissions')); Alert::set($Language->g('You do not have sufficient permissions'));
Redirect::page('dashboard'); Redirect::page('dashboard');
} }
@ -30,7 +38,7 @@ if (!checkRole(array('admin','moderator'), false)) {
// ============================================================================ // ============================================================================
if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if ($_POST['status']==='delete') { if ($_POST['type']==='delete') {
if (deletePage($_POST['key'])) { if (deletePage($_POST['key'])) {
Alert::set( $Language->g('The changes have been saved') ); Alert::set( $Language->g('The changes have been saved') );
} }

View File

@ -23,4 +23,15 @@ checkRole(array('admin'));
// ============================================================================ // ============================================================================
$pluginClassName = $layout['parameters']; $pluginClassName = $layout['parameters'];
activatePlugin($pluginClassName); activatePlugin($pluginClassName);
if (isset($plugins['all'][$pluginClassName])) {
$plugin = $plugins['all'][$pluginClassName];
} else {
Redirect::page('plugins');
}
if (method_exists($plugin, 'form')) {
Redirect::page('configure-plugin/'.$pluginClassName);
}
Redirect::page('plugins#'.$pluginClassName); Redirect::page('plugins#'.$pluginClassName);

View File

@ -31,6 +31,11 @@ echo '<td>Bludit Build Number</td>';
echo '<td>'.BLUDIT_BUILD.'</td>'; echo '<td>'.BLUDIT_BUILD.'</td>';
echo '</tr>'; echo '</tr>';
echo '<tr>';
echo '<td><a href="'.HTML_PATH_ADMIN_ROOT.'developers'.'">Bludit Developers</a></td>';
echo '<td></td>';
echo '</tr>';
echo ' echo '
</tbody> </tbody>
</table> </table>

View File

@ -2,7 +2,7 @@
echo Bootstrap::pageTitle(array('title'=>$L->g('Content'), 'icon'=>'cog')); echo Bootstrap::pageTitle(array('title'=>$L->g('Content'), 'icon'=>'cog'));
function table($status) { function table($type) {
global $url; global $url;
global $Language; global $Language;
global $published; global $published;
@ -11,7 +11,7 @@ function table($status) {
global $static; global $static;
global $sticky; global $sticky;
if ($status=='published') { if ($type=='published') {
$list = $published; $list = $published;
if (empty($list)) { if (empty($list)) {
echo '<p class="mt-4 text-muted">'; echo '<p class="mt-4 text-muted">';
@ -19,7 +19,7 @@ function table($status) {
echo '</p>'; echo '</p>';
return false; return false;
} }
} elseif ($status=='draft') { } elseif ($type=='draft') {
$list = $drafts; $list = $drafts;
if (empty($list)) { if (empty($list)) {
echo '<p class="mt-4 text-muted">'; echo '<p class="mt-4 text-muted">';
@ -27,7 +27,7 @@ function table($status) {
echo '</p>'; echo '</p>';
return false; return false;
} }
} elseif ($status=='scheduled') { } elseif ($type=='scheduled') {
$list = $scheduled; $list = $scheduled;
if (empty($list)) { if (empty($list)) {
echo '<p class="mt-4 text-muted">'; echo '<p class="mt-4 text-muted">';
@ -35,7 +35,7 @@ function table($status) {
echo '</p>'; echo '</p>';
return false; return false;
} }
} elseif ($status=='static') { } elseif ($type=='static') {
$list = $static; $list = $static;
if (empty($list)) { if (empty($list)) {
echo '<p class="mt-4 text-muted">'; echo '<p class="mt-4 text-muted">';
@ -43,7 +43,7 @@ function table($status) {
echo '</p>'; echo '</p>';
return false; return false;
} }
} elseif ($status=='sticky') { } elseif ($type=='sticky') {
$list = $sticky; $list = $sticky;
if (empty($list)) { if (empty($list)) {
echo '<p class="mt-4 text-muted">'; echo '<p class="mt-4 text-muted">';
@ -59,7 +59,7 @@ function table($status) {
<tr> <tr>
<th class="border-0" scope="col">'.$Language->g('Title').'</th> <th class="border-0" scope="col">'.$Language->g('Title').'</th>
<th class="border-0 d-none d-lg-table-cell" scope="col">'.$Language->g('URL').'</th> <th class="border-0 d-none d-lg-table-cell" scope="col">'.$Language->g('URL').'</th>
<th class="border-0 text-center d-none d-sm-table-cell" scope="col">'.( ((ORDER_BY=='position') || ($status!='published'))?$Language->g('Position'):$Language->g('Creation date')).'</th> <th class="border-0 text-center d-none d-sm-table-cell" scope="col">'.( ((ORDER_BY=='position') || ($type!='published'))?$Language->g('Position'):$Language->g('Creation date')).'</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -67,9 +67,9 @@ function table($status) {
if (ORDER_BY=='position') { if (ORDER_BY=='position') {
foreach ($list as $pageKey) { foreach ($list as $pageKey) {
$page = buildPage($pageKey); try {
if ($page) { $page = new PageX($pageKey);
if (!$page->isChild() || $status!='published') { if (!$page->isChild() || $type!='published') {
echo '<tr> echo '<tr>
<td> <td>
<a href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">' <a href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">'
@ -102,12 +102,14 @@ function table($status) {
} }
} }
} }
} catch (Exception $e) {
// Continue
} }
} }
} else { } else {
foreach ($list as $pageKey) { foreach ($list as $pageKey) {
$page = buildPage($pageKey); try {
if ($page) { $page = new PageX($pageKey);
echo '<tr>'; echo '<tr>';
echo '<td> echo '<td>
<a href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">' <a href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">'
@ -118,9 +120,11 @@ function table($status) {
$friendlyURL = Text::isEmpty($url->filters('page')) ? '/'.$page->key() : '/'.$url->filters('page').'/'.$page->key(); $friendlyURL = Text::isEmpty($url->filters('page')) ? '/'.$page->key() : '/'.$url->filters('page').'/'.$page->key();
echo '<td class="d-none d-lg-table-cell"><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>'; echo '<td class="d-none d-lg-table-cell"><a target="_blank" href="'.$page->permalink().'">'.$friendlyURL.'</a></td>';
echo '<td class="text-center d-none d-sm-table-cell">'.( ((ORDER_BY=='position') || ($status!='published'))?$page->position():$page->dateRaw(ADMIN_PANEL_DATE_FORMAT) ).'</td>'; echo '<td class="text-center d-none d-sm-table-cell">'.( ((ORDER_BY=='position') || ($type!='published'))?$page->position():$page->dateRaw(ADMIN_PANEL_DATE_FORMAT) ).'</td>';
echo '</tr>'; echo '</tr>';
} catch (Exception $e) {
// Continue
} }
} }
} }

View File

@ -34,7 +34,7 @@ $page = array(
'slug'=>$autosaveUUID, 'slug'=>$autosaveUUID,
'title'=>$title.' [ Autosave ] ', 'title'=>$title.' [ Autosave ] ',
'content'=>$content, 'content'=>$content,
'status'=>'draft' 'type'=>'draft'
); );
// Get the page key by the UUID // Get the page key by the UUID

View File

@ -39,7 +39,7 @@ class dbPages extends dbJSON {
{ {
$row = array(); $row = array();
// Check values on args or set default values // Check values on args and set default values if not exists
foreach ($this->dbFields as $field=>$value) { foreach ($this->dbFields as $field=>$value) {
if (isset($args[$field])) { if (isset($args[$field])) {
// Sanitize if will be stored on database // Sanitize if will be stored on database
@ -52,42 +52,50 @@ class dbPages extends dbJSON {
$row[$field] = $finalValue; $row[$field] = $finalValue;
} }
// Tags // Content
if (!empty($args['tags'])) { // This variable is not belong to the database so is not defined in $row
$row['tags'] = $this->generateTags($args['tags']); $contentRaw = $args['content'];
} else {
$row['tags'] = array(); // Parent
// This variable is not belong to the database so is not defined in $row
$parent = '';
if (!empty($args['parent'])) {
$parent = $args['parent'];
} }
// Slug from the title or the content // Slug from the title or the content
// This variable is not belong to the database so is not defined in $row
if (empty($args['slug'])) { if (empty($args['slug'])) {
if (!empty($args['title'])) { if (!empty($row['title'])) {
$args['slug'] = $this->generateSlug($args['title']); $slug = $this->generateSlug($row['title']);
} else { } else {
$args['slug'] = $this->generateSlug($args['content']); $slug = $this->generateSlug($contentRaw);
} }
} } else {
$slug = $args['slug'];
// Parent
if (!isset($args['parent'])) {
$row['parent'] = '';
} }
// Generate key // Generate key
$key = $this->generateKey($args['slug'], $args['parent']); // This variable is not belong to the database so is not defined in $row
$key = $this->generateKey($slug, $parent);
// Generate UUID // Generate UUID
if (empty($args['uuid'])) { if (empty($row['uuid'])) {
$row['uuid'] = $this->generateUUID(); $row['uuid'] = $this->generateUUID();
} }
// Tags
if (!empty($row['tags'])) {
$row['tags'] = $this->generateTags($args['tags']);
}
// Validate date // Validate date
if (!Valid::date($args['date'], DB_DATE_FORMAT)) { if (!Valid::date($row['date'], DB_DATE_FORMAT)) {
$row['date'] = Date::current(DB_DATE_FORMAT); $row['date'] = Date::current(DB_DATE_FORMAT);
} }
// Schedule page // Schedule page
if (($args['date']>Date::current(DB_DATE_FORMAT)) && ($args['type']=='published')) { if (($row['date']>Date::current(DB_DATE_FORMAT)) && ($row['type']=='published')) {
$row['type'] = 'scheduled'; $row['type'] = 'scheduled';
} }
@ -99,7 +107,7 @@ class dbPages extends dbJSON {
} }
// Create the index.txt and save the file // Create the index.txt and save the file
if( file_put_contents(PATH_PAGES.$key.DS.FILENAME, $args['content']) === false ) { if( file_put_contents(PATH_PAGES.$key.DS.FILENAME, $contentRaw) === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the content in the file ['.FILENAME.']',LOG_TYPE_ERROR); Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the content in the file ['.FILENAME.']',LOG_TYPE_ERROR);
return false; return false;
} }
@ -137,56 +145,73 @@ class dbPages extends dbJSON {
$row[$field] = $finalValue; $row[$field] = $finalValue;
} }
// Tags // Content
if (!empty($args['tags'])) { // This variable is not belong to the database so is not defined in $row
$row['tags'] = $this->generateTags($args['tags']); $contentRaw = $args['content'];
} else {
$row['tags'] = array();
}
// Parent // Parent
if (!isset($args['parent'])) { // This variable is not belong to the database so is not defined in $row
$row['parent'] = ''; $parent = '';
if (!empty($args['parent'])) {
$parent = $args['parent'];
} }
$newKey = $this->generateKey($args['slug'], $row['parent'], false, $args['key']); // Old key
// This variable is not belong to the database so is not defined in $row
$key = $args['key'];
// Slug from the title or the content
// This variable is not belong to the database so is not defined in $row
if (empty($args['slug'])) {
if (!empty($row['title'])) {
$slug = $this->generateSlug($row['title']);
} else {
$slug = $this->generateSlug($contentRaw);
}
} else {
$slug = $args['slug'];
}
// New key
// This variable is not belong to the database so is not defined in $row
$newKey = $this->generateKey($slug, $parent, false, $key);
// If the page is draft then the created time is the current // If the page is draft then the created time is the current
if ($this->db[$args['key']]['type']=='draft') { if ($this->db[$key]['type']=='draft') {
$row['date'] = Date::current(DB_DATE_FORMAT); $row['date'] = Date::current(DB_DATE_FORMAT);
} elseif (!Valid::date($args['date'], DB_DATE_FORMAT)) { } elseif (!Valid::date($row['date'], DB_DATE_FORMAT)) {
$row['date'] = $this->db[$args['key']]['date']; $row['date'] = $this->db[$key]['date'];
} }
// Modified date // Modified date
$row['dateModified'] = Date::current(DB_DATE_FORMAT); $row['dateModified'] = Date::current(DB_DATE_FORMAT);
// Schedule page // Schedule page
if (($args['date']>Date::current(DB_DATE_FORMAT)) && ($args['type']=='published')) { if (($row['date']>Date::current(DB_DATE_FORMAT)) && ($row['type']=='published')) {
$row['type'] = 'scheduled'; $row['type'] = 'scheduled';
} }
if ($climode===false) { if ($climode===false) {
// Move the directory from old key to new key. // Move the directory from old key to new key.
if ($newKey!==$args['key']) { if ($newKey!==$key) {
if( Filesystem::mv(PATH_PAGES.$args['key'], PATH_PAGES.$newKey) === false ) { if( Filesystem::mv(PATH_PAGES.$key, PATH_PAGES.$newKey) === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to move the directory to '.PATH_PAGES.$newKey); Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to move the directory to '.PATH_PAGES.$newKey);
return false; return false;
} }
} }
// Make the index.txt and save the file. // Make the index.txt and save the file.
if (file_put_contents(PATH_PAGES.$newKey.DS.FILENAME, $args['content'])===false) { if (file_put_contents(PATH_PAGES.$newKey.DS.FILENAME, $contentRaw)===false) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to put the content in the file '.FILENAME); Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to put the content in the file '.FILENAME);
return false; return false;
} }
} }
// Remove the old key // Remove the old key
unset( $this->db[$args['key']] ); unset( $this->db[$key] );
// Reindex Orphan Children // Reindex Orphan Children
$this->reindexChildren($args['key'], $newKey); $this->reindexChildren($key, $newKey);
// Checksum MD5 // Checksum MD5
$row['md5file'] = md5_file(PATH_PAGES.$newKey.DS.FILENAME); $row['md5file'] = md5_file(PATH_PAGES.$newKey.DS.FILENAME);

View File

@ -510,10 +510,7 @@ function deletePage($key) {
// Call the plugins after page deleted // Call the plugins after page deleted
Theme::plugins('afterPageDelete'); Theme::plugins('afterPageDelete');
// Re-index categories
reindexCategories(); reindexCategories();
// Re-index tags
reindextags(); reindextags();
// Add to syslog // Add to syslog
@ -533,10 +530,12 @@ function editUser($args) {
global $syslog; global $syslog;
if ($dbUsers->set($args)) { if ($dbUsers->set($args)) {
// Add to syslog
$syslog->add(array( $syslog->add(array(
'dictionaryKey'=>'user-edited', 'dictionaryKey'=>'user-edited',
'notes'=>$args['username'] 'notes'=>$args['username']
)); ));
return true; return true;
} }
@ -563,10 +562,12 @@ function disableUser($args) {
// Disable the user // Disable the user
if ($dbUsers->disableUser($username)) { if ($dbUsers->disableUser($username)) {
// Add to syslog
$syslog->add(array( $syslog->add(array(
'dictionaryKey'=>'user-disabled', 'dictionaryKey'=>'user-disabled',
'notes'=>$username 'notes'=>$username
)); ));
return true; return true;
} }
@ -604,10 +605,12 @@ function deleteUser($args) {
} }
if ($dbUsers->delete($username)) { if ($dbUsers->delete($username)) {
// Add to syslog
$syslog->add(array( $syslog->add(array(
'dictionaryKey'=>'user-deleted', 'dictionaryKey'=>'user-deleted',
'notes'=>$username 'notes'=>$username
)); ));
return true; return true;
} }
@ -746,10 +749,12 @@ function changeUserPassword($args) {
} }
if ($dbUsers->setPassword(array('username'=>$username, 'password'=>$newPassword))) { if ($dbUsers->setPassword(array('username'=>$username, 'password'=>$newPassword))) {
// Add to syslog
$syslog->add(array( $syslog->add(array(
'dictionaryKey'=>'user-password-changed', 'dictionaryKey'=>'user-password-changed',
'notes'=>$username 'notes'=>$username
)); ));
Alert::set($Language->g('The changes have been saved'), ALERT_STATUS_OK); Alert::set($Language->g('The changes have been saved'), ALERT_STATUS_OK);
return true; return true;
} }
@ -769,10 +774,12 @@ function checkRole($allowRoles, $redirect=true) {
} }
if ($redirect) { if ($redirect) {
// Add to syslog
$syslog->add(array( $syslog->add(array(
'dictionaryKey'=>'access-deny', 'dictionaryKey'=>'access-deny',
'notes'=>$login->username() 'notes'=>$login->username()
)); ));
Alert::set($Language->g('You do not have sufficient permissions')); Alert::set($Language->g('You do not have sufficient permissions'));
Redirect::page('dashboard'); Redirect::page('dashboard');
} }
@ -792,6 +799,7 @@ function createCategory($category) {
} }
if ($dbCategories->add(array('name'=>$category))) { if ($dbCategories->add(array('name'=>$category))) {
// Add to syslog
$syslog->add(array( $syslog->add(array(
'dictionaryKey'=>'new-category-created', 'dictionaryKey'=>'new-category-created',
'notes'=>$category 'notes'=>$category
@ -826,6 +834,7 @@ function editCategory($args) {
// Change the category key in the pages database // Change the category key in the pages database
$dbPages->changeCategory($args['oldKey'], $newCategoryKey); $dbPages->changeCategory($args['oldKey'], $newCategoryKey);
// Add to syslog
$syslog->add(array( $syslog->add(array(
'dictionaryKey'=>'category-edited', 'dictionaryKey'=>'category-edited',
'notes'=>$newCategoryKey 'notes'=>$newCategoryKey
@ -845,6 +854,7 @@ function deleteCategory($args) {
// Remove the category from the pages ? or keep it if the user want to recovery the category ? // Remove the category from the pages ? or keep it if the user want to recovery the category ?
// Add to syslog
$syslog->add(array( $syslog->add(array(
'dictionaryKey'=>'category-deleted', 'dictionaryKey'=>'category-deleted',
'notes'=>$args['oldCategoryKey'] 'notes'=>$args['oldCategoryKey']

View File

@ -54,8 +54,8 @@ class pluginDisqus extends Plugin {
if ( !$url->notFound() && if ( !$url->notFound() &&
( $url->whereAmI()=='page' && ( $url->whereAmI()=='page' &&
(($this->getDbField('enablePosts') && $page->status()=='published') || (($this->getDbField('enablePosts') && $page->published()) ||
($this->getDbField('enablePages') && $page->status()=='static')) ($this->getDbField('enablePages') && $page->static()))
) && ) &&
$page->allowComments() ) { $page->allowComments() ) {
$html = '<div id="disqus_thread"></div>'; $html = '<div id="disqus_thread"></div>';

View File

@ -275,7 +275,7 @@ function install($adminPassword, $timezone)
} }
// Directories for initial plugins // Directories for initial plugins
$pluginsToInstall = array('simplemde', 'tags', 'about', 'simple-stats'); $pluginsToInstall = array('simplemde', 'tags', 'about', 'simple-stats', 'robots');
foreach ($pluginsToInstall as $plugin) { foreach ($pluginsToInstall as $plugin) {
if (!mkdir(PATH_PLUGINS_DATABASES.$plugin, DIR_PERMISSIONS, true)) { if (!mkdir(PATH_PLUGINS_DATABASES.$plugin, DIR_PERMISSIONS, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.$plugin; $errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.$plugin;
@ -497,6 +497,17 @@ function install($adminPassword, $timezone)
LOCK_EX LOCK_EX
); );
// File plugins/robots/db.php
file_put_contents(
PATH_PLUGINS_DATABASES.'robots'.DS.'db.php',
$dataHead.json_encode(
array(
'position'=>1
),
JSON_PRETTY_PRINT),
LOCK_EX
);
return true; return true;
} }