View Full Version : Full Search Strings
tfw2005
05-16-2008, 08:13 PM
I saw this, didn't even realize it was originally formatted like this before it went to searchid in browser upon clicking:
search.php?do=searchresults&string=tag_text&catid=0&quicksearch=1&tag=1
Even tho its probably not "best practices", is there a way to create hand done URL strings pointing to different variables, even if they do eventually turn to searchids? Something like
search.php?do=searchresults&string=$entry[field88]&catid=0&quicksearch=1&cfield88=1
search.php?do=searchresults&string=$entry[title]&catid=0&quicksearch=1&title=1
etc? If so, a list of working variables that could be used would be great. title, pagetext, keywords, username, customfieldXYZ, etc, and how to format them in that string.
Then, after thats done, if possible that is, is there any way to make that variable we insert to the string formatted like the multi-word tags, such as "Tag_Name_Has_Underscores" Maybe like a new variable we can hook into showentry like: $entry[field60_parsed] so it renders like that.
That way we can limit searches to exact phrases, in exact fields.
Hope this can work out. Thanks!
Brian
05-17-2008, 01:19 PM
search.php?do=searchresults&string=My_Text&catid=0&fields[]=title&cfields[]=field1&cfields[]=field3
You can add the '&field[]=' attribute for title, keywords, pagetext (entry description), and posts (replies to the entry).
Custom fields can be added the same way, except using '&cfield[]=' in the URL.
Note that since these are in arrays, you will need to add the 'fields[]=' part in the URL multiple times to allow multiple fields to be searched. Example:
search.php?do=searchresults&string=My_Text&catid=0&fields[]=title&fields[]=keywords&fields[]=pagetext&fields[]=posts
Also note that if you add 'quicksearch=1' then that will automatically search the title, keywords, description, and posts without the need for the 'field[]' parts in the URL.
As for formatting the words to replace the spaces with underscores, you should be able to add a plugin to the 'vba_dyna_showentry_cfieldloop' hook location with code that looks something like this:
$customsearch[$thisfield] = str_replace(' ', '_', strip_tags($field['value']));
Then in your ADV_DYNA_SHOWENTRY template you can use this to display that formatted text:
$customsearch[fieldX]
tfw2005
05-17-2008, 04:09 PM
Thanks Brian. Plugin for underscore situation working.
In relation to the strings, I've done this:
search.php?do=searchresults&string=$customsearch[field58]&catid=0&cfields[]=field58
To search for the formatted text in custom field 58 only, and when i click the link, i get this:
Vbulletin Message:
You must choose a category to search in!
I even hardcoded a category number so it was like
search.php?do=searchresults&string=$customsearch[field58]&catid=32&cfields[]=field58
and got the same message.
Any ideas?
Brian
05-17-2008, 04:22 PM
Sorry about that... I added some code to search.php when I was testing to make sure the fields were passed properly and apparently added it before the category check is run. If you add '&catids[]=0' to the URL then that should take care of that issue.
tfw2005
05-17-2008, 05:05 PM
Hehe, I tried catid[]=0 too thinking i was smart. Missed the s.
That seems to work, thanks Brian, this will help tremendously in making the system more dynamic. This really got me excited for some reason. /nerd.
My suggestion - Make this default in the system somehow, remove the searchid from these types, and add some optional SEO rules to the htaccess, ones that can be added optionally even if you have SEO turned on, in case people dont care or won't use it, wont bog it down. I'll link you to my final results to show you how I think it's useful once I'm done.
tfw2005
05-17-2008, 05:25 PM
Hehe, ok, I'm gonna push it, but figured I'd give it a shot...
Any easy plugin to go along with all this that will parse the cfields the same way as tags, so that if there is a comma present, it treats each individual set of words between the commas as one search string?
So if i put...
search.php?do=searchresults&string=$customsearch[field58]&catids[]=0&cfields[]=field58
and cfield58 has : TEXT 1, TEXT 2, TEXT 3
Then $customsearch[field58] or a new variable (preferred) produces
<a href="$vba_options[dyna_homeurl]/search.php?do=searchresults&string=TEXT_1&catids[]=0&cfields[]=field58">TEXT 1</a>, <a href="$vba_options[dyna_homeurl]/search.php?do=searchresults&string=TEXT_2&catids[]=0&cfields[]=field58">TEXT 2</a>, <a href="$vba_options[dyna_homeurl]/earch.php?do=searchresults&string=TEXT_3&catids[]=0&cfields[]=field58">TEXT 3</a>
Basically the tags situation, but for cfields linking to cfields search results.
Brian
05-19-2008, 02:38 PM
Sorry, I'm not sure that one's going to be quite as easy. :/
tfw2005
05-19-2008, 09:15 PM
Tis Ok, I figured as much. It is on my "suggestions" list for future releases tho :). I think I am going to adjust my setup (currently using 60 or so custom fields I think) to be more "one word/phrase per field", add in 10/20 fields for same data "name 1, name 2, name 3, etc", to allow multiple data per "type of filed", have my guys re-enter data, so that I can use the method above to cross link. Just create the search strings in templates with "search field 1,2,3, and 4 for XYZ phrase". Not optimal situation, but will get the job done sans a custom-fields-tags situation.
Thanks again for the hook up.
tfw2005
05-20-2008, 07:51 PM
Question - Somewhat related to this:
How hard would it be to add a new type of custom field, lets say multiple select PLUS, which has an additional field, called "url", and if that is parsed and displayed, it links the option choice name to the url entered on the back end?
Entry on the back end could work like
Title 1|http://www.domain/link1.html
Title 2|http://www.domain/link2.html
Title 3|http://www.domain/link3.html
Title 4|http://www.domain/link4.html
Or something.
But, select list on create/edit entry pages looks the same. System just knows to look for a URL and connect it to the option name when displaying in showentry.
Possible sooner than later or at all?
Later!
Brian
05-21-2008, 02:46 PM
I would think you could add a plugin to the 'vba_dyna_showentry_cfieldloop' hook location that looks something like this to handle that.
if ($field['fieldid'] == X)
{
$field['value'] = '<a href="http://domain.com/link' . $field['value'] . '">' . $field['value'] . '</a>';
}
tfw2005
05-21-2008, 04:52 PM
Edit, misread what this does. Am I correct in thinking this will work....
$customsearch1[$field['value']] = str_replace(' ', '_', strip_tags($field['value']));
if ($field['fieldid'] == 58)
{
$field['value'] = '<a href="$vba_options[dyna_homeurl]/search.php?do=catids[]=0&cfields[]=field58&searchresults&string=' . $customsearch1[$field['value']] . '">' . $field['value'] . '</a>';
}
Adding in the $customsearch method from above.
Brian
05-22-2008, 03:00 PM
The first line should be $customsearch1[$field['fieldid']]
tfw2005
05-23-2008, 05:39 AM
Hey Brian,
this is giving me every choice from the multiple select box, with commas, inside one search string. And, all chosen options have one href tag wrapped around all of them. I guess this needs to be specified as "for each" somehow, that the hook isn't doing.
Thanks for helping out.
Brian
05-23-2008, 12:42 PM
$customsearch1[$field['value']] = str_replace(' ', '_', strip_tags($field['value']));
if ($field['fieldid'] == 58)
{
$field['value'] = '<a href="$vba_options[dyna_homeurl]/search.php?do=catids[]=0&cfields[]=field58&searchresults&string=' . $customsearch1[$field['value']] . '">' . $field['value'] . '</a>';
}
The code in red there should only be "$field['value']". No need for the $custmsearch variable.
tfw2005
05-23-2008, 01:04 PM
Sorry Brian. Same thing is happening. Tho, if I just use $field['value'], the strings that are inserted (all of them) just don't have the _ inbetween words.
I am putting this in vba_dyna_showentry_cfieldloop hook location.
To clarify:
What I want is
Multiple Select
Entry 1
Entry 2
Entry 3
to turn into
<a href="http://www.domain.com/dyna/search.php?do=catids[]=0&cfields[]=field243&searchresults&string=Entry_1">Entry 1</a>, <a href="http://www.domain.com/dyna/search.php?do=catids[]=0&cfields[]=field243&searchresults&string=Entry_2">Entry 2</a>, <a href="http://www.domain.com/dyna/search.php?do=catids[]=0&cfields[]=field243&searchresults&string=Entry_3">Entry 3</a>
What I am getting is
<a href="http://www.domain.com/dyna/search.php?do=catids[]=0&cfields[]=field243&searchresults&string=Entry_1,Entry_2,Entry_3">Entry 1, Entry 2, Entry 3</a>
The only difference in the 2 tries is that one has the _ and one doesn't. href is still wrapping the same way per option.
Brian
05-23-2008, 02:58 PM
Errr, it looks like you changed more code than I realized...
$customsearch1[$thisfield] = str_replace(' ', '_', strip_tags($field['value']));
if ($field['fieldid'] == 58)
{
$field['value'] = '<a href="$vba_options[dyna_homeurl]/search.php?do=catids[]=0&cfields[]=field58&searchresults&string=' . $customsearch1[$thisfield] . '">' . $field['value'] . '</a>';
}
Setting/using things like $customsearch1[$filed['value']] is not going to work since you're setting the key for that value in the $customsearch1 array to the value entered for the custom field. The array keys needs to be set to a unique id, like $thisfield (gives you "fieldX") or even $field['fieldid'] (gives you "X"). Then you use $customsearch1[$thisfield] to get the value that was set and altered to add the backslashes.
tfw2005
05-23-2008, 07:18 PM
Ok, thanks for looking into this first off.
I see what you are saying with needing the fieldid somewhere in the $customsearch
Let's forget the $customsearch part for now.
I did up solely this code:
if ($field['fieldid'] == 58)
{
$field2['value'] = str_replace(' ', '_', strip_tags($field['value']));
$field['value'] = '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=catids[]=0&cfields[]=field58&searchresults&string=' . $field2['value'] . '">' . $field['value'] . '</a>';
}
That gives me back the string= as str_replaced properly, and the "value name" non-str_replaced properly.
However, it does not wrap the href tag around each select option, it wraps one href tag around all options.
Is there a different variable for multiple select custom field options that needs to be specified? Like:
$field[value['option1'] aka $field[value['this_option']
Or
foreach ($field[value['option']] as somethingorother) do the href dealy;
Because using solely your unmodified code, or any other variation, field['value'] for multiple select custom fields is grouping all selected choices as one "value".
Hope that makes sense. I read over this thread and your responses to make sure I didn't just miss something, but I can't see it if I did.
tfw2005
05-29-2008, 02:11 AM
Hey Brian,
Wanted to see if you were gonna give this last part a shot, or if it's a no go. Waiting on this to see how to proceed with revamp of the system.
Brian
05-29-2008, 12:47 PM
You would need to format the value back into an array and then use something like this to process them.
if ($field['type'] == 'multiple_select' OR $field['type'] == 'checkbox')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$filed['value'] = '<a href="{link}">' . $fieldvalue . '</a>';
}
}
}
tfw2005
05-29-2008, 05:34 PM
Thanks Brian. That is *almost working*. It does parse the multiple selects, and apply the url to the individual option.
One problem, only showing one option/value on the page, the last option selected.
If I have
Multiple Select 1 - Selected
Multiple Select 2 - Selected
Multiple Select 3 - Selected
Multiple Select 4
Multiple Select 5
Then the only thing that shows up on the showentry page is "Multiple Select 3".
I guess each time it runs thru the loop, it overwrites $field['value'] with the last one it did.
Any way around that?
Brian
05-30-2008, 02:01 PM
Errr, looks like I missed a dot.
foreach ($field['array_value'] AS $fieldvalue)
{
$filed['value'] .= '<a href="{link}">' . $fieldvalue . '</a>';
}
tfw2005
05-30-2008, 02:07 PM
Seems to be working. Absolutely fantastic. Brian you are the man. Now, time to go to work on this puppy.
Later!
tfw2005
08-01-2008, 04:40 AM
Hehe, see how some server problems and life changes can slow things down? :)
So, I started to go to work on this puppy finally.
I have these custom fields that need to be parsed per multiple select entry. I have the code in place, one set of if then statements for each custom filed ID. 18 total.
Is there a way to condense this code, and possibly reduce any stress having all 18 of these one after another in a plugin would cause?
Custom filed IDs are 243 - 260.
if ($field['fieldid'] == 243)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field243">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 244)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field244">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 245)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field245">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 246)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field246">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 247)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field247">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 248)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field248">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 249)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field249">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 250)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field250">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 251)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field251">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 252)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field252">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 253)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field253">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 254)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field254">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 255)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field255">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 256)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field256">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 257)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field257">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 258)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field258">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 259)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field259">' . $fieldvalue . '</a><br />';
}
}
}
}
if ($field['fieldid'] == 260)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field260">' . $fieldvalue . '</a><br />';
}
}
}
}
tfw2005
08-01-2008, 05:41 AM
Second issue related to this, not sure where to change things if possible.
I currently have this hack in place to strip tags from the name, then add underscores for spaces, so that a direct url can be created, linking to the option name from a multiple select list to search results of that exact text in the same custom field within the system.
Example:
Multiple Select Option 3: Devastation # 3
is linked to via hardcoding and these hacks:
/dyna/search.php?do=searchresults&string=Devastation_#_3&catids[]=0&cfields[]=field258
That works for all multi word entries in a multiple select box. With one exception.
If the pound character - # - is in the text from the multiple select option, then when you click on the search results string, it gives you this error message:
Vbulletin Message: You must choose some fields to search in!
It only happens when # is present in the text, and therefore the search string.
Is there any way around this, adjusting the strip tags, etc?
Thanks!
Brian
08-01-2008, 10:45 AM
For the custom field code, use this for your first line:
if ($field['type'] == 'multiple_select' AND $field['fieldid'] >= 243 AND $field['fieldid'] <= 260)
Then change your link like so:
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field' . $field['fieldid'] . '">' . $fieldvalue . '</a><br />';
And that should let you condense things down from 18 to 1.
For the issue with # characters, looks like that's happening with the default tag usage as well, which can be corrected by looking in the dynamics/showentry.php file for this code:
if ($highlightkeywords)
{
$keyword = highlight_keywords($keyword, $highlight['string'], $highlight['wholeword']);
}
And adding this just below:
$keyword_nohighlight = preg_replace("/[^a-z_0-9 -]/i", '', str_replace(' ', '_', $keyword_nohighlight));
tfw2005
08-02-2008, 04:27 AM
Thanks Brian. This will work for now.
However, what happens if I create more custom fileds down the road which are out of order. So like
243-260, 275, 299, 302-307, etc etc.
Is there an array/explode situation that can be done. Ill enter the numbers comma seperated once, then it explodes and does it for each, or something. Or just use the OR command for each.
tfw2005
08-02-2008, 05:55 AM
Ok, ran into an issue. RE - The # problem.
The code you posted does work for fixing tags with # in them.
However, I have this custom code to generate the URLs for multiple select options as links:
if ($field['fieldid'] == 243)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = str_replace(' ', '_', strip_tags($fieldvalue));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field243">' . $fieldvalue . '</a><br />';
}
}
}
}
I changed it to this, and it does in fact strip the pound sign from the search url string:
if ($field['fieldid'] == 243)
{
if ($field['type'] == 'multiple_select')
{
$field['array_value'] = explode(', ', $field['value']);
if (!empty($field['array_value']))
{
$field['value'] = '';
foreach ($field['array_value'] AS $fieldvalue)
{
$fieldvalue2 = preg_replace("/[^a-z_0-9 -]/i", '', str_replace(' ', '_', strip_tags($fieldvalue)));
$field['value'] .= '<a href="' . $vba_options[dyna_homeurl]. '/search.php?do=searchresults&string=' . $fieldvalue2 . '&catids[]=0&cfields[]=field243">' . $fieldvalue . '</a><br />';
}
}
}
}
This line is what changed
$fieldvalue2 = preg_replace("/[^a-z_0-9 -]/i", '', str_replace(' ', '_', strip_tags($fieldvalue)));.
So, it does strip the # sign from that URL, but when you click it now, you get this message:
vBulletin Message
Sorry - no matches. Please try some different terms.
I guess it's not recognizing others in the system because the search url is different than it was before we removed the pound, and it doesn't know to do that for returning results, etc?
I have that plugin in the vba_dyna_showentry_cfieldloop hook location.
Any way around this?
tfw2005
08-02-2008, 06:04 AM
BTW, to get around this I just removed the # sign from the titles of all my multiple select fileds for now. But if a more permanent solution can be figured out whenever, that would be cool. Just not super important now if you are busy.
Brian
08-02-2008, 01:49 PM
However, what happens if I create more custom fileds down the road which are out of order. So like
243-260, 275, 299, 302-307, etc etc.
I would stick with the less/greater than code while you can. Once you add more then you can just add more conditions, something like this:
if ($field['type'] == 'multiple_select' AND (($field['fieldid'] >= 243 AND $field['fieldid'] <= 260) OR ($field['fieldid'] >= 302 AND $field['fieldid'] <= 307) OR in_array($field['fieldid'], array(275, 299))))
As for the # signs, I'll have to look into that some more before the next release.
tfw2005
08-07-2008, 05:43 PM
Another issue with this. Apparently, if there is a quotation mark or single quote anywhere in the text of a search string, it automatically returns no results. I have almost 2000 entries with 100+ custom fields each, dunno if I can edit them all to not have special characters this time.
Example:
/search.php?do=searchresults&string=%22Let%27s_hit_the_road,_Autobots._We_have_a_planet_to_save!%22&catids[]=0&cfields[]=field62
Gives: Sorry - no matches. Please try some different terms.
I guess this is somewhat related to the # situation above. Happening in multiple select and regular text entry boxes.
Basically, It would be best to remove all punctuation, spaces, and special characters in the search string, and have results work the same. I can code the removal of the characters from the string, but then the results dont come back because the system isnt matching the 2.
This affects tags, even with the fix above in place. Fix above strips those items in some cases, turns " to quot , but doesn't return results for newly formatted url.
All dont work:
"Ultra Magnus" - /search.php?do=searchresults&string=quotUltra_Magnusquot&catid=0&quicksearch=1&tag=1
Ultra's - /search.php?do=searchresults&string=Ultras&catid=0&quicksearch=1&tag=1
"Ultra's Magnus" - /search.php?do=searchresults&string=quotUltras_Magnusquot&catid=0&quicksearch=1&tag=1
BTW, if you can point me in the right direction for where to get strips in for tags, single line text custom field results, and then the search result functions, I can try working this out, just don't know where to go for what I guess is the search results.
Im assuming we would need a more robust strip for tags, custom fileds, and then go to the search functions and say if "is tag" or "is custom field type X" then "results should be stripped like this" else "regular".
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.