Post Reply 
Need help with php
Plugin->Zinga's plugin username colors
Author Message
Pirata Nervo
NervOS Developer

Posts: 699.4765
Threads: 39
Joined: 20th Jun 2007
Reputation: -0.79225
E-Pigs: 19.2466
Offline
Post: #1
Need help with php
Im trying to make a plugin like zinga's plugin(username color just that), im trying to make this:

replace in functions.php:
this:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function format_name($username, $usergroup, $displaygroup="")
{
	global $groupscache, $cache;

	if(!is_array($groupscache))
	{
		$groupscache = $cache->read("usergroups");
	}

	if($displaygroup != 0)
	{
		$usergroup = $displaygroup;
	}
	
	
	$ugroup = $groupscache[$usergroup];
	$format = $ugroup['namestyle'];
	$userin = substr_count($format, "{username}");
	if($userin == 0)
	{
		$format = "{username}";
	}
	$format = stripslashes($format);
	return str_replace("{username}", $username, $format);
}

with this:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function format_name($username, $usergroup, $displaygroup="")
{
	global $db, $groupscache, $cache;
	$query = $db->simple_select(TABLE_PREFIX."userfields", "fid5", "ufid='".intval($uid)."'");

	if(!is_array($groupscache))
	{
		$groupscache = $cache->read("usergroups");
	}

	if($displaygroup != 0)
	{
		$usergroup = $displaygroup;
	}
	$ugroup = $groupscache[$usergroup];
	$format = "<span style=\"color:{$userfields['fid5']};\">{username}</span>"; // This the 'namestyle' can be easily changed in the admin cp for each group but i want to change it for each user
	$userin = substr_count($format, "{username}"); // function that counts how many times {username} substring is in the $formats string
	if($userin == 0) // if {username} substring wasnt found in the $format string, then
	{
		$format = "{username}"; // the $format string = "{username}"
	}
	$format = stripslashes($format); // The stripslashes() function removes backslashes from the $format string
	return str_replace("{username}", $username, $format); // replaces {username} with $username, so the $format string will contain $username instead of {username}
}


It doesn't show the colors...but it affects the colors because it shows the default color in all usernames


(This post was last modified: 07/09/2007 04:03 PM by Pirata Nervo.)
07/09/2007 07:13 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Th3_Hellrider
Existential Entity

Posts: 17.2600
Threads: 3
Joined: 10th Aug 2007
Reputation: 0.76198
E-Pigs: 0.6697
Offline
Post: #2
RE: Need help with php
Hmm, i haven't got too much experience in PHP scripting, but it should be ok... Probably mistake:D

{Translated with google -.-}

Hellrider®: Your Connection to Perfection.
07/09/2007 08:52 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Pirata Nervo
NervOS Developer

Posts: 699.4765
Threads: 39
Joined: 20th Jun 2007
Reputation: -0.79225
E-Pigs: 19.2466
Offline
Post: #3
RE: Need help with php
but it isn't working lool and what was translated with google?

07/09/2007 09:12 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Pirata Nervo
NervOS Developer

Posts: 699.4765
Threads: 39
Joined: 20th Jun 2007
Reputation: -0.79225
E-Pigs: 19.2466
Offline
Post: #4
RE: Need help with php
Updated with a new question as i resolved my other problem.
Also zinga changed the php code i don't know why but its:

            $ugroup = $groupscache[$usergroup];
            $format = "<span style=\"color:{$userfields['fid5']};\">{username}</span>";
            $userin = substr_count($format, "{username}");

not

            $ugroup = $groupscache[$usergroup];
            $format = "<span style=\"color:{$userfields['fid5']};\">{username}</span>";
            $userin = substr_count($format, "{username}");

(This post was last modified: 08/09/2007 12:44 AM by Pirata Nervo.)
07/09/2007 03:36 PM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA
Smart Alternative

Posts: 17,023.4213
Threads: 1,174
Joined: 19th Jan 2007
Reputation: -1.71391
E-Pigs: 446.0333
Offline
Post: #5
RE: Need help with php
Firstly, the code you supplied is rather illogical and obviously doesn't work...
Secondly, it's very inefficient - you make a query every time you have to format a name - for example, if there's 100 names needing to be formatted, your code queries the database 100 times just to do that.
My method hardly affects speed, but to achieve that, a lot of code edits are needed.

I'll point out some problems with your script, however, I'm not going to provide you with a full solution (since it won't be "good" anyway):

PHP Code:
    $query = $db->simple_select(TABLE_PREFIX."userfields", "fid5", "ufid='".intval($uid)."'");


  1. The query isn't used anywhere
  2. $uid is not initialized, and means nothing

The rest looks like it will work.

Pirata Nervo Wrote:Updated with a new question as i resolved my other problem.
Also zinga changed the php code i don't know why but its:

            $ugroup = $groupscache[$usergroup];
            $format = "<span style=\"color:{$userfields['fid5']};\">{username}</span>";
            $userin = substr_count($format, "{username}");

not

            $ugroup = $groupscache[$usergroup];
            $format = "<span style=\"color:{$userfields['fid5']};\">{username}</span>";
            $userin = substr_count($format, "{username}");
What???
07/09/2007 09:10 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Pirata Nervo
NervOS Developer

Posts: 699.4765
Threads: 39
Joined: 20th Jun 2007
Reputation: -0.79225
E-Pigs: 19.2466
Offline
Post: #6
RE: Need help with php
You probably changed the php bbcode so it doesn't say / it says \

PHP Code:
$format = "<span style=\"color:{$userfields['fid5']};\">

its not that.
its:
$format = "<span style=\"color:{$userfields['fid5']};\">


O and thanks, but it isn't working with my code lol


(This post was last modified: 08/09/2007 01:07 AM by Pirata Nervo.)
08/09/2007 12:45 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Pirata Nervo
NervOS Developer

Posts: 699.4765
Threads: 39
Joined: 20th Jun 2007
Reputation: -0.79225
E-Pigs: 19.2466
Offline
Post: #7
RE: Need help with php
I deleted everything in this post.

Its not \ its \ , i don't know what does it means but its not that, but it says that inside of php tags.

im trying to make a function:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function format_namePN($username, $usergroup, $displaygroup="")
{
	global $groupscache, $cache;

	if(!is_array($groupscache))
	{
		$groupscache = $cache->read("usergroups");
	}

	if($displaygroup != 0)
	{
		$usergroup = $displaygroup;
	}
	if($userfields['fid5'])
	{
		$format = "<span style=\"color:{$userfields['fid5']};\">{username}</span>";
	}
	else
	{
		$ugroup = $groupscache[$usergroup];
		$format = $ugroup['namestyle'];
	}
    	$userin = substr_count($format, "{username}"); // function that counts how many times {username} substring is in the $formats string
    	if($userin == 0) // if {username} substring wasnt found in the $format string, then
    	{
      	$format = "{username}"; // the $format string = "{username}"
    	}
    	$format = stripslashes($format); // The stripslashes() function removes backslashes from the $format string
    	return str_replace("{username}", $username, $format); // replaces {username} with $username, so the $format string will contain $username instead of {username}
} 


I don't know why it isn't working do i need to call anything before using the userfields['fid5'] ?
Because it always uses the else condition insteaad of using the first one.


(This post was last modified: 08/09/2007 03:55 PM by Pirata Nervo.)
08/09/2007 05:58 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA
Smart Alternative

Posts: 17,023.4213
Threads: 1,174
Joined: 19th Jan 2007
Reputation: -1.71391
E-Pigs: 446.0333
Offline
Post: #8
RE: Need help with php
double you tee eff?  First thing, $userfields is undeclared...
08/09/2007 07:11 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Pirata Nervo
NervOS Developer

Posts: 699.4765
Threads: 39
Joined: 20th Jun 2007
Reputation: -0.79225
E-Pigs: 19.2466
Offline
Post: #9
RE: Need help with php
but how do i check if it exists in the db? that's my main question.
Im also using require_once "./member.php"; and still doesn't work.

(This post was last modified: 09/09/2007 02:47 AM by Pirata Nervo.)
09/09/2007 02:25 AM
Visit this user's website Find all posts by this user Quote this message in a reply
ZiNgA BuRgA
Smart Alternative

Posts: 17,023.4213
Threads: 1,174
Joined: 19th Jan 2007
Reputation: -1.71391
E-Pigs: 446.0333
Offline
Post: #10
RE: Need help with php
Check what exists in the DB?  You have an undeclared variable - that's your issue.  A lot of scripting languages don't require explicit variable declaration, so sticking in a variable that doesn't exist won't cause an error.  In C, for example, using an undeclared variable would cause a compiler error, eg:

Code:
1
2
3
4
5
6
#include <stuff>
int main()
{
 printf("%s",nonExistantVariable);
 return 0;
}

The above would obviously not compile.
In PHP, no error would be generated however - nonExistantVariable would just be null.


Pirata Nervo Wrote:Im also using require_once "./member.php"; and still doesn't work.
Do you have the path right?  But why do you want to include member.php anyway?
09/09/2007 05:10 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: