1
0
Эх сурвалжийг харах

Ticket #4558 - Build-in API support: Image sizes.

AntonLV 2 жил өмнө
parent
commit
781524feee

+ 2 - 1
inc/classes/BxDolCmtsQuery.php

@@ -677,7 +677,8 @@ class BxDolCmtsQuery extends BxDolDb
         		`tf2e`.*,
         		`tf`.`file_name` AS `file_name`,
         		`tf`.`mime_type` AS `mime_type`,
-        		`tf`.`size` AS `size` 
+        		`tf`.`size` AS `size`,
+                        `tf`.`dimensions` AS `dimensions`
         	FROM `{$this->_sTableFiles2Entries}` AS `tf2e` 
         	LEFT JOIN `{$this->_sTableFiles}` AS `tf` ON (`tf2e`.`image_id` = `tf`.`id`) " . $sJoin . " 
         	WHERE 1 " . $sWhere;

+ 1 - 1
inc/utils.inc.php

@@ -2522,7 +2522,7 @@ function bx_api_get_image($sStorage, $iId)
     if(!empty($aFile['dimensions'])){
         $aTmp = explode('x', $aFile['dimensions']);
         $iWidth = (int) $aTmp[0];
-        $$iHeight = (int) $aTmp[1];
+        $iHeight = (int) $aTmp[1];
     }
     if (!empty($sUrl)){
         return [

+ 1 - 0
install/sql/system.sql

@@ -1745,6 +1745,7 @@ CREATE TABLE IF NOT EXISTS `sys_cmts_images` (
   `mime_type` varchar(128) NOT NULL,
   `ext` varchar(32) NOT NULL,
   `size` bigint(20) NOT NULL,
+  `dimensions` varchar(24) NOT NULL,
   `added` int(11) NOT NULL,
   `modified` int(11) NOT NULL,
   `private` int(11) NOT NULL,

+ 6 - 0
modules/boonex/timeline/classes/BxTimelineModule.php

@@ -5064,12 +5064,18 @@ class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolCon
         if(empty($aPhotos) || !is_array($aPhotos))
             return [];
 
+        $sStorage = $this->_oConfig->getObject('storage_photos');
         $oTranscoderSm = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_view'));
         $oTranscoderMd = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_medium'));
         $oTranscoderLg = BxDolTranscoderImage::getObjectInstance($this->_oConfig->getObject('transcoder_photos_big'));
 
         $aResult = [];
         foreach($aPhotos as $iPhotoId) {
+            if($this->_bIsApi) {
+                $aResult[] = bx_api_get_image($sStorage, $iPhotoId);
+                continue;
+            }
+
             $sPhotoSrcMd = $oTranscoderMd->getFileUrl($iPhotoId);
             if(empty($sPhotoSrcMd))
                 continue;

+ 11 - 8
template/scripts/BxBaseCmts.php

@@ -1547,17 +1547,20 @@ class BxBaseCmts extends BxDolCmts
                 $iWidth = $iHeight = 0;
 
                 if($bImage) {
-                    if($oTranscoder)
+                    if(!$this->_bIsApi && $oTranscoder)
                         $sPreview = $oTranscoder->getFileUrl($aFile['image_id']);
 
-                    $aImageInfo = BxDolImageResize::getInstance()->getImageSize($sFile);
-                    if(isset($aImageInfo['w']))
-                        $iWidth = (int)$aImageInfo['w'];
-                    if(isset($aImageInfo['h']))
-                        $iHeight = (int)$aImageInfo['h'];
+                    if(empty($aFile['dimensions'])) {
+                        $aFileInfo = $oStorage->getFile($aFile['image_id']);
+                        if(!empty($aFileInfo['dimensions']))
+                            $aFile['dimensions'] = $aFileInfo['dimensions'];
+                    }
+
+                    if(!empty($aFile['dimensions']))
+                        list($iWidth, $iHeight) = explode('x', $aFile['dimensions']);
                 }
 
-                if(!$sPreview)
+                if(!$this->_bIsApi && !$sPreview)
                     $sPreview = $this->_oTemplate->getIconUrl($oStorage->getIconNameByFileName($aFile['file_name']));
 
                 $aTmplVarsFile = array(
@@ -1572,7 +1575,7 @@ class BxBaseCmts extends BxDolCmts
                     'h' => $iHeight
                 );
 
-                if (bx_is_api()){
+                if($this->_bIsApi){
                     $aTmplImages[] = array(
                         'is_image' => $bImage,
                         'file' => $aTmplVarsFile['file'],