Cotonti / Open Source PHP Content Management FrameworkContent Management Framework

Forums / Cotonti / Extensions / Tag search working more like a search engine

staleo
#1 2014-05-01 19:10

Hi all again,

I got a little question concerning the Tags plugin.

Let's assume we got bunch of pages about cinema actors, and 4-5 dozens of tags, among which are "Bruce Willis" and "Sharon Stone". We read a page about Bruce Willis, than click on the tag to check if there were any pages about him. The page URL becomes something like http://domain.com/tags/bruce-willis, here we can see the list of articles about Willis, and whatever. Also, here we can see an input with the instant search for another actor or movie. We type here "Sharon Stone", click search. Allright, here we go, we got a list of articles about Stone, but the URL now is http://domain.com/tags?a=pages instead of http://domain.com/tags/sharon-stoneAbove that, if we now click on any article about Stone, and then click "Back" in the browser, Chrome will ask us to resend the inpit data to the server by refreshing the page (F5), which is pretty far from excellence.

Are there any ways of making the Tags plugin look and feel in a more google style, or wikipedia style? Because in fact, if you have a lot of tags and pages, search within tags is a small google on your site. I'm planning to have around 2-3 thousand pages, and not less that a thousand tags, so this enhancement I described above would be amazingly valuable.

Dear community, any ideas?


This post was edited by staleo (2014-05-01 19:34, 5 years ago)
Macik
#2 2014-05-02 18:13

It's done this way because while you click tag link you get search result for tag with default parameters (pages order and search scope — pages|forum). And while you makes search from the Tags form you can specify addition parameters like scope and order. 

So if we want use /tags/bruce-willis, we can not add addition params, and on the other side if we add params we get it in URL — /tags/bruce-willis/&order=…

 

but… This quest can be partially solved with addition javascript:

file `tags.php` line ~80 (remove `a` parameter, adding `t` parameter):

	'TAGS_ACTION' => cot_url('plug', 'e=tags&t=-searchtag-'),

in `tags.tpl` (add input named `a`, and add script for target url substitution):

	<form action="{TAGS_ACTION}" method="post">
		<input id="tags-sq" type="text" name="t" value="{TAGS_QUERY}" />
		<input type="submit" value="&raquo;&raquo;" />
		<input type="hidden" name="a" value="{PHP.a}">
		<select name="order">
			<option value="">{PHP.L.tags_Orderby}</option>
			<option value="">--</option>
			{TAGS_ORDER}
		</select>
	</form>
	<script type="text/javascript">
		$(function() {
	  	$('form').submit(function(e){
	  		var url = $(this).attr('action'),
	  				tag = $(this).find('input[name="t"]').val();
	  		$(this).attr('action',url.replace(/\-searchtag\-/g,encodeURIComponent(tag)));
	  	});
    });
	</script>

This code works only with javascript and jQuery enabled.

p/s/ By pressing back button or F5 you still get browser query to resend request as we use addition parameters.

p.p.s. if you dont care about addition params or it «hardcoded» in plugin we can use simple redirect:

		$(function() {
	  	$('form').submit(function(e){
	  		var url = $(this).attr('action'),
	  				tag = $(this).find('input[name="t"]').val();
	  		window.location.assign(getBaseHref() + url.replace(/\-searchtag\-/g,encodeURIComponent(tag)));
	  	});
    });

As you suppose it should be..

https://github.com/macik
правильный хостинг — https://goo.gl/fjCa1F