Merge branch '0.7.x' of git@gitorious.org:laconica/dev into 0.7.x

This commit is contained in:
Evan Prodromou 2009-02-09 07:26:17 -05:00
commit e29ebc18c7
13 changed files with 176 additions and 113 deletions

View File

@ -191,13 +191,13 @@ class EditgroupAction extends Action
array('http', 'https')))) { array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.')); $this->showForm(_('Homepage is not a valid URL.'));
return; return;
} else if (!is_null($fullname) && strlen($fullname) > 255) { } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).')); $this->showForm(_('Full name is too long (max 255 chars).'));
return; return;
} else if (!is_null($description) && strlen($description) > 140) { } else if (!is_null($description) && mb_strlen($description) > 140) {
$this->showForm(_('description is too long (max 140 chars).')); $this->showForm(_('description is too long (max 140 chars).'));
return; return;
} else if (!is_null($location) && strlen($location) > 255) { } else if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).')); $this->showForm(_('Location is too long (max 255 chars).'));
return; return;
} }

View File

@ -71,13 +71,13 @@ class FacebookinviteAction extends FacebookAction
common_config('site', 'name'))); common_config('site', 'name')));
$this->element('p', null, _('Invitations have been sent to the following users:')); $this->element('p', null, _('Invitations have been sent to the following users:'));
$friend_ids = $_POST['ids']; // XXX: Hmm... is this the best way to acces the list? $friend_ids = $_POST['ids']; // XXX: Hmm... is this the best way to access the list?
$this->elementStart('ul', array('id' => 'facebook-friends')); $this->elementStart('ul', array('id' => 'facebook-friends'));
foreach ($friend_ids as $friend) { foreach ($friend_ids as $friend) {
$this->elementStart('li'); $this->elementStart('li');
$this->element('fb:profile-pic', array('uid' => $friend)); $this->element('fb:profile-pic', array('uid' => $friend, 'size' => 'square'));
$this->element('fb:name', array('uid' => $friend, $this->element('fb:name', array('uid' => $friend,
'capitalize' => 'true')); 'capitalize' => 'true'));
$this->elementEnd('li'); $this->elementEnd('li');
@ -92,6 +92,12 @@ class FacebookinviteAction extends FacebookAction
// Get a list of users who are already using the app for exclusion // Get a list of users who are already using the app for exclusion
$exclude_ids = $this->facebook->api_client->friends_getAppUsers(); $exclude_ids = $this->facebook->api_client->friends_getAppUsers();
$exclude_ids_csv = null;
// fbml needs these as a csv string, not an array
if ($exclude_ids) {
$exclude_ids_csv = implode(',', $exclude_ids);
}
$content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) . $content = sprintf(_('You have been invited to %s'), common_config('site', 'name')) .
htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>'); htmlentities('<fb:req-choice url="' . $this->app_uri . '" label="Add"/>');
@ -103,10 +109,17 @@ class FacebookinviteAction extends FacebookAction
'content' => $content)); 'content' => $content));
$this->hidden('invite', 'true'); $this->hidden('invite', 'true');
$actiontext = sprintf(_('Invite your friends to use %s'), common_config('site', 'name')); $actiontext = sprintf(_('Invite your friends to use %s'), common_config('site', 'name'));
$this->element('fb:multi-friend-selector', array('showborder' => 'false',
'actiontext' => $actiontext, $multi_params = array('showborder' => 'false');
'exclude_ids' => implode(',', $exclude_ids), $multi_params['actiontext'] = $actiontext;
'bypass' => 'cancel'));
if ($exclude_ids_csv) {
$multi_params['exclude_ids'] = $exclude_ids_csv;
}
$multi_params['bypass'] = 'cancel';
$this->element('fb:multi-friend-selector', $multi_params);
$this->elementEnd('fb:request-form'); $this->elementEnd('fb:request-form');

View File

@ -242,7 +242,7 @@ class FinishopenidloginAction extends Action
} }
} }
if ($sreg['fullname'] && strlen($sreg['fullname']) <= 255) { if ($sreg['fullname'] && mb_strlen($sreg['fullname']) <= 255) {
$fullname = $sreg['fullname']; $fullname = $sreg['fullname'];
} }

View File

@ -142,13 +142,13 @@ class NewgroupAction extends Action
array('http', 'https')))) { array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.')); $this->showForm(_('Homepage is not a valid URL.'));
return; return;
} else if (!is_null($fullname) && strlen($fullname) > 255) { } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).')); $this->showForm(_('Full name is too long (max 255 chars).'));
return; return;
} else if (!is_null($description) && strlen($description) > 140) { } else if (!is_null($description) && mb_strlen($description) > 140) {
$this->showForm(_('description is too long (max 140 chars).')); $this->showForm(_('description is too long (max 140 chars).'));
return; return;
} else if (!is_null($location) && strlen($location) > 255) { } else if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).')); $this->showForm(_('Location is too long (max 255 chars).'));
return; return;
} }

View File

@ -1,9 +1,12 @@
<?php <?php
/* /**
* Laconica - a distributed open-source microblogging tool * Laconica, the distributed open-source microblogging tool
* Copyright (C) 2008, Controlez-Vous, Inc.
* *
* This program is free software: you can redistribute it and/or modify * Action for showing profiles self-tagged with a given tag
*
* PHP version 5
*
* LICENCE: This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by * it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
@ -15,62 +18,109 @@
* *
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @category Action
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Zach Copley <zach@controlyourself.ca>
* @copyright 2009 Control Yourself, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*/ */
if (!defined('LACONICA')) { exit(1); } if (!defined('LACONICA')) {
exit(1);
}
require_once INSTALLDIR.'/lib/profilelist.php'; require_once INSTALLDIR.'/lib/profilelist.php';
/**
* This class outputs a paginated list of profiles self-tagged with a given tag
*
* @category Output
* @package Laconica
* @author Evan Prodromou <evan@controlyourself.ca>
* @author Zach Copley <zach@controlyourself.ca>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://laconi.ca/
*
* @see Action
*/
class PeopletagAction extends Action class PeopletagAction extends Action
{ {
var $tag = null; var $tag = null;
var $page = null; var $page = null;
function handle($args) /**
* For initializing members of the class.
*
* @param array $argarray misc. arguments
*
* @return boolean true
*/
function prepare($argarray)
{ {
parent::handle($args); parent::prepare($argarray);
parent::prepare($args);
$this->tag = $this->trimmed('tag'); $this->tag = $this->trimmed('tag');
if (!common_valid_profile_tag($this->tag)) { if (!common_valid_profile_tag($this->tag)) {
$this->clientError(sprintf(_('Not a valid people tag: %s'), $this->tag)); $this->clientError(sprintf(_('Not a valid people tag: %s'),
$this->tag));
return; return;
} }
$this->page = $this->trimmed('page'); $this->page = ($this->arg('page')) ? $this->arg('page') : 1;
if (!$this->page) { common_set_returnto($this->selfUrl());
$this->page = 1;
return true;
} }
/**
* Handler method
*
* @param array $argarray is ignored since it's now passed in in prepare()
*
* @return boolean is read only action?
*/
function handle($argarray)
{
parent::handle($argarray);
$this->showPage(); $this->showPage();
} }
/**
* Whips up a query to get a list of profiles based on the provided
* people tag and page, initalizes a ProfileList widget, and displays
* it to the user.
*
* @return nothing
*/
function showContent() function showContent()
{ {
$profile = new Profile(); $profile = new Profile();
$offset = ($page-1)*PROFILES_PER_PAGE; $offset = ($this->page - 1) * PROFILES_PER_PAGE;
$limit = PROFILES_PER_PAGE + 1; $limit = PROFILES_PER_PAGE + 1;
if (common_config('db','type') == 'pgsql') { if (common_config('db', 'type') == 'pgsql') {
$lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset; $lim = ' LIMIT ' . $limit . ' OFFSET ' . $offset;
} else { } else {
$lim = ' LIMIT ' . $offset . ', ' . $limit; $lim = ' LIMIT ' . $offset . ', ' . $limit;
} }
# XXX: memcached this // XXX: memcached this
$qry = 'SELECT profile.* ' . $qry = 'SELECT profile.* ' .
'FROM profile JOIN profile_tag ' . 'FROM profile JOIN profile_tag ' .
'ON profile.id = profile_tag.tagger ' . 'ON profile.id = profile_tag.tagger ' .
'WHERE profile_tag.tagger = profile_tag.tagged ' . 'WHERE profile_tag.tagger = profile_tag.tagged ' .
'AND tag = "%s" ' . 'AND tag = "%s" ' .
'ORDER BY profile_tag.modified DESC'; 'ORDER BY profile_tag.modified DESC%s';
$profile->query(sprintf($qry, $this->tag, $lim)); $profile->query(sprintf($qry, $this->tag, $lim));
@ -80,13 +130,19 @@ class PeopletagAction extends Action
$this->pagination($this->page > 1, $this->pagination($this->page > 1,
$cnt > PROFILES_PER_PAGE, $cnt > PROFILES_PER_PAGE,
$this->page, $this->page,
$this->trimmed('action'), 'peopletag',
array('tag' => $this->tag)); array('tag' => $this->tag));
} }
/**
* Returns the page title
*
* @return string page title
*/
function title() function title()
{ {
return sprintf( _('Users self-tagged with %s - page %d'), $this->tag, $this->page); return sprintf(_('Users self-tagged with %s - page %d'),
$this->tag, $this->page);
} }
} }

View File

@ -198,13 +198,13 @@ class ProfilesettingsAction extends AccountSettingsAction
!Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) { !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.')); $this->showForm(_('Homepage is not a valid URL.'));
return; return;
} else if (!is_null($fullname) && strlen($fullname) > 255) { } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).')); $this->showForm(_('Full name is too long (max 255 chars).'));
return; return;
} else if (!is_null($bio) && strlen($bio) > 140) { } else if (!is_null($bio) && mb_strlen($bio) > 140) {
$this->showForm(_('Bio is too long (max 140 chars).')); $this->showForm(_('Bio is too long (max 140 chars).'));
return; return;
} else if (!is_null($location) && strlen($location) > 255) { } else if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).')); $this->showForm(_('Location is too long (max 255 chars).'));
return; return;
} else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) { } else if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {

View File

@ -167,13 +167,13 @@ class RegisterAction extends Action
array('http', 'https')))) { array('http', 'https')))) {
$this->showForm(_('Homepage is not a valid URL.')); $this->showForm(_('Homepage is not a valid URL.'));
return; return;
} else if (!is_null($fullname) && strlen($fullname) > 255) { } else if (!is_null($fullname) && mb_strlen($fullname) > 255) {
$this->showForm(_('Full name is too long (max 255 chars).')); $this->showForm(_('Full name is too long (max 255 chars).'));
return; return;
} else if (!is_null($bio) && strlen($bio) > 140) { } else if (!is_null($bio) && mb_strlen($bio) > 140) {
$this->showForm(_('Bio is too long (max 140 chars).')); $this->showForm(_('Bio is too long (max 140 chars).'));
return; return;
} else if (!is_null($location) && strlen($location) > 255) { } else if (!is_null($location) && mb_strlen($location) > 255) {
$this->showForm(_('Location is too long (max 255 chars).')); $this->showForm(_('Location is too long (max 255 chars).'));
return; return;
} else if (strlen($password) < 6) { } else if (strlen($password) < 6) {

View File

@ -56,7 +56,7 @@ class TwitapiaccountAction extends TwitterapiAction
$location = trim($this->arg('location')); $location = trim($this->arg('location'));
if (!is_null($location) && strlen($location) > 255) { if (!is_null($location) && mb_strlen($location) > 255) {
// XXX: But Twitter just truncates and runs with it. -- Zach // XXX: But Twitter just truncates and runs with it. -- Zach
$this->clientError(_('That\'s too long. Max notice size is 255 chars.'), 406, $apidate['content-type']); $this->clientError(_('That\'s too long. Max notice size is 255 chars.'), 406, $apidate['content-type']);

View File

@ -93,22 +93,22 @@ class UpdateprofileAction extends Action
} }
# optional stuff # optional stuff
$fullname = $req->get_parameter('omb_listenee_fullname'); $fullname = $req->get_parameter('omb_listenee_fullname');
if ($fullname && strlen($fullname) > 255) { if ($fullname && mb_strlen($fullname) > 255) {
$this->clientError(_("Full name is too long (max 255 chars).")); $this->clientError(_("Full name is too long (max 255 chars)."));
return false; return false;
} }
$homepage = $req->get_parameter('omb_listenee_homepage'); $homepage = $req->get_parameter('omb_listenee_homepage');
if ($homepage && (!common_valid_http_url($homepage) || strlen($homepage) > 255)) { if ($homepage && (!common_valid_http_url($homepage) || mb_strlen($homepage) > 255)) {
$this->clientError(sprintf(_("Invalid homepage '%s'"), $homepage)); $this->clientError(sprintf(_("Invalid homepage '%s'"), $homepage));
return false; return false;
} }
$bio = $req->get_parameter('omb_listenee_bio'); $bio = $req->get_parameter('omb_listenee_bio');
if ($bio && strlen($bio) > 140) { if ($bio && mb_strlen($bio) > 140) {
$this->clientError(_("Bio is too long (max 140 chars).")); $this->clientError(_("Bio is too long (max 140 chars)."));
return false; return false;
} }
$location = $req->get_parameter('omb_listenee_location'); $location = $req->get_parameter('omb_listenee_location');
if ($location && strlen($location) > 255) { if ($location && mb_strlen($location) > 255) {
$this->clientError(_("Location is too long (max 255 chars).")); $this->clientError(_("Location is too long (max 255 chars)."));
return false; return false;
} }

View File

@ -469,19 +469,19 @@ class UserauthorizationAction extends Action
} }
# optional stuff # optional stuff
$fullname = $req->get_parameter('omb_listenee_fullname'); $fullname = $req->get_parameter('omb_listenee_fullname');
if ($fullname && strlen($fullname) > 255) { if ($fullname && mb_strlen($fullname) > 255) {
throw new OAuthException("Full name '$fullname' too long."); throw new OAuthException("Full name '$fullname' too long.");
} }
$homepage = $req->get_parameter('omb_listenee_homepage'); $homepage = $req->get_parameter('omb_listenee_homepage');
if ($homepage && (!common_valid_http_url($homepage) || strlen($homepage) > 255)) { if ($homepage && (!common_valid_http_url($homepage) || mb_strlen($homepage) > 255)) {
throw new OAuthException("Invalid homepage '$homepage'"); throw new OAuthException("Invalid homepage '$homepage'");
} }
$bio = $req->get_parameter('omb_listenee_bio'); $bio = $req->get_parameter('omb_listenee_bio');
if ($bio && strlen($bio) > 140) { if ($bio && mb_strlen($bio) > 140) {
throw new OAuthException("Bio too long '$bio'"); throw new OAuthException("Bio too long '$bio'");
} }
$location = $req->get_parameter('omb_listenee_location'); $location = $req->get_parameter('omb_listenee_location');
if ($location && strlen($location) > 255) { if ($location && mb_strlen($location) > 255) {
throw new OAuthException("Location too long '$location'"); throw new OAuthException("Location too long '$location'");
} }
$avatar = $req->get_parameter('omb_listenee_avatar'); $avatar = $req->get_parameter('omb_listenee_avatar');

View File

@ -246,7 +246,7 @@ function mail_subscribe_notify_profile($listenee, $other)
"\n".'Faithfully yours,'."\n".'%7$s.'."\n\n". "\n".'Faithfully yours,'."\n".'%7$s.'."\n\n".
"----\n". "----\n".
"Change your email address or ". "Change your email address or ".
"notification options at ".'%8$s\n'), "notification options at ".'%8$s' ."\n"),
$long_name, $long_name,
common_config('site', 'name'), common_config('site', 'name'),
$other->profileurl, $other->profileurl,

View File

@ -478,7 +478,7 @@ function common_linkify($url) {
} }
else $title = ''; else $title = '';
return "<a href=\"$url\" $title class=\"extlink\">$display</a>"; return "<a href=\"$url\" $title rel=\"external\">$display</a>";
} }
function common_longurl($short_url) function common_longurl($short_url)

View File

@ -34,22 +34,19 @@ require_once INSTALLDIR . '/lib/facebookutil.php';
$last_updated_file = INSTALLDIR . '/scripts/facebook_last_updated'; $last_updated_file = INSTALLDIR . '/scripts/facebook_last_updated';
// Lock file name // Lock file name
$tmp_file = INSTALLDIR . '/scripts/update_facebook.lock'; $lock_file = INSTALLDIR . '/scripts/update_facebook.lock';
// Make sure only one copy of the script is running at a time // Make sure only one copy of the script is running at a time
if (!($tmp_file = @fopen($tmp_file, "w"))) $lock_file = @fopen($lock_file, "w+");
{ if (!flock( $lock_file, LOCK_EX | LOCK_NB, &$wouldblock) || $wouldblock) {
die("Can't open lock file. Script already running?"); die("Can't open lock file. Script already running?\n");
} }
$facebook = getFacebook(); $facebook = getFacebook();
$current_time = time(); $current_time = time();
$since = getLastUpdated(); $since = getLastUpdated();
updateLastUpdated($current_time);
$notice = getFacebookNotices($since); $notice = getFacebookNotices($since);
$cnt = 0; $cnt = 0;
while($notice->fetch()) { while($notice->fetch()) {
@ -73,9 +70,18 @@ while($notice->fetch()) {
// Avoid a Loop // Avoid a Loop
if ($notice->source != 'Facebook') { if ($notice->source != 'Facebook') {
updateStatus($fbuid, $content);
try {
$facebook->api_client->users_setStatus($content,
$fbuid, false, true);
updateProfileBox($facebook, $flink, $notice); updateProfileBox($facebook, $flink, $notice);
$cnt++; $cnt++;
} catch(FacebookRestClientException $e) {
print "Couldn't sent notice $notice->id!\n";
print $e->getMessage();
// Remove flink?
}
} }
} }
} }
@ -83,16 +89,11 @@ while($notice->fetch()) {
if ($cnt > 0) { if ($cnt > 0) {
print date('r', $current_time) . print date('r', $current_time) .
": Found $cnt new notices to send to Facebook since last run at " . ": Found $cnt new notices for Facebook since last run at " .
date('Y-m-d H:i:s', $since) . "\n"; date('r', $since) . "\n";
} }
#Save the last updated time. It needs to do this even if there were no fclose($lock_file);
#changes made, otherwise it will never create it and thus never send
#any updates at all.
updateLastUpdated($current_time);
exit(0); exit(0);
@ -111,37 +112,30 @@ function userCanUpdate($fbuid) {
return $result; return $result;
} }
function updateStatus($fbuid, $content) {
global $facebook;
try {
$result = $facebook->api_client->users_setStatus($content, $fbuid, false, true);
} catch(FacebookRestClientException $e){
print_r($e);
}
}
function getLastUpdated(){ function getLastUpdated(){
global $last_updated_file, $current_time; global $last_updated_file, $current_time;
$last = $current_time;
$file = fopen($last_updated_file, 'r'); if (file_exists($last_updated_file) &&
($file = fopen($last_updated_file, 'r'))) {
if ($file) {
$last = fgets($file); $last = fgets($file);
} else { } else {
print "Unable to read $last_updated_file. Using current time.\n"; print "$last_updated_file doesn't exit. Trying to create it...\n";
return $current_time; $file = fopen($last_updated_file, 'w+') or
die("Can't open $last_updated_file for writing!\n");
print 'Success. Using current time (' . date('r', $last) .
") to look for new notices.\n";
} }
fclose($file); fclose($file);
return $last; return $last;
} }
function updateLastUpdated($time){ function updateLastUpdated($time){
global $last_updated_file; global $last_updated_file;
$file = fopen($last_updated_file, 'w') or die("Can't open $last_updated_file for writing!"); $file = fopen($last_updated_file, 'w') or
die("Can't open $last_updated_file for writing!");
fwrite($file, $time); fwrite($file, $time);
fclose($file); fclose($file);
} }