Merge 9647beb1e1d118f21c76a531587c1255e792ca00 into 3ff2ac0d53a999e824ed2da50e9dc1a4c8ee686b
This commit is contained in:
commit
88831b9db6
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,5 +0,0 @@
|
|||||||
.DS_Store
|
|
||||||
bl-content/databases
|
|
||||||
bl-content/pages
|
|
||||||
bl-content/posts
|
|
||||||
bl-content/uploads
|
|
@ -102,6 +102,32 @@ class HTML {
|
|||||||
$args['type'] = 'password';
|
$args['type'] = 'password';
|
||||||
self::formInputText($args);
|
self::formInputText($args);
|
||||||
}
|
}
|
||||||
|
public static function formCheckbox($args)
|
||||||
|
{
|
||||||
|
$id = 'js'.$args['name'];
|
||||||
|
$class = empty($args['class']) ? '' : 'class="'.$args['class'].'"';
|
||||||
|
$placeholder = empty($args['placeholder']) ? '' : 'placeholder="'.$args['placeholder'].'"';
|
||||||
|
|
||||||
|
$html = '<div class="uk-form-row">';
|
||||||
|
|
||||||
|
if(!empty($args['label'])) {
|
||||||
|
$html .= '<label for="'.$id.'" class="uk-form-label">'.$args['label'].'</label>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= '<div class="uk-form-controls">';
|
||||||
|
// without the hidden field it doesn't send any post value when the checkbox is not checked
|
||||||
|
$html .= "<input type='hidden' value='0' name='".$args['name']."'>";
|
||||||
|
$html .= '<input type="checkbox" id="'.$id.'" name="'.$args['name'].'" '.$class.' '.$placeholder.' value=1 '.($args['checked']?"checked":"").' />';
|
||||||
|
|
||||||
|
if(!empty($args['tip'])) {
|
||||||
|
$html .= '<p class="uk-form-help-block">'.$args['tip'].'</p>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= '</div>';
|
||||||
|
$html .= '</div>';
|
||||||
|
|
||||||
|
echo $html;
|
||||||
|
}
|
||||||
|
|
||||||
public static function formTextarea($args)
|
public static function formTextarea($args)
|
||||||
{
|
{
|
||||||
|
@ -20,6 +20,13 @@ HTML::formOpen(array('class'=>'uk-form-horizontal'));
|
|||||||
'tip'=>$L->g('number-of-posts-to-show-per-page')
|
'tip'=>$L->g('number-of-posts-to-show-per-page')
|
||||||
));
|
));
|
||||||
|
|
||||||
|
HTML::formCheckbox(array(
|
||||||
|
'name'=>'shuffleIdeticalTags',
|
||||||
|
'label'=>$L->g('Shufle posts with identical tags'),
|
||||||
|
'checked'=>$Site->shuffleIdeticalTags(),
|
||||||
|
'class'=>'uk-width-1-3 uk-form-medium',
|
||||||
|
));
|
||||||
|
|
||||||
HTML::formSelect(array(
|
HTML::formSelect(array(
|
||||||
'name'=>'homepage',
|
'name'=>'homepage',
|
||||||
'label'=>$L->g('Default home page'),
|
'label'=>$L->g('Default home page'),
|
||||||
|
@ -51,7 +51,7 @@ if( ($Url->whereAmI()==='post') && ($Url->notFound()===false) )
|
|||||||
// Build posts by specific tag.
|
// Build posts by specific tag.
|
||||||
elseif( ($Url->whereAmI()==='tag') && ($Url->notFound()===false) )
|
elseif( ($Url->whereAmI()==='tag') && ($Url->notFound()===false) )
|
||||||
{
|
{
|
||||||
$posts = buildPostsForPage($Url->pageNumber(), $Site->postsPerPage(), true, $Url->slug());
|
$posts = buildPostsForPage($Url->pageNumber(), $Site->postsPerPage(), true, $Url->slug());
|
||||||
}
|
}
|
||||||
// Build posts for homepage or admin area.
|
// Build posts for homepage or admin area.
|
||||||
else
|
else
|
||||||
|
@ -19,7 +19,7 @@ class dbPosts extends dbJSON
|
|||||||
function __construct()
|
function __construct()
|
||||||
{
|
{
|
||||||
parent::__construct(PATH_DATABASES.'posts.php');
|
parent::__construct(PATH_DATABASES.'posts.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the amount of posts
|
// Return the amount of posts
|
||||||
// $total = TRUE, returns the total of posts
|
// $total = TRUE, returns the total of posts
|
||||||
@ -103,6 +103,7 @@ class dbPosts extends dbJSON
|
|||||||
|
|
||||||
public function add($args)
|
public function add($args)
|
||||||
{
|
{
|
||||||
|
global $Site;
|
||||||
$dataForDb = array(); // This data will be saved in the database
|
$dataForDb = array(); // This data will be saved in the database
|
||||||
$dataForFile = array(); // This data will be saved in the file
|
$dataForFile = array(); // This data will be saved in the file
|
||||||
|
|
||||||
@ -190,6 +191,10 @@ class dbPosts extends dbJSON
|
|||||||
// Sort posts before save
|
// Sort posts before save
|
||||||
$this->sortByDate();
|
$this->sortByDate();
|
||||||
|
|
||||||
|
if($Site->shuffleIdeticalTags()){
|
||||||
|
$this->mixTags();
|
||||||
|
}
|
||||||
|
|
||||||
if( $this->save() === false ) {
|
if( $this->save() === false ) {
|
||||||
|
|
||||||
// Trying to rollback
|
// Trying to rollback
|
||||||
@ -402,7 +407,59 @@ class dbPosts extends dbJSON
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function sortLowToHigh($a, $b) {
|
// Mix the posts so that neighbour posts have different Tags -
|
||||||
|
// helpfull if you want to show diverse content. Case studies for example
|
||||||
|
public function mixTags()
|
||||||
|
{
|
||||||
|
$previousValue = null;
|
||||||
|
$finalArray=array();
|
||||||
|
$buffeArray=array();
|
||||||
|
|
||||||
|
// Get array keys
|
||||||
|
$arrayKeys = array_keys($this->db);
|
||||||
|
// Fetch last array key
|
||||||
|
$lastArrayKey = array_pop($arrayKeys);
|
||||||
|
|
||||||
|
foreach($this->db as $key=>$row){
|
||||||
|
foreach($buffeArray as $bufferKey=>$bufferRow){
|
||||||
|
// Get buffer array keys
|
||||||
|
$finalArrayKeys = array_keys($finalArray);
|
||||||
|
// Fetch last array key
|
||||||
|
$finalArraylastArrayKey = array_pop($finalArrayKeys);
|
||||||
|
|
||||||
|
if($bufferRow['tags']!=$finalArray[$finalArraylastArrayKey]['tags']){
|
||||||
|
$finalArray[$bufferKey]=$bufferRow;
|
||||||
|
unset($buffeArray[$bufferKey]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$finalArrayKeys = array_keys($finalArray);
|
||||||
|
// Fetch last array key
|
||||||
|
$finalArraylastArrayKey = array_pop($finalArrayKeys);
|
||||||
|
|
||||||
|
if(empty($finalArray)){
|
||||||
|
$finalArray[$key]=$row;
|
||||||
|
}
|
||||||
|
elseif($row['tags']==$finalArray[$finalArraylastArrayKey]['tags']){
|
||||||
|
$buffeArray[$key]=$row;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$finalArray[$key]=$row;
|
||||||
|
}
|
||||||
|
|
||||||
|
//reached the end so no other choice but to add the remaining buffer
|
||||||
|
if($key == $lastArrayKey) {
|
||||||
|
$finalArray=array_merge($finalArray,$buffeArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
$previousValue = $row;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db=$finalArray;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sortLowToHigh($a, $b) {
|
||||||
return $a['date']>$b['date'];
|
return $a['date']>$b['date'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ class dbSite extends dbJSON
|
|||||||
'description'=> array('inFile'=>false, 'value'=>''),
|
'description'=> array('inFile'=>false, 'value'=>''),
|
||||||
'footer'=> array('inFile'=>false, 'value'=>'I wanna be a pirate!'),
|
'footer'=> array('inFile'=>false, 'value'=>'I wanna be a pirate!'),
|
||||||
'postsperpage'=> array('inFile'=>false, 'value'=>''),
|
'postsperpage'=> array('inFile'=>false, 'value'=>''),
|
||||||
|
'shuffleIdeticalTags'=> array('inFile'=>false, 'value'=>''),
|
||||||
'language'=> array('inFile'=>false, 'value'=>'en'),
|
'language'=> array('inFile'=>false, 'value'=>'en'),
|
||||||
'locale'=> array('inFile'=>false, 'value'=>'en_US'),
|
'locale'=> array('inFile'=>false, 'value'=>'en_US'),
|
||||||
'timezone'=> array('inFile'=>false, 'value'=>'America/Argentina/Buenos_Aires'),
|
'timezone'=> array('inFile'=>false, 'value'=>'America/Argentina/Buenos_Aires'),
|
||||||
@ -51,13 +52,13 @@ class dbSite extends dbJSON
|
|||||||
{
|
{
|
||||||
foreach($args as $field=>$value)
|
foreach($args as $field=>$value)
|
||||||
{
|
{
|
||||||
if( isset($this->dbFields[$field]) )
|
if( isset($this->dbFields[$field]) )
|
||||||
{
|
{
|
||||||
$this->db[$field] = Sanitize::html($value);
|
$this->db[$field] = Sanitize::html($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $this->save() === false ) {
|
if( $this->save() === false ) {
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to save the database file.');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -239,6 +240,12 @@ class dbSite extends dbJSON
|
|||||||
return $this->getField('postsperpage');
|
return $this->getField('postsperpage');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns if tags mix is enabled.
|
||||||
|
public function shuffleIdeticalTags()
|
||||||
|
{
|
||||||
|
return $this->getField('shuffleIdeticalTags');
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the current language.
|
// Returns the current language.
|
||||||
public function language()
|
public function language()
|
||||||
{
|
{
|
||||||
|
@ -27,16 +27,16 @@ function buildPost($key)
|
|||||||
global $Parsedown;
|
global $Parsedown;
|
||||||
global $Site;
|
global $Site;
|
||||||
|
|
||||||
// Post object, content from FILE.
|
// Post object, content from FILE.
|
||||||
$Post = new Post($key);
|
$Post = new Post($key);
|
||||||
if( !$Post->isValid() ) {
|
if( !$Post->isValid() ) {
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the post from file with key: '.$key);
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the post from file with key: '.$key);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Post database, content from DATABASE JSON.
|
// Post database, content from DATABASE JSON.
|
||||||
$db = $dbPosts->getPostDB($key);
|
$db = $dbPosts->getPostDB($key);
|
||||||
if( !$db ) {
|
if( !$db ) {
|
||||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the post from database with key: '.$key);
|
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying build the post from database with key: '.$key);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -46,7 +46,7 @@ function buildPost($key)
|
|||||||
$Post->setField($field, $value);
|
$Post->setField($field, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Content in raw format
|
// Content in raw format
|
||||||
$contentRaw = $Post->content();
|
$contentRaw = $Post->content();
|
||||||
$Post->setField('contentRaw', $contentRaw, true);
|
$Post->setField('contentRaw', $contentRaw, true);
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ function buildPost($key)
|
|||||||
$username = $Post->username();
|
$username = $Post->username();
|
||||||
$Post->setField('user', $dbUsers->getUser($username));
|
$Post->setField('user', $dbUsers->getUser($username));
|
||||||
|
|
||||||
return $Post;
|
return $Post;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeUnpublished=true, $tagKey=false)
|
function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeUnpublished=true, $tagKey=false)
|
||||||
@ -105,8 +105,29 @@ function buildPostsForPage($pageNumber=0, $amount=POSTS_PER_PAGE_ADMIN, $removeU
|
|||||||
array_push($posts, $Post);
|
array_push($posts, $Post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return $posts;
|
||||||
|
}
|
||||||
|
|
||||||
return $posts;
|
function buildTagPosts($tag,$amount=3, $pageNumber=0){
|
||||||
|
global $dbTags;
|
||||||
|
$posts=array();
|
||||||
|
$tag=str_replace(" ", "-",$tag);
|
||||||
|
|
||||||
|
$keys= $dbTags->getList($pageNumber, $amount, $tag);
|
||||||
|
foreach($keys as $key=>$value) {
|
||||||
|
$Post = buildPost($key);
|
||||||
|
|
||||||
|
if($Post==false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$posts['itms'][$key]=$Post->vars;
|
||||||
|
$posts['itms'][$key]['permalink']=$Post->permalink();
|
||||||
|
}
|
||||||
|
|
||||||
|
$posts['count']=$dbTags->countPostsByTag($tag);
|
||||||
|
$posts['page']=$pageNumber;
|
||||||
|
|
||||||
|
return $posts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// PAGE FUNCTIONS
|
// PAGE FUNCTIONS
|
||||||
@ -193,7 +214,7 @@ function buildAllPages()
|
|||||||
// Remove the error page
|
// Remove the error page
|
||||||
unset($list['error']);
|
unset($list['error']);
|
||||||
|
|
||||||
// Sorte pages
|
// Sort pages
|
||||||
uasort($list, 'sortPages');
|
uasort($list, 'sortPages');
|
||||||
|
|
||||||
foreach($list as $key=>$db)
|
foreach($list as $key=>$db)
|
||||||
|
@ -18,11 +18,17 @@ class Url
|
|||||||
|
|
||||||
// remove parameters GET, do not use parse_url because has problem with utf-8.
|
// remove parameters GET, do not use parse_url because has problem with utf-8.
|
||||||
$explode = explode('?', $decode);
|
$explode = explode('?', $decode);
|
||||||
$this->uri = $explode[0];
|
$this->uri = $explode[0];
|
||||||
|
|
||||||
$this->parameters = $_GET;
|
// deal with server config when missing the get params
|
||||||
|
if(empty($_GET)){
|
||||||
|
isset($explode[1]) ? parse_str($explode[1], $this->parameters):"";
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
$this->parameters=$_GET;
|
||||||
|
}
|
||||||
|
|
||||||
$this->uriStrlen = Text::length($this->uri);
|
$this->uriStrlen = Text::length($this->uri);
|
||||||
|
|
||||||
$this->whereAmI = 'home';
|
$this->whereAmI = 'home';
|
||||||
|
|
||||||
@ -142,7 +148,7 @@ class Url
|
|||||||
|
|
||||||
public function pageNumber()
|
public function pageNumber()
|
||||||
{
|
{
|
||||||
if(isset($this->parameters['page'])) {
|
if(isset($this->parameters['page'])) {
|
||||||
return $this->parameters['page'];
|
return $this->parameters['page'];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -170,7 +176,7 @@ class Url
|
|||||||
// Check if the filter is in the uri.
|
// Check if the filter is in the uri.
|
||||||
$position = Text::stringPosition($this->uri, $filter);
|
$position = Text::stringPosition($this->uri, $filter);
|
||||||
|
|
||||||
// If the position is FALSE, the filter isn't in the URI.
|
// If the position is FALSE, the filter isn't in the URI.
|
||||||
if($position===false) {
|
if($position===false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -33,25 +33,30 @@ class pluginAPI extends Plugin {
|
|||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
$html .= '<div>';
|
$html .= '<div>';
|
||||||
$html .= '<p><b>Show all posts:</b> <a href="'.DOMAIN_BASE.'api/show/all/posts/'.$this->getDbField('authKey').'">'.DOMAIN_BASE.'api/show/all/posts/'.$this->getDbField('authKey').'</a></p>';
|
$html .= '<p><b>Show all posts:</b> <a href="'.DOMAIN_BASE.'api/show/all/posts?key='.$this->getDbField('authKey').'">'.DOMAIN_BASE.'api/show/all/posts?key='.$this->getDbField('authKey').'</a></p>';
|
||||||
$html .= '<div class="tip">Get all posts from this site.</div>';
|
$html .= '<div class="tip">Get all posts from this site.</div>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
$html .= '<div>';
|
$html .= '<div>';
|
||||||
$html .= '<p><b>Show all pages:</b> <a href="'.DOMAIN_BASE.'api/show/all/pages/'.$this->getDbField('authKey').'">'.DOMAIN_BASE.'api/show/all/pages/'.$this->getDbField('authKey').'</a></p>';
|
$html .= '<p><b>Show all pages:</b> <a href="'.DOMAIN_BASE.'api/show/all/pages?key='.$this->getDbField('authKey').'">'.DOMAIN_BASE.'api/show/all/pages?key='.$this->getDbField('authKey').'</a></p>';
|
||||||
$html .= '<div class="tip">Get all pages from this site.</div>';
|
$html .= '<div class="tip">Get all pages from this site.</div>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
$html .= '<div>';
|
$html .= '<div>';
|
||||||
$html .= '<p><b>Show post:</b> <a href="'.DOMAIN_BASE.'api/show/post/{POST-NAME}">'.DOMAIN_BASE.'api/show/post/{POST-NAME}</a></p>';
|
$html .= '<p><b>Show post:</b> <a href="'.DOMAIN_BASE.'api/show/post/POST-NAME?key='.$this->getDbField('authKey').'">'.DOMAIN_BASE.'api/show/post/{POST-NAME}?key='.$this->getDbField('authKey').'</a></p>';
|
||||||
$html .= '<div class="tip">Get a particular post, change the {POST-NAME} with the post friendly url.</div>';
|
$html .= '<div class="tip">Get a particular post, change the {POST-NAME} with the post friendly url.</div>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
$html .= '<div>';
|
$html .= '<div>';
|
||||||
$html .= '<p><b>Show page:</b> <a href="'.DOMAIN_BASE.'api/show/page/{PAGE-NAME}">'.DOMAIN_BASE.'api/show/page/{PAGE-NAME}</a></p>';
|
$html .= '<p><b>Show page:</b> <a href="'.DOMAIN_BASE.'api/show/page/PAGE-NAME?key='.$this->getDbField('authKey').'">'.DOMAIN_BASE.'api/show/page/{PAGE-NAME}?key='.$this->getDbField('authKey').'</a></p>';
|
||||||
$html .= '<div class="tip">Get a particular page, change the {PAGE-NAME} with the page friendly url.</div>';
|
$html .= '<div class="tip">Get a particular page, change the {PAGE-NAME} with the page friendly url.</div>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
|
$html .= '<div>';
|
||||||
|
$html .= '<p><b>Show posts by tag filter:</b> <a href="'.DOMAIN_BASE.'api/show/tag/TAG-NAME/PER-PAGE/PAGE-NUM?key='.$this->getDbField('authKey').'">'.DOMAIN_BASE.'api/show/tag/{TAG-NAME}/{PER-PAGE}/{PAGE-NUM}?key='.$this->getDbField('authKey').'</a></p>';
|
||||||
|
$html .= '<div class="tip">Get all posts filterd by a tag name , per page limit and page number.</div>';
|
||||||
|
$html .= '</div>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,6 +139,14 @@ class pluginAPI extends Plugin {
|
|||||||
return json_encode($tmp);
|
return json_encode($tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getTagPosts($tag,$amount=3,$pageNumber=0)
|
||||||
|
{
|
||||||
|
$posts = buildTagPosts($tag,$amount,$pageNumber);
|
||||||
|
return json_encode($posts);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private function getPage($key)
|
private function getPage($key)
|
||||||
{
|
{
|
||||||
// Generate the object Page
|
// Generate the object Page
|
||||||
@ -167,7 +180,7 @@ class pluginAPI extends Plugin {
|
|||||||
|
|
||||||
public function beforeRulesLoad()
|
public function beforeRulesLoad()
|
||||||
{
|
{
|
||||||
global $Url;
|
global $Url;
|
||||||
|
|
||||||
// The URI start with /api/
|
// The URI start with /api/
|
||||||
$startString = HTML_PATH_ROOT.'api/';
|
$startString = HTML_PATH_ROOT.'api/';
|
||||||
@ -177,6 +190,8 @@ class pluginAPI extends Plugin {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
// Remove the first part of the URI
|
// Remove the first part of the URI
|
||||||
$URI = mb_substr($URI, $length);
|
$URI = mb_substr($URI, $length);
|
||||||
|
|
||||||
@ -188,41 +203,44 @@ class pluginAPI extends Plugin {
|
|||||||
// show all pages {AUTH KEY}
|
// show all pages {AUTH KEY}
|
||||||
|
|
||||||
// Get parameters
|
// Get parameters
|
||||||
$parameters = explode('/', $URI);
|
$parameters = explode('/', $URI);
|
||||||
|
|
||||||
for($i=0; $i<3; $i++) {
|
|
||||||
if(empty($parameters[$i])) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
// Sanizite
|
|
||||||
$parameters[$i] = Sanitize::html($parameters[$i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default JSON
|
// Default JSON
|
||||||
$json = json_encode(array(
|
$json = json_encode(array(
|
||||||
'status'=>'0',
|
'status'=>'0',
|
||||||
'bludit'=>'Bludit API plugin',
|
'bludit'=>'Bludit API plugin',
|
||||||
'message'=>'Check the parameters'
|
'message'=>'Check the parameters'
|
||||||
));
|
));
|
||||||
|
|
||||||
if($parameters[0]==='show') {
|
if(!isset($_GET['key']) OR $_GET['key']!==$this->getDbField('authKey') ){
|
||||||
|
exit($json);
|
||||||
|
}
|
||||||
|
|
||||||
|
for($i=0; $i<count($parameters); $i++) {
|
||||||
|
// Sanizite
|
||||||
|
$parameters[$i] = Sanitize::html($parameters[$i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if($parameters[0]==='show') {
|
||||||
|
|
||||||
if($parameters[1]==='all') {
|
if($parameters[1]==='all') {
|
||||||
|
|
||||||
// Authentication key from the URI
|
if($parameters[2] === 'posts') {
|
||||||
$authKey = $parameters[3];
|
$json = $this->getAllPosts();
|
||||||
|
}
|
||||||
// Compare keys
|
elseif($parameters[2] === 'pages') {
|
||||||
if( $authKey===$this->getDbField('authKey') ) {
|
$json = $this->getAllPages();
|
||||||
|
}
|
||||||
if($parameters[2] === 'posts') {
|
}
|
||||||
$json = $this->getAllPosts();
|
elseif($parameters[1]==='tag') {
|
||||||
}
|
if(isset($parameters[2]) AND isset($parameters[3])AND isset($parameters[4])){
|
||||||
elseif($parameters[2] === 'pages') {
|
$tag = $parameters[2];
|
||||||
$json = $this->getAllPages();
|
$limit = $parameters[3];
|
||||||
}
|
$page = $parameters[4];
|
||||||
}
|
$json = $this->getTagPosts($tag,$limit,$page);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elseif($parameters[1]==='post' || $parameters[1]==='page') {
|
elseif($parameters[1]==='post' || $parameters[1]==='page') {
|
||||||
|
|
||||||
@ -236,9 +254,6 @@ class pluginAPI extends Plugin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
exit($json);
|
||||||
// Print the JSON
|
|
||||||
header('Content-Type: application/json');
|
|
||||||
exit($json);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,8 +6,15 @@ class pluginTags extends Plugin {
|
|||||||
{
|
{
|
||||||
$this->dbFields = array(
|
$this->dbFields = array(
|
||||||
'label'=>'Tags',
|
'label'=>'Tags',
|
||||||
'sort'=>'date'
|
'sort'=>'date',
|
||||||
|
'link'=>''
|
||||||
);
|
);
|
||||||
|
$this->dbTokens = array(
|
||||||
|
"[postUrl]",
|
||||||
|
"[tagName]",
|
||||||
|
"[tagCount]"
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function form()
|
public function form()
|
||||||
@ -31,7 +38,14 @@ class pluginTags extends Plugin {
|
|||||||
$html .= '<option value="'.$key.'">'.$Language->get($value).'</option>';
|
$html .= '<option value="'.$key.'">'.$Language->get($value).'</option>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$html .= '</select>';
|
$html .= '</select>';
|
||||||
|
$html .= '</div>';
|
||||||
|
|
||||||
|
$html .= '<div>';
|
||||||
|
$html .= '<label>'.$Language->get('Customize link').'</label>';
|
||||||
|
$html .= '<input name="link" id="jslink" type="text" value="'.$this->getDbField('link').'">';
|
||||||
|
$html .= '<pre>available tokens '. implode(', ', $this->dbTokens).' <br/>'.
|
||||||
|
htmlspecialchars('<a href="[token1]#content" >[token2] [token3]</a>').'</pre>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
return $html;
|
return $html;
|
||||||
@ -72,10 +86,25 @@ class pluginTags extends Plugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach($tagArray as $tagKey=>$fields)
|
foreach($tagArray as $tagKey=>$fields)
|
||||||
{
|
{
|
||||||
// Print the parent
|
// Print the parent
|
||||||
$html .= '<li><a href="'.HTML_PATH_ROOT.$filter.'/'.$fields['tagKey'].'">'.$fields['name'].' ('.$fields['count'].')</a></li>';
|
$link='<a href="'.HTML_PATH_ROOT.$filter.'/'.$fields['tagKey'].'">'.$fields['name'].' ('.$fields['count'].')</a>';
|
||||||
|
if(!empty($this->getDbField('link'))){
|
||||||
|
$replacments=array(
|
||||||
|
"[postUrl]"=>HTML_PATH_ROOT.$filter.'/'.$fields['tagKey'], html_entity_decode($this->getDbField('link')),
|
||||||
|
"[tagName]"=>$fields['name'],
|
||||||
|
"[tagCount]"=>$fields['count']
|
||||||
|
);
|
||||||
|
$link= html_entity_decode($this->getDbField('link'));
|
||||||
|
foreach($this->dbTokens as $token){
|
||||||
|
$link= str_replace($token,$replacments[$token],$link);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$html .= "<li>$link</li>";
|
||||||
}
|
}
|
||||||
$html .= '</ul>';
|
$html .= '</ul>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user