function codo_cat_build_structure($cat, $new_topics) { $DURI = DURI; $CAT_IMGS = CAT_ICON_IMGS; $no_topics_title = _t('No. of topics'); $new_no = ''; if (isset($new_topics[$cat->cat_id])) { $new_no = '<a title="' . _t('new topics') . '"><span class="codo_new_topics_count">' . $new_topics[$cat->cat_id] . '</span></a>'; } if ($cat->granted) { $no_topics = \CODOF\Util::abbrev_no($cat->no_topics, 2); } else { $no_topics = '-'; } $url = RURI . 'category/' . $cat->cat_alias; echo <<<EOD <div class="row"> <div class="codo_category_img col-md-2 col-xs-2"> <img draggable="false" src="{$DURI}{$CAT_IMGS}{$cat->cat_img}" /> </div> <div class="codo_categories_category col-md-10 col-xs-10"> <a href="{$url}"><div class="codo_category_title">{$cat->cat_name}</div></a> <span data-toggle="tooltip" data-placement="bottom" title="{$no_topics_title}" class="codo_category_num_topics codo_bs_tooltip">{$no_topics}</span> {$new_no} </div> </div> EOD; static $num_topics = 0; $num_topics++; }
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; }
function smarty_modifier_abbrev_no($string) { return \CODOF\Util::abbrev_no($string, 2); }
/** private functions --------------------------------------------------------- */ public function gen_posts_arr($posts, $search = false) { $_posts = array(); $user = \CODOF\User\User::get(); $uid = $user->id; $i = 0; foreach ($posts as $post) { $message = \CODOF\Format::message($post['message']); if ($search) { $message = $search->get_matching_str($message); } $_posts[$i] = array("id" => $post['id'], "avatar" => \CODOF\Util::get_avatar_path($post['avatar'], $post['id']), "name" => $post['name'], "post_created" => \CODOF\Time::get_pretty_time($post['post_created']), "post_modified" => \CODOF\Time::get_pretty_time($post['post_modified']), "post_id" => $post['post_id'], "message" => $message, "imessage" => $post['imessage'], "reputation" => $post['reputation'], "role" => \CODOF\User\User::getRoleName($post['rid']), "no_posts" => \CODOF\Util::abbrev_no($post['no_posts'], 1), "signature" => $post['signature']); $_posts[$i]['tid'] = $this->tid; $_posts[$i]['page'] = $this->from + 1; $_posts[$i]['safe_title'] = $this->safe_title; if ($this->topic_post_id == $post['post_id']) { //is a topic $_posts[$i]['is_topic'] = true; if ($post['id'] == $uid) { //this topic belongs to current user $_posts[$i]['can_edit_topic'] = $user->can(array('edit my topics', 'edit all topics'), $this->cat_id); $_posts[$i]['can_delete_topic'] = $user->can(array('delete my topics', 'delete all topics'), $this->cat_id); } else { $_posts[$i]['can_edit_topic'] = $user->can('edit all topics', $this->cat_id); $_posts[$i]['can_delete_topic'] = $user->can('delete all topics', $this->cat_id); } $_posts[$i]['can_manage_topic'] = $_posts[$i]['can_edit_topic'] || $_posts[$i]['can_delete_topic']; } else { $_posts[$i]['is_topic'] = false; if ($post['id'] == $uid) { //this topic belongs to current user $_posts[$i]['can_edit_post'] = $user->can(array('edit my posts', 'edit all posts'), $this->cat_id); $_posts[$i]['can_delete_post'] = $user->can(array('delete my posts', 'delete all posts'), $this->cat_id); } else { $_posts[$i]['can_edit_post'] = $user->can('edit all posts', $this->cat_id); $_posts[$i]['can_delete_post'] = $user->can('delete all posts', $this->cat_id); } $_posts[$i]['can_manage_post'] = $_posts[$i]['can_edit_post'] || $_posts[$i]['can_delete_post']; } $_posts[$i]['can_see_history'] = $user->can('see history', $this->cat_id); if ($this->tuid == $uid) { //if my topic $_posts[$i]['can_reply'] = true; //i can reply to my own topic } else { $_posts[$i]['can_reply'] = $user->can('reply to all topics', $this->cat_id, $this->tid); } if ($search) { $_posts[$i]['in_search'] = true; } $i++; } return $_posts; }
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 function category($catid, $page) { $cat = new \CODOF\Forum\Category($this->db); $cat_info = $cat->get_cat_info($catid); $cid = $cat_info['cat_id']; $user = \CODOF\User\User::get(); if (!$cat_info) { $this->view = 'not_found'; return; } if (!$user->can('view category', $cid)) { $this->view = 'access_denied'; return; } $cats = $cat->get_categories(); $cats_tree = $cat->generate_tree($cats); $sub_cats = $cat->get_sub_categories($cats_tree, $cid); $this->smarty->assign('parents', $cat->find_parents($cats, $cid)); $this->smarty->assign('cats', $cats_tree); $this->smarty->assign('sub_cats', $sub_cats); //$num_results = \CODOF\Util::get_opt("num_posts_cat_topics"); $subscriber = new \CODOF\Forum\Notification\Subscriber(); $this->smarty->assign('no_followers', $subscriber->followersOfCategory($cid)); if (\CODOF\User\CurrentUser\CurrentUser::loggedIn()) { $this->smarty->assign('my_subscription_type', $subscriber->levelForCategory($cid)); } $api = new Ajax\forum\category(); $num_topics_page = \CODOF\Util::get_opt('num_posts_cat_topics'); $data = $api->get_topics($cid, $page); $this->smarty->assign('load_more_hidden', false); if ($page * $num_topics_page >= $cat_info['no_topics']) { $this->smarty->assign('load_more_hidden', true); } if (isset($_GET['search']) && $_GET['search'] != null) { //$search_conds = json_decode($_GET['search']); $search_data = $_GET['search']; } else { $search_data = '{}'; } $user = \CODOF\User\User::get(); $this->smarty->assign('new_topics', $data['new_topics']); $this->smarty->assign('can_create_topic', $cat->canCreateTopicIn($cid)); $this->smarty->assign('can_search', $user->can('use search')); $this->smarty->assign('search_data', $search_data); $this->smarty->assign('topics', \CODOF\HB\Render::tpl('forum/category', $data)); $this->smarty->assign('cat_info', $cat_info); $this->smarty->assign('cat_alias', $catid); $this->smarty->assign('curr_page', $page); $this->smarty->assign('num_posts_per_page', $num_topics_page); $this->assign_editor_vars(); $no_topics = $no_posts = ' -- '; if ($user->can('view all topics', $cid)) { $no_topics = \CODOF\Util::abbrev_no($cat_info['no_topics'], 2); $no_posts = \CODOF\Util::abbrev_no($cat_info['no_posts'], 2); } $this->smarty->assign('no_topics', $no_topics); $this->smarty->assign('no_posts', $no_posts); $this->css_files = array('category', 'editor', 'jquery.textcomplete'); $this->js_files = array(array('category/category.js', array('type' => 'defer')), array('category/jquery.easing.1.3.js', array('type' => 'defer')), array('bootstrap-tagsinput.js', array('type' => 'defer')), array('bootstrap-slider.js', array('type' => 'defer'))); $this->js_files = array_merge($this->js_files, $cat->get_js_editor_files()); $this->smarty->assign('can_make_sticky', $user->can('make sticky')); $this->view = 'forum/category'; $this->smarty->assign('can_make_sticky', $user->can('make sticky')); $this->smarty->assign('can_add_tags', $user->can('add tags')); \CODOF\Hook::call('on_category_view', array($cat_info)); \CODOF\Store::set('rel:canonical_page', '/'); \CODOF\Store::set('sub_title', $cat_info['cat_name']); \CODOF\Store::set('og:url', RURI . 'category/' . $catid); \CODOF\Store::set('og:desc', $cat_info['cat_description']); \CODOF\Store::set('og:image', DURI . CAT_IMGS . $cat_info['cat_img']); }