<commit_before><?php

/**
 * WordPress modules
 * @package modules
 * @subpackage wordpress
 */

define('WPCOM_READ_URL', 'https://public-api.wordpress.com/rest/v1.1/notifications/read');
define('WPCOM_NOTICES_URL', 'https://public-api.wordpress.com/rest/v1/notifications/?number=20&fields=id,type,unread,subject,timestamp');
define('WPCOM_NOTICE_URL', 'https://public-api.wordpress.com/rest/v1/notifications/');
define('WPCOM_FP_URL', 'https://public-api.wordpress.com/rest/v1.1/freshly-pressed/?number=20&fields=ID,site_ID,author,date,title');

if (!defined('DEBUG_MODE')) { die(); }

/**
 * @subpackage feeds/handler
 */
class Hm_Handler_wordpress_msg_action extends Hm_Handler_Module {
    public function process() {

        list($success, $form) = $this->process_form(array('action_type', 'message_ids'));
        if ($success) {
            $id_list = explode(',', $form['message_ids']);
            $wp_details = $this->user_config->get('wp_connect_details', array());
            $wp_ids = array();
            if ($form['action_type'] == 'read') {
                foreach ($id_list as $msg_id) {
                    if (preg_match("/^wordpress_0_(\d)+$/", $msg_id)) {
                        $parts = explode('_', $msg_id, 3);
                        $wp_ids[] = $parts[2];
                    }
                }
                if (!empty($wp_ids)) {
                    $post = array();
                    foreach ($wp_ids as $id) {
                        $post['counts['.$id.']'] = 5;
                    }
                    $res = wp_fetch_content($wp_details, WPCOM_READ_URL, $post);
                    if (!is_array($res) || !array_key_exists('success', $res) || $res['success'] != 1) {
                        Hm_Msgs::add('ERRUnable to update read status of WordPress notification');
                    }
                }
            }
        }
    }
}

/**
 * @subpackage wordpress/handler
 */
class Hm_Handler_wp_load_sources extends Hm_Handler_Module {
    public function process() {
        if (array_key_exists('list_path', $this->request->get)) {
            $path = $this->request->get['list_path'];
        }
        else {
            $path = '';
        }
        if ($path == 'combined_inbox' || $path == 'unread') {
            $this->append('data_sources', array('callback' => 'load_wp_notices_for_combined_list', 'type' => 'wordpress', 'name' => 'WordPress.com Notifications', 'id' => 0));
        }
    }
}

/**
 * @subpackage wordpress/handler
 */
class Hm_Handler_wordpress_folders_data extends Hm_Handler_Module {
    public function process() {
        $this->out('wp_connect_details', $this->user_config->get('wp_connect_details', array()));
    }
}

/**
 * @subpackage wordpress/handler
 */
class Hm_Handler_get_wp_notice_data extends Hm_Handler_Module {
    public function process() {
        if (array_key_exists('uid', $this->request->get)) {
            $wp_details = $this->user_config->get('wp_connect_details', array());
            if ($wp_details) {
                $details = wp_get_notice_detail($wp_details, $this->request->get['uid']);
                if (is_array($details) && !empty($details)) {<commit_msg>fix a data source bug in the wp module<commit_after><?php

/**
 * WordPress modules
 * @package modules
 * @subpackage wordpress
 */

define('WPCOM_READ_URL', 'https://public-api.wordpress.com/rest/v1.1/notifications/read');
define('WPCOM_NOTICES_URL', 'https://public-api.wordpress.com/rest/v1/notifications/?number=20&fields=id,type,unread,subject,timestamp');
define('WPCOM_NOTICE_URL', 'https://public-api.wordpress.com/rest/v1/notifications/');
define('WPCOM_FP_URL', 'https://public-api.wordpress.com/rest/v1.1/freshly-pressed/?number=20&fields=ID,site_ID,author,date,title');

if (!defined('DEBUG_MODE')) { die(); }

/**
 * @subpackage feeds/handler
 */
class Hm_Handler_wordpress_msg_action extends Hm_Handler_Module {
    public function process() {

        list($success, $form) = $this->process_form(array('action_type', 'message_ids'));
        if ($success) {
            $id_list = explode(',', $form['message_ids']);
            $wp_details = $this->user_config->get('wp_connect_details', array());
            $wp_ids = array();
            if ($form['action_type'] == 'read') {
                foreach ($id_list as $msg_id) {
                    if (preg_match("/^wordpress_0_(\d)+$/", $msg_id)) {
                        $parts = explode('_', $msg_id, 3);
                        $wp_ids[] = $parts[2];
                    }
                }
                if (!empty($wp_ids)) {
                    $post = array();
                    foreach ($wp_ids as $id) {
                        $post['counts['.$id.']'] = 5;
                    }
                    $res = wp_fetch_content($wp_details, WPCOM_READ_URL, $post);
                    if (!is_array($res) || !array_key_exists('success', $res) || $res['success'] != 1) {
                        Hm_Msgs::add('ERRUnable to update read status of WordPress notification');
                    }
                }
            }
        }
    }
}

/**
 * @subpackage wordpress/handler
 */
class Hm_Handler_wp_load_sources extends Hm_Handler_Module {
    public function process() {
        $wp_details = $this->user_config->get('wp_connect_details', array());
        if (empty($wp_details)) {
            return;
        }
        if (array_key_exists('list_path', $this->request->get)) {
            $path = $this->request->get['list_path'];
        }
        else {
            $path = '';
        }
        if ($path == 'combined_inbox' || $path == 'unread') {
            $this->append('data_sources', array('callback' => 'load_wp_notices_for_combined_list', 'type' => 'wordpress', 'name' => 'WordPress.com Notifications', 'id' => 0));
        }
    }
}

/**
 * @subpackage wordpress/handler
 */
class Hm_Handler_wordpress_folders_data extends Hm_Handler_Module {
    public function process() {
        $this->out('wp_connect_details', $this->user_config->get('wp_connect_details', array()));
    }
}

/**
 * @subpackage wordpress/handler
 */
class Hm_Handler_get_wp_notice_data extends Hm_Handler_Module {
    public function process() {
        if (array_key_exists('uid', $this->request->get)) {
            $wp_details = $this->user_config->get('wp_connect_details', array());
            if ($wp_details) {
                $details = wp_get_notice_detail($wp_details, $this->request->get['uid']);
                if (is_array($details) && !empty($details)) {
{'fraction_non_alphanumeric': 0.16536158452326116, 'fraction_numerical': 0.004913250422232458, 'mean_word_length': 2.45021186440678, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 8, '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': '335548', 'n_tokens_mistral': 2053, 'n_tokens_neox': 1988, 'n_words': 316}