function form($instance)
 {
     $title = esc_attr($instance['title']);
     $feed_id = @$instance['feed_id'];
     $posts_limit = @$instance['posts_limit'];
     // Set defaults
     // ...
     $opts = new Wdgpo_Options();
     $gplus_feeds = $opts->get_option('gplus_import_ids');
     $gplus_feeds = $gplus_feeds ? array_filter($gplus_feeds) : array();
     $gplus_feeds[] = $opts->get_option('gplus_page_id');
     $gplus_feeds[] = $opts->get_option('gplus_profile_id');
     $posts_limit = $posts_limit ? $posts_limit : 10;
     $html = '<p>';
     $html .= '<label for="' . $this->get_field_id('title') . '">' . __('Title:', 'wdgpo') . '</label>';
     $html .= '<input type="text" name="' . $this->get_field_name('title') . '" id="' . $this->get_field_id('title') . '" class="widefat" value="' . $title . '"/>';
     $html .= '</p>';
     $html .= '<p>';
     $html .= '<label for="' . $this->get_field_id('feed_id') . '">' . __('Show items for this feed:', 'wdgpo') . '</label> ';
     $html .= '<select name="' . $this->get_field_name('feed_id') . '" id="' . $this->get_field_id('feed_id') . '">';
     foreach ($gplus_feeds as $key => $feed) {
         $selected = $feed == $feed_id ? 'selected="selected"' : '';
         $html .= "<option value='{$feed}' {$selected}>{$feed}&nbsp;</option>";
     }
     $html .= '</select>';
     $html .= '</p>';
     $html .= '<p>';
     $html .= '<label for="' . $this->get_field_id('posts_limit') . '">' . __('Show this many imported posts:', 'wdgpo') . '</label> ';
     $html .= '<select name="' . $this->get_field_name('posts_limit') . '" id="' . $this->get_field_id('posts_limit') . '">';
     for ($i = 1; $i < 21; $i++) {
         $selected = $i == $posts_limit ? 'selected="selected"' : '';
         $html .= "<option value='{$i}' {$selected}>{$i}</option>";
     }
     $html .= '</select>';
     $html .= '</p>';
     echo $html;
 }
Ejemplo n.º 2
0
            define('WDGPO_PLUGIN_URL', str_replace('http://', @$_SERVER["HTTPS"] == 'on' ? 'https://' : 'http://', WP_PLUGIN_URL), true);
            $textdomain_handler = 'load_plugin_textdomain';
        } else {
            // No textdomain is loaded because we can't determine the plugin location.
            // No point in trying to add textdomain to string and/or localizing it.
            wp_die(__('There was an issue determining where Google+ plugin is installed. Please reinstall.'));
        }
    }
}
$textdomain_handler('wdgpo', false, WDGPO_PLUGIN_SELF_DIRNAME . '/languages/');
require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wdgpo_installer.php';
Wdgpo_Installer::check();
require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wdgpo_logger.php';
require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wdgpo_options.php';
require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wdgpo_codec.php';
Wdgpo_Options::populate();
require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wdgpo_google_auth.php';
Wdgpo_GoogleAuth::init();
require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wdgpo_scheduled_importer.php';
// Widgets
require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wpgpo_widget.php';
add_action('widgets_init', create_function('', "register_widget('Wdgpo_WidgetPlusone');"));
require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wpgpo_gplus_page_widget.php';
add_action('widgets_init', create_function('', "register_widget('Wdgpo_Gplus_WidgetPage');"));
require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wpgpo_gplus_activities_widget.php';
add_action('widgets_init', create_function('', "register_widget('Wdgpo_Gplus_WidgetActivities');"));
if (is_admin()) {
    require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wdgpo_admin_form_renderer.php';
    require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wdgpo_admin_pages.php';
    require_once WDGPO_PLUGIN_BASE_DIR . '/lib/class_wdgpo_contextual_help.php';
    Wdgpo_AdminPages::serve();
 function _show_posts($limit)
 {
     $feed_id = Wdgpo_Options::get_option('gplus_page_id');
     $query = new WP_Query(array('post_type' => array('post', 'wdgpo_imported_post'), 'meta_key' => 'wdgpo_gplus_feed_id', 'meta_value' => $feed_id, 'posts_per_page' => (int) $limit));
     echo "<ul class='wdgpo_gplus_posts'>";
     foreach ($query->posts as $post) {
         $url = 'wdgpo_imported_post' == $post->post_type ? get_post_meta($post->ID, 'wdgpo_gplus_item_id', true) : get_permalink($post->ID);
         echo "<li>";
         echo '<a class="wdgpo_gplus_post_title" href="' . esc_url($url) . '">' . esc_html($post->post_title) . '</a>';
         echo "</li>";
     }
     echo "</ul>";
 }
 function process_gplus_page_code($args)
 {
     $args = shortcode_atts(array('appearance' => false, 'float' => false), $args);
     $appearance = $args['appearance'] ? $args['appearance'] : 'medium_icon';
     $float = in_array($args['float'], array('left', 'right')) ? "style='float:{$args['float']};'" : '';
     $data = new Wdgpo_Options();
     $page_id = $data->get_option('gplus_page_id');
     if (!$page_id) {
         return '';
     }
     $tpl = '<a href="https://plus.google.com/%s/?prsrc=3" style="text-decoration: none;"><img src="https://ssl.gstatic.com/images/icons/gplus-%d.png" width="%d" height="%d" style="border: 0;"></img></a>';
     $tpl = "<div class='wdgpo wdgpo_gplus_page wdgpo_gplus_page_{$appearance}' {$float}>{$tpl}</div>";
     $ret = '';
     switch ($appearance) {
         case "small_icon":
             $ret = sprintf($tpl, $page_id, 16, 16, 16);
             break;
         case "medium_icon":
             $ret = sprintf($tpl, $page_id, 32, 32, 32);
             break;
         case "large_icon":
             $ret = sprintf($tpl, $page_id, 64, 64, 64);
             break;
     }
     return $ret;
 }
 function create_gplus_import_settings_box()
 {
     if (!function_exists('curl_init')) {
         return false;
     }
     global $current_user;
     $opt = $this->_get_option();
     $post_category = @$opt['gplus_post_category'];
     $post_tags = @$opt['gplus_post_tags'];
     $post_tags = $post_tags ? $post_tags : array();
     $post_format = @$opt['gplus_post_format'];
     $import_ids = @$opt['gplus_import_ids'];
     $import_ids = $import_ids ? array_filter($import_ids) : array();
     $post_author = @$opt['gplus_post_author'];
     $post_author = $post_author ? $post_author : $current_user->user_login;
     $import_hashtags = @$opt['gplus_import_hashtags'];
     $import_limit = (int) @$opt['gplus_import_limit'];
     $import_limit = $import_limit ? $import_limit : Wdgpo_GoogleAuth::GPLUS_MAX_RESULTS;
     $formats_to_hashtags = @$opt['gplus_formats_to_hashtags'];
     $formats_to_hashtags = $formats_to_hashtags ? $formats_to_hashtags : array();
     // Multiple import
     if (!$import_ids) {
         echo '<p><a href="#multiple_import" id="wdgpo-multiple_import-action">' . __('Multiple import', 'wdgpo') . '</a></p>';
     }
     $style = $import_ids ? 'block' : 'none';
     echo '<div id="wdgpo-multiple_import" style="display:' . $style . '">';
     echo '<ul>';
     $import_ids[] = '';
     // One for the empty item
     foreach ($import_ids as $idx => $id) {
         $id = esc_attr($id);
         echo '<li>';
         echo "<label>" . __('Google+ ID:', 'wdgpo') . "</label> ";
         echo "<input type='text' size='64' name='wdgpo[gplus_import_ids][]' value='{$id}' />";
         echo ' <a href="#wdgpo-remove_item" class="wdgpo-multiple_import-remove_item">' . __('Remove', 'wdgpo') . '</a>';
         echo '</li>';
     }
     echo '</ul>';
     echo '<input type="button" id="wdgpo-multi_import-add_one" value="' . esc_attr(__('Add Google+ ID to import', 'wdgpo')) . '" />';
     echo '</div>';
     echo '<div><small>' . __('In addition to your page, you can import posts from a number of other Google+ profiles/pages.', 'wdgpo') . '</small></div>';
     echo '<div><small>' . __('Keep in mind that every additional import adds more to total processing time.', 'wdgpo') . '</small></div>';
     // Publish posts
     echo "<br />";
     if (defined('BP_VERSION')) {
         // BuddyPress activities
         $bp_checked = @$opt['gplus_post_bp_activities'] ? 'checked="checked"' : '';
         $wp_checked = @$opt['gplus_post_no_publish'] ? '' : 'checked="checked"';
         echo '<label for="">' . __('Import posts into BuddyPress as:', 'wdgpo') . '</label><br />' . '<input type="hidden" value="0" name="wdgpo[gplus_post_bp_activities]">' . '<input id="gplus_post_bp_activities" type="checkbox" value="1" name="wdgpo[gplus_post_bp_activities]" ' . $bp_checked . '>' . ' <label for="gplus_post_bp_activities">' . __('Activities', 'wdgpo') . '</label>' . '<div><small>' . __('Select this option if you want import your Google+ activities as BuddyPress activities.', 'wdgpo') . '</small></div>' . '<input type="hidden" value="1" name="wdgpo[gplus_post_no_publish]">' . '<input id="gplus_post_no_publish" type="checkbox" value="0" name="wdgpo[gplus_post_no_publish]" ' . $wp_checked . '>' . ' <label for="gplus_post_no_publish">' . __('Posts', 'wdgpo') . '</label>' . '<div><small>' . __('Select this option if you want import your Google+ activities as posts on your blog.', 'wdgpo') . '</small></div>' . '<div><small>' . __('Changing these settings will only affect newly imported posts.', 'wdgpo') . '</small></div>' . "";
     } else {
         // Regular WordPress
         echo '<label for="">' . __('I want to display my imported posts in widgets and shortcode only:', 'wdgpo') . '</label><br />' . $this->_create_checkbox('gplus_post_no_publish') . '<div><small>' . __('Select this option if you want to show your imported posts in your widgets, but not actually post them on your blog.', 'wdgpo') . '</small></div>' . '<div><small>' . __('Changing this setting will only affect newly imported posts.', 'wdgpo') . '</small></div>' . "";
     }
     // Import limit
     echo "<br />";
     echo '<label for="wdgpo-gplus_import_limit">' . __('Limit import to this many posts:', 'wdgpo') . '</label> ' . "<input type='text' size='3' name='wdgpo[gplus_import_limit]' id='wdgpo-gplus_import_limit' value='{$import_limit}' />" . '<div><small>' . __('At most this many posts will be imported', 'wdgpo') . '</small></div>' . '<div><small>' . __("To prevent timeout issues and incomplete imports, you'll want to keep this number fairly low.", 'wdgpo') . '</small></div>' . "";
     // Import now
     if (@Wdgpo_Options::get_token()) {
         echo '<p><input type="button" id="wdgpo-gplus_import_now" value="' . esc_attr(__('Import now', 'wdgpo')) . '" /></p>';
     }
     // Author assignment
     echo "<h4>" . __('Author assignment', 'wgdpo') . "</h4>";
     echo '<label for="wdgpo-gplus_post_author">' . __('Assign imported posts to this user:'******'wdgpo') . '</label> ' . "<input type='text' size='32' name='wdgpo[gplus_post_author]' id='wdgpo-gplus_post_author' value='{$post_author}' />" . "<br />";
     $user = get_userdatabylogin($post_author);
     if (!$user->ID) {
         echo '<div class="error below-h2"><p>' . __('Invalid username!', 'wdgpo') . '</p></div>';
     }
     echo '<div><small>' . __('All your imported posts will be assigned to this user.', 'wdgpo') . '</small></div>';
     // Categories
     echo "<h4>" . __('Category assignment', 'wgdpo') . "</h4>";
     $categories = get_categories(array('type' => 'post', 'taxonomy' => 'category', 'hierarchical' => 1, 'hide_empty' => 0));
     echo '<label for="wdgpo-gplus_post_category">' . __('Apply this category:', 'wdqs') . '</label> ';
     echo '<select name="wdgpo[gplus_post_category]" id="wdgpo-gplus_post_category">';
     echo "<option value=''>" . __('No category', 'wdgpo') . "</option>";
     foreach ($categories as $category) {
         $selected = $category->term_id == $post_category ? "selected='selected'" : '';
         $name = esc_html($category->name);
         if ($category->parent) {
             $name = "&#8212;&nbsp;{$name}";
         }
         echo "<option value='{$category->term_id}' {$selected}>{$name}</option>";
     }
     echo '</select>';
     echo '<div><small>' . __('This category will be automatically added to all your imported posts.', 'wdgpo') . '</small></div>';
     // Tags
     echo "<h4>" . __('Tags assignment', 'wgdpo') . "</h4>";
     $tags = get_tags(array('hide_empty' => 0));
     echo '<label for="wdgpo-gplus_post_tags">' . __('Apply these tags:', 'wdqs') . '</label><br /> ';
     echo '<select style="height:6em" name="wdgpo[gplus_post_tags][]" multiple="multiple" size="3" id="wdgpo-gplus_post_tags">';
     foreach ($tags as $tag) {
         $selected = in_array($tag->slug, $post_tags) ? "selected='selected'" : '';
         $name = esc_html($tag->name);
         echo "<option value='{$tag->slug}' {$selected}>{$name}</option>";
     }
     echo '</select>';
     echo '<div><small>' . __('These tags will be automatically added to all your imported posts.', 'wdgpo') . '</small></div>';
     echo '<label for="gplus_auto_tag-yes">' . __('Auto-create and apply tags from activity author name:', 'wdgpo') . '</label> ' . $this->_create_checkbox('gplus_auto_tag') . "<br />";
     echo '<div><small>' . __('All your imported posts will be auto-tagged according to activity author display name.', 'wdgpo') . '</small></div>';
     echo '<label for="gplus_auto_hashtag-yes">' . __('Auto-create and apply tags from detected hashtags:', 'wdgpo') . '</label> ' . $this->_create_checkbox('gplus_auto_hashtag') . "<br />";
     echo '<div><small>' . __('All your imported posts will be auto-tagged according to detected hashtags.', 'wdgpo') . '</small></div>';
     // Post formats
     echo "<h4>" . __('Post formats assignment', 'wgdpo') . "</h4>";
     $theme_formats = get_theme_support('post-formats');
     $theme_formats = is_array($theme_formats) ? $theme_formats[0] : array();
     array_unshift($theme_formats, '');
     echo '<label for="wdgpo-gplus_post_format">' . __('Apply this post format:', 'wdgpo') . '</label> ';
     if (!current_theme_supports('post-formats') || !$theme_formats) {
         _e('<p>Your theme does not support post formats</p>', 'wdgpo');
     } else {
         echo '<select name="wdgpo[gplus_post_format]" id="wdgpo-gplus_post_format">';
         foreach ($theme_formats as $format) {
             $selected = $format == $post_format ? "selected='selected'" : '';
             $name = esc_html(get_post_format_string($format));
             echo "<option value='{$format}' {$selected}>{$name}</option>";
         }
         echo '</select>';
         echo '<div><small>' . __('This format will be applied to all your imported posts.', 'wdgpo') . '</small></div>';
         // Post Formats to Hashtags
         echo "<br />";
         echo "<ul>";
         foreach ($theme_formats as $format) {
             if (!$format) {
                 continue;
             }
             $hashtags = esc_attr(@$formats_to_hashtags[$format]);
             $name = esc_html(get_post_format_string($format));
             echo '<li>';
             echo "<label for='wdgpo-map-{$format}-to-hashtags'>" . sprintf(__('Map <b>%s</b> post format to imported posts with these hashtags:', 'wdgpo'), $format) . '</label> ';
             echo "<input type='text' size='32' name='wdgpo[gplus_formats_to_hashtags][{$format}]' id='wdgpo-map-{$format}-to-hashtags' value='{$hashtags}' />";
             echo '</li>';
         }
         echo "</ul>";
         echo '<div><small>' . __('Separate multiple hashtags with commas, i.e. <code>#hashtag1,#hashtag2</code>', 'wdgpo') . '</small></div>';
         echo '<div><small>' . __('Any hashtag to post format mapping you set up here will take precedence over your assigned default post format.', 'wdgpo') . '</small></div>';
     }
     // Hashtags
     echo "<h4>" . __('Hashtags filter', 'wgdpo') . "</h4>";
     echo '<label for="wdgpo-gplus_import_hashtags">' . __('Import only posts with these hashtags:', 'wdgpo') . '</label><br />' . "<input type='text' class='widefat' name='wdgpo[gplus_import_hashtags]' id='wdgpo-gplus_import_hashtags' value='{$import_hashtags}' />" . '<div><small>' . __('Separate multiple hashtags with commas, i.e. <code>#hashtag1,#hashtag2</code>', 'wdgpo') . '</small></div>' . '<div><small>' . __('Leave this field empty to import all posts.', 'wdgpo') . '</small></div>' . "";
 }