2016-05-29 19:21:11 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
2018-02-09 00:46:12 +01:00
|
|
|
// Re-index database of categories
|
2017-12-26 17:45:02 +01:00
|
|
|
// If you create/edit/remove a page is necessary regenerate the database of categories
|
2017-07-26 01:17:13 +02:00
|
|
|
function reindexCategories() {
|
2018-08-02 22:33:53 +02:00
|
|
|
global $categories;
|
|
|
|
return $categories->reindex();
|
2016-05-29 19:21:11 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 00:46:12 +01:00
|
|
|
// Re-index database of tags
|
|
|
|
// If you create/edit/remove a page is necessary regenerate the database of tags
|
2017-07-26 01:17:13 +02:00
|
|
|
function reindexTags() {
|
2018-08-02 22:33:53 +02:00
|
|
|
global $tags;
|
|
|
|
return $tags->reindex();
|
2017-03-26 20:51:32 +02:00
|
|
|
}
|
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
// Generate the page 404 Not found
|
2017-07-28 19:37:06 +02:00
|
|
|
function buildErrorPage() {
|
2018-07-17 19:13:01 +02:00
|
|
|
global $site;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2017-07-28 19:37:06 +02:00
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
try {
|
|
|
|
$pageNotFoundKey = $site->pageNotFound();
|
2018-08-02 17:06:53 +02:00
|
|
|
$pageNotFound = New Page($pageNotFoundKey);
|
2018-07-17 19:13:01 +02:00
|
|
|
} catch (Exception $e) {
|
2018-08-02 17:06:53 +02:00
|
|
|
$pageNotFound = New Page(false);
|
2018-08-05 17:54:20 +02:00
|
|
|
$pageNotFound->setField('title', $L->get('page-not-found'));
|
|
|
|
$pageNotFound->setField('content', $L->get('page-not-found-content'));
|
2018-07-25 23:42:00 +02:00
|
|
|
$pageNotFound->setField('username', 'admin');
|
2018-07-17 19:13:01 +02:00
|
|
|
}
|
2017-07-28 19:37:06 +02:00
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
return $pageNotFound;
|
2017-07-28 19:37:06 +02:00
|
|
|
}
|
|
|
|
|
2017-12-26 17:45:02 +01:00
|
|
|
// This function is only used from the rule 69.pages.php, DO NOT use this function!
|
2018-02-09 00:46:12 +01:00
|
|
|
// This function generate a particular page from the current slug of the url
|
2019-05-09 17:20:35 +02:00
|
|
|
// If the slug has not a page associacted returns FALSE and set not-found as true
|
2017-07-26 01:17:13 +02:00
|
|
|
function buildThePage() {
|
2018-07-17 19:13:01 +02:00
|
|
|
global $url;
|
2017-07-26 01:17:13 +02:00
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
try {
|
|
|
|
$pageKey = $url->slug();
|
2018-08-02 17:06:53 +02:00
|
|
|
$page = New Page($pageKey);
|
2018-07-17 19:13:01 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$url->setNotFound();
|
2017-07-26 01:17:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
2018-07-17 19:13:01 +02:00
|
|
|
|
2019-05-26 23:09:38 +02:00
|
|
|
if ($page->draft() || $page->scheduled() || $page->autosave()) {
|
2019-05-09 17:20:35 +02:00
|
|
|
if ($url->parameter('preview')!==md5($page->uuid())) {
|
|
|
|
$url->setNotFound();
|
|
|
|
return false;
|
|
|
|
}
|
2017-07-26 01:17:13 +02:00
|
|
|
}
|
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
return $page;
|
2017-07-26 01:17:13 +02:00
|
|
|
}
|
|
|
|
|
2017-12-26 17:45:02 +01:00
|
|
|
// This function is only used from the rule 69.pages.php, DO NOT use this function!
|
2017-07-26 01:17:13 +02:00
|
|
|
function buildPagesForHome() {
|
2017-05-10 23:21:45 +02:00
|
|
|
return buildPagesFor('home');
|
2017-05-10 20:40:28 +02:00
|
|
|
}
|
|
|
|
|
2017-12-26 17:45:02 +01:00
|
|
|
// This function is only used from the rule 69.pages.php, DO NOT use this function!
|
2017-07-26 01:17:13 +02:00
|
|
|
function buildPagesByCategory() {
|
2018-07-17 19:13:01 +02:00
|
|
|
global $url;
|
2017-05-12 20:18:44 +02:00
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
$categoryKey = $url->slug();
|
2017-05-10 23:21:45 +02:00
|
|
|
return buildPagesFor('category', $categoryKey, false);
|
2017-05-10 20:40:28 +02:00
|
|
|
}
|
|
|
|
|
2017-12-26 17:45:02 +01:00
|
|
|
// This function is only used from the rule 69.pages.php, DO NOT use this function!
|
2017-07-26 01:17:13 +02:00
|
|
|
function buildPagesByTag() {
|
2018-07-17 19:13:01 +02:00
|
|
|
global $url;
|
2017-05-12 20:18:44 +02:00
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
$tagKey = $url->slug();
|
2017-05-10 23:21:45 +02:00
|
|
|
return buildPagesFor('tag', false, $tagKey);
|
|
|
|
}
|
|
|
|
|
2018-02-09 00:46:12 +01:00
|
|
|
// This function is only used from the rule 69.pages.php, DO NOT use this function!
|
2018-07-17 19:13:01 +02:00
|
|
|
// Generate the global variables $content / $content, defined on 69.pages.php
|
2018-02-09 00:46:12 +01:00
|
|
|
// This function is use for buildPagesForHome(), buildPagesByCategory(), buildPagesByTag()
|
2017-07-26 01:17:13 +02:00
|
|
|
function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $pages;
|
2018-08-02 22:33:53 +02:00
|
|
|
global $categories;
|
|
|
|
global $tags;
|
2018-07-17 19:13:01 +02:00
|
|
|
global $site;
|
|
|
|
global $url;
|
2016-05-29 19:21:11 +02:00
|
|
|
|
2017-05-10 23:21:45 +02:00
|
|
|
// Get the page number from URL
|
2018-07-17 19:13:01 +02:00
|
|
|
$pageNumber = $url->pageNumber();
|
2017-05-10 23:21:45 +02:00
|
|
|
|
2017-09-10 23:09:44 +02:00
|
|
|
if ($for=='home') {
|
2017-05-10 23:21:45 +02:00
|
|
|
$onlyPublished = true;
|
2018-08-06 21:46:58 +02:00
|
|
|
$numberOfItems = $site->itemsPerPage();
|
|
|
|
$list = $pages->getList($pageNumber, $numberOfItems, $onlyPublished);
|
2018-03-27 18:40:03 +02:00
|
|
|
|
|
|
|
// Include sticky pages only in the first page
|
|
|
|
if ($pageNumber==1) {
|
2018-08-03 18:59:23 +02:00
|
|
|
$sticky = $pages->getStickyDB();
|
2018-03-27 18:40:03 +02:00
|
|
|
$list = array_merge($sticky, $list);
|
|
|
|
}
|
2017-05-10 23:21:45 +02:00
|
|
|
}
|
2017-09-10 23:09:44 +02:00
|
|
|
elseif ($for=='category') {
|
2018-08-06 21:46:58 +02:00
|
|
|
$numberOfItems = $site->itemsPerPage();
|
|
|
|
$list = $categories->getList($categoryKey, $pageNumber, $numberOfItems);
|
2017-05-10 23:21:45 +02:00
|
|
|
}
|
2017-09-10 23:09:44 +02:00
|
|
|
elseif ($for=='tag') {
|
2018-08-06 21:46:58 +02:00
|
|
|
$numberOfItems = $site->itemsPerPage();
|
|
|
|
$list = $tags->getList($tagKey, $pageNumber, $numberOfItems);
|
2016-05-29 19:21:11 +02:00
|
|
|
}
|
|
|
|
|
2017-07-26 01:17:13 +02:00
|
|
|
// There are not items, invalid tag, invalid category, out of range, etc...
|
2017-07-30 23:15:33 +02:00
|
|
|
if ($list===false) {
|
2018-07-17 19:13:01 +02:00
|
|
|
$url->setNotFound();
|
2017-07-26 01:17:13 +02:00
|
|
|
return false;
|
2016-05-29 19:21:11 +02:00
|
|
|
}
|
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
$content = array();
|
2018-02-09 00:46:12 +01:00
|
|
|
foreach ($list as $pageKey) {
|
2018-07-17 19:13:01 +02:00
|
|
|
try {
|
2018-08-02 17:06:53 +02:00
|
|
|
$page = new Page($pageKey);
|
2019-02-28 19:55:06 +01:00
|
|
|
if ( ($page->type()=='published') ||
|
|
|
|
($page->type()=='sticky') ||
|
|
|
|
($page->type()=='static')
|
|
|
|
) {
|
|
|
|
array_push($content, $page);
|
|
|
|
}
|
2018-07-17 19:13:01 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
// continue
|
2017-05-10 20:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2018-10-18 19:21:57 +02:00
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
return $content;
|
2017-05-10 20:40:28 +02:00
|
|
|
}
|
2017-06-04 22:08:20 +02:00
|
|
|
|
2018-02-09 00:46:12 +01:00
|
|
|
// Returns an array with all the static pages as Page-Object
|
|
|
|
// The static pages are order by position all the time
|
|
|
|
function buildStaticPages() {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $pages;
|
2018-02-09 00:46:12 +01:00
|
|
|
|
|
|
|
$list = array();
|
2018-08-03 18:59:23 +02:00
|
|
|
$pagesKey = $pages->getStaticDB();
|
2018-07-18 21:48:37 +02:00
|
|
|
foreach ($pagesKey as $pageKey) {
|
2018-07-17 19:13:01 +02:00
|
|
|
try {
|
2018-08-02 17:06:53 +02:00
|
|
|
$page = new Page($pageKey);
|
2018-07-18 21:48:37 +02:00
|
|
|
array_push($list, $page);
|
2018-07-17 19:13:01 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
// continue
|
|
|
|
}
|
2018-02-09 00:46:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:06:53 +02:00
|
|
|
// Returns the Page-Object if exists, FALSE otherwise
|
|
|
|
function buildPage($pageKey) {
|
|
|
|
try {
|
|
|
|
$page = new Page($pageKey);
|
|
|
|
return $page;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 00:46:12 +01:00
|
|
|
// Returns an array with all the parent pages as Page-Object
|
|
|
|
// The pages are order by the settings on the system
|
|
|
|
function buildParentPages() {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $pages;
|
2018-02-09 00:46:12 +01:00
|
|
|
|
|
|
|
$list = array();
|
2018-08-03 18:59:23 +02:00
|
|
|
$pagesKey = $pages->getPublishedDB();
|
2018-02-09 00:46:12 +01:00
|
|
|
foreach ($pagesKey as $pageKey) {
|
2018-07-18 21:48:37 +02:00
|
|
|
try {
|
2018-08-02 17:06:53 +02:00
|
|
|
$page = new Page($pageKey);
|
2018-09-09 17:53:08 +02:00
|
|
|
if ($page->isParent()) {
|
|
|
|
array_push($list, $page);
|
|
|
|
}
|
2018-07-18 21:48:37 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
// continue
|
2018-02-09 00:46:12 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the Plugin-Object if is enabled and installed, FALSE otherwise
|
2017-12-27 14:19:28 +01:00
|
|
|
function getPlugin($pluginClassName) {
|
2017-12-20 20:37:17 +01:00
|
|
|
global $plugins;
|
|
|
|
|
2018-09-03 18:31:46 +02:00
|
|
|
if (pluginActivated($pluginClassName)) {
|
2017-12-27 14:19:28 +01:00
|
|
|
return $plugins['all'][$pluginClassName];
|
2017-12-20 20:37:17 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-27 14:44:57 +01:00
|
|
|
// Returns TRUE if the plugin is activaed / installed, FALSE otherwise
|
|
|
|
function pluginActivated($pluginClassName) {
|
|
|
|
global $plugins;
|
|
|
|
|
|
|
|
if (isset($plugins['all'][$pluginClassName])) {
|
|
|
|
return $plugins['all'][$pluginClassName]->installed();
|
|
|
|
}
|
|
|
|
return false;
|
2017-06-19 23:14:38 +02:00
|
|
|
}
|
|
|
|
|
2017-09-09 00:33:14 +02:00
|
|
|
function activatePlugin($pluginClassName) {
|
|
|
|
global $plugins;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2017-09-09 00:33:14 +02:00
|
|
|
|
|
|
|
// Check if the plugin exists
|
|
|
|
if (isset($plugins['all'][$pluginClassName])) {
|
|
|
|
$plugin = $plugins['all'][$pluginClassName];
|
|
|
|
if ($plugin->install()) {
|
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-09-09 00:33:14 +02:00
|
|
|
'dictionaryKey'=>'plugin-activated',
|
|
|
|
'notes'=>$plugin->name()
|
|
|
|
));
|
|
|
|
|
|
|
|
// Create an alert
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('plugin-activated'));
|
2017-09-09 00:33:14 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deactivatePlugin($pluginClassName) {
|
|
|
|
global $plugins;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2017-09-09 00:33:14 +02:00
|
|
|
|
|
|
|
// Check if the plugin exists
|
|
|
|
if (isset($plugins['all'][$pluginClassName])) {
|
|
|
|
$plugin = $plugins['all'][$pluginClassName];
|
|
|
|
|
|
|
|
if ($plugin->uninstall()) {
|
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-09-09 00:33:14 +02:00
|
|
|
'dictionaryKey'=>'plugin-deactivated',
|
|
|
|
'notes'=>$plugin->name()
|
|
|
|
));
|
|
|
|
|
|
|
|
// Create an alert
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('plugin-deactivated'));
|
2017-09-09 00:33:14 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-18 19:41:54 +01:00
|
|
|
function deactivateAllPlugin() {
|
|
|
|
global $plugins;
|
|
|
|
global $syslog;
|
|
|
|
global $L;
|
|
|
|
|
|
|
|
// Check if the plugin exists
|
|
|
|
foreach ($plugins['all'] as $plugin) {
|
|
|
|
if ($plugin->uninstall()) {
|
|
|
|
// Add to syslog
|
|
|
|
$syslog->add(array(
|
|
|
|
'dictionaryKey'=>'plugin-deactivated',
|
|
|
|
'notes'=>$plugin->name()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-06 18:26:59 +01:00
|
|
|
function changePluginsPosition($pluginClassList) {
|
|
|
|
global $plugins;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-02-06 18:26:59 +01:00
|
|
|
|
|
|
|
foreach ($pluginClassList as $position=>$pluginClassName) {
|
|
|
|
if (isset($plugins['all'][$pluginClassName])) {
|
|
|
|
$plugin = $plugins['all'][$pluginClassName];
|
|
|
|
$plugin->setPosition(++$position);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2018-02-06 18:26:59 +01:00
|
|
|
'dictionaryKey'=>'plugins-sorted',
|
|
|
|
'notes'=>''
|
|
|
|
));
|
|
|
|
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('The changes have been saved'));
|
2018-02-06 18:26:59 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-09-14 15:48:57 +02:00
|
|
|
/*
|
|
|
|
Create a new page
|
|
|
|
|
|
|
|
The array $args support all the keys from variable $dbFields of the class pages.class.php
|
|
|
|
If you don't pass all the keys, the default values are used, the default values are from $dbFields in the class pages.class.php
|
|
|
|
*/
|
2017-07-05 19:59:51 +02:00
|
|
|
function createPage($args) {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $pages;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2017-06-22 23:50:12 +02:00
|
|
|
|
2018-05-08 00:15:40 +02:00
|
|
|
// Check if the autosave page exists for this new page and delete it
|
2018-07-17 19:13:01 +02:00
|
|
|
if (isset($args['uuid'])) {
|
2018-08-03 18:59:23 +02:00
|
|
|
$autosaveKey = $pages->getByUUID('autosave-'.$args['uuid']);
|
2018-07-17 19:13:01 +02:00
|
|
|
if (!empty($autosaveKey)) {
|
|
|
|
Log::set('Function createPage()'.LOG_SEP.'Autosave deleted for '.$args['title'], LOG_TYPE_INFO);
|
|
|
|
deletePage($autosaveKey);
|
|
|
|
}
|
2018-05-08 00:15:40 +02:00
|
|
|
}
|
|
|
|
|
2017-07-05 19:59:51 +02:00
|
|
|
// The user is always the one loggued
|
|
|
|
$args['username'] = Session::get('username');
|
2018-07-11 23:36:46 +02:00
|
|
|
if (empty($args['username'])) {
|
|
|
|
Log::set('Function createPage()'.LOG_SEP.'Empty username.', LOG_TYPE_ERROR);
|
2017-07-05 19:59:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-03 18:59:23 +02:00
|
|
|
$key = $pages->add($args);
|
2017-07-29 01:20:47 +02:00
|
|
|
if ($key) {
|
2017-06-22 23:50:12 +02:00
|
|
|
// Call the plugins after page created
|
|
|
|
Theme::plugins('afterPageCreate');
|
|
|
|
|
|
|
|
reindexCategories();
|
2019-02-22 14:25:40 +01:00
|
|
|
reindexTags();
|
2017-06-22 23:50:12 +02:00
|
|
|
|
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-10-02 22:42:18 +02:00
|
|
|
'dictionaryKey'=>'new-content-created',
|
2019-02-20 23:13:59 +01:00
|
|
|
'notes'=>(empty($args['title'])?$key:$args['title'])
|
2017-06-22 23:50:12 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
2018-07-11 23:36:46 +02:00
|
|
|
Log::set('Function createNewPage()'.LOG_SEP.'Error occurred when trying to create the page', LOG_TYPE_ERROR);
|
|
|
|
Log::set('Function createNewPage()'.LOG_SEP.'Cleaning database...', LOG_TYPE_ERROR);
|
|
|
|
deletePage($key);
|
|
|
|
Log::set('Function createNewPage()'.LOG_SEP.'Cleaning finished...', LOG_TYPE_ERROR);
|
2017-06-22 23:50:12 +02:00
|
|
|
|
|
|
|
return false;
|
2017-06-23 00:41:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function editPage($args) {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $pages;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-06-23 00:41:00 +02:00
|
|
|
|
2019-05-26 23:09:38 +02:00
|
|
|
// Check if the autosave/preview page exists for this new page and delete it
|
2018-07-17 19:13:01 +02:00
|
|
|
if (isset($args['uuid'])) {
|
2019-02-25 16:32:00 +01:00
|
|
|
$autosaveKey = $pages->getByUUID('autosave-'.$args['uuid']);
|
|
|
|
if ($autosaveKey) {
|
2019-05-26 23:09:38 +02:00
|
|
|
Log::set('Function editPage()'.LOG_SEP.'Autosave/Preview deleted for '.$autosaveKey, LOG_TYPE_INFO);
|
2019-02-25 16:32:00 +01:00
|
|
|
deletePage($autosaveKey);
|
2018-07-17 19:13:01 +02:00
|
|
|
}
|
2018-05-08 00:15:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-11 23:36:46 +02:00
|
|
|
// Check if the key is not empty
|
2017-09-23 13:10:05 +02:00
|
|
|
if (empty($args['key'])) {
|
2018-07-11 23:36:46 +02:00
|
|
|
Log::set('Function editPage()'.LOG_SEP.'Empty key.', LOG_TYPE_ERROR);
|
2017-09-23 13:10:05 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the page key exist
|
2018-08-03 18:59:23 +02:00
|
|
|
if (!$pages->exists($args['key'])) {
|
2018-07-11 23:36:46 +02:00
|
|
|
Log::set('Function editPage()'.LOG_SEP.'Page key does not exist, '.$args['key'], LOG_TYPE_ERROR);
|
2017-07-05 19:59:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-03 18:59:23 +02:00
|
|
|
$key = $pages->edit($args);
|
2017-08-11 21:22:26 +02:00
|
|
|
if ($key) {
|
2017-06-23 00:41:00 +02:00
|
|
|
// Call the plugins after page modified
|
|
|
|
Theme::plugins('afterPageModify');
|
|
|
|
|
|
|
|
reindexCategories();
|
2019-02-22 14:25:40 +01:00
|
|
|
reindexTags();
|
2017-06-23 00:41:00 +02:00
|
|
|
|
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-10-02 22:42:18 +02:00
|
|
|
'dictionaryKey'=>'content-edited',
|
2019-02-25 16:32:00 +01:00
|
|
|
'notes'=>empty($args['title'])?$key:$args['title']
|
2017-06-23 00:41:00 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
return $key;
|
|
|
|
}
|
|
|
|
|
2018-07-11 23:36:46 +02:00
|
|
|
Log::set('Function editPage()'.LOG_SEP.'Something happen when try to edit the page.', LOG_TYPE_ERROR);
|
2017-06-23 00:41:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deletePage($key) {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $pages;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-06-23 00:41:00 +02:00
|
|
|
|
2018-08-03 18:59:23 +02:00
|
|
|
if ($pages->delete($key)) {
|
2017-06-23 00:41:00 +02:00
|
|
|
// Call the plugins after page deleted
|
|
|
|
Theme::plugins('afterPageDelete');
|
|
|
|
|
|
|
|
reindexCategories();
|
2019-02-22 14:25:40 +01:00
|
|
|
reindexTags();
|
2017-06-23 00:41:00 +02:00
|
|
|
|
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-10-02 22:42:18 +02:00
|
|
|
'dictionaryKey'=>'content-deleted',
|
2017-06-23 00:41:00 +02:00
|
|
|
'notes'=>$key
|
|
|
|
));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-28 00:31:40 +02:00
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
function editUser($args) {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $users;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-06-28 00:31:40 +02:00
|
|
|
|
2018-08-03 18:59:23 +02:00
|
|
|
if ($users->set($args)) {
|
2018-07-17 23:58:01 +02:00
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2018-05-14 00:00:10 +02:00
|
|
|
'dictionaryKey'=>'user-edited',
|
|
|
|
'notes'=>$args['username']
|
2017-06-28 00:31:40 +02:00
|
|
|
));
|
2018-07-17 23:58:01 +02:00
|
|
|
|
2017-06-28 00:31:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
function disableUser($args) {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $users;
|
2018-07-14 15:17:06 +02:00
|
|
|
global $login;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-06-28 00:31:40 +02:00
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
// Arguments
|
|
|
|
$username = $args['username'];
|
|
|
|
|
|
|
|
// Only administrators can disable users
|
2018-07-14 15:17:06 +02:00
|
|
|
if ($login->role()!=='admin') {
|
2018-05-14 00:00:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the username exists
|
2018-08-03 18:59:23 +02:00
|
|
|
if (!$users->exists($username)) {
|
2018-05-14 00:00:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable the user
|
2018-08-03 18:59:23 +02:00
|
|
|
if ($users->disableUser($username)) {
|
2018-07-17 23:58:01 +02:00
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2018-05-14 00:00:10 +02:00
|
|
|
'dictionaryKey'=>'user-disabled',
|
|
|
|
'notes'=>$username
|
2017-06-28 00:31:40 +02:00
|
|
|
));
|
2018-07-17 23:58:01 +02:00
|
|
|
|
2017-06-28 00:31:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
function deleteUser($args) {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $users, $pages;
|
2018-07-14 15:17:06 +02:00
|
|
|
global $login;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-06-28 00:31:40 +02:00
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
// Arguments
|
|
|
|
$username = $args['username'];
|
|
|
|
$deleteContent = isset($args['deleteContent']) ? $args['deleteContent'] : false;
|
|
|
|
|
|
|
|
// Only administrators can delete users
|
2018-07-14 15:17:06 +02:00
|
|
|
if ($login->role()!=='admin') {
|
2017-06-28 00:31:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
// The user admin cannot be deleted
|
|
|
|
if ($username=='admin') {
|
2017-06-28 00:31:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
// Check if the username exists
|
2018-08-03 18:59:23 +02:00
|
|
|
if (!$users->exists($username)) {
|
2018-05-14 00:00:10 +02:00
|
|
|
return false;
|
2017-06-28 00:31:40 +02:00
|
|
|
}
|
2018-05-14 00:00:10 +02:00
|
|
|
|
|
|
|
if ($deleteContent) {
|
2018-08-03 18:59:23 +02:00
|
|
|
$pages->deletePagesByUser(array('username'=>$username));
|
2018-05-14 00:00:10 +02:00
|
|
|
} else {
|
2018-08-03 18:59:23 +02:00
|
|
|
$pages->transferPages(array('oldUsername'=>$username));
|
2017-06-28 00:31:40 +02:00
|
|
|
}
|
|
|
|
|
2018-08-03 18:59:23 +02:00
|
|
|
if ($users->delete($username)) {
|
2018-07-17 23:58:01 +02:00
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-06-28 00:31:40 +02:00
|
|
|
'dictionaryKey'=>'user-deleted',
|
2018-05-14 00:00:10 +02:00
|
|
|
'notes'=>$username
|
2017-06-28 00:31:40 +02:00
|
|
|
));
|
2018-07-17 23:58:01 +02:00
|
|
|
|
2017-06-28 00:31:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-05 19:59:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-05 23:30:30 +02:00
|
|
|
function createUser($args) {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $users;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-07-05 19:59:51 +02:00
|
|
|
|
2020-01-01 13:34:59 +01:00
|
|
|
$args['new_username'] = Text::removeSpecialCharacters($args['new_username']);
|
|
|
|
|
2017-07-05 19:59:51 +02:00
|
|
|
// Check empty username
|
2018-04-27 20:36:43 +02:00
|
|
|
if (Text::isEmpty($args['new_username'])) {
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('username-field-is-empty'), ALERT_STATUS_FAIL);
|
2017-07-05 19:59:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check already exist username
|
2018-08-03 18:59:23 +02:00
|
|
|
if ($users->exists($args['new_username'])) {
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('username-already-exists'), ALERT_STATUS_FAIL);
|
2017-07-05 19:59:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Password length
|
2018-04-27 20:36:43 +02:00
|
|
|
if (Text::length($args['new_password']) < PASSWORD_LENGTH) {
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('Password must be at least '.PASSWORD_LENGTH.' characters long'), ALERT_STATUS_FAIL);
|
2017-07-05 19:59:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check new password and confirm password are equal
|
2018-04-27 20:36:43 +02:00
|
|
|
if ($args['new_password'] != $args['confirm_password']) {
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('The password and confirmation password do not match'), ALERT_STATUS_FAIL);
|
2017-07-05 19:59:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Filter form fields
|
|
|
|
$tmp = array();
|
2020-01-01 13:34:59 +01:00
|
|
|
$tmp['username'] = $args['new_username'];
|
2017-07-05 19:59:51 +02:00
|
|
|
$tmp['password'] = $args['new_password'];
|
|
|
|
$tmp['role'] = $args['role'];
|
|
|
|
$tmp['email'] = $args['email'];
|
|
|
|
|
|
|
|
// Add the user to the database
|
2018-08-03 18:59:23 +02:00
|
|
|
if ($users->add($tmp)) {
|
2017-07-05 19:59:51 +02:00
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-09-08 00:43:53 +02:00
|
|
|
'dictionaryKey'=>'new-user-created',
|
2017-07-05 19:59:51 +02:00
|
|
|
'notes'=>$tmp['username']
|
|
|
|
));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-26 21:00:20 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function editSettings($args) {
|
2018-07-17 19:13:01 +02:00
|
|
|
global $site;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-08-03 18:59:23 +02:00
|
|
|
global $pages;
|
2017-07-26 21:00:20 +02:00
|
|
|
|
2017-09-03 23:29:09 +02:00
|
|
|
if (isset($args['language'])) {
|
2018-07-17 19:13:01 +02:00
|
|
|
if ($args['language']!=$site->language()) {
|
2017-09-03 23:29:09 +02:00
|
|
|
$tmp = new dbJSON(PATH_LANGUAGES.$args['language'].'.json', false);
|
|
|
|
if (isset($tmp->db['language-data']['locale'])) {
|
|
|
|
$args['locale'] = $tmp->db['language-data']['locale'];
|
|
|
|
} else {
|
|
|
|
$args['locale'] = $args['language'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 20:16:45 +02:00
|
|
|
if (empty($args['homepage'])) {
|
|
|
|
$args['homepage'] = '';
|
2020-03-25 21:25:00 +01:00
|
|
|
$args['uriBlog'] = '';
|
2019-09-25 20:16:45 +02:00
|
|
|
}
|
2020-03-25 21:25:00 +01:00
|
|
|
|
2019-09-25 20:16:45 +02:00
|
|
|
if (empty($args['pageNotFound'])) {
|
|
|
|
$args['pageNotFound'] = '';
|
|
|
|
}
|
|
|
|
|
2017-09-09 00:33:14 +02:00
|
|
|
if (isset($args['uriPage'])) {
|
|
|
|
$args['uriPage'] = Text::addSlashes($args['uriPage']);
|
|
|
|
}
|
2018-03-06 19:42:18 +01:00
|
|
|
|
2017-09-09 00:33:14 +02:00
|
|
|
if (isset($args['uriTag'])) {
|
|
|
|
$args['uriTag'] = Text::addSlashes($args['uriTag']);
|
|
|
|
}
|
2018-03-06 19:42:18 +01:00
|
|
|
|
2017-09-09 00:33:14 +02:00
|
|
|
if (isset($args['uriCategory'])) {
|
|
|
|
$args['uriCategory'] = Text::addSlashes($args['uriCategory']);
|
|
|
|
}
|
|
|
|
|
2020-03-25 21:25:00 +01:00
|
|
|
if (!empty($args['uriBlog'])) {
|
2017-09-15 20:02:53 +02:00
|
|
|
$args['uriBlog'] = Text::addSlashes($args['uriBlog']);
|
2018-03-06 19:42:18 +01:00
|
|
|
} else {
|
2020-03-25 21:25:00 +01:00
|
|
|
if (!empty($args['homepage']) && empty($args['uriBlog'])) {
|
|
|
|
$args['uriBlog'] = '/blog/';
|
|
|
|
} else {
|
|
|
|
$args['uriBlog'] = '';
|
|
|
|
}
|
2017-09-15 20:02:53 +02:00
|
|
|
}
|
|
|
|
|
2019-05-12 12:32:12 +02:00
|
|
|
if (isset($args['extremeFriendly'])) {
|
|
|
|
$args['extremeFriendly'] = (($args['extremeFriendly']=='true')?true:false);
|
|
|
|
}
|
2018-07-28 21:00:12 +02:00
|
|
|
|
2019-09-02 18:24:34 +02:00
|
|
|
if (isset($args['customFields'])) {
|
|
|
|
// Custom fields need to be JSON format valid, also the empty JSON need to be "{}"
|
|
|
|
json_decode($args['customFields']);
|
|
|
|
if (json_last_error() != JSON_ERROR_NONE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$pages->setCustomFields($args['customFields']);
|
|
|
|
}
|
|
|
|
|
2018-07-17 19:13:01 +02:00
|
|
|
if ($site->set($args)) {
|
2017-09-09 00:33:14 +02:00
|
|
|
// Check current order-by if changed it reorder the content
|
2018-07-17 19:13:01 +02:00
|
|
|
if ($site->orderBy()!=ORDER_BY) {
|
|
|
|
if ($site->orderBy()=='date') {
|
2018-08-03 18:59:23 +02:00
|
|
|
$pages->sortByDate();
|
2017-09-09 00:33:14 +02:00
|
|
|
} else {
|
2018-08-03 18:59:23 +02:00
|
|
|
$pages->sortByPosition();
|
2017-09-09 00:33:14 +02:00
|
|
|
}
|
2018-08-03 18:59:23 +02:00
|
|
|
$pages->save();
|
2017-09-09 00:33:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2019-06-16 22:31:48 +02:00
|
|
|
'dictionaryKey'=>'settings-changes',
|
2017-07-26 21:00:20 +02:00
|
|
|
'notes'=>''
|
|
|
|
));
|
|
|
|
|
2017-09-09 00:33:14 +02:00
|
|
|
// Create alert
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('The changes have been saved'));
|
2017-07-26 21:00:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-28 00:31:40 +02:00
|
|
|
return false;
|
2017-07-29 21:03:18 +02:00
|
|
|
}
|
|
|
|
|
2018-05-15 20:12:15 +02:00
|
|
|
function changeUserPassword($args) {
|
2018-08-03 18:59:23 +02:00
|
|
|
global $users;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-06-10 13:54:55 +02:00
|
|
|
global $syslog;
|
2018-05-15 20:12:15 +02:00
|
|
|
|
|
|
|
// Arguments
|
|
|
|
$username = $args['username'];
|
|
|
|
$newPassword = $args['newPassword'];
|
|
|
|
$confirmPassword = $args['confirmPassword'];
|
|
|
|
|
|
|
|
// Password length
|
|
|
|
if (Text::length($newPassword) < 6) {
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('Password must be at least 6 characters long'), ALERT_STATUS_FAIL);
|
2018-05-15 20:12:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($newPassword!=$confirmPassword) {
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('The password and confirmation password do not match'), ALERT_STATUS_FAIL);
|
2018-05-15 20:12:15 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-03 18:59:23 +02:00
|
|
|
if ($users->setPassword(array('username'=>$username, 'password'=>$newPassword))) {
|
2018-07-17 23:58:01 +02:00
|
|
|
// Add to syslog
|
2018-06-10 13:54:55 +02:00
|
|
|
$syslog->add(array(
|
2018-05-15 20:12:15 +02:00
|
|
|
'dictionaryKey'=>'user-password-changed',
|
|
|
|
'notes'=>$username
|
|
|
|
));
|
2018-07-17 23:58:01 +02:00
|
|
|
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('The changes have been saved'), ALERT_STATUS_OK);
|
2018-05-15 20:12:15 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-20 21:48:43 +02:00
|
|
|
// Returns true if the user is allowed to procceded
|
|
|
|
function checkRole($allowRoles, $redirect=true) {
|
2018-07-14 15:17:06 +02:00
|
|
|
global $login;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-05-20 21:48:43 +02:00
|
|
|
global $syslog;
|
|
|
|
|
2018-07-14 15:17:06 +02:00
|
|
|
$userRole = $login->role();
|
2018-05-20 21:48:43 +02:00
|
|
|
if (in_array($userRole, $allowRoles)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($redirect) {
|
2018-07-17 23:58:01 +02:00
|
|
|
// Add to syslog
|
2018-06-10 13:54:55 +02:00
|
|
|
$syslog->add(array(
|
2018-08-18 16:15:38 +02:00
|
|
|
'dictionaryKey'=>'access-denied',
|
2018-07-14 15:17:06 +02:00
|
|
|
'notes'=>$login->username()
|
2018-05-20 21:48:43 +02:00
|
|
|
));
|
2018-07-17 23:58:01 +02:00
|
|
|
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('You do not have sufficient permissions'));
|
2018-05-20 21:48:43 +02:00
|
|
|
Redirect::page('dashboard');
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-01 19:38:56 +01:00
|
|
|
// Add a new category to the system
|
2018-04-22 17:45:31 +02:00
|
|
|
// Returns TRUE is successfully added, FALSE otherwise
|
2018-11-07 15:40:22 +01:00
|
|
|
function createCategory($args) {
|
2018-08-02 22:33:53 +02:00
|
|
|
global $categories;
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-11-01 19:38:56 +01:00
|
|
|
|
2018-11-07 15:40:22 +01:00
|
|
|
if (Text::isEmpty($args['name'])) {
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('Category name is empty'), ALERT_STATUS_FAIL);
|
2017-11-01 19:38:56 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-07 15:40:22 +01:00
|
|
|
if ($categories->add(array('name'=>$args['name'], 'description'=>$args['description']))) {
|
2018-07-17 23:58:01 +02:00
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-11-01 19:38:56 +01:00
|
|
|
'dictionaryKey'=>'new-category-created',
|
2018-11-07 15:40:22 +01:00
|
|
|
'notes'=>$args['name']
|
2017-11-01 19:38:56 +01:00
|
|
|
));
|
|
|
|
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('Category added'), ALERT_STATUS_OK);
|
2017-11-01 19:38:56 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('The category already exists'), ALERT_STATUS_FAIL);
|
2017-11-01 19:38:56 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-22 17:45:31 +02:00
|
|
|
function editCategory($args) {
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-08-03 18:59:23 +02:00
|
|
|
global $pages;
|
2018-08-02 22:33:53 +02:00
|
|
|
global $categories;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-07-29 21:03:18 +02:00
|
|
|
|
2018-04-27 20:36:43 +02:00
|
|
|
if (Text::isEmpty($args['name']) || Text::isEmpty($args['newKey']) ) {
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('Empty fields'));
|
2017-07-29 21:03:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-02 22:33:53 +02:00
|
|
|
$newCategoryKey = $categories->edit($args);
|
2018-04-22 17:45:31 +02:00
|
|
|
|
|
|
|
if ($newCategoryKey==false) {
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('The category already exists'));
|
2017-07-29 21:03:18 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-22 17:45:31 +02:00
|
|
|
// Change the category key in the pages database
|
2018-08-03 18:59:23 +02:00
|
|
|
$pages->changeCategory($args['oldKey'], $newCategoryKey);
|
2017-07-29 21:03:18 +02:00
|
|
|
|
2018-07-17 23:58:01 +02:00
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-07-29 21:03:18 +02:00
|
|
|
'dictionaryKey'=>'category-edited',
|
2018-04-22 17:45:31 +02:00
|
|
|
'notes'=>$newCategoryKey
|
2017-07-29 21:03:18 +02:00
|
|
|
));
|
|
|
|
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('The changes have been saved'));
|
2017-07-29 21:03:18 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-22 17:45:31 +02:00
|
|
|
function deleteCategory($args) {
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2018-08-02 22:33:53 +02:00
|
|
|
global $categories;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-07-29 21:03:18 +02:00
|
|
|
|
|
|
|
// Remove the category by key
|
2018-08-02 22:33:53 +02:00
|
|
|
$categories->remove($args['oldKey']);
|
2018-04-22 17:45:31 +02:00
|
|
|
|
|
|
|
// Remove the category from the pages ? or keep it if the user want to recovery the category ?
|
2017-07-29 21:03:18 +02:00
|
|
|
|
2018-07-17 23:58:01 +02:00
|
|
|
// Add to syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-07-29 21:03:18 +02:00
|
|
|
'dictionaryKey'=>'category-deleted',
|
2018-07-25 23:42:00 +02:00
|
|
|
'notes'=>$args['oldKey']
|
2017-07-29 21:03:18 +02:00
|
|
|
));
|
|
|
|
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set($L->g('The changes have been saved'));
|
2017-07-29 21:03:18 +02:00
|
|
|
return true;
|
2017-09-08 00:43:53 +02:00
|
|
|
}
|
|
|
|
|
2017-12-18 23:49:53 +01:00
|
|
|
// Returns an array with all the categories
|
|
|
|
// By default, the database of categories is alphanumeric sorted
|
|
|
|
function getCategories() {
|
2018-08-02 22:33:53 +02:00
|
|
|
global $categories;
|
2017-12-18 23:49:53 +01:00
|
|
|
|
|
|
|
$list = array();
|
2018-08-02 22:33:53 +02:00
|
|
|
foreach ($categories->keys() as $key) {
|
2017-12-18 23:49:53 +01:00
|
|
|
$category = new Category($key);
|
|
|
|
array_push($list, $category);
|
|
|
|
}
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the object category if the category exists, FALSE otherwise
|
|
|
|
function getCategory($key) {
|
2018-08-02 17:06:53 +02:00
|
|
|
try {
|
|
|
|
$category = new Category($key);
|
|
|
|
return $category;
|
|
|
|
} catch (Exception $e) {
|
2017-12-18 23:49:53 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns an array with all the tags
|
|
|
|
// By default, the database of tags is alphanumeric sorted
|
|
|
|
function getTags() {
|
2018-08-02 22:33:53 +02:00
|
|
|
global $tags;
|
2017-12-18 23:49:53 +01:00
|
|
|
|
|
|
|
$list = array();
|
2018-08-02 22:33:53 +02:00
|
|
|
foreach ($tags->db as $key=>$fields) {
|
2017-12-18 23:49:53 +01:00
|
|
|
$tag = new Tag($key);
|
|
|
|
array_push($list, $tag);
|
|
|
|
}
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
2018-08-02 17:06:53 +02:00
|
|
|
// Returns the object tag if the tag exists, FALSE otherwise
|
|
|
|
function getTag($key) {
|
|
|
|
try {
|
|
|
|
$tag = new Tag($key);
|
|
|
|
return $tag;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-09 00:59:06 +01:00
|
|
|
// Activate a theme
|
2017-09-08 00:43:53 +02:00
|
|
|
function activateTheme($themeDirectory) {
|
2018-07-17 19:13:01 +02:00
|
|
|
global $site;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2019-01-04 14:21:15 +01:00
|
|
|
global $L, $language;
|
2017-09-08 00:43:53 +02:00
|
|
|
|
|
|
|
if (Sanitize::pathFile(PATH_THEMES.$themeDirectory)) {
|
2019-07-21 15:10:33 +02:00
|
|
|
if (Filesystem::fileExists(PATH_THEMES.$themeDirectory.DS.'install.php')) {
|
|
|
|
include_once(PATH_THEMES.$themeDirectory.DS.'install.php');
|
2019-06-16 22:31:48 +02:00
|
|
|
}
|
|
|
|
|
2018-11-09 00:59:06 +01:00
|
|
|
$site->set(array('theme'=>$themeDirectory));
|
2017-09-08 00:43:53 +02:00
|
|
|
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-09-08 00:43:53 +02:00
|
|
|
'dictionaryKey'=>'new-theme-configured',
|
2018-11-09 00:59:06 +01:00
|
|
|
'notes'=>$themeDirectory
|
2017-09-08 00:43:53 +02:00
|
|
|
));
|
|
|
|
|
2018-08-05 17:54:20 +02:00
|
|
|
Alert::set( $L->g('The changes have been saved') );
|
2017-09-08 00:43:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-12-27 14:19:28 +01:00
|
|
|
}
|
2019-01-30 23:15:36 +01:00
|
|
|
|
|
|
|
function ajaxResponse($status=0, $message="", $data=array()) {
|
|
|
|
$default = array('status'=>$status, 'message'=>$message);
|
|
|
|
$output = array_merge($default, $data);
|
|
|
|
exit (json_encode($output));
|
2019-04-07 20:43:42 +02:00
|
|
|
}
|
|
|
|
|
2019-05-09 17:20:35 +02:00
|
|
|
/*
|
|
|
|
| This function checks the image extension,
|
|
|
|
| generate a new filename to not overwrite the exists,
|
|
|
|
| generate the thumbnail,
|
|
|
|
| and move the image to a proper place
|
|
|
|
|
|
|
|
|
| @file string Path and filename of the image
|
|
|
|
| @imageDir string Path where the image is going to be stored
|
|
|
|
| @thumbnailDir string Path where the thumbnail is going to be stored, if you don't set the variable is not going to create the thumbnail
|
|
|
|
|
|
|
|
|
| @return string/boolean Path and filename of the new image or FALSE if there were some error
|
|
|
|
*/
|
|
|
|
function transformImage($file, $imageDir, $thumbnailDir=false) {
|
2019-04-07 20:43:42 +02:00
|
|
|
global $site;
|
|
|
|
|
|
|
|
// Check image extension
|
|
|
|
$fileExtension = Filesystem::extension($file);
|
|
|
|
$fileExtension = Text::lowercase($fileExtension);
|
2019-05-29 19:28:11 +02:00
|
|
|
if (!in_array($fileExtension, $GLOBALS['ALLOWED_IMG_EXTENSION']) ) {
|
2019-04-07 20:43:42 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a filename to not overwrite current image if exists
|
|
|
|
$filename = Filesystem::filename($file);
|
|
|
|
$nextFilename = Filesystem::nextFilename($imageDir, $filename);
|
|
|
|
|
2019-07-21 15:10:33 +02:00
|
|
|
// Move the image to a proper place and rename
|
2019-04-07 20:43:42 +02:00
|
|
|
$image = $imageDir.$nextFilename;
|
|
|
|
Filesystem::mv($file, $image);
|
|
|
|
chmod($image, 0644);
|
|
|
|
|
|
|
|
// Generate Thumbnail
|
|
|
|
if (!empty($thumbnailDir)) {
|
|
|
|
if ($fileExtension == 'svg') {
|
|
|
|
symlink($image, $thumbnailDir.$nextFilename);
|
|
|
|
} else {
|
|
|
|
$Image = new Image();
|
|
|
|
$Image->setImage($image, $site->thumbnailWidth(), $site->thumbnailHeight(), 'crop');
|
|
|
|
$Image->saveImage($thumbnailDir.$nextFilename, $site->thumbnailQuality(), true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $image;
|
2019-11-15 14:59:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function downloadRestrictedFile($file) {
|
|
|
|
if (is_file($file)) {
|
|
|
|
header('Content-Description: File Transfer');
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
|
|
header('Content-Disposition: attachment; filename="'.basename($file).'"');
|
|
|
|
header('Expires: 0');
|
|
|
|
header('Cache-Control: must-revalidate');
|
|
|
|
header('Pragma: public');
|
|
|
|
header('Content-Length: ' . filesize($file));
|
|
|
|
readfile($file);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|