function create() { $app = C('URL_MODEL') == 2 ? '' : "/index.php"; $unit = 5000; //类别页面 $num = $_GET['num'] ? $_GET['num'] : 0; Vendor('Google.Sitemap'); $sitemap = new google_sitemap(); if ($num == 0) { //写入头部 $fh = fopen($this->xmlpath, 'w'); fwrite($fh, $sitemap->header); fclose($fh); $dao = D('Cate'); $data = $dao->order('pid asc')->select(); $cats[] = array("loc" => "http://" . $_SERVER['HTTP_HOST'], "changefreq" => "weekly", "priority" => 1.0); foreach ($data as $k => $v) { $cats[] = array("loc" => "http://" . $_SERVER['HTTP_HOST'] . "{$app}/" . rawurlencode(tourlstr($v['name'])) . "-cid-" . $v['id'] . ".html", "changefreq" => "weekly", "priority" => 1.0); } $cats[] = array("loc" => "http://" . $_SERVER['HTTP_HOST'] . "{$app}/Products-index.html", "changefreq" => "weekly", "priority" => 0.8); } //产品页面 $dao = D('Products'); $data = $dao->order('id desc')->limit("{$num},{$unit}")->select(); if (!$data) { //写入底部 $fh = fopen($this->xmlpath, 'a'); fwrite($fh, $sitemap->footer); fclose($fh); $sitemap = "http://" . $_SERVER['HTTP_HOST'] . '/sitemap.xml'; $pingurl = "http://www.google.com/webmasters/sitemaps/ping?sitemap=" . rawurlencode($sitemap); //通知google更新 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $pingurl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); //$this->assign('jumpUrl',U("Sitemap/index")); //$this->success('生成网站地图成功!'); die("生成网站地图成功"); } foreach ($data as $k => $v) { $cats[] = array("loc" => "http://" . $_SERVER['HTTP_HOST'] . "{$app}/" . rawurlencode(tourlstr($v['name'])) . "-pid-" . $v['id'] . ".html", "changefreq" => "weekly", "priority" => 0.8); } for ($i = 0, $count = count($cats); $i < $count; $i++) { $value = $cats[$i]; $site_map_item =& new google_sitemap_item($value['loc'], "", $value['changefreq'], $value['priority']); $sitemap->add_item($site_map_item); } //header( "Content-type: application/xml; charset=\"".$sitemap->charset . "\"", true ); //header( 'Pragma: no-cache' ); $sitemap->build($this->xmlpath); $more = $num + $unit; //$this->assign('jumpUrl',U("Sitemap/create?num=$more")); //$this->success("正在生成产品从".$num."到".$more); echo "正在生成产品从" . $num . "到" . $more . "\n"; echo "<script>location.href='" . U("Sitemap/create?num={$more}") . "';</script>"; }
function build_url($vo, $type) { switch ($type) { case 'pro_url': $url = U(tourlstr($vo['name']) . '@', array('pid' => $vo['id'])); if (strcasecmp(GROUP_NAME, 'Member') == 0 || strcasecmp(GROUP_NAME, 'Admin') == 0) { $url = str_replace(GROUP_NAME . '-', '', $url); } return $url; case 'pid': $url = U(tourlstr($vo['name']) . '@', array('pid' => $vo['pid'])); if (strcasecmp(GROUP_NAME, 'Member') == 0 || strcasecmp(GROUP_NAME, 'Admin') == 0) { $url = str_replace(GROUP_NAME . '-', '', $url); } return $url; case 'products_id': $url = U(tourlstr($vo['products_name']) . '@', array('pid' => $vo['products_id'])); if (strcasecmp(GROUP_NAME, 'Member') == 0 || strcasecmp(GROUP_NAME, 'Admin') == 0) { $url = str_replace(GROUP_NAME . '-', '', $url); } return $url; case 'pro_name': return $vo['name']; case 'pro_smallimage': return __ROOT__ . '/' . $vo['smallimage']; case 'pro_bigimage': return __ROOT__ . '/' . $vo['bigimage']; case 'altimg': if (GetSettValue('isBigimg') == 0) { return ''; } return __ROOT__ . '/' . $vo['bigimage']; case 'pro_price': return getprice($vo['price'], $vo['pricespe']); //特价表示 //return $vo['price']; //特价表示 //return $vo['price']; case 'pro_pricespe': return $vo['pricespe']; case 'cate_url': return U(tourlstr($vo['name']) . '@', array('cid' => $vo['id'])); case 'cate_name': return $vo['name']; case 'ad_name': return $vo['name']; case 'ad_remark': return $vo['remark']; case 'ad_link': return $vo['link']; case 'ad_img': return __ROOT__ . '/' . $vo['img_url']; case 'article_url': return U('Article/index', array('id' => $vo['id'])); case 'article_title': return $vo['title']; case 'article_dateline': return date('Y-m-d H:i:s', $vo['dateline']); case 'cate_img': return __ROOT__ . '/' . $vo['imgurl']; case 'g_bigimage': return __ROOT__ . '/' . $vo['img_url']; case 'g_smallimage': return __ROOT__ . '/' . $vo['thumb_url']; case 'hotmail': //msn $r = array(); foreach (explode(',', $vo) as $k => $v) { $r[$v] = "msnim:chat?contact=" . $v; } return $r; case 'yahoo': //yahoo $r = array(); foreach (explode(',', $vo) as $k => $v) { $r[$v] = "ymsgr:sendIM?" . $v; } return $r; case 'email': //email $r = array(); foreach (explode(',', $vo) as $k => $v) { $r[$v] = "mailto:" . $v; } return $r; case 'skype': //skype $r = array(); foreach (explode(',', $vo) as $k => $v) { $r[$v] = "callto://" . $v; } return $r; case 'qq': //qq $r = array(); foreach (explode(',', $vo) as $k => $v) { $r[$v] = "tencent://Message/?Menu=YES&Uin=" . $v . "&websiteName=im.qq.com"; } return $r; case 'gtalk': //gtalk $r = array(); foreach (explode(',', $vo) as $k => $v) { $r[$v] = "gtalk:chat?jid=" . $v . "&from_jid="; } return $r; case 'tel': //tel $r = array(); foreach (explode(',', $vo) as $k => $v) { $r[$v] = $v; } return $r; } }