找回密码
 注册加入

扫一扫,极速登录

QQ登录

只需一步,快速开始

搜索
查看: 5032|回复: 3

function_category.php(1.5.2) 改进

[复制链接]
发表于 2011-8-18 23:53:49 | 显示全部楼层 |阅读模式
模板选择choices字段时显示不正常,对visitedshow(),neighborhood()进行改进可以解决问题:

  1. function visitedshow($tids, $sortoptionarray, $sortid, $template, $modurl) {
  2.         global $_G;

  3.         $optionlist = $data = $datalist = $searchvalue = $searchunit = $stemplate = $_G['optionvisitlist'] = array();
  4.         $valuefield = '';

  5.         foreach($sortoptionarray as $optionid => $option) {

  6.                 if($option['visitedshow']) {
  7.                         $valuefield .= ','.$option['identifier'];
  8.                         $optionlist[$option['identifier']]['unit'] = $option['unit'];
  9.                         $optionlist[$option['identifier']]['type'] = $option['type'];   //dima:新增
  10.                         $optionlist[$option['identifier']]['choices'] = $option['choices']; //dima:新增
  11.                         $searchvalue[] = '/\[('.$option['identifier'].')value\]/e';
  12.                         $searchunit[] = '/\[('.$option['identifier'].')unit\]/e';
  13.                 }
  14.         }

  15.         if($tids && is_array($tids)) {
  16.                 $query = DB::query("SELECT tid $valuefield FROM ".DB::table('category_sortvalue')."$sortid  WHERE tid IN (".dimplode($tids).")");
  17.                 while($thread = DB::fetch($query)) {
  18.                         foreach($optionlist as $identifier => $option) {
  19.                                 $_G['optionvisitlist'][$thread['tid']][$identifier]['unit'] = $option['unit'];

  20.                                 if(in_array($option['type'], array('radio', 'checkbox', 'select'))){ //dima:这里增加了一个if ... else ... 判断
  21.                                         $_G['optionvisitlist'][$thread['tid']][$identifier]['value'] = '';
  22.                                         foreach(explode("\t", $thread[$identifier]) as $choiceid) {
  23.                                         $_G['optionvisitlist'][$thread['tid']][$identifier]['value'] .= $option['choices'][$choiceid].' ';
  24.                                         }
  25.                                 }else{
  26.                                 $_G['optionvisitlist'][$thread['tid']][$identifier]['value'] = $thread[$identifier]; //dima:原来只有这一行
  27.                                 }

  28.                                 $data[$thread['tid']] = $thread['tid'];
  29.                         }
  30.                 }

  31.                 foreach($data as $tid => $option) {
  32.                         $stemplate[$tid] = preg_replace(array("/\[url\](.+?)\[\/url\]/i"),
  33.                                                         array("<a href="$modurl?mod=view&tid=$tid">\\1</a>"
  34.                                                         ), stripslashes($template));
  35.                         $stemplate[$tid] = preg_replace($searchvalue, "showvisitlistoption('\\1', 'value', '$tid')", $stemplate[$tid]);
  36.                         $stemplate[$tid] = preg_replace($searchunit, "showvisitlistoption('\\1', 'unit', '$tid')", $stemplate[$tid]);
  37.                 }

  38.                 if(!empty($data)) {
  39.                         foreach(array_reverse($tids) as $tid) {
  40.                                 if($data[$tid]) {
  41.                                         $datalist[$tid] = $stemplate[$tid];
  42.                                 }
  43.                         }
  44.                 }
  45.         }

  46.         return $datalist;
  47. }
复制代码
  1. function neighborhood($tid, $sortid, $cityid, $districtid, $streetid, $sortoptionarray, $template, $modurl) {
  2.         global $_G;

  3.         $optionlist = $data = $datalist = $searchvalue = $searchunit = $stemplate = $imagelist = $_G['optionvaluelist'] = array();
  4.         $valuefield = '';
  5.         foreach($sortoptionarray as $optionid => $option) {
  6.                 if($option['visitedshow']) {
  7.                         $valuefield .= ','.$option['identifier'];
  8.                         $optionlist[$option['identifier']]['unit'] = $option['unit'];
  9.                         $optionlist[$option['identifier']]['type'] = $option['type'];  //dima:新增
  10.                         $optionlist[$option['identifier']]['choices'] = $option['choices'];  //dima:新增
  11.                         $searchvalue[] = '/\[('.$option['identifier'].')value\]/e';
  12.                         $searchunit[] = '/\[('.$option['identifier'].')unit\]/e';
  13.                         $optionlist['attachid'] = '';
  14.                 }
  15.         }

  16.         $query = DB::query("SELECT tid, attachid $valuefield FROM ".DB::table('category_sortvalue')."$sortid WHERE city='$cityid' AND district='$districtid' AND street='$streetid' AND tid!='$tid' ORDER BY dateline DESC LIMIT 5");
  17.         while($thread = DB::fetch($query)) {
  18.                 foreach($optionlist as $identifier => $option) {
  19.                         $_G['optionvaluelist'][$thread['tid']][$identifier]['unit'] = $option['unit'];

  20.                                 if(in_array($option['type'], array('radio', 'checkbox', 'select'))){ //dima:这里增加了一个if ... else ... 判断
  21.                                         $_G['optionvaluelist'][$thread['tid']][$identifier]['value'] = '';
  22.                                         foreach(explode("\t", $thread[$identifier]) as $choiceid) {
  23.                                         $_G['optionvaluelist'][$thread['tid']][$identifier]['value'] .= $option['choices'][$choiceid].' ';
  24.                                         }
  25.                                 }else{
  26.                         $_G['optionvaluelist'][$thread['tid']][$identifier]['value'] = $thread[$identifier]; //dima:原来只有这一行
  27.                                 }

  28.                         if($identifier == 'attachid') {
  29.                                 $imagelist[$thread['tid']] = $thread['attachid'] ? '<img src="'.getcateimg($thread['attachid'], 0, 48, 48).'">' : '<img src="template/default/category/images/noupload.gif" width="48" height="48">';
  30.                         } else {
  31.                                 $data[$thread['tid']] = $thread['tid'];
  32.                         }
  33.                 }
  34.         }
复制代码



修改修的文件:
function_category.rar (10.42 KB, 下载次数: 1)



评分

参与人数 1金币 +20 收起 理由
管理员 + 20 很给力!

查看全部评分

 楼主| 发表于 2011-8-18 23:58:01 | 显示全部楼层
改进后如图
wokanguodefangyuan.JPG
回复 支持 反对

使用道具 举报

发表于 2011-8-19 00:10:20 | 显示全部楼层
欢迎大家都参与研究,一起改善程序
回复 支持 反对

使用道具 举报

发表于 2012-3-29 11:07:54 | 显示全部楼层
欢迎大家都参与研究,一起改善程序
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册加入  

本版积分规则

Archiver|手机版|小黑屋|Discuz!扩展中心 ( 浙ICP备14042422号-1 )|网站地图QQ机器人

GMT+8, 2024-5-6 05:50 , Processed in 0.299333 second(s), 17 queries , Gzip On, Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表