View Single Post
Old 05-27-2012, 01:47 PM  
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,073
Ok, you need a folder for the make sigs script. This folder has htaccess that redirects any .jpg or .gif call to the make sigs program.

So htaccess looks something like this:

AuthUserFile /dev/null
AuthGroupFile /dev/null

RewriteEngine On

ReWriteRule .*\.(jpg|gif)$ http://www.domain_installed_on/sigs/make_sig.php [R,L]

Then I have a config file for the hook ups to the database and some other stuff:

<?php

function hookitup()
{

// full server path to ttf font library
$font_path='/home/xxxxxxxx/ttffonts/';

// font name to use for sig
$font_name='Loungy.ttf';

//font size to use for sig
$font_size='18';

// name of blog being pulled from
$blog_name='yourblogname.com';

// put mysql credentials necessary for your main database here

$main_host='xxxxxxxx';
$main_user='xxxxxxx';
$main_pass='xxxxxx';
$main_dbname='xxxxxxx';

// put mysql credentials necessary for your blog database here

$blog_host='xxxxxxxxx';
$blog_user='xxxxxxxx';
$blog_pass='xxxxxxxxxx';
$blog_dbname='xxxxxxxxx';

$maindb = mysql_pconnect($main_host,$main_user,$main_pass);
if(!$maindb)
{
die("could not hook up to the main database");
}
if($main_host==$blog_host && $main_user==$blog_user && $main_pass==$blog_pass)
{
// if all data is in one db then use the same connection

$blogdb=$maindb;
}
else
{
// if data is in different dbs then we need 2 connections
$blogdb = mysql_pconnect($blog_host,$blog_user,$blog_pass);
if(!$blogdb)
{
die("could not hook up to the blog database");
}
}

$returnit=array(
"maindb"=>$maindb,
"blogdb"=>$blogdb,
"main_dbname"=>$main_dbname,
"blog_dbname"=>$blog_dbname,
"font_path"=>$font_path,
"font_name"=>$font_name,
"font_size"=>$font_size,
"blog_name"=>$blog_name
);

return $returnit;
}
?>

Then there is the make_sigs script (please not that I have some hardcodes in there for gfy, these were dynamic but I hardcoded the changes I made a few days ago for the blog pull in and demo and I have not gotten back to changing it up:

<?php
error_reporting(0);

$ip2use=$_SERVER['REMOTE_ADDR'];
if(!isset($_SERVER['HTTP_REFERER']))
{
$refer2use='';
}
else
{
$refer2use=mysql_real_escape_string($_SERVER['HTTP_REFERER']);
}

require_once('../sig_config.php');

$dblist=hookitup();

$maindb=$dblist['maindb'];
$blogdb=$dblist['blogdb'];
$maindbname=$dblist['main_dbname'];
$blogdbname=$dblist['blog_dbname'];
$fontpath=$dblist['font_path'];
$fontname=$fontpath . $dblist['font_name'];
$fontsize=$dblist['font_size'];
$blogname=$dblist['blog_name'];

// This assumes the blog is WP and the posts table is wp_posts
$sql_str="select id, post_title from " . $blogdbname . ".wp_posts order by rand() limit 1 ";
$result = mysql_query($sql_str,$blogdb);
//echo "result=" . $result . "<br>";
$blog=mysql_fetch_array($result);
$id2use=$blog['id'];

// mod to handle blogs. Not bringing in multi lines from blog database
$numlines=1;

$lines=array();

$sql_str="select * from " . $maindbname . ".sig_track where ";
$sql_str .="ip='" . $ip2use . "' ";
$sql_str .="and refer='" . $refer2use . "' ";
$result=mysql_query($sql_str,$maindb);
//echo "sql=" . $sql_str . "<br>";
//echo "result - pull from sig_track=" . $result . "<br>";
if($result)
{
if(mysql_num_rows($result)>0)
{
$sql_str="update " . $maindbname . ".sig_track set currid='" . $id2use . "' where ";
$sql_str .="ip='" . $ip2use . "' ";
$sql_str .="and refer='" . $refer2use . "' ";
$result=mysql_query($sql_str,$maindb);
//echo "result - update sig_track=" . $result . "<br>";
}
else
{
$sql_str="insert into " . $maindbname . ".sig_track(ip, refer, currid) values(";
$sql_str .="'" . $ip2use . "', ";
$sql_str .="'" . $refer2use . "',";
$sql_str .="'" . $id2use . "')";
$result=mysql_query($sql_str,$maindb);
//echo "result - insert into sig_track=" . $result . "<br>";
}
}

$sql_str="update " . $maindbname . ".currentid set currid='" . $id2use . "'";
$result = mysql_query($sql_str,$maindb);

$line2use=$blogname . ' - ' . $blog['post_title'];
$lines[1]=$line2use;

$lines2use=1;

$imwidth=0;
$imheight=0;

// should be reading this in from table for gfy make 900
$width2use=900;

// hardcode for gfy
$maxwidth=900;
//$maxwidth=0;

$maxheight=0;
$outstr='';

$linechk=imagettfbbox($fontsize,0,$fontname, 'test');
$height2use=($linechk[1] - $linechk[7]) + 5;

for($linecnt=1;$linecnt<=$numlines;$linecnt++)
{
$workstr=$lines[$linecnt];
if (strlen($lines[$linecnt])>0)
{
$linechk=imagettfbbox($fontsize,0,$fontname, $lines[$linecnt]);
$currwidth=$linechk[2] - $linechk[0];
$parts=0;
$breakit=0;
$breaklen=0;
$holdstr='';
if($currwidth>$width2use and strlen($workstr)>0)
{
$parts=intval($currwidth/$width2use);
if (($currwidth/$width2use-$parts)>0)
{
$parts=$parts + 1;
}
}
if($parts>0)
{
$holdstr='';
$lines2use=$parts;
$breakit=$parts;
$chklen=strlen($workstr);
while($breakit>0)
{
$linechk=imagettfbbox($fontsize,0,$fontname, $workstr);
$breaklen=$linechk[2] - $linechk[0];
if($breaklen>$width2use)
{
while($breaklen>$width2use)
{
$chklen=$chklen-1;
$strtochk=substr($workstr,0,$chklen);
$linechk=imagettfbbox($fontsize,0,$fontname, $strtochk);
$breaklen=$linechk[2] - $linechk[0];
}
$currwidth=$breaklen;
$newlen=intval($chklen);
$testchar=substr($workstr,$newlen,1);
if($testchar<>' ')
{
while($testchar<>' ')
{
$newlen=$newlen-1;
$testchar=substr($workstr,$newlen,1);
}
}
$holdstr=$holdstr . substr($workstr,0,$newlen);
$workstr=trim(substr($workstr,$newlen));
$holdstr=$holdstr . chr(13) . chr(10);
$lines2use=$lines2use + 1;
$breakit=$breakit-1;
}
else
{
$breakit=$breakit-1;
}
}

$workstr=$holdstr . $workstr;
$maxheight=$maxheight + ($lines2use * $height2use);
}
else
{
$lines2use=$lines2use+1;
$maxheight=$maxheight + $height2use + 5;
}

if($currwidth>$maxwidth)
{
$maxwidth=$currwidth;
}
}
else
{
$lines2use=$lines2use+1;
$maxheight=$maxheight + $height2use + 5;
}
$outstr=$outstr . $workstr . chr(13) . chr(10);
}

//$maxwidth=$maxwidth+25;

header ("Content-type: image/gif");
$im = imagecreate ($maxwidth, $maxheight);

// hardcoded colors for gfy
$background = imagecolorallocate ($im, 51, 51, 51);
$foreground = imagecolorallocate ($im, 255, 255, 255);
imagettftext ($im, $fontsize, 0, 5, 20, $foreground, $fontname, $outstr);
imagegif ($im);
imagedestroy ($im);

?>


Database tables I am using:

--
-- Table structure for table `currentid`
--

CREATE TABLE IF NOT EXISTS `currentid` (
`currid` char(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


--
-- Table structure for table `sig_track`
--

CREATE TABLE IF NOT EXISTS `sig_track` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` char(15) NOT NULL,
`refer` varchar(254) NOT NULL,
`currid` char(10) NOT NULL,
PRIMARY KEY (`id`),
KEY `ip` (`ip`,`refer`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1102 ;



I think that does it.

Enjoy




.
__________________
All cookies cleared!

Last edited by sarettah; 05-27-2012 at 01:56 PM..
sarettah is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote