示例#1
0
 /**
  * Adds tweets to the database.
  * @param string $data - Twitter XML results
  * @param string $hashsearch - null if using auth session, or the hashtag being used to search
  * @param string $username
  */
 function add_tweets($data, $hashsearch = null, $username = '')
 {
     $feed_data = $this->_setup_simplepie($data);
     //Pass this the raw xml data
     if ($feed_data->get_item_quantity() != 0) {
         foreach ($feed_data->get_items(0, 50) as $feed_data_item) {
             //Grab tweet data from RSS feed
             $tweet_link = $feed_data_item->get_link();
             $full_date = $feed_data_item->get_date();
             $tweet_date = date("Y-m-d H:i:s", strtotime($full_date));
             if ($hashsearch != null) {
                 $tweet_hashtag = $hashsearch;
                 $full_tweet = $feed_data_item->get_title();
                 $tweet_from = $feed_data_item->get_author()->get_name();
                 //chop off string at "("
                 $tweet_from = trim(substr($tweet_from, 0, stripos($tweet_from, '(')));
                 $tweet_to = '';
                 // There is no "to" so we make it blank
                 $tweet = $full_tweet;
             } else {
                 $tweet_hashtag = '';
                 //not searching using a hashtag
                 $full_tweet = $feed_data_item->get_description();
                 //Parse tweet for data
                 $chop_location = ': @' . $username;
                 $cut1 = stripos($full_tweet, $chop_location);
                 //Find the position of the username
                 $cut2 = $cut1 + strlen($chop_location) + 1;
                 //Calculate the pos of the start of the tweet
                 $tweet_from = substr($full_tweet, 0, $cut1);
                 $tweet_to = $username;
                 $tweet = substr($full_tweet, $cut2);
             }
             if (isset($full_tweet) && !empty($full_tweet)) {
                 // We need to check for duplicates.
                 // Note: Heave on server.
                 $dupe_count = ORM::factory('twitter')->where('tweet_link', $tweet_link)->where('tweet', $tweet)->count_all();
                 if ($dupe_count == 0) {
                     // Add tweet to database
                     $newtweet = new Twitter_Model();
                     $newtweet->tweet_from = $tweet_from;
                     $newtweet->tweet_to = $tweet_to;
                     $newtweet->tweet_hashtag = $tweet_hashtag;
                     $newtweet->tweet_link = $tweet_link;
                     $newtweet->tweet = $tweet;
                     $newtweet->tweet_date = $tweet_date;
                     $newtweet->save();
                 }
             }
         }
     } else {
         return FALSE;
         //if there are no items in the feed
     }
     $feed_data->__destruct();
     //in the off chance we hit a ton of feeds, we need to clean it out
     return TRUE;
     //if there were items in the feed
 }
示例#2
0
文件: index.php 项目: LockGit/emlog
        if ($w > 150 || $h > 120) {
            $uppath = Option::UPLOADFILE_PATH . gmdate('Ym') . '/';
            $thum = str_replace($uppath, $uppath . 'thum-', $upfname);
            resizeImage($upfname, $thum, 120, 150);
            $upfname = $thum;
        }
        $tdata['img'] = str_replace('../', '', $upfname);
    }
    $Twitter_Model->addTwitter($tdata);
    $CACHE->updateCache(array('sta', 'newtw'));
    doAction('post_twitter', $t);
    emDirect("./?action=tw");
}
if (ROLE === ROLE_ADMIN && $action == 'delt') {
    LoginAuth::checkToken();
    $Twitter_Model = new Twitter_Model();
    $id = isset($_GET['id']) ? intval($_GET['id']) : '';
    $Twitter_Model->delTwitter($id);
    $CACHE->updateCache(array('sta', 'newtw'));
    emDirect("./?action=tw");
}
if ($action == 'login') {
    Option::get('login_code') == 'y' ? $ckcode = "<span>验证码</span>\n    <div class=\"val\"><img src=\"../include/lib/checkcode.php\" /><br />\n\t<input name=\"imgcode\" id=\"imgcode\" type=\"text\" />\n    </div>" : ($ckcode = '');
    include View::getView('header');
    include View::getView('login');
    include View::getView('footer');
    View::output();
}
if ($action == 'auth') {
    session_start();
    $username = addslashes(trim($_POST['user']));
示例#3
0
文件: index.php 项目: LockGit/emlog
 } elseif (!$r || strlen($r) > 420) {
     exit('err1');
 } elseif (ROLE == ROLE_VISITOR && empty($rname)) {
     exit('err2');
 } elseif (ROLE == ROLE_VISITOR && Option::get('reply_code') == 'y' && session_start() && $rcode != $_SESSION['code']) {
     exit('err3');
 }
 foreach ($user_cache as $val) {
     if (isset($val['name']) && $val['name'] == $rname) {
         exit('err4');
     }
 }
 $date = time();
 $name = subString(ROLE == ROLE_VISITOR ? $rname : addslashes($user_cache[UID]['name']), 0, 16);
 $rdata = array('tid' => $tid, 'content' => $r, 'name' => $name, 'date' => $date, 'hide' => ROLE == ROLE_VISITOR ? Option::get('ischkreply') : 'n');
 $Twitter_Model = new Twitter_Model();
 $Reply_Model = new Reply_Model();
 $rid = $Reply_Model->addReply($rdata);
 if ($rid === false) {
     exit('err5');
 }
 doAction('reply_twitter', $r, $name, $date, $tid);
 if (Option::get('ischkreply') == 'n' || ROLE != ROLE_VISITOR) {
     $Twitter_Model->updateReplyNum($tid, '+1');
 } else {
     exit('succ1');
 }
 $CACHE->updateCache('sta');
 $_SESSION['code'] = null;
 $date = smartDate($date);
 $r = htmlClean(stripslashes($r));
示例#4
0
<?php

/**
 * 微语
 * @copyright (c) Emlog All Rights Reserved
 */
require_once 'globals.php';
$Twitter_Model = new Twitter_Model();
if ($action == '') {
    $Reply_Model = new Reply_Model();
    $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
    $tws = $Twitter_Model->getTwitters($page, 1);
    $twnum = $Twitter_Model->getTwitterNum(1);
    $pageurl = pagination($twnum, Option::get('admin_perpage_num'), $page, 'twitter.php?page=');
    $avatar = empty($user_cache[UID]['avatar']) ? './views/images/avatar.jpg' : '../' . $user_cache[UID]['avatar'];
    include View::getView('header');
    require_once View::getView('twitter');
    include View::getView('footer');
    View::output();
}
// 发布微语.
if ($action == 'post') {
    $t = isset($_POST['t']) ? addslashes(trim($_POST['t'])) : '';
    $img = isset($_POST['img']) ? addslashes(trim($_POST['img'])) : '';
    LoginAuth::checkToken();
    if ($img && !$t) {
        $t = '分享图片';
    }
    if (!$t) {
        emDirect("twitter.php?error_a=1");
    }