From a20e46b06126bd4495fcce0e9d27014bde91a7f5 Mon Sep 17 00:00:00 2001 From: epriestley Date: Sat, 9 Jul 2011 18:03:59 -0700 Subject: [PATCH] Provide a public view of feed Summary: Depends on D628. Provides a config option so you can set up a public feed, which you can iframe. This needs some work but sort of works. Test Plan: Loaded the public feed as a logged-out user. Reviewed By: codeblock Reviewers: jungejason, tuomaspelkonen, aran, codeblock CC: aran, codeblock Differential Revision: 635 --- conf/default.conf.php | 9 +++ src/__phutil_library_map__.php | 2 + ...AphrontDefaultApplicationConfiguration.php | 1 + .../base/PhabricatorFeedController.php | 7 ++ .../PhabricatorFeedPublicStreamController.php | 72 +++++++++++++++++++ .../feed/controller/publicstream/__init__.php | 19 +++++ 6 files changed, 110 insertions(+) create mode 100644 src/applications/feed/controller/publicstream/PhabricatorFeedPublicStreamController.php create mode 100644 src/applications/feed/controller/publicstream/__init__.php diff --git a/conf/default.conf.php b/conf/default.conf.php index 7e4dc0ab63..427cd084b2 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -416,6 +416,15 @@ return array( 'gcdaemon.ttl.differential-parse-cache' => 14 * (24 * 60 * 60), +// -- Feed ------------------------------------------------------------------ // + + // If you set this to true, you can embed Phabricator activity feeds in other + // pages using iframes. These feeds are completely public, and a login is not + // required to view them! This is intended for things like open source + // projects that want to expose an activity feed on the project homepage. + 'feed.public' => false, + + // -- Customization --------------------------------------------------------- // // Paths to additional phutil libraries to load. diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 976c022083..4745a3723b 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -341,6 +341,7 @@ phutil_register_library_map(array( 'PhabricatorFeedConstants' => 'applications/feed/constants/base', 'PhabricatorFeedController' => 'applications/feed/controller/base', 'PhabricatorFeedDAO' => 'applications/feed/storage/base', + 'PhabricatorFeedPublicStreamController' => 'applications/feed/controller/publicstream', 'PhabricatorFeedQuery' => 'applications/feed/query', 'PhabricatorFeedStory' => 'applications/feed/story/base', 'PhabricatorFeedStoryData' => 'applications/feed/storage/story', @@ -863,6 +864,7 @@ phutil_register_library_map(array( 'PhabricatorEmailTokenController' => 'PhabricatorAuthController', 'PhabricatorFeedController' => 'PhabricatorController', 'PhabricatorFeedDAO' => 'PhabricatorLiskDAO', + 'PhabricatorFeedPublicStreamController' => 'PhabricatorFeedController', 'PhabricatorFeedStoryData' => 'PhabricatorFeedDAO', 'PhabricatorFeedStoryDifferential' => 'PhabricatorFeedStory', 'PhabricatorFeedStoryReference' => 'PhabricatorFeedDAO', diff --git a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php index b2c8d29ac3..b3c66694db 100644 --- a/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php @@ -332,6 +332,7 @@ class AphrontDefaultApplicationConfiguration '/feed/' => array( '$' => 'PhabricatorFeedStreamController', + 'public/$' => 'PhabricatorFeedPublicStreamController', ), '/V(?P\d+)$' => 'PhabricatorSlowvotePollController', diff --git a/src/applications/feed/controller/base/PhabricatorFeedController.php b/src/applications/feed/controller/base/PhabricatorFeedController.php index 3d81bbfd69..28f59c43a4 100644 --- a/src/applications/feed/controller/base/PhabricatorFeedController.php +++ b/src/applications/feed/controller/base/PhabricatorFeedController.php @@ -28,6 +28,13 @@ abstract class PhabricatorFeedController extends PhabricatorController { $page->appendChild($view); $response = new AphrontWebpageResponse(); + + if (!empty($data['public'])) { + $page->setFrameable(true); + $page->setShowChrome(false); + $response->setFrameable(true); + } + return $response->setContent($page->render()); } diff --git a/src/applications/feed/controller/publicstream/PhabricatorFeedPublicStreamController.php b/src/applications/feed/controller/publicstream/PhabricatorFeedPublicStreamController.php new file mode 100644 index 0000000000..853c9c916a --- /dev/null +++ b/src/applications/feed/controller/publicstream/PhabricatorFeedPublicStreamController.php @@ -0,0 +1,72 @@ +getRequest(); + + $query = new PhabricatorFeedQuery(); + $stories = $query->execute(); + + $handles = array(); + $objects = array(); + if ($stories) { + $handle_phids = array_mergev(mpull($stories, 'getRequiredHandlePHIDs')); + $object_phids = array_mergev(mpull($stories, 'getRequiredObjectPHIDs')); + $handles = id(new PhabricatorObjectHandleData($handle_phids)) + ->loadHandles(); + $objects = id(new PhabricatorObjectHandleData($object_phids)) + ->loadObjects(); + } + + // TODO: We need this for timezones but should develop some more general + // solution for logged-out pages. + $dummy_user = new PhabricatorUser(); + + $views = array(); + foreach ($stories as $story) { + $story->setHandles($handles); + $story->setObjects($objects); + + $view = $story->renderView(); + $view->setViewer($dummy_user); + + $views[] = $view->render(); + } + + return $this->buildStandardPageResponse( + $views, + array( + 'title' => 'Public Feed', + 'public' => true, + )); + } +} diff --git a/src/applications/feed/controller/publicstream/__init__.php b/src/applications/feed/controller/publicstream/__init__.php new file mode 100644 index 0000000000..0227a49c7b --- /dev/null +++ b/src/applications/feed/controller/publicstream/__init__.php @@ -0,0 +1,19 @@ +