Merge pull request #12 from dignajar/master

New pull request
This commit is contained in:
Edi 2016-01-23 00:59:06 +01:00
commit 359804abb8
419 changed files with 10490 additions and 4679 deletions

10
.gitignore vendored
View File

@ -1,7 +1,5 @@
.DS_Store .DS_Store
!themes/pure bl-content/databases
themes/* bl-content/pages
content/databases bl-content/posts
content/pages bl-content/uploads
content/posts
content/uploads

View File

@ -1,8 +1,8 @@
[Bludit](http://www.bludit.com/) — Flat file CMS [Bludit](http://www.bludit.com/)
================================================ ================================
Create your own Blog in seconds. **Fast**, **simple**, **extensible** and **flat file** CMS.
Fast, simple, extensible and Flat file CMS. Bludit is a simple web application to make your own **blog** or **site** in seconds, it's completly **free and open source**. Bludit uses flat-files (text files in JSON format) to store the posts and pages, you don't need to install or configure a database.
- [Documentation](http://docs.bludit.com) - [Documentation](http://docs.bludit.com)
- [Help and Support](http://forum.bludit.com) - [Help and Support](http://forum.bludit.com)
@ -10,13 +10,13 @@ Fast, simple, extensible and Flat file CMS.
- [Themes](https://github.com/dignajar/bludit-themes) - [Themes](https://github.com/dignajar/bludit-themes)
- [More plugins and themes](http://forum.bludit.com/viewforum.php?f=14) - [More plugins and themes](http://forum.bludit.com/viewforum.php?f=14)
Social Social networks
------ ---------------
- [Twitter](https://twitter.com/bludit) - [Twitter](https://twitter.com/bludit)
- [Facebook](https://www.facebook.com/bluditcms) - [Facebook](https://www.facebook.com/bluditcms)
- [Google+](https://plus.google.com/+Bluditcms) - [Google+](https://plus.google.com/+Bluditcms)
- [Freenode IRC](https://webchat.freenode.net) channel #bludit - [Freenode IRC](https://webchat.freenode.net) channel **#bludit**
[![Join the chat at https://gitter.im/dignajar/bludit](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dignajar/bludit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Join the chat at https://gitter.im/dignajar/bludit](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/dignajar/bludit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

View File

@ -40,10 +40,6 @@ class dbJSON
$this->dbBackup = $array; $this->dbBackup = $array;
} }
} }
else
{
Log::set(__METHOD__.LOG_SEP.'File '.$file.' does not exists');
}
} }
public function restoreDB() public function restoreDB()
@ -58,6 +54,7 @@ class dbJSON
return count($this->db); return count($this->db);
} }
// Returns the value from the field.
public function getField($field) public function getField($field)
{ {
if(isset($this->db[$field])) { if(isset($this->db[$field])) {
@ -86,24 +83,24 @@ class dbJSON
return file_put_contents($this->file, $data, LOCK_EX); return file_put_contents($this->file, $data, LOCK_EX);
} }
// Returns a JSON encoded string on success or FALSE on failure.
private function serialize($data) private function serialize($data)
{ {
// DEBUG: La idea es siempre serializar en json, habria que ver si siempre esta cargado json_enconde y decode return json_encode($data, JSON_PRETTY_PRINT);
if(JSON) {
return json_encode($data, JSON_PRETTY_PRINT);
}
return serialize($data);
} }
// Returns the value encoded in json in appropriate PHP type.
private function unserialize($data) private function unserialize($data)
{ {
// DEBUG: La idea es siempre serializar en json, habria que ver si siempre esta cargado json_enconde y decode // NULL is returned if the json cannot be decoded.
if(JSON) { $decode = json_decode($data, true);
return json_decode($data, true);
// If NULL returns false.
if(empty($decode)) {
return false;
} }
return unserialize($data); return $decode;
} }
} }

View File

@ -8,6 +8,8 @@ class Plugin {
// (string) Database path and filename // (string) Database path and filename
public $filenameDb; public $filenameDb;
public $filenameMetadata;
// (array) Database unserialized // (array) Database unserialized
public $db; public $db;
@ -18,20 +20,10 @@ class Plugin {
public $className; public $className;
// (array) Plugin's information. // (array) Plugin's information.
public $data; public $metadata;
function __construct() function __construct()
{ {
$this->data = array(
'name'=>'',
'description'=>'',
'author'=>'',
'email'=>'',
'website'=>'',
'version'=>'',
'releaseDate'=>''
);
$this->dbFields = array(); $this->dbFields = array();
$reflector = new ReflectionClass(get_class($this)); $reflector = new ReflectionClass(get_class($this));
@ -50,7 +42,12 @@ class Plugin {
$this->filenameDb = PATH_PLUGINS_DATABASES.$this->directoryName.DS.'db.php'; $this->filenameDb = PATH_PLUGINS_DATABASES.$this->directoryName.DS.'db.php';
// If the plugin installed then get the database. // --- Metadata ---
$this->filenameMetadata = PATH_PLUGINS.$this->directoryName().DS.'metadata.json';
$metadataString = file_get_contents($this->filenameMetadata);
$this->metadata = json_decode($metadataString, true);
// If the plugin is installed then get the database.
if($this->installed()) if($this->installed())
{ {
$Tmp = new dbJSON($this->filenameDb); $Tmp = new dbJSON($this->filenameDb);
@ -74,18 +71,19 @@ class Plugin {
} }
// Returns the item from plugin-data. // Returns the item from plugin-data.
public function getData($key) public function getMetadata($key)
{ {
if(isset($this->data[$key])) { if(isset($this->metadata[$key])) {
return $this->data[$key]; return $this->metadata[$key];
} }
return ''; return '';
} }
public function setData($array) public function setMetadata($key, $value)
{ {
$this->data = $array; $this->metadata[$key] = $value;
return true;
} }
public function getDbField($key, $html=true) public function getDbField($key, $html=true)
@ -124,37 +122,37 @@ class Plugin {
public function name() public function name()
{ {
return $this->getData('name'); return $this->getMetadata('name');
} }
public function description() public function description()
{ {
return $this->getData('description'); return $this->getMetadata('description');
} }
public function author() public function author()
{ {
return $this->getData('author'); return $this->getMetadata('author');
} }
public function email() public function email()
{ {
return $this->getData('email'); return $this->getMetadata('email');
} }
public function website() public function website()
{ {
return $this->getData('website'); return $this->getMetadata('website');
} }
public function version() public function version()
{ {
return $this->getData('version'); return $this->getMetadata('version');
} }
public function releaseDate() public function releaseDate()
{ {
return $this->getData('releaseDate'); return $this->getMetadata('releaseDate');
} }
public function className() public function className()

View File

@ -6,10 +6,23 @@
function updateBludit() function updateBludit()
{ {
global $Site; global $Site;
global $dbPosts;
// Check if Bludit need to be update. // Check if Bludit need to be update.
if( ($Site->currentBuild() < BLUDIT_BUILD) || isset($_GET['update']) ) if( ($Site->currentBuild() < BLUDIT_BUILD) || isset($_GET['update']) )
{ {
// --- Update dates ---
foreach($dbPosts->db as $key=>$post)
{
$date = Date::format($post['date'], 'Y-m-d H:i', DB_DATE_FORMAT);
if($date !== false) {
$dbPosts->setPostDb($key,'date',$date);
}
}
$dbPosts->save();
// --- Update directories ---
$directories = array( $directories = array(
PATH_POSTS, PATH_POSTS,
PATH_PAGES, PATH_PAGES,

View File

@ -21,30 +21,4 @@ if($Login->role()!=='admin') {
// Main after POST // Main after POST
// ============================================================================ // ============================================================================
$themes = array(); $themes = buildThemes();
$themesPaths = Filesystem::listDirectories(PATH_THEMES);
foreach($themesPaths as $themePath)
{
$langLocaleFile = $themePath.DS.'languages'.DS.$Site->locale().'.json';
$langDefaultFile = $themePath.DS.'languages'.DS.'en_US.json';
// Check if exists default language
if( Sanitize::pathFile($langDefaultFile) )
{
$database = new dbJSON($langDefaultFile, false);
$databaseArray = $database->db;
$themeMetaData = $database->db['theme-data'];
// Check if exists locale language
if( Sanitize::pathFile($langLocaleFile) ) {
$database = new dbJSON($langLocaleFile, false);
$themeMetaData = array_merge($themeMetaData, $database->db['theme-data']);
}
$themeMetaData['dirname'] = basename($themePath);
// Theme data
array_push($themes, $themeMetaData);
}
}

View File

@ -179,6 +179,19 @@ button.delete-button:hover {
text-transform: uppercase; text-transform: uppercase;
} }
#jstagList {
margin-top: 5px;
}
#jstagList span {
background: #f1f1f1;
border-radius: 3px;
color: #2672ec;
margin-right: 5px;
padding: 3px 10px;
cursor: pointer;
}
/* ----------- BLUDIT IMAGES V8 ----------- */ /* ----------- BLUDIT IMAGES V8 ----------- */
#bludit-images-v8 { #bludit-images-v8 {
@ -340,6 +353,11 @@ h3.titleOptions {
/* ----------- PLUGIN LIST / THEME LIST ----------- */ /* ----------- PLUGIN LIST / THEME LIST ----------- */
tr.plugin-installed,
tr.theme-installed {
background: #F2F7FF !important;
}
div.plugin-links > a { div.plugin-links > a {
display: inline-block; display: inline-block;
margin-top: 5px; margin-top: 5px;

File diff suppressed because one or more lines are too long

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

View File

Before

Width:  |  Height:  |  Size: 1005 B

After

Width:  |  Height:  |  Size: 1005 B

View File

@ -20,7 +20,22 @@ class HTML {
public static function formClose() public static function formClose()
{ {
$html = '</form>'; $html = '</form>';
echo $html;
$script = '<script>
$(document).ready(function() {
// Prevent the form submit when press enter key.
$("form").keypress(function(e) {
if (e.which == 13) {
return false;
}
});
});
</script>';
echo $html.$script;
} }
// label, name, value, tip // label, name, value, tip
@ -52,22 +67,104 @@ class HTML {
echo $html; echo $html;
} }
public static function formInputAutocomplete($args) public static function tagsAutocomplete($args)
{ {
// Tag array for Javascript
$tagArray = 'var tagArray = [];';
if(!empty($args['value'])) {
$tagArray = 'var tagArray = ["'.implode('","', $args['value']).'"]';
}
$args['value'] = '';
// Text input
self::formInputText($args); self::formInputText($args);
echo '<div id="jstagList"></div>';
$script = '<script> $script = '<script>
$("input[name=\"'.$args['name'].'\"]").autoComplete({
minChars: 1, '.$tagArray.'
source: function(term, suggest){
term = term.toLowerCase(); function insertTag(tag)
var choices = ['.$args['words'].']; {
var matches = []; // Clean the input text
for (i=0; i<choices.length; i++) $("#jstags").val("");
if (~choices[i].toLowerCase().indexOf(term)) matches.push(choices[i]);
suggest(matches); if(tag.trim()=="") {
} return true;
}
// Check if the tag is already inserted.
var found = $.inArray(tag, tagArray);
if(found == -1) {
tagArray.push(tag);
renderTagList();
}
}
function removeTag(tag)
{
var found = $.inArray(tag, tagArray);
if(found => 0) {
tagArray.splice(found, 1);
renderTagList();
}
}
function renderTagList()
{
if(tagArray.length == 0) {
$("#jstagList").html("");
}
else {
$("#jstagList").html("<span>"+tagArray.join("</span><span>")+"</span>");
}
}
$("#jstags").autoComplete({
minChars: 1,
source: function(term, suggest){
term = term.toLowerCase();
var choices = ['.$args['words'].'];
var matches = [];
for (i=0; i<choices.length; i++)
if (~choices[i].toLowerCase().indexOf(term)) matches.push(choices[i]);
suggest(matches);
},
onSelect: function(e, value, item) {
// Insert the tag when select whit the mouse click.
insertTag(value);
}
}); });
$(document).ready(function() {
// When the page is loaded render the tags
renderTagList();
// Remove the tag when click on it.
$("body").on("click", "#jstagList > span", function() {
value = $(this).html();
removeTag(value);
});
// Insert tag when press enter key.
$("#jstags").keypress(function(e) {
if (e.which == 13) {
var value = $(this).val();
insertTag(value);
}
});
// When form submit.
$("form").submit(function(e) {
var list = tagArray.join(",");
$("#jstags").val(list);
});
});
</script>'; </script>';
echo $script; echo $script;
@ -157,7 +254,7 @@ $("input[name=\"'.$args['name'].'\"]").autoComplete({
$html = '<!-- BLUDIT QUICK IMAGES -->'; $html = '<!-- BLUDIT QUICK IMAGES -->';
$html .= ' $html .= '
<div id="bludit-quick-images"> <div id="bludit-quick-images">
<div id="bludit-quick-images-thumbnails"> <div id="bludit-quick-images-thumbnails" onmousedown="return false">
'; ';
$thumbnailList = Filesystem::listFiles(PATH_UPLOADS_THUMBNAILS,'*','*',true); $thumbnailList = Filesystem::listFiles(PATH_UPLOADS_THUMBNAILS,'*','*',true);
@ -172,7 +269,7 @@ $html .= '
'; ';
if(empty($thumbnailList)) { if(empty($thumbnailList)) {
$html .= '<div class="empty-images uk-block uk-text-center uk-block-muted">There are no images, upload someone to make your site more cheerful.</div>'; $html .= '<div class="empty-images uk-block uk-text-center uk-block-muted">'.$L->g('There are no images').'</div>';
} }
$html .= ' $html .= '
@ -345,7 +442,7 @@ $html .= '
'; ';
if(empty($thumbnailList)) { if(empty($thumbnailList)) {
$html .= '<div class="empty-images uk-block uk-text-center uk-block-muted">There are no images, upload someone to make your site more cheerful.</div>'; $html .= '<div class="empty-images uk-block uk-text-center uk-block-muted">'.$L->g('There are no images').'</div>';
} }
$html .= ' $html .= '

View File

@ -77,11 +77,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
)); ));
// Tags input // Tags input
HTML::formInputAutocomplete(array( HTML::tagsAutocomplete(array(
'name'=>'tags', 'name'=>'tags',
'value'=>$_Page->tags(), 'value'=>$_Page->tags(true),
'tip'=>$L->g('Type the tag and press enter'),
'class'=>'uk-width-1-1 uk-form-large', 'class'=>'uk-width-1-1 uk-form-large',
'tip'=>$L->g('Write the tags separated by commas'),
'label'=>$L->g('Tags'), 'label'=>$L->g('Tags'),
'words'=>'"'.implode('", "', $dbTags->getAll()).'"' 'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
)); ));

View File

@ -71,11 +71,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
)); ));
// Tags input // Tags input
HTML::formInputAutocomplete(array( HTML::tagsAutocomplete(array(
'name'=>'tags', 'name'=>'tags',
'value'=>$_Post->tags(), 'value'=>$_Post->tags(true),
'tip'=>$L->g('Type the tag and press enter'),
'class'=>'uk-width-1-1 uk-form-large', 'class'=>'uk-width-1-1 uk-form-large',
'tip'=>$L->g('Write the tags separated by commas'),
'label'=>$L->g('Tags'), 'label'=>$L->g('Tags'),
'words'=>'"'.implode('", "', $dbTags->getAll()).'"' 'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
)); ));

View File

@ -64,11 +64,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
)); ));
// Tags input // Tags input
HTML::formInputAutocomplete(array( HTML::tagsAutocomplete(array(
'name'=>'tags', 'name'=>'tags',
'value'=>'', 'value'=>'',
'tip'=>$L->g('Type the tag and press enter'),
'class'=>'uk-width-1-1 uk-form-large', 'class'=>'uk-width-1-1 uk-form-large',
'tip'=>$L->g('Write the tags separated by commas'),
'label'=>$L->g('Tags'), 'label'=>$L->g('Tags'),
'words'=>'"'.implode('", "', $dbTags->getAll()).'"' 'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
)); ));

View File

@ -64,11 +64,11 @@ echo '<div class="sidebar uk-width-large-2-10">';
)); ));
// Tags input // Tags input
HTML::formInputAutocomplete(array( HTML::tagsAutocomplete(array(
'name'=>'tags', 'name'=>'tags',
'value'=>'', 'value'=>'',
'tip'=>$L->g('Type the tag and press enter'),
'class'=>'uk-width-1-1 uk-form-large', 'class'=>'uk-width-1-1 uk-form-large',
'tip'=>$L->g('Write the tags separated by commas'),
'label'=>$L->g('Tags'), 'label'=>$L->g('Tags'),
'words'=>'"'.implode('", "', $dbTags->getAll()).'"' 'words'=>'"'.implode('", "', $dbTags->getAll()).'"'
)); ));

View File

@ -3,7 +3,7 @@
HTML::title(array('title'=>$L->g('Plugins'), 'icon'=>'puzzle-piece')); HTML::title(array('title'=>$L->g('Plugins'), 'icon'=>'puzzle-piece'));
echo ' echo '
<table class="uk-table uk-table-striped"> <table class="uk-table">
<thead> <thead>
<tr> <tr>
<th class="uk-width-1-5">'.$L->g('Name').'</th> <th class="uk-width-1-5">'.$L->g('Name').'</th>
@ -18,7 +18,7 @@ echo '
foreach($plugins['all'] as $Plugin) foreach($plugins['all'] as $Plugin)
{ {
echo ' echo '
<tr> <tr '.($Plugin->installed()?'class="plugin-installed"':'class="plugin-notInstalled"').'>
<td> <td>
<div class="plugin-name">'.$Plugin->name().'</div> <div class="plugin-name">'.$Plugin->name().'</div>
<div class="plugin-links"> <div class="plugin-links">
@ -26,7 +26,7 @@ foreach($plugins['all'] as $Plugin)
if($Plugin->installed()) { if($Plugin->installed()) {
if(method_exists($Plugin, 'form')) { if(method_exists($Plugin, 'form')) {
echo '<a class="configure" href="'.HTML_PATH_ADMIN_ROOT.'configure-plugin/'.$Plugin->className().'">'.$L->g('Configure').'</a>'; echo '<a class="configure" href="'.HTML_PATH_ADMIN_ROOT.'configure-plugin/'.$Plugin->className().'">'.$L->g('Settings').'</a>';
echo '<span class="separator"> | </span>'; echo '<span class="separator"> | </span>';
} }
echo '<a class="uninstall" href="'.HTML_PATH_ADMIN_ROOT.'uninstall-plugin/'.$Plugin->className().'">'.$L->g('Deactivate').'</a>'; echo '<a class="uninstall" href="'.HTML_PATH_ADMIN_ROOT.'uninstall-plugin/'.$Plugin->className().'">'.$L->g('Deactivate').'</a>';

View File

@ -3,7 +3,7 @@
HTML::title(array('title'=>$L->g('Themes'), 'icon'=>'paint-brush')); HTML::title(array('title'=>$L->g('Themes'), 'icon'=>'paint-brush'));
echo ' echo '
<table class="uk-table uk-table-striped"> <table class="uk-table">
<thead> <thead>
<tr> <tr>
<th class="uk-width-1-5">'.$L->g('Name').'</th> <th class="uk-width-1-5">'.$L->g('Name').'</th>
@ -18,7 +18,7 @@ echo '
foreach($themes as $theme) foreach($themes as $theme)
{ {
echo ' echo '
<tr> <tr '.($theme['dirname']==$Site->theme()?'class="theme-installed"':'class="theme-notInstalled"').'>
<td> <td>
<div class="plugin-name">'.$theme['name'].'</div> <div class="plugin-name">'.$theme['name'].'</div>
<div class="plugin-links"> <div class="plugin-links">

View File

@ -23,4 +23,4 @@ elseif( $_POST['type']==='post' ) {
echo json_encode( array('slug'=>$slug) ); echo json_encode( array('slug'=>$slug) );
?> ?>

View File

@ -4,7 +4,7 @@
define('BLUDIT_VERSION', 'githubVersion'); define('BLUDIT_VERSION', 'githubVersion');
define('BLUDIT_CODENAME', ''); define('BLUDIT_CODENAME', '');
define('BLUDIT_RELEASE_DATE', ''); define('BLUDIT_RELEASE_DATE', '');
define('BLUDIT_BUILD', '20151119'); define('BLUDIT_BUILD', '20160122');
// Debug mode // Debug mode
define('DEBUG_MODE', TRUE); define('DEBUG_MODE', TRUE);
@ -21,24 +21,28 @@ if(DEBUG_MODE)
// PHP paths // PHP paths
// PATH_ROOT and PATH_BOOT are defined in index.php // PATH_ROOT and PATH_BOOT are defined in index.php
define('PATH_LANGUAGES', PATH_ROOT.'languages'.DS); define('PATH_LANGUAGES', PATH_ROOT.'bl-languages'.DS);
define('PATH_THEMES', PATH_ROOT.'themes'.DS); define('PATH_THEMES', PATH_ROOT.'bl-themes'.DS);
define('PATH_PLUGINS', PATH_ROOT.'plugins'.DS); define('PATH_PLUGINS', PATH_ROOT.'bl-plugins'.DS);
define('PATH_KERNEL', PATH_ROOT.'kernel'.DS); define('PATH_KERNEL', PATH_ROOT.'bl-kernel'.DS);
define('PATH_CONTENT', PATH_ROOT.'bl-content'.DS);
define('PATH_ABSTRACT', PATH_KERNEL.'abstract'.DS); define('PATH_ABSTRACT', PATH_KERNEL.'abstract'.DS);
define('PATH_RULES', PATH_KERNEL.'boot'.DS.'rules'.DS); define('PATH_RULES', PATH_KERNEL.'boot'.DS.'rules'.DS);
define('PATH_HELPERS', PATH_KERNEL.'helpers'.DS); define('PATH_HELPERS', PATH_KERNEL.'helpers'.DS);
define('PATH_AJAX', PATH_KERNEL.'ajax'.DS); define('PATH_AJAX', PATH_KERNEL.'ajax'.DS);
define('PATH_JS', PATH_KERNEL.'js'.DS); define('PATH_JS', PATH_KERNEL.'js'.DS);
define('PATH_CONTENT', PATH_ROOT.'content'.DS);
define('PATH_POSTS', PATH_CONTENT.'posts'.DS); define('PATH_POSTS', PATH_CONTENT.'posts'.DS);
define('PATH_PAGES', PATH_CONTENT.'pages'.DS); define('PATH_PAGES', PATH_CONTENT.'pages'.DS);
define('PATH_DATABASES', PATH_CONTENT.'databases'.DS); define('PATH_DATABASES', PATH_CONTENT.'databases'.DS);
define('PATH_PLUGINS_DATABASES', PATH_CONTENT.'databases'.DS.'plugins'.DS); define('PATH_PLUGINS_DATABASES', PATH_CONTENT.'databases'.DS.'plugins'.DS);
define('PATH_TMP', PATH_CONTENT.'tmp'.DS); define('PATH_TMP', PATH_CONTENT.'tmp'.DS);
define('PATH_UPLOADS', PATH_CONTENT.'uploads'.DS); define('PATH_UPLOADS', PATH_CONTENT.'uploads'.DS);
define('PATH_UPLOADS_PROFILES', PATH_UPLOADS.'profiles'.DS); define('PATH_UPLOADS_PROFILES', PATH_UPLOADS.'profiles'.DS);
define('PATH_UPLOADS_THUMBNAILS', PATH_UPLOADS.'thumbnails'.DS); define('PATH_UPLOADS_THUMBNAILS', PATH_UPLOADS.'thumbnails'.DS);
define('PATH_ADMIN', PATH_KERNEL.'admin'.DS); define('PATH_ADMIN', PATH_KERNEL.'admin'.DS);
define('PATH_ADMIN_THEMES', PATH_ADMIN.'themes'.DS); define('PATH_ADMIN_THEMES', PATH_ADMIN.'themes'.DS);
define('PATH_ADMIN_CONTROLLERS', PATH_ADMIN.'controllers'.DS); define('PATH_ADMIN_CONTROLLERS', PATH_ADMIN.'controllers'.DS);
@ -76,7 +80,7 @@ define('NO_PARENT_CHAR', '3849abb4cb7abd24c2d8dac17b216f17');
define('POSTS_PER_PAGE_ADMIN', 10); define('POSTS_PER_PAGE_ADMIN', 10);
// Check if JSON encode and decode are enabled. // Check if JSON encode and decode are enabled.
define('JSON', function_exists('json_encode')); // define('JSON', function_exists('json_encode'));
// TRUE if new posts hand-made set published, or FALSE for draft. // TRUE if new posts hand-made set published, or FALSE for draft.
define('CLI_STATUS', 'published'); define('CLI_STATUS', 'published');
@ -132,7 +136,6 @@ include(PATH_KERNEL.'parsedown.class.php');
include(PATH_KERNEL.'parsedownextra.class.php'); include(PATH_KERNEL.'parsedownextra.class.php');
include(PATH_KERNEL.'security.class.php'); include(PATH_KERNEL.'security.class.php');
// Include Helpers Classes // Include Helpers Classes
include(PATH_HELPERS.'text.class.php'); include(PATH_HELPERS.'text.class.php');
include(PATH_HELPERS.'log.class.php'); include(PATH_HELPERS.'log.class.php');
@ -152,7 +155,7 @@ include(PATH_HELPERS.'image.class.php');
Session::start(); Session::start();
if(Session::started()===false) { if(Session::started()===false) {
Log::set('init.php'.LOG_SEP.'Error occurred when trying to start the session.'); Log::set('init.php'.LOG_SEP.'Error occurred when trying to start the session.');
exit('Bludit CMS. Failed to start session.'); exit('Bludit. Failed to start session.');
} }
// Objects // Objects
@ -165,7 +168,10 @@ $Url = new Url();
$Parsedown = new ParsedownExtra(); $Parsedown = new ParsedownExtra();
$Security = new Security(); $Security = new Security();
// HTML PATHS // --- Relative paths ---
// This paths are relative for the user / web browsing.
// Base URL
// The user can define the base URL. // The user can define the base URL.
// Left empty if you want to Bludit try to detect the base URL. // Left empty if you want to Bludit try to detect the base URL.
$base = ''; $base = '';
@ -188,30 +194,29 @@ else {
$base = '/'; $base = '/';
} }
define('HTML_PATH_ROOT', $base); define('HTML_PATH_ROOT', $base);
define('HTML_PATH_THEMES', HTML_PATH_ROOT.'bl-themes/');
// Paths for themes define('HTML_PATH_THEME', HTML_PATH_THEMES.$Site->theme().'/');
define('HTML_PATH_THEMES', HTML_PATH_ROOT.'themes/');
define('HTML_PATH_THEME', HTML_PATH_ROOT.'themes/'.$Site->theme().'/');
define('HTML_PATH_THEME_CSS', HTML_PATH_THEME.'css/'); define('HTML_PATH_THEME_CSS', HTML_PATH_THEME.'css/');
define('HTML_PATH_THEME_JS', HTML_PATH_THEME.'js/'); define('HTML_PATH_THEME_JS', HTML_PATH_THEME.'js/');
define('HTML_PATH_THEME_IMG', HTML_PATH_THEME.'img/'); define('HTML_PATH_THEME_IMG', HTML_PATH_THEME.'img/');
define('HTML_PATH_ADMIN_ROOT', HTML_PATH_ROOT.'admin/'); define('HTML_PATH_ADMIN_ROOT', HTML_PATH_ROOT.'admin/');
define('HTML_PATH_ADMIN_THEME', HTML_PATH_ROOT.'kernel/admin/themes/'.$Site->adminTheme().'/'); define('HTML_PATH_ADMIN_THEME', HTML_PATH_ROOT.'bl-kernel/admin/themes/'.$Site->adminTheme().'/');
define('HTML_PATH_ADMIN_THEME_JS', HTML_PATH_ADMIN_THEME.'js/'); define('HTML_PATH_ADMIN_THEME_JS', HTML_PATH_ADMIN_THEME.'js/');
define('HTML_PATH_ADMIN_THEME_CSS', HTML_PATH_ADMIN_THEME.'css/'); define('HTML_PATH_ADMIN_THEME_CSS', HTML_PATH_ADMIN_THEME.'css/');
define('HTML_PATH_ADMIN_THEME_IMG', HTML_PATH_ADMIN_THEME.'img/'); define('HTML_PATH_ADMIN_THEME_IMG', HTML_PATH_ADMIN_THEME.'img/');
define('HTML_PATH_UPLOADS', HTML_PATH_ROOT.'content/uploads/'); define('HTML_PATH_UPLOADS', HTML_PATH_ROOT.'bl-content/uploads/');
define('HTML_PATH_UPLOADS_PROFILES', HTML_PATH_UPLOADS.'profiles/'); define('HTML_PATH_UPLOADS_PROFILES', HTML_PATH_UPLOADS.'profiles/');
define('HTML_PATH_UPLOADS_THUMBNAILS', HTML_PATH_UPLOADS.'thumbnails/'); define('HTML_PATH_UPLOADS_THUMBNAILS', HTML_PATH_UPLOADS.'thumbnails/');
define('HTML_PATH_PLUGINS', HTML_PATH_ROOT.'plugins/'); define('HTML_PATH_PLUGINS', HTML_PATH_ROOT.'bl-plugins/');
define('JQUERY', HTML_PATH_ADMIN_THEME_JS.'jquery.min.js'); define('JQUERY', HTML_PATH_ADMIN_THEME_JS.'jquery.min.js');
// PHP paths with dependency // --- PHP paths with dependency ---
define('PATH_THEME', PATH_ROOT.'themes'.DS.$Site->theme().DS); // This paths are absolutes for the OS.
define('PATH_THEME', PATH_ROOT.'bl-themes'.DS.$Site->theme().DS);
define('PATH_THEME_PHP', PATH_THEME.'php'.DS); define('PATH_THEME_PHP', PATH_THEME.'php'.DS);
define('PATH_THEME_CSS', PATH_THEME.'css'.DS); define('PATH_THEME_CSS', PATH_THEME.'css'.DS);
define('PATH_THEME_JS', PATH_THEME.'js'.DS); define('PATH_THEME_JS', PATH_THEME.'js'.DS);
@ -219,6 +224,7 @@ define('PATH_THEME_IMG', PATH_THEME.'img'.DS);
define('PATH_THEME_LANG', PATH_THEME.'languages'.DS); define('PATH_THEME_LANG', PATH_THEME.'languages'.DS);
// --- Absolute paths with domain --- // --- Absolute paths with domain ---
// This paths are absolutes for the user / web browsing.
define('DOMAIN', $Site->domain()); define('DOMAIN', $Site->domain());
define('DOMAIN_BASE', DOMAIN.HTML_PATH_ROOT); define('DOMAIN_BASE', DOMAIN.HTML_PATH_ROOT);
define('DOMAIN_THEME_CSS', DOMAIN.HTML_PATH_THEME_CSS); define('DOMAIN_THEME_CSS', DOMAIN.HTML_PATH_THEME_CSS);

View File

@ -47,7 +47,7 @@ unset($pluginsEvents['all']);
// Functions // Functions
// ============================================================================ // ============================================================================
function build_plugins() function buildPlugins()
{ {
global $plugins; global $plugins;
global $pluginsEvents; global $pluginsEvents;
@ -72,26 +72,24 @@ function build_plugins()
{ {
$Plugin = new $pluginClass; $Plugin = new $pluginClass;
// Default language and meta data for the plugin
$tmpMetaData = array();
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.'en_US.json';
$database = new dbJSON($languageFilename, false);
$tmpMetaData = $database->db['plugin-data'];
// Check if the plugin is translated. // Check if the plugin is translated.
$languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.$Site->locale().'.json'; $languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.$Site->locale().'.json';
if( Sanitize::pathFile($languageFilename) ) if( !Sanitize::pathFile($languageFilename) ) {
{ $languageFilename = PATH_PLUGINS.$Plugin->directoryName().DS.'languages'.DS.'en_US.json';
$database = new dbJSON($languageFilename, false);
$tmpMetaData = array_merge($tmpMetaData, $database->db['plugin-data']);
} }
// Set plugin meta data $database = file_get_contents($languageFilename);
$Plugin->setData($tmpMetaData); $database = json_decode($database, true);
// Add words to language dictionary. // Set name and description from the language file.
unset($database->db['plugin-data']); $Plugin->setMetadata('name',$database['plugin-data']['name']);
$Language->add($database->db); $Plugin->setMetadata('description',$database['plugin-data']['description']);
// Remove name and description, and add new words if there are.
unset($database['plugin-data']);
if(!empty($database)) {
$Language->add($database);
}
// Push Plugin to array all plugins installed and not installed. // Push Plugin to array all plugins installed and not installed.
$plugins['all'][$pluginClass] = $Plugin; $plugins['all'][$pluginClass] = $Plugin;
@ -113,4 +111,4 @@ function build_plugins()
// Main // Main
// ============================================================================ // ============================================================================
build_plugins(); buildPlugins();

View File

@ -9,6 +9,11 @@ if($Url->whereAmI()=='admin') {
$postPerPage = POSTS_PER_PAGE_ADMIN; $postPerPage = POSTS_PER_PAGE_ADMIN;
$numberOfPosts = $dbPosts->numberPost(true); // published and drafts $numberOfPosts = $dbPosts->numberPost(true); // published and drafts
} }
elseif($Url->whereAmI()=='tag') {
$postPerPage = $Site->postsPerPage();
$tagKey = $Url->slug();
$numberOfPosts = $dbTags->countPostsByTag($tagKey);
}
else { else {
$postPerPage = $Site->postsPerPage(); $postPerPage = $Site->postsPerPage();
$numberOfPosts = $dbPosts->numberPost(false); // published $numberOfPosts = $dbPosts->numberPost(false); // published

View File

@ -0,0 +1,84 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
// ============================================================================
// Variables
// ============================================================================
// ============================================================================
// Functions
// ============================================================================
function buildThemes()
{
global $Site;
$themes = array();
$themesPaths = Filesystem::listDirectories(PATH_THEMES);
foreach($themesPaths as $themePath)
{
// Check if the theme is translated.
$languageFilename = $themePath.DS.'languages'.DS.$Site->locale().'.json';
if( !Sanitize::pathFile($languageFilename) ) {
$languageFilename = $themePath.DS.'languages'.DS.'en_US.json';
}
if( Sanitize::pathFile($languageFilename) )
{
$database = file_get_contents($languageFilename);
$database = json_decode($database, true);
if(empty($database)) {
Log::set('99.themes.php'.LOG_SEP.'JSON Error on theme '.$themePath);
break;
}
$database = $database['theme-data'];
$database['dirname'] = basename($themePath);
// --- Metadata ---
$filenameMetadata = $themePath.DS.'metadata.json';
if( Sanitize::pathFile($filenameMetadata) )
{
$metadataString = file_get_contents($filenameMetadata);
$metadata = json_decode($metadataString, true);
if(empty($metadata)) {
Log::set('99.themes.php'.LOG_SEP.'JSON Error on theme '.$themePath);
break;
}
$database = $database + $metadata;
// Theme data
array_push($themes, $database);
}
}
}
return $themes;
}
// ============================================================================
// Main
// ============================================================================
// Load the language file
$languageFilename = PATH_THEME.DS.'languages'.DS.$Site->locale().'.json';
if( !Sanitize::pathFile($languageFilename) ) {
$languageFilename = PATH_THEME.DS.'languages'.DS.'en_US.json';
}
if( Sanitize::pathFile($languageFilename) )
{
$database = file_get_contents($languageFilename);
$database = json_decode($database, true);
// Remote the name and description.
unset($database['theme-data']);
// Load words from the theme language
if(!empty($database)) {
$Language->add($database);
}
}

View File

@ -14,7 +14,7 @@ class dbPages extends dbJSON
'date'=> array('inFile'=>false, 'value'=>''), 'date'=> array('inFile'=>false, 'value'=>''),
'position'=> array('inFile'=>false, 'value'=>0), 'position'=> array('inFile'=>false, 'value'=>0),
'coverImage'=> array('inFile'=>false, 'value'=>''), 'coverImage'=> array('inFile'=>false, 'value'=>''),
'hash'=> array('inFile'=>false, 'value'=>'') 'checksum'=> array('inFile'=>false, 'value'=>'')
); );
function __construct() function __construct()
@ -78,7 +78,7 @@ class dbPages extends dbJSON
// Create Hash // Create Hash
$serialize = serialize($dataForDb+$dataForFile); $serialize = serialize($dataForDb+$dataForFile);
$dataForDb['hash'] = sha1($serialize); $dataForDb['checksum'] = sha1($serialize);
// Make the directory. Recursive. // Make the directory. Recursive.
if( Filesystem::mkdir(PATH_PAGES.$key, true) === false ) { if( Filesystem::mkdir(PATH_PAGES.$key, true) === false ) {
@ -164,7 +164,7 @@ class dbPages extends dbJSON
// Create Hash // Create Hash
$serialize = serialize($dataForDb+$dataForFile); $serialize = serialize($dataForDb+$dataForFile);
$dataForDb['hash'] = sha1($serialize); $dataForDb['checksum'] = sha1($serialize);
// Move the directory from old key to new key. // Move the directory from old key to new key.
if($newKey!==$args['key']) if($newKey!==$args['key'])

View File

@ -12,7 +12,7 @@ class dbPosts extends dbJSON
'allowComments'=> array('inFile'=>false, 'value'=>false), 'allowComments'=> array('inFile'=>false, 'value'=>false),
'date'=> array('inFile'=>false, 'value'=>''), 'date'=> array('inFile'=>false, 'value'=>''),
'coverImage'=> array('inFile'=>false, 'value'=>''), 'coverImage'=> array('inFile'=>false, 'value'=>''),
'hash'=> array('inFile'=>false, 'value'=>'') 'checksum'=> array('inFile'=>false, 'value'=>'')
); );
private $numberPosts = array( private $numberPosts = array(
@ -110,12 +110,12 @@ class dbPosts extends dbJSON
return false; return false;
} }
// Date // If the date not valid, then set the current date.
if(!Valid::date($args['date'], DB_DATE_FORMAT)) { if(!Valid::date($args['date'], DB_DATE_FORMAT)) {
$args['date'] = $currentDate; $args['date'] = $currentDate;
} }
// Schedule post? // Schedule post ?
if( ($args['date']>$currentDate) && ($args['status']=='published') ) { if( ($args['date']>$currentDate) && ($args['status']=='published') ) {
$args['status'] = 'scheduled'; $args['status'] = 'scheduled';
} }
@ -161,7 +161,7 @@ class dbPosts extends dbJSON
// Create Hash // Create Hash
$serialize = serialize($dataForDb+$dataForFile); $serialize = serialize($dataForDb+$dataForFile);
$dataForDb['hash'] = sha1($serialize); $dataForDb['checksum'] = sha1($serialize);
// Make the directory. // Make the directory.
if( Filesystem::mkdir(PATH_POSTS.$key) === false ) { if( Filesystem::mkdir(PATH_POSTS.$key) === false ) {
@ -314,7 +314,7 @@ class dbPosts extends dbJSON
$saveDatabase = false; $saveDatabase = false;
// Check scheduled posts and publish. // Check scheduled posts
foreach($this->db as $postKey=>$values) foreach($this->db as $postKey=>$values)
{ {
if($values['status']=='scheduled') if($values['status']=='scheduled')
@ -330,7 +330,7 @@ class dbPosts extends dbJSON
} }
} }
// Save the database. // Save the database ?
if($saveDatabase) if($saveDatabase)
{ {
if( $this->save() === false ) { if( $this->save() === false ) {
@ -421,7 +421,7 @@ class dbPosts extends dbJSON
// All keys posts // All keys posts
$allPosts[$key] = true; $allPosts[$key] = true;
// Create the new entry if not exists on DATABASE. // Create the new entry if not exist on DATABASE.
if(!isset($this->db[$key])) { if(!isset($this->db[$key])) {
// New entry on database // New entry on database
$this->db[$key] = $fields; $this->db[$key] = $fields;
@ -447,7 +447,7 @@ class dbPosts extends dbJSON
if(Valid::date($valueFromFile, DB_DATE_FORMAT)) { if(Valid::date($valueFromFile, DB_DATE_FORMAT)) {
$this->db[$key]['date'] = $valueFromFile; $this->db[$key]['date'] = $valueFromFile;
if( $valueFromFile>$currentDate ) { if( $valueFromFile > $currentDate ) {
$this->db[$key]['status'] = 'scheduled'; $this->db[$key]['status'] = 'scheduled';
} }
} }

View File

@ -152,12 +152,15 @@ class dbSite extends dbJSON
return $this->getField('footer'); return $this->getField('footer');
} }
// Returns the url site. // Returns the full domain and base url.
// For example, http://www.domain.com/bludit/
public function url() public function url()
{ {
return $this->getField('url'); return $this->getField('url');
} }
// Returns the protocol and the domain, without the base url.
// For example, http://www.domain.com
public function domain() public function domain()
{ {
// If the URL field is not set, try detect the domain. // If the URL field is not set, try detect the domain.
@ -261,4 +264,4 @@ class dbSite extends dbJSON
return date_default_timezone_set($timezone); return date_default_timezone_set($timezone);
} }
} }

View File

@ -26,4 +26,4 @@ class Email {
return mail($args['to'], $args['subject'], $message, implode(PHP_EOL, $headers)); return mail($args['to'], $args['subject'], $message, implode(PHP_EOL, $headers));
} }
} }

Some files were not shown because too many files have changed in this diff Show More