summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-02-06 15:38:10 -0500
committerEvan Prodromou <evan@controlyourself.ca>2009-02-06 15:38:10 -0500
commit02d7167906b63d490db3b5c3848accc5235b220f (patch)
tree92323dec8d456fdc737ee3a74c48dedf4cb92bcd /lib
parentd260d841ebae71acf7bf726f52acaa6391ce1824 (diff)
parent60f737dc1eb2f126bae28ce095bc2d17a22bd7d9 (diff)
Merge branch '0.7.x' into 0.8.x
Diffstat (limited to 'lib')
-rw-r--r--lib/action.php20
-rw-r--r--lib/common.php3
-rw-r--r--lib/error.php2
-rw-r--r--lib/facebookaction.php171
-rw-r--r--lib/htmloutputter.php4
-rw-r--r--lib/imagefile.php159
-rw-r--r--lib/jabber.php2
-rw-r--r--lib/mailbox.php6
-rw-r--r--lib/noticelist.php17
-rw-r--r--lib/noticesection.php2
-rw-r--r--lib/personal.php1
-rw-r--r--lib/popularnoticesection.php2
-rw-r--r--lib/profilelist.php2
-rw-r--r--lib/profileminilist.php2
-rw-r--r--lib/profilesection.php2
-rw-r--r--lib/rssaction.php4
-rw-r--r--lib/settingsaction.php7
-rw-r--r--lib/twitterapi.php2
-rw-r--r--lib/util.php167
19 files changed, 399 insertions, 176 deletions
diff --git a/lib/action.php b/lib/action.php
index 587d2ab13..c4172ada1 100644
--- a/lib/action.php
+++ b/lib/action.php
@@ -73,7 +73,6 @@ class Action extends HTMLOutputter // lawsuit
parent::__construct($output, $indent);
}
-
/**
* For initializing members of the class.
*
@@ -162,15 +161,15 @@ class Action extends HTMLOutputter // lawsuit
'media' => 'screen, projection, tv'));
$this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
'href="'.theme_path('css/ie.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
- $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
- 'href="'.theme_path('css/ie.css', null).'?version='.LACONICA_VERSION.'" /><![endif]');
foreach (array(6,7) as $ver) {
- if (file_exists(theme_file('ie'.$ver.'.css'))) {
+ if (file_exists(theme_file('css/ie'.$ver.'.css', 'base'))) {
// Yes, IE people should be put in jail.
$this->comment('[if lte IE '.$ver.']><link rel="stylesheet" type="text/css" '.
'href="'.theme_path('css/ie'.$ver.'.css', 'base').'?version='.LACONICA_VERSION.'" /><![endif]');
}
}
+ $this->comment('[if IE]><link rel="stylesheet" type="text/css" '.
+ 'href="'.theme_path('css/ie.css', null).'?version='.LACONICA_VERSION.'" /><![endif]');
}
/**
@@ -246,7 +245,6 @@ class Action extends HTMLOutputter // lawsuit
// does nothing by default
}
-
/**
* Show body.
*
@@ -257,7 +255,7 @@ class Action extends HTMLOutputter // lawsuit
function showBody()
{
$this->elementStart('body', array('id' => $this->trimmed('action')));
- $this->elementStart('div', 'wrap');
+ $this->elementStart('div', array('id' => 'wrap'));
$this->showHeader();
$this->showCore();
$this->showFooter();
@@ -354,7 +352,7 @@ class Action extends HTMLOutputter // lawsuit
$this->elementEnd('dd');
$this->elementEnd('dl');
}
-
+
/**
* Show site notice.
*
@@ -368,7 +366,9 @@ class Action extends HTMLOutputter // lawsuit
$this->elementStart('dl', array('id' => 'site_notice',
'class' => 'system_notice'));
$this->element('dt', null, _('Site notice'));
- $this->element('dd', null, $text);
+ $this->elementStart('dd', null);
+ $this->raw($text);
+ $this->elementEnd('dd');
$this->elementEnd('dl');
}
}
@@ -385,7 +385,7 @@ class Action extends HTMLOutputter // lawsuit
$notice_form = new NoticeForm($this);
$notice_form->show();
}
-
+
/**
* Show anonymous message.
*
@@ -761,7 +761,7 @@ class Action extends HTMLOutputter // lawsuit
/**
* Boolean understands english (yes, no, true, false)
*
- * @param string $key query key we're interested in
+ * @param string $key query key we're interested in
* @param string $def default value
*
* @return boolean interprets yes/no strings as boolean
diff --git a/lib/common.php b/lib/common.php
index 825ba0ff7..5b4e3c40c 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -19,12 +19,11 @@
if (!defined('LACONICA')) { exit(1); }
-define('LACONICA_VERSION', '0.7.0');
+define('LACONICA_VERSION', '0.7.1');
define('AVATAR_PROFILE_SIZE', 96);
define('AVATAR_STREAM_SIZE', 48);
define('AVATAR_MINI_SIZE', 24);
-define('MAX_AVATAR_SIZE', 256 * 1024);
define('NOTICES_PER_PAGE', 20);
define('PROFILES_PER_PAGE', 20);
diff --git a/lib/error.php b/lib/error.php
index 03065bc70..526d9f81b 100644
--- a/lib/error.php
+++ b/lib/error.php
@@ -111,7 +111,7 @@ class ErrorAction extends Action
function showBody()
{
$this->elementStart('body', array('id' => 'error'));
- $this->elementStart('div', 'wrap');
+ $this->elementStart('div', array('id' => 'wrap'));
$this->showHeader();
$this->showCore();
$this->showFooter();
diff --git a/lib/facebookaction.php b/lib/facebookaction.php
index bfba702e6..043a078cd 100644
--- a/lib/facebookaction.php
+++ b/lib/facebookaction.php
@@ -129,7 +129,7 @@ class FacebookAction extends Action
* Start an Facebook ready HTML document
*
* For Facebook we don't want to actually output any headers,
- * DTD info, etc.
+ * DTD info, etc. Just Stylesheet and JavaScript links.
*
* If $type isn't specified, will attempt to do content negotiation.
*
@@ -140,6 +140,9 @@ class FacebookAction extends Action
function startHTML($type=null)
{
+ $this->showStylesheets();
+ $this->showScripts();
+
$this->elementStart('div', array('class' => 'facebook-page'));
}
@@ -168,7 +171,7 @@ class FacebookAction extends Action
function showBody()
{
- $this->elementStart('div', 'wrap');
+ $this->elementStart('div', array('id' => 'wrap'));
$this->showHeader();
$this->showCore();
$this->showFooter();
@@ -181,8 +184,6 @@ class FacebookAction extends Action
function showHead($error, $success)
{
- $this->showStylesheets();
- $this->showScripts();
if ($error) {
$this->element("h1", null, $error);
@@ -204,7 +205,6 @@ class FacebookAction extends Action
// Make this into a widget later
function showLocalNav()
{
-
$this->elementStart('ul', array('class' => 'nav'));
$this->elementStart('li', array('class' =>
@@ -229,18 +229,7 @@ class FacebookAction extends Action
$this->elementEnd('li');
$this->elementEnd('ul');
-
}
-
- /**
- * Show primary navigation.
- *
- * @return nothing
- */
- function showPrimaryNav()
- {
- // we don't want to show anything for this
- }
/**
* Show header of the page.
@@ -254,7 +243,6 @@ class FacebookAction extends Action
$this->elementStart('div', array('id' => 'header'));
$this->showLogo();
$this->showNoticeForm();
- $this->showPrimaryNav();
$this->elementEnd('div');
}
@@ -282,7 +270,6 @@ class FacebookAction extends Action
$loginmsg_part1 = _('To use the %s Facebook Application you need to login ' .
'with your username and password. Don\'t have a username yet? ');
-
$loginmsg_part2 = _(' a new account.');
$this->elementStart('dd');
@@ -291,18 +278,18 @@ class FacebookAction extends Action
$this->element('a',
array('href' => common_local_url('register')), _('Register'));
$this->text($loginmsg_part2);
+ $this->elementEnd('p');
$this->elementEnd('dd');
+
$this->elementEnd('dl');
-
$this->elementEnd('div');
-
}
function showLoginForm($msg = null)
{
- $this->elementStart('div', array('class' => 'content'));
+ $this->elementStart('div', array('id' => 'content'));
$this->element('h1', null, _('Login'));
if ($msg) {
@@ -330,6 +317,7 @@ class FacebookAction extends Action
$this->elementEnd('ul');
$this->submit('submit', _('Login'));
+ $this->elementEnd('fieldset');
$this->elementEnd('form');
$this->elementStart('p');
@@ -338,6 +326,7 @@ class FacebookAction extends Action
$this->elementEnd('p');
$this->elementEnd('div');
+ $this->elementEnd('div');
}
@@ -347,42 +336,70 @@ class FacebookAction extends Action
// Need to include inline CSS for styling the Profile box
+ $app_props = $this->facebook->api_client->Admin_getAppProperties(array('icon_url'));
+ $icon_url = $app_props['icon_url'];
+
$style = '<style>
+ .entry-title *,
+ .entry-content * {
+ font-size:14px;
+ font-family:"Lucida Sans Unicode", "Lucida Grande", sans-serif;
+ }
+ .entry-title a,
+ .entry-content a {
+ color:#002E6E;
+ }
+
.entry-title .vcard .photo {
float:left;
display:inline;
+ margin-right:11px;
+ margin-bottom:11px
}
- .entry-title .vcard .nickname {
- margin-left:5px;
- }
-
+ .entry-title {
+ margin-bottom:11px;
+ }
.entry-title p.entry-content {
display:inline;
- margin-left:5px;
+ margin-left:5px;
}
+ div.entry-content {
+ clear:both;
+ }
div.entry-content dl,
div.entry-content dt,
div.entry-content dd {
display:inline;
+ text-transform:lowercase;
}
- div.entry-content dt,
- div.entry-content dd {
- display:inline;
- margin-left:5px;
+ div.entry-content dd,
+ div.entry-content .device dt {
+ margin-left:0;
+ margin-right:5px;
}
- div.entry-content dl.timestamp dt {
+ div.entry-content dl.timestamp dt,
+ div.entry-content dl.response dt {
display:none;
}
div.entry-content dd a {
display:inline-block;
}
+
+ #facebook_laconica_app {
+ text-indent:-9999px;
+ height:16px;
+ width:16px;
+ display:block;
+ background:url('.$icon_url.') no-repeat 0 0;
+ float:right;
+ }
</style>';
$this->xw->openMemory();
- $item = new FacebookNoticeListItem($notice, $this);
+ $item = new FacebookProfileBoxNotice($notice, $this);
$item->show();
$fbml = "<fb:wide>$style " . $this->xw->outputMemory(false) . "</fb:wide>";
@@ -465,8 +482,6 @@ class FacebookAction extends Action
$content_shortened = common_shorten_links($content);
if (mb_strlen($content_shortened) > 140) {
- common_debug("Content = '$content_shortened'", __FILE__);
- common_debug("mb_strlen(\$content) = " . mb_strlen($content_shortened), __FILE__);
$this->showPage(_('That\'s too long. Max notice size is 140 chars.'));
return;
}
@@ -539,6 +554,18 @@ class FacebookNoticeForm extends NoticeForm
class FacebookNoticeList extends NoticeList
{
+
+ /**
+ * constructor
+ *
+ * @param Notice $notice stream of notices from DB_DataObject
+ */
+
+ function __construct($notice, $out=null)
+ {
+ parent::__construct($notice, $out);
+ }
+
/**
* show the list of notices
*
@@ -593,6 +620,20 @@ class FacebookNoticeList extends NoticeList
class FacebookNoticeListItem extends NoticeListItem
{
+
+ /**
+ * constructor
+ *
+ * Also initializes the profile attribute.
+ *
+ * @param Notice $notice The notice we'll display
+ */
+
+ function __construct($notice, $out=null)
+ {
+ parent::__construct($notice, $out);
+ }
+
/**
* recipe function for displaying a single notice in the Facebook App.
*
@@ -645,3 +686,65 @@ class FacebookNoticeListItem extends NoticeListItem
}
}
+
+
+class FacebookProfileBoxNotice extends FacebookNoticeListItem
+{
+
+ /**
+ * constructor
+ *
+ * Also initializes the profile attribute.
+ *
+ * @param Notice $notice The notice we'll display
+ */
+
+ function __construct($notice, $out=null)
+ {
+ parent::__construct($notice, $out);
+ }
+
+ /**
+ * Recipe function for displaying a single notice in the
+ * Facebook App's Profile
+ *
+ * @return void
+ */
+
+ function show()
+ {
+
+ $this->out->elementStart('div', 'entry-title');
+ $this->showAuthor();
+ $this->showContent();
+ $this->out->elementEnd('div');
+
+ $this->out->elementStart('div', 'entry-content');
+
+ $this->showNoticeLink();
+ $this->showNoticeSource();
+ $this->showReplyTo();
+ $this->out->elementEnd('div');
+
+ $this->showAppLink();
+
+ }
+
+ function showAppLink()
+ {
+
+ $this->facebook = getFacebook();
+
+ $app_props = $this->facebook->api_client->Admin_getAppProperties(
+ array('canvas_name', 'application_name'));
+
+ $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name'];
+ $this->app_name = $app_props['application_name'];
+
+ $this->out->elementStart('a', array('id' => 'facebook_laconica_app',
+ 'href' => $this->app_uri));
+ $this->out->text($this->app_name);
+ $this->out->elementEnd('a');
+ }
+
+}
diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php
index f9245414f..7780b1c19 100644
--- a/lib/htmloutputter.php
+++ b/lib/htmloutputter.php
@@ -172,7 +172,7 @@ class HTMLOutputter extends XMLOutputter
'type' => 'text',
'id' => $id);
if ($value) {
- $attrs['value'] = htmlspecialchars($value);
+ $attrs['value'] = $value;
}
$this->element('input', $attrs);
if ($instructions) {
@@ -206,7 +206,7 @@ class HTMLOutputter extends XMLOutputter
'class' => 'checkbox',
'id' => $id);
if ($value) {
- $attrs['value'] = htmlspecialchars($value);
+ $attrs['value'] = $value;
}
if ($checked) {
$attrs['checked'] = 'checked';
diff --git a/lib/imagefile.php b/lib/imagefile.php
index 7f1db892c..db344db8f 100644
--- a/lib/imagefile.php
+++ b/lib/imagefile.php
@@ -47,18 +47,22 @@ if (!defined('LACONICA')) {
class ImageFile
{
- var $filename = null;
- var $barename = null;
- var $type = null;
- var $height = null;
- var $width = null;
+ var $id;
+ var $filepath;
+ var $barename;
+ var $type;
+ var $height;
+ var $width;
- function __construct($filename=null, $type=null, $width=null, $height=null)
+ function __construct($id=null, $filepath=null, $type=null, $width=null, $height=null)
{
- $this->filename = $filename;
- $this->type = $type;
- $this->width = $type;
- $this->height = $type;
+ $this->id = $id;
+ $this->filepath = $filepath;
+
+ $info = @getimagesize($this->filepath);
+ $this->type = ($info) ? $info[2]:$type;
+ $this->width = ($info) ? $info[0]:$width;
+ $this->height = ($info) ? $info[1]:$height;
}
static function fromUpload($param='upload')
@@ -68,7 +72,7 @@ class ImageFile
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
- throw new Exception(_('That file is too big.'));
+ throw new Exception(sprintf(_('That file is too big. The maximum file size is %d.'), $this->maxFileSize()));
return;
case UPLOAD_ERR_PARTIAL:
@unlink($_FILES[$param]['tmp_name']);
@@ -79,35 +83,140 @@ class ImageFile
return;
}
- $imagefile = new ImageFile($_FILES[$param]['tmp_name']);
- $info = @getimagesize($imagefile->filename);
+ $info = @getimagesize($_FILES[$param]['tmp_name']);
if (!$info) {
- @unlink($imagefile->filename);
+ @unlink($_FILES[$param]['tmp_name']);
throw new Exception(_('Not an image or corrupt file.'));
return;
}
- $imagefile->width = $info[0];
- $imagefile->height = $info[1];
+ if ($info[2] !== IMAGETYPE_GIF &&
+ $info[2] !== IMAGETYPE_JPEG &&
+ $info[2] !== IMAGETYPE_PNG) {
- switch ($info[2]) {
- case IMAGETYPE_GIF:
- case IMAGETYPE_JPEG:
- case IMAGETYPE_PNG:
- $imagefile->type = $info[2];
- break;
- default:
- @unlink($imagefile->filename);
+ @unlink($_FILES[$param]['tmp_name']);
throw new Exception(_('Unsupported image file format.'));
return;
}
- return $imagefile;
+ return new ImageFile(null, $_FILES[$param]['tmp_name']);
+ }
+
+ function resize($size, $x = 0, $y = 0, $w = null, $h = null)
+ {
+ $w = ($w === null) ? $this->width:$w;
+ $h = ($h === null) ? $this->height:$h;
+
+ if (!file_exists($this->filepath)) {
+ throw new Exception(_('Lost our file.'));
+ return;
+ }
+
+ switch ($this->type) {
+ case IMAGETYPE_GIF:
+ $image_src = imagecreatefromgif($this->filepath);
+ break;
+ case IMAGETYPE_JPEG:
+ $image_src = imagecreatefromjpeg($this->filepath);
+ break;
+ case IMAGETYPE_PNG:
+ $image_src = imagecreatefrompng($this->filepath);
+ break;
+ default:
+ throw new Exception(_('Unknown file type'));
+ return;
+ }
+
+ $image_dest = imagecreatetruecolor($size, $size);
+
+ if ($this->type == IMAGETYPE_GIF || $this->type == IMAGETYPE_PNG) {
+
+ $transparent_idx = imagecolortransparent($image_src);
+
+ if ($transparent_idx >= 0) {
+
+ $transparent_color = imagecolorsforindex($image_src, $transparent_idx);
+ $transparent_idx = imagecolorallocate($image_dest, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
+ imagefill($image_dest, 0, 0, $transparent_idx);
+ imagecolortransparent($image_dest, $transparent_idx);
+
+ } elseif ($this->type == IMAGETYPE_PNG) {
+
+ imagealphablending($image_dest, false);
+ $transparent = imagecolorallocatealpha($image_dest, 0, 0, 0, 127);
+ imagefill($image_dest, 0, 0, $transparent);
+ imagesavealpha($image_dest, true);
+
+ }
+ }
+
+ imagecopyresampled($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $w, $h);
+
+ $outname = Avatar::filename($this->id,
+ image_type_to_extension($this->type),
+ $size,
+ common_timestamp());
+
+ $outpath = Avatar::path($outname);
+
+ switch ($this->type) {
+ case IMAGETYPE_GIF:
+ imagegif($image_dest, $outpath);
+ break;
+ case IMAGETYPE_JPEG:
+ imagejpeg($image_dest, $outpath);
+ break;
+ case IMAGETYPE_PNG:
+ imagepng($image_dest, $outpath);
+ break;
+ default:
+ throw new Exception(_('Unknown file type'));
+ return;
+ }
+
+ return $outname;
}
function unlink()
{
@unlink($this->filename);
}
+
+ static function maxFileSize()
+ {
+ $value = ImageFile::maxFileSizeInt();
+
+ if ($value > 1024 * 1024) {
+ return ($value/(1024*1024)).'Mb';
+ } else if ($value > 1024) {
+ return ($value/(1024)).'kB';
+ } else {
+ return $value;
+ }
+ }
+
+ static function maxFileSizeInt()
+ {
+ return min(ImageFile::strToInt(ini_get('post_max_size')),
+ ImageFile::strToInt(ini_get('upload_max_filesize')),
+ ImageFile::strToInt(ini_get('memory_limit')));
+ }
+
+ static function strToInt($str)
+ {
+ $unit = substr($str, -1);
+ $num = substr($str, 0, -1);
+
+ switch(strtoupper($unit)){
+ case 'G':
+ $num *= 1024;
+ case 'M':
+ $num *= 1024;
+ case 'K':
+ $num *= 1024;
+ }
+
+ return $num;
+ }
} \ No newline at end of file
diff --git a/lib/jabber.php b/lib/jabber.php
index f1be57768..f41d984d6 100644
--- a/lib/jabber.php
+++ b/lib/jabber.php
@@ -178,7 +178,7 @@ function jabber_format_entry($profile, $notice)
$entry .= "<link href='" . htmlspecialchars($profile->profileurl) . "'/>\n";
$entry .= "<link rel='self' type='application/rss+xml' href='" . $self_url . "'/>\n";
$entry .= "<author><name>" . $profile->nickname . "</name></author>\n";
- $entry .= "<icon>" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "</icon>\n";
+ $entry .= "<icon>" . $profile->avatarUrl(AVATAR_PROFILE_SIZE) . "</icon>\n";
$entry .= "</source>\n";
$entry .= "<title>" . htmlspecialchars($msg) . "</title>\n";
$entry .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
diff --git a/lib/mailbox.php b/lib/mailbox.php
index 8d5d44e49..d77234549 100644
--- a/lib/mailbox.php
+++ b/lib/mailbox.php
@@ -63,6 +63,8 @@ class MailboxAction extends PersonalAction
$this->page = 1;
}
+ common_set_returnto($this->selfUrl());
+
return true;
}
@@ -181,8 +183,8 @@ class MailboxAction extends PersonalAction
'class' => 'url'));
$avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
$this->element('img', array('src' => ($avatar) ?
- common_avatar_display_url($avatar) :
- common_default_avatar(AVATAR_STREAM_SIZE),
+ $avatar->displayUrl() :
+ Avatar::defaultImage(AVATAR_STREAM_SIZE),
'class' => 'photo avatar',
'width' => AVATAR_STREAM_SIZE,
'height' => AVATAR_STREAM_SIZE,
diff --git a/lib/noticelist.php b/lib/noticelist.php
index 7c88c33cc..9fc0126b3 100644
--- a/lib/noticelist.php
+++ b/lib/noticelist.php
@@ -203,11 +203,14 @@ class NoticeListItem extends Widget
function showNoticeOptions()
{
- $this->out->elementStart('div', 'notice-options');
- $this->showFaveForm();
- $this->showReplyLink();
- $this->showDeleteLink();
- $this->out->elementEnd('div');
+ $user = common_current_user();
+ if ($user) {
+ $this->out->elementStart('div', 'notice-options');
+ $this->showFaveForm();
+ $this->showReplyLink();
+ $this->showDeleteLink();
+ $this->out->elementEnd('div');
+ }
}
/**
@@ -282,8 +285,8 @@ class NoticeListItem extends Widget
$avatar = $this->profile->getAvatar($avatar_size);
$this->out->element('img', array('src' => ($avatar) ?
- common_avatar_display_url($avatar) :
- common_default_avatar($avatar_size),
+ $avatar->displayUrl() :
+ Avatar::defaultImage($avatar_size),
'class' => 'avatar photo',
'width' => $avatar_size,
'height' => $avatar_size,
diff --git a/lib/noticesection.php b/lib/noticesection.php
index aa8e03229..97b517529 100644
--- a/lib/noticesection.php
+++ b/lib/noticesection.php
@@ -82,7 +82,7 @@ class NoticeSection extends Section
$profile->nickname,
'href' => $profile->profileurl,
'class' => 'url'));
- $this->out->element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
+ $this->out->element('img', array('src' => (($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_MINI_SIZE)),
'width' => AVATAR_MINI_SIZE,
'height' => AVATAR_MINI_SIZE,
'class' => 'avatar photo',
diff --git a/lib/personal.php b/lib/personal.php
index 900df0257..e46350c63 100644
--- a/lib/personal.php
+++ b/lib/personal.php
@@ -55,7 +55,6 @@ class PersonalAction extends Action
function handle($args)
{
parent::handle($args);
- common_set_returnto($this->selfUrl());
}
}
diff --git a/lib/popularnoticesection.php b/lib/popularnoticesection.php
index 89daaa563..5734d8001 100644
--- a/lib/popularnoticesection.php
+++ b/lib/popularnoticesection.php
@@ -31,7 +31,7 @@ if (!defined('LACONICA')) {
exit(1);
}
-define('NOTICES_PER_SECTION', 6);
+define('NOTICES_PER_SECTION', 5);
/**
* Base class for sections showing lists of notices
diff --git a/lib/profilelist.php b/lib/profilelist.php
index 6e14c0b69..4d924b039 100644
--- a/lib/profilelist.php
+++ b/lib/profilelist.php
@@ -97,7 +97,7 @@ class ProfileList extends Widget
$avatar = $this->profile->getAvatar(AVATAR_STREAM_SIZE);
$this->out->elementStart('a', array('href' => $this->profile->profileurl,
'class' => 'url'));
- $this->out->element('img', array('src' => ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE),
+ $this->out->element('img', array('src' => ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE),
'class' => 'photo avatar',
'width' => AVATAR_STREAM_SIZE,
'height' => AVATAR_STREAM_SIZE,
diff --git a/lib/profileminilist.php b/lib/profileminilist.php
index 81cd7aed5..0d466bba8 100644
--- a/lib/profileminilist.php
+++ b/lib/profileminilist.php
@@ -74,7 +74,7 @@ class ProfileMiniList extends ProfileList
'rel' => 'contact member',
'class' => 'url'));
$avatar = $this->profile->getAvatar(AVATAR_MINI_SIZE);
- $this->out->element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
+ $this->out->element('img', array('src' => (($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_MINI_SIZE)),
'width' => AVATAR_MINI_SIZE,
'height' => AVATAR_MINI_SIZE,
'class' => 'avatar photo',
diff --git a/lib/profilesection.php b/lib/profilesection.php
index 3642ae164..8ed290e03 100644
--- a/lib/profilesection.php
+++ b/lib/profilesection.php
@@ -86,7 +86,7 @@ class ProfileSection extends Section
'rel' => 'contact member',
'class' => 'url'));
$avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
- $this->out->element('img', array('src' => (($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_MINI_SIZE)),
+ $this->out->element('img', array('src' => (($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_MINI_SIZE)),
'width' => AVATAR_MINI_SIZE,
'height' => AVATAR_MINI_SIZE,
'class' => 'avatar photo',
diff --git a/lib/rssaction.php b/lib/rssaction.php
index 2bd7f1f19..131e8ac65 100644
--- a/lib/rssaction.php
+++ b/lib/rssaction.php
@@ -199,7 +199,7 @@ class Rss10Action extends Action
$this->element('dc:date', null, common_date_w3dtf($notice->created));
$this->element('dc:creator', null, ($profile->fullname) ? $profile->fullname : $profile->nickname);
$this->element('sioc:has_creator', array('rdf:resource' => $creator_uri));
- $this->element('laconica:postIcon', array('rdf:resource' => common_profile_avatar_url($profile)));
+ $this->element('laconica:postIcon', array('rdf:resource' => $profile->avatarUrl()));
$this->element('cc:licence', array('rdf:resource' => common_config('license', 'url')));
$this->elementEnd('item');
$this->creators[$creator_uri] = $profile;
@@ -216,7 +216,7 @@ class Rss10Action extends Action
$this->element('foaf:name', null, $profile->fullname);
}
$this->element('sioc:id', null, $id);
- $avatar = common_profile_avatar_url($profile);
+ $avatar = $profile->avatarUrl();
$this->element('sioc:avatar', array('rdf:resource' => $avatar));
$this->elementEnd('sioc:User');
}
diff --git a/lib/settingsaction.php b/lib/settingsaction.php
index dfe1f114b..53c807c6f 100644
--- a/lib/settingsaction.php
+++ b/lib/settingsaction.php
@@ -76,7 +76,12 @@ class SettingsAction extends Action
// change important settings or see private info, and
// _all_ our settings are important
common_set_returnto($this->selfUrl());
- common_redirect(common_local_url('login'));
+ $user = common_current_user();
+ if ($user->hasOpenID()) {
+ common_redirect(common_local_url('openidlogin'));
+ } else {
+ common_redirect(common_local_url('login'));
+ }
} else if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->handlePost();
} else {
diff --git a/lib/twitterapi.php b/lib/twitterapi.php
index da8b8b1e5..a4d183fcd 100644
--- a/lib/twitterapi.php
+++ b/lib/twitterapi.php
@@ -43,7 +43,7 @@ class TwitterapiAction extends Action
$avatar = $profile->getAvatar(AVATAR_STREAM_SIZE);
- $twitter_user['profile_image_url'] = ($avatar) ? common_avatar_display_url($avatar) : common_default_avatar(AVATAR_STREAM_SIZE);
+ $twitter_user['profile_image_url'] = ($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_STREAM_SIZE);
$twitter_user['protected'] = 'false'; # not supported by Laconica yet
$twitter_user['url'] = ($profile->homepage) ? $profile->homepage : null;
diff --git a/lib/util.php b/lib/util.php
index 07e124811..7ce4e229e 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -386,46 +386,99 @@ function common_render_text($text)
$r = htmlspecialchars($text);
$r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r);
- $r = preg_replace_callback('@(ftp|http|https|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://[^\]>\s]+@', 'common_render_uri_thingy', $r);
- $r = preg_replace_callback('@(mailto|aim|tel):[^\]>\s]+@', 'common_render_uri_thingy', $r); // Pseudo-protocols don't require '//' after ':'.
- $r = preg_replace('/(^|\s+)#([A-Za-z0-9_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r);
+ $r = common_replace_urls_callback($r, 'common_linkify');
+ $r = preg_replace('/(^|\(|\[|\s+)#([A-Za-z0-9_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r);
// XXX: machine tags
return $r;
}
-function common_render_uri_thingy($matches)
-{
- $uri = $matches[0];
- $trailer = '';
+function common_replace_urls_callback($text, $callback) {
+ // Start off with a regex
+ $regex = '#
+ (?:
+ (?:
+ (?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://
+ |
+ (?:mailto|aim|tel):
+ )
+ [^.\s]+\.[^\s]+
+ |
+ (?:[^.\s/:]+\.)+
+ (?:museum|travel|[a-z]{2,4})
+ (?:[:/][^\s]*)?
+ )
+ #ix';
+ preg_match_all($regex, $text, $matches);
+
+ // Then clean up what the regex left behind
+ $offset = 0;
+ foreach($matches[0] as $url) {
+ $url = htmlspecialchars_decode($url);
+
+ // Make sure we didn't pick up an email address
+ if (preg_match('#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$#i', $url)) continue;
+
+ // Remove trailing punctuation
+ $url = rtrim($url, '.?!,;:\'"`');
+
+ // Remove surrounding parens and the like
+ preg_match('/[)\]>]+$/', $url, $trailing);
+ if (isset($trailing[0])) {
+ preg_match_all('/[(\[<]/', $url, $opened);
+ preg_match_all('/[)\]>]/', $url, $closed);
+ $unopened = count($closed[0]) - count($opened[0]);
+
+ // Make sure not to take off more closing parens than there are at the end
+ $unopened = ($unopened > mb_strlen($trailing[0])) ? mb_strlen($trailing[0]):$unopened;
+
+ $url = ($unopened > 0) ? mb_substr($url, 0, $unopened * -1):$url;
+ }
- // Some heuristics for extracting URIs from surrounding punctuation
- // Strip from trailing text...
- if (preg_match('/^(.*)([,.:"\']+)$/', $uri, $matches)) {
- $uri = $matches[1];
- $trailer = $matches[2];
- }
+ // Remove trailing punctuation again (in case there were some inside parens)
+ $url = rtrim($url, '.?!,;:\'"`');
- $pairs = array(
- ']' => '[', // technically disallowed in URIs, but used in Java docs
- ')' => '(', // far too frequent in Wikipedia and MSDN
- );
- $final = substr($uri, -1, 1);
- if (isset($pairs[$final])) {
- $openers = substr_count($uri, $pairs[$final]);
- $closers = substr_count($uri, $final);
- if ($closers > $openers) {
- // Assume the paren was opened outside the URI
- $uri = substr($uri, 0, -1);
- $trailer = $final . $trailer;
+ // Make sure we didn't capture part of the next sentence
+ preg_match('#((?:[^.\s/]+\.)+)(museum|travel|[a-z]{2,4})#i', $url, $url_parts);
+
+ // Were the parts capitalized any?
+ $last_part = (mb_strtolower($url_parts[2]) !== $url_parts[2]) ? true:false;
+ $prev_part = (mb_strtolower($url_parts[1]) !== $url_parts[1]) ? true:false;
+
+ // If the first part wasn't cap'd but the last part was, we captured too much
+ if ((!$prev_part && $last_part)) {
+ $url = substr_replace($url, '', mb_strpos($url, '.'.$url_parts[2], 0));
}
+
+ // Capture the new TLD
+ preg_match('#((?:[^.\s/]+\.)+)(museum|travel|[a-z]{2,4})#i', $url, $url_parts);
+
+ $tlds = array('ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'edu', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'info', 'int', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm', 'mn', 'mo', 'mobi', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'museum', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc', 'ne', 'net', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt', 'pw', 'py', 'qa', 're', 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tel', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'travel', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm', 'zw');
+
+ if (!in_array($url_parts[2], $tlds)) continue;
+
+ // Call user specified func
+ $modified_url = $callback($url);
+
+ // Replace it!
+ $start = mb_strpos($text, $url, $offset);
+ $text = mb_substr($text, 0, $start).$modified_url.mb_substr($text, $start + mb_strlen($url), mb_strlen($text));
+ $offset = $start + mb_strlen($modified_url);
}
- if ($longurl = common_longurl($uri)) {
+
+ return $text;
+}
+
+function common_linkify($url) {
+ $display = $url;
+ $url = (!preg_match('#^([a-z]+://|(mailto|aim|tel):)#i', $url)) ? 'http://'.$url:$url;
+
+ if ($longurl = common_longurl($url)) {
$longurl = htmlentities($longurl, ENT_QUOTES, 'UTF-8');
- $title = " title='$longurl'";
+ $title = "title=\"$longurl\"";
}
else $title = '';
- return '<a href="' . $uri . '"' . $title . ' class="extlink">' . $uri . '</a>' . $trailer;
+ return "<a href=\"$url\" $title class=\"extlink\">$display</a>";
}
function common_longurl($short_url)
@@ -449,7 +502,7 @@ function common_shorten_links($text)
static $cache = array();
if (isset($cache[$text])) return $cache[$text];
// \s = not a horizontal whitespace character (since PHP 5.2.4)
- return $cache[$text] = preg_replace('@https?://[^)\]>\s]+@e', "common_shorten_link('\\0')", $text);
+ return $cache[$text] = common_replace_urls_callback($text, 'common_shorten_link');;
}
function common_shorten_link($url, $reverse = false)
@@ -614,48 +667,6 @@ function common_relative_profile($sender, $nickname, $dt=null)
return null;
}
-// where should the avatar go for this user?
-
-function common_avatar_filename($id, $extension, $size=null, $extra=null)
-{
- global $config;
-
- if ($size) {
- return $id . '-' . $size . (($extra) ? ('-' . $extra) : '') . $extension;
- } else {
- return $id . '-original' . (($extra) ? ('-' . $extra) : '') . $extension;
- }
-}
-
-function common_avatar_path($filename)
-{
- global $config;
- return INSTALLDIR . '/avatar/' . $filename;
-}
-
-function common_avatar_url($filename)
-{
- return common_path('avatar/'.$filename);
-}
-
-function common_avatar_display_url($avatar)
-{
- $server = common_config('avatar', 'server');
- if ($server) {
- return 'http://'.$server.'/'.$avatar->filename;
- } else {
- return $avatar->url;
- }
-}
-
-function common_default_avatar($size)
-{
- static $sizenames = array(AVATAR_PROFILE_SIZE => 'profile',
- AVATAR_STREAM_SIZE => 'stream',
- AVATAR_MINI_SIZE => 'mini');
- return theme_path('default-avatar-'.$sizenames[$size].'.png');
-}
-
function common_local_url($action, $args=null, $fragment=null)
{
$url = null;
@@ -697,6 +708,8 @@ function common_fancy_url($action, $args=null)
return common_path("api/statuses/public_timeline.atom");
case 'publicxrds':
return common_path('xrds');
+ case 'tagrss':
+ return common_path('tag/' . $args['tag'] . '/rss');
case 'featuredrss':
return common_path('featuredrss');
case 'favoritedrss':
@@ -898,7 +911,7 @@ function common_fancy_url($action, $args=null)
case 'grouprss':
return common_path('group/'.$args['nickname'].'/rss');
case 'groupmembers':
- return common_path('group/'.$args['nickname'].'/members');
+ return common_path('group/'.$args['nickname'].'/members' . (($args['page']) ? ('?page=' . $args['page']) : ''));
case 'grouplogo':
return common_path('group/'.$args['nickname'].'/logo');
case 'usergroups':
@@ -1470,16 +1483,6 @@ function common_markup_to_html($c)
return Markdown($c);
}
-function common_profile_avatar_url($profile, $size=AVATAR_PROFILE_SIZE)
-{
- $avatar = $profile->getAvatar($size);
- if ($avatar) {
- return common_avatar_display_url($avatar);
- } else {
- return common_default_avatar($size);
- }
-}
-
function common_profile_uri($profile)
{
if (!$profile) {