<?php
//function library
/*------------------------------------------------------------------------
ComicPub - A program designed to aid and assist the author of web comics in
their publishment on the 'innernet'
Copyright (C) 2003 Tim Bielawa
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
------------------------------------------------------------------------*/
//this function server to pop up the actual menu that you see when you click a help link
require("vars.php");
function pop_help($word, $useme){
$stripped_word = str_replace(" ", '', $word);
echo "<a href=\"javascript:popUp('get_help.php?" . $stripped_word . "')\">" . $useme . "</a>";
}
//this is used in the 'post a new comic' page to list the avaliable comics to use
function list_files(){
echo "<select name='comics' size='7' style='width: 150px; height: 125px; font-family: arial, verdana;'>\n";
global $directory;
$directory = './comics/';
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "\t<option value='" . $file . "'>$file\n";
}
}
closedir($handle);
}
echo "</select>\n";
}
function list_files_selected($which){ //this is used to
echo "<select name='comics' size='7' style='width: 150px; height: 125px; font-family: arial, verdana;'>\n";
global $directory;
$directory = './comics/';
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if("$file" == "$which"){
echo "\t<option selected value='" . $file . "'>$file\n";
} else {
echo "\t<option value='" . $file . "'>$file\n";
}
}
}
closedir($handle);
}
echo "</select>\n";
}
//gets total number of comics posted to date
function get_total_comics(){
global $site;
$link = mysql_connect("$site[mysql_host]", "$site[mysql_name]", "$site[mysql_pass]") or die(mysql_error());
mysql_select_db($site[mysql_prefix] . $site[mysql_db]) or die(mysql_error());
$q = "SELECT * FROM `" . $mysql_prefix . "comics`";
$res = mysql_query($q);
return mysql_num_rows($res);
}
function get_comic_data($id){ //ths comics in handy for getting info for nearly anything you need to do 2004-1-7
global $site;
$link = mysql_connect("$site[mysql_host]", "$site[mysql_name]", "$site[mysql_pass]") or die(mysql_error());
mysql_select_db($site[mysql_prefix] . $site[mysql_db]) or die(mysql_error());
$q = "SELECT * FROM `comics` WHERE `id` = '" . $id . "'";
$res = @mysql_query($q);
if($data = @mysql_fetch_array($res)){
return $data;
} else {
$error = "ERROR";
return $error;
}
}
function remove_comic($id) {
global $site;
$link = mysql_connect("$site[mysql_host]", "$site[mysql_name]", "$site[mysql_pass]") or die(mysql_error());
mysql_select_db($site[mysql_prefix] . $site[mysql_db]) or die(mysql_error());
$data = get_comic_data($id); //use this for the message below. so i can get comic title and id before it's removed
$q = "DELETE FROM `comics` WHERE `id` = '$id' LIMIT 1";
if(@mysql_query($q)){
echo "Comic \"" . $data[title] . "\" with id number: " . $id . " has been removed.";
} else {
echo mysql_error();
}
}
function previous_comic($timestamp){ //time stamp is the comic it has to work off of
global $site;
$link = mysql_connect("$site[mysql_host]", "$site[mysql_name]", "$site[mysql_pass]") or die(mysql_error());
mysql_select_db($site[mysql_prefix] . $site[mysql_db]) or die(mysql_error());
$q = "SELECT * FROM `comics`";
$res = mysql_query($q);
$comics = ARRAY();
$i = 0;
// echo "<PRE>";
while($e = mysql_fetch_assoc($res)){
$comics[] = $e;
if($e[time] == $timestamp){
$element = $i;
$i++;
} else {
$i++;
}
// print_r($e);
}
$last = $element - 1;
$previous = $comics[$last][id]; //last comic entity (this - 1) field 'id'
$data = get_comic_data($comics[$element][id]);
if(end_cap($data[id]) !== "FIRST"){
echo "<a href='" . $site[absurl] . "/" . $site[view] . "?" . $previous . "'><img src='images/left_arrow.gif' border='0' alt='previous comic'></a> ";
} else {
echo "<img src='images/left_arrow.gif' border='0'> ";
}
}
function next_comic($timestamp){
global $site;
$link = mysql_connect("$site[mysql_host]", "$site[mysql_name]", "$site[mysql_pass]") or die(mysql_error());
mysql_select_db($site[mysql_prefix] . $site[mysql_db]) or die(mysql_error());
$q = "SELECT * FROM `comics`";
$res = mysql_query($q);
$comics = ARRAY();
$i = 0;
while($e = mysql_fetch_assoc($res)){
$comics[] = $e;
if($e[time] == $timestamp){
$element = $i;
$i++;
} else {
$i++;
}
}
$next = $element + 1;
$comics = $comics[$next][id];
$data = get_comic_data($comics[$element][id]);
if(end_cap($data[id]) !== "LAST"){
echo "<a href='" . $site[absurl] . "/" . $site[view] . "?" . $comics . "'><img src='images/right_arrow.gif' border='0' alt='next comic'></a>\n";
} else {
echo "<img src='images/right_arrow.gif' border='0'> ";
}
}
function latest_comic(){
$q = "SELECT `id` as 'id' FROM `comics` ORDER BY `id` DESC LIMIT 0,1";
$res = mysql_query($q);
$this_comic = mysql_result($res, 0, 'id');
/////////////////////////////////////////////////////////////////////////
$q = "SELECT * FROM `comics`";
$res = mysql_query($q);
$comics = ARRAY();/*
while($e = mysql_fetch_assoc($res)){
$comics[] = $e;
if($e[time] == $timestamp) {
$
$element = $
if(end_cap($data[id]) !== "LAST"){*/
return $this_comic;
}
function first_comic(){
$q = "SELECT * FROM `comics` ORDER BY `id` ASC LIMIT 0,1";
$res = mysql_query($q);
$first = mysql_fetch_assoc($res);
echo "<a href='" . "";
}
function end_cap($id){ //test if a comic selected is first or last comic and return a flag
$id = get_comic_data($id); //get data on prespective comic
$q = "SELECT * FROM `comics` ORDER BY `id` DESC LIMIT 0,1";
$res = mysql_query($q);
$ish = mysql_fetch_assoc($res);
if($id[id] == $ish[id]){//is the comic the most recent one posted?
$message = "LAST";
}
$q = "SELECT * FROM `comics` ORDER BY `id` ASC LIMIT 0,1";
$res = mysql_query($q);
$ish = mysql_fetch_assoc($res);
if($id[id] == $ish[id]){ //is the comic the first one posted?
$message = "FIRST";
}
if(!$message){ //comic is not first or last. return "no"
$message = 'NO'; //for debugging of course
}
return $message;
}
function get_comic_title($id){
$data = get_comic_data($id);
$title = $data[title];
echo $title;
}
function get_comments_amount($id){ //see how many comments are associated with any particular comic
$q = "SELECT * FROM `comments` WHERE `association` = " . $id;
$res = mysql_query($q);
if($total_comments != @mysql_num_rows($res)){
$total_comments = 0;
}
return $total_comments;
}
function view_comments_link($id){
$q = "SELECT * FROM `comics` WHERE `id` = " . $id;
$res = mysql_query($q);
if($e = mysql_fetch_assoc($res)){
if(get_comments_amount($id) >= 1 && $e[allow_comments] == 1){
echo "<a href='comments.php?" . $id . "'>Comments(" . get_comments_amount($id). ")</a>";
} elseif($e[allow_comments] == 0) {
echo "<a href='comments.php?" . $id . "'>Author Comment</a>";
} elseif(get_comments_amount($id) == 0 && $e[allow_comments] == 1){
echo "<a href='comments.php?" . $id . "'>Comments(0)</a>";
} else {
echo "<a href='comments.php?" . $id . "'>Author Comment</a>";
}
// echo "Comic exists";
} else {
echo "<b>Comic doesnt exist</b>";
}
}
?>