Discuz!官方免费开源建站系统

 找回密码
 立即注册
搜索

请问 如何把 数据调用的样式插入到模板

[复制链接]
小义哥 发表于 2010-12-1 10:34:14 | 显示全部楼层 |阅读模式
44.jpg
请问如何将自己设计的 数据调用样式 里面的 塞到模板里面去啊  
在模板文件中药怎么写呢 请问
回复

使用道具 举报

maru 发表于 2010-12-1 12:11:48 | 显示全部楼层


我也想知道
回复

使用道具 举报

 楼主| 小义哥 发表于 2010-12-1 13:29:15 | 显示全部楼层
  为什么 不像这个里面的动议一样  $threadsortshow[typetemplate]
$threadsortshow[style1]
$threadsortshow[style2]
$threadsortshow[style3]
$threadsortshow[style4]
$threadsortshow[style5]




回复

使用道具 举报

 楼主| 小义哥 发表于 2010-12-1 13:31:54 | 显示全部楼层
  1. function showsorttemplate($sortid, $sortoptionarray, $templatearray, $threadlist, $threadids = array(), $arealist = array(), $modurl) {
  2.         global $_G;

  3.         $searchtitle = $searchvalue = $searchunit = $stemplate = $searchtids = $sortlistarray = $skipaids = $sortdata = $_G['optionvaluelist'] = array();

  4.         $addthreadid = !empty($threadids) ? "AND tid IN (".dimplode($threadids).")" : '';
  5.         $query = DB::query("SELECT sortid, tid, optionid, value, expiration FROM ".DB::table('category_sortoptionvar')." WHERE sortid='$sortid' $addthreadid");
  6.         while($sortthread = DB::fetch($query)) {
  7.                 $optionid = $sortthread['optionid'];
  8.                 $tid = $sortthread['tid'];
  9.                 $arrayoption = $sortoptionarray[$optionid];
  10.                 if($sortoptionarray[$optionid]['subjectshow']) {
  11.                         $_G['optionvaluelist'][$tid][$arrayoption['identifier']]['title'] = $arrayoption['title'];
  12.                         $_G['optionvaluelist'][$tid][$arrayoption['identifier']]['unit'] = $arrayoption['unit'];
  13.                         if(in_array($arrayoption['type'], array('radio', 'checkbox', 'select'))) {
  14.                                 if($arrayoption['type'] == 'checkbox') {
  15.                                         foreach(explode("\t", $sortthread['value']) as $choiceid) {
  16.                                                 $sortthreadlist[$tid][$arrayoption['title']] .= $arrayoption['choices'][$choiceid].' ';
  17.                                                 $_G['optionvaluelist'][$tid][$arrayoption['identifier']]['value'] .= $arrayoption['choices'][$choiceid].' ';
  18.                                         }
  19.                                 } else {
  20.                                         $sortthreadlist[$tid][$arrayoption['title']] = $_G['optionvaluelist'][$tid][$arrayoption['identifier']]['value'] = $arrayoption['choices'][$sortthread['value']];
  21.                                 }
  22.                         } else {
  23.                                 if($sortthread['value']) {
  24.                                         $sortthreadlist[$tid][$arrayoption['title']] = $_G['optionvaluelist'][$tid][$arrayoption['identifier']]['value'] = $sortthread['value'];
  25.                                 } else {
  26.                                         $sortthreadlist[$tid][$arrayoption['title']] = $_G['optionvaluelist'][$tid][$arrayoption['identifier']]['value'] = $arrayoption['defaultvalue'];
  27.                                         $_G['optionvaluelist'][$tid][$arrayoption['identifier']]['unit'] = '';
  28.                                 }
  29.                         }
  30.                         $sortthreadlist[$tid]['sortid'] = $sortid;
  31.                 }
  32.         }

  33.         if($templatearray && $sortthreadlist) {
  34.                 foreach($threadlist as $thread) {
  35.                         $sortdata[$thread['tid']]['recommend'] = $thread['recommend'] ? '<span class="rec">'.lang('category/template', 'house_stick').'</span>' : '';
  36.                         $sortdata[$thread['tid']]['displayorder'] = $thread['displayorder'] ? '<span class="pin">'.lang('category/template', 'totop').'</span>' : '';
  37.                         $sortdata[$thread['tid']]['attach'] = $thread['attachnum'] > 1 ? '<span class="pic">'.lang('category/template', 'house_imgs').'</span>' : '';
  38.                         $sortdata[$thread['tid']]['subjecturl'] = '<a href="'.$modurl.'?mod=view&tid='.$thread['tid'].'" '.$thread['highlight'].'>'.$thread['subject'].'</a>';
  39.                         $sortdata[$thread['tid']]['subject'] = $thread['subject'];
  40.                         $sortdata[$thread['tid']]['author'] = $thread['authorid'] ? '<a href="'.$modurl.'?mod=broker&action=my&uid='.$thread['authorid'].'" target="_blank">'.$thread['author'].'</a>' : $thread['author'];
  41.                         $sortdata[$thread['tid']]['image'] = $thread['attachid'] ? '<img src="'.getcateimg($thread['attachid']).'">' : '<img src="template/default/category/images/noupload.gif">';
  42.                         $sortdata[$thread['tid']]['dateline'] = $thread['dateline'] ? dgmdate($thread['dateline'], 'u') : '';
  43.                         $sortdata[$thread['tid']]['city'] = $thread['city'] ? $arealist['city'][$thread['city']] : '';
  44.                         $sortdata[$thread['tid']]['district'] = $thread['district'] ? $arealist['district'][$thread['city']][$thread['district']] : '';
  45.                         $sortdata[$thread['tid']]['street'] = $thread['street'] ? $arealist['street'][$thread['district']][$thread['street']] : '';
  46.                         $sortdata[$thread['tid']]['expiration'] = $thread['expiration'] && $thread['expiration'] < TIMESTAMP ? '<span class="over">'.lang('category/template', 'house_overdue').'</span>' : '';
  47.                 }

  48.                 foreach($sortoptionarray as $sortid => $option) {
  49.                         if($option['subjectshow']) {
  50.                                 $searchtitle[] = '/{('.$option['identifier'].')}/e';
  51.                                 $searchvalue[] = '/\[('.$option['identifier'].')value\]/e';
  52.                                 $searchunit[] = '/\[('.$option['identifier'].')unit\]/e';
  53.                         }
  54.                 }

  55.                 foreach($sortthreadlist as $tid => $option) {
  56.                         $stemplate[$tid] = preg_replace(array("/\{city\}/i", "/\{district\}/i", "/\{street\}/i", "/\{image\}/i", "/\{attach\}/i", "/\{recommend\}/i", "/\{displayorder\}/i", "/\{dateline\}/i", "/\{author\}/i", "/\{subjecturl\}/i", "/\{subject\}/i", "/\{expiration\}/i", "/\[url\](.+?)\[\/url\]/i"),
  57.                                                         array(
  58.                                                                 $sortdata[$tid]['city'],
  59.                                                                 $sortdata[$tid]['district'],
  60.                                                                 $sortdata[$tid]['street'],
  61.                                                                 $sortdata[$tid]['image'],
  62.                                                                 $sortdata[$tid]['attach'],
  63.                                                                 $sortdata[$tid]['recommend'],
  64.                                                                 $sortdata[$tid]['displayorder'],
  65.                                                                 $sortdata[$tid]['dateline'],
  66.                                                                 $sortdata[$tid]['author'],
  67.                                                                 $sortdata[$tid]['subjecturl'],
  68.                                                                 $sortdata[$tid]['subject'],
  69.                                                                 $sortdata[$tid]['expiration'],
  70.                                                                 "<a href="$modurl?mod=view&tid=$tid">\\1</a>"
  71.                                                         ), stripslashes($templatearray));
  72.                         $stemplate[$tid] = preg_replace($searchtitle, "showlistoption('\\1', 'title', '$tid')", $stemplate[$tid]);
  73.                         $stemplate[$tid] = preg_replace($searchvalue, "showlistoption('\\1', 'value', '$tid')", $stemplate[$tid]);
  74.                         $stemplate[$tid] = preg_replace($searchunit, "showlistoption('\\1', 'unit', '$tid')", $stemplate[$tid]);
  75.                 }
  76.         }

  77.         $sortlistarray['template'] = $stemplate;

  78.         return $sortlistarray;
  79. }

  80. function showlistoption($var, $type, $tid) {
  81.         global $_G;
  82.         if($_G['optionvaluelist'][$tid][$var][$type]) {
  83.                 return $_G['optionvaluelist'][$tid][$var][$type];
  84.         } else {
  85.                 return '';
  86.         }
  87. }

  88. function showvisitlistoption($var, $type, $tid) {
  89.         global $_G;
  90.         if($_G['optionvisitlist'][$tid][$var][$type]) {
  91.                 return $_G['optionvisitlist'][$tid][$var][$type];
  92.         } else {
  93.                 return '';
  94.         }
  95. }

  96. function neighborhood($tid, $sortid, $cityid, $districtid, $streetid, $sortoptionarray, $template, $modurl) {
  97.         global $_G;

  98.         $optionlist = $data = $datalist = $searchvalue = $searchunit = $stemplate = $imagelist = $_G['optionvaluelist'] = array();
  99.         $valuefield = '';
  100.         foreach($sortoptionarray as $optionid => $option) {
  101.                 if($option['visitedshow']) {
  102.                         $valuefield .= ','.$option['identifier'];
  103.                         $optionlist[$option['identifier']]['unit'] = $option['unit'];
  104.                         $searchvalue[] = '/\[('.$option['identifier'].')value\]/e';
  105.                         $searchunit[] = '/\[('.$option['identifier'].')unit\]/e';
  106.                         $optionlist['attachid'] = '';
  107.                 }
  108.         }

  109.         $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");
  110.         while($thread = DB::fetch($query)) {
  111.                 foreach($optionlist as $identifier => $option) {
  112.                         $_G['optionvaluelist'][$thread['tid']][$identifier]['unit'] = $option['unit'];
  113.                         $_G['optionvaluelist'][$thread['tid']][$identifier]['value'] = $thread[$identifier];
  114.                         if($identifier == 'attachid') {
  115.                                 $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">';
  116.                         } else {
  117.                                 $data[$thread['tid']] = $thread['tid'];
  118.                         }
  119.                 }
  120.         }

  121.         foreach($data as $tid => $option) {
  122.                 $datalist[$tid] = preg_replace(array("/\{image\}/i", "/\[url\](.+?)\[\/url\]/i"),
  123.                                                 array($imagelist[$tid], "<a href="$modurl?mod=view&tid=$tid">\\1</a>"
  124.                                                 ), stripslashes($template));
  125.                 $datalist[$tid] = preg_replace($searchvalue, "showlistoption('\\1', 'value', '$tid')", $datalist[$tid]);
  126.                 $datalist[$tid] = preg_replace($searchunit, "showlistoption('\\1', 'unit', '$tid')", $datalist[$tid]);
  127.         }

  128.         return $datalist;
  129. }

  130. function threadsortshow($tid, $sortoptionarray, $templatearray, $authorid, $groupid) {
  131.         global $_G;

  132.         $optiondata = $searchtitle = $searchvalue = $searchunit = $memberinfofield = $_G['category_option'] = array();
  133.         $intermediary = '';

  134.         if($sortoptionarray) {
  135.                 $query = DB::query("SELECT optionid, value, expiration FROM ".DB::table('category_sortoptionvar')." WHERE tid='$tid'");
  136.                 while($option = DB::fetch($query)) {
  137.                         $optiondata[$option['optionid']]['value'] = $option['value'];
  138.                         $optiondata[$option['optionid']]['expiration'] = $option['expiration'] && $option['expiration'] <= TIMESTAMP ? 1 : 0;
  139.                         $sortdataexpiration = $option['expiration'];
  140.                 }

  141.                 foreach($sortoptionarray as $optionid => $option) {
  142.                         $_G['category_option'][$option['identifier']]['title'] = $option['title'];
  143.                         $_G['category_option'][$option['identifier']]['unit'] = $option['unit'];
  144.                         $_G['category_option'][$option['identifier']]['type'] = $option['type'];

  145.                         if(($option['expiration'] && !$optiondata[$optionid]['expiration']) || empty($option['expiration'])) {
  146.                                 if(($option['protect']['usergroup'] && strstr("\t".$option['protect']['usergroup']."\t", "\t$_G[groupid]\t")) || empty($option['protect']['usergroup']) || ($authorid == $_G['uid'] && !empty($_G['uid']))) {
  147.                                         if($option['type'] == 'checkbox') {
  148.                                                 $_G['category_option'][$option['identifier']]['value'] = '';
  149.                                                 foreach(explode("\t", $optiondata[$optionid]['value']) as $choiceid) {
  150.                                                         $_G['category_option'][$option['identifier']]['value'] .= $option['choices'][$choiceid].'&nbsp;';
  151.                                                 }
  152.                                         } elseif(in_array($option['type'], array('radio', 'select', 'intermediary'))) {
  153.                                                 if($option['type'] == 'intermediary' && $groupid != 1) {
  154.                                                         $_G['category_option'][$option['identifier']]['value'] = $_G['category_usergrouplist'][$groupid]['title'];
  155.                                                 } else {
  156.                                                         $_G['category_option'][$option['identifier']]['value'] = $option['choices'][$optiondata[$optionid]['value']];
  157.                                                 }
  158.                                         } elseif($option['type'] == 'url') {
  159.                                                 $_G['category_option'][$option['identifier']]['value'] = $optiondata[$optionid]['value'] ? "<a href="".$optiondata[$optionid]['value']."" target="_blank">".$optiondata[$optionid]."</a>" : '';
  160.                                         } elseif($option['type'] == 'textarea') {
  161.                                                 $_G['category_option'][$option['identifier']]['value'] = $optiondata[$optionid]['value'] ? nl2br($optiondata[$optionid]['value']) : '';
  162.                                         } elseif($option['type'] == 'phone') {
  163.                                                 if($option['numbercheck'] && $groupid == 1 && $optiondata[$optionid]['value']) {
  164.                                                         $intermediary = checkphonenum($optiondata[$optionid]['value'], 'check') >= 5 ? '<div class="intermediary">'.lang('category/template', 'house_friend_tips').'</div>' : '';
  165.                                                 }
  166.                                                 $_G['category_option'][$option['identifier']]['value'] = $optiondata[$optionid]['value'] ? $optiondata[$optionid]['value'] : $option['defaultvalue'];
  167.                                         } else {
  168.                                                 $_G['category_option'][$option['identifier']]['value'] = $optiondata[$optionid]['value'];
  169.                                         }

  170.                                         if($option['protect']['status'] && $optiondata[$optionid]['value'] && $_G['uid'] != $authorid) {
  171.                                                 if($option['protect']['mode'] == 1) {
  172.                                                         $_G['category_option'][$option['identifier']]['value'] = '<image src="category.php?mod=misc&action=protectsort&sortvalue='.$optiondata[$optionid]['value'].'">';
  173.                                                 } elseif($option['protect']['mode'] == 2) {
  174.                                                         $_G['category_option'][$option['identifier']]['value'] = '<span id="sortmessage_'.$option['identifier'].'"><a href="javascript:;" onclick="ajaxget(\'category.php?mod=misc&action=protectsort&tid='.$tid.'&optionid='.$optionid.'\', \'sortmessage_'.$option['identifier'].'\')">'.lang('category/template', 'house_click').'</a></span>';
  175.                                                 } elseif($option['protect']['mode'] == 4) {
  176.                                                         $exist = DB::result_first('SELECT tid FROM '.DB::table('category_payoption')." WHERE uid='$_G[uid]' AND tid='$tid' AND optionid='$optionid'");
  177.                                                         if(empty($exist)) {
  178.                                                                 $creditsid = $option['protect']['credits']['title'];
  179.                                                                 $creditsname = $_G['setting']['extcredits'][$creditsid]['title'];
  180.                                                                 $price = $option['protect']['credits']['price'];
  181.                                                                 $_G['category_option'][$option['identifier']]['value'] = '<a href="###" onclick="showWindow(\'buyoption\', \'category.php?mod=misc&action=buyoption&optionid='.$optionid.'&tid='.$tid.'&handlekey=forumthread\');">
  182.                                                                 '.lang('category/template', 'house_buy_view').$price.$creditsname.lang('category/template', 'house_buy_view').'</a>';
  183.                                                         } else {
  184.                                                                 $_G['category_option'][$option['identifier']]['value'] = $optiondata[$optionid]['value'];
  185.                                                         }
  186.                                                 }
  187.                                         }

  188.                                         if(empty($_G['category_option'][$option['identifier']]['value'])) {
  189.                                                 $_G['category_option'][$option['identifier']]['value'] = $option['defaultvalue'];
  190.                                                 $_G['category_option'][$option['identifier']]['unit'] = '';
  191.                                         }
  192.                                 } else {
  193.                                         $_G['category_option'][$option['identifier']]['value'] = lang('category/template', 'house_nopur_view');
  194.                                 }
  195.                         } else {
  196.                                 $_G['category_option'][$option['identifier']]['value'] = lang('category/template', 'house_view_expired');
  197.                         }
  198.                 }

  199.                 $typetemplate = '';
  200.                 if($templatearray) {
  201.                         foreach($sortoptionarray as $option) {
  202.                                 $searchtitle[] = '/{('.$option['identifier'].')}/e';
  203.                                 $searchvalue[] = '/\[('.$option['identifier'].')value\]/e';
  204.                                 $searchunit[] = '/\[('.$option['identifier'].')unit\]/e';
  205.                         }

  206.                         $threadexpiration = $sortdataexpiration ? dgmdate($sortdataexpiration) : lang('category/template', 'house_perpetual');
  207.                         $typetemplate = preg_replace(array("/\{expiration\}/i", "/\{intermediary\}/i"), array($threadexpiration, $intermediary), stripslashes($templatearray));
  208.                         $typetemplate = preg_replace($searchtitle, "showcateoption('\\1', 'title')", $typetemplate);
  209.                         $typetemplate = preg_replace($searchvalue, "showcateoption('\\1', 'value')", $typetemplate);
  210.                         $typetemplate = preg_replace($searchunit, "showcateoption('\\1', 'unit')", $typetemplate);
  211.                 }
  212.        
  213.        
  214.        
  215.         }



  216.         $threadsortshow['optionlist'] = $_G['category_option'];
  217.         $threadsortshow['typetemplate'] = $typetemplate;
  218.         $threadsortshow['style1'] = $style1;
  219.         $threadsortshow['expiration'] = dgmdate($sortdataexpiration, 'd');

  220.         return $threadsortshow;
  221. }
复制代码
为什么不吧这个函数优化下呢 加上一个sytle 的样式 自定义这样我们可以随意的设计模板格式啊老大  你的那个默认的东西 太多了 我想给他分开
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2025-8-23 17:58 , Processed in 0.099432 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

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