PDA

View Full Version : Help: Strip formatting from {vb:raw criteriaDisplay}


BeoRski
01-25-2012, 11:47 AM
It would be great if {vb:raw criteriaDisplay} only returns the raw keywords without the html formatting tags and the prefix "Keyword(s): ". This will greatly help everyone in customizing their forums or in my case, implement Google's Limited Release Adsense for Search feature.

Example: If you search for vBulletin Suite the above variable will return "Keyword(s): <b><u>vBulletin</u></b>, <b><u>Suite</u></b>". It would be better if it simply returned "vBulletin, Suite" as the formatting and the prefix can easily be added through the template.

Any suggestions on how to go around this will be highly appreciated. Thanks!

kh99
01-25-2012, 12:37 PM
The prefix is the phrase key_words, so you could possibly edit that (although for some reason it doesn't include the ':' or the parameters). The separating tags are hard-coded in vb/search/criteria.php. You could possibly create a plugin using hook search_complete and make some changes to the criteria string (note that the keywords is only one of the possible criteria displayed in that string).

BeoRski
01-25-2012, 02:26 PM
The prefix is the phrase key_words, so you could possibly edit that (although for some reason it doesn't include the ':' or the parameters). The separating tags are hard-coded in vb/search/criteria.php. You could possibly create a plugin using hook search_complete and make some changes to the criteria string (note that the keywords is only one of the possible criteria displayed in that string).
Thank you for your response. If we change it through a plugin, I assume it will also change the overall behavior of the variable. How can we change it so that it is passed on as another variable? I am not a developer but I understand some of the concepts. I would appreciate examples if possible. ^_^

kh99
01-25-2012, 02:39 PM
Well, I'm confused about exactly what you want to do. Like I mentioned above, the keywords are only one criteria that can be displayed in the {vb:raw criteriaDisplay} variable, so it seems like you'd want to separate them all, which is a bit more work. Unless you have a separate use for just a list of the keywords? In any case I agree that they have made it very difficult to customize that part of the results display. Most of vb separates the display formatting from the logic, but the search criteria class mostly does it's own formatting for some reason.

BeoRski
01-25-2012, 02:43 PM
kh99, you are correct. I am only interested in getting the keyword list.

kh99
01-25-2012, 03:10 PM
OK, you could create plugin using hook search_complete and this code:

if (get_class($this) == 'vb_Search_Resultsview')
{
$this->template->register('keywords', $criteria->get_keywords());
}


Then in the template, keywords is an array of arrays, like is described in this comment from the get_words function:

* Return the parsed keywords to filter
*
* @return array. An array of array("word" => $word, "joiner" => $joiner)
* where $word is the keyword and $joiner indicates how the word should be
* joined to the query. $joiner should be one of "AND", "OR", or "NOT"
* with the exception of the first item for which $joiner is NULL.
* It is up to the search implementation to define exactly how to treat
* the words specified.
*/
public function get_keywords()


So for instance I could put this in the template:

<vb:each from="keywords" value="keyword">
Keyword: {vb:raw keyword.joiner} {vb:raw keyword.word}<BR />
</vb:each>

Then when I search for test OR moderators (for example), I get this output:

Keyword: test
Keyword: OR moderators


Anyway, I hope that helps.

BeoRski
01-25-2012, 03:55 PM
Wow! Thank you very much. I will try it out and post a feedback. ^_^

--------------- Added 1327511155 at 1327511155 ---------------

I have successfully implemented this. Thank you so much for your help kh99!

farru
03-21-2013, 04:57 AM
Hey there,

Sorry for bringing this thread back from the dark. I am running 4.2.0 and can't seem to find any reference of 'search_complete' in templates. I assume the template name has been changed? Or, may be i am not looking in the right spot. If anyone can point me in the right direction, i would really appreciate that.

kh99
03-21-2013, 10:34 AM
search_complete is a hook location for plugins. If you want to implement the above, you need to go to Plugins & Products > Add New Plugin and select search_complete from the Hook Location dropdown. You also need a title (something so that you'll remember what it's for years from now). Then copy the code into the large box, select the 'Yes" radio button to make it active, and Save.

Then you'd also need to edit the search_resultlist template as is mentioned above.

tbworld
03-21-2013, 11:02 PM
KH99 - I am a big fan. Thanks so much for taking the time to help so many people here. I constantly find your replies insightful :).

In my journeys, I noticed that plugin 'search_complete' appears in 'resultsview.php' and 'search.php'. I see why this might be needed, but it also seems as it could cause problems if the user doesn't know. Am I missing something in this assumption?

kh99
03-22-2013, 12:04 AM
In my journeys, I noticed that plugin 'search_complete' appears in 'resultsview.php' and 'search.php'. I see why this might be needed, but it also seems as it could cause problems if the user doesn't know. Am I missing something in this assumption?

That was quite a while ago, so I can't remember exactly what I was thinking at the time, but I believe the check for get_class($this) == 'vb_Search_Resultsview' was meant to make sure that the other line is only executed when the resultsview.php hook is called. In fact, looking at it now, I'm not sure why it works because the search.php hook is not in any class, so there would be no $this. Maybe it works because it would just be a null value? Or maybe you're asking because it doesn't work...

tbworld
03-22-2013, 01:01 AM
I'm not sure why it works because the search.php hook is not in any class, so there would be no $this. Maybe it works because it would just be a null value? Or maybe you're asking because it doesn't work...

Actually, I never understood it. I just added another hook in the code as to not mess any future execution of code that might call it. I found it interesting that one was part of a class and the other is not. I will have to revisit that code with your thoughts in mind. I guess I figured that it was accidentally given a similar name.

If I do not leave myself some major comments in my code I cannot remember what I did after a week! Thanks so much for your relply :)

kh99
03-22-2013, 01:23 AM
Oh, I see, you were asking about the hooks and not this code specifically. I didn't think of that, maybe it is a mistake. I don't have the code in front of me right now so I can't look to see if there's anything in common between the two locations that would make it make sense. I know there are some other hooks that are called in more than one place on purpose, so it's possible that it's not a mistake, but you're right, it could be confusing.

izzet
03-29-2013, 03:26 AM
hi http://www.yazsana.net/tag/kabak-tarifleri/ meta desc. or keyword not found :s help me problem pls.

Talk Hard
08-07-2016, 10:28 PM
I fugured another way since this only worked for search and my tags pages only get indexed.

I used the replacement tool .
I added in </u></b> replaced with nothing
I added in <u><b> """"""

Nothing broke yet:
http://www.scam.com/tags.php?tag=deals