CpmFetch: view...MediaByKeyword CpmFetch: view...MediaByKeyword
 

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

CpmFetch: view...MediaByKeyword

Started by cornetchap, August 31, 2005, 01:43:52 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cornetchap

Hi all.

I've been using the CpmFetch software for a while now on a couple of websites I run and I thought I'd share some mods I've made that you may be interested in, namely:


  • cpmViewRandomImagesByKeyword
  • cpmViewLastAddedImagesByKeyword

and their corresponding DAO functions.

Ideally I was going to do these functions by keywords (note the 's') but couldn't be faffed figuring out how to do this sensibly in SQL.

Note that these are modifications to an old version of CpmFetch so may not be compatible with the latest version.

Changes to coppermine.php are:

  /**
  * Displays random images based on keyword
  *
  * This will generate a table and populate it with the random media and style
  * it based on the entries in the style hash. The number of photos returned
  * matches the number of rows multiplied by the number of columns.
  *
  * @param int $rows The number of rows desired in the output
  * @param int $columns The number of columns desired in the output
  * @param array $keywords An array of keyword strings to match
  * @param array $options Optional, configuration options
  *
  */
  function cpm_viewLastAddedMediaByKeyword($keyword, $rows, $columns, $options="") {
    if (is_array($options) && version_compare(phpversion(),'4.2.0')) {
      $options = array_change_key_case($options, CASE_LOWER);
    }

    $resultset = $this->cpm->getLastAddedImageByKeyword($keyword,
                                                        $rows * $columns);
    print $this->createTable($resultset, $rows, $columns, $options);
  }

  /**
  * Displays random images based on keyword
  *
  * This will generate a table and populate it with the random media and style
  * it based on the entries in the style hash. The number of photos returned
  * matches the number of rows multiplied by the number of columns.
  *
  * @param int $rows The number of rows desired in the output
  * @param int $columns The number of columns desired in the output
  * @param array $keywords An array of keyword strings to match
  * @param array $options Optional, configuration options
  *
  */
  function cpm_viewRandomMediaByKeyword($keyword, $rows, $columns, $options="") {
    if (is_array($options) && version_compare(phpversion(),'4.2.0')) {
      $options = array_change_key_case($options, CASE_LOWER);
    }

    $resultset = $this->cpm->getRandomImageByKeyword($keyword,
                                                     $rows * $columns);
    print $this->createTable($resultset, $rows, $columns, $options);
  }


Changes to coppermine_dao.php are:


  var $sqlPictureSelect = ' p.filepath, p.filename, p.aid, p.filesize, p.title, p.caption, p.owner_name, p.ctime, p.hits, p.pid ';

  // Returns last added image based on a keyword search
  function getLastAddedImageByKeyword($keyword = "", $count) {
    $retval = "";

    if (is_numeric($count) && !empty($keyword)) {
      $sqlcode = "SELECT " . $this->sqlPictureSelect . " FROM " . $this->cpm_table_prefix . "pictures as p where locate('" . $keyword . "', p.keywords) <> 0 and p.approved='YES' order by p.ctime desc limit 0,$count";
      $retval = $this->dbExecuteSql($sqlcode);
    }

    return($retval);
  }

  // Returns a random image based on a keyword search
  function getRandomImageByKeyword($keyword = "", $count) {
    $retval = "";

    if (is_numeric($count) && !empty($keyword)) {
      $sqlcode = "SELECT " . $this->sqlPictureSelect . " FROM " . $this->cpm_table_prefix . "pictures as p where locate('" . $keyword . "', p.keywords) <> 0 and p.approved='YES' order by rand() limit $count";
      $retval = $this->dbExecuteSql($sqlcode);
    }

    return($retval);
  }

vuud

Quote from: cornetchap on August 31, 2005, 01:43:52 PM
Hi all.

I've been using the CpmFetch software for a while now on a couple of websites I run and I thought I'd share some mods I've made that you may be interested in, namely:


  • cpmViewRandomImagesByKeyword
  • cpmViewLastAddedImagesByKeyword

and their corresponding DAO functions.



Hah, looks like I made it to the big time when people are modding my stuff :)

Just a matter of time before the woman, money and wine starts rolling in...


Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

Anke

This is exactly what I was looking for... Unfortunately I can't get it to work in cpmfetch 1.6.2
Has anyone done that already? Or can tell me in which version it works?

vuud

Quote from: Anke on December 27, 2005, 03:59:09 PM
This is exactly what I was looking for... Unfortunately I can't get it to work in cpmfetch 1.6.2
Has anyone done that already? Or can tell me in which version it works?

Yeah, some of the code changed.  This is slated to be included in one of the future releases of cpmfetch (with the authors blessing).  Sometime in the 1.7 development chain (which has started).

Will be announced on the mailing list at http://cpmfetch.fistfullofcode.com and in the main forum.



Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

Anke


vuud

Quote from: Anke on December 28, 2005, 12:52:21 PM
Thanks for the info :)

This type of functionality has been included in CpmFetch 1.9.11 and greater.  It allows for searching the keywords, captions and / or descriptions for keywords.

See http://cpmfetch.fistfullofcode.com


Please post for help to the forum... PM me only if you are sending security related items (passwords, security problems, etc).

cpmFetch - Images, RSS feeds from CPG from outside CPG
New release notification signup also. 
See http://cpmfetch.fistfullofco

hdelange

i have downloaded the latest version 2.0.0 and i will use the option media selected by keywords and that works great.

$objCpm->cpm_viewRandomMediaFrom("cat=2:album=526:keyword=anab",4, 5, $options);

now my question i also want to make a selection of the text that stays in the descrition, is that possible?

ik tried it to change keyword to description, but this does not work.

$objCpm->cpm_viewRandomMediaFrom("cat=2:album=526:description=anab",4, 5, $options);


is this one option?

greatz,

Henk