<?php
/**
 * [UQcms System] Copyright uqcms.com
 * QQ: 2200631718
 * Author: gj.name
 * This is NOT a freeware
*/
defined('IN_UQ') or exit('Access Denied'); class news_mod extends module { public function get_one($arr){ $id = isset($arr['id'])?$arr['id']:''; $alias = isset($arr['alias'])?$arr['alias']:''; if($id){ $wsql = " where id = ".$id; }elseif($alias){ $wsql = " where alias = '".$alias."'"; }else{ return false; } $row = $this->db->get_one("select * from ".table('news').$wsql); if($row && $row['id']){ preg_match_all("/<img([^>]*)\s*src=('|\")([^'\"]+)('|\")/", $row['content'],$matches); $new_arr=array_unique($matches[3]); if($new_arr){ foreach($new_arr as $key){ $all_img[] = $key; } } $row['all_images'] = $all_img; $prev_row = $this->db->get_one("select id,cid,title from ".table("news")." where id < ".$row['id']." order by id desc limit 1"); $next_row = $this->db->get_one("select id,cid,title from ".table("news")." where id > ".$row['id']." order by id asc limit 1"); $row['prev_id'] = $prev_row['id']; $row['prev_title'] = $prev_row['title']; $row['next_id'] = $next_row['id']; $row['next_title'] = $next_row['title']; return $row; }else{ return false; } } public function get_list($arr){ $cid = isset($arr['cid'])?$arr['cid']:''; $alias = isset($arr['alias'])?$arr['alias']:''; $page = isset($arr['page'])?$arr['page']:'1'; $page_size = isset($arr['page_size'])?$arr['page_size']:'20'; if($alias){ $crow = $this->db->get_one("select * from ".table('news_cats')." where alias = '".$alias."'"); $cid = $crow['cid']; } if($cid){ $wsql = " where cid = ".$cid; }else{ $wsql = ""; } $sql = "select * from ".table('news').$wsql." order by id desc limit ".($page-1)*$page_size.",".$page_size; $query = $this->db->get_all($sql); $datas['list'] = $query; $total = $this->db->get_one("select count(id) as total from ".table("news").$wsql); $datas['page'] = $this->uqcms_page(array('page'=>$page,'page_size'=>$page_size,'total'=>$total['total'])); return $datas; } public function cats_list($pcid){ $cats_one = $this->db->get_one("select * from ".table('news_cats')." where cid = ".$pcid); if($cats_one['pcid'] != '0'){ $pcid = $cats_one['pcid']; } $query = $this->db->query("select * from ".table('news_cats')." where pcid = ".$pcid); while($row = $this->db->fetch_array($query)){ $data[] = $row; } return $data; } public function cats_one($cid){ return $this->db->get_one("select * from ".table('news_cats')." where cid = ".$cid); } public function footer_list($arr){ $id = isset($arr['id'])?$arr['id']:''; $query = $this->db->query("select * from ".table('news_cats')." where alias = 'foot' and status = 1"); while($row = $this->db->fetch_array($query)){ $nquery = $this->db->query("select id,cid,title from ".table('news')." where status = 1 and cid = ".$row['cid']); while($nrow = $this->db->fetch_array($nquery)){ $rowid[] = $nrow['id']; $row['list'][] = $nrow; } if(in_array($id, $rowid)){ $row['ck'] = '1'; }else{ $row['ck'] = '0'; } unset($rowid); $data[] = $row; } return $data; } function cats(){ $all = $this->db->get_all("select * from ".table("news_cats")); if($all){ foreach($all as $k=>$v){ $cats[$v['cid']] = $v['name']; } return $cats; }else{ return false; } } }