Changeset 1325871
- Timestamp:
- 01/11/2016 03:20:07 PM (10 years ago)
- Location:
- click-tweet/trunk
- Files:
-
- 1 added
- 5 edited
-
assets/css/click-and-tweet-editor.css (modified) (3 diffs)
-
assets/css/click-and-tweet.css (modified) (1 diff)
-
assets/js/click-and-tweet-tinymce-plugin.js (modified) (12 diffs)
-
click-and-tweet.php (modified) (17 diffs)
-
languages (added)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
click-tweet/trunk/assets/css/click-and-tweet-editor.css
r1312087 r1325871 19 19 display: block; 20 20 position: absolute; 21 padding: 25px 15px ;21 padding: 25px 15px 40px; 22 22 min-width: 200px; 23 23 min-height: 80px; … … 105 105 z-index: 1000; 106 106 } 107 108 .click-and-tweet-tooltip label{ 107 .click-and-tweet-tooltip label:not(.blue){ 108 display: block; 109 padding: 3px; 110 font-size: 0.8em; 111 } 112 .click-and-tweet-tooltip label.blue{ 109 113 background: #55acee; 110 114 display: inline-block; … … 163 167 color: #55acee; 164 168 } 169 170 .click-and-tweet-tooltip .panel .more-link{ 171 font-size: 1.6em; 172 text-align: right; 173 color: #FFF; 174 text-decoration: none; 175 position: absolute; 176 bottom: 0px; 177 right: 10px; 178 } 179 180 .click-and-tweet-tooltip .panel .back-link{ 181 font-size: 1.6em; 182 text-align: right; 183 color: #FFF; 184 text-decoration: none; 185 position: absolute; 186 bottom: 0px; 187 left: 10px; 188 } 189 190 .click-and-tweet-tooltip .panel .back-link small{ 191 font-size: 0.5em; 192 vertical-align: middle; 193 padding-left: 5px; 194 } 195 196 .click-and-tweet-tooltip select{ 197 width: 100%; 198 font-size: 2em; 199 } -
click-tweet/trunk/assets/css/click-and-tweet.css
r1312087 r1325871 24 24 padding-top: 100%; 25 25 } 26 27 .click-and-tweet-card{ 28 display: block; 29 width:100%; 30 max-width: 640px; 31 padding:1.625rem; 32 margin: 2.6rem auto; 33 background-color: #FFFFFF; 34 border: solid 1px #EEE; 35 -webkit-border-radius: 0.4rem; 36 border-radius: 0.4rem; 37 -webkit-box-shadow: 0 0 3px 0 rgba(0,0,0,0.025); 38 box-shadow: 0 0 3px 0 rgba(0,0,0,0.025); 39 position: relative; 40 } 41 42 .click-and-tweet-card .click-and-tweet-twitter-logo{ 43 background-image: url('../img/twitter-logo.png'); 44 background-position: center; 45 background-size: contain; 46 background-repeat: no-repeat; 47 display: block; 48 height: 2.8em; 49 width: 2.8em; 50 position: relative; 51 } 52 53 .click-and-tweet-card .click-and-tweet-twitter-logo:before{ 54 content: ""; 55 display: block; 56 padding-top: 100%; 57 } 58 59 .click-and-tweet-card .click-and-tweet-twitter-logo a{ 60 display: block; 61 width:100%; 62 height: 100%; 63 position: absolute; 64 top: 0; 65 left: 0; 66 text-indent: -9999px; 67 } 68 69 .click-and-tweet-card .click-and-tweet-card-link{ 70 display:block; 71 text-align: left; 72 } 73 74 .click-and-tweet-card.left-center .click-and-tweet-twitter-logo{ 75 position: absolute; 76 top: 50%; 77 left: 1.625rem; 78 -webkit-transform: translateY(-50%); 79 transform: translateY(-50%); 80 } 81 82 .click-and-tweet-card.left-center .click-and-tweet-card-link{ 83 padding-left: 4.625em; 84 85 } 86 87 .click-and-tweet-card.left-top .click-and-tweet-twitter-logo{ 88 position: absolute; 89 top: 12.5%; 90 left: 1rem; 91 } 92 93 .click-and-tweet-card.left-top .click-and-tweet-card-link{ 94 padding-left: 3em; 95 } 96 97 .click-and-tweet-card.left-bottom .click-and-tweet-twitter-logo{ 98 position: absolute; 99 bottom: 12.5%; 100 left: 1rem; 101 } 102 103 .click-and-tweet-card.left-bottom .click-and-tweet-card-link{ 104 padding-left: 3em; 105 } 106 107 .click-and-tweet-card.right-center .click-and-tweet-twitter-logo{ 108 position: absolute; 109 top: 50%; 110 right: 1.625rem; 111 -webkit-transform: translateY(-50%); 112 transform: translateY(-50%); 113 } 114 115 .click-and-tweet-card.right-center .click-and-tweet-card-link{ 116 padding-right: 4.625em; 117 } 118 119 .click-and-tweet-card.right-top .click-and-tweet-twitter-logo{ 120 position: absolute; 121 top: 12.5%; 122 right: 1rem; 123 } 124 125 .click-and-tweet-card.right-top .click-and-tweet-card-link{ 126 padding-right: 3em; 127 } 128 129 .click-and-tweet-card.right-bottom .click-and-tweet-twitter-logo{ 130 position: absolute; 131 bottom: 12.5%; 132 right: 1rem; 133 } 134 135 .click-and-tweet-card.right-bottom .click-and-tweet-card-link{ 136 padding-right: 3em; 137 } 138 139 .click-and-tweet-card.center-top { 140 padding-top: 3.5em; 141 } 142 .click-and-tweet-card.center-top .click-and-tweet-twitter-logo{ 143 position: absolute; 144 top: 4%; 145 left: 50%; 146 -webkit-transform: translateX(-50%); 147 transform: translateX(-50%); 148 } 149 150 .click-and-tweet-card.center-bottom { 151 padding-bottom: 3.5em; 152 } 153 154 .click-and-tweet-card.center-bottom .click-and-tweet-twitter-logo{ 155 position: absolute; 156 bottom: 4%; 157 left: 50%; 158 -webkit-transform: translateX(-50%); 159 transform: translateX(-50%); 160 } 161 162 .click-and-tweet-card.center-top .click-and-tweet-card-link, 163 .click-and-tweet-card.center-bottom .click-and-tweet-card-link{ 164 text-align: center; 165 } -
click-tweet/trunk/assets/js/click-and-tweet-tinymce-plugin.js
r1312087 r1325871 1 1 (function($) { 2 2 tinymce.PluginManager.add('click_and_tweet', function(ed, url) { 3 var activeShortcode, editorEditable = true; 3 var activeShortcode, editorEditable = true, shortcodeAdded = false, activeSpan; 4 5 var defaults = { 6 handle : click_and_tweet.defaultUsername || null, 7 layout : click_and_tweet.defaultLayout || null, 8 inlinePosition : click_and_tweet.defaultInlinePosition || null, 9 cardPosition : click_and_tweet.defaultCardPosition || null 10 }; 11 12 var inlineTweetPositions = { 13 '' : 'Default', 14 'left' : 'Left', 15 'right' : 'Right' 16 }; 17 18 var cardTweetPositions = { 19 '' : 'Default', 20 'center-top': 'Center Top', 21 'center-bottom': 'Center Bottom', 22 'left-center': 'Left Center', 23 'left-top': 'Left Top', 24 'left-bottom': 'Left Bottom', 25 'right-center': 'Right Center', 26 'right-top': 'Right Top', 27 'right-bottom': 'Right Bottom' 28 }; 4 29 5 30 /** … … 26 51 content : text 27 52 }); 53 shortcodeAdded = true; 28 54 } 29 55 } … … 40 66 ed.on('click', function(e) { 41 67 toggleTooltip(e); 42 68 togglePanel(e); 43 69 closeToolTip(e); 70 updatePositionSelectOnChange(e); 44 71 45 72 if ($(e.target).is('input[type="text"]')) { … … 71 98 'data-handle' : shortcode.attrs.named.handle || '', 72 99 'data-hashtag' : shortcode.attrs.named.hashtag || '', 100 'data-related' : shortcode.attrs.named.related || '', 101 'data-layout' : shortcode.attrs.named.layout || '', 102 'data-position' : shortcode.attrs.named.position || '', 73 103 } 74 104 }) + spacer; 75 105 }); 106 activeSpan = result; 76 107 event.content = result; 108 }); 109 110 ed.on('SetContent', function(event) { 111 if(shortcodeAdded){ 112 //Trigger open here 113 shortcodeAdded = false; 114 } 77 115 }); 78 116 … … 94 132 handle : $(e).data('handle') || '', 95 133 hashtag : $(e).data('hashtag') || '', 134 related : $(e).data('related') || '', 135 layout : $(e).data('layout') || '', 136 position : $(e).data('position') || '' 96 137 } 97 138 }); … … 113 154 var tooltip = '<div class="click-and-tweet-tooltip mceNonEditable" contenteditable="false">' + 114 155 '<span class="close">×</span>' + 115 '<div>' + 116 '<label>@</label>' + 117 '<input type="text" name="handle" class="click-and-tweet-hash mceEditable" contenteditable="true" placeholder="@username">' + 156 '<div class="panel default">' + 157 '<div>' + 158 '<label class="blue">@</label>' + 159 '<input type="text" name="handle" class="click-and-tweet-username mceEditable" contenteditable="true" placeholder="@username">' + 160 '</div>' + 161 '<div>' + 162 '<label class="blue">#</label>' + 163 '<input type="text" name="hashtag" class="click-and-tweet-hash mceEditable" contenteditable="true" placeholder="#hashtag">' + 164 '</div>' + 165 '<div>' + 166 '<label class="blue">@</label>' + 167 '<input type="text" name="related" class="click-and-tweet-related mceEditable" contenteditable="true" placeholder="@relatedUsername">' + 168 '</div>' + 169 '<a class="toggle-panel more-link" data-panel="more" title="More">···</a>' + 118 170 '</div>' + 119 '<div>' + 120 '<label>#</label>' + 121 '<input type="text" name="hashtag" class="click-and-tweet-hash mceEditable" contenteditable="true" placeholder="#hashtag">' + 171 '<div class="panel more" style="display: none;">' + 172 '<div>' + 173 '<label>Layout</label>' + 174 '<select class="click-to-tweet-layout" name="layout">' + 175 '<option value="inline">Inline</option>' + 176 '<option value="card">Card</option>' + 177 '</select>' + 178 '</div>' + 179 '<div>' + 180 '<label>Position</label>' + 181 '<select class="click-to-tweet-layout-position" name="position"></select>' + 182 '</div>' + 183 '<a class="toggle-panel back-link" data-panel="default" title="Back">‹<small>Back</small></a>' + 122 184 '</div>' + 123 185 '</div>'; … … 159 221 activeShortcode = ''; 160 222 toggleEditable(); 223 } 224 } 225 226 /** 227 * Close the tooltip 228 */ 229 function togglePanel(e) 230 { 231 if ($($(e.target)[0]).hasClass('toggle-panel') || $($(e.target)[0]).parent().hasClass('toggle-panel')) { 232 var target = ($($(e.target)[0]).parent().hasClass('toggle-panel')) ? $($(e.target)[0]).parent() : $($(e.target)[0]); 233 var panel = target.data('panel'); 234 target.closest('.click-and-tweet-tooltip').find('.panel').hide(); 235 target.closest('.click-and-tweet-tooltip').find('.panel.' + panel).show(); 236 return false; 161 237 } 162 238 } … … 198 274 //Determine the y position of the tooltip 199 275 switch (true) { 200 case targetYOffset >= maxYOffset :276 case targetYOffset >= maxYOffset && maxYOffset > 0 : 201 277 yClassName = 'top'; 202 278 break; … … 264 340 setTimeout(function () { 265 341 var shortcode = element; 266 var inputs = $('.click-and-tweet-tooltip', ed.getBody()).find('input[type="text"] ');342 var inputs = $('.click-and-tweet-tooltip', ed.getBody()).find('input[type="text"], select'); 267 343 268 344 inputs.each(function(i,e){ … … 270 346 }); 271 347 272 inputs.on('keyup ', function(){348 inputs.on('keyup change', function(){ 273 349 shortcode.attr('data-' + $(this).attr('name'), $(this).val()); 274 350 }); … … 283 359 function setInputFields(e, parent) 284 360 { 285 var defaults = { 286 handle : click_and_tweet.defaultUsername || null 287 }; 288 289 var value = parent[0].dataset[$(e).attr('name')] || ''; 290 291 $(e).val(value); 361 if( typeof parent[0].dataset[$(e).attr('name')] !== 'undefined'){ 362 var value = parent[0].dataset[$(e).attr('name')] || ''; 363 if(value) $(e).val(value); 364 } 365 366 if($(e).attr('name') == 'layout'){ 367 updatePositionSelect(e); 368 } 292 369 293 370 if($(e).attr('name') == 'handle' && defaults.handle) $(e).attr('placeholder', defaults.handle); … … 326 403 } 327 404 } 405 406 /** 407 * Update the position select options 408 */ 409 function updatePositionSelect(e) 410 { 411 e = e.currentTarget || e; 412 var options = ($(e).val() == 'card') ? cardTweetPositions : inlineTweetPositions; 413 var layout = $('.click-to-tweet-layout', ed.getBody()); 414 var layoutPosition = $('.click-to-tweet-layout-position', ed.getBody()); 415 416 layoutPosition.empty(); 417 $.each(options, function(value,key) { 418 layoutPosition.append($("<option></option>").attr("value", value).text(key)); 419 }); 420 } 421 422 /** 423 * Update the position select options when the layout select changes 424 */ 425 function updatePositionSelectOnChange(e) 426 { 427 if(e.target.className == 'click-to-tweet-layout'){ 428 $('.click-to-tweet-layout', ed.getBody()).on('change', function(e){ 429 updatePositionSelect(e); 430 }); 431 } 432 } 328 433 }); 329 434 -
click-tweet/trunk/click-and-tweet.php
r1312087 r1325871 4 4 * Plugin URI: http://spacestud.io 5 5 * Description: Quote text in your WordPress posts for easy sharing on twitter. 6 * Version: 0. 1.06 * Version: 0.2.0 7 7 * Author: Space Studio 8 8 * Author URI: http://spacestud.io … … 27 27 28 28 /** 29 * Activation Hook 30 */ 31 register_activation_hook(__FILE__, array('ClickAndTweet', 'activation')); 32 33 /** 34 * Deactivation Hook 35 */ 36 register_deactivation_hook(__FILE__, array('ClickAndTweet', 'deactivation')); 37 38 /** 39 * Uninstall Hook 40 */ 41 register_uninstall_hook(__FILE__, array('ClickAndTweet', 'uninstall')); 42 43 /** 29 44 * Click & Tweet 30 45 */ … … 43 58 * @var string 44 59 */ 45 protected $optionName = 'click_and_tweet_settings'; 60 static $pluginOptionName = 'click_and_tweet_settings'; 61 62 /** 63 * Plugin option name. 64 * 65 * @var string 66 */ 67 public $optionName = 'click_and_tweet_settings'; 68 69 /** 70 * Inline Layout Positions 71 * 72 * @var array 73 */ 74 protected $inlinePositions = ['left' => 'Left', 'right' => 'Right']; 75 76 /** 77 * Card Layout Positions 78 * 79 * @var array 80 */ 81 protected $cardPositions = [ 82 'center-top' => 'Center Top', 83 'center-bottom' => 'Center Bottom', 84 'left-center' => 'Left Center', 85 'left-top' => 'Left Top', 86 'left-bottom' => 'Left Bottom', 87 'right-center' => 'Right Center', 88 'right-top' => 'Right Top', 89 'right-bottom' => 'Right Bottom' 90 ]; 46 91 47 92 /** … … 50 95 public function __construct() 51 96 { 97 $this->optionName = self::$pluginOptionName; 98 52 99 $this->settings = get_option($this->optionName); 53 100 … … 64 111 public function adminInit() 65 112 { 66 register_activation_hook(__FILE__, array($this, 'activation'));67 register_deactivation_hook(__FILE__, array($this, 'deactivation'));68 113 add_action('admin_init', array($this, 'registerSettings')); 69 114 add_action('admin_init', array($this, 'editorStyle')); … … 87 132 public function enqueueAdminScripts($hook) 88 133 { 89 //var_dump($hook); die; 134 90 135 $adminPages = array('settings_page_click-and-tweet', 'post.php'); 91 136 if (!in_array($hook, $adminPages)) { … … 110 155 ); 111 156 157 //sets the values for username, inline positions, and card positions as long as they are selected, to change the default. 112 158 if(!empty($this->settings['use_default_username']) && isset($this->settings['default_username'])) { 113 159 $data['defaultUsername'] = $this->settings['default_username']; 160 } 161 162 if(!empty($this->settings['inline_tweet_position'])) { 163 $data['defaultInlinePosition'] = $this->settings['inline_tweet_position']; 164 } 165 166 if(!empty($this->settings['card_tweet_position'])) { 167 $data['defaultCardPosition'] = $this->settings['card_tweet_position']; 114 168 } 115 169 … … 153 207 154 208 /** 155 * Plugin Activation. 156 */ 157 public function activation() 209 * Plugin Activation. Sets the default settings. 210 */ 211 public static function activation() 212 { 213 $option = get_option(self::$pluginOptionName); 214 215 if(!isset($option['inline_tweet_position'])) { 216 $option['inline_tweet_position'] = 'right'; 217 update_option(self::$pluginOptionName, $option); 218 } 219 220 if(!isset($option['card_tweet_position'])) { 221 $option['card_tweet_position'] = 'left-center'; 222 update_option(self::$pluginOptionName, $option); 223 } 224 } 225 226 /** 227 * Plugin Deactivation. 228 */ 229 public static function deactivation() 158 230 { 159 231 // … … 161 233 162 234 /** 163 * Plugin Deactivation.164 */165 public function deactivation()166 {167 //168 }169 170 /**171 235 * Function to uninstall the plugin 172 236 */ 173 public function uninstall() 174 { 175 // If uninstall is not called from WordPress, exit 176 if (!defined('WP_UNINSTALL_PLUGIN')) { 177 exit(); 178 } 179 237 public static function uninstall() 238 { 180 239 delete_option($this->optionName); 181 240 … … 207 266 <h2>Click & Tweet Settings</h2> 208 267 <p> </p> 268 209 269 <form class="" action="options.php" method="post" enctype="multipart/form-data"> 210 270 <?php … … 256 316 ); 257 317 318 add_settings_field( 319 $id = 'use_twitter_shortlink', 320 $title = 'Url Shortlink', 321 $callback = array($this, 'callbackTwitterShortlinkField'), 322 $page = 'click_and_tweet_settings', 323 $section = 'click_and_tweet_settings' 324 ); 325 326 add_settings_field( 327 $id = 'use_auto_truncate', 328 $title = 'Auto Truncate', 329 $callback = array($this, 'callbackTwitterAutoTruncateField'), 330 $page = 'click_and_tweet_settings', 331 $section = 'click_and_tweet_settings' 332 ); 333 334 add_settings_field( 335 $id = 'inline_tweet_position', 336 $title = 'Default Inline Position', 337 $callback = array($this, 'callbackInlineTweetPositionField'), 338 $page = 'click_and_tweet_settings', 339 $section = 'layout_positioning' 340 ); 341 342 add_settings_field( 343 $id = 'card_tweet_position', 344 $title = 'Default Card Position', 345 $callback = array($this, 'callbackCardPositionField'), 346 $page = 'click_and_tweet_settings', 347 $section = 'layout_positioning' 348 ); 258 349 259 350 add_settings_section( 260 351 $id = 'click_and_tweet_settings', 261 $title = ' ',352 $title = 'General Settings', 262 353 $callback = array($this, 'callbackTwitterHandleSection'), 263 354 $page = 'click_and_tweet_settings' 264 355 ); 356 357 add_settings_section( 358 $id = 'layout_positioning', 359 $title = 'Layout and Positioning', 360 $callback = array($this, 'callbackLayoutSection'), 361 $page = 'click_and_tweet_settings' 362 ); 265 363 } 266 364 … … 273 371 } 274 372 373 public function callbackLayoutSection() 374 { 375 echo ''; 376 } 275 377 276 378 /** … … 296 398 } 297 399 400 /* 401 * function to turn the twitter shortlink on or off. 402 */ 403 public function callbackTwitterShortlinkField() 404 { 405 $checked_yes = (isset($this->settings['use_twitter_shortlink']) && $this->settings['use_twitter_shortlink'] == 1) ? 'checked' : ''; 406 $checked_no = (!isset($this->settings['use_twitter_shortlink']) || $this->settings['use_twitter_shortlink'] == 0) ? 'checked' : ''; 407 $html = "<input type='radio' name='click_and_tweet_settings[use_twitter_shortlink]' value='1' $checked_yes /> On <input type='radio' name='click_and_tweet_settings[use_twitter_shortlink]' value='0' $checked_no /> Off"; 408 $html .= "<p class='description'>Display Shortlink Url instead of Permalink.</p>"; 409 echo $html; 410 } 411 412 /* 413 * function to call back the Auto Truncate Settings field. 414 */ 415 public function callbackTwitterAutoTruncateField() 416 { 417 $checked_yes = (isset($this->settings['use_auto_truncate']) && $this->settings['use_auto_truncate'] == 1) ? 'checked' : ''; 418 $checked_no = (!isset($this->settings['use_auto_truncate']) || $this->settings['use_auto_truncate'] == 0) ? 'checked' : ''; 419 $html = "<input type='radio' name='click_and_tweet_settings[use_auto_truncate]' value='1' $checked_yes /> On <input type='radio' name='click_and_tweet_settings[use_auto_truncate]' value='0' $checked_no /> Off"; 420 $html .= "<p class='description'>Auto truncate text to avoid exceeding 140 characters on Twitter.</p>"; 421 echo $html; 422 } 423 424 /** 425 * callback function that returns a select menu of inline tweet Positions 426 */ 427 public function callbackInlineTweetPositionField() 428 { 429 $options = ''; 430 $selected = isset($this->settings['inline_tweet_position']) ? $this->settings['inline_tweet_position'] : ''; 431 432 foreach ($this->inlinePositions as $key => $value) { 433 $isSelected = ($key == $selected) ? ' selected' : ''; 434 $options .= "<option value=\"$key\"$isSelected>$value</option>"; 435 } 436 437 $selectMenu = "<select name=\"click_and_tweet_settings[inline_tweet_position]\">$options</select>"; 438 439 echo $selectMenu; 440 } 441 442 /** 443 * callback function that returns a select menu of card Positions 444 */ 445 public function callbackCardPositionField() 446 { 447 $options = ''; 448 $selected = isset($this->settings['card_tweet_position']) ? $this->settings['card_tweet_position'] : ''; 449 450 foreach ($this->cardPositions as $key => $value) { 451 $isSelected = ($key == $selected) ? ' selected' : ''; 452 $options .= "<option value=\"$key\"$isSelected>$value</option>"; 453 } 454 455 $selectMenu = "<select name=\"click_and_tweet_settings[card_tweet_position]\">$options</select>"; 456 457 echo $selectMenu; 458 } 459 298 460 /** 299 461 * sanitizes the setting for the twitter handle and adds '@' to the beginning. … … 351 513 public function clickAndTweetShortCode($atts, $content) 352 514 { 353 $linkAttributes = "href=\"{$this->shortcodeUrl($atts, $content)}\" 354 target=\"_blank\" 355 class=\"click-and-tweet-inline\""; 356 357 $twitterLogo = "<span class=\"click-and-tweet-twitter-logo\"></span>"; 358 359 $linkContent = "{$content}{$twitterLogo}"; 360 361 $content = "<a {$linkAttributes}>{$linkContent}</a>"; 362 515 $content = (isset($atts['layout']) && ($atts['layout'] == 'card')) ? $this->cardTweet($atts, $content) : $this->inlineTweet($atts, $content); 363 516 return $content; 364 517 } … … 384 537 private function getQuery($atts = array(), $content) 385 538 { 539 $text = html_entity_decode($content); 540 $username = $this->getUsername($atts); 541 $url = $this->getUrl(); 542 $hashtags = $this->getHashtags($atts); 543 $related = $this->getRelated($atts); 544 386 545 $query = [ 387 'text' => html_entity_decode($content), 388 'url' => get_permalink(), 389 'hashtags' => $this->getHastags($atts) 546 'text' => $this->autoTruncate($text, $username, $url, $hashtags), 547 'url' => $url, 548 'hashtags' => $hashtags, 549 'related' => $related 390 550 ]; 391 551 392 if($via = $this->getUsername($atts)) $query['via'] = $via; 552 if($username) $query['via'] = $username; 553 554 if($related) $query['related'] = $related; 393 555 394 556 return $query; 557 } 558 559 /** 560 * Auto Truncates the tweet to prevent the tweet from exceeding 140 characters 561 * @param string $text, $username, $url, $hashtag 562 * @return string $text 563 */ 564 private function autoTruncate($text, $username, $url, $hashtag) 565 { 566 $more = "..."; 567 $moreLength = strlen($more); 568 $textLength = strlen($text); 569 $usernameLength = ($username) ? strlen($username) + 1 : 0; 570 $viaLength = ($username) ? 4 : 0; 571 $hashtagCount = (!empty($hashtag) && count(explode(',',$hashtag)) > 1) ? count(explode(',',$hashtag)) : 0; 572 $hashtagLength = strlen($hashtag) + $hashtagCount + 1; 573 $urlLength = (strlen($url) >= 23) ? 21 : strlen($url) + 1; 574 575 $totalLength = $textLength + $hashtagLength + $viaLength + $usernameLength + $urlLength + $moreLength; 576 $x = $hashtagLength + $viaLength + $usernameLength + $urlLength + $moreLength; 577 578 if(isset($this->settings['use_auto_truncate']) && ($this->settings['use_auto_truncate'] == 1)) { 579 if($totalLength > 140) { 580 $text = wp_html_excerpt($text, $totalLength - 140); 581 $y = 140 - $x; 582 $text = wp_html_excerpt($text, $y - 3, $more); 583 } 584 } 585 586 return $text; 587 } 588 589 /** 590 * Get the url for the tweet 591 * @return string 592 */ 593 private function getUrl() 594 { 595 if((isset($this->settings['use_twitter_shortlink']) && $this->settings['use_twitter_shortlink'] == 1)) { 596 return $url = wp_get_shortlink(); 597 } 598 599 return $url = get_permalink();; 395 600 } 396 601 … … 405 610 isset($this->settings['default_username']) ? $this->settings['default_username'] : ''; 406 611 $handle = (!empty($atts['handle'])) ? $atts['handle'] : $defaultUsername; 407 408 612 $username = trim(str_replace('@', '', $handle)); 409 613 410 614 return $username; 411 412 615 } 413 616 … … 417 620 * @return $hashtags 418 621 */ 419 private function getHas tags($atts = array())622 private function getHashtags($atts = array()) 420 623 { 421 624 if(isset($atts['hashtag'])){ 422 625 $hashtags = $atts['hashtag']; 423 $hashtags = str_replace('#', '', $hashtags);626 $hashtags = trim(str_replace('#', '', $hashtags)); 424 627 $hashtags = explode(' ', $hashtags); 425 628 $hashtags = implode(',', $hashtags); 629 $hashtags = rtrim($hashtags, ','); 630 426 631 return $hashtags; 427 632 } 428 633 429 634 return $hashtags = ''; 635 } 636 637 /** 638 * Get related usernames 639 * @param array $atts 640 * @return string $related 641 */ 642 private function getRelated($atts) 643 { 644 if(isset($atts['related'])){ 645 $related = $atts['related']; 646 $related = str_replace('@', '', $related); 647 $related = explode(' ', $related); 648 $related = implode(',', $related); 649 650 return $related; 651 } 652 653 return $related = ''; 654 } 655 656 /** 657 * Create an inline tweet 658 * @param array $atts 659 * @param string $content 660 * @return string 661 */ 662 public function inlineTweet($atts, $content) 663 { 664 $position = (!empty($atts['position'])) ? ' '.$atts['position'] : ' '.$this->settings['inline_tweet_position']; 665 666 $linkAttributes = "href=\"{$this->shortcodeUrl($atts, $content)}\" 667 target=\"_blank\" 668 title=\"Click & Tweet this!\" 669 class=\"click-and-tweet-inline$position\""; 670 671 $twitterLogo = "<span class=\"click-and-tweet-twitter-logo\"></span>"; 672 673 $linkContent = (isset($position) && trim($position) == 'left') ? "{$twitterLogo}{$content}" : "{$content}{$twitterLogo}"; 674 675 $content = "<a {$linkAttributes}>{$linkContent}</a>"; 676 677 return $content; 678 } 679 680 /** 681 * Create a tweet card 682 * @param array $atts 683 * @param string $content 684 * @return string 685 */ 686 public function cardTweet($atts, $content) 687 { 688 $position = (!empty($atts['position'])) ? ' '.$atts['position'] : ' '.$this->settings['card_tweet_position']; 689 690 $linkAttributes = "href=\"{$this->shortcodeUrl($atts, $content)}\" 691 target=\"_blank\" 692 title=\"Click & Tweet this!\" 693 class=\"click-and-tweet-card-link$position\""; 694 695 $twitterLogo = "<span class=\"click-and-tweet-twitter-logo\"> 696 <a href=\"{$this->shortcodeUrl($atts, $content)}\" target=\"_blank\" title=\"Click & Tweet this!\"> 697 Click & Tweet this! 698 </a> 699 </span>"; 700 701 $linkContent = "{$content}"; 702 703 $content = "<div class=\"click-and-tweet-card$position\">{$twitterLogo}<a {$linkAttributes}>{$linkContent}</a></div>"; 704 705 return $content; 430 706 } 431 707 } -
click-tweet/trunk/readme.txt
r1312107 r1325871 1 1 === Click & Tweet === 2 Contributors: Space_Studio, tlaverdure 2 Contributors: Space_Studio, tlaverdure, bbearchell 3 3 Tags: twitter, click, tweet, click-to-tweet, click-and-tweet, inline-tweet, tweet-card 4 4 Requires at least: 3.8 … … 10 10 11 11 == Description == 12 Why Use It?12 ###Why Use It? 13 13 14 14 Surely you’d jump on the opportunity to use a tool that practically allows your content to market itself. Too good to be true? We all know the power and reach that Twitter has as a marketing tool. So we created this Click & Tweet plugin to provide your users with an enticing, simple way to share the content on your website. By doing this, you not only increase your audience, but also strengthen your authority as the opinions of peers hold a lot of weight today when it comes to backing a brand. 15 15 16 16 Share buttons can become just an afterthought, and by the last sentence users are probably already considering where to turn their attention next. The Click & Tweet plugin allows site owners to highlight what they consider to be the most “tweetable” phrases. Now when the reader comes across a key sentence or phrase that the author has highlighted, he can simply click the link at the end of the sentence and send the pre-formatted tweet. You have the ability to format the tweet to include a mention of your Twitter username, add hashtags, and a link back to your website. 17 18 ###Documentation 19 Read the documentation here: 20 21 [Documentation](https://space-studio.gitbooks.io/click-tweet-plugin/content/) 17 22 18 23 == Installation == … … 39 44 40 45 == Changelog == 46 = 0.2.0 = 47 * Added the option to create tweet cards. 48 * Added layout and positioning settings, allowing you to edit where you want the twitter logo on both inline tweets and tweet cards. 49 * Added a related username field to allow addition of related username. 50 * Bug Fixes 51 41 52 = 0.1.0 = 42 53 * Initial release of plugin.
Note: See TracChangeset
for help on using the changeset viewer.