<commit_before><?php
class Duoshuo_WordPress extends Duoshuo_Abstract{
	
	const VERSION = '1.0';
	
	protected static $_instance = null;
	
	/**
	 * 
	 * @var string
	 */
	public $pluginDirUrl;
	
	/**
	 * 
	 * @var array
	 */
	protected $errorMessages = array();
	
	protected $EMBED = false;
	
	public $shortName;
	
	public $secret;
	
	protected $_scriptsPrinted = false;
	
	protected static $_defaultOptions = array(
		'duoshuo_debug'					=>	0,
		'duoshuo_api_hostname'			=>	'api.duoshuo.com',
		'duoshuo_cron_sync_enabled'		=>	1,
		'duoshuo_seo_enabled'			=>	1,
		'duoshuo_postpone_print_scripts'=>	0,
		'duoshuo_cc_fix'				=>	1,
		'duoshuo_sync_pingback_and_trackback'=>	0,
		'duoshuo_social_login_enabled'	=>	1,
		'duoshuo_comments_wrapper_intro'=>	'',
		'duoshuo_comments_wrapper_outro'=>	'',
		'duoshuo_last_log_id'			=>	0,
	);
	
	protected function __construct(){
		$this->shortName = $this->getOption('short_name');
		$this->secret = $this->getOption('secret');
		
		foreach (self::$_defaultOptions as $optionName => $value)
			if (get_option($optionName) === false)
				update_option($optionName, $value);
		
		$this->pluginDirUrl = plugin_dir_url(__FILE__);
	}
	
	/**
	 * 
	 * @return Duoshuo_WordPress
	 */
	public static function getInstance(){
		if (self::$_instance === null)
			self::$_instance = new self();
		return self::$_instance;
	}
	
	public function timezone(){
		return get_option('gmt_offset');
	}
	
	public function getOption($key){
		return get_option('duoshuo_' . $key);
	}
	
	public function updateOption($key, $value){
		return update_option('duoshuo_' . $key, $value);
	}
	
	public function deleteOption($key){
		return delete_option('duoshuo_' . $key);
	}
	
	public function updateUserMeta($userId, $metaKey, $metaValue){
		return function_exists('update_user_meta')
			? update_user_meta($userId, $metaKey, $metaValue)
			: update_usermeta($userId, $metaKey, $metaValue);
	}
	
	public function getUserMeta($userId, $metaKey, $single = false){
		//get_user_meta 从3.0开始有效: get_usermeta($user->ID, $blog_prefix.'capabilities', true);
		return function_exists('get_user_meta')
			? get_user_meta($userId, $metaKey, true)
			: get_usermeta($userId, $metaKey);
	}
	
	public function updateThreadMeta($threadId, $metaKey, $metaValue){
		return update_post_meta($threadId, $metaKey, $metaValue);
	}
	
	public function threadKey($post){
		return $post->post_status == 'inherit'
			? ($post->post_parent ? $post->post_parent : null)
			: $post->ID;
	}
	
	public function topPost($post){
		return $post->post_status == 'inherit'
			? ($post->post_parent ? get_post($post->post_parent) : null)
			: $post;
	}
	
	public function get_blog_prefix(){
		global $wpdb;
		return method_exists($wpdb,'get_blog_prefix')
			? $wpdb->get_blog_prefix()
			: $wpdb->prefix;
	}
	
	public function connected(){
		$connected_failed = get_option('duoshuo_connect_failed');
		return $connected_failed
			? (time() - $connected_failed > 1800)
			: true;
	}
	
	public function normalizeUrl($url){
		if (strpos($url, '/') === 0){
			$site_url = get_option('site_url');
			
			if (false !== $pos = strpos($site_url, '/', 8))
				$site_url = substr($site_url, 0, $pos);
			
			return $site_url . $url;
		}
		else{
			return $url;
		}
	}
	
	public function setJwtCookie($logged_in_cookie, $expire, $expiration, $user_id, $scheme){
		$jwt = $this->jwt($user_id);
		$secure = $scheme == 'secure_auth';<commit_msg>bug fix: site_url -> siteurl<commit_after><?php
class Duoshuo_WordPress extends Duoshuo_Abstract{
	
	const VERSION = '1.0';
	
	protected static $_instance = null;
	
	/**
	 * 
	 * @var string
	 */
	public $pluginDirUrl;
	
	/**
	 * 
	 * @var array
	 */
	protected $errorMessages = array();
	
	protected $EMBED = false;
	
	public $shortName;
	
	public $secret;
	
	protected $_scriptsPrinted = false;
	
	protected static $_defaultOptions = array(
		'duoshuo_debug'					=>	0,
		'duoshuo_api_hostname'			=>	'api.duoshuo.com',
		'duoshuo_cron_sync_enabled'		=>	1,
		'duoshuo_seo_enabled'			=>	1,
		'duoshuo_postpone_print_scripts'=>	0,
		'duoshuo_cc_fix'				=>	1,
		'duoshuo_sync_pingback_and_trackback'=>	0,
		'duoshuo_social_login_enabled'	=>	1,
		'duoshuo_comments_wrapper_intro'=>	'',
		'duoshuo_comments_wrapper_outro'=>	'',
		'duoshuo_last_log_id'			=>	0,
	);
	
	protected function __construct(){
		$this->shortName = $this->getOption('short_name');
		$this->secret = $this->getOption('secret');
		
		foreach (self::$_defaultOptions as $optionName => $value)
			if (get_option($optionName) === false)
				update_option($optionName, $value);
		
		$this->pluginDirUrl = plugin_dir_url(__FILE__);
	}
	
	/**
	 * 
	 * @return Duoshuo_WordPress
	 */
	public static function getInstance(){
		if (self::$_instance === null)
			self::$_instance = new self();
		return self::$_instance;
	}
	
	public function timezone(){
		return get_option('gmt_offset');
	}
	
	public function getOption($key){
		return get_option('duoshuo_' . $key);
	}
	
	public function updateOption($key, $value){
		return update_option('duoshuo_' . $key, $value);
	}
	
	public function deleteOption($key){
		return delete_option('duoshuo_' . $key);
	}
	
	public function updateUserMeta($userId, $metaKey, $metaValue){
		return function_exists('update_user_meta')
			? update_user_meta($userId, $metaKey, $metaValue)
			: update_usermeta($userId, $metaKey, $metaValue);
	}
	
	public function getUserMeta($userId, $metaKey, $single = false){
		//get_user_meta 从3.0开始有效: get_usermeta($user->ID, $blog_prefix.'capabilities', true);
		return function_exists('get_user_meta')
			? get_user_meta($userId, $metaKey, true)
			: get_usermeta($userId, $metaKey);
	}
	
	public function updateThreadMeta($threadId, $metaKey, $metaValue){
		return update_post_meta($threadId, $metaKey, $metaValue);
	}
	
	public function threadKey($post){
		return $post->post_status == 'inherit'
			? ($post->post_parent ? $post->post_parent : null)
			: $post->ID;
	}
	
	public function topPost($post){
		return $post->post_status == 'inherit'
			? ($post->post_parent ? get_post($post->post_parent) : null)
			: $post;
	}
	
	public function get_blog_prefix(){
		global $wpdb;
		return method_exists($wpdb,'get_blog_prefix')
			? $wpdb->get_blog_prefix()
			: $wpdb->prefix;
	}
	
	public function connected(){
		$connected_failed = get_option('duoshuo_connect_failed');
		return $connected_failed
			? (time() - $connected_failed > 1800)
			: true;
	}
	
	public function normalizeUrl($url){
		if (strpos($url, '/') === 0){
			$siteurl = get_option('siteurl');
			
			if (strlen($siteurl) >=8 && (false !== $pos = strpos($siteurl, '/', 8)))
				$siteurl = substr($siteurl, 0, $pos);
			
			return $siteurl . $url;
		}
		else{
			return $url;
		}
	}
	
	public function setJwtCookie($logged_in_cookie, $expire, $expiration, $user_id, $scheme){
		$jwt = $this->jwt($user_id);
		$secure = $scheme == 'secure_auth';
{'fraction_non_alphanumeric': 0.15714911640134366, 'fraction_numerical': 0.005695925222725281, 'mean_word_length': 4.439237490071485, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '2932560', 'n_tokens_mistral': 2770, 'n_tokens_neox': 2456, 'n_words': 460}