From 19e10b2b5d71afabfe037a2250637e0414c95831 Mon Sep 17 00:00:00 2001 From: tuomaspelkonen Date: Fri, 27 May 2011 12:50:02 -0700 Subject: [PATCH] Embedded youtube videos. Summary: Markup support for embedding Youtube videos. Test Plan: https://www.youtube.com/watch?v=Vw4KVoEVcr0 was embedded Reviewed By: epriestley Reviewers: epriestley CC: aran, epriestley Differential Revision: 353 --- conf/default.conf.php | 4 ++ src/__phutil_library_map__.php | 2 + .../DifferentialMarkupEngineFactory.php | 5 ++ .../differential/parser/markup/__init__.php | 1 + .../PhabricatorRemarkupRuleYoutube.php | 53 +++++++++++++++++++ .../remarkup/markuprule/youtube/__init__.php | 13 +++++ 6 files changed, 78 insertions(+) create mode 100644 src/infrastructure/markup/remarkup/markuprule/youtube/PhabricatorRemarkupRuleYoutube.php create mode 100644 src/infrastructure/markup/remarkup/markuprule/youtube/__init__.php diff --git a/conf/default.conf.php b/conf/default.conf.php index 831059cb81..897b0f5734 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -339,6 +339,10 @@ return array( 'maniphest.enabled' => true, +// -- Remarkup -------------------------------------------------------------- // + + 'remarkup.enable-embedded-youtube' => false, + // -- Customization --------------------------------------------------------- // // Paths to additional phutil libraries to load. diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 18f18faec6..0a91f59874 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -410,6 +410,7 @@ phutil_register_library_map(array( 'PhabricatorRemarkupRuleImageMacro' => 'infrastructure/markup/remarkup/markuprule/imagemacro', 'PhabricatorRemarkupRuleManiphest' => 'infrastructure/markup/remarkup/markuprule/maniphest', 'PhabricatorRemarkupRuleProxyImage' => 'infrastructure/markup/remarkup/markuprule/proxyimage', + 'PhabricatorRemarkupRuleYoutube' => 'infrastructure/markup/remarkup/markuprule/youtube', 'PhabricatorRepository' => 'applications/repository/storage/repository', 'PhabricatorRepositoryArcanistProject' => 'applications/repository/storage/arcanistproject', 'PhabricatorRepositoryArcanistProjectEditController' => 'applications/repository/controller/arcansistprojectedit', @@ -843,6 +844,7 @@ phutil_register_library_map(array( 'PhabricatorRemarkupRuleImageMacro' => 'PhutilRemarkupRule', 'PhabricatorRemarkupRuleManiphest' => 'PhutilRemarkupRule', 'PhabricatorRemarkupRuleProxyImage' => 'PhutilRemarkupRule', + 'PhabricatorRemarkupRuleYoutube' => 'PhutilRemarkupRule', 'PhabricatorRepository' => 'PhabricatorRepositoryDAO', 'PhabricatorRepositoryArcanistProject' => 'PhabricatorRepositoryDAO', 'PhabricatorRepositoryArcanistProjectEditController' => 'PhabricatorRepositoryController', diff --git a/src/applications/differential/parser/markup/DifferentialMarkupEngineFactory.php b/src/applications/differential/parser/markup/DifferentialMarkupEngineFactory.php index 297b111000..00c4e38849 100644 --- a/src/applications/differential/parser/markup/DifferentialMarkupEngineFactory.php +++ b/src/applications/differential/parser/markup/DifferentialMarkupEngineFactory.php @@ -31,6 +31,11 @@ class DifferentialMarkupEngineFactory { if (PhabricatorEnv::getEnvConfig('files.enable-proxy')) { $rules[] = new PhabricatorRemarkupRuleProxyImage(); } + + if (PhabricatorEnv::getEnvConfig('remarkup.enable-embedded-youtube')) { + $rules[] = new PhabricatorRemarkupRuleYoutube(); + } + $rules[] = new PhutilRemarkupRuleHyperlink(); $rules[] = new PhabricatorRemarkupRuleDifferential(); diff --git a/src/applications/differential/parser/markup/__init__.php b/src/applications/differential/parser/markup/__init__.php index 2a4ccd6556..bcd31d17e2 100644 --- a/src/applications/differential/parser/markup/__init__.php +++ b/src/applications/differential/parser/markup/__init__.php @@ -12,6 +12,7 @@ phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/ phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/imagemacro'); phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/maniphest'); phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/proxyimage'); +phutil_require_module('phabricator', 'infrastructure/markup/remarkup/markuprule/youtube'); phutil_require_module('phutil', 'markup/engine/remarkup'); phutil_require_module('phutil', 'markup/engine/remarkup/blockrule/remarkupcode'); diff --git a/src/infrastructure/markup/remarkup/markuprule/youtube/PhabricatorRemarkupRuleYoutube.php b/src/infrastructure/markup/remarkup/markuprule/youtube/PhabricatorRemarkupRuleYoutube.php new file mode 100644 index 0000000000..bf6a7e7dae --- /dev/null +++ b/src/infrastructure/markup/remarkup/markuprule/youtube/PhabricatorRemarkupRuleYoutube.php @@ -0,0 +1,53 @@ +uri = new PhutilURI($text); + + if ($this->uri->getDomain() && + preg_match('/youtube\.com$/', $this->uri->getDomain())) { + return $this->markupYoutubeLink(); + } + + return $text; + } + + public function markupYoutubeLink() { + $v = idx($this->uri->getQueryParams(), 'v'); + if ($v) { + $youtube_src = 'https://www.youtube.com/embed/'.$v; + $iframe = + '
+ +
'; + return $this->getEngine()->storeText($iframe); + } else { + return $this->uri; + } + } + +} diff --git a/src/infrastructure/markup/remarkup/markuprule/youtube/__init__.php b/src/infrastructure/markup/remarkup/markuprule/youtube/__init__.php new file mode 100644 index 0000000000..29225031f1 --- /dev/null +++ b/src/infrastructure/markup/remarkup/markuprule/youtube/__init__.php @@ -0,0 +1,13 @@ +