/**
 * Called when a user was just created or attached (safe to call at any time later as well).  This
 * function will check to see if the user has a Wikia Avatar and if they don't, it will attempt to
 * use this Facebook-connected user's profile picture as their Wikia Avatar.
 *
 * FIXME: Is there a way to make this fail gracefully if we ever un-include the Masthead extension?
 */
function wikia_fbconnect_considerProfilePic(&$specialConnect)
{
    wfProfileIn(__METHOD__);
    global $wgUser;
    // We need the facebook id to have any chance of getting a profile pic.
    $fb_ids = FBConnectDB::getFacebookIDs($wgUser);
    if (count($fb_ids) > 0) {
        $fb_id = array_shift($fb_ids);
        if (class_exists('Masthead')) {
            // If the useralready has a masthead avatar, don't overwrite it, this function shouldn't alter anything in that case.
            $masthead = Masthead::newFromUser($wgUser);
            if (!$masthead->hasAvatar()) {
                global $wgEnableUserProfilePagesV3;
                if (!empty($wgEnableUserProfilePagesV3)) {
                    //bugId:10580
                    // Attempt to store the facebook profile pic as the Wikia avatar.
                    $picUrl = FBConnectProfilePic::getImgUrlById($fb_id, FB_PIC_BIG);
                } else {
                    // Attempt to store the facebook profile pic as the Wikia avatar.
                    $picUrl = FBConnectProfilePic::getImgUrlById($fb_id, FB_PIC_SQUARE);
                }
                if ($picUrl != "") {
                    if (!empty($wgEnableUserProfilePagesV3)) {
                        //bugId:10580
                        $tmpFile = '';
                        $sUrl = $masthead->uploadByUrlToTempFile($picUrl, $tmpFile);
                        $app = F::app();
                        $userProfilePageV3 = new UserProfilePageController($app);
                        $data->source = 'facebook';
                        $data->file = $tmpFile;
                        $userProfilePageV3->saveUsersAvatar($wgUser->getId(), $data);
                    } else {
                        $errorNo = $masthead->uploadByUrl($picUrl);
                        // Apply this as the user's new avatar if the image-pull went okay.
                        if ($errorNo == UPLOAD_ERR_OK) {
                            $sUrl = $masthead->getLocalPath();
                            if (!empty($sUrl)) {
                                /* set user option */
                                $wgUser->setOption(AVATAR_USER_OPTION_NAME, $sUrl);
                                $wgUser->saveSettings();
                            }
                        }
                    }
                }
            }
        }
    }
    wfProfileOut(__METHOD__);
    return true;
}
Esempio n. 2
0
 /**
  * This is called when a user is logged into a Wikia account and has just gone through the Facebook Connect popups,
  * but has not been connected inside the system.
  *
  * This function will connect them in the database, save default preferences and present them with "Congratulations"
  * message and a link to modify their User Preferences.
  *
  * This is different from attachUser because that is made to synchronously test a login at the same time as creating
  * the account via the ChooseName form.  This function, however, is designed for when the existing user is already logged in
  * and wants to quickly connect their facebook account.  The main difference, therefore, is that this function usese default
  * preferences while the other form should have already shown the preferences form to the user.
  */
 public function connectExisting()
 {
     global $wgUser, $wgRequest;
     wfProfileIn(__METHOD__);
     $fb_ids = FBConnectDB::getFacebookIDs($wgUser);
     if (count($fb_ids) > 0) {
         // Will display a message that they're already logged in and connected.
         $this->sendPage('alreadyLoggedIn');
     } else {
         // Store the facebook-id <=> mediawiki-id mapping.
         // TODO: FIXME: What sould we do if this fb_id is already connected to a DIFFERENT mediawiki account.
         $fb = new FBConnectAPI();
         $fb_id = $fb->user();
         FBConnectDB::addFacebookID($wgUser, $fb_id);
         // Save the default user preferences.
         global $fbEnablePushToFacebook;
         if (!empty($fbEnablePushToFacebook)) {
             global $fbPushEventClasses;
             if (!empty($fbPushEventClasses)) {
                 $DEFAULT_ENABLE_ALL_PUSHES = true;
                 foreach ($fbPushEventClasses as $pushEventClassName) {
                     $pushObj = new $pushEventClassName();
                     $className = get_class();
                     $prefName = $pushObj->getUserPreferenceName();
                     $wgUser->setOption($prefName, $DEFAULT_ENABLE_ALL_PUSHES ? "1" : "0");
                 }
             }
         }
         $wgUser->setOption("fbFromExist", "1");
         $wgUser->saveSettings();
         wfRunHooks('SpecialConnect::userAttached', array(&$this));
         $this->sendPage('displaySuccessAttaching');
     }
     wfProfileOut(__METHOD__);
 }
Esempio n. 3
0
 /**
  * put facebook message
  * @author Tomasz Odrobny
  */
 public static function pushEvent($message, $params, $class)
 {
     global $wgServer, $wgUser;
     $id = FBConnectDB::getFacebookIDs($wgUser);
     if (count($id) < 1) {
         return 1001;
         //status for disconnected
     }
     /* only one event par request */
     if (self::$eventCounter > 0) {
         return 1000;
         //status for out of limit
     }
     self::$eventCounter++;
     if (wfRunHooks('FBConnect::BeforePushEvent', array($id, &$message, &$params, &$class))) {
         $fb = new FBConnectAPI();
         $image = $params['$EVENTIMG'];
         if (strpos($params['$EVENTIMG'], 'http://') === false) {
             $image = $wgServer . '/index.php?action=ajax&rs=FBConnectPushEvent::showImage&time=' . time() . '&fb_id=' . $wgUser->getId() . "&event=" . $class . '&img=' . $params['$EVENTIMG'];
         }
         $href = $params['$ARTICLE_URL'];
         $description = wfMsg($message);
         $link = wfMsg($message . '-link');
         $short = wfMsg($message . '-short');
         $params['$FB_NAME'] = "";
         foreach ($params as $key => $value) {
             if ($value instanceof Article) {
                 continue;
             }
             $description = str_replace($key, $value, $description);
             $link = str_replace($key, $value, $link);
             $short = str_replace($key, $value, $short);
         }
         $status = $fb->publishStream($href, $description, $short, $link, $image);
         self::addEventStat($status, $class);
         return $status;
     }
     return false;
 }
	/**
	 * Handle confirmations from Facebook Connect
	 */
	public static function addFacebookConnectConfirmation(&$html) {
		wfProfileIn(__METHOD__);
		global $wgRequest, $wgUser;


		// FBConnect messages
		if ( F::app()->checkSkin( 'oasis' ) && class_exists('FBConnectHooks')) {

			$preferencesUrl = SpecialPage::getTitleFor('Preferences')->getFullUrl();
			$fbStatus = $wgRequest->getVal('fbconnected');

			switch($fbStatus) {
				// success
				case 1:
					$id = FBConnectDB::getFacebookIDs($wgUser, DB_MASTER);
					if (count($id) > 0) {

						global $wgEnableFacebookSync;
						if ($wgEnableFacebookSync == true) {
							$userURL = AvatarService::getUrl($wgUser->mName);
							self::addConfirmation(wfMsg('fbconnect-connect-msg-sync-profile', $preferencesUrl, $userURL));
						}
						else {
							self::addConfirmation(wfMsg('fbconnect-connect-msg', $preferencesUrl));
						}
					}
					break;

				// error
				case 2:
					$fb = new FBConnectAPI();
					if (strlen($fb->user()) < 1) {
						self::addConfirmation(wfMsgExt('fbconnect-connect-error-msg', array('parseinline'), $preferencesUrl), self::CONFIRMATION_ERROR);
					}
					break;
			}
		}

		wfProfileOut(__METHOD__);
		return true;
	}
Esempio n. 5
0
 /**
  * Retrieves group membership data from Facebook.
  */
 public function getGroupRights($user = null)
 {
     global $fbUserRightsFromGroup;
     // Groupies can be members, officers or admins (the latter two infer the former)
     $rights = array('member' => false, 'officer' => false, 'admin' => false);
     // If no group ID is specified, then there's no group to belong to
     $gid = $fbUserRightsFromGroup;
     if (!$gid) {
         return $rights;
     }
     // Translate $user into a Facebook ID
     if (!$user) {
         $user = $this->user();
     } else {
         if ($user instanceof User) {
             $users = FBConnectDB::getFacebookIDs($user);
             if (count($users)) {
                 $user = $users[0];
             } else {
                 // Not a Connected user, can't be in a group
                 return $rights;
             }
         }
     }
     // Cache the rights for an individual user to prevent hitting Facebook for duplicate info
     static $rights_cache = array();
     if (array_key_exists($user, $rights_cache)) {
         // Retrieve the rights from the cache
         return $rights_cache[$user];
     }
     // This can contain up to 500 IDs, avoid requesting this info twice
     static $members = false;
     // Get a random 500 group members, along with officers, admins and not_replied's
     if ($members === false) {
         try {
             // Check to make sure our session is still valid
             $members = $this->Facebook()->api_client->groups_getMembers($gid);
         } catch (FacebookRestClientException $e) {
             // Invalid session; we're not going to be able to get the rights
             $rights_cache[$user] = $rights;
             return $rights;
         }
     }
     if ($members) {
         // Check to see if the user is an officer
         if (array_key_exists('officers', $members) && in_array($user, $members['officers'])) {
             $rights['member'] = $rights['officer'] = true;
         }
         // Check to see if the user is an admin of the group
         if (array_key_exists('admins', $members) && in_array($user, $members['admins'])) {
             $rights['member'] = $rights['admin'] = true;
         }
         // Because the latter two rights infer the former, this step isn't always necessary
         if (!$rights['member']) {
             // Check to see if we are one of the (up to 500) random users
             if (array_key_exists('not_replied', $members) && is_array($members['not_replied']) && in_array($user, $members['not_replied']) || in_array($user, $members['members'])) {
                 $rights['member'] = true;
             } else {
                 // For groups of over 500ish, we must use this extra API call
                 // Notice that it occurs last, because we can hopefully avoid having to call it
                 $group = $this->Facebook()->api_client->groups_get(intval($user), $gid);
                 if (is_array($group) && is_array($group[0]) && $group[0]['gid'] == "{$gid}") {
                     $rights['member'] = true;
                 }
             }
         }
     }
     // Cache the rights
     $rights_cache[$user] = $rights;
     return $rights;
 }
 /**
  * isFbConnectionNeeded -- checkes is everything OK with Facebook connection
  *
  * @access public
  * @author Jakub
  *
  * @return boolean
  */
 public static function isFbConnectionNeeded()
 {
     global $wgRequireFBConnectionToComment, $wgEnableFacebookConnectExt, $wgUser;
     if (!empty($wgRequireFBConnectionToComment) && !empty($wgEnableFacebookConnectExt)) {
         $fb = new FBConnectAPI();
         $tmpArrFaceBookId = FBConnectDB::getFacebookIDs($wgUser);
         $isFBConnectionProblem = $fb->user() == 0 || !isset($tmpArrFaceBookId[0]) || (int) $fb->user() != (int) $tmpArrFaceBookId[0];
         return $isFBConnectionProblem;
     } else {
         return false;
     }
 }
Esempio n. 7
0
 public static function SkinTemplatePageBeforeUserMsg(&$msg)
 {
     global $wgRequest, $wgUser, $wgServer;
     $pref = Title::newFromText("Preferences", NS_SPECIAL);
     if ($wgRequest->getVal("fbconnected", "") == 1) {
         $id = FBConnectDB::getFacebookIDs($wgUser, DB_MASTER);
         if (count($id) > 0) {
             $msg = Xml::element("img", array("id" => "fbMsgImage", "src" => $wgServer . '/skins/common/fbconnect/fbiconbig.png'));
             $msg .= "<p>" . wfMsg('fbconnect-connect-msg', array("\$1" => $pref->getFullUrl())) . "</p>";
             /** Wikia change - starts  @author Andrzej 'nAndy' Łukaszewski */
             wfRunHooks('FounderProgressBarOnFacebookConnect');
             /** Wikia change - ends */
         }
     }
     if ($wgRequest->getVal("fbconnected", "") == 2) {
         $fb = new FBConnectAPI();
         if (strlen($fb->user()) < 1) {
             $msg = Xml::element("img", array("id" => "fbMsgImage", "src" => $wgServer . '/skins/common/fbconnect/fbiconbig.png'));
             $msg .= "<p>" . wfMsgExt('fbconnect-connect-error-msg', 'parse', array("\$1" => $pref->getFullUrl())) . "</p>";
         }
     }
     return true;
 }