Saturngod

What's on my mind

facebook on apiwork

Today, I tried to combine with facebook and apiwork. Great!! it's not too hard. Now, I can call facebook class easily and apiwork can use [facebook developer wiki](http://wiki.developers.facebook.com/index.php/Main_Page). I just use Facebook Class for my apiwork.

In Controller (facebook.php)

<?php
class facebookController extends Controller {

function facebookController()
{
parent::Controller();
}

function index()
{
$this->load->Facebook();
$data[‘fb_user’]=$this->fb->get_loggedin_user();
$data[‘appapikey’]=AWConfig::fbapikey;
$data[‘fb’]=$this->fb;
$this->load->view("facebook_test",$data);
}
}
?>

In View (facebook_test.php),

<html>
<head>
<!– Call Javascript For FBML –>

<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php/en_US&quot; type="text/javascript"></script><script type="text/javascript">FB.init("<?= $appapikey ?>");</script>

<title>Facebook Connect</title>
</head>
<body>
<?php
if(!$fb_user)
{
?>
<!– Login Button –>
<fb:login-button v="2" size="medium" onlogin="window.location.reload(true);">Connect with Facebook</fb:login-button>

<?php
}
else
{
echo "Facebook";

//User
//http://wiki.developers.facebook.com/index.php/Users.getInfo
//can retrive many user information except user’s email , check wiki
$user_details=$fb->api_client->users_getInfo($fb_user, array(‘uid’,’last_name’,’first_name’,’proxied_email’,’email_hashes’));
$uid=$user_details[0][‘uid’];
$firstName=$user_details[0][‘first_name’];
$lastName=$user_details[0][‘last_name’];
$proxemail=$user_details[0][‘proxied_email’];
$email=$user_details[0][‘email_hashes’];
echo $uid;
echo "<br>";
echo $email;
echo "<br>";
echo $proxemail;
echo "<br>";
echo $firstName;
echo "<br>";
echo $lastName;

//Friend
//http://wiki.developers.facebook.com/index.php/Friends.get
echo "<p>Friends:";
$friends = $fb->api_client->friends_get();
//slice the friend list
$friends = array_slice($friends, 0, 5);
foreach ($friends as $friend) {
echo "<br>$friend";
}
echo "</p>";
?>

<!–
http://developers.facebook.com/tools.php?connect_wizard
–>

<!– Profile Picture –>
<fb:profile-pic uid="<?= $uid ?>" size="square" facebook-logo="true"></fb:profile-pic>
<br/>
<!– Friend Pic –>
<div id="profile_pics"></div>
<script type="text/javascript">
var widget_div = document.getElementById("profile_pics");
FB.ensureInit(function () {
FB.Facebook.get_sessionState().waitUntilReady(function() {
FB.Facebook.apiClient.friends_get(null, function(result) {
var markup = "";
var num_friends = result ? Math.min(5, result.length) : 0;
if (num_friends > 0) {
for (var i=0; i<num_friends; i++) {
markup +=
‘<fb:profile-pic size="square" uid="’+result[i]+’" facebook-logo="true"></fb:profile-pic>’;
}
}
widget_div.innerHTML = markup;
FB.XFBML.Host.parseDomElement(widget_div);
});
});
});
</script>

<?

//status

$status=$fb->api_client->call_method("facebook.status.get", array(‘uid’=>$uid, ‘limit’=>’5’));

for($i=0;$i<5;$i++)
{
echo $status[$i][‘message’];
echo "<hr>";
}
//you can try
//print_r($status);

echo "<br>";

//Check Permission
$permission = $fb->api_client->Users_hasAppPermission(‘status_update’);
if($permission)
{
//If permission have status update
$msg=$fb->api_client->call_method("facebook.status.set",array(‘status’=>’I can update stataus from fb connect’));
}
else
{
?>
<script>
/
extended permission are
status_update, photo_upload, video_upload, create_note, and share_item
/

//Call facebook and return to ornagai.com
//if not get permission , next for Allow, next_cancel for not Allow
location.href="http://www.facebook.com/authorize.php?api_key=<?= $appapikey ?>&v=1.0&ext_perm=status_update&next=http://www.yoursite.com/fbconnect.php&next_cancel=http://www.yoursite.com&quot;

//You can also use dialog messagebox
/
FB.Connect.showPermissionDialog("status_update", function(perms) {
if (!perms) {
continue_without_permission();
} else {
save_session();
}
});
/
</script>
<?
}
?>
<!–
with PHP
$fb->logout( "http://site.com/returnAfterLogout.php&quot; )
–>

Logout
<?
}//End Facebook user
?>
</body>
</html>

Add jquery built in apiwork

haha. I add jquery for default. Here, I use in my view like this

&lt;html&gt; &lt;head&gt; &lt;?php /* add script from code.jquery.com $this-&gt;jq-&gt;get_latest(); */ //you can also load like this $this-&gt;load-&gt;js('jquery'); $this-&gt;jq-&gt;noconfilt=true //for jquery no conflit&nbsp; $this-&gt;jq-&gt;get_script();&nbsp; ?&gt;&nbsp; &lt;script&gt; &lt;?php $this-&gt;jq-&gt;start_jq(); ?&gt; alert("I'm jquery"); &lt;?php $this-&gt;jq-&gt;end_jq(); ?&gt; &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt;

Done MVC

Today, I done my MVC framework raw, not include library file.

Just call Controller -> Model -> View

I told about my controller in yesterday. Here my view design

class simpleModel extends Model {

function simpleModel()
{
parent::Model();
}
function printit()
{
$data[‘a’]=1;
$this->load->view("Test",$data);
}
}

Here test view

<h3>Title</h3><?= $a; ?>

how nice. Haha… you may told, imm… totally look like CI. Of course, I’m crazy in CI and my MVC look like CI but code is not same. I also used extract method for array key to variable. Now, I just need to combine with my old apiwork. After that, apiwork will be MVC framework.

load model look like CI

<div class="CodeRay">
Abstract class Controller extends Loader {
public $load;
function Controller()
{
        $this->load=$this;
}
abstract function index();
}

So, I can call like this

class IndexController extends Controller {

    function IndexController()
    {
        parent::Controller();
    }

        function index()
        {
                $this->load->model("simple");
                print_r($this->simple);
        }
}

This is my first time setting look like this and I never thinking before

$this->load=$this ;

In the old, I calling like this

$this->load->simple->function();

hmm… How stupid it!!! Cheer!!!! Saturngod