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;
 }
 public function gen_topic_arr_all_topics($topics, $search = false)
 {
     $_topics = array();
     $user = \CODOF\User\User::get();
     $uid = $user->id;
     $i = 0;
     foreach ($topics as $topic) {
         $message = \CODOF\Format::message($topic['message']);
         if ($search) {
             $message = $search->get_matching_str($message);
         }
         if (!$this->ajax) {
             //    $message = \CODOF\Filter::json_safe($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" => "gg" . \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_id" => $topic['last_post_id'], "sticky" => Forum::isSticky($topic['topic_status']), "last_post_time" => \CODOF\Time::get_pretty_time($topic['last_post_time'] != $topic['topic_created'] ? $topic['last_post_time'] : NULL));
         if ($search) {
             $_topics[$i]["message"] = $message;
         } else {
             $excerpt = \CODOF\Format::excerpt($message, $topic['topic_id'], $_topics[$i]["safe_title"]);
             $_topics[$i]["message"] = $excerpt['message'];
             $_topics[$i]["overflow"] = $excerpt['overflow'];
         }
         if ($search && $search->match_titles == 'Yes') {
             $_topics[$i]['title'] = $search->highlight($_topics[$i]['title']);
         }
         if ($topic['uid'] == $uid) {
             //this topic belongs to current user
             $_topics[$i]['can_edit_topic'] = $user->can(array('edit my topics', 'edit all topics'), $topic['cat_id']);
             $_topics[$i]['can_delete_topic'] = $user->can(array('delete my topics', 'delete all topics'), $topic['cat_id']);
         } else {
             $_topics[$i]['can_edit_topic'] = $user->can('edit all topics', $topic['cat_id']);
             $_topics[$i]['can_delete_topic'] = $user->can('delete all topics', $topic['cat_id']);
         }
         $_topics[$i]['can_manage_topic'] = $_topics[$i]['can_edit_topic'] || $_topics[$i]['can_delete_topic'];
         if ($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;
 }