Beispiel #1
0
 function create()
 {
     $avatar = $this->attachlib->get_avatar($this->user['user_id']);
     $content = $this->input['thread'];
     $topic_id = $this->input['tid'];
     $pcd = intval($this->input['pcd']);
     $aid = urldecode($this->input['aid']);
     if ($aid) {
         $aid_array = array_filter(explode(',', $aid));
         $aid = $this->attachlib->tmp2att($aid_array);
     }
     if ($pcd) {
         $c = new content();
         $article = $c->get_published_content_byid($pcd);
         if ($article) {
             $extend_arc = array('title' => $article['title'], 'brief' => $article['brief'], 'href' => $article['content_url'], 'bundle_id' => $article['bundle_id'], 'module_id' => $article['module_id']);
             $article = is_array($article['indexpic']) ? array('host' => $article['indexpic']['host'], 'dir' => $article['indexpic']['dir'], 'filepath' => $article['indexpic']['filepath'], 'filename' => $article['indexpic']['filename']) : array();
             $aid .= ',' . $this->attachlib->attach($article, 'publish', 'attach', $extend_arc);
         }
     }
     if (!$topic_id) {
         $this->errorOutput("请选择一个话题");
     }
     $short_link = $this->attachlib->outlink(urldecode($this->input['outlink']));
     if ($short_link) {
         $aid .= ',' . $short_link;
     }
     $location = array('lat' => $this->input['lat'], 'lon' => $this->input['lon'], 'address' => urldecode($this->input['address']), 'gpsx' => $this->input['gpsx'], 'gpsy' => $this->input['gpsy']);
     if ($location['lat'] && $location['lon']) {
         $loc = FromBaiduToGpsXY($location['lon'], $location['lat']);
         $location['gpsx'] = $loc['x'];
         $location['gpsy'] = $loc['y'];
     } elseif ($location['gpsx'] && $location['gpsy']) {
         $loc = FromGpsToBaiduXY($location['gpsx'], $location['gpsy']);
         $location['lon'] = $loc['x'];
         $location['lat'] = $loc['y'];
     }
     if ($map = $this->attachlib->map($location)) {
         $aid .= ',' . $map;
     }
     if (!$content && !$aid) {
         $this->errorOutput("内容不能为空");
     }
     $aid = $aid ? trim($aid, ',') : '';
     $data = array('tid' => $topic_id, 'content' => $content, 'aid' => $aid, 'client' => $this->input['client'] ? $this->input['client'] : $this->user['user_name'], 'status' => 0, 'create_time' => TIMENOW, 'user_id' => $this->user['user_id'], 'avatar' => $avatar ? addslashes(serialize($avatar)) : '', 'user_name' => $this->user['user_name'], 'pcd' => $pcd, 'ip' => hg_getip());
     $sql = 'INSERT INTO ' . DB_PREFIX . 'thread SET ';
     foreach ($data as $key => $val) {
         $sql .= "`{$key}` = \"{$val}\",";
     }
     $sql = trim($sql, ',');
     $this->db->query($sql);
     $data['id'] = $this->db->insert_id();
     $data['format_create_time'] = hg_tran_time($data['create_time']);
     $data['materail'] = $this->attachlib->get_attach_by_aid($aid);
     $this->attachlib->delete_attach(urldecode($this->input['aid']));
     $this->addItem($data);
     $this->output();
 }
Beispiel #2
0
 public function get_conditions()
 {
     $conditions = '';
     if ($this->input['fav']) {
         $sql = 'SELECT * FROM ' . DB_PREFIX . 'favorite where user_id=' . $this->user['user_id'];
         $fav_id = $this->db->query_first($sql);
         $this->input['id'] = $fav_id['tid'] ? $fav_id['tid'] : '-1';
     }
     if ($this->input['id']) {
         $ids = explode(',', $this->input['id']);
         foreach ($ids as $id) {
             if (!intval($id)) {
                 $this->errorOutput(PARAMETER_ERROR);
             }
         }
         $conditions .= ' AND id IN(' . $this->input['id'] . ')';
     }
     if ($this->input['user_id']) {
         $conditions .= ' AND user_id =  ' . $this->input['user_id'];
     }
     if ($this->input['sid']) {
         $conditions .= ' AND sid =  ' . $this->input['sid'];
     }
     $conditions .= ' AND status=1';
     $distance = intval($this->input['distance']);
     $lon = $this->input['lon'];
     $lat = $this->input['lat'];
     $gpsx = $this->input['gpsx'];
     $gpsy = $this->input['gpsy'];
     if ($lat && $lon) {
         $loc = FromBaiduToGpsXY($lon, $lat);
         $gpsx = $loc['x'];
         $gpsy = $loc['y'];
     } elseif ($gpsx && $gpsy) {
         $loc = FromGpsToBaiduXY($gpsx, $gpsy);
         $lon = $loc['x'];
         $lat = $loc['y'];
     }
     $this->location = array('lat' => $lat, 'lon' => $lon, 'gpsx' => $gpsx, 'gpsy' => $gpsy);
     if ($gpsx && $gpsy && $distance) {
         $range = 180 / pi() * $distance / 6372.797;
         //里面的 $distance 就代表搜索 $distance 之内,单位km
         $lngR = $range / cos($gpsx * pi() / 180);
         //echo $range;exit()
         $maxLat = $gpsx + $range;
         //最大纬度
         $minLat = $gpsx - $range;
         //最小纬度
         $maxLng = $gpsy + $lngR;
         //最大经度
         $minLng = $gpsy - $lngR;
         //最小经度
         $condition .= ' AND gpsy >=' . $minLng . ' AND gpsy <=' . $maxLng . ' AND gpsx >=' . $minLat . ' AND gpsx <= ' . $maxLat . ' AND gpsy != 0.00000000000000 AND gpsx != 0.00000000000000 ';
     }
     return $conditions;
 }