workspaces directory for plugins

This commit is contained in:
Diego Najar 2018-09-05 22:55:14 +02:00
parent b5d4ceda09
commit d62e19707b
9 changed files with 38 additions and 41 deletions

View File

@ -8,8 +8,8 @@ RewriteEngine on
# Base directory # Base directory
# RewriteBase / # RewriteBase /
# Deny direct access to .txt files # Deny direct access to the next directories
RewriteRule ^bl-content/(.*)\.txt$ - [R=404,L] RewriteRule ^bl-content/(databases|workspaces|pages|tmp|)/.*$ - [R=404,L]
# All URL process by index.php # All URL process by index.php
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f

View File

@ -214,12 +214,14 @@ class Plugin {
return false; 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); mkdir(PATH_PLUGINS_DATABASES.$this->directoryName, 0755, true);
// Create database
$this->dbFields['position'] = $position; $this->dbFields['position'] = $position;
// Sanitize default values to store in the file // Sanitize default values to store in the file
foreach ($this->dbFields as $key=>$value) { foreach ($this->dbFields as $key=>$value) {
$value = Sanitize::html($value); $value = Sanitize::html($value);
@ -227,13 +229,21 @@ class Plugin {
$this->db[$key] = $value; $this->db[$key] = $value;
} }
// Create the database
return $this->save(); return $this->save();
} }
public function uninstall() public function uninstall()
{ {
// Delete database
$path = PATH_PLUGINS_DATABASES.$this->directoryName; $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() public function installed()
@ -243,7 +253,7 @@ class Plugin {
public function workspace() public function workspace()
{ {
return PATH_PLUGINS_DATABASES.$this->directoryName.DS; return PATH_WORKSPACES.$this->directoryName.DS;
} }
public function init() public function init()

View File

@ -22,7 +22,7 @@ checkRole(array('admin'));
// Main after POST // Main after POST
// ============================================================================ // ============================================================================
$pluginClassName = $layout['parameters']; $pluginClassName = $layout['parameters'];
if (activatePlugin($pluginClassName)===false) { if (!activatePlugin($pluginClassName)) {
Log::set('Fail when try to activate the plugin.', LOG_TYPE_ERROR); Log::set('Fail when try to activate the plugin.', LOG_TYPE_ERROR);
} }

View File

@ -38,6 +38,7 @@ define('PATH_DATABASES', PATH_CONTENT.'databases'.DS);
define('PATH_PLUGINS_DATABASES', PATH_CONTENT.'databases'.DS.'plugins'.DS); define('PATH_PLUGINS_DATABASES', PATH_CONTENT.'databases'.DS.'plugins'.DS);
define('PATH_TMP', PATH_CONTENT.'tmp'.DS); define('PATH_TMP', PATH_CONTENT.'tmp'.DS);
define('PATH_UPLOADS', PATH_CONTENT.'uploads'.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_PROFILES', PATH_UPLOADS.'profiles'.DS);
define('PATH_UPLOADS_THUMBNAILS', PATH_UPLOADS.'thumbnails'.DS); define('PATH_UPLOADS_THUMBNAILS', PATH_UPLOADS.'thumbnails'.DS);

View File

@ -68,8 +68,9 @@ class Page {
public function content($sanitize=false) public function content($sanitize=false)
{ {
// If already set the content, return it // If already set the content, return it
if (!empty($this->getValue('content'))) { $content = $this->getValue('content');
return $this->getValue('content'); if (!empty($content)) {
return $content;
} }
$contentRaw = $this->contentRaw(); $contentRaw = $this->contentRaw();

View File

@ -21,28 +21,6 @@ class pluginBackup extends Plugin {
$this->zip = extension_loaded('zip'); $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() public function post()
{ {
if (isset($_POST['createBackup'])) { if (isset($_POST['createBackup'])) {

View File

@ -81,13 +81,13 @@ class pluginRSS extends Plugin {
$doc = new DOMDocument(); $doc = new DOMDocument();
$doc->formatOutput = true; $doc->formatOutput = true;
$doc->loadXML($xml); $doc->loadXML($xml);
$doc->save($this->workspace().'rss.xml'); return $doc->save($this->workspace().'rss.xml');
} }
public function install($position=0) public function install($position=0)
{ {
parent::install($position); parent::install($position);
$this->createXML(); return $this->createXML();
} }
public function post() public function post()

View File

@ -62,13 +62,13 @@ class pluginSitemap extends Plugin {
$doc = new DOMDocument(); $doc = new DOMDocument();
$doc->formatOutput = true; $doc->formatOutput = true;
$doc->loadXML($xml); $doc->loadXML($xml);
$doc->save($this->workspace().'sitemap.xml'); return $doc->save($this->workspace().'sitemap.xml');
} }
public function install($position=0) public function install($position=0)
{ {
parent::install($position); parent::install($position);
$this->createXML(); return $this->createXML();
} }
public function post() public function post()

View File

@ -49,6 +49,7 @@ define('PATH_LANGUAGES', PATH_ROOT.'bl-languages'.DS);
define('PATH_UPLOADS', PATH_CONTENT.'uploads'.DS); define('PATH_UPLOADS', PATH_CONTENT.'uploads'.DS);
define('PATH_TMP', PATH_CONTENT.'tmp'.DS); define('PATH_TMP', PATH_CONTENT.'tmp'.DS);
define('PATH_PAGES', PATH_CONTENT.'pages'.DS); define('PATH_PAGES', PATH_CONTENT.'pages'.DS);
define('PATH_WORKSPACES', PATH_CONTENT.'workspaces'.DS);
define('PATH_DATABASES', PATH_CONTENT.'databases'.DS); define('PATH_DATABASES', PATH_CONTENT.'databases'.DS);
define('PATH_PLUGINS_DATABASES',PATH_CONTENT.'databases'.DS.'plugins'.DS); define('PATH_PLUGINS_DATABASES',PATH_CONTENT.'databases'.DS.'plugins'.DS);
define('PATH_UPLOADS_PROFILES', PATH_UPLOADS.'profiles'.DS); define('PATH_UPLOADS_PROFILES', PATH_UPLOADS.'profiles'.DS);
@ -208,8 +209,8 @@ RewriteEngine on
# Base directory # Base directory
RewriteBase '.HTML_PATH_ROOT.' RewriteBase '.HTML_PATH_ROOT.'
# Deny direct access to .txt files # Deny direct access to the next directories
RewriteRule ^bl-content/(.*)\.txt$ - [R=404,L] RewriteRule ^bl-content/(databases|workspaces|pages|tmp|)/.*$ - [R=404,L]
# All URL process by index.php # All URL process by index.php
RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
@ -299,6 +300,11 @@ function install($adminPassword, $timezone)
error_log('[ERROR] '.$errorText, 0); 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 // Create files
// ============================================================================ // ============================================================================
@ -493,6 +499,7 @@ function install($adminPassword, $timezone)
JSON_PRETTY_PRINT), JSON_PRETTY_PRINT),
LOCK_EX LOCK_EX
); );
mkdir(PATH_WORKSPACES.'simple-stats', DIR_PERMISSIONS, true);
// File plugins/tinymce/db.php // File plugins/tinymce/db.php
file_put_contents( file_put_contents(