Răsfoiți Sursa

Merge branch 'master' of https://github.com/unaio/una

AntonLV 3 ani în urmă
părinte
comite
e7ef489dfd

+ 2 - 1
inc/classes/BxDolLocationFieldNominatim.php

@@ -89,7 +89,7 @@ class BxDolLocationFieldNominatim extends BxDolLocationField
             $aVars['id_status'] = $oForm->getInputId($aInput) . '_status';
             $aVars['location_string'] = $sLocationString;
             $aVars['nominatim_server'] = $this->getNominatimServer();
-            $aVars['nominatim_email'] = $this->getNominatimEmail();
+            $aVars['nominatim_email'] = $this->getNominatimEmail();            
 
             $sRet = $oForm->getTemplate()->parseHtmlByName('location_field_plain_auto.html', $aVars);
         }
@@ -133,6 +133,7 @@ class BxDolLocationFieldNominatim extends BxDolLocationField
                 'nominatim_server' => $this->getNominatimServer(),
                 'nominatim_email' => $this->getNominatimEmail(),
                 'inputs' => $sInputs,
+                'normalize_names' => getParam('sys_location_normalize_names') ? 1 : 0,
             ));
         }
         return $sRet;

+ 3 - 1
install/sql/system.sql

@@ -669,7 +669,9 @@ INSERT INTO `sys_options`(`category_id`, `name`, `caption`, `value`, `type`, `ex
 (@iCategoryId, 'sys_nominatim_server', '_adm_stg_cpt_option_sys_nominatim_server', 'https://nominatim.openstreetmap.org', 'digit', '', '', '', 40),
 (@iCategoryId, 'sys_nominatim_email', '_adm_stg_cpt_option_sys_nominatim_email', '', 'digit', '', '', '', 42),
 
-(@iCategoryId, 'sys_location_leaflet_provider', '_adm_stg_cpt_option_sys_location_leaflet_provider', 'OpenStreetMap.Mapnik', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:42:"get_options_location_leaflet_get_providers";s:5:"class";s:13:"TemplServices";}', '', '', 50);
+(@iCategoryId, 'sys_location_leaflet_provider', '_adm_stg_cpt_option_sys_location_leaflet_provider', 'OpenStreetMap.Mapnik', 'select', 'a:3:{s:6:"module";s:6:"system";s:6:"method";s:42:"get_options_location_leaflet_get_providers";s:5:"class";s:13:"TemplServices";}', '', '', 50),
+
+(@iCategoryId, 'sys_location_normalize_names', '_adm_stg_cpt_option_sys_location_normalize_names', '', 'checkbox', '', '', '', 60);
 
 --
 -- CATEGORY: Social Settings

+ 2 - 13
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -3504,20 +3504,9 @@ class BxBaseModGeneralModule extends BxDolModule
             return false;
         
         if (bx_is_api()){
-            $aForm = $oCmts->getFormPost(0);
-            if (is_array($aForm)){
-                $aForm['id'] = 2;
-            }
-            else
-                $aForm = ['id' => 2, 'type' => 'form', 'name' => 'comment', 'data' => $aForm->getCodeAPI(), 'request' => ['url' => '/api.php?r=' . $this->_aModule['name'] . '/entity_comments', 'immutable' => true]];
-            
-            
-            return [
-                ['id' => 1, 'type' => 'browse', 'data' => $oCmts->getCommentsBlockAPI([], ['in_designbox' => false, 'show_empty' => false])],
-                $aForm 
-            ];
+            return [bx_srv('system', 'get_form', [$sObject, $iId, 0], 'TemplCmtsServices')];
         }
-        return $oCmts->getCommentsBlock(array(), array('in_designbox' => false, 'show_empty' => false));
+        return $oCmts->getCommentsBlock([], ['in_designbox' => false, 'show_empty' => false]);
     }
 
     protected function _getFields($iContentId)

+ 1 - 1
modules/boonex/azure_connect/classes/BxAzrConModule.php

@@ -117,7 +117,7 @@ class BxAzrConModule extends BxBaseModConnectModule
             
             if ($iLocalProfileId && $oProfile = BxDolProfile::getInstance($iLocalProfileId)) {
                 // user already exists
-                $this->setLogged($oProfile ->id());
+                $this->setLogged($oProfile ->id(), '', true, true); // remember user
             }             
             else {  
                 // register new user

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

@@ -1604,6 +1604,7 @@
     <string name="_adm_stg_cpt_option_sys_location_map_default"><![CDATA[Location map provider]]></string>
     <string name="_adm_stg_cpt_option_sys_location_map_zoom_default"><![CDATA[Location map zoom]]></string>
     <string name="_adm_stg_cpt_option_sys_location_leaflet_provider"><![CDATA[Leaflet tile layers provider]]></string>
+    <string name="_adm_stg_cpt_option_sys_location_normalize_names"><![CDATA[Normalize geographic names]]></string>
     <string name="_adm_stg_cpt_option_sys_maps_api_key"><![CDATA[Google Maps API key]]></string>
     <string name="_adm_stg_cpt_option_sys_embed_default"><![CDATA[Embeds provider]]></string>
     <string name="_adm_stg_cpt_option_sys_embedly_api_key"><![CDATA[Embed.ly API key (fill in to use instead of Iframely)]]></string>

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

@@ -1583,6 +1583,7 @@
     <string name="_adm_stg_cpt_option_sys_location_map_default"><![CDATA[Поставщик для отображения карт]]></string>
     <string name="_adm_stg_cpt_option_sys_location_map_zoom_default"><![CDATA[Увеличение карты]]></string>
     <string name="_adm_stg_cpt_option_sys_location_leaflet_provider"><![CDATA[Поставщик карт для Leaflet]]></string>
+    <string name="_adm_stg_cpt_option_sys_location_normalize_names"><![CDATA[Нормализация географических названий]]></string>
     <string name="_adm_stg_cpt_option_sys_maps_api_key"><![CDATA[Ключ Google Maps API]]></string>
     <string name="_adm_stg_cpt_option_sys_embed_default"><![CDATA[Поставщик встраиваемого кода]]></string>
     <string name="_adm_stg_cpt_option_sys_embedly_api_key"><![CDATA[Ключ Embed.ly API (заполните, чтобы использовать вместо Iframely)]]></string>

+ 14 - 8
template/location_field_plain.html

@@ -70,15 +70,21 @@
                 if ('undefined' !== typeof(oResult[0].address)) {
                     if ('undefined' !== typeof(oResult[0].address.state) && 0 == $('input[name="__name___state"]').val().length)
                         $('input[name="__name___state"]').val(oResult[0].address.state);
+                    else if (__normalize_names__ && $('input[name="__name___state"]').val() != oResult[0].address.state)
+                        $('input[name="__name___state"]').val(oResult[0].address.state);
 
-                    if (0 == $('input[name="__name___city"]').val().length) {
-                        if ('undefined' !== typeof(oResult[0].address.city))
-                            $('input[name="__name___city"]').val(oResult[0].address.city);
-                        else if ('undefined' !== typeof(oResult[0].address.town))
-                            $('input[name="__name___city"]').val(oResult[0].address.town);
-                        else if ('undefined' !== typeof(oResult[0].address.village))
-                            $('input[name="__name___city"]').val(oResult[0].address.village);
-                    }
+                    var sCity = '';
+                    if ('undefined' !== typeof(oResult[0].address.city))
+                        sCity = oResult[0].address.city;
+                    else if ('undefined' !== typeof(oResult[0].address.town))
+                        sCity = oResult[0].address.town;
+                    else if ('undefined' !== typeof(oResult[0].address.village))
+                        sCity = oResult[0].address.village;
+
+                    if (sCity && 0 == $('input[name="__name___city"]').val().length)
+                        $('input[name="__name___city"]').val(sCity);
+                    else if (__normalize_names__ && sCity && $('input[name="__name___city"]').val() != sCity)
+                        $('input[name="__name___city"]').val(sCity);
                 }
                 if ('undefined' !== typeof(oResult[0].licence))
                     $('.bx-form-input-location-__name__ .bx-form-input-location-copyright').html(oResult[0].licence);

+ 29 - 9
template/scripts/BxBaseCmts.php

@@ -134,26 +134,46 @@ class BxBaseCmts extends BxDolCmts
         return $this->_oTemplate->_wrapInTagJsCode("if(window['" . $this->_sJsObjName . "'] == undefined) var " . $this->_sJsObjName . " = new " . $this->_sJsObjClass . "(" . json_encode($aParams) . "); " . $this->_sJsObjName . ".cmtInit();");
     }
 
-    function getCommentsBlockAPI($aBp = [], $aDp = [])
+    function getCommentsBlockAPI($aBp = [], $aDp = [], $iCommentId = 0, $iStart = 0)
     {
         $mixedResult = $this->isViewAllowed();
         if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
             return $mixedResult; // TODO: error checking
-
+        
+        $aBp['type'] = 'head';
         $this->_getParams($aBp, $aDp);
         $this->_prepareParams($aBp, $aDp);
+        $aBp['order']['way'] = 'desc';
+        $aBp['order_way'] = 'desc';
+        $aBp['start'] = $iStart ; 
+        $aPp = $aBp['per_view'];
+        $aBp['per_view'] =  $aBp['per_view'] + 1; 
 
-        $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
+        $aCmts = [];
+        
+        if ($iCommentId == 0)
+            $aCmts = $this->getCommentsArray($aBp['vparent_id'], $aBp['filter'], $aBp['order'], $aBp['start'], $aBp[($aBp['init_view'] != -1 ? 'init' : 'per') . '_view']);
+        else
+            $aCmts = [['cmt_id' => $iCommentId]];
+        
+        $iStartFrom = 0;
+        if (count($aCmts) == $aBp['per_view']){
+            $aBp['per_view'] = $aPp;
+            $aCmts = array_slice($aCmts, 0, $aBp['per_view']); 
+            $iStartFrom = $aBp['start'] + $aBp['per_view'];
+        }
+            
         $aCmtsRv = [];
         
         foreach ($aCmts as $aCmt) {
             $aCmtsRv[] = $this->getCommentStructure($aCmt['cmt_id'], $aBp, $aDp);
         }
-
-       // print_r($aCmtsRv);
         
         return [
             'unit' => 'comments',
+            'start' => $iStartFrom,
+            'module' => $this->_sSystem, 
+            'object_id' => $this->_iId,
             'data' => $aCmtsRv,
         ];
     }
@@ -1178,7 +1198,7 @@ class BxBaseCmts extends BxDolCmts
             if(!$bCmtText && !$bImageIds) {
                 $oForm->aInputs['cmt_text']['error'] =  _t('_Please enter characters');
                 $oForm->setValid(false);
-                return bx_is_api() ? $oForm : ['form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id];
+                return bx_is_api() ? ['form' => $oForm, 'res' => 0] : ['form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id];
             }
 
             $aParent = [];
@@ -1227,16 +1247,16 @@ class BxBaseCmts extends BxDolCmts
                 if(($mixedResult = $this->onPostAfter($iCmtId, $aDp)) !== false){
                     if (bx_is_api()){
                         $this->_unsetFormObject(BX_CMT_ACTION_POST);
-                        return $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId);
+                        return ['form' => $this->_getForm(BX_CMT_ACTION_POST, $iCmtParentId), 'res' => $iCmtId];
                     }
                     else{
-                        return $mixedResult;
+                         return ['form' => $mixedResult, 'res' => $iCmtId];
                     }
                 }
             }
             return bx_is_api() ? ['id' => 1, 'type' => 'msg', 'data' => _t('_cmt_err_cannot_perform_action')] : ['msg' => _t('_cmt_err_cannot_perform_action')];
         }
-        return bx_is_api() ? $oForm : ['form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id];
+        return bx_is_api() ? ['form' => $oForm, 'res' => 0] : ['form' => $oForm->getCode($bDynamic), 'form_id' => $oForm->id];
     }
 
     protected function _getFormEdit($iCmtId, $aDp = [])

+ 41 - 0
template/scripts/BxBaseCmtsServices.php

@@ -407,6 +407,47 @@ class BxBaseCmtsServices extends BxDol
             'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
         );
     }
+    
+    public function serviceGetForm($sObject, $iId, $iParent)
+    {
+        $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
+        if (!$oCmts || !$oCmts->isEnabled())
+            return false;
+        
+        $oForm = $oCmts->getFormPost($iParent);
+        
+        if (isset($oForm['form'])){
+            $aRv = [
+                'id' => '1', 
+                'type' => 'comments', 
+                'form' => ['id' => 'cmt_form', 'type' => 'form', 'name' => 'comment', 'data' => $oForm['form']->getCodeAPI(), 'request' => ['url' => '/api.php?r=system/get_form/TemplCmtsServices/&params=' . json_encode([$sObject, $iId, $iParent]), 'immutable' => true]]];
+            
+            $aRv['browse'] = [
+               'id' => 'cmt_list', 
+               'type' => 'browse', 
+               'insert' => 'before', 
+               'data' => $oCmts->getCommentsBlockAPI([], ['in_designbox' => false, 'show_empty' => false], $oForm['res'] > 0 ? $oForm['res'] : 0)
+            ];
+        }
+        
+        return $aRv;
+    }
+    
+    public function serviceGetList($sObject, $iId, $iStart)
+    {
+        $oCmts = BxDolCmts::getObjectInstance($sObject, $iId);
+        
+        if (!$oCmts || !$oCmts->isEnabled())
+            return false;
+        
+        $aRv['browse'] = [
+            'id' => 'cmt_list', 
+            'type' => 'browse', 
+            'insert' => 'after', 
+            'data' => $oCmts->getCommentsBlockAPI([], ['in_designbox' => false, 'show_empty' => false], 0, $iStart)
+        ];
+        return $aRv;
+    }
 }
 
 /** @} */