forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 themes (visuals) => Topic started by: allvip on June 09, 2014, 09:09:57 am

Title: Sort by keywords
Post by: allvip 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
Title: Re: Sort by keywords
Post by: Αndré 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 (http://forum.coppermine-gallery.net/index.php/topic,63706.0.html) 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.
Title: Re: Sort by keywords
Post by: allvip on June 19, 2014, 01:47:07 pm
I did try to edit the plugin but I am no good at that.
Title: Re: Sort by keywords
Post by: Αndré on June 19, 2014, 03:04:48 pm
Then I suggest to use the rewrite rule.
Title: Re: Sort by keywords
Post by: allvip 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.
Title: Re: Sort by keywords
Post by: Αndré 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).
Title: Re: Sort by keywords
Post by: allvip on June 24, 2014, 02:30:42 pm
OK.Test it on my localhost.It works.Thanks 1000 times.
Title: Re: Sort by keywords
Post by: Αndré 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
Title: Re: Sort by keywords
Post by: allvip 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).