Textpattern PHP Cross Reference Content Management Systems

Source: /textpattern/publish/search.php - 55 lines - 1610 bytes - Summary - Text - Print

Description: Tools for searching site contents.

   1  <?php
   2  
   3  /*
   4   * Textpattern Content Management System
   5   * https://textpattern.com/
   6   *
   7   * Copyright (C) 2020 The Textpattern Development Team
   8   *
   9   * This file is part of Textpattern.
  10   *
  11   * Textpattern is free software; you can redistribute it and/or
  12   * modify it under the terms of the GNU General Public License
  13   * as published by the Free Software Foundation, version 2.
  14   *
  15   * Textpattern is distributed in the hope that it will be useful,
  16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18   * GNU General Public License for more details.
  19   *
  20   * You should have received a copy of the GNU General Public License
  21   * along with Textpattern. If not, see <https://www.gnu.org/licenses/>.
  22   */
  23  
  24  /**
  25   * Tools for searching site contents.
  26   *
  27   * @package Search
  28   */
  29  
  30  /**
  31   * Limits search to searchable sections.
  32   *
  33   * This function gets a list of searchable sections as an SQL where clause.
  34   * The returned results can be then be used in or as an SQL query.
  35   *
  36   * @return string|bool SQL statement, or FALSE when all sections are included the search
  37   * @example
  38   * if ($r = safe_count('textpattern', "Title LIKE '%a%' " . filterSearch()))
  39   * {
  40   *     echo 'Found {$r} articles with "a" in the title.';
  41   * }
  42   */
  43  
  44  function filterSearch()
  45  {
  46      static $filterSearch = null;
  47      global $txp_sections;
  48  
  49      if (!isset($filterSearch)) {
  50          $rs = array_filter(array_column($txp_sections, 'searchable', 'name'));
  51          $filterSearch = $rs ? 'AND Section IN('.join(',', quote_list(array_keys($rs))).')' : false;
  52      }
  53  
  54      return $filterSearch;
  55  }

title

Description

title

Description

title

Description

title

title

Body