diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b9b654a572..a5b33bc14d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2641,11 +2641,14 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( '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 @@ phutil_register_library_map(array( '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 index 0000000000..d4c36aecbe --- /dev/null +++ b/src/aphront/site/PhabricatorShortSite.php @@ -0,0 +1,44 @@ +getHost(); + + $uri = PhabricatorEnv::getEnvConfig('phurl.short-uri'); + if (!strlen($uri)) { + return null; + } + + $phurl_installed = PhabricatorApplication::isClassInstalled( + 'PhabricatorPhurlApplication'); + if (!$phurl_installed) { + return false; + } + + 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 index 0000000000..378724a4b5 --- /dev/null +++ b/src/applications/config/option/PhabricatorPhurlConfigOptions.php @@ -0,0 +1,35 @@ +newOption('phurl.short-uri', 'string', null) + ->setLocked(true) + ->setSummary(pht('URI that Phurl will use to shorten URLs.')) + ->setDescription( + pht( + 'Set the URI that Phurl will use to share shortened URLs.')) + ->addExample( + 'https://some-very-short-domain.museum/', + pht('Valid Setting')), + ); + } +} diff --git a/src/applications/phurl/application/PhabricatorPhurlApplication.php b/src/applications/phurl/application/PhabricatorPhurlApplication.php index 7b01a3f4c5..015ed75fe7 100644 --- a/src/applications/phurl/application/PhabricatorPhurlApplication.php +++ b/src/applications/phurl/application/PhabricatorPhurlApplication.php @@ -51,4 +51,11 @@ final class PhabricatorPhurlApplication extends PhabricatorApplication { ); } + public function getShortRoutes() { + return array( + '/u/(?P[^/]+)' => 'PhabricatorPhurlShortURLController', + '.*' => 'PhabricatorPhurlShortURLDefaultController', + ); + } + } diff --git a/src/applications/phurl/controller/PhabricatorPhurlShortURLController.php b/src/applications/phurl/controller/PhabricatorPhurlShortURLController.php new file mode 100644 index 0000000000..b4f97d6813 --- /dev/null +++ b/src/applications/phurl/controller/PhabricatorPhurlShortURLController.php @@ -0,0 +1,19 @@ +getViewer(); + $append = $request->getURIData('append'); + $main_domain_uri = PhabricatorEnv::getProductionURI('/u/'.$append); + + return id(new AphrontRedirectResponse()) + ->setIsExternal(true) + ->setURI($main_domain_uri); + } +} diff --git a/src/applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php b/src/applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php new file mode 100644 index 0000000000..7d48f56e24 --- /dev/null +++ b/src/applications/phurl/controller/PhabricatorPhurlShortURLDefaultController.php @@ -0,0 +1,13 @@ +getViewer(); $id = $request->getURIData('id'); @@ -32,5 +36,4 @@ final class PhabricatorPhurlURLAccessController return id(new AphrontRedirectResponse())->setURI('/'.$url->getMonogram()); } } - }