🔥 Remove the remote-content plugin
This commit is contained in:
parent
9a4e606607
commit
e76f511738
13 changed files with 0 additions and 336 deletions
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"complete-url-of-the-zip-file": "Den komplette URL sti, til der hvor zip filen befinder sig.",
|
|
||||||
"plugin-data": {
|
|
||||||
"description": "Denne udvidelse giver en nem måde at få indholdet fra dit websted uploadet til Github eller lignende service, og være fuld synkroniseret med din Koblog installation.",
|
|
||||||
"name": "Remote Content"
|
|
||||||
},
|
|
||||||
"source": "Kilde",
|
|
||||||
"try-webhook": "Prøv webhook'et",
|
|
||||||
"webhook": "Webhook"
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Remote Content",
|
|
||||||
"description": "Das Plugin snychronisiert die Inhalte eines Repository wie GitHub mit einer Koblog-Installation."
|
|
||||||
},
|
|
||||||
"webhook": "Webhook",
|
|
||||||
"source": "Quelle",
|
|
||||||
"try-webhook": "Webhook testen",
|
|
||||||
"complete-url-of-the-zip-file": "Vollständiger URL des ZIP-Archivs."}
|
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Remote Content",
|
|
||||||
"description": "Das Plugin snychronisiert die Inhalte eines Repository wie GitHub mit einer Koblog-Installation."
|
|
||||||
},
|
|
||||||
"webhook": "Webhook",
|
|
||||||
"source": "Quelle",
|
|
||||||
"try-webhook": "Webhook testen",
|
|
||||||
"complete-url-of-the-zip-file": "Vollständiger URL des ZIP-Archivs."}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Remote Content",
|
|
||||||
"description": "This plugin provides an easy way to have the content of your site on Github or similar and in turn is synchronized with your Koblog."
|
|
||||||
},
|
|
||||||
"webhook": "Webhook",
|
|
||||||
"source": "Source",
|
|
||||||
"try-webhook": "Try webhook",
|
|
||||||
"complete-url-of-the-zip-file": "Complete URL of the zip file."
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Contenido remoto",
|
|
||||||
"description": "Este plugin provee una forma facil de tener el contenido de tu sitio en Github o similar y a su vez esta sincronizado con tu Koblog."
|
|
||||||
},
|
|
||||||
"webhook": "Webhook",
|
|
||||||
"source": "Origen",
|
|
||||||
"try-webhook": "Probar webhook",
|
|
||||||
"complete-url-of-the-zip-file": "URL completa del archivo zip."
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "محتوای راه دور",
|
|
||||||
"description": "این افزونه یک راه آسان برای داشتن محتوای سایت شما در Github یا مشابه دارد و به نوبه خود، با بلودیت شما هماهنگ شده است ."
|
|
||||||
},
|
|
||||||
"webhook": "Webhook",
|
|
||||||
"source": "منبع",
|
|
||||||
"try-webhook": "امتحان webhook",
|
|
||||||
"complete-url-of-the-zip-file": "آدرس وب کامل فایل زیپ."
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Contenu distant",
|
|
||||||
"description": "Ce plugin fournit un moyen facile d'avoir le contenu de votre site sur Github ou similaire et à son tour est synchronisé avec votre Koblog."
|
|
||||||
},
|
|
||||||
"webhook": "Webhook",
|
|
||||||
"source": "Source",
|
|
||||||
"try-webhook": "Tester le webhook",
|
|
||||||
"complete-url-of-the-zip-file": "URL complète du fichier zip."
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Contenuto remoto",
|
|
||||||
"description": "Questo plugin offre un modo semplice di avere il contenuto del proprio sito su Github e simili e di tenerli sincronizzati con Koblog."
|
|
||||||
},
|
|
||||||
"webhook": "Webhook",
|
|
||||||
"source": "Sorgente",
|
|
||||||
"try-webhook": "Prova webhook",
|
|
||||||
"complete-url-of-the-zip-file": "URL completo del file zipe."
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Remote Content",
|
|
||||||
"description": "This plugin provides an easy way to have the content of your site on Github or similar and in turn is synchronized with your Koblog."
|
|
||||||
},
|
|
||||||
"webhook": "Webhook",
|
|
||||||
"source": "ソース",
|
|
||||||
"try-webhook": "Try webhook",
|
|
||||||
"complete-url-of-the-zip-file": "Complete URL of the zip file."
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Externe Inhoud",
|
|
||||||
"description": "Met deze plugin is het eenvoudig om inhoud voor de website op GitHub of soortgelijke bronnen te beheren en vervolgens te synchroniseren met Koblog."
|
|
||||||
},
|
|
||||||
"webhook": "Web-hook",
|
|
||||||
"source": "Bron",
|
|
||||||
"try-webhook": "Web-hook testen",
|
|
||||||
"complete-url-of-the-zip-file": "Complete URL van het .zip-bestand."
|
|
||||||
}
|
|
|
@ -1,11 +0,0 @@
|
||||||
{
|
|
||||||
"plugin-data":
|
|
||||||
{
|
|
||||||
"name": "Remote Content",
|
|
||||||
"description": "Этот плагин обеспечивает простой способ синхронизации вашего сайта и Github или аналогичной платформы."
|
|
||||||
},
|
|
||||||
"webhook": "Вебхук",
|
|
||||||
"source": "Источник",
|
|
||||||
"try-webhook": "Попробовать этот вебхук",
|
|
||||||
"complete-url-of-the-zip-file": "Полный URL-адрес zip-файла."
|
|
||||||
}
|
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"author": "Koblog",
|
|
||||||
"email": "",
|
|
||||||
"website": "https://plugins.koblog.com/plugin/remote-content",
|
|
||||||
"version": "kb_0.0.1",
|
|
||||||
"releaseDate": "2024-08-23",
|
|
||||||
"license": "MIT",
|
|
||||||
"compatible": "kb_0.0.1",
|
|
||||||
"notes": ""
|
|
||||||
}
|
|
|
@ -1,208 +0,0 @@
|
||||||
<?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' => ''
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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>';
|
|
||||||
$html .= '<label>' . $language->get('Webhook') . '</label>';
|
|
||||||
$html .= '<input id="jswebhook" name="webhook" type="text" dir="auto" 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" dir="auto" value="' . $this->getValue('source') . '" placeholder="https://">';
|
|
||||||
$html .= '<span class="tip">' . $language->get('Complete URL of the zip file') . '</span>';
|
|
||||||
$html .= '</div>';
|
|
||||||
|
|
||||||
$html .= '<hr>';
|
|
||||||
$html .= '<div>';
|
|
||||||
$html .= '<button type="button" id="jstryWebhook" class="btn btn-primary" onclick="tryWebhook()">' . $language->get('Try webhook') . '</button>';
|
|
||||||
$html .= <<<EOF
|
|
||||||
<script>
|
|
||||||
function tryWebhook() {
|
|
||||||
var webhook = document.getElementById("jswebhook").value;
|
|
||||||
window.open(DOMAIN_BASE+webhook, '_blank');
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
EOF;
|
|
||||||
$html .= '</div>';
|
|
||||||
|
|
||||||
return $html;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function beforeAll()
|
|
||||||
{
|
|
||||||
// Check Webhook
|
|
||||||
$webhook = $this->getValue('webhook');
|
|
||||||
if ($this->webhook($webhook)) {
|
|
||||||
$this->cleanUp();
|
|
||||||
|
|
||||||
// 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, DIR_PERMISSIONS, true);
|
|
||||||
mkdir(PATH_UPLOADS, DIR_PERMISSIONS, true);
|
|
||||||
mkdir(PATH_UPLOADS_PROFILES, DIR_PERMISSIONS, true);
|
|
||||||
mkdir(PATH_UPLOADS_THUMBNAILS, DIR_PERMISSIONS, true);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function cleanUp()
|
|
||||||
{
|
|
||||||
$workspace = $this->workspace();
|
|
||||||
Filesystem::deleteRecursive($workspace . DS);
|
|
||||||
mkdir($workspace, DIR_PERMISSIONS, 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')) {
|
|
||||||
$parentList = Filesystem::listDirectories($root . DS . 'pages' . DS);
|
|
||||||
foreach ($parentList as $parentDirectory) {
|
|
||||||
$parentKey = basename($parentDirectory);
|
|
||||||
if (Filesystem::fileExists($parentDirectory . DS . 'index.md')) {
|
|
||||||
$row = $this->parsePage($parentDirectory . DS . 'index.md');
|
|
||||||
$row['slug'] = $parentKey;
|
|
||||||
$pages->add($row);
|
|
||||||
}
|
|
||||||
|
|
||||||
$childList = Filesystem::listDirectories($parentDirectory . DS);
|
|
||||||
foreach ($childList as $childDirectory) {
|
|
||||||
$childKey = basename($childDirectory);
|
|
||||||
if (Filesystem::fileExists($childDirectory . DS . 'index.md')) {
|
|
||||||
$row = $this->parsePage($childDirectory . DS . 'index.md');
|
|
||||||
$row['slug'] = $childKey;
|
|
||||||
$row['parent'] = $parentKey;
|
|
||||||
$pages->add($row);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Theme::plugins('afterPageCreate');
|
|
||||||
reindexCategories();
|
|
||||||
reindexTags();
|
|
||||||
reindexAuthors();
|
|
||||||
reindexArchives();
|
|
||||||
reindexKinds();
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = $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…
Add table
Reference in a new issue