Plugin Directory

Changeset 470073


Ignore:
Timestamp:
12/02/2011 02:46:59 AM (14 years ago)
Author:
anubisthejackle
Message:

Update 2.1 - Added auto update on settings change, and manual tag placement VIA shortcode.

Location:
auto-more-tag/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • auto-more-tag/trunk/auto-more-options-page.php

    r461477 r470073  
    1414<div class="wrap">
    1515    <h2>Auto More Tag by <a href="http://travisweston.com/">Travis Weston</a></h2>
    16         <?php $options = get_option('tw_auto_more_tag'); ?>
     16        <?php $options = get_option('tw_auto_more_tag');
     17            if(isset($_GET['settings-updated']) && isset($options['auto_update']) && $options['auto_update'] == true){
     18                $this->updateAll();
     19            }
     20        ?>
    1721        <?php
    1822            if(hasErrors($options['messages']) || hasNotices($options['messages']) || hasWarnings($options['messages'])){
     
    9094                <label for="tw_auto_more_tag[credit_me]">Give Credit Where Credit is Due?</label>
    9195                <select id="tw_auto_more_tag[credit_me]" name="tw_auto_more_tag[credit_me]">
    92                     <option value="0" <?php echo (!isset($options['credit_me']) || $options['credit_me'] == false) ? 'selected="SELECTED" ' : null; ?>/>No
    93                     <option value="1" <?php echo (isset($options['credit_me']) && $options['credit_me'] == true) ? 'selected="SELECTED" ' : null;?>/>Yes
     96                    <option value="0" <?php echo (isset($options['credit_me']) && $options['credit_me'] == false) ? 'selected="SELECTED" ' : null; ?>/>No
     97                    <option value="1" <?php echo (!isset($options['credit_me']) || $options['credit_me'] == true) ? 'selected="SELECTED" ' : null;?>/>Yes
     98                </select>
     99            </div>
     100            <div>
     101                <label for="tw_auto_more_tag[auto_update]">Auto Update Posts On Settings Update?</label>
     102                <select id="tw_auto_more_tag[auto_update]" name="tw_auto_more_tag[auto_update]">
     103                    <option value="1" <?php echo (!isset($options['auto_update']) || $options['auto_update'] == true) ? 'selected="SELECTED" ' : null;?>/>Yes
     104                    <option value="0" <?php echo (isset($options['auto_update']) && $options['auto_update'] == false) ? 'selected="SELECTED" ' : null;?>/>No
     105                </select>
     106            </div>
     107            <div>
     108                <label for="tw_auto_more_tag[ignore_man_tag]">Ignore Manually Inserted Tags?</label>
     109                <select id="tw_auto_more_tag[ignore_man_tag]" name="tw_auto_more_tag[ignore_man_tag]">
     110                    <option value="1" <?php echo (!isset($options['ignore_man_tag']) || $options['ignore_man_tag'] == true) ? 'selected="SELECTED" ' : null;?>/>Yes
     111                    <option value="0" <?php echo (isset($options['ignore_man_tag']) && $options['ignore_man_tag'] == false) ? 'selected="SELECTED" ' : null;?>/>No
    94112                </select>
    95113            </div>
  • auto-more-tag/trunk/auto-more.php

    r461477 r470073  
    66Author: Travis Weston
    77Author URI: http://travisweston.com/
    8 Version: 2.0
     8Version: 2.1
    99*/
    10 file_put_contents('debug.log', 'test', FILE_APPEND);
     10
    1111if(!defined('TW_AUTO_MORE_TAG')){
    1212   
     
    2020
    2121        public function __construct() {
     22            global $wpdb;
     23
     24            $this->_db = &$wpdb;
     25
    2226            self::$_instance = $this;
    2327        }
     
    4549            $length = $options['quantity'];
    4650            $breakOn = $options['break'];
    47            
    48             $shortCode = strpos($data, '[amt_override');
    49 
    50             if($shortCode !== false){
    51                 return $data;
     51
     52            $moreTag = strpos($data, '[amt_override]');
     53
     54            if($moreTag !== false && $options['ignore_man_tag'] != true){
     55               
     56                return self::$_instance->manual($data);
     57
    5258            }
    5359
     
    7177        }
    7278
     79        public function manual($data) {
     80
     81            $data = str_replace('<!--more-->', '', $data);
     82            $data = str_replace('[amt_override]','[amt_override]<!--more-->', $data);
     83
     84            return $data;
     85
     86        }
     87
    7388        public function byWord($data, $length, $breakOn) {
    7489            // UNUSED IN CURRENT VERSION
     
    96111                $temp = substr($data, 0, $pos);
    97112                $temp_end = substr($data, $pos);
     113                if(empty($temp_end) || trim($temp_end) == null || strlen($temp_end) <= 0)
     114                    return $data;
     115
    98116                $data = $temp.'<!--more-->'.$temp_end;
    99117
     
    127145            $temp = substr($data, 0, $pos);
    128146            $temp_end = substr($data, $pos);
     147           
     148            if(empty($temp_end) || trim($temp_end) == null)
     149                return $data;
     150
    129151            $data = $temp.'<!--more-->'.$temp_end;
    130152
     
    141163        public function validateOptions($input){
    142164
     165           
    143166            $start = $input;
    144            
     167               
    145168            $input['messages'] = array(
    146169                    'errors' => array(),
     
    164187            }
    165188
     189            $input['ignore_man_tag'] = (isset($input['ignore_man_tag']) && ((bool)$input['ignore_man_tag'] == true)) ? true : false;
     190
    166191            $input['units'] = ((int)$input['units'] == 1) ? 1 : (((int)$input['units'] == 2) ? 2 : 3);
    167192
     
    184209           
    185210            $input['break'] = (isset($input['break']) && (int)$input['break'] == 2) ? 2 : 1;
    186 
    187             $input['credit'] = true;
    188 
     211       
    189212            return $input;
    190213
     
    201224        }
    202225
    203         #public function manualOverride($atts, $content = null, $code = null){
    204         #   #NOT CURRENTLY WORKING
    205         #   return '<!--more-->';
    206         #}
     226        private function updateAll() {
     227       
     228            $posts = get_posts(array(
     229                'numberposts' => '-1',
     230                'post_status' => 'publish',
     231                'post_type' => 'post'
     232            ));
     233
     234            if(count($posts) > 0){
     235                global $post;
     236                foreach($posts as $post){
     237                    setup_postdata($post);
     238                    $post->post_content = self::addTag($post->post_content);
     239                    wp_update_post($post);         
     240                }
     241            }
     242   
     243        }
     244
     245        public function manualOverride($atts, $content = null, $code = null){
     246            // We just want to make this tag disappear. Let's just make it go away now...
     247            return null;
     248        }
     249
    207250    }
    208251    $tw_auto_more_tag = new tw_auto_more_tag();
     
    212255    add_action('wp_footer', 'tw_auto_more_tag::doFooter');
    213256    add_filter('content_save_pre', 'tw_auto_more_tag::addTag', '1', 2);
    214     #add_shortcode('amt_override', array($tw_auto_more_tag, 'manualOverride'));
    215     define('TW_AUTO_MORE_TAG', '<div style="text-align: center;"><a href="http://travisweston.com" target="_blank" style="font-size: 8pt;">Auto More Tag powered by TravisWeston.com</a></div>');
     257    add_shortcode('amt_override', array($tw_auto_more_tag, 'manualOverride'));
     258   
     259    define('TW_AUTO_MORE_TAG', '<div style="text-align: center;"><a href="http://travisweston.com" target="_blank" style="font-size: 7pt;">PHP/MySQL Components, WordPress Plugins, and Technology Opinions at TravisWeston.com</a></div>');
    216260}
  • auto-more-tag/trunk/readme.txt

    r461477 r470073  
    55Requires at least: 3.2.1
    66Tested up to: 3.2.1
    7 Stable tag: 2.0
     7Stable tag: 2.1
    88
    99Allows you to add a More tag to your post automatically upon publication.
     
    3535== Changelog ==
    3636
     37= 2.1 =
     38
     39Added option to automatically update when new settings are saved. This cycles through all your posts, and updates each one based on the new Auto More Tag settings. Also added in a shortcode for manual placement, for those times when you just have to do it yourself.
     40
    3741= 2.0 =
    3842
Note: See TracChangeset for help on using the changeset viewer.