* @package StatusNet
* @author Craig Andrews <candrews@integralblue.com>
* @author Zach Copley <zach@status.net>
- * @copyright 2009-2010 StatusNet, Inc.
+ * @copyright 2009-2011 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
$this->notice = $notice;
$profile_id = $profile ? $profile->id : $notice->profile_id;
- $this->flink = Foreign_link::getByUserID(
- $profile_id,
- FACEBOOK_SERVICE
- );
-
- if (!empty($this->flink)) {
+ try {
+ $this->flink = Foreign_link::getByUserID($profile_id, FACEBOOK_SERVICE);
$this->user = $this->flink->getUser();
+ } catch (NoResultException $e) {
+ // at least $this->flink could've gotten set to something,
+ // but the logic that was here before didn't care, so let's not care either
}
}
// If it's not a reply, or if the user WANTS to send @-replies,
// then, yeah, it can go to Facebook.
- if (!preg_match('/@[a-zA-Z0-9_]{1,15}\b/u', $this->notice->content) ||
+
+ if (empty($this->notice->reply_to) ||
($this->flink->noticesync & FOREIGN_NOTICE_SEND_REPLY)) {
return true;
}
// Facebook has a 420-char hardcoded max.
if (mb_strlen($statustxt) > 420) {
- $noticeUrl = common_shorten_url($this->notice->uri);
+ $noticeUrl = common_shorten_url($this->notice->getUrl());
$urlLen = mb_strlen($noticeUrl);
$txt = mb_substr($statustxt, 0, 420 - ($urlLen + 3)) . ' … ' . $noticeUrl;
}
foreach($attachments as $attachment)
{
- if($enclosure = $attachment->getEnclosure()){
+ try {
+ $enclosure = $attachment->getEnclosure();
$fbmedia = $this->getFacebookMedia($enclosure);
- }else{
+ } catch (ServerException $e) {
$fbmedia = $this->getFacebookMedia($attachment);
}
if($fbmedia){
$subject = _m('Your Facebook connection has been removed');
// TRANS: E-mail body. %1$s is a username, %2$s is the StatusNet sitename.
- $msg = _m('Hi %1$s,\n\n'.
- 'We are sorry to inform you we are unable to publish your notice to\n'.
- 'Facebook, and have removed the connection between your %2$s account and\n'.
- 'Facebook.\n\n'.
- 'This may have happened because you have removed permission for %2$s\n'.
- 'to post on your behalf, or perhaps you have deactivated your Facebook\n'.
- 'account. You can reconnect your %2$s account to Facebook at any time by\n'.
- 'logging in with Facebook again.\n\n'.
- 'Sincerely,\n\n'.
- '%2$s\n');
+ $msg = _m("Hi %1\$s,\n\n".
+ "We are sorry to inform you we are unable to publish your notice to\n".
+ "Facebook, and have removed the connection between your %2\$s account and\n".
+ "Facebook.\n\n".
+ "This may have happened because you have removed permission for %2\$s\n".
+ "to post on your behalf, or perhaps you have deactivated your Facebook\n".
+ "account. You can reconnect your %2\$s account to Facebook at any time by\n".
+ "logging in with Facebook again.\n\n".
+ "Sincerely,\n\n".
+ "%2\$s\n");
$body = sprintf(
$msg,
// TRANS: E-mail body. %1$s is a username,
// TRANS: %2$s is the StatusNet sitename, %3$s is the site contact e-mail address.
- $msg = _m('Hi %1$s,\n\n'.
- 'We have noticed you have deauthorized the Facebook connection for your\n'.
- '%2$s account. You have not set a password for your %2$s account yet, so\n'.
- 'you will not be able to login. If you wish to continue using your %2$s\n'.
- 'account, please contact the site administrator (%3$s) to set a password.\n\n'.
- 'Sincerely,\n\n'.
- '%2$s\n');
+ $msg = _m("Hi %1\$s,\n\n".
+ "We have noticed you have deauthorized the Facebook connection for your\n".
+ "%2\$s account. You have not set a password for your %2\$s account yet, so\n".
+ "you will not be able to login. If you wish to continue using your %2\$s\n".
+ "account, please contact the site administrator (%3\$s) to set a password.\n\n".
+ "Sincerely,\n\n".
+ "%2\$s\n");
$body = sprintf(
$msg,
*/
static function facebookStatusId($notice)
{
- $n2i = Notice_to_item::staticGet('notice_id', $notice->id);
+ $n2i = Notice_to_item::getKV('notice_id', $notice->id);
if (empty($n2i)) {
return null;
static function addFacebookUser($fbuser)
{
// remove any existing, possibly outdated, record
- $luser = Foreign_user::getForeignUser($fbuser['id'], FACEBOOK_SERVICE);
-
- if (!empty($luser)) {
-
- $result = $luser->delete();
-
+ try {
+ $fuser = Foreign_user::getForeignUser($fbuser->id, FACEBOOK_SERVICE);
+ $result = $fuser->delete();
if ($result != false) {
common_log(
LOG_INFO,
sprintf(
'Removed old Facebook user: %s, fbuid %d',
- $fbuid['name'],
- $fbuid['id']
+ $fbuid->name,
+ $fbuid->id
),
__FILE__
);
}
+ } catch (NoResultException $e) {
+ // no old foreign users exist for this id
}
$fuser = new Foreign_user();
- $fuser->nickname = $fbuser['name'];
- $fuser->uri = $fbuser['link'];
- $fuser->id = $fbuser['id'];
+ $fuser->nickname = $fbuser->username;
+ $fuser->uri = $fbuser->link;
+ $fuser->id = $fbuser->id;
$fuser->service = FACEBOOK_SERVICE;
$fuser->created = common_sql_now();
LOG_WARNING,
sprintf(
'Failed to add new Facebook user: %s, fbuid %d',
- $fbuser['name'],
- $fbuser['id']
+ $fbuser->username,
+ $fbuser->id
),
__FILE__
);
LOG_INFO,
sprintf(
'Added new Facebook user: %s, fbuid %d',
- $fbuser['name'],
- $fbuser['id']
+ $fbuser->name,
+ $fbuser->id
),
__FILE__
);
*/
function streamRemove()
{
- $n2i = Notice_to_item::staticGet('notice_id', $this->notice->id);
+ $n2i = Notice_to_item::getKV('notice_id', $this->notice->id);
if (!empty($this->flink) && !empty($n2i)) {
try {
*/
function like()
{
- $n2i = Notice_to_item::staticGet('notice_id', $this->notice->id);
+ $n2i = Notice_to_item::getKV('notice_id', $this->notice->id);
if (!empty($this->flink) && !empty($n2i)) {
try {
*/
function unLike()
{
- $n2i = Notice_to_item::staticGet('notice_id', $this->notice->id);
+ $n2i = Notice_to_item::getKV('notice_id', $this->notice->id);
if (!empty($this->flink) && !empty($n2i)) {
try {