Alexander 5 лет назад
Родитель
Сommit
c325e80246

+ 2 - 1
composer.json

@@ -92,7 +92,8 @@
         "recurly/recurly-client": "2.10.*",
         "stripe/stripe-php": "^7.95",
         "twilio/sdk": "^5.19",
-        "avto-dev/composer-cleanup-plugin": "dev-master"
+        "avto-dev/composer-cleanup-plugin": "dev-master",
+        "mpratt/embera": "~2.0"
     },
     "scripts": {
         "post-update-cmd": [

+ 67 - 2
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "3d1f04931a4d3d5f0352d496c7f93a9c",
+    "content-hash": "66416d9b669859af8845a58c1c602a16",
     "packages": [
         {
             "name": "achingbrain/php5-akismet",
@@ -797,6 +797,69 @@
             },
             "time": "2019-02-05T23:41:09+00:00"
         },
+        {
+            "name": "mpratt/embera",
+            "version": "2.0.22",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/mpratt/Embera.git",
+                "reference": "79a5b789a674b4fcab374e5669c0270b910f28a9"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/mpratt/Embera/zipball/79a5b789a674b4fcab374e5669c0270b910f28a9",
+                "reference": "79a5b789a674b4fcab374e5669c0270b910f28a9",
+                "shasum": ""
+            },
+            "require": {
+                "ext-json": "*",
+                "php": ">=5.6"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^9.0"
+            },
+            "suggest": {
+                "ext-curl": "Allow to fetch data using curl instead of using file_get_contents"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Embera\\": "src/Embera"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Michael Pratt",
+                    "email": "yo@michael-pratt.com",
+                    "homepage": "http://www.michael-pratt.com",
+                    "role": "Author/Developer"
+                }
+            ],
+            "description": "Oembed consumer library. Converts urls into their html embed code. Supports 150+ sites, such as Youtube, Twitter, vimeo, Instagram etc.",
+            "homepage": "https://github.com/mpratt/Embera",
+            "keywords": [
+                "Auto embed",
+                "Embed Text",
+                "Responsive Embeds",
+                "Url Embed",
+                "embed",
+                "instagram",
+                "oembed",
+                "twitter",
+                "vimeo",
+                "vine",
+                "youtube"
+            ],
+            "support": {
+                "issues": "https://github.com/mpratt/Embera/issues",
+                "source": "https://github.com/mpratt/Embera/tree/2.0.22"
+            },
+            "time": "2021-09-29T00:42:12+00:00"
+        },
         {
             "name": "paypal/paypal-checkout-sdk",
             "version": "1.0.1",
@@ -1473,7 +1536,9 @@
     },
     "prefer-stable": false,
     "prefer-lowest": false,
-    "platform": [],
+    "platform": {
+        "php": ">=5.6"
+    },
     "platform-dev": [],
     "plugin-api-version": "2.1.0"
 }

+ 3 - 2
install/sql/system.sql

@@ -75,7 +75,8 @@ CREATE TABLE `sys_objects_embeds` (
 
 INSERT INTO `sys_objects_embeds` (`object`, `title`, `override_class_name`, `override_class_file`) VALUES
 ('sys_embedly', 'Embedly', 'BxTemplEmbedEmbedly', ''),
-('sys_iframely', 'Iframely', 'BxTemplEmbedIframely', '');
+('sys_iframely', 'Iframely', 'BxTemplEmbedIframely', ''),
+('sys_oembed', 'Oembed', 'BxTemplEmbedOembed', '');
 
 
 -- --------------------------------------------------------
@@ -437,7 +438,7 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 
 (@iCategoryId, 'useLikeOperator', '_adm_stg_cpt_option_use_like_operator', 'on', 'checkbox', '', '', '', 45),
 
-(@iCategoryId, 'sys_embed_default', '_adm_stg_cpt_option_sys_embed_default', '', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:25:"get_options_embed_default";s:5:"class";s:13:"TemplServices";}', '', '', 79),
+(@iCategoryId, 'sys_embed_default', '_adm_stg_cpt_option_sys_embed_default', 'sys_oembed', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:25:"get_options_embed_default";s:5:"class";s:13:"TemplServices";}', '', '', 79),
 (@iCategoryId, 'sys_embedly_api_key', '_adm_stg_cpt_option_sys_embedly_api_key', '', 'digit', '', '', '', 80),
 
 (@iCategoryId, 'sys_iframely_api_key', '_adm_stg_cpt_option_sys_iframely_api_key', '', 'digit', '', '', '', 90);

+ 21 - 0
modules/boonex/artificer/data/template/system/scripts/BxTemplEmbedOembed.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolEmbed
+ */
+class BxTemplEmbedOembed extends BxBaseEmbedOembed
+{
+    public function __construct ($aObject, $oTemplate = false)
+    {
+        parent::__construct ($aObject, $oTemplate);
+    }
+}
+
+/** @} */

+ 21 - 0
modules/boonex/decorous/data/template/system/scripts/BxTemplEmbedOembed.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolEmbed
+ */
+class BxTemplEmbedOembed extends BxBaseEmbedOembed
+{
+    public function __construct ($aObject, $oTemplate = false)
+    {
+        parent::__construct ($aObject, $oTemplate);
+    }
+}
+
+/** @} */

+ 21 - 0
modules/boonex/lucid/data/template/system/scripts/BxTemplEmbedOembed.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolEmbed
+ */
+class BxTemplEmbedOembed extends BxBaseEmbedOembed
+{
+    public function __construct ($aObject, $oTemplate = false)
+    {
+        parent::__construct ($aObject, $oTemplate);
+    }
+}
+
+/** @} */

+ 21 - 0
modules/boonex/ocean/data/template/system/scripts/BxTemplEmbedOembed.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolEmbed
+ */
+class BxTemplEmbedOembed extends BxBaseEmbedOembed
+{
+    public function __construct ($aObject, $oTemplate = false)
+    {
+        parent::__construct ($aObject, $oTemplate);
+    }
+}
+
+/** @} */

+ 21 - 0
modules/boonex/protean/data/template/system/scripts/BxTemplEmbedOembed.php

@@ -0,0 +1,21 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaTemplate UNA Template Classes
+ * @{
+ */
+
+/**
+ * @see BxDolEmbed
+ */
+class BxTemplEmbedOembed extends BxBaseEmbedOembed
+{
+    public function __construct ($aObject, $oTemplate = false)
+    {
+        parent::__construct ($aObject, $oTemplate);
+    }
+}
+
+/** @} */

+ 17 - 0
oembed.php

@@ -0,0 +1,17 @@
+<?php
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaCore UNA Core
+ * @{
+ */
+
+require_once('./inc/header.inc.php');
+require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
+
+$aLinks = bx_get('l');
+
+bx_import('BxDolEmbed');
+$oEmbed = BxDolEmbed::getObjectInstance('sys_oembed');
+echoJson($oEmbed->parseLinks($aLinks));

+ 17 - 0
template/css/oembed.css

@@ -0,0 +1,17 @@
+.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;
+}

+ 39 - 0
template/embed_oembed_integration.html

@@ -0,0 +1,39 @@
+<script>
+    function bx_oembed_process_links(el) {
+        var alinksHref = [];
+        var alinksEl = [];
+
+        if (typeof el.tagName != 'undefined' && el.tagName == 'A') {
+            alinksEl.push(el);
+            alinksHref.push($(el).attr('href'));
+        } else {
+            $('a[bx-oembed-url]', el).each(function (i, a) {
+                alinksEl.push(a);
+                alinksHref.push($(a).attr('href'));
+            });
+        }
+
+        if (alinksEl.length) {
+            $.post(sUrlRoot + 'oembed.php', {l: alinksHref}, function (oResponse) {
+                if (oResponse.length)
+                    for (i in oResponse) {
+                        if (oResponse[i].html.length) {
+                            $(alinksEl[i]).replaceWith(oResponse[i].html);
+                        } else {
+                            $(alinksEl[i]).removeAttr('bx-oembed-url');
+                        }
+                    }
+            }, 'json');
+        }
+    }
+
+    $(document).ready(function(){
+        bx_oembed_process_links(this);
+
+        if (typeof glOnProcessHtml === 'undefined')
+            glOnProcessHtml = [];
+        if (glOnProcessHtml instanceof Array) {
+            glOnProcessHtml.push(bx_oembed_process_links);
+        }
+    });
+</script>

+ 1 - 0
template/embed_oembed_link.html

@@ -0,0 +1 @@
+<a bx-oembed-url href="__link__" __attrs__>__title__</a>

+ 102 - 0
template/scripts/BxBaseEmbedOembed.php

@@ -0,0 +1,102 @@
+<?php defined('BX_DOL') or die('hack attempt');
+/**
+ * Copyright (c) UNA, Inc - https://una.io
+ * MIT License - https://opensource.org/licenses/MIT
+ *
+ * @defgroup    UnaBaseView UNA Base Representation Classes
+ * @{
+ */
+
+/**
+ * Oembed integration.
+ * @see BxDolEmbed
+ */
+class BxBaseEmbedOembed extends BxDolEmbed
+{
+    var $_iCacheTTL = 3600;
+
+    public function __construct ($aObject, $oTemplate)
+    {
+        parent::__construct ($aObject);
+
+        if ($oTemplate)
+            $this->_oTemplate = $oTemplate;
+        else
+            $this->_oTemplate = BxDolTemplate::getInstance();
+    }
+
+    public function getLinkHTML ($sLink, $sTitle = '', $sMaxWidth = '')
+    {
+        $aAttrs = array(
+            'title' => bx_html_attribute($sTitle),
+        );
+
+        // check for external link
+        if (strncmp(BX_DOL_URL_ROOT, $sLink, strlen(BX_DOL_URL_ROOT)) !== 0) {
+            $aAttrs['target'] = '_blank';
+
+            if (getParam('sys_add_nofollow') == 'on')
+                $aAttrs['rel'] = 'nofollow';
+        }
+
+        return $this->_oTemplate->parseHtmlByName('embed_oembed_link.html', array(
+            'link' => $sLink,
+            'title' => $sTitle,
+            'attrs' => bx_convert_array2attrs($aAttrs),
+            'width' => $sMaxWidth,
+        ));
+    }
+
+    public function addProcessLinkMethod ()
+    {
+        return "
+        <script>
+            function bx_embed_link(e) {                
+                bx_oembed_process_links(e);
+            }
+        </script>";
+    }
+
+    public function addJsCss ()
+    {
+        if ($this->_bCssJsAdded)
+            return '';
+
+        $this->_bCssJsAdded = true;
+
+        $this->_oTemplate->addCss('oembed.css');
+        return $this->_oTemplate->parseHtmlByName('embed_oembed_integration.html', []);
+    }
+
+    public function parseLinks(&$aLinks) {
+        $aResult = [];
+        if ($aLinks && is_array($aLinks)) {
+            $oEmbera = $this->getEmberaInstance();
+
+            foreach ($aLinks as $sLink) {
+                $sHtml = $oEmbera->autoEmbed($sLink);
+                //if nothing to change/embed then return empty string to not replace anything on a frontend
+                $aResult[] = ['html' => $sHtml != $sLink ? $sHtml : ''];
+            }
+        }
+        return $aResult;
+    }
+
+    public function getUrlData($sLink) {
+        $oEmbera = $this->getEmberaInstance();
+        return $oEmbera->getUrlData([$sLink]);
+    }
+
+    protected function getEmberaInstance() {
+        static $oEmbera;
+        if (!$oEmbera) {
+            $oHttpCache = new Embera\Http\HttpClientCache(new Embera\Http\HttpClient());
+            $oHttpCache->setCachingEngine(new Embera\Cache\Filesystem(BX_DIRECTORY_PATH_TMP, $this->_iCacheTTL));
+            $oEmbera = new Embera\Embera(['responsive' => true], null, $oHttpCache);
+        }
+
+        return $oEmbera;
+    }
+}
+
+/** @} */