Fixed, sticky and system pages
This commit is contained in:
parent
1f5dd3ac99
commit
c2cf10c39b
|
@ -8,48 +8,6 @@
|
|||
// Functions
|
||||
// ============================================================================
|
||||
|
||||
function addPage($args)
|
||||
{
|
||||
global $dbPages;
|
||||
global $Language;
|
||||
global $Syslog;
|
||||
|
||||
// Add the page, if the $key is FALSE the creation of the page failure
|
||||
$key = $dbPages->add($args);
|
||||
|
||||
if($key) {
|
||||
// Re-index categories
|
||||
reindexCategories();
|
||||
|
||||
// Re-index tags
|
||||
reindextags();
|
||||
|
||||
// Call the plugins after page created
|
||||
Theme::plugins('afterPageCreate');
|
||||
|
||||
// Add to syslog
|
||||
$Syslog->add(array(
|
||||
'dictionaryKey'=>'new-page-created',
|
||||
'notes'=>$args['title']
|
||||
));
|
||||
|
||||
// Create an alert
|
||||
Alert::set( $Language->g('Page added successfully') );
|
||||
|
||||
// Redirect
|
||||
Redirect::page('pages');
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the page');
|
||||
Log::set(__METHOD__.LOG_SEP.'Cleaning database...');
|
||||
$dbPages->delete($key);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Main before POST
|
||||
// ============================================================================
|
||||
|
@ -60,7 +18,11 @@ function addPage($args)
|
|||
|
||||
if( $_SERVER['REQUEST_METHOD'] == 'POST' )
|
||||
{
|
||||
addPage($_POST);
|
||||
if( createNewPage($_POST)!==false ) {
|
||||
Alert::set( $Language->g('Page added successfully') );
|
||||
}
|
||||
|
||||
Redirect::page('pages');
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
|
|
|
@ -42,8 +42,8 @@ if( $Url->whereAmI()==='page' ) {
|
|||
if($page===false) {
|
||||
$Url->setNotFound(true);
|
||||
}
|
||||
// The page is not published
|
||||
elseif( !$page->published() ) {
|
||||
// The page is not published, still scheduled or draft
|
||||
elseif( $page->scheduled() || $page->draft() ) {
|
||||
$Url->setNotFound(true);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -179,3 +179,34 @@ function printDebug($array) {
|
|||
var_dump($array);
|
||||
echo '</pre>';
|
||||
}
|
||||
|
||||
function createNewPage($args) {
|
||||
global $dbPages;
|
||||
global $Syslog;
|
||||
|
||||
$key = $dbPages->add($args);
|
||||
if($key) {
|
||||
// Call the plugins after page created
|
||||
Theme::plugins('afterPageCreate');
|
||||
|
||||
// Re-index categories
|
||||
reindexCategories();
|
||||
|
||||
// Re-index tags
|
||||
reindextags();
|
||||
|
||||
// Add to syslog
|
||||
$Syslog->add(array(
|
||||
'dictionaryKey'=>'new-page-created',
|
||||
'notes'=>$args['title']
|
||||
));
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
Log::set('Function createNewPage()'.LOG_SEP.'Error occurred when trying to create the page');
|
||||
Log::set('Function createNewPage()'.LOG_SEP.'Cleaning database...');
|
||||
$dbPages->delete($key);
|
||||
|
||||
return false;
|
||||
}
|
|
@ -335,29 +335,31 @@ class Page {
|
|||
return $this->getValue('key');
|
||||
}
|
||||
|
||||
// Returns TRUE if the post/page is published, FALSE otherwise.
|
||||
// (boolean) Returns TRUE if the page is published, FALSE otherwise
|
||||
public function published()
|
||||
{
|
||||
return ($this->getValue('status')==='published');
|
||||
}
|
||||
|
||||
// Returns TRUE if the post/page is scheduled, FALSE otherwise.
|
||||
// (boolean) Returns TRUE if the page is scheduled, FALSE otherwise
|
||||
public function scheduled()
|
||||
{
|
||||
return ($this->getValue('status')==='scheduled');
|
||||
}
|
||||
|
||||
// Returns TRUE if the post/page is draft, FALSE otherwise.
|
||||
// (boolean) Returns TRUE if the page is draft, FALSE otherwise
|
||||
public function draft()
|
||||
{
|
||||
return ($this->getValue('status')=='draft');
|
||||
}
|
||||
|
||||
// (boolean) Returns TRUE if the page is sticky, FALSE otherwise
|
||||
public function sticky()
|
||||
{
|
||||
return ($this->getValue('status')=='sticky');
|
||||
}
|
||||
|
||||
// (boolean) Returns TRUE if the page is fixed, FALSE otherwise
|
||||
public function fixed()
|
||||
{
|
||||
return ($this->getValue('status')=='fixed');
|
||||
|
|
|
@ -8,40 +8,23 @@ class pluginAPI extends Plugin {
|
|||
$token = md5( uniqid().time().DOMAIN );
|
||||
|
||||
$this->dbFields = array(
|
||||
'ping'=>0, // 0 = false, 1 = true
|
||||
'token'=>$token, // API Token
|
||||
'showAllAmount'=>15, // Amount of posts and pages for return
|
||||
'authentication'=>1 // Authentication required
|
||||
'amountOfItems'=>15 // Amount of items to return
|
||||
);
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
$html = '';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<p><b>Authorization Key:</b> '.$this->getDbField('token').'</p>';
|
||||
$html .= '<div class="tip">This key is private, do not share it with anyone.</div>';
|
||||
$html = '<div>';
|
||||
$html .= '<label>'.$Language->get('API Token').'</label>';
|
||||
$html .= '<input type="text" value="'.$this->getValue('token').'" disabled>';
|
||||
$html .= '<span class="tip">'.$Language->get('This token is for read only and is regenerated every time you install the plugin').'</span>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<p><b>Show all posts:</b> <a href="'.DOMAIN_BASE.'api/show/all/posts/'.$this->getDbField('token').'">'.DOMAIN_BASE.'api/show/all/posts/'.$this->getDbField('token').'</a></p>';
|
||||
$html .= '<div class="tip">Get all posts from this site.</div>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<p><b>Show all pages:</b> <a href="'.DOMAIN_BASE.'api/show/all/pages/'.$this->getDbField('token').'">'.DOMAIN_BASE.'api/show/all/pages/'.$this->getDbField('token').'</a></p>';
|
||||
$html .= '<div class="tip">Get all pages from this site.</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 .= '<div class="tip">Get a particular post, change the {POST-NAME} with the post friendly url.</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 .= '<div class="tip">Get a particular page, change the {PAGE-NAME} with the page friendly url.</div>';
|
||||
$html .= '<label>'.$Language->get('Amount of pages').'</label>';
|
||||
$html .= '<input id="jsamountOfItems" name="amountOfItems" type="text" value="'.$this->getValue('amountOfItems').'">';
|
||||
$html .= '<span class="tip">'.$Language->get('The amount of pages to return when you call to /api/pages').'</span>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
|
@ -110,43 +93,29 @@ class pluginAPI extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
// REQUESTS
|
||||
// ------------------------------------------------------------
|
||||
|
||||
// /api/posts
|
||||
if( ($method==='GET') && ($parameters[0]==='posts') && empty($parameters[1]) ) {
|
||||
$data = $this->getAllPosts();
|
||||
$this->response($data);
|
||||
// (GET) /api/pages
|
||||
if( ($method==='GET') && ($parameters[0]==='pages') && empty($parameters[1]) ) {
|
||||
$data = $this->getPages();
|
||||
}
|
||||
// /api/pages
|
||||
elseif( ($method==='GET') && ($parameters[0]==='pages') && empty($parameters[1]) ) {
|
||||
$data = $this->getAllPages();
|
||||
$this->response($data);
|
||||
}
|
||||
// /api/posts/{key}
|
||||
elseif( ($method==='GET') && ($parameters[0]==='posts') && !empty($parameters[1]) ) {
|
||||
$data = $this->getPost($parameters[1]);
|
||||
$this->response($data);
|
||||
}
|
||||
// /api/pages/{key}
|
||||
// (GET) /api/pages/<key>
|
||||
elseif( ($method==='GET') && ($parameters[0]==='pages') && !empty($parameters[1]) ) {
|
||||
$data = $this->getPage($parameters[1]);
|
||||
$this->response($data);
|
||||
}
|
||||
// /api/cli/regenerate
|
||||
elseif( ($method==='POST') && ($parameters[0]==='cli') && ($parameters[1]==='regenerate') ) {
|
||||
|
||||
// Regenerate posts
|
||||
if( $dbPosts->cliMode() ) {
|
||||
reIndexTagsPosts();
|
||||
}
|
||||
|
||||
// Regenerate pages
|
||||
$dbPages->cliMode();
|
||||
|
||||
$this->response(array(
|
||||
'status'=>'0',
|
||||
'message'=>'Pages and post regenerated.'
|
||||
));
|
||||
// (POST) /api/pages
|
||||
elseif( ($method==='POST') && ($parameters[0]==='pages') && empty($parameters[1]) && $writePermissions ) {
|
||||
$data = $this->newPage($inputs);
|
||||
}
|
||||
else {
|
||||
$data = array(
|
||||
'status'=>'1',
|
||||
'message'=>'Error: URI not found or Access denied.'
|
||||
);
|
||||
}
|
||||
|
||||
$this->response($data);
|
||||
}
|
||||
|
||||
// PRIVATE METHODS
|
||||
|
@ -215,80 +184,6 @@ class pluginAPI extends Plugin {
|
|||
exit($json);
|
||||
}
|
||||
|
||||
private function ping()
|
||||
{
|
||||
if($this->getDbField('ping')) {
|
||||
|
||||
// Get the authentication key
|
||||
$token = $this->getDbField('token');
|
||||
|
||||
$url = 'https://api.bludit.com/ping?token='.$token.'&url='.DOMAIN_BASE;
|
||||
|
||||
// Check if curl is installed
|
||||
if( function_exists('curl_version') ) {
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
$out = curl_exec($ch);
|
||||
|
||||
if($out === false) {
|
||||
Log::set('Plugin API : '.'Curl error: '.curl_error($ch));
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
}
|
||||
else {
|
||||
$options = array(
|
||||
"ssl"=>array(
|
||||
"verify_peer"=>false,
|
||||
"verify_peer_name"=>false
|
||||
)
|
||||
);
|
||||
|
||||
$stream = stream_context_create($options);
|
||||
$out = file_get_contents($url, false, $stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function getPost($key)
|
||||
{
|
||||
// Generate the object Post
|
||||
$Post = buildPost($key);
|
||||
|
||||
if(!$Post) {
|
||||
return array(
|
||||
'status'=>'1',
|
||||
'message'=>'Post not found.'
|
||||
);
|
||||
}
|
||||
|
||||
$data['status'] = '0';
|
||||
$data['message'] = '';
|
||||
$data['data'] = $Post->json( $returnsArray=true );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getAllPosts()
|
||||
{
|
||||
$posts = buildPostsForPage(0, $this->getDbField('showAllAmount'), true, false);
|
||||
|
||||
$tmp = array(
|
||||
'status'=>'0',
|
||||
'message'=>'',
|
||||
'data'=>array()
|
||||
);
|
||||
|
||||
foreach($posts as $Post) {
|
||||
array_push($tmp['data'], $Post->json( $returnsArray=true ));
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
private function getPage($key)
|
||||
{
|
||||
// Generate the object Page
|
||||
|
@ -301,30 +196,44 @@ class pluginAPI extends Plugin {
|
|||
);
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['status'] = '0';
|
||||
$data['message'] = '';
|
||||
$data['message'] = 'Page filtered by key: '.$key;
|
||||
$data['data'] = $Page->json( $returnsArray=true );
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
private function getAllPages()
|
||||
private function getPages()
|
||||
{
|
||||
$pages = buildAllPages();
|
||||
global $dbPages;
|
||||
|
||||
$onlyPublished = true;
|
||||
$amountOfItems = $this->getValue('amountOfItems');
|
||||
$pageNumber = 1;
|
||||
$list = $dbPages->getList($pageNumber, $amountOfItems, $onlyPublished);
|
||||
|
||||
$tmp = array(
|
||||
'status'=>'0',
|
||||
'message'=>'',
|
||||
'message'=>'List of pages, amount of items: '.$amountOfItems,
|
||||
'data'=>array()
|
||||
);
|
||||
|
||||
foreach($pages as $Page) {
|
||||
if($Page->published()) {
|
||||
array_push($tmp['data'], $Page->json( $returnsArray=true ));
|
||||
}
|
||||
// Get keys of pages
|
||||
$keys = array_keys($list);
|
||||
foreach($keys as $pageKey) {
|
||||
// Create the page object from the page key
|
||||
$page = buildPage($pageKey);
|
||||
array_push($tmp['data'], $Page->json( $returnsArray=true ));
|
||||
}
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
|
||||
private function newPage($args)
|
||||
{
|
||||
// This function is defined on functions.php
|
||||
return createNewPage($args);
|
||||
}
|
||||
|
||||
}
|
|
@ -307,7 +307,7 @@ function install($adminPassword, $email, $timezone)
|
|||
'description'=>$Language->get('Page not found'),
|
||||
'username'=>'admin',
|
||||
'tags'=>array(),
|
||||
'status'=>'published',
|
||||
'status'=>'system',
|
||||
'date'=>$currentDate,
|
||||
'dateModified'=>'',
|
||||
'allowComments'=>false,
|
||||
|
|
Loading…
Reference in New Issue