在购买 SiteFactory™ CMS 授权的时候就对“动易SiteFactory”的客服人员指出了SiteFactory在文章分页中存在一个Bug或者瑕疵,如今SiteFactory已更新至1.20版,但是该问题依然存在,鉴于其他用户也会遭遇此困惑,在此将我的即刻处理办法贡献给大家,以便大家在使用中能正常分页。
一、错误现象:
该错误只有在为网站指定 网站生成目录 时才会出现,如果您在配置网站参数时不填写确定将静态页生成在根目录下,即填写网站生成目录项,则不会出现此问题,因此该问题较为隐蔽,以至于动易开发人员在用户指出此错误时仍未及时排除。
由于在根目录下生成静态页会在日后管理时感觉网站根目录十分凌乱,我们通常会为静态页指定一个专门的生成目录,如“html”,此时如果http://www.xxx.net网站节点号为2008,ID为69860的项目需要分两页,按理系统应该生成
上一页 1 2 下一页 ,但实际上却成了上一页 1 2 下一页 即将http://www.xxx.net/html/2008/10/24/69860.html和http://www.xxx.net/html/2008/10/24/69860_2.html 两个页面链接变成了http://www.xxx.net/html2008/10/24/69860.html和http://www.xxx.net/html2008/10/24/69860_2.html ,html与2008之间的斜线丢失了,访问者根本无法翻页继续浏览。
二、处理办法:
1、脚本处理法,SiteFactory的早期版本的动态库做了混淆,无法查清其错误位置,便想了个用脚本纠正的办法,即在“内容页模板”上找出路,找到分页标签,{PE.Page id="内容分页" datasource="contentpage" span="span"/}改为如下形式:
<div id="pageerr" style="clear:both; margin:10px 0; text-align:center;">{PE.Page id="内容分页" datasource="contentpage" span="span"/}</div>
<script type="text/javascript">
<!--纠正分页错误-->
var a_pager = document.getElementById("pageerr").getElementsByTagName("a");
var a_pager_Count=a_pager.length;
var re = ///html/g;
for(var i=0;i<a_pager_Count;i++)
{
a_pager[i].href = a_pager[i].href.replace(re, "/html/");
}
</script>
即通过脚本将丢失的斜线再加回去,这样就不影响访问者浏览了。但这个办法有个缺陷就是搜索引擎还是糊涂的,无法索引后续页面。
2、直接修改动态库。SiteFactory的后期版本不再混淆动态库了,在PowerEasy.StaticHtml.dll中我找到了出现错误的位置
public void CreateContentHtml(CommonModelInfo commonModelInfo)
{
NodeInfo cacheNodeById = Nodes.GetCacheNodeById(commonModelInfo.NodeId);
if (cacheNodeById.IsCreateContentPage && (cacheNodeById.PurviewType <= 0))
{
TemplateInfo templateInfo = new TemplateInfo();
NameValueCollection values = new NameValueCollection();
values.Add("id", commonModelInfo.GeneralId.ToString());
values.Add("page", "1");
templateInfo.QueryList = values;
templateInfo.CurrentPage = 1;
templateInfo.RootPath = this.PhysicalApplicationPath;
templateInfo.SiteUrl = this.SiteUrl;
templateInfo.IsDynamicPage = false;
templateInfo.PageType = 0;
templateInfo.PageName = this.TemplatePageName(commonModelInfo, cacheNodeById);
templateInfo.TemplateContent = Template.GetTemplateContent(ItemTemplateFilePath(commonModelInfo), this.PhysicalApplicationPath);
int pageNum = 0;
try
{
TemplateTransform.GetHtml(templateInfo);
}
catch
{
this.CreateMessage = string.Concat(new object[] { "<li>第<font color='red'><b>", this.CreateCompleted + 1, "</b></font>条信息生成失败。 ID:", commonModelInfo.GeneralId.ToString(), " 标题:<a target=_blank href=#>", commonModelInfo.Title, "</a>内容解析出现异常,跳过生成</li>", this.CreateMessage });
}
finally
{
string str = string.Empty;
string pageName = string.Empty;
pageNum = templateInfo.PageNum;
HtmlAbstract.AddHeardRunatServer(templateInfo, pageName);
if (templateInfo.TemplateContent.IndexOf("$$$PowerEasy.ChargeTips$$$", StringComparison.Ordinal) > 0)
{
string newValue = ChargeTipsMessage(commonModelInfo.GeneralId, commonModelInfo.ModelId);
templateInfo.TemplateContent = templateInfo.TemplateContent.Replace("$$$PowerEasy.ChargeTips$$$", newValue);
pageNum = 0;
}
pageName = ContentManage.ContentHtmlName(commonModelInfo, cacheNodeById, 0);
str = VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.CreateHtmlPath) + pageName;
FileSystemObject.WriteFile(VirtualPathUtility.AppendTrailingSlash(this.PhysicalApplicationPath) + str, templateInfo.TemplateContent);
string str4 = (VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteInfo.VirtualPath) + str).Replace("//", "/");
this.CreateMessage = string.Concat(new object[] { "<li>成功生成第<font color='blue'><b>", this.CreateCompleted + 1, "</b></font>条信息。 ID:", commonModelInfo.GeneralId.ToString(), " 标题:<a target=_blank href=", str4, ">", commonModelInfo.Title, "</a></li>", this.CreateMessage });
}
if (pageNum > 1)
{
for (int i = 1; i < pageNum; i++)
{
templateInfo.TemplateContent = Template.GetTemplateContent(ItemTemplateFilePath(commonModelInfo), this.PhysicalApplicationPath);
values = new NameValueCollection();
values.Add("id", commonModelInfo.GeneralId.ToString());
values.Add("page", (i + 1).ToString());
templateInfo.QueryList = values;
templateInfo.PageName = this.TemplatePageName(commonModelInfo, cacheNodeById);
templateInfo.CurrentPage = i + 1;
TemplateTransform.GetHtml(templateInfo);
string str5 = ContentManage.ContentHtmlName(commonModelInfo, cacheNodeById, i + 1);
HtmlAbstract.AddHeardRunatServer(templateInfo, str5);
string str6 = VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.CreateHtmlPath) + str5;
FileSystemObject.WriteFile(VirtualPathUtility.AppendTrailingSlash(this.PhysicalApplicationPath) + str6, templateInfo.TemplateContent);
string str7 = (VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteInfo.VirtualPath) + str6).Replace("//", "/");
this.CreateMessage = string.Concat(new object[] { "<li>成功生成第<font color='blue'><b>", this.CreateCompleted + 1, "</b></font>篇文章的第<font color='red'><b>", i, "</b></font>个分页。。 ID:", commonModelInfo.GeneralId.ToString(), " 标题:<a target=_blank href=", str7, ">", commonModelInfo.Title, "</a></li>", this.CreateMessage });
if ((i % 20) == 0)
{
this.CreateMessage = "为了缓解服务器压力,暂停一秒生成";
Thread.Sleep(0x3e8);
}
}
}
ContentManage.UpdateCreateTime(commonModelInfo.GeneralId, new DateTime?(DateTime.Now));
if (this.m_EnableCreateNodePage)
{
HtmlCategory category = new HtmlCategory();
category.PhysicalApplicationPath = this.PhysicalApplicationPath;
category.SiteUrl = this.SiteUrl;
category.CreateNodesHtml(cacheNodeById);
}
if (this.m_EnableCreateIndexPage)
{
HtmlCategory category2 = new HtmlCategory();
category2.PhysicalApplicationPath = this.PhysicalApplicationPath;
category2.SiteUrl = this.SiteUrl;
NodeInfo nodeInfo = Nodes.GetCacheNodeById(-2);
category2.CreateNodesHtml(nodeInfo);
}
}
}
问题发生在红色标注的代码: 便可以从根本上解决问题了。但这种做法一来不知是否违反授权协议,动易是否会计较,二来牵一发动全身, 改动此处一点点东西要对所有的关联库都重新编译一次,每次动易升级又得再来一次,不仅繁琐也不是一般程序员做得了的。 3、最简单也是最有效的。这也是促成我今天要这篇文章的起因。曾经想过在设置网站参数时直接将生成目录填写为带斜线的形式,即将“html”填写为“html/”, 但是页面验证又通不过,懒得修改页面验证,便打开了Config目录中的Site.config文件, 找到 <CreateHtmlPath>html</CreateHtmlPath>将其改为 <CreateHtmlPath>html/</CreateHtmlPath>,然后进行生成测试,结果一切正常。 问题圆满解决。问题虽然麻烦但找到症结后解决起来却十分简单,时间关系就不贴图了。 |