コード例 #1
0
ファイル: FBConnectUser.php プロジェクト: schwarer2006/wikia
 /**
  * Update a user's settings with the values retrieved from the current
  * logged-in Facebook user. Settings are only updated if a different value
  * is returned from Facebook and the user's settings allow an update on
  * login.
  */
 function updateFromFacebook()
 {
     wfProfileIn(__METHOD__);
     // Keep track of whether any settings were modified
     $mod = false;
     // Connect to the Facebook API and retrieve the user's info
     $fb = new FBConnectAPI();
     $userinfo = $fb->getUserInfo();
     // Update the following options if the user's settings allow it
     $updateOptions = array('nickname', 'fullname', 'language', 'timecorrection', 'email');
     foreach ($updateOptions as $option) {
         // Translate Facebook parameters into MediaWiki parameters
         $value = self::getOptionFromInfo($option, $userinfo);
         if ($value && $this->getOption("fbconnect-update-on-login-{$option}", "0") == "1") {
             switch ($option) {
                 case 'fullname':
                     $this->setRealName($value);
                     break;
                 default:
                     $this->setOption($option, $value);
             }
             $mod = true;
         }
     }
     // Only save the updated settings if something was changed
     if ($mod) {
         $this->saveSettings();
     }
     wfProfileOut(__METHOD__);
 }
コード例 #2
0
 /**
  * @dataProvider isConfigSetupDataProvider
  */
 public function testIsConfigSetup($expected, $fbAppId, $fbAppSecret)
 {
     $this->fbAppId = $fbAppId;
     $this->fbAppSecret = $fbAppSecret;
     $app = $this->getMock('WikiaApp', array('getGlobal'));
     $app->expects($this->any())->method('getGlobal')->will($this->returnCallback(array($this, 'isConfigSetupGlobalsCallback')));
     F::setInstance('App', $app);
     $result = FBConnectAPI::isConfigSetup();
     $this->assertEquals($expected, $result);
 }
コード例 #3
0
ファイル: FBConnectAPI.php プロジェクト: schwarer2006/wikia
 /**
  * Get the Facebook client object for easy access.
  */
 public function Facebook()
 {
     global $fbAppId, $fbAppSecret;
     // Construct a new Facebook object on first time access
     if (is_null(self::$__Facebook) && self::isConfigSetup()) {
         self::$__Facebook = F::build('Facebook3', array(array('appId' => $fbAppId, 'secret' => $fbAppSecret)));
         self::$__Facebook->api_client = F::build('FacebookRestClient', array($fbAppId, $fbAppSecret, null));
         //Facebook( $fbAppId, $fbAppSecret );
         if (!self::$__Facebook) {
             error_log('Could not create facebook client.');
         }
     }
     return self::$__Facebook;
 }
コード例 #4
0
ファイル: SpecialConnect.php プロジェクト: schwarer2006/wikia
 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;
 }
コード例 #5
0
 function mainLoginForm(&$specialConnect, $msg, $msgtype = 'error')
 {
     global $wgUser, $wgOut, $wgHiddenPrefs, $wgEnableEmail;
     global $wgCookiePrefix, $wgLoginLanguageSelector;
     global $wgAuth, $wgEmailConfirmToEdit, $wgCookieExpiration, $wgRequest;
     $this->msg = $msg;
     $this->msgtype = $msgtype;
     $tmpl = new ChooseNameTemplate();
     $tmpl->addInputItem('wpMarketingOptIn', 1, 'checkbox', 'tog-marketingallowed');
     $returnto = "";
     if (!empty($this->mReturnTo)) {
         $returnto = '&returnto=' . wfUrlencode($this->mReturnTo);
         if (!empty($this->mReturnToQuery)) {
             $returnto .= '&returntoquery=' . wfUrlencode($this->mReturnToQuery);
         }
     }
     $tmpl->set('actioncreate', $specialConnect->getTitle('ChooseName')->getLocalUrl($returnto));
     $tmpl->set('link', '');
     $tmpl->set('header', '');
     //$tmpl->set( 'name', $this->mUsername ); // intelligently defaulted below
     $tmpl->set('password', $this->mPassword);
     $tmpl->set('retype', $this->mRetype);
     $tmpl->set('actiontype', $this->mActionType);
     $tmpl->set('realname', $this->mRealName);
     $tmpl->set('domain', $this->mDomain);
     $tmpl->set('message', $msg);
     $tmpl->set('messagetype', $msgtype);
     $tmpl->set('createemail', $wgEnableEmail && $wgUser->isLoggedIn());
     $tmpl->set('userealname', !in_array('realname', $wgHiddenPrefs));
     $tmpl->set('useemail', $wgEnableEmail);
     $tmpl->set('emailrequired', $wgEmailConfirmToEdit);
     $tmpl->set('canreset', $wgAuth->allowPasswordChange());
     $tmpl->set('canremember', $wgCookieExpiration > 0);
     $tmpl->set('remember', $wgUser->getOption('rememberpassword') or $this->mRemember);
     $tmpl->set('birthyear', $this->wpBirthYear);
     $tmpl->set('birthmonth', $this->wpBirthMonth);
     $tmpl->set('birthday', $this->wpBirthDay);
     # Prepare language selection links as needed
     if ($wgLoginLanguageSelector) {
         $tmpl->set('languages', $this->makeLanguageSelector());
         if ($this->mLanguage) {
             $tmpl->set('uselang', $this->mLanguage);
         }
     }
     // Facebook-specific customizations below.
     global $fbConnectOnly;
     // Connect to the Facebook API
     $fb = new FBConnectAPI();
     $fb_user = $fb->user();
     $userinfo = $fb->getUserInfo($fb_user);
     // If no email was set yet, then use the value from facebook (which is quite likely also empty, but probably not always).
     if (!$this->mEmail) {
         $this->mEmail = FBConnectUser::getOptionFromInfo('email', $userinfo);
     }
     $tmpl->set('email', $this->mEmail);
     // If the langue isn't set already and there is a setting for it from facebook, apply that.
     if (!$this->mLanguage) {
         $this->mLanguage = FBConnectUser::getOptionFromInfo('language', $userinfo);
     }
     if ($this->mLanguage) {
         $tmpl->set('uselang', $this->mLanguage);
     }
     // Make this an intelligent guess at a good username (based off of their nickname, real name, etc.).
     if (!$this->mUsername) {
         if ($wgUser->isLoggedIn()) {
             $this->mUsername = $wgUser->getName();
         } else {
             $nickname = FBConnectUser::getOptionFromInfo('nickname', $userinfo);
             if (self::userNameOK($nickname)) {
                 $this->mUsername = $nickname;
             } else {
                 $fullname = FBConnectUser::getOptionFromInfo('fullname', $userinfo);
                 if (self::userNameOK($fullname)) {
                     $this->mUsername = $fullname;
                 } else {
                     if (empty($nickname)) {
                         $nickname = $fullname;
                     }
                     // Their nickname and full name were taken, so generate a username based on the nickname.
                     $specialConnect->setUserNamePrefix($nickname);
                     $this->mUsername = $specialConnect->generateUserName();
                 }
             }
         }
     }
     $tmpl->set('name', $this->mUsername);
     /*
     // NOTE: We're not using this at the moment because it seems that there is no need to show these boxes... we'll just default to updating nothing on login (to avoid confusion & to make signup quicker).
     // Create the checkboxes for the user options.
     global $wgCookiePrefix;
     $name = isset($_COOKIE[$wgCookiePrefix . 'UserName']) ?
     			trim($_COOKIE[$wgCookiePrefix . 'UserName']) : '';
     // Build an array of attributes to update
     $updateOptions = array();
     foreach ($specialConnect->getAvailableUserUpdateOptions() as $option) {
     	// Translate the MW parameter into a FB parameter
     	$value = FBConnectUser::getOptionFromInfo($option, $userinfo);
     	// If no corresponding value was received from Facebook, then continue
     	if (!$value) {
     		continue;
     	}
     	// Build the list item for the update option
     	$updateOptions[] = "<li><input name=\"wpUpdateUserInfo$option\" type=\"checkbox\" " .
     		"value=\"1\" id=\"wpUpdateUserInfo$option\" /><label for=\"wpUpdateUserInfo$option\">" .
     		wfMsgHtml("fbconnect-$option") . wfMsgExt('colon-separator', array('escapenoentities')) .
     		" <i>$value</i></label></li>";
     }
     // Implode the update options into an unordered list
     $updateChoices = count($updateOptions) > 0 ? "\n" . wfMsgHtml('fbconnect-updateuserinfo') . "\n<ul>\n" . implode("\n", $updateOptions) . "\n</ul>\n" : '';
     $html = "<tr style='display:none'><td>$updateChoices</td></tr>";
     $tmpl->set( 'updateOptions', $html);
     */
     $tmpl->set('updateOptions', '');
     // Give authentication and captcha plugins a chance to modify the form
     // NOTE: We don't do this for fbconnect.
     //$wgAuth->modifyUITemplate( $template );
     //wfRunHooks( 'UserCreateForm', array( &$template ) );
     $this->ajaxTemplate = $tmpl;
 }
コード例 #6
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;
 }
コード例 #7
0
	/**
	 * 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;
	}
コード例 #8
0
 /**
  * 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;
     }
 }
コード例 #9
0
ファイル: FBConnectHooks.php プロジェクト: schwarer2006/wikia
 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;
 }