Updates
This commit is contained in:
parent
f3ba92527b
commit
708514fc81
Binary file not shown.
After Width: | Height: | Size: 1005 B |
|
@ -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 ?>">
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -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.
|
||||
|
|
|
@ -372,13 +372,27 @@ class dbPages extends dbJSON
|
|||
// 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);
|
||||
|
||||
// DEBUG: Update tags
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove old pages from db
|
||||
|
|
|
@ -378,13 +378,15 @@ class dbPosts extends dbJSON
|
|||
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'];
|
||||
|
@ -392,55 +394,62 @@ class dbPosts extends dbJSON
|
|||
}
|
||||
|
||||
$fields['status'] = CLI_STATUS;
|
||||
$fields['date'] = Date::current(DB_DATE_FORMAT);
|
||||
$fields['date'] = $currentDate;
|
||||
|
||||
// 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)
|
||||
{
|
||||
if(file_exists($directory.DS.'index.txt'))
|
||||
{
|
||||
// The key is the directory name.
|
||||
$key = basename($directory);
|
||||
|
||||
if(file_exists($directory.DS.'index.txt')) {
|
||||
// The key is the directory name
|
||||
$newPaths[$key] = true;
|
||||
}
|
||||
}
|
||||
// All keys posts
|
||||
$allPosts[$key] = true;
|
||||
|
||||
foreach($newPaths as $key=>$value)
|
||||
{
|
||||
// Create the new entry if not exists on DATABASE.
|
||||
if(!isset($this->db[$key])) {
|
||||
// New entry on database
|
||||
$this->db[$key] = $fields;
|
||||
}
|
||||
|
||||
// Create the post from FILE.
|
||||
$Post = new Post($key);
|
||||
|
||||
// Update all fields from FILE to DATABASE.
|
||||
foreach($fields as $f=>$v)
|
||||
{
|
||||
if($Post->getField($f)) {
|
||||
|
||||
// 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);
|
||||
// Generate tags array.
|
||||
$this->db[$key]['tags'] = $this->generateTags($valueFromFile);
|
||||
}
|
||||
elseif($f=='date') {
|
||||
if(!Valid::date($valueFromFile,DB_DATE_FORMAT)) {
|
||||
$valueFromFile = Date::current(DB_DATE_FORMAT);
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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]);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -32,51 +32,48 @@ class pluginPages extends Plugin {
|
|||
global $Language;
|
||||
global $pagesParents;
|
||||
global $Site, $Url;
|
||||
$home = $Url->whereAmI()==='home';
|
||||
|
||||
$html = '<div class="plugin plugin-pages">';
|
||||
|
||||
// Print the label if it not empty.
|
||||
// Print the label if not empty.
|
||||
$label = $this->getDbField('label');
|
||||
if( !empty($label) ) {
|
||||
$html .= '<h2>'.$label.'</h2>';
|
||||
}
|
||||
|
||||
$html .= '<div class="plugin-content">';
|
||||
|
||||
$parents = $pagesParents[NO_PARENT_CHAR];
|
||||
|
||||
$html .= '<ul>';
|
||||
|
||||
// Show home link ?
|
||||
if($this->getDbField('homeLink')) {
|
||||
$current = ($Site->homeLink()==$home) ? ' class="active"' : '';
|
||||
$html .= '<li' .$current. '><a class="parent" href="'.$Site->homeLink().'">'.$Language->get('Home').'</a></li>';
|
||||
$html .= '<li>';
|
||||
$html .= '<a class="parent'.( ($Url->whereAmI()=='home')?' active':'').'" href="'.$Site->homeLink().'">'.$Language->get('Home').'</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
|
||||
$parents = $pagesParents[NO_PARENT_CHAR];
|
||||
foreach($parents as $parent)
|
||||
{
|
||||
//if($Site->homepage()!==$parent->key())
|
||||
{
|
||||
$current_parent = ($parent->slug()==$Url->slug()) ? ' class="active"' : '';
|
||||
// Print the parent
|
||||
$html .= '<li' .$current_parent. '><a class="parent" href="'.$parent->permalink().'">'.$parent->title().'</a>';
|
||||
$html .= '<li>';
|
||||
$html .= '<a class="parent '.( ($parent->key()==$Url->slug())?' active':'').'" href="'.$parent->permalink().'">'.$parent->title().'</a>';
|
||||
|
||||
// Check if the parent has children
|
||||
if(isset($pagesParents[$parent->key()]))
|
||||
{
|
||||
$children = $pagesParents[$parent->key()];
|
||||
|
||||
// Print the children
|
||||
// Print children
|
||||
$html .= '<ul>';
|
||||
foreach($children as $child)
|
||||
{
|
||||
$current_child = ($child->slug()==$Url->slug()) ? ' class="active"' : '';
|
||||
$html .= '<li' .$current_child. '><a class="children" href="'.$child->permalink().'">'.$child->title().'</a></li>';
|
||||
$html .= '<li>';
|
||||
$html .= '<a class="children '.( ($child->key()==$Url->slug())?' active':'').'" href="'.$child->permalink().'">'.$child->title().'</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
$html .= '</ul>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$html .= '</li></ul>';
|
||||
$html .= '</div>';
|
||||
|
|
|
@ -268,9 +268,6 @@ div.plugin-content li {
|
|||
margin-top: 5px;
|
||||
}
|
||||
|
||||
div.plugin-content ul li.active a {
|
||||
color: #2672ec;
|
||||
}
|
||||
div.plugin-content ul {
|
||||
display: block;
|
||||
list-style-type: none;
|
||||
|
@ -292,6 +289,11 @@ div.plugin-content ul > li > ul > li > a {
|
|||
color: #777;
|
||||
}
|
||||
|
||||
div.plugin-content a.active {
|
||||
color: #2672ec !important;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------
|
||||
Responsive
|
||||
------------------------ */
|
||||
|
|
Loading…
Reference in New Issue