Bug fixes, developer area, google plugin updated, rss and sitemap updated
This commit is contained in:
parent
19d6ab347b
commit
1f5dd3ac99
@ -11,6 +11,8 @@
|
||||
}
|
||||
|
||||
.label-draft,
|
||||
.label-fixed,
|
||||
.label-sticky,
|
||||
.label-empty-title,
|
||||
.label-time {
|
||||
background: #A979D1 none repeat scroll 0 0;
|
||||
@ -24,6 +26,10 @@
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
.label-fixed {
|
||||
background: #7BD179;
|
||||
}
|
||||
|
||||
.label-empty-title {
|
||||
background: #53D192;
|
||||
}
|
||||
|
@ -133,8 +133,13 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
|
||||
'name'=>'status',
|
||||
'label'=>$L->g('Status'),
|
||||
'class'=>'uk-width-1-1 uk-form-medium',
|
||||
'options'=>array('published'=>$L->g('Published'), 'draft'=>$L->g('Draft')),
|
||||
'selected'=>($page->draft()?'draft':'published'),
|
||||
'options'=>array(
|
||||
'published'=>$L->g('Published'),
|
||||
'draft'=>$L->g('Draft'),
|
||||
'fixed'=>$L->g('Fixed'),
|
||||
'sticky'=>$L->g('Sticky')
|
||||
),
|
||||
'selected'=>$page->status(),
|
||||
'tip'=>''
|
||||
));
|
||||
|
||||
|
@ -118,7 +118,12 @@ echo '<div class="bl-publish-sidebar uk-width-2-10">';
|
||||
'name'=>'status',
|
||||
'label'=>$L->g('Status'),
|
||||
'class'=>'uk-width-1-1 uk-form-medium',
|
||||
'options'=>array('published'=>$L->g('Published'), 'draft'=>$L->g('Draft')),
|
||||
'options'=>array(
|
||||
'published'=>$L->g('Published'),
|
||||
'draft'=>$L->g('Draft'),
|
||||
'fixed'=>$L->g('Fixed'),
|
||||
'sticky'=>$L->g('Sticky')
|
||||
),
|
||||
'selected'=>'published',
|
||||
'tip'=>''
|
||||
));
|
||||
|
@ -22,14 +22,11 @@ echo '
|
||||
|
||||
foreach($pages as $page) {
|
||||
$status = false;
|
||||
if($page->scheduled()) {
|
||||
$status = $Language->g('Scheduled');
|
||||
}
|
||||
elseif(!$page->published()) {
|
||||
$status = $Language->g('Draft');
|
||||
if($page->status()!='published') {
|
||||
$status = $Language->g( $page->status() );
|
||||
}
|
||||
echo '<tr>';
|
||||
echo '<td><a href="'.HTML_PATH_ADMIN_ROOT.'edit-page/'.$page->key().'">'.($status?'<span class="label-draft">'.$status.'</span>':'').($page->title()?$page->title():'<span class="label-empty-title">'.$Language->g('Empty title').'</span> ').'</a></td>';
|
||||
echo '<td><a href="'.HTML_PATH_ADMIN_ROOT.'edit-page/'.$page->key().'">'.($status?'<span class="label-'.$page->status().'">'.$status.'</span>':'').($page->title()?$page->title():'<span class="label-empty-title">'.$Language->g('Empty title').'</span> ').'</a></td>';
|
||||
|
||||
echo '<td class="uk-text-center">'.( (ORDER_BY=='date') ? $page->dateRaw() : $page->position() ).'</td>';
|
||||
|
||||
|
@ -268,6 +268,18 @@ class dbPages extends dbJSON
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// (array) Returns a database with the fixed pages
|
||||
public function getFixedDB()
|
||||
{
|
||||
$tmp = $this->db;
|
||||
foreach($tmp as $key=>$fields) {
|
||||
if($fields['status']!='fixed') {
|
||||
unset($tmp[$key]);
|
||||
}
|
||||
}
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
// Returns a database with drafts pages
|
||||
public function getDraftDB()
|
||||
{
|
||||
|
@ -13,6 +13,8 @@ class dbUsers extends dbJSON
|
||||
'registered'=> array('inFile'=>false, 'value'=>'1985-03-15 10:00'),
|
||||
'tokenEmail'=> array('inFile'=>false, 'value'=>''),
|
||||
'tokenEmailTTL'=> array('inFile'=>false, 'value'=>'2009-03-15 14:00'),
|
||||
'tokenAuth'=> array('inFile'=>false, 'value'=>''),
|
||||
'tokenAuthTTL'=> array('inFile'=>false, 'value'=>'2009-03-15 14:00'),
|
||||
'twitter'=> array('inFile'=>false, 'value'=>''),
|
||||
'facebook'=> array('inFile'=>false, 'value'=>''),
|
||||
'googlePlus'=> array('inFile'=>false, 'value'=>''),
|
||||
@ -72,6 +74,17 @@ class dbUsers extends dbJSON
|
||||
return false;
|
||||
}
|
||||
|
||||
// Returns the username with the authentication token assigned, FALSE otherwise
|
||||
public function getByAuthToken($token)
|
||||
{
|
||||
foreach($this->db as $username=>$fields) {
|
||||
if($fields['tokenAuth']==$token) {
|
||||
return $username;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Return TRUE if the user exists, FALSE otherwise.
|
||||
public function userExists($username)
|
||||
{
|
||||
|
@ -353,6 +353,22 @@ class Page {
|
||||
return ($this->getValue('status')=='draft');
|
||||
}
|
||||
|
||||
public function sticky()
|
||||
{
|
||||
return ($this->getValue('status')=='sticky');
|
||||
}
|
||||
|
||||
public function fixed()
|
||||
{
|
||||
return ($this->getValue('status')=='fixed');
|
||||
}
|
||||
|
||||
// (string) Returns status of the page
|
||||
public function status()
|
||||
{
|
||||
return $this->getValue('status');
|
||||
}
|
||||
|
||||
// Returns the title field
|
||||
public function title()
|
||||
{
|
||||
|
@ -4,14 +4,12 @@ class pluginAPI extends Plugin {
|
||||
|
||||
public function init()
|
||||
{
|
||||
global $Security;
|
||||
|
||||
// This key is used for request such as get the list of all posts and pages
|
||||
$token = md5($Security->key1().time().DOMAIN);
|
||||
// Generate the API Token
|
||||
$token = md5( uniqid().time().DOMAIN );
|
||||
|
||||
$this->dbFields = array(
|
||||
'ping'=>0, // 0 = false, 1 = true
|
||||
'token'=>$token, // Private key
|
||||
'token'=>$token, // API Token
|
||||
'showAllAmount'=>15, // Amount of posts and pages for return
|
||||
'authentication'=>1 // Authentication required
|
||||
);
|
||||
@ -56,9 +54,11 @@ class pluginAPI extends Plugin {
|
||||
public function beforeRulesLoad()
|
||||
{
|
||||
global $Url;
|
||||
global $dbPosts;
|
||||
global $dbPages;
|
||||
global $dbUsers;
|
||||
|
||||
// CHECK URL
|
||||
// ------------------------------------------------------------
|
||||
// Check if the URI start with /api/
|
||||
$startString = HTML_PATH_ROOT.'api/';
|
||||
$URI = $Url->uri();
|
||||
@ -70,72 +70,46 @@ class pluginAPI extends Plugin {
|
||||
// Remove the first part of the URI
|
||||
$URI = mb_substr($URI, $length);
|
||||
|
||||
// METHODS
|
||||
// ------------------------------------------------------------
|
||||
// GET
|
||||
// POST
|
||||
// PUT
|
||||
// DELETE
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
// INPUTS
|
||||
// ------------------------------------------------------------
|
||||
// token | authentication token
|
||||
|
||||
$inputs = json_decode(file_get_contents('php://input'),true);
|
||||
|
||||
if( empty($inputs) ) {
|
||||
// Default variables for $input
|
||||
$inputs = array(
|
||||
'token'=>''
|
||||
);
|
||||
}
|
||||
else {
|
||||
// Sanitize inputs
|
||||
foreach( $inputs as $key=>$value ) {
|
||||
if(empty($value)) {
|
||||
$this->response(array(
|
||||
'status'=>'1',
|
||||
'message'=>'Invalid input.'
|
||||
));
|
||||
} else {
|
||||
$inputs[$key] = Sanitize::html($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
$inputs = $this->getInputs();
|
||||
|
||||
// PARAMETERS
|
||||
// ------------------------------------------------------------
|
||||
// /api/posts | GET | returns all posts
|
||||
// /api/posts/{key} | GET | returns the post with the {key}
|
||||
// /api/pages | GET | returns all pages
|
||||
// /api/pages/{key} | GET | returns the page with the {key}
|
||||
// /api/cli/regenerate | POST | check for new posts and pages
|
||||
$parameters = $this->getParameters($URI);
|
||||
|
||||
$parameters = explode('/', $URI);
|
||||
// API TOKEN
|
||||
// ------------------------------------------------------------
|
||||
$tokenAPI = $this->getValue('token');
|
||||
|
||||
// Sanitize parameters
|
||||
foreach( $parameters as $key=>$value ) {
|
||||
if(empty($value)) {
|
||||
$this->response(array(
|
||||
'status'=>'1',
|
||||
'message'=>'Invalid parameter.'
|
||||
));
|
||||
} else {
|
||||
$parameters[$key] = Sanitize::html($value);
|
||||
// Check empty token
|
||||
if( empty($inputs['token']) ) {
|
||||
$this->response(array(
|
||||
'status'=>'1',
|
||||
'message'=>'Missing API token.'
|
||||
));
|
||||
}
|
||||
|
||||
// Check the token is valid
|
||||
if( $inputs['token']!=$tokenAPI ) {
|
||||
$this->response(array(
|
||||
'status'=>'1',
|
||||
'message'=>'Invalid API token.'
|
||||
));
|
||||
}
|
||||
|
||||
// AUTHENTICATION TOKEN
|
||||
// ------------------------------------------------------------
|
||||
$writePermissions = false;
|
||||
if( !empty($inputs['authentication']) ) {
|
||||
// Get the user with the authentication token
|
||||
$username = $dbUsers->getByAuthToken($inputs['authentication']);
|
||||
if( $username!==false ) {
|
||||
// Enable write permissions
|
||||
$writePermissions = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check authentication
|
||||
if( $this->getDbField('authentication')==1 ) {
|
||||
if( $inputs['token']!=$this->getDbField('token') ) {
|
||||
$this->response(array(
|
||||
'status'=>'1',
|
||||
'message'=>'Invalid token.'
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// /api/posts
|
||||
if( ($method==='GET') && ($parameters[0]==='posts') && empty($parameters[1]) ) {
|
||||
@ -175,13 +149,68 @@ class pluginAPI extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
// FUNCTIONS
|
||||
// PRIVATE METHODS
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
private function getParameters($URI)
|
||||
{
|
||||
// PARAMETERS
|
||||
// ------------------------------------------------------------
|
||||
// /api/pages | GET | returns all pages
|
||||
// /api/pages/{key} | GET | returns the page with the {key}
|
||||
// /api/cli/regenerate | POST | check for new posts and pages
|
||||
|
||||
$parameters = explode('/', $URI);
|
||||
|
||||
// Sanitize parameters
|
||||
foreach($parameters as $key=>$value) {
|
||||
$parameters[$key] = Sanitize::html($value);
|
||||
}
|
||||
|
||||
return $parameters;
|
||||
}
|
||||
|
||||
private function getInputs()
|
||||
{
|
||||
// METHODS
|
||||
// ------------------------------------------------------------
|
||||
// GET
|
||||
// POST
|
||||
// PUT
|
||||
// DELETE
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
switch($method) {
|
||||
case "POST":
|
||||
$inputs = $_POST;
|
||||
break;
|
||||
case "GET":
|
||||
case "DELETE":
|
||||
$inputs = $_GET;
|
||||
break;
|
||||
case "PUT":
|
||||
$inputs = file_get_contents("php://input");
|
||||
break;
|
||||
default:
|
||||
$inputs = json_encode(array());
|
||||
break;
|
||||
}
|
||||
|
||||
// Input data need to be JSON
|
||||
$inputs = json_decode(file_get_contents('php://input'),true);
|
||||
|
||||
// Sanitize inputs
|
||||
foreach($inputs as $key=>$value) {
|
||||
$inputs[$key] = Sanitize::html($value);
|
||||
}
|
||||
|
||||
return $inputs;
|
||||
}
|
||||
|
||||
private function response($data=array())
|
||||
{
|
||||
$json = json_encode($data);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
exit($json);
|
||||
}
|
||||
|
@ -1,7 +1,11 @@
|
||||
{
|
||||
"plugin-data":
|
||||
{
|
||||
"name": "Fixed Pages",
|
||||
"description": "Show a list of links."
|
||||
}
|
||||
"name": "Fixed pages",
|
||||
"description": "Shows a list of pages, you can define the amount of items and the order depends of settings."
|
||||
},
|
||||
|
||||
"home-page": "Home page",
|
||||
"show-home-link": "Show home link",
|
||||
"amount-of-items": "Amount of items"
|
||||
}
|
||||
|
@ -4,140 +4,33 @@ class pluginFixedPages extends Plugin {
|
||||
|
||||
public function init()
|
||||
{
|
||||
// JSON database
|
||||
$jsondb = json_encode(array(
|
||||
'about'=>'About'
|
||||
));
|
||||
|
||||
// Fields and default values for the database of this plugin
|
||||
$this->dbFields = array(
|
||||
'label'=>'Fixed Pages',
|
||||
'jsondb'=>$jsondb
|
||||
'homeLink'=>true
|
||||
);
|
||||
|
||||
// Disable default Save and Cancel button
|
||||
$this->formButtons = false;
|
||||
}
|
||||
|
||||
// Method called when a POST request is sent
|
||||
public function post()
|
||||
{
|
||||
global $dbPages;
|
||||
|
||||
// Get current jsondb value from database
|
||||
// All data stored in the database is html encoded
|
||||
$jsondb = $this->db['jsondb'];
|
||||
$jsondb = Sanitize::htmlDecode($jsondb);
|
||||
|
||||
// Convert JSON to Array
|
||||
$pagesFixed = json_decode($jsondb, true);
|
||||
|
||||
// Check if the user click on the button delete or add
|
||||
if( isset($_POST['delete']) ) {
|
||||
// Values from $_POST
|
||||
$pageKey = $_POST['delete'];
|
||||
|
||||
// Change the status of the page from fixed to published
|
||||
$dbPages->setStatus($pageKey, 'published');
|
||||
|
||||
// Delete the link from the array
|
||||
unset($pagesFixed[$pageKey]);
|
||||
}
|
||||
elseif( isset($_POST['add']) ) {
|
||||
// Values from $_POST
|
||||
$pageTitle = $_POST['newPageTitle'];
|
||||
$pageKey = $_POST['newPageKey'];
|
||||
|
||||
// Change the status of the page from fixed to published
|
||||
$dbPages->setStatus($pageKey, 'fixed');
|
||||
|
||||
// Add the link
|
||||
$pagesFixed[$pageKey] = $pageTitle;
|
||||
}
|
||||
|
||||
// Encode html to store the values on the database
|
||||
$this->db['label'] = Sanitize::html($_POST['label']);
|
||||
$this->db['jsondb'] = Sanitize::html(json_encode($pagesFixed));
|
||||
|
||||
// Save the database
|
||||
return $this->save();
|
||||
}
|
||||
|
||||
// Method called on plugin settings on the admin area
|
||||
// Method called on the settings of the plugin on the admin area
|
||||
public function form()
|
||||
{
|
||||
global $Language;
|
||||
global $dbPages;
|
||||
|
||||
$options = array();
|
||||
foreach($dbPages->db as $key=>$fields) {
|
||||
$page = buildPage($key);
|
||||
if($page->published()) {
|
||||
$options[$key] = $page->title();
|
||||
}
|
||||
}
|
||||
|
||||
$html = '<div>';
|
||||
$html .= '<label>'.$Language->get('Label').'</label>';
|
||||
$html .= '<input name="label" type="text" value="'.$this->getValue('label').'">';
|
||||
$html .= '<input id="jslabel" name="label" type="text" value="'.$this->getValue('label').'">';
|
||||
$html .= '<span class="tip">'.$Language->get('Title of the plugin for the sidebar').'</span>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<button name="save" class="blue" type="submit">Save</button>';
|
||||
$html .= '</div>';
|
||||
|
||||
// NEW PAGE
|
||||
$html .= '<legend>'.$Language->get('New fixed page').'</legend>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<label>'.$Language->get('Title').'</label>';
|
||||
$html .= '<input name="newPageTitle" type="text" value="">';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<label>'.$Language->get('Page').'</label>';
|
||||
$html .= '<select name="newPageKey">';
|
||||
foreach($options as $key=>$title) {
|
||||
$html .= '<option value="'.$key.'">'.$title.'</option>';
|
||||
}
|
||||
$html .= '<label>'.$Language->get('Home link').'</label>';
|
||||
$html .= '<select name="homeLink">';
|
||||
$html .= '<option value="true" '.($this->getValue('showCero')?'checked':'').'>Enabled</option>';
|
||||
$html .= '<option value="false" '.($this->getValue('showCero')?'checked':'').'>Disabled</option>';
|
||||
$html .= '</select>';
|
||||
$html .= '<span class="tip">'.$Language->get('Show the home link on the sidebar').'</span>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<button name="add" class="blue" type="submit">Add</button>';
|
||||
$html .= '</div>';
|
||||
|
||||
// LIST OF PAGES
|
||||
$html .= '<legend>'.$Language->get('Fixed pages').'</legend>';
|
||||
|
||||
$jsondb = $this->getValue('jsondb', $unsanitized=false);
|
||||
$pagesFixed = json_decode($jsondb, true);
|
||||
foreach($pagesFixed as $pageKey=>$pageTitle) {
|
||||
$html .= '<div>';
|
||||
$html .= '<label>'.$Language->get('Title').'</label>';
|
||||
$html .= '<input type="text" value="'.$pageTitle.'" disabled>';
|
||||
$html .= '</div>';
|
||||
|
||||
$page = buildPage($pageKey);
|
||||
if($page) {
|
||||
$title = $page->title();
|
||||
} else {
|
||||
$title = $Language->get('Error page deleted');
|
||||
}
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<label>'.$Language->get('Page linked').'</label>';
|
||||
$html .= '<input type="text" value="'.$title.'" disabled>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<button name="delete" type="submit" value="'.$pageKey.'">Delete</button>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '</br>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
@ -145,6 +38,11 @@ class pluginFixedPages extends Plugin {
|
||||
public function siteSidebar()
|
||||
{
|
||||
global $Language;
|
||||
global $Url;
|
||||
global $Site;
|
||||
global $dbPages;
|
||||
|
||||
$pages = $dbPages->getFixedDB();
|
||||
|
||||
// HTML for sidebar
|
||||
$html = '<div class="plugin plugin-pages">';
|
||||
@ -152,15 +50,23 @@ class pluginFixedPages extends Plugin {
|
||||
$html .= '<div class="plugin-content">';
|
||||
$html .= '<ul>';
|
||||
|
||||
// Get the JSON DB, getValue() with the option unsanitized HTML code
|
||||
$jsondb = $this->getValue('jsondb', false);
|
||||
$pagesFixed = json_decode($jsondb);
|
||||
|
||||
// By default the database of categories are alphanumeric sorted
|
||||
foreach($pagesFixed as $key=>$title) {
|
||||
// Show Home page link
|
||||
if( $this->getValue('homeLink') ) {
|
||||
$html .= '<li>';
|
||||
$html .= '<a href="'.DOMAIN_PAGES.$key.'">';
|
||||
$html .= $title;
|
||||
$html .= '<a href="'.$Site->url().'">';
|
||||
$html .= $Language->get('Home page');
|
||||
$html .= '</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
|
||||
// Get keys of pages
|
||||
$keys = array_keys($pages);
|
||||
foreach($keys as $pageKey) {
|
||||
// Create the page object from the page key
|
||||
$page = buildPage($pageKey);
|
||||
$html .= '<li>';
|
||||
$html .= '<a href="'.$page->permalink().'">';
|
||||
$html .= $page->title();
|
||||
$html .= '</a>';
|
||||
$html .= '</li>';
|
||||
}
|
||||
|
@ -41,8 +41,7 @@ class pluginOpenGraph extends Plugin {
|
||||
'siteName' =>$Site->title()
|
||||
);
|
||||
|
||||
switch($WHERE_AM_I)
|
||||
{
|
||||
switch($WHERE_AM_I) {
|
||||
// The user filter by page
|
||||
case 'page':
|
||||
$og['type'] = 'article';
|
||||
@ -56,6 +55,7 @@ class pluginOpenGraph extends Plugin {
|
||||
|
||||
// The user is in the homepage
|
||||
default:
|
||||
$content = '';
|
||||
// The image it's from the first page
|
||||
if(isset($pages[0]) ) {
|
||||
$og['image'] = $pages[0]->coverImage($absolute=true);
|
||||
|
Loading…
Reference in New Issue
Block a user