API plugin and changes on plugins system

This commit is contained in:
dignajar 2016-06-04 22:31:07 -03:00
parent 81eaf4cc06
commit 2aed08be5f
13 changed files with 122 additions and 49 deletions

View File

@ -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

View File

@ -1,3 +0,0 @@
# varlogdiego
tes

View File

@ -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);
}
}

View File

@ -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

View File

@ -658,3 +658,7 @@ div.plugin-links > span.separator {
margin-bottom: 0px !important;
display: inline-block;
}
#jsformplugin p {
margin-bottom: 0;
}

View File

@ -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
// ====================================================

View File

@ -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 .= '<div>';
$html .= '<p>Authorization Key: '.$this->getDbField('authKey').'</p>';
$html .= '<input type="hidden" name="ping" value="0">';
$html .= '<input name="ping" id="jsping" type="checkbox" value="1" '.($this->getDbField('ping')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jsping">Ping Bludit.com</label>';
$html .= '<div class="tip">Enable this feature to share your posts and pages with Bludit.com.</div>';
$html .= '</div>';
$html .= '<div>';
$html .= '<input name="ping" id="jsping" type="checkbox" value="true" '.($this->getDbField('ping')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jsping">Ping Bludit.com</label>';
$html .= '<p><b>Authorization Key:</b> '.$this->getDbField('authKey').'</p>';
$html .= '<div class="tip">This key is private, do not share it with anyone.</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 .= '<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('authKey').'">'.DOMAIN_BASE.'api/show/all/pages/'.$this->getDbField('authKey').'</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 post:</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 .= '</div>';
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,7 +158,25 @@ class pluginAPI extends Plugin {
'message'=>'Check the parameters'
));
if($parameters[0] === 'show') {
if($parameters[0]==='show') {
if($parameters[1]==='all') {
// 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]==='post' || $parameters[1]==='page') {
$key = $parameters[2];
@ -122,6 +187,7 @@ class pluginAPI extends Plugin {
$json = $this->getPage($key);
}
}
}
// Print the JSON
header('Content-Type: application/json');

View File

@ -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 .= '</div>';
$html .= '<div>';
$html .= '<input name="enablePages" id="jsenablePages" type="checkbox" value="true" '.($this->getDbField('enablePages')?'checked':'').'>';
$html .= '<input type="hidden" name="enablePages" value="0">';
$html .= '<input name="enablePages" id="jsenablePages" type="checkbox" value="1" '.($this->getDbField('enablePages')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jsenablePages">'.$Language->get('Enable Disqus on pages').'</label>';
$html .= '</div>';
$html .= '<div>';
$html .= '<input name="enablePosts" id="jsenablePosts" type="checkbox" value="true" '.($this->getDbField('enablePosts')?'checked':'').'>';
$html .= '<input type="hidden" name="enablePosts" value="0">';
$html .= '<input name="enablePosts" id="jsenablePosts" type="checkbox" value="1" '.($this->getDbField('enablePosts')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jsenablePosts">'.$Language->get('Enable Disqus on posts').'</label>';
$html .= '</div>';
$html .= '<div>';
$html .= '<input name="enableDefaultHomePage" id="jsenableDefaultHomePage" type="checkbox" value="true" '.($this->getDbField('enableDefaultHomePage')?'checked':'').'>';
$html .= '<input type="hidden" name="enableDefaultHomePage" value="0">';
$html .= '<input name="enableDefaultHomePage" id="jsenableDefaultHomePage" type="checkbox" value="1" '.($this->getDbField('enableDefaultHomePage')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jsenableDefaultHomePage">'.$Language->get('Enable Disqus on default home page').'</label>';
$html .= '</div>';

View File

@ -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 = '<div>';
$html .= '<input name="enable" id="jsenable" type="checkbox" value="true" '.($this->getDbField('enable')?'checked':'').'>';
$html .= '<input type="hidden" name="enable" value="0">';
$html .= '<input name="enable" id="jsenable" type="checkbox" value="1" '.($this->getDbField('enable')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jsenable">'.$Language->get('Enable maintenance mode').'</label>';
$html .= '</div>';

View File

@ -9,14 +9,6 @@ class pluginOpenGraph extends Plugin {
$dom->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'.$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)

View File

@ -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 .= '</div>';
$html .= '<div>';
$html .= '<input name="homeLink" id="jshomeLink" type="checkbox" value="true" '.($this->getDbField('homeLink')?'checked':'').'>';
$html .= '<input type="hidden" name="homeLink" value="0">';
$html .= '<input name="homeLink" id="jshomeLink" type="checkbox" value="1" '.($this->getDbField('homeLink')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jshomeLink">'.$Language->get('Show home link').'</label>';
$html .= '</div>';

View File

@ -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 .= '</div>';
$html .= '<div>';
$html .= '<input name="autosave" id="jsautosave" type="checkbox" value="true" '.($this->getDbField('autosave')?'checked':'').'>';
$html .= '<input type="hidden" name="autosave" value="0">';
$html .= '<input name="autosave" id="jsautosave" type="checkbox" value="1" '.($this->getDbField('autosave')?'checked':'').'>';
$html .= '<label class="forCheckbox" for="jsautosave">'.$Language->get('Autosave').'</label>';
$html .= '</div>';