/** * @param Entity\Block $block * @return bool */ function clearMenuCache(Entity\Block $block) { if ($block->menuItemTranslation) { $url = $block->menuItemTranslation->getUrl(true); } elseif ($block->menuItem) { $url = $block->menuItem->getUrl(true); } else { return false; } $url = str_ireplace(['https://', 'http://'], '', $url); $this->cache->deleteCache($url); return true; }
/** * @param int $mode */ public function init($mode = Core::ROUTE_NORMAL) { $globalConfigs = array('ENV' => self::ENV_DEVELOPMENT, 'JS_FOLDER' => '/js', 'CSS_FOLDER' => '/css', 'CONSOLIDATE_FOLDER' => '/consolidated', 'PROFILER_ENABLED' => false); foreach ($globalConfigs as $config => $val) { if (!defined($config)) { define($config, $val); } } if (ENV == self::ENV_DEVELOPMENT) { error_reporting(E_ALL | E_STRICT); ini_set("display_errors", 1); } if (is_object($this->session) && $this->isCLI() === false) { $this->session->start(); } $this->mode = $mode; $this->startTimer(__CLASS__); // Assign our output handler to output clean errors ob_start(); // ingore user abort, is recommed for ajax request and db changes if ($this->request->isXmlHttpRequest()) { ignore_user_abort(true); } $this->registryManager->init(); if ($this->isCLI() === false) { // Sanitize all request variables $_GET = $this->sanitize($_GET); $_POST = $this->sanitize($_POST); $_COOKIE = $this->sanitize($_COOKIE); if ($mode === Core::ROUTE_NORMAL) { $this->cache->load(); // Try to load a site by the requested URI $this->route->loadSite(); if (!$this->request->isXmlHttpRequest() && !$this->request->isPost()) { echo '<!-- ' . $this->getPageLoadTime() . 'sec -->'; } $this->response->finish(false, true); } } else { $params = getopt('p:'); if ($params['p']) { $_SERVER['REQUEST_URI'] = $params['p']; $this->route->loadVirtualRoutes(); echo $this->route->checkVirtualRoute(); } } }
/** * @param int $mode */ public function init($mode = Core::ROUTE_NORMAL) { if (ENV == self::ENV_DEVELOPMENT) { error_reporting(E_ALL | E_STRICT); ini_set("display_errors", 1); } if (is_object($this->session) && $this->isCLI() === false) { $this->session->start(); } $this->mode = $mode; $this->startTimer(__CLASS__); // Assign our output handler to output clean errors ob_start(); // ingore user abort, is recommed for ajax request and db changes if ($this->request->isXmlHttpRequest()) { ignore_user_abort(true); } $this->registryManager->init(); if ($this->isCLI() === false) { // Sanitize all request variables $_GET = $this->sanitize($_GET); $_POST = $this->sanitize($_POST); $_COOKIE = $this->sanitize($_COOKIE); if ($mode === Core::ROUTE_NORMAL) { $this->cache->load(); // Try to load a site by the requested URI $this->route->loadSite(); $this->response->finish(false, true); } } else { $params = getopt('p:'); if ($params['p']) { $_SERVER['REQUEST_URI'] = $params['p']; $this->route->loadRoutes(); echo $this->route->getVirtualRouteContent(); } } }
/** * */ public function menuItemNotFound() { $page404 = null; if ($this->currentMenuItem) { $localeId = $this->session->get('localeId', false); $page404 = $this->db->createQueryBuilder()->select("menuItemTranslation, menuItem, template, site, locale")->from('\\Fraym\\Menu\\Entity\\MenuItemTranslation', 'menuItemTranslation')->join('menuItemTranslation.menuItem', 'menuItem')->leftJoin("menuItem.template", 'template')->join("menuItem.site", 'site')->join("menuItemTranslation.locale", 'locale')->setMaxResults(1)->setParameter('site', $this->currentMenuItem->site->id)->where("site.id = :site AND menuItem.is404 = 1 AND menuItem.active = 1"); if ($localeId) { $page404 = $page404->andWhere('locale.id = :locale')->setParameter('locale', $localeId); } else { $page404 = $page404->andWhere('locale.default = 1'); } $page404 = $page404->getQuery()->getOneOrNullResult(); } // call site note found view if (is_object($page404)) { $this->render404Site($page404); // cache the 404 page $this->cache->setCacheContent(); } else { error_log('Menuitem not found or template not set!'); $this->response->sendHTTPStatusCode(500); } $this->response->finish(true, true); }
/** * @return $this */ public function connect() { // Prevent to connect twice if ($this->entityManager) { return $this; } $applicationDir = $this->core->getApplicationDir(); $this->createModuleDirCache(); $cache = $this->cache->getCacheProvider(); $config = new \Doctrine\ORM\Configuration(); $config->setMetadataCacheImpl($cache); $config->addCustomStringFunction('MD5', '\\DoctrineExtensions\\Query\\Mysql\\Md5'); $config->addCustomStringFunction('ACOS', '\\DoctrineExtensions\\Query\\Mysql\\Acos'); $config->addCustomStringFunction('ASIN', '\\DoctrineExtensions\\Query\\Mysql\\Asin'); $config->addCustomStringFunction('ATAN', '\\DoctrineExtensions\\Query\\Mysql\\Atan'); $config->addCustomStringFunction('ATAN2', '\\DoctrineExtensions\\Query\\Mysql\\Atan2'); $config->addCustomStringFunction('BINARY', '\\DoctrineExtensions\\Query\\Mysql\\Binary'); $config->addCustomStringFunction('CHARLENGTH', '\\DoctrineExtensions\\Query\\Mysql\\CharLength'); $config->addCustomStringFunction('CONCATWS', '\\DoctrineExtensions\\Query\\Mysql\\ConcatWs'); $config->addCustomStringFunction('COS', '\\DoctrineExtensions\\Query\\Mysql\\Cos'); $config->addCustomStringFunction('COT', '\\DoctrineExtensions\\Query\\Mysql\\COT'); $config->addCustomStringFunction('COUNTIF', '\\DoctrineExtensions\\Query\\Mysql\\CountIf'); $config->addCustomStringFunction('CRC32', '\\DoctrineExtensions\\Query\\Mysql\\Crc32'); $config->addCustomStringFunction('DATE', '\\DoctrineExtensions\\Query\\Mysql\\Date'); $config->addCustomStringFunction('DATEADD', '\\DoctrineExtensions\\Query\\Mysql\\DateAdd'); $config->addCustomStringFunction('DATEDIFF', '\\DoctrineExtensions\\Query\\Mysql\\DateFormat'); $config->addCustomStringFunction('DAY', '\\DoctrineExtensions\\Query\\Mysql\\Day'); $config->addCustomStringFunction('DEGREES', '\\DoctrineExtensions\\Query\\Mysql\\Degrees'); $config->addCustomStringFunction('FIELD', '\\DoctrineExtensions\\Query\\Mysql\\Field'); $config->addCustomStringFunction('FINDINSET', '\\DoctrineExtensions\\Query\\Mysql\\FindInSet'); $config->addCustomStringFunction('GROUPCONCAT', '\\DoctrineExtensions\\Query\\Mysql\\GroupConcat'); $config->addCustomStringFunction('HOUR', '\\DoctrineExtensions\\Query\\Mysql\\Hour'); $config->addCustomStringFunction('IFELSE', '\\DoctrineExtensions\\Query\\Mysql\\IfElse'); $config->addCustomStringFunction('IFNULL', '\\DoctrineExtensions\\Query\\Mysql\\IfNUll'); $config->addCustomStringFunction('MATCHAGAINST', '\\DoctrineExtensions\\Query\\Mysql\\MatchAgainst'); $config->addCustomStringFunction('MONTH', '\\DoctrineExtensions\\Query\\Mysql\\Month'); $config->addCustomStringFunction('NULLIF', '\\DoctrineExtensions\\Query\\Mysql\\NullIf'); $config->addCustomStringFunction('PI', '\\DoctrineExtensions\\Query\\Mysql\\Pi'); $config->addCustomStringFunction('RADIANS', '\\DoctrineExtensions\\Query\\Mysql\\Radians'); $config->addCustomStringFunction('RAND', '\\DoctrineExtensions\\Query\\Mysql\\Rand'); $config->addCustomStringFunction('REGEXP', '\\DoctrineExtensions\\Query\\Mysql\\Regexp'); $config->addCustomStringFunction('ROUND', '\\DoctrineExtensions\\Query\\Mysql\\Round'); $config->addCustomStringFunction('SHA1', '\\DoctrineExtensions\\Query\\Mysql\\Sha1'); $config->addCustomStringFunction('SHA2', '\\DoctrineExtensions\\Query\\Mysql\\Sha2'); $config->addCustomStringFunction('SIN', '\\DoctrineExtensions\\Query\\Mysql\\Sin'); $config->addCustomStringFunction('STRTODATE', '\\DoctrineExtensions\\Query\\Mysql\\StrToDate'); $config->addCustomStringFunction('TAN', '\\DoctrineExtensions\\Query\\Mysql\\Tan'); $config->addCustomStringFunction('TIMESTAMPDIFF', '\\DoctrineExtensions\\Query\\Mysql\\TimestampDiff'); $config->addCustomStringFunction('WEEK', '\\DoctrineExtensions\\Query\\Mysql\\Week'); $config->addCustomStringFunction('YEAR', '\\DoctrineExtensions\\Query\\Mysql\\Year'); if (!defined('ENV') || ENV === \Fraym\Core::ENV_DEVELOPMENT) { $config->setAutoGenerateProxyClasses(true); } $modelDirs = $this->getModuleDirCache(); \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(function ($class) { return class_exists($class, true); }); $annotationReader = new \Doctrine\Common\Annotations\AnnotationReader(); $this->cachedAnnotationReader = new \Doctrine\Common\Annotations\CachedReader($annotationReader, $cache); $this->annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($this->cachedAnnotationReader, $modelDirs); /** * Ignore PHP-DI Annotation */ $annotationReader->addGlobalIgnoredName('Injectable'); $annotationReader->addGlobalIgnoredName('Inject'); $config->setMetadataDriverImpl($this->annotationDriver); $config->setQueryCacheImpl($cache); $config->setResultCacheImpl($cache); $config->setProxyDir($applicationDir . DIRECTORY_SEPARATOR . CACHE_DOCTRINE_PROXY_PATH); $config->setProxyNamespace('Proxies'); $this->fetchMode = \PDO::FETCH_OBJ; $tablePrefix = new TablePrefix(DB_TABLE_PREFIX); $this->eventManager = new \Doctrine\Common\EventManager(); $this->eventManager->addEventListener(\Doctrine\ORM\Events::loadClassMetadata, $tablePrefix); $this->entityManager = \Doctrine\ORM\EntityManager::create($this->connectionOptions, $config, $this->eventManager); $this->pdo = $this->entityManager->getConnection(); $this->pdo->getDatabasePlatform()->registerDoctrineTypeMapping('set', 'string'); $driverChain = new \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain(); \Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $this->cachedAnnotationReader); $this->eventManager->addEventListener([\Doctrine\ORM\Events::preRemove, \Doctrine\ORM\Events::postRemove, \Doctrine\ORM\Events::prePersist, \Doctrine\ORM\Events::postPersist, \Doctrine\ORM\Events::preUpdate, \Doctrine\ORM\Events::postUpdate, \Doctrine\ORM\Events::postLoad, \Doctrine\ORM\Events::onFlush], $this->eventListener); return $this; }
/** * Template helper function to include another template file. * * @param $file * @param array $vars * @param null $cacheKey * @param bool $showError * @return bool|mixed|string */ public function includeTemplate($file, $vars = [], $cacheKey = null, $showError = true) { $filename = $this->getTemplateFilePath($file); if (is_file($filename)) { if (count($vars)) { foreach ($vars as $templateVarName => $val) { $this->assign($templateVarName, $val); } } else { $this->templateVars = $this->lastTemplateVars; } $content = $this->cache->getDataCache($cacheKey); if ($content === false) { $content = $this->prepareTemplate(file_get_contents($filename)); if ($cacheKey !== null) { $this->cache->setDataCache($cacheKey, $content); } } return $content; } return $showError ? "Template: {$file} not found." : ""; }
chdir(realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..')); } if (is_file('Config.php')) { require 'Config.php'; } else { echo '<a href="/install.php">Please install Fraym.</a>'; exit(0); } $classLoader = (require 'Vendor/autoload.php'); date_default_timezone_set(TIMEZONE); define('CACHE_DI_PATH', 'Cache/DI'); define('CACHE_DOCTRINE_PROXY_PATH', 'Cache/DoctrineProxies'); define('JS_FOLDER', '/js'); define('CSS_FOLDER', '/css'); define('CONSOLIDATE_FOLDER', '/consolidated'); \Fraym\Cache\Cache::createCacheFolders(); $builder = new \DI\ContainerBuilder(); $builder->useAnnotations(true); if (\Fraym\Core::ENV_STAGING === ENV || \Fraym\Core::ENV_PRODUCTION === ENV) { error_reporting(-1); ini_set("display_errors", 0); $builder->writeProxiesToFile(true, CACHE_DI_PATH); define('GLOBAL_CACHING_ENABLED', true); $apcEnabled = (extension_loaded('apc') || extension_loaded('apcu')) && ini_get('apc.enabled'); } else { error_reporting(-1); ini_set("display_errors", 1); define('GLOBAL_CACHING_ENABLED', false); $apcEnabled = false; } define('APC_ENABLED', $apcEnabled);
/** * Callback function to clear the cache if a block element is created or changed */ public function clearCache() { $location = $this->request->post('location', false); $this->cache->deleteCache($location); }