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: #11
RE: Need help with php
well the member.php has the $usefields varaible, and i can use the $userfields variable there without doing anything i just need to do what i did in my code.

Like this per example:
Replace this:

PHP Code:
$formattedname = format_name($memprofile['username'], $memprofile['usergroup'], $memprofile['displaygroup']); 


with this:

PHP Code:
1
2
3
4
5
6
7
8
    if($userfields['fid5'])
    {
        $formattedname = "<span style=\"color:{$userfields['fid5']}\">{$memprofile['username']}</span>";
    }
    else
    {
        $formattedname = format_name($memprofile['username'], $memprofile['usergroup'], $memprofile['displaygroup']);
    } 


So this is my function now:

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
31
32
33
34
function format_namePN($username, $usergroup, $displaygroup="")
{
    global $groupscache, $cache, $db;
	
	$query = $db->simple_select("SELECT * FROM userfields");
    $userfields = $db->fetch_field($query);

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

    if($displaygroup != 0)
    {
        $usergroup = $displaygroup;
    }

    if($userfields['fid5')
    {
        $format = "<span style=\"${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}
} 


Still not working.

And its  $format = "<span style=\"${userfields['fid5'};\">{username}</span>"; not  with &#092


(This post was last modified: 09/09/2007 06:10 AM by Pirata Nervo.)
09/09/2007 06:09 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: #12
RE: Need help with php
Uhh....  the two functions kinda contradict each other...  Try working through your logic first.
09/09/2007 06:12 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: #13
RE: Need help with php
but i know what im doing and i know what to edit but i don't know what i need to acess userfields.

Also what functions contradict each other?

10/09/2007 02:38 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: #14
RE: Need help with php
Well, if you know what you're doing, you obviously don't need help! :P

*sigh* okay, I'll give you a quick 1 minute function (too lazy to test if it works).  It _should_ work, but do note that it's _very_ slow:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function format_name($username, $usergroup, $displaygroup="")
{
	global $db;
	$query = $db->query("SELECT fid5 FROM ".TABLE_PREFIX."userfields f LEFT JOIN ".TABLE_PREFIX."users u ON u.uid = f.uid WHERE u.username = '".$db->escape_string($username)."'");
	
	if(!strpos($format = $db->fetch_field($query, 'fid5'), '{username}'))
	{
		global $groupscache, $cache;

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

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

(This post was last modified: 10/09/2007 03:09 AM by ZiNgA BuRgA.)
10/09/2007 03:07 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: #15
RE: Need help with php
i don't think that's what i want, i just want users to insert the hex color, not the <span style="{$userfields['fid5'};">{username}</span>

I tested that:
MySQL error: 1054
Unknown column 'f.uid' in 'on clause'
Query: SELECT fid5 FROM mybb_userfields f LEFT JOIN mybb_users u ON u.uid = f.uid WHERE u.username = 'GoogleBot'

10/09/2007 03:24 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: #16
RE: Need help with php
also i tried that in the function format_name instead of format_namePN
and i get this error:
MySQL error: 1054
Unknown column 'f.uid' in 'on clause'
Query: SELECT fid5 FROM mybb_userfields f LEFT JOIN mybb_users u ON u.uid = f.uid WHERE u.username = 'Pirata Nervo'

10/09/2007 02:53 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: #17
RE: Need help with php
Well, if it's not called "uid" replace it with the proper name.  I'm too lazy to look up what the correct name is.

If you don't want people entering a <span> then just remove it...
10/09/2007 04:12 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: #18
RE: Need help with php
Ok this is how it is:
f.ufid

No errors shown, BUT, nothing changed.
Also remove what? the span???
Doesn't your function requires people to insert <span style="#hexcolorhere;">{username}</span> instead of just #hexcolor?

11/09/2007 01:41 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: #19
RE: Need help with php
Urgh, okay, tell me what do you have in fid5?

Try setting it to something like:

Code:
<span style="color: red;">{$username}</span>


Let's take this one step at a time.

11/09/2007 03:54 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: #20
RE: Need help with php
I have #ff0000.

ok let me try with that.

(This post was last modified: 11/09/2007 04:01 AM by Pirata Nervo.)
11/09/2007 04:00 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: