diff --git a/bl-kernel/admin/controllers/new-page.php b/bl-kernel/admin/controllers/new-page.php index 92c7b43b..31e85d29 100644 --- a/bl-kernel/admin/controllers/new-page.php +++ b/bl-kernel/admin/controllers/new-page.php @@ -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'); } // ============================================================================ diff --git a/bl-kernel/boot/rules/69.pages.php b/bl-kernel/boot/rules/69.pages.php index 56a786b9..bc94890e 100644 --- a/bl-kernel/boot/rules/69.pages.php +++ b/bl-kernel/boot/rules/69.pages.php @@ -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 { diff --git a/bl-kernel/functions.php b/bl-kernel/functions.php index 4de24bed..09f7f387 100644 --- a/bl-kernel/functions.php +++ b/bl-kernel/functions.php @@ -178,4 +178,35 @@ function printDebug($array) { echo '
';
 	var_dump($array);
 	echo '
'; +} + +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; } \ No newline at end of file diff --git a/bl-kernel/page.class.php b/bl-kernel/page.class.php index 82c717b4..712e20fc 100644 --- a/bl-kernel/page.class.php +++ b/bl-kernel/page.class.php @@ -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'); diff --git a/bl-plugins/api/plugin.php b/bl-plugins/api/plugin.php index d0235e41..4ed3b348 100644 --- a/bl-plugins/api/plugin.php +++ b/bl-plugins/api/plugin.php @@ -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 .= '
'; - $html .= '

Authorization Key: '.$this->getDbField('token').'

'; - $html .= '
This key is private, do not share it with anyone.
'; + $html = '
'; + $html .= ''; + $html .= ''; + $html .= ''.$Language->get('This token is for read only and is regenerated every time you install the plugin').''; $html .= '
'; $html .= '
'; - $html .= '

Show all posts: '.DOMAIN_BASE.'api/show/all/posts/'.$this->getDbField('token').'

'; - $html .= '
Get all posts from this site.
'; - $html .= '
'; - - $html .= '
'; - $html .= '

Show all pages: '.DOMAIN_BASE.'api/show/all/pages/'.$this->getDbField('token').'

'; - $html .= '
Get all pages from this site.
'; - $html .= '
'; - - $html .= '
'; - $html .= '

Show post: '.DOMAIN_BASE.'api/show/post/{POST-NAME}

'; - $html .= '
Get a particular post, change the {POST-NAME} with the post friendly url.
'; - $html .= '
'; - - $html .= '
'; - $html .= '

Show page: '.DOMAIN_BASE.'api/show/page/{PAGE-NAME}

'; - $html .= '
Get a particular page, change the {PAGE-NAME} with the page friendly url.
'; + $html .= ''; + $html .= ''; + $html .= ''.$Language->get('The amount of pages to return when you call to /api/pages').''; $html .= '
'; 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/ 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); + } + } \ No newline at end of file diff --git a/install.php b/install.php index 55e55359..d212f2f5 100644 --- a/install.php +++ b/install.php @@ -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,