分页: 2/43 第一页 上页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 下页 最后页 [ 显示模式: 摘要 | 列表 ]
Nov
24

ecshop中调用smarty的foreach-iteration函数     2009

 11:40    189    0   noel Ecshop/Ecmall/Smarty 不指定
ecshop中调用smarty的foreach-iteration函数
  ecshop中的模板技术确实不错,ecshop的smarty也写的很好,foreach标签是ecshop中smarty用的最多的一个标签了。而foreach中的iteration非常有用。

    iteration其实是foreach循环中的下标,而且从1开始.直接循环。所以在ecshop销售排行中,很多人用这个来区分销售的图标.他是foreach下name的键值.{foreach name=top_goods from=$top_goods item=goods}


   <meta http-equiv="Content-Type" content="text/html; charset=gbk">
<div class="mod2">
<h1><span class="left"></span><span class="right"></span>销售排行</h1>
<!-- {foreach name=top_goods from=$top_goods item=goods}-->
  <ul class="top10 clearfix">
<li><img src="../images/top_{$smarty.foreach.top_goods.iteration}.gif" class="iteration" />
<!-- {if $smarty.foreach.top_goods.iteration<2}-->

    <table width="185" border="0">
  <tr>
    <td><a href="{$goods.url}" target="_blank"><img src="{$goods.thumb}" alt="{$goods.name&#124;escape:html}" class="topimg" height="80px" width="80px" /></a></td>
    <td>售价:<font class="f1">{$goods.price}</font></td>
  </tr>
</table>



<!-- {/if} -->
       <{if $smarty.foreach.top_goods.iteration<4}class="iteration1"{/if}>
      <a href="{$goods.url}" title="{$goods.name&#124;escape:html}" target="_blank">{$goods.short_name}</a><br />

      </li>
   <div style="clear:both;"></div>
    </ul>
  <!-- {/foreach} -->
</div>
    这个是ecshop销售排行的模板,他通过巧妙使用foreach来实现了图标的对应
.><img src="../images/top_{$smarty.foreach.top_goods.iteration}.gif" class="iteration" />
Nov
24

ECSHOP前台添加搜索问题功能     2009

 11:39    208    0   noel Ecshop/Ecmall/Smarty 不指定
ECSHOP前台添加搜索问题功能


//lib_main.php
function assign_comment($id, $type, $type2=0, $page = 1,$search=false)
{
  if($search){
    $comment_where = (!empty($type2)) ? " AND content LIKE '%" . mysql_like_quote($type2) . "%' " : '';
    }else{
    $comment_where=  (!empty($type2)) ? " AND comment_type2 = '".$type2."'" : '';
      }
    /* 取得评论列表 */
    $count = $GLOBALS['db']->getOne('SELECT COUNT(*) FROM ' .$GLOBALS['ecs']->table('comment').
           " WHERE id_value = '$id' AND comment_type = '$type' $comment_where  AND status = 1 AND parent_id = 0");
    $size  = !empty($GLOBALS['_CFG']['comments_number']) ? $GLOBALS['_CFG']['comments_number'] : 5;

    $page_count = ($count > 0) ? intval(ceil($count / $size)) : 1;

    $sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') .
            " WHERE id_value = '$id' AND comment_type = '$type' $comment_where AND status = 1 AND parent_id = 0".
            ' ORDER BY comment_id DESC';
    $res = $GLOBALS['db']->selectLimit($sql, $size, ($page-1) * $size);

    $arr = array();
    $ids = '';
    while ($row = $GLOBALS['db']->fetchRow($res))
    {
        $ids .= $ids ? ",$row[comment_id]" : $row['comment_id'];
        $arr[$row['comment_id']]['id']       = $row['comment_id'];
        $arr[$row['comment_id']]['email']    = $row['email'];
    $arr[$row['comment_id']]['comment_type2'] = $row['comment_type2'];
        $arr[$row['comment_id']]['username'] = $row['user_name'];
        $arr[$row['comment_id']]['content']  = str_replace('\r\n', '
', htmlspecialchars($row['content']));
        $arr[$row['comment_id']]['content']  = str_replace('\n', '
', $arr[$row['comment_id']]['content']);
        $arr[$row['comment_id']]['rank']     = $row['comment_rank'];
        $arr[$row['comment_id']]['add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
    }
    /* 取得已有回复的评论 */
    if ($ids)
    {
        $sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('comment') .
                " WHERE parent_id IN( $ids )";
        $res = $GLOBALS['db']->query($sql);
        while ($row = $GLOBALS['db']->fetch_array($res))
        {
            $arr[$row['parent_id']]['re_content']  = str_replace('\n', '
', htmlspecialchars($row['content']));
            $arr[$row['parent_id']]['re_add_time'] = local_date($GLOBALS['_CFG']['time_format'], $row['add_time']);
            $arr[$row['parent_id']]['re_email']    = $row['email'];
            $arr[$row['parent_id']]['re_username'] = $row['user_name'];
        }
    }
    /* 分页样式 */
    //$pager['styleid'] = isset($GLOBALS['_CFG']['page_style'])? intval($GLOBALS['_CFG']['page_style']) : 0;
    $pager['page']         = $page;
    $pager['size']         = $size;
    $pager['record_count'] = $count;
    $pager['page_count']   = $page_count;
    $pager['page_first']   = "javascript:gotoPage(1,$id,$type,$type2)";
    $pager['page_prev']    = $page > 1 ? "javascript:gotoPage(" .($page-1). ",$id,$type,$type2)" : 'javascript:;';
    $pager['page_next']    = $page < $page_count ? 'javascript:gotoPage(' .($page + 1) . ",$id,$type,$type2)" : 'javascript:;';
    $pager['page_last']    = $page < $page_count ? 'javascript:gotoPage(' .$page_count. ",$id,$type,$type2)"  : 'javascript:;';

    $cmt = array('comments' => $arr, 'pager' => $pager);

    return $cmt;
}


//comment.php

  /*
     * act 参数不为空
     * 默认为评论内容列表
     * 根据 _GET 创建一个静态对象
     */
    $cmt = new stdClass();
    $cmt->id   = !empty($_GET['id'])   ? intval($_GET['id'])   : 0;
    $cmt->type = !empty($_GET['type']) ? intval($_GET['type']) : 0;
  //$cmt->type2 = !empty($_GET['type2']) ? intval($_GET['type2']) : 0;


  if(isset($_GET['type2'])){
  $cmt->type2 = !empty($_GET['type2']) ? intval($_GET['type2']) : 0;
  $search=false;
  }else{
  $cmt->type2 = !empty($_GET['keyword']) ? trim($_GET['keyword']) : 0;
  $cmt->type2 = iconv("UTF-8","GB2312",$cmt->type2);
  $search=true;
    }
    $cmt->page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
}

if ($result['error'] == 0)
{
    $comments = assign_comment($cmt->id, $cmt->type, $cmt->type2, $cmt->page,$search);

//因为之前做了评论分频道 所以TYPE2为列表的定位 现在用来做KEYWORDS的入口给 assign_comment 函数

//最后是JS

  function searchComment()
  {
      var keyword =  document.getElementById('zx_search').value;
      if (keyword.length > 0)
      {
Ajax.call('comment.php?act=gotopage', 'page=' + 1 + '&id=' + {$id} + '&type=' + {$comment_type} + '&keyword=' + keyword, gotoPageResponse, 'GET', 'JSON');

      }
      else
      {
          document.getElementById('zx_search').focus();
      }
  }
ECSHOP-index_get_only_article 指定获取1篇文章

/**
* 获得指定栏目文章内容。
*
* @access  private
* @return  array
*/
function index_get_only_article($cat_aid)
{
    $sql = "SELECT title ,content FROM " .$GLOBALS['ecs']->table('article'). " WHERE article_id  = ".$cat_aid." LIMIT 1";
    $res = $GLOBALS['db']->getAll($sql);
    $arr = array();
    foreach ($res AS $row)
    {

        $arr['title']       = $row['title'];
      $arr['content']       = $row['content'];    
    }
    return $arr;
}
ecshop支持自定义图片和链接的邮件发送方式

ECSHOP邮件互动性的商城,要求是可以发送要求邮件 而且需要支持图片和外联 这当然需要一个 base64_encode() 来支持发送了 检查了一下 内置了这个函数 那应该没有问题 查看了一下 邮件 被过滤了连接
我用的是FCK编辑器 之前自己开发的时候也用过 提交出来的内容好像是有反斜杠的 于是用 htmlspecialchars()
来测试一下 果然出现了反斜杠,这样就比较容易解决了 一下是我的解决方法 CONTENT是从 FCK里面提交出来的 希望
有需要的人可以用到

  $email = trim($_REQUEST['email']);
  $content = stripslashes($_REQUEST['saymsg']);//去掉反斜杠函数
  $subject = trim($_REQUEST['subject']);

   if(!empty($email)){
   $email = explode(',', $email);
  foreach($email as $value){
    if(!empty($value)){
  send_mail('', trim($value), $subject , $content,1);
    }
  }

sys_msg(sprintf("发送成功", htmlspecialchars(stripslashes($_POST['username']))), 0, $link);
   }else{
     sys_msg(sprintf("邮件为空 发送失败", htmlspecialchars(stripslashes($_POST['username']))), 0, $link);
     }
Nov
24

javascript操作复选框函数     2009

 11:37    187    0   noel Ecshop/Ecmall/Smarty 不指定
javascript操作复选框函数

function CheckAll(form) {//全选
for (var i=0;i    var e = form.elements[i];
    if (e.name != 'chkall')
       e.checked = form.chkall.checked;
   }
}

function checkSelect()//判断是否有选项
{
   var pass = false;
   var input_elements = document.getElementsByName("Pdel[]");

   for ( var i= 0; i< input_elements.length ; i++ )
   {
    var is_checked =   input_elements[i].checked;
    var input_name =   input_elements[i].getAttribute("name");
    var input_type = input_elements[i].getAttribute("type");

    if ( input_type == "checkbox" && input_name != "chkall" && true == is_checked )
     pass = true;
   }

   if ( false == pass )
   {
    alert("请选择要删除的选项!");
    return false;
   }
   else
    return true;
}

function selrev() {//反选
with(document.myform) {
   for(i=0;i    thiselm = elements[i];
    if(thiselm.name.match(/dfile\[]/))
  thiselm.checked = !thiselm.checked;
   }
}
}
Nov
24

用ECSHOP里的 获得查询时间和次数代码     2009

 11:36    179    0   noel Ecshop/Ecmall/Smarty 不指定
用ECSHOP里的 获得查询时间和次数代码

/**
* 获得查询时间和次数,并赋值给smarty
*
* @access  public
* @return  void
*/
function assign_query_info()
{
    if ($GLOBALS['db']->queryTime == '')
    {
        $query_time = 0;
    }
    else
    {
        if (PHP_VERSION >= '5.0.0')
        {
            $query_time = number_format(microtime(true) - $GLOBALS['db']->queryTime, 6);
        }
        else
        {
            list($now_usec, $now_sec)     = explode(' ', microtime());
            list($start_usec, $start_sec) = explode(' ', $GLOBALS['db']->queryTime);
            $query_time = number_format(($now_sec - $start_sec) + ($now_usec - $start_usec), 6);
        }
    }
    $GLOBALS['smarty']->assign('query_info', sprintf($GLOBALS['_LANG']['query_info'], $GLOBALS['db']->queryCount, $query_time));
    /* 内存占用情况 */
    if ($GLOBALS['_LANG']['memory_info'] && function_exists('memory_get_usage'))
    {
        $GLOBALS['smarty']->assign('memory_info', sprintf($GLOBALS['_LANG']['memory_info'], memory_get_usage() / 1048576));
    }
    /* 是否启用了 gzip */
    $gzip_enabled = gzip_enabled() ? $GLOBALS['_LANG']['gzip_enabled'] : $GLOBALS['_LANG']['gzip_disabled'];//这行出错
$GLOBALS['smarty']->assign('gzip_enabled', $gzip_enabled);
}
$smarty->fetch 的使用 生成静态页面

include("Smarty.class.php");$smarty = new Smarty;
$smarty->caching = true;
// only do db calls if cache doesn't exist// 只有在缓存不存在时才调用数据库if(!$smarty->is_cached("index.tpl")){
// dummy up some data $address = "245 N 50th"; $db_data = array(   "City" => "Lincoln",   "State" => "Nebraska",   "Zip" = > "68502"   );
$smarty->assign("Name","Fred"); $smarty->assign("Address",$address); $smarty->assign($db_data);
}
// capture the output// 捕获输出$output = $smarty->fetch("index.tpl");
// do something with $output here// 对将要输出的内容进行处理
echo $output;
Nov
24

修改ecshop后台的版权信息     2009

 11:35    213    0   noel Ecshop/Ecmall/Smarty 不指定
修改ecshop后台的版权信息
在languages/zh_cn/admin/common.php文件修改
admin/templates/index.htm
Line 4
*/
    {$lang.cp_home}
/*
admin/templates/login.htm
Line 4
*/
    {$lang.cp_home}
/*
admin/templates/top.htm
Line 132
Line 135
*/
    
<   img src=”images/ecshop_logo.gif” alt=”ECSHOP - power for e-commerce” />

    
  • {$lang.about}

  • /*
    admin/templates/start.htm
    Line 6
    */
        
    /*
    Line 184-195
    */
          
            {$lang.ecs_version}
            {$ecs_version} RELEASE {$ecs_release}
            {$lang.install_date}
            {$install_date}
          
          
            {$lang.ec_charset}
            {$ecs_charset}
            
            
          
    /*
    admin/tempaltes/pageheader.htm
    Line 24
    */
    {$lang.cp_home} {if $ur_here} - {$ur_here} {/if}
    /*
    admin/templates/pagefooter.htm
    Line 3
    */
    {$lang.copyright}
    /*
    admin/templates/menu.htm
    Line 143
    */

    Nov
    24

    ECSHOP获得指定栏目最新的商品列表     2009

     11:34    226    0   noel Ecshop/Ecmall/Smarty 不指定
    ECSHOP获得指定栏目最新的商品列表

    /**
    * 获得指定栏目最新的商品列表。
    *
    * @access  private
    * @return  array
    */
    function index_get_class_goods($cat_aid, $cat_num)
    {


       $sql = "SELECT goods_id  FROM " .$GLOBALS['ecs']->table('goods'). "WHERE (cat_id = ".$cat_aid." OR goods_id in (".good_cat_id($cat_aid).") ) and is_on_sale = 1 order by `last_update` desc LIMIT " . $cat_num;
        $res = $GLOBALS['db']->getAll($sql);
        $arr = array();
        foreach ($res AS $idx => $row)
        {
            $arr[$idx]['id']          = $row['goods_id'];
            $arr[$idx]['url']     = build_uri('goods', array('gid' => $row['goods_id']));
        }
        return $arr;
    }

    function good_cat_id($cat_aid){
    $sql = "SELECT goods_id  FROM " .$GLOBALS['ecs']->table('goods_cat'). " WHERE cat_id = ".$cat_aid;
        $res = $GLOBALS['db']->getAll($sql);
          $arr = array();
        foreach ($res AS $row)
        {
            $arr[] = $row['goods_id'];

        }

      $ck_explode=implode(',',$arr);
      return $ck_explode;
      }

    $smarty->assign(’shop_notice’, $_CFG['shop_notice']); // 商店公告
    加上
    $smarty->assign(’news_goods’, index_get_class_goods(18,4)); // 新品快递
    $smarty->assign(’design_recommend’, index_get_class_goods(35,4)); // 设计师推荐

    指定函数定义放到HTML里就可以了

    Tags:
    ECSHOP调用分类文章函数index_get_class_articles
    /**
    * 获得指定栏目最新的文章列表。
    *
    * @access  private
    * @return  array
    */
    function index_get_class_articles($cat_aid, $cat_num)
    {
        $sql = "SELECT article_id, title,open_type,cat_id,file_url FROM " .$GLOBALS['ecs']->table('article'). " WHERE cat_id = ".$cat_aid." and is_open = 1 LIMIT " . $cat_num;
        $res = $GLOBALS['db']->getAll($sql);
        $arr = array();
        foreach ($res AS $idx => $row)
        {
            $arr[$idx]['id']          = $row['article_id'];
            $arr[$idx]['title']       = $row['title'];
            $arr[$idx]['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ?
                                            sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title'];
            $arr[$idx]['cat_name']    = $row['cat_name'];
            $arr[$idx]['add_time']    = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']);
            $arr[$idx]['url']         = $row['open_type'] != 1 ?
                                            build_uri('article', array('aid' => $row['article_id']), $row['title']) : trim($row['file_url']);
            $arr[$idx]['cat_url']     = build_uri('article_cat', array('acid' => $row['cat_id']));
        }
        return $arr;
    }


    2、第二步是在index.dwt模板想调用的地方增加以下代码,(注:以下调上面设置里的分类ID为8的文章列表):


            

  •       
    分页: 2/43 第一页 上页 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 下页 最后页 [ 显示模式: 摘要 | 列表 ]