Ejemplo n.º 1
0
function zem_rp_get_related_posts()
{
    if (zem_rp_should_exclude()) {
        return;
    }
    global $post, $zem_rp_is_first_widget;
    $options = zem_rp_get_options();
    $platform_options = zem_rp_get_platform_options();
    $meta = zem_rp_get_meta();
    $posts_and_title = zem_rp_fetch_posts_and_title();
    $related_posts = $posts_and_title['posts'];
    $title = $posts_and_title['title'];
    $selected_related_posts = zem_rp_get_selected_posts();
    $related_posts_content = "";
    if (!$related_posts) {
        return;
    }
    $posts_footer = '';
    if (current_user_can($options['only_admins_can_edit_related_posts'] ? 'manage_options' : 'edit_posts')) {
        $posts_footer .= '<div class="zem_rp_footer" style="text-align: right;"><a class="zem_rp_edit" href="#" id="zem_rp_edit_related_posts">' . __('Edit Related Posts', 'zemanta_related_posts') . '</a></div>';
    }
    if ($options['display_zemanta_linky']) {
        $posts_footer .= '<div class="zem_rp_footer" style="text-align: right;">' . '<a class="zem_rp_backlink" style="color: #999; font-size: 11px; text-decoration: none;" target="_blank" href="http://www.zemanta.com/?related-posts" rel="nofollow">Zemanta</a>' . '</div>';
    }
    $css_classes = 'related_post zem_rp';
    $css_classes_wrap = str_replace(array('.css', '-'), array('', '_'), esc_attr('zem_rp_th_' . $platform_options['theme_name']));
    if ($related_posts) {
        $related_posts_lis = zem_rp_generate_related_posts_list_items($related_posts, $selected_related_posts);
        $related_posts_ul = '<ul class="' . $css_classes . '">' . $related_posts_lis . '</ul>';
        $related_posts_content = $title ? '<h3 class="related_post_title">' . $title . '</h3>' : '';
        $related_posts_content .= $related_posts_ul;
    }
    $first_id_attr = '';
    if ($zem_rp_is_first_widget) {
        $zem_rp_is_first_widget = false;
        $first_id_attr = 'id="zem_rp_first"';
    }
    $output = '<div class="zem_rp_wrap ' . $css_classes_wrap . '" ' . $first_id_attr . '>' . '<div class="zem_rp_content">' . $related_posts_content . $posts_footer . '</div>' . '</div>';
    return "\n" . $output . "\n";
}
Ejemplo n.º 2
0
function zem_is_classic()
{
    $meta = zem_rp_get_meta();
    if (isset($meta['classic_user']) && $meta['classic_user']) {
        return true;
    }
    return false;
}
Ejemplo n.º 3
0
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');
}