Not Solved Fault in uninstalling a plugin didn't remove the code
#1
Not Solved
Plugin: User CSS
Description: Simple plugin which sticks a Custom CSS textbox under UserCP -> Options.
Site: http://mybbhacks.zingaburga.com/showthread.php?tid=1300

I removed the plugin and the texbox remained in the usercp, and installed it again and it added another textbox, and when I uninstalled is again it removed it but not the original. So there is a stuck textbox there.

Is there is a simple modification to the PHP I could make so that when deactivating and uninstalling it it would remove the extra code?

Thanks.

<?php
defined('IN_MYBB') or die('This file cannot be accessed directly.');

$plugins->add_hook('global_start', 'usercss_global');
$plugins->add_hook('usercp_options_end', 'usercss_editor');
$plugins->add_hook('usercp_do_options_end', 'usercss_change');

function usercss_info() {
	return array(
		'name'			=> 'UserCSS',
		'description'	=> 'Very simple plugin to allow users to add global custom CSS.',
		'website'		=> 'http://mybbhacks.zingaburga.com/',
		'author'		=> 'ZiNgA BuRgA',
		'authorsite'	=> 'http://zingaburga.com/',
		'version'		=> '1.1',
		'compatibility'	=> '14*,15*,16*,17*,18*',
		'guid'			=> ''
	);
}

function usercss_install() {
	global $db;
	$db->write_query('ALTER TABLE `'.$db->table_prefix.'users` ADD COLUMN `usercss` text not null');
}

function usercss_activate() {
	// template modification
	require_once MYBB_ROOT.'inc/adminfunctions_templates.php';
	find_replace_templatesets('headerinclude', '~\{\$stylesheets\}~', '$0{$usercss}');
	find_replace_templatesets('usercp_options', '~(?:\<td colspan\="2"\>\{\$stylelist\}\</td\>|\{\$board_style\})~i', "$0\n</tr>\n<tr>\n<td colspan=\"2\" class=\"smalltext\"><label for=\"usercss\">Custom CSS:</label> [WARNING! save down <a href=\"usercp.php?action=options&amp;nousercss=1\">this link</a> in case you mess up your CSS]</td></tr><tr><td colspan=\"2\"><textarea name=\"usercss\" id=\"usercss\" style=\"width: 100%; height: 4em;\">{\$user['usercss']}</textarea></td>");
}

function usercss_is_installed() {
	return $GLOBALS['db']->field_exists('usercss', 'users');
}

function usercss_deactivate() {
	require_once MYBB_ROOT.'inc/adminfunctions_templates.php';
	find_replace_templatesets('headerinclude', '~\{\$usercss\}~i', '', 0);
	find_replace_templatesets('usercp_options', '~\<tr\>\s*\<td [^>]+\>\s*(?:\<[^>]+\>\s*)?Custom CSS.*?\</td\>\s*\</tr\>\s*\<tr\>\s*\<td [^>]+\>\s*\<textarea.*?/textarea\>\s*\</td\>\s*\</tr\>\s*~si', '', 0);
}

function usercss_uninstall() {
	global $db;
	$db->write_query('ALTER TABLE `'.$db->table_prefix.'users` DROP COLUMN `usercss`');
}

function usercss_global() {
	global $mybb;
	if(!$mybb->user['uid'] || !$mybb->user['usercss'] || $mybb->input['nousercss']) return;
	
	// do evaluations
	$mybb->user['usercss'] = preg_replace_callback("~(\n|^)/\*@- *([a-z0-9\-_]+\.php)(, *[a-z0-9\-_]+\.php)* *\*/\r?\n.*?\n/\*@-\*/(?=\r?\n|$)~si", 'usercss_global_preg', $mybb->user['usercss']);
	
	$GLOBALS['usercss'] = '<style type="text/css"><!-- '.$mybb->user['usercss'].' --></style>';
}
function usercss_global_preg($m) {
	// our ultra-confusing compact one-liner!
	return $m[(int)! in_array(THIS_SCRIPT, explode(',', strtolower(str_replace(' ', '', $m[2].$m[3]))))];
}

function usercss_editor() {
	global $user;
	$user['usercss'] = htmlspecialchars_uni($user['usercss']);
}

function usercss_change() {
	// cause I'm too lazy to do a proper way
	global $mybb, $db;
	if(!isset($mybb->input['usercss'])) return;
	$usercss = strip_tags(str_replace('-->', '', $mybb->input['usercss']));
	$db->update_query('users', array(
		'usercss' => $db->escape_string($usercss)
	), 'uid='.$mybb->user['uid']);
}
Reply
#2
Not Solved
Yes you could make the modification to the plugin but is removing it from your theme all you're wanting to do? If so just go in and manually delete the template code.
Reply
#3
Not Solved
Yes, just wanting to remove it from theme. Thank you. I'll seek the code in the template. ... will you please give me a clue what to search and remove?
Reply
#4
Not Solved
It will be in your usercp_options template under UserCP Templates.

What you should be looking for and removing: it'll be some of the data in this.
find_replace_templatesets('usercp_options', '~(?:\<td colspan\="2"\>\{\$stylelist\}\</td\>|\{\$board_style\})~i', "$0\n</tr>\n<tr>\n<td colspan=\"2\" class=\"smalltext\"><label for=\"usercss\">Custom CSS:</label> [WARNING! save down <a href=\"usercp.php?action=options&amp;nousercss=1\">this link</a> in case you mess up your CSS]</td></tr><tr><td colspan=\"2\"><textarea name=\"usercss\" id=\"usercss\" style=\"width: 100%; height: 4em;\">{\$user['usercss']}</textarea></td>");
Reply
#5
Not Solved
That was fun, thank you. My mind has been e x p a n d e d in regards to understanding php.

Thank you.

Smile
Reply
#6
Not Solved
(2017-01-27, 09:54 AM)JesusChristIsGod Wrote: That was fun, thank you. My mind has been e x p a n d e d in regards to understanding php.

Thank you.

Smile

That's all it takes. Just a little looking around and you'll start to understand MyBB's templating system fairly quickly.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)