Date format for posts and plugin pages bug fixes

This commit is contained in:
dignajar 2015-11-14 13:47:26 -03:00
parent 16651cf8f7
commit 9d16a4b754
12 changed files with 332 additions and 50 deletions

View File

@ -26,7 +26,7 @@ echo '
echo '<tr>'; echo '<tr>';
echo '<td><a href="'.HTML_PATH_ADMIN_ROOT.'edit-post/'.$Post->key().'">'.($status?'<span class="label-draft">'.$status.'</span>':'').($Post->title()?$Post->title():'<span class="label-empty-title">'.$Language->g('Empty title').'</span> ').'</a></td>'; echo '<td><a href="'.HTML_PATH_ADMIN_ROOT.'edit-post/'.$Post->key().'">'.($status?'<span class="label-draft">'.$status.'</span>':'').($Post->title()?$Post->title():'<span class="label-empty-title">'.$Language->g('Empty title').'</span> ').'</a></td>';
echo '<td class="uk-text-center">'.$Post->date().'</td>'; echo '<td class="uk-text-center">'.$Post->dateRaw().'</td>';
echo '<td><a target="_blank" href="'.$Post->permalink().'">'.$Url->filters('post').'/'.$Post->key().'</a></td>'; echo '<td><a target="_blank" href="'.$Post->permalink().'">'.$Url->filters('post').'/'.$Post->key().'</a></td>';
echo '</tr>'; echo '</tr>';
} }

View File

@ -35,6 +35,13 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
'tip'=>$L->g('you-can-use-this-field-to-define-a-set-off') 'tip'=>$L->g('you-can-use-this-field-to-define-a-set-off')
)); ));
HTML::formInputText(array(
'name'=>'dateFormat',
'label'=>$L->g('Date format'),
'value'=>$Site->dateFormat(),
'class'=>'uk-width-1-2 uk-form-medium'
));
echo '<div class="uk-form-row"> echo '<div class="uk-form-row">
<div class="uk-form-controls"> <div class="uk-form-controls">
<button type="submit" class="uk-button uk-button-primary">'.$L->g('Save').'</button> <button type="submit" class="uk-button uk-button-primary">'.$L->g('Save').'</button>

View File

@ -58,6 +58,15 @@ class dbJSON
return count($this->db); return count($this->db);
} }
public function getField($field)
{
if(isset($this->db[$field])) {
return $this->db[$field];
}
return $this->dbFields[$field]['value'];
}
// Save the JSON file. // Save the JSON file.
public function save() public function save()
{ {

View File

@ -75,7 +75,7 @@ define('CLI_STATUS', 'published');
// Database format date // Database format date
define('DB_DATE_FORMAT', 'Y-m-d H:i'); define('DB_DATE_FORMAT', 'Y-m-d H:i');
// Database format date // Date format for Dashboard schedule posts
define('SCHEDULED_DATE_FORMAT', 'd M - h:i a'); define('SCHEDULED_DATE_FORMAT', 'd M - h:i a');
// Token time to live for login via email. The offset is defined by http://php.net/manual/en/datetime.modify.php // Token time to live for login via email. The offset is defined by http://php.net/manual/en/datetime.modify.php
@ -128,6 +128,7 @@ include(PATH_HELPERS.'email.class.php');
include(PATH_HELPERS.'filesystem.class.php'); include(PATH_HELPERS.'filesystem.class.php');
include(PATH_HELPERS.'alert.class.php'); include(PATH_HELPERS.'alert.class.php');
include(PATH_HELPERS.'paginator.class.php'); include(PATH_HELPERS.'paginator.class.php');
include(PATH_HELPERS.'image.class.php');
// Session // Session
Session::start(); Session::start();

View File

@ -68,6 +68,13 @@ function buildPost($key)
$Post->setField('breakContent', $explode[0], true); $Post->setField('breakContent', $explode[0], true);
$Post->setField('readMore', !empty($explode[1]), true); $Post->setField('readMore', !empty($explode[1]), true);
// Date format
$postDate = $Post->date();
$Post->setField('dateRaw', $postDate, true);
$postDateFormated = $Post->dateRaw( $Site->dateFormat() );
$Post->setField('date', $postDateFormated, true);
// Parse username for the post. // Parse username for the post.
if( $dbUsers->userExists( $Post->username() ) ) if( $dbUsers->userExists( $Post->username() ) )
{ {

View File

@ -2,7 +2,7 @@
class dbSite extends dbJSON class dbSite extends dbJSON
{ {
private $dbFields = array( public $dbFields = array(
'title'=> array('inFile'=>false, 'value'=>'I am Guybrush Threepwood, mighty developer'), 'title'=> array('inFile'=>false, 'value'=>'I am Guybrush Threepwood, mighty developer'),
'slogan'=> array('inFile'=>false, 'value'=>''), 'slogan'=> array('inFile'=>false, 'value'=>''),
'description'=> array('inFile'=>false, 'value'=>''), 'description'=> array('inFile'=>false, 'value'=>''),
@ -19,7 +19,9 @@ class dbSite extends dbJSON
'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'), 'uriTag'=> array('inFile'=>false, 'value'=>'/tag/'),
'url'=> array('inFile'=>false, 'value'=>''), 'url'=> array('inFile'=>false, 'value'=>''),
'cliMode'=> array('inFile'=>false, 'value'=>true), 'cliMode'=> array('inFile'=>false, 'value'=>true),
'emailFrom'=> array('inFile'=>false, 'value'=>'') 'emailFrom'=> array('inFile'=>false, 'value'=>''),
'dateFormat'=> array('inFile'=>false, 'value'=>'F j, Y'),
'timeFormat'=> array('inFile'=>false, 'value'=>'g:i a')
); );
function __construct() function __construct()
@ -61,9 +63,9 @@ class dbSite extends dbJSON
public function uriFilters($filter='') public function uriFilters($filter='')
{ {
$filters['admin'] = '/admin/'; $filters['admin'] = '/admin/';
$filters['post'] = $this->db['uriPost']; $filters['post'] = $this->getField('uriPost');
$filters['page'] = $this->db['uriPage']; $filters['page'] = $this->getField('uriPage');
$filters['tag'] = $this->db['uriTag']; $filters['tag'] = $this->getField('uriTag');
if(empty($filter)) { if(empty($filter)) {
return $filters; return $filters;
@ -74,70 +76,83 @@ class dbSite extends dbJSON
public function urlPost() public function urlPost()
{ {
return $this->url().ltrim($this->db['uriPost'], '/'); $filter = $this->getField('uriPost');
return $this->url().ltrim($filter, '/');
} }
public function urlPage() public function urlPage()
{ {
return $this->url().ltrim($this->db['uriPage'], '/'); $filter = $this->getField('uriPage');
return $this->url().ltrim($filter, '/');
} }
public function urlTag() public function urlTag()
{ {
return $this->url().ltrim($this->db['uriTag'], '/'); $filter = $this->getField('uriTag');
return $this->url().ltrim($filter, '/');
} }
// Returns the site title. // Returns the site title.
public function title() public function title()
{ {
return $this->db['title']; return $this->getField('title');
} }
public function emailFrom() public function emailFrom()
{ {
return $this->db['emailFrom']; return $this->getField('emailFrom');
}
public function dateFormat()
{
return $this->getField('dateFormat');
}
public function timeFormat()
{
return $this->getField('timeFormat');
} }
// Returns the site slogan. // Returns the site slogan.
public function slogan() public function slogan()
{ {
return $this->db['slogan']; return $this->getField('slogan');
} }
// Returns the site description. // Returns the site description.
public function description() public function description()
{ {
return $this->db['description']; return $this->getField('description');
} }
// Returns the site theme name. // Returns the site theme name.
public function theme() public function theme()
{ {
return $this->db['theme']; return $this->getField('theme');
} }
// Returns the admin theme name. // Returns the admin theme name.
public function adminTheme() public function adminTheme()
{ {
return $this->db['adminTheme']; return $this->getField('adminTheme');
} }
// Returns the footer text. // Returns the footer text.
public function footer() public function footer()
{ {
return $this->db['footer']; return $this->getField('footer');
} }
// Returns the url site. // Returns the url site.
public function url() public function url()
{ {
return $this->db['url']; return $this->getField('url');
} }
// Returns TRUE if the cli mode is enabled, otherwise FALSE. // Returns TRUE if the cli mode is enabled, otherwise FALSE.
public function cliMode() public function cliMode()
{ {
return $this->db['cliMode']; return $this->getField('cliMode');
} }
// Returns the relative home link // Returns the relative home link
@ -149,25 +164,25 @@ class dbSite extends dbJSON
// Returns the timezone. // Returns the timezone.
public function timezone() public function timezone()
{ {
return $this->db['timezone']; return $this->getField('timezone');
} }
// Returns posts per page. // Returns posts per page.
public function postsPerPage() public function postsPerPage()
{ {
return $this->db['postsperpage']; return $this->getField('postsperpage');
} }
// Returns the current language. // Returns the current language.
public function language() public function language()
{ {
return $this->db['language']; return $this->getField('language');
} }
// Returns the current locale. // Returns the current locale.
public function locale() public function locale()
{ {
return $this->db['locale']; return $this->getField('locale');
} }
// Returns the current language in short format. // Returns the current language in short format.
@ -183,7 +198,7 @@ class dbSite extends dbJSON
// Returns the current homepage. // Returns the current homepage.
public function homepage() public function homepage()
{ {
return $this->db['homepage']; return $this->getField('homepage');
} }
// Set the locale. // Set the locale.

View File

@ -0,0 +1,232 @@
<?php defined('BLUDIT') or die('Bludit CMS.');
class Image {
private $image;
private $width;
private $height;
private $imageResized;
public function setImage($fileName, $newWidth, $newHeight, $option="auto")
{
// *** Open up the file
$this->image = $this->openImage($fileName);
// *** Get width and height
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
$this->resizeImage($newWidth, $newHeight, $option);
}
public function saveImage($savePath, $imageQuality="100", $force_jpg=false)
{
$extension = strtolower(pathinfo($savePath, PATHINFO_EXTENSION));
// Remove the extension
$filename = substr($savePath, 0,strrpos($savePath,'.'));
$path_complete = $filename.'.'.$extension;
if($force_jpg)
{
imagejpeg($this->imageResized, $filename.'.jpg', $imageQuality);
}
else
{
switch($extension)
{
case 'jpg':
case 'jpeg':
if (imagetypes() & IMG_JPG) {
imagejpeg($this->imageResized, $path_complete, $imageQuality);
}
break;
case 'gif':
if (imagetypes() & IMG_GIF) {
imagegif($this->imageResized, $path_complete);
}
break;
case 'png':
// *** Scale quality from 0-100 to 0-9
$scaleQuality = round(($imageQuality/100) * 9);
// *** Invert quality setting as 0 is best, not 9
$invertScaleQuality = 9 - $scaleQuality;
if (imagetypes() & IMG_PNG) {
imagepng($this->imageResized, $path_complete, $invertScaleQuality);
}
break;
default:
// *** No extension - No save.
break;
}
}
imagedestroy($this->imageResized);
}
private function openImage($file)
{
// *** Get extension
$extension = strtolower(strrchr($file, '.'));
switch($extension)
{
case '.jpg':
case '.jpeg':
$img = imagecreatefromjpeg($file);
break;
case '.gif':
$img = imagecreatefromgif($file);
break;
case '.png':
$img = imagecreatefrompng($file);
break;
default:
$img = false;
break;
}
return $img;
}
private function resizeImage($newWidth, $newHeight, $option)
{
// *** Get optimal width and height - based on $option
$optionArray = $this->getDimensions($newWidth, $newHeight, $option);
$optimalWidth = $optionArray['optimalWidth'];
$optimalHeight = $optionArray['optimalHeight'];
// *** Resample - create image canvas of x, y size
$this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);
// *** if option is 'crop', then crop too
if ($option == 'crop') {
$this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight);
}
}
private function getDimensions($newWidth, $newHeight, $option)
{
if( ($this->width < $newWidth) and ($this->height < $newHeight) )
{
return array('optimalWidth' => $this->width, 'optimalHeight' => $this->height);
}
switch ($option)
{
case 'exact':
$optimalWidth = $newWidth;
$optimalHeight= $newHeight;
break;
case 'portrait':
$optimalWidth = $this->getSizeByFixedHeight($newHeight);
$optimalHeight= $newHeight;
break;
case 'landscape':
$optimalWidth = $newWidth;
$optimalHeight= $this->getSizeByFixedWidth($newWidth);
break;
case 'auto':
$optionArray = $this->getSizeByAuto($newWidth, $newHeight);
$optimalWidth = $optionArray['optimalWidth'];
$optimalHeight = $optionArray['optimalHeight'];
break;
case 'crop':
$optionArray = $this->getOptimalCrop($newWidth, $newHeight);
$optimalWidth = $optionArray['optimalWidth'];
$optimalHeight = $optionArray['optimalHeight'];
break;
}
return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
}
private function getSizeByFixedHeight($newHeight)
{
$ratio = $this->width / $this->height;
$newWidth = $newHeight * $ratio;
return $newWidth;
}
private function getSizeByFixedWidth($newWidth)
{
$ratio = $this->height / $this->width;
$newHeight = $newWidth * $ratio;
return $newHeight;
}
private function getSizeByAuto($newWidth, $newHeight)
{
if ($this->height < $this->width)
// *** Image to be resized is wider (landscape)
{
$optimalWidth = $newWidth;
$optimalHeight= $this->getSizeByFixedWidth($newWidth);
}
elseif ($this->height > $this->width)
// *** Image to be resized is taller (portrait)
{
$optimalWidth = $this->getSizeByFixedHeight($newHeight);
$optimalHeight= $newHeight;
}
else
// *** Image to be resizerd is a square
{
if ($newHeight < $newWidth) {
$optimalWidth = $newWidth;
$optimalHeight= $this->getSizeByFixedWidth($newWidth);
} else if ($newHeight > $newWidth) {
$optimalWidth = $this->getSizeByFixedHeight($newHeight);
$optimalHeight= $newHeight;
} else {
// *** Sqaure being resized to a square
$optimalWidth = $newWidth;
$optimalHeight= $newHeight;
}
}
return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
}
private function getOptimalCrop($newWidth, $newHeight)
{
$heightRatio = $this->height / $newHeight;
$widthRatio = $this->width / $newWidth;
if ($heightRatio < $widthRatio) {
$optimalRatio = $heightRatio;
} else {
$optimalRatio = $widthRatio;
}
$optimalHeight = $this->height / $optimalRatio;
$optimalWidth = $this->width / $optimalRatio;
return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
}
private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight)
{
// *** Find center - this will be used for the crop
$cropStartX = ( $optimalWidth / 2) - ( $newWidth /2 );
$cropStartY = ( $optimalHeight/ 2) - ( $newHeight/2 );
$crop = $this->imageResized;
//imagedestroy($this->imageResized);
// *** Now crop from center to exact requested size
$this->imageResized = imagecreatetruecolor($newWidth , $newHeight);
imagecopyresampled($this->imageResized, $crop , 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight , $newWidth, $newHeight);
}
}

View File

@ -101,7 +101,13 @@ class Post extends fileContent
// Returns the post date according to locale settings and format settings. // Returns the post date according to locale settings and format settings.
public function date($format=false) public function date($format=false)
{ {
$date = $this->getField('date'); return $this->getField('date');
}
// Returns the post date according to locale settings and format as database stored.
public function dateRaw($format=false)
{
$date = $this->getField('dateRaw');
if($format) { if($format) {
return Date::format($date, DB_DATE_FORMAT, $format); return Date::format($date, DB_DATE_FORMAT, $format);

View File

@ -204,5 +204,7 @@
"upload-image": "Upload image", "upload-image": "Upload image",
"drag-and-drop-or-click-here": "Drag and drop or click here", "drag-and-drop-or-click-here": "Drag and drop or click here",
"insert-image": "Insert image", "insert-image": "Insert image",
"supported-image-file-types": "Supported image file types" "supported-image-file-types": "Supported image file types",
"date-format": "Date format",
"time-format": "Time format"
} }

View File

@ -53,6 +53,9 @@ class pluginPages extends Plugin {
$parents = $pagesParents[NO_PARENT_CHAR]; $parents = $pagesParents[NO_PARENT_CHAR];
foreach($parents as $parent) foreach($parents as $parent)
{
// Check if the parent is published
if( $parent->published() )
{ {
// Print the parent // Print the parent
$html .= '<li>'; $html .= '<li>';
@ -64,16 +67,21 @@ class pluginPages extends Plugin {
$children = $pagesParents[$parent->key()]; $children = $pagesParents[$parent->key()];
// Print children // Print children
$html .= '<ul>'; $html .= '<ul class="children">';
foreach($children as $child) foreach($children as $child)
{ {
$html .= '<li>'; // Check if the child is published
$html .= '<a class="children '.( ($child->key()==$Url->slug())?' active':'').'" href="'.$child->permalink().'">'.$child->title().'</a>'; if( $child->published() )
{
$html .= '<li class="child">';
$html .= '<a class="'.( ($child->key()==$Url->slug())?' active':'').'" href="'.$child->permalink().'">'.$child->title().'</a>';
$html .= '</li>'; $html .= '</li>';
} }
}
$html .= '</ul>'; $html .= '</ul>';
} }
} }
}
$html .= '</li></ul>'; $html .= '</li></ul>';
$html .= '</div>'; $html .= '</div>';

View File

@ -2,11 +2,6 @@
"theme-data": "theme-data":
{ {
"name": "Pure", "name": "Pure",
"description": "Einfaches und übersichtliches Theme unter Verwendung des Frameworks Pure.css. Website: http://purecss.io.", "description": "Einfaches und übersichtliches Theme unter Verwendung des Frameworks Pure.css."
"author": "Bludit",
"email": "",
"website": "https://github.com/dignajar/bludit-themes",
"version": "0.3",
"releaseDate": "2015-10-02"
} }
} }

View File

@ -2,11 +2,11 @@
"theme-data": "theme-data":
{ {
"name": "Pure", "name": "Pure",
"description": "Simple and clean theme, based on the framework Pure.css. Website: http://purecss.io", "description": "Simple and clean theme, based on the framework Pure.css.",
"author": "Bludit", "author": "Bludit",
"email": "", "email": "",
"website": "https://github.com/dignajar/bludit-themes", "website": "https://github.com/dignajar/bludit-themes",
"version": "0.3", "version": "0.6",
"releaseDate": "2015-10-02" "releaseDate": "2015-11-13"
} }
} }