Example #1
0
function flickrthumbnails_crawl()
{
    global $THINKTANK_CFG;
    global $db;
    global $conn;
    if (isset($THINKTANK_CFG['flickr_api_key']) && $THINKTANK_CFG['flickr_api_key'] != '') {
        $logger = new Logger($THINKTANK_CFG['log_location']);
        $fa = new FlickrAPIAccessor($THINKTANK_CFG['flickr_api_key'], $logger);
        $ldao = new LinkDAO($db, $logger);
        $flickrlinkstoexpand = $ldao->getLinksToExpandByURL('http://flic.kr/');
        if (count($flickrlinkstoexpand > 0)) {
            $logger->logStatus(count($flickrlinkstoexpand) . " Flickr links to expand", "Flickr Plugin");
        } else {
            $logger->logStatus("No Flickr links to expand", "Flickr Plugin");
        }
        foreach ($flickrlinkstoexpand as $fl) {
            $eurl = $fa->getFlickrPhotoSource($fl);
            if ($eurl["expanded_url"] != '') {
                $ldao->saveExpandedUrl($fl, $eurl["expanded_url"], '', 1);
            } elseif ($eurl["error"] != '') {
                $ldao->saveExpansionError($fl, $eurl["error"]);
            }
        }
        $logger->close();
        # Close logging
    }
}
Example #2
0
 function testCreatingNewLogger()
 {
     global $THINKTANK_CFG;
     $logger = new Logger($THINKTANK_CFG['log_location']);
     $logger->logStatus('Should write this to the log', get_class($this));
     $this->assertTrue(file_exists($THINKTANK_CFG['log_location']), 'File created');
     $messages = file($THINKTANK_CFG['log_location']);
     $this->assertWantedPattern('/Should write this to the log/', $messages[sizeof($messages) - 1]);
     $logger->setUsername('ginatrapani');
     $logger->logStatus('Should write this to the log with a username', get_class($this));
     $this->assertWantedPattern('/ginatrapani | TestOfLogging:Should write this to the log/', $messages[sizeof($messages) - 1]);
     $logger->close();
 }
 /**
  * Fetch a save the posts and replies on a Facebook page.
  * @param int $pid Page ID
  */
 public function fetchPagePostsAndReplies($pid)
 {
     $stream = FacebookGraphAPIAccessor::apiRequest('/' . $pid . '/posts', $this->access_token);
     if (isset($stream->data) && is_array($stream->data) && sizeof($stream->data > 0)) {
         $this->logger->logStatus(sizeof($stream->data) . " Facebook posts found for page ID {$pid}", get_class($this));
         $thinkup_data = $this->parseStream($stream, 'facebook page');
         $posts = $thinkup_data["posts"];
         $post_dao = DAOFactory::getDAO('PostDAO');
         foreach ($posts as $post) {
             if ($post['author_username'] == "" && isset($post['author_user_id'])) {
                 $commenter_object = $this->fetchUserInfo($post['author_user_id'], 'facebook', 'Facebook page comments');
                 if (isset($commenter_object)) {
                     $post["author_username"] = $commenter_object->full_name;
                     $post["author_fullname"] = $commenter_object->full_name;
                     $post["author_avatar"] = $commenter_object->avatar;
                 }
             }
             $added_posts = $post_dao->addPost($post);
             $this->logger->logStatus("Added {$added_posts} post ID " . $post["post_id"] . " on " . $post["network"] . " for " . $post["author_username"] . ":" . $post["post_text"], get_class($this));
         }
         $users = $thinkup_data["users"];
         if (count($users) > 0) {
             foreach ($users as $user) {
                 $user["post_count"] = $post_dao->getTotalPostsByUser($user['user_id'], $user['network']);
                 $found_in = 'Facebook page stream';
                 $user_object = new User($user, $found_in);
                 $user_dao = DAOFactory::getDAO('UserDAO');
                 $user_dao->updateUser($user_object);
             }
         }
     } else {
         $this->logger->logStatus("No Facebook posts found for page ID {$pid}", get_class($this));
     }
 }
Example #4
0
function expandurls_crawl()
{
    global $THINKTANK_CFG;
    global $db;
    global $conn;
    $logger = new Logger($THINKTANK_CFG['log_location']);
    $ldao = new LinkDAO($db, $logger);
    $linkstoexpand = $ldao->getLinksToExpand();
    $logger->logStatus(count($linkstoexpand) . " links to expand", "Expand URLs Plugin");
    foreach ($linkstoexpand as $l) {
        $eurl = untinyurl($l, $logger, $ldao);
        if ($eurl != '') {
            $ldao->saveExpandedUrl($l, $eurl);
        }
    }
    $logger->logStatus("URL expansion complete for this run", "Expand URLs Plugin");
    $logger->close();
    # Close logging
}