public function selectReply($aid) { $sql = "SELECT r.rid,r.aid,r.uid,r.rcontent,r.create_time,r.zan,u.user_img,u.nickname FROM " . $this->table . " AS r," . C('DB_PREFIX') . $this->utable . " AS u where r.aid='" . $aid . "' AND r.uid=u.id ORDER BY r.create_time DESC"; $res = $this->query($sql); $result = array(); if ($res) { foreach ($res as $v) { $v['time'] = dateaway($v['create_time']); $data[] = $v; } // p($data); return $data; } else { return false; } }
public function userReply() { $uid = isset($_GET['uid']) ? $_GET['uid'] : 0; $uid = $this->vali($uid); $res = K('User')->userReply($uid); $arr = []; foreach ($res as $v) { $v['time'] = dateaway($v['create_time']); $arr[] = $v; } #p($arr); if ($res) { $this->assign('res', $arr); } else { $this->assign('res', 0); } $this->v(); }
function arclist($attr, $content, &$smarty) { $model = 'article'; // p($attr);die; //获得指定文章 $aid = intval(isset($attr['aid']) ? $attr['aid'] : 0); //获得指定类型文章 $cid = intval(isset($attr['cid']) ? $attr['cid'] : 0); //显示条数 $row = isset($attr['row']) ? $attr['row'] : 10; //标题长度 $titlelen = isset($attr['titlelen']) ? $attr['titlelen'] : '10'; //简介长度 $infolen = isset($attr['infolen']) ? intval($attr['infolen']) : 80; //是否只获取有缩略图的文章 1获得只有图片的 0 有没有都行 $image = intval(isset($attr['image']) ? $attr['image'] : 0); //排序 //显示类型 hot 热门文章 new 最新文章 $order = isset($attr['order']) ? strtolower(trim($attr['order'])) : ''; $reply = intval(isset($attr['reply']) ? $attr['reply'] : 0); //对快进行命名 $bname = isset($attr['name']) ? $attr['name'] : "field"; // echo $image;die; /*==========================语句重组===============================*/ $adb = M($model); //实例化一个数据库模型 //---------------------------where------------------------------- if ($aid) { //指定文章id $adb->where("aid=" . $aid); } if ($cid) { $adb->where("cid=" . $cid); } if ($image) { $adb->where("thumb <> ''"); } //---------------------------order------------------------------- if ($order) { switch ($order) { case 'hot': //查看次数最多 $order = 'hits DESC'; break; case 'rand': //随机排序 $order = 'rand()'; break; case 'new': //最新文章 $order = 'create_time DESC'; break; case 'tj': $adb->where('recommend=1'); default: // \$order= str_replace(array('aid','cid'), array(\$db->table.'.aid','category.cid'), \$order); } } else { $order = 'aid DESC'; } //---------------------------查询条件------------------------------- //---------------------------limit------------------------------- $result = $adb->order($order)->limit($row)->all(); //---------------------------重组文章数据------------------------------- $article = array(); $str = ""; // $result = article_data_ready($result); foreach ($result as $index => $field) { // $field=article_data_ready($field); $field['url'] = "index.php?m=Index&c=view&a=article&aid=" . $field['aid']; $field['_index'] = $index; $field['_index_1'] = $index + 1; $field['_first'] = $index == 0 ? true : false; $field['_last'] = $index == count($result) - 1 ? true : false; $field['title'] = mb_substr($field['title'], 0, $titlelen, 'utf8'); $field['title_highlight'] = $field['highlight'] ? "<span style='color:red'>" . $field['title'] . "</span>" : $field['title']; $field['excerpt'] = mb_substr($field['excerpt'], 0, $infolen, 'utf-8'); if (isset($field['new_window']) || isset($field['redirecturl'])) { $field['link'] = '<a href="' . $field['url'] . '" target="_blank">' . $field['title'] . '</a>'; } else { $field['link'] = '<a href="' . $field['url'] . '">' . $field['title'] . '</a>'; } if ($reply) { $field['rnum'] = count(M('article_reply')->where("aid='" . $field['aid'] . "'")->all()); } $field['create_time'] = dateaway($field['create_time']) . '(' . date('m-d', $field['create_time']) . ')'; #date('Y-m-d',$field['create_time']); $article[] = $field; $fieldName = array_keys($field); $temp = $content; foreach ($fieldName as $name) { $temp = str_replace("[\$" . $bname . "." . $name . "]", $field[$name], $temp); } $str .= $temp; } // p($article); // p($str); $smarty->assign("list", $article); return $str; }