<? require_once("bootstrap.inc.php"); header("Content-type: application/json; charset=utf-8"); $sql = new SQLSelect(); $sql->AddField("id"); $sql->AddField("nickname as name"); $sql->AddField("avatar"); $sql->AddField("glops"); $sql->AddTable("users"); $r = array(); if ($_POST["search"]) { $sql->AddWhere(sprintf_esc("nickname like '%%%s%%'",_like($_POST["search"]))); $sql->AddOrder(sprintf_esc("if(nickname='%s',1,2), nickname, lastLogin DESC",$_POST["search"])); $sql->SetLimit(10); $r = SQLLib::selectRows( $sql->GetQuery() ); } else if ($_POST["id"]) { $sql->AddWhere(sprintf_esc("id = %d",$_POST["id"])); $sql->SetLimit(1); $r = SQLLib::selectRows( $sql->GetQuery() ); } echo json_encode($r); ?>
<? require_once("bootstrap.inc.php"); $r = SQLLib::selectRows(sprintf_esc("select name,type,party_year from prods where name like '%%%s%%' order by views desc limit 10",_like($_GET["what"]))); $res[0] = $_GET["what"]; foreach($r as $o) { $res[1][] = $o->name; $res[2][] = $o->type.($o->party_year?", ".$o->party_year:""); } header("Content-type: application/json; charset=utf-8"); echo json_encode($res); ?>
function post($id, $uid, $userid, $user, $name, $img, $date, $post, $var, $rid, $type, $client) { $client_apps_array = array("", "web", "mobile", ""); $client_apps_url = array("", "./?force_web=2", "./?force_mobile=2", ""); $rp = ""; $client1 = $client_apps_array[$client]; $clienturl = $client_apps_url[$client]; $client = "<a href='{$clienturl}' class='small' target='_blank'>via {$client1}</a>"; if ($type == 1) { $con = new db(); $conc = $con->c(); $q = mysqli_query($conc, "SELECT `post`.`id`,`users`.`user` FROM `post` INNER JOIN `users` ON (`users`.`id` = `post`.`user`) WHERE `post`.`id` = {$rid} "); $r = mysqli_fetch_array($q); $pid = $r[1]; $rp = "<a href='" . PTH . "/?view={$rid}&t={$type}' class='del' onclick='return _op({$rid},{$type})' title='in reply to {$pid}'><table><tr><td><div class='preply'></div></td><td>to {$pid}</td></tr></table></a>"; $con->close_db_con($conc); } else { if ($type == 2) { $con = new db(); $conc = $con->c(); $q = mysqli_query($conc, "SELECT `post`.`id`,`users`.`user` FROM `post` INNER JOIN `users` ON (`users`.`id` = `post`.`user`) WHERE `post`.`id` = {$rid} "); $r = mysqli_fetch_array($q); $pid = $r[1]; $con->close_db_con($conc); $rp = "<a href='" . PTH . "/?view={$rid}&t={$type}' class='del' onclick='return _op({$rid},{$type})' title='refed from {$pid}'><table><tr><td><div class='prefeed'></div></td><td>from {$pid}</td></tr></table></a>"; } } $bb = "."; $imgclass = "smpdiv"; $post_style = ""; $url = "./{$user}"; if ($_SESSION["mobile"] == 2) { // $bb = ".."; // $url = "./?i=$user"; $imgclass = "ssmpdiv"; } if ($var == "pop") { $style = "style='width:400px;'"; $var = ""; $imgclass = "ssmpdiv"; $post_style = "style='font-size:10px;'"; } if ($_SESSION["uid"] != 0) { $con = new db(); $conc = $con->c(); $del = $uid == $userid ? "<a onclick='return _del(event,\"{$id}\")'><div title='delete' class='delete'></div></a>" : ""; $nl = numlikes($conc, $id); $like = _like($conc, $id, $uid) ? " style='background-image:url(" . PTH . "/img/like.png);' class='like' title='unlike {$nl}'" : " title='like {$nl}' style='background:url(" . PTH . "/img/like_2.png) center no-repeat;' class='like'"; $con->close_db_con($conc); $llike = " <div {$like} onclick='_like(event,{$id},{$userid})' class='like' onmouseover='_textgrow(event)' align='center'>" . $nl . "</div>"; $reply = "<a href='" . PTH . "/?rep={$id}&u={$user}&t=1' class='del' onclick='return _reply(event)' rid='{$id}' u='{$user}'><div class='preply' title='reply {$name}'></div></a>"; $repost = "<a href='" . PTH . "/?rep={$id}&u={$user}&t=2' class='del' onclick='return _repost(event)' rid='{$id}' u='{$user}'><div title='refeed' class='prefeed' ></div></a>"; } $style = stripos($post, "@" . $_SESSION["user"]) !== false ? "style='border-left:2px solid #444;'" : ""; // $style = $userid == $uid?"style='border-right:1px solid #444;'":$style; // $style = ""; //_pop(event,$userid) return "<div class='post' id='post{$id}' {$style} onmouseover='_postOver(event)' >\n\t\t\t\t<table width='100%'><tr><td width='10%'><a href='{$url}' onclick='return _pop(event,\"{$user}\")' ><div class='{$imgclass}' style='background-image:url(" . PTH . "{$img});'></div></a></td>\n\t\t\t\t<td width='90%'>\n\t\t\t\t<table width='100%'><tr><td width='100%'><a href='{$url}' onclick='return _pop(event,\"{$userid}\")' onmouseover='' >{$user}</a> <i style='_pn'>{$name}</i><br/><span class='_post' id='post_span_" . $id . "' {$post_style}>{$post}</span><br/></td></tr></table>\n\t\t\t\t<table style='float:right;'><tr><td valign='middle'><a class='del' style='display:none;' udate='" . date("U", $date) . "' title='" . date("r", $date) . "' href='" . PTH . "/?view={$id}&t=0' onclick='return _op({$id},0);'>" . gtime($date) . "</a></td><td valign='middle'>{$rp}</td><td valign='middle'>{$client}</td><td>{$llike}</td><td>{$reply}</td><td>{$repost}</td><td>{$del}</td><td valign='middle'>{$var}</td></tr></table></td></tr></table>\n\t\t\t\t</div> "; }
/** * @youyiyiper * 查:得到查询总数 * * @param array $param 查询的条件 * @return 返回查询总数 */ public function get_count2($param = array()) { if (empty($param)) { return FALSE; } /*方式一 $act_arr = array('table','where','having','join','groupby', 'like'); foreach ($act_arr as $key => $value) { isset($param[$value]) ? $$value = $param[$value] : $$value = ''; } */ //方式二 extract($param); //表名必须存在 并且 不能为空 if (empty($table)) { return FALSE; } if (!empty($where)) { $this->db->where($where); } if (!empty($like)) { $this - _like($like); } //关联关系,二维数组,可查看下面 _join($join) 方法 if (isset($join) && !empty($join)) { $this->_join($join); } if (!empty($groupby)) { $this->db->group_by($groupby); } if (!empty($having)) { $this->db->having($having); } $this->db->from($table); return $this->db->count_all_results(); }