MyBB Community Forums

Full Version: php how to check users theme?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have 2 themes on my forum. One the default white theme, and the other a dark theme. I have custom MyCodes that appear to the default white theme. However they look odd in the dark theme. Is there a way i can put in the MyCode field to use X code if in default theme, and to use Y code if in the dark theme?

The screenshot is of the dark theme of a postbit using custom mycode's. The Quote tag is darkened, but that is because the author accounted for that. The others are custom MyCodes. 

I would like to make the error and output tags the same as quote tag just with the red and blue outline...but only in the dark theme, and leave it as is in the default white theme.

here is the dark themes global.css of blockquote. Like i said im just not sure how to select the CSS based on the users theme in MYCode. I do have YourCode plugin but there isnt an option for a CSS selection.
blockquote {
	margin: 0;
	background: #202020;
	color: #a0a0a0;
	border: 1px solid #303030;
	padding: 10px;
}
blockquote cite {
	font-weight: bold;
	border-bottom: 1px solid #303030;
	font-style: normal;
	display: block;
	padding-bottom: 3px;
	margin: 0 0 10px 0;
}
blockquote cite span {
	float: right;
	font-weight: normal;
	font-size: 12px;
	color: #666;
}
blockquote cite span.highlight {
	float: none;
	font-weight: bold;
	padding-bottom: 0;
}

EDIT:
I forgot we dont use mycode/yourcode for specifically those BBCode tags. We made  a plugin to do it.
<?php

// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.");
}


function customcodetags_info()
{
	return array(
		"name"			=> "Custom Code Tags",
		"description"	=> "Adds custom MyCode for python code, output, errors and inline code",
		"author"		=> "stranac",
		"version"		=> "1.1",
		"codename"		=> "customcodename",
		"compatibility" => "18*"
	);
}

$plugins->add_hook("parse_message_start", "find_custom_tags");
$plugins->add_hook("parse_message_end", "replace_custom_tags");


function find_custom_tags($message)
{
	global $custom_code_matches, $parser, $mybb;

	// to quote class_parser.php: "Get rid of carriage returns for they are the workings of the devil"
	$message = str_replace("\r", "", $message);

	// if MyCode needs to be replaced, filter out all code tags.
	if(!empty($parser->options['allow_mycode'])) {
		$pattern = "#\[(code|php|python|output|error)\](.*?)\[/\\1\]\n*|\[icode\]([^\n]*?)\[/icode\]|`([^\n]*?)`#si";

		preg_match_all($pattern, $message, $custom_code_matches, PREG_SET_ORDER);
		$message = preg_replace($pattern, "---custom-code-tags-plugin---", $message);
	}

	return $message;
}


function replace_custom_tags($message) {
	global $custom_code_matches, $parser;

	if(!empty($parser->options['allow_mycode'])) {
		// if we split up any code tags, parse them and glue it all back together
		if(count($custom_code_matches) > 0) {

			foreach($custom_code_matches as $match) {
				$type = my_strtolower($match[1]);
				$content = $match[2];

				if ($type == "") { // icode and ` matched by separate regex, so details need to be corrected
					$type = "icode";
					$content = ($match[3] != "") ? $match[3] : $match[4];
				}

				$content = $parser->parse_html($content);
				$content = str_replace('$', '$', $content);
				$content = str_replace('\\', '\', $content);

				$content = format_code($type, $content);
				$message = preg_replace("#---custom-code-tags-plugin---\n?#", $content, $message, 1);
			}
		}
	}
	
	return $message;
}


function format_code($type, $content)
{
	// hijack [code] and [php] tags
	if (in_array($type, ["python", "code", "php"])) {
		return "<pre class=\"brush: python\" title=\"Python Code: <span>(Double-click to select all)</span>\">".$content."</pre>";
	}
	// inline code
	elseif ($type == "icode") {
		return "<code class=\"icode\">".$content."</code>";
	}
	// [error] and [output] tags
	else {
		return "<pre><code class=\"codeblock ".$type."\"><div class=\"title\">".ucfirst($type).":</div>".$content."</code></pre>";
	}
}
[/code]
So i guess the the question now would be how would you say check the condition for testing which theme the user is using?