本帖最后由 suxiaojack 于 2011-1-7 20:24 编辑
经过实际书写一些复杂的代码,修正两处BUG,解决HTML自定义错误时,DIY失效问题。
- function sxx_block_display_batch($bid)
- {
- $mixed_code=block_fetch_content($bid);
- $sql="select blockclass from ".DB::table("common_block")." where bid=$bid";
- $query=DB::query($sql);
- if($row=DB::fetch($query))
- {
- $blockclass=$row['blockclass'];
- }else
- {
- echo ("no block id:$bid,Please check your database.");
- echo ($mixed_code);
- return;
- };
- if(
- $blockclass==="html_html" && ($_GET['diy']!="yes") #支持DIY当语句错误时可以修改
- )
- {
- $mixed_code=preg_replace("/\[html\]|\[\/html\]/i","",$mixed_code);
- $mixed_code=preg_replace("/\'/","\\\'",$mixed_code);#还是自动转换好点!!!
- $phpmark1="/?"; #可以采取两种书写方式 /? phpcode ?/ 或者 [php] phpcode [/php]
- $phpmark1end="?/";
- $phpmark2="[php]";
- $phpmark2end="[/php]";
- $phpmark= (stripos($mixed_code,$phpmark1,0) ? $phpmark1:$phpmark2);
- $phpmarkend = ( stripos($mixed_code,$phpmark1,0) ? $phpmark1end:$phpmark2end ) ;
- $phpmarkslen= ( stripos($mixed_code,$phpmark1,0) ? 2:5 );
- $phpmarkelen= ( stripos($mixed_code,$phpmark1,0) ? 2:6 );
- $spos=0;
- $epos=0;
- $mixed_cool="";
- do
- {
- $epos=stripos($mixed_code,$phpmark,$spos);
- if($epos!==false)
- {
- $html_code=substr($mixed_code,$spos,$epos-$spos);
- $mixed_cool.="echo('$html_code');";
- $spos=$epos+$phpmarkslen;
- $epos=stripos($mixed_code,$phpmarkend,$spos);
- if($epos!==false)
- {
- $php_code=substr($mixed_code,$spos,$epos-$spos);
- $spos=$epos+$phpmarkelen;
- $mixed_cool.=$php_code;
- }else
- {
- echo("error!no php_end_mark.");
- echo($mixed_code);
- return;
- };
- }else
- {
- $html_code=substr($mixed_code,$spos);
- $mixed_cool.="echo('$html_code');";
- };
- }while($epos!==false);
- eval($mixed_cool);
- }
- else if($_GET['diy']=="yes"&&$blockclass==="html_html")
- {
- echo("自"."定"."义HT"."ML by "."su"."xi"."ao"."ja"."ck fixed");
- echo block_fetch_content($bid,false,false,true);#这里修改了!!!
- }
- else
- {
- echo($mixed_code);
- };
- }
- function block_fetch_content($bid, $isjscall=false, $forceupdate=false,$debug_block=false) {
- global $_G;
- static $allowmem = null;
- if($allowmem === null) {
- $allowmem = getglobal('setting/memory/diyblockoutput/enable') && memory('check');
- }
- $str = '';
- $block = empty($_G['block'][$bid])?array():$_G['block'][$bid];
- if(!$block) {
- return;
- }
- if($forceupdate) {
- block_updatecache($bid, true);
- $block = $_G['block'][$bid];
- } elseif($block['cachetime'] > 0 && $_G['timestamp'] - $block['dateline'] > $block['cachetime']) {
- if($isjscall || $block['punctualupdate']) {
- block_updatecache($bid, true);
- $block = $_G['block'][$bid];
- } elseif(empty($_G['blockupdate']) || $block['dateline'] < $_G['blockupdate']['dateline']) {
- $_G['blockupdate'] = array('bid'=>$bid, 'dateline'=>$block['dateline']);
- }
- }
- if($allowmem && empty($block['hidedisplay']) && empty($block['nocache'])) {
- $str = memory('get', 'blockcache_'.$bid.'_'.($isjscall ? 'js' : 'htm'));
- if($str !== null) {
- return $str;
- }
- }
- if($isjscall) {
- if($block['summary']) $str .= $block['summary'];
- $str .= block_template($bid);
- } else {
- $classname = !empty($block['classname']) ? $block['classname'].' ' : '';
- $str .= "<div id="portal_block_$bid" class="{$classname}block move-span">";
- if($block['title']) $str .= $block['title'];
- $str .= '<div id="portal_block_'.$bid.'_content" class="content">';
- if($block['summary']) {
- $block['summary'] = stripslashes($block['summary']);
- #suxiaojack fixed 修正DIY失效问题!!!
- if($debug_block)
- {
- $debug_bstr=$block['summary'];
- $debug_bstr=preg_replace("/\</","<",$debug_bstr);
- $debug_bstr=preg_replace("/\>/",">",$debug_bstr);
- $str .= "<div class="portal_block_summary">$debug_bstr</div>";#!!!
- }
- else
- {
- $str .= "<div class="portal_block_summary">$block[summary]</div>";
- };
- }
- $str .= block_template($bid);
- $str .= '</div>';
- $str .= "</div>";
- }
- if($allowmem && empty($block['hidedisplay']) && empty($block['nocache'])) {
- memory('set', 'blockcache_'.$bid.'_'.($isjscall ? 'js' : 'htm'), $str, getglobal('setting/memory/diyblockoutput/ttl'));
- }
- return !empty($block['hidedisplay']) ? '' : $str;
- }
复制代码 DIY中如果有错误,经常会无法再DIY所以,最好是DIY时只有框架,内部自定义的内容都是文字输出。
测试代码:
使用anythingslider幻灯的效果。自定义了ccs显示400x300的幻灯。
- <LINK rel="stylesheet" type="text/css" href="/xlfw/sx/slider400x300.css" media="screen">
- <SCRIPT type="text/javascript" src="/xlfw/sx/jquery.min.js"></SCRIPT>
- <SCRIPT type="text/javascript" src="/xlfw/sx/jquery.easing.1.2.js"></SCRIPT>
- <SCRIPT type="text/javascript" charset="utf-8" src="/xlfw/sx/jquery.anythingslider.js"></SCRIPT>
- <SCRIPT type="text/javascript">
- function formatText(index, panel) {
- return index + "";
- }
- $(function () {
- $('.anythingSlider').anythingSlider({
- easing: "easeInOutExpo", // 定义插件
- autoPlay: true, // 这将关闭整个FUNCTIONALY,如果它不只是开始运行与否。
- delay: 3000, // 自动播放模式下,幻灯片轮换时间
- startStopped: false, //如果是自动播放,这可以迫使它停止启动
- animationTime: 600, // 幻灯片的过渡时间
- hashTags: true, // 是否跟换hashtag是链接地址
- buildNavigation: true, // 如果是真,建立和锚链接列表链接到每张幻灯片
- pauseOnHover: true, // 如果是真,并启用自动播放,鼠标经过暂停播放
- startText: "自动", // Start text
- stopText: "暂停", // Stop text
- navigationFormatter: formatText // 在这个文件的顶部使用详情(高级使用)
- });
- $("#slide-jump").click(function(){
- $('.anythingSlider').anythingSlider();
- });
- });
- </script>
- <DIV class="anythingSlider">
- <DIV class="wrapper">
- <UL>
- /?
- \$sql="select * from ".DB::table("portal_article_title")." where thumb=1 order by dateline desc limit 0,8";
- \$query=DB::query(\$sql);
- while(\$row=DB::fetch(\$query))
- {
- ?/<LI><div><center><a href="/xlfw/portal.php?mod=view&aid=/?echo("\$row[aid]");?/"><img alt="/?echo("\$row[title]");?/" height=300 src=http:///?echo("\$_SERVER[SERVER_NAME]");?//xlfw/data/attachment/portal//?echo("\$row[pic]");?/></a></center></div></LI>
- /?};?/
- </UL>
- </DIV></DIV>
复制代码
上述代码调试修正后工作正常。注意\的写法,一个\这个要这样表示\$slash="\\\\";用\$slash吧,有点恐怖哈哈。 |