News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Coppermine "Latest 5 pictures" for Info Center

Started by kegobeer, July 04, 2004, 02:16:00 PM

Previous topic - Next topic

kegobeer

I wanted to show the latest 5 pictures from my Coppermine gallery, so here's a little hack for your BoardIndex.template.php file.

First, create a file called coppermine.php and save it in your Sources directory with the following code:
<?php
  
$request5 db_query("
SELECT pid, filepath, filename, title
FROM cpg130_pictures
WHERE approved='YES'
ORDER BY pid DESC
LIMIT 5"
__FILE____LINE__);

$imagecounter 0;

echo '<table width="90%" border="0">';

while ($row5=mysql_fetch_array($request5)) {
$imagecounter++;
$imagefilename $row5['filename'];
$imageurl[$imagecounter] = '<img src="../coppermine/albums/'.$row5['filepath'].'thumb_'.$imagefilename.'" height="100" width="100" alt="">';
$imagetitle[$imagecounter] = $row5['title'];
}
echo '<tr align="center">';
for ($x 1$x <= $imagecounter$x++) {
echo '<td width="150">'.$imageurl[$x].'</td>';
}
echo '</tr><tr align="center">';
for ($x 1$x <= $imagecounter$x++) {
echo '<td width="150">'.$imagetitle[$x].'</td>';
}
echo '</tr></table>';
?>


If your Coppermine table isn't called cpg130, change line 4 to reflect your table name.

Then, in BoardIndex.template.php, put this to include it in your Info Center, or wherever you want it:
  // Show the latest 5 pictures
  echo '
  <tr>
  <td class="catbg" colspan="2">Latest Pictures from the Gallery
  </td>
  </tr>
  <tr>
  <td class="windowbg" width="20" align="center">
  <a href="../coppermine/index.php">
  <img src="../coppermine/images/coppermine.gif" alt="Gallery" border="0" /></a>
  </td>
  <td class="windowbg2" width="100%">';

include ("Sources/coppermine.php");

echo '
</td>
</tr>';


I created a custom icon and put it in my coppermine directory, so if you don't have one just remove the code accordingly.

If you have wmv videos (or whatever, just change .wmv) with custom thumbnails in your gallery, you can add this after the $imagefilename = $row5['filename'] statement:
$imagefilename = str_replace('.wmv', '.jpg', $imagefilename);

My gallery isn't very fancy and I always make sure my special items have custom thumbnails, so it works great for me.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Cccddd

#1
good stuff. My only suggestion is, since it's so small, I would suggest moving it to SSI.php instead. I already did this but I made a bunch of other changes too so im not bothering to post the code

here it is in use: http://nrrds.com

Alisha

Quote from: Cheschire on July 04, 2004, 07:31:45 PM
good stuff. My only suggestion is, since it's so small, I would suggest moving it to SSI.php instead. I already did this but I made a bunch of other changes too so im not bothering to post the code

here it is in use: http://nrrds.com

I think you did what I am trying to do with this idea! I wanted to add the last 5 images or Random 5 to a Html page outside of the forums.  I am thinking I will also add them to the bottom, but I mostly wanted them on the index.php page. How would I make it into SSI? 

I am VERY new to the SSI thing, in fact only thing I know how to do is grab the one from the examples and use them. I would be most greatfull for any help! I have been trying and trying using Coppermine Stuff! lol

Cccddd

#3
open SSI.php:


function ssi_latestPics()
{
   $request5 = db_query("
      SELECT pid, filepath, filename, title
      FROM gallery_pictures
      WHERE approved='YES'
      ORDER BY pid DESC
      LIMIT 5", __FILE__, __LINE__);

   $imagecounter = 0;

   while ($row5 = mysql_fetch_array($request5))
   {
      $imagefilename = $row5['filename'];
      $imageurl[$imagecounter] = '<a href="/gallery/displayimage.php?album=lastup&pos=' . $imagecounter . '"><img src="/gallery/albums/'.$row5['filepath'].'thumb_'.$imagefilename.'" height="100" width="100" alt="' . $row5['title'] . '"></a>';
      $imagetitle[$imagecounter] = $row5['title'];
      $imagecounter++;
   }

   for ($x = 0; $x < $imagecounter; $x++)
      echo $imageurl[$x].'<br /><br />';
}


in your whatever_im_not_smf.php file:


include_once("/path/to/SSI.php");
echo 'blah this is html', ssi_latestPics(), ' blah this is after the pics html';

Alisha

Ok, I tried this and punched up a Bunch of errors! I changed some things around a little, and now down to 3 lol

I am thinking it is because I use a separate SQL for for coppermine than I do for SMF ? Could that be the problem?


Cccddd

can you post the exact errors you are getting?

kegobeer

I did end up putting it in ssi.php, but only after I decided to have a non forum page.  I kept it out of ssi.php because, if it's anything like other types of ssi files, it's best not to include ssi.php in forum pages.

I'm going to mod the code to pull the album location from the config table, so the webmaster doesn't have to do much editing of the file.  I'm also planning on doing a check for the file type to display a custom thumbnail or the default type image, just like coppermine does.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

[Unknown]

You can include SSI.php for templates just fine.  This isn't YaBB SE.

-[Unknown]

Cccddd

yeah in my page its included in BoardIndex.php. That front page on http://nrrds.com is BoardIndex believe it or not, but I use SSI because its easier to edit SSI.php than to edit a bunch of Sources/blah.php files to put all the mods back in everytime i upgrade.

kegobeer

Here's the mod I was talking about.  Bear in mind, when I make custom thumbnails for documents (zip, rar, doc, etc) I name them thumb_filename.jpg.  This mod looks for the existence of that name, and if it doesn't find it, it uses the default thumbnail for the mime type.

The only thing that would need to be modified is $cpgtable.

Put this in ssi.php.

function ssi_latestCoppermine()
{
global $FILE_TYPES;
$cpgtable = 'cpg130';  // Change to your Coppermine table prefix

// Pull the filetypes from the Coppermine tables
if (count($FILE_TYPES)==0) {
         $result55 = db_query("
         SELECT extension, mime, content
         FROM ".$cpgtable."_filetypes", __FILE__, __LINE__);
         
         while ($row = mysql_fetch_array($result55)) {
             // Only add types that are in both the database and user defined parameter
            $FILE_TYPES[$row['extension']] = $row;
    }   
    }
   
    mysql_free_result($result55);

// Count the total number of approved pictures
$temp55 = db_query("
SELECT count(*)
FROM ". $cpgtable ."_pictures
WHERE approved='YES'", __FILE__, __LINE__);

$picTotal = mysql_fetch_array($temp55);
$picTotal = $picTotal[0];
mysql_free_result($temp55);

// Count the total number of albums
$temp55 = db_query("
SELECT count(*)
FROM ". $cpgtable ."_albums", _FILE__, __LINE__);

$albumTotal = mysql_fetch_array($temp55);
$albumTotal = $albumTotal[0];
mysql_free_result($temp55);

// Get the ecards_more_pic_target and fullpath variables
$temp55 = db_query("
SELECT value
FROM ". $cpgtable ."_config
WHERE name='ecards_more_pic_target'", __FILE__, __LINE__);

list($pic_target) = mysql_fetch_row($temp55);
mysql_free_result($temp55);

$temp55 = db_query("
SELECT value
FROM ". $cpgtable ."_config
WHERE name='fullpath'", __FILE__, __LINE__);

list($fullpath) = mysql_fetch_row($temp55);
mysql_free_result($temp55);

$picurl = $pic_target . $fullpath;

// Get the 5 most recent
  $request5 = db_query("
SELECT pid, filepath, filename, title
FROM ".$cpgtable."_pictures
WHERE approved='YES'
ORDER BY pid DESC
LIMIT 5", __FILE__, __LINE__);

$imagecounter = 0;

echo '<table width="100%">';

while ($row5=mysql_fetch_array($request5)) {
$imagecounter++;
$imagefilename = $row5['filename'];

// Look for custom thumbs
$mime_content = get_type($imagefilename);

$whattype = get_type($imagefilename,'image');
if (!$whattype) {
$imagefilename = str_replace('.'.$mime_content['extension'],'.jpg',$imagefilename);
if (file_exists($picurl.$row5['filepath']."thumb_".$imagefilename)) {
$imageurl[$imagecounter] = '<img src="'.$picurl.$row5['filepath'].'thumb_'.$imagefilename.'" height="100" width="100" alt="">';
} else {
$imageurl[$imagecounter] = '<img src="coppermine/images/thumb_'.$mime_content['extension'].'" height="100" width="100" alt="">';
}
}

if ($imageurl[$imagecounter]=='') $imageurl[$imagecounter] = '<img src="'.$picurl.$row5['filepath'].'thumb_'.$imagefilename.'" height="100" width="100" alt="">';
$imagetitle[$imagecounter] = $row5['title'];
}
echo '<tr align="center">';
for ($x = 1; $x <= $imagecounter; $x++) {
echo '<td width="150">'.$imageurl[$x].'</td>';
}
echo '</tr><tr align="center">';
for ($x = 1; $x <= $imagecounter; $x++) {
echo '<td width="150">'.$imagetitle[$x].'</td>';
}
echo '</tr></table>';
echo '<br /><center>The Gallery has '.$picTotal.' images in '.$albumTotal.' albums.  You should go <a href="coppermine/index.php">see</a> them!</center>';
mysql_free_result($request5);
}

function get_type($filename,$filter=null)
{
// Figure out the file type - pulled from Coppermine 1.3.0
    global $FILE_TYPES;
    if (!is_array($filename))
        $filename = explode('.',$filename);
    $EOA = count($filename)-1;
    $filename[$EOA] = strtolower($filename[$EOA]);

    if (!is_null($filter) && $FILE_TYPES[$filename[$EOA]]['content']==$filter)
        return $FILE_TYPES[$filename[$EOA]];
    elseif (is_null($filter))
        return $FILE_TYPES[$filename[$EOA]];
    else
        return null;
}
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Alisha

Quote from: Cheschire on July 05, 2004, 11:05:05 AM
can you post the exact errors you are getting?

Well when I posted this I has already rmoved the PHP from the index file, and uploaded it to remove the error. Now when I add it back, I can not seem to recreate the error. Although, I get nothing! No, errors or images?

Cccddd


Alisha

I installed / added kegobeer AWESOME SSI.PHP Mod! :) It worked! YAY! Although, not perfectly!

Well I am sure this is something I need to fix to customize to my site, although, it says there are;

The Gallery has 0 images in 30 albums. You should go see them!

lol well thats not true! :) there are 17+ images in 30 albums! :)

Any idea what went wrong? Is this the Thumbnail file name thing he as talking about that I totally do not understand?

kegobeer

I don't know why it's not working for you.  Try this: Save this code as temp.php, upload it to your site, and see if you get the latest 5 pics.

<?php
require("linktoyourssifile");
ssi_latestCoppermine();
?>

"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Alisha

#14
nope, same thing!

http://dancedancekc.com/temp.php

Again, I will note, Coppermine SQL is separate from my SMF SQL. Totally diffrent database. Also, I think I changed all the /coppermine/ urls to /Gallery/ Url to match my site.  Although, It does find the Albums but not the images?


kegobeer

In in ssi_latestCoppermine(); replace count(*) with COUNT(*)
If that doesn't do anything, try replacing
$temp55 = db_query("
SELECT count(*)
FROM ". $cpgtable ."_pictures
WHERE approved='YES'", __FILE__, __LINE__);

$picTotal = mysql_fetch_array($temp55);
$picTotal = $picTotal[0];

with
$temp55 = db_query("
SELECT *
FROM ". $cpgtable ."_pictures
WHERE approved='YES'", __FILE__, __LINE__);

$picTotal = mysql_num_rows($temp55);
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Alisha

I will try that next! Although, I was investigating things here, and I added a Album, and it still shows 30 and not 31. So I checked the SQL, NOT there, weird! There is a Image there of me, and it shows up in coppermine!

Now the really weird PART, I guess when I bridged SMF with coppermine, it made a table in my SMF sql database.  Well also, the NEW Album is NOT there either! So I am not sure where its writting and to what SQL file! lol

This is totally confusing me now! :)

Alisha


kegobeer

I think the problem is the way you have SMF and Coppermine installed and set up.  The way it should work - Install SMF and Coppermine separately (html/coppermine and html/forums).  Use the same username and password for your admin account.  Make sure both work correctly.  Have both use the same database; it's ok, the table prefixes will be different.  Then follow the instructions with Coppermine to use the SMF bridge file.  Once that's done everything should work ok.  You'll have to go into Coppermine and set group permissions so your members can upload.
"The truth of the matter is that you always know the right thing to do. The hard part is doing it." - Norman Schwarzkopf
Posting and you (Click "WATCH THIS MOVIE")

Alisha

I did install them separately. I made sure they both worked perfectly a Long time before I even knew there was a bridge for SMF, Then I installed the Bridge as instructed.  I did have to back into coppermine and change the the permissions for the SMF groups! 

I looked into the SQLs and the one in the SMF is showing 0 images in each cat / album. So I am 900% sure the problem isn't with your script! Its with the coppermine config. I am just not sure where or what SQL it is writting it information.  You script is returning the information from the SMF sql exactly as it is there.

Although, the SFM SQL doesn't have the information of what is what in coppermine! New Album / Image etc...  I looked into the config in coppermine and the SQL paths are not there anymore since the bridge, or maybe they were not there at all before,  I am not sure! I will solve this problem when I can figure out how to change where coppermine writes to the sql and chance it to the SMF SQL! :)

Advertisement: