/**
  * Connects given Wikia account with FB account and sets FB feed preferences
  *
  * @param User $user Wikia account
  */
 private function connectWithFacebook(User $user)
 {
     FBConnectDB::addFacebookID($user, $this->fbUserId);
     foreach ($this->fbFeedOptions as $feedName) {
         $optionName = "fbconnect-push-allow-{$feedName}";
         $user->setOption($optionName, 1);
     }
 }
示例#2
0
 function checkCreateAccount()
 {
     global $wgUser;
     $response = new AjaxResponse();
     $fb = new FBConnectAPI();
     $fb_user = $fb->user();
     $error = json_encode(array("status" => "error"));
     if (empty($fb_user)) {
         $response->addText($error);
         return $response;
     }
     if ((int) $wgUser->getId() != 0) {
         $response->addText($error);
         return $response;
     }
     if (FBConnectDB::getUser($fb_user) != null) {
         $response->addText($error);
         return $response;
     }
     $titleObj = SpecialPage::getTitleFor('Connect');
     if (wfReadOnly()) {
         $response->addText($error);
         return $response;
     }
     if ($wgUser->isBlockedFromCreateAccount()) {
         $response->addText($error);
         return $response;
     }
     if (count($permErrors = $titleObj->getUserPermissionsErrors('createaccount', $wgUser, true)) > 0) {
         $response->addText($error);
         return $response;
     }
     $response->addText(json_encode(array("status" => "ok")));
     return $response;
 }
/**
 * 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;
}
示例#4
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;
	}
示例#6
0
 function verifyAccountReclamation()
 {
     $sr = (int) $this->Facebook()->getUser();
     if ($sr == 0) {
         return true;
     }
     $user = FBConnectDB::getUser($sr);
     return $user;
 }
 /**
  * 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;
     }
 }
示例#8
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;
 }
示例#9
0
 public static function coreDisconnectFromFB($user = null)
 {
     global $wgRequest, $wgUser, $wgAuth;
     if ($user == null) {
         $user = $wgUser;
     }
     $statusError = array('status' => "error", "msg" => wfMsg('fbconnect-unknown-error'));
     if (!$user instanceof User) {
         return $statusError;
     }
     if ($user->getId() == 0) {
         return $statusError;
     }
     $dbw = wfGetDB(DB_MASTER, array(), FBConnectDB::sharedDB());
     $dbw->begin();
     $rows = FBConnectDB::removeFacebookID($user);
     // Remind password attemp
     $params = new FauxRequest(array('wpName' => $user->getName()));
     $result = array();
     $loginForm = new LoginForm($params);
     if ($wgUser->getOption("fbFromExist")) {
         $res = $loginForm->mailPasswordInternal($user, true, 'fbconnect-passwordremindertitle-exist', 'fbconnect-passwordremindertext-exist');
     } else {
         $res = $loginForm->mailPasswordInternal($user, true, 'fbconnect-passwordremindertitle', 'fbconnect-passwordremindertext');
     }
     if (WikiError::isError($res)) {
         return $statusError;
     }
     return array('status' => "ok");
 }