From d62e19707bc640e8bd4fd72c54678840cb741921 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Wed, 5 Sep 2018 22:55:14 +0200 Subject: [PATCH] workspaces directory for plugins --- .htaccess | 8 +++---- bl-kernel/abstract/plugin.class.php | 20 ++++++++++++----- .../admin/controllers/install-plugin.php | 2 +- bl-kernel/boot/init.php | 1 + bl-kernel/pagex.class.php | 5 +++-- bl-plugins/backup/plugin.php | 22 ------------------- bl-plugins/rss/plugin.php | 6 ++--- bl-plugins/sitemap/plugin.php | 4 ++-- install.php | 11 ++++++++-- 9 files changed, 38 insertions(+), 41 deletions(-) diff --git a/.htaccess b/.htaccess index cefe7dbe..7a181871 100644 --- a/.htaccess +++ b/.htaccess @@ -6,13 +6,13 @@ AddDefaultCharset UTF-8 RewriteEngine on # Base directory -#RewriteBase / +# RewriteBase / -# Deny direct access to .txt files -RewriteRule ^bl-content/(.*)\.txt$ - [R=404,L] +# Deny direct access to the next directories +RewriteRule ^bl-content/(databases|workspaces|pages|tmp|)/.*$ - [R=404,L] # All URL process by index.php RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*) index.php [PT,L] - + \ No newline at end of file diff --git a/bl-kernel/abstract/plugin.class.php b/bl-kernel/abstract/plugin.class.php index 6409a701..62d82d79 100644 --- a/bl-kernel/abstract/plugin.class.php +++ b/bl-kernel/abstract/plugin.class.php @@ -214,12 +214,14 @@ class Plugin { return false; } - // Create plugin directory for databases and other files + // Create workspace + $workspace = $this->workspace(); + mkdir($workspace, 0755, true); + + // Create plugin directory for the database mkdir(PATH_PLUGINS_DATABASES.$this->directoryName, 0755, true); - // Create database $this->dbFields['position'] = $position; - // Sanitize default values to store in the file foreach ($this->dbFields as $key=>$value) { $value = Sanitize::html($value); @@ -227,13 +229,21 @@ class Plugin { $this->db[$key] = $value; } + // Create the database return $this->save(); } public function uninstall() { + // Delete database $path = PATH_PLUGINS_DATABASES.$this->directoryName; - return Filesystem::deleteRecursive($path); + Filesystem::deleteRecursive($path); + + // Delete workspace + $workspace = $this->workspace(); + Filesystem::deleteRecursive($workspace); + + return true; } public function installed() @@ -243,7 +253,7 @@ class Plugin { public function workspace() { - return PATH_PLUGINS_DATABASES.$this->directoryName.DS; + return PATH_WORKSPACES.$this->directoryName.DS; } public function init() diff --git a/bl-kernel/admin/controllers/install-plugin.php b/bl-kernel/admin/controllers/install-plugin.php index 560c3a14..eb5a8832 100644 --- a/bl-kernel/admin/controllers/install-plugin.php +++ b/bl-kernel/admin/controllers/install-plugin.php @@ -22,7 +22,7 @@ checkRole(array('admin')); // Main after POST // ============================================================================ $pluginClassName = $layout['parameters']; -if (activatePlugin($pluginClassName)===false) { +if (!activatePlugin($pluginClassName)) { Log::set('Fail when try to activate the plugin.', LOG_TYPE_ERROR); } diff --git a/bl-kernel/boot/init.php b/bl-kernel/boot/init.php index 875f44ea..f76dbe96 100644 --- a/bl-kernel/boot/init.php +++ b/bl-kernel/boot/init.php @@ -38,6 +38,7 @@ define('PATH_DATABASES', PATH_CONTENT.'databases'.DS); define('PATH_PLUGINS_DATABASES', PATH_CONTENT.'databases'.DS.'plugins'.DS); define('PATH_TMP', PATH_CONTENT.'tmp'.DS); define('PATH_UPLOADS', PATH_CONTENT.'uploads'.DS); +define('PATH_WORKSPACES', PATH_CONTENT.'workspaces'.DS); define('PATH_UPLOADS_PROFILES', PATH_UPLOADS.'profiles'.DS); define('PATH_UPLOADS_THUMBNAILS', PATH_UPLOADS.'thumbnails'.DS); diff --git a/bl-kernel/pagex.class.php b/bl-kernel/pagex.class.php index 168c365d..0eb04b19 100644 --- a/bl-kernel/pagex.class.php +++ b/bl-kernel/pagex.class.php @@ -68,8 +68,9 @@ class Page { public function content($sanitize=false) { // If already set the content, return it - if (!empty($this->getValue('content'))) { - return $this->getValue('content'); + $content = $this->getValue('content'); + if (!empty($content)) { + return $content; } $contentRaw = $this->contentRaw(); diff --git a/bl-plugins/backup/plugin.php b/bl-plugins/backup/plugin.php index 2cbd2d52..e0f26acb 100644 --- a/bl-plugins/backup/plugin.php +++ b/bl-plugins/backup/plugin.php @@ -21,28 +21,6 @@ class pluginBackup extends Plugin { $this->zip = extension_loaded('zip'); } - // Install the plugin and create the workspace directory - public function install($position=0) - { - parent::install($position); - $workspace = $this->workspace(); - return mkdir($workspace, 0755, true); - } - - // Uninstall the plugin and delete the workspace directory - public function uninstall() - { - parent::uninstall(); - $workspace = $this->workspace(); - return Filesystem::deleteRecursive($workspace); - } - - // Redefine workspace - public function workspace() - { - return PATH_CONTENT.'backup'.DS; - } - public function post() { if (isset($_POST['createBackup'])) { diff --git a/bl-plugins/rss/plugin.php b/bl-plugins/rss/plugin.php index 504227c1..a7a57003 100644 --- a/bl-plugins/rss/plugin.php +++ b/bl-plugins/rss/plugin.php @@ -59,7 +59,7 @@ class pluginRSS extends Plugin { $xml .= ''.$site->description().''; // Get keys of pages - foreach($list as $pageKey) { + foreach ($list as $pageKey) { try { // Create the page object from the page key $page = new Page($pageKey); @@ -81,13 +81,13 @@ class pluginRSS extends Plugin { $doc = new DOMDocument(); $doc->formatOutput = true; $doc->loadXML($xml); - $doc->save($this->workspace().'rss.xml'); + return $doc->save($this->workspace().'rss.xml'); } public function install($position=0) { parent::install($position); - $this->createXML(); + return $this->createXML(); } public function post() diff --git a/bl-plugins/sitemap/plugin.php b/bl-plugins/sitemap/plugin.php index 0f1067a9..c212bef6 100644 --- a/bl-plugins/sitemap/plugin.php +++ b/bl-plugins/sitemap/plugin.php @@ -62,13 +62,13 @@ class pluginSitemap extends Plugin { $doc = new DOMDocument(); $doc->formatOutput = true; $doc->loadXML($xml); - $doc->save($this->workspace().'sitemap.xml'); + return $doc->save($this->workspace().'sitemap.xml'); } public function install($position=0) { parent::install($position); - $this->createXML(); + return $this->createXML(); } public function post() diff --git a/install.php b/install.php index d9ad62f4..0e248198 100644 --- a/install.php +++ b/install.php @@ -49,6 +49,7 @@ define('PATH_LANGUAGES', PATH_ROOT.'bl-languages'.DS); define('PATH_UPLOADS', PATH_CONTENT.'uploads'.DS); define('PATH_TMP', PATH_CONTENT.'tmp'.DS); define('PATH_PAGES', PATH_CONTENT.'pages'.DS); +define('PATH_WORKSPACES', PATH_CONTENT.'workspaces'.DS); define('PATH_DATABASES', PATH_CONTENT.'databases'.DS); define('PATH_PLUGINS_DATABASES',PATH_CONTENT.'databases'.DS.'plugins'.DS); define('PATH_UPLOADS_PROFILES', PATH_UPLOADS.'profiles'.DS); @@ -208,8 +209,8 @@ RewriteEngine on # Base directory RewriteBase '.HTML_PATH_ROOT.' -# Deny direct access to .txt files -RewriteRule ^bl-content/(.*)\.txt$ - [R=404,L] +# Deny direct access to the next directories +RewriteRule ^bl-content/(databases|workspaces|pages|tmp|)/.*$ - [R=404,L] # All URL process by index.php RewriteCond %{REQUEST_FILENAME} !-f @@ -299,6 +300,11 @@ function install($adminPassword, $timezone) error_log('[ERROR] '.$errorText, 0); } + if (!mkdir(PATH_WORKSPACES, DIR_PERMISSIONS, true)) { + $errorText = 'Error when trying to created the directory=>'.PATH_WORKSPACES; + error_log('[ERROR] '.$errorText, 0); + } + // ============================================================================ // Create files // ============================================================================ @@ -493,6 +499,7 @@ function install($adminPassword, $timezone) JSON_PRETTY_PRINT), LOCK_EX ); + mkdir(PATH_WORKSPACES.'simple-stats', DIR_PERMISSIONS, true); // File plugins/tinymce/db.php file_put_contents(