Completed upgrade of search add-on for use with new OSS version and desired features.
authorChuck Scott <cscott@gaslightmedia.com>
Thu, 26 Jul 2018 15:49:21 +0000 (11:49 -0400)
committerChuck Scott <cscott@gaslightmedia.com>
Thu, 26 Jul 2018 15:49:21 +0000 (11:49 -0400)
Added search engine test when submitting General Search Settings page in Management.
Updated glmSearch.php to do indexing and removal of URLS imediately.
Added hooks (filters) for other add-ons to request a page be updated by OSS.
Added management options for selectable searcxh filters and server URL in Management.
Added search filter (from management) selection in search results page.
Added database fields and updated db version.
Started migrating plugin names to GLM Associated.

14 files changed:
classes/data/dataManagement.php
classes/glmSearch.php
index.php
models/front/search/index.php
readme.txt
setup/adminHooks.php
setup/commonHooks.php [new file with mode: 0644]
setup/databaseScripts/create_database_V0.0.3.sql
setup/databaseScripts/dbVersions.php
setup/databaseScripts/update_database_V0.0.5.sql [new file with mode: 0644]
setup/hooksHelp.html
setup/shortcodes.php
views/admin/management/search.html
views/front/search/index.html

index 3d532b5..495f9b8 100644 (file)
@@ -168,8 +168,14 @@ class GlmDataSearchManagement extends GlmDataAbstract
                 'type' => 'integer',
                 'required' => true,
                 'use' => 'a'
-            )
+            ),
 
+            // Url Search Filtes
+            'url_filters' => array (
+                'field' => 'url_filters',
+                'type' => 'text',
+                'use' => 'a'
+            )
 
 
         );
index c42200d..064df3b 100644 (file)
@@ -61,6 +61,20 @@ class GLMSearch
      * @access private\r
      */\r
     private $auth;\r
+    /**\r
+     * Authentication iser\r
+     *\r
+     * @var    $authUser\r
+     * @access private\r
+     */\r
+    private $authUser;\r
+    /**\r
+     * Authentication key\r
+     *\r
+     * @var    $authKey\r
+     * @access private\r
+     */\r
+    private $authKey;\r
     /**\r
      * Error messages array\r
      *\r
@@ -228,6 +242,8 @@ class GLMSearch
             $this->exclude_home_page = $exclude_home_page;\r
 \r
             // Build authentication parameters for submissions\r
+            $this->authUser = $login;\r
+            $this->authKey = $key;\r
             $this->auth = "login=$login&key=$key";\r
 \r
             // Create curl instance - and set to return response\r
@@ -238,6 +254,93 @@ class GLMSearch
 \r
     }\r
 \r
+    /**\r
+     * Build picklist of user selectable URL filters\r
+     *\r
+     * @param string $selectName Filter select input field name for checking if any are selected.\r
+     *\r
+     * @return array An array of selectable options each like the following\r
+     *      'selectedfilter' => array (\r
+     *          'title' => Title of selected filter,\r
+     *          'filter' => URL filter for selected filter\r
+     *      ),\r
+     *      'options' => array(\r
+     *          {title} = array(\r
+     *              'title' => A title for the Option\r
+     *              'filter' => The URL filter text\\r
+     *              'selected' => True if filter is selected, all false by default.\r
+     *          ),\r
+     *          ....\r
+     *      )\r
+     *\r
+     * If there's no filters, this function returns false.\r
+     *\r
+     */\r
+    public function glmSearchUrlFilterOptions( $selectName = false )\r
+    {\r
+\r
+        $urlFilters = array(\r
+            'selected' => false,\r
+            'options' => array()
+        );\r
+\r
+        // Check if there's any filters listed\r
+        $rawFilters =trim($this->config['settings']['url_filters']);\r
+        if ($rawFilters == '') {\r
+            return false;\r
+        }\r
+\r
+        // Break up filters list by line break (one per line)\r
+        $filters = explode("\n", $rawFilters);\r
+\r
+        // If we don't have any filters, return false\r
+        if (!is_array($filters) || count($filters) <= 0) {\r
+            return false;\r
+        }\r
+\r
+        // For each filter supplied in Management\r
+        foreach ($filters as $filter) {\r
+\r
+            // Separate title and URL filter\r
+            $fil = explode(',', trim($filter));\r
+\r
+            // If there was a filter on this line\r
+            if (is_array($fil) && count($fil) == 2) {\r
+\r
+                $title = trim($fil[0]);\r
+                $filter = trim($fil[1]);\r
+\r
+                // Add to selection array\r
+                $urlFilters['options'][$title] = array(\r
+                    'title' => $title,\r
+                    'filter' => $filter,\r
+                    'selected' => false
+                );\r
+\r
+                // If this is the selected filter\r
+                if (isset($_REQUEST[$selectName]) && $_REQUEST[$selectName] == $title) {\r
+\r
+                    // Mark it as the selected filter\r
+                    $urlFilters['options'][$title]['selected'] = true;\r
+\r
+                    // Save this filter info for use is the search\r
+                    $urlFilters['selected'] = array(\r
+                        'title' => $title,\r
+                        'filter' => $filter
+                    );\r
+                }\r
+            }\r
+        }\r
+\r
+        if (count($urlFilters) == 0) {\r
+            return false;\r
+        }\r
+\r
+        return $urlFilters;\r
+\r
+    }\r
+\r
+\r
     /**\r
      * Perform a search on the Web site\r
      *\r
@@ -248,12 +351,13 @@ class GLMSearch
      *                                  Default = 0 (first page)\r
      * @param integer   $rows       Number of rows per result page\r
      *                                  Default = 10\r
+     * @param string    $urlFrilter A URL filter string used to limit search to those URLs.\r
      *\r
      * @return string   JSON of results or false if a failure\r
      *\r
      * @access public\r
      */\r
-    public function glmSearch($query, $operator = 'OR', $start = 0, $rows = 10)\r
+    public function glmSearch($query, $operator = 'OR', $start = 0, $rows = 10, $urlFilter = false)\r
     {\r
 \r
         // Clear all the results data\r
@@ -291,7 +395,7 @@ class GLMSearch
 \r
         // Create request URL\r
         switch ($this->type) {\r
-               case 'field':\r
+            case 'field':http://www.opensearchserver.com/documentation/README.md\r
                 $url = $this->server.'/services/rest/index/'.$this->index.'/search/field/?'.$this->auth;\r
                 break;\r
                case 'pattern':\r
@@ -344,9 +448,16 @@ class GLMSearch
                     "query" => $addHosts\r
                 );\r
 \r
+                // If there's a URL filter, use that\r
+                if ($urlFilter) {\r
+                    $this->request['filters'][] = array(\r
+                        "type" => "QueryFilter",\r
+                        "negative" => false,\r
+                        "query" => 'urlExact: "'.$urlFilter.'"'\r
+                    );\r
 \r
-                // If excluding the home page contents, add a negative filter for that for this site\r
-                if ($this->exclude_home_page) {\r
+                // Otherwise If excluding the home page contents, add a negative filter for that for this site\r
+                } elseif ($this->exclude_home_page) {\r
                        $this->request['filters'][] = array(\r
                         "type" => "QueryFilter",\r
                         "negative" => true,\r
@@ -369,6 +480,8 @@ class GLMSearch
             unset($this->request['filters']);\r
         }\r
 \r
+        // echo "glmSearch <pre>".print_r($this->request,1)."</pre>";\r
+\r
         // Set curl options\r
         curl_setopt_array($this->curl, array(\r
             CURLOPT_URL => $url,\r
@@ -541,6 +654,8 @@ class GLMSearch
     /**\r
      * Tell OpenSearchServer to crawl a particular URL pattern\r
      *\r
+     * OpenSearchServer Privileges Required: "Web crawler: start and stop"\r
+     *\r
      * @param string    $url      URL to crawl\r
      *\r
      * @return array    Object    Results from Search Engine or false if failure.\r
@@ -558,16 +673,20 @@ class GLMSearch
             return false;\r
         }\r
 \r
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {\r
+            trigger_error("glmSearch: OSS Crawl URL = $url",E_USER_NOTICE);\r
+        }\r
+\r
         // Create request URL\r
         $param = 'url='.$url;\r
-        $url = $this->server.'/services/rest/index/'.$this->index.'/crawler/web/crawl?'.$this->auth.'&'.$param;\r
+        $curlUrl = $this->server.'/services/rest/index/'.$this->index.'/crawler/web/crawl?'.$this->auth.'&'.$param;\r
 \r
         // Set curl options\r
         curl_setopt_array($this->curl, array(\r
-            CURLOPT_URL => $url,\r
+            CURLOPT_URL => $curlUrl,\r
             CURLOPT_POST => false,\r
-            CURLOPT_VERBOSE => 1,\r
-            CURLOPT_HEADER => 1\r
+            CURLOPT_VERBOSE => true,\r
+            CURLOPT_HEADER => true\r
         ));\r
 \r
         // Do curl call and get result;\r
@@ -583,15 +702,87 @@ class GLMSearch
         $this->httpHeader = substr($res, 0, $header_size);\r
         $this->rawResults = substr($res, $header_size);\r
 \r
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {\r
+            $res = json_decode($this->rawResults);\r
+            trigger_error("glmSearch: OSS Crawl ".$res->info,E_USER_NOTICE);\r
+        }\r
+\r
         // Check HTTP status code\r
         if ($this->httpStatus != 200) {\r
             return false;\r
         }\r
 \r
-        // Debug information\r
-        $this->errorMessages[] = 'crawlURL() - Completed successfully.';\r
+        return true;\r
+\r
+    }\r
+\r
+    /**\r
+     * Tell OpenSearchServer to delete a document\r
+     *\r
+     * OpenSearchServer Privileges Required: "Index: query the index" and "Index: insert data"\r
+     *\r
+     * @param string    $url      URL of document to delete\r
+     *\r
+     * @return array    Object    Results or false if failure.\r
+     *\r
+     * @access public\r
+     */\r
+    public function removeURL($removeUrl)\r
+    {\r
+\r
+        // Clear all the results data\r
+        $this->clearResults();\r
+\r
+        // Filter and validate supplied parameters\r
+        if (($removeUrl = filter_var($removeUrl, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false) {\r
+            return false;\r
+        }\r
+\r
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {\r
+            trigger_error("glmSearch: OSS Remove URL = $removeUrl",E_USER_NOTICE);\r
+        }\r
+\r
+        // Create request URL\r
+        $curlUrl = $this->server.'/services/rest/index/'.$this->index.'/document/url?'.$this->auth;\r
+\r
+        $removeUrls = array(\r
+            $removeUrl\r
+        );\r
+\r
+        // Set curl options\r
+        curl_setopt_array($this->curl, array(\r
+            CURLOPT_URL => $curlUrl,\r
+            CURLOPT_CUSTOMREQUEST => 'DELETE',\r
+            CURLOPT_POSTFIELDS => json_encode($removeUrls, JSON_UNESCAPED_SLASHES ),\r
+            CURLOPT_HTTPHEADER => array("Content-type: application/json"),\r
+            CURLOPT_VERBOSE => true,\r
+            CURLOPT_HEADER => true\r
+        ));\r
+\r
+        // Do curl call and get result;\r
+        try {\r
+            $res = curl_exec($this->curl);\r
+        } catch (Exception $e) {\r
+            return false;\r
+        }\r
+\r
+        // Parse out results elements\r
+        $this->httpStatus = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);\r
+        $header_size = curl_getinfo($this->curl, CURLINFO_HEADER_SIZE);\r
+        $this->httpHeader = substr($res, 0, $header_size);\r
+        $this->rawResults = substr($res, $header_size);\r
+\r
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {\r
+            trigger_error("glmSearch: OSS Remove URL HTTP Status = $this->httpStatus",E_USER_NOTICE);\r
+        }\r
+\r
+\r
+        // Check HTTP status code\r
+        if ($this->httpStatus != 200) {\r
+            return false;\r
+        }\r
 \r
-        return json_decode($this->rawResults);\r
+        return true;\r
     }\r
 \r
     /**\r
index a0e8afd..7310eda 100644 (file)
--- a/index.php
+++ b/index.php
@@ -1,6 +1,6 @@
 <?php
 /**
- * Plugin Name: GLM Members Database Search
+ * Plugin Name: GLM Associate - OpenSearchServer Add-On
  * Plugin URI: http://www.gaslightmedia.com/
  * Description: Gaslight Media Members Database.
  * Version: 1.2.2
@@ -10,7 +10,7 @@
  */
 
 /**
- * Gaslight Media Members Database Search Add-On
+ * GLM Associate - OpenSearchServer Add-On
  * Index
  *
  * PHP version 5.5
@@ -44,7 +44,7 @@ if (!defined('ABSPATH')) {
  *  version from this plugin.
  */
 define('GLM_MEMBERS_SEARCH_PLUGIN_VERSION', '1.2.2');
-define('GLM_MEMBERS_SEARCH_PLUGIN_DB_VERSION', '0.0.4');
+define('GLM_MEMBERS_SEARCH_PLUGIN_DB_VERSION', '0.0.5');
 
 // This is the minimum version of the GLM Members DB plugin require for this plugin.
 define('GLM_MEMBERS_SEARCH_PLUGIN_MIN_MEMBERS_REQUIRED_VERSION', '2.2.0');
index 4a49dd2..77090eb 100644 (file)
@@ -113,21 +113,42 @@ class GlmMembersFront_search_index extends GLMSearch
         $query = false;
         $start = 0;
         $rows = $this->config['settings']['numb_rows'];
+        $urlFilter = false;
         $searchResult = array(
             'operator' => 'AND'
         );
 
-        /*
-         * Get input from form
-         */
-        if (isset($_REQUEST['query'])) {
+
+        if (isset($_REQUEST['query']) && trim($_REQUEST['query']) != '') {
+            $query = trim($_REQUEST['query']);
+        } else {
+            if ($actionData['request']['query'] != '') {
+                $query = trim($actionData['request']['query']);
+            }
+        }
+
+        if (isset($_REQUEST['matchAll'])) {
+            $matchAll = trim($_REQUEST['matchAll']);
+        } else {
+            if ($actionData['request']['match-all'] != '') {
+                $matchAll = trim($actionData['request']['match-all']);
+            }
+        }
+
+        // Check if a URL filter is supplied by the short
+        if ($actionData['request']['url-filter'] != '') {
+            $matchAll = trim($actionData['request']['match-all']);
+        }
+
+
+        // If we have a search query
+        if ($query && $query != '') {
 
             $haveSearchRequest = true;
 
             // Assemble requested query
-            $query = $_REQUEST['query'];
             $operator = 'OR';
-            if (isset($_REQUEST['matchAll']) && $_REQUEST['matchAll'] == 'on') {
+            if (in_array(strtolower($matchAll), array('on','true','yes','1'))) {
                 $operator = 'AND';
             }
 
@@ -139,9 +160,18 @@ class GlmMembersFront_search_index extends GLMSearch
                 $rows = $_REQUEST['rows'];
             }
 
+            // Check for URL filter selection by user
+            $urlFilters = $this->glmSearchUrlFilterOptions('urlFilter');
+            $filter = false;
+            if ($urlFilters['selected']) {
+                $urlFilter = $urlFilters['selected']['filter'];
+            } elseif ($actionData['request']['url-filter']) {
+                $urlFilter = trim($actionData['request']['url-filter']);
+            }
+
             // Send request to OpenSearchServer and get results
             if (trim($query) != '') {
-                $searchResult = $this->glmSearch($query, $operator, $start, $rows);
+                $searchResult = $this->glmSearch($query, $operator, $start, $rows, $urlFilter);
                 if (!$searchResult) {
                     $searchFailure = true;
                     $failureMessage = $this->rawResults;
@@ -163,7 +193,8 @@ class GlmMembersFront_search_index extends GLMSearch
             'searchFailure'     => $searchFailure,
             'failureMessage'    => $failureMessage,
             'searchResult'      => $searchResult,
-            'query'             => $query
+            'query'             => $query,
+            'urlFilters'        => $urlFilters
         );
 
         $view = 'index.html';
index e51df00..9f0d0b2 100644 (file)
@@ -1,4 +1,4 @@
-=== Gaslight Media Member Database Search Child Plugin ===
+=== GLM Associate - Search Add-On ===
 Contributors: cscott@gaslightmedia.com
 Donate link: http://www.gaslightmedia.com
 Tags: Gaslight Media,Plugin,Members Search
@@ -33,7 +33,33 @@ e.g.
 
 == Changelog ==
 
-= 1.2.3 =
+= (pending) =
+
+* Added "Server URL" management setting
+The OpenSearchServer URL can now be specified in the "Server URL" management setting for this add-on.
+In the past, the server URL was hard-coded making it impossible to migrate to another server or to have
+more than one server.
+
+* Added "Selectable Search Filters management setting
+A textarea was added to the management settings for this add-on to provide a list of URL filters. These
+filters make it possible to have a search return results only including pages that match the URL filter.
+The filters are specified with a name and filter string and can be used in hidden search form fields or
+in a picklist for the user to select searching by one of thesefilter.
+
+* Page and Post changes now immediately affect search results
+Now whenever there is a new Page or Post created, and update to one, or the status is changed, the search engine
+is requested to add, update, or remove a `Page or Post as appropriate. These changes take place immediately
+so a search will return the updated results without having to wait for a re-crawl of the site.
+
+* Updated filters for indexing or removing a URL
+The glm_member_db_common_search_indexurl and glm_member_db_common_search_removeurl filters have been 
+enhanced so that search results are immediately affected.
+
+* Requires Open Search Server v1.5 or later
+This release has been tested with OpenSearchServer v1.5.14 and may not function properly with earlier versions.  
+
+
+= 1.2.2 =
 
 * Fixed problem with automatic deactivation due to change in index file name from a while ago.
 
index 9f42b9f..b367a7c 100644 (file)
@@ -49,19 +49,106 @@ add_filter( 'glm-member-db-dashboard-widget-warnings', function( $content ) {
     return $content;
 });
 
-// Ask the search engine to crawl the post or page whenever it's updated
-function glm_member_db_admin_search_crawlUrl( $post_id ) {
+//
 
-    $post_title = get_the_title($post_id);
-    $post_url = get_permalink($post_id);
-    $post_status = get_post_status($post_id);                           // Status string
-    $post_password_protected = post_password_required($post_id);        // True if password protectedd
+/* Ask the search engine to crawl the post or page whenever it's updated depending on status
+ *
+ * Hook provides the post/page status array both before update and after. This is compared
+ * to determine if a post/page needs to be crawled or removed.
+ *
+ * The pre and post update URLs are built using the current base url and the pre and post
+ * update slug (post_name).
+ *
+ * The post/page is crawled any time there's an update that results in $post_after with
+ * [post_status] = "publish" and no value in [post_password].
+ *
+ * The post/page is removed any time $post_before with [post_status] = "publish" and no
+ * value in [post_password] while $post_after does not meet those requirements.
+ *
+ * Sample post status array
+ *
+ *     [ID] => 1069
+ *     [post_author] => 2
+ *     [post_date] => 2018-06-26 11:11:32
+ *     [post_date_gmt] => 2018-06-26 15:11:32
+ *     [post_content] => We be here.
+ *     [post_title] => We be here
+ *     [post_excerpt] =>
+ *     [post_status] => publish
+ *     [comment_status] => closed
+ *     [ping_status] => closed
+ *     [post_password] =>
+ *     [post_name] => we-be-here
+ *     [to_ping] =>
+ *     [pinged] =>
+ *     [post_modified] => 2018-06-26 11:12:39
+ *     [post_modified_gmt] => 2018-06-26 15:12:39
+ *     [post_content_filtered] =>
+ *     [post_parent] => 0
+ *     [guid] => http://192.168.44.80/?page_id=1069
+ *     [menu_order] => 0
+ *     [post_type] => page
+ *     [post_mime_type] =>
+ *     [comment_count] => 0
+ *     [filter] => raw
+ *
+ *     if either [post_status] is not "publis" or [post_password] is not blank then
+ *     the post/page should not be indexed.
+ */
+function glm_member_db_admin_post_updated( $post_id, $post_after, $post_before )
+{
+
+    global $config;
+
+
+    // Load and instatiate the glmSearch class
+    require_once GLM_MEMBERS_SEARCH_PLUGIN_CLASS_PATH.'/glmSearch.php';
+    $server = $config['settings']['server'];
+    $index = $config['settings']['search_index'];
+    $website = $config['settings']['website'];
+    $login = $config['settings']['login'];
+    $key = $config['settings']['login_key'];
+    $exclude_home_page = $config['settings']['exclude_home_page'];
+    $GlmSearch = new GLMSearch($server, $index, $website, $login, $key, $exclude_home_page);
+
+    // Get pre and post update URLs. These are not always available in status array
+    $preUpdateUrl = get_home_url(null, $post_before->post_name).'/';
+    $postUpdateUrl = get_home_url(null, $post_after->post_name).'/';
+
+    if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+        trigger_error("Hook glm_member_db_admin_post_updated called for post ID $post_id (".$post_after->post_name.")",E_USER_NOTICE);
+    }
 
-    /*
-     * get_post_type
-     */
+    // Check if we need to crawl this page/post - Published with no password
+    if ($post_after->post_status == 'publish' && trim($post_after->post_password) == '') {
 
-//    $content .= $this->controller('search', 'ossRequest', array('request' => 'crawl', 'url' => $post_url));
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+            trigger_error("glmSearch OSS Crawl Requested: $postUpdateUrl",E_USER_NOTICE);
+        }
+
+        // Crawl using $postUpdateUrl
+        $GlmSearch->crawlURL($postUpdateUrl);
+
+    }
+
+    // Check if we need to remove this post/page - Was published and now not or has password
+    if (
+        ($post_before->post_status == 'publish' && trim($post_before->post_password) == '') &&
+        ($post_after->post_status != 'publish' || trim($post_after->post_password) != '') ) {
+
+        if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+            trigger_error("OSS Remove Requested: $preUpdateUrl",E_USER_NOTICE);
+        }
+
+        // Remove using $preUpdateUrl
+        $GlmSearch->removeURL($preUpdateUrl);
+
+    }
 
 }
-add_action( 'save_post', 'glm_member_db_admin_search_crawlUrl' );
\ No newline at end of file
+add_action( 'post_updated', 'glm_member_db_admin_post_updated', 10, 3 );
+
+
+
+
+
diff --git a/setup/commonHooks.php b/setup/commonHooks.php
new file mode 100644 (file)
index 0000000..11f24a7
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members Misc Common Hooks and Filters
+ * Called by both Admin and Front controllers
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package  glmMembersDatabase
+ * @author   Chuck Scott <cscott@gaslightmedia.com>
+ * @license  http://www.gaslightmedia.com Gaslightmedia
+ * @release  commonHooks.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link     http://dev.gaslightmedia.com/
+ */
+
+/*
+ * Place Misc Hooks and Filters that should be available to both admin and front processes here.
+ * If this file exists, it will be included by the main plugin script.
+ *
+ * Note that filter and hook callback functions must be included in-line as shown below...
+ *
+ *  add_filter( 'filter_title', function( $parameter ) {
+ *     // Function code
+ *  });
+ *
+ *  Also note that parameters will be in the context of either the Front or Admin controller,
+ *  depending on where the hook is called from.
+ */
+
+
+/* Filters to ask for a page to be indexed and removed
+ *
+ * Only parameter passed is the URL to be indexed or removed
+ *
+ * Value passed back is trye of succsessful or false if not.
+ *
+ */
+add_filter('glm_member_db_common_search_indexurl', function($url) {
+
+    global $config;
+
+    // Load and instatiate the glmSearch class
+    require_once GLM_MEMBERS_SEARCH_PLUGIN_CLASS_PATH.'/glmSearch.php';
+    $server = $config['settings']['server'];
+    $index = $config['settings']['search_index'];
+    $website = $config['settings']['website'];
+    $login = $config['settings']['login'];
+    $key = $config['settings']['login_key'];
+    $exclude_home_page = $config['settings']['exclude_home_page'];
+    $GlmSearch = new GLMSearch($server, $index, $website, $login, $key, $exclude_home_page);
+
+    if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+        trigger_error("Hook glm_member_db_common_search_indexurl called for URL ".$url,E_USER_NOTICE);
+    }
+
+    // Add URL to index
+    $res = $GlmSearch->crawlURL($url);
+
+    return $res;
+
+}, 10, 2);
+
+add_filter('glm_member_db_common_search_removeurl', function($url) {
+
+    global $config;
+
+    // Load and instatiate the glmSearch class
+    require_once GLM_MEMBERS_SEARCH_PLUGIN_CLASS_PATH.'/glmSearch.php';
+    $server = $config['settings']['server'];
+    $index = $config['settings']['search_index'];
+    $website = $config['settings']['website'];
+    $login = $config['settings']['login'];
+    $key = $config['settings']['login_key'];
+    $exclude_home_page = $config['settings']['exclude_home_page'];
+    $GlmSearch = new GLMSearch($server, $index, $website, $login, $key, $exclude_home_page);
+
+    if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
+        trigger_error("Hook glm_member_db_common_search_removeurl called for URL ".$url,E_USER_NOTICE);
+    }
+
+    // Add URL to index
+    $res = $GlmSearch->removeURL($url);
+
+    return $res;
+
+}, 10, 2);
+
index 62e3eea..10637da 100644 (file)
@@ -16,6 +16,7 @@ CREATE TABLE {prefix}management (
   numb_rows SMALLINT NULL,              -- Number of rows to show per page in results
   login TINYTEXT NULL,                  -- OSS API Login 
   login_key TINYTEXT NULL,              -- OSS API Login Key
+  url_filters text NULL,                -- URL filters that may be selected by user (one per line as "Title, {urlfilter}" 
   PRIMARY KEY (id)
 );
 
index 62f2e23..1b4be0a 100644 (file)
@@ -17,6 +17,7 @@ $glmMembersSearchDbVersions = array(
     '0.0.1' => array('version' => '0.0.1', 'tables' => 1, 'date' => '06/20/16'),
     '0.0.2' => array('version' => '0.0.2', 'tables' => 1, 'date' => '07/05/16'),
     '0.0.3' => array('version' => '0.0.3', 'tables' => 1, 'date' => '07/07/16'),
-    '0.0.4' => array('version' => '0.0.4', 'tables' => 1, 'date' => '06/05/18')
+    '0.0.4' => array('version' => '0.0.4', 'tables' => 1, 'date' => '06/05/18'),
+    '0.0.5' => array('version' => '0.0.5', 'tables' => 1, 'date' => '07/24/18')
 );
 
diff --git a/setup/databaseScripts/update_database_V0.0.5.sql b/setup/databaseScripts/update_database_V0.0.5.sql
new file mode 100644 (file)
index 0000000..eb3d147
--- /dev/null
@@ -0,0 +1,13 @@
+-- Gaslight Media Members Database 
+-- File Created: 7/24/18 11:34:00  
+-- Database Version: 0.0.5
+-- Database Update From Previous Version Script
+-- 
+-- To permit each query below to be executed separately,
+-- all queries must be separated by a line with four dashses
+
+ALTER TABLE {prefix}management ADD COLUMN url_filters text;
+
+----
+
+UPDATE {prefix}management SET url_filters = '';
index 7f18905..63be316 100644 (file)
@@ -1,3 +1,29 @@
 <!-- Hooks Help from glm-member-db-search Add-On -->
 
         <tr><th colspan="3" class="glm-notice"><p>Search Add-On</p></th></tr>
+
+        <tr><th colspan="3"><h2>Common (front/adminh) Hooks</h2></td></tr>
+
+        <tr>
+            <td>glm_member_db_common_search_indexurl</td>
+            <td>Filter</td>
+            <td>$url</td>
+            <td>
+                This filter requests that the search engine add to or update the supplied URL in the active index. 
+                If successful, the URL is immediately added
+                to the active index and will show up in relevant searches and this filter returns TRUE. If the
+                URL is not supplied or can't bee indexed, this filter will return FALSE.
+            </td>
+        </tr>
+        <tr>
+            <td>glm_member_db_common_search_removeurl</td>
+            <td>Filter</td>
+            <td>$url</td>
+            <td>
+                This filter requests that the search engine remove a url from the active index If successful the URL 
+                wiull be immediatly removed from the active index, will no longer show up in relevant searches and this filter will return TRUE.
+                If the URL is not supplied or the search engine is not able to remove it from the active index, this filter will return FALSE. 
+            </td>
+        </tr>
+
+        
\ No newline at end of file
index 9721b28..856d7f5 100644 (file)
@@ -99,7 +99,9 @@ $glmMembersSearchShortcodes = array(
         'action' => 'index',
         'table' => false,
         'attributes' => array(
-            'search' => false                           // Text to search for or false
+            'query' => false,                    // Text to search for or false
+            'match-all' => false,                // Flag to match all (yes, true, 1)
+            'url-filter' => false                // An otional URL filter
         )
     ),
     'glm-members-search-sitemap' => array(
index 6b922bb..5f37563 100644 (file)
                 </td>
             </tr>
             <tr>
-                <th>Exclude Home Page Content<br>From Search Results:</th>
+                <th>Exclude Home Page Content:</th>
                 <td>
                     <input type="checkbox" name="exclude_home_page"{if $searchSettings.fieldData.exclude_home_page.value} checked="checked"{/if}>
                 </td>
             </tr>
             <tr>
-                <th>Default number of rows per result page:</th>
+                <th>Results per page:</th>
                 <td>
                     <input type="text" name="numb_rows" value="{$searchSettings.fieldData.numb_rows}" class="glm-form-text-input-veryshort">
                 </td>
             </tr>
+            <tr>
+                <th>Selectable Search Filters</th>
+                <td>
+                    <textarea style="width: 90%;" cols="90" name="url_filters">{$searchSettings.fieldData.url_filters}</textarea>
+                    <p>
+                        Search filters permit users to select a particular area of the Web site they want to search. This can be
+                        user to restrict results to members, events or other infomration based on a particular part of the URL.
+                        For example, an option to restrict results to member data only would look like the following.
+                        <pre>Members, http://www.gaslightmedia.com/member-detail/*</pre>
+                        The user will see "Members" in a picklist along with the search text input field. If selected, only results
+                        with a URL that includes the specified URL segment will be listed.
+                        Note that these URL segments don't have to start with "http://". They can instead have a wild-card chaaraceter (*)
+                        at the beginning and only have as much of the URL as is necessary to match the desired pages.
+                        There can be an unlimtied number of lines in this text area. Each line is a separate selectable option. 
+                        There will also be a blank option in that picklist to search all areas of the Web site.
+                    </p>
+                    <p>
+                        Also note that since multiple hostnames can be specified in the "Website" field to permit searches on more than one 
+                        Web site, these search filters can be used to select a specific site to search out of those multiple sites.
+                    </p>
+                </td>
+            </tr>
         </table>
         <input type="submit" value="Update Settings" class="button-primary">
     </form>
index b8774a3..8ae0208 100644 (file)
@@ -3,6 +3,15 @@
     <form action="{$thisUrl}?glm_action=index" method="post" enctype="multipart/form-data">
         Search for: <input type="hidden" name="GLMSearch" value="true">
         <input type="text" name="query" value="{$query}">
+    {if $urlFilters}
+        Search only ...
+        <select name="urlFilter">
+            <option value=""></option>
+      {foreach $urlFilters.options as $filter}
+            <option value="{$filter.title}" {if $filter.selected}selected{/if}>{$filter.title}</option>
+      {/foreach}
+        </select>
+    {/if}
         <input type="checkbox" name="matchAll" {if $searchResult.operator == 'AND'}checked{/if} value="on"> Match all words
         <input type="submit" id="submit" value="Search">
     </form>