Beispiel #1
0
function fetch_web($schemas, $test = null)
{
    global $_user, $_channels;
    $updated_file = array();
    foreach ($schemas as $k => $v) {
        if (!$v->channel && $v->url == '' || $v->keywords == '') {
            continue;
        }
        if ($v->channel) {
            $url_arr = $_channels[$v->channel]['url'];
        } else {
            $url_arr = explode(' ', $v->url);
        }
        foreach ($url_arr as $url_key => $url) {
            $url = mkurl($v->channel, $url_key, $url, $v->url);
            $filename = md5($url) . '.tmp';
            if (in_array($filename, $updated_file)) {
                $html = file_get_contents(CACHE_PATH . $filename);
            } else {
                $file = '';
                $context = $v->channel ? mkfp_context($url_key) : null;
                $html = file_get_contents($url, false, $context);
                $html = format_script($html);
                file_put_contents(CACHE_PATH . $filename, $html);
                $updated_file[] = $filename;
            }
            //处理关键词
            $keywords = $v->keywords;
            $encoding = mb_detect_encoding($html, array('ASCII', 'GB2312', 'GBK', 'UTF-8'));
            if ($encoding == 'EUC-CN') {
                $encoding = 'GB2312';
                $keywords = iconv('UTF-8', 'GBK', $keywords);
            } elseif ($encoding == 'CP936') {
                $keywords = iconv('UTF-8', $encoding, $keywords);
            }
            $keywords = explode(' ', $keywords);
            $first_key = array_shift($keywords);
            $lpos = 0;
            $rpos = NULL;
            $len = strlen($first_key);
            for ($lpos = strpos($html, $first_key, $lpos); $lpos !== false; $lpos = strpos($html, $first_key, $lpos + $len)) {
                $rpos = find_key($html, $keywords, $lpos + $len);
                if ($rpos) {
                    $html_len = strlen($html);
                    //得到关键词上下文
                    for ($j = 1; $j < 6 && $lpos !== false; $j++) {
                        $lpos = strrpos($html, '</', $lpos - $html_len - 2);
                    }
                    if (!$lpos) {
                        $lpos = 0;
                    }
                    for ($i = 1; $i < 5; $i++) {
                        $rpos = strpos($html, '</', $rpos + 2);
                    }
                    if (!$rpos) {
                        $rpos = $html_len;
                    }
                    $result = substr($html, $lpos, $rpos - $lpos);
                    break;
                }
            }
            $result = trim(strip_tags($result, '<a>'));
            //确定包含数字
            if ($v->max_num != '' || $v->min_num != '') {
                $result = find_num($result, $v->max_num, $v->min_num);
            }
            if ($result) {
                $result = str_replace(array("\n", "\r", "\t", "  "), '', $result);
                if ($encoding != 'UTF-8') {
                    $result = substr($result, 0, 400);
                    $result = iconv('GBK', 'UTF-8', $result);
                } else {
                    $result = mb_substr($result, 0, 400, 'utf8');
                }
                $website = isset($_channels[$v->channel]['website'][$url_key]) ? $_channels[$v->channel]['website'][$url_key] : $url;
                $content = $result . "<a href='{$website}' target='_blank'>查看</a>";
                if ($test) {
                    return $content;
                } else {
                    $_user = user::get_one(array('user_id' => $v->user_id));
                    schema::update(array('status' => 'off', 'schema_id' => $v->schema_id));
                    msg::add(array('schema_id' => $v->schema_id, 'title' => $v->title, 'content' => $content, 'status' => 'new'));
                    $email = filter_var($_user->email, FILTER_VALIDATE_EMAIL);
                    if ($_user->email_notify == 'on' && $email) {
                        mail::send_cron($email, $v->title, $content);
                    }
                    if ($_user->app_notify == 'on' && $_user->baidu_uid) {
                        push::push_message($_user->baidu_uid, $v->title, $result);
                    }
                }
                $result = NULL;
                break;
            }
        }
    }
}
Beispiel #2
0
    }
    //endif enddateiem
    $validTimes = getTimes($schedule_record);
    if (is_array($validTimes) && in_array($now, $validTimes)) {
        switch ($schedule_record["type"]) {
            case "job":
                $success = @(include $schedule_record["job"]);
                break;
            case "pushrecord":
                include_once "../../modules/api/include/push.php";
                //try to include table specific functions
                $tableFile = "../../modules/" . $schedule_record["modulename"] . "/include/" . $schedule_record["maintable"] . ".php";
                if (file_exists($tableFile)) {
                    include_once $tableFile;
                }
                $push = new push($db, $schedule_record["pushrecordid"]);
                $success = $push->process();
                break;
        }
        //end switch
        if ($success) {
            $updatestatement = "UPDATE scheduler SET lastrun=NOW() WHERE id=" . $schedule_record["id"];
            $db->query($updatestatement);
            $log = new phpbmsLog("Scheduled Job " . $schedule_record["name"] . " (" . $schedule_record["id"] . ") completed", "SCHEDULER", "usr:42e0cc76-3c31-d9b6-ff12-fe4adfd15e75");
        } else {
            $log = new phpbmsLog("Scheduled Job " . $schedule_record["name"] . " (" . $schedule_record["id"] . ") returned errors", "SCHEDULER", "usr:42e0cc76-3c31-d9b6-ff12-fe4adfd15e75");
        }
        //endif success
    }
    //endif is_array();
}
Beispiel #3
0
 /**
  * 返回最新的20条公共点滴
  * @param count  每次返回的记录数   缺省值20,最大值200 
  * @return xml/json 用户信息
  */
 public function getTimeline()
 {
     $userinfo = array();
     $usrinfoall = array();
     $ids = array();
     $statusids = array();
     //验证用户是否登录
     require_once ROOT_DIR . 'lib/user/user.class.php';
     $this->user = new user();
     $userinfo = $this->user->verify_credentials();
     if (!$userinfo['id']) {
         $this->errorOutput(USENAME_NOLOGIN);
     }
     //$userinfo['id'] = 2;
     //$this->input['gettoal']='gettotal';
     //获取用户参数
     //判断是否需要取总数
     if (!$this->input['count']) {
         $this->input['count'] = 20;
     } elseif ($this->input['count'] > 200) {
         $this->input['count'] = 200;
     }
     $count = intval($this->input['count']);
     $page = intval($this->input['page']);
     //取总数时需传入数值gettotal
     $gettotal = trim($this->input['gettoal']);
     $offset = $page * $count;
     //取得本人和所关注人的点滴id
     include_once ROOT_DIR . 'lib/class/push.class.php';
     $push = new push();
     //取得本人和所关注人的点滴总数
     if ($gettotal) {
         $total = $push->getuserinbox($userinfo['id'], $page, $count, $gettotal);
     }
     $stat = $push->getuserinbox($userinfo['id'], $page, $count, '');
     if (!$stat) {
         //退出
         return false;
     }
     foreach ($stat as $key => $values) {
         $statusids[] = $values['status_id'];
     }
     //取得本人和所关注人的点滴信息
     $all = $this->getblog($statusids, 1);
     //取得本人相关的媒体信息
     if ($statusids) {
         $media = $this->obj->getMedia($statusids);
     }
     //取得转发我的点滴信息
     if (count($this->trans)) {
         $alltran = $this->getblog($this->trans, 2);
         $mediatran = $this->obj->getMedia($this->trans);
     }
     //博客用户信息和转发用户信息合并
     $this->setXmlNode('statuses', 'status');
     if ($total) {
         $this->addItem($total['0']);
     }
     foreach ($all as $key => $values) {
         $alltran[$values['reply_status_id']]['medias'] = $mediatran[$values['reply_status_id']];
         $values['retweeted_status'] = $alltran[$values['reply_status_id']];
         $values['medias'] = $media[$values['id']];
         $this->addItem($values);
     }
     $this->output();
 }
Beispiel #4
0
<?php

include INCLUDES_PATH . 'baiduapi/Channel.class.php';
push::$push = new Channel(baidu_apiKey, baidu_secretKey);
class push
{
    public static $push;
    public static function push_message($user_id, $title, $desc)
    {
        //推送消息到某个user,设置push_type = 1;
        //推送消息到一个tag中的全部user,设置push_type = 2;
        //推送消息到该app中的全部user,设置push_type = 3;
        $push_type = 1;
        //推送单播消息
        $optional[Channel::USER_ID] = $user_id;
        //如果推送单播消息,需要指定user
        //optional[Channel::TAG_NAME] = "xxxx";  //如果推送tag消息,需要指定tag_name
        //指定发到android设备
        $optional[Channel::DEVICE_TYPE] = 3;
        //指定消息类型为通知
        $optional[Channel::MESSAGE_TYPE] = 1;
        //通知类型的内容必须按指定内容发送,示例如下:
        $message = "{ \n\t\t\t\t'title': '{$title}',\n\t\t\t\t'description': '{$desc}',\n\t\t\t\t'notification_basic_style':7,\n\t\t\t\t'open_type':2,\n\t\t\t\t'url':'http://pickcat.sinaapp.com'\n\t\t\t}";
        $message_key = "msg_key";
        $ret = self::$push->pushMessage($push_type, $message, $message_key, $optional);
    }
}
Beispiel #5
0
 /**
  * 删除点滴信息
  */
 public function destroy()
 {
     include_once ROOT_DIR . 'lib/class/member.class.php';
     $this->member = new member();
     if (!$this->user['user_id']) {
         $this->errorOutput(USENAME_NOLOGIN);
     }
     //获取用户参数
     if (!$this->input['id']) {
         return;
     }
     //一次性最多批量删除二十个点滴信息
     $sta = explode(',', urldecode($this->input['id']));
     if (count($sta) > 20) {
         return;
     }
     //判断是否是管理员
     if (!$this->user['is_admin']) {
         $extion = " and member_id=" . $this->user['user_id'];
     }
     //删除单条记录时候返回本条记录信息
     if (count($sta) == 1) {
         //查询出要删除的信息
         //$sql = "SELECT sta.* , mea.source FROM ".DB_PREFIX."status sta  LEFT JOIN ".DB_PREFIX."media mea ON sta.id = mea.status_id ORDER BY sta.id DESC  limit $offset , $count";
         $sql = "SELECT sta.* , exl.transmit_count,exl.reply_count,exl.comment_count FROM " . DB_PREFIX . "status sta  LEFT JOIN " . DB_PREFIX . "status_extra exl ON sta.id = exl.status_id where sta.id=" . $this->input['id'] . $extion;
         $row = $this->db->query_first($sql);
         if (!$row) {
             $this->errorOutput(DELETE_FALES);
         }
         $members = $this->member->getMemberById($row['member_id']);
         $members = $members[0][$this->user['user_id']];
         $last_status_id = $members['last_status_id'];
         $member_id = $members['member_id'];
         //对应user的键值
         foreach ($members as $key => $values) {
             $mem[$values['id']] = $values;
         }
     } else {
         /*if(!$userinfo['is_admin'])
         		{
         			$sql = "SELECT id  FROM ".DB_PREFIX."status where id in(".$this->input['id'].")".$extion;
         			$result = $this->db->query($sql);
         			while($r = $this->db->fetch_array($result))
         			{		
         				$row[]=$r['id'];
         			}
         			if(!$row)
         			{
         				$row = array();
         			}
         			//求补集
         			$dsta = array_diff($sta,$row);
         			if(count($dsta))
         			{
         				$this -> errorOutput(DELETE_FALES);
         			}	
         		}*/
     }
     /**
      * 添加微博删除积分(消耗)
      */
     $this->member->add_credit_log(DELETE_STATUS);
     //删除push表中的数据
     include_once ROOT_DIR . 'lib/class/push.class.php';
     $push = new push();
     $stat = $push->delete($this->input['id']);
     $stat = true;
     //删除各表中的数据
     if ($stat) {
         $sql = "delete " . DB_PREFIX . "status ," . DB_PREFIX . "status_extra , " . DB_PREFIX . "status_comments ,\r\n\t\t\t" . DB_PREFIX . "status_member , " . DB_PREFIX . "status_topic , " . DB_PREFIX . "status_favorites from " . DB_PREFIX . "status\r\n\t\t\tleft join " . DB_PREFIX . "status_extra on " . DB_PREFIX . "status.id = " . DB_PREFIX . "status_extra.status_id \r\n\t\t\tleft join " . DB_PREFIX . "status_comments on " . DB_PREFIX . "status.id = " . DB_PREFIX . "status_comments.status_id \r\n\t\t\tleft join " . DB_PREFIX . "status_member on " . DB_PREFIX . "status.id = " . DB_PREFIX . "status_member.status_id\r\n\t\t\tleft join " . DB_PREFIX . "status_topic on " . DB_PREFIX . "status.id = " . DB_PREFIX . "status_topic.status_id\r\n\t\t\tleft join " . DB_PREFIX . "status_favorites on " . DB_PREFIX . "status.id = " . DB_PREFIX . "status_favorites.status_id  \r\n\t\t\twhere " . DB_PREFIX . "status.id in(" . urldecode($this->input['id']) . ")";
         $reply = $this->db->query($sql);
         if ($last_status_id == $this->input['id']) {
             $sql = "SELECT id FROM " . DB_PREFIX . "status where member_id=" . $member_id . " ORDER BY create_at DESC";
             $first = $this->db->query_first($sql);
             if (!empty($first)) {
                 $this->member->update_last_status($member_id, $first['id']);
             }
         }
     }
     //删除所有的转发信息
     if ($reply) {
         $sql = "delete  from " . DB_PREFIX . "status where reply_status_id in(" . urldecode($this->input['id']) . ")";
         $rowd = $this->db->query($sql);
     }
     //如果删除成功则返回删除的数据
     if ($rowd && count($sta) == 1) {
         //博客信息和用户信息合并
         $this->setXmlNode('statuses', 'status');
         $row['user'] = $mem[$row['member_id']];
         $this->addItem($row);
         /**
         			 * 同步删除点滴
         			$bind_info = $this->user->get_bind_info(); //获取绑定信息
         			
         			$bind_info = $bind_info[0];
         			
         			if($bind_info['state'] == 1 && $bind_info['last_key'])
         			{
         				$status_id = urldecode($this->input['id']);				
         				$is_syn = $this->check_syn_status($status_id , 1);
         							
         				//该条点滴是同步发送的点滴
         				if($is_syn)
         				{					
         					include_once (ROOT_PATH . 'lib/class/weibooauth.class.php');
         					$last_key = unserialize($bind_info['last_key']);
         					$oauth = new WeiboClient( WB_AKEY , WB_SKEY , $last_key['oauth_token'] , $last_key['oauth_token_secret'] );
         					//$oauth = new WeiboOAuth( WB_AKEY , WB_SKEY , 'e9b1d743a687550cec725e65fd204b6c' , '119934aabf1632d426533505c0f02e70' );								
         					//同步删除点滴
         				
         					$content = $oauth->destroy($is_syn['syn_id']);
         				}
         			} */
         $this->output();
     } elseif ($rowd) {
         $this->setXmlNode('statuses', 'status');
         $this->addItem('sucess');
         $this->output();
     } else {
         $this->errorOutput(DELETE_FALES);
     }
 }
Beispiel #6
0
 function runPush($pushRecordUuid)
 {
     include_once "modules/api/include/push.php";
     $uuidArray = getUuidArray($this->db, $this->tabledefuuid, $this->idsArray);
     if ($uuidArray === false) {
         $uuidArray = array();
     }
     $push = new push($this->db, $pushRecordUuid, $uuidArray);
     $thereturn = $push->process();
     if ($thereturn !== false) {
         $message = count($push->uuidArray) . " record(s) pushed.";
     } else {
         $message = "An error has occured.";
     }
     return $message;
 }