Example #1
0
 public function get_posts($tid, $from, $topic_info)
 {
     $post = new \CODOF\Forum\Post($this->db);
     $posts = array();
     $num_pages = 'not_passed';
     $posts_per_page = \CODOF\Util::get_opt("num_posts_per_topic");
     $title = \CODOF\Filter::URL_safe($topic_info['title']);
     if (isset($_GET['str'])) {
         $num_pages = 'calc_count';
     }
     if (isset($_GET['str']) && $_GET['str'] != "") {
         $user = \CODOF\User\User::get();
         if (!$user->can('use search')) {
             exit('permission denied');
         }
         $search = new \CODOF\Search\Search();
         $search->str = $_GET['str'];
         $search->num_results = $posts_per_page;
         $search->from = $from * $search->num_results;
         if ($num_pages == 'calc_count') {
             $search->count_rows = true;
         }
         $search->tid = $tid;
         $search->match_titles = 'No';
         $search->order = $_GET['order'];
         $search->sort = $_GET['sort'];
         $search->time_within = $_GET['search_within'];
         $res = $search->search();
         if ($num_pages == 'calc_count') {
             $num_pages = $post->get_num_pages($search->get_total_count(), $search->num_results);
         }
         $post->topic_post_id = $topic_info['post_id'];
         $post->tuid = $topic_info['uid'];
         $post->cat_id = $topic_info['cat_id'];
         $post->tid = $tid;
         $post->safe_title = $title;
         $post->from = $from;
         $posts = $post->gen_posts_arr($res, $search);
         //var_dump($topics);
     } else {
         $topic = new \CODOF\Forum\Topic($this->db);
         $num_pages = $topic->get_num_pages($topic_info['no_posts'], $posts_per_page);
         $post->topic_post_id = $topic_info['post_id'];
         $post->tuid = $topic_info['uid'];
         $post->cat_id = $topic_info['cat_id'];
         $post->tid = $tid;
         $post->safe_title = $title;
         $post->from = $from;
         $posts = $post->get_posts($tid, $from);
     }
     return array("posts" => $posts, "num_pages" => $num_pages);
 }
 private function format($topics)
 {
     $_topics = array();
     $i = 0;
     foreach ($topics as $topic) {
         $message = \CODOF\Format::message($topic['message']);
         $_topics[$i] = array("cat_alias" => $topic['cat_alias'], "cat_img" => $topic['cat_img'], "id" => $topic['id'], "avatar" => \CODOF\Util::get_avatar_path($topic['avatar'], $topic['id']), "name" => $topic['name'], "post_created" => \CODOF\Time::get_pretty_time($topic['post_created']), "topic_id" => $topic['topic_id'], "post_id" => $topic['post_id'], "safe_title" => \CODOF\Filter::URL_safe($topic['title']), "title" => \CODOF\Util::mid_cut($topic['title'], 200), "no_replies" => \CODOF\Util::abbrev_no($topic['no_posts'] - 1, 1), "no_views" => \CODOF\Util::abbrev_no($topic['no_views'], 1), "last_post_uid" => $topic['last_post_uid'], "last_post_name" => $topic['last_post_name'], "last_post_time" => \CODOF\Time::get_pretty_time($topic['last_post_time'] != $topic['topic_created'] ? $topic['last_post_time'] : NULL));
         $excerpt = \CODOF\Format::excerpt($message, $topic['topic_id'], $_topics[$i]["safe_title"]);
         $_topics[$i]["message"] = $excerpt['message'];
         $_topics[$i]["overflow"] = $excerpt['overflow'];
         $_topics[$i]["status"] = $topic['topic_status'];
         $_topics[$i]["what"] = 'is_topic';
         $i++;
     }
     return $_topics;
 }
 private function gen_posts_arr($posts)
 {
     $_posts = array();
     $i = 0;
     $topics_set = array();
     foreach ($posts as $post) {
         if (isset($topics_set[$post['topic_id']])) {
             $_posts[$topics_set[$post['topic_id']]]['contents'][] = array("post_id" => $post['post_id'], "message" => \CODOF\Format::message($post['message']), "post_created" => \CODOF\Time::get_pretty_time($post['post_created']));
             //$topics_set[$post['topic_id']]++;
             continue;
         }
         $_posts[$i] = array("id" => $post['id'], "avatar" => \CODOF\Util::get_avatar_path($post['avatar'], $post['id']), "name" => $post['name'], "no_replies" => \CODOF\Util::abbrev_no($post['no_posts'] - 1, 1), "no_views" => \CODOF\Util::abbrev_no($post['no_views'], 1), "topic_created" => \CODOF\Time::get_pretty_time($post['topic_created']), "cat_alias" => $post['cat_alias'], "cat_img" => $post['cat_img'], "contents" => array(array("post_id" => $post['post_id'], "message" => \CODOF\Format::message($post['message']), "post_created" => \CODOF\Time::get_pretty_time($post['post_created']))), "topic_id" => $post['topic_id'], "safe_title" => \CODOF\Filter::URL_safe($post['title']), "title" => html_entity_decode(\CODOF\Util::mid_cut($post['title'], 200), ENT_NOQUOTES, "UTF-8"));
         $topics_set[$post['topic_id']] = $i;
         $i++;
     }
     return $_posts;
 }
Example #4
0
 public function gen_topic_arr($topics, $cid)
 {
     $_topics = array();
     $user = \CODOF\User\User::get();
     $uid = $user->id;
     $i = 0;
     foreach ($topics as $topic) {
         $message = \CODOF\Format::message($topic['message']);
         $_topics[$i] = array("id" => $topic['id'], "avatar" => \CODOF\Util::get_avatar_path($topic['avatar'], $topic['id']), "name" => $topic['name'], "post_created" => \CODOF\Time::get_pretty_time($topic['post_created']), "topic_created" => $topic['topic_created'], "topic_id" => $topic['topic_id'], "post_id" => $topic['post_id'], "safe_title" => \CODOF\Filter::URL_safe(html_entity_decode($topic['title'])), "title" => $topic['title'], "no_replies" => \CODOF\Util::abbrev_no($topic['no_posts'] - 1, 1), "no_views" => \CODOF\Util::abbrev_no($topic['no_views'], 1), "last_post_name" => $topic['lname'], "last_post_uid" => $topic['luid'], "sticky" => Forum::isSticky($topic['topic_status']), "last_post_id" => $topic['last_post_id'], "last_post_time" => \CODOF\Time::get_pretty_time($topic['lpost_time'] != $topic['topic_created'] ? $topic['lpost_time'] : NULL));
         $excerpt = \CODOF\Format::excerpt($message, $topic['topic_id'], $_topics[$i]["safe_title"]);
         $_topics[$i]["message"] = $excerpt['message'];
         $_topics[$i]["overflow"] = $excerpt['overflow'];
         if ($topic['uid'] == $uid) {
             //this topic belongs to current user
             $_topics[$i]['can_edit_topic'] = $user->can(array('edit my topics', 'edit all topics'), $cid);
             $_topics[$i]['can_delete_topic'] = $user->can(array('delete my topics', 'delete all topics'), $cid);
         } else {
             $_topics[$i]['can_edit_topic'] = $user->can('edit all topics', $cid);
             $_topics[$i]['can_delete_topic'] = $user->can('delete all topics', $cid);
         }
         $_topics[$i]['can_manage_topic'] = $_topics[$i]['can_edit_topic'] || $_topics[$i]['can_delete_topic'];
         if (isset($search)) {
             $_topics[$i]['in_search'] = true;
         }
         if (in_array($topic['topic_id'], $this->new_topic_ids)) {
             $_topics[$i]["new_topic"] = true;
         }
         if (in_array($topic['topic_id'], $this->new_replies)) {
             $_topics[$i]["new_replies"] = $this->new_replies[$topic['topic_id']][0];
             $_topics[$i]["last_reply_id"] = $this->new_replies[$topic['topic_id']][1];
         }
         if (isset($this->tags[$topic['topic_id']])) {
             $_topics[$i]["tags"] = $this->tags[$topic['topic_id']];
         }
         $i++;
     }
     return $_topics;
 }
 public static function get_alias($name)
 {
     return \CODOF\Filter::URL_safe($name);
 }
function smarty_modifier_URL_safe($string)
{
    return \CODOF\Filter::URL_safe($string);
}
Example #7
0
 public function topic($tid, $page)
 {
     $topic = new \CODOF\Forum\Topic($this->db);
     $post = new \CODOF\Forum\Post($this->db);
     $topic_info = $topic->get_topic_info($tid);
     if ($topic_info['topic_status'] == \CODOF\Forum\Forum::MERGED_REDIRECT_ONLY) {
         $tid = $topic_info['redirect_to'];
         $topic_info = $topic->get_topic_info($tid);
     }
     if ($topic_info['topic_status'] == \CODOF\Forum\Forum::MODERATION_BY_FILTER) {
         $topic_is_spam = true;
     } else {
         $topic_is_spam = false;
     }
     $this->smarty->assign('topic_is_spam', $topic_is_spam);
     $user = \CODOF\User\User::get();
     if ($topic_is_spam) {
         if (!($user->can('moderate topics') || $user->id == $topic_info['uid'])) {
             $this->view = 'access_denied';
             return false;
         }
     }
     if (!$topic->canViewTopic($topic_info['uid'], $topic_info['cat_id'], $topic_info['topic_id'])) {
         //\CODOF\Hook::call('page not found', array('type' => 'topic', 'id' => $tid));
         \CODOF\Store::set('sub_title', _t('Access denied'));
         $this->view = 'access_denied';
         return;
     }
     $tracker = new \CODOF\Forum\Tracker($this->db);
     $tracker->mark_topic_as_read($topic_info['cat_id'], $tid);
     if (!$topic_info) {
         $this->view = 'not_found';
     } else {
         $posts_per_page = \CODOF\Util::get_opt("num_posts_per_topic");
         if (strpos($page, "post-") !== FALSE) {
             $pid = (int) str_replace("post-", "", $page);
             $prev_posts = $post->get_num_prev_posts($tid, $pid);
             $from = floor($prev_posts / $posts_per_page);
         } else {
             $from = (int) $page - 1;
         }
         $topic_info['no_replies'] = $topic_info['no_posts'] - 1;
         $name = \CODOF\Filter::URL_safe($topic_info['title']);
         $subscriber = new \CODOF\Forum\Notification\Subscriber();
         $this->smarty->assign('no_followers', $subscriber->followersOfTopic($topic_info['topic_id']));
         if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
             $this->smarty->assign('my_subscription_type', $subscriber->levelForTopic($topic_info['topic_id']));
         }
         $this->smarty->assign('tags', $topic->getTags($topic_info['topic_id']));
         $api = new Ajax\forum\topic();
         $posts_data = $api->get_posts($tid, $from, $topic_info);
         $num_pages = $posts_data['num_pages'];
         $posts = $posts_data['posts'];
         $posts_tpl = \CODOF\HB\Render::tpl('forum/topic', $posts_data);
         $this->smarty->assign('posts', $posts_tpl);
         $this->smarty->assign('topic_info', $topic_info);
         $this->smarty->assign('title', htmlentities($topic_info['title'], ENT_QUOTES, "UTF-8"));
         $search_data = array();
         if (isset($_GET['str'])) {
             $search_data = array('str' => strip_tags($_GET['str']));
         }
         $this->smarty->assign('search_data', json_encode($search_data));
         $url = 'topic/' . $topic_info['topic_id'] . '/' . $name . '/';
         $this->smarty->assign('pagination', $post->paginate($num_pages, $from + 1, $url, false, $search_data));
         if (ceil(($topic_info['no_posts'] + 1) / $posts_per_page) > $num_pages) {
             //next reply will go to next page
             $this->smarty->assign('new_page', 'yes');
         } else {
             $this->smarty->assign('new_page', 'nope');
         }
         $cat = new \CODOF\Forum\Category($this->db);
         $cats = $cat->get_categories();
         $cid = $topic_info['cat_id'];
         $parents = $cat->find_parents($cats, $cid);
         array_push($parents, array("name" => $topic_info['cat_name'], "alias" => $topic_info['cat_alias']));
         $this->smarty->assign('can_search', $user->can('use search'));
         $this->smarty->assign('parents', $parents);
         $this->smarty->assign('num_pages', $num_pages);
         $this->smarty->assign('curr_page', $from + 1);
         //starts from 1
         $this->smarty->assign('url', RURI . $url);
         $this->assign_editor_vars();
         $tuid = $topic_info['uid'];
         $this->assign_admin_vars($tuid);
         $this->css_files = array('topic', 'editor', 'jquery.textcomplete');
         $arr = array(array('topic/topic.js', array('type' => 'defer')), array('modal.js', array('type' => 'defer')), array('bootstrap-slider.js', array('type' => 'defer')));
         $this->js_files = array_merge($arr, $post->get_js_editor_files());
         \CODOF\Hook::call('on_topic_view', array($topic_info));
         $this->view = 'forum/topic';
         \CODOF\Store::set('sub_title', $topic_info['title']);
         \CODOF\Store::set('og:type', 'article');
         \CODOF\Store::set('og:title', $topic_info['title']);
         \CODOF\Store::set('og:url', RURI . $url);
         $mesg = $posts[0]['imessage'];
         \CODOF\Store::set('og:desc', strlen($mesg) > 200 ? substr($mesg, 0, 197) . "..." : $mesg);
         if ($from > 0) {
             //previous page exists
             \CODOF\Store::set('rel:prev', RURI . $url . $from);
         }
         $curr_page = $from + 1;
         if ($curr_page < $num_pages) {
             //next page exists
             \CODOF\Store::set('rel:next', RURI . $url . ($curr_page + 1));
         }
         \CODOF\Store::set('article:published', date('c', $topic_info['topic_created']));
         if ($topic_info['topic_updated'] > 0) {
             \CODOF\Store::set('article:modified', date('c', $topic_info['topic_updated']));
         }
     }
 }
Example #8
0
 public function edit_profile($id)
 {
     $edit = \CODOF\User\User::get();
     $id = (int) $id;
     if (!$this->can_edit_profile($id)) {
         $this->view = 'access_denied';
         return false;
     }
     $values = array("name" => \CODOF\Filter::msg_safe($_POST['name']), "signature" => \CODOF\Format::omessage($_POST['signature']));
     $success = true;
     if (isset($_FILES) && $_FILES['avatar']['error'] != UPLOAD_ERR_NO_FILE) {
         $success = false;
         \CODOF\File\Upload::$width = 128;
         \CODOF\File\Upload::$height = 128;
         \CODOF\File\Upload::$resizeImage = true;
         \CODOF\File\Upload::$resizeIconPath = DATA_PATH . PROFILE_ICON_PATH;
         $result = \CODOF\File\Upload::do_upload($_FILES['avatar'], PROFILE_IMG_PATH);
         if (\CODOF\File\Upload::$error) {
             $this->smarty->assign('file_upload_error', $result);
         } else {
             $values["avatar"] = $result['name'];
             $success = true;
         }
     }
     $edited = $edit->set($values);
     if (!$edited) {
         Util::log("Failed to update user details profile/id/edit");
         $success = false;
     }
     $this->smarty->assign('user_profile_edit', $success);
     $this->profile($id, 'edit');
 }
Example #9
0
 /**
  * Generates absolute url to topic or post[if post id provided]
  * @param int $tid topic id
  * @param string $title topic title
  * @param int $pid post id [optional]
  * @return string absolute url to topic/post
  */
 public static function getPostURL($tid, $title, $pid = false)
 {
     $safe_title = \CODOF\Filter::URL_safe($title);
     $url = RURI . "topic/{$tid}/{$safe_title}";
     if ($pid) {
         $url .= "/post-{$pid}/#post-{$pid}";
     }
     return $url;
 }