Kaynağa Gözat

#4558 - Build-in API support (fix uploaders)

romanlesnikov 1 yıl önce
ebeveyn
işleme
f0b8d82f3d

+ 1 - 1
modules/base/profile/classes/BxBaseModProfileUploaderCoverCrop.php

@@ -71,7 +71,7 @@ class BxBaseModProfileUploaderCoverCrop extends BxTemplUploaderHTML5
 
             // for cover image show only unassigned ghosts and currently set covers
             if ($aFile['file_id'] == $aContentInfo[$CNF['FIELD_COVER']] || $aFile['file_id'] != $aContentInfo[$CNF['FIELD_PICTURE']])
-                $aResult[] = $aFile;
+                $aResult[$aFile['file_id'] = $aFile;
 
         }
 

+ 1 - 1
modules/base/profile/classes/BxBaseModProfileUploaderPictureCrop.php

@@ -70,7 +70,7 @@ class BxBaseModProfileUploaderPictureCrop extends BxTemplUploaderCrop
 
             // for profile pictures show only unassigned ghosts and currently set profile pictures
             if (($aFile['file_id'] == $aContentInfo[$CNF['FIELD_PICTURE']] || $aFile['file_id'] != $aContentInfo[$CNF['FIELD_COVER']]))
-                $aResult[] = $aFile;            
+                $aResult[$aFile['file_id'] = $aFile;            
         }
 
         if ('array' == $sFormat) {

+ 15 - 0
template/scripts/BxBaseFormView.php

@@ -390,10 +390,25 @@ class BxBaseFormView extends BxDolForm
                     $oStorage = BxDolStorage::getObjectInstance($aInput['storage_object']);
                     $aInput['ext_allow'] = $oStorage->getObjectData()['ext_allow'];
                     $aInput['ext_deny'] = $oStorage->getObjectData()['ext_deny'];
+                    
                     $aInput['ghost_template'] = '';
                     $aInput['value'] = '';
                     $aInput['values'] = '';
                     $aInput['values_src'] = '';
+                    if (!empty($aInput['content_id'])){
+                        $oUploader = BxDolUploader::getObjectInstance($aInput['uploaders'][0], $aInput['storage_object'], genRndPwd(8));
+                        $oData = $oUploader->getGhostsWithOrder((int)bx_get_logged_profile_id(), 'json', $aInput['images_transcoder'], $aInput['content_id']);
+                        if ($oData){
+                            $aData = json_decode($oData, true);
+                            $aInput['values_src'] = array_values($aData['g']);
+                            $aGhostIds = [];
+                            foreach ($aData['g'] as &$aGhost) {
+                                $aGhostIds[] = $aGhost['file_id'];
+                            }
+                            $aInput['value'] = implode(',', $aGhostIds);
+                        }
+                      
+                    }
                 }
                 
                 if (isset($aInput['type']) && 'custom' == $aInput['type']){

+ 9 - 4
template/scripts/BxBaseUploaderCrop.php

@@ -82,10 +82,15 @@ class BxBaseUploaderCrop extends BxDolUploader
 
     public function handleUploads ($iProfileId, $mixedFiles, $isMultiple = true, $iContentId = false, $bPrivate = true)
     {
-        ob_start();
-        parent::handleUploads ($iProfileId, $mixedFiles, $isMultiple, $iContentId, $bPrivate);
-        $s = ob_get_clean();
-        echo strip_tags(str_replace('window.parent.', 'window.', $s));
+        if (bx_is_api()){
+             return parent::handleUploads ($iProfileId, $mixedFiles, $isMultiple, $iContentId, $bPrivate);;
+         }
+         else{
+            ob_start();
+            parent::handleUploads ($iProfileId, $mixedFiles, $isMultiple, $iContentId, $bPrivate);
+            $s = ob_get_clean();
+            echo strip_tags(str_replace('window.parent.', 'window.', $s));
+        }
     }
 
 }