<commit_before><?php
/*
Plugin Name: Onebox
Plugin URI: https://github.com/surrealroad/wp-onebox
Description: Replaces a boring hyperlink with a lovely Facebook/Twitter-style box with additional information about the destination page
Version: 0.5.1
Author: Surreal Road Limited
Author URI: http://www.surrealroad.com
Text Domain: onebox
Domain Path: /languages
License: MIT
*/

/*
// debug
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);
*/

// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) ) {
	echo 'Hi there!  I\'m just a plugin, not much I can do when called directly.';
	exit;
}

class OneboxPlugin {

	//Version
	static $version ='0.5.1';
	static $sampleLink = "https://github.com/surrealroad/wp-onebox";
	static $enableAffiliate = true;

	//Options and defaults

	public function __construct() {
		register_activation_hook(__FILE__,array(__CLASS__, 'install' ));
		register_uninstall_hook(__FILE__,array( __CLASS__, 'uninstall'));
		add_action('init', array($this, 'init'));
		add_action('admin_init', array($this, 'admin_init'));
		add_action('admin_init', array($this,'registerSettings'));
		add_action('admin_menu', array($this,'pluginSettings'));
	}

	static function install(){
		update_option("onebox_version",self::$version);
		update_option("onebox_affiliate_links", self::$enableAffiliate);
		add_option("onebox_template_html", '<div class="onebox-result {class}">
<div class="onebox-header-wrapper">
<div class="onebox-header">
<a href="{url}" target="_blank" rel="nofollow">{favicon}<span class="onebox-sitename">{sitename}</span></a> / <span class="onebox-title"><a href="{url}" target="_blank" rel="nofollow">{title}</a></span>
<span class="onebox-title-button">{title-button}</span>
</div>
</div>
<div class="onebox-body-wrapper">
<a href="{url}" target="_blank" rel="nofollow">{image}</a>
<div class="onebox-body">
<p class="onebox-description">{description} — <a href="{url}">Read More</a></p><p class="onebox-additional">{additional}</p>
</div>
</div>
<div class="onebox-footer-wrapper">
<div class="onebox-footer"><span class="onebox-footer-info">{footer}</span><span class="onebox-footer-button">{footer-button}</span></div>
</div>
<div class="onebox-clearfix"></div>
</div>');
		add_option("onebox_enable_css", true);
		add_option("onebox_enable_dark_css", false);
		add_option("onebox_enable_apc_cache", true);
		add_option("onebox_github_apikey", '');
	}

	static function uninstall(){
		delete_option('onebox_version');
		delete_option('onebox_affiliate_links');
		delete_option('onebox_template_html');
		delete_option('onebox_enable_css');
		delete_option('onebox_enable_dark_css');
		delete_option('onebox_enable_apc_cache');
		delete_option('onebox_github_apikey');
	}


	public function init() {
		//Allow translations
		load_plugin_textdomain('onebox', false, basename(dirname(__FILE__)).'/languages');

		add_action('wp_enqueue_scripts', array($this, 'enqueueScripts'));
		add_action('wp_enqueue_scripts', array($this, 'enqueueStyles'));

		add_action('admin_enqueue_scripts', array($this, 'enqueueScripts'));
	}

	public function admin_init() {
	    add_settings_section('onebox-template', __( 'Template Configuration', 'onebox' ), array($this, 'initTemplateSettings'), 'onebox');
	    add_settings_field('onebox-template-html', __( 'Template HTML', 'onebox' ), array($this, 'templateHTMLInput'), 'onebox', 'onebox-template');
	    add_settings_field('onebox-enable-css', __( 'Enable Styles', 'onebox' ), array($this, 'templateCSSInput'), 'onebox', 'onebox-template');
	    add_settings_field('onebox-enable-dark-css', __( 'Use Dark Theme', 'onebox' ), array($this, 'templateDarkCSSInput'), 'onebox', 'onebox-template');
	    add_settings_section('onebox-features', __( 'Special Features', 'onebox' ), array($this, 'initFeatureSettings'), 'onebox');
	    add_settings_field('onebox-apc-cache', __( 'Enable APC Caching', 'onebox' ), array($this, 'apcCacheInput'), 'onebox', 'onebox-features');
	    add_settings_field('onebox-github-api', __( 'GitHub API Token', 'onebox' ), array($this, 'githubAPIInput'), 'onebox', 'onebox-features');
    }

    function registerSettings() {
		register_setting('onebox', 'onebox_template_html');
		register_setting('onebox', 'onebox_enable_css');
		register_setting('onebox', 'onebox_enable_dark_css');
		register_setting('onebox', 'onebox_enable_apc_cache');
		register_setting('onebox', 'onebox_github_apikey');
    }

	// Enqueue Javascript

	function enqueueScripts() {

		wp_enqueue_script(
			'onebox',
			plugins_url( '/js/onebox.js' , __FILE__ ),
			array( 'jquery' )
		);

		// build settings to use in script http://ottopress.com/2010/passing-parameters-from-php-to-javascripts-in-plugins/
		$params = array(
			"renderURL" => plugins_url( '/render.php' , __FILE__ ),
			"template" => get_option('onebox_template_html'),
			"dark" => get_option('onebox_enable_dark_css')
		);
		wp_localize_script( 'onebox', 'OneboxParams', $params );
	}

	// Enqueue Static CSS

	function enqueueStyles() {
       wp_register_style( 'oneboxStylesheet', plugins_url( '/style/onebox.css' , __FILE__ ) );
       if(get_option('onebox_enable_css')) wp_enqueue_style( 'oneboxStylesheet' );
   }


	// add [onebox] shortcode

	static function renderOneboxShortcode($atts) {
	   extract(shortcode_atts(array('url' => ""), $atts));
	   return '<div class="onebox-container"><a href="'.$url.'">'.__( 'Link', 'onebox').'</a></div>' ;<commit_msg>use wp_kses_post on html template output<commit_after><?php
/*
Plugin Name: Onebox
Plugin URI: https://github.com/surrealroad/wp-onebox
Description: Replaces a boring hyperlink with a lovely Facebook/Twitter-style box with additional information about the destination page
Version: 0.5.1
Author: Surreal Road Limited
Author URI: http://www.surrealroad.com
Text Domain: onebox
Domain Path: /languages
License: MIT
*/

/*
// debug
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);
*/

// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) ) {
	echo 'Hi there!  I\'m just a plugin, not much I can do when called directly.';
	exit;
}

class OneboxPlugin {

	//Version
	static $version ='0.5.1';
	static $sampleLink = "https://github.com/surrealroad/wp-onebox";
	static $enableAffiliate = true;

	//Options and defaults

	public function __construct() {
		register_activation_hook(__FILE__,array(__CLASS__, 'install' ));
		register_uninstall_hook(__FILE__,array( __CLASS__, 'uninstall'));
		add_action('init', array($this, 'init'));
		add_action('admin_init', array($this, 'admin_init'));
		add_action('admin_init', array($this,'registerSettings'));
		add_action('admin_menu', array($this,'pluginSettings'));
	}

	static function install(){
		update_option("onebox_version",self::$version);
		update_option("onebox_affiliate_links", self::$enableAffiliate);
		add_option("onebox_template_html", '<div class="onebox-result {class}">
<div class="onebox-header-wrapper">
<div class="onebox-header">
<a href="{url}" target="_blank" rel="nofollow">{favicon}<span class="onebox-sitename">{sitename}</span></a> / <span class="onebox-title"><a href="{url}" target="_blank" rel="nofollow">{title}</a></span>
<span class="onebox-title-button">{title-button}</span>
</div>
</div>
<div class="onebox-body-wrapper">
<a href="{url}" target="_blank" rel="nofollow">{image}</a>
<div class="onebox-body">
<p class="onebox-description">{description} — <a href="{url}">Read More</a></p><p class="onebox-additional">{additional}</p>
</div>
</div>
<div class="onebox-footer-wrapper">
<div class="onebox-footer"><span class="onebox-footer-info">{footer}</span><span class="onebox-footer-button">{footer-button}</span></div>
</div>
<div class="onebox-clearfix"></div>
</div>');
		add_option("onebox_enable_css", true);
		add_option("onebox_enable_dark_css", false);
		add_option("onebox_enable_apc_cache", true);
		add_option("onebox_github_apikey", '');
	}

	static function uninstall(){
		delete_option('onebox_version');
		delete_option('onebox_affiliate_links');
		delete_option('onebox_template_html');
		delete_option('onebox_enable_css');
		delete_option('onebox_enable_dark_css');
		delete_option('onebox_enable_apc_cache');
		delete_option('onebox_github_apikey');
	}


	public function init() {
		//Allow translations
		load_plugin_textdomain('onebox', false, basename(dirname(__FILE__)).'/languages');

		add_action('wp_enqueue_scripts', array($this, 'enqueueScripts'));
		add_action('wp_enqueue_scripts', array($this, 'enqueueStyles'));

		add_action('admin_enqueue_scripts', array($this, 'enqueueScripts'));
	}

	public function admin_init() {
	    add_settings_section('onebox-template', __( 'Template Configuration', 'onebox' ), array($this, 'initTemplateSettings'), 'onebox');
	    add_settings_field('onebox-template-html', __( 'Template HTML', 'onebox' ), array($this, 'templateHTMLInput'), 'onebox', 'onebox-template');
	    add_settings_field('onebox-enable-css', __( 'Enable Styles', 'onebox' ), array($this, 'templateCSSInput'), 'onebox', 'onebox-template');
	    add_settings_field('onebox-enable-dark-css', __( 'Use Dark Theme', 'onebox' ), array($this, 'templateDarkCSSInput'), 'onebox', 'onebox-template');
	    add_settings_section('onebox-features', __( 'Special Features', 'onebox' ), array($this, 'initFeatureSettings'), 'onebox');
	    add_settings_field('onebox-apc-cache', __( 'Enable APC Caching', 'onebox' ), array($this, 'apcCacheInput'), 'onebox', 'onebox-features');
	    add_settings_field('onebox-github-api', __( 'GitHub API Token', 'onebox' ), array($this, 'githubAPIInput'), 'onebox', 'onebox-features');
    }

    function registerSettings() {
		register_setting('onebox', 'onebox_template_html');
		register_setting('onebox', 'onebox_enable_css');
		register_setting('onebox', 'onebox_enable_dark_css');
		register_setting('onebox', 'onebox_enable_apc_cache');
		register_setting('onebox', 'onebox_github_apikey');
    }

	// Enqueue Javascript

	function enqueueScripts() {

		wp_enqueue_script(
			'onebox',
			plugins_url( '/js/onebox.js' , __FILE__ ),
			array( 'jquery' )
		);

		// build settings to use in script http://ottopress.com/2010/passing-parameters-from-php-to-javascripts-in-plugins/
		$params = array(
			"renderURL" => plugins_url( '/render.php' , __FILE__ ),
			"template" => wp_kses_post(get_option('onebox_template_html')),
			"dark" => get_option('onebox_enable_dark_css')
		);
		wp_localize_script( 'onebox', 'OneboxParams', $params );
	}

	// Enqueue Static CSS

	function enqueueStyles() {
       wp_register_style( 'oneboxStylesheet', plugins_url( '/style/onebox.css' , __FILE__ ) );
       if(get_option('onebox_enable_css')) wp_enqueue_style( 'oneboxStylesheet' );
   }


	// add [onebox] shortcode

	static function renderOneboxShortcode($atts) {
	   extract(shortcode_atts(array('url' => ""), $atts));
	   return '<div class="onebox-container"><a href="'.$url.'">'.__( 'Link', 'onebox').'</a></div>' ;
{'fraction_non_alphanumeric': 0.17554688209131342, 'fraction_numerical': 0.0019969138603975673, 'mean_word_length': 6.384718498659518, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 95, 'https://': 4, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1937382', 'n_tokens_mistral': 3817, 'n_tokens_neox': 3636, 'n_words': 661}