Ecshop二次开发-让网站底部的文章用help.php文件打开

目的:使帮助文档用不同于一般文档的模板来显示

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

方法:用了一个很苯又不叫苯但很实用的方法(新建帮助文件help.php和模板文件help.dwt,然后修改两个系统函数build_uri()和get_shop_help()来实现)

1、复制artile.php文件重命名为help.php文件,不过里面的有些代码可以删掉,我只保留了如下代码(help.php文件):

  1. <?php
  2. /**
  3. * ECSHOP 帮助内容
  4. * ============================================================================
  5. * 版权所有 2005-2008 上海商派网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.ecshop.com;
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * $Author: testyang $
  12. * $Id: article.php 15115 2008-10-28 09:43:36Z testyang $
  13. */
  14. define('IN_ECS', true);
  15. require(dirname(__FILE__) . '/includes/init.php');
  16. if ((DEBUG_MODE & 2) != 2)
  17. {
  18. $smarty->caching = true;
  19. }
  20. /*------------------------------------------------------ */
  21. //-- INPUT
  22. /*------------------------------------------------------ */
  23. $_REQUEST['id'] = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;
  24. $article_id     = $_REQUEST['id'];
  25. if(isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] < 0)
  26. {
  27. $article_id = $db->getOne("SELECT article_id FROM " . $ecs->table('article') . " WHERE cat_id = '".intval($_REQUEST['cat_id'])."' ");
  28. }
  29. /*------------------------------------------------------ */
  30. //-- PROCESSOR
  31. /*------------------------------------------------------ */
  32. $cache_id = sprintf('%X', crc32($_REQUEST['id'] . '-' . $_CFG['lang']));
  33. if (!$smarty->is_cached('help.dwt', $cache_id))
  34. {
  35. /* 文章详情 */
  36. $article = get_article_info($article_id);
  37. if (empty($article))
  38. {
  39.        ecs_header("Location: ./\n");
  40.        exit;
  41. }
  42. if (!empty($article['link']) && $article['link'] != 'http://' && $article['link'] != 'https://')
  43. {
  44.        ecs_header("locationarticle[link]\n");
  45.        exit;
  46. }
  47. $smarty->assign('categories',    get_categories_tree());   // 分类
  48. $smarty->assign('helps',          get_shop_help()); // 网店帮助
  49. $smarty->assign('id',             $article_id);
  50. $smarty->assign('username',       $_SESSION['user_name']);
  51. $smarty->assign('email',          $_SESSION['email']);
  52. $smarty->assign('type',          '1');
  53. $smarty->assign('promotion_info', get_promotion_info());
  54. $smarty->assign('article',    $article);
  55. $smarty->assign('keywords',     htmlspecialchars($article['keywords']));
  56. $smarty->assign('descriptions', htmlspecialchars($article['title']));
  57. $catlist = array();
  58. foreach(get_article_parent_cats($article['cat_id']) as $k=>$v)
  59. {
  60.        $catlist[] = $v['cat_id'];
  61. }
  62. assign_template('a', $catlist);
  63. $position = assign_ur_here($article['cat_id'], $article['title']);
  64. $smarty->assign('page_title', $position['title']); // 页面标题
  65. $smarty->assign('comment_type', 1);
  66. assign_dynamic('article');
  67. }
  68. $smarty->display('help.dwt', $cache_id);
  69. /*------------------------------------------------------ */
  70. //-- PRIVATE FUNCTION
  71. /*------------------------------------------------------ */
  72. /**
  73. * 获得指定的文章的详细信息
  74. *
  75. * @access   private
  76. * @param integer     $article_id
  77. * @return   array
  78. */
  79. function get_article_info($article_id)
  80. {
  81. /* 获得文章的信息 */
  82. $sql = "SELECT a.*, IFNULL(AVG(r.comment_rank), 0) AS comment_rank ".
  83.          "FROM " .$GLOBALS['ecs']->table('article'). " AS a ".
  84.          "LEFT JOIN " .$GLOBALS['ecs']->table('comment'). " AS r ON r.id_value = a.article_id AND comment_type = 1 ".
  85.          "WHERE a.is_open = 1 AND a.article_id = '$article_id' GROUP BY a.article_id";
  86. $row = $GLOBALS['db']->getRow($sql);
  87. if ($row !== false)
  88. {
  89.        $row['add_time']     = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); // 修正添加时间显示
  90.        /* 作者信息如果为空,则用网站名称替换 */
  91.        if (empty($row['author']) || $row['author'] == '_SHOPHELP')
  92.        {
  93.          $row['author'] = $GLOBALS['_CFG']['shop_name'];
  94.        }
  95. }
  96. return $row;
  97. }
  98. ?>
复制代码

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

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
  5. <meta name="Keywords" content="{$keywords}" />
  6. <meta name="Description" content="{$description}" />
  7. <!-- TemplateBeginEditable name="doctitle" -->
  8. <title>{$page_title}</title>
  9. <!-- TemplateEndEditable --><!-- TemplateBeginEditable name="head" --><!-- TemplateEndEditable -->
  10. <link rel="shortcut icon" href="favicon.ico" />
  11. <link rel="icon" href="animated_favicon.gif" type="image/gif" />
  12. <link href="{$ecs_css_path}" rel="stylesheet" type="text/css" />
  13. {* 包含脚本文件 *}
  14. {insert_scripts files='common.js'}
  15. </head>
  16. <body>
  17. <!-- #BeginLibraryItem "/library/page_header.lbi" --><!-- #EndLibraryItem -->
  18. <!--当前位置 start-->
  19. <div class="block box">
  20. <div id="ur_here">
  21.    <!-- #BeginLibraryItem "/library/ur_here.lbi" --><!-- #EndLibraryItem -->
  22. </div>
  23. </div>
  24. <!--当前位置 end-->
  25. <div class="blank"></div>
  26. <div class="block clearfix">
  27. <!--left start-->
  28. <div class="AreaL">
  29. <!-- #BeginLibraryItem "/library/help2.lbi" -->
  30. <!-- #EndLibraryItem -->
  31. </div>
  32. <!--left end-->
  33.    <!--right start-->
  34.    <div class="AreaR">
  35. <div class="box">
  36.     <div class="box_1">
  37.    <div >
  38.       <div class="tc" >
  39.       <font class="f5 f6">{$article.title|escape:html}</font>
  40.       </div>
  41.       <!-- {if $article.content } -->
  42.       {$article.content}
  43.       <!-- {/if} -->
  44.       {if $article.open_type eq 2 or $article.open_type eq 1}<br />
  45.       <div><a href="{$article.file_url}" target="_blank">{$lang.relative_file}</a></div>
  46.       {/if}
  47.    </div>
  48. </div>
  49.    </div>
  50.    <div class="blank"></div>
  51.    </div>
  52.    <!--right end-->
  53. </div>
  54. <div class="blank"></div>
  55. <!-- #BeginLibraryItem "/library/page_footer.lbi" --><!-- #EndLibraryItem -->
  56. </body>
  57. </html>
复制代码

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

  1. <div class="box">
  2. <div class="box_1">
  3. <div id="help_tree">
  4. <h5>帮助中心</h5>
  5. <!-- {foreach from=$helps item=help_cat} -->
  6. <dl>
  7. <dt><span>{$help_cat.cat_name}</span></dt>
  8. <!-- {foreach from=$help_cat.article item=item} -->
  9. <dd><a href="{$item.url}" title="{$item.title|escape:html}">{$item.short_title}</a></dd>
  10. <!--{/foreach}-->
  11. </dl>
  12. <!--{/foreach}-->
  13. </div>
  14. </div>
  15. </div>
复制代码

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

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

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

  1. case 'article':
  2. if (empty($aid))
  3. {
  4. return false;
  5. }
  6. else
  7. {
  8. $uri = $rewrite ? 'article-' . $aid : 'article.php?id=' . $aid;
  9. }
  10. break;
复制代码

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

  1. case 'help':
  2. if (empty($aid))
  3. {
  4. return false;
  5. }
  6. else
  7. {
  8. $uri = $rewrite ? 'help-' . $aid : 'help.php?id=' . $aid;
  9. }
  10. break;
复制代码

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

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

修改为:

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

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

OK!大功告成!!!

posted @ 2011-12-17 21:53  做个好男人  阅读(275)  评论(0编辑  收藏  举报