4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: tgiokdi on July 13, 2006, 04:08:08 AM

Title: Search Category Names, Not File Names
Post 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 :(
Title: Re: Search Category Names, Not File Names
Post by: tgiokdi on July 15, 2006, 09:23:03 PM
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:
Title: Re: Search Category Names, Not File Names
Post by: tgiokdi on August 09, 2006, 05:59:06 AM
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
Title: Re: Search Category Names, Not File Names
Post by: Jasmine on August 12, 2006, 08:22:08 PM
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:

Examples:

In search.php, find:
Code: [Select]
//-----------------------------------------------------
//--- Show Search Results -----------------------------
//-----------------------------------------------------

add after:
Code: [Select]
// 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:
Code: [Select]
{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.
Title: Re: Search Category Names, Not File Names
Post by: WeZ on August 16, 2006, 11:16:19 PM
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
Title: Re: Search Category Names, Not File Names
Post by: Jasmine on August 17, 2006, 08:03:29 PM
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.
Title: Re: Search Category Names, Not File Names
Post by: WeZ on August 18, 2006, 07:41:12 PM
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
Title: Re: Search Category Names, Not File Names
Post by: Jasmine on August 19, 2006, 01:09:15 AM
I've updated the first two lines of code.  Hope this helps.  Anyone else care to refine the code?
Title: Re: Search Category Names, Not File Names
Post by: V@no on August 19, 2006, 06:55:49 AM
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)
Code: [Select]
array_push( $search_cat_result, get_category_path( $row['cat_id'],1));                   // add match to arrayis a slower equalent of
Code: [Select]
$search_cat_result[] = get_category_path( $row['cat_id'],1);                   // add match to array
Title: Re: Search Category Names, Not File Names
Post by: WeZ on August 19, 2006, 11:28:30 AM
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?
Title: Re: Search Category Names, Not File Names
Post by: Jasmine on August 19, 2006, 08:03:27 PM
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 :) 
Title: Re: Search Category Names, Not File Names
Post by: WeZ on August 19, 2006, 09:33:15 PM
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
Title: Re: Search Category Names, Not File Names
Post by: Jasmine on August 20, 2006, 08:48:56 PM
Above code updated to ascertain if keywords were entered before executing. 

WeZ: Did you wrap your template output tags with if ... endif conditionals?
Title: Re: Search Category Names, Not File Names
Post by: V@no on August 20, 2006, 09:40:39 PM
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
Code: [Select]
      $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:
Code: [Select]
   }
$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
Title: Re: Search Category Names, Not File Names
Post by: Jasmine on August 20, 2006, 10:46:52 PM
Original post modified with your recommendation.  Thank you!
Title: Re: Search Category Names, Not File Names
Post by: WeZ on August 22, 2006, 06:53:02 PM
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;
Quote
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:
Code: [Select]
  {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
Code: [Select]
$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
Code: [Select]
$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
Title: Re: Search Category Names, Not File Names
Post by: V@no on August 23, 2006, 06:00:09 AM
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 ;)
Title: Re: Search Category Names, Not File Names
Post by: WeZ on August 23, 2006, 12:56:04 PM
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.

Title: Re: Search Category Names, Not File Names
Post by: SAD on October 03, 2006, 11:33:39 PM
Jasmine

Code: [Select]
   }
  $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

Code: [Select]
   }
$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  : :)
Title: Re: Search Category Names, Not File Names
Post by: WeZ on October 25, 2006, 09:24:29 AM
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
Title: Re: Search Category Names, Not File Names
Post by: artmedia on July 17, 2008, 03:17:09 AM
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):
Title: Re: Search Category Names, Not File Names
Post by: stormdesign on September 16, 2009, 01:42:42 AM
any help???

I'm using now 1. 7. 7
Title: Re: Search Category Names, Not File Names
Post by: V@no on September 16, 2009, 03:16:33 AM
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.
Title: Re: Search Category Names, Not File Names
Post by: Hagen-Roderich on October 06, 2009, 09:37:18 AM
any help???

I'm using now 1. 7. 7

I am useing v. 1.7.7 also, and it works.
Thank you all.
Title: Re: Search Category Names, Not File Names
Post by: henary on December 01, 2010, 03:05:00 PM
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