Rep Moduna Cache sistemi ekler ve sayfa başı 50 SQL sorgusu tasarruf eder
Kod:
##############################################################
## MOD Title: Renommee / Reputation - System Cache Addon
## MOD Author: BG x < [email protected] > (Tobias Hau) http://www.springenderhund.de
## MOD Description:
## Fügt zum Renommee MOD ein Cachesystem hinzu und spart somit ca. 50 SQL zugriffe pro Seite
##
##
## MOD Version: 0.1.0
##
## Installation Level: Easy
## Installation Time: 5 Minutes
##
## Files To Edit:
## includes/functions.php
## renommee.php
## admin/admin_renommee.php
## admin/admin_renommee_rang_edit.php
##
## Included Files:
## n/a
##
##############################################################
## Author Notes:
##
##
##############################################################
## MOD History:
##
## 2006-11-01 - Version 0.1.0
## - First official version
##
##############################################################
## Bevor dieser Mod in das Forum integriert wird, sollten alle zu verändernden Daten gesichert werden!
##
## //
##
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#
#-----[ DIY ]------------------------------------------
#
#
# Erstelle im Cache Verzeichniss einen neuen Ordner mit dem Namen "renom" und setze CHMOD 777 für den Ordner
#
#-----[ OPEN ]------------------------------------------------
#
includes/functions.php
#
#-----[ FIND ]------------------------------------------
#
//
// Start -> Renommee - Mod
//
// Funktion zur Anzeige der Renommeepunkte + zugehöriger Title-Tags mit Auswahl mit URL Option
function renommee_anzeige($id, $topic_id, $url_wanted)
{
global $db;
// Auslesen der Konfigurationsdaten
$sql = "SELECT * FROM " . RENOMMEE_KONFIG;
if( !$result = $db->sql_query($sql) )
{
message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
}
else
{
while( $row = $db->sql_fetchrow($result) )
{
$config_name = $row['name'];
$config_value = $row['wert'];
$renommee_rowset[$config_name] = $config_value;
}
}
$undef_text = $renommee_rowset['undef_text'];
$aktiviert = $renommee_rowset['aktiviert'];
$startwert = $renommee_rowset['standard'];
// Auslesen der benötigten Benutzerdaten
$sql = "SELECT renommee_gesamt, renommee_startwert, username
FROM " . USERS_TABLE . "
WHERE user_id = '$id'";
if ( !$result = $db->sql_query($sql) )
{
message_die(CRITICAL_ERROR, "Could not query user information", "", __LINE__, __FILE__, $sql);
}
else
{
while( $row = $db->sql_fetchrow($result) )
{
$renommee_rowset = $row;
}
}
$gesamtwert = $renommee_rowset['renommee_gesamt'];
$startwert_vergeben = $renommee_rowset['renommee_startwert'];
$username = $renommee_rowset['username'];
// Vergabe des Startwertes, wenn noch nicht getan
if ( $startwert_vergeben == 0 )
{
$gesamtwert = $gesamtwert + $startwert;
$sql = "UPDATE " . USERS_TABLE . " SET renommee_gesamt = '$gesamtwert', renommee_startwert = '1' WHERE user_id = '$id'";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Failed to update user configuration", "", __LINE__, __FILE__, $sql);
}
}
unset($row);
unset($renommee_rowset);
// Ranglistendaten aus der Datenbank + Rangtextvergabe
$sql = "SELECT * FROM " . RENOMMEE_RANGLISTE;
if ( !$result = $db->sql_query($sql) )
{
message_die(CRITICAL_ERROR, "Could not query ranking information", "", __LINE__, __FILE__, $sql);
}
else
{
while( $row = $db->sql_fetchrow($result) )
{
$renommee_rowset[] = $row;
$total_rangs++;
}
}
for ( $i = 0; $i < $total_rangs; $i++ )
{
if ( $renommee_rowset[$i]['punkte'] <= $gesamtwert AND $renommee_rowset[($i + 1)]['punkte'] > $gesamtwert )
{
$text = $renommee_rowset[$i]['text'];
}
}
unset($row);
unset($renommee_rowset);
unset($total_rangs);
// Erstellung der Ausgabe
if ( $text == "" )
{
$text = $undef_text;
}
$text = $username . " " . $text;
if ( $gesamtwert < 0 )
{
$grafik = '<img src="images/renommee_rot.gif" border="0" alt="' . $text . '" title="' . $text . '">';
}
elseif ( $gesamtwert == 0 )
{
$grafik = '<img src="images/renommee_grau.gif" border="0" alt="' . $text . '" title="' . $text . '">';
}
elseif ( $gesamtwert > 0 )
{
$sql = "SELECT * FROM " . RENOMMEE_GRAFIK_RANGLISTE;
if ( !$result = $db->sql_query($sql) )
{
message_die(CRITICAL_ERROR, "Could not query ranking information", "", __LINE__, __FILE__, $sql);
}
else
{
while( $row = $db->sql_fetchrow($result) )
{
$renommee_rowset[] = $row;
$total_rangs++;
}
}
if ( $renommee_rowset[$total_rangs - 1]['punkte'] <= $gesamtwert )
{
$anzahl = $renommee_rowset[$total_rangs - 1]['anzahl'];
}
else
{
for ( $i = 0; $i < $total_rangs; $i++ )
{
if ( $renommee_rowset[$i]['punkte'] <= $gesamtwert AND $renommee_rowset[($i + 1)]['punkte'] > $gesamtwert )
{
$anzahl = $renommee_rowset[$i]['anzahl'];
}
}
}
unset($row);
unset($renommee_rowset);
for ( $i = 0; $i < $anzahl; $i++ )
{
$grafik .= '<img src="images/renommee_gruen.gif" border="0" alt="' . $text . '" title="' . $text . '"> ';
}
}
if ($url_wanted == 1)
{
$ausgabe = '<a href="#" alt="' . $text . '" title="' . $text . '" onclick="return renommee(' . $topic_id . ')" target="renommee" style="text-decoration: none;">' . $grafik . '</a>';
}
else
{
$ausgabe = $grafik;
}
if ($aktiviert == 1 AND $id != "-1")
{
return $ausgabe;
}
}
// Funktion zur Zählung der Bewertungen seit dem letzten Login
function renommee_bewertungen($id, $last_login)
{
global $db;
// Auslesen der Renommeedaten aus der Datenbank
$sql = "SELECT id
FROM " . RENOMMEE . "
WHERE datum > '$last_login' AND ziel_id = '$id'";
if( !$result = $db->sql_query($sql) )
{
message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
}
else
{
while( $row = $db->sql_fetchrow($result) )
{
$total_bewertungen++;
}
}
return $total_bewertungen;
}
//
// End -> Renommee - Mod
//
#
#-----[ REPLACE, WITH ]------------------------------------------------
#
//
// Start -> Renommee - Mod
//
// Funktion zur Anzeige der Renommeepunkte + zugehöriger Title-Tags mit Auswahl mit URL Option
function renommee_anzeige($id, $topic_id, $url_wanted)
{
global $db, $phpEx;
// Auslesen der Konfigurationsdaten
// Config Table File Cache MOD
// alphamonkey (EAK) 7/6/2004
// scriptmaster AT alphamonkey DOT net
//
if ( file_exists($phpbb_root_path . 'cache/config_ren.' . $phpEx) ) {
include($phpbb_root_path . 'cache/config_ren.' .$phpEx);
// message_die(CRITICAL_ERROR, "Could not run required config cache file" , "", __LINE__, __FILE__, "");
}
else
{
$file_config_table_text = ARRAY();
$sql = "SELECT * FROM " . RENOMMEE_KONFIG;
if( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, "Could not query config information" , "", __LINE__, __FILE__, $sql);
}
$file_config_table_text[] = '<?php';
while ( $row = $db->sql_fetchrow($result) )
{
$renommee_rowset[$row['name']] = $row['wert'];
$file_config_table_text[] = '$renommee_rowset[' . $row['name'] . '] = "' . addslashes($row['wert']) . '";';
}
$file_config_table_text[] = '?>';
$file_config_table = fopen ( $phpbb_root_path . 'cache/config_ren.'.$phpEx, 'w');
fwrite ( $file_config_table, implode("
", $file_config_table_text) );
fclose ( $file_config_table );
}
$undef_text = $renommee_rowset['undef_text'];
$aktiviert = $renommee_rowset['aktiviert'];
$startwert = $renommee_rowset['standard'];
// Auslesen der benötigten Benutzerdaten
// cache mod start
// Change following two variables if you need to:
$cache_update = 36000; // 10 hours cache timeout. change it to whatever you want
$cache_file = $phpbb_root_path . 'cache/renom/ren-user' . $id .'.php'; // file where to store cache
$do_update = true;
if (@file_exists($cache_file))
{
$last_update = 0;
include($cache_file);
$renommee_rowset = array();
$renommee_rowset = $savedata['renommee_rowset'];
if($last_update > (time() - $cache_update))
{
$do_update = false;
}
}
if($do_update)
{
// cache mod end
$sql = "SELECT renommee_gesamt, renommee_startwert, username
FROM " . USERS_TABLE . "
WHERE user_id = '$id'";
if ( !$result = $db->sql_query($sql) )
{
message_die(CRITICAL_ERROR, "Could not query user information", "", __LINE__, __FILE__, $sql);
}
$renommee_rowset = $db->sql_fetchrowset($result);
$savedata = array();
$savedata['renommee_rowset'] = $renommee_rowset;
// Version cache mod start
$file_text = "<?\n \$last_update = " . time() . "; \$savedata = " . var_export($savedata, true) . ";\n ?>";
$handle = fopen ( $phpbb_root_path . 'cache/renom/ren-user' . $id.'.'.$phpEx, 'w');
fwrite($handle,$file_text);
fclose($handle);
}
$gesamtwert = $renommee_rowset[0]['renommee_gesamt'];
$startwert_vergeben = $renommee_rowset[0]['renommee_startwert'];
$username = $renommee_rowset[0]['username'];
// Vergabe des Startwertes, wenn noch nicht getan
if ( $startwert_vergeben == 0 )
{
$gesamtwert = $gesamtwert + $startwert;
$sql = "UPDATE " . USERS_TABLE . " SET renommee_gesamt = '$gesamtwert', renommee_startwert = '1' WHERE user_id = '$id'";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Failed to update user configuration", "", __LINE__, __FILE__, $sql);
}
}
unset($row);
unset($renommee_rowset);
// Ranglistendaten aus der Datenbank + Rangtextvergabe
if ( file_exists($phpbb_root_path . 'cache/ren_rank.' . $phpEx) ) {
include($phpbb_root_path . 'cache/ren_rank.' .$phpEx);
$renommee_rowset = array();
$renommee_rowset = $savedata['renommee_rowset'];
}
else
{
$file_config_table_text = ARRAY();
$sql = "SELECT * FROM " . RENOMMEE_RANGLISTE;
if( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, "Could not query config information" , "", __LINE__, __FILE__, $sql);
}
$renommee_rowset = $db->sql_fetchrowset($result);
$savedata = array();
$savedata['renommee_rowset'] = $renommee_rowset;
// $save_string = addslashes(serialize($savedata));
$file_text = "<?\n \$savedata = " . var_export($savedata, true) . ";\n ?>";
$handle = fopen ( $phpbb_root_path . 'cache/ren_rank.'.$phpEx, 'w');
fwrite($handle,$file_text);
fclose($handle);
}
for ( $i = 0; $i < count($renommee_rowset); $i++ )
{
if ( $renommee_rowset[$i]['punkte'] <= $gesamtwert AND $renommee_rowset[($i + 1)]['punkte'] > $gesamtwert )
{
$text = $renommee_rowset[$i]['text'];
}
}
unset($row);
unset($renommee_rowset);
unset($total_rangs);
// Erstellung der Ausgabe
if ( $text == "" )
{
$text = $undef_text;
}
$text = $username . " " . $text;
if ( $gesamtwert < 0 )
{
$grafik = '<img src="images/renommee_rot.gif" border="0" alt="' . $text . '" title="' . $text . '">';
}
elseif ( $gesamtwert == 0 )
{
$grafik = '<img src="images/renommee_grau.gif" border="0" alt="' . $text . '" title="' . $text . '">';
}
elseif ( $gesamtwert > 0 )
{
if ( file_exists($phpbb_root_path . 'cache/ren_rank_graf.' . $phpEx) ) {
include($phpbb_root_path . 'cache/ren_rank_graf.' .$phpEx);
$renommee_rowset = array();
$renommee_rowset = $savedata['renommee_rowset'];
}
else
{
$file_config_table_text = ARRAY();
$sql = "SELECT * FROM " . RENOMMEE_GRAFIK_RANGLISTE;
if( !($result = $db->sql_query($sql)) )
{
message_die(CRITICAL_ERROR, "Could not query config information" , "", __LINE__, __FILE__, $sql);
}
$renommee_rowset = $db->sql_fetchrowset($result);
$savedata = array();
$savedata['renommee_rowset'] = $renommee_rowset;
$file_text = "<?\n \$savedata = " . var_export($savedata, true) . ";\n ?>";
$handle = fopen ( $phpbb_root_path . 'cache/ren_rank_graf.'.$phpEx, 'w');
fwrite($handle,$file_text);
fclose($handle);
}
$total_rangs=count($renommee_rowset);
if ( $renommee_rowset[$total_rangs - 1]['punkte'] <= $gesamtwert )
{
$anzahl = $renommee_rowset[$total_rangs - 1]['anzahl'];
}
else
{
for ( $i = 0; $i < $total_rangs; $i++ )
{
if ( $renommee_rowset[$i]['punkte'] <= $gesamtwert AND $renommee_rowset[($i + 1)]['punkte'] > $gesamtwert )
{
$anzahl = $renommee_rowset[$i]['anzahl'];
}
}
}
unset($row);
unset($renommee_rowset);
for ( $i = 0; $i < $anzahl; $i++ )
{
$grafik .= '<img src="images/renommee_gruen.gif" border="0" alt="' . $text . '" title="' . $text . '"> ';
}
}
if ($url_wanted == 1)
{
$ausgabe = '<a href="#" alt="' . $text . '" title="' . $text . '" onclick="return renommee(' . $topic_id . ')" target="renommee" style="text-decoration: none;">' . $grafik . '</a>';
}
else
{
$ausgabe = $grafik;
}
if ($aktiviert == 1 AND $id != "-1")
{
return $ausgabe;
}
}
// Funktion zur Zählung der Bewertungen seit dem letzten Login
function renommee_bewertungen($id, $last_login)
{
global $db;
// Auslesen der Renommeedaten aus der Datenbank
$sql = "SELECT id
FROM " . RENOMMEE . "
WHERE datum > '$last_login' AND ziel_id = '$id'";
if( !$result = $db->sql_query($sql) )
{
message_die(CRITICAL_ERROR, "Could not query config information", "", __LINE__, __FILE__, $sql);
}
else
{
while( $row = $db->sql_fetchrow($result) )
{
$total_bewertungen++;
}
}
return $total_bewertungen;
}
//
// End -> Renommee - Mod
//
#
#-----[ OPEN ]------------------------------------------------
#
renommee.php
#
#-----[ FIND ]------------------------------------------------
#
$sql = "UPDATE " . USERS_TABLE . " SET renommee_gesamt = '$renommeewert_gesamt' WHERE user_id = '" . $_POST[user_id] ."'";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Failed to update information", "", __LINE__, __FILE__, $sql);
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
$id=$_POST[user_id];
if ( ! unlink ($phpbb_root_path . 'cache/renom/ren-user' . $id .'.'.$phpEx) )
{
message_die(GENERAL_ERROR, "Failed to delete cachefile cache/renom/ren-user$id.$phpEx", "", __LINE__, __FILE__, "");
}
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_renommee.php
#
#-----[ FIND ]------------------------------------------------
#
$sql = "UPDATE " . RENOMMEE_KONFIG . " SET
wert = '" . str_replace("\'", "''", $renommee_config[$config_name]) . "'
WHERE name = '$config_name'";
if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Failed to update general configuration for $config_name", "", __LINE__, __FILE__, $sql);
}
}
}
if ( isset($_POST['submit']) )
{
#
#-----[ AFTER, ADD ]------------------------------------------
#
if ( !unlink ($phpbb_root_path . 'cache/config_ren.'.$phpEx) )
{
message_die(GENERAL_ERROR, "Failed to write to cache/config_ren.$phpEx", "", __LINE__, __FILE__, "");
}
#
#-----[ FIND ]------------------------------------------------
#
$sql = "UPDATE " . USERS_TABLE . " SET
renommee_gesamt = '" . $renommee_config['standard'] . "', renommee_startwert = 1";
if ( !$result = $db->sql_query($sql) )
{
message_die(CRITICAL_ERROR, "Could not query config information in admin_board", "", __LINE__, __FILE__, $sql);
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
if ( ! unlink ($phpbb_root_path . 'cache/config_ren.'.$phpEx) )
{
message_die(GENERAL_ERROR, "Failed to write to cache/config_table.$phpEx", "", __LINE__, __FILE__, "");
}
#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_renommee_rang_edit.php
#
#-----[ FIND ]------------------------------------------------
#
// Löschen, Ändern und Hinzufügen von Rängen
if ( $_GET['mode'] == "loeschen" )
{
$sql = "DELETE FROM " . RENOMMEE_RANGLISTE . " WHERE id = '" . $_GET['id'] . "'";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, 'Could not delete', '', __LINE__, __FILE__, $sql);
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
if ( @file_exists($phpbb_root_path . 'cache/ren_rank.'.$phpEx) )
unlink ($phpbb_root_path . 'cache/ren_rank.'.$phpEx);
#
#-----[ FIND ]------------------------------------------------
#
$sql = "UPDATE " . RENOMMEE_RANGLISTE . "
SET punkte = '" . str_replace("\'", "''", $_POST['punkte']) . "', text = '" . str_replace("\'", "''", $_POST['beschreibung']) . "'
WHERE id = '" . $_POST['id'] . "'";
if( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Failed to update general configuration for $config_name", "", __LINE__, __FILE__, $sql);
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
if ( @file_exists($phpbb_root_path . 'cache/ren_rank.'.$phpEx) )
unlink ($phpbb_root_path . 'cache/ren_rank.'.$phpEx);
#
#-----[ FIND ]------------------------------------------------
#
$sql = "INSERT INTO ". RENOMMEE_RANGLISTE ." (punkte, text) VALUES ('$punkte ', '$beschreibung')";
if ( !$db->sql_query($sql) )
{
message_die(GENERAL_ERROR, "Failed to update general configuration", "", __LINE__, __FILE__, $sql);
}
#
#-----[ AFTER, ADD ]------------------------------------------
#
if ( @file_exists($phpbb_root_path . 'cache/ren_rank.'.$phpEx) )
unlink ($phpbb_root_path . 'cache/ren_rank.'.$phpEx);
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM