本帖最后由 c4m 于 2009-6-9 16:33 编辑
先前一个站长(ahqueer)让我帮他实现“同城异性动态”功能,由于最近事情比较多延误至今,说声抱歉,现将代码发放到这里供大家共享,本人支持共享,希望大家网站越做越好,呵呵
示范站点:http://www.86112.com
言归正传,实现方法如下:
1 打开 ./source/space_feed.php
1) 查找:- //分页
- $perpage = $_SCONFIG['feedmaxnum']<50?50:$_SCONFIG['feedmaxnum'];
- $start = empty($_GET['start'])?0:intval($_GET['start']);
复制代码 在其上面添加:- //同城异性动态
- $samecityuid = "";
- $query = $_SGLOBAL['db']->query("SELECT uid FROM ".tname('spacefield')." WHERE residecity = '".$space['residecity']."' AND sex != '".$space['sex']."' AND sex !=0");
- while($value = $_SGLOBAL['db']->fetch_array($query)){
- $samecityuid .=$value[uid].",";
- }
- $samecityuid = substr($samecityuid,0,strlen($samecityuid)-1);
复制代码 2) 查找:- //默认动态类型
- if($_SCONFIG['my_status'] && $_SCONFIG['feeddefaultfilter'] && empty($_GET['filter'])) {
- $_GET['filter'] = $_SCONFIG['feeddefaultfilter'];
- }
复制代码 在下面添加:- if(empty($_GET['view'])){
- $_GET['view'] = 'all';
- }
复制代码 3) 查找:- //默认动态类型
- if($_SCONFIG['my_status'] && $_SCONFIG['feeddefaultfilter'] && empty($_GET['filter'])) {
- $_GET['filter'] = $_SCONFIG['feeddefaultfilter'];}
复制代码 将其替换为:- //默认动态类型
- if($_SCONFIG['my_status'] && $_SCONFIG['feeddefaultfilter'] && empty($_GET['filter'])) {
- $_GET['filter'] = $_SCONFIG['feeddefaultfilter'];
- $_GET['view'] = $_SCONFIG['feeddefaultfilter'];
- }
复制代码 }[/code]
4) 查找:- if($_GET['view'] == 'all') {
- $wheresql = "friend='0'";//没有隐私
- $theurl = "space.php?uid=$space[uid]&do=$do&view=all";
- $f_index = '';
- } else {
- if(empty($space['feedfriend'])) {
- $wheresql = "uid='$space[uid]'";
- $theurl = "space.php?uid=$space[uid]&do=$do&view=me";
- $f_index = '';
- $_GET['view'] = 'me';
- } else {
- $wheresql = "uid IN ('0',$space[feedfriend])";
- $theurl = "space.php?uid=$space[uid]&do=$do&view=we";
- $f_index = 'USE INDEX(dateline)';
- $_GET['view'] = 'we';
- $notime = 1;
- }
- }
复制代码 将其替换为:- if($_GET['view'] == 'city'){
- if(!empty($samecityuid)) {
- $wheresql = "uid IN ('0',$samecityuid)";
- $theurl = "space.php?uid=$space[uid]&do=$do";
- $_GET['view'] = 'city';
- }else{
- $wheresql = "uid < 0";
- $theurl = "space.php?uid=$space[uid]&do=$do";
- }
- }else {
- if($_GET['view'] == 'all') {
- $wheresql = "friend='0'";//没有隐私
- $theurl = "space.php?uid=$space[uid]&do=$do";
- $f_index = '';
- } else {
- if(empty($space['feedfriend'])) {
- $wheresql = "uid='$space[uid]'";
- $theurl = "space.php?uid=$space[uid]&do=$do";
- $f_index = '';
- $_GET['view'] = 'me';
- } else {
- $wheresql = "uid IN ('0',$space[feedfriend])";
- $theurl = "space.php?uid=$space[uid]&do=$do";
- $f_index = 'USE INDEX(dateline)';
- $_GET['view'] = 'we';
- $notime = 1;
- }
- }
- }
复制代码 5)查找:- $my_actives = array(in_array($_GET['filter'], array('site','myapp'))?$_GET['filter']:'all' => ' class="active"');
- $actives = array(in_array($_GET['view'], array('me','all'))?$_GET['view']:'we' => ' class="active"');
复制代码 将其替换为:- $my_actives = array(in_array($_GET['filter'], array('site','city','myapp'))?$_GET['filter']:'all' => ' class="active"');
- $actives = array(in_array($_GET['view'], array('me','city','all'))?$_GET['view']:'we' => ' class="active"');
复制代码 2 打开 ./tempalte/default/space_feed.htm
1) 查找:- <li id="viewall" onmouseover="showMenu(this.id)"{$my_actives[all]}><a href="$theurl&filter=all"><span>全部动态 <img src="image/tri.gif" alt="" /></span></a></li>
- <li id="viewsite" onmouseover="showMenu(this.id)"{$my_actives[site]}><a href="$theurl&filter=site"><span>站内 <img src="image/tri.gif" alt="" /></span></a></li>
- <li id="viewmyapp" onmouseover="showMenu(this.id)"{$my_actives[myapp]}><a href="$theurl&filter=myapp"><span>应用 <img src="image/tri.gif" alt="" /></span></a></li>
复制代码 将其替换为:- <li id="viewcity" {$my_actives[city]}><a href="$theurl&view=city&filter=city"><span>同城异性的动态</span></a></li>
- <li id="viewall" onmouseover="showMenu(this.id)"{$my_actives[all]}><a href="$theurl&view=all&filter=all"><span>全部动态 <img src="image/tri.gif" alt="" /></span></a></li>
- <li id="viewsite" onmouseover="showMenu(this.id)"{$my_actives[site]}><a href="$theurl&view=all&filter=site"><span>站内 <img src="image/tri.gif" alt="" /></span></a></li>
- <li id="viewmyapp" onmouseover="showMenu(this.id)"{$my_actives[myapp]}><a href="$theurl&view=all&filter=myapp"><span>应用 <img src="image/tri.gif" alt="" /></span></a></li>
复制代码 2) 查找:- <li$actives[we]><a href="space.php?do=home&view=we"><span>好友的动态</span></a></li>
复制代码 在其上面添加:- <li$actives[city]><a href="space.php?do=home&view=city"><span>同城的动态</span></a></li>
复制代码 3 打开:./admin/tpl/config.htm
查找:- <option value="all">全部动态</option>
复制代码 在其下面添加:- <option value="city"{$feeddefaultfilterselect[city]}>同城异性动态</option>
复制代码 4 登陆uchome后台,点击基本设置--> 站点设置 设置 “首页动态默认显示设置”,可以选择 “同城异性动态”,
注:这个设置的目的是登录进首页后,显示的默认状态
5 进入后台更新缓存,如有问题 QQ:359513995 |