public static function getArticleCommentUrl($paramArr = array()) { $options = array('class_id' => 0, 'docId' => 0, 'type' => 0); $options = array_merge($options, $paramArr); extract($options); #获得频道ID与评论ID的对应 $Cls2cmtArr = ZOL_Api::run("Article.Comment.classToComment", array('typeId' => 1)); $url = "http://comments.zol.com.cn/"; if (!isset($Cls2cmtArr[$class_id])) { return $url; } $cmtClsId = $Cls2cmtArr[$class_id]; $url .= "{$cmtClsId}/{$docId}_{$type}_1.html"; return $url; }
/** * 将k-val数组值的首字符显示出来 */ public static function firstCharArr($paramArr = array()) { $options = array('data' => array()); $options = array_merge($options, $paramArr); extract($options); if ($data) { foreach ($data as $key => &$val) { $val = trim($val); $firstChar = ZOL_Api::run("Base.String.getFirstLetter", array('input' => $val)); $val = $firstChar . '_' . $val; } asort($data); } return $data; }
/** * 往mongo中存一组数,用于计算平均值 * 传入一个int或者float类型 */ function storage_tmp_data($data) { #缓存key $cacheKey = 'Guess_you_like:tmp_data_average:guess1_1'; $mDataArr = ZOL_Api::run("Kv.MongoCenter.get", array('module' => 'cms', 'tbl' => 'zol_index', 'key' => $cacheKey)); if (!$mDataArr || !is_array($mDataArr)) { $mDataArr = array(); } $mDataArr[] = $data; #写入缓存 ZOL_Api::run("Kv.MongoCenter.set", array('module' => 'cms', 'tbl' => 'zol_index', 'key' => $cacheKey, 'data' => $mDataArr, 'life' => 3600)); return true; }
/** * 检查文章大黑字是否是当天的文章 */ function checkIsTodayArticle($docId) { if (!$docId) { return false; } $dataArr = ZOL_Api::run("Article.Doc.getDocInfo", array('docId' => $docId, 'rtnCols' => 'pub_date')); return strtotime($dataArr['pub_date']) < strtotime(date('Y-m-d 00:00:00')) ? false : true; }
/** * 产品线搜索 */ public function doSubcateSuggestion(ZOL_Request $input, ZOL_Response $output) { $callback = $input->get('jsoncallback'); $keyword = htmlspecialchars($input->get('keyword')); if ($callback && $keyword) { $json = array(); if ($keyword) { $dataArr = ZOL_Api::run("Pro.Cate.getSubcateByDb", array('name' => $keyword, 'num' => 10, 'noSecond' => 1)); if ($dataArr) { foreach ($dataArr as $key => $val) { $json[] = '<font rel="' . $val['subcateId'] . '">' . iconv('gbk', 'utf-8', $val['name']) . '</font>'; } } $json = array_unique($json); } $json = $callback . '(' . json_encode($json) . ')'; echo $json; } exit; }
/** * 获取指定文章打赏成功的用户 */ public static function doGetRewardUser(ZOL_Request $input, ZOL_Response $output) { $articleId = $input->request('articleId'); $callback = $input->request('callback'); $articleId = 5591168; if (!$articleId) { Helper_Reward_RewardFunc::ajaxExit(array('flag' => 'error', 'msg' => '文章id未知!', 'toLog' => 0)); } $res1 = Helper_Reward_RewardModel::getRewardUser(array('articleId' => $articleId, 'orderStatus' => 1, 'debug' => 0)); //var_dump($res1); if ($res1['data']) { # 获取用户的头像,先获取6个用户名 $userArr = $guestUserArr = array(); foreach ($res1['data'] as $k => $v) { if ($v['custmer'] == 'guest') { $guestUserArr[] = $v; } else { $userArr[] = $v; } } $userArr = array_merge($userArr, $guestUserArr); $i = 1; foreach ($userArr as $k => $v) { if ($i > 6) { break; } if ($v['custmer'] == 'guest') { continue; } $dataArr = ZOL_Api::run("User.Base.getUserInfo", array('userid' => $v['custmer'], 'rtnCols' => 'photo,nickName')); $userArr[$k]['photo'] = $dataArr['photo']; $userArr[$k]['nickName'] = $dataArr['nickName']; $userArr[$k]['myCenter'] = 'http://my.zol.com.cn/' . $v['custmer']; $i++; } #var_dump($userArr);exit(); Helper_Reward_RewardFunc::ajaxExit(array('flag' => 'success', 'data' => $userArr, 'callback' => $callback, 'totalCount' => $res1['totalCount'], 'toLog' => 0)); } else { Helper_Reward_RewardFunc::ajaxExit(array('flag' => 'error', 'data' => '没有数据!', 'toLog' => 0)); } }
public static function getSubcateIdByName($paramArr) { $options = array('nameData' => array()); if (is_array($paramArr)) { $options = array_merge($options, $paramArr); } extract($options); if (!$nameData) { return fasle; } $returnData = array(); $errorData = array(); #获取所有产品线 数据 $dataArr = ZOL_Api::run("Pro.Cate.getSubCate", array('showHiden' => 0)); foreach ($nameData as $key => $val) { $key = trim($key); $keyId = 0; $valId = 'array('; $val = trim($val); $nameArr = explode("、", $val); foreach ($dataArr as $sdata) { if ($key == $sdata['name']) { $keyId = $sdata['id']; break; } } foreach ($nameArr as $name) { $finded = false; foreach ($dataArr as $sdata) { if (trim($name) == trim($sdata['name'])) { $valId .= $sdata['id'] . ','; $finded = true; break; } } if (false == $finded) { #如果没有找到 去otherName 里面找 foreach ($dataArr as $sdata) { if (isset($sdata['otherName'])) { $otherName = explode(",", $sdata['otherName']); if ($sdata['otherName'] && $otherName && in_array(trim($name), $otherName)) { $valId .= $sdata['id'] . ','; $finded = true; break; } } } } if (false == $finded) { if (isset($errorData[$key])) { $errorData[$key] .= $name . ','; } else { $errorData[$key] = $name . ','; } } } $valId .= $keyId . '),#' . $key . ':' . $val; #最后加上自己本身的产品线 $returnData['src'][$key] = $val; #元数据做对比 $returnData['error'] = $errorData; #错误数据,即没有找到匹配的数据 $returnData['val'][$keyId] = $valId; #匹配的数据,如果error数组里没数据,直接用 } return $returnData; }
/** * 执行API的方法 */ public static function run($method, $param = false) { if (!$method) { return false; } $method = str_replace(".", "_", $method); $class = "API_Item_" . substr($method, 0, strrpos($method, "_")); $func = substr($method, strrpos($method, "_") + 1); self::$_nowMethod = $method; //通过私有云run调用 $data = call_user_func_array(array($class, $func), array($param)); #返回结果的处理 #格式如id,name,age *(id,name) id,row(tm,name) colorArr(*(name)) if ($data && is_array($data) && isset($param['rtnCols']) && $param['rtnCols']) { $level1Arr = array(); #第一维 $level2Arr = array(); #第二维 $level3Arr = array(); #第三维 #下面正则的作用:因为不过多维都是用逗号分割字段,id,row(tm(se,fr),name) 不好区分, #第三维用# 第二维用+ id,row(tm(se#fr)+name) $rtnCols = preg_replace_callback("#\\(.*\\(.*(,).*\\).*\\)#isU", create_function('$matches', 'return str_replace(",","#",$matches[0]);'), $param['rtnCols']); $rtnCols = preg_replace_callback("#\\(.*(,).*\\)#isU", create_function('$matches', 'return str_replace(",","+",$matches[0]);'), $rtnCols); $tmpArr = explode(",", $rtnCols); $l1Star = $l2Star = false; #第一维是否是* foreach ($tmpArr as $v) { $v = trim($v); if ($lp = strpos($v, '(')) { $v2 = substr($v, $lp + 1, -1); $v = substr($v, 0, $lp); $l1Star = $v == '*'; #第三维的处理 if ($lp2 = strpos($v2, '(')) { $v3 = substr($v2, $lp2 + 1, -1); $v2 = substr($v2, 0, $lp2); $l2Star = $v2 == '*'; $level3Arr[$v2] = explode("#", $v3); } $level2Arr[$v] = explode("+", $v2); } $level1Arr[] = $v; } $newData = array(); #对返回数据进行字段过滤处理 foreach ($data as $kk => $vv) { #符合第一维的限制 if ($l1Star || in_array($kk, $level1Arr)) { #如果是*,或是指定的key #如果第二维有限制 if ((isset($level2Arr[$kk]) || isset($level2Arr['*'])) && is_array($vv)) { $newVv = array(); foreach ($vv as $kk2 => $vv2) { #echo $kk; #print_r($level2Arr[$kk]); if (isset($level2Arr[$kk]) && (in_array($kk2, $level2Arr[$kk]) || in_array('*', $level2Arr[$kk])) || isset($level2Arr['*']) && in_array($kk2, $level2Arr['*'])) { #如果第三维有限制 如 color(*(name)) if ((isset($level3Arr[$kk2]) || isset($level3Arr['*'])) && is_array($vv2)) { $newVv2 = array(); foreach ($vv2 as $kk3 => $vv3) { if (isset($level3Arr[$kk2]) && in_array($kk3, $level3Arr[$kk2]) || isset($level3Arr['*']) && in_array($kk3, $level3Arr['*'])) { $newVv2[$kk3] = $vv3; } } $vv2 = $newVv2; } $newVv[$kk2] = $vv2; } } $vv = $newVv; } $newData[$kk] = $vv; } } $data = $newData; } //<<返回数据处理完毕 if (ZOL_API_UTF8 && $data) { $data = self::toUTF8($data); # array_walk_recursive($data, "api_json_convert_encoding_g2u"); return $data; } return $data; }
defined('ZOL_API_UTF8') || define('ZOL_API_UTF8', false); defined('ZOL_API_DEBUG') || define('ZOL_API_DEBUG', false); defined('ZOL_API_LOG') || define('ZOL_API_LOG', ZOL_API_ROOT . "/Log"); if (!ZOL_API_ISFW) { defined('SYSTEM_TIME') || define('SYSTEM_TIME', isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time()); defined('SYSTEM_DATE') || define('SYSTEM_DATE', date('Y-m-d H:i:s', SYSTEM_TIME)); defined('IS_DEBUGGING') || define('IS_DEBUGGING', false); } //引入配置文件 require_once ZOL_API_BASE . '/ApiConfig.php'; spl_autoload_register(array('ZOL_Api', 'autoload')); if (!ZOL_API_ISFW) { //如果不是ZOL框架,配置自动加载,模拟一下框架的相关文件 // 将ZOL_Api的自动加载包含进来 foreach (array('Db', 'ZOL') as $nv) { ZOL_Api::setNameSpace(ZOL_API_ROOT . '/' . $nv); } } if (!function_exists('get_called_class')) { function get_called_class() { $bt = debug_backtrace(); $lines = file($bt[1]['file']); preg_match('/([a-zA-Z0-9\\_]+)::' . $bt[1]['function'] . '/', $lines[$bt[1]['line'] - 1], $matches); return $matches[1]; } } /** * json的相关处理 */ function api_json_encode($value)
/** * 文章页壁纸精选(软件频道) wuhw add 2015-02-25 * */ public static function getDeskInfo($array) { defined('ZOL_API_ISFW') || define('ZOL_API_ISFW', false); //是否使用ZOL新框架,true为使用 require_once '/www/zdata/Api.php'; //引入私有云入口文件 $start = rand(0, 40); #美女壁纸 $meinv = ZOL_Api::run("Desk.DeskList.getList", array('pageType' => 1, 'cate' => 3, 'picSize' => '120x90', 'isDown' => 1, 'limit' => $start . ',10')); #明星壁纸 $mingxing = ZOL_Api::run("Desk.DeskList.getList", array('pageType' => 1, 'cate' => 4, 'picSize' => '120x90', 'isDown' => 1, 'limit' => $start . ',10')); #风景壁纸 $fengjing = ZOL_Api::run("Desk.DeskList.getList", array('pageType' => 1, 'cate' => 6, 'picSize' => '120x90', 'isDown' => 1, 'limit' => $start . ',10')); #动漫壁纸 $dongman = ZOL_Api::run("Desk.DeskList.getList", array('pageType' => 1, 'cate' => 14, 'picSize' => '120x90', 'isDown' => 1, 'limit' => $start . ',10')); #手机壁纸 $sjBizhi = ZOL_Api::run("Mobile.MobileBiZhiNew.getGroupInfo", array('g_order' => 2, 'z_jqtype' => 2, 'g_recommend' => 1, 'z_showlink' => 1, 'p_src' => '120x90', 'z_limit' => $start . ',10')); $str = '<div class="module"> <div class="module-header"><h3>精美壁纸推荐</h3></div> <ul class="rank-tab switch clearfix"> <li class="first current" rel="tab_list_1">美女</li> <li rel="tab_list_2">明星</li> <li rel="tab_list_3">风景</li> <li rel="tab_list_4">动漫</li> <li rel="tab_list_5">手机</li> </ul> <div id="tab_list_1" class="game-rec">'; if ($meinv['list']) { $str .= '<ul class="game-rec-list clearfix">'; foreach ($meinv['list'] as $k => $v) { if ($k > 3) { break; } $str .= '<li> <a href="' . $v['detailUrl'] . '"> <img width="120" height="90" alt="" src="' . $v['fileName'] . '"> <span>' . $v['name'] . '</span> </a> </li>'; } $str .= '</ul> <ul class="news-list">'; foreach ($meinv['list'] as $k => $v) { if ($k <= 3) { continue; } $str .= '<li> <a title="' . $v['name'] . '" href="' . $v['detailUrl'] . '">' . $v['name'] . '</a> </li>'; } $str .= '</ul>'; } $str .= '</div> <div id="tab_list_2" class="game-rec" style="display:none">'; if ($mingxing['list']) { $str .= '<ul class="game-rec-list clearfix">'; foreach ($mingxing['list'] as $k => $v) { if ($k > 3) { break; } $str .= '<li> <a href="' . $v['detailUrl'] . '"> <img width="120" height="90" alt="" src="' . $v['fileName'] . '"> <span>' . $v['name'] . '</span> </a> </li>'; } $str .= '</ul> <ul class="news-list">'; foreach ($mingxing['list'] as $k => $v) { if ($k <= 3) { continue; } $str .= '<li> <a title="' . $v['name'] . '" href="' . $v['detailUrl'] . '">' . $v['name'] . '</a> </li>'; } $str .= '</ul>'; } $str .= '</div> <div id="tab_list_3" class="game-rec" style="display:none">'; if ($fengjing['list']) { $str .= '<ul class="game-rec-list clearfix">'; foreach ($fengjing['list'] as $k => $v) { if ($k > 3) { break; } $str .= '<li> <a href="' . $v['detailUrl'] . '"> <img width="120" height="90" alt="" src="' . $v['fileName'] . '"> <span>' . $v['name'] . '</span> </a> </li>'; } $str .= '</ul> <ul class="news-list">'; foreach ($fengjing['list'] as $k => $v) { if ($k <= 3) { continue; } $str .= '<li> <a title="' . $v['name'] . '" href="' . $v['detailUrl'] . '">' . $v['name'] . '</a> </li>'; } $str .= '</ul>'; } $str .= '</div> <div id="tab_list_4" class="game-rec" style="display:none">'; if ($dongman['list']) { $str .= '<ul class="game-rec-list clearfix">'; foreach ($dongman['list'] as $k => $v) { if ($k > 3) { break; } $str .= '<li> <a href="' . $v['detailUrl'] . '"> <img width="120" height="90" alt="" src="' . $v['fileName'] . '"> <span>' . $v['name'] . '</span> </a> </li>'; } $str .= '</ul> <ul class="news-list">'; foreach ($dongman['list'] as $k => $v) { if ($k <= 3) { continue; } $str .= '<li> <a title="' . $v['name'] . '" href="' . $v['detailUrl'] . '">' . $v['name'] . '</a> </li>'; } $str .= '</ul>'; } $str .= '</div> <div id="tab_list_5" class="game-rec" style="display:none">'; if ($sjBizhi) { $str .= '<ul class="game-rec-list clearfix">'; foreach ($sjBizhi as $k => $v) { if ($k > 3) { break; } $str .= '<li> <a href="http://sj.zol.com.cn' . $v['z_grouplink'] . '"> <img width="120" height="90" alt="' . $v['g_name'] . '" src="' . $v['p_src'] . '" > <span>' . $v['g_name'] . '</span> </a> </li>'; } $str .= '</ul> <ul class="news-list">'; foreach ($sjBizhi as $k => $v) { if ($k <= 3) { continue; } $str .= '<li> <a title="' . $v['g_name'] . '" href="http://sj.zol.com.cn' . $v['z_grouplink'] . '">' . $v['g_name'] . '</a> </li>'; } $str .= '</ul>'; } $str .= '</div> </div> <!--end r_bd-->'; if ($array['classId'] == '228') { $str .= "<div class='module'><script>write_ad('doc_new_bottom');</script></div>"; } return $str; }
/** * 将没有分词的文章id记录入日志,存在mogoDb中 * @params int $msg 记录的article_id */ function toLog($msg) { return false; if (!$msg) { return false; } $str .= $msg . ','; $key = 'guess_you_like_logo'; # 获取之前的值 # 从mongo中查看是否有数据 $getDataArr = ZOL_Api::run("Kv.MongoCenter.get", array('module' => 'cms', 'tbl' => 'zol_index', 'key' => $key)); if ($getDataArr && is_array($getDataArr)) { $getDataArr[] = $msg; } else { $getDataArr = array(); $getDataArr[] = $msg; } #并且将其存放在mongo缓存中 ZOL_Api::run("Kv.MongoCenter.set", array('module' => 'cms', 'tbl' => 'zol_index', 'key' => $key, 'data' => $getDataArr, 'life' => 7 * 24 * 3600)); return true; }