Преглед изворни кода

#1339 Embeds for all content types

RomanL пре 4 година
родитељ
комит
8303123b08

+ 5 - 0
inc/classes/BxDolContentInfo.php

@@ -271,6 +271,11 @@ class BxDolContentInfo extends BxDolFactory implements iBxDolFactoryObject
     {
         return $this->_call('get_text', $iContentId);
     }
+    
+    public function getContentEmbed ($iContentId)
+    {
+        return $this->_call('get_embed', $iContentId);
+    }
 
     public function getContentInfo ($iContentId, $bSearchableFieldsOnly = true)
     {

+ 12 - 0
inc/classes/BxDolPageQuery.php

@@ -43,6 +43,18 @@ class BxDolPageQuery extends BxDolDb
         }
         return $oDb->getOne($sQuery, $a);
     }
+    
+    static public function getContentInfoObjectNameByURI($sURI)
+    {
+        $oDb = BxDolDb::getInstance();
+        $a = array('uri' => $sURI);
+        $sQuery = "SELECT `module`, `content_info` FROM `sys_objects_page` WHERE `uri` = :uri";
+        $aRow = $oDb->getRow($sQuery, $a);
+        if ($aRow['content_info'] != '') 
+            return $aRow['content_info'];
+        
+        return $aRow['module'];
+    }
 
 	static public function getPageTriggers($sTriggerName)
     {

+ 22 - 0
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -97,6 +97,18 @@ class BxBaseModGeneralModule extends BxDolModule
         }
         $this->$sMethodName();
     }
+    
+    public function actionEmbed($iContentId)
+    {
+        $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+        if(empty($aContentInfo))
+            return '';
+
+        if(empty($sUnitTemplate))
+            $sUnitTemplate = 'unit_gallery.html';
+
+        echo $this->_oTemplate->unit($aContentInfo, true, $sUnitTemplate);
+    }
    
 	public function subactionDelete()
     {
@@ -267,6 +279,16 @@ class BxBaseModGeneralModule extends BxDolModule
 
         return $mixedResult;
     }
+    
+    public function serviceGetEmbed ($iContentId)
+    {
+        $sTitle = $this->_getFieldValue('FIELD_TITLE', $iContentId);
+        return $this->_oTemplate->parseHtmlByName('embed.html', [
+            'title' => $sTitle,
+            'url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'embed/' . $iContentId . '/'
+        ]);
+    }
+    
 
     public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
     {

+ 1 - 0
modules/base/general/template/embed.html

@@ -0,0 +1 @@
+<iframe width="300" height="300" src="__url__" title="__title__" frameborder="0" allowfullscreen></iframe>

+ 53 - 4
oembed.php

@@ -10,8 +10,57 @@
 require_once('./inc/header.inc.php');
 require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
 
-$aLinks = bx_get('l');
+// used in oembed integration
+if (bx_get('l')){
+    
+    $aLinks = bx_get('l');
 
-bx_import('BxDolEmbed');
-$oEmbed = BxDolEmbed::getObjectInstance('sys_oembed');
-echoJson($oEmbed->parseLinks($aLinks));
+    bx_import('BxDolEmbed');
+    $oEmbed = BxDolEmbed::getObjectInstance('sys_oembed');
+    echoJson($oEmbed->parseLinks($aLinks));
+}
+
+// embedded representation of a URL on third party sites
+if (bx_get('url')){
+    $sUrl = urldecode(bx_get('url'));
+    $aUrl = parse_url($sUrl);
+    $aUri = explode('/', $aUrl['path']);
+    $aParams = [];
+    parse_str($aUrl['query'], $aParams);
+    if (!$aUri || empty($aUri[2]))
+        echo 'no';
+    
+    $sContentInfoObject = BxDolPageQuery::getContentInfoObjectNameByURI($aUri[2]);
+    $oContentInfo = BxDolContentInfo::getObjectInstance($sContentInfoObject);
+    
+    $sTitle = $oContentInfo->getContentTitle($aParams['id']);
+    $iAuthor = $oContentInfo->getContentAuthor($aParams['id']);
+    $oProfile = BxDolProfile::getInstance($iAuthor);
+    $sAuthorName = $oProfile->getDisplayName();
+    $sAuthorUrl = $oProfile->getUrl();
+    $sHtml = $oContentInfo->getContentEmbed($aParams['id']);
+    $sThumb = $oContentInfo->getContentThumb($aParams['id']);
+    
+    if (bx_get('format') == 'json'){
+        $aResult = [
+            'version' => '1.0',
+            'type' => 'rich',
+            'title' => $sTitle,
+            'url' => $sUrl,
+            'author_name' => $sAuthorName,
+            'author_url' => $sAuthorUrl,
+            'url' => $sUrl,
+            'provider_name' => getParam('site_title'),
+            'provider_url' => BX_DOL_URL_ROOT,
+            'html' => $sHtml,
+        ];
+        
+        if ($sThumb){
+             $aResult['thumbnail_url'] = $sThumb;
+        }
+        
+        header('Content-Type: application/json; charset=utf-8');
+        
+        echo json_encode($aResult);
+    }
+}