Esempio n. 1
0
 public function load()
 {
     $scanner = new Scanner();
     $scanner->scan(array('modules', 'themes'), 5);
     $array = array_merge($scanner->getModulesMetaData(), $scanner->getThemesMetaData());
     $array = array_merge($array, $scanner->getPluginsMetaData());
     $this->sync($array);
 }
Esempio n. 2
0
 public function enterNode(\Twig_NodeInterface $node, \Twig_Environment $env)
 {
     $this->stack[] = $node;
     if ($node instanceof \Twig_Node_Expression_Function) {
         $name = $node->getAttribute('name');
         if (in_array($name, $this->methodNames)) {
             $args = $node->getNode('arguments');
             switch ($name) {
                 case '_n':
                 case '_fn':
                     $id = $args->getNode(0)->getAttribute('value') . '|' . $args->getNode(1)->getAttribute('value');
                     break;
                 default:
                 case '__f':
                 case '__':
                     $id = $args->getNode(0)->getAttribute('value');
                     break;
             }
             // obtain translation domain from composer file
             $composerPath = str_replace($this->file->getRelativePathname(), '', $this->file->getPathname());
             if (isset(self::$domainCache[$composerPath])) {
                 $domain = self::$domainCache[$composerPath];
             } else {
                 $scanner = new Scanner();
                 $scanner->scan(array($composerPath), 1);
                 $metaData = $scanner->getModulesMetaData(true);
                 $domains = array_keys($metaData);
                 if (isset($domains[0])) {
                     $domain = strtolower($domains[0]);
                     // cache result of file lookup
                     self::$domainCache[$composerPath] = $domain;
                 } else {
                     $domain = 'messages';
                 }
             }
             $domainNode = array_search($name, $this->methodNames);
             $domain = $args->hasNode($domainNode) ? $args->getNode($domainNode)->getAttribute('value') : $domain;
             $message = new Message($id, $domain);
             $message->addSource(new FileSource((string) $this->file, $node->getLine()));
             $this->catalogue->add($message);
         }
     }
     return $node;
 }
Esempio n. 3
0
 /**
  * Scan the file system for modules.
  *
  * This function scans the file system for modules and returns an array with all (potential) modules found.
  * This information is used to regenerate the module list.
  *
  * @throws AccessDeniedException Thrown if the user doesn't have admin permissions over the module
  * @throws \RuntimeException Thrown if the version information of a module cannot be found
  *
  * @return array An array of modules found in the file system.
  */
 public function getfilemodules()
 {
     // Security check
     if (!System::isInstalling()) {
         if (!SecurityUtil::checkPermission('ZikulaExtensionsModule::', '::', ACCESS_ADMIN)) {
             throw new AccessDeniedException();
         }
     }
     $boot = new \Zikula\Bundle\CoreBundle\Bundle\Bootstrap();
     $helper = new \Zikula\Bundle\CoreBundle\Bundle\Helper\BootstrapHelper($boot->getConnection($this->getContainer()->get('kernel')));
     // sync the filesystem and the bundles table
     $helper->load();
     // Get all modules on filesystem
     $filemodules = array();
     $scanner = new Scanner();
     $scanner->scan(array('system', 'modules'), 5);
     $newModules = $scanner->getModulesMetaData();
     // scan for all bundle-type modules (psr-0 & psr-4) in either /system or /modules
     foreach ($newModules as $name => $module) {
         foreach ($module->getPsr0() as $ns => $path) {
             ZLoader::addPrefix($ns, $path);
         }
         foreach ($module->getPsr4() as $ns => $path) {
             ZLoader::addPrefixPsr4($ns, $path);
         }
         $class = $module->getClass();
         /** @var $bundle \Zikula\Core\AbstractModule */
         $bundle = new $class();
         $class = $bundle->getVersionClass();
         $version = new $class($bundle);
         $version['name'] = $bundle->getName();
         $array = $version->toArray();
         unset($array['id']);
         // Work out if admin-capable
         if (file_exists($bundle->getPath() . '/Controller/AdminController.php')) {
             $caps = $array['capabilities'];
             $caps['admin'] = array('version' => '1.0');
             $array['capabilities'] = $caps;
         }
         // Work out if user-capable
         if (file_exists($bundle->getPath() . '/Controller/UserController.php')) {
             $caps = $array['capabilities'];
             $caps['user'] = array('version' => '1.0');
             $array['capabilities'] = $caps;
         }
         // loads the gettext domain for 3rd party modules
         if (!strpos($bundle->getPath(), 'modules') === false) {
             ZLanguage::bindModuleDomain($bundle->getName());
         }
         $array['capabilities'] = serialize($array['capabilities']);
         $array['securityschema'] = serialize($array['securityschema']);
         $array['dependencies'] = serialize($array['dependencies']);
         $filemodules[$bundle->getName()] = $array;
         $filemodules[$bundle->getName()]['oldnames'] = isset($array['oldnames']) ? $array['oldnames'] : '';
     }
     // set the paths to search
     $rootdirs = array('modules' => ModUtil::TYPE_MODULE);
     // do not scan `/system` since all are accounted for above
     // scan for legacy modules
     // NOTE: the scan below does rescan all psr-0 & psr-4 type modules and intentionally fails.
     foreach ($rootdirs as $rootdir => $moduletype) {
         if (is_dir($rootdir)) {
             $dirs = FileUtil::getFiles($rootdir, false, true, null, 'd');
             foreach ($dirs as $dir) {
                 $oomod = false;
                 // register autoloader
                 if (file_exists("{$rootdir}/{$dir}/Version.php") || is_dir("{$rootdir}/{$dir}/lib")) {
                     ZLoader::addAutoloader($dir, array($rootdir, "{$rootdir}/{$dir}/lib"));
                     ZLoader::addPrefix($dir, $rootdir);
                     $oomod = true;
                 }
                 // loads the gettext domain for 3rd party modules
                 if (is_dir("modules/{$dir}/locale")) {
                     ZLanguage::bindModuleDomain($dir);
                 }
                 try {
                     $modversion = ExtensionsUtil::getVersionMeta($dir, $rootdir);
                 } catch (\Exception $e) {
                     throw new \RuntimeException($e->getMessage());
                     continue;
                 }
                 if (!$modversion) {
                     continue;
                 }
                 if (!isset($modversion['capabilities'])) {
                     $modversion['capabilities'] = array();
                 }
                 $name = $dir;
                 // Get the module version
                 if (!$modversion instanceof Zikula_AbstractVersion) {
                     if (isset($modversion['profile']) && $modversion['profile']) {
                         $modversion['capabilities']['profile'] = '1.0';
                     }
                     if (isset($modversion['message']) && $modversion['message']) {
                         $modversion['capabilities']['message'] = '1.0';
                     }
                 } elseif ($oomod) {
                     // Work out if admin-capable
                     if (file_exists("{$rootdir}/{$dir}/lib/{$dir}/Controller/Admin.php")) {
                         $caps = $modversion['capabilities'];
                         $caps['admin'] = array('version' => '1.0');
                         $modversion['capabilities'] = $caps;
                     }
                     // Work out if user-capable
                     if (file_exists("{$rootdir}/{$dir}/lib/{$dir}/Controller/User.php")) {
                         $caps = $modversion['capabilities'];
                         $caps['user'] = array('version' => '1.0');
                         $modversion['capabilities'] = $caps;
                     }
                 }
                 $version = $modversion['version'];
                 $description = $modversion['description'];
                 if (isset($modversion['displayname']) && !empty($modversion['displayname'])) {
                     $displayname = $modversion['displayname'];
                 } else {
                     $displayname = $modversion['name'];
                 }
                 $capabilities = serialize($modversion['capabilities']);
                 // bc for urls
                 if (isset($modversion['url']) && !empty($modversion['url'])) {
                     $url = $modversion['url'];
                 } else {
                     $url = $displayname;
                 }
                 if (isset($modversion['securityschema']) && is_array($modversion['securityschema'])) {
                     $securityschema = serialize($modversion['securityschema']);
                 } else {
                     $securityschema = serialize(array());
                 }
                 $core_min = isset($modversion['core_min']) ? $modversion['core_min'] : '';
                 $core_max = isset($modversion['core_max']) ? $modversion['core_max'] : '';
                 $oldnames = isset($modversion['oldnames']) ? $modversion['oldnames'] : '';
                 if (isset($modversion['dependencies']) && is_array($modversion['dependencies'])) {
                     $moddependencies = serialize($modversion['dependencies']);
                 } else {
                     $moddependencies = serialize(array());
                 }
                 $filemodules[$name] = array('directory' => $dir, 'name' => $name, 'type' => $moduletype, 'displayname' => $displayname, 'url' => $url, 'oldnames' => $oldnames, 'version' => $version, 'capabilities' => $capabilities, 'description' => $description, 'securityschema' => $securityschema, 'dependencies' => $moddependencies, 'core_min' => $core_min, 'core_max' => $core_max);
                 // important: unset modversion and modtype, otherwise the
                 // following modules will have some values not defined in
                 // the next version files to be read
                 unset($modversion);
                 unset($modtype);
             }
         }
     }
     return $filemodules;
 }
Esempio n. 4
0
 /**
  * Gets the object associated with a given module name
  *
  * @param string $moduleName
  * @param boolean $force = false Force load a module and add autoloaders
  *
  * @return null|\Zikula\Core\AbstractModule
  */
 public static function getModule($moduleName, $force = false)
 {
     /** @var $kernel Zikula\Bundle\CoreBundle\HttpKernel\ZikulaKernel */
     $kernel = ServiceUtil::getManager()->get('kernel');
     try {
         return $kernel->getModule($moduleName);
     } catch (\InvalidArgumentException $e) {
     }
     if ($force) {
         $modInfo = self::getInfo(self::getIdFromName($moduleName));
         if (empty($modInfo)) {
             throw new \RuntimeException(__('Error! No such module exists.'));
         }
         $osDir = DataUtil::formatForOS($modInfo['directory']);
         $modPath = $modInfo['type'] == self::TYPE_SYSTEM ? "system" : "modules";
         $scanner = new Scanner();
         $scanner->scan(array("{$modPath}/{$osDir}"), 1);
         $modules = $scanner->getModulesMetaData(true);
         /** @var $moduleMetaData \Zikula\Bundle\CoreBundle\Bundle\MetaData */
         $moduleMetaData = !empty($modules[$modInfo['name']]) ? $modules[$modInfo['name']] : null;
         if (null !== $moduleMetaData) {
             // moduleMetaData only exists for bundle-type modules
             $boot = new \Zikula\Bundle\CoreBundle\Bundle\Bootstrap();
             $boot->addAutoloaders($kernel, $moduleMetaData->getAutoload());
             if ($modInfo['type'] == self::TYPE_MODULE) {
                 if (is_dir("modules/{$osDir}/Resources/locale")) {
                     ZLanguage::bindModuleDomain($modInfo['name']);
                 }
             }
             $moduleClass = $moduleMetaData->getClass();
             return new $moduleClass();
         }
     }
     return null;
 }