Example #1
0
function facebook_crawl()
{
    //TODO Crawl Facebook posts and comments and insert them into the database
    global $THINKTANK_CFG;
    global $db;
    global $conn;
    $logger = new Logger($THINKTANK_CFG['log_location']);
    $id = new InstanceDAO($db, $logger);
    $oid = new OwnerInstanceDAO($db, $logger);
    $instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook');
    foreach ($instances as $i) {
        $logger->setUsername($i->network_username);
        $tokens = $oid->getOAuthTokens($i->id);
        $session_key = $tokens['oauth_access_token'];
        $fb = new Facebook($THINKTANK_CFG['facebook_api_key'], $THINKTANK_CFG['facebook_api_secret']);
        $cfg = new Config($i->network_username, $i->network_user_id);
        $id->updateLastRun($i->id);
        $crawler = new FacebookCrawler($i, $logger, $fb, $db);
        $crawler->fetchInstanceUserInfo($i->network_user_id, $session_key);
        $crawler->fetchUserPostsAndReplies($i->network_user_id, $session_key);
        $id->save($crawler->instance, $crawler->owner_object->post_count, $logger, $fb);
    }
    $logger->close();
    # Close logging
}
Example #2
0
function twitter_crawl()
{
    global $THINKTANK_CFG;
    global $db;
    global $conn;
    $logger = new Logger($THINKTANK_CFG['log_location']);
    $id = new InstanceDAO($db, $logger);
    $oid = new OwnerInstanceDAO($db, $logger);
    $instances = $id->getAllActiveInstancesStalestFirstByNetwork('twitter');
    foreach ($instances as $i) {
        $logger->setUsername($i->network_username);
        $tokens = $oid->getOAuthTokens($i->id);
        $noauth = true;
        if (isset($tokens['oauth_access_token']) && $tokens['oauth_access_token'] != '' && isset($tokens['oauth_access_token_secret']) && $tokens['oauth_access_token_secret'] != '') {
            $noauth = false;
        }
        if ($noauth) {
            $api = new CrawlerTwitterAPIAccessorOAuth('NOAUTH', 'NOAUTH', $THINKTANK_CFG['oauth_consumer_key'], $THINKTANK_CFG['oauth_consumer_secret'], $i, $THINKTANK_CFG['archive_limit']);
        } else {
            $api = new CrawlerTwitterAPIAccessorOAuth($tokens['oauth_access_token'], $tokens['oauth_access_token_secret'], $THINKTANK_CFG['oauth_consumer_key'], $THINKTANK_CFG['oauth_consumer_secret'], $i, $THINKTANK_CFG['archive_limit']);
        }
        $crawler = new TwitterCrawler($i, $logger, $api, $db);
        $cfg = new Config($i->network_username, $i->network_user_id);
        $api->init($logger);
        if ($api->available_api_calls_for_crawler > 0) {
            $id->updateLastRun($i->id);
            // No auth req'd
            $crawler->fetchInstanceUserInfo();
            // No auth for public Twitter users
            $crawler->fetchInstanceUserTweets();
            if (!$noauth) {
                // Auth req'd, for calling user only
                $crawler->fetchInstanceUserRetweetsByMe();
                // Auth req'd, for calling user only
                $crawler->fetchInstanceUserMentions();
                // Auth req'd, for calling user only
                $crawler->fetchInstanceUserFriends();
                // Auth req'd, for calling user only
                $crawler->fetchInstanceUserFollowers();
            }
            $crawler->fetchStrayRepliedToTweets();
            $crawler->fetchUnloadedFollowerDetails();
            $crawler->fetchFriendTweetsAndFriends();
            // TODO: Get direct messages
            // TODO: Gather favorites data
            if ($noauth) {
                // No auth req'd
                $crawler->fetchSearchResults($i->network_username);
            }
            $crawler->cleanUpFollows();
            // Save instance
            $id->save($crawler->instance, $crawler->owner_object->post_count, $logger, $api);
        }
    }
    $logger->close();
    # Close logging
}
Example #3
0
function twitter_crawl()
{
    global $THINKTANK_CFG;
    global $db;
    global $conn;
    $logger = new Logger($THINKTANK_CFG['log_location']);
    $id = new InstanceDAO($db, $logger);
    $oid = new OwnerInstanceDAO($db, $logger);
    $lurlapi = new LongUrlAPIAccessor($THINKTANK_CFG['app_title']);
    $flickrapi = new FlickrAPIAccessor($THINKTANK_CFG['flickr_api_key']);
    $instances = $id->getAllActiveInstancesStalestFirst();
    foreach ($instances as $i) {
        $logger->setUsername($i->network_username);
        $tokens = $oid->getOAuthTokens($i->id);
        $api = new CrawlerTwitterAPIAccessorOAuth($tokens['oauth_access_token'], $tokens['oauth_access_token_secret'], $THINKTANK_CFG['oauth_consumer_key'], $THINKTANK_CFG['oauth_consumer_secret'], $i, $THINKTANK_CFG['archive_limit']);
        $crawler = new TwitterCrawler($i, $logger, $api, $db);
        $cfg = new Config($i->network_username, $i->network_user_id);
        $api->init($logger);
        if ($api->available_api_calls_for_crawler > 0) {
            $id->updateLastRun($i->id);
            $crawler->fetchInstanceUserInfo();
            $crawler->fetchInstanceUserTweets($lurlapi, $flickrapi);
            $crawler->fetchInstanceUserRetweetsByMe($lurlapi, $flickrapi);
            $crawler->fetchInstanceUserMentions($lurlapi, $flickrapi);
            $crawler->fetchInstanceUserFriends();
            $crawler->fetchInstanceUserFollowers();
            $crawler->fetchStrayRepliedToTweets($lurlapi, $flickrapi);
            $crawler->fetchUnloadedFollowerDetails();
            $crawler->fetchFriendTweetsAndFriends($lurlapi, $flickrapi);
            // TODO: Get direct messages
            // TODO: Gather favorites data
            $crawler->cleanUpFollows();
            // Save instance
            $id->save($crawler->instance, $crawler->owner_object->post_count, $logger, $api);
        }
    }
    $logger->close();
    # Close logging
    if (isset($conn)) {
        $db->closeConnection($conn);
    }
    // Clean up
}
Example #4
0
$fb_user = null;
$facebook = new Facebook($THINKTANK_CFG['facebook_api_key'], $THINKTANK_CFG['facebook_api_secret']);
try {
    $fb_user = $facebook->api_client->users_getLoggedInUser();
    echo "Facebook user is logged in and user ID set<br />";
    $fb_username = $facebook->api_client->users_getInfo($fb_user, 'name');
    $fb_username = $fb_username[0]['name'];
} catch (Exception $e) {
    echo "EXCEPTION: " . $e->message;
}
if (isset($_GET['sessionKey']) && isset($fb_user) && $fb_user > 0) {
    $session_key = $_GET['sessionKey'];
    echo "DEBUG:";
    echo "Session Key: " . $session_key . "<br />";
    $od = new OwnerDAO($db);
    $id = new InstanceDAO($db);
    $oid = new OwnerInstanceDAO($db);
    $ud = new UserDAO($db);
    $owner = $od->getByEmail($_SESSION['user']);
    $i = $id->getByUserId($fb_user);
    if (isset($i)) {
        echo "Instance exists<br />";
        $oi = $oid->get($owner->id, $i->id);
        if ($oi == null) {
            //Instance already exists, owner instance doesn't
            $oid->insert($owner->id, $i->id, $session_key);
            //Add owner instance with session key
            echo "Created owner instance.<br />";
        }
    } else {
        //Instance does not exist
Example #5
0
<?php

session_start();
isset($_SESSION['user']) ? $_u = $_SESSION['user'] : ($_u = '');
isset($_SESSION['instance']) ? $_i = $_SESSION['instance'] : ($_i = '');
//Print_r  ($_i);
require_once "common/init.php";
$db = new Database($THINKTANK_CFG);
$conn = $db->getConnection();
$cfg = new Config();
$pd = new PostDAO($db);
$id = new InstanceDAO($db);
$s = new SmartyThinkTank();
//Pagination
$count = 15;
if (isset($_REQUEST['page'])) {
    $page = $_REQUEST['page'];
} else {
    $page = 1;
}
if ($page > 1) {
    $s->assign('prev_page', $page - 1);
}
$s->assign('cfg', $cfg);
$i = $id->getInstanceFreshestOne();
$s->assign('crawler_last_run', $i->crawler_last_run);
$s->assign('i', $_i);
// show tweet with public replies
if (isset($_REQUEST['t']) && $pd->isPostByPublicInstance($_REQUEST['t'])) {
    if (!$s->is_cached('public.tpl', $_REQUEST['t'])) {
        $post = $pd->getPost($_REQUEST['t']);
Example #6
0
$to = new TwitterOAuth($cfg->oauth_consumer_key, $cfg->oauth_consumer_secret, $request_token, $request_token_secret);
$tok = $to->getAccessToken();
if (isset($tok['oauth_token']) && isset($tok['oauth_token_secret'])) {
    $api = new TwitterAPIAccessorOAuth($tok['oauth_token'], $tok['oauth_token_secret'], $THINKTANK_CFG['oauth_consumer_key'], $THINKTANK_CFG['oauth_consumer_secret']);
    $u = $api->verifyCredentials();
    //	echo "User ID: ". $u['user_id'];
    //	echo "User name: ". $u['user_name'];
    $twitter_id = $u['user_id'];
    $tu = $u['user_name'];
    $db = new Database($THINKTANK_CFG);
    $conn = $db->getConnection();
    $od = new OwnerDAO($db);
    $owner = $od->getByEmail($_SESSION['user']);
    if ($twitter_id > 0) {
        echo "Twitter authentication successful.<br />";
        $id = new InstanceDAO($db);
        $i = $id->getByUsername($tu);
        $oid = new OwnerInstanceDAO($db);
        if (isset($i)) {
            echo "Instance already exists.<br />";
            $oi = $oid->get($owner->id, $i->id);
            if ($oi != null) {
                echo "Owner already has this instance, no insert or update.<br />";
            } else {
                $oid->insert($owner->id, $i->id, $tok['oauth_token'], $tok['oauth_token_secret']);
                echo "Added owner instance.<br />";
            }
        } else {
            echo "Instance does not exist.<br />";
            $id->insert($twitter_id, $tu);
            echo "Created instance.<br />";
Example #7
0
    if (!$session->pwdCheck($_POST['oldpass'], $origpass)) {
        $errormsg = "Old password does not match or empty.";
    } elseif ($_POST['pass1'] != $_POST['pass2']) {
        $errormsg = "New passwords did not match. Your password has not been changed.";
    } elseif (strlen($_POST['pass1']) < 5) {
        $errormsg = "New password must be at least 5 characters. Your password has not been changed.";
    } else {
        $cryptpass = $session->pwdcrypt($_POST['pass1']);
        $od->updatePassword($_SESSION['user'], $cryptpass);
        $successmsg = "Your password has been updated.";
    }
}
$s = new SmartyThinkTank();
$s->caching = 0;
$cfg = new Config();
$id = new InstanceDAO($db);
$od = new OwnerDAO($db);
$oid = new OwnerInstanceDAO($db);
$owner = $od->getByEmail($_SESSION['user']);
$s->assign('cfg', $cfg);
$s->assign('owner', $owner);
// grab instance from session variable
$i = unserialize($_SESSION['instance']);
$s->assign('instance', $i);
if ($owner->is_admin) {
    $owners = $od->getAllOwners();
    foreach ($owners as $o) {
        $instances = $id->getByOwner($o, true);
        $o->setInstances($instances);
    }
    $s->assign('owners', $owners);
Example #8
0
<?php

session_start();
if (!isset($_SESSION['user'])) {
    header("Location: /session/login.php");
}
$u = $_GET["u"];
$p = $_GET["p"];
if ($p != 1) {
    $p = 0;
}
chdir("..");
require_once 'config.webapp.inc.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH);
require_once "init.php";
$cfg = new Config();
$db = new Database($TWITALYTIC_CFG);
$conn = $db->getConnection();
$id = new InstanceDAO($db);
$id->setPublic($u, $p);
$db->closeConnection($conn);
Example #9
0
<?php

session_start();
if (!isset($_SESSION['user'])) {
    header("Location: /session/login.php");
}
// set up
chdir("..");
require_once 'config.webapp.inc.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH);
require_once "init.php";
$db = new Database($TWITALYTIC_CFG);
$conn = $db->getConnection();
$id = new InstanceDAO($db);
$od = new OwnerDAO($db);
$cfg = new Config($db);
$s = new SmartyTwitalytic();
$s->caching = 0;
$owner = $od->getByEmail($_SESSION['user']);
$owner_instances = $id->getByOwner($owner);
$to = new TwitterOAuth($cfg->oauth_consumer_key, $cfg->oauth_consumer_secret);
/* Request tokens from twitter */
$tok = $to->getRequestToken();
$token = $tok['oauth_token'];
$_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret'];
/* Build the authorization URL */
$oauthorize_link = $to->getAuthorizeURL($token);
$s->assign('owner_instances', $owner_instances);
$s->assign('owner', $owner);
$s->assign('cfg', $cfg);
$s->assign('oauthorize_link', $oauthorize_link);
Example #10
0
<?php

chdir("..");
require_once "common/init.php";
session_start();
$session = new Session();
if (!$session->isLoggedIn()) {
    header("Location: ../index.php");
}
$u = $_GET["u"];
$p = $_GET["p"];
if ($p != 1) {
    $p = 0;
}
$id = new InstanceDAO($db);
$id->setActive($u, $p);
$db->closeConnection($conn);
Example #11
0
 /**
  * @return
  */
 public function launchStreams()
 {
     $logger = Logger::getInstance('stream_log_location');
     if (!$this->php_path) {
         $logger->logError("php path is not set: check Twitter Realtime plugin configuration", __METHOD__ . ',' . __LINE__);
         return;
     }
     // get information from database about all streams.  This data is indexed by email + instance id.
     $stream_hash = $this->stream_proc_dao->getAllStreamProcesses();
     // get all owners
     $owners = $this->owner_dao->getAllOwners();
     $count = 0;
     // exec the stream processing script for each owner. This will fire up the
     // stream consumption if the owner has a twitter instance.
     foreach ($owners as $owner) {
         if ($count == self::MAX_INSTANCES) {
             break;
             // only open user stream process for up to MAX_INSTANCES instances
         }
         // the last argument in the following causes only active instances to be retrieved.
         $instances = $this->instance_dao->getByOwnerAndNetwork($owner, 'twitter', true, true);
         foreach ($instances as $instance) {
             $owner_email = $owner->email;
             if (isset($owner_email)) {
                 $idx = $owner_email . "_" . $instance->id;
                 $start_new_proc = false;
                 // if a 'live' process for that user is already running, take no action
                 if (isset($stream_hash[$idx]) && $stream_hash[$idx]['email'] == $owner_email && $stream_hash[$idx]['instance_id'] == $instance->id) {
                     if (strtotime($stream_hash[$idx]['last_report']) < time() - self::GAP_TIME) {
                         $logger->logInfo("killing process " . $stream_hash[$idx]['process_id'] . " -- it has not updated recently", __METHOD__ . ',' . __LINE__);
                         $this->psKill($stream_hash[$idx]['process_id']);
                         $this->stream_proc_dao->deleteProcess($stream_hash[$idx]['process_id']);
                         $start_new_proc = true;
                     } else {
                         $logger->logInfo("process " . $stream_hash[$idx]['process_id'] . " listed with recent update time for instance with {$owner_email} and " . $stream_hash[$idx]['instance_id'] . "-- not starting another one", __METHOD__ . ',' . __LINE__);
                         $count++;
                         // include this proc in the count of running processes
                     }
                 } else {
                     // start up a process for that instance
                     $start_new_proc = true;
                 }
                 if ($start_new_proc) {
                     $logger->logInfo("starting new process for " . "{$owner_email} and " . $instance->id, __METHOD__ . ',' . __LINE__);
                     $pass = $this->owner_dao->getPass($owner_email);
                     if ($pass && isset($this->php_path)) {
                         // @TODO - check that the dir paths are set properly
                         // then exec using that owner email and the encrypted pwd as args
                         $logfile = $this->log_dir . '/' . $owner_email . '_' . $instance->id . '.log';
                         $pid = shell_exec('cd ' . $this->streaming_dir . '; ' . $this->php_path . ' stream2.php ' . ' ' . $instance->id . ' ' . $owner_email . ' ' . $pass . ' > ' . $logfile . ' 2>&1 & echo $!');
                         if (!isset($pid)) {
                             throw new StreamingException("error: could not obtain PID when starting stream2 process.");
                         }
                         // insert PID and email/instance id information into the database.
                         $res = $this->stream_proc_dao->insertProcessInfo(trim($pid), $owner_email, $instance->id);
                         if (!$res) {
                             throw new StreamingException("error: issue inserting process information into database.");
                         }
                         $logger->logInfo("started pid " . trim($pid) . " for {$owner_email} and instance id " . $instance->id, __METHOD__ . ',' . __LINE__);
                         $count++;
                     } else {
                         $logger->logError("error: not launching stream for {$owner_email}-- error " . "with specified password or php path", __METHOD__ . ',' . __LINE__);
                     }
                 }
                 if ($count == self::MAX_INSTANCES) {
                     break;
                     // only open user stream process for up to MAX_OWNERS instances
                 }
             } else {
                 $logger->logError("error: email info not available. not launching stream for instance " . $instance->id, __METHOD__ . ',' . __LINE__);
             }
         }
         // end foreach instance
     }
     // end foreach owner
 }
Example #12
0
    if (!$session->pwdCheck($_POST['oldpass'], $origpass)) {
        $errormsg = "Old password does not match or empty.";
    } elseif ($_POST['pass1'] != $_POST['pass2']) {
        $errormsg = "New passwords did not match. Your password has not been changed.";
    } elseif (strlen($_POST['pass1']) < 5) {
        $errormsg = "New password must be at least 5 characters. Your password has not been changed.";
    } else {
        $cryptpass = $session->pwdcrypt($_POST['pass1']);
        $od->updatePassword($_SESSION['user'], $cryptpass);
        $successmsg = "Your password has been updated.";
    }
}
$s = new SmartyThinkTank();
$s->caching = 0;
$cfg = new Config();
$id = new InstanceDAO($db);
$od = new OwnerDAO($db);
$oid = new OwnerInstanceDAO($db);
$owner = $od->getByEmail($_SESSION['user']);
$s->assign('cfg', $cfg);
$s->assign('owner', $owner);
if ($owner->is_admin) {
    $owners = $od->getAllOwners();
    foreach ($owners as $o) {
        $instances = $id->getByOwner($o, true);
        $o->setInstances($instances);
    }
    $s->assign('owners', $owners);
}
/* Begin plugin-specific configuration handling */
$cmi = $webapp->getConfigMenu();
Example #13
0
    header("Location: /session/login.php");
}
// set up
chdir("..");
require_once 'config.webapp.inc.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH);
require_once "init.php";
$pd = new PostDAO($db);
if (isset($_REQUEST['t']) && is_numeric($_REQUEST['t']) && $pd->isPostInDB($_REQUEST['t'])) {
    $status_id = $_REQUEST['t'];
    $s = new SmartyThinkTank();
    if (!$s->is_cached('status.index.tpl', $status_id)) {
        $post = $pd->getPost($status_id);
        $u = new Utils();
        // BUG: THIS ISN'T GOING TO WORK WHEN LOOKING AT POSTS OF OTHER USERS BECAUSE THEY DON'T HAVE INSTANCES
        $id = new InstanceDAO($db);
        $i = $id->getByUsername($post->author_username);
        if (isset($i)) {
            $s->assign('likely_orphans', $pd->getLikelyOrphansForParent($post->pub_date, $i->network_user_id, $post->author_username, 15));
            $s->assign('all_tweets', $pd->getAllPosts($i->network_user_id, 15));
        }
        $cfg = new Config($i->network_username, $i->network_user_id);
        // instantiate data access objects
        $ud = new UserDAO($db);
        $all_replies = $pd->getRepliesToPost($status_id);
        $all_replies_count = count($all_replies);
        $all_retweets = $pd->getRetweetsOfPost($status_id);
        $retweet_reach = $pd->getPostReachViaRetweets($status_id);
        $public_replies = $pd->getPublicRepliesToPost($status_id);
        $public_replies_count = count($public_replies);
        $private_replies_count = $all_replies_count - $public_replies_count;
Example #14
0
}
// set up
chdir("..");
require_once 'config.webapp.inc.php';
ini_set("include_path", ini_get("include_path") . ":" . $INCLUDE_PATH);
require_once "init.php";
$db = new Database();
$conn = $db->getConnection();
$td = new TweetDAO();
if (isset($_REQUEST['t']) && is_numeric($_REQUEST['t']) && $td->isTweetInDB($_REQUEST['t'])) {
    $status_id = $_REQUEST['t'];
    $s = new SmartyTwitalytic();
    if (!$s->is_cached('status.index.tpl', $status_id)) {
        $tweet = $td->getTweet($status_id);
        $u = new Utils();
        $id = new InstanceDAO();
        $i = $id->getByUsername($tweet['author_username']);
        if (isset($i)) {
            $s->assign('likely_orphans', $td->getLikelyOrphansForParent($tweet['pub_date'], $i->twitter_user_id, $tweet['author_username'], 15));
            $s->assign('all_tweets', $td->getAllTweets($i->twitter_user_id, 15));
        }
        $cfg = new Config($i->twitter_username, $i->twitter_user_id);
        // instantiate data access objects
        $ud = new UserDAO();
        $all_replies = $td->getRepliesToTweet($status_id);
        $all_replies_count = count($all_replies);
        $public_replies = $td->getPublicRepliesToTweet($status_id);
        $public_replies_count = count($public_replies);
        $private_replies_count = $all_replies_count - $public_replies_count;
        $tweet = $td->getTweet($status_id);
        $s->assign('tweet', $tweet);
Example #15
0
}
// set up
chdir("..");
require_once 'config.webapp.inc.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH);
require_once "init.php";
$db = new Database($TWITALYTIC_CFG);
$conn = $db->getConnection();
$td = new TweetDAO($db);
if (isset($_REQUEST['t']) && is_numeric($_REQUEST['t']) && $td->isTweetInDB($_REQUEST['t'])) {
    $status_id = $_REQUEST['t'];
    $s = new SmartyTwitalytic();
    if (!$s->is_cached('status.index.tpl', $status_id)) {
        $tweet = $td->getTweet($status_id);
        $u = new Utils();
        $id = new InstanceDAO($db);
        $i = $id->getByUsername($tweet->author_username);
        if (isset($i)) {
            $s->assign('likely_orphans', $td->getLikelyOrphansForParent($tweet->pub_date, $i->twitter_user_id, $tweet->author_username, 15));
            $s->assign('all_tweets', $td->getAllTweets($i->twitter_user_id, 15));
        }
        $cfg = new Config($i->twitter_username, $i->twitter_user_id);
        // instantiate data access objects
        $ud = new UserDAO($db);
        $all_replies = $td->getRepliesToTweet($status_id);
        $all_replies_count = count($all_replies);
        $public_replies = $td->getPublicRepliesToTweet($status_id);
        $public_replies_count = count($public_replies);
        $private_replies_count = $all_replies_count - $public_replies_count;
        $tweet = $td->getTweet($status_id);
        $s->assign('tweet', $tweet);
Example #16
0
session_start();
if (!isset($_SESSION['user'])) {
    header("Location: /session/login.php");
}
// set up
chdir("..");
require_once 'config.webapp.inc.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH);
require_once "init.php";
$db = new Database($THINKTANK_CFG);
$conn = $db->getConnection();
$od = new OwnerDAO($db);
$owner = $od->getByEmail($_SESSION['user']);
$td = new TweetDAO($db);
$id = new InstanceDAO($db);
if (isset($_REQUEST['u']) && $id->isUserConfigured($_REQUEST['u'])) {
    $username = $_REQUEST['u'];
    $oid = new OwnerInstanceDAO($db);
    if (!$oid->doesOwnerHaveAccess($owner, $username)) {
        echo 'Insufficient privileges. <a href="/">Back</a>.';
        $db->closeConnection($conn);
        die;
    } else {
        $tweets = $td->getAllTweetsByUsername($username);
    }
} else {
    echo 'No access';
    $db->closeConnection($conn);
    die;
}
Example #17
0
<?php

session_start();
if (!isset($_SESSION['user'])) {
    header("Location: ../session/login.php");
}
// set up
chdir("..");
require_once "common/init.php";
$od = new OwnerDAO($db);
$ud = new UserDAO($db);
$fd = new FollowDAO($db);
$id = new InstanceDAO($db);
$pd = new PostDAO($db);
$s = new SmartyThinkTank();
if (isset($_REQUEST['u']) && $ud->isUserInDBByName($_REQUEST['u']) && isset($_REQUEST['i'])) {
    $user = $ud->getUserByName($_REQUEST['u']);
    $owner = $od->getByEmail($_SESSION['user']);
    // let's use the session variable to guarantee a value rather than the $i POST value, which can be blank
    $i = $id->getByUsername($_SESSION['network_username']);
    //$i = $id->getByUsername($_SESSION['i']);
    if (isset($i)) {
        $cfg = new Config($i->network_username, $i->network_user_id);
        if (!$s->is_cached('user.index.tpl', $i->network_username . "-" . $user->username)) {
            $s->assign('instances', $id->getByOwner($owner));
            $s->assign('profile', $user);
            $s->assign('user_statuses', $pd->getAllPosts($user->user_id, 20));
            $s->assign('sources', $pd->getStatusSources($user->user_id));
            $s->assign('cfg', $cfg);
            $s->assign('instance', $i);
            $s->assign('i', $i);
Example #18
0
<?php

session_start();
if (!isset($_SESSION['user'])) {
    header("Location: /session/login.php");
}
// set up
chdir("..");
require_once 'config.webapp.inc.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH);
require_once "init.php";
$db = new Database($TWITALYTIC_CFG);
$conn = $db->getConnection();
$ud = new UserDAO($db);
$fd = new FollowDAO($db);
$id = new InstanceDAO($db);
$td = new TweetDAO($db);
if (isset($_REQUEST['u']) && $ud->isUserInDBByName($_REQUEST['u']) && isset($_REQUEST['i'])) {
    $user = $ud->getUserByName($_REQUEST['u']);
    $i = $id->getByUsername($_REQUEST['i']);
    if (isset($i)) {
        $cfg = new Config($i->twitter_username, $i->twitter_user_id);
        $s = new SmartyTwitalytic();
        if (!$s->is_cached('user.index.tpl', $i->twitter_username . "-" . $user['user_name'])) {
            $s->assign('profile', $user);
            $s->assign('user_statuses', $td->getAllTweets($user['user_id'], 20));
            $s->assign('sources', $td->getStatusSources($user['user_id']));
            $s->assign('cfg', $cfg);
            $s->assign('instance', $i);
            $exchanges = $td->getExchangesBetweenUsers($cfg->twitter_user_id, $user['user_id']);
            $s->assign('exchanges', $exchanges);
Example #19
0
if ($_POST['changepass'] == 'Change Password') {
    $originalpass = $od->getPass($_SESSION['user']);
    $origpass = $originalpass['pwd'];
    if (!$session->pwdCheck($_POST['oldpass'], $origpass)) {
        $errormsg = "Old password does not match or empty.";
    } elseif ($_POST['pass1'] != $_POST['pass2']) {
        $errormsg = "New passwords did not match. Your password has not been changed.";
    } elseif (strlen($_POST['pass1']) < 5) {
        $errormsg = "New password must be at least 5 characters. Your password has not been changed.";
    } else {
        $cryptpass = $session->pwdcrypt($_POST['pass1']);
        $od->updatePassword($_SESSION['user'], $cryptpass);
        $successmsg = "Your password has been updated.";
    }
}
$id = new InstanceDAO($db);
$od = new OwnerDAO($db);
$cfg = new Config();
$s = new SmartyThinkTank();
$s->caching = 0;
$owner = $od->getByEmail($_SESSION['user']);
$owner_instances = $id->getByOwner($owner);
$to = new TwitterOAuth($cfg->oauth_consumer_key, $cfg->oauth_consumer_secret);
/* Request tokens from twitter */
$tok = $to->getRequestToken();
$token = $tok['oauth_token'];
$_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret'];
/* Build the authorization URL */
$oauthorize_link = $to->getAuthorizeURL($token);
if ($owner->is_admin) {
    $owners = $od->getAllOwners();
Example #20
0
<?php

require_once 'config.crawler.inc.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH);
require_once "init.php";
$db = new Database($THINKTANK_CFG);
$conn = $db->getConnection();
$logger = new Logger($THINKTANK_CFG['log_location']);
$id = new InstanceDAO($db, $logger);
$oid = new OwnerInstanceDAO($db, $logger);
$lurlapi = new LongUrlAPIAccessor($THINKTANK_CFG['app_title']);
$flickrapi = new FlickrAPIAccessor($THINKTANK_CFG['flickr_api_key']);
$instances = $id->getAllInstancesStalestFirst();
foreach ($instances as $i) {
    $logger->setUsername($i->twitter_username);
    $tokens = $oid->getOAuthTokens($i->id);
    $api = new CrawlerTwitterAPIAccessorOAuth($tokens['oauth_access_token'], $tokens['oauth_access_token_secret'], $THINKTANK_CFG['oauth_consumer_key'], $THINKTANK_CFG['oauth_consumer_secret'], $i, $THINKTANK_CFG['archive_limit']);
    $crawler = new Crawler($i, $logger, $api, $db);
    $cfg = new Config($i->twitter_username, $i->twitter_user_id);
    $api->init($logger);
    if ($api->available_api_calls_for_crawler > 0) {
        $id->updateLastRun($i->id);
        $crawler->fetchInstanceUserInfo();
        $crawler->fetchInstanceUserTweets($lurlapi, $flickrapi);
        $crawler->fetchInstanceUserRetweetsByMe($lurlapi, $flickrapi);
        $crawler->fetchInstanceUserMentions($lurlapi, $flickrapi);
        $crawler->fetchInstanceUserFriends();
        $crawler->fetchInstanceUserFollowers();
        $crawler->fetchStrayRepliedToTweets($lurlapi, $flickrapi);
        $crawler->fetchUnloadedFollowerDetails();
        $crawler->fetchFriendTweetsAndFriends($lurlapi, $flickrapi);
Example #21
0
<?php

session_start();
if (!isset($_SESSION['user'])) {
    header("Location: session/login.php");
}
// set up
require_once 'config.webapp.inc.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH);
require_once "init.php";
$od = new OwnerDAO($db);
$owner = $od->getByEmail($_SESSION['user']);
$id = new InstanceDAO($db);
if (isset($_REQUEST['u']) && $id->isUserConfigured($_REQUEST['u'])) {
    $username = $_REQUEST['u'];
    $oid = new OwnerInstanceDAO($db);
    if (!$oid->doesOwnerHaveAccess($owner, $username)) {
        echo 'Insufficient privileges. <a href="/">Back</a>.';
        $db->closeConnection($conn);
        die;
    } else {
        $i = $id->getByUsername($username);
    }
} else {
    $db->closeConnection($conn);
    die;
}
if (!isset($_REQUEST['d'])) {
    $_REQUEST['d'] = "all-tweets";
}
$s = new SmartyThinkTank();
Example #22
0
// set up
chdir("..");
require_once 'config.webapp.inc.php';
ini_set("include_path", ini_get("include_path") . PATH_SEPARATOR . $INCLUDE_PATH);
require_once "init.php";
$tu = $_POST['twitter_username'];
$tp = $_POST['twitter_password'];
$db = new Database($THINKTANK_CFG);
$conn = $db->getConnection();
$od = new OwnerDAO($db);
$owner = $od->getByEmail($_SESSION['user']);
$api = new TwitterAPIAccessor($tu, $tp);
$twitter_id = $api->doesAuthenticate();
if ($twitter_id > 0) {
    echo "Twitter authentication successful.<br />";
    $id = new InstanceDAO($db);
    $i = $id->getByUsername($tu);
    $oid = new OwnerInstanceDAO($db);
    if (isset($i)) {
        echo "Instance already exists.<br />";
        $id->updatePassword($tu, $tp);
        echo "Updated existing instance's password.<br />";
        $oi = $oid->get($owner->id, $i->id);
        if ($oi != null) {
            echo "Owner already has this instance, no insert or update.<br />";
        } else {
            $oid->insert($owner->id, $i->id);
            echo "Added owner instance.<br />";
        }
    } else {
        echo "Instance does not exist.<br />";
Example #23
0
<?php

session_start();
if (!isset($_SESSION['user'])) {
    require_once 'public.php';
    die;
} else {
    require_once "common/init.php";
    $od = new OwnerDAO($db);
    $owner = $od->getByEmail($_SESSION['user']);
    $id = new InstanceDAO($db);
    $s = new SmartyThinkTank();
    if (isset($_REQUEST['u']) && $id->isUserConfigured($_REQUEST['u'])) {
        $username = $_REQUEST['u'];
        $oid = new OwnerInstanceDAO($db);
        if (!$oid->doesOwnerHaveAccess($owner, $username)) {
            echo 'Insufficient privileges. <a href="/">Back</a>.';
            $db->closeConnection($conn);
            die;
        } else {
            $i = $id->getByUsername($username);
        }
    } else {
        $i = $id->getFreshestByOwnerId($owner->id);
        if (!isset($i) && $i == null) {
            $s->assign('msg', 'You have no Twitter accounts configured. <a href="' . $THINKTANK_CFG['site_root_path'] . 'account/?p=twitter">Set up a Twitter account here</a>');
            $s->display('message.tpl');
            $db->closeConnection($conn);
            die;
        }
    }