Forráskód Böngészése

Ticket #2246 - Points 1 and 2.

AntonLV 7 éve
szülő
commit
5e7d3b4db1

+ 19 - 0
inc/utils.inc.php

@@ -1074,6 +1074,25 @@ function bx_get ($sName, $sMethod = false)
         return false;
 }
 
+function bx_get_with_prefix ($sPrefix, $sMethod = false)
+{
+    $aSources = array('get' => &$_GET, 'post' => &$_POST);
+
+    $aFiltered = array();
+    foreach($aSources as $sName => $aSource)
+        if($sMethod == $sName || !$sMethod)
+            $aFiltered = array_merge($aFiltered, array_filter($aSource, function($sKey) use ($sPrefix) {
+                return strpos($sKey, $sPrefix) === 0;
+            }, ARRAY_FILTER_USE_KEY));
+
+    $aUpdated = array();
+    array_walk($aFiltered, function($sValue, $sKey) use ($sPrefix, &$aUpdated) {
+        $aUpdated[trim(str_replace($sPrefix, '', $sKey), '_-')] = $sValue;
+    });
+
+    return $aUpdated;
+}
+
 function bx_get_base_url_inline($aParams = array())
 {
     $aBaseLink = parse_url(BX_DOL_URL_ROOT);

+ 6 - 0
modules/base/text/classes/BxBaseModTextConfig.php

@@ -47,6 +47,12 @@ class BxBaseModTextConfig extends BxBaseModGeneralConfig
 
             // objects
             'OBJECT_VOTES_POLL_ANSWERS' => $this->_sName . '_poll_answers',
+
+            // styles
+            'STYLES_POLLS_EMBED_CLASS' => 'body.bx-page-iframe.bx-def-color-bg-page',
+            'STYLES_POLLS_EMBED_CONTENT' => array(
+                'background-color' => '#ffffff'
+            ),
         );
 
         $this->_aJsClasses = array(

+ 27 - 0
modules/base/text/classes/BxBaseModTextModule.php

@@ -20,6 +20,33 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
     }
 
     // ====== ACTIONS METHODS
+    public function actionEmbedPoll($iPollId = 0)
+    {
+        if(empty($iPollId) && bx_get('poll_id') !== false)
+            $iPollId = (int)bx_get('poll_id');
+
+        $aParams = bx_get_with_prefix('param');
+        array_walk($aParams, function(&$sValue) {
+            $sValue = bx_process_input($sValue);
+        });
+
+        $this->_oTemplate->embedPollItem($iPollId, $aParams);
+    }
+
+    public function actionEmbedPolls($iId = 0)
+    {
+        list($iContentId, $aContentInfo) = $this->_getContent($iId);
+        if($iContentId === false)
+            return;
+
+        $aParams = bx_get_with_prefix('param');
+        array_walk($aParams, function(&$sValue) {
+            $sValue = bx_process_input($sValue);
+        });
+
+        $this->_oTemplate->embedPollItems($aContentInfo, $aParams);
+    }
+
     public function actionGetPoll()
     {
         $iPollId = (int)bx_get('poll_id');

+ 71 - 2
modules/base/text/classes/BxBaseModTextTemplate.php

@@ -25,8 +25,11 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
 
     public function getJsCode($sType, $aParams = array(), $bWrap = true)
     {
+        $CNF = &$this->getModule()->_oConfig->CNF;
+
         $aParams = array_merge(array(
-            'aHtmlIds' => $this->_oConfig->getHtmlIds()
+            'aHtmlIds' => $this->_oConfig->getHtmlIds(),
+            'sEditorId' => isset($CNF['FIELD_TEXT_ID']) ? $CNF['FIELD_TEXT_ID'] : ''
         ), $aParams);
 
         return parent::getJsCode($sType, $aParams, $bWrap);
@@ -252,6 +255,13 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
                 )
             ),
             'action_menu' => !empty($mixedMenu) ? $mixedMenu->getCode() : '',
+            'bx_if:show_action_embed' => array(
+                'condition' => $bManage,
+                'content' => array(
+                    'js_object' => $sJsObject,
+                    'id' => $iPollId
+                )
+            ),
             'bx_if:show_action_delete' => array(
                 'condition' => $bManage,
                 'content' => array(
@@ -263,7 +273,66 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
             'content' => $this->$sMethod($aPoll, $bDynamic)
         ));
     }
-    
+
+    public function embedPollItem($mixedPoll, $aParams = array())
+    {
+        $CNF = &$this->getModule()->_oConfig->CNF;
+
+        $sHeader = '';
+        $sContent = $this->getPollItem($mixedPoll, 0, $aParams);
+        if(!empty($sContent)) {
+            $aPoll = is_array($mixedPoll) ? $mixedPoll : $this->_oDb->getPolls(array('type' => 'id', 'id' => (int)$mixedPoll));
+
+            $sHeader = strmaxtextlen($aPoll[$CNF['FIELD_POLL_TEXT']], 32, '...');
+            $sContent = $this->getJsCode('poll') . $sContent;
+        }
+
+        $this->addJs(array('polls.js'));
+        $this->addCss(array('polls.css'));
+
+        $oTemplate = BxDolTemplate::getInstance();
+        $oTemplate->addCssStyle($CNF['STYLES_POLLS_EMBED_CLASS'], $CNF['STYLES_POLLS_EMBED_CONTENT']);
+        $oTemplate->setPageNameIndex(BX_PAGE_EMBED);
+        $oTemplate->setPageHeader($sHeader);
+        $oTemplate->setPageContent('page_main_code', $sContent);
+        $oTemplate->getPageCode();
+        exit;
+    }
+
+    public function embedPollItems($mixedContentInfo, $aParams = array())
+    {
+        $CNF = &$this->getModule()->_oConfig->CNF;
+
+        $aContentInfo = is_array($mixedContentInfo) ? $mixedContentInfo : $this->_oDb->getContentInfoById((int)$mixedContentInfo);
+        if(empty($aContentInfo) || !is_array($aContentInfo))
+            return;
+
+        $aPolls = $this->_oDb->getPolls(array('type' => 'content_id', 'content_id' => (int)$aContentInfo[$CNF['FIELD_ID']]));
+        if(empty($aPolls) || !is_array($aPolls))
+            return;
+
+        $sContent = '';
+        foreach($aPolls as $aPoll)
+            $sContent .= $this->getPollItem($aPoll, 0, $aParams);
+
+        $sHeader = '';
+        if(!empty($sContent)) {
+            $sHeader = strmaxtextlen($aContentInfo[$CNF['FIELD_TITLE']], 32, '...');
+            $sContent = $this->getJsCode('poll') . $sContent;
+        }
+
+        $this->addJs(array('polls.js'));
+        $this->addCss(array('polls.css'));
+
+        $oTemplate = BxDolTemplate::getInstance();
+        $oTemplate->addCssStyle($CNF['STYLES_POLLS_EMBED_CLASS'], $CNF['STYLES_POLLS_EMBED_CONTENT']);
+        $oTemplate->setPageNameIndex(BX_PAGE_EMBED);
+        $oTemplate->setPageHeader($sHeader);
+        $oTemplate->setPageContent('page_main_code', $sContent);
+        $oTemplate->getPageCode();
+        exit;
+    }
+
     protected function _getPollAnswers($aPoll, $bDynamic = false)
     {
         $CNF = &$this->getModule()->_oConfig->CNF;

+ 7 - 0
modules/base/text/template/css/polls.css

@@ -184,6 +184,13 @@ div.bx-base-text-pr-graph .bx-base-text-prg-text {
 	white-space: nowrap;
 }
 
+/*--- Poll item embed ---*/
+.bx-base-text-poll-embed {
+    width: 560px;
+    height: 315px;
+}
+
+
 /*--- Animation ---*/
 @-webkit-keyframes bx-base-text-prg-bar-anim {
     from {

+ 3 - 0
modules/base/text/template/poll_item.html

@@ -2,6 +2,9 @@
     <div class="bx-base-text-poll-cnt bx-def-box bx-def-round-corners bx-def-color-bg-box bx-def-padding bx-def-box-sizing">
         <div class="bx-base-text-poll-actions bx-def-padding-sec-bottom">
             __action_menu__
+            <bx_if:show_action_embed>
+                <a class="bx-base-text-poll-action bx-base-text-pa-icon bx-base-text-pa-embed bx-def-margin-sec-left-auto" href="javascript:void(0)" onclick="javascript:__js_object__.embedPoll(this, __id__);" title="<bx_text_attribute:_sys_txt_form_entry_input_picture_insert />"><i class="sys-icon paperclip"></i></a>
+            </bx_if:show_action_embed>
             <bx_if:show_action_delete>
                 <a class="bx-base-text-poll-action bx-base-text-pa-icon bx-base-text-pa-delete bx-def-margin-sec-left-auto" href="javascript:void(0)" onclick="javascript:__js_object__.deletePoll(this, __id__);" title="<bx_text_attribute:_Delete />"><i class="sys-icon times"></i></a>
             </bx_if:show_action_delete>

+ 10 - 0
modules/boonex/posts/js/polls.js

@@ -13,10 +13,12 @@ function BxPostsPolls(oOptions) {
     this._sActionsUrl = oOptions.sActionUrl;
     this._sObjName = oOptions.sObjName == undefined ? 'oBxPostsPolls' : oOptions.sObjName;
     this._iOwnerId = oOptions.iOwnerId == undefined ? 0 : oOptions.iOwnerId;
+    this._sEditorId = oOptions.sEditorId == undefined ? '' : oOptions.sEditorId;
     this._sAnimationEffect = oOptions.sAnimationEffect == undefined ? 'slide' : oOptions.sAnimationEffect;
     this._iAnimationSpeed = oOptions.iAnimationSpeed == undefined ? 'slow' : oOptions.iAnimationSpeed;
     this._aHtmlIds = oOptions.aHtmlIds == undefined ? {} : oOptions.aHtmlIds;
     this._oRequestParams = oOptions.oRequestParams == undefined ? {} : oOptions.oRequestParams;
+    
 }
 
 BxPostsPolls.prototype.initFlickity = function(oParent) {
@@ -98,6 +100,14 @@ BxPostsPolls.prototype.afterPollFormSubmit = function (oForm, oData)
         fContinue();
 };
 
+BxPostsPolls.prototype.embedPoll = function(oLink, iId) 
+{
+    var sEmbedUrl = this._sActionsUrl + 'embed_poll/' + iId;
+    var sHtmlId = 'bx-base-general-poll-' + iId;
+
+    bx_editor_insert_html (this._sEditorId, sHtmlId, '<iframe class="bx-base-text-poll-embed" src="' + sEmbedUrl + '" frameborder="0" allow="autoplay; picture-in-picture" allowfullscreen></iframe>');
+};
+
 BxPostsPolls.prototype.deletePoll = function(oLink, iId)
 {
     var $this = this;