PHP Code:
if (@txpinterface == 'public') {
register_callback("tcm_rating_pt", 'pretext');
register_callback("tcm_rating_js", 'pretext');
}
if (@txpinterface == 'admin') {
$myevent = 'rating';
$mytab = 'ratings';
add_privs($myevent, '1,2,3,4,5');
register_tab("extensions", $myevent, $mytab);
register_callback("tcm_rating_admin", $myevent);
}
function tcm_rating_admin($event, $step)
{
if (!$step or !in_array($step, array('tcm_rating_install_db', 'tcm_rating_uninstall_db', 'tcm_rating_install_form', 'showcss', 'append_css'))) {
list_queue();
} else $step();
}
function tcm_rating_install_form($message = '')
{
tcm_rating_install_db();
pagetop("Rating Admin");
echo "<div align=\"center\" style=\"margin-top:3em\">" . sLink('rating', 'list_queue', 'List', 'navlink') . "</div>";
echo "<div align=\"center\" style=\"margin-top:3em\">";
echo form(
tag("SQL", "h3") .
graf("Drop DB Tables: " .
fInput("submit", "uninstall", "Uninstall", "publish") .
eInput("rating") . sInput("tcm_rating_uninstall_db") , " style=\"text-align:center\""));
echo "</div>";
$styleslist = safe_column("name", "txp_css", "1=1");
echo "<div align=\"center\" style=\"margin-top:3em\">";
echo form(
tag("CSS", "h3") .
graf("Append CSS to " . selectInput('css', $styleslist) .br.
"Image Path: ". fInput('text','image_path','','edit').br.
fInput("submit", "append", "Append", "publish") .
'<a target="_blank" href="?event=rating&step=showcss"
onclick="window.open(this.href, \'popupwindow\',\'width=600, height=600,scrollbars,resizable\'); return false;">View CSS</a>'
. eInput("rating") . sInput("append_css") , " style=\"text-align:center\"")
);
echo "</div>";
}
function append_css()
{
$name = gps('css');
$image_path = gps('image_path');
$thecss = base64_decode(fetch("css", 'txp_css', 'name', $name));
$append_css = return_css($image_path);
$newcss = base64_encode($thecss . $append_css);
$rs = safe_update("txp_css", "css = '" . $newcss . "'", "name = '$name'");
if ($rs) {
tcm_rating_install_form("CSS Append successful");
} else {
tcm_rating_install_form("CSS Append failed");
}
}
function showcss()
{
$image_path = (gps('image_path')) ? gps('image_path') : "";
echo <<< HEADSECTION
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Textpattern: Rating CSS View</title>
</head>
<body>
HEADSECTION;
echo form(
"Image Path: ". fInput('text','image_path','','edit').
fInput("submit", "showcss", "Show CSS", "publish")
. eInput("rating") . sInput("showcss") , " style=\"text-align:center\"");
echo tcm_textarea('500', '550', htmlentities(return_css($image_path)), 'css');
exit;
}
function tcm_textarea($h, $w, $content, $name)
{
return '<textarea name="' . $name . '" style="height:' . $h . 'px;width:' . $w . 'px;font-family:monaco,courier,courier new;font-size:10px;margin-top:6px" rows="1" cols="1">' . htmlspecialchars($content) . '</textarea>';
}
function tcm_rating_install_db()
{
$sql = "CREATE TABLE IF NOT EXISTS `" . PFX . "txp_tcm_rqueue` (
`parent_id` int(11) NOT NULL default '0',
`id` int(11) NOT NULL auto_increment,
`ip` varchar(30) NOT NULL default '',
`rating` int(11) NOT NULL default '0',
`posted` datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (`id`),
KEY `ip` (`ip`),
KEY `posted` (`posted`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
$rs = safe_query($sql);
$sql2 = "CREATE TABLE IF NOT EXISTS `" . PFX . "txp_tcm_rsum` (
`id` int(10) NOT NULL auto_increment,
`parent_id` int(10) unsigned NOT NULL default '0',
`ratings` int(11) NOT NULL default '0',
`sum` int(11) NOT NULL default '0',
`average` float NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `parent_id` (`parent_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;";
$rs2 = safe_query($sql2);
if ($rs && $rs2) {
//echo pagetop("Install Rating System", "installation successful");
safe_delete("txp_tcm_rqueue", "posted < date_sub(now(),interval 1 day)");
} else {
//echo pagetop("Install Rating System", "installation failed");
}
}
function tcm_rating_uninstall_db()
{
$rs = safe_query("DROP TABLE IF EXISTS `txp_tcm_rqueue`;");
$rs2 = safe_query("DROP TABLE IF EXISTS `txp_tcm_rsum`;");
if ($rs && $rs2) {
tcm_rating_install_form("uninstallation successful");
} else {
tcm_rating_install_form("uninstallation failed");
}
}
function list_queue($message = '')
{
tcm_rating_install_db();
if (isset($message)) {
pagetop("View Rating Queue", $message);
} else {
pagetop("View Rating Queue");
}
$page = gps('page');
$total = getCount('txp_tcm_rqueue', "1");
$limit = 40;
$numPages = ceil($total / $limit);
$page = (!$page) ? 1 : $page;
$offset = ($page - 1) * $limit;
$nav[] = ($page > 1)
? PrevNextLink("rating", $page-1, gTxt('prev'), 'prev') : '';
$nav[] = sp . small($page . '/' . $numPages) . sp;
$nav[] = ($page != $numPages)
? PrevNextLink("rating", $page + 1, gTxt('next'), 'next') : '';
/*
$rs = safe_rows_start("*, unix_timestamp(posted) as stamp",
"txp_tcm_rqueue",
"1 order by posted desc limit $offset, $limit"
);
*/
$rs = safe_rows_start_joined("*, unix_timestamp(".PFX."txp_tcm_rqueue.posted) as stamp", Array('textpattern', 'txp_tcm_rqueue'),
PFX."txp_tcm_rqueue.parent_id = ".PFX."textpattern.ID ".' order by '.PFX."txp_tcm_rqueue.posted desc limit $offset, $limit");
if ($rs) {
echo tag("Rating Queue", "h3", " style='text-align: center'");
echo startTable('list'),
assHead('time', 'host', 'article', 'rating'),
tr(tdcs(sLink('rating', 'tcm_rating_install_form', 'Install & Admin', 'navlink'), '4'));
while ($a = nextRow($rs)) {
extract($a);
$fstamp = date("n/j g:i a", ($stamp + tz_offset()));
//
echo tr(
td($fstamp) .
td(tag($ip, 'a', ' href="http://www.dnsstuff.com/tools/city.ch?ip='.$ip.'" ')) .
td(tag($Title, 'a', ' href="'.tcm_permlinkurl($a).'"')) .
td(rating_dots($rating)));
unset($fstamp, $ip, $parent_id, $rating);
}
echo '<tr><td colspan="4" align="right" style="padding:10px">',
join('', $nav),
"</td></tr>";
echo endTable();
}
}
// -------------------------------------------------------------
function tcm_permlinkurl($article_array)
{
global $permlink_mode, $prefs;
if (isset($prefs['custom_url_func']) and is_callable($prefs['custom_url_func']))
return call_user_func($prefs['custom_url_func'], $article_array);
if (empty($article_array)) return;
extract($article_array);
if (!isset($title)) $title = $Title;
if (empty($url_title)) $url_title = stripSpace($title);
if (empty($section)) $section = $Section; // lame, huh?
if (empty($posted)) $posted = $Posted;
if (empty($thisid)) $thisid = $ID;
switch($permlink_mode) {
case 'section_id_title':
if ($prefs['attach_titles_to_permalinks'])
{
return hu."$section/$thisid/$url_title";
}else{
return hu."$section/$thisid/";
}
case 'year_month_day_title':
list($y,$m,$d) = explode("-",date("Y-m-d",$posted));
return hu."$y/$m/$d/$url_title";
case 'id_title':
if ($prefs['attach_titles_to_permalinks'])
{
return hu."$thisid/$url_title";
}else{
return hu."$thisid/";
}
case 'section_title':
return hu."$section/$url_title";
case 'title_only':
return hu."$url_title";
case 'messy':
return hu."index.php?id=$thisid";
}
}
Bookmarks