Skip to content

Month: April 2008

Allowing flash (flv) files to be stored and embedded in a coppermine gallery

NOTICE: this is from April 2008. The information was accurate then and may still be accurate, but keep that in mind. Software changes. This info may need some adaptation. Also, see the disclaimer at the bottom of the post.

I have several websites for which I am responsible. On one site, I am building a new gallery site for storing pictures as well as sound and video clips. There are several good options for building a gallery site, and I have used more than one with success. For the site in question, I decided to use Coppermine, which is powerful, configurable, open source, and freely licensed using the GNU GPL.

I ran into a little snag that took some work to figure out. To help me remember what I did, I am blogging it here. Maybe someone else will find it useful as well.

Coppermine makes it very easy to store, embed and play lots of media files and formats. That is awesome. I found one that is not supported…the now common flv, or flash video. In fact, by default you can’t even upload a file with an flv extension. Bummer. Off to Google I ran.

I found several sites with ideas and info, but one was more useful than others. Even it required lots of reading and page turning. I decided to put all the info in one page for my easy reference, but the Coppermine Gallery forum deserves a link and the credit for this method. I’m just posting it, people there came up with it. That is an old thread, though, and things have changed since the first post. I had to read the whole thing to figure out what needed to happen to make this work, and that is the reason for this post, rather than just a bookmark in my personal web browser. Okay, here are the steps I took that got this working for me.

Note: get your site up and running, with the theme work complete before doing this. That will make your life a little easier.

1. Download and install the filetype editor MOD discussed here. The mod is included in the cpg1.4.x_plugin_pack_v3 package available on the SourceForge download page for Coppermine. I happened to upload all of the plugins to my website, and sorted them from there, ending up using only a handful. That was easier for me. You do it how you want to.

2. Run the plugin and make a new filetype using the following data; “flv – application/x-shockwave-flash – movie – Flash player”

3. Download the FLV Player from this site. Extract the archive locally and upload mediaplayer.swf and swfobject.js to your Coppermine site’s root directory.

4. I added the following code to my theme’s theme.php file, before the function theme_html_img_nav_menu().

Note: this code is available in a txt file here, which will probably be easier and better than trying to cut/paste from this page.

//** added by matthew to try to get flv play to work **
function theme_html_picture()
{
global $CONFIG, $CURRENT_PIC_DATA, $CURRENT_ALBUM_DATA, $USER;
global $album, $comment_date_fmt, $template_display_media;
global $lang_display_image_php, $lang_picinfo;

$pid = $CURRENT_PIC_DATA['pid'];
$pic_title = '';

if (!isset($USER['liv']) || !is_array($USER['liv'])) {
$USER['liv'] = array();
}
// Add 1 to hit counter
if (!USER_IS_ADMIN && !in_array($pid, $USER['liv']) && isset($_COOKIE[$CONFIG['cookie_name'] . '_data'])) {
add_hit($pid);
if (count($USER['liv']) > 4) array_shift($USER['liv']);
array_push($USER['liv'], $pid);
}

if($CONFIG['thumb_use']=='ht' && $CURRENT_PIC_DATA['pheight'] > $CONFIG['picture_width'] ){ // The wierd comparision is because only picture_width is stored
$condition = true;
}elseif($CONFIG['thumb_use']=='wd' && $CURRENT_PIC_DATA['pwidth'] > $CONFIG['picture_width']){
$condition = true;
}elseif($CONFIG['thumb_use']=='any' && max($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight']) > $CONFIG['picture_width']){
$condition = true;
}else{
$condition = false;
}

if ($CURRENT_PIC_DATA['title'] != '') {
$pic_title .= $CURRENT_PIC_DATA['title'] . "\n";
}
if ($CURRENT_PIC_DATA['caption'] != '') {
$pic_title .= $CURRENT_PIC_DATA['caption'] . "\n";
}
if ($CURRENT_PIC_DATA['keywords'] != '') {
$pic_title .= $lang_picinfo['Keywords'] . ": " . $CURRENT_PIC_DATA['keywords'];
}

if (!$CURRENT_PIC_DATA['title'] && !$CURRENT_PIC_DATA['caption']) {
template_extract_block($template_display_media, 'img_desc');
} else {
if (!$CURRENT_PIC_DATA['title']) {
template_extract_block($template_display_media, 'title');
}
if (!$CURRENT_PIC_DATA['caption']) {
template_extract_block($template_display_media, 'caption');
}
}

$CURRENT_PIC_DATA['menu'] = html_picture_menu(); //((USER_ADMIN_MODE && $CURRENT_ALBUM_DATA['category'] == FIRST_USER_CAT + USER_ID) || ($CONFIG['users_can_edit_pics'] && $CURRENT_PIC_DATA['owner_id'] == USER_ID && USER_ID != 0) || GALLERY_ADMIN_MODE) ? html_picture_menu($pid) : '';

if ($CONFIG['make_intermediate'] && $condition ) {
$picture_url = get_pic_url($CURRENT_PIC_DATA, 'normal');
} else {
$picture_url = get_pic_url($CURRENT_PIC_DATA, 'fullsize');
}

$image_size = compute_img_size($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight'], $CONFIG['picture_width']);

$pic_title = '';
$mime_content = cpg_get_type($CURRENT_PIC_DATA['filename']);

if ($mime_content['content']=='movie' || $mime_content['content']=='audio') {

if ($CURRENT_PIC_DATA['pwidth']==0 || $CURRENT_PIC_DATA['pheight']==0) {
$CURRENT_PIC_DATA['pwidth']  = 320; // Default width

// Set default height; if file is a movie
if ($mime_content['content']=='movie') {
$CURRENT_PIC_DATA['pheight'] = 240; // Default height
}
}

$ctrl_offset['mov']=15;
$ctrl_offset['wmv']=45;
$ctrl_offset['swf']=0;
$ctrl_offset['rm']=0;
$ctrl_offset_default=45;
$ctrl_height = (isset($ctrl_offset[$mime_content['extension']]))?($ctrl_offset[$mime_content['extension']]):$ctrl_offset_default;
$image_size['whole']='width="'.$CURRENT_PIC_DATA['pwidth'].'" height="'.($CURRENT_PIC_DATA['pheight']+$ctrl_height).'"';
}


if ($mime_content['content']=='image') {
if (isset($image_size['reduced'])) {
$winsizeX = $CURRENT_PIC_DATA['pwidth']+5;  //the +'s are the mysterious FF and IE paddings
$winsizeY = $CURRENT_PIC_DATA['pheight']+3; //the +'s are the mysterious FF and IE paddings
$pic_html = "<a href=\"javascript:;\" onclick=\"MM_openBrWindow('displayimage.php?pid=$pid&fullsize=1','" . uniqid(rand()) . "','scrollbars=yes,toolbar=no,status=no,resizable=yes,width=$winsizeX,height=$winsizeY')\">";
$pic_title = $lang_display_image_php['view_fs'] . "\n==============\n" . $pic_title;
$pic_html .= "<img src=\"" . $picture_url . "\" class=\"image\" border=\"0\" alt=\"{$lang_display_image_php['view_fs']}\" /><br />";
$pic_html .= "</a>\n";
} else {
$pic_html = "<img src=\"" . $picture_url . "\" {$image_size['geom']} class=\"image\" border=\"0\" alt=\"\" /><br />\n";
}
} elseif ($mime_content['content']=='document') {
$pic_thumb_url = get_pic_url($CURRENT_PIC_DATA,'thumb');
$pic_html = "<a href=\"{$picture_url}\" target=\"_blank\" class=\"document_link\"><img src=\"".$pic_thumb_url."\" border=\"0\" class=\"image\" /></a>\n<br />";
} else {
$autostart = ($CONFIG['media_autostart']) ? ('true'):('false');

$players['WMP'] = array('id' => 'MediaPlayer',
'clsid' => 'classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" ',
'codebase' => 'codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701" ',
'mime' => 'type="application/x-mplayer2" ',
);
$players['RMP'] = array('id' => 'RealPlayer',
'clsid' => 'classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" ',
'codebase' => '',
'mime' => 'type="audio/x-pn-realaudio-plugin" '
);
$players['QT']  = array('id' => 'QuickTime',
'clsid' => 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ',
'codebase' => 'codebase="http://www.apple.com/qtactivex/qtplugin.cab" ',
'mime' => 'type="video/x-quicktime" '
);
$players['SWF'] = array('id' => 'SWFlash',
'clsid' => ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ',
'codebase' => 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ',
'mime' => 'type="application/x-shockwave-flash" '
);
$players['UNK'] = array('id' => 'DefaultPlayer',
'clsid' => '',
'codebase' => '',
'mime' => ''
);

if (isset($_COOKIE[$CONFIG['cookie_name'].'_'.$mime_content['extension'].'player'])) {
$user_player = $_COOKIE[$CONFIG['cookie_name'].'_'.$mime_content['extension'].'player'];
} else {
$user_player = $mime_content['player'];
}

// There isn't a player selected or user wants client-side control
if (!$user_player) {
$user_player = 'UNK';
}

if ($mime_content['content']=='movie' && $mime_content['mime']=='application/x-shockwave-flash') {
if ($CURRENT_PIC_DATA['pwidth']==0 || $CURRENT_PIC_DATA['pheight']==0) {
$CURRENT_PIC_DATA['pwidth']  = 640; // Default width
$CURRENT_PIC_DATA['pheight'] = 480; // Default height
}
$CURRENT_PIC_DATA['pwidth']-=26; // black bars on sides for me for some reason

$flv =  $CONFIG['fullpath'] . $CURRENT_PIC_DATA['filepath'] . $CURRENT_PIC_DATA['filename'];

if($mime_content['extension']!='flv') {
$flvcheck = fopen($flv,"r");
$flv=fgets($flvcheck);
fclose($flvcheck);
}
$exxvars=str_replace($CONFIG['thumb_pfx'], $CONFIG['normal_pfx'], get_pic_url($CURRENT_PIC_DATA,'thumb'));
if(!file_exists($exxvars)) $exxvars=get_pic_url($CURRENT_PIC_DATA,'thumb');
$exxvars="â„‘=".$exxvars;
$pic_html = "<embed src=\"mediaplayer.swf\" width='".$CURRENT_PIC_DATA['pwidth']."' height='".$CURRENT_PIC_DATA['pheight']."' allowfullscreen=\"true\" allowscriptaccess=\"always\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\"
flashvars=\"file=$flv$exxvars\"></embed>";

} else {

$player = $players[$user_player];

$pic_html  = '<object id="'.$player['id'].'" '.$player['classid'].$player['codebase'].$player['mime'].$image_size['whole'].'>';
$pic_html .= "<param name=\"autostart\" value=\"$autostart\" /><param name=\"src\" value=\"". $picture_url . "\" />";
$pic_html .= '<embed '.$image_size['whole'].' src="'. $picture_url . '" autostart="'.$autostart.'" '.$player['mime'].'></embed>';
$pic_html .= "</object><br />\n";

}
}

$CURRENT_PIC_DATA['html'] = $pic_html;
$CURRENT_PIC_DATA['header'] = '';
$CURRENT_PIC_DATA['footer'] = '';

$CURRENT_PIC_DATA = CPGPluginAPI::filter('file_data',$CURRENT_PIC_DATA);

$params = array('{CELL_HEIGHT}' => '100',
'{IMAGE}' => $CURRENT_PIC_DATA['header'].$CURRENT_PIC_DATA['html'].$CURRENT_PIC_DATA['footer'],
'{ADMIN_MENU}' => $CURRENT_PIC_DATA['menu'],
'{TITLE}' => bb_decode($CURRENT_PIC_DATA['title']),
'{CAPTION}' => bb_decode($CURRENT_PIC_DATA['caption']),
);

return template_eval($template_display_media, $params);
}
//** end added by matthew **

I have not tried them, but I have read that there are some changes you can make to your theme’s template.html file that will allow you to change the size of the video on site. If I am successful doing so, I will add that info in a comment here. Otherwise, this is all I have done, and the site in question now allows me to upload flash video and play it in the same way as an mpg or mov.

EDIT: March 9, 2009. I am no longer in charge of the site that I was working on when I wrote this. I’m leaving this post up in the hopes that it is helpful to others, but I don’t have a site available to use to help people troubleshoot. Sorry. You are still free and very welcome to post comments, questions, or tips, there just isn’t any guarantee that I will be able to help, but maybe someone else will. 🙂

Fun with Conky, part 3

All the way back in October 2007 I made two posts about conky, a lightweight and highly configurable system monitor for your desktop.

I still use conky and love it. My configuration changes regularly, especially the colors, but you can get the basic idea from the config files I included in the earlier posts. There is one change I made recently that I would like to highlight because I think others will appreciate it.

Originally, and for many months, I had a line in the configuration that would query a specific website to get my public IP address. I appreciate whatismyip.org allowing people to do this. At the same time, the service has some limitations that I wanted to bypass. For example, you are limited to the number of queries per unit of time, and occasionally I would end up with a conky that included an ugly html page smeared over my desktop instead of a pretty set of IP numbers.

How to fix it?

I decided to do what any good geek would do and make my own IP query site. I won’t share the location, simply because I can’t afford to have 10,000 requests per hour hitting my web server. However, this is something that anyone with web hosting space can do. It is simple.

I just made an unbelievably short php file and uploaded it to my web server. Here is what it contains.

<? $remote = $_SERVER[“REMOTE_ADDR”]; echo $remote; ?>

Yep, that’s it. Put that in a file on your web server with a name like myip.php and test it out by pointing your browser there. If you get your IP address as the response, you are set. Add something like this to your conky file and you are good to go.

${color #FEB60D}Public IP ${color #FECE0D}${execi 360 curl ‘http://yourwebaddress_notmine.com/myip.php’}

Using rsync to back up my laptop

There are lots of good ways to back up your computer. I’ve used several. Lately, I am enjoying the ease, convenience, and quality of rsync. In typical geek fashion, I was perusing the rsync man page the other day and found some nice options that I hadn’t known about, so I started to experiment.

I wanted to back up my laptop to a portable, external hard drive, starting with a full backup, then going to incremental backups after that. I also wanted to make sure the backup was kept in sync with my local hard drive, but without accidentally permanently deleting anything from the backup that I might want or need later. Here is what I came up with, posted here mainly for the sake of my memory, but you might find it interesting as well.

First, to back up the entire hard drive, I need to do this as root. Since I am using Ubuntu, and because I like sudo, I just add that to the beginning of the command and enter my password at the prompt. This reminds me to mention that it is important that your backup be kept in a secure location, just as with your computer. Anyone with physical access to the backup drive will eventually have access to all your data.

Here is the command I used, followed by an explanation of the options I am using.

sudo rsync --force --ignore-errors --delete --delete-excluded --exclude-from=/media/disk/matthew-exclude.txt --backup --backup-dir=`date +%Y-%m-%d` -av / /media/disk/backup/matthew-laptop

Options used:

–force: forces the deletion of directories on the backup drive, even if they are not empty

–ignore-errors: tells –delete to go ahead and delete files even when there are I/O errors

–delete: deletes unnecessary or extra files from destination directories

–delete-excluded: deletes excluded files from destination directories

–exclude-from=/media/disk/matthew-exclude.txt: tells rsync not to backup files or directories listed in this file, which I include on the destination drive (my sample is below)

–backup: creates backups of files before deleting them

–backup-dir=`date +%Y-%m-%d`: creates a backup directory on the destination drive for those backups with today’s date as the directory name

-av: archive mode, which combines lots of great stuff together like preserving file permissions and ownership, and verbose output, which is nice for knowing what is going on

This is my exclude file.

home/lost+found/
home/.Trash-root/
home/matt/.thumbnails/
home/matt/.Trash/
lost+found/
media
mnt
proc
root/.thumbnails/
root/.Trash/
sys
tmp

That’s it. The first time I ran it, it took a long time. Of course, I have some 75 gigabites of data, so that isn’t surprising. After that, only things which have changed need to be transferred or deleted, so the process is quite fast.