Location: PHPKode > projects > AdaptBB > plugins/post_totals.php
<?php
$protect = "yes";
$plugin_name = "Post Totals";
$plugin_url = "admin.php?view=plugins&do=load&plugin=".strtolower(str_replace(" ", "_", $plugin_name));
$plugin_version = "1.0";
$url = strtolower(str_replace(" ", "_", $plugin_name)).".php";

$apage = basename($_SERVER['PHP_SELF']);
$siteurl = "http://".$_SERVER['HTTP_HOST'].str_replace($apage, "", $_SERVER['PHP_SELF']);
$url = $_GET['url'];

if ($_GET['check'] == "status") {
echo 1;
}

if ($module == "install_".$url) {
$tot = 0;
if (mysql_num_rows(mysql_query("SELECT * FROM ".$pre."plugins WHERE name = '".$plugin_name."'")) > 1) {
echo "<b>".$plugin_name."</b> Plugin already installed. <a href='admin.php?view=plugins&do=install'>Return</a>";
} else {
echo "Beginning to install the <b>".$plugin_name."</b> Plugin...<br /><br />";
$query1 = mysql_query("INSERT INTO ".$pre."plugins VALUES (null, '".$plugin_name."', '".$_GET['url']."', '".$plugin_version."', 'On')");
if ($query1 == TRUE) {
$tot = $tot + 1;
echo "`".$pre."plugins` MySQL data row Inserted? <font color='green'>True</font><br />";
} else {
echo "`".$pre."plugins` MySQL data row Inserted? <font color='red'>False</font><br />";
}
if ($tot == 1) {
echo "<br /><b>".$plugin_name."</b> Plugin installed <font color='green'>Sucessfully!</font>. <a href='".$plugin_url."'>".$plugin_name." Plugin</a>";
} else {
echo "<br /><b>".$plugin_name."</b> Plugin installed <font color='red'>Un-Sucessfully!</font>. Please check mysql settings and if need be, please submit a <a href='admin.php?view=support'>support ticket</a>.";
}
}
}

if ($module == "uninstall_".$url) {
$tot = 0;
if (mysql_num_rows(mysql_query("SELECT * FROM ".$pre."plugins WHERE name = '".$plugin_name."'")) > 1) {
echo "<b>".$plugin_name."</b> Plugin already un-installed, or not yet installed. <a href='admin.php?view=plugins&do=install'>Return</a>";
} else {
echo "Beginning to un-install the <b>".$plugin_name."</b> Plugin...<br /><br />";
$query1 = mysql_query("DELETE FROM ".$pre."plugins WHERE name = '".$plugin_name."'");
if ($query1 == TRUE) {
$tot = $tot + 1;
echo "`".$pre."plugins` MySQL data row Deleted? <font color='green'>True</font><br />";
} else {
echo "`".$pre."plugins` MySQL data row Deleted? <font color='red'>False</font><br />";
}
if ($tot == 1) {
echo "<br /><b>".$plugin_name."</b> Plugin un-installed <font color='green'>Sucessfully!</font>. <a href='admin.php?view=plugins'>Plugins</a>";
echo $data;
} else {
echo "<br /><b>".$plugin_name."</b> Plugin un-installed <font color='red'>Un-Sucessfully!</font>. Please check mysql settings and if need be, please submit a <a href='admin.php?view=support'>support ticket</a>.";
echo $data;
}
}
}

if (basename($_SERVER['PHP_SELF']) == "admin.php") {
if ($module == "") {
echo "<b>Directory</b>&nbsp;&nbsp;-&nbsp;&nbsp;<a href='admin.php?view=plugins'>Plugins</a> / <a href='".$plugin_url."'>".$plugin_name." Plugin</a><br /><br /><br />";

echo "<form action='".$plugin_url."&module=submit' method='post'><table cellpadding='5' cellspacing='0' border='0' width='90%' align='center' style='border: 2px solid #dddddd'><tr style='background:url(".$siteurl."inc/images/topbg.jpg) repeat-x;'><td><td><b>".$plugin_name."</b></td></tr><tr><td><b>Post Totals</b></td><td><input type='checkbox' class='input' name='posts_total' checked></td></tr><tr><td><b>Topic Totals</b></td><td><input type='checkbox' class='input' name='topics_total' checked></td></tr><tr><td><input type='submit' value='Update Data' class='input'></td><td>&nbsp;</td></tr></table></form>";
echo "<br /><center><small>For each thing you check, the totals will be reset. This should only be necessary once in a while, or really only if you notice a problem.</small></center>";
}

if ($module == "submit") {
if ($p[0]) {
echo "<b>Directory</b>&nbsp;&nbsp;-&nbsp;&nbsp;<a href='admin.php?view=plugins'>Plugins</a> / <a href='".$plugin_url."'>".$plugin_name." Plugin</a><br /><br /><br />";

if ($_POST['posts_total']) {
$update = 0;
$sql = mysql_query("SELECT * FROM ".$pre."posts WHERE post_type != 'post' ORDER BY `id` DESC");
while($rd = mysql_fetch_array($sql)) {
unset($id);
$id = $rd[forum_id];
$check = mysql_num_rows(mysql_query("SELECT * FROM ".$pre."posts WHERE post_type = 'post' AND topic_id = '".$rd[id]."'"));
//echo $rd[id]."-".$check."/".$rd[post_count]."<br>";
/*
if (!$topic_count[$id]) {
$topic_count[$id] = 0;
}
if (!$post_count[$id]) {
$post_count[$id] = 0;
}
*/
$post_count[$id] = $post_count[$id] + $check;
$topic_count[$id] = $topic_count[$id] + 1;

if ($check != $rd[post_count]) {
mysql_query("UPDATE ".$pre."posts SET post_count = '".$check."' WHERE id = '".$rd[id]."'");
$update = $update + 1;
}
}
}

$sql2 = mysql_query("SELECT * FROM ".$pre."forums WHERE section_id > 0 ORDER BY `ord` ASC");
while($re = mysql_fetch_array($sql2)) {
unset($id);
$id = $re[id];

if (!$topic_count[$id]) {
$topic_count[$id] = 0;
}
if (!$post_count[$id]) {
$post_count[$id] = 0;
}

//echo $id."-".$post_count[$id]."/".$re[post_count]." ".$topic_count[$id]."/".$re[topic_count]."<br>";

if ($post_count[$id] != $re[post_count] && $_POST['posts_total']) {
mysql_query("UPDATE ".$pre."forums SET post_count = '".$post_count[$id]."' WHERE id = '".$id."'");
$update = $update + 1;
}
if ($topic_count[$id] != $re[topic_count] && $_POST['topics_total']) {
mysql_query("UPDATE ".$pre."forums SET topic_count = '".$topic_count[$id]."' WHERE id = '".$id."'");
$update = $update + 1;
}
}

//echo re_direct("1500", "admin.php?view=tools");
echo "<b>".$update."</b> totals were updated. <a href='".$plugin_url."'>Return</a>";
}
}

}

if (basename($_SERVER['PHP_SELF']) == "index.php") {
if ($module == strtolower(str_replace(" ", "_", $plugin_name))) {
echo 1;
}
}
?>
Return current item: AdaptBB