4images Forum & Community
4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: tgiokdi on July 13, 2006, 04:08:08 AM
-
site in question:
www.secretfilesandorigins.com (http://www.secretfilesandorigins.com)
I'd like to be able to search just the category names, and have the results page have links to the categories that fit the description. The focus of the site is going to be comic book covers, with the category being the series name, and the differnet issues just named whatever number issue it's for.
ie:
Category: DC
Subcategory: Action Comics
When you search for "action comics" right now, nothing comes up. I've searched the boards and come up null :(
-
it's been a couple days, and no replies. Has no one seriously figured out how to search the category names? Is there a lmitation that I'm not aware of? This is something that is desperately needed in a picture gallery, and I'm shocked, SHOCKED, that a category search isn't included.
Let me remind you. I am SHOCKED :lol:
-
Anyone have any suggestions for an image gallery that will support category searches? I'm flabbergasted that 4images doesn't support this very basic feature
-
Here's a simple solution. I'm sure it can be optimized. It will find all instances of a keyword or keywords in a category tree.
Important notes:
- The code below doesn't even think about OR, AND, or NOT queries
- It will match ANY of the keywords entered
Examples:
- "athens museum (http://gallery.jazzhaven.com/search.htm?search_keywords=athens%20museum)"
- "corinth (http://gallery.jazzhaven.com/search.htm?search_keywords=corinth)"
In search.php, find:
//-----------------------------------------------------
//--- Show Search Results -----------------------------
//-----------------------------------------------------
add after:
// MOD: Search category names for keywords (http://www.4homepages.de/forum/index.php?topic=13675#msg75934)
if (isset($split_words)){
$split_words1 = preg_replace("/^\*/", '', $split_words);
$cat_search_keywords = stripslashes(htmlspecialchars(trim(join("|", $split_words1)))); // clean up user input
$search_cat_result = array(); // initialize array
$resultcat = $site_db->query("SELECT cat_id FROM ".CATEGORIES_TABLE.""); // grab all cats
while ($row = $site_db->fetch_array($resultcat)) { // loop through cats
if ( preg_match( "/($cat_search_keywords)/i", get_category_path_nohtml( $row['cat_id'])) & // find match(es) in cat tree
check_permission("auth_viewcat", $row['cat_id']) ){ // check permission
$search_cat_result[] = get_category_path( $row['cat_id'],1); // add match to array
}
}
$site_db->free_result();
}
$site_template->register_vars( 'cat_wordsearch', (empty($search_cat_result) ? "" : join("\n\n<li>", $search_cat_result)) ); // add result to template
// END MOD: Search category names for keywords
Add in search.html:
{if cat_wordsearch}
<h4>category title results:</h4>
<div style="font-size: 90%;height: 100px; border: 1px dashed #47697e; overflow: auto; background-color: #D7DED1">
<p class="text">One or more of your search criteria resulted in a match the following category names.</p>
<ul>{cat_wordsearch}</ul>
</div>
{endif cat_wordsearch}
Corrections and enhancements are welcome. :)
Note: The get_category_path_nohtml subroutine is found in the [MOD] Dynamic Page Title for v1.7 & v1.7.1 (http://www.4homepages.de/forum/index.php?topic=6613.0) topic.
Update 2006/08/16: Added auth_viewcat and updated add match to array line per V@no's suggestion below.
Update 2006/08/20: Mod now checks to ensure that a query was entered before executing.
Update 2006/08/20: Included V@no's modification to register cat_wordsearch when no search keywords present.
-
Hi All,
Anyone know where i can get the get_category_path_nohtml function?
i've tried to implement this mod but get an error when the line that calls this function?
Kind Regards,
WeZ
-
Sorry about that. My gallery uses so many mods, that I forget which subroutines are standard and which are mods.
The get_category_path_nohtml subroutine is found in the [MOD] Dynamic Page Title for v1.7 & v1.7.1 (http://www.4homepages.de/forum/index.php?topic=6613.0) topic.
-
Hi Jasmine,
Thank-You for the update... all went well this time...
One last little problem though which i even see on your gallery site...
if you search for athe* then you get the results for athens, however if you search for *thens, then it crashes horribly :?
think you can update the subroutine to cater for the leading * or am i asking for too much :wink:
Kind Regards,
WeZ
-
I've updated the first two lines of code. Hope this helps. Anyone else care to refine the code?
-
1) your code does not obey categories permissions, thereforе visitors will be able see the names and ids of categories they have no access to.
2) array_push( $search_cat_result, get_category_path( $row['cat_id'],1)); // add match to array
is a slower equalent of$search_cat_result[] = get_category_path( $row['cat_id'],1); // add match to array
-
I've installed alot of mods, but this mod adds more Value add than most of the others because when you get images off the net, most of them have been renamed by the gallery application they were hosted under and most of the times, with no usable description in the file name. this way as long as you've saved them into a folder with a good description, youre sorted.
It is for this reason i would like to see this as prhaps a built in optional extra in future releases of 4Images.
but, thats just my .02c worth ;-)
V@no, That is quite a sneaky point you make. I also notice that if you click on the advanced search link, it lists all categories there as well - even if you are not logged in.
what can be done about it - Jasmine Maybe?
-
V@no, thank you for pointing that out. I've updated the original post. Please let me know what you think.
I'd also like to see it honor AND OR NOT queries, but php is not my first language, and that's about the best I can do for now :)
-
Hi Jasmine,
Your code does now indeed look like it obeys security. one small bug though - if the user clicks the "advanced search" button "with no text actaully in the text box - you get a warning at the top of your page "Warning: join() [function.join]: Bad arguments" on this line:
[qcode]
$cat_search_keywords = stripslashes(htmlspecialchars(trim(join("|", $split_words1)))); // clean up user input
[/qcode]
i beleive it was because there was no user input :-) ... anyway, it's minor but seeing as it affects your site as well you will probably want to fix it ;-)
V@no, I Have a question for you... Attached, you can see my default search form. when the user selects "advanced search" how do i get it so that it only displays the default 4images form? i only want the "Category Title Results" and "Image Category Results" when there actually is a resultset.
Anyway, keep well both of you...
Kind Regards,
WeZ
-
Above code updated to ascertain if keywords were entered before executing.
WeZ: Did you wrap your template output tags with if ... endif conditionals?
-
in order for {if cat_wordsearch} {endif cat_wordsearch} condition to work, the {cat_wordsearch} must be registered every time.
Right now, it only registered when you enter some keywords.
So $site_template->register_vars( 'cat_wordsearch', join("\n\n<li>", $search_cat_result) ); // add result to template
}
// END MOD: Search category names for keywords
Can be replaced by: }
$site_template->register_vars( 'cat_wordsearch', (empty($search_cat_result) ? "" : join("\n\n<li>", $search_cat_result)) ); // add result to template
// END MOD: Search category names for keywords
-
Original post modified with your recommendation. Thank you!
-
Hi V@no & Jasmine,
i trust you guys are well... Sorry i did not get back to you but i was caught up with work :-(
Anyway, Jasmine;
WeZ: Did you wrap your template output tags with if ... endif conditionals?
From my limited knowledge, i think i did... here is my code for your review:
{if content}
<table width="450" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="head1">{content}</td>
</tr>
{if cat_wordsearch}
<h4>category title results:</h4>
<div style="font-size: 90%;height: 100px; border: 1px dashed #47697e; overflow: auto; background-color: #D7DED1">
<p class="text">One or more of your search criteria resulted in a match the following category names.</p>
<ul>{cat_wordsearch}</ul>
</div>
{endif cat_wordsearch}
{if catlist}
<!-- Start Result category list-->
<h4>Image Category Results:</h4>
<div style="height: 100px; border: 1px dashed #47697e; overflow: auto;">
<p class="text">Category list of images found on this page.</p>
<ul>{catlist}</ul>
</div>
<h4>Pictures within these Categories:</h4>
<!-- End Result category list-->
{endif catlist}
<br />
</table>
{endif content}
And one last thing, If i use your block updated of code i get an error on the line
$site_template->register_vars( 'cat_wordsearch', (empty($search_cat_result) ? "" join("\n\n<li>", $search_cat_result)) ); // add result to template
but if i use V@no's
$site_template->register_vars( 'cat_wordsearch', join("\n\n<li>", $search_cat_result) ); // add result to template
it looks fine when you search something. if you click on 'advanced search' it still gives "Warning: join() [function.join]: Bad arguments." error on the line mentioned above.
Thank-You for all your help so far guys.
Kind Regards,
WeZ
-
ops, my bad, I missed : just before word "join"...I've updated my reply on previous page.
P.S. next time if you see any error messages, please quote them, they can help determin where exactly is the misstake ;)
-
Hi V@no,
Thanks, your line works now :-)
Jasmine, I Still need help with my search.html please :roll:
V@no, Can you see if i am correct in my testing of the searech algorithym? i search for *vide* i get a folder "video" which is correct. But if i search for *vid* i will also get a folder "victoria". But if i test it with *vid, i do not get the "victoria" folder. i have tested it with other words and my results are that the search seems to be omitting the last character before the trailing * when one is used. I.E. a search for *vid* is actaully returning results that *vi* would return.
Where can i echo the sql statement executed to verify weather my results are true or not?
Kind Regards,
Wesley.
-
Jasmine
}
$site_template->register_vars( 'cat_wordsearch', (empty($search_cat_result) ? "" join("\n\n<li>", $search_cat_result)) ); // add result to template
// END MOD: Search category names for keywords
Replace
}
$site_template->register_vars( 'cat_wordsearch', (empty($search_cat_result) ? "" : join("\n\n<li>", $search_cat_result)) ); // add result to template
// END MOD: Search category names for keywords
The sign was lost : :)
-
V@no, Can you see if i am correct in my testing of the searech algorithym? i search for *vide* i get a folder "video" which is correct. But if i search for *vid* i will also get a folder "victoria". But if i test it with *vid, i do not get the "victoria" folder. i have tested it with other words and my results are that the search seems to be omitting the last character before the trailing * when one is used. I.E. a search for *vid* is actaully returning results that *vi* would return.
Hi V@no,
Please can you help me with this? the resultset is definately omitting the last characted behind the trailing *
Kind Regards,
WZ
-
Hi, this mod supports 4images 1.7.4? i have added the code for search.php after
//-----------------------------------------------------
//--- Show Search Results -----------------------------
//-----------------------------------------------------
but I just got a blank page, some idea?
My code is (i just have added your code):
-
any help???
I'm using now 1. 7. 7
-
replace
$site_template->register_vars( 'cat_wordsearch', (empty($search_cat_result) ? "" join("\n\n<li>", $search_cat_result)) ); // add result to template
with:
$site_template->register_vars( 'cat_wordsearch', (empty($search_cat_result) ? "" : join("\n\n<li>", $search_cat_result)) ); // add result to template
P.S. next time please format your post with bbcodes and if you are planning on showing code from the entire file, consider attach it to your post as an attachment (this time I did it for you), this way it won't clog up the database with unnecessary data.
-
any help???
I'm using now 1. 7. 7
I am useing v. 1.7.7 also, and it works.
Thank you all.
-
Hello,
i've just use this in my 1.7.9, but dosn't work :cry: even i used fresh copy of search.php, i'll get no results in the frame.
Did anyone use this on 1.7.9?
Thanks,
Henry
EDIT:
Now I'm using this MOD http://www.4homepages.de/forum/index.php?topic=28587
Regadrs,
Henry