소스 검색

#978 move attachments block to general module + enhancements in

Alex Trofimov 9 년 전
부모
커밋
432b321f06

+ 10 - 2
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -355,6 +355,14 @@ class BxBaseModGeneralModule extends BxDolModule
         return $this->_entityComments($CNF['OBJECT_COMMENTS'], $iContentId);
     }
 
+    /**
+     * Entry attachments block
+     */
+    public function serviceEntityAttachments ($iContentId = 0)
+    {
+        return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
+    }
+    
     /**
      * Delete content entry
      * @param $iContentId content id 
@@ -952,7 +960,7 @@ class BxBaseModGeneralModule extends BxDolModule
 
     // ====== PROTECTED METHODS
 
-    protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false)
+    protected function _serviceEntityForm ($sFormMethod, $iContentId = 0, $sDisplay = false, $sCheckFunction = false)
     {
         $iContentId = $this->_getContent($iContentId, false);
         if($iContentId === false)
@@ -961,7 +969,7 @@ class BxBaseModGeneralModule extends BxDolModule
         bx_import('FormsEntryHelper', $this->_aModule);
         $sClass = $this->_aModule['class_prefix'] . 'FormsEntryHelper';
         $oFormsHelper = new $sClass($this);
-        return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay);
+        return $oFormsHelper->$sFormMethod((int)$iContentId, $sDisplay, $sCheckFunction);
     }
 
     protected function _serviceTemplateFunc ($sFunc, $iContentId, $sFuncGetContent = 'getContentInfoById')

+ 94 - 0
modules/base/general/classes/BxBaseModGeneralTemplate.php

@@ -153,6 +153,21 @@ class BxBaseModGeneralTemplate extends BxDolModuleTemplate
         ));
     }
 
+    function entryAttachments ($aData, $aParams = array())
+    {
+        return $this->entryAttachmentsByStorage($this->getModule()->_oConfig->CNF['OBJECT_STORAGE'], $aData, $aParams);
+    }
+
+	function entryAttachmentsByStorage ($sStorage, $aData, $aParams = array())
+    {
+        if (!($a = $this->getAttachments($sStorage, $aData, $aParams)))
+            return '';
+
+    	return $this->parseHtmlByName('attachments.html', array(
+            'bx_repeat:attachments' => $a,
+        ));
+    }
+    
     protected function getUnitMetaItem($sName, $sContent, $aAttrs = array(), $sTemplate = 'unit_meta_item.html')
     {
         if(empty($sContent))
@@ -182,6 +197,85 @@ class BxBaseModGeneralTemplate extends BxDolModuleTemplate
 
         return $this->parseHtmlByName($sTemplate, $aTmplVars);
     }
+
+	protected function getAttachments ($sStorage, $aData, $aParams = array())
+    {
+        $CNF = &$this->getModule()->_oConfig->CNF;
+
+        $oStorage = BxDolStorage::getObjectInstance($sStorage);
+        $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
+        $aTranscodersVideo = false;
+
+        if (isset($CNF['OBJECT_VIDEOS_TRANSCODERS']) && $CNF['OBJECT_VIDEOS_TRANSCODERS'])
+            $aTranscodersVideo = array (
+                'poster' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']),
+                'mp4' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']),
+                'webm' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['webm']),
+            );
+
+        $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]);
+        if (!$aGhostFiles)
+            return false;
+
+        $sFilterField = isset($aParams['filter_field']) ? $aParams['filter_field'] : $CNF['FIELD_THUMB'];
+		if(!empty($sFilterField) && isset($aData[$sFilterField]))
+	        foreach ($aGhostFiles as $k => $a) {
+	            // don't show thumbnail in attachments
+	            if ($a['id'] == $aData[$sFilterField])
+	                unset($aGhostFiles[$k]);
+	        }
+
+        if(!$aGhostFiles)
+            return false;
+
+        $aAttachmnts = array();
+        foreach ($aGhostFiles as $k => $a) {
+
+            $isImage = $oTranscoder && (0 === strncmp('image/', $a['mime_type'], 6)); // preview for images, transcoder object for preview must be defined
+            $isVideo = $aTranscodersVideo && (0 === strncmp('video/', $a['mime_type'], 6)); // preview for videos, transcoder object for video must be defined
+            $sUrlOriginal = $oStorage->getFileUrlById($a['id']);
+            $sImgPopupId = 'bx-messages-atachment-popup-' . $a['id'];
+
+            // images are displayed with preview and popup upon clicking
+            $a['bx_if:image'] = array (
+                'condition' => $isImage,
+                'content' => array (
+                    'url_original' => $sUrlOriginal,
+                    'attr_file_name' => bx_html_attribute($a['file_name']),
+                    'popup_id' => $sImgPopupId,
+                    'url_preview' => $isImage ? $oTranscoder->getFileUrl($a['id']) : '',
+                    'popup' =>  BxTemplFunctions::getInstance()->transBox($sImgPopupId, '<img src="' . $sUrlOriginal . '" />', true, true),
+                ),
+            );
+
+            // videos are displayed inline
+            $a['bx_if:video'] = array (
+                'condition' => $isVideo,
+                'content' => array (
+                    'video' => $isVideo && $aTranscodersVideo ? BxTemplFunctions::getInstance()->videoPlayer(
+                        $aTranscodersVideo['poster']->getFileUrl($a['id']), 
+                        $aTranscodersVideo['mp4']->getFileUrl($a['id']), 
+                        $aTranscodersVideo['webm']->getFileUrl($a['id']),
+                        false, ''
+                    ) : '',
+                ),
+            );
+
+            // non-images are displayed as text links to original file
+            $a['bx_if:not_image'] = array (
+                'condition' => !$isImage && !$isVideo,
+                'content' => array (
+                    'url_original' => $sUrlOriginal,
+                    'attr_file_name' => bx_html_attribute($a['file_name']),
+                    'file_name' => bx_process_output($a['file_name']),
+                ),
+            );
+
+            $aAttachmnts[] = $a;
+        }
+
+        return $aAttachmnts;
+    }
 }
 
 /** @} */

+ 28 - 0
modules/base/general/template/attachments.html

@@ -0,0 +1,28 @@
+<div class="bx-base-general-attachments bx-clearfix">
+
+    <bx_repeat:attachments>
+        <div class="bx-base-general-attachment bx-def-box bx-def-color-bg-box bx-def-gal-img-size" style="float:left;">
+            <bx_if:image>
+                <a href="javascript:void(0);" title="__attr_file_name__" onclick="$('#__popup_id__').dolPopupImage('__url_original__', $(this).parent())">
+                    <img class="bx-def-gal-img-size" src="__url_preview__" />
+                </a>
+                __popup__
+            </bx_if:image>
+            <bx_if:video>
+                __video__
+            </bx_if:video>
+            <bx_if:not_image>
+                <a href="__url_original__" title="__attr_file_name__">
+                    <div class="bx-def-round-corners bx-def-padding-sec">__file_name__</div>
+                </a>
+            </bx_if:not_image>
+        </div>
+    </bx_repeat:attachments>
+
+    <script>
+        $(document).ready(function() {
+            bx_center_content('.bx-base-general-attachments', '.bx-base-general-attachment', true);
+        });
+    </script>
+
+</div>

+ 14 - 0
modules/base/general/template/css/main.css

@@ -18,6 +18,20 @@
 	vertical-align: top;
 }
 
+/* attachments */
+.bx-base-general-attachments .bx-base-general-attachment video,
+.bx-base-general-attachments .bx-base-general-attachment {
+    width:18.75rem;
+    height:12.5rem;
+}
+
+.bx-base-general-attachments {
+    margin:-1px;
+}
+.bx-base-general-attachment {
+    margin:1px;
+}
+
 /* comments item */
 div.bx-base-general-comments div.bx-base-general-comments-element-holder,
 div.bx-base-general-comments div.bx-base-general-comments-counter-holder {

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

@@ -105,14 +105,6 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         return $this->_serviceTemplateFunc ('entryAuthor', $iContentId);
     }
 
-    /**
-     * Entry attachments block
-     */
-    public function serviceEntityAttachments ($iContentId = 0)
-    {
-        return $this->_serviceTemplateFunc ('entryAttachments', $iContentId);
-    }
-
     public function serviceEntityBreadcrumb ($iContentId = 0)
     {
     	if (!$iContentId)

+ 0 - 94
modules/base/text/classes/BxBaseModTextTemplate.php

@@ -86,21 +86,6 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
     	));
     }
 
-    function entryAttachments ($aData, $aParams = array())
-    {
-        return $this->entryAttachmentsByStorage($this->getModule()->_oConfig->CNF['OBJECT_STORAGE'], $aData, $aParams);
-    }
-
-	function entryAttachmentsByStorage ($sStorage, $aData, $aParams = array())
-    {
-        if (!($a = $this->getAttachments($sStorage, $aData, $aParams)))
-            return '';
-
-    	return $this->parseHtmlByName('attachments.html', array(
-            'bx_repeat:attachments' => $a,
-        ));
-    }
-
     protected function checkPrivacy ($aData, $isCheckPrivateContent, $oModule, $sTemplateName = '')
     {
         if ($isCheckPrivateContent && CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = $oModule->checkAllowedView($aData))) {
@@ -241,85 +226,6 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
         $sLinkMore = ' <a title="' . bx_html_attribute(_t('_sys_read_more', $sTitle)) . '" href="' . $sUrl . '"><i class="sys-icon ellipsis-h"></i></a>';
         return  strmaxtextlen($sText, (int)getParam($CNF['PARAM_CHARS_SUMMARY']), $sLinkMore);
     }
-
-	protected function getAttachments ($sStorage, $aData, $aParams = array())
-    {
-        $CNF = &$this->getModule()->_oConfig->CNF;
-
-        $oStorage = BxDolStorage::getObjectInstance($sStorage);
-        $oTranscoder = BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_IMAGES_TRANSCODER_PREVIEW']);
-        $aTranscodersVideo = false;
-
-        if ($CNF['OBJECT_VIDEOS_TRANSCODERS'])
-            $aTranscodersVideo = array (
-                'poster' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['poster']),
-                'mp4' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['mp4']),
-                'webm' => BxDolTranscoderImage::getObjectInstance($CNF['OBJECT_VIDEOS_TRANSCODERS']['webm']),
-            );
-
-        $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]);
-        if (!$aGhostFiles)
-            return false;
-
-        $sFilterField = isset($aParams['filter_field']) ? $aParams['filter_field'] : $CNF['FIELD_THUMB'];
-		if(!empty($sFilterField) && isset($aData[$sFilterField]))
-	        foreach ($aGhostFiles as $k => $a) {
-	            // don't show thumbnail in attachments
-	            if ($a['id'] == $aData[$sFilterField])
-	                unset($aGhostFiles[$k]);
-	        }
-
-        if(!$aGhostFiles)
-            return false;
-
-        $aAttachmnts = array();
-        foreach ($aGhostFiles as $k => $a) {
-
-            $isImage = $oTranscoder && (0 === strncmp('image/', $a['mime_type'], 6)); // preview for images, transcoder object for preview must be defined
-            $isVideo = $aTranscodersVideo && (0 === strncmp('video/', $a['mime_type'], 6)); // preview for videos, transcoder object for video must be defined
-            $sUrlOriginal = $oStorage->getFileUrlById($a['id']);
-            $sImgPopupId = 'bx-messages-atachment-popup-' . $a['id'];
-
-            // images are displayed with preview and popup upon clicking
-            $a['bx_if:image'] = array (
-                'condition' => $isImage,
-                'content' => array (
-                    'url_original' => $sUrlOriginal,
-                    'attr_file_name' => bx_html_attribute($a['file_name']),
-                    'popup_id' => $sImgPopupId,
-                    'url_preview' => $isImage ? $oTranscoder->getFileUrl($a['id']) : '',
-                    'popup' =>  BxTemplFunctions::getInstance()->transBox($sImgPopupId, '<img src="' . $sUrlOriginal . '" />', true, true),
-                ),
-            );
-
-            // videos are displayed inline
-            $a['bx_if:video'] = array (
-                'condition' => $isVideo,
-                'content' => array (
-                    'video' => $isVideo && $aTranscodersVideo ? BxTemplFunctions::getInstance()->videoPlayer(
-                        $aTranscodersVideo['poster']->getFileUrl($a['id']), 
-                        $aTranscodersVideo['mp4']->getFileUrl($a['id']), 
-                        $aTranscodersVideo['webm']->getFileUrl($a['id']),
-                        false, ''
-                    ) : '',
-                ),
-            );
-
-            // non-images are displayed as text links to original file
-            $a['bx_if:not_image'] = array (
-                'condition' => !$isImage && !$isVideo,
-                'content' => array (
-                    'url_original' => $sUrlOriginal,
-                    'attr_file_name' => bx_html_attribute($a['file_name']),
-                    'file_name' => bx_process_output($a['file_name']),
-                ),
-            );
-
-            $aAttachmnts[] = $a;
-        }
-
-        return $aAttachmnts;
-    }
 }
 
 /** @} */

+ 1 - 28
modules/base/text/template/attachments.html

@@ -1,28 +1 @@
-<div class="bx-base-text-attachments bx-clearfix">
-
-    <bx_repeat:attachments>
-        <div class="bx-base-text-attachment bx-def-box bx-def-color-bg-box bx-def-gal-img-size" style="float:left;">
-            <bx_if:image>
-                <a href="javascript:void(0);" title="__attr_file_name__" onclick="$('#__popup_id__').dolPopupImage('__url_original__', $(this).parent())">
-                    <img class="bx-def-gal-img-size" src="__url_preview__" />
-                </a>
-                __popup__
-            </bx_if:image>
-            <bx_if:video>
-                __video__
-            </bx_if:video>
-            <bx_if:not_image>
-                <a href="__url_original__" title="__attr_file_name__">
-                    <div class="bx-def-round-corners bx-def-padding-sec">__file_name__</div>
-                </a>
-            </bx_if:not_image>
-        </div>
-    </bx_repeat:attachments>
-
-    <script>
-        $(document).ready(function() {
-            bx_center_content('.bx-base-text-attachments', '.bx-base-text-attachment', true);
-        });
-    </script>
-
-</div>
+<bx_include_base:../modules/base/general/template/attachments.html />

+ 0 - 13
modules/base/text/template/css/main.css

@@ -230,19 +230,6 @@ div.bx-base-text-breadcrumb i {
     margin-bottom:0;
 }
 
-.bx-base-text-attachments .bx-base-text-attachment video,
-.bx-base-text-attachments .bx-base-text-attachment {
-    width:18.75rem;
-    height:12.5rem;
-}
-
-.bx-base-text-attachments {
-    margin:-1px;
-}
-.bx-base-text-attachment {
-    margin:1px;
-}
-
 .bx-base-text-entity-actions-all .bx-base-text-entity-share,
 .bx-base-text-entity-actions-all .bx-menu-btns-hor {
     display:inline-block;