Support » Plugins » Semi-Coppermine integration

  • Resolved bitziz

    I’ve just started using WP so if I don’t code per the WP hack style, please correct me and I will change my stuff. I’m not 100% sure on how to use the myhacks.php file yet so I just did a direct index.php edit. Someone with more experience, please point out the mistakes so I can change accordingly.
    The following code should be added to the menu section and will display a random image and its title from the coppermine gallery. It will also link the image to the album the image is in. You can see it working here:
    Here’s the code :
    <li id=”categories”>Photolog Image:

      function mysql_fetch_array_r($result, $index_row = “”, $fetch = MYSQL_ASSOC){
      $i = 0;
      while ($row = mysql_fetch_array($result,$fetch)){
      $whole_result[$i] = $row;
      return $whole_result;
      $server = “localhost”; //your coppermine db host
      $db = “”; // your coppermine db name
      $user = “”; // your coppermine db user
      $pass = “”; // your coppermine db pass
      $pictures_db = “cpg11d_pictures”; // your coppermine pictures db, typically cpg11d_pictures. look it up in phpmyadmin if you aren’t sure.
      $link = mysql_connect ($server, $user, $pass);
      if (!link) {
      echo “Unable to connect to database”;
      $db_selected = mysql_select_db($db, $link);
      if (!$db_selected) {
      echo “Unable to select image db ” . mysql_error();
      $query = “SELECT MAX(pid) from ” . $pictures_db;
      $query_result = mysql_query($query, $link);
      $img_id = mysql_fetch_array($query_result);
      $pid = rand(1, $img_id[‘MAX(pid)’]);
      $final_query = “SELECT filepath, filename, title from ” . $pictures_db . ” where pid=” . $pid;
      $final_result = mysql_query($final_query, $link);
      $final_array = mysql_fetch_array_r($final_result);
      $img_path = “/photos/albums/” . $final_array[0][‘filepath’] . “thumb_” . $final_array[0][‘filename’];
      $link_query = “SELECT aid from ” . $pictures_db . ” where pid=” . $pid;
      $link_temp_result = mysql_query($link_query, $link);
      $link_temp_array = mysql_fetch_array($link_temp_result);
      $aid = $link_temp_array[0][‘aid’];
      $link_query = “SELECT MIN(pid) from ” . $pictures_db . ” where aid=” . $aid;
      $link_temp_result = mysql_query($link_query, $link);
      $link_temp_array = mysql_fetch_array($link_temp_result);
      $min_pid = $link_temp_array[0];
      $pos = $pid – $min_pid;
      echo ‘‘ . ‘<div align=”center”> <img src=”‘ . $img_path . ‘” border=”0″><br>’;
      echo $final_array[0][‘title’] . “</div>”;

    Any comments and suggestions are welcome.

Viewing 4 replies - 1 through 4 (of 4 total)
  • well done !
    If you want to go deeper in the integration…have a look at my site….

    Nicely done about displaying the pics in the post. Although you might want to make the link open in a new window. Another thing is, How did you figure out which position the pics are in? I tried but found my way doesn’t work if you upload all the pics and then deletes one after, the counting gets all messed up.

    I simply analysed the Coppermine code…. In fact, I ripped and adapted the main Picture management function and moved it into a WP way….
    The result is very easy and powerful ! Now, I am getting from CPG itself all its parameters and data. The only remaining small issue is that the view count is not updated. But it is not severe. :o)
    Download the module and play with it. I am sure you will be interested and it could help you ! :o)

    Oh ok. I wrote my own code to do what I wanted. It’s really simple actually as you can see above. Just select all the images, find the max id and do a rand from 1 to max. The album id you can get once you have the pic id. I will look at the CPG code to see how they figure out which position the pic is in but as it stands now the link will display the album view so it’s not too severe anyhow. Just would be nice that’s all. I will download the module and play with it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Semi-Coppermine integration’ is closed to new replies.