Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15412042
D14447.id34918.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
D14447.id34918.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2641,11 +2641,14 @@
'PhabricatorPhrictionApplication' => 'applications/phriction/application/PhabricatorPhrictionApplication.php',
'PhabricatorPhrictionConfigOptions' => 'applications/phriction/config/PhabricatorPhrictionConfigOptions.php',
'PhabricatorPhurlApplication' => 'applications/phurl/application/PhabricatorPhurlApplication.php',
+ 'PhabricatorPhurlConfigOptions' => 'applications/config/option/PhabricatorPhurlConfigOptions.php',
'PhabricatorPhurlController' => 'applications/phurl/controller/PhabricatorPhurlController.php',
'PhabricatorPhurlDAO' => 'applications/phurl/storage/PhabricatorPhurlDAO.php',
'PhabricatorPhurlLinkRemarkupRule' => 'applications/phurl/remarkup/PhabricatorPhurlLinkRemarkupRule.php',
'PhabricatorPhurlRemarkupRule' => 'applications/phurl/remarkup/PhabricatorPhurlRemarkupRule.php',
'PhabricatorPhurlSchemaSpec' => 'applications/phurl/storage/PhabricatorPhurlSchemaSpec.php',
+ 'PhabricatorPhurlShortURLController' => 'applications/phurl/controller/PhabricatorPhurlShortURLController.php',
+ 'PhabricatorPhurlShortURLDefaultController' => 'applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php',
'PhabricatorPhurlURL' => 'applications/phurl/storage/PhabricatorPhurlURL.php',
'PhabricatorPhurlURLAccessController' => 'applications/phurl/controller/PhabricatorPhurlURLAccessController.php',
'PhabricatorPhurlURLEditController' => 'applications/phurl/controller/PhabricatorPhurlURLEditController.php',
@@ -2954,6 +2957,7 @@
'PhabricatorSetupIssue' => 'applications/config/issue/PhabricatorSetupIssue.php',
'PhabricatorSetupIssueUIExample' => 'applications/uiexample/examples/PhabricatorSetupIssueUIExample.php',
'PhabricatorSetupIssueView' => 'applications/config/view/PhabricatorSetupIssueView.php',
+ 'PhabricatorShortSite' => 'aphront/site/PhabricatorShortSite.php',
'PhabricatorSimpleEditType' => 'applications/transactions/edittype/PhabricatorSimpleEditType.php',
'PhabricatorSite' => 'aphront/site/PhabricatorSite.php',
'PhabricatorSlowvoteApplication' => 'applications/slowvote/application/PhabricatorSlowvoteApplication.php',
@@ -6774,11 +6778,14 @@
'PhabricatorPhrictionApplication' => 'PhabricatorApplication',
'PhabricatorPhrictionConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPhurlApplication' => 'PhabricatorApplication',
+ 'PhabricatorPhurlConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorPhurlController' => 'PhabricatorController',
'PhabricatorPhurlDAO' => 'PhabricatorLiskDAO',
'PhabricatorPhurlLinkRemarkupRule' => 'PhutilRemarkupRule',
'PhabricatorPhurlRemarkupRule' => 'PhabricatorObjectRemarkupRule',
'PhabricatorPhurlSchemaSpec' => 'PhabricatorConfigSchemaSpec',
+ 'PhabricatorPhurlShortURLController' => 'PhabricatorPhurlController',
+ 'PhabricatorPhurlShortURLDefaultController' => 'PhabricatorPhurlController',
'PhabricatorPhurlURL' => array(
'PhabricatorPhurlDAO',
'PhabricatorPolicyInterface',
@@ -7167,6 +7174,7 @@
'PhabricatorSetupIssue' => 'Phobject',
'PhabricatorSetupIssueUIExample' => 'PhabricatorUIExample',
'PhabricatorSetupIssueView' => 'AphrontView',
+ 'PhabricatorShortSite' => 'PhabricatorSite',
'PhabricatorSimpleEditType' => 'PhabricatorEditType',
'PhabricatorSite' => 'AphrontSite',
'PhabricatorSlowvoteApplication' => 'PhabricatorApplication',
diff --git a/src/aphront/site/PhabricatorShortSite.php b/src/aphront/site/PhabricatorShortSite.php
new file mode 100644
--- /dev/null
+++ b/src/aphront/site/PhabricatorShortSite.php
@@ -0,0 +1,38 @@
+<?php
+
+final class PhabricatorShortSite extends PhabricatorSite {
+
+ public function getDescription() {
+ return pht("Serves shortened URL's.");
+ }
+
+ public function getPriority() {
+ return 2000;
+ }
+
+ public function newSiteForRequest(AphrontRequest $request) {
+ $host = $request->getHost();
+
+ $uri = PhabricatorEnv::getEnvConfig('phurl.short-uri');
+ if (!strlen($uri)) {
+ return null;
+ }
+
+ if ($this->isHostMatch($host, array($uri))) {
+ return new PhabricatorShortSite();
+ }
+
+ return null;
+ }
+
+ public function getRoutingMaps() {
+ $app = PhabricatorApplication::getByClass('PhabricatorPhurlApplication');
+
+ $maps = array();
+ $maps[] = $this->newRoutingMap()
+ ->setApplication($app)
+ ->setRoutes($app->getShortRoutes());
+ return $maps;
+ }
+
+}
diff --git a/src/applications/config/option/PhabricatorPhurlConfigOptions.php b/src/applications/config/option/PhabricatorPhurlConfigOptions.php
new file mode 100644
--- /dev/null
+++ b/src/applications/config/option/PhabricatorPhurlConfigOptions.php
@@ -0,0 +1,34 @@
+<?php
+
+final class PhabricatorPhurlConfigOptions
+ extends PhabricatorApplicationConfigOptions {
+
+ public function getName() {
+ return pht('Phurl');
+ }
+
+ public function getDescription() {
+ return pht('Options for Phurl short domains.');
+ }
+
+ public function getFontIcon() {
+ return 'fa-link';
+ }
+
+ public function getGroup() {
+ return 'core';
+ }
+
+ public function getOptions() {
+ return array(
+ $this->newOption('phurl.short-uri', 'string', false)
+ ->setLocked(true)
+ ->setSummary(pht("URI that Phurl will use to shorten URL's."))
+ ->setDefault('http://www.zz.us')
+ ->setDescription(
+ pht(
+ "Set the URI that Phurl will use to share shortened URL's."))
+ ->addExample('http://ph.ly/', pht('Valid Setting')),
+ );
+ }
+}
diff --git a/src/applications/phurl/application/PhabricatorPhurlApplication.php b/src/applications/phurl/application/PhabricatorPhurlApplication.php
--- a/src/applications/phurl/application/PhabricatorPhurlApplication.php
+++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php
@@ -51,4 +51,12 @@
);
}
+ public function getShortRoutes() {
+ return array(
+ '/u/(?P<id>[1-9]\d*)' => 'PhabricatorPhurlShortURLController',
+ '/u/(?P<alias>[^/]+)' => 'PhabricatorPhurlShortURLController',
+ '.*' => 'PhabricatorPhurlShortURLDefaultController',
+ );
+ }
+
}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlShortURLController.php b/src/applications/phurl/controller/PhabricatorPhurlShortURLController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phurl/controller/PhabricatorPhurlShortURLController.php
@@ -0,0 +1,23 @@
+<?php
+
+final class PhabricatorPhurlShortURLController
+ extends PhabricatorPhurlController {
+
+ public function handleRequest(AphrontRequest $request) {
+ $viewer = $this->getViewer();
+ $id = $request->getURIData('id');
+ $alias = $request->getURIData('alias');
+
+ $append = $id ? $id : $alias;
+
+ $main_domain_uri = PhabricatorEnv::getProductionURI('/u/'.$append);
+ return id(new AphrontRedirectResponse())
+ ->setIsExternal(true)
+ ->setURI($main_domain_uri);
+ }
+
+ public function shouldRequireLogin() {
+ return false;
+ }
+
+}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php b/src/applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php
@@ -0,0 +1,14 @@
+<?php
+
+final class PhabricatorPhurlShortURLDefaultController
+ extends PhabricatorPhurlController {
+
+ public function handleRequest(AphrontRequest $request) {
+ return new Aphront404Response();
+ }
+
+ public function shouldRequireLogin() {
+ return false;
+ }
+
+}
diff --git a/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php b/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
--- a/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
+++ b/src/applications/phurl/controller/PhabricatorPhurlURLAccessController.php
@@ -33,4 +33,8 @@
}
}
+ public function shouldAllowPublic() {
+ return true;
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Mar 20, 11:00 AM (2 d, 16 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7582897
Default Alt Text
D14447.id34918.diff (8 KB)
Attached To
Mode
D14447: Allow a domain other than the install domain to serve as a short Phurl domain
Attached
Detach File
Event Timeline
Log In to Comment