/** * 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(); }
public function onControllerInit($event) { $controller = $event->subject(); if (isset($controller->request->params['prefix'])) { $menuFile = $controller->request->params['prefix'] . '_menus'; if ($theme = Configure::read('App.admin.theme')) { if ($theme != '' && $theme != 'RearEngine' && Plugin::loaded($theme)) { $controller->viewBuilder()->theme($theme); } } foreach (Plugin::loaded() as $plugin) { try { Configure::load($plugin . '.' . $menuFile, 'default', true); } catch (\Exception $e) { if (Configure::read('debug')) { Log::warning('Unable to load app ' . $plugin . '/Config/' . $menuFile . ' config file', ['scope' => 'RearEngine plugin']); } } } try { Configure::load($menuFile, 'default', true); } catch (\Exception $e) { if (Configure::read('debug')) { Log::warning('Unable to load App/Config/' . $menuFile . ' config file.', ['scope' => 'RearEngine plugin']); } } } }
/** * Get list of plugins to process. Plugins without a webroot directory are skipped. * * @param string|null $name Name of plugin for which to symlink assets. * If null all plugins will be processed. * @return array List of plugins with meta data. */ protected function _list($name = null) { if ($name === null) { $pluginsList = Plugin::loaded(); } else { if (!Plugin::loaded($name)) { $this->err(sprintf('Plugin %s is not loaded.', $name)); return []; } $pluginsList = [$name]; } $plugins = []; foreach ($pluginsList as $plugin) { $path = Plugin::path($plugin) . 'webroot'; if (!is_dir($path)) { $this->out('', 1, Shell::VERBOSE); $this->out(sprintf('Skipping plugin %s. It does not have webroot folder.', $plugin), 2, Shell::VERBOSE); continue; } $link = Inflector::underscore($plugin); $dir = WWW_ROOT; $namespaced = false; if (strpos($link, '/') !== false) { $namespaced = true; $parts = explode('/', $link); $link = array_pop($parts); $dir = WWW_ROOT . implode(DIRECTORY_SEPARATOR, $parts) . DIRECTORY_SEPARATOR; } $plugins[$plugin] = ['srcPath' => Plugin::path($plugin) . 'webroot', 'destDir' => $dir, 'link' => $link, 'namespaced' => $namespaced]; } return $plugins; }
/** * Internal method to resolve partial paths, returning full paths * @param string|array $paths Partial paths * @return array * @throws InternalErrorException * @use $type */ protected function _resolvePath($paths) { $loadedPlugins = Plugin::loaded(); return array_map(function ($path) use($loadedPlugins) { $pluginSplit = pluginSplit($path); //Note that using `pluginSplit()` is not sufficient, because // `$path` may still contain a dot if (!empty($pluginSplit[0]) && in_array($pluginSplit[0], $loadedPlugins)) { list($plugin, $path) = $pluginSplit; } if (substr($path, 0, 1) === '/') { $path = substr($path, 1); } else { $path = $this->type . DS . $path; } if (!empty($plugin)) { $path = Plugin::path($plugin) . 'webroot' . DS . $path; } else { $path = WWW_ROOT . $path; } //Appends the file extension, if not already present if (pathinfo($path, PATHINFO_EXTENSION) !== $this->type) { $path = sprintf('%s.%s', $path, $this->type); } if (!file_exists($path)) { throw new InternalErrorException(__d('assets', 'File `{0}` doesn\'t exist', str_replace(APP, null, $path))); } return $path; }, (array) $paths); }
/** * 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; }
/** * Builds asset file path based on the provided $url. * * @param string $url Asset URL * @return string|void Absolute path for asset file */ protected function _getAssetFile($url) { $parts = explode('/', $url); $pluginPart = []; $plugin = false; for ($i = 0; $i < 2; $i++) { if (!isset($parts[$i])) { break; } $pluginPart[] = Inflector::camelize($parts[$i]); $possiblePlugin = implode('/', $pluginPart); if ($possiblePlugin && Plugin::loaded($possiblePlugin)) { $plugin = $possiblePlugin; $parts = array_slice($parts, $i + 1); break; } } $isAssetRequest = isset($parts[0]) && $parts[0] === 'ASSETS'; if ($isAssetRequest && Configure::read('debug')) { $parts = array_slice($parts, 1); } else { $isAssetRequest = false; } if ($plugin && Plugin::loaded($plugin)) { return $this->_getPluginAsset($plugin, $parts, $isAssetRequest); } else { return $this->_getAppAsset($parts, $isAssetRequest); } }
public function index() { if (Plugin::loaded('Search')) { $this->Currencies->addBehavior('Search.Searchable'); $this->Common->loadComponent('Search.Prg'); $this->Prg->commonProcess(); $currencies = $this->paginate($this->Currencies->find('searchable', $this->Prg->parsedParams())); } else { $currencies = $this->paginate(); } $baseCurrency = []; foreach ($currencies as $currency) { if ($currency['Currency']['base']) { $baseCurrency = $currency; break; } } if (empty($baseCurrency)) { $baseCurrency = $this->Currencies->find('first', ['conditions' => ['base' => true]]); if (!$baseCurrency) { $this->Flash->warning(__('noBaseCurrency')); } } $this->set(compact('baseCurrency', 'currencies')); }
public function onControllerInit($event) { $controller = $event->subject(); if (($theme = Configure::read('App.theme')) && Plugin::loaded($theme)) { $controller->viewBuilder()->theme($theme); } }
public function injectEditor(Event $event, $layoutFile) { $_view = $event->subject(); $content = $_view->fetch('content'); if (Configure::read('Editorial.autoload')) { $searchClass = Configure::read('Editorial.autoload'); if (empty($searchClass)) { $searchClass = 'editor'; } $plugin = Configure::read('Editorial.editor'); list($vendor, $class) = $this->vendorSplit($plugin); $searchRegex = '/(<textarea.*class\\=\\".*' . Configure::read('Editorial.class') . '.*\\"[^>]*>.*<\\/textarea>)/isU'; //preg_match_all($searchRegex, $content, $matches); //debug($matches); if (Plugin::loaded($plugin) !== false && preg_match_all($searchRegex, $content, $matches)) { if (!$_view->helpers()->has('Editor')) { $options['className'] = $class . '.' . $class; if ($vendor) { $options['className'] = $vendor . '/' . $options['className']; } $options['options'] = $plugin . '.defaults'; if ($editorDefaults = Configure::read('Editorial.' . $class . '.defaults')) { $options['options'] = $editorDefaults; } $_view->loadHelper('Editor', $options); $_view->Editor->initialize(); } $_view->Editor->connect($content); } } }
public function callback() { if (Plugin::loaded('Passengers')) { $session = $this->request->session(); $user = $session->read('Auth.User'); if (!isset($user['id'])) { exit; } } $opts = Configure::read('Summernote.elFinder'); foreach ($opts['roots'] as $key => $root) { if (isset($root['primary']) || $root['primary'] === true) { if (Plugin::loaded('Passengers') && $user['role_id'] != 4) { $root['path'] .= DS . 'users_content' . DS . 'user_' . $user['id']; $root['URL'] .= 'users_content/user_' . $user['id'] . '/'; } } if ($dir = new Folder($root['path'], true, 0755)) { $opts['roots'][$key]['path'] = $root['path']; $opts['roots'][$key]['URL'] = $root['URL']; } unset($dir); } // run elFinder $connector = new elFinderConnector(new elFinder($opts)); $connector->run(); }
public static function load($name) { $path = THREEPLUGINS . $name; if (file_exists($path . DS . 'plugin.ini')) { $basename = basename($path); $config = (new IniReader())->readFile($path . DS . 'plugin.ini')->toArray(); if (array_key_exists('enabled', $config) && $config['enabled'] === true) { if (\Cake\Core\Plugin::loaded('ThreePlugins/' . $basename) === true) { return true; } if (array_key_exists('depend', $config)) { if (is_array($config['depend'])) { foreach ($config['depend'] as $v) { if (!\Cake\Core\Plugin::loaded($v) && self::load($v) !== true) { throw new MissingDependencyException('Missing dependency ' . $v . ' for plugin ' . $name); } } } else { if (!\Cake\Core\Plugin::loaded($config['depend']) && self::load($config['depend']) !== true) { throw new MissingDependencyException('Missing dependency ' . $config['depend'] . ' for plugin ' . $name); } } } \Cake\Core\Plugin::load('ThreePlugins/' . $basename, ['autoload' => true, 'bootstrap' => array_key_exists('bootstrap', $config) ? $config['bootstrap'] : false, 'routes' => array_key_exists('routes', $config) ? $config['routes'] : false]); $class = '\\ThreePlugins\\' . $basename . '\\' . $basename . 'Plugin'; if (!class_exists($class)) { throw new FileNotFoundException('Missing class ' . $class . ' into the plugin ' . $name); } (new $class())->initialize(); return true; } } return false; }
public function onControllerInit(Event $event) { $controller = $event->subject(); //Skip Auth for non app controllers. DebugKit For example //possible injection hole, but needed. if (!in_array('App\\Controller\\AppController', class_parents($controller))) { return; } $controller->loadComponent('Cookie'); $loginRedirect = '/'; if (isset($controller->request->params['prefix'])) { $loginRedirect .= $controller->request->params['prefix']; } $controller->loadComponent('Auth', ['loginAction' => ['plugin' => 'Passengers', 'controller' => 'Users', 'action' => 'signin'], 'loginRedirect' => $loginRedirect, 'logoutRedirect' => ['plugin' => 'Passengers', 'controller' => 'Users', 'action' => 'signin'], 'unauthorizedRedirect' => ['plugin' => 'Passengers', 'controller' => 'Users', 'action' => 'signin'], 'authenticate' => [AuthComponent::ALL => ['fields' => ['username' => 'username', 'password' => 'password'], 'userModel' => 'Passengers.Users', 'finder' => 'active'], 'Form', 'Passengers.Cookie']]); $authorizeConfig = []; if ($authorizers = Configure::read('Passengers.authorizers')) { foreach ($authorizers as $key => $authorizer) { if (isset($authorizer['className']) && ($plugin = pluginSplit($authorizer['className'])[0])) { if (!Plugin::loaded($plugin)) { continue; } } $authorizeConfig[$key] = $authorizer; } } $forceAuth = Configure::read('App.force_user_auth'); if ($forceAuth && empty($authorizeConfig)) { $authorizeConfig[] = 'Controller'; } $controller->Auth->config('authorize', array(AuthComponent::ALL => ['actionPath' => 'controllers/']) + $authorizeConfig); $this->_setUser($controller); $controller->loadComponent('Passengers.AuthUser'); $controller->viewBuilder()->helpers(['Passengers.AuthUser']); }
/** * Initialize table config. * * @param array $config Config options * @return void */ public function initialize(array $config) { $this->table('tags_tags'); $this->displayField('label'); if (Plugin::loaded('Muffin/Slug')) { $this->addBehavior('Muffin/Slug.Slug'); } }
/** * Locate the tasks bake will use. * * Scans the following paths for tasks that are subclasses of * Cake\Shell\Task\BakeTask: * * - Cake/Shell/Task/ * - App/Shell/Task/ * - Shell/Task for each loaded plugin * * @return void */ public function loadTasks() { $tasks = []; $tasks = $this->_findTasks($tasks, APP, Configure::read('App.namespace')); foreach (Plugin::loaded() as $plugin) { $tasks = $this->_findTasks($tasks, Plugin::classPath($plugin), $plugin, $plugin); } $this->tasks = array_values($tasks); parent::loadTasks(); }
/** * @param string|null $path * @return string */ protected function getPath($path = null) { if ($path === null) { $path = ROOT . DS; } elseif ($path === 'core') { $path = CORE_PATH; } elseif (Plugin::loaded($path)) { $path = Plugin::path($path); } return $path; }
/** * Inject search conditions to the qeury object. * * @param \Cake\Event\Event $event Event * @return void */ public function injectSearch(Event $event) { if (!Plugin::loaded('Search')) { throw new RuntimeException('You need to load the Search plugin in order to use the SearchListener.'); } if (!in_array($event->name, $this->config('enabled'))) { return; } $filterParams = $this->_table()->filterParams($this->_request()->query); $event->subject->query->find('search', $filterParams); }
/** * Setup helpers * * @return void */ protected function _setupHelpers() { $this->loadHelper('Html', ['className' => 'BootstrapUI.Html']); $this->loadHelper('Form', ['className' => 'BootstrapUI.Form', 'widgets' => ['datetime' => ['CrudView\\View\\Widget\\DateTimeWidget', 'select']]]); $this->loadHelper('Flash', ['className' => 'BootstrapUI.Flash']); $this->loadHelper('Paginator', ['className' => 'BootstrapUI.Paginator']); $this->loadHelper('CrudView.CrudView'); $this->loadHelper('BootstrapUI.Flash'); if (Plugin::loaded('AssetCompress')) { $this->loadHelper('AssetCompress.AssetCompress'); } }
/** * LanguagesController::admin_index() * * @return void */ public function index() { if (Plugin::loaded('Search')) { $this->Languages->addBehavior('Search.Searchable'); $this->Common->loadComponent('Search.Prg'); $this->Prg->commonProcess(); $languages = $this->paginate($this->Languages->find('searchable', $this->Prg->parsedParams())); } $language = $this->Languages->newEntity(); $languages = $this->paginate(); $this->set(compact('languages', 'language')); }
/** * Resolve a plugin file to its full path. * * @param string $file The theme file to find. * @throws RuntimeException when plugins are missing. * @return string The expanded path */ protected function _expandPlugin($file) { preg_match(self::PLUGIN_PATTERN, $file, $matches); if (empty($matches[1]) || empty($matches[2])) { throw new RuntimeException('Missing required parameters'); } if (!Plugin::loaded($matches[1])) { throw new RuntimeException($matches[1] . ' is not a loaded plugin.'); } $path = Plugin::path($matches[1]); return $path . 'webroot' . DS . $matches[2]; }
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; }
/** * Union migrate manager constructor. * * @param null $plugin */ public function __construct($plugin = null) { if (Plugin::loaded($plugin)) { $this->_connectionConfig = ConnectionManager::config($this->_connectionName); $this->_adapterName = $this->_getAdapterName($this->_connectionConfig['driver']); $config = ['paths' => ['migrations' => UnionPlugin::migrationPath($plugin)], 'environments' => $this->_configuration()]; $this->_plugin = $plugin; $this->_config = new Config($config); $adapterOptions = $this->_config->getEnvironment($this->_connectionName); $this->_adapter = $this->_setAdapter($adapterOptions); } }
/** * Initialize method * * @param array $config The configuration for the Table. * @return void */ public function initialize(array $config) { parent::initialize($config); $this->table('users'); $this->displayField('username'); $this->primaryKey('id'); $this->addBehavior('Timestamp'); $this->addBehavior('Muffin/Trash.Trash'); $this->addBehavior('Muffin/Tokenize.Tokenize'); if (Plugin::loaded('Search')) { $this->addBehavior('Search.Search'); } }
/** * Method that returns all controller names. * @param bool $includePlugins flag for including plugin controllers * @return array controller names */ protected function _getAllControllers($includePlugins = true) { $controllers = $this->_getDirControllers(APP . 'Controller' . DS); if ($includePlugins === true) { $plugins = \Cake\Core\Plugin::loaded(); foreach ($plugins as $plugin) { // plugin path $path = \Cake\Core\Plugin::path($plugin) . 'src' . DS . 'Controller' . DS; $controllers = array_merge($controllers, $this->_getDirControllers($path, $plugin)); } } return $controllers; }
/** * On setup admin application data. * * @param Event $event */ public function onSetupAdminData(Event $event) { $controller = $event->subject(); $plugins = Plugin::loaded(); foreach ($plugins as $plugin) { $pluginPath = Plugin::path($plugin); $adminNav = $pluginPath . 'config' . DS . 'admin_menu.php'; if (file_exists($adminNav)) { /** @noinspection PhpIncludeInspection */ require_once $adminNav; } } }
/** * Finds all plugins with a Template directory. * * @return array */ protected static function pluginsWithTemplates() { $plugins = Plugin::loaded(); array_walk($plugins, function ($plugin, $index) use(&$plugins) { $paths = App::path('Template', $plugin); array_walk($paths, function ($path, $index) use(&$paths) { if (!is_dir($path)) { unset($paths[$index]); } }); }); return $plugins; }
/** * Faz uma instalação básica do plugin. * A instalação consiste em criar o arquivo de configurações do plugin no diretório apropriado. * Este método é chamado pelo método PluginStarter::load() quando necessário. * * @param string $pluginName O nome do plugin a ser instalado. * @return void */ public function install($pluginName) { $settingsFileFolder = $this->pluginInstallationFolder . $pluginName . DS; if (Plugin::loaded($pluginName)) { $defaultFile = Plugin::path($pluginName) . 'config' . DS . 'default_settings.php'; $folderHandler = new Folder(); if (!$folderHandler->cd($settingsFileFolder)) { $folderHandler->create($settingsFileFolder); } $fileHandler = new File($defaultFile); $fileHandler->copy($settingsFileFolder . 'settings.php'); $fileHandler->close(); } }
/** * Load all configuration files in the application. * * Loads: * * - The app config (asset_compress.ini) * - The asset_compress.ini file in each plugin. * * In addition for each file found the `asset_compress.local.ini` * will be loaded if it is present. * * @param string $path The configuration file path to start loading from. * @return \MiniAsset\AssetConfig The completed configuration object. */ public function loadAll($path = null) { if (!$path) { $path = CONFIG . 'asset_compress.ini'; } $config = new AssetConfig([], ['WEBROOT' => WWW_ROOT]); $this->_load($config, $path); $plugins = Plugin::loaded(); foreach ($plugins as $plugin) { $pluginConfig = Plugin::path($plugin) . 'config' . DS . 'asset_compress.ini'; $this->_load($config, $pluginConfig, $plugin . '.'); } return $config; }
/** * Inject search conditions to the qeury object. * * @param \Cake\Event\Event $event Event * @return void */ public function injectSearch(Event $event) { if (!Plugin::loaded('Search')) { throw new RuntimeException('You need to load the Search plugin in order to use the SearchListener.'); } if (!in_array($event->name, $this->config('enabled'))) { return; } $table = $this->_table(); if (!$table->behaviors()->hasMethod('filterParams')) { throw new RuntimeException(sprintf('Missing Search.Search behavior on %s', get_class($table))); } $filterParams = $table->filterParams($this->_request()->query); $event->subject->query->find('search', $filterParams); }
/** * CountryProvincesController::admin_index() * * @param mixed $cid * @return void */ public function index($cid = null) { $cid = $this->_processCountry($cid); if (Plugin::loaded('Search')) { $this->CountryProvinces->addBehavior('Search.Searchable'); $this->Common->loadComponent('Search.Prg'); $this->Prg->commonProcess(); $countryProvinces = $this->paginate($this->CountryProvinces->find('searchable', $this->Prg->parsedParams())); } else { $countryProvinces = $this->paginate(); } $countries = $this->CountryProvinces->Countries->find('list'); $this->set(compact('countryProvinces', 'countries')); $this->helpers[] = 'Geo.GoogleMapV3'; }
public static function paths() { if (empty(self::$_paths)) { $path = 'DashboardWidget' . DS; self::$_paths[] = APP . $path; foreach (Plugin::loaded() as $plugin) { // skip, to force inclusion at end of array if ('Gourmet/Dashboard' == $plugin) { continue; } self::$_paths[] = Plugin::path($plugin) . 'src' . DS . $path; } self::$_paths[] = Plugin::path('Gourmet/Dashboard') . 'src' . DS . $path; } return self::$_paths; }