Example #1
0
 /**
  * @param Theme $view
  * @return string
  */
 public function render(Theme $view)
 {
     $this->context['name'] = $this->name;
     return $view->render($this->template, $this->context);
 }
Example #2
0
 /**
  * @param \Post $post
  * @param Theme $view
  * @return bool
  */
 static function export(\Post $post, Theme $view)
 {
     $post->save();
     if ($post->post_vkontakte && $post->post_twitter) {
         return ['vkontakte' => $post->post_vkontakte, 'twitter' => $post->post_twitter];
     }
     $context = ['title' => $post->title, 'content' => $post->content_plain(), 'tags' => implode(' ', $post->hashtags()), 'url' => Env::$request->getSchemeAndHttpHost() . '/post/' . $post->id . '-' . $post->slug . '.html', 'author' => $post->author->username, 'category' => $post->category->title];
     return $post->export(['vkontakte' => $view->render('@assets/templates/smp.vkontakte.twig', $context), 'twitter' => $view->render('@assets/templates/smp.twitter.twig', $context)]);
 }
Example #3
0
 /**
  * @param $url
  * @param $theme
  * @param $namespace
  */
 public function __construct($url, $theme = 'default', $namespace = '')
 {
     // Authentication
     /** @var Auth auth */
     $this->auth = NCService::load('User.Auth');
     /** @var \User user */
     $this->user = $this->auth->identify(Env::$request->cookies->get('sess'));
     // Settings
     /** @var Settings settings */
     $this->settings = NCService::load('Application.Settings');
     // Analytics module
     if ($this->analytics) {
         $counter = NCService::load('Application.Analytics', [$this->user ? $this->user->id : null]);
         $counter->save();
     }
     // Renderring
     /** @var Theme view */
     $this->view = NCModuleCore::load_view($theme);
     // Translation
     /** @var Translate lang */
     $this->lang = NCModuleCore::load_lang();
     // Module level routing
     /** @var NCRouter map */
     $this->map = new NCRouter($this, $namespace);
     // Adding sitemap to urls
     $this->map->addRoute('sitemap.xml', [$this, 'sitemap'], 'sitemap');
     // Register reverse url filter
     $this->view->twig->addFilter(new \Twig_SimpleFilter('url', [$this->map, 'reverse_filter']));
     // Register translate filters
     $this->view->twig->addFilter(new \Twig_SimpleFilter('lang', [$this->lang, 'translate']));
     $this->view->twig->addFilter(new \Twig_SimpleFilter('dlang', [$this->lang, 'translate_date']));
     // Assign user
     $this->view->assign('user', $this->user ? $this->user->to_array() : []);
     $this->view->assign('group', $this->user ? $this->user->group : []);
     // Assign captcha URL
     $this->view->assign('secure_image', NCModuleCore::$captcha_url);
     // Loading modules globals
     $this->view->load_globals($this, $this->lang);
     // Disable access to banned users
     if ($this->user->ban_time > time() || $this->user->ban_time == -1) {
         Env::$response->setContent($this->errorBanned(Env::$request, $this->user->ban_reason));
         Env::$response->send();
         return;
     }
     // Check access to current module
     if (!$this->access()) {
         Env::$response->setContent($this->error403(Env::$request));
         Env::$response->send();
         return;
     }
     // Build current module map
     $this->route();
     /** @var NCRoute $route */
     $route = $this->map->match($url);
     // Check route
     if (!is_callable($route->callback)) {
         Env::$response->setContent($this->error404(Env::$request));
         Env::$response->send();
         return;
     }
     // Bufferization content
     ob_start();
     $this->configure();
     if (strpos($url, 'sitemap.xml') > -1) {
         Env::$response->headers->set('Content-Type', 'application/xml');
         $response = call_user_func($route->callback, new NCSitemapBuilder(), $this->map);
         $response = strval($response);
     } else {
         $response = call_user_func($route->callback, Env::$request, $route->matches);
     }
     $buffer = ob_get_clean();
     Env::$response->setContent(!is_null($response) ? $response : $buffer);
     // Flush content
     Env::$response->send();
 }