From 3504f2e6e7f576062be11163494957bb76d5d513 Mon Sep 17 00:00:00 2001 From: Diego Najar Date: Sun, 2 Jul 2017 18:56:43 +0200 Subject: [PATCH] Filesystem helper improved --- .../remote-content/languages/en_US.json | 7 - bl-plugins/remote-content/metadata.json | 10 -- bl-plugins/remote-content/plugin.php | 130 ------------------ 3 files changed, 147 deletions(-) delete mode 100644 bl-plugins/remote-content/languages/en_US.json delete mode 100644 bl-plugins/remote-content/metadata.json delete mode 100644 bl-plugins/remote-content/plugin.php diff --git a/bl-plugins/remote-content/languages/en_US.json b/bl-plugins/remote-content/languages/en_US.json deleted file mode 100644 index 535a22ae..00000000 --- a/bl-plugins/remote-content/languages/en_US.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "plugin-data": - { - "name": "Remote Content", - "description": "" - } -} \ No newline at end of file diff --git a/bl-plugins/remote-content/metadata.json b/bl-plugins/remote-content/metadata.json deleted file mode 100644 index a5c64fc0..00000000 --- a/bl-plugins/remote-content/metadata.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "author": "Bludit", - "email": "", - "website": "https://plugins.bludit.com", - "version": "2.0", - "releaseDate": "2017-05-26", - "license": "MIT", - "compatible": "2.0", - "notes": "" -} \ No newline at end of file diff --git a/bl-plugins/remote-content/plugin.php b/bl-plugins/remote-content/plugin.php deleted file mode 100644 index 86d22db4..00000000 --- a/bl-plugins/remote-content/plugin.php +++ /dev/null @@ -1,130 +0,0 @@ -dbFields = array( - 'source'=>'localbluditv2.com/bl-content.zip', - 'webhook'=>'remote-content-webhook' - ); - } - - public function install($position=0) - { - parent::install($position); - $workspace = $this->workspace(); - mkdir($workspace, 0755, true); - } - - public function uninstall() - { - parent::uninstall(); - $workspace = $this->workspace(); - Filesystem::deleteRecursive($workspace); - } - - public function beforeRulesLoad() - { - if( $this->webhook() ) { - $this->getFile(); - $this->updateContent(); - $this->cleanUp(); - exit(); - } - } - - private function workspace() - { - return PATH_CONTENT.'remotecontent'.DS; - } - - private function webhook() - { - global $Url; - - // Check URI start with the webhook - $webhook = $this->getValue('webhook'); - if( empty($webhook) ) { - return false; - } - $startString = HTML_PATH_ROOT.$webhook; - $URI = $Url->uri(); - $length = mb_strlen($startString, CHARSET); - if( mb_substr($URI, 0, $length)!=$startString ) { - return false; - } - - Log::set('Plugin Remote Content'.LOG_SEP.'Webhook request.'); - - return true; - } - - private function cleanUp() - { - Log::set('Plugin Remote Content'.LOG_SEP.'Cleaning...'); - $workspace = $this->workspace(); - Filesystem::deleteRecursive($workspace); - mkdir($workspace, 0755, true); - return true; - } - - private function updateContent() - { - // Directory where the zip file was uncompress - $destinationPath = $this->workspace(); - - // This helps when uncompress the zip file and the files are saved inside a directory - $listDirectories = Filesystem::listDirectories($destinationPath); - if(count($listDirectories)==1) { - $uncompressDirectory = $listDirectories[0]; - } else { - $uncompressDirectory = $destinationPath; - } - - $uncompressDirectory = rtrim($uncompressDirectory, '/'); - - // Copy page directory - if(Filesystem::directoryExists($uncompressDirectory.DS.'pages')) { - Log::set('Plugin Remote Content'.LOG_SEP.'Copying pages...'); - Filesystem::copyRecursive($uncompressDirectory.DS.'pages', PATH_PAGES); - } - - // Copy databases directory - if(Filesystem::directoryExists($uncompressDirectory.DS.'databases')) { - Log::set('Plugin Remote Content'.LOG_SEP.'Copying databases...'); - Filesystem::copyRecursive($uncompressDirectory.DS.'databases', PATH_DATABASES); - } - - // Copy uploads directory - if(Filesystem::directoryExists($uncompressDirectory.DS.'uploads')) { - Log::set('Plugin Remote Content'.LOG_SEP.'Copying uploads...'); - Filesystem::copyRecursive($uncompressDirectory.DS.'uploads', PATH_UPLOADS); - } - - return true; - } - - private function getFile() - { - // Download the zip file - Log::set('Plugin Remote Content'.LOG_SEP.'Downloading the zip file.'); - $url = $this->getValue('source'); - $destinationPath = $this->workspace(); - $destinationFile = $destinationPath.'content.zip'; - TCP::download($url, $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; - } -} \ No newline at end of file