本文整理汇总了PHP中Session::getLoggedInUser方法的典型用法代码示例。如果您正苦于以下问题:PHP Session::getLoggedInUser方法的具体用法?PHP Session::getLoggedInUser怎么用?PHP Session::getLoggedInUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Session
的用法示例。
在下文中一共展示了Session::getLoggedInUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: crawl
/**
* Gets called when crawler runs.
*
* About crawler exclusivity (mutex usage):
* When launched by an admin, no other user, admin or not, will be able to launch a crawl until this one is done.
* When launched by a non-admin, we first check that no admin run is under way, and if that's the case,
* we launch a crawl for the current user only.
* No user will be able to launch two crawls in parallel, but different non-admin users crawls can run in parallel.
*/
public function crawl()
{
if (!Session::isLoggedIn()) {
throw new UnauthorizedUserException('You need a valid session to launch the crawler.');
}
$mutex_dao = DAOFactory::getDAO('MutexDAO');
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
if (empty($owner)) {
throw new UnauthorizedUserException('You need a valid session to launch the crawler.');
}
$global_mutex_name = 'crawler';
// Everyone needs to check the global mutex
$lock_successful = $mutex_dao->getMutex($global_mutex_name);
if ($lock_successful) {
// Global mutex was free, which means no admin crawls are under way
if ($owner->is_admin) {
// Nothing more needs to be done, since admins use the global mutex
$mutex_name = $global_mutex_name;
} else {
// User is a non-admin; let's use a user mutex.
$mutex_name = 'crawler-' . $owner->id;
$lock_successful = $mutex_dao->getMutex($mutex_name);
$mutex_dao->releaseMutex($global_mutex_name);
}
}
if ($lock_successful) {
$this->emitObjectMethod('crawl');
$mutex_dao->releaseMutex($mutex_name);
} else {
throw new CrawlerLockedException("Error starting crawler; another crawl is already in progress.");
}
}
示例2: testOutput
public function testOutput()
{
//not logged in
$controller = new TwitterPluginHashtagConfigurationController(null, 'twitter', 'ginatrapani');
$output = $controller->go();
$v_mgr = $controller->getViewManager();
$config = Config::getInstance();
$this->assertEqual('You must <a href="' . $config->getValue('site_root_path') . 'session/login.php">log in</a> to do this.', $v_mgr->getTemplateDataItem('error_msg'));
//logged in, no user set up
$this->simulateLogin('me@example.com');
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
$controller = new TwitterPluginHashtagConfigurationController(null, 'twitter', 'ginatrapani');
$output = $controller->go();
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('user'), 'string');
$this->assertEqual('Twitter user @ginatrapani does not exist.', $v_mgr->getTemplateDataItem('error_msg'));
//logged in, user set up
$builders = array();
$builders[] = FixtureBuilder::build('instances', array('network_username' => 'ginatrapani', 'network' => 'twitter'));
$controller = new TwitterPluginHashtagConfigurationController(null, 'twitter', 'ginatrapani');
$output = $controller->go();
$v_mgr = $controller->getViewManager();
$this->assertIsA($v_mgr->getTemplateDataItem('user'), 'string');
$this->assertIsA($v_mgr->getTemplateDataItem('hashtags'), 'array');
}
示例3: 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__);
}
}
}
示例4: go
public function go()
{
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
if (isset($_GET['source']) && $_GET['source'] == "new") {
$this->addSuccessMessage("Article has been added succesfully");
}
if (isset($_POST['submit'])) {
if ($_POST['title'] == '') {
$this->addErrorMessage("Title of the article should not be empty");
} elseif (!isset($_POST['is_published'])) {
$this->addErrorMessage("Please tell if the article has been published successfully?");
} elseif ($_POST['content'] == '') {
$this->addErrorMessage("Article post should not be empty");
} else {
$this->title = $_POST['title'];
$this->is_published = $_POST['is_published'];
$this->content = $_POST['content'];
$this->last_modified = date("Y-m-d H-i-s");
$this->last_modified_by = Session::getLoggedInUser();
ArticleBackend::updateArticle($id, $this->title, $this->content, $this->last_modified, $this->last_modified_by);
$this->addSuccessMessage("Article has been updated succesfully");
}
}
$article = ArticleBackend::getArticle($id);
$this->setViewTemplate('editarticle.tpl');
$this->addToView('article', $article[0]);
$this->generateView();
if (isset($_POST['deletesubmit'])) {
ArticleBackend::deleteArticle($id);
header('Location:' . SOURCE_ROOT_PATH . "admin/pages/articlemanager.php?source=del");
}
}
示例5: 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__);
}
}
示例6: 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__);
}
}
示例7: 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__);
}
}
}
示例8: 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__);
}
}
示例9: checkUserPermission
public static function checkUserPermission()
{
$user = Session::getLoggedInUser();
if (Session::isUser()) {
// You are allowed to perform operation
return true;
} else {
return Session::throwHimOut();
}
}
示例10: getController
private function getController($logged_in, $is_admin = false)
{
if ($logged_in) {
$this->simulateLogin('me@example.com', $is_admin);
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
$controller = new InsightsGeneratorPluginConfigurationController($owner);
} else {
$controller = new InsightsGeneratorPluginConfigurationController(true);
}
return $controller;
}
开发者ID:jkuehl-carecloud,项目名称:ThinkUp,代码行数:12,代码来源:TestOfInsightsGeneratorPluginConfigurationController.php
示例11: crawl
public function crawl()
{
$logger = Logger::getInstance();
$config = Config::getInstance();
$id = DAOFactory::getDAO('InstanceDAO');
$oid = DAOFactory::getDAO('OwnerInstanceDAO');
$od = DAOFactory::getDAO('OwnerDAO');
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('facebook', true);
//get cached
$current_owner = $od->getByEmail(Session::getLoggedInUser());
//crawl Facebook user profiles
$instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook');
foreach ($instances as $instance) {
if (!$oid->doesOwnerHaveAccess($current_owner, $instance)) {
// Owner doesn't have access to this instance; let's not crawl it.
continue;
}
$logger->setUsername($instance->network_username);
$logger->logUserSuccess("Starting to collect data for " . $instance->network_username . " on Facebook.", __METHOD__ . ',' . __LINE__);
$tokens = $oid->getOAuthTokens($instance->id);
$access_token = $tokens['oauth_access_token'];
$id->updateLastRun($instance->id);
$crawler = new FacebookCrawler($instance, $access_token);
try {
$crawler->fetchInstanceUserInfo();
$crawler->fetchUserPostsAndReplies($instance->network_user_id);
} catch (Exception $e) {
$logger->logUserError('PROFILE EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__);
}
$id->save($crawler->instance, 0, $logger);
$logger->logUserSuccess("Finished collecting data for " . $instance->network_username . " on Facebook.", __METHOD__ . ',' . __LINE__);
}
//crawl Facebook pages
$instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook page');
foreach ($instances as $instance) {
$logger->setUsername($instance->network_username);
$logger->logUserSuccess("Starting to collect data for " . $instance->network_username . "'s Facebook Page.", __METHOD__ . ',' . __LINE__);
$tokens = $oid->getOAuthTokens($instance->id);
$access_token = $tokens['oauth_access_token'];
$id->updateLastRun($instance->id);
$crawler = new FacebookCrawler($instance, $access_token);
try {
$crawler->fetchPagePostsAndReplies($instance->network_user_id);
} catch (Exception $e) {
$logger->logUserError('PAGE EXCEPTION: ' . $e->getMessage(), __METHOD__ . ',' . __LINE__);
}
$id->save($crawler->instance, 0, $logger);
$logger->logUserSuccess("Finished collecting data for " . $instance->network_username . "'s Facebook Page.", __METHOD__ . ',' . __LINE__);
}
}
示例12: crawl
public function crawl()
{
$logger = Logger::getInstance();
$config = Config::getInstance();
$id = DAOFactory::getDAO('InstanceDAO');
$oid = DAOFactory::getDAO('OwnerInstanceDAO');
$od = DAOFactory::getDAO('OwnerDAO');
$plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
$options = $plugin_option_dao->getOptionsHash('facebook', true);
//get cached
$current_owner = $od->getByEmail(Session::getLoggedInUser());
//crawl Facebook user profiles
$instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook');
foreach ($instances as $instance) {
if (!$oid->doesOwnerHaveAccess($current_owner, $instance)) {
// Owner doesn't have access to this instance; let's not crawl it.
continue;
}
$logger->setUsername($instance->network_username);
$tokens = $oid->getOAuthTokens($instance->id);
$session_key = $tokens['oauth_access_token'];
$fb = new Facebook($options['facebook_api_key']->option_value, $options['facebook_api_secret']->option_value);
$id->updateLastRun($instance->id);
$crawler = new FacebookCrawler($instance, $fb);
try {
$crawler->fetchInstanceUserInfo($instance->network_user_id, $session_key);
$crawler->fetchUserPostsAndReplies($instance->network_user_id, $session_key);
} catch (Exception $e) {
$logger->logStatus('PROFILE EXCEPTION: ' . $e->getMessage(), get_class($this));
}
$id->save($crawler->instance, $crawler->owner_object->post_count, $logger);
}
//crawl Facebook pages
$instances = $id->getAllActiveInstancesStalestFirstByNetwork('facebook page');
foreach ($instances as $instance) {
$logger->setUsername($instance->network_username);
$tokens = $oid->getOAuthTokens($instance->id);
$session_key = $tokens['oauth_access_token'];
$fb = new Facebook($options['facebook_api_key']->option_value, $options['facebook_api_secret']->option_value);
$id->updateLastRun($instance->id);
$crawler = new FacebookCrawler($instance, $fb);
try {
$crawler->fetchPagePostsAndReplies($instance->network_user_id, $instance->network_viewer_id, $session_key);
} catch (Exception $e) {
$logger->logStatus('PAGE EXCEPTION: ' . $e->getMessage(), get_class($this));
}
$id->save($crawler->instance, 0, $logger);
}
$logger->close();
# Close logging
}
示例13: testConfigOptionsIsAdmin
public function testConfigOptionsIsAdmin()
{
// build some options data
$builders = $this->buildPluginData();
$this->simulateLogin('me@example.com', true);
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
$controller = new TwitterRealtimePluginConfigurationController($owner, 'twitterrealtime');
$output = $controller->go();
$this->assertPattern('/save options/', $output);
// should have no submit option
$this->assertPattern('/php_path/', $output);
$this->assertPattern('/redis/', $output);
// should have secret option
}
开发者ID:narpaldhillon,项目名称:ThinkUp,代码行数:15,代码来源:TestOfTwitterRealtimePluginConfigurationController.php
示例14: testOutputNoParams
public function testOutputNoParams()
{
// build some options data
$options_arry = $this->buildPluginOptions();
//not logged in, no owner set
$controller = new FlickrThumbnailsPluginConfigurationController(null, 'flickrthumbnails');
$output = $controller->go();
$v_mgr = $controller->getViewManager();
$config = Config::getInstance();
$this->assertEqual('You must <a href="' . $config->getValue('site_root_path') . 'session/login.php">log in</a> to do this.', $v_mgr->getTemplateDataItem('errormsg'));
//logged in
$this->simulateLogin('me@example.com');
$owner_dao = DAOFactory::getDAO('OwnerDAO');
$owner = $owner_dao->getByEmail(Session::getLoggedInUser());
$controller = new FlickrThumbnailsPluginConfigurationController($owner, 'flickrthumbnails');
$output = $controller->go();
$this->assertPattern('/Flickr API key/', $output);
}
示例15: update
public function update($status)
{
if (!Session::isAdmin() && !Session::isTeacher()) {
$username = Session::getLoggedInUser();
$url = $_SERVER['REQUEST_URI'];
$url_components = explode("/", $url);
$count_url_components = count($url_components);
for ($i = 0; $url_components[$i] != "challenges"; $i++) {
}
$pkg_name = $url_components[$i + 1];
$user = User::findByUserName($username);
$challenge = Challenge::getChallengeByPkgName($pkg_name);
$user_id = $user->id;
$challenge_id = $challenge[0]->id;
if (!ChallengeAttempts::isChallengeCleared($user_id, $challenge_id)) {
ChallengeAttempts::addChallengeAttempt($user_id, $challenge_id, $status);
}
}
}