Skip to content

Commit

Permalink
Merge pull request #1479 from buddha87/master
Browse files Browse the repository at this point in the history
Fixed #1416: Show video link on edit view
  • Loading branch information
luke- committed Feb 15, 2016
2 parents 3999596 + 8b94d19 commit 23ef083
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
4 changes: 3 additions & 1 deletion protected/humhub/models/UrlOembed.php
Expand Up @@ -56,6 +56,8 @@ public function attributeLabels()
public static function GetOEmbed($url)
{

$url = trim($url);

// Check if the given URL has OEmbed Support
if (UrlOembed::HasOEmbedSupport($url)) {

Expand Down Expand Up @@ -111,7 +113,7 @@ public static function loadUrl($url)
try {
$data = \yii\helpers\Json::decode($jsonOut);
if (isset($data['type']) && ($data['type'] === "video" || $data['type'] === 'rich' || $data['type'] === 'photo')) {
$html = "<div class='oembed_snippet'>" . $data['html'] . "</div>";
$html = "<div class='oembed_snippet' data-url='" . \yii\helpers\Html::encode($url) . "'>" . $data['html'] . "</div>";
}
} catch (\yii\base\InvalidParamException $ex) {
Yii::warning($ex->getMessage());
Expand Down
2 changes: 1 addition & 1 deletion protected/humhub/modules/comment/views/comment/edit.php
Expand Up @@ -14,7 +14,7 @@

<!-- create contenteditable div for HEditorWidget to place the data -->
<div id="comment_input_<?php echo $comment->id; ?>_contenteditable" class="form-control atwho-input"
contenteditable="true"><?php echo \humhub\widgets\RichText::widget(['text' => $comment->message]); ?></div>
contenteditable="true"><?php echo \humhub\widgets\RichText::widget(['text' => $comment->message, 'edit' => true]); ?></div>


<?php
Expand Down
2 changes: 1 addition & 1 deletion protected/humhub/modules/post/views/post/edit.php
Expand Up @@ -12,7 +12,7 @@

<!-- create contenteditable div for HEditorWidget to place the data -->
<div id="post_input_<?php echo $post->id; ?>_contenteditable" class="form-control atwho-input"
contenteditable="true"><?php echo \humhub\widgets\RichText::widget(['text' => $post->message]); ?></div>
contenteditable="true"><?php echo \humhub\widgets\RichText::widget(['text' => $post->message, 'edit' => true]); ?></div>

<?= \humhub\widgets\RichTextEditor::widget(['id' => 'post_input_' . $post->id, 'inputContent' => $post->message, 'record' => $post]); ?>

Expand Down
13 changes: 11 additions & 2 deletions protected/humhub/widgets/RichText.php
Expand Up @@ -36,6 +36,11 @@ class RichText extends \humhub\components\Widget
*/
public $minimal = false;

/**
* @var boolean edit mode
*/
public $edit = false;

/**
* @var \humhub\components\ActiveRecord this richtext belongs to
*/
Expand All @@ -60,8 +65,13 @@ public function run()
if (!$this->minimal) {
$maxOembedCount = 3; // Maximum OEmbeds
$oembedCount = 0; // OEmbeds used
$that = $this;

$this->text = preg_replace_callback('/(https?:\/\/.*?)(\s|$)/i', function ($match) use (&$oembedCount, &$maxOembedCount) {
$this->text = preg_replace_callback('/(https?:\/\/.*?)(\s|$)/i', function ($match) use (&$oembedCount, &$maxOembedCount, &$that) {

if ($that->edit) {
return Html::a($match[0], Html::decode($match[0]), array('target' => '_blank'));
}

// Try use oembed
if ($maxOembedCount > $oembedCount) {
Expand All @@ -71,7 +81,6 @@ public function run()
return $oembed;
}
}

return Html::a($match[1], Html::decode($match[1]), array('target' => '_blank')) . $match[2];
}, $this->text);
}
Expand Down

0 comments on commit 23ef083

Please sign in to comment.