remove cli mode functions
This commit is contained in:
parent
e65a26d66a
commit
b85ecdae89
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,7 +3,6 @@ dbgenerator.php
|
||||
bl-content/*
|
||||
bl-plugins/timemachine
|
||||
bl-plugins/timemachine-x
|
||||
bl-plugins/remote-content
|
||||
bl-plugins/discovery
|
||||
bl-plugins/updater
|
||||
bl-kernel/bludit.pro.php
|
||||
|
@ -265,6 +265,12 @@ function changePluginsPosition($pluginClassList) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
Create a new page
|
||||
|
||||
The array $args support all the keys from variable $dbFields of the class pages.class.php
|
||||
If you don't pass all the keys, the default values are used, the default values are from $dbFields in the class pages.class.php
|
||||
*/
|
||||
function createPage($args) {
|
||||
global $pages;
|
||||
global $syslog;
|
||||
|
@ -51,7 +51,7 @@ class Pages extends dbJSON {
|
||||
|
||||
// Create a new page
|
||||
// This function returns the key of the new page
|
||||
public function add($args, $climode=false)
|
||||
public function add($args)
|
||||
{
|
||||
$row = array();
|
||||
|
||||
@ -116,18 +116,16 @@ class Pages extends dbJSON {
|
||||
$row['type'] = 'scheduled';
|
||||
}
|
||||
|
||||
if ($climode===false) {
|
||||
// Create the directory
|
||||
if( Filesystem::mkdir(PATH_PAGES.$key, true) === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the directory ['.PATH_PAGES.$key.']',LOG_TYPE_ERROR);
|
||||
return false;
|
||||
}
|
||||
// Create the directory
|
||||
if( Filesystem::mkdir(PATH_PAGES.$key, true) === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the directory ['.PATH_PAGES.$key.']',LOG_TYPE_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the index.txt and save the file
|
||||
if( file_put_contents(PATH_PAGES.$key.DS.FILENAME, $contentRaw) === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the content in the file ['.FILENAME.']',LOG_TYPE_ERROR);
|
||||
return false;
|
||||
}
|
||||
// Create the index.txt and save the file
|
||||
if( file_put_contents(PATH_PAGES.$key.DS.FILENAME, $contentRaw) === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to create the content in the file ['.FILENAME.']',LOG_TYPE_ERROR);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Checksum MD5
|
||||
@ -145,7 +143,7 @@ class Pages extends dbJSON {
|
||||
return $key;
|
||||
}
|
||||
|
||||
public function edit($args, $climode=false)
|
||||
public function edit($args)
|
||||
{
|
||||
// Old key
|
||||
// This variable is not belong to the database so is not defined in $row
|
||||
@ -213,22 +211,20 @@ class Pages extends dbJSON {
|
||||
$row['type'] = 'scheduled';
|
||||
}
|
||||
|
||||
if ($climode===false) {
|
||||
// Move the directory from old key to new key.
|
||||
if ($newKey!==$key) {
|
||||
if( Filesystem::mv(PATH_PAGES.$key, PATH_PAGES.$newKey) === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to move the directory to '.PATH_PAGES.$newKey);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Make the index.txt and save the file.
|
||||
if (file_put_contents(PATH_PAGES.$newKey.DS.FILENAME, $contentRaw)===false) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to put the content in the file '.FILENAME);
|
||||
// Move the directory from old key to new key.
|
||||
if ($newKey!==$key) {
|
||||
if( Filesystem::mv(PATH_PAGES.$key, PATH_PAGES.$newKey) === false ) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to move the directory to '.PATH_PAGES.$newKey);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Make the index.txt and save the file.
|
||||
if (file_put_contents(PATH_PAGES.$newKey.DS.FILENAME, $contentRaw)===false) {
|
||||
Log::set(__METHOD__.LOG_SEP.'Error occurred when trying to put the content in the file '.FILENAME);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove the old key
|
||||
unset( $this->db[$key] );
|
||||
|
||||
|
12
bl-plugins/remote-content/languages/en.json
Normal file
12
bl-plugins/remote-content/languages/en.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"plugin-data":
|
||||
{
|
||||
"name": "Remote Content",
|
||||
"description": ""
|
||||
},
|
||||
"webhook": "Webhook",
|
||||
"source": "Source",
|
||||
"keep-content": "Keep content",
|
||||
"complete-url-of-the-zip-file": "Complete URL of the zip file.",
|
||||
"if-you-want-to-keep-the-content-generate-via-the-user-interface-enable-this-field": "If you want to keep the content generate via the user interface enable this field."
|
||||
}
|
12
bl-plugins/remote-content/languages/es.json
Normal file
12
bl-plugins/remote-content/languages/es.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"plugin-data":
|
||||
{
|
||||
"name": "Contenido remoto",
|
||||
"description": ""
|
||||
},
|
||||
"webhook": "Webhook",
|
||||
"source": "Source",
|
||||
"keep-content": "Keep content",
|
||||
"complete-url-of-the-zip-file": "Complete URL of the zip file.",
|
||||
"if-you-want-to-keep-the-content-generate-via-the-user-interface-enable-this-field": "If you want to keep the content generate via the user interface enable this field."
|
||||
}
|
10
bl-plugins/remote-content/metadata.json
Normal file
10
bl-plugins/remote-content/metadata.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"author": "Bludit",
|
||||
"email": "",
|
||||
"website": "https://plugins.bludit.com/plugin/remote-content",
|
||||
"version": "3.0",
|
||||
"releaseDate": "2018-09-14",
|
||||
"license": "MIT",
|
||||
"compatible": "3.0",
|
||||
"notes": ""
|
||||
}
|
176
bl-plugins/remote-content/plugin.php
Normal file
176
bl-plugins/remote-content/plugin.php
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
class pluginRemoteContent extends Plugin {
|
||||
|
||||
public function init()
|
||||
{
|
||||
// Generate a random string for the webhook
|
||||
$randomWebhook = uniqid();
|
||||
|
||||
// Key and value for the database of the plugin
|
||||
$this->dbFields = array(
|
||||
'webhook'=>$randomWebhook,
|
||||
'source'=>'https://github.com/bludit/remote-content-example/archive/master.zip'
|
||||
);
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
global $Language;
|
||||
|
||||
if (extension_loaded('zip')===false) {
|
||||
$this->formButtons = false;
|
||||
return '<div class="alert alert-success">'.$Language->get('the-extension-zip-is-not-installed').'</div>';
|
||||
}
|
||||
|
||||
$html = '<div class="alert alert-primary" role="alert">';
|
||||
$html .= $this->description();
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<label>'.$Language->get('Webhook').'</label>';
|
||||
$html .= '<input id="jswebhook" name="webhook" type="text" value="'.$this->getValue('webhook').'">';
|
||||
$html .= '<span class="tip">'.DOMAIN_BASE.$this->getValue('webhook').'</span>';
|
||||
$html .= '</div>';
|
||||
|
||||
$html .= '<div>';
|
||||
$html .= '<label>'.$Language->get('Source').'</label>';
|
||||
$html .= '<input id="jssource" name="source" type="text" value="'.$this->getValue('source').'" placeholder="https://">';
|
||||
$html .= '<span class="tip">'.$Language->get('Complete URL of the zip file').'</span>';
|
||||
$html .= '</div>';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public function beforeAll()
|
||||
{
|
||||
// Check Webhook
|
||||
$webhook = $this->getValue('webhook');
|
||||
if ($this->webhook($webhook)) {
|
||||
// Download files
|
||||
//$this->downloadFiles();
|
||||
|
||||
// Delete the current content
|
||||
$this->deleteContent();
|
||||
|
||||
// Generate the new content
|
||||
$this->generateContent();
|
||||
|
||||
// End request
|
||||
$this->response(array('status'=>'0'));
|
||||
}
|
||||
}
|
||||
|
||||
private function downloadFiles()
|
||||
{
|
||||
// Download the zip file
|
||||
Log::set('Plugin Remote Content'.LOG_SEP.'Downloading the zip file.');
|
||||
$source = $this->getValue('source');
|
||||
$destinationPath = $this->workspace();
|
||||
$destinationFile = $destinationPath.'content.zip';
|
||||
TCP::download($source, $destinationFile);
|
||||
|
||||
// Uncompress the zip file
|
||||
Log::set('Plugin Remote Content'.LOG_SEP.'Uncompress the zip file.');
|
||||
$zip = new ZipArchive;
|
||||
if ($zip->open($destinationFile)===true) {
|
||||
$zip->extractTo($destinationPath);
|
||||
$zip->close();
|
||||
}
|
||||
|
||||
// Delete the zip file
|
||||
unlink($destinationFile);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Delete the page and uploads directories from bl-content
|
||||
private function deleteContent()
|
||||
{
|
||||
// Clean the page database
|
||||
global $pages;
|
||||
$pages->db = array();
|
||||
|
||||
Filesystem::deleteRecursive(PATH_PAGES);
|
||||
Filesystem::deleteRecursive(PATH_UPLOADS);
|
||||
mkdir(PATH_PAGES, 0755, true);
|
||||
mkdir(PATH_UPLOADS, 0755, true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function generateContent()
|
||||
{
|
||||
global $pages;
|
||||
|
||||
$root = Filesystem::listDirectories($this->workspace());
|
||||
$root = $root[0]; // first directory created by the unzip
|
||||
|
||||
// For each page inside the pages directory
|
||||
// Parse the page and add to the database
|
||||
if (Filesystem::directoryExists($root.DS.'pages')) {
|
||||
$pageList = Filesystem::listDirectories($root.DS.'pages'.DS);
|
||||
foreach ($pageList as $directory) {
|
||||
if (Filesystem::fileExists($directory.DS.'index.md')) {
|
||||
// Parse the page from the file
|
||||
$row = $this->parsePage($directory.DS.'index.md');
|
||||
|
||||
// Add the page to the database
|
||||
$pages->add($row);
|
||||
|
||||
// Call the plugins after page created
|
||||
Theme::plugins('afterPageCreate');
|
||||
|
||||
// Reindex databases
|
||||
reindexCategories();
|
||||
reindextags();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function response($data=array())
|
||||
{
|
||||
$json = json_encode($data);
|
||||
header('Content-Type: application/json');
|
||||
exit($json);
|
||||
}
|
||||
|
||||
private function parsePage($filename)
|
||||
{
|
||||
$lines = file($filename);
|
||||
$row = array();
|
||||
|
||||
// Title
|
||||
$title = ltrim($lines[0], '#'); // Remove the first #
|
||||
$title = trim($title);
|
||||
unset($lines[0]);
|
||||
$row['title'] = $title;
|
||||
|
||||
foreach ($lines as $key=>$line) {
|
||||
if (Text::startsWith($line, '<!--')) {
|
||||
$line = preg_replace('/<!\-\-/', '', $line);
|
||||
$line = preg_replace('/\-\->/', '', $line);
|
||||
$line = trim($line);
|
||||
|
||||
$explode = $explode = explode(':', $line, 2);
|
||||
|
||||
$field = Text::lowercase($explode[0]);
|
||||
$field = trim($field);
|
||||
unset($explode[0]);
|
||||
$row[$field] = trim($explode[1]);
|
||||
|
||||
unset($lines[$key]);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$row['content'] = implode($lines);
|
||||
$row['username'] = 'admin';
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user