Plugin Directory

Changeset 1068865


Ignore:
Timestamp:
01/15/2015 10:17:30 PM (11 years ago)
Author:
JonathanMH_com
Message:

%link% replace string, version bump

Location:
append-link-on-copy/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • append-link-on-copy/trunk/index.php

    r658908 r1068865  
    44    Plugin URI: http://jonathanmh.com/wordpress-plugin-append-link-on-copy/
    55    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.2
     6    Version: 0.2
    77    Author: Jonathan M. Hethey
    88    Author URI: http://jonathanmh.com
     
    1212if ( ! class_exists( 'Appendlink' ) ){
    1313class Appendlink {
    14    
     14
    1515    private $plugin_url;
    1616    private $plugin_dir;
    1717    private $options;
    18    
     18
    1919    function __construct() {
    2020        $this->plugin_url = plugins_url( basename( dirname( __FILE__ ) ) );
    2121        $this->plugin_dir = dirname( __FILE__ );
    22        
     22
    2323        $this->options = get_option('append_link_on_copy_options');
    24        
     24
    2525        add_action( 'init', array( &$this, 'init') );
    2626        add_action( 'wp', array( &$this, 'load_script' ) );
    27        
     27
    2828        add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
    2929        add_action( 'admin_init', array( &$this, 'admin_init' ) );
    3030    }
    31    
     31
    3232    function init(){
    3333        $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%';
    3535        if( !isset($options['prepend_break']) ) $options['prepend_break'] = 2;
    3636        if( !isset($options['use_title']) ) $options['use_title'] = 'false';
     
    3939        $this->options = $options;
    4040    }
    41    
     41
    4242    function load_script() {
    4343        wp_register_script( 'append_link', $this->plugin_url . '/js/append_link.js');
    4444        wp_enqueue_script( 'append_link' );
    45        
     45
    4646        global $post;
    47        
     47
    4848        /* debugging
    4949        echo '<pre>';
     
    5151        echo '</pre>';
    5252        */
    53        
     53
    5454        $options = $this->options;
    55        
     55
    5656        $params =   array(
    5757              'read_more'           => $options['readmore']
     
    6363            , 'always_link_site'    => $options['always_link_site']
    6464        );
    65        
     65
    6666        if ($options['use_title'] === 'true') {
    6767            if (is_singular()){
     
    7373            }
    7474        }
    75            
    76        
     75
     76
    7777        wp_localize_script( 'append_link', 'append_link', $params );
    7878    }
    79    
     79
    8080    function admin_menu() {
    8181        // add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function);
     
    8888        );
    8989    }
    90    
     90
    9191    function admin_init() {
    92        
     92
    9393        // register_setting( $option_group, $option_name, $sanitize_callback );
    9494        register_setting(
     
    9797            , array( &$this, 'settings_validate' )
    9898        );
    99        
     99
    100100        // add_settings_section( $id, $title, $callback, $page );
    101101        add_settings_section(
     
    105105            , 'append_link_on_copy_options'
    106106        );
    107        
     107
    108108        add_settings_section(
    109109            'preview'
     
    112112            , 'append_link_on_copy_options'
    113113        );
    114        
     114
    115115        // add_settings_field( $id, $title, $callback, $page, $section, $args );
    116116        add_settings_field(
    117117            'readmore'
    118             , "Read more label: (like: \"Read more at:\" or \"Read full article here:\" )"
     118            , "Read more link: (like: Text copied from %link% )"
    119119            , array( &$this, 'field_readmore' )
    120120            , 'append_link_on_copy_options'
    121121            , 'main'
    122122        );
    123        
     123
    124124        add_settings_field(
    125125            'add_site_name'
     
    129129            , 'main'
    130130        );
    131        
     131
    132132        add_settings_field(
    133133            'use_title'
     
    137137            , 'main'
    138138        );
    139        
     139
    140140        add_settings_field(
    141141            'always_link_site'
     
    145145            , 'main'
    146146        );
    147        
     147
    148148        add_settings_field(
    149149            'prepend_break'
     
    154154        );
    155155    }
    156    
     156
    157157    function section_main() {
    158158        echo __('Change the appearance and contents of the appended link.');
    159159    }
    160    
     160
    161161    function section_preview() {
    162162        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';
     
    165165        $sample_site_link = 'http://jonathanmh.com/';
    166166        $sample_site_name = 'JonathanMH.com';
    167        
    168        
     167
     168
    169169        if ($this->options['always_link_site'] == true) {
    170170            $link = '<a href="' . $sample_site_link . '">';
     
    173173            $link = '<a href="' . $sample_page_link . '">';
    174174        }
    175        
     175
    176176        if ($this->options['use_title'] == 'true'){
    177177            $link .= 'Append Link on Copy';
     
    185185            }
    186186        }
    187        
     187
    188188        if ($this->options['add_site_name'] == 'true'){
    189             $link .= ' | ' . $sample_site_name; 
    190         }
    191        
     189            $link .= ' | ' . $sample_site_name;
     190        }
     191
    192192        $link .= '</a>';
    193        
     193
    194194        echo '<h4>' . 'Quoted text: </h4>';
    195195        echo "<blockquote>";
     
    205205            echo '<br />';
    206206        }
    207        
    208         echo
    209             $this->options['readmore']
    210             . ' ' . $link;
     207
     208        echo $this->options['readmore'] . ' ' . $link;
    211209        echo "</blockquote>";
    212210        echo '<h4>' . 'Text preview' . '</h4>';
     
    216214            echo '<br />';
    217215        }
    218        
    219         echo
    220             $this->options['readmore']
    221             . ' ' . strip_tags($link);
     216
     217        echo $this->options['readmore'] . ' ' . strip_tags($link);
    222218        echo "</blockquote>";
    223         /* debugging for options
    224         echo '<pre>';
    225         var_dump($this->options);
    226         echo '</pre>';
    227 */
    228     }
    229    
     219    }
     220
    230221    function field_readmore() {
    231222        echo
     
    238229            . '" />';
    239230    }
    240    
     231
    241232    function field_prepend_break() {
    242233        echo
     
    249240            . '" />';
    250241    }
    251    
     242
    252243    function field_add_site_name() {
    253244    echo  '<input type="hidden" name="append_link_on_copy_options[add_site_name]" value="false" />'
     
    256247        .' />';
    257248    }
    258    
     249
    259250    function field_use_title() {
    260251    echo  '<input type="hidden" name="append_link_on_copy_options[use_title]" value="false" />'
     
    263254        .' />';
    264255    }
    265    
     256
    266257    function field_always_link_site() {
    267258        echo  '<input type="hidden" name="append_link_on_copy_options[always_link_site]" value="false" />'
     
    270261        .' />';
    271262    }
    272    
     263
    273264    function settings_page()
    274265    {
    275266        require( $this->plugin_dir . '/settings.php' );
    276267    }
    277    
     268
    278269    function settings_validate( $input ) {
    279270        $newinput = $input;
     
    281272        $newinput['prepend_break'] = (integer) $input['prepend_break'];
    282273        //$newinput['prepend_break'] = trim($input['prepend_break']);
    283        
     274
    284275        return $newinput;
    285276    }
    286277
    287    
     278
    288279}
    289    
     280
    290281$append_link = new Appendlink();
    291282
  • append-link-on-copy/trunk/js/append_link.js

    r658680 r1068865  
    66    var linebreaks = '';
    77    var link_name;
    8    
     8
     9
    910    for (i = 0; i < append_link.prepend_break; i++) {
    1011        linebreaks = linebreaks + '<br />';
    1112    }
    12    
     13
    1314    if (append_link.use_title == 'true') {
    1415        link_name = append_link.page_title;
     
    1718        link_name = document.URL
    1819    }
    19    
     20
    2021    if (append_link.add_site_name == 'true') {
    2122        link_name += ' | ' + append_link.site_name;
    2223    }
    23    
     24
    2425    if (append_link.always_link_site == true) {
    2526        link_url = append_link.site_url;
     
    2829        link_url = document.URL;
    2930    }
    30    
     31
    3132    var pagelink =
    3233        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
    4238    var copytext = selection + pagelink;
    4339    var newdiv = document.createElement('div');
     40
    4441    newdiv.style.position='absolute';
    4542    newdiv.style.left='-99999px';
  • append-link-on-copy/trunk/readme.txt

    r658866 r1068865  
    44Tags: append link, copyright, js, javscript, add text to copy and paste, copy 'n paste, copy & paste
    55Requires at least: 2.8
    6 Tested up to: 3.5
    7 Stable tag: 0.1.2
     6Tested up to: 4.1
     7Stable tag: 0.2
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5252== Changelog ==
    5353
     54= 0.2 =
     552015-1-15
     56
     57version bump, link replace string
     58
    5459= 0.1.1 =
    55602013-1-25
Note: See TracChangeset for help on using the changeset viewer.