示例#1
0
 /**
  * @param NCModule $module
  * @param Theme $view
  * @param Translate $lang
  * @return array
  */
 public static function globalize(NCModule $module, Theme $view, Translate $lang)
 {
     // Categories listing
     $categories = function () {
         $categories = \PostCategory::listing();
         /** @var RecursiveTree $recursive_tree */
         $recursive_tree = NCService::load('Module.RecursiveTree', [$categories]);
         $categories = array_map(function ($item) use($recursive_tree) {
             $result = $item->to_array();
             $result['link'] = '/post/category/' . $item->id;
             $result['posts'] = \Post::count(['conditions' => ['category_id IN (?) AND moderate = ?', $recursive_tree->childs($item->id), '0']]);
             return $result;
         }, $categories);
         return $categories;
     };
     // User publications
     $publications = function () use($module) {
         $publications = 0;
         if ($module->user) {
             $publications = \Post::count(['conditions' => ['author_id = ?', $module->user->id]]);
         }
         return $publications;
     };
     return ['_publ' => lazy_arr('publications', ['$categories' => $categories, '$users' => $publications])];
 }
示例#2
0
 /**
  * @param NCModule $module
  * @param \Service\Render\Theme $theme
  * @param \Service\Application\Translate $translate
  * @return array|\System\Engine\NCBlock[]
  */
 static function globalize($module, $theme, $translate)
 {
     /*
      * Last 5 topics
      */
     $last_topics = function () {
         $topics = \ForumTheme::as_array(\ForumTheme::find('all', ['conditions' => ['active = 1'], 'order' => 'updated_at DESC', 'limit' => 5]));
         $topics = array_map(function ($item) {
             $item['link'] = '/forum/topic/' . $item['id'];
             return $item;
         }, $topics);
         return $topics;
     };
     return ['_forum' => lazy_arr('forum', ['$last' => $last_topics])];
 }
示例#3
0
 /**
  * ULogin registration and authorization
  *
  * @param NCModule $module
  * @param \Service\Render\Theme $theme
  * @param \Service\Application\Translate $translate
  * @return array|\System\Engine\NCBlock[]
  */
 static function globalize($module, $theme, $translate)
 {
     // Gravatar
     $theme->twig->addFilter(new \Twig_SimpleFilter('avatar', function ($user, $default = null) {
         return $user['avatar'] ? $user['avatar'] : User::get_gravatar_url($user['email'], 256, $default);
     }));
     // Refer host
     $theme->twig->addFilter(new \Twig_SimpleFilter('host', function ($url, $default = 1) {
         $data = parse_url($url);
         if (isset($data['host'])) {
             return $data['host'];
         }
         if ($default === 1) {
             return $url;
         }
         return $default;
     }));
     // URL Decode
     $theme->twig->addFilter(new \Twig_SimpleFilter('url_decode', function ($url) {
         return urldecode($url);
     }));
     // ULogin authentication
     if (!$module->user && Env::$request->isMethod('post') && isset($_POST['token'])) {
         $s = file_get_contents('http://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']);
         $data = new Options(json_decode($s, true));
         $hash = User::encrypt(User::encrypt($data->get('network') . $data->get('identity')));
         if ($user = $module->auth->authenticate_by_hash($hash)) {
             $module->auth->login($user);
         } else {
             $user = User::create(['username' => $data['first_name'] . ' ' . $data['last_name'], 'password' => $hash, 'email' => $data->get('email', $data->get('identity')), 'avatar' => $data->get('photo', ''), 'group_id' => $module->settings->get('users_group')]);
         }
         if (isset($user) && $user instanceof User) {
             $module->auth->login($user);
             Env::$response->sendHeaders();
             return static::redirect_response('/');
         }
     }
     /*
      * Last 5 users
      */
     $last_users = function () {
         return \User::as_array(User::find('all', ['conditions' => ['ban_time = 0 OR ban_time IS NULL'], 'order' => 'register_date DESC', 'limit' => 5]));
     };
     return ['_user' => lazy_arr('users', ['$last' => $last_users]), 'ulogin' => ['small' => '<script src="//ulogin.ru/js/ulogin.js"></script><div id="uLogin" data-ulogin="******"></div>', 'panel' => '<script src="//ulogin.ru/js/ulogin.js"></script><div id="uLogin" data-ulogin="******"></div>']];
 }
示例#4
0
 static function globalize($module, $theme, $translate)
 {
     /*
      * Add all pages to context
      */
     $pages = function () {
         return array_map(function ($p) {
             $page = $p->to_array();
             $page['url'] = '/page/' . $page['id'] . '-' . $page['slug'] . '.html';
             return $page;
         }, \Page::all());
     };
     /*
      * Short description filter
      */
     $theme->twig->addFilter(new \Twig_SimpleFilter('short', function ($value) {
         $short_tag = '<!-- split -->';
         if (strpos($value, $short_tag) > 0) {
             return reset(explode($short_tag, $value, 2));
         }
         return $value;
     }));
     return ['_pages' => lazy_arr('pages', ['$list' => $pages])];
 }
示例#5
0
 static function globalize($module, $theme, $translate)
 {
     /*
      * Comments array
      */
     $theme->twig->addFilter(new \Twig_SimpleFilter('comments', function ($post, $limit = 50, $reversed = false) {
         // Find conditions
         $conditions = ['parent_id = ?', intval($post)];
         if (!is_numeric($post)) {
             $conditions = ['post = ?', $post];
         }
         // Comments
         $comments = \Comment::find('all', ['conditions' => $conditions, 'limit' => $limit, 'order' => 'created_at DESC']);
         $comments = \Comment::as_array($comments);
         return $reversed ? array_reverse($comments) : $comments;
     }));
     /*
      * Comments counter
      */
     $theme->twig->addFilter(new \Twig_SimpleFilter('comments_count', function ($post) {
         // Find conditions
         $conditions = ['parent_id = ?', intval($post)];
         if (!is_numeric($post)) {
             $conditions = ['post = ?', $post];
         }
         // Count comments
         return \Comment::count(['conditions' => $conditions]);
     }));
     /*
      * Last 5 comments
      */
     $last_comments = function () {
         return \Comment::as_array(\Comment::find('all', ['order' => 'created_at DESC', 'limit' => 5]));
     };
     return ['_comm' => lazy_arr('comments', ['$last' => $last_comments])];
 }
示例#6
0
 /**
  * Global vars
  *
  * @param NCModule $module
  * @param Theme $view
  * @param Translate $lang
  * @return array|\System\Engine\NCBlock[]
  */
 static function globalize(NCModule $module, Theme $view, Translate $lang)
 {
     $view->twig->addFilter(new \Twig_SimpleFilter('ord', function ($order) {
         $cur = Env::$request->get('order');
         if (strpos($cur, $order) > -1) {
             return $cur[0] == '-' ? 'fa-chevron-down' : 'fa-chevron-up';
         }
         return strpos($cur, $order);
     }));
     /**
      * Substr
      */
     $view->twig->addFilter(new \Twig_SimpleFilter('sub', function ($str, $len = 24) {
         if (\len($str) > $len) {
             $str = \cut($str, 0, $len - 3) . '...';
         }
         return $str;
     }));
     /**
      * Long to ip
      */
     $view->twig->addFilter(new \Twig_SimpleFilter('longip', function ($str) {
         return long2ip($str);
     }));
     /**
      * IP to long
      */
     $view->twig->addFilter(new \Twig_SimpleFilter('iplong', function ($str) {
         return ip2long($str);
     }));
     return ['title_prefix' => NCService::load('Application.Settings')->conf->get('title_prefix'), 'lang_code' => $lang->pack, 'ga' => lazy_arr('ga', ['$code' => function () {
         /** @var GA $manager */
         $manager = NCService::load('SocialMedia.GA');
         return $manager->code();
     }])];
 }