2017-01-27, 04:15 AM
(This post was last modified: 2017-01-27, 04:16 AM by JesusChristIsGod.)
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.
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&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']);
}