function update($input, $old_input)
 {
     global $extrp_sanitize;
     $input['post_date'] = array(isset($input['post_date_show_date']) ? sanitize_key($input['post_date_show_date']) : '', isset($input['post_date_time_diff']) ? sanitize_key($input['post_date_time_diff']) : '');
     if (isset($input['image_size'])) {
         if ('' == sanitize_key($input['image_size'])) {
             $input['post_title'] = (bool) 1;
         }
     }
     if (isset($input['highlight'])) {
         if ('' != $input['highlight']) {
             $input['hl'] = is_array($input['highlight']) ? sanitize_key($input['highlight']['hl']) : sanitize_key($input['highlight']);
             $input['hlt'] = isset($input['add']['hl_val_' . $input['hl']]) ? sanitize_text_field($input['add']['hl_val_' . $input['hl']]) : sanitize_key($input['hl']);
             if ('no' != $input['hl']) {
                 if ('col' == $input['hl'] || 'bgcol' == $input['hl']) {
                     $input['hlt'] = $extrp_sanitize->sanitize_hex_color($input['hlt']);
                 }
                 if ('css' == $input['hl']) {
                     $input['hlt'] = sanitize_text_field($input['hlt']);
                 }
                 if ('class' == $input['hl']) {
                     $input['hlt'] = sanitize_html_class($input['hlt']);
                 }
             }
             $input['highlight'] = array('hl' => $input['hl'], 'hlt' => $input['hlt']);
         }
     }
     $new_input = $old_input;
     $new_input = [];
     $default = extrp_default_setting('shortcode');
     $keys = array_keys($default);
     foreach ($keys as $k) {
         if (isset($input[$k])) {
             $new_input[$k] = $input[$k];
         } else {
             $new_input[$k] = false;
         }
     }
     return $extrp_sanitize->sanitize($new_input);
 }
 public static function on_deactivation()
 {
     global $extrp_settings, $extrp_screen_id, $extrp_screen_id_tool;
     $current_user = wp_get_current_user();
     $user_id = $current_user->ID;
     delete_user_meta($user_id, 'closedpostboxes_' . $extrp_screen_id);
     delete_user_meta($user_id, 'metaboxhidden_' . $extrp_screen_id);
     delete_user_meta($user_id, 'meta-box-order_' . $extrp_screen_id);
     delete_user_meta($user_id, 'closedpostboxes_' . $extrp_screen_id_tool);
     delete_user_meta($user_id, 'metaboxhidden_' . $extrp_screen_id_tool);
     delete_user_meta($user_id, 'meta-box-order_' . $extrp_screen_id_tool);
     self::delete_cache();
     wp_clear_scheduled_hook('extrp_delete_cache');
     $default = extrp_default_setting();
     delete_option('extrp_version');
     update_option('extrp_with_relevanssi', (bool) 0);
     $upgraded_from = get_option('extrp_version_upgraded_from');
     if ($upgraded_from) {
         delete_option('extrp_version_upgraded_from');
     }
     wp_delete_attachment(extrp_get_attach_id($extrp_settings['noimage']['default'], null), true);
 }
 private function table_data()
 {
     global $extrp_data, $extrp_sanitize;
     $setting = array_keys(extrp_default_setting('shortcode'));
     $data = [];
     foreach ($setting as $k) {
         $id = absint($extrp_sanitize->extrp_multidimensional_search($extrp_data, array('parameter' => $k)));
         $normal = $extrp_data[$id]['normal'];
         $optional = $extrp_data[$id]['optional'];
         if (is_array($extrp_data[$id]['normal'])) {
             $normal = '<kbd>' . implode('</kbd><kbd>', array_keys($normal)) . '</kbd>';
         } else {
             if ('post__in' == $k || 'post__not_in' == $k || 'image_size' == $k || 'post_date' == $k) {
                 $normal = '<em>empty</em>';
             } else {
                 $normal = '<kbd>' . $normal . '</kbd>';
             }
         }
         if (is_array($extrp_data[$id]['optional'])) {
             if ('relatedby' == $k || 'heading' == $k || 'postheading' == $k || 'display' == $k || 'shape' == $k || 'post_excerpt' == $k) {
                 $optional = '<kbd>' . implode('</kbd><kbd>', array_values($optional)) . '</kbd>';
             } elseif ('highlight' == $k) {
                 $optional = '<kbd>' . implode('</kbd><kbd>', array_keys($optional)) . '</kbd><div class="hlt"></div>';
             } else {
                 $optional = '<kbd>' . implode('</kbd><kbd>', array_keys($optional)) . '</kbd>';
             }
         } else {
             $optional = '<kbd>' . $optional . '</kbd>';
         }
         if (is_array($extrp_data[$id]['description'])) {
             $description = $extrp_data[$id]['description'][0];
         } else {
             $description = $extrp_data[$id]['description'];
         }
         $data[] = array('id' => $extrp_data[$id]['id'], 'parameter' => $extrp_data[$id]['parameter'], 'normal' => $normal, 'optional' => $optional, 'lang' => '<i>' . $extrp_data[$id]['lang'] . '</i>', 'description' => $description);
     }
     return $data;
 }
function extrp_related_posts_shortcode($atts = null, $result = '')
{
    global $post, $extrp_settings, $extrp_sanitize;
    if (is_home() || is_front_page()) {
        return;
    }
    $post_id = null === $post->ID ? get_the_ID() : (int) $post->ID;
    $option = 'shortcode';
    $default_setting = shortcode_atts(extrp_default_setting('shortcode'), $atts, 'jv-related-posts');
    $a = $extrp_sanitize->sanitize($default_setting);
    $result = extrp_create_html($a['relatedby'], $post_id, $a['single'], $a['posts'], $a['post_date'], $a['subtitle'], $a['randomposts'], $a['titlerandom'], $a['post_title'], $a['desc'], $a['image_size'], $a['display'], $a['shape'], $a['crop'], $a['heading'], $a['postheading'], $a['post_excerpt'], $a['maxchars'], $a['highlight'], $a['relevanssi'], $a['post__in'], $a['post__not_in'], $option);
    if ($extrp_settings['active']) {
        add_filter('the_content', 'extrp_filter_the_content', 10);
    }
    $author_id = $post->post_author;
    $option = 'publish_posts';
    $can_publish_posts = user_can($author_id, extrp_capability_filter($option));
    if (!$can_publish_posts) {
        return;
    }
    //well, users that can't publish posts, no cake for you. (default)
    return $result;
}
function extrp_do_your_settings($post, $arg = '')
{
    global $extrp_settings, $extrp_sanitize;
    $b = $extrp_sanitize->sanitize($extrp_settings);
    if (!$b['thumb']) {
        $b['image_size'] = false;
    }
    if (!empty($arg)) {
        $d = is_array($arg) ? $arg : array('post__not_in' => $extrp_sanitize->post_ids($arg));
        $i = extrp_default_setting('shortcode');
        $new_d = $extrp_sanitize->sanitize($d);
        foreach ($b as $k => $v) {
            if (!array_key_exists($k, $i)) {
                unset($b[$k]);
            }
            foreach ($new_d as $kk => $vv) {
                if (!array_key_exists($kk, $i)) {
                    unset($new_d[$kk]);
                }
            }
        }
        $b = wp_parse_args($new_d, $b);
    }
    return $b;
}
 public function sanitize($input)
 {
     global $extrp_sanitize, $extrp_settings;
     $extrp_data = $extrp_sanitize->big_data();
     $default = extrp_default_setting();
     $new_input = array();
     $id = absint($extrp_sanitize->extrp_multidimensional_search($extrp_data, array('parameter' => 'post_type')));
     $post_type = array();
     foreach ($extrp_data[$id]['optional'] as $type) {
         $type = sanitize_key($type);
         if (isset($input['post_type_' . $type])) {
             $post_type[] = $type;
         }
     }
     if (!array_filter($post_type)) {
         $post_type[] = 'post';
     }
     $input['post_type'] = $post_type;
     $input['post_date'] = array(isset($input['post_date_show_date']) ? sanitize_key($input['post_date_show_date']) : '', isset($input['post_date_time_diff']) ? sanitize_key($input['post_date_time_diff']) : '');
     if (isset($input['delcache'])) {
         global $wpdb;
         $caches = wp_cache_get('extrp_transient_cache_all', 'extrpcache');
         if (false == $caches) {
             $s = "%extrp_cache_post_%";
             $sql = "\n\t\t\t\t\t\t  SELECT option_name\n\t\t\t\t\t\t  FROM {$wpdb->options}\n\t\t\t\t\t\t  WHERE option_name\n\t\t\t\t\t\t  LIKE %s\n\t\t\t\t\t\t  ";
             $sql = $wpdb->prepare($sql, $s);
             $caches = $wpdb->get_col($sql);
             wp_cache_set('extrp_transient_cache_all', $caches, 'extrpcache', 300);
         }
         if ($caches) {
             $del_transient = array();
             foreach ($caches as $transient) {
                 if (!delete_option($transient)) {
                     $del_transient[] = sanitize_key($transient);
                 }
             }
             if (false == in_array('error', $del_transient)) {
                 $msg = __('Success to delete all cache.', 'extrp');
                 add_settings_error('extrp-notices', esc_attr('delete-cache'), $msg, 'updated');
             } else {
                 $msg = __('These caches still exist, try to delete again. If error still exist, check your database connection.', 'extrp');
                 $list = implode('</li><li>', $del_transient);
                 $list = sprintf('<p><ul><li>%s</li></ul></p>', $list);
                 add_settings_error('extrp-notices', esc_attr('delete-cache'), $msg . $list, 'error');
             }
         } else {
             $msg = __('Cache was empty, there is no cache need to be deleted.', 'extrp');
             add_settings_error('extrp-notices', esc_attr('delete-cache'), $msg, 'notice-warning');
         }
     }
     if (!isset($input['thumb']) && !isset($input['post_title'])) {
         $msg = __('Unable to hide the post title if thumbnail not set.', 'extrp');
         add_settings_error('extrp-notices', 'hide-title', $msg, 'notice-warning');
         $input['post_title'] = (bool) 1;
     }
     if (isset($input['relevanssi']) && 1 == $input['relevanssi']) {
         if (0 == $this->with_relevanssi) {
             add_settings_error('extrp-notices', esc_attr('error-notice-relevanssi'), __('Unable to use Relevanssi algorithm, please activate/install Relevanssi plugin', 'extrp'), 'notice-warning');
             $input['relevanssi'] = (bool) 0;
         }
     }
     if (isset($input['customsize_size']) && '' !== $input['customsize_size']) {
         if (false == $extrp_sanitize->customsize_key($input['customsize_size'])) {
             $msg = __('Unable to add this image size, please check your input again.', 'extrp');
             $keyname = sprintf('<kbd>%s</kbd>', esc_html($input['customsize_size']));
             add_settings_error('extrp-notices', 'error-notice-customsize', $msg . $keyname, 'error');
             $input['customsize'] = $extrp_settings['customsize'];
         } else {
             if ('' != intval($input['customsize_width']) && '' != intval($input['customsize_height'])) {
                 $input['customsize_crop'] = isset($input['customsize_crop']) ? (bool) 1 : (bool) 0;
                 $customsize = array();
                 for ($i = 0; $i < count($input['customsize_size']); $i++) {
                     $customsize[$i] = array('size' => sanitize_key($input['customsize_size']), 'width' => intval($input['customsize_width']), 'height' => intval($input['customsize_height']), 'crop' => wp_validate_boolean($input['customsize_crop']));
                 }
                 $input['customsize'] = $customsize;
             } else {
                 $msg = __('Unable to add this image size, width or height is not defined.', 'extrp');
                 add_settings_error('extrp-notices', 'error-notice-customsize', $msg, 'error');
                 $input['customsize'] = $extrp_settings['customsize'];
             }
         }
     }
     if (isset($input['highlight'])) {
         if ('' != $input['highlight']) {
             $input['hl'] = is_array($input['highlight']) ? $extrp_sanitize->highlight_name($input['highlight']['hl']) : $extrp_sanitize->highlight_name($input['highlight']);
             $input['hlt'] = isset($input['hl_val_' . $input['hl']]) ? sanitize_text_field($input['hl_val_' . $input['hl']]) : sanitize_key($input['hl']);
             if ('no' != $input['hl']) {
                 if ('col' == $input['hl'] || 'bgcol' == $input['hl']) {
                     $input['hlt'] = $extrp_sanitize->sanitize_hex_color($input['hlt']);
                 }
                 if ('css' == $input['hl']) {
                     $input['hlt'] = sanitize_text_field($input['hlt']);
                 }
                 if ('class' == $input['hl']) {
                     $input['hlt'] = sanitize_html_class($input['hlt']);
                 }
             }
             $input['highlight'] = array('hl' => $input['hl'], 'hlt' => $input['hlt']);
         } else {
             $msg = __('Unable to set highlight, please check your input again.', 'extrp');
             add_settings_error('extrp-notices', 'error-notice-highlight', $msg, 'error');
             $input['highlight'] = $extrp_settings['highlight'];
         }
     }
     $keys = array_keys($default);
     if (isset($input['reset']) && 'Reset' == sanitize_text_field($input['reset'])) {
         $msg = __('Success to reset your data.', 'extrp');
         add_settings_error('extrp-notices', esc_attr('reset-notice'), $msg, 'updated');
         $attach_id = extrp_get_attach_id(esc_url_raw($input['src']), null);
         if (!$attach_id) {
             $attach_id_default = extrp_get_attach_id($extrp_sanitize->noimage_default(), null);
             if (!$attach_id_default) {
                 return extrp_bail_noimage();
             }
         }
         return $default;
     }
     if (isset($input['src'])) {
         $attach_id = extrp_get_attach_id(esc_url_raw($input['src']), null);
         if (!$attach_id) {
             $attach_id_default = extrp_get_attach_id($extrp_sanitize->noimage_default(), null);
             if (!$attach_id_default) {
                 return extrp_bail_noimage();
             }
             return $extrp_settings;
         }
         $input['noimage'] = array('attachment_id' => absint($input['attachment_id']), 'default' => $extrp_sanitize->noimage_default(), 'size' => sanitize_key($input['image_size']), 'src' => esc_url_raw($input['src']), 'crop' => isset($input['crop']) ? wp_validate_boolean($input['crop']) : false);
     }
     foreach ($keys as $k) {
         if (isset($input[$k])) {
             $new_input[$k] = $input[$k];
         } else {
             $new_input[$k] = false;
         }
     }
     return $extrp_sanitize->sanitize($new_input);
 }