当前位置: 首页>>代码示例>>PHP>>正文


PHP Utils::getApplicationURL方法代码示例

本文整理汇总了PHP中Utils::getApplicationURL方法的典型用法代码示例。如果您正苦于以下问题:PHP Utils::getApplicationURL方法的具体用法?PHP Utils::getApplicationURL怎么用?PHP Utils::getApplicationURL使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Utils的用法示例。


在下文中一共展示了Utils::getApplicationURL方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: control

 public function control()
 {
     $this->redirectToSternIndiaEndpoint('forgot.php');
     $config = Config::getInstance();
     //$this->addToView('is_registration_open', $config->getValue('is_registration_open'));
     // if (isset($_POST['email']) && $_POST['Submit'] == 'Send Reset') {
     // /$_POST['email'] = 'prabhat@sternindia.com';
     if (isset($_POST['email'])) {
         $this->disableCaching();
         $dao = DAOFactory::getDAO('UserDAO');
         $user = $dao->getByEmail($_POST['email']);
         if (isset($user)) {
             $token = $user->setPasswordRecoveryToken();
             $es = new ViewManager();
             $es->caching = false;
             //$es->assign('apptitle', $config->getValue('app_title_prefix')."ThinkUp" );
             $es->assign('first_name', $user->first_name);
             $es->assign('recovery_url', "session/reset.php?token={$token}");
             $es->assign('application_url', Utils::getApplicationURL(false));
             $es->assign('site_root_path', $config->getValue('site_root_path'));
             $message = $es->fetch('_email.forgotpassword.tpl');
             $subject = $config->getValue('app_title_prefix') . "Stern India Password Recovery";
             //Will put the things in queue to mail the things.
             Resque::enqueue('user_mail', 'Mailer', array($_POST['email'], $subject, $message));
             $this->addToView('link_sent', true);
         } else {
             $this->addErrorMessage('Error: account does not exist.');
         }
     }
     $this->setViewTemplate('Session/forgot.tpl');
     return $this->generateView();
 }
开发者ID:prabhatse,项目名称:olx_hack,代码行数:32,代码来源:class.ForgotPasswordController.php

示例2: reportVersion

 /**
  * Report installation version back to thinkup.com. If usage reporting is enabled, include instance username
  * and network.
  * @param Instance $instance
  * @return array ($report_back_url, $referer_url, $status, $contents)
  */
 public static function reportVersion(Instance $instance)
 {
     //Build URLs with appropriate parameters
     $config = Config::getInstance();
     $report_back_url = 'http://thinkup.com/version.php?v=' . $config->getValue('THINKUP_VERSION');
     //Explicity set referer for when this is called by a command line script
     $referer_url = Utils::getApplicationURL();
     //If user hasn't opted out, report back username and network
     if ($config->getValue('is_opted_out_usage_stats') === true) {
         $report_back_url .= '&usage=n';
     } else {
         $referer_url .= "?u=" . urlencode($instance->network_username) . "&n=" . urlencode($instance->network);
     }
     $in_test_mode = isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS" || getenv("MODE") == "TESTS";
     if (!$in_test_mode) {
         //only make live request if we're not running the test suite
         //Make the cURL request
         $c = curl_init();
         curl_setopt($c, CURLOPT_URL, $report_back_url);
         curl_setopt($c, CURLOPT_REFERER, $referer_url);
         curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
         $contents = curl_exec($c);
         $status = curl_getinfo($c, CURLINFO_HTTP_CODE);
         curl_close($c);
     } else {
         $contents = '';
         $status = 200;
     }
     return array($report_back_url, $referer_url, $status, $contents);
 }
开发者ID:nagyistoce,项目名称:ThinkUp,代码行数:36,代码来源:class.Reporter.php

示例3: authControl

 public function authControl()
 {
     $config = Config::getInstance();
     Loader::definePathConstants();
     $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/geoencoder/view/geoencoder.account.index.tpl');
     $this->view_mgr->addHelp('geoencoder', 'userguide/settings/plugins/geoencoder');
     $this->addToView('message', 'This is the GeoEncoder plugin configuration page for ' . $this->owner->email . '.');
     /** set option fields **/
     // gmaps_api_key text field
     $name_field = array('name' => 'gmaps_api_key', 'label' => 'Google Maps API Key', 'size' => 55);
     $this->addPluginOption(self::FORM_TEXT_ELEMENT, $name_field);
     $this->addPluginOptionRequiredMessage('gmaps_api_key', 'Please enter your Google Maps API Key');
     // distance_unit radio field
     $distance_unit_field = array('name' => 'distance_unit', 'label' => 'Unit of Distance');
     $distance_unit_field['values'] = array('Kilometers' => 'km', 'Miles' => 'mi');
     $distance_unit_field['default_value'] = 'km';
     $this->addPluginOption(self::FORM_RADIO_ELEMENT, $distance_unit_field);
     $plugin = new GeoEncoderPlugin();
     if (!$plugin->isConfigured()) {
         $this->addInfoMessage('Please complete plugin setup to start using it.', 'setup');
         $this->addToView('is_configured', false);
     } else {
         $this->addToView('is_configured', true);
     }
     $this->addToView('thinkup_site_url', Utils::getApplicationURL());
     return $this->generateView();
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:27,代码来源:class.GeoEncoderPluginConfigurationController.php

示例4: control

 public function control()
 {
     $config = Config::getInstance();
     $this->addToView('is_registration_open', $config->getValue('is_registration_open'));
     if (isset($_POST['Submit']) && $_POST['Submit'] == 'Send Reset') {
         $this->disableCaching();
         $dao = DAOFactory::getDAO('OwnerDAO');
         $user = $dao->getByEmail($_POST['email']);
         if (isset($user)) {
             $token = $user->setPasswordRecoveryToken();
             $es = new ViewManager();
             $es->caching = false;
             $es->assign('apptitle', $config->getValue('app_title_prefix') . "ThinkUp");
             $es->assign('recovery_url', "session/reset.php?token={$token}");
             $es->assign('application_url', Utils::getApplicationURL($false));
             $es->assign('site_root_path', $config->getValue('site_root_path'));
             $message = $es->fetch('_email.forgotpassword.tpl');
             Mailer::mail($_POST['email'], $config->getValue('app_title_prefix') . "ThinkUp Password Recovery", $message);
             $this->addSuccessMessage('Password recovery information has been sent to your email address.');
         } else {
             $this->addErrorMessage('Error: account does not exist.');
         }
     }
     $this->view_mgr->addHelp('forgot', 'userguide/accounts/index');
     $this->setViewTemplate('session.forgot.tpl');
     return $this->generateView();
 }
开发者ID:kuthulas,项目名称:ProjectX,代码行数:27,代码来源:class.ForgotPasswordController.php

示例5: authControl

 public function authControl()
 {
     $config = Config::getInstance();
     Loader::definePathConstants();
     $this->setViewTemplate(THINKUP_WEBAPP_PATH . 'plugins/twitter/view/twitter.account.index.tpl');
     $this->view_mgr->addHelp('twitter', 'userguide/settings/plugins/twitter/index');
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     // get plugin option values if defined...
     $plugin_options = $this->getPluginOptions();
     $oauth_consumer_key = $this->getPluginOption('oauth_consumer_key');
     $oauth_consumer_secret = $this->getPluginOption('oauth_consumer_secret');
     $archive_limit = $this->getPluginOption('archive_limit');
     $num_twitter_errors = $this->getPluginOption('num_twitter_errors');
     $this->addToView('twitter_app_name', "ThinkUp " . $_SERVER['SERVER_NAME']);
     $this->addToView('thinkup_site_url', Utils::getApplicationURL(true));
     $plugin = new TwitterPlugin();
     if ($plugin->isConfigured()) {
         $this->addToView('is_configured', true);
         $owner_instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'twitter');
         $this->addToView('owner_instances', $owner_instances);
         if (isset($this->owner) && $this->owner->isMemberAtAnyLevel()) {
             if ($this->owner->isMemberLevel()) {
                 if (sizeof($owner_instances) > 0) {
                     $this->do_show_add_button = false;
                     $this->addInfoMessage("To connect another Twitter account to ThinkUp, upgrade your membership.", 'membership_cap');
                 }
             }
         }
         if (isset($_GET['oauth_token']) || $this->do_show_add_button) {
             $twitter_oauth = new TwitterOAuth($oauth_consumer_key, $oauth_consumer_secret);
             /* Request tokens from twitter */
             $token_array = $twitter_oauth->getRequestToken(Utils::getApplicationURL(true) . "account/?p=twitter");
             if (isset($token_array['oauth_token']) || isset($_SESSION["MODE"]) && $_SESSION["MODE"] == "TESTS" || getenv("MODE") == "TESTS") {
                 //testing
                 $token = $token_array['oauth_token'];
                 SessionCache::put('oauth_request_token_secret', $token_array['oauth_token_secret']);
                 if (isset($_GET['oauth_token'])) {
                     self::addAuthorizedUser($oauth_consumer_key, $oauth_consumer_secret, $num_twitter_errors);
                 }
                 if ($this->do_show_add_button) {
                     /* Build the authorization URL */
                     $oauthorize_link = $twitter_oauth->getAuthorizeURL($token);
                     $this->addToView('oauthorize_link', $oauthorize_link);
                 }
             } else {
                 //set error message here
                 $this->addErrorMessage("Unable to obtain OAuth tokens from Twitter. Please double-check the consumer key and secret " . "are correct.", "setup");
                 $oauthorize_link = '';
                 $this->addToView('is_configured', false);
             }
         }
     } else {
         $this->addInfoMessage('Please complete plugin setup to start using it.', 'setup');
         $this->addToView('is_configured', false);
     }
     // add plugin options from
     $this->addOptionForm();
     return $this->generateView();
 }
开发者ID:nagyistoce,项目名称:ThinkUp,代码行数:59,代码来源:class.TwitterPluginConfigurationController.php

示例6: bounce

 /**
  * Bounce user to public page or to error page.
  * @throws ControllerAuthException
  */
 protected function bounce()
 {
     if ($this->content_type == 'text/html; charset=UTF-8' && $this->url_mapping != null) {
         $this->redirect(Utils::getApplicationURL() . 'session/login.php?redirect=' . $this->url_mapping);
     } else {
         throw new ControllerAuthException('You must log in to access this controller: ' . get_class($this));
     }
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:12,代码来源:class.ThinkUpAuthController.php

示例7: control

 public function control()
 {
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $hours_since_last_crawl = $instance_dao->getHoursSinceLastCrawlerRun();
     if (isset($hours_since_last_crawl) && $hours_since_last_crawl > $this->threshold) {
         $this->addToView('message', Utils::getApplicationURL() . ": Crawler hasn't run in " . round($hours_since_last_crawl) . " hours");
     }
     return $this->generateView();
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:9,代码来源:class.CheckCrawlerController.php

示例8: processPageActions

 /**
  * Process actions based on $_GET parameters. Authorize FB user or add FB page.
  * @param arr $options Facebook plugin options
  */
 protected function processPageActions($options)
 {
     //authorize user
     if (isset($_GET["code"]) && isset($_GET["state"])) {
         //validate state to avoid CSRF attacks
         if ($_GET["state"] == SessionCache::get('facebook_auth_csrf')) {
             //Prepare API request
             //First, prep redirect URI
             $redirect_uri = Utils::getApplicationURL() . 'account/?p=facebook';
             //Build API request URL
             $api_req = 'oauth/access_token';
             $api_req_params = array('client_id' => $options['facebook_app_id']->option_value, 'client_secret' => $options['facebook_api_secret']->option_value, 'redirect_uri' => $redirect_uri, 'state' => SessionCache::get('facebook_auth_csrf'), 'code' => $_GET["code"]);
             $access_token_response = FacebookGraphAPIAccessor::apiRequest($api_req, null, $api_req_params, null);
             //DEBUG
             // Logger::getInstance()->logInfo("Access token response: "
             //     .Utils::varDumpToString($access_token_response), __METHOD__.','.__LINE__);
             if (isset($access_token_response->error)) {
                 $this->addErrorMessage("There was a problem. Facebook says: " . $access_token_response->error->message . " Please try again.", 'user_add');
                 $logger->logInfo("Added error message ", __METHOD__ . ',' . __LINE__);
                 return;
             }
             $access_token = $access_token_response->access_token;
             if (isset($access_token)) {
                 /**
                  * Swap in short-term token for long-lived token as per
                  * https://developers.facebook.com/docs/facebook-login/access-tokens/#extending
                  */
                 $api_req = 'oauth/access_token';
                 $api_req_params = array('grant_type' => 'fb_exchange_token', 'client_id' => $options['facebook_app_id']->option_value, 'client_secret' => $options['facebook_api_secret']->option_value, 'fb_exchange_token' => $access_token);
                 $access_token_response = FacebookGraphAPIAccessor::apiRequest($api_req, null, $api_req_params);
                 // DEBUG
                 // Logger::getInstance()->logInfo("Exchanged access token response: "
                 //     .Utils::varDumpToString($access_token_response), __METHOD__.','.__LINE__);
                 $access_token = $access_token_response->access_token;
                 $fb_user_profile = FacebookGraphAPIAccessor::apiRequest('me', $access_token, 'name,id');
                 //DEBUG
                 // Logger::getInstance()->logInfo("FB user profile: ".Utils::varDumpToString($fb_user_profile),
                 //     __METHOD__.','.__LINE__);
                 if (isset($fb_user_profile->error)) {
                     $error_msg = "Problem authorizing your Facebook account!";
                     $error_object = $access_token_response;
                     if (isset($error_object) && isset($error_object->error->type) && isset($error_object->error->message)) {
                         $error_msg = $error_msg . "<br>Facebook says: \"" . $error_object->error->type . ": " . $error_object->error->message . "\"";
                     } else {
                         $error_msg = $error_msg . "<br>Facebook's response: \"" . $access_token_response . "\"";
                     }
                     $this->addErrorMessage($error_msg, 'user_add', true);
                 } else {
                     $fb_username = isset($fb_user_profile->name) ? $fb_user_profile->name : '';
                     $fb_user_id = isset($fb_user_profile->id) ? $fb_user_profile->id : '';
                     if (empty($fb_username)) {
                         $error = 'Sorry, ThinkUp does not support business accounts.';
                         $this->addErrorMessage($error, 'user_add');
                     } else {
                         $this->saveAccessToken($fb_user_id, $access_token, $fb_username);
                     }
                 }
             } else {
                 $error_msg = "Problem authorizing your Facebook account! Please correct your plugin settings.";
                 $error_object = $access_token_response;
                 if (isset($error_object) && isset($error_object->error->type) && isset($error_object->error->message)) {
                     $error_msg = $error_msg . "<br>Facebook says: \"" . $error_object->error->type . ": " . $error_object->error->message . "\"";
                 } else {
                     $error_msg = $error_msg . "<br>Facebook's response: \"" . $access_token_response . "\"";
                 }
                 $this->addErrorMessage($error_msg, 'user_add', true);
             }
         } else {
             $this->addErrorMessage("Could not authenticate Facebook account due to invalid CSRF token.", 'user_add');
         }
     }
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:76,代码来源:class.FacebookPluginConfigurationController.php

示例9: setUpInstagramInteractions

 /**
  * Populate view manager with instagram interaction UI, like the instagram Add User button and page dropdown.
  * @param array $options 'instagram_app_id' and 'instagram_api_secret'
  */
 protected function setUpInstagramInteractions($options)
 {
     // Create our instagram Application instance
     if (Utils::isThinkUpLLC()) {
         $redirect_uri = Config::getInstance()->getValue('thinkupllc_endpoint') . 'instagram/?u=' . Config::getInstance()->getValue('install_folder');
     } else {
         $redirect_uri = Utils::getApplicationURL() . 'account/?p=instagram';
     }
     $scope = array('likes', 'comments', 'relationships');
     $instagram = new Instagram\Auth(array('client_id' => $options['instagram_app_id']->option_value, 'client_secret' => $options['instagram_api_secret']->option_value, 'redirect_uri' => $redirect_uri));
     if ($this->do_show_add_button) {
         $instagramconnect_link = sprintf('https://api.instagram.com/oauth/authorize/?client_id=%s&redirect_uri=%s&response_type=code&scope=%s', $options['instagram_app_id']->option_value, $redirect_uri, implode('+', $scope));
         $this->addToView('instaconnect_link', $instagramconnect_link);
     }
     self::processPageActions($options, $instagram);
     $logger = Logger::getInstance();
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $instances = $instance_dao->getByOwnerAndNetwork($this->owner, 'instagram');
     $owner_instance_dao = DAOFactory::getDAO('OwnerInstanceDAO');
     foreach ($instances as $instance) {
         $tokens = $owner_instance_dao->getOAuthTokens($instance->id);
         if (isset($tokens['auth_error']) && $tokens['auth_error'] != '') {
             $instance->auth_error = $tokens['auth_error'];
         }
     }
     $this->addToView('instances', $instances);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:31,代码来源:class.InstagramPluginConfigurationController.php

示例10: authControl

 /**
  * Launch the crawler, if the latest crawler_last_run date is older than X minutes, then return a valid RSS feed.
  * @return string rendered view markup
  */
 public function authControl()
 {
     $this->setContentType('application/rss+xml; charset=UTF-8');
     $this->setViewTemplate('rss.tpl');
     $config = Config::getInstance();
     $rss_crawler_refresh_rate = $config->getValue('rss_crawler_refresh_rate');
     if (empty($rss_crawler_refresh_rate)) {
         $rss_crawler_refresh_rate = 20;
         // minutes
     }
     $base_url = Utils::getApplicationURL();
     $crawler_plugin_registrar_launched = false;
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $email = $this->getLoggedInUser();
     $owner = parent::getOwner($email);
     $freshest_instance = $instance_dao->getFreshestByOwnerId($owner->id);
     if ($freshest_instance) {
         $crawler_plugin_registrar_last_run = strtotime($freshest_instance->crawler_last_run);
     }
     if ($freshest_instance && $crawler_plugin_registrar_last_run < time() - $rss_crawler_refresh_rate * 60) {
         $crawler_plugin_registrar_run_url = $base_url . 'crawler/run.php?' . sprintf('un=%s&as=%s', $email, $owner->api_key);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $crawler_plugin_registrar_run_url);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
         // seconds
         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
         // seconds
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, true);
         $result = curl_exec($ch);
         curl_close($ch);
         $body = substr($result, strpos($result, "\r\n\r\n") + 4);
         if (strpos($result, 'Content-Type: application/json') && function_exists('json_decode')) {
             $json = json_decode($body);
             if (isset($json->error)) {
                 $crawler_plugin_registrar_launched = false;
             } else {
                 if (isset($json->result) && $json->result == 'success') {
                     $crawler_plugin_registrar_launched = true;
                 }
             }
         } else {
             if (strpos($body, 'Error starting crawler') !== FALSE) {
                 $crawler_plugin_registrar_launched = false;
             } else {
                 $crawler_plugin_registrar_launched = true;
             }
         }
     }
     $items = array();
     $logger = Logger::getInstance();
     // Don't return an item if there is a crawler log defined;
     // it would just duplicate the information available in that file.
     if ($crawler_plugin_registrar_launched && !isset($logger->log)) {
         $title = 'ThinkUp crawl started on ' . date('Y-m-d H:i:s');
         $link = $base_url . 'rss.php?d=' . urlencode(date('Y-m-d H:i:s'));
         $description = "Last ThinkUp crawl ended on {$freshest_instance->crawler_last_run}<br />A new crawl " . "was started just now, since it's been more than {$rss_crawler_refresh_rate} minutes since the last run.";
         $items[] = self::createRSSItem($title, $link, $description);
     }
     $items = array_merge($items, $this->getAdditionalItems($base_url));
     $this->addToView('items', $items);
     $this->addToView('logged_in_user', htmlspecialchars($this->getLoggedInUser()));
     $this->addToView('rss_crawler_refresh_rate', htmlspecialchars($rss_crawler_refresh_rate));
     return $this->generateView();
 }
开发者ID:JWFoxJr,项目名称:ThinkUp,代码行数:69,代码来源:class.RSSController.php

示例11: testGetApplicationURL

 public function testGetApplicationURL()
 {
     //no SSL
     $_SERVER['HTTP_HOST'] = "mytestthinkup";
     $_SERVER['HTTPS'] = null;
     $cfg = Config::getInstance();
     $cfg->setValue('site_root_path', '/my/path/to/thinkup/');
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //with SSL
     $_SERVER['HTTPS'] = true;
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'https://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //nonstandard port
     $_SERVER['HTTPS'] = null;
     $_SERVER['SERVER_PORT'] = '1003';
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://mytestthinkup:1003/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //standard port 80
     $_SERVER['HTTPS'] = null;
     $_SERVER['SERVER_PORT'] = '80';
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //SSL standard port 443
     $_SERVER['HTTPS'] = true;
     $_SERVER['SERVER_PORT'] = '443';
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'https://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //no port set
     $_SERVER['HTTPS'] = null;
     $_SERVER['SERVER_PORT'] = '80';
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //localhost
     $_SERVER['HTTP_HOST'] = "localhost";
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://localhost/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //localhost - return IP
     $_SERVER['HTTP_HOST'] = "localhost";
     $utils_url = Utils::getApplicationURL(true);
     $expected_url = 'http://127.0.0.1/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
 }
开发者ID:JWFoxJr,项目名称:ThinkUp,代码行数:50,代码来源:TestOfUtils.php

示例12: sendInvalidOAuthEmailAlert

 /**
  * Send user email alert about invalid OAuth tokens, at most one message per week.
  * In test mode, this will only write the message body to a file in the application data directory.
  * @param str $email
  * @param str $username
  * @return bool Whether or not email was sent
  */
 private function sendInvalidOAuthEmailAlert($email, $username)
 {
     //Determine whether or not an email about invalid tokens was sent in the past 7 days
     $should_send_email = true;
     $option_dao = DAOFactory::getDAO('OptionDAO');
     $plugin_dao = DAOFactory::getDAO('PluginDAO');
     $plugin_id = $plugin_dao->getPluginId('facebook');
     $last_email_timestamp = $option_dao->getOptionByName(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp');
     if (isset($last_email_timestamp)) {
         //option exists, a message was sent
         //a message was sent in the past week
         if ($last_email_timestamp->option_value > strtotime('-1 week')) {
             $should_send_email = false;
         } else {
             $option_dao->updateOption($last_email_timestamp->option_id, time());
         }
     } else {
         $option_dao->insertOption(OptionDAO::PLUGIN_OPTIONS . '-' . $plugin_id, 'invalid_oauth_email_sent_timestamp', time());
     }
     if ($should_send_email) {
         $mailer_view_mgr = new ViewManager();
         $mailer_view_mgr->caching = false;
         $mailer_view_mgr->assign('thinkup_site_url', Utils::getApplicationURL());
         $mailer_view_mgr->assign('email', $email);
         $mailer_view_mgr->assign('faceboook_user_name', $username);
         $message = $mailer_view_mgr->fetch(Utils::getPluginViewDirectory('facebook') . '_email.invalidtoken.tpl');
         Mailer::mail($email, "Please re-authorize ThinkUp to access " . $username . " on Facebook", $message);
         return true;
     } else {
         return false;
     }
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:39,代码来源:class.FacebookPlugin.php

示例13: testGetApplicationURL

 public function testGetApplicationURL()
 {
     $cfg = Config::getInstance();
     $cfg->setValue('site_root_path', '/my/path/to/thinkup/');
     //no $_SERVER vars set, but with application setting set
     $builder = FixtureBuilder::build('options', array('namespace' => 'application_options', 'option_name' => 'server_name', 'option_value' => 'testservername'));
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://testservername/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //SERVER_NAME, not HTTP_HOST
     $_SERVER['HTTP_HOST'] = null;
     $_SERVER['SERVER_NAME'] = 'mytestservername';
     $_SERVER['HTTPS'] = null;
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://mytestservername/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //no SSL
     $_SERVER['SERVER_NAME'] = null;
     $_SERVER['HTTP_HOST'] = "mytestthinkup";
     $_SERVER['HTTPS'] = null;
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //no SSL but with $_SERVER['HTTPS'] set to empty string
     $_SERVER['HTTPS'] = '';
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //with SSL
     $_SERVER['HTTPS'] = true;
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'https://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //nonstandard port
     $_SERVER['HTTPS'] = null;
     $_SERVER['SERVER_PORT'] = '1003';
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://mytestthinkup:1003/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //standard port 80
     $_SERVER['HTTPS'] = null;
     $_SERVER['SERVER_PORT'] = '80';
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //SSL standard port 443
     $_SERVER['HTTPS'] = true;
     $_SERVER['SERVER_PORT'] = '443';
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'https://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //no port set
     $_SERVER['HTTPS'] = null;
     $_SERVER['SERVER_PORT'] = '80';
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://mytestthinkup/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //localhost
     $_SERVER['HTTP_HOST'] = "localhost";
     $utils_url = Utils::getApplicationURL();
     $expected_url = 'http://localhost/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //localhost - return IP
     $_SERVER['HTTP_HOST'] = "localhost";
     $utils_url = Utils::getApplicationURL(true);
     $expected_url = 'http://127.0.0.1/my/path/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //with spaces in site_rooth_path
     $_SERVER['HTTP_HOST'] = "localhost";
     $cfg->setValue('site_root_path', '/my/path and this space/to/thinkup/');
     $utils_url = Utils::getApplicationURL(false);
     $expected_url = 'http://localhost/my/path+and+this+space/to/thinkup/';
     $this->assertEqual($utils_url, $expected_url);
     //with capital letters in site_root_path
     $_SERVER['HTTP_HOST'] = "localhost";
     $cfg->setValue('site_root_path', '/ThinkUp/');
     $utils_url = Utils::getApplicationURL(false);
     $expected_url = 'http://localhost/ThinkUp/';
     $this->assertEqual($utils_url, $expected_url);
     //with capital letters and spaces in site_root_path
     $_SERVER['HTTP_HOST'] = "localhost";
     $cfg->setValue('site_root_path', '/Think Up/');
     $utils_url = Utils::getApplicationURL(false);
     $expected_url = 'http://localhost/Think+Up/';
     $this->assertEqual($utils_url, $expected_url);
     //with capital letters in host and in site_root_path
     $_SERVER['HTTP_HOST'] = "LocalHost";
     $cfg->setValue('site_root_path', '/Think Up/');
     $utils_url = Utils::getApplicationURL(false);
     $expected_url = 'http://localhost/Think+Up/';
     $this->assertEqual($utils_url, $expected_url);
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:92,代码来源:TestOfUtils.php

示例14: processPageActions

 /**
  * Process actions based on $_GET parameters. Authorize FB user or add FB page.
  * @param arr $options Facebook plugin options
  * @param Facebook $facebook Facebook object
  */
 protected function processPageActions($options, Facebook $facebook)
 {
     //authorize user
     if (isset($_GET["code"]) && isset($_GET["state"])) {
         //validate state to avoid CSRF attacks
         if ($_GET["state"] == SessionCache::get('facebook_auth_csrf')) {
             //Prepare API request
             //First, prep redirect URI
             $redirect_uri = urlencode(Utils::getApplicationURL() . 'account/?p=facebook');
             //Build API request URL
             $api_req = 'https://graph.facebook.com/oauth/access_token?client_id=' . $options['facebook_app_id']->option_value . '&client_secret=' . $options['facebook_api_secret']->option_value . '&redirect_uri=' . $redirect_uri . '&state=' . SessionCache::get('facebook_auth_csrf') . '&code=' . $_GET["code"];
             $access_token_response = FacebookGraphAPIAccessor::rawApiRequest($api_req, false);
             parse_str($access_token_response);
             if (isset($access_token)) {
                 /**
                  * Swap in short-term token for long-lived token as per
                  * https://developers.facebook.com/docs/facebook-login/access-tokens/#extending
                  */
                 $api_req = 'https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id=' . $options['facebook_app_id']->option_value . '&client_secret=' . $options['facebook_api_secret']->option_value . '&fb_exchange_token=' . $access_token;
                 $access_token_response = FacebookGraphAPIAccessor::rawApiRequest($api_req, false);
                 parse_str($access_token_response);
                 $facebook->setAccessToken($access_token);
                 $fb_user_profile = $facebook->api('/me');
                 $fb_username = $fb_user_profile['name'];
                 $fb_user_id = $fb_user_profile['id'];
                 if (empty($fb_username)) {
                     $error = 'Sorry, ThinkUp does not support business accounts.';
                     $this->addErrorMessage($error, 'authorization');
                 } else {
                     $this->addSuccessMessage($this->saveAccessToken($fb_user_id, $access_token, $fb_username), 'authorization');
                 }
             } else {
                 $error_msg = "Problem authorizing your Facebook account! Please correct your plugin settings.";
                 $error_object = json_decode($access_token_response);
                 if (isset($error_object) && isset($error_object->error->type) && isset($error_object->error->message)) {
                     $error_msg = $error_msg . "<br>Facebook says: \"" . $error_object->error->type . ": " . $error_object->error->message . "\"";
                 } else {
                     $error_msg = $error_msg . "<br>Facebook's response: \"" . $access_token_response . "\"";
                 }
                 $this->addErrorMessage($error_msg, 'authorization', true);
             }
         } else {
             $this->addErrorMessage("Could not authenticate Facebook account due to invalid CSRF token.", 'authorization');
         }
     }
     //insert pages
     if (isset($_GET["action"]) && $_GET["action"] == "add page" && isset($_GET["facebook_page_id"]) && isset($_GET["viewer_id"]) && isset($_GET["owner_id"]) && isset($_GET["instance_id"])) {
         //get access token
         $oid = DAOFactory::getDAO('OwnerInstanceDAO');
         $tokens = $oid->getOAuthTokens($_GET["instance_id"]);
         $access_token = $tokens['oauth_access_token'];
         $page_data = FacebookGraphAPIAccessor::apiRequest('/' . $_GET["facebook_page_id"], $access_token, "id,name,picture");
         self::insertPage($page_data->id, $_GET["viewer_id"], $_GET["instance_id"], $page_data->name, $page_data->picture->data->url);
     }
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:60,代码来源:class.FacebookPluginConfigurationController.php

示例15: authControl

 /**
  * Launch the crawler, if the latest crawler_last_run date is older than X minutes, then return a valid RSS feed.
  * @return string rendered view markup
  */
 public function authControl()
 {
     $this->setContentType('application/rss+xml; charset=UTF-8');
     $this->setViewTemplate('rss.tpl');
     $config = Config::getInstance();
     $rss_crawler_refresh_rate = $config->getValue('rss_crawler_refresh_rate');
     if (empty($rss_crawler_refresh_rate)) {
         $rss_crawler_refresh_rate = 20;
         // minutes
     }
     $base_url = Utils::getApplicationURL();
     $crawler_plugin_registrar_launched = false;
     $instance_dao = DAOFactory::getDAO('InstanceDAO');
     $email = $this->getLoggedInUser();
     $owner = parent::getOwner($email);
     $freshest_instance = $instance_dao->getFreshestByOwnerId($owner->id);
     if ($freshest_instance) {
         $crawler_plugin_registrar_last_run = strtotime($freshest_instance->crawler_last_run);
     }
     if ($freshest_instance && $crawler_plugin_registrar_last_run < time() - $rss_crawler_refresh_rate * 60) {
         $crawler_plugin_registrar_run_url = $base_url . 'crawler/run.php?' . sprintf('un=%s&as=%s', $email, $owner->api_key);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $crawler_plugin_registrar_run_url);
         curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
         // seconds
         curl_setopt($ch, CURLOPT_TIMEOUT, 5);
         // seconds
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
         curl_setopt($ch, CURLOPT_HEADER, true);
         $result = curl_exec($ch);
         curl_close($ch);
         $body = substr($result, strpos($result, "\r\n\r\n") + 4);
         if (strpos($result, 'Content-Type: application/json') && function_exists('json_decode')) {
             $json = json_decode($body);
             if (isset($json->error)) {
                 $crawler_plugin_registrar_launched = false;
             } else {
                 if (isset($json->result) && $json->result == 'success') {
                     $crawler_plugin_registrar_launched = true;
                 }
             }
         } else {
             if (strpos($body, 'Error starting crawler') !== FALSE) {
                 $crawler_plugin_registrar_launched = false;
             } else {
                 $crawler_plugin_registrar_launched = true;
             }
         }
     }
     $items = array();
     $logger = Logger::getInstance();
     // Don't return an item if there is a crawler log defined;
     // it would just duplicate the information available in that file.
     if ($crawler_plugin_registrar_launched && !isset($logger->log)) {
         $title = 'ThinkUp crawl started on ' . date('Y-m-d H:i:s');
         $link = $base_url . 'rss.php?d=' . urlencode(date('Y-m-d H:i:s'));
         $description = "Last ThinkUp crawl ended on {$freshest_instance->crawler_last_run}<br />A new crawl " . "was started just now, since it's been more than {$rss_crawler_refresh_rate} minutes since the last run.";
         $items[] = self::createRSSItem($title, $link, $description);
     }
     $items = array_merge($items, $this->getAdditionalItems($base_url));
     //Add insights to RSS feed
     $insight_dao = DAOFactory::getDAO('InsightDAO');
     if ($this->isAdmin()) {
         ///show all insights for all service users
         $insights = $insight_dao->getAllInstanceInsights($page_count = InsightStreamController::PAGE_INSIGHTS_COUNT + 1, 1);
     } else {
         //show only service users owner owns
         $owner_dao = DAOFactory::getDAO('OwnerDAO');
         $owner = $owner_dao->getByEmail($this->getLoggedInUser());
         $insights = $insight_dao->getAllOwnerInstanceInsights($owner->id, $page_count = InsightStreamController::PAGE_INSIGHTS_COUNT + 1, 1);
     }
     if (sizeof($insights) == 0) {
         $title = 'No insights exist on ' . date('Y-m-d H:i:s');
         $link = $base_url . 'rss.php?d=' . urlencode(date('Y-m-d H:i:s'));
         $description = "ThinkUp doesn't have any insights to show you. Check your crawler log to make sure " . "ThinkUp is capturing data.";
         $items[] = self::createRSSItem($title, $link, $description);
     } else {
         foreach ($insights as $insight) {
             $username_in_title = ($insight->instance->network == 'twitter' ? '@' : '') . $insight->instance->network_username;
             $title = str_replace(':', '', $insight->headline) . " (" . $username_in_title . ")";
             $link = $base_url . '?u=' . $insight->instance->network_username . '&n=' . urlencode($insight->instance->network) . '&d=' . urlencode(date('Y-m-d', strtotime($insight->date))) . '&s=' . urlencode($insight->slug);
             $description = $insight->headline . " " . $insight->text . '<br><a href="' . $link . '">Link</a>';
             $time = strtotime($insight->date);
             $items[] = self::createRSSItem($title, $link, $description, $time);
         }
     }
     $this->addToView('items', $items);
     $this->addToView('logged_in_user', htmlspecialchars($this->getLoggedInUser()));
     $this->addToView('rss_crawler_refresh_rate', htmlspecialchars($rss_crawler_refresh_rate));
     return $this->generateView();
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:95,代码来源:class.RSSController.php


注:本文中的Utils::getApplicationURL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。