From a6ab9c4a3e820b9d293075b1fec8b5eb05df87e9 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 11 Feb 2010 16:42:58 -0500 Subject: Themes can be served from an SSL server --- lib/default.php | 3 ++- lib/theme.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/default.php b/lib/default.php index bf4b83718..1a2cc4cf6 100644 --- a/lib/default.php +++ b/lib/default.php @@ -123,7 +123,8 @@ $default = 'theme' => array('server' => null, 'dir' => null, - 'path'=> null), + 'path'=> null, + 'ssl' => false), 'javascript' => array('server' => null, 'path'=> null), diff --git a/lib/theme.php b/lib/theme.php index 020ce1ac4..bed631d9c 100644 --- a/lib/theme.php +++ b/lib/theme.php @@ -110,9 +110,9 @@ class Theme $server = common_config('site', 'server'); } - // XXX: protocol + $protocol = common_config('theme', 'ssl') ? 'https' : 'http'; - $this->path = 'http://'.$server.$path.$name; + $this->path = $protocol . '://'.$server.$path.$name; } } -- cgit v1.2.3-54-g00ecf From 316ed3f86b60150d66460b478bf7146811bb6bb1 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 11 Feb 2010 16:47:47 -0500 Subject: null theme ssl setting means 'guess' --- README | 2 ++ lib/theme.php | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README b/README index 9b4147645..2b021b36c 100644 --- a/README +++ b/README @@ -1221,6 +1221,8 @@ path: Path part of theme URLs, before the theme name. Relative to the (using version numbers as the path) to make sure that all files are reloaded by caching clients or proxies. Defaults to null, which means to use the site path + '/theme'. +ssl: Whether to use SSL for theme elements. Default is null, which means + guess based on site SSL settings. xmpp ---- diff --git a/lib/theme.php b/lib/theme.php index bed631d9c..0be8c3b9d 100644 --- a/lib/theme.php +++ b/lib/theme.php @@ -110,7 +110,18 @@ class Theme $server = common_config('site', 'server'); } - $protocol = common_config('theme', 'ssl') ? 'https' : 'http'; + $ssl = common_config('theme', 'ssl'); + + if (is_null($ssl)) { // null -> guess + if (common_config('site', 'ssl') == 'always' && + !common_config('theme', 'server')) { + $ssl = true; + } else { + $ssl = false; + } + } + + $protocol = ($ssl) ? 'https' : 'http'; $this->path = $protocol . '://'.$server.$path.$name; } -- cgit v1.2.3-54-g00ecf From 5175b5062ea7635016a392496e8495d03d71a4ae Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 11 Feb 2010 16:48:15 -0500 Subject: default theme ssl to null --- lib/default.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/default.php b/lib/default.php index 1a2cc4cf6..fd6831fa9 100644 --- a/lib/default.php +++ b/lib/default.php @@ -124,7 +124,7 @@ $default = array('server' => null, 'dir' => null, 'path'=> null, - 'ssl' => false), + 'ssl' => null), 'javascript' => array('server' => null, 'path'=> null), -- cgit v1.2.3-54-g00ecf From d6869cde7ba7e577d54f0c6ecab3599dc85f0f67 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 11 Feb 2010 16:51:15 -0500 Subject: let avatars be served over SSL --- README | 2 ++ classes/Avatar.php | 15 +++++++++++++-- lib/default.php | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README b/README index 2b021b36c..9843ab89b 100644 --- a/README +++ b/README @@ -1192,6 +1192,8 @@ server: If set, defines another server where avatars are stored in the typically only make 2 connections to a single server at a time , so this can parallelize the job. Defaults to null. +ssl: Whether to access avatars using HTTPS. Defaults to null, meaning + to guess based on site-wide SSL settings. public ------ diff --git a/classes/Avatar.php b/classes/Avatar.php index 91bde0f04..dbe2cd813 100644 --- a/classes/Avatar.php +++ b/classes/Avatar.php @@ -82,9 +82,20 @@ class Avatar extends Memcached_DataObject $server = common_config('site', 'server'); } - // XXX: protocol + $ssl = common_config('avatar', 'ssl'); + + if (is_null($ssl)) { // null -> guess + if (common_config('site', 'ssl') == 'always' && + !common_config('avatar', 'server')) { + $ssl = true; + } else { + $ssl = false; + } + } + + $protocol = ($ssl) ? 'https' : 'http'; - return 'http://'.$server.$path.$filename; + return $protocol.'://'.$server.$path.$filename; } function displayUrl() diff --git a/lib/default.php b/lib/default.php index fd6831fa9..d19e04036 100644 --- a/lib/default.php +++ b/lib/default.php @@ -111,7 +111,8 @@ $default = 'avatar' => array('server' => null, 'dir' => INSTALLDIR . '/avatar/', - 'path' => $_path . '/avatar/'), + 'path' => $_path . '/avatar/', + 'ssl' => null), 'background' => array('server' => null, 'dir' => INSTALLDIR . '/background/', -- cgit v1.2.3-54-g00ecf From b96af33d978bddfa66aa893ff1d59f2d83903afa Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 11 Feb 2010 16:59:39 -0500 Subject: put Javascript files under SSL --- README | 11 +++++++++++ lib/default.php | 3 ++- lib/htmloutputter.php | 15 +++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README b/README index 9843ab89b..7531df997 100644 --- a/README +++ b/README @@ -1226,6 +1226,17 @@ path: Path part of theme URLs, before the theme name. Relative to the ssl: Whether to use SSL for theme elements. Default is null, which means guess based on site SSL settings. +javascript +---------- + +server: You can speed up page loading by pointing the + theme file lookup to another server (virtual or real). + Defaults to NULL, meaning to use the site server. +path: Path part of Javascript URLs. Defaults to null, + which means to use the site path + '/js/'. +ssl: Whether to use SSL for JavaScript files. Default is null, which means + guess based on site SSL settings. + xmpp ---- diff --git a/lib/default.php b/lib/default.php index d19e04036..8a21271b8 100644 --- a/lib/default.php +++ b/lib/default.php @@ -128,7 +128,8 @@ $default = 'ssl' => null), 'javascript' => array('server' => null, - 'path'=> null), + 'path'=> null, + 'ssl' => null), 'throttle' => array('enabled' => false, // whether to throttle edits; false by default 'count' => 20, // number of allowed messages in timespan diff --git a/lib/htmloutputter.php b/lib/htmloutputter.php index 317f5ea61..47e56fc8f 100644 --- a/lib/htmloutputter.php +++ b/lib/htmloutputter.php @@ -376,9 +376,20 @@ class HTMLOutputter extends XMLOutputter $server = common_config('site', 'server'); } - // XXX: protocol + $ssl = common_config('javascript', 'ssl'); + + if (is_null($ssl)) { // null -> guess + if (common_config('site', 'ssl') == 'always' && + !common_config('javascript', 'server')) { + $ssl = true; + } else { + $ssl = false; + } + } + + $protocol = ($ssl) ? 'https' : 'http'; - $src = 'http://'.$server.$path.$src . '?version=' . STATUSNET_VERSION; + $src = $protocol.'://'.$server.$path.$src . '?version=' . STATUSNET_VERSION; } $this->element('script', array('type' => $type, -- cgit v1.2.3-54-g00ecf From 3018683718bd73bf00472622f9e81914703d50a7 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 11 Feb 2010 17:03:31 -0500 Subject: let backgrounds be put under SSL --- README | 2 ++ classes/Design.php | 15 +++++++++++++-- lib/default.php | 3 ++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/README b/README index 7531df997..3b2baaeeb 100644 --- a/README +++ b/README @@ -1521,6 +1521,8 @@ dir: directory to write backgrounds too. Default is '/background/' subdir of install dir. path: path to backgrounds. Default is sub-path of install path; note that you may need to change this if you change site-path too. +ssl: Whether or not to use HTTPS for background files. Defaults to + null, meaning to guess from site-wide SSL settings. ping ---- diff --git a/classes/Design.php b/classes/Design.php index 4e7d7dfb2..ff44e0109 100644 --- a/classes/Design.php +++ b/classes/Design.php @@ -155,9 +155,20 @@ class Design extends Memcached_DataObject $server = common_config('site', 'server'); } - // XXX: protocol + $ssl = common_config('background', 'ssl'); + + if (is_null($ssl)) { // null -> guess + if (common_config('site', 'ssl') == 'always' && + !common_config('background', 'server')) { + $ssl = true; + } else { + $ssl = false; + } + } + + $protocol = ($ssl) ? 'https' : 'http'; - return 'http://'.$server.$path.$filename; + return $protocol.'://'.$server.$path.$filename; } function setDisposition($on, $off, $tile) diff --git a/lib/default.php b/lib/default.php index 8a21271b8..0822654f6 100644 --- a/lib/default.php +++ b/lib/default.php @@ -116,7 +116,8 @@ $default = 'background' => array('server' => null, 'dir' => INSTALLDIR . '/background/', - 'path' => $_path . '/background/'), + 'path' => $_path . '/background/', + 'ssl' => null), 'public' => array('localonly' => true, 'blacklist' => array(), -- cgit v1.2.3-54-g00ecf From 31461e120f23416c8c4979805900e3018fb2a6fd Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 11 Feb 2010 17:06:57 -0500 Subject: let files go to SSL dir too --- README | 2 ++ classes/File.php | 15 +++++++++++++-- lib/default.php | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README b/README index 3b2baaeeb..75336eb83 100644 --- a/README +++ b/README @@ -1462,6 +1462,8 @@ server: server name to use when creating URLs for uploaded files. a virtual server here can speed up Web performance. path: URL path, relative to the server, to find files. Defaults to main path + '/file/'. +ssl: whether to use HTTPS for file URLs. Defaults to null, meaning to + guess based on other SSL settings. filecommand: command to use for determining the type of a file. May be skipped if fileinfo extension is installed. Defaults to '/usr/bin/file'. diff --git a/classes/File.php b/classes/File.php index ee418a802..91b12d2e2 100644 --- a/classes/File.php +++ b/classes/File.php @@ -228,9 +228,20 @@ class File extends Memcached_DataObject $server = common_config('site', 'server'); } - // XXX: protocol + $ssl = common_config('attachments', 'ssl'); - return 'http://'.$server.$path.$filename; + if (is_null($ssl)) { // null -> guess + if (common_config('site', 'ssl') == 'always' && + !common_config('attachments', 'server')) { + $ssl = true; + } else { + $ssl = false; + } + } + + $protocol = ($ssl) ? 'https' : 'http'; + + return $protocol.'://'.$server.$path.$filename; } } diff --git a/lib/default.php b/lib/default.php index 0822654f6..8b1fe2769 100644 --- a/lib/default.php +++ b/lib/default.php @@ -188,6 +188,7 @@ $default = array('server' => null, 'dir' => INSTALLDIR . '/file/', 'path' => $_path . '/file/', + 'ssl' => null, 'supported' => array('image/png', 'image/jpeg', 'image/gif', -- cgit v1.2.3-54-g00ecf From f3a82e787c70e8cf749c79f22fe37ce6c9c9d4d3 Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Fri, 12 Feb 2010 19:00:35 -0800 Subject: Add OStatus PuSH hub and Salmon links back into user and group feeds --- actions/apitimelinegroup.php | 14 +++++++- actions/apitimelineuser.php | 14 +++++++- lib/api.php | 1 - lib/atom10feed.php | 21 +++++++----- lib/atomgroupnoticefeed.php | 67 +++++++++++++++++++++++++++++++++++++++ lib/atomnoticefeed.php | 4 ++- lib/atomusernoticefeed.php | 66 ++++++++++++++++++++++++++++++++++++++ plugins/OStatus/OStatusPlugin.php | 37 +++++++++++---------- 8 files changed, 193 insertions(+), 31 deletions(-) create mode 100644 lib/atomgroupnoticefeed.php create mode 100644 lib/atomusernoticefeed.php diff --git a/actions/apitimelinegroup.php b/actions/apitimelinegroup.php index 45962fa76..3c74e36b5 100644 --- a/actions/apitimelinegroup.php +++ b/actions/apitimelinegroup.php @@ -138,7 +138,19 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction try { - $atom = new AtomNoticeFeed(); + // If this was called using an integer ID, i.e.: using the canonical + // URL for this group's feed, then pass the Group object into the feed, + // so the OStatus plugin, and possibly other plugins, can access it. + // Feels sorta hacky. -- Z + + $atom = null; + $id = $this->arg('id'); + + if (strval(intval($id)) === strval($id)) { + $atom = new AtomGroupNoticeFeed($this->group); + } else { + $atom = new AtomGroupNoticeFeed(); + } $atom->setId($id); $atom->setTitle($title); diff --git a/actions/apitimelineuser.php b/actions/apitimelineuser.php index d20bb0d20..24752e45f 100644 --- a/actions/apitimelineuser.php +++ b/actions/apitimelineuser.php @@ -148,7 +148,19 @@ class ApiTimelineUserAction extends ApiBareAuthAction header('Content-Type: application/atom+xml; charset=utf-8'); - $atom = new AtomNoticeFeed(); + // If this was called using an integer ID, i.e.: using the canonical + // URL for this user's feed, then pass the User object into the feed, + // so the OStatus plugin, and possibly other plugins, can access it. + // Feels sorta hacky. -- Z + + $atom = null; + $id = $this->arg('id'); + + if (strval(intval($id)) === strval($id)) { + $atom = new AtomUserNoticeFeed($this->user); + } else { + $atom = new AtomUserNoticeFeed(); + } $atom->setId($id); $atom->setTitle($title); diff --git a/lib/api.php b/lib/api.php index 494b595d1..22eef7436 100644 --- a/lib/api.php +++ b/lib/api.php @@ -1154,7 +1154,6 @@ class ApiAction extends Action $this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en-US', 'xmlns:thr' => 'http://purl.org/syndication/thread/1.0')); - Event::handle('StartApiAtom', array($this)); } function endTwitterAtom() diff --git a/lib/atom10feed.php b/lib/atom10feed.php index 806a9684b..14a3beb83 100644 --- a/lib/atom10feed.php +++ b/lib/atom10feed.php @@ -175,6 +175,8 @@ class Atom10Feed extends XMLStringer $this->element('updated', null, $this->updated); + $this->renderAuthors(); + $this->renderLinks(); } @@ -221,17 +223,20 @@ class Atom10Feed extends XMLStringer function getString() { - $this->validate(); + if (Event::handle('StartApiAtom', array($this))) { - $this->initFeed(); - $this->renderAuthors(); + $this->validate(); + $this->initFeed(); - if (!empty($this->subject)) { - $this->raw($this->subject); - } + if (!empty($this->subject)) { + $this->raw($this->subject); + } + + $this->renderEntries(); + $this->endFeed(); - $this->renderEntries(); - $this->endFeed(); + Event::handle('EndApiAtom', array($this)); + } return $this->xw->outputMemory(); } diff --git a/lib/atomgroupnoticefeed.php b/lib/atomgroupnoticefeed.php new file mode 100644 index 000000000..52ee4c7d6 --- /dev/null +++ b/lib/atomgroupnoticefeed.php @@ -0,0 +1,67 @@ +. + * + * @category Feed + * @package StatusNet + * @author Zach Copley + * @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 for group notice feeds. May contains a reference to the group. + * + * @category Feed + * @package StatusNet + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ +class AtomGroupNoticeFeed extends AtomNoticeFeed +{ + private $group; + + /** + * Constructor + * + * @param Group $group the group for the feed (optional) + * @param boolean $indent flag to turn indenting on or off + * + * @return void + */ + function __construct($group = null, $indent = true) { + parent::__construct($indent); + $this->group = $group; + } + + function getGroup() + { + return $this->group; + } + +} diff --git a/lib/atomnoticefeed.php b/lib/atomnoticefeed.php index 34ed44b2e..b7a60bde6 100644 --- a/lib/atomnoticefeed.php +++ b/lib/atomnoticefeed.php @@ -2,7 +2,7 @@ /** * StatusNet, the distributed open-source microblogging tool * - * Class for building and Atom feed from a collection of notices + * Class for building an Atom feed from a collection of notices * * PHP version 5 * @@ -101,3 +101,5 @@ class AtomNoticeFeed extends Atom10Feed } } + + diff --git a/lib/atomusernoticefeed.php b/lib/atomusernoticefeed.php new file mode 100644 index 000000000..9f224325c --- /dev/null +++ b/lib/atomusernoticefeed.php @@ -0,0 +1,66 @@ +. + * + * @category Feed + * @package StatusNet + * @author Zach Copley + * @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 for user notice feeds. May contain a reference to the user. + * + * @category Feed + * @package StatusNet + * @author Zach Copley + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ +class AtomUserNoticeFeed extends AtomNoticeFeed +{ + private $user; + + /** + * Constructor + * + * @param User $user the user for the feed (optional) + * @param boolean $indent flag to turn indenting on or off + * + * @return void + */ + function __construct($user = null, $indent = true) { + parent::__construct($indent); + $this->user = $user; + } + + function getUser() + { + return $this->user; + } +} diff --git a/plugins/OStatus/OStatusPlugin.php b/plugins/OStatus/OStatusPlugin.php index 8444c3d73..bf7dde296 100644 --- a/plugins/OStatus/OStatusPlugin.php +++ b/plugins/OStatus/OStatusPlugin.php @@ -63,9 +63,9 @@ class OStatusPlugin extends Plugin $m->connect('main/ostatus?nickname=:nickname', array('action' => 'ostatusinit'), array('nickname' => '[A-Za-z0-9_-]+')); $m->connect('main/ostatussub', - array('action' => 'ostatussub')); + array('action' => 'ostatussub')); $m->connect('main/ostatussub', - array('action' => 'ostatussub'), array('feed' => '[A-Za-z0-9\.\/\:]+')); + array('action' => 'ostatussub'), array('feed' => '[A-Za-z0-9\.\/\:]+')); // PuSH actions $m->connect('main/push/hub', array('action' => 'pushhub')); @@ -112,35 +112,34 @@ class OStatusPlugin extends Plugin * Set up a PuSH hub link to our internal link for canonical timeline * Atom feeds for users and groups. */ - function onStartApiAtom(Action $action) + function onStartApiAtom(AtomNoticeFeed $feed) { - if ($action instanceof ApiTimelineUserAction) { + $id = null; + + if ($feed instanceof AtomUserNoticeFeed) { $salmonAction = 'salmon'; - } else if ($action instanceof ApiTimelineGroupAction) { + $id = $feed->getUser()->id; + } else if ($feed instanceof AtomGroupNoticeFeed) { $salmonAction = 'salmongroup'; + $id = $feed->getGroup()->id; } else { return; } - $id = $action->arg('id'); - if (strval(intval($id)) === strval($id)) { - // Canonical form of id in URL? These are used for OStatus syndication. - + if (!empty($id)) { $hub = common_config('ostatus', 'hub'); if (empty($hub)) { // Updates will be handled through our internal PuSH hub. $hub = common_local_url('pushhub'); } - $action->element('link', array('rel' => 'hub', - 'href' => $hub)); + $feed->addLink($hub, array('rel' => 'hub')); // Also, we'll add in the salmon link $salmon = common_local_url($salmonAction, array('id' => $id)); - $action->element('link', array('rel' => 'salmon', - 'href' => $salmon)); + $feed->addLink($salmon, array('rel' => 'salmon')); } } - + /** * Add the feed settings page to the Connect Settings menu * @@ -201,7 +200,7 @@ class OStatusPlugin extends Plugin $output->element('a', array('href' => $url, 'class' => 'entity_remote_subscribe'), _m('OStatus')); - + $output->elementEnd('li'); } } @@ -221,25 +220,25 @@ class OStatusPlugin extends Plugin $w = new Webfinger; $endpoint_uri = ''; - + $result = $w->lookup($webfinger); if (empty($result)) { continue; } - + foreach ($result->links as $link) { if ($link['rel'] == 'salmon') { $endpoint_uri = $link['href']; } } - + if (empty($endpoint_uri)) { continue; } $xml = ''; $xml .= $notice->asAtomEntry(); - + $salmon = new Salmon(); $salmon->post($endpoint_uri, $xml); } -- cgit v1.2.3-54-g00ecf From fc19179bc54de1837bbc64f052a93628be9c6a3d Mon Sep 17 00:00:00 2001 From: Sarven Capadisli Date: Sat, 13 Feb 2010 18:40:36 +0100 Subject: Added event hook to remote subscription --- EVENTS.txt | 10 +++++++++- lib/userprofile.php | 9 ++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/EVENTS.txt b/EVENTS.txt index 6bf12bf13..69fe2ddcc 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -1,4 +1,4 @@ -InitializePlugin: a chance to initialize a plugin in a complete environment +\InitializePlugin: a chance to initialize a plugin in a complete environment CleanupPlugin: a chance to cleanup a plugin at the end of a program @@ -355,6 +355,14 @@ EndShowHeadElements: Right before the tag; put