also nochmal, das ganze posting war jetzt weg...
ich hab ein paar änderungen vorgenommen beim modul.txt
hier der code
module.txt
Code: Alles auswählen
Der folgende PHP-Code muss so eingefügt werden, dass er bei jedem Seitenzugriff aufgerufen wird:
(Zum Beispiel in einem Modul oder am Ende der front_content.php)
//----- cut -----
/* Include the plugin configuration */
$handle = opendir($cfg['path']['contenido'] . $cfg["path"]['plugins'] );
while ($plugin = readdir($handle))
{
$configfile = $cfg['path']['contenido'] . $cfg["path"]['plugins'] . $plugin . "/includes/config.plugin.php";
if (@file_exists($configfile))
{
include($configfile);
}
}
if (isset($cfg['plugins']['agents'])) {
$plugin = true;
} else {
$plugin = false;
}
if ($plugin) {
$db = new DB_Contenido;
// Filter prüfen
$sqlq = 'SELECT filterid FROM '.$cfg["tab"]["filter"].' WHERE "'.$HTTP_USER_AGENT.'" LIKE value';
$db->query($sqlq);
if (!$db->next_record()){
// Wenn Agent unbekannt => hinzufügen
$sqlq = 'SELECT agentid FROM '.$cfg["tab"]["agent"].' WHERE name = "'.$HTTP_USER_AGENT.'"';
$db->query($sqlq);
if (!$db->next_record()){
$sqli="INSERT INTO ".$cfg["tab"]["agent"]." (name) VALUES ('".$HTTP_USER_AGENT."')";
$db->query($sqli);
$db->query($sqlq);
$db->next_record();
}
$agentid = $db->f("agentid");
// Wenn IP unbekannt => hinzufügen
$sqlq = 'SELECT hostid FROM '.$cfg["tab"]["host"].' WHERE ip = "'.$REMOTE_ADDR.'"';
$db->query($sqlq);
if (!$db->next_record()){
$sqli="INSERT INTO ".$cfg["tab"]["host"]." (ip) VALUES ('".$REMOTE_ADDR."')";
$db->query($sqli);
$db->query($sqlq);
$db->next_record();
}
$hostid = $db->f("hostid");
// Visit updaten / hinzufügen
$sqlq = 'SELECT visitid, hits FROM '.$cfg["tab"]["visit"].' WHERE agentid = "'.$agentid.'" AND hostid = "'.$hostid.'" AND date = "'.date("Y-m-d").'"';
$db->query($sqlq);
if (!$db->next_record()){
$sqli="INSERT INTO ".$cfg["tab"]["visit"]." (agentid,hostid,date,hits) VALUES ('".$agentid."','".$hostid."','".date("Y-m-d")."','1')";
$db->query($sqli);
$db->query($sqlq);
$db->next_record();
}
else{
$visitid = $db->f("visitid");
$hits = $db->f("hits") + 1;
$sqlu="UPDATE ".$cfg["tab"]["visit"]." SET hits='".$hits."', date='".date("Y-m-d")."' WHERE visitid='".$visitid."'";
$db->query($sqlu);
}
}
}
//----- cut -----
vorteil hier ist das die $cfg definition der config.plugin.php ausgelesen werden...
sobald $cfg["plugins"]["agents"] gesetzt ist wird der code ausgeführt...
die variablen für den db zugriff stehen dann ebenso sofort zur verfügung
$cfg["tab"]["visit"], $cfg["tab"]["host"], $cfg["tab"]["filter"], $cfg["tab"]["agents"]
ebenso hab ich das ganze für den plugin installer aufbereitet...
ein direktes einfügen der sql statements in die db ist somit nicht mehr nötig... der sql prefix wird automatisch vergeben, ebenso wie wie der areaid werte...
zusätzlich werden die con_sequence einträge vorgenommen...
der plugin installer besteht aus drei dateien...
install.php install.sql uninstall.sql*(optional)
die uninstall.sql enthält die daten zum entfernen der erstellten tabellen und con_sequence einträge... sollte sie nicht vorhanden sein bleiben die tabellen und einträge bestehen...
hier der code
install.sql
Code: Alles auswählen
####Plugin Agents;0.0.0.1;Cavegn Christian;ID_RUBBISH00####
#
# Tabellen für Agents
#
CREATE TABLE !PREFIX!_agents_agent (
agentid INT NOT NULL auto_increment,
name CHAR(128) NOT NULL,
PRIMARY KEY (agentid)
);
CREATE TABLE !PREFIX!_agents_visit (
visitid INT NOT NULL auto_increment,
agentid INT NOT NULL,
hostid INT NOT NULL,
date DATE NOT NULL,
hits INT NOT NULL,
PRIMARY KEY (visitid)
);
CREATE TABLE !PREFIX!_agents_host (
hostid INT NOT NULL auto_increment,
ip CHAR(15) NOT NULL,
host CHAR(128) NULL,
PRIMARY KEY (hostid)
);
CREATE TABLE !PREFIX!_agents_filter (
filterid INT NOT NULL auto_increment,
type CHAR(5) NOT NULL,
value CHAR(128) NOT NULL,
PRIMARY KEY (filterid)
);
#
# Einträge für Contenido Tabellen
#
# con_sequence entries... not used by now
INSERT INTO !PREFIX!_sequence VALUES ('!PREFIX!_agents_agent', '1');
INSERT INTO !PREFIX!_sequence VALUES ('!PREFIX!_agents_visit', '1');
INSERT INTO !PREFIX!_sequence VALUES ('!PREFIX!_agents_host', '1');
INSERT INTO !PREFIX!_sequence VALUES ('!PREFIX!_agents_filter', '1');
INSERT INTO !PREFIX!_area VALUES ('!PID!00', '0', 'agents', '1', '1');
# if you use menuless batch
INSERT INTO !PREFIX!_area VALUES ('!PID!00', '0', 'agents', '1', '1', '0');
INSERT INTO !PREFIX!_files VALUES ('!PID!01', '!PID!00', 'agents/includes/include.agents_edit.php', 'main');
INSERT INTO !PREFIX!_files VALUES ('!PID!02', '!PID!00', 'agents/includes/include.agents_left_top.php', 'main');
INSERT INTO !PREFIX!_files VALUES ('!PID!03', '!PID!00', 'agents/includes/include.agents_menu.php', 'main');
INSERT INTO !PREFIX!_files VALUES ('!PID!04', '!PID!00', 'include.subnav_blank.php', 'main');
INSERT INTO !PREFIX!_frame_files VALUES ('!PID!01', '!PID!00', '4', '!PID!01');
INSERT INTO !PREFIX!_frame_files VALUES ('!PID!02', '!PID!00', '1', '!PID!02');
INSERT INTO !PREFIX!_frame_files VALUES ('!PID!03', '!PID!00', '2', '!PID!03');
INSERT INTO !PREFIX!_frame_files VALUES ('!PID!04', '!PID!00', '3', '!PID!04');
# die 4 ist das vierte menu, also statistik
INSERT INTO !PREFIX!_nav_sub VALUES ('!PID!00', '4', '!PID!00', '0', 'agents/xml/lang_de_DE.xml;navigation/statistic/agents', '1');
uninstall.sql
Code: Alles auswählen
#
# Eigene Tabellen
#
DELETE FROM !PREFIX!_sequence WHERE seq_name = '!PREFIX!_agents_agent';
DELETE FROM !PREFIX!_sequence WHERE seq_name = '!PREFIX!_agents_visit';
DELETE FROM !PREFIX!_sequence WHERE seq_name = '!PREFIX!_agents_host';
DELETE FROM !PREFIX!_sequence WHERE seq_name = '!PREFIX!_agents_filter';
DROP TABLE !PREFIX!_agents_agent;
DROP TABLE !PREFIX!_agents_visit;
DROP TABLE !PREFIX!_agents_host;
DROP TABLE !PREFIX!_agents_filter;
install.php
Code: Alles auswählen
<?php
/* PLUGIN INSTALLER
* Version 0.3
* Für Contenido 4.4.4 and up 4.5.x
* Autor: Martin Horwath (horwath@dayside.net)
* Datum: 26.09.2004
* Modifiziert: 29.11.2004
*/
$contenido_path = '../../';
include_once ($contenido_path . 'includes/config.php');
cInclude ("includes", 'functions.general.php');
$cfg["debug"]["backend_exectime"]["fullstart"] = getmicrotime();
cInclude ("includes", 'functions.i18n.php');
cInclude ("includes", 'functions.api.php');
cInclude ("includes", 'functions.general.php');
cInclude ("includes", 'functions.database.php');
cInclude ("classes", 'class.xml.php');
cInclude ("classes", 'class.navigation.php');
cInclude ("classes", 'class.template.php');
cInclude ("classes", 'class.backend.php');
cInclude ("classes", 'class.notification.php');
cInclude ("classes", 'class.area.php');
cInclude ("classes", 'class.action.php');
cInclude ("classes", 'class.layout.php');
cInclude ("classes", 'class.treeitem.php');
cInclude ("classes", 'class.user.php');
cInclude ("classes", 'class.group.php');
cInclude ("classes", 'class.cat.php');
cInclude ("classes", 'class.client.php');
cInclude ("classes", 'class.inuse.php');
cInclude ("classes", 'class.table.php');
cInclude ("includes", 'functions.str.php');
page_open(array('sess' => 'Contenido_Session',
'auth' => 'Contenido_Challenge_Crypt_Auth',
'perm' => 'Contenido_Perm'));
i18nInit($cfg["path"]["contenido"].$cfg["path"]["locale"], $belang);
cInclude ("includes", 'cfg_language_de.inc.php');
class DB_Upgrade extends DB_Contenido {
}
$cfg["debug"]["installer"] = false;
$checktablestatus = true;
/* Instanzen der DB_Contenido */
$db = new DB_Contenido;
$db2 = new DB_Contenido;
$db_str = new DB_Contenido;
$cfg["debug"]["backend_exectime"]["start"] = getmicrotime();
/* con_sequence update */
if ($checktablestatus) {
$required_fields = Array( "idplugin",
"name",
"version",
"author",
"idinternal",
"url",
"status",
"description",
"install",
"uninstall",
"date");
$required_table = "DROP TABLE ".$cfg['tab']['plugins'].";
CREATE TABLE ".$cfg['tab']['plugins']." (
idplugin INT(10) NOT NULL default '0',
name VARCHAR(60) default NULL,
version VARCHAR(10) NOT NULL default '0',
author VARCHAR(60) default NULL,
idinternal VARCHAR(32) NOT NULL default '0',
url TEXT,
status INT(10) NOT NULL default '0',
description TEXT,
install TEXT,
uninstall TEXT,
date DATETIME NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY (idplugin)
) TYPE=MyISAM;";
// now we check if the plugin table has the right format...
msg( "Checking status ". $cfg['tab']['plugins']);
$ptable = $db->metadata($cfg['tab']['plugins']);
foreach ($ptable as $key) {
if (!in_array($key['name'], $required_fields)) {
msg( $key['name']." (this key can be deleted)", "unused key");
} else {
$availableKeys[] = $key['name'];
}
$foundkeys[] = $key['name'];
}
foreach ($required_fields as $key) {
if (!in_array($key, $foundkeys)) {
msg( $key." (this key must be added)", "missing key");
$missingKeys[] = $key;
}
}
unset ($foundkeys, $key);
// available elements in table are stored in array -> $availableKeys;
// missing elements in table are stored in array -> $missingKeys;
// this is a possible way to handle new versions of plugin installer
// since this is initial release the table will be dropped and recreated
// when a missing element is found.
if (count($missingKeys) > 0) {
$sql_data = remove_remarks($required_table);
$sql_pieces = split_sql_file($sql_data, ';');
msg(count($sql_pieces)." queries", "Executing:");
foreach ($sql_pieces as $sqlinit) {
$db->query($sqlinit);
msg($sqlinit);
}
} else {
msg("ok");
}
}
echo '<html><body style="font-family: Verdana; font-size:11px;">';
// installer starts here
echo "<b>PLUGIN INSTALLER</b><br><br>\n";
$clink = "<br><a href=\"../../index.php?contenido=$contenido\">Switch to backend</a>\r\n";
if ($installsql = file_get_contents('install.sql')) {
// get info from sql file
if (preg_match ("/####(.*)####/i", $installsql, $pinfo)) {
$pinfo = explode (";",$pinfo[1]);
// take some nice names easier to work with...
$pname = $pinfo[0];
$pversion = $pinfo[1];
$pauthor = $pinfo[2];
$pinternalid = $pinfo[3];
unset($pinfo);
// first show info
echo "Plugin Name: ".$pname."<br>\n";
echo "Plugin Version: ".$pversion."<br>\n";
echo "Author: ".$pauthor."<br>\n";
echo "Internal ID: ".$pinternalid."<br>\n";
// the user don't need this info...
$installsql = preg_replace ("/####(.*)####/i", "", $installsql);
$pstatus = true;
} else {
echo "Info missing. First line of install.sql should include following line:<br>";
echo "<b>####NAME;VERSION;AUTHOR;INTERNAL_ID####</b><br>";
echo "No further action takes place<br>";
$pstatus = false;
}
// check if idinternal is allready available in table
$sql = "SELECT * FROM ".$cfg["tab"]["plugins"]." WHERE idinternal='".$pinternalid."';";
$db->query($sql);
if ($db->next_record()) {
$mode = "update";
$message .= "Plugin with this internal id allready exists in table.<br>\n";
if ($pversion == $db->f('version')) {
$message .= "This version is allready installed.<br>\n";
$mode = "uninstall";
} else {
$message .= "Switching to upgrade mode.<br>\n";
}
$pluginid = $db->f('idplugin');
} else {
$mode = "install";
$message .= "No plugin with this internal id exists in table.<br>\n";
$pluginid = getSequenceId($cfg["tab"]["plugins"]);
}
if (!$install && !$uninstall) {
echo "<br>".$message;
}
if (!$install && $mode!="uninstall") {
echo "<br><a href=$PHP_SELF?install=1&contenido=$contenido>Install $pname $pversion</a></br>";
}
if (!$uninstall && $mode=="uninstall") {
echo "<br><a href=$PHP_SELF?uninstall=1&contenido=$contenido>UnInstall $pname $pversion</a></br>";
}
if ($uninstall) {
$sql = "SELECT uninstall FROM ".$cfg["tab"]["plugins"]." WHERE idplugin='".$pluginid."'";
msg($sql);
$db->query($sql);
$db->next_record();
$uninstallsql = $db->f('uninstall');
$sql_data = remove_remarks($uninstallsql);
$sql_pieces = split_sql_file($sql_data, ';');
msg(count($sql_pieces)." queries", "Executing:");
foreach ($sql_pieces as $sqlinit) {
$db->query($sqlinit);
msg($sqlinit);
}
echo "<br><b>Uninstall complete.</b><br>\r\n";
}
if ($pstatus && $install) {
$PID = 100 + $pluginid; // generate !PID! replacement
$replace = array('!PREFIX!' => $cfg['sql']['sqlprefix'],
'!PID!' => $PID);
$installsql = strtr($installsql, $replace);
if($mode == "install") { // insert all data from install.sql
$sql = "INSERT INTO ".$cfg["tab"]["plugins"]." (idplugin,name,`version`,author,idinternal,`status`,`date`) VALUES ('".$pluginid."','".$pname."','".$pversion."','".$pauthor."','".$pinternalid."','0','".date("Y-m-d H:i:s")."');";
$uninstallsql = "DELETE FROM ".$cfg["tab"]["plugins"]." WHERE idplugin='".$pluginid."';\r\n";
msg($sql);
$db->query($sql);
msg ($installsql, "Install query:");
$sql_data = remove_remarks($installsql);
$sql_pieces = split_sql_file($sql_data, ';');
msg(count($sql_pieces)." queries", "Executing:");
foreach ($sql_pieces as $sqlinit) {
//$sqlinit = strtr($sqlinit, $replace);
// create uninstall.sql for each insert entry
if (preg_match("/INSERT\s+INTO\s+(.*)\s+VALUES\s*\([´\"'\s]*(\d+)/i", $sqlinit, $tmpsql) ) {
$tmpidname = $db->metadata(trim($tmpsql[1]));
$tmpidname = $tmpidname[0]['name'];
$uninstallsql = "DELETE FROM ".trim($tmpsql[1])." WHERE ".$tmpidname."='".trim($tmpsql[2])."';\r\n".$uninstallsql;
}
$db->query($sqlinit);
msg($sqlinit);
}
if ($uninstallsqlfile = file_get_contents('uninstall.sql')) {
$uninstallsqlfile = remove_remarks($uninstallsqlfile); // remove all comments
$uninstallsql .= strtr($uninstallsqlfile, $replace); // add to generated sql
echo "I found uninstall.sql in ".dirname(__FILE__)."<br>Statements added to uninstall query.<br>\n";
}
msg ($uninstallsql, "Uninstall query:");
$sql = "UPDATE ".$cfg["tab"]["plugins"]." SET install=0x".bin2hex($installsql).", uninstall=0x".bin2hex($uninstallsql)." WHERE (idplugin='".$pluginid."');";
msg($sql,"un/install statements stored");
$db->query($sql);
echo "<br><b>Install complete.</b><br>\r\n";
}
if($mode == "update") {
echo "yes here is something to do for you...<br>\n";
}
/* con_sequence update */
updateSequence();
}
} else {
echo "Sorry i found no install.sql in ".dirname(__FILE__)."<br>\n";
}
//echo $clink;
showmsg();
echo '</body></html>';
// some functions to work with...
/**
* removes '# blabla...' from the mysql_dump.
* This function was originally developed for phpbb 2.01
* (C) 2001 The phpBB Group http://www.phpbb.com
*
* @return string input_without_#
*/
function remove_remarks($sql)
{
$lines = explode("\n", $sql);
// try to keep mem. use down
$sql = "";
$linecount = count($lines);
$output = "";
for ($i = 0; $i < $linecount; $i++)
{
if (($i != ($linecount - 1)) || (strlen($lines[$i]) > 0))
{
if ($lines[$i][0] != "#")
{
$output .= $lines[$i] . "\n";
}
else
{
$output .= "\n";
}
// Trading a bit of speed for lower mem. use here.
$lines[$i] = "";
}
}
return $output;
}
/**
* Splits sql- statements into handy pieces.
* This function was original developed for the phpbb 2.01
* (C) 2001 The phpBB Group http://www.phpbb.com
*
* @return array sql_pieces
*/
function split_sql_file($sql, $delimiter)
{
// Split up our string into "possible" SQL statements.
$tokens = explode($delimiter, $sql);
// try to save mem.
$sql = "";
$output = array();
// we don't actually care about the matches preg gives us.
$matches = array();
// this is faster than calling count($oktens) every time thru the loop.
$token_count = count($tokens);
for ($i = 0; $i < $token_count; $i++)
{
// Dont wanna add an empty string as the last thing in the array.
if (($i != ($token_count - 1)) || (strlen($tokens[$i] > 0)))
{
// This is the total number of single quotes in the token.
$total_quotes = preg_match_all("/'/", $tokens[$i], $matches);
// Counts single quotes that are preceded by an odd number of backslashes,
// which means they're escaped quotes.
$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$i], $matches);
$unescaped_quotes = $total_quotes - $escaped_quotes;
// If the number of unescaped quotes is even, then the delimiter did NOT occur inside a string literal.
if (($unescaped_quotes % 2) == 0)
{
// It's a complete sql statement.
$output[] = $tokens[$i];
// save memory.
$tokens[$i] = "";
}
else
{
// incomplete sql statement. keep adding tokens until we have a complete one.
// $temp will hold what we have so far.
$temp = $tokens[$i] . $delimiter;
// save memory..
$tokens[$i] = "";
// Do we have a complete statement yet?
$complete_stmt = false;
for ($j = $i + 1; (!$complete_stmt && ($j < $token_count)); $j++)
{
// This is the total number of single quotes in the token.
$total_quotes = preg_match_all("/'/", $tokens[$j], $matches);
// Counts single quotes that are preceded by an odd number of backslashes,
// which means theyre escaped quotes.
$escaped_quotes = preg_match_all("/(?<!\\\\)(\\\\\\\\)*\\\\'/", $tokens[$j], $matches);
$unescaped_quotes = $total_quotes - $escaped_quotes;
if (($unescaped_quotes % 2) == 1)
{
// odd number of unescaped quotes. In combination with the previous incomplete
// statement(s), we now have a complete statement. (2 odds always make an even)
$output[] = $temp . $tokens[$j];
// save memory.
$tokens[$j] = "";
$temp = "";
// exit the loop.
$complete_stmt = true;
// make sure the outer loop continues at the right point.
$i = $j;
}
else
{
// even number of unescaped quotes. We still dont have a complete statement.
// (1 odd and 1 even always make an odd)
$temp .= $tokens[$j] . $delimiter;
// save memory.
$tokens[$j] = "";
}
} // for..
} // else
}
}
return $output;
}
// simple function to update con_sequence
function updateSequence($table=false) {
global $db, $cfg;
if (!$table) {
$sql = "SHOW TABLES";
$db->query($sql);
while ($db->next_record())
{
dbUpdateSequence($cfg['sql']['sqlprefix']."_sequence", $db->f(0));
}
} else {
dbUpdateSequence($cfg['sql']['sqlprefix']."_sequence", $table);
}
}
// read out next free id
function getSequenceId($table) {
global $db2, $cfg;
$sql= "SELECT nextid FROM ".$cfg['sql']['sqlprefix']."_sequence"." where seq_name = '$table'";
$db2->query($sql);
if ($db2->next_record()) {
return $db2->f("nextid");
} else {
msg($table,"missing in con_sequence");
return 0;
}
}
// debug functions
function msg($value, $info=false) {
global $cfg;
if (trim($cfg["debug"]["messages"]) == "") $cfg["debug"]["messages"] = "<br><b>DEBUG:</b>";
if ($cfg["debug"]["installer"]) {
if ($info) { $cfg["debug"]["messages"] .= "<b>$info</b> -> "; }
if (is_array($value)) {
ob_start();
print_r($value);
$output = ob_get_contents();
ob_end_clean();
$cfg["debug"]["messages"] .= "<pre>".htmlspecialchars($output)."</pre>";
} else {
$cfg["debug"]["messages"] .= htmlspecialchars($value)."<br>";
}
}
}
function showmsg() {
global $cfg;
if ($cfg["debug"]["installer"]) {
echo "<div style=\"font-family: Verdana, Arial, Helvetica, Sans-Serif; font-size: 11px; color: #000000\">";
echo $cfg["debug"]["messages"];
echo "</div>";
}
}
$cfg["debug"]["backend_exectime"]["end"] = getmicrotime();
if ($cfg["debug"]["rendering"] == true)
{
echo "Rendering this page took: " . ($cfg["debug"]["backend_exectime"]["end"] - $cfg["debug"]["backend_exectime"]["start"])." seconds<br>";
echo "Building the complete page took: " . ($cfg["debug"]["backend_exectime"]["end"] - $cfg["debug"]["backend_exectime"]["fullstart"])." seconds<br>";
if (function_exists("memory_get_usage"))
{
echo "Include memory usage: ".human_readable_size(memory_get_usage()-$cfg["debug"]["oldmemusage"])."<br>";
echo "Complete memory usage: ".human_readable_size(memory_get_usage())."<br>";
}
}
page_close();
?>
ach ja install.txt
Code: Alles auswählen
1. agents.tar.bz2 nach contenido/plugins entpacken
2. install.php aufrufen
3. Sicherstellen, dass der php-Code aus module.txt bei jedem
Seitenaufruf ausgeführt wird. (Siehe module.txt)
vielleicht magst es ja übernehmen...
zu install.sql erste zeile
####Plugin Agents;0.0.0.1;Cavegn Christian;ID_RUBBISH00####
Plugin Agents -> der name des plugins
0.0.0.1 -> die versionsnummer des plugins upgrades sind in weiterer folge mit dem installer möglich
Cavegn Christian -> der author (ich hoffe der name stimmt)
ID_RUBBISH00 -> interne id (damit der installer erkennt das dieses plugin entweder installiert ist oder nicht)