public function index($param) { global $_W, $_P; //获取插件配置 $config = Amango_Addons_Config('Sharephotos'); $nowtime = time(); if (!empty($_W['picurl'])) { //限制每天分享的图片数量 $todaystart = strtotime(date('Y-m-d 00:00:00', $nowtime)); $todayend = strtotime(date('Y-m-d 23:59:59', $nowtime)); $condition = array('from' => $_P['fromusername'], 'sharetime' => array('egt', $todaystart), 'sharetime' => array('elt', $todayend)); $hassharenums = M('Addonssharepics')->where($condition)->count(); if ($hassharenums >= $config['shareitmes']) { $this->assign('Text', "[可怜]亲~您今天已分享了" . $config['shareitmes'] . "次\n请明天再分享吧!"); $this->display(); } $article[0] = array('Title' => "分享图片成功", 'Description' => "请回复下你对这张照片的评价吧~", 'PicUrl' => $_W['picurl'], 'Url' => $_W['picurl']); //锁定图片分享模式 $this->lock('model', 'Sharephotos'); //缓存微信图片链接 $this->cache('sharepicurl', $_W['picurl']); $this->assign('Duotw', $article); $this->display(); } else { //判断是否存在模式锁定 $lastmodel = $this->locked('model'); $urlcache = $this->cache('sharepicurl'); if (!empty($lastmodel) && !empty($_W['content']) && !empty($urlcache)) { //远程保存图片至本地数据库 $urldown = $this->savepics($urlcache); //将照片地址写入数据库 初始化浏览量为1 $data = array('from' => $_P['fromusername'], 'nickname' => $_P['nickname'], 'picurl' => $urldown, 'sharetime' => $nowtime, 'content' => $_W['content'], 'views' => 1, 'status' => $config['random']); M('Addonssharepics')->add($data); //清除缓存 $this->cache('sharepicurl', NULL); //清除模块锁定 $this->lock('model', ''); //评价照片 $commonurl = $this->create_loginurl('index'); $article[0] = array('Title' => "分享图片成功", 'Description' => "分享理由:" . $_W['content'], 'PicUrl' => $urlcache, 'Url' => $commonurl); $this->assign('Duotw', $article); $this->display(); } else { //展示图片分享内容 底部附带分享方法 $article[0] = array('Title' => "精彩美图,随手分享", 'Description' => "", 'PicUrl' => str_replace('./', 'http://' . $_SERVER['HTTP_HOST'] . '/', ONETHINK_ADDON_PATH . 'Sharephotos/Public/banner.jpg'), 'Url' => $this->create_loginurl('index')); $gebi = array_merge($article, $this->show(6)); $this->assign('Duotw', $gebi); $this->display(); } } wx_error(json_encode($_W)); die; wx_success('Hello World!这是图吧的微信Bundle!'); }
protected function train($param) { global $_W; $_W['content'] = str_replace('公交', '', $_W['content']); $_W['content'] = str_replace(' ', '', $_W['content']); $userpost = explode('到', $_W['content']); $userfrom = empty($userpost[0]) ? $config['origin'] : $userpost[0]; $userto = empty($userpost[1]) ? $config['region'] : $userpost[1]; if (empty($userto)) { wx_error("亲:目的地不能为空哦\n公交查询格式\n公交**到**"); } //获取该插件配置参数 $config = Amango_Addons_Config(); $config['trainak'] || wx_error('请联系站长填写公交API的密匙'); $config['where'] || wx_error('请联系站长填写一个默认所在的省市,例如:石狮,厦门'); $direc = 'http://api.map.baidu.com/direction/v1?mode=transit&origin=' . urlencode($userfrom) . '&destination=' . urlencode($userto) . '®ion=' . urlencode($config['where']) . '&output=json&ak=' . $config['trainak']; $Fisr_result = file_get_contents($direc); $Fisrresult = json_decode($Fisr_result, true); $errorMsg[2] = '参数错误'; $errorMsg[5] = '权限或配额校验失败'; if ($Fisrresult['status'] != 0) { wx_error($errorMsg[$Fisrresult['status']]); } if ($Fisrresult['type'] == 1) { $resultStr = ''; foreach ($Fisrresult['result']['origin'] as $key => $value) { $result .= $value['name'] . "\n"; } wx_error("亲:公交查询格式\n********到********\n出发地不明确,请输入下列地址\n" . $result); } if ($Fisrresult['type'] == 2) { $resultStr = ''; $resultinfo = ''; foreach ($Fisrresult['result']['routes'] as $key => $value) { $result .= "--路线" . ($key + 1) . "-----\n"; $resultinfo = ''; foreach ($value['scheme'][0]['steps'] as $ke => $va) { $resultinfo .= $ke + 1 . "):" . strip_tags($va[0]['stepInstruction']) . "\n"; } $result .= $resultinfo; if ($key == 1) { break; } } $replycontext['Content'] = "【公交】" . $userfrom . "=>" . $userto . "\n" . $result; $this->assign('Text', $replycontext); $this->display(); } wx_error("亲:目的地不能为空哦\n公交查询格式\n公交**到**"); }
public function sharepicsajax() { $config = Amango_Addons_Config('Sharephotos'); $model = M('Addonssharepics'); $total = $model->where(array('status' => 1))->count(); $listRows = $config['pagenums'] > 0 ? $config['pagenums'] : 5; $page = new \Think\Page($total, $listRows); $list = $model->where(array('status' => 1))->limit($page->firstRow . ',' . $page->listRows)->select(); $newlist = array(); foreach ($list as $key => $value) { $rangdheight = rand(10, 20); $newlist[] = array('tid' => $value['id'], 'subject' => $value['content'], 'author' => $value['nickname'], 'views' => $value['views'], 'pid' => $value['sharetime'], 'thumb' => $value['picurl'], 'picHeight' => $rangdheight); } $this->ajaxReturn($newlist); }
public function show($where, $limit = 1) { //获取配置 $config = Amango_Addons_Config(); $limit = $limit == 0 ? 1 : $limit; $nums = $config['nums'] >= 1 ? $config['nums'] : $limit; // //$to 可能为多用户 // //获取本地隔壁动态 至少一条 $lists = M('Addonsneighbours')->where(array('to' => ''))->order('creattime desc')->order('rand()')->field('id,from,location,creattime,view,sharetype,to,school,content')->limit($nums)->select(); //$lists = D('Addons://Neighbours/AddonsneighboursView')->select(); $newlist = array(); $usermodel = M('Weixinmember'); foreach ($lists as $key => $value) { $nickname = $usermodel->where(array('id' => $value['from']))->getField('nickname'); if ($value['sharetype'] == 'text') { $randnum = rand(1, 6); $randimg = 'http://' . $_SERVER['HTTP_HOST'] . '/Addons/Neighbours/Public/images/default_head' . $randnum . '.png'; $newlist[$key] = array('Title' => "-" . $nickname . "-刚在隔壁说:\n" . $value['content'], 'Description' => "", 'PicUrl' => $randimg, 'Url' => U('Home/Addons/execute', array('_addons' => 'Neighbours', '_controller' => 'Home', '_action' => 'index', 'id' => $value['id']), '', true)); } if ($value['sharetype'] == 'picture') { $newlist[$key] = array('Title' => "-" . $nickname . "-在隔壁分享了一张照片", 'Description' => "", 'PicUrl' => $value['content'], 'Url' => ""); } } //判断是否有外大学提醒缓存 $tips = S('Neighbours_tip'); if (empty($tips)) { $tips = ',厦门工学院'; $schoolinfo = explode(',', $tips); unset($schoolinfo[0]); //读取外校授权列表 $othertips = array(); $other = parse_config($config['dsfjr']); foreach ($schoolinfo as $key => $value) { //判断该学校是否在名下 if (!empty($other[$value])) { $urllist[] = $other[$value]; } } $othertips = $this->readOther($urllist); } return $newlist; }
public function index() { //获取该插件配置参数 $config = Amango_Addons_Config(); //查看缓存是否存在 $article = S('ADDONS_SnatchTieba'); if (empty($article)) { Amango_Addons_Import('phpQuery/phpQuery.php'); \phpQuery::$defaultCharset = 'GBK'; \phpQuery::newDocumentFile('http://tieba.baidu.com/f?kw=' . urlencode($config['tieba_name']) . '&fr=ala0'); $articlecontent = array(); $artlist = \pq(".j_thread_list"); foreach ($artlist as $li) { //获取评论数 $tz_commont = iconv('GBK', 'UTF-8', \pq($li)->find('.threadlist_rep_num')->html()); //获取标题 $tz_title = iconv('GBK', 'UTF-8', \pq($li)->find('a.j_th_tit')->html()); //获取内容 $tz_content = iconv('GBK', 'UTF-8', \pq($li)->find('.threadlist_abs_onlyline')->html()); $tz_content = preg_replace('/s/', '', $tz_content); $tz_content = str_replace('<!---->', '', $tz_content); //获取链接 $tz_link = 'http://tieba.baidu.com' . iconv('GBK', 'UTF-8', \pq($li)->find('a.j_th_tit')->attr('href')); //获取作者 $tz_author = strip_tags(iconv('GBK', 'UTF-8', \pq($li)->find('span.tb_icon_author a')->html())); $tz_author = preg_replace('/s/', '', $tz_author); //获取回复者 $tz_reply = iconv('GBK', 'UTF-8', \pq($li)->find('span.tb_icon_author_rely a')->html()); //获取回复时间 $tz_replytime = \pq($li)->find('span.j_reply_data')->text(); $tz_replytime = preg_replace('/s/', '', $tz_replytime); //获取图片 $tz_pic = iconv('GBK', 'UTF-8', \pq($li)->find('img')->attr('original')); if (!in_array($tz_title, $toptitle)) { $articlecontent['other'][] = array('Title' => 1 == $config['tieba_extra'] ? "[" . $tz_commont . "]" . $tz_title . "\n" . $tz_content . "\n作者:" . $tz_author . "|回复:" . $tz_reply . "-" . $tz_replytime : $tz_title . "\n" . $tz_content, 'Description' => '', 'PicUrl' => empty($tz_pic) ? '' : $tz_pic, 'Url' => $tz_link); } } $allownums = $config['tieba_nums'] > 8 ? 8 : $config['tieba_nums']; $allownums = $allownums >= 1 ? $allownums : 1; if ($config['tieba_jinghua'] == 1) { $arttoplist = \pq(".thread_top"); foreach ($arttoplist as $li) { //获取评论数 $tz_commont = iconv('GBK', 'UTF-8', \pq($li)->find('.threadlist_rep_num')->html()); //获取标题 $tz_title = iconv('GBK', 'UTF-8', \pq($li)->find('a.j_th_tit')->html()); //获取链接 $tz_link = 'http://tieba.baidu.com' . iconv('GBK', 'UTF-8', \pq($li)->find('a.j_th_tit')->attr('href')); //获取作者 $tz_author = strip_tags(iconv('GBK', 'UTF-8', \pq($li)->find('span.tb_icon_author a')->html())); $toptitle[] = $tz_title; $tz_author = preg_replace('/s/', '', $tz_author); $articlecontent['top'][] = array('Title' => "[" . $tz_commont . "]" . $tz_title, 'Description' => '', 'PicUrl' => empty($tz_pic) ? '' : $tz_pic, 'Url' => $tz_link); } $article = self::havejinghua($articlecontent['top'], $articlecontent['other'], $allownums); } else { $article = self::deljinghua($articlecontent['other'], $allownums); } \phpQuery::unloadDocuments(); if ($config['tieba_cache'] > 0 && !empty($article)) { S('ADDONS_SnatchTieba', $article, $config['tieba_cache']); } } $this->assign('Duotw', $article); $this->display(); }