论坛风格切换
  • 4383阅读
  • 0回复

简单介绍zencart对广告操作的函数 [复制链接]

上一主题 下一主题
 

发帖
6653
大洋
50269
贡献值
940
只看楼主 正序阅读 使用道具 楼主  发表于: 2011-09-13

关于zencart中对广告的操作函数位于includes\functions\banner.php文件中,下面简单介绍一下这些函数的功能。 
zen_set_banner_status($banners_id, $status)  
该函数设置一个指定ID的广告的显示状态,如果要激活该广告就设置$status参数为1,否则设置为0 

  1.   function zen_set_banner_status($banners_id, $status) {
  2.     global $db;
  3.     if ($status == '1') {///激活该广告
  4.       $sql = "update " . TABLE_BANNERS . "
  5.               set status = 1, date_status_change = now(), date_scheduled = NULL
  6.               where banners_id = '" . (int)$banners_id . "'";
  7.       return $db->Execute($sql);
  8.     } elseif ($status == '0') {///不激活
  9.       $sql = "update " . TABLE_BANNERS . "
  10.               set status = 0, date_status_change = now()
  11.               where banners_id = '" . (int)$banners_id . "'";
  12.       return $db->Execute($sql);
  13.     } else {
  14.       return -1;
  15.     }
  16.   }
 
//// 
zen_activate_banners() 
如果添加广告的时候设置了Scheduled At: 值后,而且该值不是当天的日期而是以后的某一天的话,该函数会把设置的日期时间跟当前的时间对比, 
如果当前的日期大于设置的值的自动激活该广告。 
  1. function zen_activate_banners() {
  2.     global $db;
  3.     $banners_query = "select banners_id, date_scheduled
  4.                       from " . TABLE_BANNERS . "
  5.                       where date_scheduled != 'NULL'";
  6.     $banners = $db->Execute($banners_query);
  7.     if ($banners->RecordCount() > 0) {
  8.       while (!$banners->EOF) {
  9.         if (date('Y-m-d H:i:s') >= $banners->fields['date_scheduled']) {////拿当前的时间跟设置的值对比
  10.           zen_set_banner_status($banners->fields['banners_id'], '1');////激活广告
  11.         }
  12.         $banners->MoveNext();
  13.       }
  14.     }
  15.   }
 
zen_expire_banners() 
如果设置了广告的过期时间,调用该函数会自动把广告设置为不激活状态。 
  1. function zen_expire_banners() {
  2.     global $db;
  3.     $banners_query = "select b.banners_id, b.expires_date, b.expires_impressions,
  4.                              sum(bh.banners_shown) as banners_shown
  5.                       from " . TABLE_BANNERS . " b, " . TABLE_BANNERS_HISTORY . " bh
  6.                       where b.status = 1
  7.                       and b.banners_id = bh.banners_id
  8.                       group by b.banners_id, b.expires_date, b.expires_impressions";
  9.     $banners = $db->Execute($banners_query);
  10.     if ($banners->RecordCount() > 0) {
  11.       while (!$banners->EOF) {
  12.         if (zen_not_null($banners->fields['expires_date'])) {
  13.           if (date('Y-m-d H:i:s') >= $banners->fields['expires_date']) {
  14.             zen_set_banner_status($banners->fields['banners_id'], '0');
  15.           }
  16.         } elseif (zen_not_null($banners->fields['expires_impressions'])) {
  17.           if ( ($banners->fields['expires_impressions'] > 0) && ($banners->fields['banners_shown'] >= $banners->fields['expires_impressions']) ) {
  18.             zen_set_banner_status($banners->fields['banners_id'], '0');
  19.           }
  20.         }
  21.         $banners->MoveNext();
  22.       }
  23.     }
  24.   }
 
zen_display_banner($action, $identifier) 
该函数的功能主要是显示一个指定ID的广告 
  1.   function zen_display_banner($action, $identifier) {
  2.     global $db, $request_type;
  3.     switch ($request_type) {
  4.       case ('SSL'):///以SSL形式打开广告
  5.         $my_banner_filter=" and banners_on_ssl= " . "1 ";
  6.         break;
  7.       case ('NONSSL'):///不用以SSL形式打开广告
  8.         $my_banner_filter='';
  9.         break;
  10.     }
  11.     if ($action == 'dynamic') {///动态广告
  12.       $new_banner_search = zen_build_banners_group($identifier);
  13.       $banners_query = "select count(*) as count
  14.                         from " . TABLE_BANNERS . "
  15.                            where status = '1' " .
  16.                            $new_banner_search . $my_banner_filter;
  17.       $banners = $db->Execute($banners_query);
  18.       if ($banners->fields['count'] > 0) {///存在指定ID的广告组
  19.         $banner = $db->Execute("select banners_id, banners_title, banners_image, banners_html_text, banners_open_new_windows, banners_url
  20.                                from " . TABLE_BANNERS . "
  21.                                where status = 1 " .
  22.                                $new_banner_search . $my_banner_filter . " order by rand()");
  23.       } else {////不存在该广告组就显示函数调用错误
  24.         return '<p class="alert">ZEN ERROR! (zen_display_banner(' . $action . ', ' . $identifier . ') -> No banners with group \'' . $identifier . '\' found!</p>';
  25.       }
  26.     } elseif ($action == 'static') {///静态广告
  27.       if (is_object($identifier)) {
  28.         $banner = $identifier;
  29.       } else {
  30.         $banner_query = "select banners_id, banners_title, banners_image, banners_html_text, banners_open_new_windows, banners_url
  31.                          from " . TABLE_BANNERS . "
  32.                          where status = 1
  33.                          and banners_id = '" . (int)$identifier . "'" . $my_banner_filter;
  34.         $banner = $db->Execute($banner_query);
  35.         if ($banner->RecordCount() < 1) {
  36.           //return '<strong>ZEN ERROR! (zen_display_banner(' . $action . ', ' . $identifier . ') -> Banner with ID \'' . $identifier . '\' not found, or status inactive</strong>';
  37.         }
  38.       }
  39.     } else {
  40.       return '<p class="alert">ZEN ERROR! (zen_display_banner(' . $action . ', ' . $identifier . ') -> Unknown $action parameter value - it must be either \'dynamic\' or \'static\'</p>';
  41.     }
  42.     if (zen_not_null($banner->fields['banners_html_text'])) {
  43.       $banner_string = $banner->fields['banners_html_text'];
  44.     } else {
  45.       if ($banner->fields['banners_url'] == '') {
  46.         $banner_string = zen_image(DIR_WS_IMAGES . $banner->fields['banners_image'], $banner->fields['banners_title']);
  47.       } else {
  48.         if ($banner->fields['banners_open_new_windows'] == '1') {
  49.           $banner_string = '<a href="' . zen_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner->fields['banners_id']) . '" target="_blank">' . zen_image(DIR_WS_IMAGES . $banner->fields['banners_image'], $banner->fields['banners_title']) . '</a>';
  50.         } else {
  51.           $banner_string = '<a href="' . zen_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner->fields['banners_id']) . '">' . zen_image(DIR_WS_IMAGES . $banner->fields['banners_image'], $banner->fields['banners_title']) . '</a>';
  52.         }
  53.       }
  54.     }
  55.     zen_update_banner_display_count($banner->fields['banners_id']);///更新广告的显示次数
  56.     return $banner_string;
  57.   }
 
// 
zen_banner_exists($action, $identifier) 
该函数主要通过ID检查一个广告是否存在 
  1. function zen_banner_exists($action, $identifier) {
  2.     global $db, $request_type;
  3.     switch ($request_type) {
  4.       case ('SSL'):
  5.         $my_banner_filter=" and banners_on_ssl= " . "1 ";
  6.         break;
  7.       case ('NONSSL'):
  8.         $my_banner_filter='';
  9.         break;
  10.     }
  11.     if ($action == 'dynamic') {
  12.       $new_banner_search = zen_build_banners_group($identifier);
  13.       return $db->Execute("select banners_id, banners_title, banners_image, banners_html_text, banners_open_new_windows, banners_url
  14.                            from " . TABLE_BANNERS . "
  15.                                where status = 1 " .
  16.                                $new_banner_search . $my_banner_filter . " order by rand()");
  17.     } elseif ($action == 'static') {
  18.       $banner_query = "select banners_id, banners_title, banners_image, banners_html_text, banners_open_new_windows, banners_url
  19.                        from " . TABLE_BANNERS . "
  20.                        where status = 1
  21.                        and banners_id = '" . (int)$identifier . "'" . $my_banner_filter;
  22.       return $banner = $db->Execute($banner_query);
  23.     } else {
  24.       return false;
  25.     }
  26.   }
 
//  
zen_update_banner_display_count($banner_id) 
该函数更新广告的显示次数 
  1. function zen_update_banner_display_count($banner_id) {
  2.     global $db;
  3.     $banner_check = $db->Execute(sprintf(SQL_BANNER_CHECK_QUERY, (int)$banner_id));
  4.     if ($banner_check->fields['count'] > 0) {
  5.       $db->Execute(sprintf(SQL_BANNER_CHECK_UPDATE, (int)$banner_id));
  6.     } else {
  7.       $sql = "insert into " . TABLE_BANNERS_HISTORY . "
  8.                      (banners_id, banners_shown, banners_history_date)
  9.               values ('" . (int)$banner_id . "', 1, now())";
  10.       $db->Execute($sql);
  11.     }
  12.   }
 
//// 
zen_update_banner_click_count($banner_id) 
该函数更新广告的点击次数 
  1.   function zen_update_banner_click_count($banner_id) {
  2.     global $db;
  3.     $db->Execute(sprintf(SQL_BANNER_UPDATE_CLICK_COUNT, (int)$banner_id));
  4.   }
 
 
 
zen_build_banners_group($selected_banners) 
该函数通过广告组的名字生产部分的查询语句,来确定要查询的广告组 
  1. function zen_build_banners_group($selected_banners) {
  2.     $selected_banners = explode(':', $selected_banners);
  3.     $size = sizeof($selected_banners);
  4.     if ($size == 1) {
  5.       $new_banner_search = " banners_group = '" . $selected_banners[0] . "'";
  6.     } else {
  7.       for ($i=0, $n=$size; $i<$n; $i+=1) {
  8.         $new_banner_search .= " banners_group = '" . $selected_banners[$i] . "'";
  9.         if ($i+1 < $n) {
  10.           $new_banner_search .= ' or ';
  11.         }
  12.       }
  13.     }
  14.     if ($new_banner_search != '') {
  15.       $new_banner_search = ' and (' . $new_banner_search . ')';
  16.     }
  17.     return $new_banner_search;
  18.   }
 

zencart外贸网站案例请看http://www.zencar-bbs.com/ 如果QQ在线联系没有反应,请直接加QQ:1023206115 或者 2257583107
关于zen cart的问题请发帖说明,不要发站内信,也不要QQ问,就是问了也没有人回复的。可以发好帖子,发帖子地址给我,叫我回复
!!!我要免费模板!!!
快速回复
限80 字节
批量上传需要先选择文件,再选择上传(---删除纯表情和无意义内容,扣1分---)
 
上一个 下一个