Skip to content

Commit

Permalink
Merge pull request #2 from dignajar/master
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
clickwork-git committed Sep 22, 2015
2 parents 0c9fceb + 0180396 commit 7f1410c
Show file tree
Hide file tree
Showing 17 changed files with 346 additions and 138 deletions.
Binary file added admin/themes/default/css/favicon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions admin/themes/default/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<title><?php echo $layout['title'] ?></title>

<link rel="shortcut icon" type="image/x-icon" href="./css/favicon.png">

<link rel="stylesheet" type="text/css" href="./css/kube.min.css?version=<?php echo BLUDIT_VERSION ?>">
<link rel="stylesheet" type="text/css" href="./css/default.css?version=<?php echo BLUDIT_VERSION ?>">
<link rel="stylesheet" type="text/css" href="./css/jquery.datetimepicker.css?version=<?php echo BLUDIT_VERSION ?>">
Expand Down
3 changes: 3 additions & 0 deletions kernel/boot/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@
define('HTML_PATH_THEME_IMG', HTML_PATH_THEME.'img/');

define('HTML_PATH_ADMIN_THEME', HTML_PATH_ROOT.'admin/themes/'.$Site->adminTheme().'/');
define('HTML_PATH_ADMIN_THEME_JS', HTML_PATH_ADMIN_THEME.'js/');
define('HTML_PATH_ADMIN_ROOT', HTML_PATH_ROOT.'admin/');
define('HTML_PATH_UPLOADS', HTML_PATH_ROOT.'content/uploads/');
define('HTML_PATH_PLUGINS', HTML_PATH_ROOT.'plugins/');

define('JQUERY', HTML_PATH_ADMIN_THEME_JS.'jquery.min.js');

// PHP paths with dependency
define('PATH_THEME', PATH_ROOT.'themes/'.$Site->theme().'/');
define('PATH_THEME_PHP', PATH_THEME.'php'.DS);
Expand Down
15 changes: 5 additions & 10 deletions kernel/boot/rules/70.pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,21 @@ function build_page($key)
global $dbUsers;
global $Parsedown;

// Page object.
// Page object, content from FILE.
$Page = new Page($key);
if( !$Page->isValid() ) {
return false;
}

// Page database.
// Page database, content from DATABASE JSON.
$db = $dbPages->getDb($key);
if( !$db ) {
return false;
}

// Foreach field from database.
foreach($db as $field=>$value)
{
// Not overwrite the value from file.
$Page->setField($field, $value, false);

// Overwrite the value on the db.
//$dbPages->setDb($key, $field, $value);
// Foreach field from DATABASE.
foreach($db as $field=>$value) {
$Page->setField($field, $value);
}

// Content in raw format
Expand Down
16 changes: 8 additions & 8 deletions kernel/boot/rules/70.posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,23 @@ function buildPost($key)
global $Parsedown;
global $Site;

// Post object, this get the content from the file.
// Post object, content from FILE.
$Post = new Post($key);
if( !$Post->isValid() ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the post from file with key: '.$key);
return false;
}

// Page database, this get the contente from the database json.
// Post database, content from DATABASE JSON.
$db = $dbPosts->getDb($key);
if( !$db ) {
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the post from database with key: '.$key);
return false;
}

// Foreach field from database.
foreach($db as $field=>$value)
{
// Not overwrite the value from file.
$Post->setField($field, $value, false);
// Foreach field from DATABASE.
foreach($db as $field=>$value) {
$Post->setField($field, $value);
}

// Content in raw format
Expand Down Expand Up @@ -119,7 +117,9 @@ function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeU

// Search for changes on posts by the user.
if( $Site->cliMode() ) {
$dbPosts->regenerateCli();
if($dbPosts->regenerateCli()) {
reIndexTagsPosts();
}
}

// Execute the scheduler.
Expand Down
25 changes: 20 additions & 5 deletions kernel/dbpages.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ public function regenerateCli()

$fields['status'] = CLI_STATUS;
$fields['date'] = Date::current(DB_DATE_FORMAT);
$fields['username'] = 'admin';

//$tmpPaths = glob(PATH_PAGES.'*', GLOB_ONLYDIR);
$tmpPaths = Filesystem::listDirectories(PATH_PAGES);
Expand Down Expand Up @@ -372,13 +373,27 @@ public function regenerateCli()
// Update all fields from FILE to DATABASE.
foreach($fields as $f=>$v)
{
if($Page->getField($f)) {
// DEBUG: Validar/Sanitizar valores, ej: validar formato fecha
$this->db[$key][$f] = $Page->getField($f);
// If the field exists on the FILE, update it.
if($Page->getField($f))
{
$valueFromFile = $Page->getField($f);

if($f=='tags') {
// Generate tags array.
$this->db[$key]['tags'] = $this->generateTags($valueFromFile);
}
elseif($f=='date') {
// Validate Date from file
if(Valid::date($valueFromFile, DB_DATE_FORMAT)) {
$this->db[$key]['date'] = $valueFromFile;
}
}
else {
// Sanitize the values from file.
$this->db[$key][$f] = Sanitize::html($valueFromFile);
}
}
}

// DEBUG: Update tags
}

// Remove old pages from db
Expand Down
82 changes: 46 additions & 36 deletions kernel/dbposts.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,69 +378,79 @@ private function sortHighToLow($a, $b) {
return $a['date']<$b['date'];
}

// Return TRUE if there are new posts, FALSE otherwise.
public function regenerateCli()
{
$db = $this->db;
$newPaths = array();
$allPosts = array();
$fields = array();
$currentDate = Date::current(DB_DATE_FORMAT);

// Default fields and value
// Generate default fields and values.
foreach($this->dbFields as $field=>$options) {
if(!$options['inFile']) {
$fields[$field] = $options['value'];
}
}

$fields['status'] = CLI_STATUS;
$fields['date'] = Date::current(DB_DATE_FORMAT);
$fields['date'] = $currentDate;
$fields['username'] = 'admin';

// Recovery pages from the first level of directories
//$tmpPaths = glob(PATH_POSTS.'*', GLOB_ONLYDIR);
// Recovery posts from the first level of directories
$tmpPaths = Filesystem::listDirectories(PATH_POSTS);
foreach($tmpPaths as $directory)
{
$key = basename($directory);

if(file_exists($directory.DS.'index.txt')) {
// The key is the directory name
$newPaths[$key] = true;
}
}
if(file_exists($directory.DS.'index.txt'))
{
// The key is the directory name.
$key = basename($directory);

foreach($newPaths as $key=>$value)
{
if(!isset($this->db[$key])) {
$this->db[$key] = $fields;
}
// All keys posts
$allPosts[$key] = true;

$Post = new Post($key);
// Create the new entry if not exists on DATABASE.
if(!isset($this->db[$key])) {
// New entry on database
$this->db[$key] = $fields;
}

// Update all fields from FILE to DATABASE.
foreach($fields as $f=>$v)
{
if($Post->getField($f)) {
// Create the post from FILE.
$Post = new Post($key);

$valueFromFile = $Post->getField($f);
// Update all fields from FILE to DATABASE.
foreach($fields as $f=>$v)
{
// If the field exists on the FILE, update it.
if($Post->getField($f))
{
$valueFromFile = $Post->getField($f);

// Validate values from file.
if($f=='tags') {
$valueFromFile = array_map('trim', explode(',', $valueFromFile));
$valueFromFile = implode(',', $valueFromFile);
}
elseif($f=='date') {
if(!Valid::date($valueFromFile,DB_DATE_FORMAT)) {
$valueFromFile = Date::current(DB_DATE_FORMAT);
if($f=='tags') {
// Generate tags array.
$this->db[$key]['tags'] = $this->generateTags($valueFromFile);
}
elseif($f=='date') {
// Validate Date from file
if(Valid::date($valueFromFile, DB_DATE_FORMAT)) {
$this->db[$key]['date'] = $valueFromFile;

if( $valueFromFile>$currentDate ) {
$this->db[$key]['status'] = 'scheduled';
}
}
}
else {
// Sanitize the values from file.
$this->db[$key][$f] = Sanitize::html($valueFromFile);
}
}

// Sanitize the values from file.
$this->db[$key][$f] = Sanitize::html($valueFromFile);
}
}
}

// Remove old posts from db
foreach( array_diff_key($db, $newPaths) as $key=>$data ) {
// Remove orphan posts from db, the orphan posts are posts deleted by hand (directory deleted).
foreach( array_diff_key($db, $allPosts) as $key=>$data ) {
unset($this->db[$key]);
}

Expand Down
2 changes: 2 additions & 0 deletions kernel/helpers/filesystem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
class Filesystem {

// NEW

// Returns an array with the absolutes directories.
public static function listDirectories($path, $regex='*')
{
$directories = glob($path.$regex, GLOB_ONLYDIR);
Expand Down
30 changes: 21 additions & 9 deletions kernel/helpers/theme.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ class Theme {

// NEW

public static function favicon($file='favicon.png', $path=HTML_PATH_THEME_IMG, $echo=true)
{
$tmp = '<link rel="shortcut icon" href="'.$path.$file.'" type="image/x-icon">'.PHP_EOL;

if($echo) {
echo $tmp;
}

return $tmp;
}

public static function css($files, $path=HTML_PATH_THEME_CSS, $echo=true)
{
if(!is_array($files)) {
Expand Down Expand Up @@ -109,6 +120,16 @@ public static function plugins($type)
}
}

public static function jquery($echo=true)
{
$tmp = '<script src="'.JQUERY.'"></script>'.PHP_EOL;

if($echo) {
echo $tmp;
}

return $tmp;
}

// OLD

Expand All @@ -120,17 +141,8 @@ public static function url($relative = true)
return BLOG_URL;
}

public static function jquery($path=JS_JQUERY)
{
$tmp = '<script src="'.$path.'"></script>'.PHP_EOL;

return $tmp;
}

public static function favicon()
{
return '<link rel="shortcut icon" href="'.HTML_THEME_CSS.'img/favicon.ico" type="image/x-icon">'.PHP_EOL;
}

public static function name()
{
Expand Down
4 changes: 4 additions & 0 deletions kernel/page.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public function tags($returnsArray=false)
return $tags;
}
else {
if($tags==false) {
return false;
}

// Return string with tags separeted by comma.
return implode(', ', $tags);
}
Expand Down
4 changes: 4 additions & 0 deletions kernel/post.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ public function tags($returnsArray=false)
return $tags;
}
else {
if($tags==false) {
return false;
}

// Return string with tags separeted by comma.
return implode(', ', $tags);
}
Expand Down
3 changes: 2 additions & 1 deletion languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,6 @@
"you-can-schedule-the-post-just-select-the-date-and-time": "You can schedule the post, just select the date and time.",
"scheduled": "Scheduled",
"publish": "Publish",
"please-check-your-theme-configuration": "Please check your theme configuration."
"please-check-your-theme-configuration": "Please check your theme configuration.",
"plugin-label": "Plugin label"
}

0 comments on commit 7f1410c

Please sign in to comment.