Skip to content

Commit

Permalink
facebook
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Hendrickson committed Oct 17, 2009
1 parent 7857989 commit 799cfd1
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 0 deletions.
Binary file added app/facebook/.DS_Store
Binary file not shown.
96 changes: 96 additions & 0 deletions app/facebook/controllers/facebook_users.php
@@ -0,0 +1,96 @@
<?php


function get( &$vars ) {
extract( $vars );
switch ( count( $collection->members )) {
case ( 1 ) :
if ($request->id && $request->entry_url())
render( 'action', 'entry' );
default :
render( 'action', 'index' );
}
}




function facebook_oauth_login_test(&$vars) {
extract($vars);
$success = false;

if ($success)
echo 1;
else
echo 0;

exit;

}



function _doctype( &$vars ) {
// doctype controller
}



function index( &$vars ) {
extract( $vars );
$theme = environment('theme');
$blocks = environment('blocks');
$atomfeed = $request->feed_url();
return vars(
array(
&$blocks,
&$profile,
&$collection,
&$atomfeed,
&$theme
),
get_defined_vars()
);
}




function _edit( &$vars ) {
extract( $vars );

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

$stat = $Setting->find_by(array('name'=>'facebook_status','profile_id'=>get_profile_id()));

if (!$stat) {
$stat = $Setting->base();
$stat->set_value('profile_id',get_profile_id());
$stat->set_value('person_id',get_person_id());
$stat->set_value('name','facebook_status');
$stat->set_value('value','enabled');
$stat->save_changes();
$stat->set_etag();
$stat = $Setting->find($stat->id);
}

// get the one-to-one-related child-record from "entries"
$sEntry =& $stat->FirstChild('entries');

$staturl = $request->url_for(array('resource'=>'settings','id'=>$stat->id,'action'=>'put'));

$status = $stat->value;

$aktwitter_tw_text_options = array(
'disabled'=>'disabled',
'enabled'=>'enabled'
);

return vars(
array( &$aktwitter_tw_text_options,&$status,&$staturl,&$sEntry,&$profile ),
get_defined_vars()
);

}

82 changes: 82 additions & 0 deletions app/facebook/plugins/facebook.php
@@ -0,0 +1,82 @@
<?php

after_filter( 'send_to_facebook', 'insert_from_post' );

before_filter( 'copy_posted_blob', 'insert_from_post' );

function copy_posted_blob( &$model, &$req ) {

if (!get_profile_id())
return;

if (get_option('facebook_status') != 'enabled')
return;

if (!file_exists($_FILES['post']['tmp_name']['attachment']))
return;

$tmp = 'cache'.DIRECTORY_SEPARATOR.make_token();
$result = copy ( $_FILES['post']['tmp_name']['attachment'] , $tmp );
$_SESSION['copied_blob'] = $tmp;

}

function send_to_facebook( &$model, &$rec ) {

if (!get_profile_id())
return;

if (!$rec->table == 'posts')
return;

// if the Record does not have a title or uri, bail out
if (!(isset($rec->title)) || !(isset($rec->uri)))
return;

if (get_option('facebook_status') != 'enabled')
return;

global $db,$prefix;

$sql = "SELECT facebook_id FROM ".$prefix."facebook_users WHERE profile_id = ".get_profile_id();
$result = $db->get_result( $sql );

if ($db->num_rows($result) == 1) {

// Facebook Streams http://brianjesse.com

$app_id = environment('facebookAppId');
$consumer_key = environment('facebookKey');
$consumer_secret = environment('facebookSecret');
$agent = environment('facebookAppName')." (curl)";

add_include_path(library_path());
add_include_path(library_path().'facebook-platform/php');
add_include_path(library_path().'facebook_stream');

require_once "FacebookStream.php";
require_once "Services/Facebook.php";

$userid = $db->result_value($result,0,'facebook_id');

$fs = new FacebookStream($consumer_key,$consumer_secret,$agent);

$notice_content = $rec->attributes['title'];

if ($userid && isset($_SESSION['copied_blob'])) {

if (extension_for(type_of($_FILES['post']['name']['attachment'])) == 'jpg')
$fs->PhotoUpload($_SESSION['copied_blob'], 0, $notice_content,$userid);

unlink($_SESSION['copied_blob']);
unset($_SESSION['copied_blob']);

} elseif ($userid) {

$fs->setStatus($notice_content,$userid);

}

}
}

63 changes: 63 additions & 0 deletions app/facebook/views/facebook_users/_edit.html
@@ -0,0 +1,63 @@
<?php include 'wp-content/language/lang_chooser.php'; //Loads the language-file ?>

<script src="<?php base_path(); ?>resource/jeditable/jquery.jeditable.js" type="text/javascript"></script>
<script src="<?php base_path(); ?>resource/jeditable/jquery.highlightFade.js" type="text/javascript"></script>

<script type="text/javascript">
// <![CDATA[


$(document).ready(function() {

var submit_to = "<?php echo $staturl; ?>";

$(".editable_select_fb_text").mouseover(function() {
$(this).highlightFade({end:'#def'});
});
$(".editable_select_fb_text").mouseout(function() {
$(this).highlightFade({end:'#fff', speed:200});
});
$(".editable_select_fb_text").editable(submit_to, {
indicator : "<img src='<?php base_path(); ?>resource/jeditable/indicator.gif'>",
data : '<?php $json = new Services_JSON(); echo $json->encode( $aktwitter_tw_text_options ); ?>',
submitdata : function() {
return {"entry[etag]" : "<?php echo $sEntry->etag; ?>"};
},
name : "setting[value]",
type : "select",
<?php if (!empty($status)) : ?>
placeholder : "<?php echo $status; ?>",
<?php endif; ?>
noappend : "true",
submit : "<?php echo $txt['facebook_settings_ok']; ?>",
tooltip : "<?php echo $txt['facebook_settings_click_edit']; ?>",
cancel : "<?php echo $txt['facebook_settings_cancel']; ?>",
callback : function(value, settings) {
$(this).html(settings['jsonarr'][value-0]);
return(value);
}
});



});

// ]]>
</script>





<div id="twitterbox">
<br />
<h3><?php echo $txt['facebook_settings_post_to_facebook']; ?></h3>
<br />
<br />
<h4><?php echo $txt['facebook_settings_status']; ?>:</h4>
<p class="editable_select_fb_text" id="editable_select_fb_text"><?php echo $status; ?></p>
<br />

</div>

<br /><br />

0 comments on commit 799cfd1

Please sign in to comment.