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

View File

@ -23,4 +23,15 @@ checkRole(array('admin'));
// ============================================================================
$pluginClassName = $layout['parameters'];
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);

View File

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

View File

@ -2,7 +2,7 @@
echo Bootstrap::pageTitle(array('title'=>$L->g('Content'), 'icon'=>'cog'));
function table($status) {
function table($type) {
global $url;
global $Language;
global $published;
@ -11,7 +11,7 @@ function table($status) {
global $static;
global $sticky;
if ($status=='published') {
if ($type=='published') {
$list = $published;
if (empty($list)) {
echo '<p class="mt-4 text-muted">';
@ -19,7 +19,7 @@ function table($status) {
echo '</p>';
return false;
}
} elseif ($status=='draft') {
} elseif ($type=='draft') {
$list = $drafts;
if (empty($list)) {
echo '<p class="mt-4 text-muted">';
@ -27,7 +27,7 @@ function table($status) {
echo '</p>';
return false;
}
} elseif ($status=='scheduled') {
} elseif ($type=='scheduled') {
$list = $scheduled;
if (empty($list)) {
echo '<p class="mt-4 text-muted">';
@ -35,7 +35,7 @@ function table($status) {
echo '</p>';
return false;
}
} elseif ($status=='static') {
} elseif ($type=='static') {
$list = $static;
if (empty($list)) {
echo '<p class="mt-4 text-muted">';
@ -43,7 +43,7 @@ function table($status) {
echo '</p>';
return false;
}
} elseif ($status=='sticky') {
} elseif ($type=='sticky') {
$list = $sticky;
if (empty($list)) {
echo '<p class="mt-4 text-muted">';
@ -59,7 +59,7 @@ function table($status) {
<tr>
<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 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>
</thead>
<tbody>
@ -67,9 +67,9 @@ function table($status) {
if (ORDER_BY=='position') {
foreach ($list as $pageKey) {
$page = buildPage($pageKey);
if ($page) {
if (!$page->isChild() || $status!='published') {
try {
$page = new PageX($pageKey);
if (!$page->isChild() || $type!='published') {
echo '<tr>
<td>
<a href="'.HTML_PATH_ADMIN_ROOT.'edit-content/'.$page->key().'">'
@ -102,12 +102,14 @@ function table($status) {
}
}
}
} catch (Exception $e) {
// Continue
}
}
} else {
foreach ($list as $pageKey) {
$page = buildPage($pageKey);
if ($page) {
try {
$page = new PageX($pageKey);
echo '<tr>';
echo '<td>
<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();
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>';
} catch (Exception $e) {
// Continue
}
}
}

View File

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

View File

@ -39,7 +39,7 @@ class dbPages extends dbJSON {
{
$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) {
if (isset($args[$field])) {
// Sanitize if will be stored on database
@ -52,42 +52,50 @@ class dbPages extends dbJSON {
$row[$field] = $finalValue;
}
// Tags
if (!empty($args['tags'])) {
$row['tags'] = $this->generateTags($args['tags']);
} else {
$row['tags'] = array();
// Content
// This variable is not belong to the database so is not defined in $row
$contentRaw = $args['content'];
// 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
// This variable is not belong to the database so is not defined in $row
if (empty($args['slug'])) {
if (!empty($args['title'])) {
$args['slug'] = $this->generateSlug($args['title']);
if (!empty($row['title'])) {
$slug = $this->generateSlug($row['title']);
} else {
$args['slug'] = $this->generateSlug($args['content']);
$slug = $this->generateSlug($contentRaw);
}
}
// Parent
if (!isset($args['parent'])) {
$row['parent'] = '';
} else {
$slug = $args['slug'];
}
// 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
if (empty($args['uuid'])) {
if (empty($row['uuid'])) {
$row['uuid'] = $this->generateUUID();
}
// Tags
if (!empty($row['tags'])) {
$row['tags'] = $this->generateTags($args['tags']);
}
// 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);
}
// 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';
}
@ -99,7 +107,7 @@ class dbPages extends dbJSON {
}
// 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);
return false;
}
@ -137,56 +145,73 @@ class dbPages extends dbJSON {
$row[$field] = $finalValue;
}
// Tags
if (!empty($args['tags'])) {
$row['tags'] = $this->generateTags($args['tags']);
} else {
$row['tags'] = array();
}
// Content
// This variable is not belong to the database so is not defined in $row
$contentRaw = $args['content'];
// Parent
if (!isset($args['parent'])) {
$row['parent'] = '';
// This variable is not belong to the database so is not defined in $row
$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 ($this->db[$args['key']]['type']=='draft') {
if ($this->db[$key]['type']=='draft') {
$row['date'] = Date::current(DB_DATE_FORMAT);
} elseif (!Valid::date($args['date'], DB_DATE_FORMAT)) {
$row['date'] = $this->db[$args['key']]['date'];
} elseif (!Valid::date($row['date'], DB_DATE_FORMAT)) {
$row['date'] = $this->db[$key]['date'];
}
// Modified date
$row['dateModified'] = Date::current(DB_DATE_FORMAT);
// 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';
}
if ($climode===false) {
// Move the directory from old key to new key.
if ($newKey!==$args['key']) {
if( Filesystem::mv(PATH_PAGES.$args['key'], PATH_PAGES.$newKey) === false ) {
if ($newKey!==$key) {
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);
return false;
}
}
// 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);
return false;
}
}
// Remove the old key
unset( $this->db[$args['key']] );
unset( $this->db[$key] );
// Reindex Orphan Children
$this->reindexChildren($args['key'], $newKey);
$this->reindexChildren($key, $newKey);
// Checksum MD5
$row['md5file'] = md5_file(PATH_PAGES.$newKey.DS.FILENAME);

View File

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

View File

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

View File

@ -275,7 +275,7 @@ function install($adminPassword, $timezone)
}
// Directories for initial plugins
$pluginsToInstall = array('simplemde', 'tags', 'about', 'simple-stats');
$pluginsToInstall = array('simplemde', 'tags', 'about', 'simple-stats', 'robots');
foreach ($pluginsToInstall as $plugin) {
if (!mkdir(PATH_PLUGINS_DATABASES.$plugin, DIR_PERMISSIONS, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.$plugin;
@ -497,6 +497,17 @@ function install($adminPassword, $timezone)
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;
}