emptyDir() публичный Метод

Empty an entire directory.
public emptyDir ( string $path = null, boolean $del = false ) : void
$path string
$del boolean
Результат void
Пример #1
0
 /**
  * Process themes method
  *
  * @param  array $post
  * @return void
  */
 public function processModules($post)
 {
     foreach ($post as $key => $value) {
         if (strpos($key, 'module_active_') !== false) {
             $id = substr($key, strrpos($key, '_') + 1);
             $ext = Table\Extensions::findById($id);
             if (isset($ext->id)) {
                 $ext->active = (int) $value;
                 $ext->save();
             }
         }
     }
     $path = BASE_PATH . APP_URI;
     if ($path == '') {
         $path = '/';
     }
     $modulePath1 = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules';
     $modulePath2 = __DIR__ . '/../../../../../module';
     $phireCookie = null;
     if (php_sapi_name() != 'cli') {
         $cookie = Cookie::getInstance(array('path' => $path));
         if (isset($cookie->phire)) {
             if (null === $phireCookie) {
                 $phireCookie = $cookie->phire;
             }
         }
     }
     if (isset($post['remove_modules'])) {
         foreach ($post['remove_modules'] as $id) {
             $ext = Table\Extensions::findById($id);
             if (isset($ext->id)) {
                 $modPath = file_exists($modulePath1 . '/' . $ext->file) ? $modulePath1 : $modulePath2;
                 $assets = unserialize($ext->assets);
                 if (count($assets['tables']) > 0) {
                     $db = Table\Extensions::getDb();
                     if (DB_INTERFACE == 'Mysqli' || DB_TYPE == 'mysql') {
                         $db->adapter()->query('SET foreign_key_checks = 0;');
                         foreach ($assets['tables'] as $table) {
                             $db->adapter()->query('DROP TABLE ' . $table);
                         }
                         $db->adapter()->query('SET foreign_key_checks = 1;');
                     } else {
                         if (DB_INTERFACE == 'Pgsql' || DB_TYPE == 'pgsql') {
                             foreach ($assets['tables'] as $table) {
                                 $db->adapter()->query('DROP TABLE ' . $table . ' CASCADE');
                             }
                         } else {
                             foreach ($assets['tables'] as $table) {
                                 $db->adapter()->query('DROP TABLE ' . $table);
                             }
                         }
                     }
                 }
                 $contentPath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH;
                 $exts = array('.zip', '.tar.gz', '.tar.bz2', '.tgz', '.tbz', '.tbz2');
                 // Check for a config and remove function
                 if (file_exists($modPath . '/' . $ext->name . '/config') && file_exists($modPath . '/' . $ext->name . '/config/module.php')) {
                     $config = (include $modPath . '/' . $ext->name . '/config/module.php');
                     if (null !== $config[$ext->name]->remove) {
                         $removeFunc = $config[$ext->name]->remove;
                         $removeFunc();
                     }
                 }
                 if (file_exists($contentPath . '/extensions/modules/' . $ext->name)) {
                     $dir = new Dir($contentPath . '/extensions/modules/' . $ext->name);
                     $dir->emptyDir(null, true);
                 }
                 foreach ($exts as $e) {
                     if (file_exists($contentPath . '/extensions/modules/' . $ext->name . $e) && is_writable($contentPath . '/extensions/modules/' . $ext->name . $e)) {
                         unlink($contentPath . '/extensions/modules/' . $ext->name . $e);
                     }
                 }
                 if (file_exists(__DIR__ . '/../../../../../module/' . $ext->name)) {
                     $dir = new Dir(__DIR__ . '/../../../../../module/' . $ext->name);
                     $dir->emptyDir(null, true);
                 }
                 foreach ($exts as $e) {
                     if (file_exists(__DIR__ . '/../../../../../module/' . $ext->name . $e) && is_writable(__DIR__ . '/../../../../../module/' . $ext->name . $e)) {
                         unlink(__DIR__ . '/../../../../../module/' . $ext->name . $e);
                     }
                 }
                 if (file_exists($contentPath . '/assets/' . strtolower($ext->name))) {
                     $dir = new Dir($contentPath . '/assets/' . strtolower($ext->name));
                     $dir->emptyDir(null, true);
                 }
                 if (null !== $phireCookie) {
                     foreach ($phireCookie->modules as $key => $value) {
                         if ($value->name == $ext->name) {
                             $modules = (array) $phireCookie->modules;
                             unset($modules[$key]);
                             $phireCookie->modules = $modules;
                         }
                     }
                 }
                 $ext->delete();
             }
         }
     }
     if (null !== $phireCookie) {
         $cookie = Cookie::getInstance(array('path' => $path));
         $cookie->set('phire', $phireCookie);
     }
 }
Пример #2
0
 /**
  * Uninstall themes
  *
  * @param  array $ids
  * @return void
  */
 public function uninstall($ids)
 {
     $themePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes';
     foreach ($ids as $id) {
         $theme = Table\Themes::findById((int) $id);
         if (isset($theme->id)) {
             // Remove the theme folder and files
             if (file_exists($themePath . '/' . $theme->folder)) {
                 $dir = new Dir($themePath . '/' . $theme->folder);
                 $dir->emptyDir(true);
             }
             // Remove the theme file
             if (file_exists($themePath . '/' . $theme->file) && is_writable($themePath . '/' . $theme->file)) {
                 unlink($themePath . '/' . $theme->file);
             }
             $children = Table\Themes::findBy(['parent_id' => $theme->id]);
             if ($children->hasRows()) {
                 foreach ($children->rows() as $child) {
                     $childThemePath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/themes/' . $child->folder;
                     // Remove the child theme folder and files
                     if (file_exists($childThemePath)) {
                         $dir = new Dir($childThemePath);
                         $dir->emptyDir(true);
                     }
                     $c = Table\Themes::findById($child->id);
                     if (isset($c->id)) {
                         $c->delete();
                     }
                 }
             }
             $theme->delete();
         }
     }
 }
Пример #3
0
 /**
  * Perform update
  *
  * @param array   $post
  * @param boolean $cli
  * @return void
  */
 public function getUpdate($post = array(), $cli = false)
 {
     $docRoot = __DIR__ . '/../../../../../..';
     // If system is writable for updates
     if (!isset($post['submit'])) {
         switch ($post['type']) {
             case 'system':
                 $remoteFile = 'http://update.phirecms.org/system/latest.' . $post['format'];
                 break;
             case 'module':
                 $remoteFile = 'http://update.phirecms.org/modules/' . strtolower($post['name']) . '/latest.' . $post['format'];
                 break;
             case 'theme':
                 $remoteFile = 'http://update.phirecms.org/themes/' . strtolower($post['name']) . '/latest.' . $post['format'];
                 break;
         }
         $remoteContents = @file_get_contents($remoteFile);
         if ($remoteContents !== false) {
             $localFile = $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format'];
             file_put_contents($localFile, $remoteContents);
             $arc = new \Pop\Archive\Archive($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             $arc->extract($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update');
             unlink($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             $msg = null;
             if ($post['type'] == 'module') {
                 if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name'])) {
                     $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                     $dir->emptyDir(null, true);
                     rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                 }
                 $msg = $this->i18n->__('The %1 module has been updated.', $post['name']);
             } else {
                 if ($post['type'] == 'theme') {
                     if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name'])) {
                         $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                         $dir->emptyDir(null, true);
                         rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                     }
                     $msg = $this->i18n->__('The %1 theme has been updated.', $post['name']);
                 } else {
                     if ($post['type'] == 'system') {
                         if ($cli) {
                             rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms', $docRoot . DIRECTORY_SEPARATOR . 'phire-cms-new');
                             $config = Table\Config::findById('updated_on');
                             $config->value = date('Y-m-d H:i:s');
                             $config->update();
                             $msg = $this->i18n->__('The system has been updated.');
                         } else {
                             $time = time();
                             mkdir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time);
                             // Move old files into archive folder
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'config', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'config');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'module', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'module');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'script', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'script');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'vendor', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'vendor');
                             // Move new files into main application path
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'config', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'config');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'module', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'module');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'script', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'script');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'vendor', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'vendor');
                             $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms');
                             $dir->emptyDir(null, true);
                             $config = Table\Config::findById('updated_on');
                             $config->value = date('Y-m-d H:i:s');
                             $config->update();
                             $msg = $this->i18n->__('The system has been updated.');
                         }
                     }
                 }
             }
             $this->data['msg'] = '<span style="color: #347703">' . $msg . '</span>';
         } else {
             $this->data['error'] = '<span style="color: #a00b0b">' . $this->i18n->__('The update file was not found.') . '</span>';
         }
         // Else use cURL/FTP
     } else {
         unset($post['submit']);
         $curl = new \Pop\Curl\Curl('http://update.phirecms.org/update.php');
         $curl->setPost(true);
         $curl->setFields($post);
         $curl->execute();
         $response = json_decode($curl->getBody());
         unset($curl);
         if ($response->error == 0) {
             $arc = new \Pop\Archive\Archive($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             $arc->extract($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update');
             unlink($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             if ($post['type'] == 'system') {
                 chmod($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/phire-cms', 0777);
             } else {
                 if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'])) {
                     chmod($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], 0777);
                 }
             }
             $post['complete'] = 1;
             $curl = new \Pop\Curl\Curl('http://update.phirecms.org/update.php');
             $curl->setPost(true);
             $curl->setFields($post);
             $curl->execute();
             $complete = json_decode($curl->getBody());
             if ($complete->error == 0) {
                 switch ($complete->type) {
                     case 'system':
                         $config = Table\Config::findById('updated_on');
                         $config->value = date('Y-m-d H:i:s');
                         $config->update();
                         $msg = $this->i18n->__('The system has been updated.');
                         chmod($docRoot . APP_PATH, 0755);
                         break;
                     case 'module':
                         if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name'])) {
                             $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                             $dir->emptyDir(null, true);
                             rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                         }
                         $msg = $this->i18n->__('The %1 module has been updated.', $complete->name);
                         break;
                     case 'theme':
                         if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name'])) {
                             $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                             $dir->emptyDir(null, true);
                             rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                         }
                         $msg = $this->i18n->__('The %1 theme has been updated.', $complete->name);
                         break;
                 }
                 $this->data['msg'] = '<span style="color: #347703">' . $msg . '</span>';
             } else {
                 $this->data['error'] = '<span style="color: #a00b0b">' . $complete->message . '</span>';
             }
         } else {
             $this->data['error'] = '<span style="color: #a00b0b">' . $response->message . '</span>';
         }
     }
     $this->postUpdate($post);
 }
Пример #4
0
 /**
  * Method to get update for one-click update
  *
  * @param string $module
  * @param string $new
  * @param string $old
  * @param int    $id
  * @return void
  */
 public function getUpdate($module = null, $new = null, $old = null, $id = null)
 {
     if (null === $module) {
         if (file_exists(CONTENT_ABS_PATH . '/assets/phire')) {
             $dir = new Dir(CONTENT_ABS_PATH . '/assets/phire');
             $dir->emptyDir(true);
         }
         if (file_exists(CONTENT_ABS_PATH . '/assets/default')) {
             $dir = new Dir(CONTENT_ABS_PATH . '/assets/default');
             $dir->emptyDir(true);
         }
         if (file_exists(CONTENT_ABS_PATH . '/assets/default-flat')) {
             $dir = new Dir(CONTENT_ABS_PATH . '/assets/default-flat');
             $dir->emptyDir(true);
         }
         if (file_exists(CONTENT_ABS_PATH . '/assets/default-top')) {
             $dir = new Dir(CONTENT_ABS_PATH . '/assets/default-top');
             $dir->emptyDir(true);
         }
         if (file_exists(CONTENT_ABS_PATH . '/assets/default-top-flat')) {
             $dir = new Dir(CONTENT_ABS_PATH . '/assets/default-top-flat');
             $dir->emptyDir(true);
         }
         file_put_contents(CONTENT_ABS_PATH . '/updates/phirecms.zip', fopen('http://updates.phirecms.org/releases/phire/phirecms.zip', 'r'));
         $basePath = realpath(CONTENT_ABS_PATH . '/updates/');
         $archive = new Archive($basePath . '/phirecms.zip');
         $archive->extract($basePath);
         unlink(CONTENT_ABS_PATH . '/updates/phirecms.zip');
         $json = json_decode(stream_get_contents(fopen('http://updates.phirecms.org/releases/phire/phire.json', 'r')), true);
         foreach ($json as $file) {
             if (!file_exists(__DIR__ . '/../' . $file) && !file_exists(dirname(__DIR__ . '/../' . $file))) {
                 mkdir(dirname(__DIR__ . '/../' . $file), 0755, true);
             }
             copy(CONTENT_ABS_PATH . '/updates/phire-cms/' . $file, __DIR__ . '/../' . $file);
         }
         $dir = new Dir(CONTENT_ABS_PATH . '/updates/phire-cms/');
         $dir->emptyDir(true);
     } else {
         if (file_exists(MODULES_ABS_PATH . '/' . $module . '-' . $old . '.zip')) {
             unlink(MODULES_ABS_PATH . '/' . $module . '-' . $old . '.zip');
         }
         if (file_exists(MODULES_ABS_PATH . '/' . $module . '-' . $old)) {
             $dir = new Dir(MODULES_ABS_PATH . '/' . $module . '-' . $old);
             $dir->emptyDir(true);
         }
         if (file_exists(CONTENT_ABS_PATH . '/assets/' . $module)) {
             $dir = new Dir(CONTENT_ABS_PATH . '/assets/' . $module);
             $dir->emptyDir(true);
         }
         file_put_contents(MODULES_ABS_PATH . '/' . $module . '-' . $new . '.zip', fopen('http://updates.phirecms.org/releases/modules/' . $module . '-' . $new . '.zip', 'r'));
         $basePath = realpath(MODULES_ABS_PATH . '/');
         $archive = new Archive($basePath . '/' . $module . '-' . $new . '.zip');
         $archive->extract($basePath);
         $mod = Table\Modules::findById($id);
         $assets = unserialize($mod->assets);
         if (isset($assets['info']['version'])) {
             $assets['info']['version'] = $new;
         } else {
             if (isset($assets['info']['Version'])) {
                 $assets['info']['Version'] = $new;
             } else {
                 if (isset($assets['info']['VERSION'])) {
                     $assets['info']['VERSION'] = $new;
                 }
             }
         }
         $mod->file = $module . '-' . $new . '.zip';
         $mod->folder = $module . '-' . $new;
         $mod->assets = serialize($assets);
         $mod->save();
     }
 }
Пример #5
0
 /**
  * Save the config data
  *
  * @param  array $post
  * @return void
  */
 public function save(array $post)
 {
     $config = Table\Config::findById('domain');
     if (isset($_SERVER['HTTP_HOST']) && $config->value != $_SERVER['HTTP_HOST']) {
         $config->value = $_SERVER['HTTP_HOST'];
         $config->save();
     }
     $config = Table\Config::findById('document_root');
     if (isset($_SERVER['DOCUMENT_ROOT']) && $config->value != $_SERVER['DOCUMENT_ROOT']) {
         $config->value = $_SERVER['DOCUMENT_ROOT'];
         $config->save();
     }
     if (!empty($post['datetime_format_custom']) && $post['datetime_format'] == 'custom') {
         $dateFormatValue = str_replace(['"', "'"], ['', ''], strip_tags($post['datetime_format_custom']));
     } else {
         if (!empty($post['datetime_format']) && $post['datetime_format'] != 'custom') {
             $dateFormatValue = $post['datetime_format'];
         } else {
             $dateFormatValue = 'M j Y';
         }
     }
     $config = Table\Config::findById('datetime_format');
     $config->value = $dateFormatValue;
     $config->save();
     $config = Table\Config::findById('pagination');
     $config->value = (int) $post['pagination'];
     $config->save();
     $config = Table\Config::findById('system_theme');
     $oldValue = $config->value;
     $config->value = $post['system_theme'];
     $config->save();
     if (isset($_SERVER['DOCUMENT_ROOT']) && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $oldValue)) {
         $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $oldValue);
         $dir->emptyDir(true);
     }
 }
Пример #6
0
 /**
  * Process batch archive file
  *
  * @param  string $file
  * @param  array  $fields
  * @return void
  */
 public function processBatch($file, array $fields)
 {
     $tmp = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp';
     mkdir($tmp);
     chmod($tmp, 0777);
     $batchFileName = (new Upload($tmp))->upload($file);
     $archive = new Archive($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $batchFileName);
     $archive->extract($tmp);
     if (stripos($archive->getFilename(), '.tar') !== false && $archive->getFilename() != $batchFileName && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $archive->getFilename())) {
         unlink($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $archive->getFilename());
     }
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $batchFileName)) {
         unlink($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/_tmp/' . $batchFileName);
     }
     $library = new MediaLibrary();
     $library->getById($fields['library_id']);
     $settings = $library->getSettings();
     $dir = new Dir($tmp, ['absolute' => true, 'recursive' => true, 'filesOnly' => true]);
     $upload = new Upload($settings['folder'], $settings['max_filesize'], $settings['disallowed_types'], $settings['allowed_types']);
     foreach ($dir->getFiles() as $file) {
         $basename = basename($file);
         $testFile = ['name' => $basename, 'size' => filesize($file), 'error' => 0];
         if ($upload->test($testFile)) {
             $fileName = $upload->checkFilename($basename);
             copy($file, $settings['folder'] . '/' . $fileName);
             $title = ucwords(str_replace(['_', '-'], [' ', ' '], substr($fileName, 0, strrpos($fileName, '.'))));
             if (null !== $library->adapter) {
                 $class = 'Pop\\Image\\' . $library->adapter;
                 $formats = array_keys($class::getFormats());
                 $fileParts = pathinfo($fileName);
                 if (!empty($fileParts['extension']) && in_array(strtolower($fileParts['extension']), $formats)) {
                     $this->processImage($fileName, $library);
                 }
             }
             $media = new Table\Media(['library_id' => $fields['library_id'], 'title' => $title, 'file' => $fileName, 'size' => filesize($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $library->folder . DIRECTORY_SEPARATOR . $fileName), 'uploaded' => date('Y-m-d H:i:s'), 'order' => 0]);
             $media->save();
             $this->data['ids'][] = $media->id;
         }
     }
     $dir->emptyDir(true);
 }
Пример #7
0
 /**
  * Uninstall modules
  *
  * @param  array                $ids
  * @param  \Pop\Service\Locator $services
  * @return void
  */
 public function uninstall($ids, $services)
 {
     $modulesPath = MODULES_ABS_PATH;
     foreach ($ids as $id) {
         $module = Table\Modules::findById((int) $id);
         if (isset($module->id)) {
             $assets = unserialize($module->assets);
             if (isset($assets['tables']) && count($assets['tables']) > 0) {
                 $db = $services['database'];
                 if (DB_INTERFACE == 'mysql' || DB_TYPE == 'mysql') {
                     $db->query('SET foreign_key_checks = 0;');
                     foreach ($assets['tables'] as $table) {
                         $db->query('DROP TABLE ' . $table);
                     }
                     $db->query('SET foreign_key_checks = 1;');
                 } else {
                     if (DB_INTERFACE == 'pgsql' || DB_TYPE == 'pgsql') {
                         foreach ($assets['tables'] as $table) {
                             $db->query('DROP TABLE ' . $table . ' CASCADE');
                         }
                     } else {
                         foreach ($assets['tables'] as $table) {
                             $db->query('DROP TABLE ' . $table);
                         }
                     }
                 }
             }
             // Run any uninstall functions
             $config = (include $modulesPath . '/' . $module->folder . '/config/module.php');
             if (isset($config[$module->name]) && isset($config[$module->name]['uninstall']) && !empty($config[$module->name]['uninstall'])) {
                 call_user_func_array($config[$module->name]['uninstall'], [$services]);
             }
             // Remove any assets
             if (file_exists(__DIR__ . '/../../..' . CONTENT_PATH . '/assets/' . strtolower($module->name))) {
                 $dir = new Dir(__DIR__ . '/../../..' . CONTENT_PATH . '/assets/' . strtolower($module->name));
                 $dir->emptyDir(true);
             }
             if (strpos($modulesPath, 'vendor') === false) {
                 // Remove the module folder and files
                 if (file_exists($modulesPath . '/' . $module->folder)) {
                     $dir = new Dir($modulesPath . '/' . $module->folder);
                     $dir->emptyDir(true);
                 }
                 // Remove the module file
                 if (file_exists($modulesPath . '/' . $module->file) && is_writable($modulesPath . '/' . $module->file)) {
                     unlink($modulesPath . '/' . $module->file);
                 }
             }
             $module->delete();
         }
     }
 }
Пример #8
0
 /**
  * Parse actions
  *
  * @param  string $folder
  * @return array
  */
 protected function parseActions($folder)
 {
     $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder);
     $curDirs = [];
     $newDirs = [];
     foreach ($dir->getFiles() as $file) {
         if (is_dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $file)) {
             $curDirs[] = $file;
         }
     }
     $actions = [];
     foreach ($_POST as $key => $value) {
         if (substr($key, 0, 12) == 'action_name_') {
             $id = substr($key, strrpos($key, '_') + 1);
             if (!empty($_POST['action_name_' . $id]) && $_POST['action_method_' . $id] != '----' && !empty($_POST['action_params_' . $id])) {
                 $actions[$_POST['action_name_' . $id]] = ['method' => $_POST['action_method_' . $id], 'params' => $_POST['action_params_' . $id], 'quality' => !empty($_POST['action_quality_' . $id]) ? (int) $_POST['action_quality_' . $id] : 80];
                 if (!file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $_POST['action_name_' . $id])) {
                     mkdir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $_POST['action_name_' . $id]);
                     chmod($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $_POST['action_name_' . $id], 0777);
                     copy($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'index.html', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $_POST['action_name_' . $id] . DIRECTORY_SEPARATOR . 'index.html');
                 }
                 $newDirs[] = $_POST['action_name_' . $id];
             }
         }
     }
     // Clean up directories
     foreach ($curDirs as $dir) {
         if (!in_array($dir, $newDirs)) {
             $d = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . $dir);
             $d->emptyDir(true);
         }
     }
     return $actions;
 }
Пример #9
0
 public function testZipExtract()
 {
     if (class_exists('ZipArchive', false)) {
         $a = new Archive(__DIR__ . '/../tmp/test.zip');
         $a->addFiles(__DIR__ . '/../tmp');
         mkdir(__DIR__ . '/../tmp/test');
         chmod(__DIR__ . '/../tmp/test', 0777);
         chmod(__DIR__ . '/../tmp/test.zip', 0777);
         $a->extract(__DIR__ . '/../tmp/test');
         unset($a);
         $dir = new Dir(__DIR__ . '/../tmp/test');
         $this->assertGreaterThan(0, count($dir->getFiles()));
         $dir->emptyDir();
         rmdir(__DIR__ . '/../tmp/test');
         if (file_exists(__DIR__ . '/../tmp/test.zip')) {
             unlink(__DIR__ . '/../tmp/test.zip');
         }
     }
 }
Пример #10
0
 public function testTbz2Extract()
 {
     $tar = false;
     $includePath = explode(PATH_SEPARATOR, get_include_path());
     foreach ($includePath as $path) {
         if (file_exists($path . DIRECTORY_SEPARATOR . 'Archive' . DIRECTORY_SEPARATOR . 'Tar.php')) {
             $tar = true;
         }
     }
     if ($tar && function_exists('bzopen')) {
         $a = new Archive(__DIR__ . '/../tmp/test.tar');
         $a->addFiles(__DIR__ . '/../tmp');
         $a->compress('bz2');
         chmod(__DIR__ . '/../tmp/test.tar.bz2', 0777);
         unset($a);
         $a = new Archive(__DIR__ . '/../tmp/test.tar.bz2');
         mkdir(__DIR__ . '/../tmp/test');
         chmod(__DIR__ . '/../tmp/test', 0777);
         $a->extract(__DIR__ . '/../tmp/test');
         $dir = new Dir(__DIR__ . '/../tmp/test');
         $this->assertGreaterThan(0, count($dir->getFiles()));
         $dir->emptyDir();
         rmdir(__DIR__ . '/../tmp/test');
         if (file_exists(__DIR__ . '/../tmp/test.tar')) {
             unlink(__DIR__ . '/../tmp/test.tar');
         }
         if (file_exists(__DIR__ . '/../tmp/test.tar.bz2')) {
             unlink(__DIR__ . '/../tmp/test.tar.bz2');
         }
     }
 }