Code: Alles auswählen
<?php
/***********************************************
* CONTENIDO MODUL - OUTPUT
*
* Modulname : vpGuestbook 1.9.1 - Ausgabe
* Author : Ingo van Peeren
* Copyright : Ingo van Peeren (ingo@van-peeren.de)
* Created : 2005-03-14
* Modified : 2006-02-14
************************************************/
// CMS_VARs initialisieren
$spez_client = "CMS_VALUE[1]";
$spez_lang = "CMS_VALUE[2]";
$tpl_datei = "CMS_VALUE[3]";
$tpl_art = "CMS_VALUE[4]";
$bilderpfad = "CMS_VALUE[5]";
$eintraege_pro_seite = "CMS_VALUE[6]";
$seitennav_art = "CMS_VALUE[7]";
$dateformat1 = "CMS_VALUE[8]";
$dateformat2 = "CMS_VALUE[9]";
$locale = "CMS_VALUE[10]";
$wrap_length = "CMS_VALUE[11]";
$link_vor = "CMS_VALUE[12]";
$link_zurueck = "CMS_VALUE[13]";
$max_seiten = "CMS_VALUE[14]";
// CMS_VARs initialisieren Ende
// eXtended-Template-Klasse (von swelpot) einbinden
// zur Verwendung siehe:
// http://www.contenido.org/forum/viewtopic.php?t=5851
if ($tpl_art == "extended") cInclude('classes', 'class.ExtendedTemplate.php');
else cInclude('classes', 'class.template.php');
$edit_url = "front_content.php?changeview=edit&client=$client&lang=$lang&action=con_editart&idartlang=$idartlang&idart=$idart&idcat=$idcat&contenido=" . $sess->id;
// locale auf ausgewählten Wert setzen
setlocale (LC_ALL, $locale);
// DB-Verbindung konfigurieren
$cfg["tab"]["vpguestbook"] = $cfg['sql']['sqlprefix']."_vpguestbook";
$db = new DB_Contenido;
// Funktionen
function htmlwrap($str, $width = 60, $break = "\n", $nobreak = "", $nobr = "pre", $utf = false) {
// Split HTML content into an array delimited by < and >
// The flags save the delimeters and remove empty variables
$content = preg_split("/([<>])/", $str, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
// Transform protected element lists into arrays
$nobreak = explode(" ", $nobreak);
$nobr = explode(" ", $nobr);
// Variable setup
$intag = false;
$innbk = array();
$innbr = array();
$drain = "";
$utf = ($utf) ? "u" : "";
// List of characters it is "safe" to insert line-breaks at
// Do not add ampersand (&) as it will mess up HTML Entities
// It is not necessary to add < and >
$lbrks = "/?!%)-}]\\\"':;";
// We use \r for adding <br /> in the right spots so just switch to \n
if ($break == "\r") $break = "\n";
while (list(, $value) = each($content)) {
switch ($value) {
// If a < is encountered, set the "in-tag" flag
case "<": $intag = true; break;
// If a > is encountered, remove the flag
case ">": $intag = false; break;
default:
// If we are currently within a tag...
if ($intag) {
// If the first character is not a / then this is an opening tag
if ($value{0} != "/") {
// Collect the tag name
preg_match("/^(.*?)(\s|$)/$utf", $value, $t);
// If this is a protected element, activate the associated protection flag
if ((!count($innbk) && in_array($t[1], $nobreak)) || in_array($t[1], $innbk)) $innbk[] = $t[1];
if ((!count($innbr) && in_array($t[1], $nobr)) || in_array($t[1], $innbr)) $innbr[] = $t[1];
// Otherwise this is a closing tag
} else {
// If this is a closing tag for a protected element, unset the flag
if (in_array(substr($value, 1), $innbk)) unset($innbk[count($innbk)]);
if (in_array(substr($value, 1), $innbr)) unset($innbr[count($innbr)]);
}
// Else if we're outside any tags...
} else if ($value) {
// If unprotected, remove all existing \r, replace all existing \n with \r
if (!count($innbr)) $value = str_replace("\n", "\r", str_replace("\r", "", $value));
// If unprotected, enter the line-break loop
if (!count($innbk)) {
do {
$store = $value;
// Find the first stretch of characters over the $width limit
if (preg_match("/^(.*?\s|^)(([^\s&]|&(\w{2,5}|#\d{2,4});){".$width."})(?!(".preg_quote($break, "/")."|\s))(.*)$/s$utf", $value, $match)) {
// Determine the last "safe line-break" character within this match
for ($x = 0, $ledge = 0; $x < strlen($lbrks); $x++) $ledge = max($ledge, strrpos($match[2], $lbrks{$x}));
if (!$ledge) $ledge = strlen($match[2]) - 1;
// Insert the modified string
$value = $match[1].substr($match[2], 0, $ledge + 1).$break.substr($match[2], $ledge + 1).$match[6];
}
// Loop while overlimit strings are still being found
} while ($store != $value);
}
// If unprotected, replace all \r with <br />\n to finish
if (!count($innbr)) $value = str_replace("\r", "<br />\n", $value);
}
}
// Send the modified segment down the drain
$drain .= $value;
}
// Return contents of the drain
return $drain;
}
function toggle_active ($entry) {
global $db, $cfg;
$sql = "UPDATE ".$cfg["tab"]["vpguestbook"]." SET active = '1' WHERE id='$entry'";
$db->query($sql);
}
function toggle_inactive ($entry) {
global $db, $cfg;
$sql = "UPDATE ".$cfg["tab"]["vpguestbook"]." SET active = '0' WHERE id='$entry'";
$db->query($sql);
}
function eintrag_loeschen ($entry) {
global $db, $cfg;
$sql = "DELETE FROM ".$cfg["tab"]["vpguestbook"]." WHERE id='$entry'";
$db->query($sql);
}
function eintraege_zaehlen () {
global $db, $cfg, $client;
$sql = "SELECT COUNT(*) as anzahl FROM ".$cfg["tab"]["vpguestbook"]." WHERE client=$client AND active=1";
$db->query($sql);
$db->next_record();
return $db->f("anzahl");
}
function eintraege_auslesen ($start, $anzahl) {
global $db, $cfg, $client, $lang, $idart, $spez_client, $spez_lang, $edit;
if ($edit && empty($_GET['edit'])) $where = "WHERE 1";
else $where = "WHERE active=1";
if ($spez_client) $where .= " AND client=$client";
if ($spez_lang) $where .= " AND lang=$lang";
$sql = "SELECT id, active, name, email, url, entry, image, comment, iphost, user1, user2, user3, UNIX_TIMESTAMP(date) as datum FROM ".$cfg["tab"]["vpguestbook"]." $where ORDER BY date DESC LIMIT $start, $anzahl";
$db->query($sql);
$eintraege = array();
$i = 0;
while ($db->next_record()) {
$eintraege[$i]['id'] = $db->f("id");
$eintraege[$i]['active'] = $db->f("active");
$eintraege[$i]['name'] = $db->f("name");
$eintraege[$i]['email'] = $db->f("email");
$eintraege[$i]['url'] = $db->f("url");
$eintraege[$i]['entry'] = $db->f("entry");
$eintraege[$i]['image'] = $db->f("image");
$eintraege[$i]['comment'] = $db->f("comment");
$eintraege[$i]['iphost'] = $db->f("iphost");
$eintraege[$i]['user1'] = $db->f("user1");
$eintraege[$i]['user2'] = $db->f("user2");
$eintraege[$i]['user3'] = $db->f("user3");
$eintraege[$i]['date'] = $db->f("datum");
$i++;
}
return $eintraege;
}
function vpgb_navigation ($start, $eintraege_pro_seite, $anzahl_eintraege, $art = 1) {
global $link_vor, $link_zurueck, $idcat, $idcatart, $max_seiten;
$hier = "front_content.php?idcatart=" . $idcatart;
$vpgb_nav = "";
if ($start > 0) {
$vpgb_nav .= "<a href=\"" . $hier . "&start=" . ($start - $eintraege_pro_seite) . "\">" . $link_zurueck . "</a>";
}
if ($anzahl_eintraege > $eintraege_pro_seite) {
$anzahl_seiten = ceil($anzahl_eintraege / $eintraege_pro_seite);
if (($max_seiten == "") || ($max_seiten > $anzahl_seiten)) {
for ($h = 1; $h <= $anzahl_seiten; $h++) {
$hstart = ($h - 1) * $eintraege_pro_seite;
if ($art == 1) {
if ($h == $anzahl_seiten) {
if ($anzahl_eintraege > ($hstart + 1)) $htext = ($hstart + 1) . "-" . $anzahl_eintraege;
else $htext = $anzahl_eintraege;
}
else $htext = ($hstart + 1) . "-" . ($hstart + $eintraege_pro_seite);
}
else $htext = $h;
if ($hstart == $start) $vpgb_nav .= " <a class=\"vpgb_aktiv\" href=\"" . $hier . "&start=" . $hstart . "\">" . $htext . "</a>";
else $vpgb_nav .= " <a href=\"" . $hier . "&start=" . $hstart . "\">" . $htext . "</a>";
}
}
else {
for ($h = 1; $h <= $anzahl_seiten; $h++) {
$hstart = ($h - 1) * $eintraege_pro_seite;
if ($art == 1) {
if ($h == $anzahl_seiten) {
if ($anzahl_eintraege > ($hstart + 1)) $htext = ($hstart + 1) . "-" . $anzahl_eintraege;
else $htext = $anzahl_eintraege;
}
else $htext = ($hstart + 1) . "-" . ($hstart + $eintraege_pro_seite);
}
else $htext = $h;
if (($hstart < $eintraege_pro_seite * 2) || ($hstart > (($anzahl_seiten - 3) * $eintraege_pro_seite)) || (($hstart > ($start - ($eintraege_pro_seite * 2))) && ($hstart < ($start + ($eintraege_pro_seite * 2))))) {
if ($hstart == $start) $vpgb_nav .= " <a class=\"vpgb_aktiv\" href=\"" . $hier . "&start=" . $hstart . "\">" . $htext . "</a>";
else $vpgb_nav .= " <a href=\"" . $hier . "&start=" . $hstart . "\">" . $htext . "</a>";
}
else $vpgb_nav .= "###";
}
}
}
if (($start + $eintraege_pro_seite) < $anzahl_eintraege) {
$vpgb_nav .= " <a href=\"" . $hier . "&start=" . ($start + $eintraege_pro_seite) . "\">" . $link_vor . "</a>";
}
$vpgb_nav = preg_replace("/(\#+)/", " <span class=\"vpgb_punkte\">…</span>", $vpgb_nav);
return $vpgb_nav;
}
function edit_comment ($entry_id, $new_entry, $type) {
global $db, $cfg, $client;
if ($type == "delete") {
$sql = "UPDATE ".$cfg["tab"]["vpguestbook"]." SET comment = '' WHERE id='$entry_id'";
$db->query($sql);
}
else {
$sql = "UPDATE ".$cfg["tab"]["vpguestbook"]." SET comment = '$new_entry' WHERE id='$entry_id'";
$db->query($sql);
}
}
// Funktionen Ende
if ($edit && empty($_GET['edit'])) {
if ($_GET['toggle_active'] == "yes") toggle_active($_GET['entry']);
if ($_GET['toggle_inactive'] == "yes") toggle_inactive($_GET['entry']);
if ($_GET['delete'] == "yes") eintrag_loeschen($_GET['entry']);
if ($_POST['edit_comment']) edit_comment($_GET['entry'], $_POST['kommentar'], "edit");
if ($_POST['delete_comment']) edit_comment($_GET['entry'], $_POST['kommentar'], "delete");
}
if (! $_GET['start']) $start = 0;
else $start = $_GET['start'];
// Einträge
$anzahl_eintraege = eintraege_zaehlen();
if ($edit && empty($_GET['edit'])) {
$eintraege = eintraege_auslesen(0, 10000);
$seitennavigation = "";
}
else {
$eintraege = eintraege_auslesen($start, $eintraege_pro_seite);
if ($seitennav_art == 1) $seitennavigation = vpgb_navigation($start, $eintraege_pro_seite, $anzahl_eintraege, 1);
else $seitennavigation = vpgb_navigation($start, $eintraege_pro_seite, $anzahl_eintraege, 0);
}
if ($tpl_art == "extended") $tpl = new ExtendedTemplate();
else $tpl = new Template;
$tpl->reset();
$tpl->set('s', 'EINTRAEGE', $anzahl_eintraege);
$tpl->set('s', 'SEITENNAVIGATION', $seitennavigation);
foreach ($eintraege as $eintrag) {
if ($edit && empty($_GET['edit'])) {
$tpl->set('d', 'EDIT', "1");
if ($eintrag['active']) $adminlinks = "<a href=\"" . $edit_url . "&toggle_inactive=yes&entry=" . $eintrag['id'] . "\"><img src=\"" . $cfg['path']['contenido_fullhtml'] . "images/online.gif\" width=\"11\" height=\"12\" border=\"0\" title=\"Offline schalten\" alt=\"Offline schalten\"></a>";
else $adminlinks = "<a href=\"" . $edit_url . "&toggle_active=yes&entry=" . $eintrag['id'] . "\"><img src=\"" . $cfg['path']['contenido_fullhtml'] . "images/offline.gif\" width=\"11\" height=\"12\" border=\"0\" title=\"Online schalten\" alt=\"Online schalten\"></a>";
$adminlinks .= '<a title="Modul löschen" href="' . $edit_url . '&delete=yes&entry=' . $eintrag['id'] . '" onClick="return confirm(\'Wollen Sie den Gästebucheintrag von ' . $eintrag['name'] . ' wirklich löschen?\')" ><img src="' . $cfg['path']['contenido_fullhtml'] . 'images/delete.gif" border="0" title="Eintrag löschen" alt="Eintrag löschen"></a>';
$comment = "<form action=\"" . $edit_url . "&entry=" . $eintrag['id'] . "\" method=\"post\">";
$comment .= "<textarea name=\"kommentar\">" . htmlentities($eintrag['comment'], ENT_QUOTES) . "</textarea><input type=\"submit\" name=\"edit_comment\" value=\"ändern\"> <input type=\"submit\" name=\"delete_comment\" value=\"löschen\">";
$comment .= "</form>";
}
else {
$comment = htmlwrap(htmlentities($eintrag['comment'], ENT_QUOTES), $wrap_length, " ");
}
$tpl->set('d', 'NAME', $eintrag['name']);
$tpl->set('d', 'EMAIL', $eintrag['email']);
$tpl->set('d', 'URL', $eintrag['url']);
$tpl->set('d', 'ENTRY', htmlwrap($eintrag['entry'], $wrap_length, " "));
$tpl->set('d', 'COMMENT', $comment);
$tpl->set('d', 'USER1', $eintrag['user1']);
$tpl->set('d', 'USER2', $eintrag['user2']);
$tpl->set('d', 'USER3', $eintrag['user3']);
$tpl->set('d', 'IPHOST', $eintrag['iphost']);
$tpl->set('d', 'IMAGE', $cfgClient[$client]['upload'].$bilderpfad.$eintrag['image']);
$tpl->set('d', 'DATE1', strftime($dateformat1, $eintrag['date']));
$tpl->set('d', 'DATE2', strftime($dateformat2, $eintrag['date']));
$tpl->set('d', 'ADMINLINKS', $adminlinks);
$tpl->next();
}
$tpl->generate('templates/' . $tpl_datei);
?>
Das wird natürlich auch in der nächsten gepackten Version mit drin sein.