Alex Trofimov 12 лет назад
Родитель
Сommit
57ae07638e

+ 54 - 8
inc/classes/BxDolMetatags.php

@@ -184,14 +184,14 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
      * @param $sZip optional ZIP/postcode
      * @return true if location was added, or false otherwise
      */
-    public function locationsAdd($iId, $sLatitude, $sLongitude, $sCountryCode = '', $sState = '', $sCity = '', $sZip = '') 
+    public function locationsAdd($iId, $sLatitude, $sLongitude, $sCountryCode, $sState, $sCity, $sZip = '') 
     {
-        // TODO:        
+        return $this->_oQuery->locationsAdd($iId, $sLatitude, $sLongitude, $sCountryCode, $sState, $sCity, $sZip);
     }
     public function locationsAddFromForm($iId, $sName, $oForm = null) 
     {
         if (!$oForm)
-            $oForm = new BxDolForm(array());
+            $oForm = new BxDolForm(array(), false);
         $this->locationsAdd($iId, $oForm->getCleanValue($sName.'_lat'), $oForm->getCleanValue($sName.'_lng'), $oForm->getCleanValue($sName.'_country'), $oForm->getCleanValue($sName.'_state'), $oForm->getCleanValue($sName.'_city'), $oForm->getCleanValue($sName.'_zip'));
     }
 
@@ -200,9 +200,21 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
      * @param $iId content id
      * @return string with links to country and city
      */
-    public function locationsString($iId) 
+    public function locationsString($iId)
     {
-        // TODO:
+        bx_import('BxDolFormQuery');
+        $aCountries = BxDolFormQuery::getDataItems('Country');
+        $aLocation = $this->locationGet($iId);
+        if (!$aLocation || !$aLocation['country'] || !isset($aCountries[$aLocation['country']]))
+            return '';
+
+        $sCountryUrl = '<a href="' . BX_DOL_URL_ROOT . 'searchKeyword.php?type=location_country&keyword=' . $aLocation['country'] . '">' . $aCountries[$aLocation['country']] . '</a>';
+        if (!$aLocation['city'])
+            return _t('_sys_location_country', $sCountryUrl);
+
+        $sCityUrl = '<a href="' . BX_DOL_URL_ROOT . 'searchKeyword.php?type=location_country_city&keyword=' . $aLocation['country'] . '&state=' . rawurlencode($aLocation['state']) . '&city=' . rawurlencode($aLocation['city']) . '">' . $aLocation['city'] . '</a>';
+            
+        return _t('_sys_location_country_city', $sCountryUrl, $sCityUrl);
     }
 
     /**
@@ -211,7 +223,8 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
      */
     protected function locationsAddMeta($iId) 
     {
-        // TODO:
+        $aLocation = $this->locationGet($iId);
+        BxDolTemplate::getInstance()->addPageMetaLocation($aLocation['lat'], $aLocation['lng'], $aLocation['country']);
     }
 
     /**
@@ -221,10 +234,43 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
      */
     public function locationsSetSearchCondition($oSearchResult, $sCountry, $sState = false, $sCity = false, $sZip = false)
     {
-        // TODO:
-    }
+        $a = array('country' => 'sCountry', 'state' => 'sState', 'city' => 'sCity', 'zip' => 'sZip');
+        foreach ($a as $sIndex => $sVar) {
+            if (!$$sVar)
+                continue;
 
+            $oSearchResult->aCurrent['restriction']['meta_location_' . $sIndex] = array(
+                'value' => $$sVar,
+                'field' => $sIndex,
+                'operator' => '=',
+                'table' => $this->_aObject['table_locations'],
+            );
+        }
 
+        $oSearchResult->aCurrent['join']['meta_keyword'] = array(
+            'type' => 'INNER',
+            'table' => $this->_aObject['table_locations'],
+            'mainField' => $oSearchResult->aCurrent['ident'],
+            'onField' => 'object_id',
+            'joinFields' => array(),
+        );
+    }
+
+    /**
+     * Get location
+     * @return location array
+     */
+    public function locationGet($iId, $sPrefix = '')
+    {
+        $a = $this->_oQuery->locationGet($iId);
+        if (!$sPrefix)
+            return $a;
+
+        $aRet = array();
+        foreach ($a as $sKey => $sVal)
+            $aRet[$sPrefix . '_' . $sKey] = $sVal;
+        return $aRet;
+    }
 
     /**
      * Add @mentions from the string (most probably @mentions will be some sort of links already, so parsing may have to look for smth like <a data-mention="bx_persons|123">mention name</a> instead of @mention, since there is no usernames for profiles modules and name could contain spaces and othr characters)

+ 22 - 0
inc/classes/BxDolMetatagsQuery.php

@@ -60,6 +60,28 @@ class BxDolMetatagsQuery extends BxDolDb
 
 
 
+    public function locationsAdd($mixedContentId, $fLat, $fLng, $sCountryCode, $sState, $sCity, $sZip)
+    {
+        $this->locationsDelete($mixedContentId);
+        if (!$fLat && !$fLng)
+            return true;
+
+        $sQuery = $this->prepare("INSERT INTO `{$this->_aObject['table_locations']}` SET `object_id` = ?, `lat` = ?, `lng` = ?, `country` = ?, `state` = ?, `city` = ?, `zip` = ?", $mixedContentId, $fLat, $fLng, $sCountryCode, $sState, $sCity, $sZip);
+        return $this->query($sQuery);
+    }
+    
+    public function locationsDelete($mixedContentId)
+    {
+        return $this->metaDelete($this->_aObject['table_locations'], $mixedContentId);
+    }
+
+    public function locationGet($mixedContentId)
+    {
+        $sQuery = $this->prepare("SELECT * FROM `{$this->_aObject['table_locations']}` WHERE `object_id` = ?", $mixedContentId);
+        return $this->getRow($sQuery);
+    }
+
+
     protected function metaDelete($sTable, $mixedContentId)
     {
         $sQuery = $this->prepare("DELETE FROM `{$sTable}` WHERE `object_id` = ?", $mixedContentId);

+ 2 - 2
inc/classes/BxDolSearch.php

@@ -597,10 +597,10 @@ class BxDolSearchResult implements iBxDolReplaceable
                 unset($this->aCurrent['restriction']['keyword']);
                 switch ($this->_sMetaType) {
                     case 'location_country':
-                        // TODO:
+                        $o->locationsSetSearchCondition($this, $sKeyword);
                         break;
                     case 'location_country_city':
-                        // TODO:
+                        $o->locationsSetSearchCondition($this, $sKeyword, bx_process_input(bx_get('state')), bx_process_input(bx_get('city')));
                         break;
                     case 'mention':
                         // TODO:

+ 34 - 7
inc/classes/BxDolTemplate.php

@@ -305,6 +305,7 @@ class BxDolTemplate extends BxDol implements iBxDolSingleton
             'header' => '',
             'header_text' => '',
             'keywords' => array(),
+            'location' => array(),
             'description'  => '',
             'robots' => '',
             'css_name' => array(),
@@ -727,6 +728,37 @@ class BxDolTemplate extends BxDol implements iBxDolSingleton
 
         $this->aPage['keywords'] = isset($this->aPage['keywords']) && is_array($this->aPage['keywords']) ? array_merge($this->aPage['keywords'], $mixedKeywords) : $mixedKeywords;
     }
+    /**
+     * Set page locatoin coordinates.
+     *
+     * @param $fLat latitude
+     * @param $fLng longitude
+     */
+    function addPageMetaLocation($fLat, $fLng, $sCountryCode)
+    {
+        $this->aPage['location'] = array('lat' => $fLat, 'lng' => $fLng, 'country' => $sCountryCode);
+    }
+    /**
+     * Returns page meta info, like meta keyword, meta description, location, etc
+     */
+    function getMetaInfo()
+    {
+        $sRet = '';
+
+        if (!empty($this->aPage['keywords']) && is_array($this->aPage['keywords']))
+            $sRet .= '<meta name="keywords" content="' . bx_html_attribute(implode(',', $this->aPage['keywords'])) . '" />';
+
+        if (!empty($this->aPage['description']) && is_string($this->aPage['description']))
+            $sRet .= '<meta name="description" content="' . bx_html_attribute($this->aPage['description']) . '" />';
+
+        if (!empty($this->aPage['location']) && isset($this->aPage['location']['lat']) && isset($this->aPage['location']['lng']) && isset($this->aPage['location']['country']))
+            $sRet .= '
+                <meta name="ICBM" content="' . $this->aPage['location']['lat'] . ';' . $this->aPage['location']['lng'] . '" />
+                <meta name="geo.position" content="' . $this->aPage['location']['lat'] . ';' . $this->aPage['location']['lng'] . '" />
+                <meta name="geo.region" content="' . bx_html_attribute($this->aPage['location']['country']) . '" />';
+
+        return $sRet;
+    }
     /**
      * Get template, which was loaded earlier.
      * @see method this->loadTemplates and field this->_aTemplates
@@ -953,13 +985,8 @@ class BxDolTemplate extends BxDol implements iBxDolSingleton
                 if(!empty($this->aPage['robots']) && is_string($this->aPage['robots']))
                     $sRet = '<meta name="robots" content="' . bx_html_attribute($this->aPage['robots']) . '" />';
                 break;
-            case 'page_keywords':
-                if(!empty($this->aPage['keywords']) && is_array($this->aPage['keywords']))
-                    $sRet = '<meta name="keywords" content="' . bx_html_attribute(implode(',', $this->aPage['keywords'])) . '" />';
-                break;
-            case 'page_description':
-                if(!empty($this->aPage['description']) && is_string($this->aPage['description']))
-                    $sRet = '<meta name="description" content="' . bx_html_attribute($this->aPage['description']) . '" />';
+            case 'meta_info':
+                $sRet = $this->getMetaInfo();
                 break;
             case 'page_header':
                 if(isset($this->aPage['header']))

+ 15 - 7
modules/base/general/classes/BxBaseModGeneralFormEntry.php

@@ -61,24 +61,32 @@ class BxBaseModGeneralFormEntry extends BxTemplFormView
         $aInput['checked'] = $this->getCleanValue($aInput['name'] . '_lat') && $this->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
 
         $aVars = array (
-            'input' => $this->genInputSwitcher($aInput),
             'name' => $aInput['name'],
             'id_status' => $this->getInputId($aInput) . '_status',
             'location_string' => _t('_sys_location_undefined'),
-            'lat' => $this->getCleanValue($aInput['name'] . '_lat'),
-            'lng' => $this->getCleanValue($aInput['name'] . '_lng'),
-            'country' => $this->getCleanValue($aInput['name'] . '_country'),
-            'state' => $this->getCleanValue($aInput['name'] . '_state'),
-            'city' => $this->getCleanValue($aInput['name'] . '_city'),
-            'zip' => $this->getCleanValue($aInput['name'] . '_zip'),
         );
+        $aLocationIndexes = array ('lat', 'lng', 'country', 'state', 'city', 'zip');
+        foreach ($aLocationIndexes as $sKey)
+            $aVars[$sKey] = $this->getLoctionVal($aInput, $sKey);
         if ($aVars['country']) {
             $aCountries = BxDolFormQuery::getDataItems('Country');
             $aVars['location_string'] = ($aVars['city'] ? $aVars['city'] . ', ' : '') . $aCountries[$aVars['country']];
         }
+        if ($this->getLoctionVal($aInput, 'lat') && $this->getLoctionVal($aInput, 'lng'))
+            $aInput['checked'] = true;
+        $aVars['input'] = $this->genInputSwitcher($aInput);
+
         return $this->oTemplate->parseHtmlByName('form_field_location.html', $aVars);
     }
 
+    protected function getLoctionVal ($aInput, $sIndex) 
+    {
+        $s = $aInput['name'] . '_' . $sIndex;
+        if (isset($this->_aSpecificValues[$s]))
+            return $this->_aSpecificValues[$s];
+        return $this->getCleanValue($s);
+    }
+
     function addCssJs ()
     {
         if (!isset($this->aParams['view_mode']) || !$this->aParams['view_mode']) {

+ 10 - 4
modules/base/general/classes/BxBaseModGeneralFormsEntryHelper.php

@@ -81,11 +81,17 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
             return MsgBox($sMsg);
 
         // check and display form
-        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
+        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
         if (!$oForm)
             return MsgBox(_t('_sys_txt_error_occured'));
 
-        $oForm->initChecker($aContentInfo);
+        $aSpecificValues = array();
+        bx_import('BxDolMetatags');
+        if (!empty($CNF['OBJECT_METATAGS'])) {
+            $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
+            $aSpecificValues = $oMetatags->locationGet($iContentId, $CNF['FIELD_LOCATION_PREFIX']);
+        }
+        $oForm->initChecker($aContentInfo, $aSpecificValues);
 
         if (!$oForm->isSubmittedAndValid())
             return $oForm->getCode();
@@ -130,7 +136,7 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
             return MsgBox($sMsg);
 
         // check and display form
-        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
+        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
         if (!$oForm)
             return MsgBox(_t('_sys_txt_error_occured'));
 
@@ -177,7 +183,7 @@ class BxBaseModGeneralFormsEntryHelper extends BxDolProfileForms
             return MsgBox($sMsg);
 
         // get form
-        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay);
+        $oForm = BxDolForm::getObjectInstance($CNF['OBJECT_FORM_ENTRY'], $sDisplay, $this->_oModule->_oTemplate);
         if (!$oForm)
             return MsgBox(_t('_sys_txt_error_occured'));
 

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

@@ -98,11 +98,13 @@ class BxBaseModTextTemplate extends BxBaseModGeneralTemplate
         $aVars = $aData;
         $aVars['entry_title'] = isset($aData[$CNF['FIELD_TITLE']]) ? $aData[$CNF['FIELD_TITLE']] : '';
         $aVars['entry_text'] = $aData[$CNF['FIELD_TEXT']];
+        $aVars['entry_location'] = '';
 
         if (!empty($CNF['OBJECT_METATAGS'])) {
             bx_import('BxDolMetatags');
             $oMetatags = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
             $aVars['text'] = $oMetatags->keywordsParse($aData[$CNF['FIELD_ID']], $aVars['text']);
+            $aVars['entry_location'] = $oMetatags->locationsString($aData[$CNF['FIELD_ID']]);
         }
 
         return $this->parseHtmlByName($sTemplateName, $aVars);

+ 1 - 0
modules/base/text/template/entry-text.html

@@ -1,6 +1,7 @@
 
 <div class="bx-base-text-entity-content bx-def-constraint-list bx-def-constraint-pre bx-def-constraint-object bx-def-constraint-iframe bx-def-constraint-img">
     <h1>__title__</h1>
+    <p class="bx-base-text-entity-location bx-def-font-grayed bx-def-font-small">__entry_location__</p>
     __text__
 </div>
 

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

@@ -1725,6 +1725,8 @@ If it is not enabled then please consider implement this optimization, since it
 	<string name="_sys_layout_top_area_bar_right"><![CDATA[Top area with right bar]]></string>
 	<string name="_sys_layout_topbottom_area_2_columns"><![CDATA[Top&bottom areas with 2 columns in the middle]]></string>
 	<string name="_sys_loading"><![CDATA[Loading...]]></string>
+	<string name="_sys_location_country"><![CDATA[ &mdash; in {0}]]></string>
+	<string name="_sys_location_country_city"><![CDATA[ &mdash; in {1}, {0}]]></string>
 	<string name="_sys_location_determining"><![CDATA[Determining location...]]></string>
 	<string name="_sys_location_geolocation_not_supported_by_browser"><![CDATA[Geolocation is not supported by this browser]]></string>
 	<string name="_sys_location_undefined"><![CDATA[No location]]></string>

+ 12 - 0
modules/boonex/posts/install/sql/install.sql

@@ -108,6 +108,18 @@ CREATE TABLE `bx_posts_meta_keywords` (
   KEY `keyword` (`keyword`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 
+CREATE TABLE `bx_posts_meta_locations` (
+  `object_id` int(10) unsigned NOT NULL,
+  `lat` double NOT NULL,
+  `lng` double NOT NULL,
+  `country` varchar(2) NOT NULL,
+  `state` varchar(255) NOT NULL,
+  `city` varchar(255) NOT NULL,
+  `zip` varchar(255) NOT NULL,
+  PRIMARY KEY (`object_id`),
+  KEY `country_state_city` (`country`,`state`(8),`city`(8))
+) ENGINE=MyISAM DEFAULT CHARSET=utf8;
+
 
 -- STORAGES & TRANSCODERS
 

+ 1 - 1
modules/boonex/posts/install/sql/uninstall.sql

@@ -1,7 +1,7 @@
 
 -- TABLES
 
-DROP TABLE IF EXISTS `bx_posts_posts`, `bx_posts_files`, `bx_posts_photos_resized`, `bx_posts_cmts`, `bx_posts_votes`, `bx_posts_votes_track`, `bx_posts_views_track`, `bx_posts_meta_keywords`;
+DROP TABLE IF EXISTS `bx_posts_posts`, `bx_posts_files`, `bx_posts_photos_resized`, `bx_posts_cmts`, `bx_posts_votes`, `bx_posts_votes_track`, `bx_posts_views_track`, `bx_posts_meta_keywords`, `bx_posts_meta_locations`;
 
 -- STORAGES & TRANSCODERS
 

+ 1 - 2
studio/template/_header.html

@@ -4,8 +4,7 @@
         <meta http-equiv="Content-Type" content="text/html; charset=__page_charset__" />
         <title>__page_header__</title>
 
-		__page_description__
-	    __page_keywords__
+        __meta_info__
 	    __page_robots__
 	    __page_icons__
 

+ 2 - 2
template/_header.html

@@ -5,8 +5,8 @@
     <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />
     <title>__page_header__</title>
     <base href="<bx_url_root />" />
-    __page_description__
-    __page_keywords__
+
+    __meta_info__
     __page_robots__
     __page_icons__