/**
  * Installing plugin
  * @param null $zipPath
  * @return array|bool
  * @throws CakeException
  */
 public function install($zipPath = null)
 {
     if (!file_exists($zipPath)) {
         throw new Exception(__d('spider', 'Invalid plugin file path'));
     }
     $pluginInfo = $this->getPluginMeta($zipPath);
     $pluginHomeDir = App::path('Plugin');
     $pluginHomeDir = reset($pluginHomeDir);
     $pluginPath = $pluginHomeDir . $pluginInfo->name . DS;
     if (is_dir($pluginPath)) {
         throw new Exception(__d('spider', 'Plugin already exists'));
     }
     $Zip = new \ZipArchive();
     if ($Zip->open($zipPath) === true) {
         new Folder($pluginPath, true);
         $Zip->extractTo($pluginPath);
         if (!empty($pluginInfo->rootPath)) {
             $old = $pluginPath . $pluginInfo->rootPath;
             $new = $pluginPath;
             $Folder = new Folder($old);
             $Folder->move($new);
         }
         $Zip->close();
         return (array) $pluginInfo;
     } else {
         throw new CakeException(__d('spider', 'Failed to extract plugin'));
     }
     return false;
 }
Exemple #2
0
 /**
  * Test plugin load by list.
  *
  * @return void
  */
 public function testLoadList()
 {
     $Folder = new Folder();
     $pluginsDir = APP_ROOT . 'Plugins' . DS;
     $TestPlgPath = $pluginsDir . 'PluginTest';
     $Folder->create($TestPlgPath, 0777);
     new File($TestPlgPath . '/config/bootstrap.php', true);
     new File($TestPlgPath . '/config/routes.php', true);
     $NoRoutesPlgPath = $pluginsDir . 'NoRoutes';
     $Folder->create($NoRoutesPlgPath, 0777);
     new File($NoRoutesPlgPath . '/config/bootstrap.php', true);
     $NoBootstrapPlgPath = $pluginsDir . 'NoBootstrap';
     $Folder->create($NoBootstrapPlgPath, 0777);
     new File($NoBootstrapPlgPath . '/config/routes.php', true);
     $NoConfigPlgPath = $pluginsDir . 'NoConfig';
     $Folder->create($NoConfigPlgPath, 0777);
     Plugin::load('Migrations');
     Plugin::loadList(['NoConfig', 'NoRoutes', 'PluginTest', 'Migrations', 'NoBootstrap']);
     $this->assertTrue(Plugin::loaded('NoBootstrap'));
     $this->assertTrue(Plugin::loaded('PluginTest'));
     $this->assertTrue(Plugin::loaded('NoRoutes'));
     $this->assertTrue(Plugin::loaded('NoConfig'));
     //  Check virtual paths.
     $this->assertSame(1, count(vPath()->getPaths('NoBootstrap:')));
     $this->assertSame(1, count(vPath()->getPaths('PluginTest:')));
     $this->assertSame(1, count(vPath()->getPaths('NoRoutes:')));
     $this->assertSame(1, count(vPath()->getPaths('NoConfig:')));
     $Folder->delete($TestPlgPath);
     $Folder->delete($NoRoutesPlgPath);
     $Folder->delete($NoConfigPlgPath);
     $Folder->delete($NoBootstrapPlgPath);
 }
Exemple #3
0
 /**
  * Overwrite shell initialize to dynamically load all Queue Related Tasks.
  *
  * @return void
  */
 public function initialize()
 {
     $plugins = Plugin::loaded();
     foreach ($plugins as $plugin) {
         $pluginPaths = App::path('Shell/Task', $plugin);
         foreach ($pluginPaths as $pluginPath) {
             $Folder = new Folder($pluginPath);
             $res = $Folder->find('Queue.+Task\\.php');
             foreach ($res as &$r) {
                 $r = $plugin . '.' . basename($r, 'Task.php');
             }
             $this->tasks = array_merge($this->tasks, $res);
         }
     }
     $paths = App::path('Shell/Task');
     foreach ($paths as $path) {
         $Folder = new Folder($path);
         $res = array_merge($this->tasks, $Folder->find('Queue.+\\.php'));
         foreach ($res as &$r) {
             $r = basename($r, 'Task.php');
         }
         $this->tasks = $res;
     }
     parent::initialize();
     $this->QueuedTasks->initConfig();
 }
Exemple #4
0
 /**
  * Test composer post autoload dump event.
  *
  * @return void
  */
 public function testPostAutoloadDump()
 {
     Plugin::load('DebugKit');
     if (!defined('DS')) {
         define('DS', DIRECTORY_SEPARATOR);
     }
     if (!defined('TMP')) {
         define('TMP', sys_get_temp_dir() . DS);
     }
     $vendorDir = ROOT . 'vendor';
     $webRoot = $vendorDir . '/cakephp/debug_kit/webroot';
     $assetsDir = $vendorDir . '/cakephp/debug_kit/assets';
     if (!is_dir($webRoot) && is_dir($assetsDir)) {
         $debugWebroot = new Folder($assetsDir);
         $debugWebroot->copy($webRoot);
         $debugWebroot->delete($assetsDir);
     }
     $composer = new Composer();
     /** @var Config $config */
     $config = new Config();
     $config->merge(['config' => ['vendor-dir' => $vendorDir]]);
     $composer->setConfig($config);
     /** @var IOInterface $io */
     $io = $this->getMock('Composer\\IO\\IOInterface');
     $event = new Event('postAutoloadDump', $composer, $io);
     Installer::postAutoloadDump($event);
     Plugin::unload('DebugKit');
 }
Exemple #5
0
 /**
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     $dir = new Folder(TMP . 'lock');
     $dir->delete();
     unset($this->Lock);
 }
 /**
  * Scan folder by path.
  *
  * @param null $path
  * @return void|\Cake\Network\Response
  */
 public function scanFolder($path = null)
 {
     if (!$path) {
         $path = WWW_ROOT;
     }
     $Folder = new Folder();
     $_path = $this->request->query('path') ? $this->request->query('path') : $path;
     if (!is_dir($_path)) {
         $Folder->create($_path);
     }
     $_path = realpath($_path) . DS;
     $regex = '/^' . preg_quote(realpath($path), '/') . '/';
     if (preg_match($regex, $_path) == false) {
         $this->_controller->Flash->error(__d('file_manager', 'Path {0} is restricted', $_path));
         return $this->_controller->redirect(['action' => 'browse']);
     }
     $blacklist = ['.git', '.svn', '.CVS'];
     $regex = '/(' . preg_quote(implode('|', $blacklist), '.') . ')/';
     if (in_array(basename($_path), $blacklist) || preg_match($regex, $_path)) {
         $this->_controller->Flash->error(__d('file_manager', 'Path %s is restricted', $_path));
         return $this->_controller->redirect(['action' => 'browse']);
     }
     $Folder->path = $_path;
     $content = $Folder->read();
     $this->_controller->set('path', $_path);
     $this->_controller->set('content', $content);
 }
Exemple #7
0
 public function beforeMarshal(Event $event, $data, $options)
 {
     $config = $this->_config;
     foreach ($config['fields'] as $fieldKey => $fieldValue) {
         $virtualField = $fieldKey;
         $file = $data[$fieldKey];
         if ((int) $file['error'] === UPLOAD_ERR_NO_FILE) {
             continue;
         }
         if (!isset($fieldValue['path'])) {
             throw new \LogicException(__('The path for the {0} field is required.', $fieldKey));
         }
         if (isset($fieldValue['prefix']) && (is_bool($fieldValue['prefix']) || is_string($fieldValue['prefix']))) {
             $this->_prefix = $fieldValue['prefix'];
         }
         $extension = (new File($file['name'], false))->ext();
         $uploadPath = $this->_getUploadPath($data, $fieldValue['path'], $extension);
         if (!$uploadPath) {
             throw new \ErrorException(__('Error to get the uploadPath.'));
         }
         $folder = new Folder($this->_config['root']);
         $folder->create($this->_config['root'] . dirname($uploadPath));
         if ($this->_moveFile($data, $file['tmp_name'], $uploadPath, $fieldKey, $fieldValue)) {
             if (!$this->_prefix) {
                 $this->_prefix = '';
             }
             $data[$fieldKey] = $uploadPath;
         }
     }
 }
 /**
  * Check if there is some files to upload and modify the entity before
  * it is saved.
  *
  * At the end, for each files to upload, unset their "virtual" property.
  *
  * @param Event  $event  The beforeSave event that was fired.
  * @param Entity $entity The entity that is going to be saved.
  *
  * @throws \LogicException When the path configuration is not set.
  * @throws \ErrorException When the function to get the upload path failed.
  *
  * @return void
  */
 public function beforeSave(Event $event, Entity $entity)
 {
     $config = $this->_config;
     foreach ($config['fields'] as $field => $fieldOption) {
         $data = $entity->toArray();
         $virtualField = $field . $config['suffix'];
         if (!isset($data[$virtualField]) || !is_array($data[$virtualField])) {
             continue;
         }
         $file = $entity->get($virtualField);
         if ((int) $file['error'] === UPLOAD_ERR_NO_FILE) {
             continue;
         }
         if (!isset($fieldOption['path'])) {
             throw new \LogicException(__('The path for the {0} field is required.', $field));
         }
         if (isset($fieldOption['prefix']) && (is_bool($fieldOption['prefix']) || is_string($fieldOption['prefix']))) {
             $this->_prefix = $fieldOption['prefix'];
         }
         $extension = (new File($file['name'], false))->ext();
         $uploadPath = $this->_getUploadPath($entity, $fieldOption['path'], $extension);
         if (!$uploadPath) {
             throw new \ErrorException(__('Error to get the uploadPath.'));
         }
         $folder = new Folder($this->_config['root']);
         $folder->create($this->_config['root'] . dirname($uploadPath));
         if ($this->_moveFile($entity, $file['tmp_name'], $uploadPath, $field, $fieldOption)) {
             if (!$this->_prefix) {
                 $this->_prefix = '';
             }
             $entity->set($field, $this->_prefix . $uploadPath);
         }
         $entity->unsetProperty($virtualField);
     }
 }
 /**
  * Includes all necessary JS code for admin editing of CmsBlocks.
  *
  * @return void
  */
 public function includeCmsAdminAssets()
 {
     $script = 'var Cms = {AdminWidgetControllers: {}};';
     $this->Html->scriptBlock($script, ['block' => true]);
     $this->Html->script('Cms.app/lib/AdminWidgetController.js', ['block' => true]);
     $availableWidgets = WidgetManager::getAvailableWidgets();
     $adminControllers = [];
     $folder = new Folder();
     foreach ($availableWidgets as $widgetIdentifier) {
         $widget = WidgetFactory::identifierFactory($widgetIdentifier);
         $webrootPath = $widget->getWebrootPath();
         if (!is_dir($webrootPath)) {
             continue;
         }
         $folder->cd($webrootPath . 'js/');
         $jsFiles = $folder->read();
         if (empty($jsFiles[1])) {
             continue;
         }
         foreach ($jsFiles[1] as $filename) {
             if (strpos($filename, 'AdminWidgetController.js') !== false) {
                 $adminControllers[] = '/cms/widget/' . $widgetIdentifier . '/js/' . $filename;
             }
         }
     }
     $this->Html->script($adminControllers, ['block' => true]);
 }
Exemple #10
0
 /**
  * Extract valid theme archive.
  *
  * @return $this|void
  */
 public function extract()
 {
     $Zip = $this->zip();
     $Theme = ThemeExtension::getInstance();
     $name = $this->_attr->get('name');
     $path = $Theme->getPath() . $name . DS;
     $alias = Plugin::nameToAlias($name);
     $isExits = $this->table()->findByAlias($alias)->first();
     if (is_dir($path) && $isExits !== null) {
         $this->_setOutput(__d('extensions', 'The theme «{0}» already exits.', sprintf('<strong>%s</strong>', $name)));
     }
     new Folder($path);
     $tmp = $this->_request->data($this->_inputName);
     $Zip->open($tmp);
     $Zip->extractTo($path);
     if (!empty($this->_rootPath[$tmp])) {
         $old = $path . DS . $this->_rootPath[$tmp];
         $new = $path;
         $Folder = new Folder($old);
         $Folder->move($new);
     }
     $this->_setResult(true);
     $this->_setOutput(__d('extensions', 'The theme «{0}» has bin successful uploaded.', sprintf('<strong>%s</strong>', $name)), true);
     return $this;
 }
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     $Folder = new Folder($this->Task->path . 'BakeTestApp');
     $Folder->delete();
     unset($this->Task);
 }
 /**
  * @return int|null
  */
 public function clean()
 {
     if (!empty($this->args[0])) {
         $folder = realpath($this->args[0]);
     } else {
         $folder = APP;
     }
     $App = new Folder($folder);
     $this->out('Cleaning copyright notices in ' . $folder);
     $ext = '.*';
     if (!empty($this->params['ext'])) {
         $ext = $this->params['ext'];
     }
     $files = $App->findRecursive('.*\\.' . $ext);
     $this->out('Found ' . count($files) . ' files.');
     $count = 0;
     foreach ($files as $file) {
         $this->out('Processing ' . $file, 1, Shell::VERBOSE);
         $content = $original = file_get_contents($file);
         $content = preg_replace('/\\<\\?php\\s*\\s+\\/\\*\\*\\s*\\s+\\* CakePHP.*\\*\\//msUi', '<?php', $content);
         if ($content === $original) {
             continue;
         }
         $count++;
         if (empty($this->params['dry-run'])) {
             file_put_contents($file, $content);
         }
     }
     $this->out('--------');
     $this->out($count . ' files fixed.');
 }
Exemple #13
0
 /**
  * Find the paths to all the installed shell templates in the app.
  *
  * Bake templates are directories under `Template/Bake` path.
  * They are listed in this order: app -> plugin -> default
  *
  * @return array Array of bake templates that are installed.
  */
 protected function _findTemplates()
 {
     $paths = App::path('Template');
     $plugins = Plugin::loaded();
     foreach ($plugins as $plugin) {
         $paths[] = Plugin::classPath($plugin) . 'Template' . DS;
     }
     $core = current(App::core('Template'));
     $Folder = new Folder($core . 'Bake' . DS . 'default');
     $contents = $Folder->read();
     $templateFolders = $contents[0];
     $paths[] = $core;
     foreach ($paths as $i => $path) {
         $paths[$i] = rtrim($path, DS) . DS;
     }
     $this->_io->verbose('Found the following bake templates:');
     $templates = [];
     foreach ($paths as $path) {
         $Folder = new Folder($path . 'Bake', false);
         $contents = $Folder->read();
         $subDirs = $contents[0];
         foreach ($subDirs as $dir) {
             $Folder = new Folder($path . 'Bake' . DS . $dir);
             $contents = $Folder->read();
             $subDirs = $contents[0];
             if (array_intersect($contents[0], $templateFolders)) {
                 $templateDir = $path . 'Bake' . DS . $dir . DS;
                 $templates[$dir] = $templateDir;
                 $this->_io->verbose(sprintf("- %s -> %s", $dir, $templateDir));
             }
         }
     }
     return $templates;
 }
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     unset($this->Task);
     $Folder = new Folder($this->path);
     $Folder->delete();
     Plugin::unload();
 }
Exemple #15
0
 private function removeAndCreateFolder($path)
 {
     $dir = new Folder($path);
     $dir->delete();
     $dir->create($path);
     $file = new File($path . DS . 'empty');
     $file->create();
 }
 public function tearDown()
 {
     parent::tearDown();
     $testPluginFolder = new Folder(ROOT . DS . 'plugins' . DS . 'PluginInstallerTest');
     $testPluginFolder->delete();
     $testPluginConfigFolder = new Folder(ROOT . DS . 'config' . DS . 'Plugins' . DS . 'PluginInstallerTest');
     $testPluginConfigFolder->delete();
 }
 /**
  * tearDown
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     unset($this->Model);
     TableRegistry::clear();
     $folder = new Folder(WWW_ROOT . 'upload');
     $folder->delete(WWW_ROOT . 'upload');
 }
 private function createFileAndDeleteTmp($identifier, $filename)
 {
     $tmpFolder = new Folder($this->tmpChunkDir($identifier));
     $chunkFiles = $tmpFolder->read(true, true, true)[1];
     if ($this->createFileFromChunks($chunkFiles, $this->uploadFolder . DIRECTORY_SEPARATOR . $filename) && $this->deleteTmpFolder) {
         $tmpFolder->delete();
     }
 }
Exemple #19
0
 /**
  * tearDown method
  *
  * @return void
  */
 public function tearDown()
 {
     parent::tearDown();
     $this->File->close();
     unset($this->File);
     $Folder = new Folder();
     $Folder->delete(TMP . 'tests/permissions');
 }
Exemple #20
0
 public function getTemplatesList($dir)
 {
     $basicDir = $dir . $this->subDir;
     $dir = new Folder($basicDir);
     $templatesList = array_map(function ($dirAddr) use($basicDir) {
         return str_replace($basicDir . '/', '', $dirAddr);
     }, $dir->findRecursive('.*\\.html'));
     return array_combine($templatesList, $templatesList);
 }
Exemple #21
0
 /**
  * Register all available themes in the composer classloader and load them as plugin.
  *
  * @return void
  */
 public static function loadThemes()
 {
     $themesFolder = new Folder(ROOT . DS . 'themes');
     $themes = $themesFolder->read()[0];
     $loader = (require ROOT . DS . 'vendor' . DS . 'autoload.php');
     foreach ($themes as $theme) {
         $loader->addPsr4('WasabiTheme\\' . $theme . '\\', [$themesFolder->path . DS . $theme . DS . 'src']);
         Plugin::load('WasabiTheme/' . $theme, ['path' => $themesFolder->path . DS . $theme . DS, 'bootstrap' => true, 'routes' => false]);
     }
 }
 protected function _publish($option)
 {
     $folderElement = new Folder(Plugin::path('TwitterBootstrap') . DS . 'src' . DS . 'Template' . DS . 'Element');
     switch ($option) {
         case 'all':
             $folderElement->copy(APP . 'Template' . DS . 'Element', false);
             break;
     }
     $this->out('Arquivos publicados');
 }
Exemple #23
0
 /**
  * Recursively adds all the files in a directory to the test suite.
  *
  * @param string $directory The directory subtree to add tests from.
  * @return void
  */
 public function addTestDirectoryRecursive($directory = '.')
 {
     $Folder = new Folder($directory);
     $files = $Folder->tree(null, true, 'files');
     foreach ($files as $file) {
         if (substr($file, -4) === '.php') {
             $this->addTestFile($file);
         }
     }
 }
 public function tearDown()
 {
     parent::tearDown();
     Plugin::unload('ThemeInstallerTest');
     $testPluginFolder = new Folder(ROOT . DS . 'plugins' . DS . 'ThemeInstallerTest');
     $testPluginFolder->delete();
     $testPluginConfigFolder = new Folder(ROOT . DS . 'config' . DS . 'Plugins' . DS . 'ThemeInstallerTest');
     $testPluginConfigFolder->delete();
     $webrootThemeFolder = new Folder(WWW_ROOT . 'theme' . DS . 'ThemeInstallerTest');
     $webrootThemeFolder->delete();
 }
 /**
  * Gets a list of counties flags suitable for select boxes.
  *
  * @return array
  */
 public static function flagsList()
 {
     $flags = [];
     $Folder = new Folder(Plugin::path('Locale') . 'webroot/img/flags/');
     foreach ($Folder->read()[1] as $icon) {
         $value = $icon;
         $label = str_replace_last('.gif', '', $icon);
         $flags[$value] = $label;
     }
     asort($flags);
     return $flags;
 }
 public function installTheme($theme)
 {
     if (!Plugin::loaded($theme)) {
         throw new \Exception('Plugin não foi carregado.');
     }
     if (!file_exists(WWW_ROOT . 'theme' . DS . $theme) or Configure::read('debug')) {
         $handler = new Folder();
         $handler->copy(['to' => WWW_ROOT . 'theme' . DS . $theme, 'from' => Plugin::path($theme) . 'webroot' . DS . '_assets', 'mode' => 0755, 'scheme' => Folder::OVERWRITE]);
         return true;
     }
     return false;
 }
Exemple #27
0
 /**
  * testAddTestDirectoryRecursiveWithNonPhp
  *
  * @return void
  */
 public function testAddTestDirectoryRecursiveWithNonPhp()
 {
     $this->skipIf(!is_writable(TMP), 'Cant addTestDirectoryRecursiveWithNonPhp unless the tmp folder is writable.');
     $Folder = new Folder(TMP . 'MyTestFolder', true, 0777);
     touch($Folder->path . DS . 'BackupTest.php~');
     touch($Folder->path . DS . 'SomeNotesTest.txt');
     touch($Folder->path . DS . 'NotHiddenTest.php');
     $suite = $this->getMock('Cake\\TestSuite\\TestSuite', ['addTestFile']);
     $suite->expects($this->exactly(1))->method('addTestFile');
     $suite->addTestDirectoryRecursive($Folder->pwd());
     $Folder->delete();
 }
 public function addDirImg()
 {
     if ($this->request->is('post')) {
         $dossier_nom = $this->request->data['dossier_nom'];
         $folder = new Folder(ROOT . '/plugins/Admin/webroot/img/projets/');
         $folder->create($dossier_nom);
         $this->Flash->success(__('Le dossier a été créé avec succès !'));
         return $this->redirect(['action' => 'index']);
     }
     $this->set('data', ['title' => __("Ajouter un dossier d'images")]);
     $this->set(compact('data'));
 }
 public function getFilelistFromControllerFolderAndIdFolder($controller, $id)
 {
     $filefolder = '../webroot' . DS . 'files';
     $folder = new Folder($filefolder . DS . $controller . DS . $id);
     $files = $folder->read();
     $list = [];
     $list[''] = '';
     foreach ($files[1] as $f) {
         $list[$f] = $f;
     }
     return $list;
 }
 /**
  * startCaching method
  *
  * Cache\[optimize] images in cache folder
  *
  * @param string $optimization 'true' or 'false'
  * @param string $srcPath folder name for source images
  * @return void
  */
 public function startCaching($optimization = 'true', $srcPath = 'src_images')
 {
     $dir = new Folder(WWW_ROOT . 'img' . DS . $srcPath);
     $files = $dir->findRecursive('.*\\.(jpg|jpeg|png|gif|svg)');
     /*
      * Error handler
      */
     if (is_null($dir->path)) {
         $this->error('<red_text>Source folder not exists!</red_text>');
     }
     if ($optimization != 'true' && $optimization != 'false') {
         $this->error('<red_text>Arguments \'optimization\' should equal \'true\' or \'false\'</red_text>');
     }
     /*
      * Caching
      */
     $counter = 1;
     $countFiles = count($files);
     $this->out('<info>Images caching</info>');
     foreach ($files as $file) {
         $file = new File($file);
         $semanticType = explode(DS, $file->Folder()->path);
         $semanticType = $semanticType[count($semanticType) - 1];
         //get semantic type name
         $this->adaptiveImagesController->passiveCaching($file->path, $semanticType);
         $this->_io->overwrite($this->progressBar($counter, $countFiles), 0, 50);
         $counter++;
     }
     /*
      * Optimization
      */
     if ($optimization == 'true') {
         $cachePath = $this->adaptiveImagesController->getCachePath();
         $pluginPath = Plugin::path('AdaptiveImages');
         $cacheDir = new Folder($pluginPath . 'webroot' . DS . $cachePath);
         $files = $cacheDir->findRecursive('.*\\.(jpg|jpeg|png|gif|svg)');
         $counter = 1;
         $countFiles = count($files);
         $this->out('');
         $this->out('<info>Images optimization</info>');
         foreach ($files as $file) {
             $this->_optimizeImage($file);
             $this->_io->overwrite($this->progressBar($counter, $countFiles), 0, 50);
             $counter++;
         }
         $this->hr();
         $this->out('<green_text>Caching and optimization completed!</green_text>');
     } elseif ($optimization == 'false') {
         $this->hr();
         $this->out('<green_text>Caching completed!</green_text>');
     }
 }