Skip to content

Commit

Permalink
unacms#1339 Embeds for all content types
Browse files Browse the repository at this point in the history
  • Loading branch information
romanlesnikov committed Dec 20, 2021
1 parent 620ab82 commit fb04cde
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 5 deletions.
5 changes: 5 additions & 0 deletions inc/classes/BxDolPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,11 @@ public function getName ()
return $this->_sObject;
}

public function getObject ()
{
return $this->_aObject;
}

public function getInjections()
{
$aResult = array();
Expand Down
18 changes: 17 additions & 1 deletion inc/classes/BxDolTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,22 @@ function getCode()
{
return $this->_sCode;
}

/**
* Get embed code.
*
* @return string embed's code.
*/
function getEmbed($sContent)
{
$this->addJs(['inc/js/|embed.js']);
$this->addCss(['embed.css']);

$this->setPageNameIndex (BX_PAGE_EMBED);
$this->setPageContent('page_main_code', '<div class="bx-embed">' . $sContent . '</div>');
$this->getPageCode();

}

/**
* Get code key.
Expand Down Expand Up @@ -1173,7 +1189,7 @@ function getMetaInfo()
if (!empty($this->aPage['rss']) && !empty($this->aPage['rss']['url']))
$sRet .= '<link rel="alternate" type="application/rss+xml" title="' . bx_html_attribute($this->aPage['rss']['title'], BX_ESCAPE_STR_QUOTE) . '" href="' . $this->aPage['rss']['url'] . '" />';

$sRet .= "<link rel=\"alternate\" type=\"application/json+oembed\" href=\"" . BX_DOL_URL_ROOT ."oembed.php?url=" . urlencode($_SERVER["REQUEST_URI"]) . "&format=json\" title=\"". (isset($this->aPage['header']) ? bx_html_attribute(strip_tags($this->aPage['header'])) : '') . "\" />";
$sRet .= "<link rel=\"alternate\" type=\"application/json+oembed\" href=\"" . BX_DOL_URL_ROOT ."em.php?url=" . urlencode($_SERVER["REQUEST_URI"]) . "&format=json\" title=\"". (isset($this->aPage['header']) ? bx_html_attribute(strip_tags($this->aPage['header'])) : '') . "\" />";

return $sRet;
}
Expand Down
3 changes: 2 additions & 1 deletion modules/base/general/classes/BxBaseModGeneralModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public function actionEmbed($iContentId)
if(empty($sUnitTemplate))
$sUnitTemplate = 'unit_gallery.html';

echo $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
$oTemplate = BxDolTemplate::getInstance();
$oTemplate->getEmbed($this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate));
}

public function subactionDelete()
Expand Down
1 change: 0 additions & 1 deletion modules/base/general/template/embed.html

This file was deleted.

2 changes: 0 additions & 2 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@

$oPage = BxDolPage::getObjectInstanceByURI('', false, true);
if ($oPage) {

$oPage->displayPage();

} else {

$oTemplate = BxDolTemplate::getInstance();
$oTemplate->displayPageNotFound();
}
Expand Down
7 changes: 7 additions & 0 deletions template/css/embed.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
body,
.bx-embed{
background-color: transparent !important;
}
.bx-embed{
width:calc(100% - 2px);
}
1 change: 1 addition & 0 deletions template/embed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<iframe width="100%" height="300" src="__url__" title="__title__" frameborder="0" allowfullscreen></iframe>
23 changes: 23 additions & 0 deletions template/embed_card.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div class="bx-base-text-unit bx-base-text-unit-gallery bx-def-gal-unit-size flex flex-col w-full p-2 box-border">
<div class="bx-base-text-unit-cnt rounded ring-1 ring-gray-200 dark:ring-gray-700 overflow-hidden bg-white dark:bg-gray-800">
<bx_if:thumb>
<a href="__url__" title="__title__">
<div class="flex-shrink-0 m-1">
<img class="h-48 w-full object-cover rounded" src="__background__" alt="">
</div>
</a>
</bx_if:thumb>
<bx_if:no_thumb>
<a href="__url__" title="__title__">
<div class="bx-def-gal-img-column flex-shrink-0 m-1">
<div class="bx-base-text-unit-no-thumb flex flex-col items-center justify-center h-48 p-4 bg-gradient-to-b from-red-400 to-red-500 box-border rounded-md"></div>
</div>
</a>
</bx_if:no_thumb>
<div class="bx-base-text-unit-text p-3 md:p-4 lg:p-6 pt-2 md:pt-3 lg:pt-5 box-border">
<div class="bx-base-text-unit-title flex items-center text-left">
<a href="__url__" class="text-lg lg:text-xl font-semibold text-gray-700 group-hover:text-gray-900 dark:text-gray-200 dark:group-hover:text-white">__title__</a>
</div>
</div>
</div>
</div>
25 changes: 25 additions & 0 deletions template/scripts/BxBasePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ public function performActionGetHelp ()
'content' => _t($aBlock['help'])
));
}

public function performActionEmbed ()
{
$aCover = $this->getPageCoverImage();
$this->_oTemplate->getEmbed($this->_oTemplate->parseHtmlByName('embed_card.html', [
'title' => _t($this->_aObject['title']),
'url' => BxDolPermalinks::getInstance()->permalink($this->_aObject['url']),
'bx_if:thumb' => [
'condition' => $this->isPageCover() && count($aCover) > 0,
'content' => [
'title' => _t($this->_aObject['title']),
'url' => BxDolPermalinks::getInstance()->permalink($this->_aObject['url']),
'background' => BxDolCover::getInstance(BxDolTemplate::getInstance())->getCoverImageUrl($aCover)
],
],
'bx_if:no_thumb' => [
'condition' => count($aCover) == 0 || !$this->isPageCover(),
'content' => [
'title' => _t($this->_aObject['title']),
'url' => BxDolPermalinks::getInstance()->permalink($this->_aObject['url']),
]
]
]
));
}

/**
* Very similar to BxBasePage::getCode
Expand Down

0 comments on commit fb04cde

Please sign in to comment.