/** * Sets the SEO url valule if is a old url. * * @access protected * @return false|RedirectResponse * @author Etienne de Longeaux <*****@*****.**> */ protected function isSEOUrl() { if ($this->is_switch_redirection_seo_authorized) { $dossier = $this->seo_redirection_repository . "/old_urls/"; \Sfynx\ToolBundle\Util\PiFileManager::mkdirr($dossier, 0777); $fileSeo = $this->seo_redirection_repository . "/" . $this->seo_redirection_file_name; //$is_cache_not_created = \Sfynx\ToolBundle\Util\PiFileManager::isEmptyDir($dossier); // very fast //if (file_exists($fileSeo) && $is_cache_not_created) { //$path_tmp_file = $dossier.'tmp.file'; //if (file_exists($fileSeo) && !file_exists($path_tmp_file)) { // we set the tmp file //$result = \Sfynx\ToolBundle\Util\PiFileManager::save($path_tmp_file, "", 0777, LOCK_EX); // if all cache seo files are not created from the seo file, we create them. $all_cache_files = \Sfynx\ToolBundle\Util\PiFileManager::GlobFiles($dossier . '*.cache'); // more fast in linux but not in windows if (file_exists($fileSeo) && count($all_cache_files) == 0) { $this->container->get("sfynx.cache.filecache")->getClient()->setPath($dossier); $file_handle = fopen($fileSeo, "r"); while (!feof($file_handle)) { $line = (string) fgets($file_handle); $line_infos = explode(':', $line); if (isset($line_infos[0]) && !empty($line_infos[0]) && isset($line_infos[1]) && !empty($line_infos[1])) { $this->container->get("sfynx.cache.filecache")->set(str_replace(PHP_EOL, '', $line_infos[0]), str_replace(PHP_EOL, '', $line_infos[1]), 0); } } fclose($file_handle); } // $filename = $this->request->getPathInfo(); $this->container->get("sfynx.cache.filecache")->getClient()->setPath($dossier); if (!$this->container->get("sfynx.cache.filecache")->get($filename)) { $SEOUrl = false; } else { $SEOUrl = $this->container->get("sfynx.cache.filecache")->get($filename); } } else { $SEOUrl = false; } if ($SEOUrl) { // we set response $response = new RedirectResponse($SEOUrl, 301); // we apply all events allowed to change the redirection response $event_response = new ResponseEvent($response, $this->date_expire); $this->container->get('event_dispatcher')->dispatch(SfynxCmfEvents::HANDLER_REQUEST_CHANGERESPONSE_SEO_REDIRECTION, $event_response); $response = $event_response->getResponse(); return $response; //$response->setResponse(new Response(\Sfynx\ToolBundle\Util\PiFileManager::getCurl($SEOUrl, null, null, $this->request->getUriForPath('')))); } return false; }
/** * Sets the specific sortOrders. * * @param string $domain The domain * @param string $extension The extension name * * @return void * @access public */ public function createTranslationFiles($domain = "messages", $extension = "yml") { $foundBundle = $this->container->get('kernel')->getBundle('SfynxTranslatorBundle'); $basePath = $foundBundle->getPath() . "/Resources/translations/"; $transfiles = PiFileManager::GlobFiles($basePath . '*.' . $extension); // more fast in linux but not in windows $dir = PiFileManager::mkdirr($basePath); if (count($transfiles) == 0) { $all_locales = $this->container->get('sfynx.auth.locale_manager')->getAllLocales(); foreach ($all_locales as $key => $lang) { $filename = $basePath . $domain . "." . $lang . "." . $extension; @file_put_contents($filename, '', LOCK_EX); } } }