<commit_before><?php
require_once BSA_PATH . '/inc/util.php';

class BsaBaiduSubmit {
    // Option name
    const OPTION_NAME = 'bsa_baidu_submit';
    const OPTION_TOKEN = 'bsa_<PASSWORD>';
    const OPTION_BAIDU_APILINK = 'http://data.zz.baidu.com/urls?site=%s&token=%s&type=original';

    // Be called when the plugin is installed
    static function install() {
        BsaUtil::enable(self::OPTION_NAME);
    }

    // Add field to setting menu
    static function setting_init() {
        // Setting field of Replace Gravatar Images
        BsaUtil::add_field(self::OPTION_NAME,
                           __('Baidu Link Submit', 'bjh-site-assistant'),
                           array(__CLASS__, 'add_field'));
    }

    // Generate HTML element for enable Baidu link submit
    static function add_field() {
        echo '<fieldset><p>';
        // Add check box for enabling
        BsaUtil::add_checkbox(self::OPTION_NAME);
        // Add description
        echo '</p><p>' . __('Please input token from B<NAME>:', 'bjh-site-assistant');
        // Add text field, name OPTIONS_GROUP[OPTION_INFO] will let form submit to save to the right option
        echo '</p><p><input type="text" class="large-text" id="' . self::OPTION_TOKEN . '" '
           . (BsaUtil::is_enabled(self::OPTION_NAME) ? '' : 'disabled')
           . ' name="' . BsaConst::OPTIONS_GROUP . '[' . self::OPTION_TOKEN . ']" value="'
           . BsaUtil::get_value(self::OPTION_TOKEN, '')
           . '"></p></fieldset><br />';
?>
<script type="text/javascript">
var bsCheck = document.getElementById("<?php echo self::OPTION_NAME; ?>");

bsCheck.onclick = function() {
    var tokenField = document.getElementById("<?php echo self::OPTION_TOKEN; ?>");
    if (bsCheck.checked) {
        tokenField.disabled = false;
    } else {
        tokenField.disabled = true;
    }
}
</script>
<?php
    }

    // Add Baidu active link submit function
    static function baidu_submit($post_id) {
        // Prevent submitting the same post multi-times
        if (BsaUtil::is_enabled(self::OPTION_NAME)
          && function_exists('curl_init')    // Need php5-curl installed
          && get_post_meta($post_id,'_baidu_submitted', true) != 1) {  // Check if already submitted
            $url = get_permalink($post_ID);
            $token = BsaUtil::get_value(self::OPTION_TOKEN, '');
            $domain = home_url();

            // Strip http(s):// from the home URL
            $pos = strrpos($domain, '//');
            if($pos != false)
            {
                $domain = substr($domain,$pos + 1);
            }<commit_msg>Fix wrong extraction of domain from home URL<commit_after><?php
require_once BSA_PATH . '/inc/util.php';

class BsaBaiduSubmit {
    // Option name
    const OPTION_NAME = 'bsa_baidu_submit';
    const OPTION_TOKEN = 'bsa_baidu_token';
    const OPTION_BAIDU_APILINK = 'http://data.zz.baidu.com/urls?site=%s&token=%s&type=original';

    // Be called when the plugin is installed
    static function install() {
        BsaUtil::enable(self::OPTION_NAME);
    }

    // Add field to setting menu
    static function setting_init() {
        // Setting field of Replace Gravatar Images
        BsaUtil::add_field(self::OPTION_NAME,
                           __('Baidu Link Submit', 'bjh-site-assistant'),
                           array(__CLASS__, 'add_field'));
    }

    // Generate HTML element for enable Baidu link submit
    static function add_field() {
        echo '<fieldset><p>';
        // Add check box for enabling
        BsaUtil::add_checkbox(self::OPTION_NAME);
        // Add description
        echo '</p><p>' . __('Please input token from Baidu Zhanzhang:', 'bjh-site-assistant');
        // Add text field, name OPTIONS_GROUP[OPTION_INFO] will let form submit to save to the right option
        echo '</p><p><input type="text" class="large-text" id="' . self::OPTION_TOKEN . '" '
           . (BsaUtil::is_enabled(self::OPTION_NAME) ? '' : 'disabled')
           . ' name="' . BsaConst::OPTIONS_GROUP . '[' . self::OPTION_TOKEN . ']" value="'
           . BsaUtil::get_value(self::OPTION_TOKEN, '')
           . '"></p></fieldset><br />';
?>
<script type="text/javascript">
var bsCheck = document.getElementById("<?php echo self::OPTION_NAME; ?>");

bsCheck.onclick = function() {
    var tokenField = document.getElementById("<?php echo self::OPTION_TOKEN; ?>");
    if (bsCheck.checked) {
        tokenField.disabled = false;
    } else {
        tokenField.disabled = true;
    }
}
</script>
<?php
    }

    // Add Baidu active link submit function
    static function baidu_submit($post_id) {
        // Prevent submitting the same post multi-times
        if (BsaUtil::is_enabled(self::OPTION_NAME)
          && function_exists('curl_init')    // Need php5-curl installed
          && get_post_meta($post_id,'_baidu_submitted', true) != 1) {  // Check if already submitted
            $url = get_permalink($post_ID);
            $token = BsaUtil::get_value(self::OPTION_TOKEN, '');
            $domain = home_url();

            // Strip http(s):// from the home URL
            $pos = strrpos($domain, '://');
            if($pos != false)
            {
                $domain = substr($domain,$pos + 3);
            }
{'fraction_non_alphanumeric': 0.14432401597261837, 'fraction_numerical': 0.0011409013120365088, 'mean_word_length': 2.4811383189940437, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 35, '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': '207627', 'n_tokens_mistral': 1613, 'n_tokens_neox': 1600, 'n_words': 362}