From: Madhumita Dhar Date: Fri, 16 Sep 2011 08:31:23 +0000 (+0000) Subject: initial commits for twitter plugin X-Git-Tag: v5_2_rc1~787 X-Git-Url: https://scm.fusionforge.org/anonscm/gitweb?p=fusionforge%2Ffusionforge.git;a=commitdiff_plain;h=a0da08175014854819f027db930ae91b785473c2 initial commits for twitter plugin --- diff --git a/.gitattributes b/.gitattributes index 5da7d911e5..2930ffa9c2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2628,11 +2628,14 @@ src/plugins/twitter/NAME -text src/plugins/twitter/README -text src/plugins/twitter/common/twitter-init.php -text src/plugins/twitter/etc/twitter.ini -text +src/plugins/twitter/include/twitterPlugin.class.php -text src/plugins/twitter/packaging/control/222plugin-twitter -text src/plugins/twitter/packaging/control/222plugin-twitter.shortdesc -text src/plugins/twitter/packaging/dirs/plugin-twitter -text src/plugins/twitter/packaging/install/plugin-twitter -text src/plugins/twitter/packaging/links/plugin-twitter -text +src/plugins/twitter/www/checks.php -text +src/plugins/twitter/www/index.php -text src/plugins/wiki/README -text src/plugins/wiki/common/WikiGroupSearchEngine.class.php -text src/plugins/wiki/common/WikiHtmlSearchRenderer.class.php -text diff --git a/src/plugins/oauthconsumer/include/provider_api.php b/src/plugins/oauthconsumer/include/provider_api.php index 64761a235d..6795e6ab5c 100644 --- a/src/plugins/oauthconsumer/include/provider_api.php +++ b/src/plugins/oauthconsumer/include/provider_api.php @@ -102,6 +102,13 @@ class OAuthProvider { return $provider; } + static function get_provider_by_name($name) { + $conn = FFOAuthDataStore::singleton(); + $row = $conn->find_provider_from_name($name); + $provider = self::convert_row_to_object($row); + return $provider; + } + static function get_all_oauthproviders() { $conn = FFOAuthDataStore::singleton(); $rows = $conn->find_all_providers(); diff --git a/src/plugins/twitter/include/twitterPlugin.class.php b/src/plugins/twitter/include/twitterPlugin.class.php new file mode 100644 index 0000000000..151e67c646 --- /dev/null +++ b/src/plugins/twitter/include/twitterPlugin.class.php @@ -0,0 +1,26 @@ +ForgeAuthPlugin() ; + + $this->name = 'twitter'; + $this->text = 'Twitter'; // To show in the tabs, use... + $this->_addHook("user_personal_links");//to make a link to the user's personal part of the plugin + $this->_addHook("usermenu"); + $this->_addHook("userisactivecheckbox"); // The "use ..." checkbox in user account + $this->_addHook("userisactivecheckboxpost"); // + + } + + function usermenu() { + global $G_SESSION,$HTML; + $text = $this->text; // this is what shows in the tab + if ($G_SESSION->usesPlugin($this->name)) { + echo $HTML->PrintSubMenu (array ($text), array ('/plugins/twitter/index.php') ); + } + } + +} diff --git a/src/plugins/twitter/www/checks.php b/src/plugins/twitter/www/checks.php new file mode 100644 index 0000000000..4b5b8917ce --- /dev/null +++ b/src/plugins/twitter/www/checks.php @@ -0,0 +1,105 @@ +isError() || !$user->isActive()) { + exit_error("Invalid User, Cannot Process your request for this user.", $pluginname); + } + + $id = $user->getID(); + + if (!$id) { + exit_error("Cannot Process your request: Invalid User", $pluginname); + } + + $realuser = user_get_object($id); + if (!($realuser) || !($realuser->usesPlugin($pluginname))) { //check if user has activated the plugin + exit_error("First activate the User's $pluginname plugin through Account Maintenance Page", $pluginname); + } + + //displays the page header and toolbar + twitter_User_Header(); + twitter_toolbar(); + +} + +function twitter_toolbar() { + global $tabs, $tablinks; + echo ''; +} + +function twitter_get_access_token() { + $userid = session_get_user()->getID(); + + $providers = OAuthProvider::get_all_oauthproviders(); + foreach ($providers as $provider) { + if(strcasecmp(trim($provider->get_name()), "twitter")==0) { + $twitter_provider = $provider; + } + } + + if($twitter_provider) { + $access_tokens = OAuthAccessToken::get_all_access_tokens_by_provider($twitter_provider->get_id(), $userid); + + if($access_tokens) { + $twitter_token = $access_tokens[0]; + for ($i=1; $iget_time_stamp()>$twitter_token->get_time_stamp()) { + $twitter_token = $access_tokens[$i]; + } + } + return array($twitter_provider, $twitter_token); + }else { + exit_error(_('You have no Twitter Access Tokens registered in the database currently')); + } + }else { + //error + exit_error(_("Couldn't find a twitter provider registered in the database. If a twitter provider exists, it needs to be named 'Twitter', else it has to be created in the OAuth Consumer plugin")); + } +} \ No newline at end of file diff --git a/src/plugins/twitter/www/index.php b/src/plugins/twitter/www/index.php new file mode 100644 index 0000000000..049f0a4abf --- /dev/null +++ b/src/plugins/twitter/www/index.php @@ -0,0 +1,33 @@ +get_id(), $http_method); +$transaction = new OAuthTransaction($twitter_provider, $twitter_token, $resource); +$response = $transaction->send_request(); +$response_array = json_decode($response); +//print_r($response_array[0]->user); + +echo ''; +foreach ($response_array as $tweet) { + echo ''; + echo ''; + echo ''; +} +echo '
twitter'.$tweet->user->name.'
'.$tweet->text.'
'; + +site_user_footer(); \ No newline at end of file