<?php
// ----------------------------------------------------------
// TagBlitz.com Plugin 1.0 for Coppermine Photo Gallery 1.4.6
// Copyright 2006 Jake Russell, All Rights Reserved
// ----------------------------------------------------------
//
// ----------------------------------------------------------
// Title: TagBlitz Plugin
// Version: 1.0 (stable)
// Author: Jake Russell - http://www.tagblitz.com
// Official Plugin Page: http://www.tagblitz.com/getcode.php
// Official Support Thread:
// Live environment test: CPG 1.4.6
// Tested with IE 6 and FF 1.5
// ----------------------------------------------------------
// 
// ----------------------------------------------------------
// AVAILABLE CUSTOMIZATIONS (Available, but not required!)
// If you prefer a text link instead of the TagBlitz button,
// simply change {$buttoncode} to {$linkcode}
// (Near line 154)
// ----------------------------------------------------------
//
// ----------------------------------------------------------
// THIS PLUGIN IS OFFERED "AS-IS" IN THE HOPE THAT IT WILL BE
// USEFUL. NO WARRANTY OR GUARANTEE WHATSOEVER IS STATED OR
// IMPLIED.
//
// You may freely distribute this plugin.
// ----------------------------------------------------------
// 
// ----------------------------------------------------------
// What does this plugin actually do?
// 
// This plugin provides two valuable services for your CPG:
//
// First, it gives your users the ability to easily share
// your CPG pages with over 50 different social bookmarking
// websites and services, including del.icio.us, Technorati,
// digg.com, Myspace, AIM, furl, and Blogger, just to name a
// few.
//
// Second, it gives your CPG the ability to produce cut and
// paste linking codes so your visitors can post thumbnail
// and text links to your pages all over the web.
//
// All the links are permanent URLs, of course.
//
// Frankly, this is the best promotional plugin in the world.
// ----------------------------------------------------------
?>
<script language="javascript" type="text/javascript">
<!--
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=yes,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}
// -->
</script>
<?php
if (!defined('IN_COPPERMINE')) die('Not in Coppermine...');
include ("{$CONFIG['ecards_more_pic_target']}/include/functions.inc.php");
// Create the BBcode with link to thumbnail 
$bbcodethumb_url = get_pic_url($CURRENT_PIC_DATA, 'thumb');

// Add a filter
$thisplugin->add_filter('file_data','bbcode_add_data');
function bbcode_add_moredata($pic_data){ //$pic_data

	$thumb_url = get_pic_url($pic_data, 'thumb');
	$fullsized_url = get_pic_url($pic_data);
	$normal_url = get_pic_url($pic_data, 'normal');

	$pic_data['html'] = $thumb_url.'<br>'.$fullsized_url.'<br>'.$normal_url.'<br>'.$pic_data['html']; 
	return $pic_data; //return $pic_data
}

function bbcode_add_data($pic_data){
include ("{$CONFIG['ecards_more_pic_target']}/include/functions.inc.php");
// Set up variables to grab the picture title and absolute URL information
// Automatically grab and encode the Title
	$title = "{$pic_data['title']}";
	$title = urlencode($title);
// Automatically grab and encode the absolute URL
	$url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
	$url = preg_replace('/\?(.*)/','',$url);
	$linkingurl = $url; // Set a separate unencoder URL for use in the Linking Codes section
	$url = urlencode($url);
// Remove displayimage.php from $linkingurl for use in thumb url
	$linkingurl2 = $linkingurl;
	$linkingurl2 = preg_replace('/displayimage(.*)/','',$linkingurl2);
// Automatically grab and encode keywords, as defined in File Information section
$keys = "{$pic_data['keywords']}";
$keys = urlencode($keys);
// Set linking code option with an event handler, in this case a "switch" command
	$event = isset($_GET['event']) ? $_GET['event'] : null;
	switch ($event) {
    	case 'show_bbcode':
//Define image URLs for linking codes
	$thumb_url = get_pic_url($pic_data, 'thumb');
	$fullsized_url = get_pic_url($pic_data);
	$downloadlink = get_pic_url($pic_data, 'normal');
	$normal_url = get_pic_url($pic_data, 'normal');			
// Set up the HTML template for the displayed data	
	$display_data =  <<<EOT
				<table>
					<tr>
						<td>
<!-- Generate assorted versions of links to absolute URL of intermediate picture page (ie - displayimage.php?pos=-1234) -->
							<p>Copy <strong>(CTRL-C)</strong> and paste <strong>(CTRL-V)</strong> the code into your site, blog, or forum.</p>
							<strong>Permanent URL:</strong>
							<br>
							<textarea onFocus="this.select()" name="u" cols="50" rows="2">{$linkingurl}?pos=-{$pic_data['pid']}</textarea>
							<br>
							<strong>HTML Linking code:</strong> (With Thumbnail)
							<br>
							<textarea onFocus="this.select()" name="t" cols="50" rows="8">&lt;a href=&quot;{$linkingurl}?pos=-{$pic_data['pid']}&quot;&gt;&lt;img src=&quot;{$linkingurl2}{$thumb_url}&quot; WIDTH=&quot;100&quot; HEIGHT=&quot;100&quot;&gt;&lt;br&gt;{$pic_data['title']}&lt;/a&gt;</textarea>
							<br>
							<strong>HTML Linking code:</strong> (Without Thumbnail)
							<br>
							<textarea onFocus="this.select()" name="x" cols="50" rows="5">&lt;a href=&quot;{$linkingurl}?pos=-{$pic_data['pid']}&quot; target=&quot;_blank&quot;&gt;{$pic_data['title']}&lt;/a&gt;</textarea>
							<br>
							<strong>Forum bbCode:</strong> (Thumb and title)
							<br>
<!-- The content of the next textbox is intentionally split into two lines, with no additional whitespace -->
<!-- This is required for the resulting bbCode to appear properly in forums -->							
							<textarea onFocus="this.select()" name="bbtx" cols="50" rows="6">[url={$linkingurl}?pos=-{$pic_data['pid']}]{$pic_data['title']}[/url]
[url={$linkingurl}?pos=-{$pic_data['pid']}][img]{$linkingurl2}{$thumb_url}[/img][/url]</textarea>
							<br>
							<strong>Forum bbCode:</strong> (Thumb only)<br>
							<textarea onFocus="this.select()" name="bbt" cols="50" rows="4">[url={$linkingurl}?pos=-{$pic_data['pid']}][img]{$linkingurl2}{$thumb_url}[/img][/url]</textarea>
							<br>
							<strong>Forum bbCode:</strong> (Title text only)
							<br>
							<textarea onFocus="this.select()" name="bbx" cols="50" rows="2">[url={$linkingurl}?pos=-{$pic_data['pid']}]{$pic_data['title']}[/url]</textarea>
						</td>
					</tr>
				</table>
EOT;
		break;
		
		default : 
// Set up variables to reflect necessary JS link from TagBlitz
$linkcode = "<a onclick=\"NewWindow(this.href,'TagBlitz','650','500','no','center');return false\" onfocus=\"this.blur()\" href=\"http://tagblitz.com/submit/?url={$url}?pos=-{$pic_data['pid']}&msurl={$url}?pos=-{$pic_data['pid']}&amp;title={$title}&keys={$keys}\" target=\"_blank\" TITLE=\"TagBlitz.com allows you to share a page on over 50 social bookmarking websites and services. No signup, no hassle!\"><font color=\"blue\" size=\"+1\">TagBlitz This Page</font></a>";
$buttoncode = "<a onclick=\"NewWindow(this.href,'TagBlitz','650','500','no','center');return false\" onfocus=\"this.blur()\" href=\"http://tagblitz.com/submit/?url={$url}?pos=-{$pic_data['pid']}&msurl={$url}?pos=-{$pic_data['pid']}&amp;title={$title}&keys={$keys}\" target=\"_blank\"><img src=\"http://www.tagblitz.com/img/button_tagblitzthis1.gif\" border=\"0\" ALT=\"TagBlitz.com allows you to share a page on over 50 social bookmarking websites and services. No signup, no hassle!\"></a>";

			$referer = ($_SERVER['PHP_SELF'] . (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] ? '?' . $_SERVER['QUERY_STRING'] : ''));
			$display_data =  <<<EOT
<table align="center" width="90%" cellpadding="5">
	<tr>
		<td>
<!-- Begin ADD TagBlitz button -->
			<div align="center">
			{$buttoncode}
	    	</div>
<!-- End ADD TagBlitz button -->
		</td>
		<td>
<!-- Begin ADD Linking Codes weblink -->							
			<div align="center">
			<a href="{$referer}&event=show_bbcode" TITLE="Website, blog, forum, and Myspace linking codes"><font color="blue" size="+1"><u>Linking codes</u></font></a>
		    </div>
<!-- End ADD Linking Codes weblink -->							
		</td>
	</tr>
</table>
EOT;
		break;
	}	
	$pic_data['html'] = $display_data.$pic_data['html'];
	return $pic_data;
}
?>
<?
// Additional notes
//
// v 1.0.1 - Fixed issue with incorrect thumb URL in inking codes.
?>