Browse Source

#4148 - Build-in API support

roman.lesnikov@gmail.com 3 years ago
parent
commit
95d6db49dc

+ 1 - 1
install/sql/system.sql

@@ -709,7 +709,7 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_api_access_by_origin', '_adm_stg_cpt_option_sys_api_access_by_origin', '', 'checkbox', '', '', '', 10),
 (@iCategoryId, 'sys_api_access_by_key', '_adm_stg_cpt_option_sys_api_access_by_key', '', 'checkbox', '', '', '', 20),
 (@iCategoryId, 'sys_api_access_unsafe_services', '_adm_stg_cpt_option_sys_api_access_unsafe_services', '', 'checkbox', '', '', '', 30);
-
+(@iCategoryId, 'sys_api_comments_flat', '_adm_stg_cpt_option_sys_api_comments_flat', '', 'checkbox', '', '', '', 30);
 --
 -- Table structure for table `sys_options_mixes`
 --

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

@@ -689,7 +689,7 @@ class BxBaseModProfileTemplate extends BxBaseModGeneralTemplate
 
         $sImageUrl = $this->getImageUrl($sNoImage);
         if(!$sImageUrl)
-            $sImageUrl = $this->getImageUrl(substr($sNoImage, 0, strrpos($sNoImage, '-')) . (bx_is_api() ? '.svg' : '.png'));
+            $sImageUrl = bx_is_api() ? '' : $this->getImageUrl(substr($sNoImage, 0, strrpos($sNoImage, '-')) . '.svg');
 
         return $sImageUrl;
     }

+ 1 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1713,6 +1713,7 @@
     <string name="_adm_stg_cpt_option_sys_api_access_by_origin"><![CDATA[Allow access by origin]]></string>
     <string name="_adm_stg_cpt_option_sys_api_access_by_key"><![CDATA[Allow access with API key]]></string>
     <string name="_adm_stg_cpt_option_sys_api_access_unsafe_services"><![CDATA[Access to unsafe services]]></string>
+    <string name="_adm_stg_cpt_option_sys_api_comments_flat"><![CDATA[Flat comments]]></string>
 
 	<string name="_adm_stg_cpt_type_system"><![CDATA[System]]></string>
 	<string name="_adm_stg_scs_save"><![CDATA[Settings were successfully saved]]></string>

+ 1 - 0
modules/boonex/russian/data/langs/system/ru.xml

@@ -1691,6 +1691,7 @@
     <string name="_adm_stg_cpt_option_sys_api_access_by_origin"><![CDATA[Доступ по "origin" заголовку]]></string>
     <string name="_adm_stg_cpt_option_sys_api_access_by_key"><![CDATA[Доступ по API ключу]]></string>
     <string name="_adm_stg_cpt_option_sys_api_access_unsafe_services"><![CDATA[Доступ к небезопасным сервисам]]></string>
+    <string name="_adm_stg_cpt_option_sys_api_comments_flat"><![CDATA[Линейные комментарии]]></string>
 
     <string name="_adm_stg_cpt_type_system"><![CDATA[Система]]></string>
     <string name="_adm_stg_scs_save"><![CDATA[Настройки удачно сохранены]]></string>

+ 0 - 10
template/scripts/BxBaseCmts.php

@@ -181,16 +181,6 @@ class BxBaseCmts extends BxDolCmts
         
     }
 
-    function decodeData ($a)
-    {
-        foreach ($a as $i => $r) {
-            if (isset($r['cmt_author_id']))
-                $a[$i]['author_data'] = BxDolProfile::getData($r['cmt_author_id']);
-        }
-
-        return $a;
-    }
-
     /**
      * get full comments block with initializations
      */

+ 11 - 2
template/scripts/BxBaseCmtsServices.php

@@ -518,7 +518,7 @@ class BxBaseCmtsServices extends BxDol
         $aBp = !isset($aParams['aBp']) ? [] : $aParams['aBp'];
         $aDp = ['in_designbox' => false, 'show_empty' => false];
         
-        $aDp['type'] = 'flat';//$aDp['type'] = 'threaded';
+        $aDp['type'] = !getParam('sys_api_access_unsafe_services') ? 'threaded' : 'flat';
         $aBp['type'] = 'head';
         $oCmts->getParams($aBp, $aDp);
         $oCmts->prepareParams($aBp, $aDp);
@@ -543,7 +543,16 @@ class BxBaseCmtsServices extends BxDol
         
         $aCmtsRv = [];
         foreach ($aCmts as $aCmt) {
-            $aCmtsRv[] = $oCmts->getCommentStructure($aCmt['cmt_id'], $aBp, $aDp);
+            $oCmt = $oCmts->getCommentStructure($aCmt['cmt_id'], $aBp, $aDp);
+            $sKey = array_keys($oCmt)[0];
+            if ($oCmt[$sKey]['data']['cmt_parent_id'] > 0){
+                $aParent = $oCmts->getCommentSimple((int)$oCmt[$sKey]['data']['cmt_parent_id']);
+                $oCmt[$sKey]['data']['cmt_parent'] = [
+                    'data' => $aParent,
+                    'author_data' => BxDolProfile::getData($aParent['cmt_author_id'])
+                ];
+            }
+            $aCmtsRv[] = $oCmt;
         }
         $aData = [
             'unit' => 'comments',