php中if的一个小问题
时间:2011-11-28
来源:互联网
PHP code
定义了$open=1;为什么总是执行rewriteurl中的else?
<?php /* Discuz X2 modified By Marshal,2011-07-08 本插件支持X2版伪静态切换,并支持不开启伪静态 www.modchina.com Marshal版权所有 require './source/class/class_core.php'; $discuz=& discuz_core::instance(); $discuz->init(); */ if(!defined('IN_DISCUZ')) { exit('Access Denied'); } /* 门户专题页 topic-{name}.html 门户文章页 article-{id}-{page}.html 论坛主题列表页 forum-{fid}-{page}.html 论坛主题内容页 thread-{tid}-{page}-{prevpage}.html 群组主题列表页 group-{fid}-{page}.html 用户个人主页 space-{user}-{value}.html 用户日志内容页 blog-{uid}-{blogid}.html 论坛 Archiver 页 {action}-{value}.html */ //只提取定义的数量条记录,设为0表示全部提取 $open=1; $froum=1000; //生产多少论坛主题列表页 $article=1000; //生成多少门户文章页 $thread=20000; //生成多少论坛帖子 $blog=1000; //生成多少用户日志内容页 $space=1000; //生成多少用户个人主页 $cat=""; //生成在什么目录,例如 data/ 结尾需加"/",留空则生成在根目录 function rewriteurl($url,$id,$ex="") { global $open; if ( $open == 1 )//伪静态 { if($url=="portal_article") {$mod="article-".$id."-1.html";} elseif($url=="forum_forumdisplay") {$mod="forum-".$id."-1.html";} elseif($url=="forum_viewthread") {$mod="thread-".$id."-1-1.html";} elseif($url=="home_blog") {$mod="blog-".$id."-".$ex.".html";} elseif($url=="common_member") {$mod="space-".$id."-1.html";} } else { if($url=="portal_article"){$mod="portal.php?mod=view&aid=".$id."";} elseif($url=="forum_forumdisplay"){$mod="forum.php?mod=forumdisplay&fid=".$id."";} elseif($url=="forum_viewthread"){$mod="forum.php?mod=viewthread&tid=".$id."";} elseif($url=="home_blog"){$mod="home.php?mod=space&uid=".$id."&do=blog&id=".$ex."";} elseif($url=="common_member") {$mod="home.php?mod=space&uid=".$id."";} } return $mod; } function Domain($root)//portal,forum,home,default { global $_G,$discuz; $marshal=$_G['setting']['domain']['app']; if(!isset($root) || !isset($marshal) || empty($marshal['default'])) {$domain=$_G['siteurl'];} elseif(!empty($marshal['default']) && empty($marshal[$root])) {$domain='http://'.$marshal['default'].'/';} else {$domain='http://'.$marshal[$root].'/';} return $domain; } class sitemap_xml { var $xml=array(''); var $site; var $index=0; var $sitemap_file='sitemap'; var $size; function sitemap_xml($sitemap_file='sitemap',$site='baidu') { $this->site=$site; $this->sitemap_file=$sitemap_file; $this->size=($site=='baidu')?1024*10240:1024*10240; } //替换loc特殊字符 function replacestr($str) { $str=str_replace("&","&",$str); $str=str_replace("'","'",$str); $str=str_replace("\"",""",$str); $str=str_replace(">",">",$str); $str=str_replace("<","<",$str); return $str; } /* * @param string $loc 页面永久链接地址 * @param date $lastmod 页面最后修改时间,ISO 8601中指定的时间格式进行描述 * @param string $changefreq 页面内容更新频率。这里可以用来描述的单词共这几个:"always", "hourly", "daily", "weekly", "monthly", "yearly" * @param string $priority 是用来指定此链接相对于其他链接的优先权比值。此值定于0.0 - 1.0之间 */ function add_url($loc,$lastmod,$changefreq,$priority) { static $size=0; $size=($size==0)?$this->size:$size; $str="<url><loc>".$this->replacestr($loc)."</loc><lastmod>$lastmod</lastmod><changefreq>$changefreq</changefreq><priority>$priority</priority></url>"; $this->xml[$this->index].=$str; $size-=strlen($str); if($size<10240) //剩余长度小于10240就重新创建一个sitemap { $this->index++; $size=$this->size; $this->xml[$this->index]=''; } } function write() { for($i=0;$i<=$this->index;$i++) { @file_put_contents($this->sitemap_file.'_'.$i.'.xml','<?xml version="1.0" encoding="UTF-8"?> <urlset'.($this->site=='google'?' xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"':'').'>'.$this->xml[$i].'</urlset>'); } $this->write_index(); } function write_index() { global $_G; $size=$this->size; $text='<?xml version="1.0" encoding="UTF-8"?>'; $text.=($this->site=='google')?'<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">':'<sitemapindex>'; for($i=0;$i<=$this->index && $size>10240;$i++) { $str='<sitemap><loc>'.Domain('portal').$this->sitemap_file.'_'.$i.'.xml</loc><lastmod>'.date('c').'</lastmod></sitemap>'; $text.=$str; $size-=strlen($str); } $text.='</sitemapindex>'; return file_put_contents($this->sitemap_file.'.xml',$text); } } $s=array('baidu','google'); foreach($s as $se) $ct[]=new sitemap_xml($cat.'sitemap_'.$se,$se); //1.article $query=DB::query('select aid,dateline from '.DB::TABLE('portal_article_title').' where status>=0'.($article==0 ? '':' limit 0,'.$article.' ')); while($row=DB::fetch($query)) { $row['url']=rewriteurl("portal_article",$row['aid']); foreach($ct as $key=> $item) { $ct[$key]->add_url(Domain('portal').$row['url'],date('c',$row['dateline']),'daily','0.8'); } } //2.froum $query=DB::query("select fid,type,status from ".DB::table('forum_forum')." where status='1' and type='forum' order by fid "); while($row=DB::fetch($query)) { $row['url']=rewriteurl("forum_forumdisplay",$row['fid']); foreach($ct as $key=>$item) { $ct[$key]->add_url(Domain('forum').$row['url'],date('c'),'always','0.8'); } } //3.thread $query=DB::query('select tid,lastpost from '.DB::table('forum_thread').' where displayorder>=0 order by tid desc'.($thread==0 ? '':' limit 0,'.$thread.' ')); while($row=DB::fetch($query)) { $row['url']=rewriteurl("forum_viewthread",$row['tid']); foreach($ct as $key=>$item) { $ct[$key]->add_url(Domain('forum').$row['url'],date('c',$row['lastpost']),'daily','0.8'); } } //4.blog $query=DB::query('select blogid,uid,dateline from '.DB::table('home_blog').' where status>=0 order by blogid desc'.($blog==0 ? '':' limit 0,'.$blog.' ')); while($row=DB::fetch($query)) { $row['url']=rewriteurl("home_blog",$row['uid'],$row['blogid']); foreach($ct as $key=>$item) { $ct[$key]->add_url(Domain('home').$row['url'],date('c',$row['dateline']),'daily','0.6'); } } /*//5.space $query=DB::query("select uid,regdate from ".DB::table('common_member')." order by uid desc".($space==0 ? '':' limit 0,'.$space.' ')); while($row=DB::fetch($query)) { $row['url']=rewriteurl("home_blog",$row['uid']); foreach($ct as $key=>$item) { $ct[$key]->add_url(Domain('home').$row['url'],date('c',$row['regdate']),'daily','0.6'); } }*/ foreach($ct as $item) { // $item->add_url(Domain('forum'),date('c'),'always','1.0'); $item->write(); } ?>
定义了$open=1;为什么总是执行rewriteurl中的else?
作者: huangdi7922 发布时间: 2011-11-28
你确定别的地方没有把$open变量清掉,正常的话肯定是1的。
作者: hellodifa 发布时间: 2011-11-28
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28