MyBB Community Forums

Full Version: how to show fid in profile ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello
I want to put a code in user profile
but at first it need a field that has been made by admin in user profile

so after that i want to show the id of that field in my code but i cant't

code :
src={$userfields[\'fid{$id}\']}

when i use it , it doesn't show the id of the field
up ...
View a larger portion of your code, using the variable $id.
i said, i made a plugin that need profile field
first, user made a field then put its id into plugin settings
but when i put the field id it doesn't appear
up ..
please help
We cannot help you with the code sample you have provided. Either provide more code or stop bumping.
OK,
I attached php file

Huh

up ...
1. First of all, you should rather put the PHP code inside MyCode [/php] tag to become faster help:
<?php
/**
 * Profile Music
 * Author : Mybbco
 * http://mybbco.ir
 */
 
 $plugins->add_hook("member_profile_start","musicprofile"); 
 
 
 if(!defined("IN_MYBB"))
{
    die("You Cannot Access This File Directly");
} 


function musicprofile_info()
{
return array(
        "name"  => "Profile Music",
        "description"=> "Add music to user profile",
        "website"        => "http://mybbco.ir",
        "author"        => "Mybbco",
        "authorsite"    => "http://community.mybbco.ir/index.php",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "*"
    );
}

function musicprofile_activate()
{
	global $db, $mybb;
	
	// Settings
    $musicprofile_group = array(
        "gid" => "NULL",
        "name" => "musicprofile",
        "title" => "Profile Music",
        "description" => "Setting For Profile Music",
        "disporder" => "1",
        "isdefault" => "no",
    );
    $db->insert_query("settinggroups", $musicprofile_group);
    
    $gid = $db->insert_id();
    $musicprofile_setting_1 = array(
        "sid"            => "NULL",
        "name"            => "power",
        "title"            => "Enable ?",
        "description"    => "Select YES to activate Profile Music",
        "optionscode"    => "yesno",
        "value"            => '0',
        "disporder"        => '1',
        "gid"            => intval($gid),
    );

    $musicprofile_setting_2 = array(
        "sid"            => "NULL",
        "name"            => "player",
        "title"            => "Music Player",
        "description"    => "enter the address of your music player to show in user profile",
        "optionscode"    => "text",
        "value"            => '',
        "disporder"        => '2',
        "gid"            => intval($gid),
    );
	$musicprofile_setting_3 = array(
        "sid"            => "NULL",
        "name"            => "title",
        "title"            => "Title of the Box",
        "description"    => "enter the title of the music box",
        "optionscode"    => "text",
        "value"            => '',
        "disporder"        => '2',
        "gid"            => intval($gid),
    );
	$musicprofile_setting_4 = array(
        "sid"            => "NULL",
        "name"            => "fid",
        "title"            => "ID of the Profiel Field",
        "description"    => "enter the ID of the field that you made",
        "optionscode"    => "text",
        "value"            => '',
        "disporder"        => '2',
        "gid"            => intval($gid),
    );


	$db->insert_query("settings", $musicprofile_setting_1);
	$db->insert_query("settings", $musicprofile_setting_2);
	$db->insert_query("settings", $musicprofile_setting_3);
	$db->insert_query("settings", $musicprofile_setting_4);
	
	include MYBB_ROOT."/inc/adminfunctions_templates.php";
	
	
	    $musicprofile_template = array(
		"title"		=> 'musicprofile',
		"template"	=> $db->escape_string('
<br />

<table border="0" cellspacing="{$theme[\'borderwidth\']}" cellpadding="{$theme[\'tablespace\']}" class="tborder">
<tr>
<td class="thead" colspan=""><strong>{$title}</strong></td>
</tr>
<tr>
<td class="trow1">
<br><center>
<object type="application/x-shockwave-flash" data="{$player}" width="100" height="50" hspace="0" align="center">
   <param name="movie" value="{$player}">
   <param name="wmode" value="transparent">
   <param name="FlashVars" value="src={$userfields[\'fid{$id}\']}&amp;autoload=yes&amp;autostart=yes&amp;repeat=yes">
</object>
</center><br>
</td>
</tr>
</table> 

<br />
'),
		"sid"		=> "-1",
		"version"	=> "1.0",
		"dateline"	=> "1157735635",
	);
	$db->insert_query("templates", $musicprofile_template);
    find_replace_templatesets("member_profile", '#{\$header}#', "{\$header}\n{\$musicprofile}");

}

function musicprofile_deactivate()
{
	require MYBB_ROOT.'/inc/adminfunctions_templates.php';
	global $db;
	$db->query("DELETE FROM ".TABLE_PREFIX."templates WHERE title='musicprofile'");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('power', 'musicprofile')");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('title', 'musicprofile')");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('player', 'musicprofile')");
	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN('fid', 'musicprofile')");

	    rebuildsettings();
    find_replace_templatesets("member_profile", '#'.preg_quote('{$musicprofile}').'#', '',0);
	
}


function musicprofile(){
	
global $mybb, $db, $templates, $memprofile, $fid, $userfields, $musicprofile;

if ($mybb->settings['power'] == 1){
	$title = $mybb->settings['title'];
	$player = $mybb->settings['player'];
	$id = $mybb->settings['fid'];
    $musicprofile = $db->escape_string($musicprofile);
	
	
	eval("\$musicprofile = \"".$templates->get("musicprofile")."\";");
	
	}
		

}
	


?>
2. Your setting names are really dangerous. What if another plugin or core used 'title' or 'fid'? Remember to ensure that they are unique. Adding the plugin name as prefix (so 'musicprofile_title', 'musicprofile_fid' etc.) is one of solutions.
3. I don't think this code is compliant with MyBB template system:
{$userfields['fid{$id}']} It would throw a security error if someone edited that template in ACP. Assign it to another variable inside your function and insert that variable into template.
4. What is this line for? $musicprofile = $db->escape_string($musicprofile); It's redundant, that variable is not a part of any database query in that function.
5. Not a serious issue, but it's more recommended to use (int) casting than intval function for such simple tasks - it's slightly faster.

There may be more mistakes, didn't check everything.