Example #1
0
 /**
  * @inheritdoc
  */
 public function process(array $params, \Smarty_Internal_Template $smarty)
 {
     if (isset($params['module'], $params['file']) === true && (bool) preg_match('=/=', $params['module']) === false && (bool) preg_match('=\\./=', $params['file']) === false) {
         // Do not include the same file multiple times
         $key = $params['module'] . '/' . $params['file'];
         if (isset($this->alreadyIncluded[$key]) === false) {
             if (!empty($params['depends'])) {
                 $this->assets->enableLibraries(explode(',', $params['depends']));
             }
             $this->alreadyIncluded[$key] = true;
             $script = '<script type="text/javascript" src="%s"></script>';
             $module = ucfirst($params['module']);
             $file = $params['file'];
             $path = $this->fileResolver->getStaticAssetPath($module . '/Resources/', $module . '/', 'Assets/js', $file . '.js');
             if (strpos($path, '/ACP3/Modules/') !== false) {
                 $path = $this->appPath->getWebRoot() . substr($path, strpos($path, '/ACP3/Modules/') + 1);
             } else {
                 $path = $this->appPath->getWebRoot() . substr($path, strlen(ACP3_ROOT_DIR));
             }
             return sprintf($script, $path);
         }
         return '';
     }
     throw new \Exception('Not all necessary arguments for the function ' . __FUNCTION__ . ' were passed!');
 }
Example #2
0
 private function setUpContainer()
 {
     $this->set('core.http.symfony_request', $this->symfonyRequest);
     $this->set('core.environment.application_path', $this->applicationPath);
     $this->setParameter('core.environment', $this->applicationMode);
     $this->addCompilerPass(new RegisterListenersPass('core.event_dispatcher', 'core.eventListener', 'core.eventSubscriber'));
     $this->addCompilerPass(new RegisterSmartyPluginsPass());
     $this->addCompilerPass(new RegisterColumnRendererPass());
     $this->addCompilerPass(new RegisterValidationRulesPass());
     $this->addCompilerPass(new RegisterWysiwygEditorsCompilerPass());
     $this->addCompilerPass(new RegisterColumnTypesCompilerPass());
     $loader = new YamlFileLoader($this, new FileLocator(__DIR__));
     $loader->load($this->applicationPath->getClassesDir() . 'config/services.yml');
     $loader->load($this->applicationPath->getClassesDir() . 'View/Renderer/Smarty/config/services.yml');
     // Try to get all available services
     /** @var Modules $modules */
     $modules = $this->get('core.modules');
     $availableModules = $this->allModules === true ? $modules->getAllModules() : $modules->getActiveModules();
     $vendors = $this->get('core.modules.vendors')->getVendors();
     foreach ($availableModules as $module) {
         foreach ($vendors as $vendor) {
             $modulePath = $this->applicationPath->getModulesDir() . $vendor . '/' . $module['dir'];
             $path = $modulePath . '/Resources/config/services.yml';
             if (is_file($path)) {
                 $loader->load($path);
             }
             $this->registerCompilerPass($vendor, $module['dir']);
         }
     }
     $this->compile();
 }
Example #3
0
 /**
  * @param string $text
  *
  * @return string
  */
 public function rewriteInternalUri($text)
 {
     $rootDir = str_replace('/', '\\/', $this->appPath->getWebRoot());
     $host = $this->request->getServer()->get('HTTP_HOST');
     $pattern = '/<a([^>]+)href="(http(s?):\\/\\/' . $host . ')?(' . $rootDir . ')?(index\\.php)?(\\/?)((?i:[a-z\\d_\\-]+\\/){2,})"/i';
     return preg_replace_callback($pattern, [$this, "rewriteInternalUriCallback"], $text);
 }
Example #4
0
 /**
  * @param \Symfony\Component\HttpFoundation\Response $response
  * @param \ACP3\Core\Environment\ApplicationPath     $appPath
  * @param string                                     $environment
  */
 public function __construct(Response $response, ApplicationPath $appPath, $environment)
 {
     $this->response = $response;
     $this->appPath = $appPath;
     $this->environment = $environment;
     $this->cacheDir = $this->appPath->getCacheDir() . 'images/';
 }
Example #5
0
File: Logger.php Project: acp3/core
 /**
  * @param string $channel
  * @param string $level
  */
 private function createChannel($channel, $level)
 {
     $fileName = $this->appPath->getCacheDir() . 'logs/' . $channel . '.log';
     $logLevelConst = constant(\Monolog\Logger::class . '::' . strtoupper($level));
     $stream = new StreamHandler($fileName, $logLevelConst);
     $stream->setFormatter(new LineFormatter(null, null, true));
     $this->channels[$channel] = new \Monolog\Logger($channel, [$stream]);
 }
Example #6
0
File: Smarty.php Project: acp3/core
 /**
  * @param array $params
  *
  * @throws \SmartyException
  */
 public function configure(array $params = [])
 {
     $this->smarty->setErrorReporting($this->isDevOrInstall() ? E_ALL : 0);
     $this->smarty->setCompileId(!empty($params['compile_id']) ? $params['compile_id'] : $this->environment);
     $this->smarty->setCompileCheck($this->isDevOrInstall());
     $this->smarty->setCompileDir($this->appPath->getCacheDir() . 'tpl_compiled/');
     $this->smarty->setCacheDir($this->appPath->getCacheDir() . 'tpl_cached/');
 }
Example #7
0
File: Assets.php Project: acp3/core
 /**
  * Checks, whether the current design uses Bootstrap or not
  *
  * @param \ACP3\Core\Environment\ApplicationPath $appPath
  * @param Libraries $libraries
  */
 public function __construct(ApplicationPath $appPath, Libraries $libraries)
 {
     $this->designXml = simplexml_load_file($appPath->getDesignPathInternal() . 'info.xml');
     $this->libraries = $libraries;
     if (isset($this->designXml->use_bootstrap) && (string) $this->designXml->use_bootstrap === 'true') {
         $this->enableLibraries(['bootstrap']);
     }
     $this->libraries->dispatchAddLibraryEvent();
 }
 public function invalidatePageCache()
 {
     if ($this->canUsePageCache->canUsePageCache()) {
         if ($this->settings->getSettings(Schema::MODULE_NAME)['page_cache_purge_mode'] == 1) {
             Purge::doPurge($this->applicationPath->getCacheDir() . 'http');
         } else {
             $this->settings->saveSettings(['page_cache_is_valid' => false], Schema::MODULE_NAME);
         }
     }
 }
Example #9
0
 /**
  * @param string $driverName
  * @param string $driverNameFqn
  *
  * @return \Doctrine\Common\Cache\CacheProvider
  */
 protected function initializeCacheDriver($driverName, $driverNameFqn)
 {
     /** @var \Doctrine\Common\Cache\CacheProvider $driver */
     switch (strtolower($driverName)) {
         case 'phpfile':
             $cacheDir = $this->appPath->getCacheDir() . 'sql/';
             return new $driverNameFqn($cacheDir);
         default:
             return new $driverNameFqn();
     }
 }
 public function invalidatePageCache()
 {
     if ($this->canUsePageCache->canUsePageCache()) {
         if ($this->settings->getSettings(Schema::MODULE_NAME)['page_cache_purge_mode'] == 1) {
             Purge::doPurge($this->applicationPath->getCacheDir() . 'http');
         } else {
             $systemModuleId = $this->modules->getModuleId(Schema::MODULE_NAME);
             $this->settingsRepository->update(['value' => false], ['module_id' => $systemModuleId, 'name' => 'page_cache_is_valid']);
         }
     }
 }
Example #11
0
 /**
  * Caches the emoticons
  *
  * @return boolean
  */
 public function saveCache()
 {
     $emoticons = $this->emoticonRepository->getAll();
     $cEmoticons = count($emoticons);
     $data = [];
     for ($i = 0; $i < $cEmoticons; ++$i) {
         $picInfos = getimagesize($this->appPath->getUploadsDir() . 'emoticons/' . $emoticons[$i]['img']);
         $code = $emoticons[$i]['code'];
         $description = $emoticons[$i]['description'];
         $data[$code] = '<img src="' . $this->appPath->getWebRoot() . 'uploads/emoticons/' . $emoticons[$i]['img'] . '" width="' . $picInfos[0] . '" height="' . $picInfos[1] . '" alt="' . $description . '" title="' . $description . '" />';
     }
     return $this->cache->save(static::CACHE_ID, $data);
 }
Example #12
0
 /**
  * @param string $modulePath
  * @param string $designPath
  * @param string $dir
  * @param string $file
  *
  * @return string
  */
 private function resolveAssetPath($modulePath, $designPath, $dir, $file)
 {
     if ($this->designAssetsPath === null) {
         $this->designAssetsPath = $this->appPath->getDesignPathInternal();
     }
     $assetPath = '';
     $designAssetPath = $this->designAssetsPath . $designPath . $dir . $file;
     // A theme has overridden a static asset of a module
     if (is_file($designAssetPath) === true) {
         $assetPath = $designAssetPath;
     } else {
         $designInfo = $this->xml->parseXmlFile($this->designAssetsPath . '/info.xml', '/design');
         // Recursively iterate over the nested themes
         if (!empty($designInfo['parent'])) {
             $this->designAssetsPath = $this->appPath->getDesignRootPathInternal() . $designInfo['parent'] . '/';
             $assetPath = $this->getStaticAssetPath($modulePath, $designPath, $dir, $file);
             $this->designAssetsPath = $this->appPath->getDesignPathInternal();
             return $assetPath;
         }
         // No overrides have been found -> iterate over all possible module namespaces
         foreach (array_reverse($this->vendors->getVendors()) as $vendor) {
             $moduleAssetPath = $this->appPath->getModulesDir() . $vendor . '/' . $modulePath . $dir . $file;
             if (is_file($moduleAssetPath) === true) {
                 $assetPath = $moduleAssetPath;
                 break;
             }
         }
     }
     $systemAssetPath = $this->appPath->getModulesDir() . $modulePath . $dir . $file;
     $this->cachedPaths[$systemAssetPath] = $assetPath;
     $this->newAssetPathsAdded = true;
     return $assetPath;
 }
Example #13
0
 /**
  * Setzt den internen Authentifizierungscookie
  *
  * @param int $userId
  * @param string $token
  * @param integer|null $expiry
  *
  * @return Cookie
  */
 public function setRememberMeCookie($userId, $token, $expiry = null)
 {
     if ($expiry === null) {
         $expiry = static::REMEMBER_ME_COOKIE_LIFETIME;
     }
     return new Cookie(self::AUTH_NAME, $userId . '|' . $token, (new \DateTime())->modify('+' . $expiry . ' seconds'), $this->appPath->getWebRoot(), $this->getCookieDomain(), $this->request->getSymfonyRequest()->isSecure());
 }
Example #14
0
File: Upload.php Project: acp3/core
 /**
  * Löscht eine Datei im uploads Ordner
  *
  * @param string $file
  *
  * @return boolean
  */
 public function removeUploadedFile($file)
 {
     $path = $this->appPath->getUploadsDir() . $this->directory . '/' . $file;
     if (!empty($file) && !preg_match('=/=', $file) && is_file($path) === true) {
         return unlink($path);
     }
     return false;
 }
Example #15
0
 /**
  * @return $this
  * @throws Core\ACL\Exception\AccessForbiddenException
  */
 public function preDispatch()
 {
     $path = $this->request->getArea() . '/' . $this->request->getFullPathWithoutArea();
     if ($this->acl->hasPermission($path) === false) {
         throw new Core\ACL\Exception\AccessForbiddenException();
     }
     $this->view->assign(['PHP_SELF' => $this->appPath->getPhpSelf(), 'ROOT_DIR' => $this->appPath->getWebRoot(), 'HOST_NAME' => $this->request->getHttpHost(), 'ROOT_DIR_ABSOLUTE' => $this->request->getScheme() . '://' . $this->request->getHttpHost() . $this->appPath->getWebRoot(), 'DESIGN_PATH' => $this->appPath->getDesignPathWeb(), 'DESIGN_PATH_ABSOLUTE' => $this->appPath->getDesignPathAbsolute(), 'LANG_DIRECTION' => $this->translator->getDirection(), 'LANG' => $this->translator->getShortIsoCode()]);
     return $this;
 }
Example #16
0
 /**
  * @inheritdoc
  */
 public function route($path, $absolute = false, $forceSecure = false)
 {
     $path = $path . (!preg_match('/\\/$/', $path) ? '/' : '');
     $pathArray = preg_split('=/=', $path, -1, PREG_SPLIT_NO_EMPTY);
     if (isset($pathArray[1]) === false) {
         $path .= 'index/';
     }
     if (isset($pathArray[2]) === false) {
         $path .= 'index/';
     }
     $prefix = '';
     // Append the current hostname to the URL
     if ($absolute === true) {
         $prefix .= $forceSecure === true ? 'https://' : $this->request->getScheme() . '://';
         $prefix .= $this->request->getHost();
     }
     $prefix .= $this->appPath->getPhpSelf() . '/';
     return $prefix . $path;
 }
Example #17
0
 /**
  * ApplicationPath constructor.
  *
  * @param string $applicationMode
  */
 public function __construct($applicationMode)
 {
     parent::__construct($applicationMode);
     $this->installerWebRoot = $this->webRoot;
     $this->webRoot = substr($this->webRoot !== '/' ? $this->webRoot . '/' : '/', 0, -14);
     $this->installerAppDir = realpath($this->appDir . '../installation') . '/Installer/';
     $this->installerModulesDir = $this->installerAppDir . 'Modules/';
     $this->installerClassesDir = $this->installerAppDir . 'Core/';
     $this->designRootPathInternal = ACP3_ROOT_DIR . 'installation/design/';
 }
Example #18
0
File: Router.php Project: acp3/core
 /**
  * @param string $path
  * @param bool   $isAbsolute
  * @param bool   $forceSecure
  *
  * @return string
  */
 protected function addUriPrefix($path, $isAbsolute, $forceSecure)
 {
     $prefix = '';
     if ($isAbsolute === true || $forceSecure === true) {
         $prefix .= $forceSecure === true ? 'https://' : $this->request->getScheme() . '://';
         $prefix .= $this->request->getHost();
     }
     $prefix .= $this->useModRewrite($path) ? $this->appPath->getWebRoot() : $this->appPath->getPhpSelf() . '/';
     return $prefix;
 }
Example #19
0
 /**
  * @return array
  */
 private function fetchRequiredFilesAndDirectories()
 {
     $defaults = ['ACP3/config.yml', 'cache/', 'uploads/', 'uploads/assets/'];
     foreach (Filesystem::scandir($this->appPath->getModulesDir()) as $row) {
         $path = 'uploads/' . $row . '/';
         if (is_dir(ACP3_ROOT_DIR . $path) === true) {
             $defaults[] = $path;
         }
     }
     return $defaults;
 }
Example #20
0
 /**
  * @param array  $files
  * @param string $path
  */
 protected function saveMinifiedAsset(array $files, $path)
 {
     $options = [];
     $options['minifiers']['text/css'] = ['Minify_CSSmin', 'minify'];
     $content = \Minify::combine($files, $options);
     if (!is_dir($this->appPath->getUploadsDir() . 'assets')) {
         @mkdir($this->appPath->getUploadsDir() . 'assets', 0755);
     }
     // Write the contents of the file to the uploads folder
     file_put_contents($path, $content, LOCK_EX);
 }
Example #21
0
File: Cache.php Project: acp3/cms
 /**
  * Erstellt den Galerie-Cache anhand der angegebenen ID
  *
  * @param integer $galleryId
  *
  * @return boolean
  */
 public function saveCache($galleryId)
 {
     $pictures = $this->pictureRepository->getPicturesByGalleryId($galleryId);
     $cPictures = count($pictures);
     $settings = $this->config->getSettings(Schema::MODULE_NAME);
     for ($i = 0; $i < $cPictures; ++$i) {
         $pictures[$i]['width'] = $settings['thumbwidth'];
         $pictures[$i]['height'] = $settings['thumbheight'];
         $picInfos = @getimagesize($this->appPath->getModulesDir() . 'gallery/' . $pictures[$i]['file']);
         if ($picInfos !== false) {
             if ($picInfos[0] > $settings['thumbwidth'] || $picInfos[1] > $settings['thumbheight']) {
                 $newHeight = $settings['thumbheight'];
                 $newWidth = intval($picInfos[0] * $newHeight / $picInfos[1]);
             }
             $pictures[$i]['width'] = isset($newWidth) ? $newWidth : $picInfos[0];
             $pictures[$i]['height'] = isset($newHeight) ? $newHeight : $picInfos[1];
         }
     }
     return $this->cache->save(self::CACHE_ID . $galleryId, $pictures);
 }
Example #22
0
 /**
  * @inheritdoc
  */
 public function destroy($sessionId)
 {
     $this->secureSession();
     if ($this->request->getCookies()->has(self::SESSION_NAME)) {
         $cookie = new Cookie(self::SESSION_NAME, '', (new \DateTime())->modify('-3600 seconds'), $this->appPath->getWebRoot(), null, $this->request->getSymfonyRequest()->isSecure());
         $this->response->headers->setCookie($cookie);
     }
     // Delete the session from the database
     $this->db->getConnection()->delete($this->db->getPrefix() . 'sessions', ['session_id' => $sessionId]);
     return true;
 }
Example #23
0
 /**
  * Gibt ein Array mit den Abhängigkeiten zu anderen Modulen eines Moduls zurück
  *
  * @param string $moduleName
  *
  * @return array
  */
 protected function getDependencies($moduleName)
 {
     if ((bool) preg_match('=/=', $moduleName) === false) {
         foreach ($this->vendors->getVendors() as $vendor) {
             $path = $this->appPath->getModulesDir() . $vendor . '/' . ucfirst($moduleName) . '/Resources/config/module.xml';
             if (is_file($path) === true) {
                 return $this->getModuleDependencies($path);
             }
         }
     }
     return [];
 }
Example #24
0
 private function applyEmoticons()
 {
     $this->config['smiley_path'] = $this->appPath->getWebRoot() . 'uploads/emoticons/';
     $this->config['smiley_images'] = $this->config['smiley_descriptions'] = '';
     $emoticons = $this->emoticonRepository->getAll();
     $cEmoticons = count($emoticons);
     $images = $descriptions = [];
     for ($i = 0; $i < $cEmoticons; ++$i) {
         $images[] = $emoticons[$i]['img'];
         $descriptions[] = $emoticons[$i]['description'];
     }
     $this->config['smiley_images'] = $images;
     $this->config['smiley_descriptions'] = $descriptions;
 }
Example #25
0
 /**
  * Returns an alphabetically sorted array of all found ACP3 modules
  *
  * @return array
  */
 public function getAllModules()
 {
     if (empty($this->allModules)) {
         foreach ($this->vendors->getVendors() as $vendor) {
             foreach (Filesystem::scandir($this->appPath->getModulesDir() . $vendor . '/') as $module) {
                 $info = $this->getModuleInfo($module);
                 if (!empty($info)) {
                     $this->allModules[$info['name']] = $info;
                 }
             }
         }
         ksort($this->allModules);
     }
     return $this->allModules;
 }
Example #26
0
 /**
  * Sets the cache for all registered languages
  *
  * @return bool
  */
 protected function saveLanguagePacksCache()
 {
     $languagePacks = [];
     foreach ($this->vendors->getVendors() as $vendors) {
         $languageFiles = glob($this->appPath->getModulesDir() . $vendors . '/*/Resources/i18n/*.xml');
         if ($languageFiles !== false) {
             foreach ($languageFiles as $file) {
                 $languagePack = $this->registerLanguagePack($file);
                 if (!empty($languagePack)) {
                     $languagePacks += $languagePack;
                 }
             }
         }
     }
     return $this->cache->save('language_packs', $languagePacks);
 }
Example #27
0
 /**
  * @param string $moduleDirectory
  *
  * @return array
  */
 protected function fetchModuleInfo($moduleDirectory)
 {
     $vendors = array_reverse($this->vendors->getVendors());
     // Reverse the order of the array -> search module customizations first, then 3rd party modules, then core modules
     foreach ($vendors as $vendor) {
         $path = $this->appPath->getModulesDir() . $vendor . '/' . $moduleDirectory . '/Resources/config/module.xml';
         if (is_file($path) === true) {
             $moduleInfo = $this->xml->parseXmlFile($path, 'info');
             if (!empty($moduleInfo)) {
                 $moduleName = strtolower($moduleDirectory);
                 $moduleInfoDb = $this->systemModuleRepository->getInfoByModuleName($moduleName);
                 return ['id' => !empty($moduleInfoDb) ? $moduleInfoDb['id'] : 0, 'dir' => $moduleDirectory, 'installed' => !empty($moduleInfoDb), 'active' => !empty($moduleInfoDb) && $moduleInfoDb['active'] == 1, 'schema_version' => !empty($moduleInfoDb) ? (int) $moduleInfoDb['version'] : 0, 'description' => $this->getModuleDescription($moduleInfo, $moduleName), 'author' => $moduleInfo['author'], 'version' => $moduleInfo['version'], 'name' => $this->getModuleName($moduleInfo, $moduleName), 'categories' => isset($moduleInfo['categories']), 'protected' => isset($moduleInfo['protected']), 'dependencies' => $this->getModuleDependencies($path)];
             }
         }
     }
     return [];
 }
Example #28
0
 /**
  * Überprüft, ob das angegebene Sprachpaket existiert
  *
  * @param string $locale
  *
  * @return boolean
  */
 public function languagePackExists($locale)
 {
     return !preg_match('=/=', $locale) && is_file($this->appPath->getModulesDir() . 'ACP3/System/Resources/i18n/' . $locale . '.xml') === true;
 }
Example #29
0
File: Vendor.php Project: acp3/core
 /**
  * Caches the various module vendors
  */
 protected function cacheVendors()
 {
     $this->vendors = array_merge(['ACP3'], Filesystem::scandir($this->appPath->getModulesDir(), ['ACP3', 'Custom']), ['Custom']);
 }
Example #30
0
 /**
  * Checks, whether the database configuration file exists
  *
  * @return bool
  */
 protected function databaseConfigExists()
 {
     $path = $this->appPath->getAppDir() . 'config.yml';
     return is_file($path) === true && filesize($path) !== 0;
 }