Changeset 1068865
- Timestamp:
- 01/15/2015 10:17:30 PM (11 years ago)
- Location:
- append-link-on-copy/trunk
- Files:
-
- 3 edited
-
index.php (modified) (25 diffs)
-
js/append_link.js (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
append-link-on-copy/trunk/index.php
r658908 r1068865 4 4 Plugin URI: http://jonathanmh.com/wordpress-plugin-append-link-on-copy/ 5 5 Description: This plugin allows the user to automatically append a link to the current page, when users copy & paste a title or any line 6 Version: 0. 1.26 Version: 0.2 7 7 Author: Jonathan M. Hethey 8 8 Author URI: http://jonathanmh.com … … 12 12 if ( ! class_exists( 'Appendlink' ) ){ 13 13 class Appendlink { 14 14 15 15 private $plugin_url; 16 16 private $plugin_dir; 17 17 private $options; 18 18 19 19 function __construct() { 20 20 $this->plugin_url = plugins_url( basename( dirname( __FILE__ ) ) ); 21 21 $this->plugin_dir = dirname( __FILE__ ); 22 22 23 23 $this->options = get_option('append_link_on_copy_options'); 24 24 25 25 add_action( 'init', array( &$this, 'init') ); 26 26 add_action( 'wp', array( &$this, 'load_script' ) ); 27 27 28 28 add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); 29 29 add_action( 'admin_init', array( &$this, 'admin_init' ) ); 30 30 } 31 31 32 32 function init(){ 33 33 $options = get_option( 'append_link_on_copy_options' ); 34 if( !isset($options['readmore']) ) $options['readmore'] = 'Read more at: ';34 if( !isset($options['readmore']) ) $options['readmore'] = 'Read more at: %link%'; 35 35 if( !isset($options['prepend_break']) ) $options['prepend_break'] = 2; 36 36 if( !isset($options['use_title']) ) $options['use_title'] = 'false'; … … 39 39 $this->options = $options; 40 40 } 41 41 42 42 function load_script() { 43 43 wp_register_script( 'append_link', $this->plugin_url . '/js/append_link.js'); 44 44 wp_enqueue_script( 'append_link' ); 45 45 46 46 global $post; 47 47 48 48 /* debugging 49 49 echo '<pre>'; … … 51 51 echo '</pre>'; 52 52 */ 53 53 54 54 $options = $this->options; 55 55 56 56 $params = array( 57 57 'read_more' => $options['readmore'] … … 63 63 , 'always_link_site' => $options['always_link_site'] 64 64 ); 65 65 66 66 if ($options['use_title'] === 'true') { 67 67 if (is_singular()){ … … 73 73 } 74 74 } 75 76 75 76 77 77 wp_localize_script( 'append_link', 'append_link', $params ); 78 78 } 79 79 80 80 function admin_menu() { 81 81 // add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function); … … 88 88 ); 89 89 } 90 90 91 91 function admin_init() { 92 92 93 93 // register_setting( $option_group, $option_name, $sanitize_callback ); 94 94 register_setting( … … 97 97 , array( &$this, 'settings_validate' ) 98 98 ); 99 99 100 100 // add_settings_section( $id, $title, $callback, $page ); 101 101 add_settings_section( … … 105 105 , 'append_link_on_copy_options' 106 106 ); 107 107 108 108 add_settings_section( 109 109 'preview' … … 112 112 , 'append_link_on_copy_options' 113 113 ); 114 114 115 115 // add_settings_field( $id, $title, $callback, $page, $section, $args ); 116 116 add_settings_field( 117 117 'readmore' 118 , "Read more l abel: (like: \"Read more at:\" or \"Read full article here:\")"118 , "Read more link: (like: Text copied from %link% )" 119 119 , array( &$this, 'field_readmore' ) 120 120 , 'append_link_on_copy_options' 121 121 , 'main' 122 122 ); 123 123 124 124 add_settings_field( 125 125 'add_site_name' … … 129 129 , 'main' 130 130 ); 131 131 132 132 add_settings_field( 133 133 'use_title' … … 137 137 , 'main' 138 138 ); 139 139 140 140 add_settings_field( 141 141 'always_link_site' … … 145 145 , 'main' 146 146 ); 147 147 148 148 add_settings_field( 149 149 'prepend_break' … … 154 154 ); 155 155 } 156 156 157 157 function section_main() { 158 158 echo __('Change the appearance and contents of the appended link.'); 159 159 } 160 160 161 161 function section_preview() { 162 162 echo '<b>Notice:</b> Even though the text preview may not show the link, many web systems automatically link everything starting with http://, also everything copied from the front page, will not append the site title'; … … 165 165 $sample_site_link = 'http://jonathanmh.com/'; 166 166 $sample_site_name = 'JonathanMH.com'; 167 168 167 168 169 169 if ($this->options['always_link_site'] == true) { 170 170 $link = '<a href="' . $sample_site_link . '">'; … … 173 173 $link = '<a href="' . $sample_page_link . '">'; 174 174 } 175 175 176 176 if ($this->options['use_title'] == 'true'){ 177 177 $link .= 'Append Link on Copy'; … … 185 185 } 186 186 } 187 187 188 188 if ($this->options['add_site_name'] == 'true'){ 189 $link .= ' | ' . $sample_site_name; 190 } 191 189 $link .= ' | ' . $sample_site_name; 190 } 191 192 192 $link .= '</a>'; 193 193 194 194 echo '<h4>' . 'Quoted text: </h4>'; 195 195 echo "<blockquote>"; … … 205 205 echo '<br />'; 206 206 } 207 208 echo 209 $this->options['readmore'] 210 . ' ' . $link; 207 208 echo $this->options['readmore'] . ' ' . $link; 211 209 echo "</blockquote>"; 212 210 echo '<h4>' . 'Text preview' . '</h4>'; … … 216 214 echo '<br />'; 217 215 } 218 219 echo 220 $this->options['readmore'] 221 . ' ' . strip_tags($link); 216 217 echo $this->options['readmore'] . ' ' . strip_tags($link); 222 218 echo "</blockquote>"; 223 /* debugging for options 224 echo '<pre>'; 225 var_dump($this->options); 226 echo '</pre>'; 227 */ 228 } 229 219 } 220 230 221 function field_readmore() { 231 222 echo … … 238 229 . '" />'; 239 230 } 240 231 241 232 function field_prepend_break() { 242 233 echo … … 249 240 . '" />'; 250 241 } 251 242 252 243 function field_add_site_name() { 253 244 echo '<input type="hidden" name="append_link_on_copy_options[add_site_name]" value="false" />' … … 256 247 .' />'; 257 248 } 258 249 259 250 function field_use_title() { 260 251 echo '<input type="hidden" name="append_link_on_copy_options[use_title]" value="false" />' … … 263 254 .' />'; 264 255 } 265 256 266 257 function field_always_link_site() { 267 258 echo '<input type="hidden" name="append_link_on_copy_options[always_link_site]" value="false" />' … … 270 261 .' />'; 271 262 } 272 263 273 264 function settings_page() 274 265 { 275 266 require( $this->plugin_dir . '/settings.php' ); 276 267 } 277 268 278 269 function settings_validate( $input ) { 279 270 $newinput = $input; … … 281 272 $newinput['prepend_break'] = (integer) $input['prepend_break']; 282 273 //$newinput['prepend_break'] = trim($input['prepend_break']); 283 274 284 275 return $newinput; 285 276 } 286 277 287 278 288 279 } 289 280 290 281 $append_link = new Appendlink(); 291 282 -
append-link-on-copy/trunk/js/append_link.js
r658680 r1068865 6 6 var linebreaks = ''; 7 7 var link_name; 8 8 9 9 10 for (i = 0; i < append_link.prepend_break; i++) { 10 11 linebreaks = linebreaks + '<br />'; 11 12 } 12 13 13 14 if (append_link.use_title == 'true') { 14 15 link_name = append_link.page_title; … … 17 18 link_name = document.URL 18 19 } 19 20 20 21 if (append_link.add_site_name == 'true') { 21 22 link_name += ' | ' + append_link.site_name; 22 23 } 23 24 24 25 if (append_link.always_link_site == true) { 25 26 link_url = append_link.site_url; … … 28 29 link_url = document.URL; 29 30 } 30 31 31 32 var pagelink = 32 33 linebreaks 33 + ' ' + append_link.read_more + ' ' 34 + "<a href='" 35 + link_url +"'>" 36 + link_name+"</a>"; 37 38 /* debugging 39 console.log(pagelink); 40 console.log(append_link); 41 */ 34 + ' ' + append_link.read_more + ' '; 35 36 pagelink = pagelink.replace('%link%', ' ' + link_url + ' '); 37 42 38 var copytext = selection + pagelink; 43 39 var newdiv = document.createElement('div'); 40 44 41 newdiv.style.position='absolute'; 45 42 newdiv.style.left='-99999px'; -
append-link-on-copy/trunk/readme.txt
r658866 r1068865 4 4 Tags: append link, copyright, js, javscript, add text to copy and paste, copy 'n paste, copy & paste 5 5 Requires at least: 2.8 6 Tested up to: 3.57 Stable tag: 0. 1.26 Tested up to: 4.1 7 Stable tag: 0.2 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 52 52 == Changelog == 53 53 54 = 0.2 = 55 2015-1-15 56 57 version bump, link replace string 58 54 59 = 0.1.1 = 55 60 2013-1-25
Note: See TracChangeset
for help on using the changeset viewer.