roman.lesnikov@gmail.com пре 3 година
родитељ
комит
a688fd3419

+ 14 - 1
inc/classes/BxDolEmbed.php

@@ -39,7 +39,7 @@
 class BxDolEmbed extends BxDolFactoryObject
 {
     protected $_bCssJsAdded = false;
-
+    protected $_sTableName = '';
     /**
      * Get editor object instance by object name
      * @param $sObject object name
@@ -71,6 +71,19 @@ class BxDolEmbed extends BxDolFactoryObject
     {
         // override this function in particular editor class
     }
+    
+    public function getData ($sUrl, $sTheme)
+    {
+        $sData = BxDolEmbedQuery::getLocal($sUrl, $sTheme, $this->_sTableName);
+        if (!$sData){
+            $sData = $this->getDataFromApi($sUrl, $sTheme); 
+            if ($sData){
+                BxDolEmbedQuery::setLocal($sUrl, $sTheme, $this->_sTableName, $sData);
+            }
+        }
+        $aData = json_decode($sData, true);
+        return $aData;
+    }
 }
 
 /** @} */

+ 14 - 0
inc/classes/BxDolEmbedQuery.php

@@ -22,6 +22,20 @@ class BxDolEmbedQuery extends BxDolFactoryObjectQuery
     {
         return parent::getObjectsFromTable('sys_objects_embeds');
     }
+    
+    static public function getLocal ($sUrl, $sTheme, $sTableName)
+    {
+        $oDb = BxDolDb::getInstance();
+        $sQuery = $oDb->prepare("SELECT `data` FROM `" . $sTableName . "` WHERE `url` = ? AND  `theme` = ?", $sUrl, $sTheme);
+        return $oDb->getOne($sQuery);
+    }
+    
+    static public function setLocal ($sUrl, $sTheme, $sTableName, $sData)
+    {
+        $oDb = BxDolDb::getInstance();
+        $sQuery = $oDb->prepare("INSERT INTO `" . $sTableName . "` (`url`, `theme`, `data`, `added`) VALUES (?, ?, ?, ?)", $sUrl, $sTheme, $sData, time());
+        $oDb->query($sQuery);
+    }
 }
 
 /** @} */

+ 9 - 0
install/sql/system.sql

@@ -80,6 +80,15 @@ INSERT INTO `sys_objects_embeds` (`object`, `title`, `override_class_name`, `ove
 ('sys_oembed', 'Oembed', 'BxTemplEmbedOembed', '');
 
 
+CREATE TABLE `sys_iframely_data` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `url` varchar(255) DEFAULT NULL,
+  `data` text DEFAULT NULL,
+  `added` int(11) DEFAULT NULL,
+  `theme` varchar(10) DEFAULT NULL,
+  PRIMARY KEY (id)
+);
+
 -- --------------------------------------------------------
 
 

+ 2 - 30
oembed.php

@@ -13,38 +13,10 @@ require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
 $aLinks = bx_get('l');
 
 bx_import('BxDolEmbed');
-$oEmbed = BxDolEmbed::getObjectInstance('sys_embedly');
+$oEmbed = BxDolEmbed::getObjectInstance('sys_iframely');
 
 if (bx_get('html')){
-    echo '<body style="margin:0"><style>iframe{width:100%} .embera-embed-responsive {
-    position: relative;
-    display: block;
-    width: 100%;
-    padding: 0;
-    overflow: hidden;
-    padding-bottom: 50%;
-}
-.embera-embed-responsive-item {
-    position: absolute;
-    top: 0;
-    bottom: 0;
-    left: 0;
-    width: 100%;
-    height: 100%;
-    border: 0;
-}
-.embedly-card{
-    width:600px;
-}
-.bx-base-attach-link-form-field .embera-embed-responsive {
-    padding-bottom: 0;
-}
-.bx-base-attach-link-form-field .embera-embed-responsive-item {
-    position: relative;
-    width: auto;
-    height: auto;
-}</style><script language="javascript" src="'.BX_DOL_URL_ROOT.'/plugins_public/jquery/jquery.min.js"></script>' . $oEmbed->addJsCss() . '<div style="max-width:900; margin:0px auto; justify-content: center; display:flex">' . $oEmbed->getLinkHTML($aLinks, '', '', bx_get('theme')) .'</div></body>';
+    echo '<div style="max-width:900; margin:0px auto; justify-content: center; ">' . $oEmbed->getDataHtml($aLinks, bx_get('theme')) . '</div>';
     exit();
 }
-//data-card-theme
 echoJson($oEmbed->parseLinks($aLinks));

+ 12 - 0
template/scripts/BxBaseEmbedIframely.php

@@ -15,6 +15,7 @@ class BxBaseEmbedIframely extends BxDolEmbed
 {
     public function __construct ($aObject, $oTemplate)
     {
+        $this->_sTableName = 'sys_iframely_data';
         parent::__construct ($aObject);
 
         if ($oTemplate)
@@ -68,6 +69,17 @@ class BxBaseEmbedIframely extends BxDolEmbed
             'key' => $sKey,
         ));
     }
+    
+    public function getDataFromApi ($sUrl, $sTheme)
+    {
+        return bx_file_get_contents("https://iframe.ly/api/oembed?theme=" . $sTheme . "&url=" . $sUrl . "&api_key=" . getParam('sys_iframely_api_key'));
+    }
+    
+    public function getDataHtml ($sUrl, $sTheme)
+    {
+        $aData = $this->getData($sUrl, $sTheme);
+        return $aData['html'];
+    }
 }
 
 /** @} */