2016-05-29 19:21:11 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
2018-02-09 00:46:12 +01:00
|
|
|
// Returns a Page-Object, the class is page.class.php, FALSE if something fail to load the page
|
2017-07-10 23:40:46 +02:00
|
|
|
function buildPage($key) {
|
2017-05-09 00:24:15 +02:00
|
|
|
global $dbPages;
|
|
|
|
global $dbUsers;
|
2017-05-17 00:04:53 +02:00
|
|
|
global $dbCategories;
|
2017-05-09 00:24:15 +02:00
|
|
|
global $Parsedown;
|
|
|
|
global $Site;
|
|
|
|
|
2017-09-21 20:42:03 +02:00
|
|
|
if (empty($key)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Page object, content from index.txt file
|
|
|
|
$page = new Page($key);
|
2017-07-29 21:03:18 +02:00
|
|
|
if (!$page->isValid()) {
|
2017-05-09 00:24:15 +02:00
|
|
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from file with key: '.$key);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Get the database from dbPages
|
2017-05-09 00:24:15 +02:00
|
|
|
$db = $dbPages->getPageDB($key);
|
2017-07-29 21:03:18 +02:00
|
|
|
if (!$db) {
|
2017-05-09 00:24:15 +02:00
|
|
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the page from database with key: '.$key);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Foreach field from database set on the object
|
2017-07-29 21:03:18 +02:00
|
|
|
foreach ($db as $field=>$value) {
|
2017-05-10 20:40:28 +02:00
|
|
|
$page->setField($field, $value);
|
2017-05-09 00:24:15 +02:00
|
|
|
}
|
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Parse Markdown
|
|
|
|
$contentRaw = $page->contentRaw();
|
2017-05-09 00:24:15 +02:00
|
|
|
$content = Text::pre2htmlentities($contentRaw); // Parse pre code with htmlentities
|
2017-05-10 20:40:28 +02:00
|
|
|
$content = $Parsedown->text($content); // Parse Markdown
|
2017-10-07 02:45:03 +02:00
|
|
|
$content = Text::imgRel2Abs($content, DOMAIN_UPLOADS); // Parse img src relative to absolute (with domain)
|
2017-05-10 20:40:28 +02:00
|
|
|
$page->setField('content', $content, true);
|
2017-05-09 00:24:15 +02:00
|
|
|
|
|
|
|
// Pagebrake
|
|
|
|
$explode = explode(PAGE_BREAK, $content);
|
2017-05-10 20:40:28 +02:00
|
|
|
$page->setField('contentBreak', $explode[0], true);
|
|
|
|
$page->setField('readMore', !empty($explode[1]), true);
|
2017-05-09 00:24:15 +02:00
|
|
|
|
|
|
|
// Date format
|
2017-05-10 20:40:28 +02:00
|
|
|
$pageDate = $page->date();
|
|
|
|
$page->setField('dateRaw', $pageDate, true);
|
2017-05-09 00:24:15 +02:00
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
$pageDateFormated = $page->dateRaw( $Site->dateFormat() );
|
|
|
|
$page->setField('date', $pageDateFormated, true);
|
2017-05-09 00:24:15 +02:00
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
// Generate and set the User object
|
|
|
|
$username = $page->username();
|
|
|
|
$page->setField('user', $dbUsers->getUser($username));
|
2017-05-09 00:24:15 +02:00
|
|
|
|
2017-05-17 00:04:53 +02:00
|
|
|
// Category
|
|
|
|
$categoryKey = $page->categoryKey();
|
|
|
|
$page->setField('categoryMap', $dbCategories->getMap($categoryKey));
|
|
|
|
|
2018-01-21 23:23:22 +01:00
|
|
|
// Get the keys of the child
|
2018-02-08 16:53:35 +01:00
|
|
|
$page->setField('childrenKeys', $dbPages->getChildren($key));
|
2018-01-21 23:23:22 +01:00
|
|
|
|
2017-05-10 20:40:28 +02:00
|
|
|
return $page;
|
2017-05-09 00:24:15 +02:00
|
|
|
}
|
|
|
|
|
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() {
|
2017-05-10 20:40:28 +02:00
|
|
|
global $dbCategories;
|
2017-06-23 00:41:00 +02:00
|
|
|
return $dbCategories->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() {
|
2017-05-21 22:01:44 +02:00
|
|
|
global $dbTags;
|
2017-06-23 00:41:00 +02:00
|
|
|
return $dbTags->reindex();
|
2017-03-26 20:51:32 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 00:46:12 +01:00
|
|
|
// Generate on the fly a 404 page-not-found
|
|
|
|
// Returns a Page-Object
|
2017-07-28 19:37:06 +02:00
|
|
|
function buildErrorPage() {
|
|
|
|
global $dbPages;
|
|
|
|
global $Language;
|
2017-09-21 20:42:03 +02:00
|
|
|
global $dbUsers;
|
2017-07-28 19:37:06 +02:00
|
|
|
|
|
|
|
$page = new Page(false);
|
2017-12-26 17:45:02 +01:00
|
|
|
$page->setField('title', $Language->get('page-not-found'));
|
|
|
|
$page->setField('content', $Language->get('page-not-found-content'));
|
|
|
|
$page->setField('user', $dbUsers->getUser('admin'));
|
2017-07-28 19:37:06 +02:00
|
|
|
|
|
|
|
return $page;
|
|
|
|
}
|
|
|
|
|
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
|
2017-12-26 17:45:02 +01:00
|
|
|
// The page is stored on the global variable $page
|
2018-02-09 00:46:12 +01:00
|
|
|
// If the slug has not a page associacted returns FALSE and is set not-found as true
|
2017-07-26 01:17:13 +02:00
|
|
|
function buildThePage() {
|
|
|
|
global $Url;
|
|
|
|
global $page, $Page;
|
2017-10-04 23:42:14 +02:00
|
|
|
global $content, $pages;
|
2017-07-26 01:17:13 +02:00
|
|
|
|
|
|
|
$page = $Page = buildPage( $Url->slug() );
|
|
|
|
|
|
|
|
// The page doesn't exist
|
2018-02-09 00:46:12 +01:00
|
|
|
if ($page===false) {
|
2017-07-28 19:37:06 +02:00
|
|
|
$Url->setNotFound();
|
2017-07-26 01:17:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-12-26 17:45:02 +01:00
|
|
|
// The page is NOT published
|
2018-02-09 00:46:12 +01:00
|
|
|
elseif ( $page->scheduled() || $page->draft() ) {
|
2017-07-28 19:37:06 +02:00
|
|
|
$Url->setNotFound();
|
2017-07-26 01:17:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-26 17:45:02 +01:00
|
|
|
// The page was generate successfully
|
2017-10-04 23:42:14 +02:00
|
|
|
$content[0] = $pages[0] = $page;
|
2017-07-26 01:17:13 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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() {
|
2017-05-12 20:18:44 +02:00
|
|
|
global $Url;
|
|
|
|
|
|
|
|
$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() {
|
2017-05-12 20:18:44 +02:00
|
|
|
global $Url;
|
|
|
|
|
|
|
|
$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!
|
|
|
|
// Generate the global variables $pages / $content, defined on 69.pages.php
|
|
|
|
// This function is use for buildPagesForHome(), buildPagesByCategory(), buildPagesByTag()
|
2017-07-26 01:17:13 +02:00
|
|
|
function buildPagesFor($for, $categoryKey=false, $tagKey=false) {
|
2017-05-10 20:40:28 +02:00
|
|
|
global $dbPages;
|
2017-05-10 23:21:45 +02:00
|
|
|
global $dbCategories;
|
2017-05-31 20:17:21 +02:00
|
|
|
global $dbTags;
|
2016-05-29 19:21:11 +02:00
|
|
|
global $Site;
|
2017-05-16 00:46:20 +02:00
|
|
|
global $Url;
|
2017-10-04 23:42:14 +02:00
|
|
|
global $content, $pages;
|
2016-05-29 19:21:11 +02:00
|
|
|
|
2017-05-10 23:21:45 +02:00
|
|
|
// Get the page number from URL
|
|
|
|
$pageNumber = $Url->pageNumber();
|
|
|
|
|
2017-09-10 23:09:44 +02:00
|
|
|
if ($for=='home') {
|
2017-05-10 23:21:45 +02:00
|
|
|
$onlyPublished = true;
|
2017-05-16 00:46:20 +02:00
|
|
|
$amountOfItems = $Site->itemsPerPage();
|
2017-06-18 22:44:07 +02:00
|
|
|
$list = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
|
2018-03-27 18:40:03 +02:00
|
|
|
|
|
|
|
// Include sticky pages only in the first page
|
|
|
|
if ($pageNumber==1) {
|
|
|
|
$sticky = $dbPages->getStickyDB();
|
|
|
|
$list = array_merge($sticky, $list);
|
|
|
|
}
|
2017-05-10 23:21:45 +02:00
|
|
|
}
|
2017-09-10 23:09:44 +02:00
|
|
|
elseif ($for=='category') {
|
2017-05-16 00:46:20 +02:00
|
|
|
$amountOfItems = $Site->itemsPerPage();
|
2017-05-10 23:21:45 +02:00
|
|
|
$list = $dbCategories->getList($categoryKey, $pageNumber, $amountOfItems);
|
|
|
|
}
|
2017-09-10 23:09:44 +02:00
|
|
|
elseif ($for=='tag') {
|
2017-05-16 00:46:20 +02:00
|
|
|
$amountOfItems = $Site->itemsPerPage();
|
2017-05-10 23:21:45 +02:00
|
|
|
$list = $dbTags->getList($tagKey, $pageNumber, $amountOfItems);
|
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) {
|
2017-07-28 19:37:06 +02:00
|
|
|
$Url->setNotFound();
|
2017-07-26 01:17:13 +02:00
|
|
|
return false;
|
2016-05-29 19:21:11 +02:00
|
|
|
}
|
|
|
|
|
2017-05-16 00:46:20 +02:00
|
|
|
$pages = array(); // global variable
|
2018-02-09 00:46:12 +01:00
|
|
|
foreach ($list as $pageKey) {
|
2017-05-10 20:40:28 +02:00
|
|
|
$page = buildPage($pageKey);
|
2018-02-09 00:46:12 +01:00
|
|
|
if ($page!==false) {
|
2017-05-10 20:40:28 +02:00
|
|
|
array_push($pages, $page);
|
|
|
|
}
|
|
|
|
}
|
2017-10-04 23:42:14 +02:00
|
|
|
$content = $pages;
|
2017-05-10 20:40:28 +02:00
|
|
|
return $pages;
|
|
|
|
}
|
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() {
|
|
|
|
global $dbPages;
|
|
|
|
|
|
|
|
$list = array();
|
|
|
|
$staticPages = $dbPages->getStaticDB();
|
|
|
|
foreach ($staticPages as $pageKey) {
|
|
|
|
$staticPage = buildPage($pageKey);
|
|
|
|
array_push($list, $staticPage);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns an array with all the parent pages as Page-Object
|
|
|
|
// The pages are order by the settings on the system
|
|
|
|
function buildParentPages() {
|
|
|
|
global $dbPages;
|
|
|
|
|
|
|
|
$list = array();
|
|
|
|
$pagesKey = $dbPages->getPublishedDB();
|
|
|
|
foreach ($pagesKey as $pageKey) {
|
|
|
|
$page = buildPage($pageKey);
|
|
|
|
if ($page->isParent()) {
|
|
|
|
array_push($list, $page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DEPRECATED
|
2017-07-13 00:44:39 +02:00
|
|
|
// Generate the global variable $pagesByParent, defined on 69.pages.php
|
2017-10-22 14:36:16 +02:00
|
|
|
function buildPagesByParent($publishedPages=true, $staticPages=true) {
|
2017-07-10 23:40:46 +02:00
|
|
|
global $dbPages;
|
|
|
|
global $pagesByParent;
|
2017-07-13 00:44:39 +02:00
|
|
|
global $pagesByParentByKey;
|
2017-07-10 23:40:46 +02:00
|
|
|
|
2017-10-22 14:36:16 +02:00
|
|
|
$onlyKeys = true;
|
|
|
|
$keys = array();
|
|
|
|
if ($publishedPages) {
|
|
|
|
$keys = array_merge($keys, $dbPages->getPublishedDB($onlyKeys));
|
|
|
|
}
|
2017-07-15 15:47:37 +02:00
|
|
|
|
2017-10-22 14:36:16 +02:00
|
|
|
foreach ($keys as $pageKey) {
|
2017-07-10 23:40:46 +02:00
|
|
|
$page = buildPage($pageKey);
|
2017-10-22 14:36:16 +02:00
|
|
|
if ($page!==false) {
|
2017-07-15 15:47:37 +02:00
|
|
|
$parentKey = $page->parentKey();
|
|
|
|
// FALSE if the page is parent
|
2017-10-22 14:36:16 +02:00
|
|
|
if ($parentKey===false) {
|
2017-07-15 15:47:37 +02:00
|
|
|
array_push($pagesByParent[PARENT], $page);
|
|
|
|
$pagesByParentByKey[PARENT][$page->key()] = $page;
|
|
|
|
} else {
|
2017-10-22 14:36:16 +02:00
|
|
|
if (!isset($pagesByParent[$parentKey])) {
|
2017-07-15 15:47:37 +02:00
|
|
|
$pagesByParent[$parentKey] = array();
|
2017-07-10 23:40:46 +02:00
|
|
|
}
|
2017-07-15 15:47:37 +02:00
|
|
|
array_push($pagesByParent[$parentKey], $page);
|
|
|
|
$pagesByParentByKey[$parentKey][$page->key()] = $page;
|
2017-07-10 23:40:46 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-09 00:46:12 +01:00
|
|
|
// DEPRECATED
|
2017-07-11 23:53:53 +02:00
|
|
|
// Returns an Array with all pages existing on the system
|
|
|
|
/*
|
|
|
|
array(
|
|
|
|
pageKey1 => Page object,
|
|
|
|
pageKey2 => Page object,
|
|
|
|
...
|
|
|
|
pageKeyN => Page object,
|
|
|
|
)
|
|
|
|
*/
|
2017-10-22 14:36:16 +02:00
|
|
|
function buildAllpages($publishedPages=true, $staticPages=true, $draftPages=true, $scheduledPages=true) {
|
2017-07-11 23:53:53 +02:00
|
|
|
global $dbPages;
|
|
|
|
|
2017-07-15 15:47:37 +02:00
|
|
|
// Get DB
|
2017-10-22 14:36:16 +02:00
|
|
|
$onlyKeys = true;
|
|
|
|
$keys = array();
|
|
|
|
if ($publishedPages) {
|
|
|
|
$keys = array_merge($keys, $dbPages->getPublishedDB($onlyKeys));
|
|
|
|
}
|
|
|
|
if ($staticPages) {
|
|
|
|
$keys = array_merge($keys, $dbPages->getStaticDB($onlyKeys));
|
|
|
|
}
|
|
|
|
if ($draftPages) {
|
|
|
|
$keys = array_merge($keys, $dbPages->getDraftDB($onlyKeys));
|
|
|
|
}
|
|
|
|
if ($scheduledPages) {
|
|
|
|
$keys = array_merge($keys, $dbPages->getScheduledDB($onlyKeys));
|
|
|
|
}
|
2017-07-15 15:47:37 +02:00
|
|
|
|
2017-07-11 23:53:53 +02:00
|
|
|
$tmp = array();
|
2017-10-22 14:36:16 +02:00
|
|
|
foreach ($keys as $pageKey) {
|
2017-07-11 23:53:53 +02:00
|
|
|
$page = buildPage($pageKey);
|
2017-10-22 14:36:16 +02:00
|
|
|
if ($page!==false) {
|
2017-07-15 21:28:54 +02:00
|
|
|
$tmp[$page->key()] = $page;
|
2017-07-11 23:53:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $tmp;
|
|
|
|
}
|
|
|
|
|
2018-02-09 00:46:12 +01:00
|
|
|
// 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;
|
|
|
|
|
2017-12-27 14:19:28 +01:00
|
|
|
if (pluginEnabled($pluginClassName)) {
|
|
|
|
return $plugins['all'][$pluginClassName];
|
2017-12-20 20:37:17 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-12-27 14:44:57 +01:00
|
|
|
// DEPRACTED
|
2017-12-27 14:19:28 +01:00
|
|
|
// Returns TRUE if the plugin is enabled and installed, FALSE otherwise
|
|
|
|
function pluginEnabled($pluginClassName) {
|
2017-12-27 14:44:57 +01:00
|
|
|
return pluginActivated($pluginClassName);
|
|
|
|
}
|
2017-06-04 22:08:20 +02:00
|
|
|
|
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;
|
2017-09-09 00:33:14 +02:00
|
|
|
global $Language;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
Alert::set($Language->g('plugin-activated'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deactivatePlugin($pluginClassName) {
|
|
|
|
global $plugins;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-09-09 00:33:14 +02:00
|
|
|
global $Language;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
Alert::set($Language->g('plugin-deactivated'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-02-06 18:26:59 +01:00
|
|
|
global $Language;
|
|
|
|
|
|
|
|
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'=>''
|
|
|
|
));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-05 19:59:51 +02:00
|
|
|
function createPage($args) {
|
2017-06-22 23:50:12 +02:00
|
|
|
global $dbPages;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-09-10 23:09:44 +02:00
|
|
|
global $Language;
|
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-11 23:36:46 +02:00
|
|
|
$autosaveKey = $dbPages->getByUUID('autosave-'.$args['uuid']);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-22 23:50:12 +02:00
|
|
|
$key = $dbPages->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();
|
|
|
|
reindextags();
|
|
|
|
|
|
|
|
// 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',
|
2017-06-22 23:50:12 +02:00
|
|
|
'notes'=>$args['title']
|
|
|
|
));
|
|
|
|
|
2017-10-02 22:42:18 +02:00
|
|
|
Alert::set( $Language->g('new-content-created') );
|
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) {
|
|
|
|
global $dbPages;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-06-23 00:41:00 +02:00
|
|
|
|
2018-05-08 00:15:40 +02:00
|
|
|
// Check if the autosave page exists for this new page and delete it
|
|
|
|
$pageKey = $dbPages->getByUUID('autosave-'.$args['uuid']);
|
|
|
|
if (!empty($pageKey)) {
|
2018-07-11 23:36:46 +02:00
|
|
|
Log::set('Function editPage()'.LOG_SEP.'Autosave deleted for '.$args['title'], LOG_TYPE_INFO);
|
2018-05-08 00:15:40 +02:00
|
|
|
deletePage($pageKey);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
if (!$dbPages->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;
|
|
|
|
}
|
|
|
|
|
2017-09-23 13:10:05 +02:00
|
|
|
// Title and content need to be here because from inside the dbPages is not visible
|
|
|
|
if (empty($args['title']) || empty($args['content'])) {
|
|
|
|
$page = buildPage($args['key']);
|
|
|
|
if (empty($args['title'])) {
|
|
|
|
$args['title'] = $page->title();
|
|
|
|
}
|
|
|
|
if (empty($args['content'])) {
|
|
|
|
$args['content'] = $page->contentRaw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-23 00:41:00 +02:00
|
|
|
$key = $dbPages->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();
|
|
|
|
reindextags();
|
|
|
|
|
|
|
|
// 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',
|
2017-06-23 00:41:00 +02:00
|
|
|
'notes'=>$args['title']
|
|
|
|
));
|
|
|
|
|
|
|
|
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) {
|
|
|
|
global $dbPages;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-06-23 00:41:00 +02:00
|
|
|
|
|
|
|
if( $dbPages->delete($key) ) {
|
|
|
|
// Call the plugins after page deleted
|
|
|
|
Theme::plugins('afterPageDelete');
|
|
|
|
|
|
|
|
// Re-index categories
|
|
|
|
reindexCategories();
|
|
|
|
|
|
|
|
// Re-index tags
|
|
|
|
reindextags();
|
|
|
|
|
|
|
|
// 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) {
|
2017-06-28 00:31:40 +02:00
|
|
|
global $dbUsers;
|
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
|
|
|
if ($dbUsers->set($args)) {
|
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
|
|
|
));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
function disableUser($args) {
|
2017-06-28 00:31:40 +02:00
|
|
|
global $dbUsers;
|
2018-05-14 00:00:10 +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
|
|
|
|
if ($Login->role()!=='admin') {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the username exists
|
|
|
|
if (!$dbUsers->exists($username)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable the user
|
|
|
|
if ($dbUsers->disableUser($username)) {
|
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
|
|
|
));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
function deleteUser($args) {
|
|
|
|
global $dbUsers, $dbPages;
|
2017-06-28 00:31:40 +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
|
|
|
|
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
|
|
|
|
if (!$dbUsers->exists($username)) {
|
|
|
|
return false;
|
2017-06-28 00:31:40 +02:00
|
|
|
}
|
2018-05-14 00:00:10 +02:00
|
|
|
|
|
|
|
if ($deleteContent) {
|
|
|
|
$dbPages->deletePagesByUser(array('username'=>$username));
|
|
|
|
} else {
|
|
|
|
$dbPages->transferPages(array('oldUsername'=>$username));
|
2017-06-28 00:31:40 +02:00
|
|
|
}
|
|
|
|
|
2018-05-14 00:00:10 +02:00
|
|
|
if ($dbUsers->delete($username)) {
|
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
|
|
|
));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-05 19:59:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-05 23:30:30 +02:00
|
|
|
function createUser($args) {
|
2017-07-05 19:59:51 +02:00
|
|
|
global $dbUsers;
|
|
|
|
global $Language;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
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'])) {
|
2017-07-05 19:59:51 +02:00
|
|
|
Alert::set($Language->g('username-field-is-empty'), ALERT_STATUS_FAIL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check already exist username
|
2018-04-27 20:36:43 +02:00
|
|
|
if ($dbUsers->exists($args['new_username'])) {
|
2017-07-05 19:59:51 +02:00
|
|
|
Alert::set($Language->g('username-already-exists'), ALERT_STATUS_FAIL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Password length
|
2018-04-27 20:36:43 +02:00
|
|
|
if (Text::length($args['new_password']) < PASSWORD_LENGTH) {
|
2017-10-07 21:49:41 +02:00
|
|
|
Alert::set($Language->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']) {
|
2017-07-05 19:59:51 +02:00
|
|
|
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
|
2018-04-27 20:36:43 +02:00
|
|
|
if ($dbUsers->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) {
|
|
|
|
global $Site;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-09-09 00:33:14 +02:00
|
|
|
global $Language;
|
2017-09-10 23:09:44 +02:00
|
|
|
global $dbPages;
|
2017-07-26 21:00:20 +02:00
|
|
|
|
2017-09-03 23:29:09 +02:00
|
|
|
if (isset($args['language'])) {
|
|
|
|
if ($args['language']!=$Site->language()) {
|
|
|
|
$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'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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']);
|
|
|
|
}
|
|
|
|
|
2017-09-15 20:02:53 +02:00
|
|
|
if (isset($args['uriBlog'])) {
|
|
|
|
$args['uriBlog'] = Text::addSlashes($args['uriBlog']);
|
2018-03-06 19:42:18 +01:00
|
|
|
} else {
|
|
|
|
$args['uriBlog'] = '';
|
2017-09-15 20:02:53 +02:00
|
|
|
}
|
|
|
|
|
2017-09-09 00:33:14 +02:00
|
|
|
if ($Site->set($args)) {
|
|
|
|
// Check current order-by if changed it reorder the content
|
|
|
|
if ($Site->orderBy()!=ORDER_BY) {
|
|
|
|
if ($Site->orderBy()=='date') {
|
|
|
|
$dbPages->sortByDate();
|
|
|
|
} else {
|
|
|
|
$dbPages->sortByPosition();
|
|
|
|
}
|
|
|
|
$dbPages->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add syslog
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-07-26 21:00:20 +02:00
|
|
|
'dictionaryKey'=>'changes-on-settings',
|
|
|
|
'notes'=>''
|
|
|
|
));
|
|
|
|
|
2017-09-09 00:33:14 +02:00
|
|
|
// Create alert
|
|
|
|
Alert::set($Language->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) {
|
|
|
|
global $dbUsers;
|
|
|
|
global $Language;
|
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) {
|
|
|
|
Alert::set($Language->g('Password must be at least 6 characters long'), ALERT_STATUS_FAIL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($newPassword!=$confirmPassword) {
|
|
|
|
Alert::set($Language->g('The password and confirmation password do not match'), ALERT_STATUS_FAIL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($dbUsers->setPassword(array('username'=>$username, 'password'=>$newPassword))) {
|
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
|
|
|
|
));
|
|
|
|
Alert::set($Language->g('The changes have been saved'), ALERT_STATUS_OK);
|
|
|
|
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) {
|
|
|
|
global $Login;
|
|
|
|
global $Language;
|
|
|
|
global $syslog;
|
|
|
|
|
|
|
|
$userRole = $Login->role();
|
|
|
|
if (in_array($userRole, $allowRoles)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($redirect) {
|
2018-06-10 13:54:55 +02:00
|
|
|
$syslog->add(array(
|
2018-05-20 21:48:43 +02:00
|
|
|
'dictionaryKey'=>'access-deny',
|
|
|
|
'notes'=>$Login->username()
|
|
|
|
));
|
|
|
|
Alert::set($Language->g('You do not have sufficient permissions'));
|
|
|
|
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
|
2017-11-01 19:38:56 +01:00
|
|
|
function createCategory($category) {
|
|
|
|
global $dbCategories;
|
|
|
|
global $Language;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-11-01 19:38:56 +01:00
|
|
|
|
|
|
|
if (Text::isEmpty($category)) {
|
|
|
|
Alert::set($Language->g('Category name is empty'), ALERT_STATUS_FAIL);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-27 20:36:43 +02:00
|
|
|
if ($dbCategories->add(array('name'=>$category))) {
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-11-01 19:38:56 +01:00
|
|
|
'dictionaryKey'=>'new-category-created',
|
|
|
|
'notes'=>$category
|
|
|
|
));
|
|
|
|
|
|
|
|
Alert::set($Language->g('Category added'), ALERT_STATUS_OK);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-22 17:45:31 +02:00
|
|
|
Alert::set($Language->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) {
|
2017-07-29 21:03:18 +02:00
|
|
|
global $Language;
|
|
|
|
global $dbPages;
|
|
|
|
global $dbCategories;
|
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']) ) {
|
2017-07-29 21:03:18 +02:00
|
|
|
Alert::set($Language->g('Empty fields'));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-27 20:36:43 +02:00
|
|
|
$newCategoryKey = $dbCategories->edit($args);
|
2018-04-22 17:45:31 +02:00
|
|
|
|
|
|
|
if ($newCategoryKey==false) {
|
|
|
|
Alert::set($Language->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-04-27 20:36:43 +02:00
|
|
|
$dbPages->changeCategory($args['oldKey'], $newCategoryKey);
|
2017-07-29 21:03:18 +02:00
|
|
|
|
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
|
|
|
));
|
|
|
|
|
|
|
|
Alert::set($Language->g('The changes have been saved'));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-22 17:45:31 +02:00
|
|
|
function deleteCategory($args) {
|
2017-07-29 21:03:18 +02:00
|
|
|
global $Language;
|
|
|
|
global $dbCategories;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-07-29 21:03:18 +02:00
|
|
|
|
|
|
|
// Remove the category by key
|
2018-04-22 17:45:31 +02:00
|
|
|
$dbCategories->remove($args['oldCategoryKey']);
|
|
|
|
|
|
|
|
// 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-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-07-29 21:03:18 +02:00
|
|
|
'dictionaryKey'=>'category-deleted',
|
2018-04-22 17:45:31 +02:00
|
|
|
'notes'=>$args['oldCategoryKey']
|
2017-07-29 21:03:18 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
Alert::set($Language->g('The changes have been saved'));
|
|
|
|
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() {
|
|
|
|
global $dbCategories;
|
|
|
|
|
|
|
|
$list = array();
|
|
|
|
foreach ($dbCategories->db as $key=>$fields) {
|
|
|
|
$category = new Category($key);
|
|
|
|
array_push($list, $category);
|
|
|
|
}
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the object category if the category exists, FALSE otherwise
|
|
|
|
function getCategory($key) {
|
|
|
|
$category = new Category($key);
|
|
|
|
if (!$category->isValid()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $category;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns an array with all the tags
|
|
|
|
// By default, the database of tags is alphanumeric sorted
|
|
|
|
function getTags() {
|
|
|
|
global $dbTags;
|
|
|
|
|
|
|
|
$list = array();
|
|
|
|
foreach ($dbTags->db as $key=>$fields) {
|
|
|
|
$tag = new Tag($key);
|
|
|
|
array_push($list, $tag);
|
|
|
|
}
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
2017-09-08 00:43:53 +02:00
|
|
|
function activateTheme($themeDirectory) {
|
|
|
|
global $Site;
|
2018-04-22 17:45:31 +02:00
|
|
|
global $syslog;
|
2017-09-08 00:43:53 +02:00
|
|
|
|
|
|
|
if (Sanitize::pathFile(PATH_THEMES.$themeDirectory)) {
|
|
|
|
$Site->set(array('theme'=>$themeDirname));
|
|
|
|
|
2018-04-22 17:45:31 +02:00
|
|
|
$syslog->add(array(
|
2017-09-08 00:43:53 +02:00
|
|
|
'dictionaryKey'=>'new-theme-configured',
|
|
|
|
'notes'=>$themeDirname
|
|
|
|
));
|
|
|
|
|
|
|
|
Alert::set( $Language->g('The changes have been saved') );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-12-27 14:19:28 +01:00
|
|
|
}
|