function minify_css($str) { $res = ''; $i = 0; $inside_block = false; $current_char = ''; while ($i + 1 < strlen($str)) { if ($str[$i] == '"' || $str[$i] == "'") { //quoted string detected $res .= $quote = $str[$i++]; $url = ''; while ($i < strlen($str) && $str[$i] != $quote) { if ($str[$i] == '\\') { $url .= $str[$i++]; } $url .= $str[$i++]; } if (strtolower(substr($res, -5, 4)) == 'url(' || strtolower(substr($res, -9, 8)) == '@import ') { $url = convertUrl($url, substr_count($str, $url)); } $res .= $url; $res .= $str[$i++]; continue; } elseif (strtolower(substr($res, -4)) == 'url(') { //url detected $url = ''; do { if ($str[$i] == '\\') { $url .= $str[$i++]; } $url .= $str[$i++]; } while ($i < strlen($str) && $str[$i] != ')'); $url = convertUrl($url, substr_count($str, $url)); $res .= $url; $res .= $str[$i++]; continue; } elseif ($str[$i] . $str[$i + 1] == '/*') { //css comment detected $i += 3; while ($i < strlen($str) && $str[$i - 1] . $str[$i] != '*/') { $i++; } if ($current_char == "\n") { $str[$i] = "\n"; } else { $str[$i] = ' '; } } if (strlen($str) <= $i + 1) { break; } $current_char = $str[$i]; if ($inside_block && $current_char == '}') { $inside_block = false; } if ($current_char == '{') { $inside_block = true; } if (preg_match('/[\\n\\r\\t ]/', $current_char)) { $current_char = " "; } if ($current_char == " ") { $pattern = $inside_block ? '/^[^{};,:\\n\\r\\t ]{2}$/' : '/^[^{};,>+\\n\\r\\t ]{2}$/'; if (strlen($res) && preg_match($pattern, $res[strlen($res) - 1] . $str[$i + 1])) { $res .= $current_char; } } else { $res .= $current_char; } $i++; } if ($i < strlen($str) && preg_match('/[^\\n\\r\\t ]/', $str[$i])) { $res .= $str[$i]; } return $res; }
} else { $where = ""; } $sql = "SELECT d.id,d.discount,d.city_id,d.name as goods_name,d.img,d.icon,d.current_price,d.origin_price,d.begin_time,d.end_time,d.brief as goodsbrief,dc.name as city_name,s.name as supplier_name,d.buy_count " . 'FROM ' . DB_PREFIX . 'deal as d ' . 'left join ' . DB_PREFIX . 'deal_city as dc on dc.id = d.city_id ' . 'left join ' . DB_PREFIX . 'supplier as s on s.id = d.supplier_id ' . "where d.is_effect = 1 and d.is_delete = 0 and d.is_shop=0 and d.time_status = 1 and d.buy_status < 2 {$where} group by d.id order by d.sort desc,d.id desc"; $list = $GLOBALS['db']->getAll($sql); $xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; $xml .= "<response date=\"" . to_date($now, "r") . "\">\r\n"; foreach ($list as $item) { $url = get_domain() . url("tuan", "deal", array("id" => $item['id'])); $xml .= "<goods>\r\n"; $xml .= "<cityid>" . $item['city_id'] . "</cityid>\r\n"; $xml .= "<cityname>" . $item['city_name'] . "</cityname>\r\n"; $xml .= "<id>" . $item['id'] . "</id>\r\n"; $xml .= "<title>" . emptyTag($item['goods_name']) . "</title>\r\n"; $xml .= "<brief><![CDATA[" . $item['goodsbrief'] . "]]></brief>\r\n"; $xml .= "<url>" . convertUrl($url) . "</url>\r\n"; $xml .= "<groupprice>" . floatval($item['current_price']) . "</groupprice>\r\n"; $xml .= "<marketprice>" . floatval($item['origin_price']) . "</marketprice>\r\n"; $xml .= "<begintime>" . to_date($item['begin_time'], "r") . "</begintime>\r\n"; $xml .= "<endtime>" . to_date($item['end_time'], "r") . "</endtime>\r\n"; //对图片路径的修复 $domain = app_conf("PUBLIC_DOMAIN_ROOT") == '' ? get_domain() . APP_ROOT : app_conf("PUBLIC_DOMAIN_ROOT"); $icon = str_replace(APP_ROOT . "./public/", $domain . "/public/", $item['icon']); $icon = str_replace("./public/", $domain . "/public/", $item['icon']); $img = str_replace(APP_ROOT . "./public/", $domain . "/public/", $item['img']); $img = str_replace("./public/", $domain . "/public/", $item['img']); $xml .= "<smallimg>" . $icon . "</smallimg>\r\n"; $xml .= "<bigimg>" . $img . "</bigimg>\r\n"; $xml .= "<suppliers>" . emptyTag($item['supplier_name']) . "</suppliers>\r\n"; $xml .= "<buycount>" . $item['buy_count'] . "</buycount>\r\n"; $xml .= "</goods>\r\n";
$xml .= "<urlset>\r\n"; foreach ($list as $item) { $xml .= "<url>\r\n"; $url = SITE_DOMAIN . url("tuan", "deal", array("id" => $item['id'])); if ($item['discount'] > 0) { $rebate = number_format($item['discount'], 1); } if ($item['origin_price'] > 0) { $rebate = number_format($item['current_price'] / $item['origin_price'] * 10, 1); } else { $rebate = 0; } $begin_time = intval($item['begin_time']) > 0 ? intval($item['begin_time']) + 8 * 3600 : 0; $end_tiime = intval($item['end_time']) > 0 ? intval($item['end_time']) + 8 * 3600 : 0; $item_brief = $item['goodsbrief'] == '' ? $item['goods_name'] : $item['goodsbrief']; $xml .= "<loc>" . convertUrl($url) . "</loc>\r\n"; $xml .= "<data>\r\n"; $xml .= "<display>\r\n"; $xml .= "<website>" . app_conf("SHOP_TITLE") . "</website>\r\n"; $xml .= "<siteurl>" . SITE_DOMAIN . APP_ROOT . "</siteurl>\r\n"; $xml .= "<city>" . $item[city_name] . "</city>\r\n"; $xml .= "<title>" . emptyTag($item['goods_name']) . "</title>\r\n"; if ($GLOBALS['distribution_cfg']['OSS_TYPE'] && $GLOBALS['distribution_cfg']['OSS_TYPE'] != "NONE") { $domain = $GLOBALS['distribution_cfg']['OSS_DOMAIN']; } else { $domain = SITE_DOMAIN . APP_ROOT; } $img = str_replace(APP_ROOT . "./public/", $domain . "/public/", $item['img']); $img = str_replace("./public/", $domain . "/public/", $item['img']); $xml .= "<image>" . $img . "</image>\r\n"; $xml .= "<startTime>" . $begin_time . "</startTime>\r\n";
$end_tiime = intval($item['end_time']) > 0 ? intval($item['end_time']) + 8 * 3600 : 0; $item_brief = $item['goodsbrief'] == '' ? $item['goods_name'] : $item['goodsbrief']; $domain = app_conf("PUBLIC_DOMAIN_ROOT") == '' ? get_domain() . APP_ROOT : app_conf("PUBLIC_DOMAIN_ROOT"); $xml .= "<keyword><![CDATA[" . emptyTag($item['goods_name']) . "]]></keyword>\r\n"; $xml .= "<url>" . convertUrl($url) . "</url>\r\n"; $xml .= "<creator>" . $domain . "</creator>\r\n"; $xml .= "<title>" . emptyTag($item['goods_name']) . "</title>\r\n"; $xml .= "<publishdate>" . date('Y-m-d', $begin_time) . "</publishdate>\r\n"; $img = str_replace(APP_ROOT . "./public/", $domain . "/public/", $item['img']); $img = str_replace("./public/", $domain . "/public/", $item['img']); $xml .= "<imageaddress1>" . $img . "</imageaddress1>\r\n"; $xml .= "<imagealt1><![CDATA[" . $item['goods_name'] . "]]></imagealt1>\r\n"; $xml .= "<imagelink1>" . convertUrl($url) . "</imagelink1>\r\n"; $xml .= "<content1><![CDATA[" . emptyTag($item['sub_name']) . "]]></content1>\r\n"; $xml .= "<linktext1><![CDATA[" . emptyTag($item['sub_name']) . "]]></linktext1>\r\n"; $xml .= "<linktarget1>" . convertUrl($url) . "</linktarget1>\r\n"; //$xml.="<content2>".emptyTag($item['goods_name'])."</content2>\r\n"; $xml .= "<content2>" . round($item['origin_price'], 2) . "</content2>\r\n"; $xml .= "<content3>" . round($item['current_price'], 2) . "</content3>\r\n"; $xml .= "<content4>" . $rebate . "</content4>\r\n"; $xml .= "<content5>" . emptyTag($item['cate_name']) . "</content5>\r\n"; $xml .= "<content6>" . $item['city_name'] . "</content6>\r\n"; $xml .= "<content7>" . $item['id'] . "</content7>\r\n"; $xml .= "<linktext2>" . iconv('utf-8', 'gbk', app_conf("SHOP_TITLE")) . "</linktext2>\r\n"; $xml .= "<linktarget2>" . get_domain() . APP_ROOT . "</linktarget2>\r\n"; $xml .= "<content8>" . date('Y-m-d H:m:s', $begin_time) . "</content8>\r\n"; $xml .= "<content9>" . date('Y-m-d H:m:s', $end_tiime) . "</content9>\r\n"; $xml .= "<valid>1</valid>\r\n"; $xml .= "</item>\r\n"; } $xml .= "</datalist>\r\n";
$rebate = number_format($item['current_price'] / $item['origin_price'] * 10, 1); } else { $rebate = 0; } $begin_time = intval($item['begin_time']) > 0 ? intval($item['begin_time']) + 8 * 3600 : 0; $end_tiime = intval($item['end_time']) > 0 ? intval($item['end_time']) + 8 * 3600 : 0; $supplier = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "supplier_location where supplier_id = " . $item['supplier_id'] . " and is_main = 1"); $address = ""; if ($supplier) { $address = emptyTag($supplier['address']); $map = convertUrl("http://ditu.google.cn/maps?f=q&source=s_q&hl=zh-CN&geocode=&q=" . $supplier['api_address']); } $xml .= "<city_name>" . $item['city_name'] . "</city_name>\r\n"; $xml .= "<site_url>" . get_domain() . APP_ROOT . "</site_url>\r\n"; $xml .= "<title>" . mb_substr(emptyTag($item['goods_name']), 0, 10, 'utf-8') . "</title>\r\n"; $xml .= "<goods_url>" . convertUrl($url) . "</goods_url>\r\n"; $xml .= "<desc>" . emptyTag($item['goods_name']) . "</desc>\r\n"; if (strstr($item['cate_name'], '餐饮') != false || strstr($item['cate_name'], '美食') != false) { $cate_name = '餐饮美食'; } elseif (strstr($item['cate_name'], '休闲') != false || strstr($item['cate_name'], '娱乐') != false) { $cate_name = '休闲娱乐'; } elseif (strstr($item['cate_name'], '美容') != false || strstr($item['cate_name'], '保健') != false) { $cate_name = '美容保健'; } elseif (strstr($item['cate_name'], '精品') != false || strstr($item['cate_name'], '购物') != false) { $cate_name = '精品购物'; } elseif (strstr($item['cate_name'], '优惠') != false || strstr($item['cate_name'], '券票') != false) { $cate_name = '优惠券票'; } else { $cate_name = '其他'; } $xml .= "<class>" . $cate_name . "</class>\r\n";
function getParsedRecipe($url, &$msg) { $html = ""; if (isNullOrEmptyString($url)) { $msg = "Missing recipe URL. Recipe not created."; return null; } try { $url = convertUrl($url); $html = file_get_contents_curl($url); $recipe = parseRecipe($html, $url); if ($recipe->ingredients() == null || count($recipe->ingredients()->get()) == 0 || !isset($recipe->Directions) || $recipe->Directions == '') { $recipe->RecipeName = "*PARTIAL* " . $recipe->RecipeName; $recipe->save(); $msg = "Recipe partially created."; } else { $msg = "Recipe created."; } return $recipe; } catch (Exception $e) { //$msg = "Fail. ".$e->getMessage(); //return null; } try { $title = getPageTitle($html); if (isNullOrEmptyString($title)) { $title = $url; } $recipe = new Recipe(); $recipe->RecipeName = "*PARTIAL* " . $title; $recipe->RecipeNote = $url; $recipe->save(); $msg = "Recipe partially created."; return $recipe; } catch (Exception $e) { $msg = "Recipe not created. " . $e->getMessage(); return null; } }