Advertisement
Guest User

Untitled

a guest
Nov 18th, 2010
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.00 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Simple Ads
  4. Plugin URI:
  5. Description:
  6. Author: Andrew Billits (Incsub)
  7. Version: 1.0.1
  8. Author URI:
  9. WDP ID: 108
  10. */
  11.  
  12. /*
  13. Copyright 2007-2009 Incsub (http://incsub.com)
  14.  
  15. This program is free software; you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License (Version 2 - GPLv2) as published by
  17. the Free Software Foundation.
  18.  
  19. This program is distributed in the hope that it will be useful,
  20. but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. GNU General Public License for more details.
  23.  
  24. You should have received a copy of the GNU General Public License
  25. along with this program; if not, write to the Free Software
  26. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. */
  28.  
  29. //------------------------------------------------------------------------//
  30. //---Classes--------------------------------------------------------------//
  31. //------------------------------------------------------------------------//
  32.  
  33. class simple_ads_page_ads {
  34. var $page_ads = 0;
  35.  
  36. function get_count() {
  37. return $this->page_ads;
  38. }
  39.  
  40. function increase() {
  41. $tmp_page_ads = $this->page_ads;
  42. $tmp_page_ads = $tmp_page_ads + 1;
  43. $this->page_ads = $tmp_page_ads;
  44. }
  45. }
  46. $simple_ads_page_ads = new simple_ads_page_ads();
  47. //------------------------------------------------------------------------//
  48. //---Hook-----------------------------------------------------------------//
  49. //------------------------------------------------------------------------//
  50. add_action('admin_menu', 'simple_ads_plug_pages');
  51. add_filter('the_content', 'simple_ads_output', 20, 1);
  52. //------------------------------------------------------------------------//
  53. //---Functions------------------------------------------------------------//
  54. //------------------------------------------------------------------------//
  55.  
  56. function simple_ads_plug_pages() {
  57. global $wpdb, $wp_roles, $current_user;
  58. if ( is_site_admin() ) {
  59. add_submenu_page('ms-admin.php', 'Advertising', 'Advertising', 10, 'advertising', 'simple_ads_site_output');
  60. }
  61. }
  62.  
  63. function simple_ads_get_ad_code($ad_type) {
  64. if ( $ad_type == 'before' ) {
  65. $ad_code = stripslashes( get_site_option('advertising_before_code') );
  66. }
  67. if ( $ad_type == 'after' ) {
  68. $ad_code = stripslashes( get_site_option('advertising_after_code') );
  69. }
  70. if ( $ad_code == 'empty' ) {
  71. $ad_code = '';
  72. }
  73. return $ad_code;
  74. }
  75.  
  76. function simple_ads_output($content) {
  77. global $wpdb, $simple_ads_page_ads;
  78. $advertising_ads_per_page = get_site_option('advertising_ads_per_page');
  79. $advertising_main_blog = get_site_option('advertising_main_blog', 'hide');
  80. $display_ads = 'yes';
  81. if ( $wpdb->blogid == 1 && $advertising_main_blog == 'hide' ) {
  82. $display_ads = 'no';
  83. }
  84. if ( $display_ads == 'yes' ) {
  85. if ( is_page() ) {
  86. if ( get_site_option('advertising_location_before_page_content') == '1' ) {
  87. $page_ads = $simple_ads_page_ads->get_count();
  88. if ( $page_ads < $advertising_ads_per_page ) {
  89. $content = simple_ads_get_ad_code('before') . $content;
  90. $simple_ads_page_ads->increase();
  91. }
  92. }
  93. if ( get_site_option('advertising_location_after_page_content') == '1' ) {
  94. $page_ads = $simple_ads_page_ads->get_count();
  95. if ( $page_ads < $advertising_ads_per_page ) {
  96. $content = $content . simple_ads_get_ad_code('after');
  97. $simple_ads_page_ads->increase();
  98. }
  99. }
  100. } else {
  101. if ( get_site_option('advertising_location_before_post_content') == '1' ) {
  102. $page_ads = $simple_ads_page_ads->get_count();
  103. if ( $page_ads < $advertising_ads_per_page ) {
  104. $content = simple_ads_get_ad_code('before') . $content;
  105. $simple_ads_page_ads->increase();
  106. }
  107. }
  108. if ( get_site_option('advertising_location_after_post_content') == '1' ) {
  109. $page_ads = $simple_ads_page_ads->get_count();
  110. if ( $page_ads < $advertising_ads_per_page ) {
  111. $content = $content . simple_ads_get_ad_code('after');
  112. $simple_ads_page_ads->increase();
  113. }
  114. }
  115. }
  116. }
  117. return $content;
  118. }
  119.  
  120. //------------------------------------------------------------------------//
  121. //---Page Output Functions------------------------------------------------//
  122. //------------------------------------------------------------------------//
  123.  
  124. function simple_ads_site_output() {
  125. global $wpdb, $wp_roles, $current_user;
  126.  
  127. if(!current_user_can('manage_options')) {
  128. echo "<p>" . __('Nice Try...') . "</p>"; //If accessed properly, this message doesn't appear.
  129. return;
  130. }
  131. if (isset($_GET['updated'])) {
  132. ?><div id="message" class="updated fade"><p><?php _e('' . urldecode($_GET['updatedmsg']) . '') ?></p></div><?php
  133. }
  134. echo '<div class="wrap">';
  135. switch( $_GET[ 'action' ] ) {
  136. //---------------------------------------------------//
  137. default:
  138. $advertising_before_code = stripslashes( get_site_option('advertising_before_code') );
  139. if ($advertising_before_code == 'empty') {
  140. $advertising_before_code = '';
  141. }
  142. $advertising_after_code = stripslashes( get_site_option('advertising_after_code') );
  143. if ($advertising_after_code == 'empty') {
  144. $advertising_after_code = '';
  145. }
  146. ?>
  147. <h2><?php _e('Advertising') ?></h2>
  148. <form method="post" action="ms-admin.php?page=advertising&action=process">
  149. <table class="form-table">
  150. <tr valign="top">
  151. <th scope="row"><?php _e('Ad Locations') ?></th>
  152. <td>
  153. <label for="advertising_location_before_post_content">
  154. <input name="advertising_location_before_post_content" id="advertising_location_before_post_content" value="1" type="checkbox" <?php if ( get_site_option('advertising_location_before_post_content') == '1' ) { echo 'checked="checked"'; } ?> >
  155. <?php _e('Before Post Content'); ?></label>
  156. <br />
  157. <label for="advertising_location_after_post_content">
  158. <input name="advertising_location_after_post_content" id="advertising_location_after_post_content" value="1" type="checkbox" <?php if ( get_site_option('advertising_location_after_post_content') == '1' ) { echo 'checked="checked"'; } ?> >
  159. <?php _e('After Post Content'); ?></label>
  160. <br />
  161. <label for="advertising_location_before_page_content">
  162. <input name="advertising_location_before_page_content" id="advertising_location_before_page_content" value="1" type="checkbox" <?php if ( get_site_option('advertising_location_before_page_content') == '1' ) { echo 'checked="checked"'; } ?> >
  163. <?php _e('Before Page Content'); ?></label>
  164. <br />
  165. <label for="advertising_location_after_page_content">
  166. <input name="advertising_location_after_page_content" id="advertising_location_after_page_content" value="1" type="checkbox" <?php if ( get_site_option('advertising_location_after_page_content') == '1' ) { echo 'checked="checked"'; } ?> >
  167. <?php _e('After Page Content'); ?></label>
  168. </td>
  169. </tr>
  170. <tr valign="top">
  171. <th scope="row"><?php _e('Ads per page') ?></th>
  172. <td>
  173. <?php
  174. $advertising_ads_per_page = get_site_option('advertising_ads_per_page', 3);
  175. ?>
  176. <select name="advertising_ads_per_page" id="advertising_ads_per_page" >
  177. <option value="1" <?php if ( $advertising_ads_per_page == '1' ) { echo 'selected="selected"'; } ?> ><?php _e('1'); ?></option>
  178. <option value="2" <?php if ( $advertising_ads_per_page == '2' ) { echo 'selected="selected"'; } ?> ><?php _e('2'); ?></option>
  179. <option value="3" <?php if ( $advertising_ads_per_page == '3' ) { echo 'selected="selected"'; } ?> ><?php _e('3'); ?></option>
  180. <option value="4" <?php if ( $advertising_ads_per_page == '4' ) { echo 'selected="selected"'; } ?> ><?php _e('4'); ?></option>
  181. <option value="5" <?php if ( $advertising_ads_per_page == '5' ) { echo 'selected="selected"'; } ?> ><?php _e('5'); ?></option>
  182. <option value="6" <?php if ( $advertising_ads_per_page == '6' ) { echo 'selected="selected"'; } ?> ><?php _e('6'); ?></option>
  183. <option value="7" <?php if ( $advertising_ads_per_page == '7' ) { echo 'selected="selected"'; } ?> ><?php _e('7'); ?></option>
  184. <option value="8" <?php if ( $advertising_ads_per_page == '8' ) { echo 'selected="selected"'; } ?> ><?php _e('8'); ?></option>
  185. <option value="9" <?php if ( $advertising_ads_per_page == '9' ) { echo 'selected="selected"'; } ?> ><?php _e('9'); ?></option>
  186. <option value="10" <?php if ( $advertising_ads_per_page == '10' ) { echo 'selected="selected"'; } ?> ><?php _e('10'); ?></option>
  187. </select>
  188. <br /><?php _e('Maximum number of ads to be shown on a single page. For Google Adsense set this to "3".') ?></td>
  189. </tr>
  190. <tr valign="top">
  191. <th scope="row"><?php _e('"Before" Ad Code') ?></th>
  192. <td>
  193. <textarea name="advertising_before_code" type="text" rows="5" wrap="soft" id="advertising_before_code" style="width: 95%"/><?php echo $advertising_before_code; ?></textarea>
  194. <br /><?php _e('Used before post and page content.') ?></td>
  195. </tr>
  196. <tr valign="top">
  197. <th scope="row"><?php _e('"After" Ad Code') ?></th>
  198. <td>
  199. <textarea name="advertising_after_code" type="text" rows="5" wrap="soft" id="advertising_after_code" style="width: 95%"/><?php echo $advertising_after_code; ?></textarea>
  200. <br /><?php _e('Used after post and page content.') ?></td>
  201. </tr>
  202. <tr valign="top">
  203. <th scope="row"><?php _e('Main Blog') ?></th>
  204. <td>
  205. <?php
  206. $advertising_main_blog = get_site_option('advertising_main_blog', 'hide');
  207. ?>
  208. <select name="advertising_main_blog" id="advertising_main_blog" >
  209. <option value="hide" <?php if ( $advertising_main_blog == 'hide' ) { echo 'selected="selected"'; } ?> ><?php _e('Hide Ads'); ?></option>
  210. <option value="show" <?php if ( $advertising_main_blog == 'show' ) { echo 'selected="selected"'; } ?> ><?php _e('Show Ads'); ?></option>
  211. </select>
  212. <br /><?php //_e('') ?></td>
  213. </tr>
  214. </table>
  215.  
  216. <p class="submit">
  217. <input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
  218. <input type="submit" name="Reset" value="<?php _e('Reset') ?>" />
  219. </p>
  220. </form>
  221. <?php
  222. break;
  223. //---------------------------------------------------//
  224. case "process":
  225. if ( isset( $_POST[ 'Reset' ] ) ) {
  226. update_site_option( "advertising_before_code", "empty" );
  227. update_site_option( "advertising_after_code", "empty" );
  228. update_site_option( "advertising_ads_per_page", "1" );
  229. update_site_option( "advertising_location_before_post_content", "0" );
  230. update_site_option( "advertising_location_after_post_content", "0" );
  231. update_site_option( "advertising_location_before_page_content", "0" );
  232. update_site_option( "advertising_location_after_page_content", "0" );
  233. update_site_option( "advertising_main_blog", "hide" );
  234. echo "
  235. <SCRIPT LANGUAGE='JavaScript'>
  236. window.location='ms-admin.php?page=advertising&updated=true&updatedmsg=" . urlencode(__('Changes saved.')) . "';
  237. </script>
  238. ";
  239. } else {
  240. if ( empty($_POST[ 'advertising_before_code' ]) ) {
  241. $advertising_before_code = 'empty';
  242. } else {
  243. $advertising_before_code = $_POST[ 'advertising_before_code' ];
  244. }
  245. if ( empty($_POST[ 'advertising_after_code' ]) ) {
  246. $advertising_after_code = 'empty';
  247. } else {
  248. $advertising_after_code = $_POST[ 'advertising_after_code' ];
  249. }
  250.  
  251. if ( empty($_POST[ 'advertising_location_before_post_content' ]) ) {
  252. $advertising_location_before_post_content = 'empty';
  253. } else {
  254. $advertising_location_before_post_content = $_POST[ 'advertising_location_before_post_content' ];
  255. }
  256. if ( empty($_POST[ 'advertising_location_after_post_content' ]) ) {
  257. $advertising_location_after_post_content = 'empty';
  258. } else {
  259. $advertising_location_after_post_content = $_POST[ 'advertising_location_after_post_content' ];
  260. }
  261. if ( empty($_POST[ 'advertising_location_before_page_content' ]) ) {
  262. $advertising_location_before_page_content = 'empty';
  263. } else {
  264. $advertising_location_before_page_content = $_POST[ 'advertising_location_before_page_content' ];
  265. }
  266. if ( empty($_POST[ 'advertising_location_after_page_content' ]) ) {
  267. $advertising_location_after_page_content = 'empty';
  268. } else {
  269. $advertising_location_after_page_content = $_POST[ 'advertising_location_after_page_content' ];
  270. }
  271.  
  272. update_site_option( "advertising_before_code", $advertising_before_code );
  273. update_site_option( "advertising_after_code", $advertising_after_code );
  274. update_site_option( "advertising_ads_per_page", $_POST[ 'advertising_ads_per_page' ] );
  275. update_site_option( "advertising_location_before_post_content", $advertising_location_before_post_content );
  276. update_site_option( "advertising_location_after_post_content", $advertising_location_after_post_content );
  277. update_site_option( "advertising_location_before_page_content", $advertising_location_before_page_content );
  278. update_site_option( "advertising_location_after_page_content", $advertising_location_after_page_content );
  279. update_site_option( "advertising_main_blog", $_POST[ 'advertising_main_blog' ] );
  280. echo "
  281. <SCRIPT LANGUAGE='JavaScript'>
  282. window.location='ms-admin.php?page=advertising&updated=true&updatedmsg=" . urlencode(__('Changes saved.')) . "';
  283. </script>
  284. ";
  285. }
  286. break;
  287. //---------------------------------------------------//
  288. case "temp":
  289. break;
  290. //---------------------------------------------------//
  291. }
  292. echo '</div>';
  293. }
  294.  
  295. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement