Esempio n. 1
0
 /**
  * Return posts list
  */
 public function view_theme($id_theme = null)
 {
     $id_theme = (int) $id_theme;
     if (empty($id_theme) || $id_theme < 1) {
         redirect('/forum/');
     }
     $themeModel = $this->Register['ModManager']->getModelInstance('Themes');
     $themeModel->bindModel('forum');
     $themeModel->bindModel('poll');
     $theme = $themeModel->getById($id_theme);
     if (!$theme->getForum()) {
         return $this->showInfoMessage(__('Can not find forum'), '/forum/');
     }
     //turn access
     $this->ACL->turn(array('forum', 'view_themes'));
     // Check access to this forum. May be locked by pass or posts count
     $this->__checkForumAccess($theme->getForum());
     $id_forum = $theme->getId_forum();
     $this->__checkThemeAccess($theme);
     if ($this->cached && $this->Cache->check($this->cacheKey)) {
         $source = $this->Cache->read($this->cacheKey);
     } else {
         // Если запрошенной темы не существует - возвращаемся на форум
         if (empty($theme)) {
             return $this->showInfoMessage(__('Topic not found'), '/forum/');
         }
         // Заголовок страницы (содержимое тега title)
         $this->addToPageMetaContext('entity_title', h($theme->getTitle()));
         $this->addToPageMetaContext('category_title', h($theme->getForum()->getTitle()));
         $markers = array();
         $markers['navigation'] = get_link(__('Forums list'), '/forum/') . __('Separator') . get_link($theme->getForum()->getTitle(), '/forum/view_forum/' . $id_forum) . __('Separator') . get_link($theme->getTitle(), '/forum/view_theme/' . $id_theme);
         if (!empty($description)) {
             $markers['navigation'] .= ' (' . $theme->getDescription() . ')';
         }
         // Page nav
         $postsModelName = $this->Register['ModManager']->getModelName('Posts');
         $postsModel = new $postsModelName();
         $total = $postsModel->getTotal(array('cond' => array('id_theme' => $id_theme)));
         if ($total === 0) {
             $this->__delete_theme($id_theme);
             return $this->showInfoMessage(__('Topic not found'), '/forum/view_forum/' . $id_forum);
         }
         list($pages, $page) = pagination($total, $this->Register['Config']->read('posts_per_page', 'forum'), '/forum/view_theme/' . $id_theme);
         $markers['pagination'] = $pages;
         $this->addToPageMetaContext('page', $page);
         // SELECT posts
         $postsModel->bindModel('author');
         $postsModel->bindModel('editor');
         $postsModel->bindModel('attacheslist');
         $posts = $postsModel->getCollection(array('id_theme' => $id_theme), array('order' => 'time ASC, id ASC', 'page' => $page, 'limit' => $this->Register['Config']->read('posts_per_page', 'forum')));
         // Ссылка "Ответить" (если тема закрыта - выводим сообщение "Тема закрыта")
         if ($theme->getLocked() == 0) {
             $markers['add_link'] = get_link(get_img('/template/' . $this->Register['Config']->read('template') . '/img/reply.png', array('alt' => __('Answer'), 'title' => __('Answer'))), '/forum/view_theme/' . $id_theme . '#sendForm');
         } else {
             $markers['add_link'] = '';
             // __('Theme is locked')
             $markers['closed_theme'] = true;
         }
         if (!$this->ACL->turn(array('forum', 'add_posts', $theme->getId_forum()), false)) {
             $markers['add_link'] = '';
         }
         $markers['meta'] = '';
         $this->_globalize($markers);
         $post_num = ($page - 1) * $this->Register['Config']->read('posts_per_page', 'forum');
         //serialize rating settings
         $settingsModelName = $this->Register['ModManager']->getModelName('UsersSettings');
         $settingsModel = new $settingsModelName();
         $rating_settings = $settingsModel->getCollection(array('type' => 'rating'));
         $rating_settings = count($rating_settings) > 0 ? $rating_settings[0]->getValues() : '';
         $usersModel = $this->Register['ModManager']->getModelInstance('Users');
         $first_top = false;
         if ($page > 1 && $theme->getFirst_top() == '1') {
             $post = $postsModel->getCollection(array('id_theme' => $id_theme), array('order' => 'time ASC, id ASC', 'limit' => 1));
             if (is_array($post) && count($post) == 1) {
                 $posts = array_merge($post, $posts);
                 $first_top = true;
             }
         }
         foreach ($posts as $post) {
             // Если автор сообщения (поста) - зарегистрированный пользователь
             $postAuthor = $post->getAuthor();
             if ($post->getId_author()) {
                 // Аватар
                 if (is_file(ROOT . '/sys/avatars/' . $post->getId_author() . '.jpg')) {
                     $postAuthor->setAvatar(get_url('/sys/avatars/' . $post->getId_author() . '.jpg'));
                 } else {
                     $postAuthor->setAvatar(get_url('/sys/img/noavatar.png'));
                 }
                 // Статус пользователя
                 $status = $this->ACL->get_group_info();
                 $user_status = array_key_exists($postAuthor->getStatus(), $status) ? $status[$postAuthor->getStatus()] : $status[0];
                 $postAuthor->setStatus_title($user_status['title']);
                 // Рейтинг пользователя (по количеству сообщений)
                 $rating = $postAuthor->getPosts();
                 $rank_star = getUserRating($rating, $rating_settings);
                 $postAuthor->setRank($rank_star['rank']);
                 if ($postAuthor->getState()) {
                     $postAuthor->setRank($postAuthor->getState());
                 }
                 $postAuthor->setUser_rank(get_img('/sys/img/' . $rank_star['img']));
                 // Если автор сообщения сейчас "на сайте"
                 $users_on_line = getOnlineUsers();
                 if (isset($users_on_line) && isset($users_on_line[$post->getId_author()])) {
                     $postAuthor->setStatus_on(__('Online'));
                 } else {
                     $postAuthor->setStatus_on(__('Offline'));
                 }
                 // Если пользователь заблокирован
                 if ($postAuthor->getBlocked()) {
                     $postAuthor->setStatus_on('<span class="statusBlock">' . __('Banned') . '</span>');
                 }
                 // Если автор сообщения - незарегистрированный пользователь
             } else {
                 $postAuthor->setAvatar(get_url('/sys/img/noavatar.png'));
                 $postAuthor->setName(__('Guest'));
             }
             $message = $this->Textarier->parseBBCodes($post->getMessage(), $post);
             $post->setMessage($message);
             $signature = $postAuthor->getSignature() ? $this->Textarier->getSignature($postAuthor->getSignature(), $postAuthor->getStatus()) : '';
             $postAuthor->setSignature($signature);
             // If author is authorized user.
             $email = '';
             $privat_message = '';
             $author_site = '';
             $user_profile = '';
             $icon_params = array('class' => 'user-details');
             if ($post->getId_author()) {
                 $user_profile = '&nbsp;' . get_link(get_img('/sys/img/icon_profile.gif', array('alt' => __('View profile'), 'title' => __('View profile'))), getProfileUrl($post->getId_author()), $icon_params);
                 if (isset($_SESSION['user'])) {
                     $email = '&nbsp;' . get_link(get_img('/sys/img/icon_email.gif', array('alt' => __('Send mail'), 'title' => __('Send mail'))), '/users/send_mail_form/' . $post->getId_author(), $icon_params);
                     $privat_message = '&nbsp;' . get_link(get_img('/sys/img/icon_pm.gif', array('alt' => __('PM'), 'title' => __('PM'))), '/users/pm_send_form/' . $post->getId_author(), $icon_params);
                 }
                 $author_site = $post->getAuthor()->getUrl() ? '&nbsp;' . get_link(get_img('/sys/img/icon_www.gif', array('alt' => __('Author site'), 'title' => __('Author site'))), h($post->getAuthor()->getUrl()), array_merge($icon_params, array('target' => '_blank')), true) : '';
             }
             $post->getAuthor()->setAuthor_site($author_site);
             $post->getAuthor()->setProfile_url($user_profile);
             $post->getAuthor()->setEmail_url($email);
             $post->getAuthor()->setPm_url($privat_message);
             // Если сообщение редактировалось...
             if ($post->getId_editor()) {
                 if ($post->getId_author() && $post->getId_author() == $post->getId_editor()) {
                     $editor = __('Edit by author') . ' ' . AtmDateTime::getDate($post->getEdittime());
                 } else {
                     $status_info = $this->ACL->get_user_group($post->getEditor()->getStatus());
                     $editor = __('Edited') . $post->getEditor()->getName() . '(' . $status_info['title'] . ') ' . AtmDateTime::getDate($post->getEdittime());
                 }
             } else {
                 $editor = '';
             }
             $post->setEditor_info($editor);
             //edit and delete links
             $edit_link = '';
             $delete_link = '';
             if (!empty($_SESSION['user'])) {
                 if ($this->ACL->turn(array('forum', 'edit_posts', $theme->getId_forum()), false) || !empty($_SESSION['user']['id']) && $post->getId_author() == $_SESSION['user']['id'] && $this->ACL->turn(array('forum', 'edit_mine_posts', $theme->getId_forum()), false)) {
                     $edit_link = get_link('', '/forum/edit_post_form/' . $post->getId(), array('class' => 'fps-edit'));
                 }
                 if ($this->ACL->turn(array('forum', 'delete_posts', $theme->getId_forum()), false) || !empty($_SESSION['user']['id']) && $post->getId_author() == $_SESSION['user']['id'] && $this->ACL->turn(array('forum', 'delete_mine_posts', $theme->getId_forum()), false)) {
                     $delete_link = get_link('', '/forum/delete_post/' . $post->getId(), array('class' => 'fps-delete', 'onClick' => "return confirm('" . __('Are you sure') . "')"));
                 }
             }
             $on_top = get_link('', '#top', array('class' => 'fps-up'), true);
             $post->setOn_top_link($on_top);
             $post->setEdit_link($edit_link);
             $post->setDelete_link($delete_link);
             //message number
             if ($first_top) {
                 $post->setPost_number(1);
                 $first_top = false;
             } else {
                 $post_num++;
                 $post->setPost_number($post_num);
             }
             $post_number_url = 'http://' . $_SERVER['HTTP_HOST'] . get_url('/' . $this->module . '/view_post/' . $post->getId(), true);
             $post->setPost_number_url($post_number_url);
             //set tags for cache
             $this->setCacheTag(array('post_id_' . $post->getId(), 'user_id_' . $post->getId_author()));
         }
         $this->setCacheTag('theme_id_' . $id_theme);
         // Polls render
         $polls = $theme->getPoll();
         if (!empty($polls[0])) {
             $theme->setPoll($this->_renderPoll($polls[0]));
         } else {
             $theme->setPoll('');
         }
         $markers = array('reply_form' => $this->add_post_form($theme));
         $this->_globalize($markers);
         $source = $this->render('posts_list.html', array('posts' => $posts, 'theme' => $theme));
         //write into cache
         if ($this->cached) {
             $this->Cache->write($source, $this->cacheKey, $this->cacheTags);
         }
     }
     // Если страницу темы запросил зарегистрированный пользователь, значит он ее просмотрит
     if (isset($_SESSION['user']) and isset($_SESSION['newThemes'])) {
         if (count($_SESSION['newThemes']) > 0) {
             if (in_array($id_theme, $_SESSION['newThemes'])) {
                 unset($_SESSION['newThemes'][$id_theme]);
             }
         } else {
             unset($_SESSION['newThemes']);
         }
     }
     $theme->setViews($theme->getViews() + 1);
     $theme->save();
     $_SESSION['VIEW_PAGE'] = 'theme' . $id_theme;
     //clean cache
     $this->Cache->clean(CACHE_MATCHING_TAG, array('action_viev_forum', 'theme_id_' . $id_theme));
     return $this->_view($source);
 }
 public static function get()
 {
     $functions = array();
     /**
      * Get one or couple entities.
      * If get one entity of the UsersModel, we also get user statistic
      *
      * @param $modelName
      * @param array $id
      * @return array
      * @throws Exception
      */
     $functions['fetch'] = function ($modelName, $id = array()) {
         $Register = Register::getInstance();
         try {
             $model = $Register['ModManager']->getModelInstance($modelName);
             // get collection of entities
             if (is_array($id) && count($id)) {
                 $id = array_map(function ($n) {
                     $n = intval($n);
                     if ($n < 1) {
                         throw new Exception('Only integer value might send as ID.');
                     }
                     return $n;
                 }, $id);
                 $ids = implode(", ", $id);
                 $result = $model->getCollection(array("`id` IN ({$ids})"));
                 // get one entity
             } else {
                 if (is_numeric($id)) {
                     $id = intval($id);
                     if ($id < 1) {
                         throw new Exception('Only integer value might send as ID.');
                     }
                     $result = $model->getById($id);
                     if ($result && strtolower($modelName) == 'users') {
                         $stat = $model->getFullUserStatistic($id);
                         $result->setStatistic($stat);
                     }
                 }
             }
         } catch (Exception $e) {
             throw new Exception($e->getMessage());
         }
         return !empty($result) ? $result : array();
     };
     /**
      * Format date.
      * If date_format == 'atm-format', just call AtmGetSimpleDate.
      *
      * @param $date string
      * @param $format string
      * @return string
      */
     $functions['AtmGetDate'] = function ($date, $format = false) {
         return AtmDateTime::getDate($date, $format);
     };
     /**
      * Return date formatted as(example) - "3 seconds before"
      *
      * @param $date string
      * @return string
      */
     $functions['AtmGetSimpleDate'] = function ($date) {
         return AtmDateTime::getSimpleDate($date);
     };
     /**
      * Check access according with ACL rules.
      *
      * @param $params array
      * @return bool
      */
     $functions['checkAccess'] = function ($params = array()) {
         if (isset($params) && is_array($params)) {
             $Register = Register::getInstance();
             return $Register['ACL']->turn($params, false);
         }
         return false;
     };
     $functions['get_url'] = function ($url, $notRoot = false, $useLang = true) {
         return get_url($url, $notRoot, $useLang);
     };
     /**
      * Return URl to the user avatar
      * or default image if avatar image is not exists.
      *
      * @param null $id_user
      * @param null $email_user
      * @return string
      */
     $functions['getAvatar'] = function ($id_user = null, $email_user = null) {
         $def = get_url('/template/' . getTemplateName() . '/img/noavatar.png', false, false);
         if (isset($id_user) && $id_user > 0) {
             if (is_file(ROOT . '/sys/avatars/' . $id_user . '.jpg')) {
                 return get_url('/sys/avatars/' . $id_user . '.jpg', false, false);
             } else {
                 $Register = Register::getInstance();
                 $Viewer = $Register['Viewer'];
                 if (Config::read('use_gravatar', 'users') && $Viewer->customFunctionExists('getGravatar')) {
                     if (!isset($email_user)) {
                         $usersModel = $Register['ModManager']->getModelInstance('Users');
                         $user = $usersModel->getById($id_user);
                         if ($user) {
                             $email_user = $user->getEmail();
                         } else {
                             return $def;
                         }
                     }
                     return $Viewer->runCustomFunction('getGravatar', array($email_user));
                 } else {
                     return $def;
                 }
             }
         } else {
             return $def;
         }
     };
     /**
      * Get either a Gravatar URL or complete image tag for a specified email address.
      *
      * @param string $email The email address
      * @param string $s Size in pixels, defaults to 80px [ 1 - 2048 ]
      * @param string $d Default imageset to use [ 404 | mm | identicon | monsterid | wavatar ]
      * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]
      * @return String containing either just a URL or a complete image tag
      */
     $functions['getGravatar'] = function ($email, $s = 120, $d = 'mm', $r = 'g') {
         $url = 'http://www.gravatar.com/avatar/' . md5(strtolower(trim($email))) . ".png?s={$s}&d={$d}&r={$r}";
         return $url;
     };
     $functions['getOrderLink'] = function ($params) {
         if (!$params || !is_array($params) || count($params) < 2) {
             return '';
         }
         $order = !empty($_GET['order']) ? strtolower(trim($_GET['order'])) : '';
         $new_order = strtolower($params[0]);
         $active = $order === $new_order;
         $asc = $active && isset($_GET['asc']);
         $url = $_SERVER['REQUEST_URI'];
         $url = preg_replace('#(order=[^&]*[&]?)|(asc=[^&]*[&]?)#i', '', $url);
         if (substr($url, -1) !== '&' && substr($url, -1) !== '?') {
             $url .= !strstr($url, '?') ? '?' : '&';
         }
         return '<a href="' . $url . 'order=' . $new_order . ($asc ? '' : '&asc=1') . '">' . $params[1] . ($active ? ' ' . ($asc ? '↑' : '↓') : '') . '</a>';
     };
     /**
      * Checks is an user online or not.
      *
      * @param $user_id int
      */
     $functions['CheckUserOnline'] = function ($user_id) {
         $users = getOnlineUsers();
         return array_key_exists($user_id, $users);
     };
     /**
      * Returns user rank img such as Stars or Progressbar
      *
      * @param $rating int
      */
     $functions['getUserRatingImg'] = function ($rating) {
         $Register = Register::getInstance();
         $settingsModel = $Register['ModManager']->getModelInstance('UsersSettings');
         $rating_settings = $settingsModel->getCollection(array('type' => 'rating'));
         $rating_settings = count($rating_settings) > 0 ? $rating_settings[0]->getValues() : '';
         $rank = getUserRating($rating, $rating_settings);
         return $rank['img'];
     };
     $custom_functions = self::loadCustomTemplateFunctions();
     if (is_array($custom_functions)) {
         $functions = array_merge($functions, $custom_functions);
     }
     return $functions;
 }
Esempio n. 3
0
}
if (!empty($_POST['rating1'])) {
    include "addtocomment.php";
    $id_articles = $_POST['id_articles'];
    $profile = getProfile($_SESSION['name']);
    $id_user = $profile[0]['id'];
    $user_rating = $_POST['user_rating'];
    setRating($id_articles, $id_user, $user_rating);
}
//rating
include "addtocomment.php";
if (isset($_GET['id']) and isset($_SESSION['name'])) {
    $profile = getProfile($_SESSION['name']);
    $id_user = $profile[0]['id'];
    $id_articles = $_GET['id'];
    $torating = getUserRating($id_user, $id_articles);
    if ($torating) {
        echo "<div align='right'><b>You rating: " . $torating['user_rating'] . "</b></div>";
        echo "<div align='right'><form action='comment.php' method='post'>\n<input type='hidden' name='id_user' value='" . $id_user . "'>\n<input type='hidden' name='id_articles' value='" . $id_articles . "'>\n<input type='submit' name='delrating' value='Delete rating'>\n</form></div>";
    } else {
        $formrating = "\n<form action='comment.php' method='post'>\n<input type='hidden' name='id_articles' value='" . $_GET['id'] . "'>\n<div align='right'>\n<select name='user_rating'>\n<option>case rating</option>\n<option value='1'>1</option>\n<option value='2'>2</option>\n<option value='3'>3</option>\n<option value='4'>4</option>\n<option value='5'>5</option>\n</select>\n</div>\n<div align='right'><input type='submit' name='rating1'></div>\n</form>";
        echo $formrating;
    }
}
//form of comment
if (!empty($_POST['rating'])) {
    if (!empty($_POST['commenttext'])) {
        include "addtocomment.php";
        $id_articles = $_POST['id_articles'];
        $text_comment = clearData($_POST['commenttext']);
        if (empty($_POST['commenttitle'])) {