Jump to content

Ticker script php questions...


Lilyfox

Recommended Posts

I posted before about help with my ticker script, and I finally got that bit sorted. I have everything working almost how I would like, but there are a few things I would like to tweak but I don't know how to. Any help would be much appreciated.

 

Here is an example of a working ticker:

ticker9.png

 

(The whole script is attached to this message)

 

1) I want to change the font & size of the generated text. I would like it to be Arial, or Verdana with the size at about 10. How can I change this?

 

2) It's start and end date on the ticker itself is too close to the edges. How can I move this in more so it appears something like this:

examplekc0.jpg

 

3) How do I remove the numbers? In the first ticker, you see the numbers in between the rope and the countdown text. It's not in the original graphic.

 

4) Is there a way to add a starting date to the script? It only has an ending date. I'd love to be able to pick a starting date rather than it choosing today's date.

 

I think that's all I need changed. I hope one of you can help me! Thank you in advance.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/79624-ticker-script-php-questions/
Share on other sites

Sorry, the last time I asked for help that is what I did and I thought it was fine.

 

Thank you.

 

The config file:

<?
/*
CONFIGURATION FILE.
GD Ticker using PNG banners and sliders.
By: Josh Houghtelin <[email protected]> www.burnmytime.com
*/

$sql_username = "mysql-username"; // SQL username
$sql_password = "mysql-password"; // SQL password
$sql_database = "mysql-database"; // SQL database name
$sql_host = "localhost"; // Normally localhost.

$default_ticker = 40; // Standard ticket number when called without a serial number.
$default_banner_image = "banners/ruler-10722.png"; // Failsafe banner
$default_slider_image = "sliders/icon-88.png";  // Failsafe slider

$use_modrewrite = "no"; // "yes" or "no" ..  Default:no

 

 

My SQL file:

 

<?php
class db {

    function db($sql_host,$sql_username,$sql_password,$sql_database){
	// CHANGE THESE TO CORRECT VALUES
        mysql_connect($sql_host,$sql_username,$sql_password) or die("MySQL Connection Failed");
        mysql_select_db($sql_database) or die("Could Not Select Database");
    }

    function query($sql){
        $result = mysql_query($sql) or die(mysql_error() . "<br>" . $sql);
        return $result;

    }

    function fetch($sql){
        $result = $this->fetch_row($this->query($sql));
        return $result;
    }

    function fetch_row($set){
        $result = mysql_fetch_row($set);
        return $result;

    }

    function fetch_array($set){
        $result = mysql_fetch_array($set);
        return $result;
    }

    function insert_id(){
        $id = mysql_insert_id();
        return $id;

    }

    function dbCall($field, $table="config"){
        list($ret) = $this->fetch_row($this->query("select $field from $table limit 1"));
        return $ret;
    }

    function setting($setting){
        list($ret) = $this->fetch_row($this->query("select value from Config WHERE setting='$setting'"));
        return $ret;
    }

    function num_rows($set){
        $result = mysql_num_rows($set);
        return $result;
    }

    function getCount($table, $where=''){
        $sql = "select count(*) from " . $table;
        if ($where != ''){ $sql .= " where " . $where; }
        list($count) = $this->fetch_row($this->query($sql));
        return $count;
    }

    function getDatabaseDetails(){
    global $database;
    $result = $this->query("show table status from $database");
        $size = 0;
        $oh = 0;
        if ($result){
            while( $row = $this->fetch_array($result)){
                $size += $row[Data_length] + $row[index_length];
                $oh += $row[Data_free];
            }
        }
        $ret[size] = number_format($size/1048576, 2) . " MB";
        $ret[overhead] = $oh . " bytes";
        return $ret;

    }

}
$db = new db($sql_host,$sql_username,$sql_password,$sql_database);
?>

 

 

Index.php

 

<?php 
/*
GD Ticker using PNG banners and sliders.
By: Josh Houghtelin <[email protected]> www.burnmytime.com

*/

header("Content-type: image/png"); //This script IS the image.
require_once('includes/Config.inc.php'); // Keep the config seperate.
require_once('includes/Mysql.inc.php'); // Never forget the MySQL abstraction layer.

if(isset($_GET['serial'])){$serial = $_GET[serial];}
else{$serial = $default_ticker;}

$result = $db->query("SELECT start, end, event, banner, slider FROM Ticker WHERE id='$serial'");
list($start_date, $end_date, $event, $banner_image, $slider_image) = $db->fetch_row($result);

$today_date = time();
$current_step = round(((($today_date - $start_date)/60)/60)/24) - 1;
$interval = round(((($end_date - $start_date)/60)/60)/24);

$remaining = $interval - $current_step;
if($remaining == 0){
$string = $event." has arrived!";
}elseif($remaining == 1){
$string = "Only $remaining day left until ".$event;
}else{
$string = "$remaining days until ".$event;
}

if(!is_file($banner_image)){
$banner_image = $default_banner_image; //"banners/ruler-10300.png";
}

if(!is_file($slider_image)){
$slider_image = $default_slider_image; //"sliders/icon-104.png";
}

$banner = imagecreatefrompng($banner_image);
$bannerheight = imagesy($banner);
$bannerwidth = imagesx($banner);
$one_step = (($bannerwidth - 20) / $interval);

$black = imagecolorallocate($banner,0,0,0);

// Numbers on the bottom of the banner.
$count_step = round($interval / 12);
$count = $interval;
$count2 = 0;
while($count>=0){
$px = (($bannerwidth - 20) / $interval) * $count2 + 5;
$interval_height = $bannerheight - 25;
imagestring($banner, 2, $px, $interval_height,$count, $black);
	$count = $count - $count_step;
	$count2 = $count2 + $count_step;
}

$slider = imagecreatefrompng($slider_image);
$sliderheight = imagesy($slider);
$sliderwidth = imagesx($slider);
$slider_location = $one_step * $current_step + 5 - ($sliderwidth / 2);

imagecopy($banner,$slider,$slider_location,0,0,0,$sliderheight,$sliderwidth);

$string_height = $bannerheight - 13;
$px    = (imagesx($banner) - 7.5 * strlen($string)) / 2;
imagestring($banner, 3, $px, $string_height, $string, $black);

imagepng($banner);
imagedestroy($banner);
//imagedestroy($slider);
?> 

 

 

new.php (the page that creates a new ticker)

 

<LINK href="style.css" rel="stylesheet" type="text/css">

<?
require_once("includes/Config.inc.php");
require_once("includes/Mysql.inc.php");
if(isset($_POST[event])){
$today_date = time();
$end_date = date("U",mktime(0,0,0,$_POST[eventmonth],$_POST[eventday],$_POST[eventyear]));

if($end_date < $today_date){
		echo "<b>Ending Date MUST come after todays date.</b> <br />";
		echo "<a href='./new.php'>Try Again</a>";
		exit();
}

$initial_gap = round(((($end_date - $today_date)/60)/60)/24);

if($initial_gap < 6){
	$start_date = date("U",mktime(0,0,0,date("n"),date("j")-6,date("Y")));
}else{
	$start_date = date("U",mktime(0,0,0,date("n"),date("j"),date("Y")));
}

$end_date = date("U",mktime(0,0,0,$_POST[eventmonth],$_POST[eventday],$_POST[eventyear]));

$event = strip_tags($_POST[event]);
if(strlen($event)==0){$event = "it is time!";}

if(!is_file($_POST[banner])){$banner = "banners/ruler-10722.png";}
else{$banner = $_POST[banner];}

if(!is_file($_POST[slider])){$slider = "sliders/icon-88.png";}
else{$slider = $_POST[slider];}

$insert = $db->query("INSERT INTO Ticker (start, end, event, banner, slider) VALUES('$start_date','$end_date','$event','$banner','$slider')");
if($insert){
	echo "<b>You have created a new banner</b> <br />";
	$banner = $db->insert_id();
	if($user_modrewrite=="YES"){
	echo "<img src='./$banner'> <br />";
	echo "Link: <a href='./$banner'>Link to Image</a>";
	}else{
	echo "<img src='./?serial=$banner'> <br />";
	echo "Link: <a href='./?serial=$banner'>Link to Image</a>";
	}
	echo "<hr><br />";
}
}

?>

<form method=post action='new.php'>
<table class='dashedoutline'><tr><td>Event Date:</td><td></tr></table>
<select name=eventmonth class='1'></td></tr></table>
<?
$count = 1;
while($count<13){
$display_date = date("M",mktime(0,0,0,$count,0,date("Y")));
$numeric_date = date("n",mktime(0,0,0,$count,0,date("Y")));
if($numeric_date == date("n")){
	echo "<option value=$numeric_date SELECTED>$display_date</option> \n";
}else{
	echo "<option value=$numeric_date>$display_date</option> \n";
}
$count++;
}
?>
</select>
<select name=eventday class=1>
<?
$count = 1;
while($count<=31){
if($count == date("j")){
	echo "<option SELECTED>$count</option> \n";
}else{
	echo "<option>$count</option> \n";
}
$count++;
}
?>
</select>
<select name=eventyear>
<option SELECTED>2007</option>
<option>2008</option>
<option>2009</option>
<option>2010</option>
</select> <br /> <br />

Event Name:<input type=text name=event maxlength=30> <br />

Select Banner <br />
<table border=0>
<?php
if ($handle = opendir('banners')) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {
           echo "<tr><td valign=top><input type=radio name=banner value='banners/$file'></td><td><img src='banners/$file'></td></tr>";
       }
   }
   closedir($handle);
}
?>
</table>

Select Slider <br />
<table border=0>
<?php
if ($handle = opendir('sliders')) {
   while (false !== ($file = readdir($handle))) {
       if ($file != "." && $file != "..") {
           echo "<tr><td valign=top><input type=radio name=slider value='sliders/$file'></td><td><img src='sliders/$file'></td></tr>";
       }
   }
   closedir($handle);
}
?>
</table>

<input type=submit value='Generate Ticker'>
</form>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.