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;
 }
Esempio n. 5
0
 /**
  * Regenerates the theme list
  * @return bool true
  * @throws \Exception
  */
 public static function regenerate()
 {
     $boot = new \Zikula\Bundle\CoreBundle\Bundle\Bootstrap();
     $helper = new \Zikula\Bundle\CoreBundle\Bundle\Helper\BootstrapHelper($boot->getConnection(ServiceUtil::getManager()->get('kernel')));
     // sync the filesystem and the bundles table
     $helper->load();
     // Get all themes on filesystem
     $filethemes = array();
     $scanner = new Scanner();
     $scanner->scan(array('themes'), 4);
     $newThemes = $scanner->getThemesMetaData();
     foreach ($newThemes as $name => $theme) {
         foreach ($theme->getPsr0() as $ns => $path) {
             ZLoader::addPrefix($ns, $path);
         }
         foreach ($theme->getPsr4() as $ns => $path) {
             ZLoader::addPrefixPsr4($ns, $path);
         }
         $class = $theme->getClass();
         /** @var $bundle \Zikula\Core\AbstractTheme */
         $bundle = new $class();
         $class = $bundle->getVersionClass();
         $version = new $class($bundle);
         $version['name'] = $bundle->getName();
         $array = $version->toArray();
         unset($array['id']);
         $directory = explode('/', $bundle->getRelativePath());
         array_shift($directory);
         $array['directory'] = implode('/', $directory);
         // loads the gettext domain for theme
         ZLanguage::bindThemeDomain($bundle->getName());
         $array['type'] = 3;
         $array['state'] = 1;
         $array['contact'] = 3;
         $array['xhtml'] = 1;
         $filethemes[$bundle->getName()] = $array;
     }
     $dirArray = FileUtil::getFiles('themes', false, true, null, 'd');
     foreach ($dirArray as $dir) {
         // Work out the theme type
         if (file_exists("themes/{$dir}/version.php")) {
             $themetype = 3;
             // set defaults
             $themeversion['name'] = preg_replace('/_/', ' ', $dir);
             $themeversion['displayname'] = preg_replace('/_/', ' ', $dir);
             $themeversion['version'] = '0';
             $themeversion['description'] = '';
             include "themes/{$dir}/version.php";
         } else {
             // anything else isn't a theme
             continue;
         }
         $filethemes[$themeversion['name']] = array('directory' => $dir, 'name' => $themeversion['name'], 'type' => 3, 'displayname' => isset($themeversion['displayname']) ? $themeversion['displayname'] : $themeversion['name'], 'version' => isset($themeversion['version']) ? $themeversion['version'] : '1.0.0', 'description' => isset($themeversion['description']) ? $themeversion['description'] : $themeversion['displayname'], 'admin' => isset($themeversion['admin']) ? (int) $themeversion['admin'] : '0', 'user' => isset($themeversion['user']) ? (int) $themeversion['user'] : '******', 'system' => isset($themeversion['system']) ? (int) $themeversion['system'] : '0', 'state' => isset($themeversion['state']) ? $themeversion['state'] : ThemeUtil::STATE_ACTIVE, 'contact' => isset($themeversion['contact']) ? $themeversion['contact'] : '', 'xhtml' => isset($themeversion['xhtml']) ? (int) $themeversion['xhtml'] : 1);
         unset($themeversion);
         unset($themetype);
     }
     $sm = ServiceUtil::getManager();
     $entityManager = $sm->get('doctrine.entitymanager');
     $dbthemes = array();
     $themeEntities = $entityManager->getRepository('ZikulaThemeModule:ThemeEntity')->findAll();
     foreach ($themeEntities as $entity) {
         $entity = $entity->toArray();
         $dbthemes[$entity['name']] = $entity;
     }
     // See if we have lost any themes since last generation
     foreach ($dbthemes as $name => $themeinfo) {
         if (empty($filethemes[$name])) {
             // delete a running configuration
             try {
                 ModUtil::apiFunc('ZikulaThemeModule', 'admin', 'deleterunningconfig', array('themename' => $name));
             } catch (\Exception $e) {
                 if (\System::isInstalling()) {
                     // silent fail when installing or upgrading
                 } else {
                     throw $e;
                 }
             }
             // delete item from db
             $item = $entityManager->getRepository('ZikulaThemeModule:ThemeEntity')->findOneBy(array('name' => $name));
             $entityManager->remove($item);
             unset($dbthemes[$name]);
         }
     }
     // See if we have gained any themes since last generation,
     // or if any current themes have been upgraded
     foreach ($filethemes as $name => $themeinfo) {
         if (empty($dbthemes[$name])) {
             // new theme
             $themeinfo['state'] = ThemeUtil::STATE_ACTIVE;
             // add item to db
             $item = new ThemeEntity();
             $item->merge($themeinfo);
             $entityManager->persist($item);
         }
     }
     // see if any themes have changed
     foreach ($filethemes as $name => $themeinfo) {
         if (isset($dbthemes[$name])) {
             if ($themeinfo['directory'] != $dbthemes[$name]['directory'] || $themeinfo['type'] != $dbthemes[$name]['type'] || $themeinfo['version'] != $dbthemes[$name]['version'] || $themeinfo['admin'] != $dbthemes[$name]['admin'] || $themeinfo['user'] != $dbthemes[$name]['user'] || $themeinfo['system'] != $dbthemes[$name]['system'] || $themeinfo['state'] != $dbthemes[$name]['state'] || $themeinfo['contact'] != $dbthemes[$name]['contact'] || $themeinfo['xhtml'] != $dbthemes[$name]['xhtml']) {
                 $themeinfo['id'] = $dbthemes[$name]['id'];
                 // update item
                 /** @var $item ThemeEntity */
                 $item = $entityManager->getRepository('ZikulaThemeModule:ThemeEntity')->find($themeinfo['id']);
                 $item->merge($themeinfo);
             }
         }
     }
     $entityManager->flush();
     return true;
 }