广州传奇网络

地址:广州市天河区东圃大马路富华楼C座

电话:13808825895

邮箱:gz020wbs@163.com

QQ:1564443073

网址:http://www.020wbs.com/

首页 > 二次开发Ecshop二次开发 > ECShop网站底部的文章用help.php文件打开

二次开发Ecshop二次开发

二次开发Ecshop二次开发

ECShop网站底部的文章用help.php文件打开

解决思路:虽然底部网店信息是通过判断cat_id=2来调用article_pro.dwt模板,我们也可以根据cat_type=5来区分帮助文档和其它文档,但还是觉得单独建立一个文件help.php来调用帮助模板help.dwt的方法显示帮助文档好。

1、复制artile.php文件重命名为help.php文件,不过里面的有些代码可以删掉,我只保留了如下代码(help.php文件):
<?php
/**
* ECSHOP 帮助内容
* ============================================================================
* 版权所有 2005-2008 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: testyang $
* $Id: article.php 15115 2008-10-28 09:43:36Z testyang $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
if ((DEBUG_MODE & 2) != 2)
{
$smarty->caching = true;
}
/*------------------------------------------------------ */
//-- INPUT
/*------------------------------------------------------ */
$_REQUEST['id'] = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
$article_id = $_REQUEST['id'];
if(isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] < 0)
{
$article_id = $db->getOne("SELECT article_id FROM " . $ecs->table('article') . " WHERE cat_id = '".intval($_REQUEST['cat_id'])."' ");
}
/*------------------------------------------------------ */
//-- PROCESSOR
/*------------------------------------------------------ */
$cache_id = sprintf('%X', crc32($_REQUEST['id'] . '-' . $_CFG['lang']));
if (!$smarty->is_cached('help.dwt', $cache_id))
{
/* 文章详情 */
$article = get_article_info($article_id);
if (empty($article))
{
ecs_header("Location: ./\n");
exit;
}
if (!empty($article['link']) && $article['link'] != 'http://' && $article['link'] != 'https://')
{
ecs_header("locationarticle[link]\n");
exit;
}
$smarty->assign('categories', get_categories_tree()); // 分类树
$smarty->assign('helps', get_shop_help()); // 网店帮助
$smarty->assign('id', $article_id);
$smarty->assign('username', $_SESSION['user_name']);
$smarty->assign('email', $_SESSION['email']);
$smarty->assign('type', '1');
$smarty->assign('promotion_info', get_promotion_info());
$smarty->assign('article', $article);
$smarty->assign('keywords', htmlspecialchars($article['keywords']));
$smarty->assign('descriptions', htmlspecialchars($article['title']));
$catlist = array();
foreach(get_article_parent_cats($article['cat_id']) as $k=>$v)
{
$catlist[] = $v['cat_id'];
}
assign_template('a', $catlist);
$position = assign_ur_here($article['cat_id'], $article['title']);
$smarty->assign('page_title', $position['title']); // 页面标题
$smarty->assign('comment_type', 1);
assign_dynamic('article');
}
$smarty->display('help.dwt', $cache_id);
/*------------------------------------------------------ */
//-- PRIVATE FUNCTION
/*------------------------------------------------------ */
/**
* 获得指定的文章的详细信息
*
* @access private
* @param integer $article_id
* @return array
*/
function get_article_info($article_id)
{
/* 获得文章的信息 */
$sql = "SELECT a.*, INULLAVG(r.comment_rank), 0) AS comment_rank ".
"FROM " .$GLOBALS['ecs']->table('article'). " AS a ".
"LEFT JOIN " .$GLOBALS['ecs']->table('comment'). " AS r ON r.id_value = a.article_id AND comment_type = 1 ".
"WHERE a.is_open = 1 AND a.article_id = '$article_id' GROUP BY a.article_id";
$row = $GLOBALS['db']->getRow($sql);
if ($row !== false)
{
$row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); // 修正添加时间显示
/* 作者信息如果为空,则用网站名称替换 */
if (empty($row['author']) || $row['author'] == '_SHOPHELP')
{
$row['author'] = $GLOBALS['_CFG']['shop_name'];
}
}
return $row;
}
?>

2、在themes/你的模板文件夹下(要么就默认default文件夹)新建一个文件help.dwt,代码如下:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<meta name="Keywords" content="{$keywords}" />
<meta name="Description" content="{$description}" />
<!-- TemplateBeginEditable name="doctitle" -->
<title>{$page_title}</title>
<!-- TemplateEndEditable --><!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
<link rel="shortcut icon" href="favicon.ico" />
<link rel="icon" href="animated_favicon.gif" type="image/gif" />
<link href="{$ecs_css_path}" rel="stylesheet" type="text/css" />
{* 包含脚本文件 *}
{insert_scripts files='common.js'}
</head>
<body>
<!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->
<!--当前位置 start-->
<div class="block box">
<div id="ur_here">
<!-- #BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem -->
</div>
</div>
<!--当前位置 end-->
<div class="blank"></div>
<div class="block clearfix">
<!--left start-->
<div class="AreaL">
<!-- #BeginLibraryItem "/library/help2.lbi" -->
<!-- #EndLibraryItem -->
</div>
<!--left end-->
<!--right start-->
<div class="AreaR">
<div class="box">
<div class="box_1">
<div style="border:4px solid #fcf8f7; background-color:#fff; padding:10px 15px 20px;">
<div class="tc" style="padding:8px;">
<font class="f5 f6">{$article.title|escape:html}</font>
</div>
<!-- {if $article.content } -->
{$article.content}
<!-- {/if} -->
{if $article.open_type eq 2 or $article.open_type eq 1}<br />
<div><a href="{$article.file_url}" target="_blank">{$lang.relative_file}</a></div>
{/if}
</div>
</div>
</div>
<div class="blank"></div>
</div>
<!--right end-->
</div>
<div class="blank"></div>
<!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->
</body>
</html>

3、在themes/你的模板文件夹(要么就默认default文件夹)/library/目录下新建一个文件help2.lbi,代码如下:


<div class="box">
<div class="box_1">
<div id="help_tree">
<h5>帮助中心</h5>
<!-- {foreach from=$helps item=help_cat} -->
<dl>
<dt><span>{$help_cat.cat_name}</span></dt>
<!-- {foreach from=$help_cat.article item=item} -->
<dd><a href="{$item.url}" title="{$item.title|escape:html}">{$item.short_title}</a></dd>
<!--{/foreach}-->
</dl>
<!--{/foreach}-->
</div>
</div>
</div>

4、在你的样式表文件里(themes/模板文件夹/style.css)加入下面代码(其实这个可以不要,主要是方便自己美化又不影响其它的artile文件):


/*帮助列表*/
#help_tree{border:4px solid #fef7f9; background-color:#fff;}
#help_tree h5{text-align:left;margin:0px;padding:2px 0px 3px 10px;font-weight:bold;font-size:14px;color:#d83135;background-color:#fef7f9;}
#help_tree dl{margin:6px;}
#help_tree dt{background:url(images/lineBg.gif) repeat-x left bottom;
color:#3f3f3f; padding:2px 0 3px 5px;font-weight:bold;
}
#help_tree dd{padding:3px 0 3px 10px;}
#help_tree dd a{color:#404040; text-decoration:none;}
#help_tree dd a:hover{color:#ff6600; text-decoration:none;}

5、在includes/lib_common.php文件中,找到函数行build_uri(),大概1449行处。
在如下代码:

case 'article':
if (empty($aid))
{
return false;
}
else
{
$uri = $rewrite ? 'article-' . $aid : 'article.php?id=' . $aid;
}
break;

的后面(大概1664行位置处)加入代码:

case 'help':
if (empty($aid))
{
return false;
}
else
{
$uri = $rewrite ? 'help-' . $aid : 'help.php?id=' . $aid;
}
break;

6、在includes/lib_main.php文件中找到函数(大概421行处)get_shop_help()
在大概439行处有这样一个语句:

$arr[$row['cat_id']]['article'][$key]['url'] = $row['open_type'] != 1 ?
build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);

修改为:

$arr[$row['cat_id']]['article'][$key]['url'] = $row['open_type'] != 1 ?
build_uri('help', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);

即:把"artilce",改为:"help"

修改以后,底部的帮助文档都是用help.php?id=*来显示了,同样支持伪静态,不过你要在httpd.conf或httpd.ini文件中加入下面语句:

Apache服务器下加:

RewriteRule ^help-([0-9]+)(.*)\.html$ help.php?id=$1 [QSA,L]

IIS服务器下加:

RewriteRule ^(.*)/help-([0-9]+)(.*)\.html$ $1/help\.php\?id=$2 [I]