function wp_rp_settings_page()
{
    if (!current_user_can('delete_users')) {
        die('Sorry, you don\'t have permissions to access this page.');
    }
    wp_rp_register();
    // handle post if needed
    wp_rp_handle_postdata();
    $options = wp_rp_get_options();
    $meta = wp_rp_get_meta();
    $articles_count = wp_rp_article_count($meta['zemanta_api_key']);
    $articles_uploaded = false;
    if (isset($_GET['wp_rp_upload_articles']) && !empty($meta['zemanta_api_key'])) {
        $articles_uploaded = wp_rp_upload_articles($meta['zemanta_api_key']);
    }
    // Update already subscribed but in the old pipeline
    if (!empty($meta["email"]) && empty($meta["subscribed"])) {
        wp_rp_subscription($meta["email"], $options["subscription_types"]);
    }
    if (isset($_GET['gp_global_notice']) && $_GET['gp_global_notice'] === '0') {
        $meta['global_notice'] = null;
        wp_rp_update_meta($meta);
    }
    $input_hidden = array('wp_rp_ajax_nonce' => wp_create_nonce('wp_rp_ajax_nonce'), 'wp_rp_json_url' => esc_attr(WP_RP_STATIC_BASE_URL . WP_RP_STATIC_JSON_PATH), 'wp_rp_version' => esc_attr(WP_RP_VERSION), 'wp_rp_dashboard_url' => esc_attr(WP_RP_CTR_DASHBOARD_URL), 'wp_rp_static_base_url' => esc_attr(WP_RP_STATIC_BASE_URL));
    $settings_file = __FILE__;
    $form_url = admin_url('admin.php?page=wordpress-related-posts');
    $form_display = !$meta['registered'] && $meta['show_turn_on_button'] && !$meta['turn_on_button_pressed'] ? 'none' : 'block';
    global $wpdb;
    $custom_fields = $wpdb->get_col("SELECT meta_key FROM {$wpdb->postmeta} GROUP BY meta_key HAVING meta_key NOT LIKE '\\_%' ORDER BY LOWER(meta_key)");
    $exclude_categories = explode(',', $options['exclude_categories']);
    $categories = get_categories(array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false));
    $subs = $options["subscription_types"];
    $subs_checked = array();
    foreach (array("activityreport", "newsletter") as $type) {
        $subs_checked[$type] = strpos($subs, $type) !== false ? " checked=checked" : "";
    }
    $blog_url = get_site_url();
    include wp_rp_get_template('settings');
}
Example #2
0
function wp_rp_settings_page()
{
    if (!current_user_can('delete_users')) {
        die('Sorry, you don\'t have permissions to access this page.');
    }
    wp_rp_register();
    $options = wp_rp_get_options();
    $meta = wp_rp_get_meta();
    // Update already subscribed but in the old pipeline
    if (!empty($meta["email"]) && empty($meta["subscribed"])) {
        wp_rp_subscription($meta["email"], $options["subscription_types"]);
    }
    if (isset($_GET['wprp_global_notice']) && $_GET['wprp_global_notice'] === '0') {
        $meta['global_notice'] = null;
        wp_rp_update_meta($meta);
    }
    $postdata = stripslashes_deep($_POST);
    if (sizeof($_POST)) {
        if (!isset($_POST['_wp_rp_nonce']) || !wp_verify_nonce($_POST['_wp_rp_nonce'], 'wp_rp_settings')) {
            die('Sorry, your nonce did not verify.');
        }
        $old_options = $options;
        $new_options = array('on_single_post' => isset($postdata['wp_rp_on_single_post']), 'max_related_posts' => isset($postdata['wp_rp_max_related_posts']) && is_numeric(trim($postdata['wp_rp_max_related_posts'])) ? intval(trim($postdata['wp_rp_max_related_posts'])) : 5, 'on_rss' => isset($postdata['wp_rp_on_rss']), 'related_posts_title' => isset($postdata['wp_rp_related_posts_title']) ? trim($postdata['wp_rp_related_posts_title']) : '', 'promoted_content_enabled' => isset($postdata['wp_rp_promoted_content_enabled']), 'enable_themes' => isset($postdata['wp_rp_enable_themes']), 'max_related_post_age_in_days' => isset($postdata['wp_rp_max_related_post_age_in_days']) && is_numeric(trim($postdata['wp_rp_max_related_post_age_in_days'])) ? intval(trim($postdata['wp_rp_max_related_post_age_in_days'])) : 0, 'custom_size_thumbnail_enabled' => isset($postdata['wp_rp_custom_size_thumbnail_enabled']) && $postdata['wp_rp_custom_size_thumbnail_enabled'] === 'yes', 'custom_thumbnail_width' => isset($postdata['wp_rp_custom_thumbnail_width']) ? intval(trim($postdata['wp_rp_custom_thumbnail_width'])) : WP_RP_CUSTOM_THUMBNAILS_WIDTH, 'custom_thumbnail_height' => isset($postdata['wp_rp_custom_thumbnail_height']) ? intval(trim($postdata['wp_rp_custom_thumbnail_height'])) : WP_RP_CUSTOM_THUMBNAILS_HEIGHT, 'thumbnail_use_custom' => isset($postdata['wp_rp_thumbnail_use_custom']) && $postdata['wp_rp_thumbnail_use_custom'] === 'yes', 'thumbnail_custom_field' => isset($postdata['wp_rp_thumbnail_custom_field']) ? trim($postdata['wp_rp_thumbnail_custom_field']) : '', 'display_zemanta_linky' => $meta['show_zemanta_linky_option'] ? isset($postdata['wp_rp_display_zemanta_linky']) : true, 'only_admins_can_edit_related_posts' => !empty($postdata['wp_rp_only_admins_can_edit_related_posts']), 'desktop' => array('display_comment_count' => isset($postdata['wp_rp_desktop_display_comment_count']), 'display_publish_date' => isset($postdata['wp_rp_desktop_display_publish_date']), 'display_excerpt' => isset($postdata['wp_rp_desktop_display_excerpt']), 'display_thumbnail' => isset($postdata['wp_rp_desktop_display_thumbnail']), 'excerpt_max_length' => isset($postdata['wp_rp_desktop_excerpt_max_length']) && is_numeric(trim($postdata['wp_rp_desktop_excerpt_max_length'])) ? intval(trim($postdata['wp_rp_desktop_excerpt_max_length'])) : 200, 'custom_theme_enabled' => isset($postdata['wp_rp_desktop_custom_theme_enabled'])));
        if (!isset($postdata['wp_rp_exclude_categories'])) {
            $new_options['exclude_categories'] = '';
        } else {
            if (is_array($postdata['wp_rp_exclude_categories'])) {
                $new_options['exclude_categories'] = join(',', $postdata['wp_rp_exclude_categories']);
            } else {
                $new_options['exclude_categories'] = trim($postdata['wp_rp_exclude_categories']);
            }
        }
        foreach (array('desktop') as $platform) {
            if (isset($postdata['wp_rp_' . $platform . '_theme_name'])) {
                // If this isn't set, maybe the AJAX didn't load...
                $new_options[$platform]['theme_name'] = trim($postdata['wp_rp_' . $platform . '_theme_name']);
            } else {
                $new_options[$platform]['theme_name'] = $old_options[$platform]['theme_name'];
            }
            if (isset($postdata['wp_rp_' . $platform . '_theme_custom_css'])) {
                $new_options[$platform]['theme_custom_css'] = $postdata['wp_rp_' . $platform . '_theme_custom_css'];
            } elseif (isset($postdata["wp_rp_{$platform}_custom_theme_enabled"])) {
                $new_options[$platform]['theme_custom_css'] = '';
            } else {
                $new_options[$platform]['theme_custom_css'] = $old_options[$platform]['theme_custom_css'];
            }
        }
        if (isset($postdata['wp_rp_classic_state'])) {
            $meta['classic_user'] = true;
        } else {
            $meta['classic_user'] = false;
        }
        wp_rp_update_meta($meta);
        if (isset($postdata['wp_rp_turn_on_button_pressed'])) {
            $meta['show_turn_on_button'] = false;
            $meta['turn_on_button_pressed'] = $postdata['wp_rp_turn_on_button_pressed'];
            $new_options['desktop']['display_thumbnail'] = true;
        }
        $preprocess_thumbnails = $new_options['desktop']['display_thumbnail'] && !$old_options['desktop']['display_thumbnail'];
        $default_thumbnail_path = wp_rp_upload_default_thumbnail_file();
        if ($default_thumbnail_path === false) {
            // no file uploaded
            if (isset($postdata['wp_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'];
                wp_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 (!wp_rp_update_options($new_options)) {
                wp_rp_add_admin_notice('error', __('Failed to save settings.', 'wp_related_posts'));
            } else {
                wp_rp_add_admin_notice('updated', __('Settings saved.', 'wp_related_posts'));
            }
            if ($preprocess_thumbnails) {
                wp_rp_process_latest_post_thumbnails();
            }
        } else {
            // I should duplicate success message here
            wp_rp_add_admin_notice('updated', __('Settings saved.', 'wp_related_posts'));
        }
    }
    $input_hidden = array('wp_rp_ajax_nonce' => wp_create_nonce("wp_rp_ajax_nonce"), 'wp_rp_json_url' => esc_attr(WP_RP_CONTENT_BASE_URL . WP_RP_STATIC_JSON_PATH), 'wp_rp_version' => esc_attr(WP_RP_VERSION), 'wp_rp_dashboard_url' => esc_attr(WP_RP_CTR_DASHBOARD_URL), 'wp_rp_static_base_url' => esc_attr(WP_RP_STATIC_BASE_URL), 'wp_rp_plugin_static_base_url' => esc_attr(plugins_url("static/", __FILE__)));
    $settings_file = __FILE__;
    $form_url = admin_url('admin.php?page=wordpress-related-posts');
    $form_display = 'block';
    //($meta['show_turn_on_button'] && !$meta['turn_on_button_pressed'] ? 'none' : 'block');
    global $wpdb;
    $custom_fields = $wpdb->get_col("SELECT meta_key FROM {$wpdb->postmeta} GROUP BY meta_key HAVING meta_key NOT LIKE '\\_%' ORDER BY LOWER(meta_key)");
    $exclude_categories = explode(',', $options['exclude_categories']);
    $categories = get_categories(array('orderby' => 'name', 'order' => 'ASC', 'hide_empty' => false));
    $blog_url = get_site_url();
    include wp_rp_get_template('settings');
}
Example #3
0
function wp_rp_load_remote_notifications()
{
    $meta = wp_rp_get_meta();
    $options = wp_rp_get_options();
    $blog_id = $meta['blog_id'];
    $auth_key = $meta['auth_key'];
    $req_options = array('timeout' => 5);
    if (!$blog_id || !$auth_key || !$options['ctr_dashboard_enabled']) {
        return;
    }
    // receive remote recommendations
    $url = WP_RP_CTR_DASHBOARD_URL . "notifications/?blog_id={$blog_id}&auth_key={$auth_key}";
    $response = wp_remote_get($url, $req_options);
    if (wp_remote_retrieve_response_code($response) == 200) {
        $body = wp_remote_retrieve_body($response);
        if ($body) {
            $json = json_decode($body);
            if ($json && isset($json->status) && $json->status === 'ok' && isset($json->data) && is_object($json->data)) {
                $messages_ref =& $meta['remote_notifications'];
                $data = $json->data;
                if (isset($data->msgs) && is_array($data->msgs)) {
                    // add new messages from server and update old ones
                    foreach ($data->msgs as $msg) {
                        $messages_ref[$msg->msg_id] = $msg->text;
                    }
                    // sort messages by identifier
                    ksort($messages_ref);
                }
                if (isset($data->delete_msgs) && is_array($data->delete_msgs)) {
                    foreach ($data->delete_msgs as $msg_id) {
                        if (array_key_exists($msg_id, $messages_ref)) {
                            unset($messages_ref[$msg_id]);
                        }
                    }
                }
                if (isset($data->turn_on_remote_recommendations) && $data->turn_on_remote_recommendations) {
                    $meta['remote_recommendations'] = true;
                } else {
                    if (isset($data->turn_off_remote_recommendations) && $data->turn_off_remote_recommendations) {
                        $meta['remote_recommendations'] = false;
                    }
                }
                if (isset($data->show_blogger_network_form) && $data->show_blogger_network_form) {
                    $meta['show_blogger_network_form'] = true;
                } else {
                    if (isset($data->hide_blogger_network_form) && $data->hide_blogger_network_form) {
                        $meta['show_blogger_network_form'] = false;
                    }
                }
                if (isset($data->show_traffic_exchange) && $data->show_traffic_exchange) {
                    $meta['show_traffic_exchange'] = true;
                    $options['traffic_exchange_enabled'] = true;
                } else {
                    if (isset($data->hide_traffic_exchange) && $data->hide_traffic_exchange) {
                        $meta['show_traffic_exchange'] = false;
                        $options['traffic_exchange_enabled'] = false;
                    }
                }
                wp_rp_update_meta($meta);
                wp_rp_update_options($options);
            }
        }
    }
}