Added database field, management model and view, and other stuff to manage Server URL
Started adding code to index posts and pages when updated or removed, not doing that right now.
Additional prep
'use' => 'a'
),
+ // OSS Server
+ 'server' => array (
+ 'field' => 'server',
+ 'type' => 'text',
+ 'required' => true,
+ 'use' => 'a'
+ ),
+
// OSS Search Index
'search_index' => array (
'field' => 'search_index',
* GLM Search Engine - Support Classes\r
*\r
* PHP version 5\r
+ * Uses OSS API v2 (RESTFul JSON)\r
*\r
* @category Support_Services\r
* @package GLMSearch\r
* @link\r
*/\r
\r
-/**** NOTE : THIS FILE HAS NOT HAD A THOUROUGH REVIEW SINCE BEING GRABBED FROM THE OLD GLM COMMON APPS *****/\r
-\r
-/*\r
- * Set OpenSearchServer base URL and port\r
- */\r
-define('OpenSearchServer', 'http://oss.gaslightmedia.com:9090');\r
-\r
/**\r
* GLM Search - Web Site Search Support Class\r
*\r
class GLMSearch\r
{\r
\r
+ /**\r
+ * URL for the OpenSearchServer that should be used. This\r
+ * information is stored in Management.\r
+ *\r
+ * @var $server\r
+ * @access private\r
+ */\r
+ private $server;\r
/**\r
* Name of the index an instance of this class will search.\r
* An index can have multiple Websites in it. If when calling\r
*/\r
private $auth;\r
/**\r
- * General error message describing any failure\r
+ * Error messages array\r
*\r
* @var $curlError\r
* @access public\r
*/\r
- public $errorMessage;\r
+ public $errorMessages;\r
/**\r
* Exception object caused by curl or other failure\r
*\r
/**\r
* Constructor\r
*\r
- * @param text $index Optional index name if Web site is part of a larger index\r
- * @param string $website Name of the Web site\r
- * @param string $login Login to OpenSearchServer\r
- * @param string $key Key for login\r
- * @param text $filterType Optional filter type (when $this->filter is true).\r
+ * @param string $server URL of server (i.e. http://oss2.gaslightmedia.com:9090)\r
+ * @param string $index Optional index name if Web site is part of a larger index\r
+ * @param string $website Name of the Web site\r
+ * @param string $login Login to OpenSearchServer\r
+ * @param string $key Key for login\r
+ * @param string $filterType Optional filter type (when $this->filter is true).\r
* Filter types are "title", "titleExact", "titlePhonetic", "content",\r
* "contentExact", "contactPhonetic", "urlSplit", "urlExact", "urlPhonetic",\r
* "full", "fullExact", "fullPhonetic"\r
- * @param text $filterValue Filter value to use with $filterType.\r
+ * @param string $filterValue Filter value to use with $filterType.\r
*\r
* @return void\r
* @access public\r
*/\r
- public function __construct($index, $website, $login, $key, $exclude_home_page, $filterType = false, $filterValue = false)\r
+ public function __construct($server, $index, $website, $login, $key, $exclude_home_page = false, $filterType = false, $filterValue = false)\r
{\r
\r
- // If there's a problem with Filter and validate supplied parameters\r
- if (\r
- (trim($website) != '' && ($website = filter_var($website, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false) ||\r
- ($login = filter_var($login, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false ||\r
- ($key = filter_var($key, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false\r
- ) {\r
- return false;\r
+ // If there's a problem with any of the required parameters\r
+ $messages = array();\r
+ $server = trim($server);\r
+ if ($server == '' || ($server = filter_var($server, FILTER_SANITIZE_URL, FILTER_FLAG_STRIP_HIGH)) == false) {\r
+ $this->errorMessages[] = "Server URL setting was not supplied or was invalid.";\r
}\r
+ $index = trim($index);\r
+ if ($index == '' || ($index = filter_var($index, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false) {\r
+ $this->errorMessages[] = "Search Index setting was not supplied or was invalid.";\r
+ }\r
+ $website = trim($website);\r
+ if (($website = filter_var($website, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false) {\r
+ $this->errorMessages[] = "Website setting was invalid.";\r
+ }\r
+ $login = trim($login);\r
+ if ($login == '' || ($login = filter_var($login, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false) {\r
+ $this->errorMessages[] = "Search Server Login setting was not supplied or invalid.";\r
+ }\r
+ $key = trim($key);\r
+ if ($key == '' || ($key = filter_var($key, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false) {\r
+ $this->errorMessages[] = "Search Key Login setting was not supplied or invalid.";\r
+ }\r
+ if (count($this->errorMessages) > 0) {\r
+ $this->error = true;\r
+ } else {\r
+\r
+ // Store supplied parameters\r
+ $this->server = $server;\r
+ $this->index = $index;\r
+ $this->website = $website;\r
+ $this->exclude_home_page = $exclude_home_page;\r
\r
- // Store supplied parameters\r
- $this->index = $index;\r
- $this->website = $website;\r
- $this->exclude_home_page = $exclude_home_page;\r
+ // Build authentication parameters for submissions\r
+ $this->auth = "login=$login&key=$key";\r
\r
- // Build authentication parameters for submissions\r
- $this->auth = "login=$login&key=$key";\r
+ // Create curl instance - and set to return response\r
+ $this->curl = curl_init();\r
+ $x = curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE);\r
\r
- // Create curl instance - and set to return response\r
- $this->curl = curl_init();\r
- curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, TRUE);\r
+ }\r
\r
}\r
\r
// Create request URL\r
switch ($this->type) {\r
case 'field':\r
- $url = OpenSearchServer.'/services/rest/index/'.$this->index.'/search/field/?'.$this->auth;\r
+ $url = $this->server.'/services/rest/index/'.$this->index.'/search/field/?'.$this->auth;\r
break;\r
case 'pattern':\r
- $url = OpenSearchServer.'/services/rest/index/'.$this->index.'/search/pattern/?'.$this->auth;\r
+ $url = $this->server.'/services/rest/index/'.$this->index.'/search/pattern/?'.$this->auth;\r
break;\r
}\r
\r
/**\r
* Tell OpenSearchServer to crawl a particular URL pattern\r
*\r
- * @param integer $pattern URL Pattern\r
+ * @param string $url URL to crawl\r
*\r
* @return array Object Results from Search Engine or false if failure.\r
*\r
* @access public\r
*/\r
- public function crawlURL($pattern)\r
+ public function crawlURL($url)\r
{\r
\r
// Clear all the results data\r
$this->clearResults();\r
\r
// Filter and validate supplied parameters\r
- if (($pattern = filter_var($pattern, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false) {\r
+ if (($url = filter_var($url, FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH)) == false) {\r
return false;\r
}\r
\r
// Create request URL\r
- $param = 'url='.$pattern;\r
- $url = OpenSearchServer.'/services/rest/index/'.$this->index.'/crawler/web/crawl?'.$this->auth.'&'.$param;\r
+ $param = 'url='.$url;\r
+ $url = $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
}\r
\r
// Debug information\r
- $this->errorMessage = 'crawlURL() - Completed successfully.';\r
+ $this->errorMessages[] = 'crawlURL() - Completed successfully.';\r
\r
return json_decode($this->rawResults);\r
}\r
'lang' => 'ENGLISH', // Language (in all caps)\r
'operator' => 'AND', // Either AND or OR - And matches pages containing all words\r
'collapsing' => array(\r
+ 'field' => 'url',\r
'max' => 2,\r
'mode' => 'OFF',\r
'type' => 'OPTIMIZED'\r
$this->rawResults = false;\r
$this->resultArray = false;\r
$this->result = false;\r
- $this->errorMessage = false;\r
+ $this->errorMessages = array();\r
$this->error = false;\r
\r
}\r
color: #008000;
margin-top: .2em;
}
+.GLMSresultWarning {
+ color: red;
+}
\ No newline at end of file
*/
public function __construct ($wpdb, $config)
{
-
+/*
// Save WordPress Database object
$this->wpdb = $wpdb;
// Save plugin configuration object
$this->config = $config;
+*/
// Delete our version from WordPress Options
delete_option('glmMembersDatabaseSearchPluginVersion');
* version from this plugin.
*/
define('GLM_MEMBERS_SEARCH_PLUGIN_VERSION', '1.2.2');
-define('GLM_MEMBERS_SEARCH_PLUGIN_DB_VERSION', '0.0.3');
+define('GLM_MEMBERS_SEARCH_PLUGIN_DB_VERSION', '0.0.4');
// 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');
$searchSettigns = false;
$settingsUpdated = false;
$settingsUpdateError = false;
+ $searchTestFailure = false;
+ $searchTestMessage = array();
// Determine if current user can edit configurations
$settingsUpdateError = true;
}
+ // Perform a search to test server, index, Website, login and key settings
+ require_once GLM_MEMBERS_SEARCH_PLUGIN_CLASS_PATH.'/glmSearch.php';
+ $settings = $searchSettings['fieldData'];
+ $GlmSearch = new GLMSearch(
+ $settings['server'],
+ $settings['search_index'],
+ $settings['website'],
+ $settings['login'],
+ $settings['login_key']
+ );
+
+ // If false then parameters aren't all correct
+ if (!$GlmSearch) {
+ $searchTestFailure = true;
+ $searchTestMessages[] = "The GlmSearch class could not be instatiated.";
+ } elseif ($GlmSearch->error) {
+ $searchTestFailure = true;
+ $searchTestMessages = $GlmSearch->errorMessages;
+ } else {
+
+ $searchResult = $GlmSearch->glmSearch("A", 'OR', 0, 2);
+
+ // Check for total failure
+ if (!$searchResult) {
+
+ $searchTestFailure = true;
+ $searchTestMessages[] = "
+ General failure when trying to test search.
+ Are Server URL, Search Index, Server Login, and Login Key all correct?
+ ";
+
+ if (count($searchTestMessages) == 0) {
+ $searchTestMessagesp[] = 'Unknown error';
+ }
+ } else {
+
+ // Check for no results returned
+ if (!is_array($searchResult) || !isset($searchResult['totalResults']) || !$searchResult['totalResults'] > 0 ) {
+
+ $searchTestFailure = true;
+ $searchTestMessages[] = "No results returned from OpenSearchServer. Is Website setting correct and has Website been indexed?";
+ }
+ }
+ }
+
break;
// Default is to get the current settings and display the form
// Compile template data
$templateData = array(
- 'reason' => '',
- 'searchSettings' => $searchSettings,
- 'settingsUpdated' => $settingsUpdated,
- 'settingsUpdateError' => $settingsUpdateError
- );
+ 'searchSettings' => $searchSettings,
+ 'settingsUpdated' => $settingsUpdated,
+ 'settingsUpdateError' => $settingsUpdateError,
+ 'searchTestFailure' => $searchTestFailure,
+ 'searchTestMessages' => $searchTestMessages
+ );
// Return status, suggested view, and data to controller
return array(
--- /dev/null
+<?php
+/**
+ * Gaslight Media Members Database
+ * GLM Members DB - Search Add-on - Request something from OSS
+ *
+ * PHP version 5.5
+ *
+ * @category glmWordPressPlugin
+ * @package glmMembersDatabase
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release ossRequest.php,v 1.0 2014/10/31 19:31:47 cscott Exp $
+ * @link http://dev.gaslightmedia.com/
+ */
+
+// Load GLM Search class
+require_once GLM_MEMBERS_SEARCH_PLUGIN_CLASS_PATH.'/glmSearch.php';
+
+/**
+ * GlmMembersAdmin_search_ossRequest
+ *
+ * PHP version 5
+ *
+ * @category Model
+ * @package GLM Member DB
+ * @author Chuck Scott <cscott@gaslightmedia.com>
+ * @license http://www.gaslightmedia.com Gaslightmedia
+ * @release SVN: $Id: search.php,v 1.0 2011/01/25 19:31:47 cscott
+ * Exp $
+ */
+class GlmMembersAdmin_search_ossRequest extends GLMSearch
+{
+
+ /**
+ * WordPress Database Object
+ *
+ * @var $wpdb
+ * @access public
+ */
+ public $wpdb;
+
+ /*
+ * Constructor
+ *
+ * This constructor performs the work for this model. This model returns
+ * an array containing the following.
+ *
+ * 'status'
+ *
+ * True if successfull and false if there was a fatal failure.
+ *
+ * 'view'
+ *
+ * A suggested view name that the contoller should use instead of the
+ * default view for this model or false to indicate that the default view
+ * should be used.
+ *
+ * 'data'
+ *
+ * Data that the model is returning for use in merging with the view to
+ * produce output.
+ *
+ * @wpdb object WordPress database object
+ *
+ * @return array Array containing status, suggested view, and any data
+ */
+ public function __construct ($wpdb, $config)
+ {
+
+ // Save WordPress Database object
+ $this->wpdb = $wpdb;
+
+ // Save plugin configuration object
+ $this->config = $config;
+
+
+ // Get the Open Search Server parameters from management settings
+ $server = $this->config['settings']['server'];
+ $index = $this->config['settings']['search_index'];
+ $website = $this->config['settings']['website'];
+ $login = $this->config['settings']['login'];
+ $key = $this->config['settings']['login_key'];
+ $exclude_home_page = $this->config['settings']['exclude_home_page'];
+
+ // Run constructor for GLMSearch data class
+ parent::__construct($server, $index, $website, $login, $key, $exclude_home_page);
+
+ }
+
+ public function modelAction($actionData = false)
+ {
+
+ // Get the requested option
+
+ }
+}
+
+?>
\ No newline at end of file
$this->config = $config;
// Get the Open Search Server parameters from management settings
+ $server = $this->config['settings']['server'];
$index = $this->config['settings']['search_index'];
$website = $this->config['settings']['website'];
$login = $this->config['settings']['login'];
$key = $this->config['settings']['login_key'];
$exclude_home_page = $this->config['settings']['exclude_home_page'];
- // Run constructor for members data class
- parent::__construct($index, $website, $login, $key, $exclude_home_page);
+ // Run constructor for GLMSearch data class
+ parent::__construct($server, $index, $website, $login, $key, $exclude_home_page);
}
$haveSearchRequest = false;
$haveSearchResult = false;
+ $searchFailure = false;
+ $failureMessage = false;
$status = true;
$query = false;
$start = 0;
// Send request to OpenSearchServer and get results
if (trim($query) != '') {
$searchResult = $this->glmSearch($query, $operator, $start, $rows);
+ if (!$searchResult) {
+ $searchFailure = true;
+ $failureMessage = $this->rawResults;
+ if (!$failureMessage) {
+ $failureMessage = 'Unknown error';
+ }
+ }
if (is_array($searchResult) && isset($searchResult['totalResults']) && $searchResult['totalResults'] > 0 ) {
$haveSearchResult = true;
}
$templateData = array(
'haveSearchRequest' => $haveSearchRequest,
'haveSearchResult' => $haveSearchResult,
+ 'searchFailure' => $searchFailure,
+ 'failureMessage' => $failureMessage,
'searchResult' => $searchResult,
'query' => $query
);
== Description ==
The Gaslight Media Members Database Search Child Plugin is an add-on to the Gaslight Media Members Database,
-which is required to install and run this plugin
+which is required to install and run this plugin.
+
+This plugin provides a shortcode that can display a search form and search results on a page. You can also
+create a custom form anywhere on the site provided that the form action targets a search page that includes
+the [glm-members-search] shortcode and includes the following submit parameters.
+
+* "query" = Search string entered by user
+* "matchAll" = Optional checkbox value to match all terms vs any terms. Default is any.
== Installation ==
-This section describes how to install the plugin and get it working.
+Use normal Wordpress plugin installation proceedures.
e.g.
$content .= $this->controller('dashboardWidget', 'search');
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
+
+ /*
+ * get_post_type
+ */
+
+// $content .= $this->controller('search', 'ossRequest', array('request' => 'crawl', 'url' => $post_url));
+
+}
+add_action( 'save_post', 'glm_member_db_admin_search_crawlUrl' );
\ No newline at end of file
-- Search Management Settings
CREATE TABLE {prefix}management (
id INT NOT NULL AUTO_INCREMENT,
+ server TINYTEXT NULL, -- OSS Search Server URL
search_index TINYTEXT NULL, -- OSS Search Index to use (normally "Index_1")
website TINYTEXT NULL, -- Hostname for the Website
exclude_home_page BOOLEAN NULL, -- Flag to say whether to exclude home page from search results
*/
$glmMembersSearchDbVersions = array(
- '0.0.1' => array('version' => '0.0.1', 'tables' => 1, 'date' => '6/20/16'),
- '0.0.2' => array('version' => '0.0.2', 'tables' => 1, 'date' => '7/5/16'),
- '0.0.3' => array('version' => '0.0.3', 'tables' => 1, 'date' => '7/7/16')
+ '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')
);
--- /dev/null
+-- Gaslight Media Members Database
+-- File Created: 7/5/16 15:27:15
+-- Database Version: 0.0.4
+-- 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 server TINYTEXT;
+
+----
+
+UPDATE {prefix}management SET server = '';
),
'dashboardWidget' => array(
'search' => GLM_MEMBERS_SEARCH_PLUGIN_SLUG
+ ),
+ 'search' => array(
+ 'ossRequest' => GLM_MEMBERS_SEARCH_PLUGIN_SLUG
)
+
),
'frontActions' => array(
'search' => array(
'index' => GLM_MEMBERS_SEARCH_PLUGIN_SLUG,
- 'sitemap' => GLM_MEMBERS_SEARCH_PLUGIN_SLUG
+ 'sitemap' => GLM_MEMBERS_SEARCH_PLUGIN_SLUG
)
)
);
<td colspan="2">
{if $settingsUpdated}<h2 class="glm-notice glm-flash-updated glm-right">Settings Updated</h2>{/if}
{if $settingsUpdateError}<span class="glm-error glm-flash-updated glm-right">Settings Update Error</span>{/if}
+ {if $searchTestFailure}
+ <h2 style="margin: 2em 0 2em 0; border: 1px black solid; padding: 5px;">
+ <span class='glm-warning' >Search Engine Test Failure</span>
+ <ul>
+ {foreach $searchTestMessages as $m}
+ <li>{$m}</li>
+ {/foreach}
+ </ul>
+ </h2>
+ {/if}
+
<h2>General Search Settings</h2>
</td>
</tr>
+ <tr>
+ <th {if $searchSettings.fieldRequired.server}class="glm-required"{/if}>Server URL:</th>
+ <td {if $searchSettings.fieldFail.server}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
+ <input type="text" name="server" value="{$searchSettings.fieldData.server}" class="glm-form-text-input-medium" placeholder="http://oss.gaslightmedia.com:9090">
+ {if $searchSettings.fieldFail.server}<p>{$searchSettings.fieldFail.server}</p>{/if}
+ </td>
+ </tr>
<tr>
<th {if $searchSettings.fieldRequired.search_index}class="glm-required"{/if}>Search Index:</th>
<td {if $searchSettings.fieldFail.search_index}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
</td>
</tr>
<tr>
- <th {if $searchSettings.fieldRequired.login}class="glm-required"{/if}>OSS Login:</th>
+ <th {if $searchSettings.fieldRequired.login}class="glm-required"{/if}>Search Server Login:</th>
<td {if $searchSettings.fieldFail.login}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
<input type="text" name="login" value="{$searchSettings.fieldData.login}" class="glm-form-text-input-medium">
{if $searchSettings.fieldFail.login}<p>{$searchSettings.fieldFail.login}</p>{/if}
</td>
</tr>
<tr>
- <th {if $searchSettings.fieldRequired.login_key}class="glm-required"{/if}>OSS login key:</th>
+ <th {if $searchSettings.fieldRequired.login_key}class="glm-required"{/if}>Search Server login key:</th>
<td {if $searchSettings.fieldFail.login_key}class="glm-form-bad-input glm-form-bad-input-misc"{/if}>
<input type="text" name="login_key" value="{$searchSettings.fieldData.login_key}" class="glm-form-text-input-medium">
{if $searchSettings.fieldFail.login_key}<p>{$searchSettings.fieldFail.login_key}</p>{/if}
</div> <!-- / front content area -->
-
- {if $frontDebug}
- <script>
- window.open('{$thisUrl}?glmDebugWindow=true','GLM_Plugin_Debug','width=800,height=800,left=50,top=50,resizable=yes,scrollbars=yes');
- </script>
- {/if}
-
+
</div> <!-- / wrap -->
\ No newline at end of file
{else}
<h4>No results matching your search.</h4>
+
+ {if $searchFailure}
+ <h4 class="GLMSresultWarning">We're sorry, there was some problem with getting search results. Please try again later.</h4>
+ <p>({$failureMessage})</p>
+ {/if}
{/if}
{else}