コード例 #1
0
 protected static function get_tweet_content()
 {
     ob_start();
     require dirname(__FILE__) . '/share-handler.php';
     ob_end_clean();
     $p = $_POST;
     $defaults = array('text' => '', 'custom_url' => '', 'custom_twitter_handles' => '', 'custom_hidden_hashtags' => '', 'custom_hidden_urls' => '', 'remove_twitter_handles' => '', 'remove_url' => '', 'remove_hidden_hashtags' => '', 'remove_hidden_urls' => '');
     //	Merge passed values with defaults
     $p = array_merge($defaults, $p);
     //	Convert empty values to boolean false to play along nicely with TT_Share_Handler
     $p = TT_Tools::empty_to_false($p);
     $SH = new TT_Share_Handler($p['text'], $p['custom_url'], $p['custom_twitter_handles'], $p['custom_hidden_hashtags'], $p['custom_hidden_urls'], $p['remove_twitter_handles'], $p['remove_url'], $p['remove_hidden_hashtags'], $p['remove_hidden_urls'], $p['post_id']);
     $data = $SH->generate_actual_text();
     //	Generate JSON response
     $json = json_encode(array('status' => true, 'data' => $data));
     echo $json;
 }
コード例 #2
0
 public static function define_settings()
 {
     register_setting('tweet_this_options', 'tt_plugin_options', array('TT_Settings', 'validation_helper'));
     //	Global settings applicable to all display modes
     add_settings_section('tweet_this_global', 'Global Settings', array('TT_Settings', 'section_content_helper_global'), TT_FILENAME);
     //	Settings applicable only to box display mode.
     add_settings_section('tweet_this_box', 'Box Display Mode Settings', array('TT_Settings', 'section_content_helper_box'), TT_FILENAME);
     //	Settings applicable only to button link display mode.
     add_settings_section('tweet_this_button_link', 'Button Link Display Mode Settings', array('TT_Settings', 'section_content_helper_button_link'), TT_FILENAME);
     //	Settings applicable only to the shortcode creator dialog box.
     add_settings_section('tweet_this_scc_dialog', 'Shortcode Creator Dialog Settings', array('TT_Settings', 'section_content_helper_scc_dialog'), TT_FILENAME);
     //	Advanced settings / Miscellaneous section
     add_settings_section('tweet_this_advanced', 'Advanced Settings', array('TT_Settings', 'section_content_helper_advanced'), TT_FILENAME);
     //////////////////////////////
     /// Global Settings Fields ///
     //////////////////////////////
     //	Default Twitter Handles
     add_settings_field('tt_default_twitter_handles', 'Default Twitter Handles', array('TT_Settings', 'field_helper_textbox'), TT_FILENAME, 'tweet_this_global', array('name' => 'default_twitter_handles', 'help_text' => 'Comma separated list of "via" Twitter handles you want added to your tweets (leave blank for none). <br />Example: <span class="tt_admin_example">@jt_morris, @DTELinux, @CraigyFerg</span>'));
     //	Default Hidden Hash Tags
     add_settings_field('tt_default_hidden_hashtags', 'Default Hidden Hashtags', array('TT_Settings', 'field_helper_textbox'), TT_FILENAME, 'tweet_this_global', array('name' => 'default_hidden_hashtags', 'help_text' => 'Any hashtags you want added to your message when tweeted, but not displayed in your Tweet This boxes (leave blank for none). <br />Example: <span class="tt_admin_example">#hashtags #rule</span>'));
     //	Default Hidden URLs
     add_settings_field('tt_default_hidden_urls', 'Default Hidden URLs', array('TT_Settings', 'field_helper_textbox'), TT_FILENAME, 'tweet_this_global', array('name' => 'default_hidden_urls', 'help_text' => 'Any URLs you want added to your message when tweeted, but not displayed in your Tweet This boxes (leave blank for none). <br />Example: <span class="tt_admin_example">http://cs.johnmorris.me http://eng.johnmorris.me</span>'));
     //	Twitter Icon
     add_settings_field('tt_twitter_icon', 'Twitter Icon', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_global', array('name' => 'twitter_icon', 'buttons' => TT_Tools::get_twitter_images_as_radio_array(), 'help_text' => 'Choose an icon to display next to the Tweet This link.', 'default' => 'bird1'));
     //	Use Shortlink
     add_settings_field('tt_use_shortlink', 'Use Shortlink?', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_global', array('name' => 'use_shortlink', 'buttons' => array(array('Yes', true), array('No', false)), 'help_text' => 'Your Shortlink Format: <span class="tt_admin_example">' . wp_get_shortlink(TT_Tools::get_id_of_last_post()) . '</span><br /><a href="http://tweetthis.jtmorris.net/posts/beginners-guide-to-wordpress-shortlinks/" target="_blank">Read this article</a> for tips on customizing your shortlinks.'));
     //	Disable URLs in Tweet
     add_settings_field('tt_disable_url', 'Disable URLs', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_global', array('name' => 'disable_url', 'buttons' => array(array('Yes', true), array('No', false)), 'help_text' => 'Choose yes to remove automatically generated URLS from your tweets by default (overridden URLs will still show up).', 'default' => false));
     //	Hide Byline
     add_settings_field('tt_hide_promotional_byline', 'Hide Promotional Byline?', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_global', array('name' => 'hide_promotional_byline', 'id' => 'tt_byline_removal', 'buttons' => array(array('Yes', true), array('No', false)), 'default' => false, 'help_text' => 'Choose "Yes" to remove the "Powered by Tweet This" byline.'));
     //	Display mode
     $box_text = 'Box' . ' (<em><a style="cursor: pointer; text-decoration: underline;" onclick="window.open(\'' . TT_ROOT_URL . 'assets/images/box.jpg\', \'popup\', \'width=491,height=492,scrollbars=no,toolbar=no,menubar=no\')">Click to See Sample</a></em>)';
     $blink_text = 'Button Link' . ' (<em><a style="cursor: pointer;  text-decoration: underline;" onclick="window.open(\'' . TT_ROOT_URL . 'assets/images/button_link.jpg\', \'popup\', \'width=530,height=380,scrollbars=no,toolbar=no,menubar=no\')">Click to See Sample</a></em>)';
     add_settings_field('tt_display_mode', 'Default Display Mode', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_global', array('name' => 'display_mode', 'buttons' => array(array($box_text, 'box'), array($blink_text, 'button_link')), 'help_text' => 'Choose the method for displaying your tweetable content.  Default mode is "Box."', 'default' => 'box'));
     /////////////////////////
     /// Box Mode Settings ///
     /////////////////////////
     //	Theme
     add_settings_field('tt_theme', 'Choose Theme', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_box', array('name' => 'base_theme', 'buttons' => TT_Tools::get_themes_as_radio_array(), 'help_text' => 'Choose the base theme for "Tweet This" boxes. NOTE: The images are not representative of actual size!', 'default' => 'light'));
     /////////////////////////////
     /// Button Link Settings ///
     ////////////////////////////
     //	Include Twitter icon?
     add_settings_field('tt_simple_link_include_icon', 'Include Twitter Icon in Link?', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_button_link', array('name' => 'simple_link_include_icon', 'buttons' => array(array('Yes', true), array('No', false)), 'help_text' => 'Choose yes to include the Twitter icon alongside your link.', 'default' => true));
     /////////////////////////////////////////
     /// Shortcode Creator Dialog Settings ///
     /////////////////////////////////////////
     //	Insert Shortcode Behavior
     add_settings_field('tt_insert_shortcode_behavior', '"Insert Shortcode" Button Behavior', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_scc_dialog', array('name' => 'insert_shortcode_behavior', 'buttons' => array(array('Automatically insert it into WordPress editor', 'auto'), array('Display shortcode for copy and paste', 'manual')), 'help_text' => 'Certain WordPress configurations and plugins interfere with automatic shortcode insertion into your editor. If you receive an error message when clicking "Insert Shortcode" button in Shortcode Creator Dialog, or nothing happens, you will need to switch to copy and paste mode.', 'default' => 'auto'));
     //	Disable Preview?
     add_settings_field('tt_disable_preview', 'Disable Preview?', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_scc_dialog', array('name' => 'disable_preview', 'buttons' => array(array('Yes', true), array('No', false)), 'help_text' => 'Disable the preview of your tweet in the shortcode creator?', 'default' => false));
     //	Disable Character Counter
     add_settings_field('tt_disable_char_count', 'Disable Character Counter?', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_scc_dialog', array('name' => 'disable_char_count', 'buttons' => array(array('Yes', true), array('No', false)), 'help_text' => 'Disable the "characters left" counter?', 'default' => false));
     //	Disable Post URL Options
     add_settings_field('tt_disable_post_url', 'Disable Post URL Options?', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_scc_dialog', array('name' => 'disable_post_url', 'buttons' => array(array('Yes', true), array('No', false)), 'help_text' => 'Disable the post URL options in the shortcode creator?', 'default' => false));
     //	Disable Twitter Handles Options
     add_settings_field('tt_disable_handles', 'Disable Twitter Handle Options?', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_scc_dialog', array('name' => 'disable_handles', 'buttons' => array(array('Yes', true), array('No', false)), 'help_text' => 'Disable the Twitter handle/user options in the shortcode creator?', 'default' => false));
     //	Disable Post URL Options
     add_settings_field('tt_disable_post_url', 'Disable Post URL Options?', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_scc_dialog', array('name' => 'disable_post_url', 'buttons' => array(array('Yes', true), array('No', false)), 'help_text' => 'Disable the post URL options in the shortcode creator?', 'default' => false));
     //	Disable Hidden Content Options
     add_settings_field('tt_disable_hidden', 'Disable Hidden Content Options?', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_scc_dialog', array('name' => 'disable_hidden', 'buttons' => array(array('Yes', true), array('No', false)), 'help_text' => 'Disable the options for hidden content in the shortcode creator?', 'default' => false));
     ///////////////////////
     /// Advanced / Misc ///
     ///////////////////////
     //	Button Text
     add_settings_field('tt_button_text_override', 'Override Button Text', array('TT_Settings', 'field_helper_textbox'), TT_FILENAME, 'tweet_this_advanced', array('name' => 'button_text_override', 'help_text' => 'Override the "Tweet This" text in the call-to-action button/link. Leave blank to use default.'));
     //	Icon Alt Tag
     add_settings_field('tt_icon_alt_text', 'Icon Alt Tag Value', array('TT_Settings', 'field_helper_textbox'), TT_FILENAME, 'tweet_this_advanced', array('name' => 'icon_alt_text', 'help_text' => 'The value of the alt attribute of the Twitter icon &lt;img&gt; tag. Default is none.'));
     //	Alternative Button Placement
     add_settings_field('tt_button_location', 'Editor Button Location', array('TT_Settings', 'field_helper_radio'), TT_FILENAME, 'tweet_this_advanced', array('name' => 'button_location', 'buttons' => array(array('Editor Toolbar, Row #1', 'row1'), array('Editor Toolbar, Row #2', 'row2'), array('Next to Add Media Button', 'media')), 'help_text' => 'By default, this plugin places the shortcode creator dialog button on the top row of the WordPress editor toolbar. Move the button to a different location here.', 'default' => 'row1'));
     //	Template
     add_settings_field('tt_template', 'Tweet Element Template', array('TT_Settings', 'field_helper_textarea'), TT_FILENAME, 'tweet_this_advanced', array('name' => 'template', 'help_text' => 'Customize the order of elements, and their separators, in resulting tweets. Template tags (in the following format "{{ separator {tag_name}}}") are replaced with the corresponding content. Leave blank to use default. Default: "{{{text}}}{{ {hidden_hashtags}}}{{ {hidden_urls}}}{{ {post_url}}}{{ via {twitter_handles}}}"<br /><a href="http://tweetthis.jtmorris.net/posts/introducing-the-tweet-element-template/" target="_blank">Read this article</a> for more detail and examples.', 'style' => 'min-width: 600px;'));
     //	Custom CSS
     add_settings_field('tt_css_override', 'Override CSS', array('TT_Settings', 'field_helper_textarea'), TT_FILENAME, 'tweet_this_advanced', array('name' => 'css_override', 'help_text' => 'Override default CSS rules for "Tweet This".', 'style' => 'min-width: 600px; min-height: 300px;'));
 }
コード例 #3
0
ファイル: setup.php プロジェクト: AgilData/WordPress-Skeleton
        public static function hooks_helper_admin_header()
        {
            //	Output the information for the dialog box and setup the dialog box.
            //	We need to be in the admin, editing a post or page for the plugin to be
            //	initialized, so we don't want to add the jQuery dialog unless the same
            //	conditions apply.  So are we?
            global $current_screen;
            $type = $current_screen->post_type;
            if (is_admin() && ($type == 'post' || $type == 'page')) {
                ?>
					<script type='text/javascript'>
						<?php 
                // Get the URL to the AJAX handler file and save it
                ?>
						var ajaxurl = "<?php 
                echo admin_url('admin-ajax.php');
                ?>
";
						
						jQuery(document).ready(function() {
							<?php 
                // Output the dialog boxes data as a JavaScript variable
                //	Strategy Cribbed From Here: http://stackoverflow.com/a/4935684/2523144
                //
                //	Encode the PHP variable as JSON.  Use native JavaScript to parse the JSON
                //	if the necessary fuction is available.  If not, use the slower jQuery
                //	version.
                $json = json_encode(TT_Tools::get_tinymce_dialog_settings());
                ?>
							window.TT_Data = <?php 
                echo $json;
                ?>
;


							<?php 
                // Turn the dialog box code included above into a jQuery dialog
                ?>
						
							var scDialog = jQuery('#TT-shortcode-creator-dialog').dialog({
								autoOpen: false,
								modal: true,
								maxHeight: 950,
								resizable: false,
								width: 650,
								open: function() {
									//	Fix Random jQuery UI CSS Scoping Issues	//
									jQuery('div.ui-widget-overlay, div.ui-dialog').wrap('<div class="tt-jqui" />');
								}
							});
							scDialog.parent('.ui-dialog').addClass( 'tt-jqui' );	//	jQuery UI Theme Scope

							jQuery('#tt-dialog-launcher').click(function(event) {
								event.preventDefault();
								jQuery('#TT-shortcode-creator-dialog').dialog("open");
							});
						});						
					</script>
					<?php 
            }
        }
コード例 #4
0
ファイル: tools.php プロジェクト: AgilData/WordPress-Skeleton
 /**
  * Returns all the plugin settings needed for the dialog box as an associative array.
  *
  * @return   [array]   Array of plugin settings for dialog box.
  */
 public static function get_tinymce_dialog_settings()
 {
     //	Because this function is not necessarily called on the post/page editor screen,
     //	the post/page URL getting function TT_Share_Handler::generate_post_url()
     //	won't always work.  So, if and when it fails, we'll need a placeholder link that
     //	we can get without failure.
     try {
         //	post ID
         global $current_screen, $post;
         $type = $current_screen->post_type;
         if ($type == 'post' || $type == 'page') {
             $id = $post->ID;
         } else {
             throw new Exception('Unable to retrieve post ID.');
         }
         //	post URL
         $SH = new TT_Share_Handler();
         $urlarr = $SH->generate_post_url($id, true);
         if (is_array($urlarr)) {
             //	Shortlink w/ qualifying info in array
             $post_url = self::get_arr_value('shortlink', $urlarr, '');
             $is_placeholder = self::get_arr_value('is_placeholder', $urlarr, false);
         } else {
             //	Nothing fancy, just the URL as a string
             $post_url = $urlarr;
             $is_placeholder = false;
         }
     } catch (Exception $e) {
         $id = 0;
         $post_url = TT_Tools::placeholder_shortlink();
         $is_placeholder = false;
     }
     //	default Twitter handles and hidden hashtags
     $options = get_option('tt_plugin_options');
     $twits = self::get_arr_value('default_twitter_handles', $options, '');
     $hashtags = self::get_arr_value('default_hidden_hashtags', $options, '');
     $hidden_urls = self::get_arr_value('default_hidden_urls', $options, '');
     //	dialog customization options
     $insert_sc_behavior = self::get_arr_value('insert_shortcode_behavior', $options, '');
     $hide_preview = self::get_arr_value('disable_preview', $options, '');
     $hide_handles = self::get_arr_value('disable_handles', $options, '');
     $hide_post_url = self::get_arr_value('disable_post_url', $options, '');
     $hide_hidden = self::get_arr_value('disable_hidden', $options, '');
     $hide_char_count = self::get_arr_value('disable_char_count', $options, '');
     return array('post_id' => $id, 'post_url' => $post_url, 'post_url_is_placeholder' => $is_placeholder, 'default_twitter_handles' => $twits, 'default_hidden_hashtags' => $hashtags, 'default_hidden_urls' => $hidden_urls, 'disable_preview' => $hide_preview, 'disable_handles' => $hide_handles, 'disable_post_url' => $hide_post_url, 'disable_hidden' => $hide_hidden, 'disable_char_count' => $hide_char_count, 'insert_shortcode_behavior' => $insert_sc_behavior);
 }
コード例 #5
0
 public function generate_post_url($id = 0, $placeholder_flag = false)
 {
     //	$id = 0 means current post to get_permalink function
     $options = get_option('tt_plugin_options');
     //	Do we need to generate the URL? If URL is disabled, we don't.
     //	If one is already provided, we don't.
     if ($options['disable_url'] && is_null($this->my_url)) {
         if ($placeholder_flag) {
             $this->my_url = "";
             return array('shortlink' => '', 'is_placeholder' => false);
         } else {
             return "";
         }
     }
     if (is_null($this->my_url)) {
         //	Yes, we need to generate a URL
         //	Okay then, do we need to construct a shortlink
         if ($options['use_shortlink']) {
             //	Yes, we need a shortlink.
             //	Try getting one the default way
             $short = wp_get_shortlink($id);
             if (empty($short)) {
                 //	No shortlink for whatever reason
                 //	Try using custom functions provided by popular shortlink pluings
                 //	Shortn.it: https://wordpress.org/plugins/shortnit/
                 if (function_exists('the_full_shortn_url')) {
                     $short = get_the_full_shortn_url();
                 } else {
                     $short = get_permalink($id);
                 }
             }
             //	Okay. Now, if the post is not yet published, the shortlink
             //	will be the default WordPress shortlink (the domain and
             //	post id: http://domain.com/?p=123). Most shortlink
             //	customization plugins, like JetPack's WP.me module and
             //	WP Bitly don't generate shortlinks until after the post
             //	is published.
             //
             //	This means that the shortlink we just worked our butts
             //	off to get... might not be correct.  The shortlink
             //	might not have been constructed yet, and WordPress just
             //	doesn't know that.
             //
             //	If this is the case, then we want to return a placeholder
             //	URL that has similar/same length.
             //
             //	Fortunately, there's a function for that which determines
             //	whether the shortlink is accurate or not... sort of.
             if (TT_Tools::is_shortlink_accurate($short)) {
                 //	YAY! It's accurate... probably.  So, use $short
                 $this->my_url = $short;
                 $this->my_url_is_placeholder = false;
             } else {
                 //	Damn... now we need a placeholder...
                 //	Fortunately, there's a function for that...
                 $this->my_url = TT_Tools::placeholder_shortlink();
                 $this->my_url_is_placeholder = true;
             }
         } else {
             //	No, no shortlink, just use normal URL
             $this->my_url = get_permalink($id);
             $this->my_url_is_placeholder = false;
         }
     }
     if ($placeholder_flag) {
         return array('shortlink' => $this->my_url, 'is_placeholder' => $this->my_url_is_placeholder);
     }
     return $this->my_url;
 }