function zem_rp_global_notice() { global $pagenow, $zem_global_notice_pages; if (!current_user_can('delete_users')) { return; } $meta = zem_rp_get_meta(); $close_url = add_query_arg(array('page' => 'zemanta-related-posts', 'zem_global_notice' => 0), admin_url('admin.php')); $notice = $meta['global_notice']; if ($notice && in_array($pagenow, $zem_global_notice_pages)) { include zem_rp_get_template('global_notice'); } }
function zem_rp_settings_page() { if (!current_user_can('delete_users')) { die('Sorry, you don\'t have permissions to access this page.'); } zem_rp_register(); $options = zem_rp_get_options(); $meta = zem_rp_get_meta(); if ($meta['email'] && !$meta['subscribed']) { $sub_types = "activityreport,newsletter"; if (!empty($options['subscription_types'])) { $sub_types = $options['subscription_types']; } zem_rp_subscribe($meta['email'], $sub_types); } $articles_count = zem_rp_article_count($meta['zemanta_api_key']); $articles_uploaded = false; if (isset($_GET['zem_upload_articles']) && !empty($meta['zemanta_api_key'])) { $articles_uploaded = zem_rp_upload_articles($meta['zemanta_api_key']); } if (isset($_GET['zem_global_notice']) && $_GET['zem_global_notice'] === '0') { $meta['global_notice'] = null; zem_rp_update_meta($meta); } $postdata = stripslashes_deep($_POST); if (sizeof($_POST)) { if (!isset($_POST['_zem_rp_nonce']) || !wp_verify_nonce($_POST['_zem_rp_nonce'], 'zem_rp_settings')) { die('Sorry, your nonce did not verify.'); } $old_options = $options; $new_options = array('on_single_post' => isset($postdata['zem_rp_on_single_post']), 'max_related_posts' => isset($postdata['zem_rp_max_related_posts']) && is_numeric(trim($postdata['zem_rp_max_related_posts'])) ? intval(trim($postdata['zem_rp_max_related_posts'])) : 5, 'on_rss' => isset($postdata['zem_rp_on_rss']), 'related_posts_title' => isset($postdata['zem_rp_related_posts_title']) ? trim($postdata['zem_rp_related_posts_title']) : '', 'max_related_post_age_in_days' => isset($postdata['zem_rp_max_related_post_age_in_days']) && is_numeric(trim($postdata['zem_rp_max_related_post_age_in_days'])) ? intval(trim($postdata['zem_rp_max_related_post_age_in_days'])) : 0, 'custom_size_thumbnail_enabled' => isset($postdata['zem_rp_custom_size_thumbnail_enabled']) && $postdata['zem_rp_custom_size_thumbnail_enabled'] === 'yes', 'custom_thumbnail_width' => isset($postdata['zem_rp_custom_thumbnail_width']) ? intval(trim($postdata['zem_rp_custom_thumbnail_width'])) : ZEM_RP_CUSTOM_THUMBNAILS_WIDTH, 'custom_thumbnail_height' => isset($postdata['zem_rp_custom_thumbnail_height']) ? intval(trim($postdata['zem_rp_custom_thumbnail_height'])) : ZEM_RP_CUSTOM_THUMBNAILS_HEIGHT, 'thumbnail_use_custom' => isset($postdata['zem_rp_thumbnail_use_custom']), 'thumbnail_custom_field' => isset($postdata['zem_rp_thumbnail_custom_field']) ? trim($postdata['zem_rp_thumbnail_custom_field']) : '', 'display_zemanta_linky' => isset($postdata['zem_rp_display_zemanta_linky']), 'only_admins_can_edit_related_posts' => !empty($postdata['zem_rp_only_admins_can_edit_related_posts']), 'desktop' => array('display_thumbnail' => isset($postdata['zem_rp_desktop_display_thumbnail']), 'display_comment_count' => isset($postdata['zem_rp_desktop_display_comment_count']), 'display_publish_date' => isset($postdata['zem_rp_desktop_display_publish_date']), 'display_excerpt' => isset($postdata['zem_rp_desktop_display_excerpt']), 'excerpt_max_length' => isset($postdata['zem_rp_desktop_excerpt_max_length']) && is_numeric(trim($postdata['zem_rp_desktop_excerpt_max_length'])) ? intval(trim($postdata['zem_rp_desktop_excerpt_max_length'])) : 200, 'custom_theme_enabled' => isset($postdata['zem_rp_desktop_custom_theme_enabled']))); if (!isset($postdata['zem_rp_exclude_categories'])) { $new_options['exclude_categories'] = ''; } else { if (is_array($postdata['zem_rp_exclude_categories'])) { $new_options['exclude_categories'] = join(',', $postdata['zem_rp_exclude_categories']); } else { $new_options['exclude_categories'] = trim($postdata['zem_rp_exclude_categories']); } } foreach (array('desktop') as $platform) { if (isset($postdata['zem_rp_' . $platform . '_theme_name'])) { // If this isn't set, maybe the AJAX didn't load... $new_options[$platform]['theme_name'] = trim($postdata['zem_rp_' . $platform . '_theme_name']); if (isset($postdata['zem_rp_' . $platform . '_theme_custom_css'])) { $new_options[$platform]['theme_custom_css'] = $postdata['zem_rp_' . $platform . '_theme_custom_css']; } else { $new_options[$platform]['theme_custom_css'] = ''; } } else { $new_options[$platform]['theme_name'] = $old_options[$platform]['theme_name']; $new_options[$platform]['theme_custom_css'] = $old_options[$platform]['theme_custom_css']; } } if (isset($postdata['zem_classic_state'])) { $meta['classic_user'] = true; } else { $meta['classic_user'] = false; } zem_rp_update_meta($meta); $default_thumbnail_path = zem_rp_upload_default_thumbnail_file(); if ($default_thumbnail_path === false) { // no file uploaded if (isset($postdata['zem_rp_default_thumbnail_remove'])) { $new_options['default_thumbnail_path'] = false; } else { $new_options['default_thumbnail_path'] = $old_options['default_thumbnail_path']; } } else { if (is_wp_error($default_thumbnail_path)) { // error while upload $new_options['default_thumbnail_path'] = $old_options['default_thumbnail_path']; zem_rp_add_admin_notice('error', $default_thumbnail_path->get_error_message()); } else { // file successfully uploaded $new_options['default_thumbnail_path'] = $default_thumbnail_path; } } if ((array) $old_options != $new_options) { if (!zem_rp_update_options($new_options)) { zem_rp_add_admin_notice('error', __('Failed to save settings.', 'zemanta_related_posts')); } else { zem_rp_add_admin_notice('updated', __('Settings saved.', 'zemanta_related_posts')); } } else { // I should duplicate success message here zem_rp_add_admin_notice('updated', __('Settings saved.', 'zemanta_related_posts')); } } $settings_file = __FILE__; $blog_url = get_site_url(); include zem_rp_get_template('settings'); }