Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Search Category and Album Titles  (Read 28378 times)

0 Members and 1 Guest are viewing this topic.

trippinsweet

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 27
Search Category and Album Titles
« on: April 03, 2006, 08:21:48 pm »

There's a plugin avaliable for searching album titles and descriptions and I found it to be very useful...except in the case of one of my galleries which showed comic book scans. All the categories had real names but the albums were named Volume 1, Volume 2, etc. so couldn't be easily searched.

I couldn't quickly figure out how coppermine stores database names and passwords so I had to hard encode the information into the file. You'll have to change it as necessary to make this hack work.

I'm also assuming everyone has coppermine installed under the default prefix "cpg140_"

Code: [Select]
<?php
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.3.0  miniCMS                                   //
// ------------------------------------------------------------------------- //
// Copyright (C) 2004 Tarique Sani <tarique@sanisoft.com>,                   //
// Amit Badkas <amit@sanisoft.com>                                           //  
// http://www.chezgreg.net/coppermine/                                       //
// ------------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify      //
// it under the terms of the GNU General Public License as published by      //
// the Free Software Foundation; either version 2 of the License, or         //
// (at your option) any later version.                                       //
// ------------------------------------------------------------------------- // 

// ------------------------------------------------------------------------- //
//   Search modification by Kum Sackey                         //
// ------------------------------------------------------------------------- // 



define('IN_COPPERMINE'true);
define('EDITPICS_PHP'true);
require(
'include/init.inc.php');

pageheader("Category Search");
printf("<center>");
starttable("100%""Category Search" 3);

?>




<?php
#class='tableborder'
  while (list($name$value) = each($HTTP_GET_VARS)) {
# echo "$name = $value<br>\n";

 if ($name == "query" $query $value;

 }
 
  while (list($name$value) = each($HTTP_GET_VARS)) {
echo "$name = $value<br>\n";
 }
 

?>


<?php
# Connection Info
$host "< your host >";
$dbName "< your db name >";
$MysqlName "< your msql name >";
$MysqlPW "< your pwd >";


#Connect to Host
$link mysql_connect($host,$MysqlName,$MysqlPW);

if (!
$link) {
   die(
'Could not connect: ' mysql_error());
}
#echo 'Connected successfully';

mysql_select_db("< your coppermine db>",$link);
$query $_GET['query'];

$query_pieces explode(" "$query);


$query "";
    
$c 0;
$cd 0;
while ($c count($query_pieces) )
{
if ($query_pieces[$c] != "")
{
if (strlen($query_pieces[$c]) < 3)
{
$query_discard[$cd] = $query_pieces[$c];
$cd $cd 1;
}
else
{
$query .= '%'.$query_pieces[$c]; 
}
}
$c $c 1;

}
$query .= '%';

// echo $query;
if ($query != '%' )
{
$result MySQL($dbName"SELECT * FROM `cpg140_categories` WHERE `name` LIKE '$query'");
$result2 MySQL($dbName"SELECT * FROM `cpg140_albums` WHERE `title` LIKE '$query'");
}
?>



<tr>
  <td class="tableb" > <div align="center">
      <table width="75%" cellspacing="2" cellpadding="2">
        <tr>
          <td> <p>This tool searches category and album titles for all the whitespace
              seperated words you input.</p>
            <p>For a search word to be valid, it must contain at least three characters.</p>
            <p>Enter search terms:</p>
            <form name="form1" method="get" action="<?php echo $PHP_SELF?>" >
              <p>
                <input type="text" name="query">
                <input type="submit" name="Submit" value="Submit">
              </p>
            </form></td>
        </tr>
      </table>
      <p>&nbsp;</p>
      <h2>Search Results</h2>

<?
if ($cd > 0)
{

echo 'The following search terms were discarded because they were too short: ';
    $c = 0;
while ($c < ($cd - 1) )
{
echo $query_discard[$c].',';
$c = $c + 1;
}
echo $query_discard[$c];
echo '<br>';
}
?>

  <?php if (MySQL_NUMROWS($result) + MySQL_NUMROWS($result2) == 0
   { echo "No results found"; } 
else
{
?>

      <table width="75%" border="1" cellpadding="2" cellspacing="2">
        <tr>
          <td colspan="2" class="tableh1">Categories</td>
        </tr>
        <?php
// Output Data into Table

while ($cat_list mysql_fetch_array($resultMYSQL_ASSOC))
{
?>

        <tr>
          <td> <a href="<?php printf("index.php?cat=%u"$cat_list['cid']); ?> ">
            <?php echo $cat_list['name']; ?> </a></td>
          <td>
            <?php if ($cat_list['description'] == "") { echo '&nbsp;'; }else { echo $cat_list['description']; } ?>
          </td>
        </tr>
        <?php
}
?>

        <tr>
          <td colspan="2" class="tableh1">Albums</td>
        </tr>
        <?php
// Output Data into Table

while ($alb_list mysql_fetch_array($result2MYSQL_ASSOC))
{
?>

        <tr>
          <td><a href="<?php printf("thumbnails.php?album=%u"$alb_list['aid']); ?> ">
            <?php echo $alb_list['title']; ?> </a></td>
          <td>
            <?php if ($alb_list['description'] == "") { echo '&nbsp;'; }else { echo $alb_list['description']; } ?>
          </td>
        </tr>
        <?php
}
?>

      </table>
          <?php
}
?>

    </div></td>
</tr>
<?php
printf
("</center>");
endtable();
?>
« Last Edit: April 03, 2006, 09:28:45 pm by GauGau »
Logged

flogghe

  • Coppermine novice
  • *
  • Offline Offline
  • Gender: Male
  • Posts: 44
    • MaritimeDigital Archive
Re: Search Category and Album Titles
« Reply #1 on: May 29, 2006, 09:21:31 pm »

Great tool! It worked immediately!

Thanks
Frederic
Logged
Kind regards,

Frederic Logghe
Webmaster MaritimeDigital Archive
http://www.ibiblio.org/maritime

line-web

  • Coppermine newbie
  • Offline Offline
  • Posts: 11
Re: Search Category and Album Titles
« Reply #2 on: July 18, 2006, 05:53:53 pm »

What is the filename?
and is it to search by album titles
Logged

trippinsweet

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 27
Re: Search Category and Album Titles
« Reply #3 on: July 19, 2006, 10:12:34 am »

Yes it seraches album titles (it says so in the title of this thread)

No it doesnt' search by filename because the traditional search page already takes care of that.

-----

I've been working on a better version of this mod. You can consider what I first published to be a quick job.
I plan to have it search descriptions for categories and albums, and also spell check the user input if you have the pspell libraries enabled.


////////////////////////////
// Changelog
////////////////////////////

--------------------------------
CPGSearch version 0.1
---------------------------------
Feature: Search Category names

--------------------------------
CPGSearch version 0.2
---------------------------------
Feature: Search Album titles

--------------------------------
CPGSearch version 0.3
---------------------------------
Feature: Search Descriptions 

--------------------------------
CPGSearch version 0.4
---------------------------------

Fix: Search only for whole words, not parts of words. Example: A search for 'king' will return albums like "King of Fighters" but not "Kingdom of Hearts"

Feature: Spell check words using pspell libraries.

For example:  A search for "kinsg' will return 0 items and suggest 'kings' as a word replacement.
Posted on: July 05, 2006, 10:26:21 AM
--------------------------------
CPGSearch version 0.5
---------------------------------

Feature: Created a custom dictionary that includes all the non-english words that are part of category names, and album titles.

Example. There is an album named Sophitia, for soul calibur. Then searches for "Sophitiaa" or "Sophitai" then it will suggest the word "Sophitia" which is the closet album name to what you entered.
Posted on: July 11, 2006, 04:59:51 PM
--------------------------------
CPGSearch version 0.6
---------------------------------

Feature: Uses a simple heurestic to determine the relevance of results and sorts the results by relevance. Most relevant results appear first.

Planned: Pagenation


Posted on: July 13, 2006, 04:35:48 PM
--------------------------------
CPGSearch version 0.65
---------------------------------

Feature exclude common words from search. Current list: 'the','and', 'that', 'but', 'him', 'her', 'our'
Logged

Abbas Ali

  • Administrator
  • Coppermine addict
  • *****
  • Country: in
  • Offline Offline
  • Gender: Male
  • Posts: 2165
  • Spread the PHP Web
    • Ranium Systems
Re: Search Category and Album Titles
« Reply #4 on: July 19, 2006, 10:51:20 am »

I modified your code slightly so that no hardcoded values are used. Users can use this code as it is...

Code: [Select]
<?php
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.3.0  miniCMS                                   //
// ------------------------------------------------------------------------- //
// Copyright (C) 2004 Tarique Sani <tarique@sanisoft.com>,                   //
// Amit Badkas <amit@sanisoft.com>                                           //
// http://www.chezgreg.net/coppermine/                                       //
// ------------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify      //
// it under the terms of the GNU General Public License as published by      //
// the Free Software Foundation; either version 2 of the License, or         //
// (at your option) any later version.                                       //
// ------------------------------------------------------------------------- //

// ------------------------------------------------------------------------- //
//   Search modification by Kum Sackey                         //
// ------------------------------------------------------------------------- //



define('IN_COPPERMINE'true);
define('EDITPICS_PHP'true);
require(
'include/init.inc.php');

pageheader("Category Search");
printf("<center>");
starttable("100%""Category Search" 3);

?>




<?php
#class='tableborder'
                          
while (list($name$value) = each($HTTP_GET_VARS)) {
                                
#               echo "$name = $value<br>\n";

                                 
if ($name == "query" $query $value;

                                 }

                                  while (list(
$name$value) = each($HTTP_GET_VARS)) {
                                        echo 
"$name = $value<br>\n";
                                                         }


?>


<?php

$query 
$_GET['query'];

$query_pieces explode(" "$query);


$query "";
    
$c 0;
        
$cd 0;
        while (
$c count($query_pieces) )
        {
                if (
$query_pieces[$c] != "")
                {
                        if (
strlen($query_pieces[$c]) < 3)
                        {
                                
$query_discard[$cd] = $query_pieces[$c];
                                
$cd $cd 1;
                        }
                        else
                        {
                        
$query .= '%'.$query_pieces[$c];
                        }
                }
                
$c $c 1;

        }
$query .= '%';

// echo $query;
if ($query != '%' )
{
        
$result cpg_db_query("SELECT * FROM `{$CONFIG['TABLE_CATEGORIES']}` WHERE `name` LIKE '$query'");
        
$result2 cpg_db_query("SELECT * FROM `{$CONFIG['TABLE_ALBUMS']}` WHERE `title` LIKE '$query'");
}
?>



<tr>
  <td class="tableb" > <div align="center">
      <table width="75%" cellspacing="2" cellpadding="2">
        <tr>
          <td> <p>This tool searches category and album titles for all the whitespace
              seperated words you input.</p>
            <p>For a search word to be valid, it must contain at least three characters.</p>
            <p>Enter search terms:</p>
            <form name="form1" method="get" action="<?php echo $PHP_SELF?>" >
              <p>
                <input type="text" name="query">
                <input type="submit" name="Submit" value="Submit">
              </p>
            </form></td>
        </tr>
      </table>
      <p>&nbsp;</p>
      <h2>Search Results</h2>

        <?
        if ($cd > 0)
        {

        echo 'The following search terms were discarded because they were too short: ';
    $c = 0;
        while ($c < ($cd - 1) )
        {
                echo $query_discard[$c].',';
                $c = $c + 1;
        }
                echo $query_discard[$c];
        echo '<br>';
        }
        ?>

          <?php if (mysql_num_rows($result) + mysql_num_rows($result2) == 0)
                                { echo 
"No results found"; }
                else
                {
        
?>

      <table width="75%" border="1" cellpadding="2" cellspacing="2">
        <tr>
          <td colspan="2" class="tableh1">Categories</td>
        </tr>
        <?php
        
// Output Data into Table

        
while ($cat_list mysql_fetch_array($resultMYSQL_ASSOC))
        {
?>

        <tr>
          <td> <a href="<?php printf("index.php?cat=%u"$cat_list['cid']); ?> ">
            <?php echo $cat_list['name']; ?> </a></td>
          <td>
            <?php if ($cat_list['description'] == "") { echo '&nbsp;'; }else { echo $cat_list['description']; } ?>
          </td>
        </tr>
        <?php
        
}
?>

        <tr>
          <td colspan="2" class="tableh1">Albums</td>
        </tr>
        <?php
        
// Output Data into Table

        
while ($alb_list mysql_fetch_array($result2MYSQL_ASSOC))
        {
?>

        <tr>
          <td><a href="<?php printf("thumbnails.php?album=%u"$alb_list['aid']); ?> ">
            <?php echo $alb_list['title']; ?> </a></td>
          <td>
            <?php if ($alb_list['description'] == "") { echo '&nbsp;'; }else { echo $alb_list['description']; } ?>
          </td>
        </tr>
        <?php
        
}
?>

      </table>
                  <?php
        
}
?>

    </div></td>
</tr>
<?php
printf
("</center>");
endtable();
?>

Logged
Chief Geek at Ranium Systems

ianc

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 21
Re: Search Category and Album Titles
« Reply #5 on: August 16, 2006, 11:23:05 pm »

I'd really like to use this mod/plug-in. Tell me, is it loaded as a separate file (and if so what is it to be named) or is the coding added to an existing file ?? (if so, what ?).

Sorry if I sound dumb, I'm still trying to find my way around the programme. Thanks.
Logged

Abbas Ali

  • Administrator
  • Coppermine addict
  • *****
  • Country: in
  • Offline Offline
  • Gender: Male
  • Posts: 2165
  • Spread the PHP Web
    • Ranium Systems
Re: Search Category and Album Titles
« Reply #6 on: August 17, 2006, 08:01:44 am »

Yes, create a new file with the above code. Name it to whatever you like.
Logged
Chief Geek at Ranium Systems

ianc

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 21
Re: Search Category and Album Titles
« Reply #7 on: August 17, 2006, 06:45:09 pm »

Sorted - sometimes you can't see the wood for the trees...  I was thinking it needed to be added to a config file or something.  Created a file - linked to it - works great, just what I needed, thanks..
Logged

wfs

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 95
Re: Search Category and Album Titles
« Reply #8 on: August 24, 2006, 09:40:02 am »

thank you Abbas.
it worked wonderfully !
thank you so much  8)
Logged

tinorebel

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 87
  • live long and prosper!
    • www.tripodart.net
Re: Search Category and Album Titles
« Reply #9 on: October 11, 2006, 02:21:24 pm »

 :D
Hy i just descovered this mod or plug-in.
Looks intresting but, got a problem.
Sorry for being dumb, but I created a php page with the code and named it srchalbcat.php
uploaded it and opend it with safari and gives me error

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /mounted-storage/home27b/sub001/sc204/www/website/gal/srchalbcat.php on line 17

obviously a stupid error but, I cant find out how to fix it...
someone can help?

THANKS
Logged
Live long and prosper!
www.tripodart.net

Nibbler

  • Guest
Re: Search Category and Album Titles
« Reply #10 on: October 11, 2006, 03:11:16 pm »

You probably made an error copying, the code itself is fine.
Logged

line-web

  • Coppermine newbie
  • Offline Offline
  • Posts: 11
Re: Search Category and Album Titles
« Reply #11 on: December 11, 2006, 02:18:33 am »

and how is it possible to use it like a mark in search for cpg 1.4.x

i want to see the fuonding albums like pichtures.
Logged

tinorebel

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Gender: Male
  • Posts: 87
  • live long and prosper!
    • www.tripodart.net
Re: Search Category and Album Titles
« Reply #12 on: December 18, 2006, 01:22:13 pm »

Hi everyone! 8)
I'm actually facing a problem that might bee usefull to solve for other people:
I have a site for selling photos, I take pictures of people, giving them a card on wich i write the name of the album and the password to access to that album (for privacy).

Now, this wonderfull plug in seemed to be perfect for me, since I malke many albums and would like my costumers to find their album as quickly an easly as possible. <<<<BUT>>>>  there is a problem: since my albums are password-protected, the search will not give me back the album I need unless I have already put the password.

 ???Do you think there is a way to solve this problem?  ???
If yes, please give me a clue on how to do it. I'm not good at all in scripting, but I can try to follow suggestions.

Any idea will be very apriciated. ::) Thanks to everyone who contributes to this great gallery and this excelent forum.
 ;)
Logged
Live long and prosper!
www.tripodart.net

jesskajess

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 30
Re: Search Category and Album Titles
« Reply #13 on: April 18, 2007, 06:19:26 pm »

I really want to use this mod too but like ' ianc ' question, I dont understand:

Sorted - sometimes you can't see the wood for the trees...  I was thinking it needed to be added to a config file or something.  Created a file - linked to it - works great, just what I needed, thanks..

- how did you 'link it'

Thank You :)

Logged
Pages: [1]   Go Up
 

Page created in 0.035 seconds with 19 queries.