Skip to content

Commit

Permalink
fb like
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed May 19, 2010
1 parent 995d7aa commit 8dd24e5
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 17 deletions.
17 changes: 16 additions & 1 deletion app/facebook/plugins/facebook.php
Expand Up @@ -182,7 +182,22 @@ function send_to_facebook( &$model, &$rec ) {
);


$f->update($notice_content,$uid);
$fb_post_id = $f->publish($notice_content,$uid);


$Like =& $db->model('Like');

$l = $Like->find_by(array('post_id'=>$rec->id));

if (!$l->exists){

$l = $Like->base();
$l->set_value('post_id',$rec->id);
}

$l->set_value('fb_post_id',$fb_post_id);

$l->save_changes();
}

}
Expand Down
5 changes: 4 additions & 1 deletion app/omb/plugins/security.php
Expand Up @@ -907,7 +907,10 @@ function _oauth( &$vars ) {
}

$_SESSION['oauth_person_id'] = $i->person_id;


if (isset($_SESSION['tw_forward']))
redirect_to($_SESSION['tw_forward']);

if (empty($redirect_to)) {
$content = "<p>there was an error in the oauth routine, sorry</p>";
} else {
Expand Down
10 changes: 9 additions & 1 deletion app/omb/plugins/wp.php
Expand Up @@ -2336,8 +2336,16 @@ function in_reply_to(&$the_post) {
add_include_path(library_path());
include('remy-tweed/plugins/linkify.php');

function add_shortcode(){
return "";
}

function maybe_unserialize(){
return "";
}


function is_page_template(){
return "";
}


26 changes: 24 additions & 2 deletions app/twitter/plugins/twitter.php
Expand Up @@ -45,8 +45,30 @@ function send_to_twitter( &$model, &$rec ) {
);

$notice_content = substr( $rec->title, 0, 140 );

$content = $to->OAuthRequest('https://twitter.com/statuses/update.xml', array('status' => $notice_content), 'POST');

$content = $to->OAuthRequest('https://twitter.com/statuses/update.json', array('status' => $notice_content), 'POST');

if (!(class_exists('Services_JSON')))
lib_include('json');

$json = new Services_JSON();
$tw_post = (array) $json->decode($content);

$Like =& $db->model('Like');

$l = $Like->find_by(array('post_id'=>$rec->id));

if (!$l->exists){

$l = $Like->base();
$l->set_value('post_id',$rec->id);
}

$l->set_value('tw_post_id',$tw_post['id']);

$l->save_changes();



} else {

Expand Down
42 changes: 30 additions & 12 deletions db/library/dbscript/facebook.php
Expand Up @@ -4,10 +4,13 @@ class FacebookHelper extends Helper {

function header( $key, $xd, $next ) {

global $request;
$url = $request->url_for('facebook_login');

echo <<<EOD
<script type="text/javascript">
function facebook_onlogin() {
window.location='$next';
window.location='$url';
}
function facebook_dologin() {
FB_RequireFeatures(["XFBML"], function(){
Expand Down Expand Up @@ -94,13 +97,16 @@ class Facebook {
var $userid;
var $api_root = 'http://www.facebook.com';

function Facebook( $key, $secret, $appid, $agent, $session, $next ){
function Facebook( $key, $secret, $appid, $agent, $session=false, $next ){
Services_Facebook::$apiKey = $key;
Services_Facebook::$secret = $secret;
$this->api = new Services_Facebook();
$this->agent = $agent;
$this->appid = $appid;
$this->api->sessionKey = $session;
if (!$session)
$_SESSION['fb_session'] = $this->api->sessionKey;
else
$this->api->sessionKey = $session;
$this->next = $next;
}

Expand All @@ -115,7 +121,7 @@ function authorize_from_access() {
$this->userid = $this->api->users->getLoggedInUser();
}

function permission_to( $perm, $uid=false, $force=false ) {
function permission_to( $perm, $uid=false, $force=false, $return=false ) {
$params = array(
'ext_perm' => $perm,
'uid' => $this->userid
Expand All @@ -128,33 +134,45 @@ function permission_to( $perm, $uid=false, $force=false ) {
$xml = (array) $xml;
}
if ($force || !$xml[0]) {
$url = $this->api_root . '/authorize.php';

$url = $this->api_root . '/connect/prompt_permissions.php';
$params = array('api_key' => Services_Facebook::$apiKey,
'v' => '1.0');
if ($uid)
$params['uid'] = $uid;
$params['ext_perm'] = $perm;
$params['next'] = $this->next;
$url = $url . '?' . http_build_query($params);

if ($return)
return $url;
header( 'Location:' . $url );
exit;
}
}

function like( $id, $uid=false ) {
//$this->permission_to( 'publish_stream', $uid );
$params = array(
'uid' => $this->userid,
);
if ($uid)
$params['uid'] = $uid;
$params['post_id'] = $id;
$res = $this->api->users->callMethod( 'stream.addLike', $params );
return (intval((string)$res) == 1);
}

function publish( $status, $uid=false ) {
$this->permission_to( 'publish_stream', $uid );
//$this->permission_to( 'publish_stream', $uid );
$params = array(
'uid' => $this->userid,
);
if ($uid)
$params['uid'] = $uid;
if (is_bool($status) && $status === true) {
$params['clear'] = 'true';
} else {
$params['status'] = $status;
}
$params['message'] = $status;
$res = $this->api->users->callMethod( 'stream.publish', $params );
return (intval((string)$res) == 1);
return (string)$res;
}

function update( $status, $uid=false ) {
Expand Down

0 comments on commit 8dd24e5

Please sign in to comment.