API plugin and changes on plugins system
This commit is contained in:
parent
81eaf4cc06
commit
2aed08be5f
|
@ -7,7 +7,7 @@ Bludit is a simple web application to make your own **blog** or **site** in seco
|
||||||
- [Documentation](https://docs.bludit.com)
|
- [Documentation](https://docs.bludit.com)
|
||||||
- [Help and Support](https://forum.bludit.com)
|
- [Help and Support](https://forum.bludit.com)
|
||||||
- [Plugins](https://plugins.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)
|
- [More plugins and themes](https://forum.bludit.com/viewforum.php?f=14)
|
||||||
|
|
||||||
Social networks
|
Social networks
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
# varlogdiego
|
|
||||||
|
|
||||||
tes
|
|
|
@ -288,7 +288,7 @@ class Content {
|
||||||
return '/'.$htmlPath.'/'.$tmp;
|
return '/'.$htmlPath.'/'.$tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function json()
|
public function json($returnsArray=false)
|
||||||
{
|
{
|
||||||
$tmp['key'] = $this->key();
|
$tmp['key'] = $this->key();
|
||||||
$tmp['title'] = $this->title();
|
$tmp['title'] = $this->title();
|
||||||
|
@ -298,6 +298,10 @@ class Content {
|
||||||
$tmp['date'] = $this->dateRaw();
|
$tmp['date'] = $this->dateRaw();
|
||||||
$tmp['permalink'] = $this->permalink(true);
|
$tmp['permalink'] = $this->permalink(true);
|
||||||
|
|
||||||
|
if($returnsArray) {
|
||||||
|
return $tmp;
|
||||||
|
}
|
||||||
|
|
||||||
return json_encode($tmp);
|
return json_encode($tmp);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -105,7 +105,7 @@ class Plugin {
|
||||||
|
|
||||||
public function setDb($args)
|
public function setDb($args)
|
||||||
{
|
{
|
||||||
$tmp = array();
|
$tmp = $this->db;
|
||||||
|
|
||||||
foreach($this->dbFields as $key=>$value)
|
foreach($this->dbFields as $key=>$value)
|
||||||
{
|
{
|
||||||
|
@ -120,10 +120,6 @@ class Plugin {
|
||||||
// Set value
|
// Set value
|
||||||
$tmp[$key] = $tmpValue;
|
$tmp[$key] = $tmpValue;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
$tmp[$key] = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db = $tmp;
|
$this->db = $tmp;
|
||||||
|
@ -186,7 +182,7 @@ class Plugin {
|
||||||
return false;
|
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);
|
mkdir(PATH_PLUGINS_DATABASES.$this->directoryName, 0755, true);
|
||||||
|
|
||||||
// Create database
|
// Create database
|
||||||
|
|
|
@ -658,3 +658,7 @@ div.plugin-links > span.separator {
|
||||||
margin-bottom: 0px !important;
|
margin-bottom: 0px !important;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#jsformplugin p {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
|
@ -14,6 +14,14 @@ class Security extends dbJSON
|
||||||
parent::__construct(PATH_DATABASES.'security.php');
|
parent::__construct(PATH_DATABASES.'security.php');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Authentication key
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
public function key1()
|
||||||
|
{
|
||||||
|
return $this->db['key1'];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ====================================================
|
// ====================================================
|
||||||
// TOKEN FOR CSRF
|
// TOKEN FOR CSRF
|
||||||
// ====================================================
|
// ====================================================
|
||||||
|
|
|
@ -4,9 +4,15 @@ class pluginAPI extends Plugin {
|
||||||
|
|
||||||
public function init()
|
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(
|
$this->dbFields = array(
|
||||||
'ping'=>false,
|
'ping'=>0, // 0 = false, 1 = true
|
||||||
'authKey'=>''
|
'authKey'=>$authKey, // Private key
|
||||||
|
'showAllAmount'=>15 // Amount of posts and pages for return
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,14 +21,36 @@ class pluginAPI extends Plugin {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
$html .= '<div>';
|
$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 .= '<div>';
|
$html .= '<div>';
|
||||||
$html .= '<input name="ping" id="jsping" type="checkbox" value="true" '.($this->getDbField('ping')?'checked':'').'>';
|
$html .= '<p><b>Authorization Key:</b> '.$this->getDbField('authKey').'</p>';
|
||||||
$html .= '<label class="forCheckbox" for="jsping">Ping Bludit.com</label>';
|
$html .= '<div class="tip">This key is private, do not share it with anyone.</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 .= '<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;
|
return $html;
|
||||||
}
|
}
|
||||||
|
@ -35,8 +63,12 @@ class pluginAPI extends Plugin {
|
||||||
private function ping()
|
private function ping()
|
||||||
{
|
{
|
||||||
if($this->getDbField('ping')) {
|
if($this->getDbField('ping')) {
|
||||||
|
|
||||||
|
// Get the authentication key
|
||||||
|
$authKey = $this->getDbField('authKey');
|
||||||
|
|
||||||
// Just a request HTTP with the website URL
|
// 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();
|
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)
|
private function getPage($key)
|
||||||
{
|
{
|
||||||
// Generate the object Page
|
// Generate the object Page
|
||||||
|
@ -91,16 +136,18 @@ class pluginAPI extends Plugin {
|
||||||
// ------------------------------------------------------------
|
// ------------------------------------------------------------
|
||||||
// show post {post slug}
|
// show post {post slug}
|
||||||
// show page {page slug}
|
// show page {page slug}
|
||||||
// show all posts
|
// show all posts {AUTH KEY}
|
||||||
// show all pages
|
// show all pages {AUTH KEY}
|
||||||
|
|
||||||
// Get parameters
|
// Get parameters
|
||||||
$parameters = explode('/', $URI);
|
$parameters = explode('/', $URI);
|
||||||
|
|
||||||
// Check parameters are sended
|
for($i=0; $i<4; $i++) {
|
||||||
for($i=0; $i<3; $i++) {
|
|
||||||
if(empty($parameters[$i])) {
|
if(empty($parameters[$i])) {
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
// Sanizite
|
||||||
|
$parameters[$i] = Sanitize::html($parameters[$i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,15 +158,34 @@ class pluginAPI extends Plugin {
|
||||||
'message'=>'Check the parameters'
|
'message'=>'Check the parameters'
|
||||||
));
|
));
|
||||||
|
|
||||||
if($parameters[0] === 'show') {
|
if($parameters[0]==='show') {
|
||||||
|
|
||||||
$key = $parameters[2];
|
if($parameters[1]==='all') {
|
||||||
|
|
||||||
if($parameters[1] === 'post') {
|
// Authentication key from the URI
|
||||||
$json = $this->getPost($key);
|
$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') {
|
elseif($parameters[1]==='post' || $parameters[1]==='page') {
|
||||||
$json = $this->getPage($key);
|
|
||||||
|
$key = $parameters[2];
|
||||||
|
|
||||||
|
if($parameters[1] === 'post') {
|
||||||
|
$json = $this->getPost($key);
|
||||||
|
}
|
||||||
|
elseif($parameters[1] === 'page') {
|
||||||
|
$json = $this->getPage($key);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,9 @@ class pluginDisqus extends Plugin {
|
||||||
{
|
{
|
||||||
$this->dbFields = array(
|
$this->dbFields = array(
|
||||||
'shortname'=>'',
|
'shortname'=>'',
|
||||||
'enablePages'=>false,
|
'enablePages'=>0,
|
||||||
'enablePosts'=>false,
|
'enablePosts'=>0,
|
||||||
'enableDefaultHomePage'=>false
|
'enableDefaultHomePage'=>1
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,17 +44,20 @@ class pluginDisqus extends Plugin {
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
$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 .= '<label class="forCheckbox" for="jsenablePages">'.$Language->get('Enable Disqus on pages').'</label>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
$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 .= '<label class="forCheckbox" for="jsenablePosts">'.$Language->get('Enable Disqus on posts').'</label>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
$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 .= '<label class="forCheckbox" for="jsenableDefaultHomePage">'.$Language->get('Enable Disqus on default home page').'</label>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ class pluginMaintenanceMode extends Plugin {
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->dbFields = array(
|
$this->dbFields = array(
|
||||||
'enable'=>false,
|
'enable'=>0,
|
||||||
'message'=>'Temporarily down for maintenance.'
|
'message'=>'Temporarily down for maintenance.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,8 @@ class pluginMaintenanceMode extends Plugin {
|
||||||
global $Language;
|
global $Language;
|
||||||
|
|
||||||
$html = '<div>';
|
$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 .= '<label class="forCheckbox" for="jsenable">'.$Language->get('Enable maintenance mode').'</label>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,6 @@ class pluginOpenGraph extends Plugin {
|
||||||
$dom->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'.$content);
|
$dom->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'.$content);
|
||||||
$finder = new DomXPath($dom);
|
$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");
|
$images = $finder->query("//img");
|
||||||
|
|
||||||
if($images->length>0)
|
if($images->length>0)
|
||||||
|
|
|
@ -5,7 +5,7 @@ class pluginPages extends Plugin {
|
||||||
public function init()
|
public function init()
|
||||||
{
|
{
|
||||||
$this->dbFields = array(
|
$this->dbFields = array(
|
||||||
'homeLink'=>true,
|
'homeLink'=>1,
|
||||||
'label'=>'Pages'
|
'label'=>'Pages'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,8 @@ class pluginPages extends Plugin {
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
$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 .= '<label class="forCheckbox" for="jshomeLink">'.$Language->get('Show home link').'</label>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ class pluginsimpleMDE extends Plugin {
|
||||||
$this->dbFields = array(
|
$this->dbFields = array(
|
||||||
'tabSize'=>'2',
|
'tabSize'=>'2',
|
||||||
'toolbar'=>'"bold", "italic", "heading", "|", "quote", "unordered-list", "|", "link", "image", "code", "horizontal-rule", "|", "preview", "side-by-side", "fullscreen", "guide"',
|
'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 .= '<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 .= '<label class="forCheckbox" for="jsautosave">'.$Language->get('Autosave').'</label>';
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue