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

#4148 - Build-in API support (images)

roman.lesnikov@gmail.com 3 éve
szülő
commit
8f807f5fdd

+ 23 - 0
inc/utils.inc.php

@@ -2353,4 +2353,27 @@ function bx_api_check_origins()
     check_logged();
 }
 
+function bx_get_image_api($sStorage, $iId)
+{
+    $oS = BxDolStorage::getObjectInstance($sStorage);
+    $aFile = $oS->getFile($iId);
+    $sUrl = $oS->getFileUrlById($iId);
+    $iWidth = 500;
+    $iHeight = 500;
+    
+    if(!empty($aFile['dimensions'])){
+        $aTmp = explode('x', $aFile['dimensions']);
+        $iWidth = (int) $aTmp[0];
+        $$iHeight = (int) $aTmp[1];
+    }
+    if (!empty($sUrl)){
+        return [
+            'src' => $sUrl,
+            'width' => $iWidth,
+            'height' => $iHeight,
+        ];
+    }    
+    return false;
+}
+
 /** @} */

+ 1 - 1
modules/base/general/classes/BxBaseModGeneralSearchResult.php

@@ -221,7 +221,7 @@ class BxBaseModGeneralSearchResult extends BxTemplSearchResult
                 $a[$i]['author_data'] = BxDolProfile::getData($r[$CNF['FIELD_AUTHOR']]);
 
             $a[$i]['url'] = $this->decodeDataUrl($oContentInfo, $r);
-            $a[$i]['url_thumb'] = $oContentInfo->getContentThumb($r['id']);
+            $a[$i]['image'] = $oContentInfo->getContentThumb($r['id']);
             $a[$i]['summary_plain'] = $this->decodeDataSummaryPlain($oContentInfo, $r);
         }
 

+ 5 - 1
modules/base/text/classes/BxBaseModTextModule.php

@@ -318,7 +318,11 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
     public function serviceGetThumb ($iContentId, $sTranscoder = '') 
     {
         $CNF = &$this->_oConfig->CNF;
-
+        if(bx_is_api()){
+            $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
+            return bx_get_image_api($CNF['OBJECT_STORAGE'], $aContentInfo[$CNF['FIELD_THUMB']]);
+        }
+            
         if(empty($sTranscoder) && !empty($CNF['OBJECT_IMAGES_TRANSCODER_GALLERY']))
             $sTranscoder = $CNF['OBJECT_IMAGES_TRANSCODER_GALLERY'];
 

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

@@ -630,6 +630,13 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
                 $sImage = $o->getFileUrlById($mixedImage['id']);
         }
         
+        if(bx_is_api() ){
+            if($sImage){
+                $aVars['image'] = bx_get_image_api($CNF['OBJECT_STORAGE'], $mixedImage['id']);
+            }
+            return $aVars;
+        }
+        
         $sAddClassPicture = "";
         $sAddCode = "";
         $oModule = $this->getModule();