<?php
/**
* Quicklinks Class
*
* Display links in a block that will popup links in a new window without
* a navigation bar and toolbar. Based on phpquote originally by Joe Stump
* (miester.org). Final conversion to phpWebSite by Seyed Razavi.
*
* This module adapted from phpWebSite plugin phpquicklinks by Michael Diehl
* <hide@address.com>
*
* @author Edward Ritter <hide@address.com>
* @verson $Id: quicklinks.inc.php,v 1.5 2002/09/04 23:55:11 esritter Exp $
* @module quicklinks
* @package phpWebSite
*/
class quicklinks {
/**
* add - adds new link
*
* @author Edward Ritter
* @param int id: link id.
* @param string link: link
* @param string text: link title
* @param int xsize: horizontal size of new window
* @param int ysize: vertical size of new window
*/
function add($link, $text, $xsize, $ysize) {
global $table_prefix;
$link = (!get_magic_quotes_gpc())?addslashes ($link):$link;
$text = (!get_magic_quotes_gpc())?addslashes ($text):$text;
if (!is_numeric ($xsize) || !is_numeric ($ysize)) {
$boxtitle = "Input Error";
$boxcontent = "The window size values need to be numeric only";
} else {
mysql_query ("INSERT INTO " . $table_prefix . "mod_quicklinks
(link, text, xsize, ysize) VALUES ('$link', '$text', '$xsize',
'$ysize')") or die ("Couldn't add link to table: " . mysql_error());
$boxtitle = "Link Added";
$boxcontent = "<a href=\"./mod.php?mod=quicklinks&op=quicklinks_admin\">Return to Quicklinks Admin</a>";
}
themesidebox($boxtitle, $boxcontent);
}
/**
* modify - displays form for editing / deleting links.
*
* @author Edward Ritter
* @param int id: link id.
*/
function modify($id) {
global $table_prefix;
$get_link = mysql_query ("SELECT link, text, xsize, ysize FROM " . $table_prefix . "mod_quicklinks WHERE id='$id'");
list ($link, $text, $xsize, $ysize) = mysql_fetch_row ($get_link);
$boxtitle = "Edit Link";
$boxcontent .= $this->form('update', $id, $link, $text, $xsize, $ysize);
themesidebox ($boxtitle, $boxcontent);
}
/**
* delete - deletes link
*
* @author Edward Ritter
* @param int id: link id.
*/
function delete($id) {
global $confirm, $table_prefix;
if ($confirm) {
mysql_query ("DELETE FROM " . $table_prefix . "mod_quicklinks WHERE id='$id'") or
die ("Couldn't delete link from table: " . mysql_error());
$boxtitle = "Link Deleted";
$boxcontent = "<a href=\"./mod.php?mod=quicklinks&op=quicklinks_admin\">Return to Quicklinks Admin</a>";
} else {
$result = mysql_query ("SELECT link, text FROM " . $table_prefix . "mod_quicklinks WHERE id='$id'");
list ($link, $text) = mysql_fetch_row ($result);
$boxtitle = "Are you sure you wish to delete link \"$link\" -> ($text)?";
$boxcontent = "<a href=\"./mod.php?mod=quicklinks&op=quicklinks_admin&adminop=delete&confirm=true&id=$id\">YES</a>
<a href=\"mod.php?mod=quicklinks&op=quicklinks_admin\">NO</a>";
}
themesidebox($boxtitle, $boxcontent);
}
/**
* update - updates link in table.
*
* @author Edward Ritter
* @param int id: link id.
* @param string link: link
* @param string text: link title
* @param int xsize: horizontal size of new window
* @param int ysize: vertical size of new window
*/
function update($id, $link, $text, $xsize, $ysize) {
global $table_prefix;
$link = (!get_magic_quotes_gpc())?addslashes ($link):$link;
$text = (!get_magic_quotes_gpc())?addslashes ($text):$text;
if (!is_numeric ($xsize) || !is_numeric ($ysize)) {
$boxtitle = "Input Error";
$boxcontent = "The window size values need to be numeric only";
} else {
$result = mysql_query ("UPDATE " . $table_prefix . "mod_quicklinks
SET link ='$link', text='$text', xsize ='$xsize',
ysize ='$ysize' WHERE id='$id'") or
die ("Couldn't update link in table: " . mysql_error());
$boxtitle = "Link Updated";
$boxcontent = "<a href=\"mod.php?mod=quicklinks&op=quicklinks_admin\">Return to Quicklinks Admin</a>.";
}
themesidebox($boxtitle, $boxcontent);
}
/**
* show_block - displays quicklinks block on index page
*
* @author Edward Ritter
* @return content: links.
*/
function show_block() {
global $table_prefix;
include ("./mod/quicklinks/quicklinks_config.php");
if ($randomlinks) {
$result = mysql_query ("SELECT * FROM " . $table_prefix . "mod_quicklinks");
$num_rows = mysql_num_rows ($result);
// only proceed if we have links in the database
if ($result > 0 && $num_rows > 0) {
// Create the random id for the link
srand((double)microtime()*1000000);
$random = 1;
if ($num_rows > 1) {
$random = rand(1,$num_rows);
}
/* Now that we have the random number we can pull out
the record also make sure we hit an existing link if
not we do a query again */
$havelink = 0;
while ($havelink != $random) {
$myrow = mysql_fetch_array ($result);
// make sure we stop this loop when we do have a link
if (is_array ($myrow)) {
$havelink = $havelink + 1;
}
}
// this is the start of the content for the link block
$content = 'Random Link<br/>';
$javascript .= "<script>function pop_rand() { new_rand=window.open('".$myrow[1]."','rand','toolbar=".$toolbar.",resizable=yes,scrollbars=yes,menubar=".$navbar.",width=".$myrow[3].",height=".$myrow[4]."');}</script>";
$content .= "<a href=\"javascript:pop_rand();\" onmouseover=\"top.status='".$myrow[2]."';return true;\"> ". $myrow[2] ." </a> <br/>";
return $javascript . $content;
} else {
// this is what we say when the links database is empty
$content .= "<br/>No links available yet.";
return $content;
}
} else {
$result = mysql_query ("SELECT * FROM " . $table_prefix .
"mod_quicklinks order by id");
$num_rows = mysql_num_rows ($result);
if ($result > 0 && $num_rows > 0) {
$content .= "External Links<br/>";
$javascript = "<script> ";
$i = 0;
while (list ($id, $link, $text,$xsize,$ysize) = mysql_fetch_row ($result)) {
$javascript .= "function pop_".$i."() { new_".$i."=window.open('".$link."','".$i."','toolbar=".$toolbar.",resizable=yes,scrollbars=yes,menubar=".$navbar.",width=".$xsize.",height=".$ysize."');}";
$content .= "<a href=\"javascript:pop_".$i++."();\" onmouseover=\"top.status='".$text."';return true;\"> ". $text ." </a> <br/>";
}
$javascript .= " </script>";
return $javascript . $content;
} else {
$content .= "<br/>No links available yet.";
return $content;
}
}
}
/**
* admin - admin functions for quicklinks block
*
* allows admin to add, modify, and delete links.
*
* @author Edward Ritter
* @param none
*/
function admin() {
global $table_prefix;
// Build Add Form
$boxtitle = "Add QuickLink";
$boxcontent = $this->form('add');
themesidebox($boxtitle,$boxcontent);
// Build Update/Delete Form
$result = mysql_query ("SELECT id, text FROM " . $table_prefix . "mod_quicklinks");
if (mysql_num_rows ($result) > 0) {
$boxtitle = "Edit Quicklinks";
$boxcontent = "<form action=\"./mod.php\" method=\"post\">
<select name=\"id\">";
while (list ($id, $text) = mysql_fetch_row ($result)) {
$boxcontent .= "<option value=\"$id\">$text</option>";
}
$boxcontent .= "</select><input type=\"hidden\" name=\"mod\" value=\"quicklinks\" />
<input type=\"hidden\" name=\"op\" value=\"quicklinks_admin\" />
<input type=\"hidden\" name=\"adminop\" value=\"modify\" />
<input type=\"submit\" value=\"Edit Link\" /></form>";
themesidebox($boxtitle,$boxcontent);
}
}
/**
* form - displays form for adding or modifying a quote
*
* @author Edward Ritter
* @param string op: add or modify
* @param int id: quote id (for modify)
* @param string link: link url
* @param string text: link title
* @param int xsize: horizontal size of new window
* @param int ysize: vertical size of new window
*/
function form($op, $id='', $link='', $text='', $xsize='', $ysize='') {
$content = "<form action=\"mod.php\" method=\"post\">
<input type=\"hidden\" name=\"mod\" value=\"quicklinks\" />";
if ($id) {
$content .= "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
}
if (!$xsize && !$ysize) {
$xsize = 0;
$ysize = 0;
}
$content .= "<input type=\"hidden\" name=\"op\" value=\"quicklinks_admin\" />
<input type=\"hidden\" name=\"adminop\" value=\"$op\" />
Link Title: <input class=\"textbox\" type=\"text\" name=\"text\" size=\"31\" maxlength=\"128\" value=\"$text\" /><br/>
Link URL: <br/>
<textarea class=\"textbox\" name=\"link\" cols=\"60\" rows=\"2\">$link</textarea><br />
New Window Size: <input type=\"text\" name=\"xsize\" size=4 value=\"$xsize\" /> by
<input type=\"text\" name=\"ysize\" size=\"4\" value=\"$ysize\" />
<em>Leave these at zero for full size window</em><br/>
<div align=\"center\">";
if ($op == "update") {
$content .= " <a href=\"./mod.php?mod=quicklinks&op=quicklinks_admin&adminop=delete&id=$id\">delete link</a> | ";
}
$content .= "<input type=\"submit\" value=\"$op\" /></div></form>";
return $content;
}
}
?>