• ecshop二次开发之百度地图


    案例效果展示:





































    代码实现:

    1.在ecshop后台找到文章管理->文章分类->添加文章分类,添加一个顶级分类,叫做“合作单位”,并且让其显示在导航栏。如下图:

































    1.在ecshop后台找到文章管理->文章列表->添加新文章。(文章标题:八维研修学院;文章分类:合作单位;文章重要性:普通;是否显示:是,等等一些东西完善了)如下图:












    3.在ecshop/languages/zh_cn/admin/article.PHP(56行)添加:

             $_LANG['baidu_map'] = '百度地图';

    4.在ecshop/admin/templates/article_info.htm第11行添加:

             <span class="tab-back" id="baidu-tab">{$lang.baidu_map}</span>

    ecshop后台文章管理->文章列表->编辑文章内容,可以看到导航标签多了一个百度地图

    5.在ecshop/admin/templates/article_info.htm第18行添加

    1. <table width="90%" id="baidu-table" style="display: none">  
    2.   
    3. <tr>  
    4.   
    5. <td class="narrow-label">{$lang.baidu_map_info}</td>  
    6.   
    7. <td><input type="text" name="point_x" size ="20" maxlength="30" value="{$article.point_x|escape}" />,<input type="text" name="point_y" size ="20" maxlength="30" value="{$article.point_y|escape}" />{$lang.require_field}</td>  
    8.   
    9. </tr>  
    10.   
    11. </table>  

    6.在ecs.article表中添加两个字段:point_x、point_y,都是varchar类型

    7.在ecshop/admin/article.php里面搜索“插入数据”,在$sql = "INSERT INTO ".$ecs->table('article')."(title, cat_id, article_type, is_open, author, "."author_email, keywords, content, add_time, file_url, open_type, link, description后面添加“,point_x,point_y”。

    添加后:

    1. $sql = "INSERT INTO ".$ecs->table('article')."(title, cat_id, article_type, is_open, author, "."author_email, keywords, content, add_time, file_url, open_type, link, description,point_x,point_y) "."VALUES ('$_POST[title]', '$_POST[article_cat]', '$_POST[article_type]', '$_POST[is_open]', "."'$_POST[author]', '$_POST[author_email]', '$_POST[keywords]', '$_POST[FCKeditor1]', "."'$add_time', '$file_url', '$open_type', '$_POST[link_url]', '$_POST[description]','$_POST[point_x]','$_POST[point_y]')";  
    2.   
    3.        $db->query($sql);  

    8.在ecshop/admin/article.php第287行添加point_x = '$_POST[point_x]',point_y = '$_POST[point_y]'

    添加后

    1. if ($exc->edit("title='$_POST[title]', cat_id='$_POST[article_cat]', article_type='$_POST[article_type]', is_open='$_POST[is_open]', author='$_POST[author]', author_email='$_POST[author_email]', keywords ='$_POST[keywords]', file_url ='$file_url', open_type='$open_type', content='$_POST[FCKeditor1]', link='$_POST[link_url]', description = '$_POST[description]',point_x = '$_POST[point_x]',point_y = '$_POST[point_y]'", $_POST['id']))  

    9.在百度地图坐标文本框输入:116.306358;40.049285

    10.在ecshop/article.php第125行添加:
    1. if($article['cat_id']==15){  
    2.   
    3.       $smarty->display('article_company.dwt', $cache_id);  
    4.   
    5.   }else{  
    6.   
    7.       $smarty->display('article.dwt', $cache_id);  
    8.   
    9.   }  

    这个是前台article.php的所有代码看情况而定(可不写)
    1. <?php  
    2.   
    3. /**  
    4.  * ECSHOP 文章内容  
    5.  * ============================================================================  
    6.  * * 版权所有 2005-2012 上海商派网络科技有限公司,并保留所有权利。  
    7.  * 网站地址: http://www.ecshop.com;  
    8.  * ----------------------------------------------------------------------------  
    9.  * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和  
    10.  * 使用;不允许对程序代码以任何形式任何目的的再发布。  
    11.  * ============================================================================  
    12.  * $Author: liubo $  
    13.  * $Id: article.php 17217 2011-01-19 06:29:08Z liubo $  
    14. */  
    15.   
    16. define('IN_ECS', true);  
    17.   
    18. require(dirname(__FILE__) . '/includes/init.php');  
    19.   
    20. if ((DEBUG_MODE & 2) != 2)  
    21. {  
    22.     $smarty->caching = true;  
    23. }  
    24.   
    25. /*------------------------------------------------------ */  
    26. //-- INPUT  
    27. /*------------------------------------------------------ */  
    28.   
    29. $_REQUEST['id'] = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0;  
    30. $article_id     = $_REQUEST['id'];  
    31. if(isset($_REQUEST['cat_id']) && $_REQUEST['cat_id'] < 0)  
    32. {  
    33.     $article_id = $db->getOne("SELECT article_id FROM " . $ecs->table('article') . " WHERE cat_id = '".intval($_REQUEST['cat_id'])."' ");  
    34. }  
    35.   
    36. /*------------------------------------------------------ */  
    37. //-- PROCESSOR  
    38. /*------------------------------------------------------ */  
    39.   
    40. $cache_id = sprintf('%X', crc32($_REQUEST['id'] . '-' . $_CFG['lang']));  
    41.   
    42. if (!$smarty->is_cached('article.dwt', $cache_id))  
    43. {  
    44.     /* 文章详情 */  
    45.     $article = get_article_info($article_id);  
    46.   
    47.     if (empty($article))  
    48.     {  
    49.         ecs_header("Location: ./ ");  
    50.         exit;  
    51.     }  
    52.   
    53.     if (!empty($article['link']) && $article['link'] != 'http://' && $article['link'] != 'https://')  
    54.     {  
    55.         ecs_header("location:$article[link] ");  
    56.         exit;  
    57.     }  
    58.   
    59.     $smarty->assign('article_categories',   article_categories_tree($article_id)); //文章分类树  
    60.     $smarty->assign('categories',       get_categories_tree());  // 分类树  
    61.     $smarty->assign('helps',            get_shop_help()); // 网店帮助  
    62.     $smarty->assign('top_goods',        get_top10());    // 销售排行  
    63.     $smarty->assign('best_goods',       get_recommend_goods('best'));       // 推荐商品  
    64.     $smarty->assign('new_goods',        get_recommend_goods('new'));        // 最新商品  
    65.     $smarty->assign('hot_goods',        get_recommend_goods('hot'));        // 热点文章  
    66.     $smarty->assign('promotion_goods',  get_promote_goods());    // 特价商品  
    67.     $smarty->assign('related_goods',    article_related_goods($_REQUEST['id']));  // 特价商品  
    68.     $smarty->assign('id',               $article_id);  
    69.     $smarty->assign('username',         $_SESSION['user_name']);  
    70.     $smarty->assign('email',            $_SESSION['email']);  
    71.     $smarty->assign('type',            '1');  
    72.     $smarty->assign('promotion_info', get_promotion_info());  
    73.   
    74.     /* 验证码相关设置 */  
    75.     if ((intval($_CFG['captcha']) & CAPTCHA_COMMENT) && gd_version() > 0)  
    76.     {  
    77.         $smarty->assign('enabled_captcha'1);  
    78.         $smarty->assign('rand',            mt_rand());  
    79.     }  
    80.   
    81.     $smarty->assign('article',      $article);  
    82.     $smarty->assign('keywords',     htmlspecialchars($article['keywords']));  
    83.     $smarty->assign('description', htmlspecialchars($article['description']));  
    84.   
    85.     $catlist = array();  
    86.     foreach(get_article_parent_cats($article['cat_id']) as $k=>$v)  
    87.     {  
    88.         $catlist[] = $v['cat_id'];  
    89.     }  
    90.   
    91.     assign_template('a', $catlist);  
    92.   
    93.     $position = assign_ur_here($article['cat_id'], $article['title']);  
    94.     $smarty->assign('page_title',   $position['title']);    // 页面标题  
    95.     $smarty->assign('ur_here',      $position['ur_here']);  // 当前位置  
    96.     $smarty->assign('comment_type'1);  
    97.   
    98.     /* 相关商品 */  
    99.     $sql = "SELECT a.goods_id, g.goods_name " .  
    100.             "FROM " . $ecs->table('goods_article') . " AS a, " . $ecs->table('goods') . " AS g " .  
    101.             "WHERE a.goods_id = g.goods_id " .  
    102.             "AND a.article_id = '$_REQUEST[id]' ";  
    103.     $smarty->assign('goods_list', $db->getAll($sql));  
    104.   
    105.     /* 上一篇下一篇文章 */  
    106.     $next_article = $db->getRow("SELECT article_id, title FROM " .$ecs->table('article'). " WHERE article_id > $article_id AND cat_id=$article[cat_id] AND is_open=1 LIMIT 1");  
    107.     if (!empty($next_article))  
    108.     {  
    109.         $next_article['url'] = build_uri('article', array('aid'=>$next_article['article_id']), $next_article['title']);  
    110.         $smarty->assign('next_article', $next_article);  
    111.     }  
    112.   
    113.     $prev_aid = $db->getOne("SELECT max(article_id) FROM " . $ecs->table('article') . " WHERE article_id < $article_id AND cat_id=$article[cat_id] AND is_open=1");  
    114.     if (!empty($prev_aid))  
    115.     {  
    116.         $prev_article = $db->getRow("SELECT article_id, title FROM " .$ecs->table('article'). " WHERE article_id = $prev_aid");  
    117.         $prev_article['url'] = build_uri('article', array('aid'=>$prev_article['article_id']), $prev_article['title']);  
    118.         $smarty->assign('prev_article', $prev_article);  
    119.     }  
    120.   
    121.     assign_dynamic('article');  
    122. }  
    123. if(isset($article) && $article['cat_id'] > 2)  
    124. {  
    125.     if($article['cat_id']==15){  
    126.         $smarty->display('article_company.dwt', $cache_id);  
    127.     }else{  
    128.         $smarty->display('article.dwt', $cache_id);  
    129.     }  
    130. }  
    131. else  
    132. {  
    133.     $smarty->display('article_pro.dwt', $cache_id);  
    134. }  
    135.   
    136. /*------------------------------------------------------ */  
    137. //-- PRIVATE FUNCTION  
    138. /*------------------------------------------------------ */  
    139.   
    140. /**  
    141.  * 获得指定的文章的详细信息  
    142.  *  
    143.  * @access  private  
    144.  * @param   integer     $article_id  
    145.  * @return  array  
    146.  */  
    147. function get_article_info($article_id)  
    148. {  
    149.     /* 获得文章的信息 */  
    150.     $sql = "SELECT a.*, IFNULL(AVG(r.comment_rank), 0) AS comment_rank ".  
    151.             "FROM " .$GLOBALS['ecs']->table('article'). " AS a ".  
    152.             "LEFT JOIN " .$GLOBALS['ecs']->table('comment'). " AS r ON r.id_value = a.article_id AND comment_type = 1 ".  
    153.             "WHERE a.is_open = 1 AND a.article_id = '$article_id' GROUP BY a.article_id";  
    154.     $row = $GLOBALS['db']->getRow($sql);  
    155.   
    156.     if ($row !== false)  
    157.     {  
    158.         $row['comment_rank'] = ceil($row['comment_rank']);                              // 用户评论级别取整  
    159.         $row['add_time']     = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); // 修正添加时间显示  
    160.   
    161.         /* 作者信息如果为空,则用网站名称替换 */  
    162.         if (empty($row['author']) || $row['author'] == '_SHOPHELP')  
    163.         {  
    164.             $row['author'] = $GLOBALS['_CFG']['shop_name'];  
    165.         }  
    166.     }  
    167.   
    168.     return $row;  
    169. }  
    170.   
    171. /**  
    172.  * 获得文章关联的商品  
    173.  *  
    174.  * @access  public  
    175.  * @param   integer $id  
    176.  * @return  array  
    177.  */  
    178. function article_related_goods($id)  
    179. {  
    180.     $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' .  
    181.                 "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".  
    182.                 'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' .  
    183.             'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' ga ' .  
    184.             'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = ga.goods_id ' .  
    185.             "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".  
    186.                     "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".  
    187.             "WHERE ga.article_id = '$id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0";  
    188.     $res = $GLOBALS['db']->query($sql);  
    189.   
    190.     $arr = array();  
    191.     while ($row = $GLOBALS['db']->fetchRow($res))  
    192.     {  
    193.         $arr[$row['goods_id']]['goods_id']      = $row['goods_id'];  
    194.         $arr[$row['goods_id']]['goods_name']    = $row['goods_name'];  
    195.         $arr[$row['goods_id']]['short_name']   = $GLOBALS['_CFG']['goods_name_length'] > 0 ?  
    196.             sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];  
    197.         $arr[$row['goods_id']]['goods_thumb']   = get_image_path($row['goods_id'], $row['goods_thumb'], true);  
    198.         $arr[$row['goods_id']]['goods_img']     = get_image_path($row['goods_id'], $row['goods_img']);  
    199.         $arr[$row['goods_id']]['market_price']  = price_format($row['market_price']);  
    200.         $arr[$row['goods_id']]['shop_price']    = price_format($row['shop_price']);  
    201.         $arr[$row['goods_id']]['url']           = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);  
    202.   
    203.         if ($row['promote_price'] > 0)  
    204.         {  
    205.             $arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);  
    206.             $arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']);  
    207.         }  
    208.         else  
    209.         {  
    210.             $arr[$row['goods_id']]['promote_price'] = 0;  
    211.         }  
    212.     }  
    213.   
    214.     return $arr;  
    215. }  
    216.   
    217. ?>  






































    11.在ecshop hemesdefault里面复制article_pro.dwt改名为article_company.dwt

    12.把下面一段话放在article_company.dwt第14行
    1. <style type="text/css">  
    2.   
    3.                    #allmap{100%;height:500px;}  
    4.   
    5.          </style>  
    6.   
    7.          <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=nXezGCeI80ZZK2IsGWDWPMgS"></script>  

    13.把<div id="allmap"></div>放在article_company.dwt第38行

    14.在article_company.dwt第39行放一下一段代码:

    1.          <script type="text/javascript">  
    2.   
    3.     // 百度地图API功能  
    4.   
    5.     var sContent =  
    6.   
    7. "<h4 style='margin:0 0 5px 0;padding:0.2em 0'>{$article.title|escape:html}</h4>" +  
    8.   
    9. "<img style='float:right;margin:4px' id='imgDemo' src='{$article.file_url}' width='139' height='104' title='{$article.title|escape:html}'/>" +  
    10.   
    11. "<p style='margin:0;line-height:1.5;font-size:13px;text-indent:2em'>{$article.description}</p>" +  
    12.   
    13. "</div>";  
    14.   
    15.     var map = new BMap.Map("allmap");  
    16.   
    17.     var point = new BMap.Point({$article.point_x},{$article.point_y});  
    18.   
    19.     var marker = new BMap.Marker(point);  
    20.   
    21.     var infoWindow = new BMap.InfoWindow(sContent);  // 创建信息窗口对象  
    22.   
    23.     map.centerAndZoom(point, 15);  
    24.   
    25.     map.addOverlay(marker);  
    26.   
    27.     marker.addEventListener("click", function(){  
    28.   
    29.         this.openInfoWindow(infoWindow);  
    30.   
    31.         //图片加载完毕重绘infowindow  
    32.   
    33.         document.getElementById('imgDemo').onload = function (){  
    34.   
    35.             infoWindow.redraw();   //防止在网速较慢,图片未加载时,生成的信息框高度比图片的总高度小,导致图片部分被隐藏  
    36.   
    37.         }  
    38.   
    39.     });  
    40.   
    41. </script>  

    page_header.lbi中修改
    1. {insert_scripts files='common.js,utils.js'}  

  • 相关阅读:
    《剑指offer》 面试题43 n个骰子的点数 (java)
    《剑指offer》面试题45 圆圈中最后剩下的数字(Java版本)
    《剑指offer》面试题39 二叉树的深度(java)
    《剑指offer》面试题32----从1到n整数中1出现的次数
    快速排序思路整理
    《Java程序猿面试宝典》之字符串
    Tomcat的server.xml
    easyui combobox 清除选中项目 和 清空option选项
    2019
    throw UnsupportedOperationException
  • 原文地址:https://www.cnblogs.com/hehe520/p/6147485.html
Copyright © 2020-2023  润新知