예제 #1
1
 /**
  * Initialize method
  */
 public function initialize()
 {
     $paths = App::path('Shell/Task', 'CodeBlastrQueue');
     foreach ($paths as $path) {
         $Folder = new Folder($path);
         $res = array_merge($this->tasks, $Folder->find('Queue.+\\.php'));
         foreach ($res as &$r) {
             $r = 'CodeBlastrQueue.' . basename($r, 'Task.php');
         }
         $this->tasks = $res;
     }
     parent::initialize();
 }
예제 #2
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();
 }
예제 #3
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;
 }
예제 #4
0
 /**
  * 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;
 }
예제 #5
0
 /**
  * Return all templates for a given plugin.
  *
  * @param string $plugin The plugin to find all templates for.
  *
  * @return mixed
  */
 public static function plugin($plugin)
 {
     $templates = [];
     foreach (App::path('Template', $plugin) as $path) {
         $templates = array_merge($templates, static::iteratePath($path));
     }
     return $templates;
 }
예제 #6
0
 /**
  * Strip the absolute path of template's paths.
  *
  * @param array       $paths  Paths to strip.
  * @param string|null $plugin Hold plugin name or null for App.
  *
  * @return array
  */
 protected static function stripAbsolutePath(array $paths, $plugin = null)
 {
     foreach (App::path('Template', $plugin) as $templatesPath) {
         array_walk($paths, function (&$path) use($templatesPath) {
             if (substr($path, 0, strlen($templatesPath)) == $templatesPath) {
                 $path = substr($path, strlen($templatesPath));
             }
         });
     }
     return $paths;
 }
예제 #7
0
파일: UnionView.php 프로젝트: Cheren/union
 /**
  * Renders view for given template file and layout.
  *
  * @param null $view
  * @param null $layout
  * @return string|void
  */
 public function render($view = null, $layout = null)
 {
     if (is_null($view) && in_array($this->request->param('action'), ['edit', 'add'])) {
         $searchPaths = App::path('Template', $this->plugin);
         $formViewFile = $this->__findViewByRequest($searchPaths);
         if (!$formViewFile) {
             $view = 'form';
         }
     }
     if ($this->Union->isAdmin()) {
         $this->Assets->widget('.jsToggle', 'UnionFieldToggle', ['csrfToken' => $this->request->cookie('csrfToken')]);
     }
     return parent::render($view, $layout);
 }
예제 #8
0
 /**
  * Bake the plugin, create directories and files
  *
  * @param string $plugin Name of the plugin in CamelCased format
  * @return bool
  */
 public function bake($plugin)
 {
     $pathOptions = App::path('Plugin');
     if (count($pathOptions) > 1) {
         $this->findPath($pathOptions);
     }
     $this->hr();
     $this->out(sprintf("<info>Plugin Name:</info> %s", $plugin));
     $this->out(sprintf("<info>Plugin Directory:</info> %s", $this->path . $plugin));
     $this->hr();
     $classBase = 'src';
     $looksGood = $this->in('Look okay?', ['y', 'n', 'q'], 'y');
     if (strtolower($looksGood) === 'y') {
         $Folder = new Folder($this->path . $plugin);
         $directories = ['config', $classBase . DS . 'Model' . DS . 'Behavior', $classBase . DS . 'Model' . DS . 'Table', $classBase . DS . 'Model' . DS . 'Entity', $classBase . DS . 'Shell' . DS . 'Task', $classBase . DS . 'Controller' . DS . 'Component', $classBase . DS . 'View' . DS . 'Helper', $classBase . DS . 'Template', 'tests' . DS . 'TestCase' . DS . 'Controller' . DS . 'Component', 'tests' . DS . 'TestCase' . DS . 'View' . DS . 'Helper', 'tests' . DS . 'TestCase' . DS . 'Model' . DS . 'Behavior', 'tests' . DS . 'Fixture', 'webroot'];
         foreach ($directories as $directory) {
             $dirPath = $this->path . $plugin . DS . $directory;
             $Folder->create($dirPath);
             new File($dirPath . DS . 'empty', true);
         }
         foreach ($Folder->messages() as $message) {
             $this->out($message, 1, Shell::VERBOSE);
         }
         $errors = $Folder->errors();
         if (!empty($errors)) {
             foreach ($errors as $message) {
                 $this->error($message);
             }
             return false;
         }
         $controllerFileName = 'AppController.php';
         $out = "<?php\n\n";
         $out .= "namespace {$plugin}\\Controller;\n\n";
         $out .= "use App\\Controller\\AppController as BaseController;\n\n";
         $out .= "class AppController extends BaseController {\n\n";
         $out .= "}\n";
         $this->createFile($this->path . $plugin . DS . $classBase . DS . 'Controller' . DS . $controllerFileName, $out);
         $emptyFile = $this->path . 'empty';
         $this->_deleteEmptyFile($emptyFile);
         $hasAutoloader = $this->_modifyAutoloader($plugin, $this->path);
         $this->_generateRoutes($plugin, $this->path);
         $this->_modifyBootstrap($plugin, $hasAutoloader);
         $this->_generatePhpunitXml($plugin, $this->path);
         $this->_generateTestBootstrap($plugin, $this->path);
         $this->hr();
         $this->out(sprintf('<success>Created:</success> %s in %s', $plugin, $this->path . $plugin), 2);
     }
     return true;
 }
예제 #9
0
 /**
  * Execution method always used for tasks.
  *
  * @return void
  */
 public function main()
 {
     if (!empty($this->params['exclude'])) {
         $this->_exclude = explode(',', $this->params['exclude']);
     }
     if (isset($this->params['files']) && !is_array($this->params['files'])) {
         $this->_files = explode(',', $this->params['files']);
     }
     if (isset($this->params['paths'])) {
         $this->_paths = explode(',', $this->params['paths']);
     } elseif (isset($this->params['plugin'])) {
         $plugin = Inflector::camelize($this->params['plugin']);
         if (!Plugin::loaded($plugin)) {
             Plugin::load($plugin);
         }
         $this->_paths = [Plugin::classPath($plugin)];
         $this->params['plugin'] = $plugin;
     } else {
         $this->_getPaths();
     }
     if (isset($this->params['extract-core'])) {
         $this->_extractCore = !(strtolower($this->params['extract-core']) === 'no');
     } else {
         $response = $this->in('Would you like to extract the messages from the CakePHP core?', ['y', 'n'], 'n');
         $this->_extractCore = strtolower($response) === 'y';
     }
     if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) {
         $this->_exclude = array_merge($this->_exclude, App::path('Plugin'));
     }
     if (!empty($this->params['validation-domain'])) {
         $this->_validationDomain = $this->params['validation-domain'];
     }
     if ($this->_extractCore) {
         $this->_paths[] = CAKE;
     }
     if (isset($this->params['merge'])) {
         $this->_merge = !(strtolower($this->params['merge']) === 'no');
     } else {
         $this->out();
         $response = $this->in('Would you like to merge all domain strings into the default.pot file?', ['y', 'n'], 'n');
         $this->_merge = strtolower($response) === 'y';
     }
     if (empty($this->_files)) {
         $this->_searchFiles();
     }
     $this->_extract();
 }
예제 #10
0
 /**
  * Return all possible paths to find view files in order
  *
  * This method overrides cakephp's default method because it doesn't allow
  * to override themes by default
  *
  * @param string|null $plugin Optional plugin name to scan for view files.
  * @param bool $cached Set to false to force a refresh of view paths. Default true.
  * @return array paths
  */
 protected function _paths($plugin = null, $cached = true)
 {
     $paths = parent::_paths($plugin, $cached);
     $templatePaths = App::path('Template');
     $themeOverridePaths = [];
     if (!empty($this->theme)) {
         for ($i = 0, $count = count($templatePaths); $i < $count; $i++) {
             $themeOverridePaths[] = $templatePaths[$i] . $this->theme . DS;
             if ($plugin) {
                 $themedPluginOverride = end($themeOverridePaths) . 'Plugin' . DS . $plugin . DS;
                 array_unshift($themeOverridePaths, $themedPluginOverride);
             }
         }
     }
     $paths = array_merge($themeOverridePaths, $paths);
     return $this->_paths = $paths;
 }
예제 #11
0
파일: Theme.php 프로젝트: UnionCMS/Core
 /**
  * Find theme path.
  *
  * @param string $name
  * @return null|string
  */
 protected static function _find($name)
 {
     $paths = App::path('Plugin');
     foreach ($paths as $path) {
         $path = FS::clean($path . '/', DS);
         $details = explode(DS, rtrim($path, DS));
         $folder = Str::trim(array_pop($details));
         $themeFolder = $path . $name;
         if (Arr::in($folder, self::$_skipFolder) || !FS::isDir($themeFolder)) {
             $themeFolder .= self::POSTFIX;
         }
         if (FS::isDir($themeFolder)) {
             return $themeFolder;
         }
     }
     return null;
 }
예제 #12
0
 /**
  * Bake the plugin's contents
  *
  * Also update the autoloader and the root composer.json file if it can be found
  *
  * @param string $plugin Name of the plugin in CamelCased format
  * @return bool
  */
 public function bake($plugin)
 {
     $pathOptions = App::path('Plugin');
     if (count($pathOptions) > 1) {
         $this->findPath($pathOptions);
     }
     $this->out(sprintf("<info>Plugin Name:</info> %s", $plugin));
     $this->out(sprintf("<info>Plugin Directory:</info> %s", $this->path . $plugin));
     $this->hr();
     $looksGood = $this->in('Look okay?', ['y', 'n', 'q'], 'y');
     if (strtolower($looksGood) !== 'y') {
         return;
     }
     $this->_generateFiles($plugin, $this->path);
     $hasAutoloader = $this->_modifyAutoloader($plugin, $this->path);
     $this->_modifyBootstrap($plugin, $hasAutoloader);
     $this->hr();
     $this->out(sprintf('<success>Created:</success> %s in %s', $plugin, $this->path . $plugin), 2);
     return true;
 }
예제 #13
0
 /**
  * Gets the shell command listing.
  *
  * @return array
  */
 public function getShellList()
 {
     $skipFiles = ['AppShell'];
     $hiddenCommands = ['CommandListShell', 'CompletionShell'];
     $plugins = Plugin::loaded();
     $shellList = array_fill_keys($plugins, null) + ['CORE' => null, 'app' => null];
     $appPath = App::path('Shell');
     $appShells = $this->_scanDir($appPath[0]);
     $appShells = array_diff($appShells, $skipFiles);
     $shellList = $this->_appendShells('app', $appShells, $shellList);
     $shells = $this->_scanDir(dirname(__DIR__));
     $shells = array_diff($shells, $appShells, $skipFiles, $hiddenCommands);
     $shellList = $this->_appendShells('CORE', $shells, $shellList);
     foreach ($plugins as $plugin) {
         $pluginPath = Plugin::classPath($plugin) . 'Shell';
         $pluginShells = $this->_scanDir($pluginPath);
         $shellList = $this->_appendShells($plugin, $pluginShells, $shellList);
     }
     return array_filter($shellList);
 }
예제 #14
0
 /**
  * Returns an array with avilable widget identifiers
  *
  * @return array
  */
 public static function getAvailableWidgets()
 {
     $widgets = [];
     $config = Configure::read('Cms.Widgets.availableWidgets');
     if (is_array($config)) {
         return $config;
     }
     $namespace = Configure::read('App.namespace');
     $widgetPaths = App::path('Widget');
     foreach ($widgetPaths as $widgetPath) {
         $appWidgetsFolder = new Folder($widgetPath);
         $contents = $appWidgetsFolder->read(true);
         foreach ($contents[0] as $folderName) {
             $widgetIdentifier = "{$namespace}.{$folderName}";
             if (self::widgetExists($widgetIdentifier)) {
                 $widgets[] = $widgetIdentifier;
             }
         }
     }
     $plugins = Plugin::loaded();
     foreach ($plugins as $plugin) {
         $widgetsPath = Plugin::classPath($plugin) . 'Widget/';
         if (!is_dir($widgetsPath)) {
             continue;
         }
         $pluginWidgetsFolder = new Folder($widgetsPath);
         $contents = $pluginWidgetsFolder->read(true);
         foreach ($contents[0] as $folderName) {
             $widgetIdentifier = "{$plugin}.{$folderName}";
             if (self::widgetExists($widgetIdentifier)) {
                 $widgets[] = $widgetIdentifier;
             }
         }
     }
     $excludedWidgets = Configure::read('Cms.Widgets.excludedWidgets');
     $widgets = array_filter($widgets, function ($widgetIdentifier) use($excludedWidgets) {
         return !in_array($widgetIdentifier, $excludedWidgets);
     });
     return $widgets;
 }
예제 #15
0
 /**
  * Renders the help document of the given plugin.
  *
  * @param string $pluginName The plugin name
  * @return void
  * @throws \Cake\Network\Exception\NotFoundException When no help document was found
  */
 public function about($pluginName)
 {
     $about = false;
     if (Plugin::loaded($pluginName)) {
         $locale = I18n::locale();
         $templatePath = App::path('Template', $pluginName)[0] . 'Element/Help/';
         $lookFor = ["help_{$locale}", 'help'];
         foreach ($lookFor as $ctp) {
             if (is_readable($templatePath . "{$ctp}.ctp")) {
                 $about = "{$pluginName}.Help/{$ctp}";
                 break;
             }
         }
     }
     if ($about) {
         $this->set('about', $about);
     } else {
         throw new NotFoundException(__d('system', 'No help was found.'));
     }
     $this->title(__d('system', 'About "{0}"', $pluginName));
     $this->Breadcrumb->push('/admin/system/help')->push(__d('system', 'About {0}', $pluginName), '#');
 }
예제 #16
0
파일: Plugin.php 프로젝트: Cheren/union
 /**
  * Checking the existence of a plugin and its connection.
  *
  * @param array $plugins
  */
 public static function load(array $plugins)
 {
     $paths = App::path('Plugin');
     foreach ($plugins as $plugin) {
         $isPlugin = false;
         if (CakePlugin::loaded($plugin)) {
             break;
         }
         foreach ($paths as $path) {
             $pluginPath = $path . $plugin . DS;
             if (is_dir($pluginPath)) {
                 $isPlugin = $pluginPath;
                 break;
             }
         }
         if ($pluginPath = $isPlugin) {
             $plgConfig = ['autoload' => true];
             //  Plugin config files.
             $plgBootstrap = $pluginPath . 'config' . DS . self::$_pluginsSrc['bootstrap'];
             $plgRoutes = $pluginPath . 'config' . DS . self::$_pluginsSrc['routes'];
             $plgEvents = $pluginPath . 'config' . DS . self::$_pluginsSrc['events'];
             if (file_exists($plgBootstrap)) {
                 $plgConfig['bootstrap'] = true;
             }
             if (file_exists($plgRoutes)) {
                 $plgConfig['routes'] = true;
             }
             CakePlugin::load($plugin, $plgConfig);
             if (CakePlugin::loaded($plugin)) {
                 Union::mergeConfig('App.paths.locales', [$pluginPath . 'src' . DS . 'Locale' . DS]);
                 if (file_exists($plgEvents)) {
                     Configure::load($plugin . '.events');
                 }
             }
         } else {
             throw new MissingPluginException(['plugin' => $plugin]);
         }
     }
 }
예제 #17
0
 /**
  * Paths for multi-site templates support.
  *
  * @param null $plugin
  * @param bool $cached
  * @return array
  */
 public function _paths($plugin = null, $cached = true)
 {
     if ($cached === true) {
         if ($plugin === null && !empty($this->_paths)) {
             return $this->_paths;
         }
         if ($plugin !== null && isset($this->_pathsForPlugin[$plugin])) {
             return $this->_pathsForPlugin[$plugin];
         }
     }
     $templatePaths = App::path('Template');
     $pluginPaths = $themePaths = [];
     if (!empty($plugin)) {
         for ($i = 0, $count = count($templatePaths); $i < $count; $i++) {
             // start customization
             // original // $pluginPaths[] = $templatePaths[$i] . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR;
             $pluginPaths[] = sprintf($templatePaths[$i] . DIRECTORY_SEPARATOR, $plugin);
             // end customization
         }
         $pluginPaths = array_merge($pluginPaths, App::path('Template', $plugin));
     }
     if (!empty($this->theme)) {
         $themePaths = App::path('Template', Inflector::camelize($this->theme));
         if ($plugin) {
             for ($i = 0, $count = count($themePaths); $i < $count; $i++) {
                 // start customization
                 // original // array_unshift($themePaths, $themePaths[$i] . 'Plugin' . DIRECTORY_SEPARATOR . $plugin . DIRECTORY_SEPARATOR);
                 array_unshift($themePaths, str_replace('vendor', SITE_DIR . DS . 'vendor', $themePaths[$i]));
                 // end customization
             }
         }
     }
     $paths = array_merge($themePaths, $pluginPaths, $templatePaths, [dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Template' . DIRECTORY_SEPARATOR]);
     if ($plugin !== null) {
         return $this->_pathsForPlugin[$plugin] = $paths;
     }
     return $this->_paths = $paths;
 }
예제 #18
0
 protected function _paths($plugin = null, $cached = true)
 {
     if ($cached === true) {
         if ($plugin === null && !empty($this->_paths)) {
             return $this->_paths;
         }
         if ($plugin !== null && isset($this->_pathsForPlugin[$plugin])) {
             return $this->_pathsForPlugin[$plugin];
         }
     }
     $prefix = $this->_prefix();
     if (empty($prefix) || !isset($this->themes) || !isset($this->themes[$prefix])) {
         return parent::_paths($plugin, $cached);
     }
     $folderName = key($this->themes[$prefix]);
     $theme = $this->themes[$prefix][$folderName];
     $makeup = [App::path('Template')[0] . $folderName . DS, App::path('Template', Inflector::camelize($theme))[0]];
     $paths = parent::_paths($plugin, $cached);
     $paths = array_merge($makeup, $paths);
     if ($plugin !== null) {
         return $this->_pathsForPlugin[$plugin] = $paths;
     }
     return $this->_paths = $paths;
 }
예제 #19
0
 /**
  * Gets a static page
  * @param string $slug Slug
  * @return string|bool Static page or false
  * @uses MeCms\Core\Plugin::all()
  */
 public static function get($slug)
 {
     //Sets the file (partial) name
     $file = implode(DS, af(explode('/', $slug)));
     //Sets the file patterns
     $patterns = [sprintf('%s-%s', $file, I18n::locale()), $file];
     //Checks if the page exists in APP
     foreach ($patterns as $pattern) {
         $file = firstValue(App::path('Template')) . 'StaticPages' . DS . $pattern . '.ctp';
         if (is_readable($file)) {
             return 'StaticPages' . DS . $pattern;
         }
     }
     //Checks if the page exists in all plugins, beginning with MeCms
     foreach (Plugin::all() as $plugin) {
         foreach ($patterns as $pattern) {
             $file = firstValue(App::path('Template', $plugin)) . 'StaticPages' . DS . $pattern . '.ctp';
             if (is_readable($file)) {
                 return sprintf('%s.%s', $plugin, 'StaticPages' . DS . $pattern);
             }
         }
     }
     return false;
 }
 public function findTemplatePaths()
 {
     $controller = $this->_registry->getController();
     $defaultViewPaths = App::path('Template');
     $pos = array_search(APP . 'Template' . DS, $defaultViewPaths);
     if ($pos !== false) {
         $viewPaths = array_splice($defaultViewPaths, 0, $pos + 1);
     } else {
         $viewPaths = $defaultViewPaths;
     }
     if ($plugin = $controller->viewBuilder()->plugin()) {
         $viewPaths = array_merge($viewPaths, App::path('Template', $plugin));
     }
     if ($theme = $controller->viewBuilder()->theme()) {
         foreach (App::path('Template', $theme) as $themePath) {
             $viewPaths[] = $themePath;
             if ($plugin) {
                 $viewPaths[] = $themePath . 'Plugin' . DS . $plugin . DS;
             }
         }
     }
     $viewPaths = array_merge($viewPaths, $defaultViewPaths);
     return array_reverse(array_unique($viewPaths));
 }
 /**
  * Will load all the plugins located in the default plugin folder.
  *
  * If passed an options array, it will be used as a common default for all plugins to be loaded
  * It is possible to set specific defaults for each plugins in the options array. Examples:
  *
  * ```
  *  Plugin::loadAll([
  *      ['bootstrap' => true],
  *      'DebugKit' => ['routes' => true],
  *  ]);
  * ```
  *
  * The above example will load the bootstrap file for all plugins, but for DebugKit it will only load the routes file
  * and will not look for any bootstrap script.
  *
  * If a plugin has been loaded already, it will not be reloaded by loadAll().
  *
  * @param array $options Options.
  * @return void
  */
 public static function loadAll(array $options = [])
 {
     static::_loadConfig();
     $plugins = [];
     foreach (App::path('Plugin') as $path) {
         if (!is_dir($path)) {
             continue;
         }
         $dir = new DirectoryIterator($path);
         foreach ($dir as $path) {
             if ($path->isDir() && !$path->isDot()) {
                 $plugins[] = $path->getBaseName();
             }
         }
     }
     if (Configure::check('plugins')) {
         $plugins = array_merge($plugins, array_keys(Configure::read('plugins')));
         $plugins = array_unique($plugins);
     }
     foreach ($plugins as $p) {
         $opts = isset($options[$p]) ? $options[$p] : null;
         if ($opts === null && isset($options[0])) {
             $opts = $options[0];
         }
         if (isset(static::$_plugins[$p])) {
             continue;
         }
         static::load($p, (array) $opts);
     }
 }
예제 #22
0
 /**
  * Test that findPath ignores paths that don't exist.
  *
  * @return void
  */
 public function testFindPathNonExistent()
 {
     $paths = App::path('Plugin');
     array_unshift($paths, '/fake/path');
     $paths[] = '/fake/path2';
     $this->Task = $this->getMock('Bake\\Shell\\Task\\PluginTask', ['in', 'out', 'err', '_stop'], [$this->io]);
     $this->Task->path = TMP . 'tests' . DS;
     $this->Task->method('findPath')->will($this->returnValue($paths[0]));
     $this->Task->findPath($paths);
 }
예제 #23
0
 /**
  * Execution method always used for tasks
  *
  * @return void
  */
 public function main()
 {
     if (!empty($this->params['exclude'])) {
         $this->_exclude = explode(',', $this->params['exclude']);
     }
     if (isset($this->params['files']) && !is_array($this->params['files'])) {
         $this->_files = explode(',', $this->params['files']);
     }
     if (isset($this->params['paths'])) {
         $this->_paths = explode(',', $this->params['paths']);
     } elseif (isset($this->params['plugin'])) {
         $plugin = Inflector::camelize($this->params['plugin']);
         if (!Plugin::loaded($plugin)) {
             Plugin::load($plugin);
         }
         $this->_paths = [Plugin::classPath($plugin)];
         $this->params['plugin'] = $plugin;
     } else {
         $this->_getPaths();
     }
     if (isset($this->params['extract-core'])) {
         $this->_extractCore = !(strtolower($this->params['extract-core']) === 'no');
     } else {
         $response = $this->in('Would you like to extract the messages from the CakePHP core?', ['y', 'n'], 'n');
         $this->_extractCore = strtolower($response) === 'y';
     }
     if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) {
         $this->_exclude = array_merge($this->_exclude, App::path('Plugin'));
     }
     if (!empty($this->params['validation-domain'])) {
         $this->_validationDomain = $this->params['validation-domain'];
     }
     if ($this->_extractCore) {
         $this->_paths[] = CAKE;
     }
     if (isset($this->params['output'])) {
         $this->_output = $this->params['output'];
     } elseif (isset($this->params['plugin'])) {
         $this->_output = $this->_paths[0] . 'Locale';
     } else {
         $message = "What is the path you would like to output?\n[Q]uit";
         while (true) {
             $response = $this->in($message, null, rtrim($this->_paths[0], DS) . DS . 'Locale');
             if (strtoupper($response) === 'Q') {
                 $this->err('Extract Aborted');
                 $this->_stop();
                 return;
             } elseif ($this->_isPathUsable($response)) {
                 $this->_output = $response . DS;
                 break;
             } else {
                 $this->err('');
                 $this->err('<error>The directory path you supplied was ' . 'not found. Please try again.</error>');
             }
             $this->out();
         }
     }
     if (isset($this->params['merge'])) {
         $this->_merge = !(strtolower($this->params['merge']) === 'no');
     } else {
         $this->out();
         $response = $this->in('Would you like to merge all domain strings into the default.pot file?', ['y', 'n'], 'n');
         $this->_merge = strtolower($response) === 'y';
     }
     if (empty($this->_files)) {
         $this->_searchFiles();
     }
     $this->_output = rtrim($this->_output, DS) . DS;
     if (!$this->_isPathUsable($this->_output)) {
         $this->err(sprintf('The output directory %s was not found or writable.', $this->_output));
         $this->_stop();
         return;
     }
     $this->_extract();
 }
예제 #24
0
 /**
  * Scan plugin directories and returns plugin names and their paths within file
  * system. We consider "plugin name" as the name of the container directory.
  *
  * Example output:
  *
  * ```php
  * [
  *     'Users' => '/full/path/plugins/Users/',
  *     'ThemeManager' => '/full/path/plugins/ThemeManager/',
  *     ...
  *     'MySuperPlugin' => '/full/path/plugins/MySuperPlugin/',
  *     'DarkGreenTheme' => '/full/path/plugins/DarkGreenTheme/',
  * ]
  * ```
  *
  * If $ignoreThemes is set to true `DarkGreenTheme` will not be part of the
  * result.
  *
  * NOTE: All paths includes trailing slash.
  *
  * @param bool $ignoreThemes Whether include themes as well or not
  * @return array Associative array as `PluginName` => `/full/path/to/PluginName`
  */
 public static function scan($ignoreThemes = false)
 {
     $cacheKey = "scan({$ignoreThemes})";
     $cache = static::cache($cacheKey);
     if (!$cache) {
         $cache = [];
         $paths = App::path('Plugin');
         $Folder = new Folder();
         $Folder->sort = true;
         foreach ($paths as $path) {
             $Folder->cd($path);
             foreach ($Folder->read(true, true, true)[0] as $dir) {
                 $name = basename($dir);
                 $cache[$name] = normalizePath("{$dir}/");
             }
         }
         // look for Cake plugins installed using Composer
         if (file_exists(VENDOR_INCLUDE_PATH . 'cakephp-plugins.php')) {
             $cakePlugins = (array) (include VENDOR_INCLUDE_PATH . 'cakephp-plugins.php');
             if (!empty($cakePlugins['plugins'])) {
                 $cache = Hash::merge($cakePlugins['plugins'], $cache);
             }
         }
         // filter, remove hidden folders and others
         foreach ($cache as $name => $path) {
             if (strpos($name, '.') === 0) {
                 unset($cache[$name]);
             } elseif ($name == 'CMS') {
                 unset($cache[$name]);
             } elseif ($ignoreThemes && str_ends_with($name, 'Theme')) {
                 unset($cache[$name]);
             }
         }
         $cache = static::cache($cacheKey, $cache);
     }
     return $cache;
 }
예제 #25
0
 /**
  * Test prefix routing and plugin combinations
  *
  * @return void
  */
 public function testPrefixRoutingAndPlugins()
 {
     Configure::write('Routing.prefixes', array('admin'));
     $paths = App::path('Plugin');
     Plugin::load(array('TestPlugin'));
     Router::reload();
     require CAKE . 'Config/routes.php';
     $request = new Request();
     Router::setRequestInfo($request->addParams(array('controller' => 'controller', 'action' => 'action', 'plugin' => null, 'prefix' => 'admin'))->addPaths(array('base' => '/', 'here' => '/', 'webroot' => '/base/')));
     Router::parse('/');
     $result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'test_plugin', 'action' => 'index'));
     $expected = '/admin/test_plugin';
     $this->assertEquals($expected, $result);
     Router::reload();
     require CAKE . 'Config/routes.php';
     $request = new Request();
     Router::setRequestInfo($request->addParams(array('plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'edit', 'pass' => array('6'), 'prefix' => 'admin'))->addPaths(array('base' => '/', 'here' => '/admin/shows/show_tickets/edit/6', 'webroot' => '/')));
     $result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'edit', 6, 'prefix' => 'admin'));
     $expected = '/admin/test_plugin/show_tickets/edit/6';
     $this->assertEquals($expected, $result);
     $result = Router::url(array('plugin' => 'test_plugin', 'controller' => 'show_tickets', 'action' => 'index', 'prefix' => 'admin'));
     $expected = '/admin/test_plugin/show_tickets';
     $this->assertEquals($expected, $result);
 }
예제 #26
0
 /**
  * Override initialize
  *
  * @return void
  */
 public function initialize()
 {
     $this->path = current(App::path('Template'));
 }
예제 #27
0
<?php

/**
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright     Copyright (c) Mindforce Team (http://mindforce.me)
* @link          http://mindforce.me RearEngine CakePHP 3 Plugin
* @since         0.0.1
* @license       http://www.opensource.org/licenses/mit-license.php MIT License
*/
use Cake\Core\Configure;
use Cake\Database\Type;
use Cake\Core\App;
use Cake\Event\EventManager;
use Cake\Core\Plugin;
Plugin::loadAll([['ignoreMissing' => true, 'bootstrap' => true, 'routes' => true], 'Platform', 'Garderobe/Bootstrap3', 'Garderobe/BootstrapKit', 'PlumSearch', 'Search']);
// Setup RearEngine as theme does not provide layout and view overriding
// so we just add it as additional templates path
Configure::write('App.paths.templates', array_merge([APP . 'Template' . DS . 'Plugin' . DS . 'RearEngine' . DS], App::path('Template', 'RearEngine'), App::path('Template')));
Configure::write('Routing.prefixes', ['admin']);
EventManager::instance()->attach(new RearEngine\Event\CoreEvent(), null, ['priority' => 2]);
예제 #28
0
 /**
  * Return all possible paths to find view files in order
  *
  * @param string|null $plugin Optional plugin name to scan for view files.
  * @param bool $cached Set to false to force a refresh of view paths. Default true.
  * @return array paths
  */
 protected function _paths($plugin = null, $cached = true)
 {
     if ($cached === true) {
         if ($plugin === null && !empty($this->_paths)) {
             return $this->_paths;
         }
         if ($plugin !== null && isset($this->_pathsForPlugin[$plugin])) {
             return $this->_pathsForPlugin[$plugin];
         }
     }
     $templatePaths = App::path('Template');
     $pluginPaths = $themePaths = [];
     if (!empty($plugin)) {
         for ($i = 0, $count = count($templatePaths); $i < $count; $i++) {
             $pluginPaths[] = $templatePaths[$i] . 'Plugin' . DS . $plugin . DS;
         }
         $pluginPaths = array_merge($pluginPaths, App::path('Template', $plugin));
     }
     if (!empty($this->theme)) {
         $themePaths = App::path('Template', Inflector::camelize($this->theme));
         if ($plugin) {
             for ($i = 0, $count = count($templatePaths); $i < $count; $i++) {
                 array_unshift($themePaths, $themePaths[$i] . 'Plugin' . DS . $plugin . DS);
             }
         }
     }
     $paths = array_merge($themePaths, $pluginPaths, $templatePaths, [dirname(__DIR__) . DS . 'Template' . DS]);
     if ($plugin !== null) {
         return $this->_pathsForPlugin[$plugin] = $paths;
     }
     return $this->_paths = $paths;
 }
예제 #29
0
 /**
  * setUp method
  *
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     Configure::write('App.namespace', 'TestApp');
     $this->_pluginPaths = App::path('Plugin');
 }
예제 #30
0
 /**
  * Find the correct path for a plugin. Scans $pluginPaths for the plugin you want.
  *
  * @param string $pluginName Name of the plugin you want ie. DebugKit
  * @return string path path to the correct plugin.
  */
 protected function _pluginPath($pluginName)
 {
     if (Plugin::loaded($pluginName)) {
         return Plugin::path($pluginName);
     }
     return current(App::path('Plugin')) . $pluginName . DIRECTORY_SEPARATOR;
 }