Random Image/media Block for mkportal

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Angel
-


Joined: 17 Nov 2003
Posts: 157
Location: Everett, Washington

PostPosted: Sat Feb 18, 2006 12:10 am    Post subject: Random Image/media Block for mkportal Reply with quote

I posted this at both devshed and mkportal's website and haven't recieved any help, sooo I thought I would try here, since everyone is so helpful. here's the thing I'm trying to write a block for mkportal, which that will display random file names for media files and random images for well images in from a standalone installation of coppermine. I'm still pretty new to php, so here's what I have so far.

block code
Code:

$sitepath = 'photo';
//the name of your coppermine gallery folder without a trailing slash
$dbprefix = 'cpg143_';
// prefix of your coppermine tables, don't forget the _ underscore

$query = $DB->query("SELECT pid, aid, title, filepath, filename FROM
 {$dbprefix}pictures ORDER BY RAND() LIMIT 1");

$photo = $DB->fetch_row($query);
$aid  = $photo['aid'];
$title  = $photo['title'];
$filepath = $photo['filepath'];
$filename = $photo['filename'];   
$thumbnail = "thumb_$filename";
$position = strlen($fileName) - (strpos($fileName, "."));
$extension = substr($fileName, -$position+1, $position);

$media = array ( "midi", "mid", " midi", "mpga", "mp2", "mp3", "aif", "ram",
 "rm", "ra", "wav","mpeg", "mpg", "qt", "mov", "avi");
$image = array ("gif", "jpeg", "jpg", "png", "bmp");

$false = '<div align="center"><b>No Files In the gallery<b></div>';

if ($extension == $media){

  $content = '<tr align=\"center\"><td>
  <a href=\"{$sitepath}/thumbnails.php?album={$aid}\">$filename</a></td>
              </tr>
              <tr>
           <td id=\"tdblock\" align=\"center\"
           style=\"text-align:center; text-decoration: none;\">
            <a href=\"{$sitepath}/thumbnails.php?album={$aid}\">
           $title</a><br /></td>
           </tr>';
}


  elseif ($extension == $image) {
  $content = '<tr align=\"center\"><td><a href=\"{$sitepath}/
  thumbnails.php?album={$aid}\">
              <img src=\"{$sitepath}/albums/{$filepath}{$thumbnail}\"
            border=\"0\" alt=\"{$title}\"></a>
              </td></tr><tr><td id=\"tdblock\" align=\"center\"
           style=\"text-align:center; text-decoration: none;\">
              <a href=\"{$sitepath}/thumbnails.php?
           album={$aid}\">$title</a><br /></td></tr>'; 
}
else {
  $content = $false;
}; 

    unset($photo);
    unset($aid);
    unset($title);
    unset($filepath);
    unset($filename);
    unset($thumbnail);


I'm very new to scripting php and I can't understand why this won't work. I recieve no errors it's just that the block always shows this part
Code:

$content = '<div align="center"><b>No Files In the gallery<b></div>';


it won't display any files. Does anyone have any ideas?

Thanks in advance,
Angel
_________________
Noize Pollution | Angel's Online | Free Net Builders | Pagan Portal
Back to top View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sat Feb 18, 2006 12:36 am    Post subject: Reply with quote

I think you're after in_array()?
A string obviously won't equal an array, so you'll have to do a "search", via something like in_array().
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
Angel
-


Joined: 17 Nov 2003
Posts: 157
Location: Everett, Washington

PostPosted: Sat Feb 18, 2006 12:38 am    Post subject: Reply with quote

Hey monkey thanks, for the help, but could you elaborate a little for me I'm a bit php illiterate..lol

thanks,
Angel
_________________
Noize Pollution | Angel's Online | Free Net Builders | Pagan Portal
Back to top View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Sat Feb 18, 2006 12:38 am    Post subject: Re: Random Image/media Block for mkportal Reply with quote

Angel wrote:
Code:

$sitepath = 'photo';
//the name of your coppermine gallery folder without a trailing slash
$dbprefix = 'cpg143_';
// prefix of your coppermine tables, don't forget the _ underscore

$query = $DB->query("SELECT pid, aid, title, filepath, filename FROM
 {$dbprefix}pictures ORDER BY RAND() LIMIT 1");

$photo = $DB->fetch_row($query);
$aid  = $photo['aid'];
$title  = $photo['title'];
$filepath = $photo['filepath'];
$filename = $photo['filename'];   
$thumbnail = "thumb_$filename";
$position = strlen($fileName) - (strpos($fileName, "."));
$extension = substr($fileName, -$position+1, $position);

$media = array ( "midi", "mid", " midi", "mpga", "mp2", "mp3", "aif", "ram",
 "rm", "ra", "wav","mpeg", "mpg", "qt", "mov", "avi");
$image = array ("gif", "jpeg", "jpg", "png", "bmp");

$false = '<div align="center"><b>No Files In the gallery<b></div>';

if ($extension == $media){

  $content = '<tr align=\"center\"><td>
  <a href=\"{$sitepath}/thumbnails.php?album={$aid}\">$filename</a></td>
              </tr>
              <tr>
           <td id=\"tdblock\" align=\"center\"
           style=\"text-align:center; text-decoration: none;\">
            <a href=\"{$sitepath}/thumbnails.php?album={$aid}\">
           $title</a><br /></td>
           </tr>';
}


  elseif ($extension == $image) {
  $content = '<tr align=\"center\"><td><a href=\"{$sitepath}/
  thumbnails.php?album={$aid}\">
              <img src=\"{$sitepath}/albums/{$filepath}{$thumbnail}\"
            border=\"0\" alt=\"{$title}\"></a>
              </td></tr><tr><td id=\"tdblock\" align=\"center\"
           style=\"text-align:center; text-decoration: none;\">
              <a href=\"{$sitepath}/thumbnails.php?
           album={$aid}\">$title</a><br /></td></tr>'; 
}
else {
  $content = $false;
}; 

    unset($photo);
    unset($aid);
    unset($title);
    unset($filepath);
    unset($filename);
    unset($thumbnail);


the problem is that you are trying to compare a value against an array
to do this you will have to use the in_array() function
more info about the in_array function can be found here

your two if() statements would look like the following
Code:

//cut
if ( in_array($extension, $media) ){
//cut
}
  elseif ( in_array($extension, $image) ) {
//cut


hope that helps
_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
Angel
-


Joined: 17 Nov 2003
Posts: 157
Location: Everett, Washington

PostPosted: Sat Feb 18, 2006 12:57 am    Post subject: Reply with quote

well I have this and still I'm told no files in the gallery, any ideas?

Code:
$sitepath = 'photo'; //the name of your coppermine gallery folder without a trailing slash
$dbprefix = 'cpg143_'; // prefix of your coppermine tables, don't forget the _ underscore

$content = "";
$query = $DB->query("SELECT pid, aid, title, filepath, filename FROM {$dbprefix}pictures ORDER BY RAND() LIMIT 1");

$photo = $DB->fetch_row($query);
$aid  = $photo['aid'];
$title  = $photo['title'];
$filepath = $photo['filepath'];
$filename = $photo['filename'];   
$thumbnail = "thumb_$filename";
$position = strlen($fileName) - (strpos($fileName, "."));
$extension = substr($fileName, -$position+1, $position);

$media = array ( "midi", "mid", " midi", "mpga", "mp2", "mp3", "aif", "ram", "rm", "ra", "wav","mpeg", "mpg", "qt", "mov", "avi");
$image = array ("gif", "jpeg", "jpg", "png", "bmp");

$false = '<tr align="center"><td><div align="center">No files In the Gallery</div></td></tr>';

if (in_array(strtolower($extension), $media)){
  $content = '<tr align="center"><td><a href="$sitepath/thumbnails.php?album={$aid}" target="_blank">{$title}</a></td></tr>';
}

elseif (in_array(strtolower($extension), $image)){
   $content = '<tr align="center"><td><a href="$sitepath/thumbnails.php?album={$aid}" target="_blank"><img src="$sitepath/albums/{$filepath}{$thumb}" border="0" alt="{$title}"></a></td></tr>
      <tr><td id="tdblock" align="center" style="text-align:center; text-decoration: none;"><a href="$sitepath/thumbnails.php?album={$aid}">$title</a><br /></td></tr>';
}
else {
  $content = $false;
}; 

    unset($photo);
    unset($aid);
    unset($title);
    unset($filepath);
    unset($filename);
    unset($thumbnail);


thanks,
Angel
_________________
Noize Pollution | Angel's Online | Free Net Builders | Pagan Portal
Back to top View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number
MonkeyNation
-


Joined: 05 Feb 2005
Posts: 921
Location: Cardiff

PostPosted: Sat Feb 18, 2006 1:08 am    Post subject: Reply with quote

I imagine it's most likely the difference of case on $filename and $fileName, among a few other possible things.
_________________
Back to top View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group