4 * This file contains the functionality of the different checks
5 * needed to be done before displaying any page of the
9 require_once $gfwww.'include/pre.php';
11 $pluginname = 'twitter';
13 $tabs = array( "Home",
17 "Other API requests");
19 $tablinks = array( '/plugins/'.$pluginname.'/index.php',
20 '/plugins/'.$pluginname.'/index.php?list=public',
21 '/plugins/'.$pluginname.'/index.php?list=user',
22 '/plugins/'.$pluginname.'/post.php',
23 '/plugins/'.$pluginname.'/others.php');
25 // the header that displays for the user portion of the plugin
26 function twitter_User_Header($params) {
27 global $DOCUMENT_ROOT,$HTML, $user_id, $pluginname;
28 $params['toptab']=$pluginname;
29 $params['user']=$user_id;
30 site_user_header($params);
34 * checks whether the user is logged in and has activated the plugin
36 function twitter_CheckUser() {
38 if (!session_loggedin()) { //check if user logged in
44 $user = session_get_user(); // get the session user
46 if (!$user || !is_object($user) || $user->isError() || !$user->isActive()) {
47 exit_error("Invalid User, Cannot Process your request for this user.", $pluginname);
53 exit_error("Cannot Process your request: Invalid User", $pluginname);
56 $realuser = user_get_object($id);
57 if (!($realuser) || !($realuser->usesPlugin($pluginname))) { //check if user has activated the plugin
58 exit_error("First activate the User's $pluginname plugin through Account Maintenance Page", $pluginname);
61 //displays the page header and toolbar
62 twitter_User_Header();
67 function twitter_toolbar() {
68 global $tabs, $tablinks;
69 echo '<ul class="widget_toolbar">';
70 for($i=0; $i<count($tabs); $i++) {
71 echo "<li>".util_make_link($tablinks[$i], _($tabs[$i]))."</li>";
76 function twitter_get_access_token() {
77 $userid = session_get_user()->getID();
79 $providers = OAuthProvider::get_all_oauthproviders();
80 foreach ($providers as $provider) {
81 if(strcasecmp(trim($provider->get_name()), "twitter")==0) {
82 $twitter_provider = $provider;
86 if($twitter_provider) {
87 $access_tokens = OAuthAccessToken::get_all_access_tokens_by_provider($twitter_provider->get_id(), $userid);
90 $twitter_token = $access_tokens[0];
91 for ($i=1; $i<count($access_tokens); $i++) {
92 //get the latest access token
93 if($access_token[$i]->get_time_stamp()>$twitter_token->get_time_stamp()) {
94 $twitter_token = $access_tokens[$i];
97 return array($twitter_provider, $twitter_token);
99 exit_error(_('You have no Twitter Access Tokens registered in the database currently'));
103 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"));