From 2aed08be5fc6df2d740dc792655cb34b2b81c7d3 Mon Sep 17 00:00:00 2001 From: dignajar Date: Sat, 4 Jun 2016 22:31:07 -0300 Subject: [PATCH] API plugin and changes on plugins system --- README.md | 2 +- bl-content/README.md | 3 - bl-kernel/abstract/content.class.php | 6 +- bl-kernel/abstract/plugin.class.php | 10 +- .../admin/themes/default/css/default.css | 4 + bl-kernel/security.class.php | 8 ++ bl-plugins/api/plugin.php | 98 ++++++++++++++++--- bl-plugins/disqus/plugin.php | 15 +-- bl-plugins/maintenancemode/plugin.php | 5 +- bl-plugins/opengraph/plugin.php | 8 -- bl-plugins/pages/plugin.php | 5 +- bl-plugins/simplemde/plugin.php | 5 +- index.php | 2 +- 13 files changed, 122 insertions(+), 49 deletions(-) delete mode 100644 bl-content/README.md diff --git a/README.md b/README.md index e2a22431..6d7d7c23 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Bludit is a simple web application to make your own **blog** or **site** in seco - [Documentation](https://docs.bludit.com) - [Help and Support](https://forum.bludit.com) - [Plugins](https://plugins.bludit.com) -- [Themes](https://github.com/dignajar/bludit-themes) +- [Themes](https://themes.bludit.com) - [More plugins and themes](https://forum.bludit.com/viewforum.php?f=14) Social networks diff --git a/bl-content/README.md b/bl-content/README.md deleted file mode 100644 index 76dfe569..00000000 --- a/bl-content/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# varlogdiego - -tes diff --git a/bl-kernel/abstract/content.class.php b/bl-kernel/abstract/content.class.php index 93c9b632..8b0cd002 100644 --- a/bl-kernel/abstract/content.class.php +++ b/bl-kernel/abstract/content.class.php @@ -288,7 +288,7 @@ class Content { return '/'.$htmlPath.'/'.$tmp; } - public function json() + public function json($returnsArray=false) { $tmp['key'] = $this->key(); $tmp['title'] = $this->title(); @@ -298,6 +298,10 @@ class Content { $tmp['date'] = $this->dateRaw(); $tmp['permalink'] = $this->permalink(true); + if($returnsArray) { + return $tmp; + } + return json_encode($tmp); } } \ No newline at end of file diff --git a/bl-kernel/abstract/plugin.class.php b/bl-kernel/abstract/plugin.class.php index c459d252..3ebd4f44 100644 --- a/bl-kernel/abstract/plugin.class.php +++ b/bl-kernel/abstract/plugin.class.php @@ -105,7 +105,7 @@ class Plugin { public function setDb($args) { - $tmp = array(); + $tmp = $this->db; foreach($this->dbFields as $key=>$value) { @@ -120,10 +120,6 @@ class Plugin { // Set value $tmp[$key] = $tmpValue; } - else - { - $tmp[$key] = false; - } } $this->db = $tmp; @@ -186,7 +182,7 @@ class Plugin { return false; } - // Create plugin directory for databases and others files. + // Create plugin directory for databases and other files mkdir(PATH_PLUGINS_DATABASES.$this->directoryName, 0755, true); // Create database @@ -219,4 +215,4 @@ class Plugin { // The user can define your own dbFields. } -} +} \ No newline at end of file diff --git a/bl-kernel/admin/themes/default/css/default.css b/bl-kernel/admin/themes/default/css/default.css index 4c08c5a2..92f4e913 100644 --- a/bl-kernel/admin/themes/default/css/default.css +++ b/bl-kernel/admin/themes/default/css/default.css @@ -658,3 +658,7 @@ div.plugin-links > span.separator { margin-bottom: 0px !important; display: inline-block; } + +#jsformplugin p { + margin-bottom: 0; +} \ No newline at end of file diff --git a/bl-kernel/security.class.php b/bl-kernel/security.class.php index 5acaa2c3..15befe9b 100644 --- a/bl-kernel/security.class.php +++ b/bl-kernel/security.class.php @@ -14,6 +14,14 @@ class Security extends dbJSON parent::__construct(PATH_DATABASES.'security.php'); } + // Authentication key + // -------------------------------------------------------------------- + public function key1() + { + return $this->db['key1']; + } + + // ==================================================== // TOKEN FOR CSRF // ==================================================== diff --git a/bl-plugins/api/plugin.php b/bl-plugins/api/plugin.php index eb2f13d9..496c3824 100644 --- a/bl-plugins/api/plugin.php +++ b/bl-plugins/api/plugin.php @@ -4,9 +4,15 @@ 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 + $authKey = md5($Security->key1().time().DOMAIN_BASE); + $this->dbFields = array( - 'ping'=>false, - 'authKey'=>'' + 'ping'=>0, // 0 = false, 1 = true + 'authKey'=>$authKey, // Private key + 'showAllAmount'=>15 // Amount of posts and pages for return ); } @@ -15,14 +21,36 @@ class pluginAPI extends Plugin { $html = ''; $html .= '
'; - $html .= '

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

'; + $html .= ''; + $html .= 'getDbField('ping')?'checked':'').'>'; + $html .= ''; + $html .= '
Enable this feature to share your posts and pages with Bludit.com.
'; $html .= '
'; $html .= '
'; - $html .= 'getDbField('ping')?'checked':'').'>'; - $html .= ''; + $html .= '

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

'; + $html .= '
This key is private, do not share it with anyone.
'; $html .= '
'; + $html .= '
'; + $html .= '

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

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

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

'; + $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 post: '.DOMAIN_BASE.'api/show/page/{PAGE-NAME}

'; + $html .= '
Get a particular page, change the {PAGE-NAME} with the page friendly url.
'; + $html .= '
'; return $html; } @@ -35,8 +63,12 @@ class pluginAPI extends Plugin { private function ping() { if($this->getDbField('ping')) { + + // Get the authentication key + $authKey = $this->getDbField('authKey'); + // Just a request HTTP with the website URL - Log::set( file_get_contents('https://www.bludit.com/api.php') ); + Log::set( file_get_contents('https://www.bludit.com/api.php?authKey='.$authKey) ); } } @@ -56,6 +88,19 @@ class pluginAPI extends Plugin { return $Post->json(); } + private function getAllPosts() + { + $posts = buildPostsForPage(0, $this->getDbField('showAllAmount'), true, false); + + $tmp = array(); + + foreach($posts as $Post) { + array_push($tmp, $Post->json( $returnsArray=true )); + } + + return json_encode($tmp); + } + private function getPage($key) { // Generate the object Page @@ -91,16 +136,18 @@ class pluginAPI extends Plugin { // ------------------------------------------------------------ // show post {post slug} // show page {page slug} - // show all posts - // show all pages + // show all posts {AUTH KEY} + // show all pages {AUTH KEY} // Get parameters $parameters = explode('/', $URI); - // Check parameters are sended - for($i=0; $i<3; $i++) { + for($i=0; $i<4; $i++) { if(empty($parameters[$i])) { return false; + } else { + // Sanizite + $parameters[$i] = Sanitize::html($parameters[$i]); } } @@ -111,15 +158,34 @@ class pluginAPI extends Plugin { 'message'=>'Check the parameters' )); - if($parameters[0] === 'show') { + if($parameters[0]==='show') { - $key = $parameters[2]; + if($parameters[1]==='all') { - if($parameters[1] === 'post') { - $json = $this->getPost($key); + // Authentication key from the URI + $authKey = $parameters[3]; + + // Compare keys + if( $authKey===$this->getDbField('authKey') ) { + + if($parameters[2] === 'posts') { + $json = $this->getAllPosts(); + } + elseif($parameters[1] === 'pages') { + $json = $this->getAllPosts(); + } + } } - elseif($parameters[1] === 'page') { - $json = $this->getPage($key); + elseif($parameters[1]==='post' || $parameters[1]==='page') { + + $key = $parameters[2]; + + if($parameters[1] === 'post') { + $json = $this->getPost($key); + } + elseif($parameters[1] === 'page') { + $json = $this->getPage($key); + } } } diff --git a/bl-plugins/disqus/plugin.php b/bl-plugins/disqus/plugin.php index 3eb8bb67..d5861887 100644 --- a/bl-plugins/disqus/plugin.php +++ b/bl-plugins/disqus/plugin.php @@ -8,9 +8,9 @@ class pluginDisqus extends Plugin { { $this->dbFields = array( 'shortname'=>'', - 'enablePages'=>false, - 'enablePosts'=>false, - 'enableDefaultHomePage'=>false + 'enablePages'=>0, + 'enablePosts'=>0, + 'enableDefaultHomePage'=>1 ); } @@ -44,17 +44,20 @@ class pluginDisqus extends Plugin { $html .= ''; $html .= '
'; - $html .= 'getDbField('enablePages')?'checked':'').'>'; + $html .= ''; + $html .= 'getDbField('enablePages')?'checked':'').'>'; $html .= ''; $html .= '
'; $html .= '
'; - $html .= 'getDbField('enablePosts')?'checked':'').'>'; + $html .= ''; + $html .= 'getDbField('enablePosts')?'checked':'').'>'; $html .= ''; $html .= '
'; $html .= '
'; - $html .= 'getDbField('enableDefaultHomePage')?'checked':'').'>'; + $html .= ''; + $html .= 'getDbField('enableDefaultHomePage')?'checked':'').'>'; $html .= ''; $html .= '
'; diff --git a/bl-plugins/maintenancemode/plugin.php b/bl-plugins/maintenancemode/plugin.php index e6f9b1c4..5a36614e 100644 --- a/bl-plugins/maintenancemode/plugin.php +++ b/bl-plugins/maintenancemode/plugin.php @@ -5,7 +5,7 @@ class pluginMaintenanceMode extends Plugin { public function init() { $this->dbFields = array( - 'enable'=>false, + 'enable'=>0, 'message'=>'Temporarily down for maintenance.' ); } @@ -15,7 +15,8 @@ class pluginMaintenanceMode extends Plugin { global $Language; $html = '
'; - $html .= 'getDbField('enable')?'checked':'').'>'; + $html .= ''; + $html .= 'getDbField('enable')?'checked':'').'>'; $html .= ''; $html .= '
'; diff --git a/bl-plugins/opengraph/plugin.php b/bl-plugins/opengraph/plugin.php index 902fe798..7a1acc34 100644 --- a/bl-plugins/opengraph/plugin.php +++ b/bl-plugins/opengraph/plugin.php @@ -9,14 +9,6 @@ class pluginOpenGraph extends Plugin { $dom->loadHTML(''.$content); $finder = new DomXPath($dom); - /* DEPRECATED - $images = $finder->query("//img[contains(@class, 'bludit-img-opengraph')]"); - - if($images->length==0) { - $images = $finder->query("//img"); - } - */ - $images = $finder->query("//img"); if($images->length>0) diff --git a/bl-plugins/pages/plugin.php b/bl-plugins/pages/plugin.php index 324d5bda..50f84e7f 100644 --- a/bl-plugins/pages/plugin.php +++ b/bl-plugins/pages/plugin.php @@ -5,7 +5,7 @@ class pluginPages extends Plugin { public function init() { $this->dbFields = array( - 'homeLink'=>true, + 'homeLink'=>1, 'label'=>'Pages' ); } @@ -20,7 +20,8 @@ class pluginPages extends Plugin { $html .= ''; $html .= '
'; - $html .= 'getDbField('homeLink')?'checked':'').'>'; + $html .= ''; + $html .= 'getDbField('homeLink')?'checked':'').'>'; $html .= ''; $html .= '
'; diff --git a/bl-plugins/simplemde/plugin.php b/bl-plugins/simplemde/plugin.php index a0d7e768..5b976cfc 100644 --- a/bl-plugins/simplemde/plugin.php +++ b/bl-plugins/simplemde/plugin.php @@ -14,7 +14,7 @@ class pluginsimpleMDE extends Plugin { $this->dbFields = array( 'tabSize'=>'2', 'toolbar'=>'"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen", "guide"', - 'autosave'=>false + 'autosave'=>0 ); } @@ -33,7 +33,8 @@ class pluginsimpleMDE extends Plugin { $html .= ''; $html .= '
'; - $html .= 'getDbField('autosave')?'checked':'').'>'; + $html .= ''; + $html .= 'getDbField('autosave')?'checked':'').'>'; $html .= ''; $html .= '
'; diff --git a/index.php b/index.php index 1a6457d2..c7fe468a 100644 --- a/index.php +++ b/index.php @@ -37,4 +37,4 @@ if($Url->whereAmI()==='admin') { // Site else { require(PATH_BOOT.'site.php'); -} \ No newline at end of file +}