2011-07-15 23:17:55 +02:00
|
|
|
<?php
|
|
|
|
|
2014-08-04 16:55:43 +02:00
|
|
|
final class PhabricatorEmbedFileRemarkupRule
|
|
|
|
extends PhabricatorObjectRemarkupRule {
|
2011-07-15 23:17:55 +02:00
|
|
|
|
2013-01-25 02:23:05 +01:00
|
|
|
const KEY_EMBED_FILE_PHIDS = 'phabricator.embedded-file-phids';
|
2012-10-23 04:06:56 +02:00
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
protected function getObjectNamePrefix() {
|
|
|
|
return 'F';
|
2011-07-15 23:17:55 +02:00
|
|
|
}
|
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
protected function loadObjects(array $ids) {
|
|
|
|
$engine = $this->getEngine();
|
2011-07-15 23:17:55 +02:00
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
$viewer = $engine->getConfig('viewer');
|
|
|
|
$objects = id(new PhabricatorFileQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs($ids)
|
|
|
|
->execute();
|
2011-07-15 23:17:55 +02:00
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
$phids_key = self::KEY_EMBED_FILE_PHIDS;
|
|
|
|
$phids = $engine->getTextMetadata($phids_key, array());
|
|
|
|
foreach (mpull($objects, 'getPHID') as $phid) {
|
|
|
|
$phids[] = $phid;
|
2011-07-15 23:17:55 +02:00
|
|
|
}
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
$engine->setTextMetadata($phids_key, $phids);
|
2012-10-23 04:06:56 +02:00
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
return $objects;
|
|
|
|
}
|
2013-03-23 01:33:36 +01:00
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
protected function renderObjectEmbed($object, $handle, $options) {
|
|
|
|
$options = $this->getFileOptions($options) + array(
|
|
|
|
'name' => $object->getName(),
|
|
|
|
);
|
|
|
|
|
|
|
|
$is_viewable_image = $object->isViewableImage();
|
|
|
|
$is_audio = $object->isAudio();
|
|
|
|
$force_link = ($options['layout'] == 'link');
|
2013-03-23 01:33:36 +01:00
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
$options['viewable'] = ($is_viewable_image || $is_audio);
|
2013-03-23 01:33:36 +01:00
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
if ($is_viewable_image && !$force_link) {
|
|
|
|
return $this->renderImageFile($object, $handle, $options);
|
|
|
|
} else if ($is_audio && !$force_link) {
|
|
|
|
return $this->renderAudioFile($object, $handle, $options);
|
|
|
|
} else {
|
|
|
|
return $this->renderFileLink($object, $handle, $options);
|
|
|
|
}
|
|
|
|
}
|
2012-01-16 19:07:21 +01:00
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
private function getFileOptions($option_string) {
|
2012-01-16 19:07:21 +01:00
|
|
|
$options = array(
|
2013-11-20 02:33:55 +01:00
|
|
|
'size' => null,
|
2012-01-16 19:07:21 +01:00
|
|
|
'layout' => 'left',
|
|
|
|
'float' => false,
|
2013-11-20 02:33:55 +01:00
|
|
|
'width' => null,
|
|
|
|
'height' => null,
|
2014-05-01 16:18:29 +02:00
|
|
|
'alt' => null,
|
2012-01-16 19:07:21 +01:00
|
|
|
);
|
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
if ($option_string) {
|
|
|
|
$option_string = trim($option_string, ', ');
|
2012-11-29 15:05:35 +01:00
|
|
|
$parser = new PhutilSimpleOptions();
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
$options = $parser->parse($option_string) + $options;
|
2012-01-16 19:07:21 +01:00
|
|
|
}
|
2012-03-23 23:32:07 +01:00
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderImageFile(
|
|
|
|
PhabricatorFile $file,
|
|
|
|
PhabricatorObjectHandle $handle,
|
|
|
|
array $options) {
|
|
|
|
|
|
|
|
require_celerity_resource('lightbox-attachment-css');
|
2013-02-06 22:43:14 +01:00
|
|
|
|
2012-10-08 22:26:10 +02:00
|
|
|
$attrs = array();
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
$image_class = null;
|
2013-11-20 02:33:55 +01:00
|
|
|
|
|
|
|
$use_size = true;
|
|
|
|
if (!$options['size']) {
|
|
|
|
$width = $this->parseDimension($options['width']);
|
|
|
|
$height = $this->parseDimension($options['height']);
|
|
|
|
if ($width || $height) {
|
|
|
|
$use_size = false;
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
$attrs += array(
|
|
|
|
'src' => $file->getBestURI(),
|
2013-11-20 02:33:55 +01:00
|
|
|
'width' => $width,
|
|
|
|
'height' => $height,
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
);
|
2013-11-20 02:33:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($use_size) {
|
|
|
|
switch ((string)$options['size']) {
|
|
|
|
case 'full':
|
|
|
|
$attrs += array(
|
|
|
|
'src' => $file->getBestURI(),
|
|
|
|
);
|
2014-04-29 14:00:48 +02:00
|
|
|
$image_class = 'phabricator-remarkup-embed-image-full';
|
2013-11-20 02:33:55 +01:00
|
|
|
break;
|
|
|
|
case 'thumb':
|
|
|
|
default:
|
|
|
|
$attrs['src'] = $file->getPreview220URI();
|
|
|
|
$dimensions =
|
|
|
|
PhabricatorImageTransformer::getPreviewDimensions($file, 220);
|
|
|
|
$attrs['width'] = $dimensions['sdx'];
|
|
|
|
$attrs['height'] = $dimensions['sdy'];
|
|
|
|
$image_class = 'phabricator-remarkup-embed-image';
|
|
|
|
break;
|
|
|
|
}
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 16:18:29 +02:00
|
|
|
if (isset($options['alt'])) {
|
|
|
|
$attrs['alt'] = $options['alt'];
|
|
|
|
}
|
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
$img = phutil_tag('img', $attrs);
|
|
|
|
|
|
|
|
$embed = javelin_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $file->getBestURI(),
|
|
|
|
'class' => $image_class,
|
|
|
|
'sigil' => 'lightboxable',
|
|
|
|
'meta' => array(
|
|
|
|
'phid' => $file->getPHID(),
|
|
|
|
'uri' => $file->getBestURI(),
|
2013-10-17 20:21:01 +02:00
|
|
|
'dUri' => $file->getDownloadURI(),
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
'viewable' => true,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
$img);
|
|
|
|
|
|
|
|
switch ($options['layout']) {
|
|
|
|
case 'right':
|
|
|
|
case 'center':
|
|
|
|
case 'inline':
|
|
|
|
case 'left':
|
|
|
|
$layout_class = 'phabricator-remarkup-embed-layout-'.$options['layout'];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$layout_class = 'phabricator-remarkup-embed-layout-left';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($options['float']) {
|
|
|
|
switch ($options['layout']) {
|
|
|
|
case 'center':
|
|
|
|
case 'inline':
|
2013-02-06 22:43:14 +01:00
|
|
|
break;
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
case 'right':
|
|
|
|
$layout_class .= ' phabricator-remarkup-embed-float-right';
|
|
|
|
break;
|
|
|
|
case 'left':
|
2013-02-06 22:43:14 +01:00
|
|
|
default:
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
$layout_class .= ' phabricator-remarkup-embed-float-left';
|
2013-02-06 22:43:14 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-01-16 19:07:21 +01:00
|
|
|
}
|
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
return phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => $layout_class,
|
|
|
|
),
|
|
|
|
$embed);
|
2012-10-23 04:06:56 +02:00
|
|
|
}
|
2012-01-16 19:07:21 +01:00
|
|
|
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
private function renderAudioFile(
|
|
|
|
PhabricatorFile $file,
|
|
|
|
PhabricatorObjectHandle $handle,
|
|
|
|
array $options) {
|
|
|
|
|
|
|
|
if (idx($options, 'autoplay')) {
|
|
|
|
$preload = 'auto';
|
|
|
|
$autoplay = 'autoplay';
|
|
|
|
} else {
|
|
|
|
$preload = 'none';
|
|
|
|
$autoplay = null;
|
2012-01-16 19:07:21 +01:00
|
|
|
}
|
|
|
|
|
2014-07-01 20:04:05 +02:00
|
|
|
return $this->newTag(
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
'audio',
|
|
|
|
array(
|
|
|
|
'controls' => 'controls',
|
|
|
|
'preload' => $preload,
|
|
|
|
'autoplay' => $autoplay,
|
|
|
|
'loop' => idx($options, 'loop') ? 'loop' : null,
|
|
|
|
),
|
2014-07-01 20:04:05 +02:00
|
|
|
$this->newTag(
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
'source',
|
|
|
|
array(
|
|
|
|
'src' => $file->getBestURI(),
|
|
|
|
'type' => $file->getMimeType(),
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function renderFileLink(
|
|
|
|
PhabricatorFile $file,
|
|
|
|
PhabricatorObjectHandle $handle,
|
|
|
|
array $options) {
|
|
|
|
|
|
|
|
return id(new PhabricatorFileLinkView())
|
|
|
|
->setFilePHID($file->getPHID())
|
2014-07-01 20:04:05 +02:00
|
|
|
->setFileName($this->assertFlatText($options['name']))
|
Modernize file embed Remarkup rule
Summary: Ref T603. Make this rule properly policy-aware, and extend from `PhabricatorRemarkupRuleObject`.
Test Plan:
- Embedded an image, tested all options (name, link, float, layout, size).
- Used lightbox to view several images.
- Embedded a text file, tested all options (name).
- Embedded audio, tested all options (loop, autoplay).
- Attached a file via comment to a task, verified edge was created.
- Attached a file via comment to a conpherence, verified edge was created.
- Viewed old files, verified remarkup version bump rendered them correctly.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T603
Differential Revision: https://secure.phabricator.com/D7192
2013-10-02 03:03:09 +02:00
|
|
|
->setFileDownloadURI($file->getDownloadURI())
|
|
|
|
->setFileViewURI($file->getBestURI())
|
2014-07-01 20:04:05 +02:00
|
|
|
->setFileViewable((bool)$options['viewable']);
|
2011-07-15 23:17:55 +02:00
|
|
|
}
|
|
|
|
|
2013-11-20 02:33:55 +01:00
|
|
|
private function parseDimension($string) {
|
|
|
|
$string = trim($string);
|
|
|
|
|
|
|
|
if (preg_match('/^(?:\d*\\.)?\d+%?$/', $string)) {
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2011-07-15 23:17:55 +02:00
|
|
|
}
|