public function onKernelException(GetResponseForExceptionEvent $event) { $exception = $event->getException(); if ($this->env != "prod") { $event->setException($exception); return; } try { $code = 404; if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) { $code = 404; } else { if ($exception instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException) { $code = 403; } } $file = $code; if ($this->env != "prod") { //$file = $file . '.' . $this->env; } $file = $file . '.html.twig'; $template = $this->siteManager->getTemplate("portal"); $template = "SymbbTemplateDefaultBundle:Exception:" . $file; $response = new Response($this->templating->render($template, array('status_code' => $code, 'status_text' => $exception->getMessage(), 'exception' => $exception))); // setup the Response object based on the caught exception $event->setResponse($response); } catch (\Exception $exc) { $event->setException($exception); } // you can alternatively set a new Exception // $exception = new \Exception('Some special exception'); // $event->setException($exception); }
protected function addChildren($menu, $children, SiteManager $siteManager, $router) { foreach ($children as $child) { if ($child->getType() == 'symfony') { try { // generate directly to check if route realy exist $uri = $router->generate($child->getSymfonyRoute(), $child->getSymfonyRouteParams()); //$childMenu = $menu->addChild($child->getTitle(), array('route' => $child->getSymfonyRoute(), 'routeParameters' => $child->getSymfonyRouteParams())); $childMenu = $menu->addChild($child->getTitle(), array('uri' => $uri)); } catch (\Exception $e) { } } else { $uri = $child->getFixUrl(); $childMenu = $menu->addChild($child->getTitle(), array('uri' => $uri)); if (strpos($uri, "www.") !== false || strpos($uri, "http") === 0) { $domains = $siteManager->getSite()->getDomainArray(); $found = false; foreach ($domains as $domain) { $domain = str_replace(array('https://', 'http://', 'www.'), '', $domain); if (!empty($uri) && !empty($domain) && strpos($uri, $domain) !== false) { $found = true; break; } } if (!$found) { $childMenu->setLinkAttributes(array('target' => '_blank')); } } } if (isset($childMenu) && isset($child) && $child->hasChildren()) { $this->addChildren($childMenu, $child->getChildren(), $siteManager, $router); } } }
/** * save a Navigation * you can pass the Navigation object or an array with the fields * if you pass an array the keys must be with underscore and not with CamelCase * @param Navigation|array $object * @return Navigation */ public function save($object) { if (is_array($object)) { $objectData = $object; if ($object['id'] > 0) { $object = $this->find($object['id']); } else { $object = new Navigation(); $site = $this->siteManager->find($objectData['site']); $object->setSite($site); } if (isset($objectData['site'])) { unset($objectData['site']); } $this->assignArrayToObject($object, $objectData); } else { if (!$object instanceof Navigation) { $this->addErrorMessage(self::ERROR_WRONG_OBJECT); } } if (!$this->hasError()) { $check = $this->navigationManager->save($object); if ($check) { $this->addSuccessMessage(self::SUCCESS_SAVED); return $object; } } return null; }
public function sendTopicNotifications(Topic $topic, $user) { if (is_numeric($user)) { $user = $this->em->getRepository('SymbbCoreUserBundle:User')->find($user); } $templateBundle = $this->siteManager->getTemplate("email"); $subject = $this->translator->trans('It was written a new answer to "%topic%"', array('%topic%' => $topic->getName()), 'symbb_email'); $sender = $this->siteManager->getSite()->getEmail(); if (!empty($sender)) { $recipient = $user->getEmail(); $message = \Swift_Message::newInstance()->setSubject($subject)->setFrom($sender)->setTo($recipient)->setBody($this->container->get('twig')->render($templateBundle . ':Email:topic_notify.' . $this->getLocale() . '.html.twig', array('topic' => $topic, 'user' => $user, 'site' => $this->siteManager->getSite())), 'text/html'); $this->mailer->send($message); } }
/** * @param int|Site $site * @return bool */ public function delete($site) { if (is_numeric($site)) { $site = $this->find($site); } else { if (!$site instanceof Site) { $this->addErrorMessage(self::ERROR_WRONG_OBJECT); } } if (!$this->hasError()) { $check = $this->siteManager->remove($site); if ($check) { $this->addSuccessMessage(self::SUCCESS_DELETED); } return $check; } return false; }
/** * @param $text * @param BBCode[] $bbcodes */ public function handleSpecialCasesByRef(&$text, $bbcodes) { foreach ($bbcodes as $bbcode) { if ($bbcode->getName() === "Image") { $text = preg_replace_callback('#\\[img\\](.+)\\[\\/img\\]#iUs', function ($matches) { $completeBBCode = $matches[0]; $newUrl = $url = $matches[1]; if (strpos($newUrl, 'http') !== 0) { $domain = $this->siteManager->getSite()->getMediaDomain(); if (substr($domain, 1, -1) === "/") { $domain = rtrim($domain, '/'); } $newUrl = $domain . $url; } return str_replace($url, $newUrl, $completeBBCode); }, $text); } } }
public function getSymbbSite() { return $this->siteManager->getSite(); }