bludit/bl-kernel/functions.php

809 lines
18 KiB
PHP
Raw Permalink Normal View History

2016-05-29 19:21:11 +02:00
<?php defined('BLUDIT') or die('Bludit CMS.');
// 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
function reindexCategories() {
2018-08-02 22:33:53 +02:00
global $categories;
return $categories->reindex();
2016-05-29 19:21:11 +02:00
}
// Re-index database of tags
// If you create/edit/remove a page is necessary regenerate the database of tags
function reindexTags() {
2018-08-02 22:33:53 +02:00
global $tags;
return $tags->reindex();
2017-03-26 20:51:32 +02:00
}
// Generate the page 404 Not found
function buildErrorPage() {
global $site;
global $L;
try {
$pageNotFoundKey = $site->pageNotFound();
2018-08-02 17:06:53 +02:00
$pageNotFound = New Page($pageNotFoundKey);
} catch (Exception $e) {
2018-08-02 17:06:53 +02:00
$pageNotFound = New Page(false);
$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');
}
return $pageNotFound;
}
2017-12-26 17:45:02 +01:00
// This function is only used from the rule 69.pages.php, DO NOT use this function!
// This function generate a particular page from the current slug of the url
// If the slug has not a page associacted returns FALSE and is set not-found as true
function buildThePage() {
global $url;
try {
$pageKey = $url->slug();
2018-08-02 17:06:53 +02:00
$page = New Page($pageKey);
} catch (Exception $e) {
$url->setNotFound();
return false;
}
2018-07-25 23:42:00 +02:00
if ( $page->draft() || $page->scheduled() ) {
$url->setNotFound();
return false;
}
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!
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!
function buildPagesByCategory() {
global $url;
2017-05-12 20:18:44 +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!
function buildPagesByTag() {
global $url;
2017-05-12 20:18:44 +02:00
$tagKey = $url->slug();
2017-05-10 23:21:45 +02:00
return buildPagesFor('tag', false, $tagKey);
}
// This function is only used from the rule 69.pages.php, DO NOT use this function!
// Generate the global variables $content / $content, defined on 69.pages.php
// This function is use for buildPagesForHome(), buildPagesByCategory(), buildPagesByTag()
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;
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
$pageNumber = $url->pageNumber();
2017-05-10 23:21:45 +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
}
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
}
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
}
// There are not items, invalid tag, invalid category, out of range, etc...
2017-07-30 23:15:33 +02:00
if ($list===false) {
$url->setNotFound();
return false;
2016-05-29 19:21:11 +02:00
}
$content = array();
foreach ($list as $pageKey) {
try {
2018-08-02 17:06:53 +02:00
$page = new Page($pageKey);
array_push($content, $page);
} catch (Exception $e) {
// continue
2017-05-10 20:40:28 +02:00
}
}
return $content;
2017-05-10 20:40:28 +02: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;
$list = array();
2018-08-03 18:59:23 +02:00
$pagesKey = $pages->getStaticDB();
foreach ($pagesKey as $pageKey) {
try {
2018-08-02 17:06:53 +02:00
$page = new Page($pageKey);
array_push($list, $page);
} catch (Exception $e) {
// continue
}
}
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;
}
}
// 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;
$list = array();
2018-08-03 18:59:23 +02:00
$pagesKey = $pages->getPublishedDB();
foreach ($pagesKey as $pageKey) {
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);
}
} catch (Exception $e) {
// continue
}
}
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;
}
function activatePlugin($pluginClassName) {
global $plugins;
global $syslog;
global $L;
// Check if the plugin exists
if (isset($plugins['all'][$pluginClassName])) {
$plugin = $plugins['all'][$pluginClassName];
if ($plugin->install()) {
// Add to syslog
$syslog->add(array(
'dictionaryKey'=>'plugin-activated',
'notes'=>$plugin->name()
));
// Create an alert
Alert::set($L->g('plugin-activated'));
return true;
}
}
return false;
}
function deactivatePlugin($pluginClassName) {
global $plugins;
global $syslog;
global $L;
// Check if the plugin exists
if (isset($plugins['all'][$pluginClassName])) {
$plugin = $plugins['all'][$pluginClassName];
if ($plugin->uninstall()) {
// Add to syslog
$syslog->add(array(
'dictionaryKey'=>'plugin-deactivated',
'notes'=>$plugin->name()
));
// Create an alert
Alert::set($L->g('plugin-deactivated'));
return true;
}
}
return false;
}
2018-02-06 18:26:59 +01:00
function changePluginsPosition($pluginClassList) {
global $plugins;
global $syslog;
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
$syslog->add(array(
2018-02-06 18:26:59 +01:00
'dictionaryKey'=>'plugins-sorted',
'notes'=>''
));
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;
global $syslog;
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
if (isset($args['uuid'])) {
2018-08-03 18:59:23 +02:00
$autosaveKey = $pages->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;
}
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();
reindextags();
// Add to syslog
$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']
));
Alert::set( $L->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) {
2018-08-03 18:59:23 +02:00
global $pages;
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
if (isset($args['uuid'])) {
2018-08-03 18:59:23 +02:00
$pageKey = $pages->getByUUID('autosave-'.$args['uuid']);
if (!empty($pageKey)) {
Log::set('Function editPage()'.LOG_SEP.'Autosave deleted for '.$args['title'], LOG_TYPE_INFO);
deletePage($pageKey);
}
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;
}
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'])) {
try {
2018-08-02 17:06:53 +02:00
$page = new Page($args['key']);
if (empty($args['title'])) {
$args['title'] = $page->title();
}
if (empty($args['content'])) {
$args['content'] = $page->contentRaw();
}
} catch (Exception $e) {
// continue
2017-09-23 13:10:05 +02:00
}
}
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();
reindextags();
// Add to syslog
$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) {
2018-08-03 18:59:23 +02:00
global $pages;
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();
reindextags();
// Add to syslog
$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;
}
2018-05-14 00:00:10 +02:00
function editUser($args) {
2018-08-03 18:59:23 +02:00
global $users;
global $syslog;
2018-08-03 18:59:23 +02:00
if ($users->set($args)) {
2018-07-17 23:58:01 +02:00
// Add to syslog
$syslog->add(array(
2018-05-14 00:00:10 +02:00
'dictionaryKey'=>'user-edited',
'notes'=>$args['username']
));
2018-07-17 23:58:01 +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;
global $login;
global $syslog;
2018-05-14 00:00:10 +02:00
// Arguments
$username = $args['username'];
// Only administrators can disable users
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
$syslog->add(array(
2018-05-14 00:00:10 +02:00
'dictionaryKey'=>'user-disabled',
'notes'=>$username
));
2018-07-17 23:58:01 +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;
global $login;
global $syslog;
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') {
return false;
}
2018-05-14 00:00:10 +02:00
// The user admin cannot be deleted
if ($username=='admin') {
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;
}
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));
}
2018-08-03 18:59:23 +02:00
if ($users->delete($username)) {
2018-07-17 23:58:01 +02:00
// Add to syslog
$syslog->add(array(
'dictionaryKey'=>'user-deleted',
2018-05-14 00:00:10 +02:00
'notes'=>$username
));
2018-07-17 23:58:01 +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;
global $L;
global $syslog;
2017-07-05 19:59:51 +02:00
// Check empty username
if (Text::isEmpty($args['new_username'])) {
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'])) {
Alert::set($L->g('username-already-exists'), ALERT_STATUS_FAIL);
2017-07-05 19:59:51 +02:00
return false;
}
// Password length
if (Text::length($args['new_password']) < PASSWORD_LENGTH) {
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
if ($args['new_password'] != $args['confirm_password']) {
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();
$tmp['username'] = Text::removeSpecialCharacters($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
$syslog->add(array(
'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;
global $syslog;
global $L;
2018-08-03 18:59:23 +02:00
global $pages;
2017-07-26 21:00:20 +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'];
}
}
}
if (isset($args['uriPage'])) {
$args['uriPage'] = Text::addSlashes($args['uriPage']);
}
2018-03-06 19:42:18 +01:00
if (isset($args['uriTag'])) {
$args['uriTag'] = Text::addSlashes($args['uriTag']);
}
2018-03-06 19:42:18 +01:00
if (isset($args['uriCategory'])) {
$args['uriCategory'] = Text::addSlashes($args['uriCategory']);
}
if (isset($args['uriBlog'])) {
$args['uriBlog'] = Text::addSlashes($args['uriBlog']);
2018-03-06 19:42:18 +01:00
} else {
$args['uriBlog'] = '';
}
2018-07-28 21:00:12 +02:00
$args['extremeFriendly'] = (($args['extremeFriendly']=='true')?true:false);
if ($site->set($args)) {
// Check current order-by if changed it reorder the content
if ($site->orderBy()!=ORDER_BY) {
if ($site->orderBy()=='date') {
2018-08-03 18:59:23 +02:00
$pages->sortByDate();
} else {
2018-08-03 18:59:23 +02:00
$pages->sortByPosition();
}
2018-08-03 18:59:23 +02:00
$pages->save();
}
// Add syslog
$syslog->add(array(
2017-07-26 21:00:20 +02:00
'dictionaryKey'=>'changes-on-settings',
'notes'=>''
));
// Create alert
Alert::set($L->g('The changes have been saved'));
2017-07-26 21:00:20 +02:00
return true;
}
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;
global $L;
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($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) {
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
$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
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) {
global $login;
global $L;
2018-05-20 21:48:43 +02:00
global $syslog;
$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
$syslog->add(array(
'dictionaryKey'=>'access-denied',
'notes'=>$login->username()
2018-05-20 21:48:43 +02:00
));
2018-07-17 23:58:01 +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
// Returns TRUE is successfully added, FALSE otherwise
2017-11-01 19:38:56 +01:00
function createCategory($category) {
2018-08-02 22:33:53 +02:00
global $categories;
global $L;
global $syslog;
2017-11-01 19:38:56 +01:00
if (Text::isEmpty($category)) {
Alert::set($L->g('Category name is empty'), ALERT_STATUS_FAIL);
2017-11-01 19:38:56 +01:00
return false;
}
2018-08-02 22:33:53 +02:00
if ($categories->add(array('name'=>$category))) {
2018-07-17 23:58:01 +02:00
// Add to syslog
$syslog->add(array(
2017-11-01 19:38:56 +01:00
'dictionaryKey'=>'new-category-created',
'notes'=>$category
));
Alert::set($L->g('Category added'), ALERT_STATUS_OK);
2017-11-01 19:38:56 +01:00
return true;
}
Alert::set($L->g('The category already exists'), ALERT_STATUS_FAIL);
2017-11-01 19:38:56 +01:00
return false;
}
function editCategory($args) {
global $L;
2018-08-03 18:59:23 +02:00
global $pages;
2018-08-02 22:33:53 +02:00
global $categories;
global $syslog;
2017-07-29 21:03:18 +02:00
if (Text::isEmpty($args['name']) || Text::isEmpty($args['newKey']) ) {
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);
if ($newCategoryKey==false) {
Alert::set($L->g('The category already exists'));
2017-07-29 21:03:18 +02:00
return false;
}
// 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
$syslog->add(array(
2017-07-29 21:03:18 +02:00
'dictionaryKey'=>'category-edited',
'notes'=>$newCategoryKey
2017-07-29 21:03:18 +02:00
));
Alert::set($L->g('The changes have been saved'));
2017-07-29 21:03:18 +02:00
return true;
}
function deleteCategory($args) {
global $L;
2018-08-02 22:33:53 +02:00
global $categories;
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']);
// 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
$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
));
Alert::set($L->g('The changes have been saved'));
2017-07-29 21:03:18 +02:00
return true;
}
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;
}
}
function activateTheme($themeDirectory) {
global $site;
global $syslog;
if (Sanitize::pathFile(PATH_THEMES.$themeDirectory)) {
$site->set(array('theme'=>$themeDirname));
$syslog->add(array(
'dictionaryKey'=>'new-theme-configured',
'notes'=>$themeDirname
));
Alert::set( $L->g('The changes have been saved') );
return true;
}
return false;
2017-12-27 14:19:28 +01:00
}