Jelajahi Sumber

Ticket #4558 - Build-in API support: Different.

AntonLV 1 tahun lalu
induk
melakukan
759b435563

+ 27 - 15
template/scripts/BxBaseDashboardServices.php

@@ -80,10 +80,18 @@ class BxBaseDashboardServices extends BxDol
         foreach($aModules as $aModule) {
             $oModule = BxDolModule::getInstance($aModule['name']);
             $CNF = &$oModule->_oConfig->CNF;
-            if (method_exists($oModule->_oDb, 'getStatByProfile')){
+            if(method_exists($oModule->_oDb, 'getStatByProfile')) {
                 $a = $bEmpty ? [] : $oModule->_oDb->getStatByProfile($iProfileId);
-                $aIcon = explode($CNF['ICON'], ' ');
-                $aData[] = array_merge(['key' => $aModule['name'], 'title' => $aModule['title'], 'add_url' => $CNF['URI_ADD_ENTRY'], 'url' => $oPermalink->permalink($CNF['URL_HOME']), 'action' => 'views', 'icon' => $CNF['ICON'], 'type' => 'simple'], $a);
+
+                $aData[] = array_merge([
+                    'key' => $aModule['name'], 
+                    'title' => $aModule['title'], 
+                    'add_url' => $CNF['URI_ADD_ENTRY'], 
+                    'url' => $oPermalink->permalink($CNF['URL_HOME']), 
+                    'action' => 'views', 
+                    'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '', 
+                    'type' => 'simple'
+                ], $a);
             }
         }
        
@@ -93,21 +101,25 @@ class BxBaseDashboardServices extends BxDol
             $CNF = &$oModule->_oConfig->CNF;
             if (method_exists($oModule->_oDb, 'getStatByProfile')){
                 $a = $bEmpty ? [] : $oModule->_oDb->getStatByProfile($iProfileId);
-                $aIcon = explode($CNF['ICON'], ' ');
 
-                $aContexts = $oModule->_oDb->getEntriesBy(['type' => 'author', 'author' => $iProfileId]);
                 $iMembers = 0;
-                if (!$bEmpty){
-                    foreach($aContexts as $aContext) {
-                        $oProfile = BxDolProfile::getInstanceByContentAndType($aContext[$CNF['FIELD_ID']], $aModule['name']);
-
-                        $oConnection = BxDolConnection::getObjectInstance($CNF['OBJECT_CONNECTIONS']);
-                        if($oConnection){
+                if(!$bEmpty && isset($CNF['OBJECT_CONNECTIONS']) && ($sConnection = $CNF['OBJECT_CONNECTIONS'])) {
+                    $aContexts = $oModule->_oDb->getEntriesBy(['type' => 'author', 'author' => $iProfileId]);
+                    foreach($aContexts as $aContext)
+                        if(($oProfile = BxDolProfile::getInstanceByContentAndType($aContext[$CNF['FIELD_ID']], $aModule['name'])) !== false && ($oConnection = BxDolConnection::getObjectInstance($sConnection)) !== false)
                             $iMembers += $oConnection->getConnectedInitiatorsCount($oProfile->id(), true);
-                        }
-                    }
-                } 
-                $aData[] = array_merge(['key' => $aModule['name'], 'title' => $aModule['title'], 'url' => $oPermalink->permalink($CNF['URL_HOME']), 'add_url' => str_replace('edit-', 'create-',$CNF['URI_EDIT_ENTRY']), 'action' => 'member',  'icon' => $CNF['ICON'], 'type' => 'simple', 'members' => $iMembers], $a);
+                }
+
+                $aData[] = array_merge([
+                    'key' => $aModule['name'], 
+                    'title' => ($_sTitle = '_' . $aModule['name']) && ($sTitle = _t($_sTitle)) && $_sTitle != $sTitle ? $sTitle : $aModule['title'], 
+                    'url' => $oPermalink->permalink($CNF['URL_HOME']), 
+                    'add_url' => str_replace('edit-', 'create-',$CNF['URI_EDIT_ENTRY']), 
+                    'action' => 'member',  
+                    'icon' => !empty($CNF['ICON']) ? $CNF['ICON'] : '', 
+                    'type' => 'simple', 
+                    'members' => $iMembers
+                ], $a);
             }
         }
         

+ 7 - 9
template/scripts/BxBaseFormView.php

@@ -390,24 +390,22 @@ 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);
+                    if(!empty($aInput['content_id']) && ($sUpr = reset($aInput['uploaders'])) && isset($aInput['storage_object']) && ($sStg = $aInput['storage_object']) && ($oUploader = BxDolUploader::getObjectInstance($sUpr, $sStg, genRndPwd(8))) !== false){
+                        $sData = $oUploader->getGhostsWithOrder((int)bx_get_logged_profile_id(), 'json', $aInput['images_transcoder'], $aInput['content_id']);
+                        if($sData && ($aData = json_decode($sData, true)) && !empty($aData['g']) && is_array($aData['g'])) {
                             $aInput['values_src'] = array_values($aData['g']);
+
                             $aGhostIds = [];
-                            foreach ($aData['g'] as &$aGhost) {
+                            array_walk($aData['g'], function($aGhost) use (&$aGhostIds) {
                                 $aGhostIds[] = $aGhost['file_id'];
-                            }
+                            });
+
                             $aInput['value'] = implode(',', $aGhostIds);
                         }
-                      
                     }
                 }
                 

+ 10 - 7
template/scripts/BxBasePage.php

@@ -504,13 +504,16 @@ class BxBasePage extends BxDolPage
     public function getPageAPI ($aBlocks = [])
     {
         define('BX_API_PAGE', true);
-        $query_string  = '';
 
-        if (isset(bx_get('params')[2]) && bx_get('params')[2] != ''){
-            $array = json_decode(bx_get('params')[2], true);
-            $query_string = http_build_query($array);
-            parse_str($query_string, $a);
-            $_GET = array_merge($_GET, $a);
+        $aGetParams = bx_get('params');
+        $bGetParams = $aGetParams !== false;
+
+        $sQueryString = '';
+        if($bGetParams && !empty($aGetParams[2]) && ($_aGetParams = json_decode($aGetParams[2], true)) && is_array($_aGetParams)) {
+            $sQueryString = http_build_query($_aGetParams);
+
+            parse_str($sQueryString, $aQueryString);
+            $_GET = array_merge($_GET, $aQueryString);
         }
 
         $bIsAvailable = $this->_isAvailablePage($this->_aObject);
@@ -528,7 +531,7 @@ class BxBasePage extends BxDolPage
             'keywords' => $this->_getPageMetaKeywords(),
             'image' => '',
             'uri' => $this->_aObject['uri'],
-            'url' =>  ((bx_get('params')[0] ? bx_get('params')[0] : $this->_aObject['uri'] ) . ($query_string != '' ? '?' . $query_string : '')),
+            'url' => ($bGetParams && !empty($aGetParams[0]) ? $aGetParams[0] : $this->_aObject['uri']) . ($sQueryString != '' ? '?' . $sQueryString : ''),
             'author' => $this->_aObject['author'],
             'added' => $this->_aObject['added'],
             'module' => $sModule,