← Back to team overview

slub.team team mailing list archive

[Merge] lp:~henrik-lochmann/goobi-presentation/bug-985487 into lp:goobi-presentation

 

Henrik Lochmann has proposed merging lp:~henrik-lochmann/goobi-presentation/bug-985487 into lp:goobi-presentation.

Requested reviews:
  Saxon State Library Team (slub.team)

For more details, see:
https://code.launchpad.net/~henrik-lochmann/goobi-presentation/bug-985487/+merge/104405

Implementation of feature/wishlist bug #985487.
-- 
https://code.launchpad.net/~henrik-lochmann/goobi-presentation/bug-985487/+merge/104405
Your team Saxon State Library Team is requested to review the proposed merge of lp:~henrik-lochmann/goobi-presentation/bug-985487 into lp:goobi-presentation.
=== modified file 'dlf/ext_localconf.php'
--- dlf/ext_localconf.php	2012-04-30 16:08:47 +0000
+++ dlf/ext_localconf.php	2012-05-02 15:42:20 +0000
@@ -66,4 +66,6 @@
 // Register command line scripts.
 $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['cliKeys'][$_EXTKEY] = array ('EXT:'.$_EXTKEY.'/cli/class.tx_dlf_cli.php', '_cli_dlf');
 
+// Register solr suggest eID.
+$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['tx_dlf_suggest'] = 'EXT:'.$_EXTKEY.'/plugins/search/class.tx_dlf_search_suggest.php';
 ?>
\ No newline at end of file

=== modified file 'dlf/plugins/search/class.tx_dlf_search.php'
--- dlf/plugins/search/class.tx_dlf_search.php	2012-03-30 09:14:14 +0000
+++ dlf/plugins/search/class.tx_dlf_search.php	2012-05-02 15:42:20 +0000
@@ -40,6 +40,27 @@
 	public $scriptRelPath = 'plugins/search/class.tx_dlf_search.php';
 
 	/**
+	 * Adds the JS files necessary for search sugestions to the 
+	 * page header.
+	 *
+	 * @access	public
+	 *
+	 * @return	void
+	 */
+	private function addSuggestSupport() {
+		$libs = array(
+			"search_suggest" => "search_suggest.js"
+		);
+
+		foreach ($libs as $lib_key => $lib_file) {
+			$GLOBALS['TSFE']->additionalHeaderData[$this->prefixId.$lib_key] .= '	<script type="text/javascript" src="'
+				.t3lib_extMgm::siteRelPath($this->extKey)
+				.'plugins/search/'.$lib_file
+				.'"></script>';	
+		}
+	}
+	
+	/**
 	 * The main method of the PlugIn
 	 *
 	 * @access	public
@@ -66,7 +87,10 @@
 		}
 
 		if (empty($this->piVars['query'])) {
-
+			
+			// Add suggest JavaScript file.
+			$this->addSuggestSupport();
+			
 			// Load template file.
 			if (!empty($this->conf['templateFile'])) {
 

=== added file 'dlf/plugins/search/class.tx_dlf_search_suggest.php'
--- dlf/plugins/search/class.tx_dlf_search_suggest.php	1970-01-01 00:00:00 +0000
+++ dlf/plugins/search/class.tx_dlf_search_suggest.php	2012-05-02 15:42:20 +0000
@@ -0,0 +1,70 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2012 Henrik Lochmann <dev@xxxxxxxxxxxxxxxx>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+/**
+ * Search suggestion Ajax backend for the Plugin 'DLF: Search' of the 
+ * 'dlf' extension. This class is invoked using the eID bypass.
+ *
+ * @author	Henrik Lochmann <dev@xxxxxxxxxxxxxxxx>
+ * @copyright	Copyright (c) 2012, Zeutschel GmbH
+ * @package	TYPO3
+ * @subpackage	tx_dlf
+ * @access	public
+ */
+require_once(PATH_tslib.'class.tslib_pibase.php');
+class tx_dlf_search_suggest extends tslib_pibase {
+
+	private $content;
+
+	public $scriptRelPath = 'plugins/search/class.tx_dlf_search_suggest.php';
+	
+	private static function getSolrSuggestUrl($query) {
+		$conf = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][tx_dlf_solr::$extKey]);
+		$host = ($conf['solrHost'] ? $conf['solrHost'] : 'localhost');
+		$port = $conf['solrPort'];
+		$path = trim($conf['solrPath'], '/').'/'.$core;
+		return "http://".$host.":".$port."/".$path."suggest/?q=".$query;
+	}
+	
+	public function main() {
+		$url = tx_dlf_search_suggest::getSolrSuggestUrl(t3lib_div::_POST('q'));
+		
+		if ($stream = fopen($url, 'r')) {
+		    $this->content .= stream_get_contents($stream);
+    		fclose($stream);
+		} else {
+			$this->content .= "Could not connect to index server.";
+		}
+	}
+	
+	public function printContent() {
+		echo $this->content;
+	}
+}
+
+$suggest = t3lib_div::makeInstance('tx_dlf_search_suggest');
+$suggest->main();
+$suggest->printContent();
+
+?>
\ No newline at end of file

=== added file 'dlf/plugins/search/search_suggest.js'
--- dlf/plugins/search/search_suggest.js	1970-01-01 00:00:00 +0000
+++ dlf/plugins/search/search_suggest.js	2012-05-02 15:42:20 +0000
@@ -0,0 +1,23 @@
+$(
+	function(){
+	    // jQuery autocomplete integration
+	    $(".autocomplete").autocomplete({ 
+        	source: function( request, response ) { 
+            	return $.post( 
+                	'/', { eID: "tx_dlf_suggest", q:  escape(request.term) }, 
+                	function( xmlData ) { 
+						var result = new Array();
+	
+						$('arr[name="suggestion"] str', xmlData).each(function(i) {
+							if ($(this).text().indexOf(request.term) == 0) {
+								result.push($(this).text());
+							}
+						});
+	
+						return response(result);
+                	},
+					'xml');
+            }
+        });
+	}
+);
\ No newline at end of file

=== modified file 'dlf/plugins/search/template.tmpl'
--- dlf/plugins/search/template.tmpl	2012-03-16 09:06:25 +0000
+++ dlf/plugins/search/template.tmpl	2012-05-02 15:42:20 +0000
@@ -1,7 +1,7 @@
 <!-- ###TEMPLATE### -->
 <form class="tx-dlf-search-form" action="###ACTION_URL###" method="post" enctype="multipart/form-data">
 	<label for="###FIELD_QUERY###">###LABEL_QUERY###</label>
-	<input type="text" id="###FIELD_QUERY###" name="###FIELD_QUERY###" value="###QUERY###" />
+	<input type="text" id="###FIELD_QUERY###" name="###FIELD_QUERY###" value="###QUERY###" class="autocomplete" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">
 	<input type="submit" value="###LABEL_SUBMIT###" />
 </form>
 <!-- ###TEMPLATE### -->
\ No newline at end of file

=== added file 'dlf/t3jquery.txt'
--- dlf/t3jquery.txt	1970-01-01 00:00:00 +0000
+++ dlf/t3jquery.txt	2012-05-02 15:42:20 +0000
@@ -0,0 +1,1 @@
+components=jQuery,Core,Position,Autocomplete
\ No newline at end of file