Created
May 6, 2012 22:30
-
-
Save vbugarsk/2624832 to your computer and use it in GitHub Desktop.
FB Yii connect without extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function actionFacebook() | |
{ | |
$alias=Yii::getPathOfAlias('custom.components.facebook'); | |
require($alias.DIRECTORY_SEPARATOR.'facebook.php'); | |
$facebook = new Facebook(array( | |
'appId' => Yii::app()->settings->get('facebook','appId'), | |
'secret' => Yii::app()->settings->get('facebook','appSecret'), | |
)); | |
$this->layout='//layouts/facebook_connect'; | |
$user=$facebook->getUser(); | |
$user_friends=$user_profile=$login_url=$logout_url=$status_update=null; | |
if(empty($user)) | |
{ | |
$login_url=$facebook->getLoginUrl(array( | |
'scope'=>'friends_photos, publish_stream', | |
'display'=>'popup', | |
'next'=>Yii::app()->createAbsoluteUrl('connect/default/facebook'), | |
)); | |
Yii::app()->request->redirect($login_url); | |
} | |
$logout_url=$facebook->getLogoutUrl(); | |
try | |
{ | |
$user_profile=$facebook->api('/me'); | |
$user_friends=$facebook->api('/me/friends'); | |
} | |
catch(FacebookApiException $e){} | |
$this->render('_facebook',array( | |
'user' => $user, | |
'user_friends' => $user_friends, | |
'user_profile' => $user_profile, | |
'login_url' => $login_url, | |
'logout_url' => $logout_url, | |
)); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<table cellpadding="0" cellspacing="0" style="margin-top: 10px;"> | |
<tr> | |
<?php if(!empty($user_friends['data'])):?> | |
<?php $i=0; foreach($user_friends['data'] AS $friend): ++$i;?> | |
<td align="left" valign="top" width="120" style="padding-bottom: 10px;"> | |
<table cellpadding="0" cellspacing="0" width="120"> | |
<tr> | |
<td align="center" valign="top"> | |
<a href="javascript:;" onclick="submitFriendForm(<?php echo (int)$friend['id'];?>);"> | |
<img src="http://graph.facebook.com/<?php echo (int)$friend['id'];?>/picture" style="border:2px solid #fff; padding:3px;"/> | |
</a> | |
</td> | |
</tr> | |
<tr> | |
<td align="center" valign="top" style="font-size:10px"> | |
<?php | |
if(strpos($friend['name'],' ')!==false) | |
{ | |
$part=explode(" ",$friend['name']); | |
if(strlen($part[0])>10) | |
echo CHtml::encode(substr($part[0],0,10)).'...'; | |
else | |
echo CHtml::encode($part[0]); | |
} | |
else | |
{ | |
if(strlen($friend['name'])>10) | |
echo CHtml::encode(substr($friend['name'],0,10)).'...'; | |
else | |
echo CHtml::encode($friend['name']); | |
} | |
?> | |
</td> | |
</tr> | |
</table> | |
</td> | |
<?php if($i % 4 == 0):?></tr><tr><?php endif;?> | |
<?php endforeach;?> | |
<?php endif;?> | |
</tr> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.yiiframework.com/forum/index.php/topic/20465-facebook-connect/