Seite 1 von 1

MOD COLOR GROUPS - Fehler nur wenn Board deaktiviert ist.

Verfasst: 31.01.2005 08:37
von Dr.Death
Hallo PHP Freaks,

ich habe ein kleine Problem mit dem Color Groups MOD.

Das MOD ansich arbeitet einwandfrei (keine Fehlermeldungen).


Folgender Fehler tritt nur dann auf, wenn ich das Board zwecks Wartungsarbeiten sperren möchte (Board Disabled).


Warning: in_array(): Wrong datatype for second argument in /pfad-vom-anbieter/forum/includes/functions_color_groups.php on line 260

Auszug aus der functions_color_groups.php

Ab Zeile 260:

Code: Alles auswählen

			if ( in_array($user_id, $colorgroup) )
			{
				// Now start looking for user group memberships //
				$sql = 'SELECT c.* FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u, ' . COLOR_GROUPS_TABLE . ' c, ' . GROUPS_TABLE . ' g
					WHERE ug.user_id = ' . $user_id . '
					AND u.user_id = ug.user_id
					AND ug.group_id = g.group_id
					AND g.group_color_group = c.group_id
					AND g.group_single_user = 0';

Kann mir jemand dazu helfen?

Doc.

Verfasst: 31.01.2005 21:08
von Andy120
hi...

Hast du etwas in diese Datei eingebaut? Wenn nicht lad mal eine neue rauf. Dieser Code da stimmt nicht.

Ausser eben du hast was einbauen wollen.

Gruss, Andy

Verfasst: 01.02.2005 07:05
von Dr.Death
Danke für den Hinweis!

Ich habe mal die "original" Datei hochgeladen...und siehe da: der Fehler ist verschwunden.

Ich hatte folgende Code Verbesserung von ACID eingebaut:

http://www.acidjunky.de/files/color_gro ... ueries.txt

Nun bin ich wieder auf über 300 SQL Queries pro Index.php aufruf.
Mit der Code verbesserung lag ich bei knapp 100.

Gibt es vielleicht doch noch eine andere Lösung?
Acid?


Mfg
Doc.

Verfasst: 01.02.2005 12:59
von Andy120
hi....

Suche

Code: Alles auswählen

function color_group_colorize_name($user_id, $no_profile = false)
{
	global $board_config, $phpEx, $db, $phpbb_root_path;

	// First see if the user is Anon
	if ($user_id != ANONYMOUS)
	{
		// Get the user info and see if they are assigned a color_group //
		$sql = 'SELECT u.user_color_group, u.username, c.* FROM ' . USERS_TABLE . ' u, ' . COLOR_GROUPS_TABLE . " c
			WHERE u.user_id = $user_id
			AND u.user_color_group = c.group_id";
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);

		if (!isset($row['username']))
		{
			//If there was a problem before, we don't want a blank username!
			$sql = 'SELECT username FROM ' . USERS_TABLE . "
			WHERE user_id = $user_id";
			$result = $db->sql_query($sql);
			$row = $db->sql_fetchrow($result);
		}
		$username = $row['username'];

		if (isset($row['group_color']))
		{
			// WE found the highest level color, head out now //
			$style_color = 'style="font-weight:bold;color:' . $row['group_color'] . '"';
		}
		else
		{
			// Now start looking for user group memberships //
			$sql = 'SELECT c.* FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u, ' . COLOR_GROUPS_TABLE . ' c, ' . GROUPS_TABLE . ' g
				WHERE ug.user_id = ' . $user_id . '
				AND u.user_id = ug.user_id
				AND ug.group_id = g.group_id
				AND g.group_color_group = c.group_id
				AND g.group_single_user = 0';
			//print $sql;
				$result = $db->sql_query($sql);
				$curr = 10000000000000;
				$style_color = '';
				while ($row = $db->sql_fetchrow($result))
				{
					// If our new group in the list is a higher order number, it's color takes precedence //
					if ($row['order_num'] < $curr)
					{
						$curr = $row['order_num'];
						$style_color = 'style="font-weight:bold;color:' . $row['group_color'] . '"';
					}
				}
		}

		// Make the profile link or no and return it //
		if ($no_profile)
		{
			$user_link = "<span $style_color>$username</span>";
		}
		else
		{
			$user_link = '<a href="' . append_sid($phpbb_root_path."profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$user_id") . '"' . $style_color .'>' . $username . '</a>';
		}
		return($user_link);
	}
	else
	{
		return false;
	}
}
Ersetze

Code: Alles auswählen

function color_group_colorize_name($user_id, $no_profile = false)
{
	global $board_config, $phpEx, $db, $phpbb_root_path, $colorusers, $coloruname, $colorgroup;
	
	// First see if the user is Anon
	if ($user_id != ANONYMOUS)
	{
		$username = $coloruname[$user_id];
		if ( $colorusers[$user_id] != 0 )
		{
			// Get the user info and see if they are assigned a color_group //
			$sql = 'SELECT u.user_color_group, u.username, c.* FROM ' . USERS_TABLE . ' u, ' . COLOR_GROUPS_TABLE . " c
				WHERE u.user_id = $user_id
				AND u.user_color_group = c.group_id";
			$result = $db->sql_query($sql);
			$row = $db->sql_fetchrow($result);

		}
		
		if (isset($row['group_color']))
		{
			// WE found the highest level color, head out now //
			$style_color = 'style="font-weight:bold;color:' . $row['group_color'] . '"';
		}
		else
		{
			if ( in_array($user_id, $colorgroup) )
			{
				// Now start looking for user group memberships //
				$sql = 'SELECT c.* FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u, ' . COLOR_GROUPS_TABLE . ' c, ' . GROUPS_TABLE . ' g
					WHERE ug.user_id = ' . $user_id . '
					AND u.user_id = ug.user_id
					AND ug.group_id = g.group_id
					AND g.group_color_group = c.group_id
					AND g.group_single_user = 0';
				//print $sql;
					$result = $db->sql_query($sql);
					$curr = 10000000000000;
					$style_color = '';
					while ($row = $db->sql_fetchrow($result))
					{
						// If our new group in the list is a higher order number, it's color takes precedence //
						if ($row['order_num'] < $curr)
						{
							$curr = $row['order_num'];
							$style_color = 'style="font-weight:bold;color:' . $row['group_color'] . '"';
						}
					}
			}
		}
		
		// Make the profile link or no and return it //
		if ($no_profile)
		{
			$user_link = "<span $style_color>$username</span>";
		}
		else
		{
			$user_link = '<a href="' . append_sid($phpbb_root_path."profile.$phpEx?mode=viewprofile&" . POST_USERS_URL . "=$user_id") . '"' . $style_color .'>' . $username . '</a>';
		}
		return($user_link);
	}
	else
	{
		$username = $coloruname[$user_id];
		if ($no_profile)
		{
			$user_link = "<span $style_color>$username</span>";
		}
		else
		{
			$user_link = '<a href="' . append_sid($phpbb_root_path."profile.php?mode=viewprofile&" . POST_USERS_URL . "=$user_id") . '"' . $style_color .'>' . $username . '</a>';
		}
		return $username;
	}
}
Gruss, Andy

Verfasst: 01.02.2005 13:52
von Dr.Death
Tja, was soll ich sagen....

jetzt hab ich den gleichen Fehler wie vorher :-(
Warning: in_array(): Wrong datatype for second argument in /pfad-vom-anbieter/forum/includes/functions_color_groups.php on line 274
die betreffende Zeile:

Code: Alles auswählen

      if ( in_array($user_id, $colorgroup) ) 

Der Fehler tritt nur dann auf, wenn ich das Board sperre.

Verfasst: 01.02.2005 14:28
von Dr.Death
Tadaa !

Ich hab den Fehler gerade selbst gefunden !!! ( *stolz* ) :-)

Der Fehler liegt an der Beschreibung von ACID:

http://www.acidjunky.de/files/color_gro ... ueries.txt

Dort wird die Änderung der COMMON.PHP beschrieben:

Code: Alles auswählen

#-----[ ÖFFNE ]------------------------------------------
#
# common.php
#
#-----[ FINDE ]------------------------------------------
#

?>

#
#-----[ DARÜBER EINFÜGEN ]------------------------------------------
#
$sql = "SELECT user_id, user_color_group, username FROM " . USERS_TABLE;
if( !($result = $db->sql_query($sql)) )   ... usw
Dummerweise werden dann die Variablen nicht eingelesen wenn das Board gesperrt wird.

Lösung:

Code: Alles auswählen

]#-----[ ÖFFNE ]------------------------------------------
#
# common.php
#
#-----[ FINDE ]------------------------------------------
//
// Show 'Board is disabled' message if needed.
//

#-----[ DARÜBER EINFÜGEN ]------------------------------------------
$sql = "SELECT user_id, user_color_group, username FROM " . USERS_TABLE;
if( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not read user color groups', '', __LINE__, __FILE__, $sql);
}

$colorusers = array();
$coloruname = array();
while ( $row = $db->sql_fetchrow($result) )
{
	$userid = $row['user_id'];
	$colorusers[$userid] = $row['user_color_group'];
	$coloruname[$userid] = $row['username'];
}

$colorgroup = array();

$sql = "SELECT ug.user_id FROM " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g
	WHERE g.group_single_user = 0
	AND g.group_id = ug.group_id
	GROUP BY ug.user_id
	ORDER BY ug.user_id";
if( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not read user color groups', '', __LINE__, __FILE__, $sql);
}
while ( $row = $db->sql_fetchrow($result) )
{
	$colorgroup[] = $row['user_id'];
}
Vielleicht kann ja mal jemand die Anleitung updaten...

Verfasst: 01.02.2005 16:37
von rabbit
btw, guck' doch mal hier vorbei, dort findest du eine sehr gute alternative zum color groups von niels: Advanced Username Colors ;)
der AUC fügt nicht einen einzigen query zu deinem board hinzu. :)