diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/action.php | 80 | ||||
-rw-r--r-- | lib/apiaction.php | 6 | ||||
-rw-r--r-- | lib/attachmentlist.php | 69 | ||||
-rw-r--r-- | lib/command.php | 14 | ||||
-rw-r--r-- | lib/currentuserdesignaction.php | 35 | ||||
-rw-r--r-- | lib/default.php | 4 | ||||
-rw-r--r-- | lib/designsettings.php | 56 | ||||
-rw-r--r-- | lib/feedlist.php | 1 | ||||
-rw-r--r-- | lib/groupeditform.php | 15 | ||||
-rw-r--r-- | lib/htmloutputter.php | 13 | ||||
-rw-r--r-- | lib/imagefile.php | 116 | ||||
-rw-r--r-- | lib/inlineattachmentlist.php | 108 | ||||
-rw-r--r-- | lib/mail.php | 4 | ||||
-rw-r--r-- | lib/mailhandler.php | 5 | ||||
-rw-r--r-- | lib/mediafile.php | 56 | ||||
-rw-r--r-- | lib/noticelist.php | 17 | ||||
-rw-r--r-- | lib/oembedhelper.php | 318 | ||||
-rw-r--r-- | lib/personalgroupnav.php | 11 | ||||
-rw-r--r-- | lib/ping.php | 75 | ||||
-rw-r--r-- | lib/router.php | 11 | ||||
-rw-r--r-- | lib/searchaction.php | 6 | ||||
-rw-r--r-- | lib/statusnet.php | 6 | ||||
-rw-r--r-- | lib/theme.php | 18 | ||||
-rw-r--r-- | lib/themeuploader.php | 7 | ||||
-rw-r--r-- | lib/uapplugin.php | 9 | ||||
-rw-r--r-- | lib/unblockform.php | 6 | ||||
-rw-r--r-- | lib/util.php | 13 |
27 files changed, 881 insertions, 198 deletions
diff --git a/lib/action.php b/lib/action.php index 01bb0f7e9..0e5d7ae36 100644 --- a/lib/action.php +++ b/lib/action.php @@ -274,15 +274,16 @@ class Action extends HTMLOutputter // lawsuit if (Event::handle('StartShowScripts', array($this))) { if (Event::handle('StartShowJQueryScripts', array($this))) { $this->script('jquery.min.js'); - $this->script('jquery.form.js'); - $this->script('jquery.cookie.js'); - $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.js').'"); }'); + $this->script('jquery.form.min.js'); + $this->script('jquery.cookie.min.js'); + $this->inlineScript('if (typeof window.JSON !== "object") { $.getScript("'.common_path('js/json2.min.js').'"); }'); $this->script('jquery.joverlay.min.js'); Event::handle('EndShowJQueryScripts', array($this)); } if (Event::handle('StartShowStatusNetScripts', array($this)) && Event::handle('StartShowLaconicaScripts', array($this))) { - $this->script('util.js'); + $this->script('util.min.js'); + $this->showScriptMessages(); // Frame-busting code to avoid clickjacking attacks. $this->inlineScript('if (window.top !== window.self) { window.top.location.href = window.self.location.href; }'); Event::handle('EndShowStatusNetScripts', array($this)); @@ -293,6 +294,59 @@ class Action extends HTMLOutputter // lawsuit } /** + * Exports a map of localized text strings to JavaScript code. + * + * Plugins can add to what's exported by hooking the StartScriptMessages or EndScriptMessages + * events and appending to the array. Try to avoid adding strings that won't be used, as + * they'll be added to HTML output. + */ + + function showScriptMessages() + { + $messages = array(); + + if (Event::handle('StartScriptMessages', array($this, &$messages))) { + // Common messages needed for timeline views etc... + + // TRANS: Localized tooltip for '...' expansion button on overlong remote messages. + $messages['showmore_tooltip'] = _m('TOOLTIP', 'Show more'); + + $messages = array_merge($messages, $this->getScriptMessages()); + + Event::handle('EndScriptMessages', array($this, &$messages)); + } + + if (!empty($messages)) { + $this->inlineScript('SN.messages=' . json_encode($messages)); + } + + return $messages; + } + + /** + * If the action will need localizable text strings, export them here like so: + * + * return array('pool_deepend' => _('Deep end'), + * 'pool_shallow' => _('Shallow end')); + * + * The exported map will be available via SN.msg() to JS code: + * + * $('#pool').html('<div class="deepend"></div><div class="shallow"></div>'); + * $('#pool .deepend').text(SN.msg('pool_deepend')); + * $('#pool .shallow').text(SN.msg('pool_shallow')); + * + * Exports a map of localized text strings to JavaScript code. + * + * Plugins can add to what's exported on any action by hooking the StartScriptMessages or + * EndScriptMessages events and appending to the array. Try to avoid adding strings that won't + * be used, as they'll be added to HTML output. + */ + function getScriptMessages() + { + return array(); + } + + /** * Show OpenSearch headers * * @return nothing @@ -824,16 +878,17 @@ class Action extends HTMLOutputter // lawsuit // TRANS: Secondary navigation menu option leading to privacy policy. _('Privacy')); $this->menuItem(common_local_url('doc', array('title' => 'source')), - // TRANS: Secondary navigation menu option. + // TRANS: Secondary navigation menu option. Leads to information about StatusNet and its license. _('Source')); $this->menuItem(common_local_url('version'), // TRANS: Secondary navigation menu option leading to version information on the StatusNet site. _('Version')); $this->menuItem(common_local_url('doc', array('title' => 'contact')), - // TRANS: Secondary navigation menu option leading to contact information on the StatusNet site. + // TRANS: Secondary navigation menu option leading to e-mail contact information on the + // TRANS: StatusNet site, where to report bugs, ... _('Contact')); $this->menuItem(common_local_url('doc', array('title' => 'badge')), - // TRANS: Secondary navigation menu option. + // TRANS: Secondary navigation menu option. Leads to information about embedding a timeline widget. _('Badge')); Event::handle('EndSecondaryNav', array($this)); } @@ -1354,4 +1409,15 @@ class Action extends HTMLOutputter // lawsuit $this->clientError(_('There was a problem with your session token.')); } } + + /** + * Check if the current request is a POST + * + * @return boolean true if POST; otherwise false. + */ + + function isPost() + { + return ($_SERVER['REQUEST_METHOD'] == 'POST'); + } } diff --git a/lib/apiaction.php b/lib/apiaction.php index 4e9dbb310..8a7be3150 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -726,6 +726,12 @@ class ApiAction extends Action $this->endDocument('xml'); } + function showSingleAtomStatus($notice) + { + header('Content-Type: application/atom+xml; charset=utf-8'); + print $notice->asAtomEntry(true, true, true, $this->auth_user); + } + function show_single_json_status($notice) { $this->initDocument('json'); diff --git a/lib/attachmentlist.php b/lib/attachmentlist.php index f6b09fb49..7e536925b 100644 --- a/lib/attachmentlist.php +++ b/lib/attachmentlist.php @@ -79,23 +79,33 @@ class AttachmentList extends Widget $atts = new File; $att = $atts->getAttachments($this->notice->id); if (empty($att)) return 0; + $this->showListStart(); + + foreach ($att as $n=>$attachment) { + $item = $this->newListItem($attachment); + $item->show(); + } + + $this->showListEnd(); + + return count($att); + } + + function showListStart() + { $this->out->elementStart('dl', array('id' =>'attachments', 'class' => 'entry-content')); // TRANS: DT element label in attachment list. $this->out->element('dt', null, _('Attachments')); $this->out->elementStart('dd'); $this->out->elementStart('ol', array('class' => 'attachments')); + } - foreach ($att as $n=>$attachment) { - $item = $this->newListItem($attachment); - $item->show(); - } - + function showListEnd() + { $this->out->elementEnd('dd'); $this->out->elementEnd('ol'); $this->out->elementEnd('dl'); - - return count($att); } /** @@ -187,7 +197,10 @@ class AttachmentListItem extends Widget } function linkAttr() { - return array('class' => 'attachment', 'href' => $this->attachment->url, 'id' => 'attachment-' . $this->attachment->id); + return array('class' => 'attachment', + 'href' => $this->attachment->url, + 'id' => 'attachment-' . $this->attachment->id, + 'title' => $this->title()); } function showLink() { @@ -203,10 +216,32 @@ class AttachmentListItem extends Widget } function showRepresentation() { + $thumb = $this->getThumbInfo(); + if ($thumb) { + $this->out->element('img', array('alt' => '', 'src' => $thumb->url, 'width' => $thumb->width, 'height' => $thumb->height)); + } + } + + /** + * Pull a thumbnail image reference for the given file, and if necessary + * resize it to match currently thumbnail size settings. + * + * @return File_Thumbnail or false/null + */ + function getThumbInfo() + { $thumbnail = File_thumbnail::staticGet('file_id', $this->attachment->id); - if (!empty($thumbnail)) { - $this->out->element('img', array('alt' => '', 'src' => $thumbnail->url, 'width' => $thumbnail->width, 'height' => $thumbnail->height)); + if ($thumbnail) { + $maxWidth = common_config('attachments', 'thumb_width'); + $maxHeight = common_config('attachments', 'thumb_height'); + if ($thumbnail->width > $maxWidth) { + $thumb = clone($thumbnail); + $thumb->width = $maxWidth; + $thumb->height = intval($thumbnail->height * $maxWidth / $thumbnail->width); + return $thumb; + } } + return $thumbnail; } /** @@ -234,6 +269,9 @@ class AttachmentListItem extends Widget } } +/** + * used for one-off attachment action + */ class Attachment extends AttachmentListItem { function showLink() { @@ -417,15 +455,6 @@ class Attachment extends AttachmentListItem function showFallback() { - // If we don't know how to display an attachment inline, we probably - // shouldn't have gotten to this point. - // - // But, here we are... displaying details on a file or remote URL - // either on the main view or in an ajax-loaded lightbox. As a lesser - // of several evils, we'll try redirecting to the actual target via - // client-side JS. - - common_log(LOG_ERR, "Empty or unknown type for file id {$this->attachment->id}; falling back to client-side redirect."); - $this->out->raw('<script>window.location = ' . json_encode($this->attachment->url) . ';</script>'); + // still needed: should show a link? } } diff --git a/lib/command.php b/lib/command.php index 658262a09..ae69f04a1 100644 --- a/lib/command.php +++ b/lib/command.php @@ -423,7 +423,7 @@ class WhoisCommand extends Command // TRANS: Whois output. // TRANS: %1$s nickname of the queried user, %2$s is their profile URL. - $whois = sprintf(_("%1\$s (%2\$s)"), $recipient->nickname, + $whois = sprintf(_m('WHOIS',"%1\$s (%2\$s)"), $recipient->nickname, $recipient->profileurl); if ($recipient->fullname) { // TRANS: Whois output. %s is the full name of the queried user. @@ -483,9 +483,11 @@ class MessageCommand extends Command if (Message::contentTooLong($this->text)) { // XXX: i18n. Needs plural support. - // TRANS: Message given if content is too long. + // TRANS: Message given if content is too long. %1$sd is used for plural. // TRANS: %1$d is the maximum number of characters, %2$d is the number of submitted characters. - $channel->error($this->user, sprintf(_('Message too long - maximum is %1$d characters, you sent %2$d.'), + $channel->error($this->user, sprintf(_m('Message too long - maximum is %1$d character, you sent %2$d.', + 'Message too long - maximum is %1$d characters, you sent %2$d.', + Message::maxContent()), Message::maxContent(), mb_strlen($this->text))); return; } @@ -584,9 +586,11 @@ class ReplyCommand extends Command if (Notice::contentTooLong($this->text)) { // XXX: i18n. Needs plural support. - // TRANS: Message given if content of a notice for a reply is too long. + // TRANS: Message given if content of a notice for a reply is too long. %1$d is used for plural. // TRANS: %1$d is the maximum number of characters, %2$d is the number of submitted characters. - $channel->error($this->user, sprintf(_('Notice too long - maximum is %1$d characters, you sent %2$d.'), + $channel->error($this->user, sprintf(_m('Notice too long - maximum is %1$d character, you sent %2$d.', + 'Notice too long - maximum is %1$d characters, you sent %2$d.', + Notice::maxContent()), Notice::maxContent(), mb_strlen($this->text))); return; } diff --git a/lib/currentuserdesignaction.php b/lib/currentuserdesignaction.php index 490f87d13..e84c77768 100644 --- a/lib/currentuserdesignaction.php +++ b/lib/currentuserdesignaction.php @@ -22,7 +22,7 @@ * @category Action * @package StatusNet * @author Evan Prodromou <evan@status.net> - * @copyright 2009 StatusNet, Inc. + * @copyright 2009-2010 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/ */ @@ -40,12 +40,33 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { * @category Action * @package StatusNet * @author Evan Prodromou <evan@status.net> + * @author Zach Copley <zach@status.net> * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ * */ class CurrentUserDesignAction extends Action { + + protected $cur = null; // The current user + + /** + * For initializing members of the class. Set a the + * current user here. + * + * @param array $argarray misc. arguments + * + * @return boolean true + */ + function prepare($argarray) + { + parent::prepare($argarray); + + $this->cur = common_current_user(); + + return true; + } + /** * A design for this action * @@ -55,11 +76,9 @@ class CurrentUserDesignAction extends Action */ function getDesign() { - $cur = common_current_user(); - - if (!empty($cur)) { + if (!empty($this->cur)) { - $design = $cur->getDesign(); + $design = $this->cur->getDesign(); if (!empty($design)) { return $design; @@ -68,4 +87,10 @@ class CurrentUserDesignAction extends Action return parent::getDesign(); } + + function getCurrentUser() + { + return $this->cur; + } } + diff --git a/lib/default.php b/lib/default.php index a19453fce..a91fa338f 100644 --- a/lib/default.php +++ b/lib/default.php @@ -250,6 +250,10 @@ $default = 'monthly_quota' => 15000000, 'uploads' => true, 'filecommand' => '/usr/bin/file', + 'show_thumbs' => true, // show thumbnails in notice lists for uploaded images, and photos and videos linked remotely that provide oEmbed info + 'thumb_width' => 100, + 'thumb_height' => 75, + 'process_links' => true, // check linked resources for embeddable photos and videos; this will hit referenced external web sites when processing new messages. ), 'application' => array('desclimit' => null), diff --git a/lib/designsettings.php b/lib/designsettings.php index 4955e9219..90296a64d 100644 --- a/lib/designsettings.php +++ b/lib/designsettings.php @@ -48,10 +48,8 @@ require_once INSTALLDIR . '/lib/webcolor.php'; * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ - class DesignSettingsAction extends AccountSettingsAction { - var $submitaction = null; /** @@ -59,9 +57,9 @@ class DesignSettingsAction extends AccountSettingsAction * * @return string Title of the page */ - function title() { + // TRANS: Page title for profile design page. return _('Profile design'); } @@ -70,9 +68,9 @@ class DesignSettingsAction extends AccountSettingsAction * * @return instructions for use */ - function getInstructions() { + // TRANS: Instructions for profile design page. return _('Customize the way your profile looks ' . 'with a background image and a colour palette of your choice.'); } @@ -84,10 +82,8 @@ class DesignSettingsAction extends AccountSettingsAction * * @return nothing */ - function showDesignForm($design) { - $this->elementStart('form', array('method' => 'post', 'enctype' => 'multipart/form-data', 'id' => 'form_settings_design', @@ -98,14 +94,18 @@ class DesignSettingsAction extends AccountSettingsAction $this->elementStart('fieldset', array('id' => 'settings_design_background-image')); + // TRANS: Fieldset legend on profile design page. $this->element('legend', null, _('Change background image')); $this->elementStart('ul', 'form_data'); $this->elementStart('li'); $this->element('label', array('for' => 'design_background-image_file'), + // TRANS: Label in form on profile design page. + // TRANS: Field contains file name on user's computer that could be that user's custom profile background image. _('Upload file')); $this->element('input', array('name' => 'design_background-image_file', 'type' => 'file', 'id' => 'design_background-image_file')); + // TRANS: Instructions for form on profile design page. $this->element('p', 'form_guide', _('You can upload your personal ' . 'background image. The maximum file size is 2MB.')); $this->element('input', array('name' => 'MAX_FILE_SIZE', @@ -115,7 +115,6 @@ class DesignSettingsAction extends AccountSettingsAction $this->elementEnd('li'); if (!empty($design->backgroundimage)) { - $this->elementStart('li', array('id' => 'design_background-image_onoff')); @@ -136,7 +135,8 @@ class DesignSettingsAction extends AccountSettingsAction $this->element('label', array('for' => 'design_background-image_on', 'class' => 'radio'), - _('On')); + // TRANS: Radio button on profile design page that will enable use of the uploaded profile image. + _m('RADIO','On')); $attrs = array('name' => 'design_background-image_onoff', 'type' => 'radio', @@ -152,12 +152,16 @@ class DesignSettingsAction extends AccountSettingsAction $this->element('label', array('for' => 'design_background-image_off', 'class' => 'radio'), - _('Off')); + // TRANS: Radio button on profile design page that will disable use of the uploaded profile image. + _m('RADIO','Off')); + // TRANS: Form guide for a set of radio buttons on the profile design page that will enable or disable + // TRANS: use of the uploaded profile image. $this->element('p', 'form_guide', _('Turn background image on or off.')); $this->elementEnd('li'); $this->elementStart('li'); $this->checkbox('design_background-image_repeat', + // TRANS: Checkbox label on profile design page that will cause the profile image to be tiled. _('Tile background image'), ($design->disposition & BACKGROUND_TILE) ? true : false); $this->elementEnd('li'); @@ -167,14 +171,15 @@ class DesignSettingsAction extends AccountSettingsAction $this->elementEnd('fieldset'); $this->elementStart('fieldset', array('id' => 'settings_design_color')); + // TRANS: Fieldset legend on profile design page to change profile page colours. $this->element('legend', null, _('Change colours')); $this->elementStart('ul', 'form_data'); try { - $bgcolor = new WebColor($design->backgroundcolor); $this->elementStart('li'); + // TRANS: Label on profile design page for setting a profile page background colour. $this->element('label', array('for' => 'swatch-1'), _('Background')); $this->element('input', array('name' => 'design_background', 'type' => 'text', @@ -188,6 +193,7 @@ class DesignSettingsAction extends AccountSettingsAction $ccolor = new WebColor($design->contentcolor); $this->elementStart('li'); + // TRANS: Label on profile design page for setting a profile page content colour. $this->element('label', array('for' => 'swatch-2'), _('Content')); $this->element('input', array('name' => 'design_content', 'type' => 'text', @@ -201,6 +207,7 @@ class DesignSettingsAction extends AccountSettingsAction $sbcolor = new WebColor($design->sidebarcolor); $this->elementStart('li'); + // TRANS: Label on profile design page for setting a profile page sidebar colour. $this->element('label', array('for' => 'swatch-3'), _('Sidebar')); $this->element('input', array('name' => 'design_sidebar', 'type' => 'text', @@ -214,6 +221,7 @@ class DesignSettingsAction extends AccountSettingsAction $tcolor = new WebColor($design->textcolor); $this->elementStart('li'); + // TRANS: Label on profile design page for setting a profile page text colour. $this->element('label', array('for' => 'swatch-4'), _('Text')); $this->element('input', array('name' => 'design_text', 'type' => 'text', @@ -227,6 +235,7 @@ class DesignSettingsAction extends AccountSettingsAction $lcolor = new WebColor($design->linkcolor); $this->elementStart('li'); + // TRANS: Label on profile design page for setting a profile page links colour. $this->element('label', array('for' => 'swatch-5'), _('Links')); $this->element('input', array('name' => 'design_links', 'type' => 'text', @@ -244,16 +253,22 @@ class DesignSettingsAction extends AccountSettingsAction $this->elementEnd('ul'); $this->elementEnd('fieldset'); + // TRANS: Button text on profile design page to immediately reset all colour settings to default. $this->submit('defaults', _('Use defaults'), 'submit form_action-default', + // TRANS: Title for button on profile design page to reset all colour settings to default. 'defaults', _('Restore default designs')); $this->element('input', array('id' => 'settings_design_reset', 'type' => 'reset', - 'value' => 'Reset', + // TRANS: Button text on profile design page to reset all colour settings to default without saving. + 'value' => _m('BUTTON','Reset'), 'class' => 'submit form_action-primary', + // TRANS: Title for button on profile design page to reset all colour settings to default without saving. 'title' => _('Reset back to default'))); - $this->submit('save', _('Save'), 'submit form_action-secondary', + // TRANS: Button text on profile design page to save settings. + $this->submit('save', _m('BUTTON','Save'), 'submit form_action-secondary', + // TRANS: Title for button on profile design page to save settings. 'save', _('Save design')); $this->elementEnd('fieldset'); @@ -268,7 +283,6 @@ class DesignSettingsAction extends AccountSettingsAction * * @return void */ - function handlePost() { if ($_SERVER['REQUEST_METHOD'] == 'POST') { @@ -280,8 +294,10 @@ class DesignSettingsAction extends AccountSettingsAction && empty($_POST) && ($_SERVER['CONTENT_LENGTH'] > 0) ) { - $msg = _('The server was unable to handle that much POST ' . - 'data (%s bytes) due to its current configuration.'); + // TRANS: Form validation error in design settings form. POST should remain untranslated. + $msg = _m('The server was unable to handle that much POST data (%s byte) due to its current configuration.', + 'The server was unable to handle that much POST data (%s bytes) due to its current configuration.', + intval($_SERVER['CONTENT_LENGTH'])); $this->showForm(sprintf($msg, $_SERVER['CONTENT_LENGTH'])); return; @@ -301,6 +317,7 @@ class DesignSettingsAction extends AccountSettingsAction } else if ($this->arg('defaults')) { $this->restoreDefaults(); } else { + // TRANS: Unknown form validation error in design settings form. $this->showForm(_('Unexpected form submission.')); } } @@ -310,7 +327,6 @@ class DesignSettingsAction extends AccountSettingsAction * * @return void */ - function showStylesheets() { parent::showStylesheets(); @@ -322,7 +338,6 @@ class DesignSettingsAction extends AccountSettingsAction * * @return void */ - function showScripts() { parent::showScripts(); @@ -340,10 +355,8 @@ class DesignSettingsAction extends AccountSettingsAction * * @return nothing */ - function saveBackgroundImage($design) { - // Now that we have a Design ID we can add a file to the design. // XXX: This is an additional DB hit, but figured having the image // associated with the Design rather than the User was worth @@ -388,6 +401,7 @@ class DesignSettingsAction extends AccountSettingsAction if ($result === false) { common_log_db_error($design, 'UPDATE', __FILE__); + // TRANS: Error message displayed if design settings could not be saved. $this->showForm(_('Couldn\'t update your design.')); return; } @@ -399,7 +413,6 @@ class DesignSettingsAction extends AccountSettingsAction * * @return nothing */ - function restoreDefaults() { $design = $this->getWorkingDesign(); @@ -410,12 +423,13 @@ class DesignSettingsAction extends AccountSettingsAction if ($result === false) { common_log_db_error($design, 'DELETE', __FILE__); + // TRANS: Error message displayed if design settings could not be saved after clicking "Use defaults". $this->showForm(_('Couldn\'t update your design.')); return; } } + // TRANS: Success message displayed if design settings were saved after clicking "Use defaults". $this->showForm(_('Design defaults restored.'), true); } - } diff --git a/lib/feedlist.php b/lib/feedlist.php index 076576028..bbe66b2e7 100644 --- a/lib/feedlist.php +++ b/lib/feedlist.php @@ -62,6 +62,7 @@ class FeedList extends Widget if (!empty($feeds)) { $this->out->elementStart('div', array('id' => 'export_data', 'class' => 'section')); + // TRANS: Header for feed links (h2). $this->out->element('h2', null, _('Feeds')); $this->out->elementStart('ul', array('class' => 'xoxo')); diff --git a/lib/groupeditform.php b/lib/groupeditform.php index 433f6a138..cc25f0688 100644 --- a/lib/groupeditform.php +++ b/lib/groupeditform.php @@ -160,14 +160,17 @@ class GroupEditForm extends Form $this->out->elementStart('li'); $this->out->input('homepage', _('Homepage'), ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage, - _('URL of the homepage or blog of the group or topic')); + _('URL of the homepage or blog of the group or topic.')); $this->out->elementEnd('li'); $this->out->elementStart('li'); $desclimit = User_group::maxDescription(); if ($desclimit == 0) { $descinstr = _('Describe the group or topic'); } else { - $descinstr = sprintf(_('Describe the group or topic in %d characters'), $desclimit); + $descinstr = sprintf(_m('Describe the group or topic in %d character or less', + 'Describe the group or topic in %d characters or less', + $desclimit), + $desclimit); } $this->out->textarea('description', _('Description'), ($this->out->arg('description')) ? $this->out->arg('description') : $description, @@ -176,7 +179,7 @@ class GroupEditForm extends Form $this->out->elementStart('li'); $this->out->input('location', _('Location'), ($this->out->arg('location')) ? $this->out->arg('location') : $location, - _('Location for the group, if any, like "City, State (or Region), Country"')); + _('Location for the group, if any, like "City, State (or Region), Country".')); $this->out->elementEnd('li'); if (common_config('group', 'maxaliases') > 0) { $aliases = (empty($this->group)) ? array() : $this->group->getAliases(); @@ -184,7 +187,9 @@ class GroupEditForm extends Form $this->out->input('aliases', _('Aliases'), ($this->out->arg('aliases')) ? $this->out->arg('aliases') : (!empty($aliases)) ? implode(' ', $aliases) : '', - sprintf(_('Extra nicknames for the group, comma- or space- separated, max %d'), + sprintf(_m('Extra nicknames for the group, separated with commas or spaces. Maximum %d alias allowed.', + 'Extra nicknames for the group, separated with commas or spaces. Maximum %d aliases allowed.', + common_config('group', 'maxaliases')), common_config('group', 'maxaliases')));; $this->out->elementEnd('li'); } @@ -199,6 +204,6 @@ class GroupEditForm extends Form function formActions() { - $this->out->submit('submit', _('Save')); + $this->out->submit('submit', _m('BUTTON','Save')); } } diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php index 42bff4490..b341d1495 100644 --- a/lib/htmloutputter.php +++ b/lib/htmloutputter.php @@ -119,9 +119,16 @@ class HTMLOutputter extends XMLOutputter $language = $this->getLanguage(); - $this->elementStart('html', array('xmlns' => 'http://www.w3.org/1999/xhtml', - 'xml:lang' => $language, - 'lang' => $language)); + $attrs = array( + 'xmlns' => 'http://www.w3.org/1999/xhtml', + 'xml:lang' => $language, + 'lang' => $language + ); + + if (Event::handle('StartHtmlElement', array($this, &$attrs))) { + $this->elementStart('html', $attrs); + Event::handle('EndHtmlElement', array($this, &$attrs)); + } } function getLanguage() diff --git a/lib/imagefile.php b/lib/imagefile.php index e47287741..159deead6 100644 --- a/lib/imagefile.php +++ b/lib/imagefile.php @@ -85,6 +85,8 @@ class ImageFile break; case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: + // TRANS: Exception thrown when too large a file is uploaded. + // TRANS: %s is the maximum file size, for example "500b", "10kB" or "2MB". throw new Exception(sprintf(_('That file is too big. The maximum file size is %s.'), ImageFile::maxFileSize())); return; @@ -113,10 +115,46 @@ class ImageFile return new ImageFile(null, $_FILES[$param]['tmp_name']); } + /** + * Compat interface for old code generating avatar thumbnails... + * Saves the scaled file directly into the avatar area. + * + * @param int $size target width & height -- must be square + * @param int $x (default 0) upper-left corner to crop from + * @param int $y (default 0) upper-left corner to crop from + * @param int $w (default full) width of image area to crop + * @param int $h (default full) height of image area to crop + * @return string filename + */ function resize($size, $x = 0, $y = 0, $w = null, $h = null) { + $targetType = $this->preferredType($this->type); + $outname = Avatar::filename($this->id, + image_type_to_extension($targetType), + $size, + common_timestamp()); + $outpath = Avatar::path($outname); + $this->resizeTo($outpath, $size, $size, $x, $y, $w, $h); + return $outname; + } + + /** + * Create and save a thumbnail image. + * + * @param string $outpath + * @param int $width target width + * @param int $height target height + * @param int $x (default 0) upper-left corner to crop from + * @param int $y (default 0) upper-left corner to crop from + * @param int $w (default full) width of image area to crop + * @param int $h (default full) height of image area to crop + * @return string full local filesystem filename + */ + function resizeTo($outpath, $width, $height, $x=0, $y=0, $w=null, $h=null) + { $w = ($w === null) ? $this->width:$w; $h = ($h === null) ? $this->height:$h; + $targetType = $this->preferredType($this->type); if (!file_exists($this->filepath)) { throw new Exception(_('Lost our file.')); @@ -124,20 +162,16 @@ class ImageFile } // Don't crop/scale if it isn't necessary - if ($size === $this->width - && $size === $this->height + if ($width === $this->width + && $height === $this->height && $x === 0 && $y === 0 && $w === $this->width - && $h === $this->height) { + && $h === $this->height + && $this->type == $targetType) { - $outname = Avatar::filename($this->id, - image_type_to_extension($this->type), - $size, - common_timestamp()); - $outpath = Avatar::path($outname); @copy($this->filepath, $outpath); - return $outname; + return $outpath; } switch ($this->type) { @@ -164,7 +198,7 @@ class ImageFile return; } - $image_dest = imagecreatetruecolor($size, $size); + $image_dest = imagecreatetruecolor($width, $height); if ($this->type == IMAGETYPE_GIF || $this->type == IMAGETYPE_PNG || $this->type == IMAGETYPE_BMP) { @@ -187,30 +221,9 @@ class ImageFile } } - imagecopyresampled($image_dest, $image_src, 0, 0, $x, $y, $size, $size, $w, $h); - - if($this->type == IMAGETYPE_BMP) { - //we don't want to save BMP... it's an inefficient, rare, antiquated format - //save png instead - $this->type = IMAGETYPE_PNG; - } else if($this->type == IMAGETYPE_WBMP) { - //we don't want to save WBMP... it's a rare format that we can't guarantee clients will support - //save png instead - $this->type = IMAGETYPE_PNG; - } else if($this->type == IMAGETYPE_XBM) { - //we don't want to save XBM... it's a rare format that we can't guarantee clients will support - //save png instead - $this->type = IMAGETYPE_PNG; - } - - $outname = Avatar::filename($this->id, - image_type_to_extension($this->type), - $size, - common_timestamp()); - - $outpath = Avatar::path($outname); + imagecopyresampled($image_dest, $image_src, 0, 0, $x, $y, $width, $height, $w, $h); - switch ($this->type) { + switch ($targetType) { case IMAGETYPE_GIF: imagegif($image_dest, $outpath); break; @@ -228,7 +241,31 @@ class ImageFile imagedestroy($image_src); imagedestroy($image_dest); - return $outname; + return $outpath; + } + + /** + * Several obscure file types should be normalized to PNG on resize. + * + * @param int $type + * @return int + */ + function preferredType($type) + { + if($type == IMAGETYPE_BMP) { + //we don't want to save BMP... it's an inefficient, rare, antiquated format + //save png instead + return IMAGETYPE_PNG; + } else if($type == IMAGETYPE_WBMP) { + //we don't want to save WBMP... it's a rare format that we can't guarantee clients will support + //save png instead + return IMAGETYPE_PNG; + } else if($type == IMAGETYPE_XBM) { + //we don't want to save XBM... it's a rare format that we can't guarantee clients will support + //save png instead + return IMAGETYPE_PNG; + } + return $type; } function unlink() @@ -241,11 +278,16 @@ class ImageFile $value = ImageFile::maxFileSizeInt(); if ($value > 1024 * 1024) { - return ($value/(1024*1024)) . _('MB'); + $value = $value/(1024*1024); + // TRANS: Number of megabytes. %d is the number. + return sprintf(_m('%dMB','%dMB',$value),$value); } else if ($value > 1024) { - return ($value/(1024)) . _('kB'); + $value = $value/1024; + // TRANS: Number of kilobytes. %d is the number. + return sprintf(_m('%dkB','%dkB',$value),$value); } else { - return $value; + // TRANS: Number of bytes. %d is the number. + return sprintf(_m('%dB','%dB',$value),$value); } } diff --git a/lib/inlineattachmentlist.php b/lib/inlineattachmentlist.php new file mode 100644 index 000000000..de5008e87 --- /dev/null +++ b/lib/inlineattachmentlist.php @@ -0,0 +1,108 @@ +<?php +/** + * StatusNet, the distributed open-source microblogging tool + * + * widget for displaying notice attachments thumbnails + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * 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/>. + * + * @category UI + * @package StatusNet + * @author Brion Vibber <brion@status.net> + * @copyright 2010 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/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +class InlineAttachmentList extends AttachmentList +{ + function showListStart() + { + $this->out->elementStart('div', array('class' => 'entry-content thumbnails')); + } + + function showListEnd() + { + $this->out->elementEnd('div'); + } + + /** + * returns a new list item for the current attachment + * + * @param File $notice the current attachment + * + * @return ListItem a list item for displaying the attachment + */ + function newListItem($attachment) + { + return new InlineAttachmentListItem($attachment, $this->out); + } +} + +class InlineAttachmentListItem extends AttachmentListItem +{ + function show() + { + if ($this->attachment->isEnclosure()) { + parent::show(); + } + } + + function showLink() { + $this->out->elementStart('a', $this->linkAttr()); + $this->showRepresentation(); + $this->out->elementEnd('a'); + } + + /** + * Build HTML attributes for the link + * @return array + */ + function linkAttr() + { + $attr = parent::linkAttr(); + $attr['class'] = 'attachment-thumbnail'; + return $attr; + } + + /** + * start a single notice. + * + * @return void + */ + function showStart() + { + // XXX: RDFa + // TODO: add notice_type class e.g., notice_video, notice_image + $this->out->elementStart('span', array('class' => 'inline-attachment')); + } + + /** + * finish the notice + * + * Close the last elements in the notice list item + * + * @return void + */ + function showEnd() + { + $this->out->elementEnd('span'); + } +} diff --git a/lib/mail.php b/lib/mail.php index 30d743848..dd6a1a366 100644 --- a/lib/mail.php +++ b/lib/mail.php @@ -593,6 +593,10 @@ function mail_notify_fave($other, $user, $notice) } $profile = $user->getProfile(); + if ($other->hasBlocked($profile)) { + // If the author has blocked us, don't spam them with a notification. + return; + } $bestname = $profile->getBestName(); diff --git a/lib/mailhandler.php b/lib/mailhandler.php index e9ba41839..69eb26bdd 100644 --- a/lib/mailhandler.php +++ b/lib/mailhandler.php @@ -57,8 +57,9 @@ class MailHandler $msg = $this->cleanup_msg($msg); $msg = common_shorten_links($msg); if (Notice::contentTooLong($msg)) { - $this->error($from, sprintf(_('That\'s too long. '. - 'Max notice size is %d chars.'), + $this->error($from, sprintf(_('That\'s too long. Maximum notice size is %d character.', + 'That\'s too long. Maximum notice size is %d characters.', + Notice::maxContent()), Notice::maxContent())); } diff --git a/lib/mediafile.php b/lib/mediafile.php index 23338cc0e..a41d7c76b 100644 --- a/lib/mediafile.php +++ b/lib/mediafile.php @@ -48,11 +48,14 @@ class MediaFile { if ($user == null) { $this->user = common_current_user(); + } else { + $this->user = $user; } $this->filename = $filename; $this->mimetype = $mimetype; $this->fileRecord = $this->storeFile(); + $this->thumbnailRecord = $this->storeThumbnail(); $this->fileurl = common_local_url('attachment', array('attachment' => $this->fileRecord->id)); @@ -102,6 +105,52 @@ class MediaFile return $file; } + /** + * Generate and store a thumbnail image for the uploaded file, if applicable. + * + * @return File_thumbnail or null + */ + function storeThumbnail() + { + if (substr($this->mimetype, 0, strlen('image/')) != 'image/') { + // @fixme video thumbs would be nice! + return null; + } + try { + $image = new ImageFile($this->fileRecord->id, + File::path($this->filename)); + } catch (Exception $e) { + // Unsupported image type. + return null; + } + + $outname = File::filename($this->user->getProfile(), 'thumb-' . $this->filename, $this->mimetype); + $outpath = File::path($outname); + + $maxWidth = common_config('attachments', 'thumb_width'); + $maxHeight = common_config('attachments', 'thumb_height'); + list($width, $height) = $this->scaleToFit($image->width, $image->height, $maxWidth, $maxHeight); + + $image->resizeTo($outpath, $width, $height); + File_thumbnail::saveThumbnail($this->fileRecord->id, + File::url($outname), + $width, + $height); + } + + function scaleToFit($width, $height, $maxWidth, $maxHeight) + { + $aspect = $maxWidth / $maxHeight; + $w1 = $maxWidth; + $h1 = intval($height * $maxWidth / $width); + if ($h1 > $maxHeight) { + $w2 = intval($width * $maxHeight / $height); + $h2 = $maxHeight; + return array($w2, $h2); + } + return array($w1, $h1); + } + function rememberFile($file, $short) { $this->maybeAddRedir($file->id, $short); @@ -278,6 +327,9 @@ class MediaFile static function getUploadedFileType($f, $originalFilename=false) { require_once 'MIME/Type.php'; require_once 'MIME/Type/Extension.php'; + + // We have to disable auto handling of PEAR errors + PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); $mte = new MIME_Type_Extension(); $cmd = &PEAR::getStaticProperty('MIME_Type', 'fileCmd'); @@ -330,6 +382,8 @@ class MediaFile } } if ($supported === true || in_array($filetype, $supported)) { + // Restore PEAR error handlers for our DB code... + PEAR::staticPopErrorHandling(); return $filetype; } $media = MIME_Type::getMedia($filetype); @@ -344,6 +398,8 @@ class MediaFile // TRANS: %s is the file type that was denied. $hint = sprintf(_('"%s" is not a supported file type on this server.'), $filetype); } + // Restore PEAR error handlers for our DB code... + PEAR::staticPopErrorHandling(); throw new ClientException($hint); } diff --git a/lib/noticelist.php b/lib/noticelist.php index df1533980..c6f964662 100644 --- a/lib/noticelist.php +++ b/lib/noticelist.php @@ -208,6 +208,7 @@ class NoticeListItem extends Widget $this->showStart(); if (Event::handle('StartShowNoticeItem', array($this))) { $this->showNotice(); + $this->showNoticeAttachments(); $this->showNoticeInfo(); $this->showNoticeOptions(); Event::handle('EndShowNoticeItem', array($this)); @@ -306,7 +307,7 @@ class NoticeListItem extends Widget $attrs = array('href' => $this->profile->profileurl, 'class' => 'url'); if (!empty($this->profile->fullname)) { - $attrs['title'] = $this->profile->fullname . ' (' . $this->profile->nickname . ')'; + $attrs['title'] = $this->profile->getFancyName(); } $this->out->elementStart('a', $attrs); $this->showAvatar(); @@ -327,11 +328,8 @@ class NoticeListItem extends Widget function showAvatar() { - if ('shownotice' === $this->out->trimmed('action')) { - $avatar_size = AVATAR_PROFILE_SIZE; - } else { - $avatar_size = AVATAR_STREAM_SIZE; - } + $avatar_size = AVATAR_STREAM_SIZE; + $avatar = $this->profile->getAvatar($avatar_size); $this->out->element('img', array('src' => ($avatar) ? @@ -386,6 +384,13 @@ class NoticeListItem extends Widget $this->out->elementEnd('p'); } + function showNoticeAttachments() { + if (common_config('attachments', 'show_thumbs')) { + $al = new InlineAttachmentList($this->notice, $this->out); + $al->show(); + } + } + /** * show the link to the main page for the notice * diff --git a/lib/oembedhelper.php b/lib/oembedhelper.php new file mode 100644 index 000000000..84cf10586 --- /dev/null +++ b/lib/oembedhelper.php @@ -0,0 +1,318 @@ +<?php +/* + * StatusNet - the distributed open-source microblogging tool + * Copyright (C) 2008-2010, StatusNet, Inc. + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * 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/>. + */ + +if (!defined('STATUSNET')) { + exit(1); +} + + +/** + * Utility class to wrap basic oEmbed lookups. + * + * Blacklisted hosts will use an alternate lookup method: + * - Twitpic + * + * Whitelisted hosts will use known oEmbed API endpoints: + * - Flickr, YFrog + * + * Sites that provide discovery links will use them directly; a bug + * in use of discovery links with query strings is worked around. + * + * Others will fall back to oohembed (unless disabled). + * The API endpoint can be configured or disabled through config + * as 'oohembed'/'endpoint'. + */ +class oEmbedHelper +{ + protected static $apiMap = array( + 'flickr.com' => 'http://www.flickr.com/services/oembed/', + 'yfrog.com' => 'http://www.yfrog.com/api/oembed', + ); + protected static $functionMap = array( + 'twitpic.com' => 'oEmbedHelper::twitPic', + ); + + /** + * Perform or fake an oEmbed lookup for the given resource. + * + * Some known hosts are whitelisted with API endpoints where we + * know they exist but autodiscovery data isn't available. + * If autodiscovery links are missing and we don't recognize the + * host, we'll pass it to oohembed.com's public service which + * will either proxy or fake info on a lot of sites. + * + * A few hosts are blacklisted due to known problems with oohembed, + * in which case we'll look up the info another way and return + * equivalent data. + * + * Throws exceptions on failure. + * + * @param string $url + * @param array $params + * @return object + */ + public static function getObject($url, $params=array()) + { + $host = parse_url($url, PHP_URL_HOST); + if (substr($host, 0, 4) == 'www.') { + $host = substr($host, 4); + } + + // Blacklist: systems with no oEmbed API of their own, which are + // either missing from or broken on oohembed.com's proxy. + // we know how to look data up in another way... + if (array_key_exists($host, self::$functionMap)) { + $func = self::$functionMap[$host]; + return call_user_func($func, $url, $params); + } + + // Whitelist: known API endpoints for sites that don't provide discovery... + if (array_key_exists($host, self::$apiMap)) { + $api = self::$apiMap[$host]; + } else { + try { + $api = self::discover($url); + } catch (Exception $e) { + // Discovery failed... fall back to oohembed if enabled. + $oohembed = common_config('oohembed', 'endpoint'); + if ($oohembed) { + $api = $oohembed; + } else { + throw $e; + } + } + } + return self::getObjectFrom($api, $url, $params); + } + + /** + * Perform basic discovery. + * @return string + */ + static function discover($url) + { + // @fixme ideally skip this for non-HTML stuff! + $body = self::http($url); + return self::discoverFromHTML($url, $body); + } + + /** + * Partially ripped from OStatus' FeedDiscovery class. + * + * @param string $url source URL, used to resolve relative links + * @param string $body HTML body text + * @return mixed string with URL or false if no target found + */ + static function discoverFromHTML($url, $body) + { + // DOMDocument::loadHTML may throw warnings on unrecognized elements, + // and notices on unrecognized namespaces. + $old = error_reporting(error_reporting() & ~(E_WARNING | E_NOTICE)); + $dom = new DOMDocument(); + $ok = $dom->loadHTML($body); + error_reporting($old); + + if (!$ok) { + throw new oEmbedHelper_BadHtmlException(); + } + + // Ok... now on to the links! + $feeds = array( + 'application/json+oembed' => false, + ); + + $nodes = $dom->getElementsByTagName('link'); + for ($i = 0; $i < $nodes->length; $i++) { + $node = $nodes->item($i); + if ($node->hasAttributes()) { + $rel = $node->attributes->getNamedItem('rel'); + $type = $node->attributes->getNamedItem('type'); + $href = $node->attributes->getNamedItem('href'); + if ($rel && $type && $href) { + $rel = array_filter(explode(" ", $rel->value)); + $type = trim($type->value); + $href = trim($href->value); + + if (in_array('alternate', $rel) && array_key_exists($type, $feeds) && empty($feeds[$type])) { + // Save the first feed found of each type... + $feeds[$type] = $href; + } + } + } + } + + // Return the highest-priority feed found + foreach ($feeds as $type => $url) { + if ($url) { + return $url; + } + } + + throw new oEmbedHelper_DiscoveryException(); + } + + /** + * Actually do an oEmbed lookup to a particular API endpoint. + * + * @param string $api oEmbed API endpoint URL + * @param string $url target URL to look up info about + * @param array $params + * @return object + */ + static function getObjectFrom($api, $url, $params=array()) + { + $params['url'] = $url; + $params['format'] = 'json'; + $data = self::json($api, $params); + return self::normalize($data); + } + + /** + * Normalize oEmbed format. + * + * @param object $orig + * @return object + */ + static function normalize($orig) + { + $data = clone($orig); + + if (empty($data->type)) { + throw new Exception('Invalid oEmbed data: no type field.'); + } + + if ($data->type == 'image') { + // YFrog does this. + $data->type = 'photo'; + } + + if (isset($data->thumbnail_url)) { + if (!isset($data->thumbnail_width)) { + // !?!?! + $data->thumbnail_width = common_config('attachments', 'thumb_width'); + $data->thumbnail_height = common_config('attachments', 'thumb_height'); + } + } + + return $data; + } + + /** + * Using a local function for twitpic lookups, as oohembed's adapter + * doesn't return a valid result: + * http://code.google.com/p/oohembed/issues/detail?id=19 + * + * This code fetches metadata from Twitpic's own API, and attempts + * to guess proper thumbnail size from the original's size. + * + * @todo respect maxwidth and maxheight params + * + * @param string $url + * @param array $params + * @return object + */ + static function twitPic($url, $params=array()) + { + $matches = array(); + if (preg_match('!twitpic\.com/(\w+)!', $url, $matches)) { + $id = $matches[1]; + } else { + throw new Exception("Invalid twitpic URL"); + } + + // Grab metadata from twitpic's API... + // http://dev.twitpic.com/docs/2/media_show + $data = self::json('http://api.twitpic.com/2/media/show.json', + array('id' => $id)); + $oembed = (object)array('type' => 'photo', + 'url' => 'http://twitpic.com/show/full/' . $data->short_id, + 'width' => $data->width, + 'height' => $data->height); + if (!empty($data->message)) { + $oembed->title = $data->message; + } + + // Thumbnail is cropped and scaled to 150x150 box: + // http://dev.twitpic.com/docs/thumbnails/ + $thumbSize = 150; + $oembed->thumbnail_url = 'http://twitpic.com/show/thumb/' . $data->short_id; + $oembed->thumbnail_width = $thumbSize; + $oembed->thumbnail_height = $thumbSize; + + return $oembed; + } + + /** + * Fetch some URL and return JSON data. + * + * @param string $url + * @param array $params query-string params + * @return object + */ + static protected function json($url, $params=array()) + { + $data = self::http($url, $params); + return json_decode($data); + } + + /** + * Hit some web API and return data on success. + * @param string $url + * @param array $params + * @return string + */ + static protected function http($url, $params=array()) + { + $client = HTTPClient::start(); + if ($params) { + $query = http_build_query($params, null, '&'); + if (strpos($url, '?') === false) { + $url .= '?' . $query; + } else { + $url .= '&' . $query; + } + } + $response = $client->get($url); + if ($response->isOk()) { + return $response->getBody(); + } else { + throw new Exception('Bad HTTP response code: ' . $response->getStatus()); + } + } +} + +class oEmbedHelper_Exception extends Exception +{ +} + +class oEmbedHelper_BadHtmlException extends oEmbedHelper_Exception +{ + function __construct($previous=null) + { + return parent::__construct('Bad HTML in discovery data.', 0, $previous); + } +} + +class oEmbedHelper_DiscoveryException extends oEmbedHelper_Exception +{ + function __construct($previous=null) + { + return parent::__construct('No oEmbed discovery data.', 0, $previous); + } +} diff --git a/lib/personalgroupnav.php b/lib/personalgroupnav.php index 25db5baa9..1f543b897 100644 --- a/lib/personalgroupnav.php +++ b/lib/personalgroupnav.php @@ -87,8 +87,11 @@ class PersonalGroupNav extends Widget if ($nickname) { $user = User::staticGet('nickname', $nickname); $user_profile = $user->getProfile(); + $name = $user_profile->getBestName(); } else { + // @fixme can this happen? is this valid? $user_profile = false; + $name = $nickname; } $this->out->elementStart('ul', array('class' => 'nav')); @@ -97,22 +100,22 @@ class PersonalGroupNav extends Widget $this->out->menuItem(common_local_url('all', array('nickname' => $nickname)), _('Personal'), - sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), + sprintf(_('%s and friends'), $name), $action == 'all', 'nav_timeline_personal'); $this->out->menuItem(common_local_url('replies', array('nickname' => $nickname)), _('Replies'), - sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)), + sprintf(_('Replies to %s'), $name), $action == 'replies', 'nav_timeline_replies'); $this->out->menuItem(common_local_url('showstream', array('nickname' => $nickname)), _('Profile'), - ($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname, + $name, $action == 'showstream', 'nav_profile'); $this->out->menuItem(common_local_url('showfavorites', array('nickname' => $nickname)), _('Favorites'), - sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')), + sprintf(_('%s\'s favorite notices'), ($user_profile) ? $name : _('User')), $action == 'showfavorites', 'nav_timeline_favorites'); $cur = common_current_user(); diff --git a/lib/ping.php b/lib/ping.php index abf1c4048..e1c7c748e 100644 --- a/lib/ping.php +++ b/lib/ping.php @@ -20,13 +20,12 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); } function ping_broadcast_notice($notice) { + if ($notice->is_local != Notice::LOCAL_PUBLIC && $notice->is_local != Notice::LOCAL_NONPUBLIC) { + return true; + } - if ($notice->is_local != Notice::LOCAL_PUBLIC && $notice->is_local != Notice::LOCAL_NONPUBLIC) { - return true; - } - - # Array of servers, URL => type - $notify = common_config('ping', 'notify'); + # Array of servers, URL => type + $notify = common_config('ping', 'notify'); try { $profile = $notice->getProfile(); } catch (Exception $e) { @@ -35,21 +34,21 @@ function ping_broadcast_notice($notice) { common_log(LOG_ERR, "Exception getting notice profile: " . $e->getMessage()); return true; } - $tags = ping_notice_tags($notice); + $tags = ping_notice_tags($notice); - foreach ($notify as $notify_url => $type) { - switch ($type) { - case 'xmlrpc': - case 'extended': - $req = xmlrpc_encode_request('weblogUpdates.ping', - array($profile->nickname, # site name - common_local_url('showstream', - array('nickname' => $profile->nickname)), - common_local_url('shownotice', - array('notice' => $notice->id)), - common_local_url('userrss', - array('nickname' => $profile->nickname)), - $tags)); + foreach ($notify as $notify_url => $type) { + switch ($type) { + case 'xmlrpc': + case 'extended': + $req = xmlrpc_encode_request('weblogUpdates.ping', + array($profile->nickname, # site name + common_local_url('showstream', + array('nickname' => $profile->nickname)), + common_local_url('shownotice', + array('notice' => $notice->id)), + common_local_url('userrss', + array('nickname' => $profile->nickname)), + $tags)); $request = HTTPClient::start(); $request->setConfig('connect_timeout', common_config('ping', 'timeout')); @@ -79,9 +78,8 @@ function ping_broadcast_notice($notice) { "Ping success for $notify_url $notice->id"); } break; - - case 'get': - case 'post': + case 'get': + case 'post': $args = array('name' => $profile->nickname, 'url' => common_local_url('showstream', array('nickname' => $profile->nickname)), @@ -108,26 +106,25 @@ function ping_broadcast_notice($notice) { "'$result->body'"); } break; - - default: - common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type); + default: + common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type); } - } + } return true; } function ping_notice_tags($notice) { - $tag = new Notice_tag(); - $tag->notice_id = $notice->id; - $tags = array(); - if ($tag->find()) { - while ($tag->fetch()) { - $tags[] = $tag->tag; - } - $tag->free(); - unset($tag); - return implode('|', $tags); - } - return NULL; + $tag = new Notice_tag(); + $tag->notice_id = $notice->id; + $tags = array(); + if ($tag->find()) { + while ($tag->fetch()) { + $tags[] = $tag->tag; + } + $tag->free(); + unset($tag); + return implode('|', $tags); + } + return NULL; } diff --git a/lib/router.php b/lib/router.php index 9aaac7dfe..c0f3bf31d 100644 --- a/lib/router.php +++ b/lib/router.php @@ -399,12 +399,12 @@ class Router $m->connect('api/statuses/show.:format', array('action' => 'ApiStatusesShow', - 'format' => '(xml|json)')); + 'format' => '(xml|json|atom)')); $m->connect('api/statuses/show/:id.:format', array('action' => 'ApiStatusesShow', 'id' => '[0-9]+', - 'format' => '(xml|json)')); + 'format' => '(xml|json|atom)')); $m->connect('api/statuses/update.:format', array('action' => 'ApiStatusesUpdate', @@ -686,6 +686,13 @@ class Router $m->connect('api/oauth/authorize', array('action' => 'ApiOauthAuthorize')); + $m->connect('api/statusnet/app/service/:id.xml', + array('action' => 'ApiAtomService', + 'id' => '[a-zA-Z0-9]+')); + + $m->connect('api/statusnet/app/service.xml', + array('action' => 'ApiAtomService')); + // Admin $m->connect('admin/site', array('action' => 'siteadminpanel')); diff --git a/lib/searchaction.php b/lib/searchaction.php index 14c3ed016..6d7f46cd6 100644 --- a/lib/searchaction.php +++ b/lib/searchaction.php @@ -70,7 +70,6 @@ class SearchAction extends Action * @return void * @see SearchGroupNav */ - function showLocalNav() { $nav = new SearchGroupNav($this, $this->trimmed('q')); @@ -127,6 +126,7 @@ class SearchAction extends Action // TRANS: Used as a field label for the field where one or more keywords // TRANS: for searching can be entered. $this->input('q', _('Keyword(s)'), $q); + // TRANS: Button text for searching site. $this->submit('search', _m('BUTTON','Search')); $this->elementEnd('li'); $this->elementEnd('ul'); @@ -138,7 +138,7 @@ class SearchAction extends Action } function searchSuggestions($q) { - // @todo FIXME: This formatting does not make this string get picked up by gettext. + // @todo FIXME: i18n issue: This formatting does not make this string get picked up by gettext. // TRANS: Standard search suggestions shown when a search does not give any results. $message = _(<<<E_O_T * Make sure all words are spelled correctly. @@ -150,7 +150,7 @@ E_O_T ); if (!common_config('site', 'private')) { $qe = urlencode($q); - // @todo FIXME: This formatting does not make this string get picked up by gettext. + // @todo FIXME: i18n issue: This formatting does not make this string get picked up by gettext. // TRANS: Standard search suggestions shown when a search does not give any results. $message .= sprintf(_(<<<E_O_T diff --git a/lib/statusnet.php b/lib/statusnet.php index 33bf32b10..85b46bbb3 100644 --- a/lib/statusnet.php +++ b/lib/statusnet.php @@ -377,7 +377,11 @@ class StatusNet static function isHTTPS() { // There are some exceptions to this; add them here! - return !empty($_SERVER['HTTPS']); + if(empty($_SERVER['HTTPS'])) { + return false; + } else { + return $_SERVER['HTTPS'] !== 'off'; + } } } diff --git a/lib/theme.php b/lib/theme.php index 95b7c1de4..5caa046c2 100644 --- a/lib/theme.php +++ b/lib/theme.php @@ -51,7 +51,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ - class Theme { var $name = null; @@ -65,14 +64,14 @@ class Theme * * @param string $name Name of the theme; defaults to config value */ - function __construct($name=null) { if (empty($name)) { $name = common_config('site', 'theme'); } if (!self::validName($name)) { - throw new ServerException("Invalid theme name."); + // TRANS: Server exception displayed if a theme name was invalid. + throw new ServerException(_('Invalid theme name.')); } $this->name = $name; @@ -95,7 +94,6 @@ class Theme $fulldir = $instroot.'/'.$name; if (file_exists($fulldir) && is_dir($fulldir)) { - $this->dir = $fulldir; $this->path = $this->relativeThemePath('theme', 'theme', $name); } @@ -113,11 +111,9 @@ class Theme * * @todo consolidate code with that for other customizable paths */ - protected function relativeThemePath($group, $fallbackSubdir, $name) { if (StatusNet::isHTTPS()) { - $sslserver = common_config($group, 'sslserver'); if (empty($sslserver)) { @@ -140,9 +136,7 @@ class Theme } $protocol = 'https'; - } else { - $path = common_config($group, 'path'); if (empty($path)) { @@ -179,7 +173,6 @@ class Theme * * @return string full pathname, like /var/www/mublog/theme/default/logo.png */ - function getFile($relative) { return $this->dir.'/'.$relative; @@ -192,7 +185,6 @@ class Theme * * @return string full URL, like 'http://example.com/theme/default/logo.png' */ - function getPath($relative) { return $this->path.'/'.$relative; @@ -258,7 +250,6 @@ class Theme * * @return string File path to the theme file */ - static function file($relative, $name=null) { $theme = new Theme($name); @@ -273,7 +264,6 @@ class Theme * * @return string URL of the file */ - static function path($relative, $name=null) { $theme = new Theme($name); @@ -285,7 +275,6 @@ class Theme * * @return array list of available theme names */ - static function listAvailable() { $local = self::subdirsOf(self::localRoot()); @@ -305,7 +294,6 @@ class Theme * * @return array relative filenames of subdirs, or empty array */ - protected static function subdirsOf($dir) { $subdirs = array(); @@ -330,7 +318,6 @@ class Theme * * @return string local root dir for themes */ - protected static function localRoot() { $basedir = common_config('local', 'dir'); @@ -347,7 +334,6 @@ class Theme * * @return string root dir for StatusNet themes */ - protected static function installRoot() { $instroot = common_config('theme', 'dir'); diff --git a/lib/themeuploader.php b/lib/themeuploader.php index 5a48e884e..b7b14d7b9 100644 --- a/lib/themeuploader.php +++ b/lib/themeuploader.php @@ -163,9 +163,10 @@ class ThemeUploader $estSize = $blockSize * max(1, intval(ceil($size / $blockSize))); $totalSize += $estSize; if ($totalSize > $sizeLimit) { - $msg = sprintf(_("Uploaded theme is too large; " . - "must be less than %d bytes uncompressed."), - $sizeLimit); + $msg = sprintf(_m('Uploaded theme is too large; must be less than %d byte uncompressed.', + 'Uploaded theme is too large; must be less than %d bytes uncompressed.', + $sizeLimit), + $sizeLimit); throw new ClientException($msg); } diff --git a/lib/uapplugin.php b/lib/uapplugin.php index 277781768..26d6a72d8 100644 --- a/lib/uapplugin.php +++ b/lib/uapplugin.php @@ -51,7 +51,6 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 * @link http://status.net/ */ - abstract class UAPPlugin extends Plugin { public $mediumRectangle = null; @@ -66,7 +65,6 @@ abstract class UAPPlugin extends Plugin * * @return boolean hook flag */ - function onEndShowStatusNetStyles($action) { // XXX: allow override by theme @@ -81,7 +79,6 @@ abstract class UAPPlugin extends Plugin * * @return boolean hook flag */ - function onStartShowAside($action) { if (!is_null($this->mediumRectangle)) { @@ -144,7 +141,6 @@ abstract class UAPPlugin extends Plugin * * @return boolean hook flag */ - function onStartShowSections($action) { if (!is_null($this->rectangle)) { @@ -165,7 +161,6 @@ abstract class UAPPlugin extends Plugin * * @return boolean hook flag */ - function onEndShowAside($action) { if (!is_null($this->wideSkyscraper)) { @@ -187,7 +182,6 @@ abstract class UAPPlugin extends Plugin * * @return void */ - abstract protected function showMediumRectangle($action); /** @@ -197,7 +191,6 @@ abstract class UAPPlugin extends Plugin * * @return void */ - abstract protected function showRectangle($action); /** @@ -207,7 +200,6 @@ abstract class UAPPlugin extends Plugin * * @return void */ - abstract protected function showWideSkyscraper($action); /** @@ -217,6 +209,5 @@ abstract class UAPPlugin extends Plugin * * @return void */ - abstract protected function showLeaderboard($action); } diff --git a/lib/unblockform.php b/lib/unblockform.php index b89d7ff78..8daad3c92 100644 --- a/lib/unblockform.php +++ b/lib/unblockform.php @@ -44,7 +44,6 @@ if (!defined('STATUSNET')) { * * @see BlockForm */ - class UnblockForm extends ProfileActionForm { /** @@ -52,7 +51,6 @@ class UnblockForm extends ProfileActionForm * * @return string Name of the action, lowercased. */ - function target() { return 'unblock'; @@ -63,11 +61,10 @@ class UnblockForm extends ProfileActionForm * * @return string Title of the form, internationalized */ - function title() { // TRANS: Title for the form to unblock a user. - return _('Unblock'); + return _m('TITLE','Unblock'); } /** @@ -75,7 +72,6 @@ class UnblockForm extends ProfileActionForm * * @return string description of the form, internationalized */ - function description() { // TRANS: Description of the form to unblock a user. diff --git a/lib/util.php b/lib/util.php index d50fa2081..ce5da1cd8 100644 --- a/lib/util.php +++ b/lib/util.php @@ -848,7 +848,7 @@ function common_linkify($url) { $canon = File_redirection::_canonUrl($url); - $longurl_data = File_redirection::where($canon); + $longurl_data = File_redirection::where($canon, common_config('attachments', 'process_links')); if (is_array($longurl_data)) { $longurl = $longurl_data['url']; } elseif (is_string($longurl_data)) { @@ -872,12 +872,14 @@ function common_linkify($url) { $f = File::staticGet('url', $longurl); if (empty($f)) { - // XXX: this writes to the database. :< - $f = File::processNew($longurl); + if (common_config('attachments', 'process_links')) { + // XXX: this writes to the database. :< + $f = File::processNew($longurl); + } } if (!empty($f)) { - if ($f->getEnclosure() || File_oembed::staticGet('file_id',$f->id)) { + if ($f->getEnclosure()) { $is_attachment = true; $attachment_id = $f->id; @@ -1010,7 +1012,7 @@ function common_group_link($sender_id, $nickname) $attrs = array('href' => $group->permalink(), 'class' => 'url'); if (!empty($group->fullname)) { - $attrs['title'] = $group->fullname . ' (' . $group->nickname . ')'; + $attrs['title'] = $group->getFancyName(); } $xs = new XMLStringer(); $xs->elementStart('span', 'vcard'); @@ -1499,6 +1501,7 @@ function common_request_id() function common_log($priority, $msg, $filename=null) { if(Event::handle('StartLog', array(&$priority, &$msg, &$filename))){ + $msg = (empty($filename)) ? $msg : basename($filename) . ' - ' . $msg; $msg = '[' . common_request_id() . '] ' . $msg; $logfile = common_config('site', 'logfile'); if ($logfile) { |