removing posts

This commit is contained in:
Diego 2017-05-17 18:48:51 +02:00
parent 63fe327fe4
commit 457c981208
17 changed files with 401 additions and 141 deletions

View File

@ -70,6 +70,10 @@ else
$Security->generateTokenCSRF();
}
// Define variables
$ADMIN_CONTROLLER = $layout['controller'];
$ADMIN_VIEW = $layout['view'];
// Load plugins before the admin area will be load.
Theme::plugins('beforeAdminLoad');

View File

@ -54,6 +54,7 @@ define('DB_PAGES', PATH_DATABASES.'pages.php');
define('DB_SITE', PATH_DATABASES.'site.php');
define('DB_CATEGORIES', PATH_DATABASES.'categories.php');
define('DB_TAGS', PATH_DATABASES.'tags.php');
define('DB_NOTIFICATIONS', PATH_DATABASES.'notifications.php');
// ADMIN URI FILTER
define('ADMIN_URI_FILTER', '/admin/');
@ -274,6 +275,9 @@ $L = $Language;
// --- CONSTANTS with dependency ---
define('ORDER_BY', $Site->orderBy());
$ADMIN_CONTROLLER = ''; // modified on bl-kernel/
$ADMIN_VIEW = '';
// DEBUG: Print constants
// $arr = array_filter(get_defined_constants(), 'is_string');
// echo json_encode($arr);

View File

@ -14,22 +14,17 @@ $plugins = array(
'pageBegin'=>array(),
'pageEnd'=>array(),
'postBegin'=>array(),
'postEnd'=>array(),
'beforeAdminLoad'=>array(),
'afterAdminLoad'=>array(),
'adminHead'=>array(),
'adminBodyBegin'=>array(),
'adminBodyEnd'=>array(),
'adminSidebar'=>array(),
'beforeAdminLoad'=>array(),
'afterAdminLoad'=>array(),
'beforeRulesLoad'=>array(),
'afterFormSave'=>array(),
'afterPostCreate'=>array(),
'afterPostModify'=>array(),
'afterPostDelete'=>array(),
'afterPageCreate'=>array(),
'afterPageModify'=>array(),
'afterPageDelete'=>array(),

View File

@ -0,0 +1,211 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
class dbNotifications extends dbJSON
{
public $dbFields = array(
'dictionaryKey'=> array('inFile'=>false, 'value'=>''),
'date'=> array('inFile'=>false, 'value'=>''),
'username'=> array('inFile'=>false, 'value'=>'')
);
function __construct()
{
parent::__construct(DB_NOTIFICATIONS);
}
public function getUser($username)
{
$User = new User();
if($this->userExists($username))
{
$User->setField('username', $username);
foreach($this->db[$username] as $key=>$value) {
$User->setField($key, $value);
}
return $User;
}
return false;
}
public function getAll()
{
return $this->db;
}
// Return an array with the username databases, filtered by username.
public function getDb($username)
{
if($this->userExists($username))
{
$user = $this->db[$username];
return $user;
}
return false;
}
// Return the username associated to an email, if the email does not exists return FALSE.
public function getByEmail($email)
{
foreach($this->db as $username=>$values) {
if($values['email']==$email) {
return $username;
}
}
return false;
}
// Return TRUE if the user exists, FALSE otherwise.
public function userExists($username)
{
return isset($this->db[$username]);
}
public function generateTokenEmail($username)
{
// Random hash
$token = sha1(Text::randomText(SALT_LENGTH).time());
$this->db[$username]['tokenEmail'] = $token;
// Token time to live, defined by TOKEN_EMAIL_TTL
$this->db[$username]['tokenEmailTTL'] = Date::currentOffset(DB_DATE_FORMAT, TOKEN_EMAIL_TTL);
// Save the database
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
return $token;
}
public function setPassword($username, $password)
{
$salt = Text::randomText(SALT_LENGTH);
$hash = sha1($password.$salt);
$args['username'] = $username;
$args['salt'] = $salt;
$args['password'] = $hash;
return $this->set($args);
}
// Disable the user
public function disableUser($username)
{
$args['username'] = $username;
$args['password'] = '!';
return $this->set($args);
}
public function set($args)
{
$dataForDb = array();
$user = $this->getDb($args['username']);
if($user===false)
{
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to get the username '.$args['username']);
return false;
}
// Verify arguments with the database fields.
foreach($args as $field=>$value)
{
if( isset($this->dbFields[$field]) )
{
// Sanitize.
$tmpValue = Sanitize::html($value);
// Set type.
settype($tmpValue, gettype($this->dbFields[$field]['value']));
$user[$field] = $tmpValue;
}
}
// Save the database
$this->db[$args['username']] = $user;
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
return true;
}
public function delete($username)
{
unset($this->db[$username]);
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
return true;
}
public function add($args)
{
$dataForDb = array();
// Verify arguments with the database fields.
foreach($this->dbFields as $field=>$options)
{
// If the user send the field.
if( isset($args[$field]) )
{
// Sanitize if will be saved on database.
if( !$options['inFile'] ) {
$tmpValue = Sanitize::html($args[$field]);
}
else {
$tmpValue = $args[$field];
}
}
// Uses a default value for the field.
else
{
$tmpValue = $options['value'];
}
// Set type
settype($tmpValue, gettype($options['value']));
// Save on database
$dataForDb[$field] = $tmpValue;
}
// Check if the user alredy exists.
if( $this->userExists($dataForDb['username']) ) {
return false;
}
// Current date.
$dataForDb['registered'] = Date::current(DB_DATE_FORMAT);
// Password
$dataForDb['salt'] = Text::randomText(SALT_LENGTH);
$dataForDb['password'] = sha1($dataForDb['password'].$dataForDb['salt']);
// Save the database
$this->db[$dataForDb['username']] = $dataForDb;
if( $this->save() === false ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
return false;
}
return true;
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "За мен",
"description": "Кратко описание за вашия сайт или за себе си."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Über",
"description": "Kurzer Text über die Website oder zu dir."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Über",
"description": "Kurzer Text über die Website oder zu dir."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "About",
"description": "Little description about your site or yourself."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Acerca de",
"description": "Breve descripción de ti mismo o sobre tu sitio."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "About",
"description": "サイトやあなた自身についての概要を表示します。"
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Over mij",
"description": "Een korte beschrijving over je site of jezelf."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "О блоге",
"description": "Небольшое описание о вашем сайте или о себя."
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Hakkında",
"description": "Senin veya siten hakkında kısa bilgiler"
}
}

View File

@ -0,0 +1,7 @@
{
"plugin-data":
{
"name": "Про блог",
"description": "Невеликий опис вашого сайту або про Вас."
}
}

View File

@ -0,0 +1,10 @@
{
"author": "Bludit",
"email": "",
"website": "https://plugins.bludit.com",
"version": "1.5.2",
"releaseDate": "2016-05-28",
"license": "MIT",
"compatible": "1.5.2",
"notes": ""
}

View File

@ -0,0 +1,21 @@
<?php
class pluginTimeMachine extends Plugin {
public function init()
{
}
public function beforeAdminLoad()
{
global $L;
$notifyText = '';
if($_SERVER['REQUEST_METHOD']=='POST') {
if($GLOBALS['ADMIN_CONTROLLER']=='new-page') {
$notifyText = $L->g('New page created');
}
}
}
}

View File

@ -41,7 +41,6 @@ define('PATH_CONTENT', PATH_ROOT.'bl-content'.DS);
define('PATH_KERNEL', PATH_ROOT.'bl-kernel'.DS);
define('PATH_LANGUAGES', PATH_ROOT.'bl-languages'.DS);
define('PATH_POSTS', PATH_CONTENT.'posts'.DS);
define('PATH_UPLOADS', PATH_CONTENT.'uploads'.DS);
define('PATH_TMP', PATH_CONTENT.'tmp'.DS);
define('PATH_PAGES', PATH_CONTENT.'pages'.DS);
@ -172,9 +171,7 @@ function getLanguageList()
$files = glob(PATH_LANGUAGES.'*.json');
$tmp = array();
foreach($files as $file)
{
foreach($files as $file) {
$t = new dbJSON($file, false);
$native = $t->db['language-data']['native'];
$locale = basename($file, '.json');
@ -184,13 +181,13 @@ function getLanguageList()
return $tmp;
}
// Generate a random string.
// Generate a random string
// Thanks, http://stackoverflow.com/questions/4356289/php-random-string-generator
function getRandomString($length = 10) {
return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);
}
// Check if Bludit is installed.
// Check if Bludit is installed
function alreadyInstalled() {
return file_exists(PATH_DATABASES.'site.php');
}
@ -203,8 +200,7 @@ function checkSystem()
$dirpermissions = 0755;
// Check .htaccess file for different webservers
if( !file_exists(PATH_ROOT.'.htaccess') )
{
if( !file_exists(PATH_ROOT.'.htaccess') ) {
if ( !isset($_SERVER['SERVER_SOFTWARE']) ||
stripos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false ||
@ -223,8 +219,7 @@ function checkSystem()
@mkdir(PATH_CONTENT, $dirpermissions, true);
// Check if the directory content is writeable.
if(!is_writable(PATH_CONTENT))
{
if(!is_writable(PATH_CONTENT)) {
$errorText = 'Writing test failure, check directory content permissions. (ERR_205)';
error_log($errorText, 0);
@ -236,7 +231,7 @@ function checkSystem()
return $stdOut;
}
// Finish with the installation.
// Installation function
function install($adminPassword, $email, $timezone)
{
global $Language;
@ -255,65 +250,54 @@ function install($adminPassword, $email, $timezone)
// 7=read,write,execute | 5=read,execute
$dirpermissions = 0755;
$firstPostSlug = 'first-post';
if(!mkdir(PATH_POSTS.$firstPostSlug, $dirpermissions, true))
{
$errorText = 'Error when trying to created the directory=>'.PATH_POSTS.$firstPostSlug;
if(!mkdir(PATH_PAGES.'welcome', $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_PAGES.'welcome';
error_log($errorText, 0);
}
if(!mkdir(PATH_PAGES.'error', $dirpermissions, true))
{
$errorText = 'Error when trying to created the directory=>'.PATH_PAGES.'error';
error_log($errorText, 0);
}
if(!mkdir(PATH_PAGES.'about', $dirpermissions, true))
{
if(!mkdir(PATH_PAGES.'about', $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_PAGES.'about';
error_log($errorText, 0);
}
if(!mkdir(PATH_PLUGINS_DATABASES.'pages', $dirpermissions, true))
{
if(!mkdir(PATH_PAGES.'error', $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_PAGES.'error';
error_log($errorText, 0);
}
if(!mkdir(PATH_PLUGINS_DATABASES.'pages', $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'pages';
error_log($errorText, 0);
}
if(!mkdir(PATH_PLUGINS_DATABASES.'simplemde', $dirpermissions, true))
{
if(!mkdir(PATH_PLUGINS_DATABASES.'simplemde', $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'simplemde';
error_log($errorText, 0);
}
if(!mkdir(PATH_PLUGINS_DATABASES.'tags', $dirpermissions, true))
{
if(!mkdir(PATH_PLUGINS_DATABASES.'tags', $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'tags';
error_log($errorText, 0);
}
if(!mkdir(PATH_PLUGINS_DATABASES.'about', $dirpermissions, true))
{
if(!mkdir(PATH_PLUGINS_DATABASES.'about', $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_PLUGINS_DATABASES.'about';
error_log($errorText, 0);
}
if(!mkdir(PATH_UPLOADS_PROFILES, $dirpermissions, true))
{
if(!mkdir(PATH_UPLOADS_PROFILES, $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_UPLOADS_PROFILES;
error_log($errorText, 0);
}
if(!mkdir(PATH_TMP, $dirpermissions, true))
{
$errorText = 'Error when trying to created the directory=>'.PATH_TMP;
if(!mkdir(PATH_UPLOADS_THUMBNAILS, $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_UPLOADS_THUMBNAILS;
error_log($errorText, 0);
}
if(!mkdir(PATH_UPLOADS_THUMBNAILS, $dirpermissions, true))
{
$errorText = 'Error when trying to created the directory=>'.PATH_UPLOADS_THUMBNAILS;
if(!mkdir(PATH_TMP, $dirpermissions, true)) {
$errorText = 'Error when trying to created the directory=>'.PATH_TMP;
error_log($errorText, 0);
}
@ -326,11 +310,13 @@ function install($adminPassword, $email, $timezone)
// File pages.php
$data = array(
'error'=>array(
'description'=>'Error page',
'description'=>$Language->get('Page not found'),
'username'=>'admin',
'tags'=>array(),
'status'=>'published',
'date'=>$currentDate,
'dateModified'=>'',
'allowComments'=>false,
'position'=>0,
'coverImage'=>'',
'md5file'=>'',
@ -343,6 +329,22 @@ function install($adminPassword, $email, $timezone)
'tags'=>array(),
'status'=>'published',
'date'=>$currentDate,
'dateModified'=>'',
'allowComments'=>false,
'position'=>2,
'coverImage'=>'',
'md5file'=>'',
'category'=>'',
'uuid'=>md5(uniqid())
),
'welcome'=>array(
'description'=>$Language->get('Welcome to Bludit'),
'username'=>'admin',
'tags'=>array('bludit'=>'Bludit','cms'=>'CMS','flat-files'=>'Flat files'),
'status'=>'published',
'date'=>$currentDate,
'dateModified'=>'',
'allowComments'=>false,
'position'=>1,
'coverImage'=>'',
'md5file'=>'',
@ -353,23 +355,6 @@ function install($adminPassword, $email, $timezone)
file_put_contents(PATH_DATABASES.'pages.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
// File posts.php
$data = array(
$firstPostSlug=>array(
'description'=>$Language->get('Welcome to Bludit'),
'username'=>'admin',
'status'=>'published',
'tags'=>array('bludit'=>'Bludit','cms'=>'CMS','flat-files'=>'Flat files'),
'allowComments'=>'false',
'date'=>$currentDate,
'coverImage'=>'',
'md5file'=>'',
'category'=>'',
'uuid'=>md5(uniqid())
)
);
file_put_contents(PATH_DATABASES.'posts.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
// File site.php
$data = array(
'title'=>'BLUDIT',
@ -383,10 +368,8 @@ function install($adminPassword, $email, $timezone)
'adminTheme'=>'default',
'homepage'=>'',
'postsperpage'=>'6',
'uriPost'=>'/post/',
'uriPage'=>'/',
'uriTag'=>'/tag/',
'uriBlog'=>'/blog/',
'uriCategory'=>'/category/',
'url'=>PROTOCOL.DOMAIN.HTML_PATH_ROOT,
'emailFrom'=>'no-reply@'.DOMAIN
@ -433,28 +416,18 @@ function install($adminPassword, $email, $timezone)
// File categories.php
$data = array(
'videos'=>array('name'=>'Videos', 'posts'=>array(), 'pages'=>array())
'videos'=>array('name'=>'Videos', 'list'=>array()),
'music'=>array('name'=>'Music', 'list'=>array())
);
file_put_contents(PATH_DATABASES.'categories.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
// File tags.php
file_put_contents(
PATH_DATABASES.'tags.php',
$dataHead.json_encode(
array(
'postsIndex'=>array(
'bludit'=>array('name'=>'Bludit', 'posts'=>array('first-post')),
'cms'=>array('name'=>'CMS', 'posts'=>array('first-post')),
'flat-files'=>array('name'=>'Flat files', 'posts'=>array('first-post'))
),
'pagesIndex'=>array()
),
JSON_PRETTY_PRINT),
LOCK_EX
$data = array(
'bludit'=>array('name'=>'Bludit', 'list'=>array('welcome')),
'cms'=>array('name'=>'CMS', 'list'=>array('welcome')),
'flat-files'=>array('name'=>'Flat files', 'list'=>array('welcome'))
);
// PLUGINS
file_put_contents(PATH_DATABASES.'tags.php', $dataHead.json_encode($data, JSON_PRETTY_PRINT), LOCK_EX);
// File plugins/pages/db.php
file_put_contents(
@ -507,22 +480,15 @@ function install($adminPassword, $email, $timezone)
LOCK_EX
);
// File FILENAME for error page
$data = 'Title: '.$Language->get('Error').'
Content: '.$Language->get('The page has not been found');
// File for error page
$data = 'Title: '.$Language->get('Error').PHP_EOL.'Content: '.$Language->get('The page has not been found');
file_put_contents(PATH_PAGES.'error'.DS.FILENAME, $data, LOCK_EX);
// File FILENAME for about page
$data = 'Title: '.$Language->get('About').'
Content:
'.$Language->get('the-about-page-is-very-important').'
'.$Language->get('change-this-pages-content-on-the-admin-panel');
// File for about page
$data = 'Title: '.$Language->get('About').PHP_EOL.'Content: '.$Language->get('the-about-page-is-very-important').' '.$Language->get('change-this-pages-content-on-the-admin-panel');
file_put_contents(PATH_PAGES.'about'.DS.FILENAME, $data, LOCK_EX);
// File FILENAME for welcome post
// File for welcome page
$text1 = Text::replaceAssoc(
array(
'{{ADMIN_AREA_LINK}}'=>PROTOCOL.DOMAIN.HTML_PATH_ROOT.'admin'
@ -530,7 +496,7 @@ Content:
$Language->get('Manage your Bludit from the admin panel')
);
$data = 'Title: '.$Language->get('First post').'
$data = 'Title: '.$Language->get('Welcome').'
Content:
## '.$Language->get('Whats next').'
@ -541,7 +507,7 @@ Content:
- '.$Language->get('Read the documentation for more information').'
- '.$Language->get('Share with your friends and enjoy');
file_put_contents(PATH_POSTS.$firstPostSlug.DS.FILENAME, $data, LOCK_EX);
file_put_contents(PATH_POSTS.$welcomePageKey.DS.FILENAME, $data, LOCK_EX);
return true;
}
@ -552,17 +518,10 @@ function checkPOST($args)
global $Language;
// Check empty password
if( strlen($args['password']) < 6 )
{
if( strlen($args['password']) < 6 ) {
return '<div>'.$Language->g('Password must be at least 6 characters long').'</div>';
}
// Check invalid email
if( !Valid::email($args['email']) && ($args['noCheckEmail']=='0') )
{
return '<div>'.$Language->g('Your email address is invalid').'</div><div id="jscompleteEmail">'.$Language->g('Proceed anyway').'</div>';
}
// Sanitize email
$email = sanitize::email($args['email']);
@ -588,7 +547,7 @@ function redirect($url) {
$error = '';
if( alreadyInstalled() ) {
exit('Bludit already installed');
exit('Bludit is already installed');
}
if( isset($_GET['demo']) ) {
@ -598,7 +557,6 @@ if( isset($_GET['demo']) ) {
if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$error = checkPOST($_POST);
if($error===true) {
redirect(HTML_PATH_ROOT);
}
@ -625,7 +583,6 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
<script charset="utf-8" src="./js/jquery.min.js?version=<?php echo time() ?>"></script>
<script charset="utf-8" src="./js/uikit/uikit.min.js?version=<?php echo time() ?>"></script>
<script charset="utf-8" src="./js/jstz.min.js?version=<?php echo time() ?>"></script>
</head>
<body class="uk-height-1-1">
<div class="uk-vertical-align uk-text-center uk-height-1-1">
@ -637,10 +594,8 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$system = checkSystem();
// Missing requirements
if(!empty($system))
{
foreach($system as $values)
{
if(!empty($system)) {
foreach($system as $values) {
echo '<div class="uk-panel">';
echo '<div class="uk-panel-badge uk-badge uk-badge-danger">FAIL</div>';
echo '<h3 class="uk-panel-title">'.$values['title'].'</h3>';
@ -661,7 +616,6 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
?>
<form id="jsformInstaller" class="uk-form uk-form-stacked" method="post" action="" autocomplete="off">
<input type="hidden" name="noCheckEmail" id="jsnoCheckEmail" value="0">
<input type="hidden" name="timezone" id="jstimezone" value="0">
<div class="uk-form-row">
@ -718,19 +672,10 @@ if( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
<script>
$(document).ready(function()
{
// Timezone
var timezone = jstz.determine();
$("#jstimezone").val( timezone.name() );
// Proceed without email field.
$("#jscompleteEmail").on("click", function() {
$("#jsnoCheckEmail").val("1");
$("#jsformInstaller").submit();
});
// Show password
$("#jsshowPassword").on("click", function() {
var input = document.getElementById("jspassword");