Ejemplo n.º 1
0
 /**
  * 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);
 }
Ejemplo n.º 2
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;
 }