Explorar o código

#87 - search by keyword

Alex Trofimov %!s(int64=12) %!d(string=hai) anos
pai
achega
e7a417920a

+ 46 - 3
inc/classes/BxDolMetatags.php

@@ -125,7 +125,7 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
             return $s;
     
         foreach ($a as $sKeyword)
-            $s = str_ireplace('#' . $sKeyword, '<a href="#"><s>#</s><b>' . $sKeyword . '</b></a>', $s);
+            $s = str_ireplace('#' . $sKeyword, '<a rel="tag" href="' . BX_DOL_URL_ROOT . 'searchKeyword.php?type=keyword&keyword=' . rawurlencode($sKeyword) . '"><s>#</s><b>' . $sKeyword . '</b></a>', $s);
 
         return $s;
     }
@@ -134,9 +134,9 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
      * Add keywords meta info to the head section
      * @param $iId content id
      */
-    protected function keywordsAddMeta($iId) 
+    protected function keywordsAddMeta($iId)
     {
-        // TODO:
+        BxDolTemplate::getInstance()->addPageKeywords($this->keywordsGet($iId));
     }
 
     /**
@@ -148,6 +148,29 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
         return $this->_oQuery->keywordsGet($iId);
     }
 
+    /**
+     * Set condition for search results object for meta keyword
+     * @param $oSearchResult search results object
+     * @param $sKeyword keyword
+     */
+    public function keywordsSetSearchCondition($oSearchResult, $sKeyword)
+    {
+        $oSearchResult->aCurrent['restriction']['meta_keyword'] = array(
+            'value' => $sKeyword,
+            'field' => 'keyword',
+            'operator' => '=',
+            'table' => $this->_aObject['table_keywords'],
+        );
+
+        $oSearchResult->aCurrent['join']['meta_keyword'] = array(
+            'type' => 'INNER',
+            'table' => $this->_aObject['table_keywords'],
+            'mainField' => $oSearchResult->aCurrent['ident'],
+            'onField' => 'object_id',
+            'joinFields' => array(),
+        );
+    }
+
 
 
     /**
@@ -185,6 +208,16 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
         // TODO:
     }
 
+    /**
+     * Set condition for search results object for meta locations
+     * @param $oSearchResult search results object
+     * @param $sCountry country and other location info
+     */
+    public function locationsSetSearchCondition($oSearchResult, $sCountry, $sState = false, $sCity = false, $sZip = false)
+    {
+        // TODO:
+    }
+
 
 
     /**
@@ -217,6 +250,16 @@ class BxDolMetatags extends BxDol implements iBxDolFactoryObject
         return 0;
     }
 
+    /**
+     * Set condition for search results object for mentions
+     * @param $oSearchResult search results object
+     * @param $sMention smbd
+     */
+    public function mentionsSetSearchCondition($oSearchResult, $sMention)
+    {
+        // TODO:
+    }
+
 
 
     /**

+ 46 - 7
inc/classes/BxDolSearch.php

@@ -47,6 +47,7 @@ class BxDolSearch extends BxDol
     protected $aChoice  = array(); ///< array of current search classes which were choosen in search area
 
     protected $_bLiveSearch = false;
+    protected $_sMetaType = '';
 
     /**
      * Constructor
@@ -90,6 +91,7 @@ class BxDolSearch extends BxDol
             $oEx = new $aValue['class']();
             $oEx->setId($aValue['id']);
             $oEx->setLiveSearch($this->_bLiveSearch);
+            $oEx->setMetaType($this->_sMetaType);
             $sCode .= $oEx->processing();
         }
         return $sCode;
@@ -113,6 +115,14 @@ class BxDolSearch extends BxDol
     {
         $this->_bLiveSearch = $bLiveSearch;
     }
+
+    public function setMetaType($s)
+    {
+        $aMetaTypes = array('location_country', 'location_country_city', 'mention', 'keyword');
+        if (in_array($s, $aMetaTypes))
+            $this->_sMetaType = $s;
+    }
+
 }
 
 /*
@@ -234,6 +244,7 @@ class BxDolSearchResult implements iBxDolReplaceable
     protected $bForceAjaxPaginate = false; ///< force ajax paginate
 
     protected $_bLiveSearch = false;
+    protected $_sMetaType = '';
 
     protected $_aMarkers = array (); ///< markers to replace somewhere, usually title and browse url (defined in custom class)
 
@@ -267,6 +278,11 @@ class BxDolSearchResult implements iBxDolReplaceable
         $this->_bLiveSearch = $bLiveSearch;
     }
 
+    public function setMetaType($s)
+    {
+        $this->_sMetaType = $s;
+    }
+
     /**
      * Display empty message if there is no content, custom empty message can be used.
      * @param $b - boolan value to enable or disable 'empty' message
@@ -384,9 +400,9 @@ class BxDolSearchResult implements iBxDolReplaceable
      */
     function setFieldUnit ($sFieldName, $sTableName, $sOperator = '', $bRenameMode = true)
     {
-        if (strlen($sOperator) > 0) {
+        if (!empty($sOperator))
             $sqlUnit  = "$sOperator(`$sTableName`.`$sFieldName`)";
-        } else
+        else
             $sqlUnit  = "`$sTableName`.`$sFieldName`";
 
         if (isset($this->aPseud) && $bRenameMode !== false) {
@@ -496,8 +512,9 @@ class BxDolSearchResult implements iBxDolReplaceable
             $aSql['joinFields'] .= $aJoins['joinFields'];
             $aSql['join'] = $aJoins['join'];
             $aSql['groupBy'] = $aJoins['groupBy'];
-        } else
-            $aSql['ownFields'] = trim($aSql['ownFields'], ', ');
+        } 
+
+        $aSql['ownFields'] = trim($aSql['ownFields'], ', ');
 
         // from
         $aSql['from'] = " FROM `{$this->aCurrent['table']}`";
@@ -548,9 +565,7 @@ class BxDolSearchResult implements iBxDolReplaceable
      */
     function setConditionParams()
     {
-        $aWhere = array();
-        $aWhere[] = '1';
-
+        // keyword
         $sKeyword = bx_process_input(bx_get('keyword'));
         if ($sKeyword !== false)
             $this->aCurrent['restriction']['keyword'] = array(
@@ -559,6 +574,7 @@ class BxDolSearchResult implements iBxDolReplaceable
                 'operator' => 'against'
             );
 
+        // owner
         if (isset($_GET['ownerName'])) {
             $sName = bx_process_input($_GET['ownerName']);
             $iUser = (int)BxDolProfileQuery::getInstance()->getIdByNickname($sName);
@@ -568,6 +584,29 @@ class BxDolSearchResult implements iBxDolReplaceable
 
         if (!empty($iUser))
             $this->aCurrent['restriction']['owner']['value'] = $iUser;
+        
+        // meta info
+        if ($this->_sMetaType && !empty($this->aCurrent['object_metatags'])) {
+            bx_import('BxDolMetatags');
+            $o = BxDolMetatags::getObjectInstance($this->aCurrent['object_metatags']);            
+            if ($o) {
+                unset($this->aCurrent['restriction']['keyword']);
+                switch ($this->_sMetaType) {
+                    case 'location_country':
+                        // TODO:
+                        break;
+                    case 'location_country_city':
+                        // TODO:
+                        break;
+                    case 'mention':
+                        // TODO:
+                        break;
+                    case 'keyword':
+                        $o->keywordsSetSearchCondition($this, $sKeyword);
+                        break;
+                }
+            }
+        }
 
         $this->setPaginate();
         $iNum = $this->getNum();

+ 8 - 0
modules/base/general/classes/BxBaseModGeneralPageEntry.php

@@ -40,11 +40,19 @@ class BxBaseModGeneralPageEntry extends BxTemplPage
         }
         $this->_oModule->checkAllowedView($this->_aContentInfo, true);
 
+        $CNF = &$this->_oModule->_oConfig->CNF;
         if (!empty($CNF['OBJECT_VIEWS'])) {
             bx_import('BxDolView');
             BxDolView::getObjectInstance($CNF['OBJECT_VIEWS'], $this->_aContentInfo[$CNF['FIELD_ID']])->doView();
         }
 
+        if (!empty($CNF['OBJECT_METATAGS'])) {
+            bx_import('BxDolMetatags');
+            $o = BxDolMetatags::getObjectInstance($CNF['OBJECT_METATAGS']);
+            if ($o)
+                $o->metaAdd($this->_aContentInfo[$CNF['FIELD_ID']]);
+        }
+
         return parent::getCode ();
     }
 

+ 1 - 0
modules/boonex/posts/classes/BxPostsSearchResult.php

@@ -19,6 +19,7 @@ class BxPostsSearchResult extends BxBaseModTextSearchResult
 
         $this->aCurrent = array(
             'name' => 'bx_posts',
+            'object_metatags' => 'bx_posts',
             'title' => _t('_bx_posts_page_title_browse'),
             'table' => 'bx_posts_posts',
             'ownFields' => array('id', 'title', 'text', 'thumb', 'author', 'added'),

+ 5 - 7
searchKeyword.php

@@ -11,19 +11,17 @@ require_once(BX_DIRECTORY_PATH_INC . "design.inc.php");
 bx_import('BxTemplSearch');
 bx_import('BxDolTemplate');
 
-$o = new BxDolSearch();
-$o->setLiveSearch(bx_get('live_search') ? 1 : 0);
+$oSearch = new BxTemplSearch();
+$oSearch->setLiveSearch(bx_get('live_search') ? 1 : 0);
+$oSearch->setMetaType(bx_process_input(bx_get('type')));
 
 $sCode = '';
 if (bx_get('keyword')) {
-    $sCode = $o->response();
+    $sCode = $oSearch->response();
     if (!$sCode)
-        $sCode = $o->getEmptyResult();
+        $sCode = $oSearch->getEmptyResult();
 }
 
-$oSearch = new BxTemplSearch();
-$oSearch->setLiveSearch(false);
-
 $oTemplate = BxDolTemplate::getInstance();
 $oTemplate->setPageNameIndex (BX_PAGE_DEFAULT);
 $oTemplate->setPageHeader (_t("_Search"));

+ 3 - 0
template/scripts/BxBaseSearch.php

@@ -27,6 +27,9 @@ class BxBaseSearch extends BxDolSearch
 
     public function getForm($iDesignBoxTemplate = BX_DB_PADDING_DEF, $sTitle = false)
     {
+        if ($this->_sMetaType)
+            return '';
+
         if (false === $sTitle)
             $sTitle = _t( "_Search");