<commit_before><?php

/**
 * @file
 * Main helper functions used in the plugin.
 *
 * These functions are used for admin pages and view rendering.
 *
 * Created by: Topsitemakers
 * http://www.topsitemakers.com/
 */

/**
 * Handle saving of admin settings data - mass.
 */
if (!function_exists('custom_debug_admin_page_save_handle')):
function custom_debug_admin_page_save_handle($message = FALSE) {
  if ($_POST) {
    foreach ($_POST as $id => $value) update_option(CUSTOM_DEBUG_SHORTNAME . $id, $value);
    $message = $message ? $message : '<p>' . __('Options saved successfully.') . '</p>';
    print '<div id="message" class="updated">' . $message . '</div>';
  }
}
endif;

/**
 * Include ("render") a view.
 */
if (!function_exists('custom_debug_get_view')):
function custom_debug_get_view($view) {
  include(plugin_dir_path(__FILE__) . '/../views/' . $view . '.php');
}
endif;

/**
 * Get the list of all active users. To be used for admin settings.
 */
if (!function_exists('custom_debug_get_list_of_users')):
function custom_debug_get_list_of_users() {
  global $wpdb;
  $users_results = $wpdb->get_results("SELECT `ID`, `user_login` FROM $wpdb->users WHERE `user_status` = 0 ORDER BY `user_login` ASC");
  $users = array(0 => __('-- Please select --'));
  foreach ($users_results as $user) {
    $users[$user->ID] = $user->user_login . ' (ID: ' . $user->ID . ')';
  }
  
  return $users;
}
endif;

/**
 * Get the list of all published posts. To be used for admin settings.
 * Can optionally filter the posts according to a specific post type.
 */
if (!function_exists('custom_debug_get_list_of_posts')):
function custom_debug_get_list_of_posts($type = 'post') {
  global $wpdb;
  $posts_results = $wpdb->get_results($wpdb->prepare("SELECT `ID`, `post_title` FROM $wpdb->posts WHERE `post_type` = '%s' AND `post_status` = 'publish' ORDER BY `post_title` ASC", array($type)));
  $posts = array(0 => __('-- Please select --'));
  foreach ($posts_results as $post) {
    $posts[$post->ID] = $post->post_title . ' (ID: ' . $post->ID . ')';
  }

  return $posts;
}
endif;

/**
 * Log output to the database.
 */
function custom_debug_watchdog($output, $type = 'log') {
  global $wpdb;
  $query = $wpdb->prepare("INSERT INTO {$wpdb->prefix}custom_debug (`time`, `type`, `output`) VALUES (%d, '%s', '%s')", array(
    current_time('timestamp'),
    $type,
    $output,
  ));
  $wpdb->query($query);
}

/**
 * Check if an option exists in the database.
 *
 * This is used for reactivating the plugin and avoiding to rewrite existing
 * settings on the site. The reason regular get_option() won't work properly
 * in this case is when you have booleans as values - if the value is set to
 * FALSE, the response will be the same as if the value does not exist in the
 * database at all.
 */
function custom_debug_option_exists($option_name) {
  global $wpdb;
  $query = $wpdb->prepare("SELECT `option_id` FROM $wpdb->options WHERE `option_name` = '%s'", array($option_name));

  return $wpdb->get_var($query);
}<commit_msg>Allowing overriding of all helper functions<commit_after><?php

/**
 * @file
 * Main helper functions used in the plugin.
 *
 * These functions are used for admin pages and view rendering.
 *
 * Created by: Topsitemakers
 * http://www.topsitemakers.com/
 */

/**
 * Handle saving of admin settings data - mass.
 */
if (!function_exists('custom_debug_admin_page_save_handle')):
function custom_debug_admin_page_save_handle($message = FALSE) {
  if ($_POST) {
    foreach ($_POST as $id => $value) update_option(CUSTOM_DEBUG_SHORTNAME . $id, $value);
    $message = $message ? $message : '<p>' . __('Options saved successfully.') . '</p>';
    print '<div id="message" class="updated">' . $message . '</div>';
  }
}
endif;

/**
 * Include ("render") a view.
 */
if (!function_exists('custom_debug_get_view')):
function custom_debug_get_view($view) {
  include(plugin_dir_path(__FILE__) . '/../views/' . $view . '.php');
}
endif;

/**
 * Get the list of all active users. To be used for admin settings.
 */
if (!function_exists('custom_debug_get_list_of_users')):
function custom_debug_get_list_of_users() {
  global $wpdb;
  $users_results = $wpdb->get_results("SELECT `ID`, `user_login` FROM $wpdb->users WHERE `user_status` = 0 ORDER BY `user_login` ASC");
  $users = array(0 => __('-- Please select --'));
  foreach ($users_results as $user) {
    $users[$user->ID] = $user->user_login . ' (ID: ' . $user->ID . ')';
  }
  
  return $users;
}
endif;

/**
 * Get the list of all published posts. To be used for admin settings.
 * Can optionally filter the posts according to a specific post type.
 */
if (!function_exists('custom_debug_get_list_of_posts')):
function custom_debug_get_list_of_posts($type = 'post') {
  global $wpdb;
  $posts_results = $wpdb->get_results($wpdb->prepare("SELECT `ID`, `post_title` FROM $wpdb->posts WHERE `post_type` = '%s' AND `post_status` = 'publish' ORDER BY `post_title` ASC", array($type)));
  $posts = array(0 => __('-- Please select --'));
  foreach ($posts_results as $post) {
    $posts[$post->ID] = $post->post_title . ' (ID: ' . $post->ID . ')';
  }

  return $posts;
}
endif;

/**
 * Log output to the database.
 */
if (!function_exists('custom_debug_watchdog')):
function custom_debug_watchdog($output, $type = 'log') {
  global $wpdb;
  $query = $wpdb->prepare("INSERT INTO {$wpdb->prefix}custom_debug (`time`, `type`, `output`) VALUES (%d, '%s', '%s')", array(
    current_time('timestamp'),
    $type,
    $output,
  ));
  $wpdb->query($query);
}
endif;

/**
 * Check if an option exists in the database.
 *
 * This is used for reactivating the plugin and avoiding to rewrite existing
 * settings on the site. The reason regular get_option() won't work properly
 * in this case is when you have booleans as values - if the value is set to
 * FALSE, the response will be the same as if the value does not exist in the
 * database at all.
 */
if (!function_exists('custom_debug_option_exists')):
function custom_debug_option_exists($option_name) {
  global $wpdb;
  $query = $wpdb->prepare("SELECT `option_id` FROM $wpdb->options WHERE `option_name` = '%s'", array($option_name));

  return $wpdb->get_var($query);
}
endif;
{'fraction_non_alphanumeric': 0.16346309158455824, 'fraction_numerical': 0.0009691487643353255, 'mean_word_length': 4.220910623946037, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5078812', 'n_tokens_mistral': 2048, 'n_tokens_neox': 2018, 'n_words': 593}