Jump to content

Help a PHP newb!


Kay2eX

Recommended Posts

There's a plugin I want to use on MyBB, and I want to edit the text and stuff so it works the way I want. Now, there are two files..

 

profilebuddies.php

profilebuddies.lang.php

 

One is that we upload to plugins folder, one goes in the English lang folder.

 

profilebuddies.lang.php

 

<?php
$l['profilebuddies_title']='{1}\' buddies';
$l['profilebuddies_title_max']='{1} of {2} buddies';
$l['profilebuddies_no_buddies']='{1} doesn\'t have add any buddy.';
$l['profilebuddies_add_buddy']='Add {1} to your buddies!';
$l['profilebuddies_manage_buddies']='Manage your buddies.';
$l['profilebuddies_mail_subject']='Someone added you to buddy list at {1}';
$l['profilebuddies_mail_message']='{1},

{2} from {3} has added you to buddy list. To view {2}\'s profile, you can follow this link:

{4}/{5}

Thank you,
{3} Staff
{4}';

 

profilebuddies.php

 

<?php
if(!defined('IN_MYBB'))
die();
$plugins->add_hook('member_profile_end','profilebuddies');
$plugins->add_hook('usercp_do_editlists_end','profilebuddies_message');
function profilebuddies_info(){
return array(
	'name'=>'Profile Buddies',
	'description'=>'Enhances the profile of all members with a list of their own buddies.',
	'website'=>'http://mods.mybboard.net/view/profile-buddies',
	'author'=>'wundi',
	'authorsite'=>'http://pharmaboard.de',
	'version'=>'1.0',
	'guid'=>'1d7ed75d036a35f3d1f658f89dbca19f',
	'compatibility'=>'14*',
	'codename'=>'profilebuddies'
);
}
function profilebuddies_activate(){
global $db;
$info=profilebuddies_info();
$setting_group_array=array(
	'name'=>$info['codename'],
	'title'=>$info['name'],
	'description'=>'Here you can edit '.$info['name'].' settings.',
	'disporder'=>1,
	'isdefault'=>0
);
$db->insert_query('settinggroups',$setting_group_array);
$group=$db->insert_id();
$settings=array(
	'profilebuddies_max'=>array(
		'Maximum buddies',
		'The maximum number of buddies that you wish to show inside profiles.',
		'text',
		'5'
	),
	'profilebuddies_message'=>array(
		'Buddy notification',
		'If you active this setting your members will get an e-mail notification when someone adds them to buddy list.',
		'onoff',
		1
	)
);
$i=1;
foreach($settings as $name=>$sinfo){
	$insert_array=array(
		'name'=>$name,
		'title'=>$db->escape_string($sinfo[0]),
		'description'=>$db->escape_string($sinfo[1]),
		'optionscode'=>$db->escape_string($sinfo[2]),
		'value'=>$db->escape_string($sinfo[3]),
		'gid'=>$group,
		'disporder'=>$i,
		'isdefault'=>0
	);
	$db->insert_query('settings',$insert_array);
	$i++;
}
rebuild_settings();
include MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets('member_profile','#<br />{\$buddylist}#i','',0);
find_replace_templatesets('member_profile','#{\$buddylist}#i','',0);
find_replace_templatesets('member_profile','#{\$modoptions}#i','<br />{$buddylist}{$modoptions}');
}
function profilebuddies_deactivate(){
global $db;
$info=profilebuddies_info();
$result=$db->simple_select('settinggroups','gid','name="'.$info['codename'].'"',array('limit'=>1));
$group=$db->fetch_array($result);
if(!empty($group['gid'])){
	$db->delete_query('settinggroups','gid="'.$group['gid'].'"');
	$db->delete_query('settings','gid="'.$group['gid'].'"');
	rebuild_settings();
}
include MYBB_ROOT.'/inc/adminfunctions_templates.php';
find_replace_templatesets('member_profile','#<br />{\$buddylist}#i','',0);
find_replace_templatesets('member_profile','#{\$buddylist}#i','',0);
}
function profilebuddies(){
global $mybb,$lang,$theme,$memprofile,$buddylist;
$lang->load('profilebuddies',false,true);
$colspan=$buddies_show=$add_buddy='';
if(!empty($memprofile['buddylist'])){
	global $db;
	$colspan=$buddies_count=substr_count($memprofile['buddylist'],',')+1;
	if($mybb->settings['profilebuddies_max']<=0)
		$mybb->settings['profilebuddies_max']=1;
	if($buddies_count>$mybb->settings['profilebuddies_max']){
		$colspan=$mybb->settings['profilebuddies_max'];
		$buddies_show='<div style="float:right;">'.$lang->sprintf($lang->profilebuddies_title_max,$mybb->settings['profilebuddies_max'],$buddies_count).'<span class="smalltext"><strong></strong></span></div>';
	}
	$width=floor(100/$colspan).'%';
	$colspan=' colspan="'.$colspan.'"';
	$query=$db->simple_select('users','uid,username,avatar,avatardimensions,usergroup,displaygroup','uid IN('.$memprofile['buddylist'].')',
		array(
			'limit'=>$mybb->settings['profilebuddies_max'],
			'order_by'=>'lastactive',
			'order_dir'=>'DESC'
		)
	);
	$bgcolor='trow1';
	while($buddy=$db->fetch_array($query)){
		$buddy_avatar='';
		if(!empty($buddy['avatar'])){
			$buddy['avatar']=htmlspecialchars_uni($buddy['avatar']);
			$avatar_dimensions=explode('|',$buddy['avatardimensions']);
			if($avatar_dimensions[0]&&$avatar_dimensions[1]){
				list($max_width,$max_height)=explode('x',my_strtolower($mybb->settings['postmaxavatarsize']));
				if($avatar_dimensions[0]>$max_width||$avatar_dimensions[1]>$max_height){
					require_once MYBB_ROOT.'inc/functions_image.php';
					$scaled_dimensions=scale_image($avatar_dimensions[0],$avatar_dimensions[1],$max_width, $max_height);
					$avatar_width_height='width="'.$scaled_dimensions['width'].'" height="'.$scaled_dimensions['height'].'"';
				}else{
					$avatar_width_height='width="'.$avatar_dimensions[0].'" height="'.$avatar_dimensions[1].'"';
				}
				$buddy_avatar='<a href="'.get_profile_link($buddy['uid']).'"><img src="'.$buddy['avatar'].'" alt="'.htmlspecialchars_uni($buddy['username']).'" '.$avatar_width_height.' /></a><br />';
			}
		}
		$buddy_name=format_name($buddy['username'],$buddy['usergroup'],$buddy['displaygroup']);
		$buddy_link=build_profile_link($buddy_name,$buddy['uid']);
		$buddies.='<td class="'.$bgcolor.'" align="center" valign="bottom" width='.$width.'>'.$buddy_avatar.'<span class="smalltext">'.$buddy_link.'</span></td>';
		if($bgcolor=='trow1')
			$bgcolor='trow2';
		else
			$bgcolor='trow1';
	}
}else{
	$buddies.='<td class="trow1">'.$lang->sprintf($lang->profilebuddies_no_buddies,htmlspecialchars_uni($memprofile['username'])).'</td>';
}
if($mybb->user['uid']!=0){
	$user_buddys=explode(',',$mybb->user['buddylist']);
	if($mybb->user['uid']==$memprofile['uid'])
		$add_buddy='<tr><td class="trow2"'.$colspan.' align="right"><a href="'.$mybb->settings['bburl'].'/usercp.php?action=editlists">'.$lang->profilebuddies_manage_buddies.'</a></td></tr>';
	elseif(!in_array($memprofile['uid'],$user_buddys))
		$add_buddy='<tr><td class="trow2"'.$colspan.' align="right"><a href="'.$mybb->settings['bburl'].'/usercp.php?action=do_editlists&my_post_key='.$mybb->post_code.'&add_username='.htmlspecialchars_uni($memprofile['username']).'">'.$lang->sprintf($lang->profilebuddies_add_buddy,htmlspecialchars_uni($memprofile['username'])).'</a></td></tr>';
}
$buddylist='<table border="0" cellspacing="'.$theme['borderwidth'].'" cellpadding="'.$theme['tablespace'].'" class="tborder"><thead><tr><td class="thead"'.$colspan.'>'.$buddies_show.'<div><strong>'.$lang->sprintf($lang->profilebuddies_title,htmlspecialchars_uni($memprofile['username'])).'</strong></div></td></tr></thead><tbody><tr>'.$buddies.'</tr>'.$add_buddy.'</tbody></table>';
}
function profilebuddies_message(){
global $mybb;
if($mybb->settings['profilebuddies_message']==1){
	global $lang,$message,$error_message;
	$lang->load('profilebuddies',false,true);
	if($message==$lang->users_added_to_buddy_list&&empty($error_message)){
		global $mybb,$db,$users;
		foreach($users as $user){
			$query=$db->simple_select('users','uid,email','username="'.$user.'"');
			$result=$db->fetch_array($query);
			$emailsubject=$lang->sprintf($lang->profilebuddies_mail_subject,$mybb->settings['bbname']);
			$emailmessage=$lang->sprintf($lang->profilebuddies_mail_message,$user,$mybb->user['username'],$mybb->settings['bbname'],$mybb->settings['bburl'],get_profile_link($mybb->user['uid']));
			my_mail($result['email'],$emailsubject,$emailmessage);
		}
	}
}
}

 

So, the stuff in profilebuddies.lang.php are what I need to edit but, if I do, do I have to edit anything in profilebuddies.php?

Link to comment
https://forums.phpfreaks.com/topic/175540-help-a-php-newb/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.