public function get_news_list($start = 0, $limit = 10, $keyword, $type = 1) { $obj = new Home(); $query = $this->news_model->get_news_list($type, $start, $limit, $keyword); if ($query != NULL) { $i = 0; foreach ($query->result() as $q) { $path = !isset($q->path_image) ? "" : $q->path_image; $title = !isset($q->title) ? "" : $q->title; $tag = !isset($q->tag) ? "" : $q->tag; $year = !isset($q->year) ? 0 : $q->year; $month = !isset($q->month) ? 0 : $q->month; $day = !isset($q->day) ? 0 : $q->day; $default = base_url('assets/img/news/default-image.png'); $news_id = !isset($q->news_id) ? "" : $q->news_id; $read_more = base_url("news/read/" . $year . '/' . $month . '/' . $day . '/' . $news_id . "/" . $this->slug($title) . ""); $title = $type == 2 || $type == 3 || $type == 4 ? $this->global_common->get_title(26, $title) : $title; $img = "<p><a class='crop' target='_blank' href='" . $read_more . "'>"; //$img .= "<img class='img-responsive opacity' width='480px' src='". base_url($path) ."' alt='".$title."'/>"; $img .= "<img class='img-responsive opacity lazy' width='480px' src='" . $default . "' data-original='" . base_url($path) . "' alt='" . $title . "'>"; $img .= "</a></p>"; $category = !isset($q->category) ? "" : $q->category; $recent_news_category = "<a href='" . base_url('news/page/0/0/' . $category) . "'>" . $category . "</a>"; $data[$i] = array("news_id" => $news_id, "news_category_id" => !isset($q->news_category_id) ? "" : $q->news_category_id, "image_id" => !isset($q->image_id) ? "" : $q->image_id, "title" => "<a href='" . $read_more . "'>" . $title . "</a>", "read_more" => "<a class='btn btn-primary' href='" . $read_more . "'>Read More</a>", "tag" => $this->global_common->get_list_tag($tag, 'news'), "summary" => !isset($q->summary) ? "" : $obj->get_preview_summary($q->summary), "body" => !isset($q->body) ? "" : $obj->get_preview_summary($q->body), "full_name" => !isset($q->nama_lengkap) ? "" : $q->nama_lengkap, "created_date" => !isset($q->created_date) ? "" : $q->created_date, "image" => $img, "recent_news_category" => $recent_news_category, "count_news_comment" => $this->news_model->count_news_comment($news_id)->count_news_comment, "count_news_stat" => $this->news_model->count_news_stat($news_id)->count_news_stat); $i++; } } else { $data = NULL; } return $data; }
function result($type = 'article', $q) { $config = $this->page_config($type, $q); $result = $this->search_model->get($type, $q, $config['page'], $config['limit']); $home = new Home(); $default = array(array("title" => "", "summary" => "", "url" => "", "no_result" => "<h2>No result.</h2>.")); if ($result['data'] == false || $q == null) { return $default; } else { $counter = 0; foreach ($result['data'] as $row) { if ($row->status == 'published') { $date = explode(" ", $row->created_date); $y = explode("-", $date[0]); $m = explode("-", $date[0]); $d = explode("-", $date[0]); if ($type == 'article') { $url = base_url("article/read/" . $y[0] . '/' . $m[1] . '/' . $d[2] . '/' . $row->article_id . "/" . $this->slug($row->title) . ""); } if ($type == 'news') { $url = base_url("news/read/" . $y[0] . '/' . $m[1] . '/' . $d[2] . '/' . $row->news_id . "/" . $this->slug($row->title) . ""); } if ($type == 'video') { $url = base_url('video/watch/' . $y[0] . '/' . $m[1] . '/' . $d[2] . '/' . $row->video_id . '/' . $this->slug($row->title)); } $data[] = array("title" => $this->get_highlight($row->title, $q), "summary" => $type != 'video' ? strip_tags($home->get_preview_summary($this->get_highlight($row->summary, $q), $url, ''), '<a></a>') : strip_tags($home->get_preview_summary($this->get_highlight($row->description, $q), $url, 'video'), '<a></a>'), "url" => $url, "no_result" => ""); $counter++; } } return $counter > 0 ? $data : $default; } }