<commit_before><?php

/**
 * @package anno
 * This file is part of the Annotum theme for WordPress
 * Built on the Carrington theme framework <http://carringtontheme.com>
 *
 * Copyright 2008-2011 Crowd Favorite, Ltd. All rights reserved. <http://crowdfavorite.com>
 * Released under the GPL license
 * http://www.opensource.org/licenses/gpl-license.php
 */

/**
 * Set acceptable custom tags for wp_kses
 */
$allowedposttags = array_merge($allowedposttags, array(
	'alt-text' => array(),
	'attrib' => array(),
	'bold' => array(),
	'cap' => array(),
	'copyright-statement' => array(),
	'copyright-holder' => array(),
	'disp-quote' => array(),
	'ext-link' => array(
		'type' => array(),
		'xlink:href' => array(),
		'title' => array(),
	),
	'fig' => array(),
	'inline-graphic' => array(
		'xlink:href' => array(),
	),
	'heading' => array(),
	'italic' => array(),
	'lbl' => array(),
	'license' => array(
		'license-type' => array(),
	),
	'license-p' => array(),
	'list' => array(
		array('list-type'),
	),
	'list-item' => array(),
	'long-desc' => array(),
	'media' => array(
		'xlink:href' => array(),
	),
	'monospace' => array(),
	'para' => array(),
	'preformat' => array(),
	'permissions' => array(),
	'sec' => array(),
	'title' => array(),
	'table-wrap' => array(),
	'underline' => array(),
	'uri' => array(
		'xlink:href' => array(),
	),
	'xref' => array(
		'ref-type' => array(),
		'rid' => array(),
	),
	'br' => array(),
));


/**
 * Load the editor and corresponding textarea the WP 3.3 way
 */
function anno_load_editor($content, $editor_id, $settings = array()) {
	$formats = array(
		'bold',
		'italic',
		'monospace',
		'preformat',
		'sup',
		'sub',
		'underline',
	);

	$extended_valid_elements = array_merge(array(
		'alt-text',
		'attrib',
		'cap',
		'copyright-statement',
		'copyright-holder',
		'disp-quote',
		'ext-link[ext-link-type:uri|xlink::href|title]',
		'fig',
		'heading',
		'inline-graphic[xlink::href]',
		'lbl',
		'license[license-type:creative-commons]',
		'license-p',
		'list[list-type]',
		'list-item',
		'long-desc',
		'media[xlink::href]',
		'monospace',
		'permissions',
		'para',
		'preformat',
		'sec',
		'table-wrap',
		'uri[xlink::href]',
		'xref[ref-type|rid]',
		'paste',
		'*[*]',
	), $formats);

	$custom_elements = array(
		'~bold',
		'~italic',
		'~sup',
		'~sub',
		'~monospace',
		'preformat',
		'~underline',
		'~ext-link',
		'~xref',
		'~inline-graphic',
		'~alt-text',
		'~lbl',
		'~long-desc',
		'~copyright-statement',
		'~copyright-holder',
		'~license',
		'~license-p',
		'~disp-quote',
		'~attrib',
		'heading',
		'sec',
		'list',
		'list-item',
		'fig',
		'title',
		'media',
		'permissions',
		'table-wrap',
		'cap',
		'disp-quote',
		'para',
		'paste',
		'uri',
		// Support for isBlock being case sensitive and nodeName returning capitalized version
		// tinymce 5.x+ no longer supports tinymce.html.Schema modifiction in plugin init (old way)
		'PARA',
		'CAP',
		'LABEL',
		'LIST',
		'LIST-ITEM',
	);

	$formats_as_children = implode('|', $formats);

	// Note the various html elements not defined by the DTD
	// This takes into account imported content and pasted content which gets inserted natively in divs and spans
	// BR accounts for being able to actually insert a line break, we handle removing or keep these later.
	$valid_children = array(
		'preformat[]',
		'body[sec|para|media|list|disp-formula|disp-quote|fig|table-wrap|preformat|div|span|heading|br]',
		'copyright-statement['.$formats_as_children.'|br]',
		'license-p['.$formats_as_children.'|xref|ext-link|br]',
		'heading['.$formats_as_children.'|div|span|br]',
		'media[uri|alt-text|long-desc|permissions|div|span|br]',
		'permissions[copyright-statement|copyright-holder|license|div|span|br]',
		'license[license-p|xref|div|span|br]',
		'license-p[preformat|br|'.$formats_as_children.']',
		'list[title|list-item|div|span|br]',
		'list-item[para|xref|list|div|span|br]',
		'disp-formula[lbl|tex-math|div|span|preformat|br]',
		'disp-quote[para|attrib|permissions|div|span|preformat|br]',
		'fig[lbl|cap|media|img|div|span|preformat|br]',
		'cap[title|para|xref|div|span|br]',
		'table-wrap[lbl|cap|table|table-wrap-foot|permissions|div|span|preformat|br]',
		'table-wrap-foot[para|div|span|br]',
		'td['.$formats_as_children.'|preformat|ext-link|break|list|media|inline-graphic|xref|br]',
		'th['.$formats_as_children.'|preformat|ext-link|break|list|media|inline-graphic|xref|br]',
		'para['.$formats_as_children.'|media|img|permissions|license|list|list-item|disp-formula|disp-quote|fig|cap|table-wrap|table-wrap-foot|table|h2|xref|img|table|ext-link|paste|div|span|div|span|a|br]',
		'sec[sec|heading|media|img|permissions|license|list|list-item|disp-formula|disp-quote|fig|cap|table-wrap|table-wrap-foot|para|h2|div|span|preformat|br]',
	);

	$default_settings = array(
		'wpautop' => false,
		'media_buttons' => false,
		'tinymce' => array(
			'remove_linebreaks' => false,
			'valid_elements' => array(
				'*[*]',
			),
			'extended_valid_elements' => implode(',', $extended_valid_elements),
			'custom_elements' => implode(',', $custom_elements),
			'valid_children' => implode(',', $valid_children),
			//  Defines formats.
			'formats' => "{
				bold : {'inline' : 'span', 'classes': 'bold', 'attributes' : {'data-xmlel' : 'bold'}},
				italic : {'inline' : 'span', 'classes': 'italic', 'attributes' : {'data-xmlel' : 'italic'}},
				monospace : {'inline' : 'span', 'classes': 'monospace', 'attributes' : {'data-xmlel' : 'monospace'}},
				preformat : {'block' : 'div', 'classes': 'preformat', 'attributes' : {'data-xmlel' : 'preformat'}},
				underline : {'inline' : 'span', 'classes': 'underline', 'attributes' : {'data-xmlel' : 'underline'}},
				superscript : {'inline' : 'span', 'classes': 'sup', 'attributes' : {'data-xmlel' : 'sup'}},
				subscript : {'inline' : 'span', 'classes': 'sub', 'attributes' : {'data-xmlel' : 'sub'}}
			}",
			'theme_advanced_blockformats' => 'Paragraph=para,Heading=heading,Section=sec',
			'forced_root_block' => '',
			'debug' => 'true',
			'verify_html' => true,
			'force_p_newlines' => true,
			'force_br_newlines' => false,
			'content_css' => trailingslashit(get_template_directory_uri()).'assets/main/css/tinymce.css',
			'object_resizing' => false
		),
	);
	// Remove WP specific tinyMCE edit image plugin.
	add_filter('tiny_mce_before_init', 'anno_tiny_mce_before_init');
	// Load the editor
	$content = esc_textarea($content);
	wp_editor($content, $editor_id, array_merge($default_settings, $settings));
	remove_filter('tiny_mce_before_init', 'anno_tiny_mce_before_init');
}

/**
 * Remove filters on editor content
 *
 */
function anno_remove_editor_content_filters($editor_markup) {
	global $post_type;
	if ($post_type == 'article') {
		remove_filter('the_editor_content', 'wp_richedit_pre');
		// Shouldnt be needed as richedit is enforced, but just in case
		remove_filter('the_editor_content', 'wp_htmledit_pre');
	}
	return $editor_markup;
}
// This is the only place we can hook into to remove 'the_editor_content' filters
add_filter('the_editor', 'anno_remove_editor_content_filters');

/**
 * Force rich editor for article post type.
 * This overrides user settings and preferences based on other post types
 */
function anno_force_richedit($editor_type) {
	global $post_type;
	if ($post_type == 'article') {
		$editor_type = 'tinymce';
	}
	return $editor_type;
}
add_filter('wp_default_editor', 'anno_force_richedit');

class Anno_tinyMCE {
	function Anno_tinyMCE() {
		add_filter("mce_external_plugins", array(&$this, 'plugins'));
		add_filter('mce_buttons', array(&$this, 'mce_buttons'));
		add_filter('mce_buttons_2', array(&$this, 'mce_buttons_2'));
		add_filter('mce_buttons_3', array(&$this, 'mce_buttons_3'));
		add_filter('mce_external_languages', array(&$this, 'external_languages'));
	}

	function mce_buttons($buttons) {
		if ($this->is_article()) {
			$buttons = explode(',', 'save,fullscreen,undo,redo,help,visualaid,visualchars,visualblocks,|,txt_validate_attrs,txt_validate_noattrs,|,textorum-insertion-before,textorum-insertion-inside,textorum-insertion-after,|,annopastetext');
		}
		return $buttons;
	}

	function mce_buttons_2($buttons) {
		if ($this->is_article()) {
			$buttons = explode(',', 'code,annoorderedlist,annobulletlist,bold,italic,underline,annopreformat,annomonospace,sup,sub,charmap,|,annosection,|,annoreferences,|,annoimages,|,annoquote,annoequations');
		}
		return $buttons;
	}

	function mce_buttons_3($buttons) {
		if ($this->is_article()) {
			$buttons = explode(',', 'table,row_before,row_after,delete_row,col_before,col_after,delete_col,split_cells,merge_cells');
		}
		return $buttons;
	}
<commit_msg>Removing buttons, moving a code button for context<commit_after><?php

/**
 * @package anno
 * This file is part of the Annotum theme for WordPress
 * Built on the Carrington theme framework <http://carringtontheme.com>
 *
 * Copyright 2008-2011 Crowd Favorite, Ltd. All rights reserved. <http://crowdfavorite.com>
 * Released under the GPL license
 * http://www.opensource.org/licenses/gpl-license.php
 */

/**
 * Set acceptable custom tags for wp_kses
 */
$allowedposttags = array_merge($allowedposttags, array(
	'alt-text' => array(),
	'attrib' => array(),
	'bold' => array(),
	'cap' => array(),
	'copyright-statement' => array(),
	'copyright-holder' => array(),
	'disp-quote' => array(),
	'ext-link' => array(
		'type' => array(),
		'xlink:href' => array(),
		'title' => array(),
	),
	'fig' => array(),
	'inline-graphic' => array(
		'xlink:href' => array(),
	),
	'heading' => array(),
	'italic' => array(),
	'lbl' => array(),
	'license' => array(
		'license-type' => array(),
	),
	'license-p' => array(),
	'list' => array(
		array('list-type'),
	),
	'list-item' => array(),
	'long-desc' => array(),
	'media' => array(
		'xlink:href' => array(),
	),
	'monospace' => array(),
	'para' => array(),
	'preformat' => array(),
	'permissions' => array(),
	'sec' => array(),
	'title' => array(),
	'table-wrap' => array(),
	'underline' => array(),
	'uri' => array(
		'xlink:href' => array(),
	),
	'xref' => array(
		'ref-type' => array(),
		'rid' => array(),
	),
	'br' => array(),
));


/**
 * Load the editor and corresponding textarea the WP 3.3 way
 */
function anno_load_editor($content, $editor_id, $settings = array()) {
	$formats = array(
		'bold',
		'italic',
		'monospace',
		'preformat',
		'sup',
		'sub',
		'underline',
	);

	$extended_valid_elements = array_merge(array(
		'alt-text',
		'attrib',
		'cap',
		'copyright-statement',
		'copyright-holder',
		'disp-quote',
		'ext-link[ext-link-type:uri|xlink::href|title]',
		'fig',
		'heading',
		'inline-graphic[xlink::href]',
		'lbl',
		'license[license-type:creative-commons]',
		'license-p',
		'list[list-type]',
		'list-item',
		'long-desc',
		'media[xlink::href]',
		'monospace',
		'permissions',
		'para',
		'preformat',
		'sec',
		'table-wrap',
		'uri[xlink::href]',
		'xref[ref-type|rid]',
		'paste',
		'*[*]',
	), $formats);

	$custom_elements = array(
		'~bold',
		'~italic',
		'~sup',
		'~sub',
		'~monospace',
		'preformat',
		'~underline',
		'~ext-link',
		'~xref',
		'~inline-graphic',
		'~alt-text',
		'~lbl',
		'~long-desc',
		'~copyright-statement',
		'~copyright-holder',
		'~license',
		'~license-p',
		'~disp-quote',
		'~attrib',
		'heading',
		'sec',
		'list',
		'list-item',
		'fig',
		'title',
		'media',
		'permissions',
		'table-wrap',
		'cap',
		'disp-quote',
		'para',
		'paste',
		'uri',
		// Support for isBlock being case sensitive and nodeName returning capitalized version
		// tinymce 5.x+ no longer supports tinymce.html.Schema modifiction in plugin init (old way)
		'PARA',
		'CAP',
		'LABEL',
		'LIST',
		'LIST-ITEM',
	);

	$formats_as_children = implode('|', $formats);

	// Note the various html elements not defined by the DTD
	// This takes into account imported content and pasted content which gets inserted natively in divs and spans
	// BR accounts for being able to actually insert a line break, we handle removing or keep these later.
	$valid_children = array(
		'preformat[]',
		'body[sec|para|media|list|disp-formula|disp-quote|fig|table-wrap|preformat|div|span|heading|br]',
		'copyright-statement['.$formats_as_children.'|br]',
		'license-p['.$formats_as_children.'|xref|ext-link|br]',
		'heading['.$formats_as_children.'|div|span|br]',
		'media[uri|alt-text|long-desc|permissions|div|span|br]',
		'permissions[copyright-statement|copyright-holder|license|div|span|br]',
		'license[license-p|xref|div|span|br]',
		'license-p[preformat|br|'.$formats_as_children.']',
		'list[title|list-item|div|span|br]',
		'list-item[para|xref|list|div|span|br]',
		'disp-formula[lbl|tex-math|div|span|preformat|br]',
		'disp-quote[para|attrib|permissions|div|span|preformat|br]',
		'fig[lbl|cap|media|img|div|span|preformat|br]',
		'cap[title|para|xref|div|span|br]',
		'table-wrap[lbl|cap|table|table-wrap-foot|permissions|div|span|preformat|br]',
		'table-wrap-foot[para|div|span|br]',
		'td['.$formats_as_children.'|preformat|ext-link|break|list|media|inline-graphic|xref|br]',
		'th['.$formats_as_children.'|preformat|ext-link|break|list|media|inline-graphic|xref|br]',
		'para['.$formats_as_children.'|media|img|permissions|license|list|list-item|disp-formula|disp-quote|fig|cap|table-wrap|table-wrap-foot|table|h2|xref|img|table|ext-link|paste|div|span|div|span|a|br]',
		'sec[sec|heading|media|img|permissions|license|list|list-item|disp-formula|disp-quote|fig|cap|table-wrap|table-wrap-foot|para|h2|div|span|preformat|br]',
	);

	$default_settings = array(
		'wpautop' => false,
		'media_buttons' => false,
		'tinymce' => array(
			'remove_linebreaks' => false,
			'valid_elements' => array(
				'*[*]',
			),
			'extended_valid_elements' => implode(',', $extended_valid_elements),
			'custom_elements' => implode(',', $custom_elements),
			'valid_children' => implode(',', $valid_children),
			//  Defines formats.
			'formats' => "{
				bold : {'inline' : 'span', 'classes': 'bold', 'attributes' : {'data-xmlel' : 'bold'}},
				italic : {'inline' : 'span', 'classes': 'italic', 'attributes' : {'data-xmlel' : 'italic'}},
				monospace : {'inline' : 'span', 'classes': 'monospace', 'attributes' : {'data-xmlel' : 'monospace'}},
				preformat : {'block' : 'div', 'classes': 'preformat', 'attributes' : {'data-xmlel' : 'preformat'}},
				underline : {'inline' : 'span', 'classes': 'underline', 'attributes' : {'data-xmlel' : 'underline'}},
				superscript : {'inline' : 'span', 'classes': 'sup', 'attributes' : {'data-xmlel' : 'sup'}},
				subscript : {'inline' : 'span', 'classes': 'sub', 'attributes' : {'data-xmlel' : 'sub'}}
			}",
			'theme_advanced_blockformats' => 'Paragraph=para,Heading=heading,Section=sec',
			'forced_root_block' => '',
			'debug' => 'true',
			'verify_html' => true,
			'force_p_newlines' => true,
			'force_br_newlines' => false,
			'content_css' => trailingslashit(get_template_directory_uri()).'assets/main/css/tinymce.css',
			'object_resizing' => false
		),
	);
	// Remove WP specific tinyMCE edit image plugin.
	add_filter('tiny_mce_before_init', 'anno_tiny_mce_before_init');
	// Load the editor
	$content = esc_textarea($content);
	wp_editor($content, $editor_id, array_merge($default_settings, $settings));
	remove_filter('tiny_mce_before_init', 'anno_tiny_mce_before_init');
}

/**
 * Remove filters on editor content
 *
 */
function anno_remove_editor_content_filters($editor_markup) {
	global $post_type;
	if ($post_type == 'article') {
		remove_filter('the_editor_content', 'wp_richedit_pre');
		// Shouldnt be needed as richedit is enforced, but just in case
		remove_filter('the_editor_content', 'wp_htmledit_pre');
	}
	return $editor_markup;
}
// This is the only place we can hook into to remove 'the_editor_content' filters
add_filter('the_editor', 'anno_remove_editor_content_filters');

/**
 * Force rich editor for article post type.
 * This overrides user settings and preferences based on other post types
 */
function anno_force_richedit($editor_type) {
	global $post_type;
	if ($post_type == 'article') {
		$editor_type = 'tinymce';
	}
	return $editor_type;
}
add_filter('wp_default_editor', 'anno_force_richedit');

class Anno_tinyMCE {
	function Anno_tinyMCE() {
		add_filter("mce_external_plugins", array(&$this, 'plugins'));
		add_filter('mce_buttons', array(&$this, 'mce_buttons'));
		add_filter('mce_buttons_2', array(&$this, 'mce_buttons_2'));
		add_filter('mce_buttons_3', array(&$this, 'mce_buttons_3'));
		add_filter('mce_external_languages', array(&$this, 'external_languages'));
	}

	function mce_buttons($buttons) {
		if ($this->is_article()) {
			$buttons = explode(',', 'save,fullscreen,undo,redo,|,annopastetext,|,code');
		}
		return $buttons;
	}

	function mce_buttons_2($buttons) {
		if ($this->is_article()) {
			$buttons = explode(',', 'annoorderedlist,annobulletlist,bold,italic,underline,annopreformat,annomonospace,sup,sub,charmap,|,annosection,|,annoreferences,|,annoimages,|,annoquote,annoequations');
		}
		return $buttons;
	}

	function mce_buttons_3($buttons) {
		if ($this->is_article()) {
			$buttons = explode(',', 'table,row_before,row_after,delete_row,col_before,col_after,delete_col,split_cells,merge_cells');
		}
		return $buttons;
	}

{'fraction_non_alphanumeric': 0.19881132735112458, 'fraction_numerical': 0.002214194149865983, 'mean_word_length': 5.370824053452115, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 125, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1537376', 'n_tokens_mistral': 6876, 'n_tokens_neox': 6405, 'n_words': 1099}