Sort by keywords Sort by keywords
 

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]

Main Menu

Sort by keywords

Started by allvip, June 09, 2014, 09:09:57 AM

Previous topic - Next topic

0 Members and 4 Guests are viewing this topic.

allvip

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

Αndré

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.

allvip

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

Αndré

Then I suggest to use the rewrite rule.

allvip

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.

Αndré

Inside the function mma_get_pic_pos, find
default:
and above, add
        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
default:
and above, add
        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).

allvip


Αndré


allvip

Great.I wanted to do the same thing (just a link to this thread as the plugin thread is not my thread).