From a373e6f500e172fed02ea6c892b69af69da4f688 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Sun, 11 Jan 2009 08:33:28 +0000 Subject: trac750 Automatically update Identi.ca profile box with user's latest dent --- actions/facebookhome.php | 17 ++++++++------ lib/facebookaction.php | 55 ------------------------------------------- lib/facebookutil.php | 57 ++++++++++++++++++++++++++++++++++++++++++++- scripts/update_facebook.php | 6 +++-- 4 files changed, 70 insertions(+), 65 deletions(-) diff --git a/actions/facebookhome.php b/actions/facebookhome.php index 4e67494f0..bbef447cd 100644 --- a/actions/facebookhome.php +++ b/actions/facebookhome.php @@ -82,21 +82,24 @@ class FacebookhomeAction extends FacebookAction function showHome($flink, $msg) { + + $facebook = get_facebook(); + $fbuid = $facebook->require_login(); + + $user = $flink->getUser(); + + $notice = $user->getCurrentNotice(); + update_profile_box($facebook, $fbuid, $user, $notice); + + $this->show_header('Home'); if ($msg) { common_element('fb:success', array('message' => $msg)); } - $facebook = get_facebook(); - $fbuid = $facebook->require_login(); - - $user = $flink->getUser(); - echo $this->show_notices($user); - $this->update_profile_box($facebook, $fbuid, $user); - $this->show_footer(); } diff --git a/lib/facebookaction.php b/lib/facebookaction.php index 04bbd67ba..ddf81c034 100644 --- a/lib/facebookaction.php +++ b/lib/facebookaction.php @@ -29,61 +29,6 @@ class FacebookAction extends Action parent::handle($args); } - function update_profile_box($facebook, $fbuid, $user) - { - - $notice = $user->getCurrentNotice(); - - # Need to include inline CSS for styling the Profile box - - $style = ''; - - $html = Facebookaction::render_notice($notice); - - - $fbml = "$style $html"; - $fbml .= "$style $html"; - - $fbml_main = "$style $html"; - - $facebook->api_client->profile_setFBML(null, $fbuid, $fbml, null, null, $fbml_main); - } - - # Display methods - function show_header($selected = 'Home', $msg = null, $success = false) { diff --git a/lib/facebookutil.php b/lib/facebookutil.php index e844dd09a..2529b8a4b 100644 --- a/lib/facebookutil.php +++ b/lib/facebookutil.php @@ -48,4 +48,59 @@ function start_fbml($indent = true) $xw = new XMLWriter(); $xw->openURI('php://output'); $xw->setIndent($indent); -} \ No newline at end of file +} + +function update_profile_box($facebook, $fbuid, $user, $notice) +{ + + // Need to include inline CSS for styling the Profile box + + $style = ''; + + global $xw; + $xw = new XMLWriter(); + $xw->openMemory(); + + $item = new NoticeListItem($notice); + $item->show(); + + $fbml = "$style " . $xw->outputMemory(false) . ""; + $fbml .= "$style " . $xw->outputMemory(false) . ""; + + $fbml_main = "$style " . $xw->outputMemory(false) . ""; + + $facebook->api_client->profile_setFBML(null, $fbuid, $fbml, null, null, $fbml_main); +} diff --git a/scripts/update_facebook.php b/scripts/update_facebook.php index 15c0e49f8..2a1251f37 100755 --- a/scripts/update_facebook.php +++ b/scripts/update_facebook.php @@ -31,7 +31,7 @@ require_once(INSTALLDIR . '/lib/common.php'); require_once(INSTALLDIR . '/lib/facebookutil.php'); // For storing the last run date-time -$last_updated_file = "/home/zach/laconica/scripts/facebook_last_updated"; +$last_updated_file = INSTALLDIR . '/scripts/facebook_last_updated'; // Lock file name $tmp_file = "/tmp/update_facebook.lock"; @@ -54,7 +54,8 @@ $cnt = 0; while($notice->fetch()) { - $flink = Foreign_link::getByUserID($notice->profile_id, 2); + $flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE); + $user = $flink->getUser(); $fbuid = $flink->foreign_id; $content = $notice->content; @@ -64,6 +65,7 @@ while($notice->fetch()) { if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $content) || (($flink->noticesync & FOREIGN_NOTICE_SEND_REPLY) == FOREIGN_NOTICE_SEND_REPLY)) { update_status($fbuid, $content); + update_profile_box($facebook, $fbuid, $user, $notice); $cnt++; } } -- cgit v1.2.3-54-g00ecf