Changeset 45331

Show
Ignore:
Timestamp:
05/12/08 03:26:35 (2 months ago)
Author:
johnkolbert
Message:

Upgraded to 1.2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • smart-ads/trunk/readme.txt

    r40979 r45331  
    44Tags: ads, advertisements, insert 
    55Requires at least: 2.3 
    6 Tested up to: 2.5 
    7 Stable tag: 1.1.
     6Tested up to: 2.5.1 
     7Stable tag: 1.
    88 
    9 This plugin allows you to intelligently insert ads (like Adsense) before and after your post content based on post wordcount, post date, or other
     9This plugin allows you to intelligently insert ads (like Adsense) before and after your post content based on post wordcount, post date, or other features
    1010 
    1111== Description == 
     
    1717== Installation == 
    1818 
    19 1. Before uploading the folder, open "yourads.php" and paste your desired advertising code into the three indicated areas. yourads.php contains three variables which house your code data: $topad, $bottomad, and $customad. Sample data is provided as an example of how to paste your code. Replace the sample data by simply highlighting it and pasting your advertising code over it. Enter your ad code into the the other two variables to match. 
     19First Installation: 
     20 
     211. Before uploading the folder, change "yourads.php.txt" to "yourads.php." This feature prevents automatic upgrades from overwriting your file. Then, open your newly renamed "yourads.php" and paste your desired advertising code into the three indicated areas. yourads.php contains three variables which house your code data: $topad, $bottomad, and $customad. Sample data is provided as an example of how to paste your code. Replace the sample data by simply highlighting it and pasting your advertising code over it. Enter your ad code into the the other two variables to match. 
    2022 
    21232. Because we're working with PHP data, you may have to "escape" your advertising code if it contains any single quotes (like ' ). Escaping means simply placing a forward slash before the single quote. So if the original sentence was: "Hello, I'm "hungry" didn't you know?" You would escape it to look like the following: "Hello, I\'m "hungry" didn\'t you know?". If your code doesn't contain single quotes then this isn't necessary. 
     
    23253. Upload the plugin folder containing both files to wp-content/plugins/ and activate from the Plugin administrative menu. 
    2426 
     27Upgrade: 
     28 
     29Use the automatic upgrade feature. Your advertising code will not be overwritten. Otherwise, upload "smartads.php" to your current smartads folder. 
     30 
    2531== Frequently Asked Questions == 
    2632 
  • smart-ads/trunk/smartads.php

    r40979 r45331  
    55Description: Automatically adds advertisements before and after your post's single page content based on word count or post age. You can also ad custom ads wherever you like by typing   <!-smartads-   > into your posts! 
    66Author: John Kolbert 
    7 Version: 1.1.
     7Version: 1.
    88Author URI: http://simply-basic.com/ 
    99 
     
    4848 
    4949function smartads_options_page(){ 
    50 include 'yourads.php'; 
     50$changefile = ABSPATH . 'wp-content/plugins/' . dirname(plugin_basename(__FILE__)) . '/yourads.php'; 
     51echo $changefile; 
     52if (file_exists($changefile)){ 
     53  include 'yourads.php'; 
     54}   
    5155      global $wpdb; 
     56      if (!file_exists($changefile)){ 
     57     echo '<div class="updated" style="color: red; font-size: 14px; height: 20px; padding: 5px; border: 1px solid #E6DB55;"><strong><center>"yourads.php" was not found. Did you change "yourads.php.txt" to "yourads.php"?</strong></center></div>'; 
     58  } 
     59 
    5260      if (isset($_POST['update_options'])) { 
    5361        $options['smart_ads_showindexcust'] = trim($_POST['smart_ads_showindexcust'],'{}'); 
     62        $options['smart_ads_custcomment'] = trim($_POST['smart_ads_custcomment'],'{}'); 
    5463    $options['smart_ads_wordcount'] = trim($_POST['smart_ads_wordcount'],'{}'); 
    5564    $options['smart_ads_days'] = trim($_POST['smart_ads_days'],'{}'); 
    5665    $options['smart_ads_catex'] = trim($_POST['smart_ads_catex'],'{}'); 
    5766    $options['smart_ads_regsuser'] = trim($_POST['smart_ads_regsuser'],'{}'); 
    58             update_option('smart_ads_insert', $options); 
     67    $options['smart_ads_imgex'] = trim($_POST['smart_ads_imgex'],'{}'); 
     68    $options['smart_ads_imgchar'] = trim($_POST['smart_ads_imgchar'],'{}'); 
     69    $options['smart_ads_postbox'] = trim($_POST['smart_ads_postbox'],'{}'); 
     70    update_option('smart_ads_insert', $options); 
    5971            // Show a message to say we've done something 
    6072            echo '<div class="updated"><p>' . __('Options saved') . '</p></div>'; 
     
    7587               <tr valign="top"> 
    7688                <th scope="row">Show Custom ads on Homepage?</th> 
    77                 <td><input type="checkbox" name="smart_ads_showindexcust" id="smart_ads_showindexcust" <?php if ($options['smart_ads_showindexcust'] == 1) {echo "checked";} ?> value="1"  > Yes <br /> If selected, Custom ads will be displayed on the main blog page. Otherwise they will only be displayed on the single post or page view. </td> 
     89                <td><input type="checkbox" name="smart_ads_showindexcust" id="smart_ads_showindexcust" <?php if ($options['smart_ads_showindexcust'] == 1) {echo "checked";} ?> value="1"  > Yes <br /> If selected, Custom ads will be displayed on the main blog page. Otherwise they will only be displayed on the single post or page view.<br /><strong>Note</strong>: <a href="https://www.google.com/adsense/support/bin/answer.py?answer=48182&sourceid=aso&subid=ww-ww-et-asui&medium=link&gsessionid=DERvyq807mw">Google policies state</a> that only three ad units may be displayed on a single page, so be careful using this option.</td> 
    7890              </tr> 
     91               <tr valign="top"> 
     92                        <th scope="row">Custom ads notation:</th> 
     93                              <td><input name="smart_ads_custcomment" type="radio" id="smart_ads_custcomment" value="comment" <?php if (($options['smart_ads_custcomment'] !== "bracket") ) {echo 'checked';} ?> /> <?php $data = '<!-smartads->'; echo htmlentities($data); ?> (<em>Default</em>, an HTML comment)<br /> 
     94          <input name="smart_ads_custcomment" type="radio" id="smart_ads_custcomment" value="bracket" <?php if ($options['smart_ads_custcomment'] == "bracket") {echo 'checked';} ?> />{smartads}<br /> Use the HTML comment unless you use the WordPress' visual editor and are having problems getting your ads to appear. 
     95      </tr> 
    7996      <tr valign="top"> 
    8097                        <th scope="row">Minimum Post <br /> Word Count:</th> 
     
    87104                  <tr valign="top"> 
    88105                    <th scope="row">Category Exclusions:</th> 
    89                       <td><input name="smart_ads_catex" type="text" id="smart_ads_catex" value="<?php echo $options['smart_ads_catex']; ?>" size="10" /> List category IDs seperated by a comma and a single space (such as 15, 2, 19)<br />This does not affect Custom Ads.</td> 
     106                      <td><input name="smart_ads_catex" type="text" id="smart_ads_catex" value="<?php echo $options['smart_ads_catex']; ?>" size="10" /> List category IDs seperated by a comma and a single space (such as 15, 2, 19)<br />These categories will not have ads placed in them. This does not affect Custom Ads.</td> 
     107                  </tr> 
     108                  <tr valign="top"> 
     109                    <th scope="row">Disable Top Ad if Post Begins with an Image:</th> 
     110                <td><input type="checkbox" name="smart_ads_imgex" id="smart_ads_imgex" <?php if ($options['smart_ads_imgex'] == 1) {echo "checked";} ?> value="1"  > Yes, if an image tag is found within the first  
     111            <input name="smart_ads_imgchar" type="text" id="smart_ads_imgchar" value="<?php echo $options['smart_ads_imgchar']; ?>" size="3" /> characters (including HTML characters). Recommended value: 200<br /> This does not affect the Bottom Ad or Custom Ads.</td> 
    90112                  </tr> 
    91113                  <tr valign="top"> 
     
    93115                <td><input type="checkbox" name="smart_ads_regsuser" id="smart_ads_regsuser" <?php if ($options['smart_ads_regsuser'] == 1) {echo "checked";} ?> value="1"  > Yes <br /> If selected, registered members of your blog will not see any ads, even custom ads.</td> 
    94116                  </tr> 
    95                   </table> 
     117                  <tr valign="top"> 
     118                    <th scope="row">Hide per-post options box:</th> 
     119                <td><input type="checkbox" name="smart_ads_postbox" id="smart_ads_postbox" <?php if ($options['smart_ads_postbox'] == 1) {echo "checked";} ?> value="1"  > Yes <br /> This allows you to hide the Smart Ads options box that appears while writing a post.<br />No post settings will be lost.</td> 
     120                  </tr> 
     121      </table> 
    96122             
    97123                  <div class="postbox"> 
    98124                  <h3>Your Code</h3> 
     125                  <?php 
     126                   
     127                  if (!file_exists($changefile)){ 
     128        echo '<div style="background: #FFFBCC; color: red; font-size: 14px; height: 20px; padding: 5px; border: 1px solid #E6DB55;"><strong><center>"yourads.php" was not found. Did you change "yourads.php.txt" to "yourads.php"?</strong></center></div>'; 
     129      } 
     130                  ?> 
    99131                  <p>The following is shown for your information only. To edit the Top, Bottom, and Custom Ads code please edit "wp-content/plugins/smartads/yourads.php".</p> 
    100132                  <div class="inside"> 
     
    110142              <tr valign="top"> 
    111143                <th scope="row">Custom Ad:</th> 
    112                         <td>This code can be inserted anywhere in your posts or pages by typing <strong><?php $data = '<!-smartads->'; echo htmlentities($data); ?></strong> where you want your ad to appear. To change this code edit "...wp-content/plugins/smartads/yourads.php"<div style="background: #eee; padding: 5px; border: 1px solid #ddd; margin-top: 5px; margin-bottom: 5px;"><?php if(trim($customad) != null)  {echo(stripslashes (htmlspecialchars ($customad)));} else {echo '<strong>Custom ad not set. Please edit <em>$customad</em> in "...wp-content/plugins/smartads/yourads.php"</strong>';} ?></div></td> 
     144                        <td>This code can be inserted anywhere in your posts or pages by typing <strong><?php $data = '<!-smartads-> or {smartads}'; echo htmlentities($data); ?></strong> where you want your ad to appear. To change this code edit "...wp-content/plugins/smartads/yourads.php"<div style="background: #eee; padding: 5px; border: 1px solid #ddd; margin-top: 5px; margin-bottom: 5px;"><?php if(trim($customad) != null)  {echo(stripslashes (htmlspecialchars ($customad)));} else {echo '<strong>Custom ad not set. Please edit <em>$customad</em> in "...wp-content/plugins/smartads/yourads.php"</strong>';} ?></div></td> 
    113145              </tr>   
    114146            </table> 
     
    136168 
    137169function smartads_write_box() { 
     170 
    138171    global $post; 
    139172    $options = get_option('smart_ads_insert'); 
     173 
    140174      if (function_exists('current_user_can')) { 
    141175            if (!current_user_can('manage_options')) return; 
     
    150184      
    151185            ?> 
    152             <div class="postbox"> 
    153       <h3>Smart Ads <small>by <a title="John Kolbert" href="http://simply-basic.com/smart-ads-plugin" target="_blank">John Kolbert</a></small></h3> 
    154   <div class="inside"> 
    155   <p></p> 
     186            <div class="side-info"> 
     187      <h5><a style="color: #000; text-decoration: none;" href="http://simply-basic.com/smart-ads-plugin" target="_blank">Smart Ads</a></h5> 
     188   
    156189            <input value="smartads_post" type="hidden" name="smartads_post" /> 
    157             <table class="form-table" style="text-align: left;"> 
    158             <tr valign="top"><th scope="row" >Disable ads for this post:</th> 
    159             <td><input type="checkbox" name="smart_ads_disable" id="smart_ads_disable" <?php if ($disable == 1) {echo "checked";} ?> value="1"  > Yes <br /> If selected, Top and Bottom ads will not be shown on this post, regardless of the word count or post date. This does not affect Custom Ads.</td> 
    160             </tr> 
    161             <tr valign="top"><th scope="row" >Minimum Word Count:</th> 
    162             <td><big><?php if (isset($options['smart_ads_wordcount']) && ($options['smart_ads_wordcount'] != 0)) {echo $options['smart_ads_wordcount'] . '</big><br /> This is the minimum number of words your post must have before Top and Bottom ads will be displayed. This can be changed in the plugin options menu.';} else{ echo "Wordcount limit not set";} ?></td></tr> 
    163     <tr valign="top"><th scope="row" >Ads Delayed For:</th> 
    164             <td><?php if(isset($options['smart_ads_days']) && ($options['smart_ads_days'] != 0)) { echo 'Ads will not be shown until this post is <big>' . $options['smart_ads_days'] . '</big> days old. This does not include Custom Ads.'; } else { echo "<big>Ad date restrictions not set.</big>"; } ?></td> 
    165        
     190            <table style="text-align: left; font-size: 10px;"> 
     191            <tr valign="top"> 
     192            <td><input type="checkbox" name="smart_ads_disable" id="smart_ads_disable" <?php if ($disable == 1) {echo "checked";} ?> value="1"  ></td><td style="font-size: 11px;">Disable ads for this post. This does not affect Custom Ads.</td> 
     193            </tr>        
    166194            </table> 
    167             </div></div> 
     195            <p>Custom ads may be added by entering <?php 
     196  if ($options['smart_ads_custcomment'] == "bracket"){ 
     197      echo '{smartads}'; 
     198      }  
     199       
     200      else {$toecho = '<!-smartads->'; 
     201      echo  htmlentities($toecho);}?> 
     202   anywhere in your post</p> 
     203            </div> 
    168204            <?php 
    169205             
     
    171207 
    172208function add_smartads_custom_field($id){ 
     209if ($options['smart_ads_postbox'] != 1){ 
    173210  $smartdisable = $_POST["smart_ads_disable"]; 
    174211     
     
    180217     add_post_meta($id, 'smartadsdisable', $smartdisable); 
    181218    }  
     219  } 
    182220} 
    183221 
     
    195233  $options = get_option('smart_ads_insert'); 
    196234  
    197   $catex = trim($options[smart_ads_catex]); 
     235  $catex = trim($options['smart_ads_catex']); 
    198236  $catex = explode(", ", $catex);   
    199237   
     
    207245 
    208246 
     247function smartads_imgexclude($content){       //exclude posts that start with images 
     248  $options = get_option('smart_ads_insert'); 
     249   
     250  if(($options['smart_ads_imgex'] == 1) && (stristr(substr($content, 0, $options['smart_ads_imgchar']), '<img') == true)){ 
     251     return 1; 
     252     } 
     253   else{ 
     254     return 0; 
     255     } 
     256} 
     257 
     258 
    209259  
    210260function smartads_insert($content){  //adds the ads 
     
    212262  global $post; 
    213263  $options = get_option('smart_ads_insert'); 
     264   
     265  if ($options['smart_ads_custcomment'] == "bracket"){ 
     266      $custtype = '{smartads}'; 
     267      } 
     268  else{ 
     269      $custtype = '<!-smartads->'; 
     270  } 
    214271  get_currentuserinfo(); 
    215272  global $user_level; 
     
    223280  if (is_page()) { 
    224281         $replace = stripslashes($customad); 
    225          $content = ereg_replace('<!-smartads->', $replace, $content); 
     282         $content = ereg_replace($custtype, $replace, $content); 
    226283        return $content; 
    227284      } 
     
    231288      if ($options['smart_ads_showindexcust'] == 1){ 
    232289         $replace = stripslashes($customad); 
    233          $content = ereg_replace('<!-smartads->', $replace, $content); 
     290         $content = ereg_replace($custtype, $replace, $content); 
    234291        return $content; 
    235292      } 
    236293      else { 
     294          $replace = ""; 
     295         $content = ereg_replace($custtype, $replace, $content); 
    237296        return $content; 
    238297        } 
     
    247306        $lastad = stripslashes($bottomad); 
    248307         
    249         $content = ereg_replace('<!-smartads->', $replace, $content); 
     308        $content = ereg_replace($custtype, $replace, $content); 
     309         
     310        if (smartads_imgexclude($content) == 1) { 
     311          $content = $content . $lastad; 
     312          return $content; 
     313        } 
     314        else { 
    250315        $content = $firstad . $content . $lastad; 
    251        return $content; 
    252         }      
     316        return $content; 
     317        } 
     318    }      
    253319    else { 
    254320         $replace = stripslashes($customad); 
    255          $content = ereg_replace('<!-smartads->', $replace, $content); 
    256         return $content; 
    257       } 
    258     } 
    259      
     321         $content = ereg_replace($custtype, $replace, $content); 
     322        return $content; 
     323      } 
     324    }     
    260325  else{ 
    261326    return $content; 
     
    264329  } 
    265330 } 
    266  return $content;  
    267 
    268    
     331  
     332 return $content; //if it's the RSS, just return the content 
     333
     334 
    269335add_filter('the_content', 'smartads_insert'); 
    270336 
     337$options = get_option('smart_ads_insert'); 
     338 
     339if (($wp_version >= "2.5") && ($options['smart_ads_postbox'] != 1)){ 
     340 
     341add_filter('submitpost_box', 'smartads_write_box'); 
     342 
     343add_action('edit_post', 'add_smartads_custom_field'); 
     344add_action('publish_post', 'add_smartads_custom_field'); 
     345add_action('save_post', 'add_smartads_custom_field'); 
     346} 
     347 
     348elseif (($wp_version < "2.5") && $options['smart_ads_postbox'] != 1){ 
    271349add_action('simple_edit_form', 'smartads_write_box'); 
    272350add_action('edit_form_advanced', 'smartads_write_box'); 
    273 add_action('edit_page_form', 'smartads_write_box'); 
    274351 
    275352add_action('edit_post', 'add_smartads_custom_field'); 
     
    277354add_action('save_post', 'add_smartads_custom_field'); 
    278355add_action('edit_page_form', 'add_smartads_custom_field'); 
    279  
     356
    280357 
    281358?>