Ejemplo n.º 1
0
 /**
  * 微信信息接口 http://www.zhbor.com/index.php?c=Api_Weixin&a=Weixin
  * 
  * 接口实现用户回复数字 返回数字对应的分类文章的url 关注微信 爱科技:hongbozxz
  */
 public function doWeixin(LJL_Request $input, LJL_Response $output)
 {
     $articleCate = self::_getCate();
     $db = Db_Blog::instance(null, 'blog_cui');
     // 		    $logPath = APP_PATH.'/Page/Api/log.php';
     // 		    file_put_contents($logPath, json_encode($db), FILE_APPEND);
     $resieveMsg = LJL_Api::run('Open.Weixin.receiveMsg', array('subscribeCallback' => 'subscribe'));
     $content = (string) $resieveMsg['Content'];
     // 		    echo LJL_Api::run('Open.Weixin.answerText',array(
     // 		        'content' => $content,
     // 		    ));die();
     //错误关键字 回复提示信息
     if (!is_numeric($content)) {
         if (mt_rand(0, 2)) {
             self::_robotAnswer($content);
         } else {
             self::_notice();
         }
     }
     $classid = substr($content, 0, 1);
     $page = substr($content, 1) ? substr($content, 1) : 1;
     //限制分类
     if ($classid > 7 || $classid < 1) {
         $this->_notice('分类在 1-7 之间');
     }
     $articleList = Helper_Blog::getArticleList(array('fields' => array('id', 'firstImgId', 'title', 'descript'), 'page' => $page, 'pageSize' => 5, 'cate' => $articleCate[$classid][0]));
     if ($articleList) {
         self::_articleList($articleList);
     } else {
         self::_noArticle($classid, $page);
     }
 }
Ejemplo n.º 2
0
 public function doDefault(LJL_Request $input, LJL_Response $output)
 {
     #如果是提交
     //var_dump($input->dopost);die;
     if ($input->dopost && $input->funName) {
         #获得所有需要参数的值
         $iparam = $output->helpCfgArr2[$input->funName]['param'];
         //var_dump($iparam);die;
         $paramVal = array();
         if ($iparam) {
             foreach ($iparam as $p) {
                 $paramValArr[$p[0]] = $input->post($p[0]);
             }
         }
         if (isset($paramValArr)) {
             foreach ($paramValArr as $k => $v) {
                 if ($v == '') {
                     unset($paramValArr[$k]);
                 }
             }
             $paramValArr = $output->paramValArr = $paramValArr;
             // array_filter($paramValArr);
         } else {
             $paramValArr = array();
             $output->paramValArr = $paramValArr;
         }
         #获得结果
         $tmpArr = explode("::", $input->funName);
         $className = "Helper_" . $tmpArr[0];
         //var_dump($className);die;
         $classMethod = $tmpArr[1];
         #特殊处理
         if ('Helper_Blog' == $className && in_array($classMethod, array('getArticleList', 'getArticleInfo'))) {
             Db_Blog::instance(null, 'blog_laura');
         }
         if (isset($output->helpCfgArr2[$input->funName]['norun'])) {
             $output->htmlVarStr = $output->helpCfgArr2[$input->funName]['norun'];
         } else {
             $data = call_user_func(array($className, $classMethod), $paramValArr);
             $output->htmlVarStr = Libs_Tools_VarDump::showVar($data);
         }
     }
     $output->setTemplate('HelperManage');
 }
Ejemplo n.º 3
0
 public function quchongexec($input)
 {
     $db = Db_Blog::instance(null, $this->website);
     $sql = "SELECT id,source FROM `blog_article_info` GROUP BY {$this->refield} HAVING COUNT(id)>1";
     $res = $db->getAll($sql);
     if (!$res) {
         $this->isrepeat = false;
         return;
     }
     foreach ((array) $res as $artInfo) {
         //$sql = "delete from blog_img where articleId='{$artInfo['id']}'";
         //$db->query($sql);
         $sql = "update `blog_article_info` set isPublished=-1 where id='{$artInfo['id']}'";
         $db->query($sql);
         $sql = "delete from `blog_article_content` where articleId='{$artInfo['id']}'";
         $db->query($sql);
         echo $artInfo['id'] . ' del' . PHP_EOL;
     }
     //var_dump($res);die;
 }
Ejemplo n.º 4
0
 private function makeDetailPage($database, $catekey)
 {
     if (!$catekey) {
         return;
     }
     Db_Blog::instance(null, $database);
     $website = substr($database, 5);
     //获取文章总数
     $count = Helper_Blog::getArticleList(array('isCount' => 1));
     $page = 1;
     $pageSize = 100;
     $totalPage = ceil($count / $pageSize);
     while ($totalPage >= $page) {
         $articleInfo = Helper_Blog::getArticleList(array('page' => $page, 'pageSize' => $pageSize, 'fields' => array('id'), 'isPublished' => 1, 'cate' => $catekey));
         if ($articleInfo) {
             foreach ($articleInfo as $val) {
                 $this->stobj->urlItem('http://' . $website . '.' . MAIN_PAGE . '/article/' . $val['id'] . '.html');
             }
         }
         $page++;
         if ($page * $pageSize % 5000 == 0) {
             //每5000条生成新的sitemap文件
             $this->saveasSiemap($database, $catekey, $page);
         }
         if ($page % 10 === 0) {
             //每10页sleep
             sleep(1);
         }
     }
     $this->saveasSiemap($database, $catekey);
 }
Ejemplo n.º 5
0
 /**
  * 导入标签,如果指定了天数,则就从指定前几天,如果没有指定天数,则从上一次插入的时间开始
  * @param LJL_Request $input
  * @param unknown $database
  */
 private function importTag(LJL_Request $input, $database)
 {
     $db = Db_Blog::instance(null, $database);
     if ($input->get('day')) {
         $day = $input->get('day') ? $input->get('day') : 1;
         //默认1天
         $fromInsertTime = SYSTEM_TIME - $day * 24 * 3600;
     } else {
         $sql = "select updateTime from blog_tags order by id desc limit 1";
         $fromInsertTime = $db->getOne($sql);
         $fromInsertTime = $fromInsertTime ? $fromInsertTime : 0;
     }
     //获取总数
     $sql = "select count(*) from blog_article_info where isPublished=1 and updateTime>{$fromInsertTime}";
     $count = $db->getOne($sql);
     $page = 1;
     $pageSize = 100;
     $totalPage = ceil($count / $pageSize);
     while ($totalPage >= $page) {
         $articleInfo = Helper_Blog::getArticleList(array('page' => $page, 'pageSize' => $pageSize, 'fields' => array('id', 'cate', 'tags'), 'updateTime' => $fromInsertTime));
         if ($articleInfo) {
             foreach ($articleInfo as $val) {
                 if (!$val['tags']) {
                     continue;
                 }
                 $tagArr = explode(',', trim(trim($val['tags'], ' '), ','));
                 foreach ($tagArr as $tag) {
                     Helper_Blog::insertTag(array('insertData' => array('articleId' => $val['id'], 'cate' => $val['cate'], 'tag' => $tag, 'updateTime' => SYSTEM_TIME)));
                 }
             }
         }
         $page++;
     }
     echo $database . ' tags import over' . PHP_EOL;
 }
Ejemplo n.º 6
0
 /**
  * 插入文章
  */
 private function insertArticle($url, $title, $content)
 {
     if (!$title || !$content) {
         return;
     }
     $db = Db_Blog::instance(null, $this->website);
     //已有该文章则退出
     $title = htmlspecialchars(strip_tags(addslashes(str_replace("'", '"', $title))));
     if (Helper_Blog::ishasArticle('', $title)) {
         return;
     }
     //echo $title;die;
     //对于有图片的文章进行搬运图片处理
     preg_match_all("/<img src=\"(.*?)\"/", $content, $matches, PREG_SET_ORDER);
     $imgidArr = array();
     if ($matches) {
         if (count($matches) > 10) {
             return;
         }
         foreach ((array) $matches as $imgsrc) {
             $imgInfo = $this->getImgNameDir();
             if (!$imgsrc[1]) {
                 continue;
             }
             //1、移动图片
             exec('wget -q --tries=3 -O ' . rtrim($imgInfo[1], '/') . '/' . $imgInfo[0] . '.jpg ' . $imgsrc[1]);
             //2、向自己库中插入图片
             $imgidArr[] = Helper_Blog::insertPic(array('picName' => $imgInfo[0], 'picExt' => 'jpg', 'time' => $imgInfo[3]));
             //3、图片地址字符串替换
             $content = str_replace($imgsrc[1], $imgInfo[2] . '/' . $imgInfo[0] . '.jpg', $content);
         }
     }
     //插入文章
     $firstImgId = $imgidArr ? $imgidArr[0] : 0;
     $desc = $firstImgId ? API_Item_Base_String::getShort(array('str' => strip_tags($content), 'length' => 120)) : API_Item_Base_String::getShort(array('str' => strip_tags($content), 'length' => 150));
     $articleId = Helper_Blog::insertArticleInfo(array('insertData' => array('firstImgId' => $firstImgId, 'insertTime' => SYSTEM_TIME, 'isPublished' => 0, 'cate' => $this->cate, 'tags' => $this->tags, 'title' => $title, 'descript' => ' ' . strip_tags(addslashes(str_replace("'", '"', $desc))) . ' ', 'source' => $url, 'content' => ' ' . htmlspecialchars(addslashes(preg_replace("/<script[\\s]*.*?<\\/script>/si", '', $content))) . ' ', 'imgArr' => $imgidArr)));
     echo 'article ' . $articleId . ' is ok' . PHP_EOL;
 }
Ejemplo n.º 7
0
 /**
  * 获取没有发布的文章的列表
  * @param unknown $page
  * @param unknown $pageSize
  * @return Ambigous <boolean, mixed>
  */
 private function getUnPublishList($page, $pageSize)
 {
     $db = Db_Blog::instance(null, $this->website);
     $limit = ' limit ' . ($page - 1) * $pageSize . ',' . $pageSize;
     $where = " where isPublished=0 ";
     if ($this->cate) {
         $where .= " and cate='{$this->cate}' ";
     }
     if ($this->tags) {
         $where .= " and tags='{$this->tags}' ";
     }
     $order = " order by id asc ";
     //其实现不用desc也行,这样前期的文章质量高,搜索引擎更喜欢
     $sql = "select id from blog_article_info {$where} {$limit}";
     return $db->getCol($sql);
 }
Ejemplo n.º 8
0
 /**
  * 图灵机器人的回答信息
  */
 public static function insertRobotAnswer($paramArr)
 {
     $options = array('insertData' => array());
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     $formatData = self::setInsertCondition($insertData);
     $sql = "INSERT INTO blog_robot_answer({$formatData['fileds']}) VALUES({$formatData['values']})";
     $db = Db_Blog::instance();
     $db->query($sql);
     return $db->lastInsertId();
 }