本文整理汇总了PHP中DAOFactory::GetDAO方法的典型用法代码示例。如果您正苦于以下问题:PHP DAOFactory::GetDAO方法的具体用法?PHP DAOFactory::GetDAO怎么用?PHP DAOFactory::GetDAO使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DAOFactory
的用法示例。
在下文中一共展示了DAOFactory::GetDAO方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: control
public function control()
{
$this->view_name = isset($_GET['v']) ? $_GET['v'] : 'default';
$post_dao = DAOFactory::getDAO('PostDAO');
$this->setPageTitle('Post Details');
$this->setViewTemplate('post.index.tpl');
$network = isset($_GET['n']) ? $_GET['n'] : 'twitter';
if ($this->shouldRefreshCache()) {
if (isset($_GET['t']) && is_numeric($_GET['t'])) {
$post_id = $_GET['t'];
$post = $post_dao->getPost($post_id, $network);
if (isset($post)) {
$config = Config::getInstance();
$this->addToView('disable_embed_code', $config->getValue('is_embed_disabled') || $post->is_protected);
if (isset($_GET['search'])) {
$this->addToView('search_on', true);
}
if (!$post->is_protected || $this->isLoggedIn()) {
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('geoencoder', true);
if (isset($options['distance_unit']->option_value)) {
$distance_unit = $options['distance_unit']->option_value;
} else {
$distance_unit = 'km';
}
$this->addToView('post', $post);
$this->addToView('unit', $distance_unit);
$replies = $post_dao->getRepliesToPost($post_id, $network, 'default', $distance_unit);
$public_replies = array();
foreach ($replies as $reply) {
if (!$reply->author->is_protected) {
$public_replies[] = $reply;
}
}
$public_replies_count = count($public_replies);
$this->addToView('public_reply_count', $public_replies_count);
if ($this->isLoggedIn()) {
$this->addToView('replies', $replies);
} else {
$this->addToView('replies', $public_replies);
}
$all_replies_count = count($replies);
$private_reply_count = $all_replies_count - $public_replies_count;
$this->addToView('private_reply_count', $private_reply_count);
$webapp = Webapp::getInstance();
$sidebar_menu = $webapp->getPostDetailMenu($post);
$this->addToView('sidebar_menu', $sidebar_menu);
$this->loadView($post);
} else {
$this->addErrorMessage('Insufficient privileges');
}
} else {
$this->addErrorMessage('Post not found');
}
} else {
$this->addErrorMessage('Post not specified');
}
}
return $this->generateView();
}
示例2: generateInsight
public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
{
parent::generateInsight($instance, $last_week_of_posts, $number_days);
$this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
$filename = basename(__FILE__, ".php");
foreach ($last_week_of_posts as $post) {
$simplified_post_date = date('Y-m-d', strtotime($post->pub_date));
// Map insight: If not a reply or retweet and geoencoded, show the map in the stream
if (!isset($post->in_reply_to_user_id) && !isset($post->in_reply_to_post_id) && !isset($post->in_retweet_of_post_id) && $post->reply_count_cache > 5) {
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('geoencoder', true);
if (isset($options['gmaps_api_key']->option_value) && $post->is_geo_encoded == 1) {
//Get post's replies and loop through them to make sure at least 5 are indeed geoencoded
$post_dao = DAOFactory::getDAO('PostDAO');
$post_replies = $post_dao->getRepliesToPost($post->post_id, $post->network);
$total_geoencoded_replies = 0;
foreach ($post_replies as $reply) {
if ($reply->is_geo_encoded == 1) {
$total_geoencoded_replies++;
}
}
if ($total_geoencoded_replies > 4) {
$this->insight_dao->insertInsight('geoencoded_replies', $instance->id, $simplified_post_date, "Going global!", "{$this->username}'s post got responses from locations all over the map.", $filename, Insight::EMPHASIS_LOW, serialize($post));
}
}
}
}
$this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
}
示例3: control
/**
* Main control method
* @return Page markup
*/
public function control() {
if ($this->shouldRefreshCache()) {
$this->setViewTemplate(Utils::getPluginViewDirectory('geoencoder').'geoencoder.map.iframe.tpl');
$this->setPageTitle('Locate Post on Map');
$post_dao = DAOFactory::getDAO('PostDAO');
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('geoencoder', true);
if (isset($options['gmaps_api_key']->option_value)) {
$api_key = $options['gmaps_api_key']->option_value;
} else {
$api_key = NULL;
}
$network = (isset($_GET['n']))?$_GET['n']:'twitter';
$type = (isset($_GET['t']))?$_GET['t']:'post';
$post_id = (isset($_GET['pid']))?$_GET['pid']:'post_id';
$post = $post_dao->getPost($post_id, $network);
if ($type == 'post' && isset($post) && $post->is_geo_encoded == 1) {
$this->addToView('post', $post);
$this->addHeaderJavaScript('plugins/geoencoder/assets/js/generatemap.js');
$this->addToView('gmaps_api', $api_key);
$post_rows = $post_dao->getRelatedPostsArray($post_id, $network, !$this->isLoggedIn());
$posts_json = $this->processLocations($post_rows, $post_id);
$this->addToView('posts_data', $posts_json);
} else {
$this->addErrorMessage('This post has not been geoencoded yet; cannot display map.');
}
}
return $this->generateView();
}
示例4: loadSinglePostThread
/**
* Load view with individual post and replies and retweets
* @param int $post_id
* @param str $network
*/
private function loadSinglePostThread($post_id, $network)
{
$this->setPageTitle('Public Post Replies');
$this->post_dao->isPostByPublicInstance($_GET['t'], $network);
$post = $this->post_dao->getPost($post_id, $network);
if (!isset($post)) {
$this->addErrorMessage("Post " . $post_id . " on " . ucwords($network) . " is not in ThinkUp.");
} else {
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('geoencoder', true);
if (isset($options['distance_unit']->option_value)) {
$distance_unit = $options['distance_unit']->option_value;
} else {
$distance_unit = 'km';
}
$public_tweet_replies = $this->post_dao->getPublicRepliesToPost($post->post_id, $network, 'default', $distance_unit);
$public_retweets = $this->post_dao->getRetweetsOfPost($post->post_id, $network, 'default', $distance_unit, true);
$this->addToView('post', $post);
$this->addToView('replies', $public_tweet_replies);
$this->addToView('retweets', $public_retweets);
$this->addToView('unit', $distance_unit);
$rtreach = 0;
foreach ($public_retweets as $t) {
$rtreach += $t->author->follower_count;
}
$this->addToView('rtreach', $rtreach);
}
}
示例5: crawl
public function crawl()
{
$logger = Logger::getInstance();
$config = Config::getInstance();
$instance_dao = DAOFactory::getDAO('InstanceDAO');
$owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('googleplus', true);
//get cached
$current_owner = $owner_dao->getByEmail(Session::getLoggedInUser());
//crawl Google+ users
$instances = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'google+');
if (isset($options['google_plus_client_id']->option_value) && isset($options['google_plus_client_secret']->option_value)) {
foreach ($instances as $instance) {
$logger->setUsername(ucwords($instance->network) . ' | ' . $instance->network_username);
$logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
$tokens = $owner_instance_dao->getOAuthTokens($instance->id);
$access_token = $tokens['oauth_access_token'];
$refresh_token = $tokens['oauth_access_token_secret'];
$instance_dao->updateLastRun($instance->id);
$google_plus_crawler = new GooglePlusCrawler($instance, $access_token);
$dashboard_module_cacher = new DashboardModuleCacher($instance);
try {
$google_plus_crawler->initializeInstanceUser($options['google_plus_client_id']->option_value, $options['google_plus_client_secret']->option_value, $access_token, $refresh_token, $current_owner->id);
$google_plus_crawler->fetchInstanceUserPosts();
} catch (Exception $e) {
$logger->logUserError('EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__);
}
$dashboard_module_cacher->cacheDashboardModules();
$instance_dao->save($google_plus_crawler->instance, 0, $logger);
$logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
}
}
}
示例6: crawl
/**
* Run when the crawler does
*/
public function crawl()
{
$this->logger->setUsername(null);
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('expandurls', true);
//Limit the number of links expanded each crawl
$this->link_limit = isset($options['links_to_expand']->option_value) ? (int) $options['links_to_expand']->option_value : 1500;
if ($this->link_limit != 0) {
//set Flickr API key
if (isset($options['flickr_api_key']->option_value)) {
$flickr_api_key = $options['flickr_api_key']->option_value;
} else {
$flickr_api_key = null;
}
//Get short links into table via initial expansion
self::expandOriginalURLs($flickr_api_key);
//Capture click counts for bit.ly URLs
if (isset($options['bitly_api_key']->option_value, $options['bitly_login']->option_value)) {
self::acquireBitlyClickStats($options['bitly_api_key']->option_value, $options['bitly_login']->option_value);
}
//@TODO Capture click counts for goo.gl URLs
//self::acquireGooglClickStats
} else {
$this->logger->logUserInfo("Limit of links to expand reached.", __METHOD__ . ',' . __LINE__);
}
}
示例7: control
/**
* Main control method
* @return Page markup
*/
public function control()
{
if ($this->shouldRefreshCache()) {
$post_dao = DAOFactory::getDAO('PostDAO');
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('geoencoder', true);
if (isset($options['gmaps_api_key']->option_value)) {
$api_key = $options['gmaps_api_key']->option_value;
} else {
$api_key = NULL;
}
$network = isset($_GET['n']) ? $_GET['n'] : 'twitter';
$type = isset($_GET['t']) ? $_GET['t'] : 'post';
$post_id = isset($_GET['pid']) ? $_GET['pid'] : 'post_id';
if ($type == 'post' && $post_dao->isPostInDB($post_id, $network)) {
$this->addHeaderJavaScript('plugins/geoencoder/assets/js/generatemap.js');
$this->addToView('gmaps_api', $api_key);
$post = $post_dao->getPost($post_id, $network);
$this->addToView('post', $post);
$post_rows = $post_dao->getRelatedPosts($post_id, $network);
$posts_json = $this->processLocations($post_rows, $post_id);
$this->addToView('posts_data', $posts_json);
} else {
$this->addErrorMessage('No visualization data found for this post');
}
}
return $this->generateView();
}
示例8: crawl
public function crawl()
{
$config = Config::getInstance();
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('flickrthumbnails', true);
$api_key = $options['flickr_api_key']->option_value;
if (isset($api_key) && $api_key != '') {
$logger = Logger::getInstance();
$fa = new FlickrAPIAccessor($api_key);
$ldao = DAOFactory::getDAO('LinkDAO');
$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
}
}
示例9: crawl
public function crawl()
{
$config = Config::getInstance();
$logger = Logger::getInstance();
$instance_dao = DAOFactory::getDAO('TwitterInstanceDAO');
$owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$instance_hashtag_dao = DAOFactory::getDAO('InstanceHashtagDAO');
// get oauth values
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('twitter', true);
$current_owner = $owner_dao->getByEmail(Session::getLoggedInUser());
$instances = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'twitter');
foreach ($instances as $instance) {
$logger->setUsername($instance->network_username);
$logger->logUserSuccess("Starting to collect data for " . $instance->network_username . " on Twitter.", __METHOD__ . ',' . __LINE__);
$tokens = $owner_instance_dao->getOAuthTokens($instance->id);
$num_twitter_errors = isset($options['num_twitter_errors']) ? $options['num_twitter_errors']->option_value : null;
$dashboard_module_cacher = new DashboardModuleCacher($instance);
try {
if (isset($tokens['oauth_access_token']) && $tokens['oauth_access_token'] != '' && isset($tokens['oauth_access_token_secret']) && $tokens['oauth_access_token_secret'] != '') {
$archive_limit = isset($options['archive_limit']->option_value) ? $options['archive_limit']->option_value : 3200;
$api = new CrawlerTwitterAPIAccessorOAuth($tokens['oauth_access_token'], $tokens['oauth_access_token_secret'], $options['oauth_consumer_key']->option_value, $options['oauth_consumer_secret']->option_value, $archive_limit, $num_twitter_errors);
$twitter_crawler = new TwitterCrawler($instance, $api);
$instance_dao->updateLastRun($instance->id);
$twitter_crawler->fetchInstanceUserTweets();
$twitter_crawler->fetchInstanceUserMentions();
$twitter_crawler->fetchInstanceUserFriends();
$twitter_crawler->fetchInstanceUserFollowers();
$twitter_crawler->fetchInstanceUserGroups();
$twitter_crawler->fetchRetweetsOfInstanceUser();
$twitter_crawler->fetchInstanceUserFavorites();
$twitter_crawler->updateStaleGroupMemberships();
$twitter_crawler->fetchStrayRepliedToTweets();
$twitter_crawler->fetchUserFriendsByIDs();
$twitter_crawler->fetchUnloadedFriendDetails();
$twitter_crawler->fetchUnloadedFollowerDetails();
$twitter_crawler->cleanUpFollows();
$twitter_crawler->updateFriendsProfiles();
//Retrieve search results for saved keyword/hashtags
$instances_hashtags = $instance_hashtag_dao->getByInstance($instance->id);
foreach ($instances_hashtags as $instance_hashtag) {
$twitter_crawler->fetchInstanceHashtagTweets($instance_hashtag);
}
} else {
throw new Exception('Missing Twitter OAuth tokens.');
}
} catch (Exception $e) {
$logger->logUserError(get_class($e) . " while crawling " . $instance->network_username . " on Twitter: " . $e->getMessage(), __METHOD__ . ',' . __LINE__);
}
$dashboard_module_cacher->cacheDashboardModules();
// Save instance
if (isset($twitter_crawler->user)) {
$instance_dao->save($instance, $twitter_crawler->user->post_count, $logger);
}
Reporter::reportVersion($instance);
$logger->logUserSuccess("Finished collecting data for " . $instance->network_username . " on Twitter.", __METHOD__ . ',' . __LINE__);
}
}
示例10: __construct
/**
* Constructor
* @param Instance $instance
* @param CrawlerTwitterAPIAccessorOAuth $api
* @return TwitterCrawler
*/
public function __construct($instance, $api) {
$this->instance = $instance;
$this->api = $api;
$this->logger = Logger::getInstance();
$this->logger->setUsername($instance->network_username);
$this->user_dao = DAOFactory::getDAO('UserDAO');
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$this->twitter_options = $plugin_option_dao->getOptionsHash('twitter');
}
示例11: crawl
public function crawl()
{
$logger = Logger::getInstance();
$config = Config::getInstance();
$instance_dao = DAOFactory::getDAO('InstagramInstanceDAO');
$owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('instagram', true);
//get cached
$max_api_calls = isset($options['max_api_calls']) ? $options['max_api_calls']->option_value : 2500;
$current_owner = $owner_dao->getByEmail(Session::getLoggedInUser());
//crawl instagram user profiles and pages
$instances = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'instagram');
foreach ($instances as $instance) {
$logger->setUsername(ucwords($instance->network) . ' | ' . $instance->network_username);
$logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
$tokens = $owner_instance_dao->getOAuthTokens($instance->id);
$access_token = $tokens['oauth_access_token'];
$instance_dao->updateLastRun($instance->id);
$dashboard_module_cacher = new DashboardModuleCacher($instance);
try {
/**
* 1. Fetch user info, media + its likes and comments.
* 2. Fetch user's likes.
* 3. Fetch user's friends, and update stale relationships.
* 4. Fetch user's followers, and update stale relationships.
* 5. Update stale friends' profiles.
*/
$instagram_crawler = new InstagramCrawler($instance, $access_token, $max_api_calls);
$instagram_crawler->fetchPostsAndReplies();
$instagram_crawler->fetchLikes();
$instagram_crawler->fetchFriends();
$instagram_crawler->fetchFollowers();
$instagram_crawler->updateStaleFriendsProfiles();
} catch (Instagram\Core\ApiAuthException $e) {
//The access token is invalid, save in owner_instances table
$owner_instance_dao->setAuthErrorByTokens($instance->id, $access_token, '', $e->getMessage());
//Send email alert
//Get owner by auth tokens first, then send to that person
$owner_email_to_notify = $owner_instance_dao->getOwnerEmailByInstanceTokens($instance->id, $access_token, '');
$email_attempt = $this->sendInvalidOAuthEmailAlert($owner_email_to_notify, $instance->network_username);
if ($email_attempt) {
$logger->logUserInfo('Sent reauth email to ' . $owner_email_to_notify, __METHOD__ . ',' . __LINE__);
} else {
$logger->logInfo('Didn\'t send reauth email to ' . $owner_email_to_notify, __METHOD__ . ',' . __LINE__);
}
$logger->logUserError(get_class($e) . ' ' . $e->getMessage(), __METHOD__ . ',' . __LINE__);
} catch (Exception $e) {
$logger->logUserError(get_class($e) . ' ' . $e->getMessage(), __METHOD__ . ',' . __LINE__);
}
$dashboard_module_cacher->cacheDashboardModules();
$instance_dao->save($instagram_crawler->instance, 0, $logger);
Reporter::reportVersion($instance);
$logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
}
}
示例12: crawl
public function crawl()
{
$logger = Logger::getInstance();
$config = Config::getInstance();
$instance_dao = DAOFactory::getDAO('InstanceDAO');
$owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('foursquare', true);
$current_owner = $owner_dao->getByEmail(Session::getLoggedInUser());
$instances = $instance_dao->getAllActiveInstancesStalestFirstByNetwork('foursquare');
// Check the client id and secret are set or we can't crawl
if (isset($options['foursquare_client_id']->option_value) && isset($options['foursquare_client_secret']->option_value)) {
// For each instance of foursquare on this install
foreach ($instances as $instance) {
if (!$owner_instance_dao->doesOwnerHaveAccessToInstance($current_owner, $instance)) {
// Owner doesn't have access to this instance; let's not crawl it.
continue;
}
// Set the user name in the log
$logger->setUsername(ucwords($instance->network) . ' | ' . $instance->network_username);
// Write to the log that we have started to collect data
$logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
// Get the OAuth tokens for this user
$tokens = $owner_instance_dao->getOAuthTokens($instance->id);
// Set the access token
$access_token = $tokens['oauth_access_token'];
// Update the last time we crawled
$instance_dao->updateLastRun($instance->id);
// Create a new crawler
$crawler = new FoursquareCrawler($instance, $access_token);
// Check the OAuth tokens we have are valid
try {
$logger->logInfo("About to initializeInstanceUser", __METHOD__ . ',' . __LINE__);
$user = $crawler->initializeInstanceUser($access_token, $current_owner->id);
if (isset($user) && $user instanceof User) {
$logger->logInfo("User initialized", __METHOD__ . ',' . __LINE__);
}
// Get the data we want and store it in the database
$logger->logInfo("About to fetchInstanceUserCheckins", __METHOD__ . ',' . __LINE__);
$crawler->fetchInstanceUserCheckins();
} catch (Exception $e) {
// Catch any errors that happen when we check the validity of the OAuth tokens
$logger->logUserError('EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__);
}
$logger->logInfo("About to cache dashboard modules", __METHOD__ . ',' . __LINE__);
// Cache the insights to improve the page load speed of the dashboard
$dashboard_module_cacher = new DashboardModuleCacher($instance);
$dashboard_module_cacher->cacheDashboardModules();
$instance_dao->save($crawler->instance, 0, $logger);
Reporter::reportVersion($instance);
// Tell the user crawling was sucessful
$logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
}
}
}
示例13: crawl
public function crawl()
{
$logger = Logger::getInstance();
$config = Config::getInstance();
$instance_dao = DAOFactory::getDAO('FacebookInstanceDAO');
$owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('facebook', true);
//get cached
$max_crawl_time = isset($options['max_crawl_time']) ? $options['max_crawl_time']->option_value : 20;
//convert to seconds
$max_crawl_time = $max_crawl_time * 60;
$current_owner = $owner_dao->getByEmail(Session::getLoggedInUser());
//crawl Facebook user profiles and pages
$profiles = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'facebook');
$pages = $instance_dao->getActiveInstancesStalestFirstForOwnerByNetworkNoAuthError($current_owner, 'facebook page');
$instances = array_merge($profiles, $pages);
foreach ($instances as $instance) {
$logger->setUsername(ucwords($instance->network) . ' | ' . $instance->network_username);
$logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
$tokens = $owner_instance_dao->getOAuthTokens($instance->id);
$access_token = $tokens['oauth_access_token'];
$instance_dao->updateLastRun($instance->id);
$facebook_crawler = new FacebookCrawler($instance, $access_token, $max_crawl_time);
$dashboard_module_cacher = new DashboardModuleCacher($instance);
try {
$facebook_crawler->fetchPostsAndReplies();
} catch (APIOAuthException $e) {
$logger->logUserError(get_class($e) . ": " . $e->getMessage(), __METHOD__ . ',' . __LINE__);
//Don't send reauth email if it's app-level API rate limting
//https://developers.facebook.com/docs/reference/ads-api/api-rate-limiting/#applimit
if (strpos($e->getMessage(), 'Application request limit reached') === false && strpos($e->getMessage(), 'Please retry your request later.') === false) {
//The access token is invalid, save in owner_instances table
$owner_instance_dao->setAuthErrorByTokens($instance->id, $access_token, '', $e->getMessage());
//Send email alert
//Get owner by auth tokens first, then send to that person
$owner_email_to_notify = $owner_instance_dao->getOwnerEmailByInstanceTokens($instance->id, $access_token, '');
$email_attempt = $this->sendInvalidOAuthEmailAlert($owner_email_to_notify, $instance->network_username);
if ($email_attempt) {
$logger->logUserInfo('Sent reauth email to ' . $owner_email_to_notify, __METHOD__ . ',' . __LINE__);
} else {
$logger->logInfo('Didn\'t send reauth email to ' . $owner_email_to_notify, __METHOD__ . ',' . __LINE__);
}
} else {
$logger->logInfo('Facebook API returned an error: ' . $e->getMessage() . ' Do nothing now and try again later', __METHOD__ . ',' . __LINE__);
}
} catch (Exception $e) {
$logger->logUserError(get_class($e) . ": " . $e->getMessage(), __METHOD__ . ',' . __LINE__);
}
$dashboard_module_cacher->cacheDashboardModules();
$instance_dao->save($facebook_crawler->instance, 0, $logger);
Reporter::reportVersion($instance);
$logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s " . ucwords($instance->network), __METHOD__ . ',' . __LINE__);
}
}
示例14: authControl
/**
* @return str
*/
public function authControl()
{
$config = Config::getInstance();
Loader::definePathConstants();
$this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/twitterrealtime/view/twitterrealtime.account.index.tpl');
$this->view_mgr->addHelp('twitterrealtime', 'userguide/settings/plugins/twitterrealtime');
$id = DAOFactory::getDAO('InstanceDAO');
$od = DAOFactory::getDAO('OwnerDAO');
// get plugin option values if defined...
$plugin_options = $this->getPluginOptions();
// get oauth option values from twitter plugin.
// @TODO -- what is the right way to do this?
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$twitter_options = $plugin_option_dao->getOptionsHash('twitter', true);
$oauth_consumer_key = null;
if (isset($twitter_options['oauth_consumer_key'])) {
$oauth_consumer_key = $twitter_options['oauth_consumer_key']->option_value;
}
$oauth_consumer_secret = null;
if (isset($twitter_options['oauth_consumer_secret'])) {
$oauth_consumer_secret = $twitter_options['oauth_consumer_secret']->option_value;
}
// @TODO - get any other option values as necessary
// $archive_limit = $this->getPluginOption('archive_limit');
$auth_from_twitter = '';
if (isset($oauth_consumer_key) && isset($oauth_consumer_secret)) {
$to = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret);
/* Request tokens from twitter */
$tok = $to->getRequestToken();
if (isset($tok['oauth_token'])) {
$token = $tok['oauth_token'];
$_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret'];
/* Build the authorization URL */
$oauthorize_link = $to->getAuthorizeURL($token);
// create indication that auth from twitter plugin is okay
$auth_from_twitter = "Using the Twitter Consumer key and secret as set in " . "the <a href=\"./?p=twitter\">Twitter plugin</a>.";
} else {
//set error message here
$this->addErrorMessage("Unable to obtain OAuth token. Check your Twitter plugin consumer key and secret configuration.");
$oauthorize_link = '';
}
} else {
$this->addErrorMessage("Missing required settings! Please configure the Twitter plugin.");
$oauthorize_link = '';
}
$owner_instances = $id->getByOwnerAndNetwork($this->owner, 'twitter');
$this->addToView('owner_instances', $owner_instances);
$this->addToView('oauthorize_link', $oauthorize_link);
$this->addToView('auth_from_twitter', $auth_from_twitter);
// add plugin options from
$this->addOptionForm();
$plugin = new TwitterRealtimePlugin();
$this->addToView('is_configured', $plugin->isConfigured());
return $this->generateView();
}
示例15: authControl
public function authControl()
{
if (!$this->is_missing_param) {
$fb_user = null;
$msg = '';
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('facebook', true);
//get cached
$facebook = new Facebook($options['facebook_api_key']->option_value, $options['facebook_api_secret']->option_value);
$fb_user = $facebook->api_client->users_getLoggedInUser();
$msg .= "Facebook user is logged in and user ID set<br />";
$fb_username = $facebook->api_client->users_getInfo($fb_user, 'name');
if (isset($_GET['sessionKey']) && isset($fb_user) && $fb_user > 0) {
$fb_username = $fb_username[0]['name'];
$session_key = $_GET['sessionKey'];
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$instance_dao = DAOFactory::getDAO('InstanceDAO');
$oid = DAOFactory::getDAO('OwnerInstanceDAO');
$user_dao = DAOFactory::getDAO('UserDAO');
$owner = $owner_dao->getByEmail($this->getLoggedInUser());
$i = $instance_dao->getByUserIdOnNetwork($fb_user, 'facebook');
if (isset($i)) {
$msg .= "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
$msg .= "Created owner instance.<br />";
}
} else {
//Instance does not exist
$msg .= "Instance does not exist<br />";
$instance_dao->insert($fb_user, $fb_username, 'facebook');
$msg .= "Created instance";
$i = $instance_dao->getByUserIdOnNetwork($fb_user, 'facebook');
$oid->insert($owner->id, $i->id, $session_key);
$msg .= "Created owner instance.<br />";
}
if (!$user_dao->isUserInDB($fb_user, 'facebook')) {
$r = array('user_id' => $fb_user, 'user_name' => $fb_username, 'full_name' => $fb_username, 'avatar' => '', 'location' => '', 'description' => '', 'url' => '', 'is_protected' => '', 'follower_count' => 0, 'friend_count' => 0, 'post_count' => 0, 'last_updated' => '', 'last_post' => '', 'joined' => '', 'last_post_id' => '', 'network' => 'facebook');
$u = new User($r, 'Owner info');
$user_dao->updateUser($u);
}
} else {
$msg .= "No session key or logged in Facebook user.";
}
$config = Config::getInstance();
$msg .= '<br /> <a href="' . $config->getValue('site_root_path') . 'account/">Back to your account</a>.';
$this->addInfoMessage($msg);
}
return $this->generateView();
}