Browse Source

#556 Files module - Timeline post

Alex Trofimov 9 years ago
parent
commit
9fd8a89fdf

+ 47 - 2
modules/boonex/files/classes/BxFilesModule.php

@@ -119,13 +119,20 @@ class BxFilesModule extends BxBaseModTextModule
             return false;
 
         if (isset($aData[$CNF['FIELD_FILE_ID']]) && $aData[$CNF['FIELD_FILE_ID']]) 
-            return $oStorage->getFile($aData[$CNF['FIELD_FILE_ID']]);
+            return $this->_addFileFields($oStorage->getFile($aData[$CNF['FIELD_FILE_ID']]));
         
         $aGhostFiles = $oStorage->getGhosts ($aData[$CNF['FIELD_AUTHOR']], $aData[$CNF['FIELD_ID']]);
         if (!$aGhostFiles)
             return false;
 
-        return array_pop($aGhostFiles);
+        return $this->_addFileFields(array_pop($aGhostFiles));
+    }
+
+    protected function _addFileFields($aFile) 
+    {
+        if (is_array($aFile))
+            $aFile['is_image'] = in_array($aFile['ext'], array('jpg', 'jpeg', 'png', 'gif', /* when ImageMagick is used - 'tif', 'tiff', 'bmp', 'ico', 'psd' */));
+        return $aFile;
     }
 
     public function serviceEntityFilePreview($iContentId = 0)
@@ -171,6 +178,44 @@ class BxFilesModule extends BxBaseModTextModule
             $this->_oDb->updateFileData ($aContentInfo[$CNF['FIELD_ID']], $sData);
         }
     }
+
+    public function serviceGetTimelinePost($aEvent)
+    {
+        $a = parent::serviceGetTimelinePost($aEvent);
+
+        $aContentInfo = $this->_oDb->getContentInfoById($aEvent['object_id']);
+        $aFile = $this->getContentFile($aContentInfo);
+        if (!$aFile['is_image']) {
+            $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->CNF['OBJECT_STORAGE']);
+            $sIcon = $oStorage ? $oStorage->getFontIconNameByFileName($aFile['file_name']) : 'file-o';
+            $a['content'] = $this->_oTemplate->parseHtmlByName('timeline_post.html', array(
+                'title' => $a['content']['title'],
+                'title_attr' => bx_html_attribute($a['content']['title']),
+                'url' => $a['content']['url'],
+                'icon' => '<i class="sys-icon ' . $sIcon . '"></i>',
+            ));
+        }
+        
+        return $a;
+    }
+    
+    protected function _getImagesForTimelinePost($aEvent, $aContentInfo, $sUrl)
+    {
+        $aFile = $this->getContentFile($aContentInfo);
+        if (!$aFile)
+            return array();
+
+        if (!$aFile['is_image'])
+            return array();
+
+        $sPhotoThumb = '';
+        if ($oImagesTranscoder = BxDolTranscoderImage::getObjectInstance($this->_oConfig->CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
+            $sPhotoThumb = $oImagesTranscoder->getFileUrl($aFile['id']);
+
+        return array(
+		    array('url' => $sUrl, 'src' => $sPhotoThumb),
+		);
+    }
 }
 
 /** @} */

+ 1 - 1
modules/boonex/files/classes/BxFilesTemplate.php

@@ -24,7 +24,7 @@ class BxFilesTemplate extends BxBaseModTextTemplate
     {
         $aFile = BxDolModule::getInstance($this->MODULE)->getContentFile($aData);
 
-        if (!in_array($aFile['ext'], array('jpg', 'jpeg', 'png', 'gif', /* when ImageMagick is used - 'tif', 'tiff', 'bmp', 'ico', 'psd' */)))
+        if (!$aFile['is_image'])
             return array('', '');
 
         $sPhotoThumb = '';

+ 5 - 0
modules/boonex/files/template/timeline_post.html

@@ -0,0 +1,5 @@
+<div class="bx-tl-item-text">
+    <div class="bx-tl-title bx-def-margin-sec-bottom bx-def-font-h3">
+        <a href="__url__" title="__title_attr__" class="bx-tl-title">__icon__ __title__</a>
+    </div>
+</div>