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: Sort by keywords  (Read 3858 times)

0 Members and 1 Guest are viewing this topic.

allvip

  • Global Moderator
  • Coppermine addict
  • *****
  • Country: 00
  • Offline Offline
  • Posts: 1290
Sort by keywords
« on: June 09, 2014, 09:09:57 am »

Is there a way to make coppermine sort images by keywords the same way is sorting images by most viewed and top rated?

I want to add a custom menu with: Nature, Animals, Cars etc and one users click on Cars coppermine to show all images that has cars in the keywords from all the albums and categories including User galleries.

I know I can make Cars to link to http://allvip.us/gallery/thumbnails.php?album=search&keywords=on&search=cars but that looks ugly.I want the link to be sort.Something like http://allvip.us/gallery/thumbnails.php?album=cars
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: Sort by keywords
« Reply #1 on: June 19, 2014, 10:41:07 am »

You'd need to create an Apache rewrite rule or a custom meta album if you don't like the search URL in the address bar. Regarding the meta album, I suggest to extend the More meta albums plugin to avoid core code modification. That plugin already has a lot of custom meta albums, so you can get an idea how it works and use one of them as base for your custom meta albums.
Logged

allvip

  • Global Moderator
  • Coppermine addict
  • *****
  • Country: 00
  • Offline Offline
  • Posts: 1290
Re: Sort by keywords
« Reply #2 on: June 19, 2014, 01:47:07 pm »

I did try to edit the plugin but I am no good at that.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: Sort by keywords
« Reply #3 on: June 19, 2014, 03:04:48 pm »

Then I suggest to use the rewrite rule.
Logged

allvip

  • Global Moderator
  • Coppermine addict
  • *****
  • Country: 00
  • Offline Offline
  • Posts: 1290
Re: Sort by keywords
« Reply #4 on: June 24, 2014, 01:32:30 pm »

I wood like to use the plugin.
Hope you can give me the code to add a new meta album: Cars, that will show all the images with keywords cars.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: Sort by keywords
« Reply #5 on: June 24, 2014, 02:16:59 pm »

Inside the function mma_get_pic_pos, find
Code: [Select]
default:and above, add
Code: [Select]
        case 'cars':
        case 'nature':
        case 'animal':
            $query = "SELECT COUNT(*) FROM {$CONFIG['TABLE_PICTURES']} AS p
                INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
                $RESTRICTEDWHERE
                AND approved = 'YES'
                AND CONCAT('{$CONFIG['keyword_separator']}', `keywords`, '{$CONFIG['keyword_separator']}') LIKE '%{$CONFIG['keyword_separator']}$album{$CONFIG['keyword_separator']}%'
                AND pid < $pid";

            $result = cpg_db_query($query);

            list($pos) = mysql_fetch_row($result);
            mysql_free_result($result);
            return strval($pos);
            break;


Inside the function mma_meta_album, find
Code: [Select]
default:and above, add
Code: [Select]
        case 'cars':
        case 'nature':
        case 'animal':
            $album_name = $meta['album'];
            if ($CURRENT_CAT_NAME) {
                $album_name .= " - $CURRENT_CAT_NAME";
            }

            $query = "SELECT pid FROM {$CONFIG['TABLE_PICTURES']} AS p
                INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
                $RESTRICTEDWHERE
                AND approved = 'YES'
                AND CONCAT('{$CONFIG['keyword_separator']}', `keywords`, '{$CONFIG['keyword_separator']}') LIKE '%{$CONFIG['keyword_separator']}{$meta['album']}{$CONFIG['keyword_separator']}%'";
            $result = cpg_db_query($query);
            $count = mysql_num_rows($result);
            mysql_free_result($result);
            if (!$count) {
                $rowset = array();
                break;
            }

            $query = "SELECT p.* FROM {$CONFIG['TABLE_PICTURES']} AS p
                INNER JOIN {$CONFIG['TABLE_ALBUMS']} AS r ON r.aid = p.aid
                $RESTRICTEDWHERE
                AND approved = 'YES'
                AND CONCAT('{$CONFIG['keyword_separator']}', `keywords`, '{$CONFIG['keyword_separator']}') LIKE '%{$CONFIG['keyword_separator']}{$meta['album']}{$CONFIG['keyword_separator']}%'
                ORDER BY pid ASC
                {$meta['limit']}";
            $result = cpg_db_query($query);
            $rowset = cpg_db_fetch_rowset($result);
            mysql_free_result($result);

            build_caption($rowset);
            break;

(not tested, but should work).
Logged

allvip

  • Global Moderator
  • Coppermine addict
  • *****
  • Country: 00
  • Offline Offline
  • Posts: 1290
Re: Sort by keywords
« Reply #6 on: June 24, 2014, 02:30:42 pm »

OK.Test it on my localhost.It works.Thanks 1000 times.
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15757
Re: Sort by keywords
« Reply #7 on: June 24, 2014, 02:34:42 pm »

For your information, I added that solution to the plugin announcement thread: http://forum.coppermine-gallery.net/index.php/topic,63706.msg375149/topicseen.html#msg375149
Logged

allvip

  • Global Moderator
  • Coppermine addict
  • *****
  • Country: 00
  • Offline Offline
  • Posts: 1290
Re: Sort by keywords
« Reply #8 on: June 24, 2014, 02:46:02 pm »

Great.I wanted to do the same thing (just a link to this thread as the plugin thread is not my thread).
Logged
Pages: [1]   Go Up
 

Page created in 0.017 seconds with 22 queries.