├── .gitmodules
├── changelog.txt
├── ad-sharing-files
└── languages
│ └── ad-sharing.pot
├── README.md
└── ad-sharing.php
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "dash-notice"]
2 | path = dash-notice
3 | url = git@bitbucket.org:incsub/wpmudev-dashboard-notification.git
4 | branch = master
5 |
--------------------------------------------------------------------------------
/changelog.txt:
--------------------------------------------------------------------------------
1 | Plugin Name: Ad Sharing, Ulrich Sossou
2 | Author: Andrew Billits
3 |
4 | Change Log:
5 | ----------------------------------------------------------------------
6 | ----------------------------------------------------------------------
7 | 1.2.1 - 19/09/2016
8 | ----------------------------------------------------------------------
9 | - Fix compatibility with PHP 7
10 |
11 | 1.2 - 07/22/2011
12 | ----------------------------------------------------------------------
13 | - Adding compatibility page only if necessary.
14 | - Fix for empty values handling.
15 | - Added informative message when no settings available to show.
16 |
17 | 1.1.9.1 - 05/20/2011
18 | ----------------------------------------------------------------------
19 | - Bug fix: "display_ads" filter returns contents outside the loop
20 |
21 | 1.1.9 - 03/07/2011
22 | ----------------------------------------------------------------------
23 | - Bug fix: maximum number of ads per page option not working
24 | - Bug fix: allow adsense ads with country code when filtering enabled
25 | - Enhancement: allow html when filtering enabled
26 |
27 | 1.1.8 - 02/24/2011
28 | ----------------------------------------------------------------------
29 | - Enhancement: Don't display anything when adsense code entered by user
30 | is not valid
31 | - Enhancement: Always show user ads when admin didn't set any ad
32 |
33 | 1.1.7 - 02/22/2011
34 | ----------------------------------------------------------------------
35 | - Enhancement: Added option to filter ad.
36 |
37 | 1.1.6 - 01/30/2011
38 | ----------------------------------------------------------------------
39 | - Enhancement: Site advertising will be shown 100% of the time if the
40 | user has not setup advertising.
41 |
42 | 1.1.5 - 01/24/2011
43 | ----------------------------------------------------------------------
44 | - New feature: Singlesite support.
45 |
46 | 1.1.4 - 01/22/2011
47 | ----------------------------------------------------------------------
48 | - Bug fix: backward compatibility.
49 |
50 | 1.1.3 - 01/04/2011
51 | ----------------------------------------------------------------------
52 | - 3.1+ compatibility.
53 | - Internationalization.
54 |
55 | 1.1.2 - 08/02/2010
56 | ----------------------------------------------------------------------
57 | - Now shows admin menu when create users permission is not given in
58 | Super Admin -> Options
59 |
60 | 1.1.1 - 06/01/2010
61 | ----------------------------------------------------------------------
62 | - 3.0+ compatibility update
63 |
64 | 1.1.0 - 12/17/2009
65 | ----------------------------------------------------------------------
66 | - Adding Update Notifications Support
67 |
68 | 1.0.9 - 10/08/2009
69 | ----------------------------------------------------------------------
70 | - Added option to disable or enable ads on the main blog
71 |
72 | 1.0.8 - 10/07/2009
73 | ----------------------------------------------------------------------
74 | - Blog ad options now match site settings
75 |
76 | 1.0.7 - 09/21/2009
77 | ----------------------------------------------------------------------
78 | - Lower user levels can no longer see the menu item
79 |
80 | 1.0.6 - 09/02/2009
81 | ----------------------------------------------------------------------
82 | - 2.8 compatibility update
83 |
84 | 1.0.5 - 08/17/2009
85 | ----------------------------------------------------------------------
86 | - 2.8 compatibility update
87 |
88 | 1.0.4 - 08/11/2009
89 | ----------------------------------------------------------------------
90 | - 2.8 compatibility update
91 |
92 | 1.0.3 - 07/24/2009
93 | ----------------------------------------------------------------------
94 | - 2.8 compatibility update
95 |
96 | 1.0.2 - 03/02/2008
97 | ----------------------------------------------------------------------
98 | - Added site admin check
99 | - Fixed ads per page bug
100 |
101 | 1.0.1 - 11/17/2008
102 | ----------------------------------------------------------------------
103 | - Site ads now display 100% of the time when blog ad code doesn't exist
104 |
105 | 1.0.0 - 11/03/2008
106 | ----------------------------------------------------------------------
107 | - Initial Release.
108 |
--------------------------------------------------------------------------------
/ad-sharing-files/languages/ad-sharing.pot:
--------------------------------------------------------------------------------
1 | # Translation of the WordPress plugin Ad Sharing 1.1.3 by Andrew Billits, Ulrich Sossou (Incsub).
2 | # Copyright (C) 2011 Andrew Billits, Ulrich Sossou (Incsub)
3 | # This file is distributed under the same license as the Ad Sharing package.
4 | # FIRST AUTHOR , 2011.
5 | #
6 | #, fuzzy
7 | msgid ""
8 | msgstr ""
9 | "Project-Id-Version: Ad Sharing 1.1.3\n"
10 | "Report-Msgid-Bugs-To: http://wordpress.org/tag/ad-sharing\n"
11 | "POT-Creation-Date: 2011-01-05 12:46+0100\n"
12 | "PO-Revision-Date: 2011-MO-DA HO:MI+ZONE\n"
13 | "Last-Translator: FULL NAME \n"
14 | "Language-Team: LANGUAGE \n"
15 | "Language: \n"
16 | "MIME-Version: 1.0\n"
17 | "Content-Type: text/plain; charset=utf-8\n"
18 | "Content-Transfer-Encoding: 8bit\n"
19 |
20 | #: ad-sharing.php:81 ad-sharing.php:88 ad-sharing.php:89 ad-sharing.php:311
21 | #: ad-sharing.php:430
22 | msgid "Advertising"
23 | msgstr ""
24 |
25 | #: ad-sharing.php:263
26 | msgid "Changes saved."
27 | msgstr ""
28 |
29 | #: ad-sharing.php:288 ad-sharing.php:421
30 | msgid "Nice Try..."
31 | msgstr ""
32 |
33 | #. #-#-#-#-# ad-sharing.pot (Ad Sharing 1.1.3) #-#-#-#-#
34 | #. Plugin Name of the plugin/theme
35 | #: ad-sharing.php:317
36 | msgid "Ad Sharing"
37 | msgstr ""
38 |
39 | #: ad-sharing.php:321
40 | msgid "Site 25% / Blog 75%"
41 | msgstr ""
42 |
43 | #: ad-sharing.php:322
44 | msgid "Site 50% / Blog 50%"
45 | msgstr ""
46 |
47 | #: ad-sharing.php:323
48 | msgid "Site 75% / Blog 25%"
49 | msgstr ""
50 |
51 | #: ad-sharing.php:325
52 | msgid ""
53 | "Note that the ads are split over page loads. For a 50/50 split site ads will "
54 | "be shown every other page, etc."
55 | msgstr ""
56 |
57 | #: ad-sharing.php:326
58 | #, php-format
59 | msgid ""
60 | "Site advertising will be shown 100% of the time on blogs that have not setup "
61 | "advertising."
62 | msgstr ""
63 |
64 | #: ad-sharing.php:331
65 | msgid "Ad Locations"
66 | msgstr ""
67 |
68 | #: ad-sharing.php:335
69 | msgid "Before Post Content"
70 | msgstr ""
71 |
72 | #: ad-sharing.php:340
73 | msgid "After Post Content"
74 | msgstr ""
75 |
76 | #: ad-sharing.php:345
77 | msgid "Before Page Content"
78 | msgstr ""
79 |
80 | #: ad-sharing.php:350
81 | msgid "After Page Content"
82 | msgstr ""
83 |
84 | #: ad-sharing.php:356
85 | msgid "Ads per page"
86 | msgstr ""
87 |
88 | #: ad-sharing.php:366
89 | msgid ""
90 | "Maximum number of ads to be shown on a single page. For Google Adsense set "
91 | "this to \"3\"."
92 | msgstr ""
93 |
94 | #: ad-sharing.php:371 ad-sharing.php:441
95 | msgid "\"Before\" Ad Code"
96 | msgstr ""
97 |
98 | #: ad-sharing.php:374 ad-sharing.php:444
99 | msgid "Used before post and page content."
100 | msgstr ""
101 |
102 | #: ad-sharing.php:379 ad-sharing.php:452
103 | msgid "\"After\" Ad Code"
104 | msgstr ""
105 |
106 | #: ad-sharing.php:382 ad-sharing.php:455
107 | msgid "Used after post and page content."
108 | msgstr ""
109 |
110 | #: ad-sharing.php:386
111 | msgid "Message"
112 | msgstr ""
113 |
114 | #: ad-sharing.php:389
115 | msgid "This message is displayed at the top of the blog advertising page."
116 | msgstr ""
117 |
118 | #: ad-sharing.php:390
119 | msgid "Tip: Use this message to explain the ad sharing."
120 | msgstr ""
121 |
122 | #: ad-sharing.php:394
123 | msgid "Main Blog"
124 | msgstr ""
125 |
126 | #: ad-sharing.php:398
127 | msgid "Hide Ads"
128 | msgstr ""
129 |
130 | #: ad-sharing.php:399
131 | msgid "Show Ads"
132 | msgstr ""
133 |
134 | #: ad-sharing.php:406 ad-sharing.php:464
135 | msgid "Save Changes"
136 | msgstr ""
137 |
138 | #: ad-sharing.php:407 ad-sharing.php:465
139 | msgid "Reset"
140 | msgstr ""
141 |
142 | #: ad-sharing.php:482
143 | msgid ""
144 | "Please install the latest version of our free "
146 | "Update Notifications plugin which helps you stay up-to-date with the "
147 | "most stable, secure versions of WPMU DEV themes and plugins. More information » "
150 | msgstr ""
151 |
152 | #. Plugin URI of the plugin/theme
153 | msgid "http://premium.wpmudev.org/project/ad-sharing"
154 | msgstr ""
155 |
156 | #. Description of the plugin/theme
157 | msgid ""
158 | "Simply split advertising revenues with your users with this easy to use "
159 | "plugin. You can use adsense, context ads or any combination of advertising "
160 | "you like. Time to reap (and share) blogging rewards!"
161 | msgstr ""
162 |
163 | #. Author of the plugin/theme
164 | msgid "Andrew Billits, Ulrich Sossou (Incsub)"
165 | msgstr ""
166 |
167 | #. Author URI of the plugin/theme
168 | msgid "http://premium.wpmudev.org/"
169 | msgstr ""
170 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Ad Sharing
2 |
3 | **INACTIVE NOTICE: This plugin is unsupported by WPMUDEV, we've published it here for those technical types who might want to fork and maintain it for their needs.**
4 |
5 | ## Translations
6 |
7 | Translation files can be found at https://github.com/wpmudev/translations
8 |
9 |
10 | ## Usage
11 |
12 | Ad Sharing allows you to offer advertising revenue to users on your single site or Multisite network.
13 |
14 | One of the best ways to attract new users to your site or network is to offer them a cut of the advertising profits from their blogs. Ad Sharing lets you do just that. Ad Sharing makes it easy to split revenue in a fair way based on the number of impressions on users' blogs. The plugin keeps track of all the numbers for you, splitting revenue based on your selections. Add this as a new feature to monetize your network and encourage your users to start generating more income for you–and for themselves.
15 |
16 | ### Advantages of Ad Sharing
17 |
18 | You've put in the hard work to get your network up and running so why not make some money?
19 |
20 | * Fair, equitable and very attractive way to share ad revenue
21 | * No need to touch the code or alter template files to insert ad codes
22 | * Use any advertising partners you want – AdSense, context ads, etc.
23 | * Sharing revenue motivates your users to promote your site
24 |
25 | ### Ad Sharing is Easy to Use
26 |
27 | You don't need to edit theme files. Simply install and activate the plugin and choose:
28 |
29 | * To display ads before and/or after your content
30 | * Impressions split you would like to make with your users
31 | * Code you would like displayed
32 |
33 | Users can then enter their own advertising code and if they choose not to then you get 100% of the revenue.
34 |
35 | ### To Get Started:
36 |
37 | Login to your admin panel for WordPress or Multisite and activate the plugin:
38 |
39 | * On regular WordPress installs – visit Plugins and Activate the plugin.
40 | * For WordPress Multisite installs – Visit Network Admin -> Plugins and Network Activate the plugin.
41 |
42 | ##### Please note
43 |
44 | * _If you have an older version of the plugin installed in /mu-plugins/ please delete it._
45 |
46 | ### For single-site use:
47 |
48 | In your dashboard, go to _Settings > Advertising_ to configure the plugin settings.
49 |
50 |
51 |
52 | Select your Ad Sharing percentage from the following defaults:
53 |
54 | * Site 25% / User 75%
55 | * Site 50% / User 50%
56 | * Site 75% / User 25%
57 |
58 | Ads will be displayed on the site based on the percentages you specify here. For example, using the "Site 25% / User 75%" setting, your site ads will be displayed 25% of the time, while user's adds will display 75% of the time.
59 |
60 | In this case (single-site use), the User would be users registered on your site with the Author user role. The plugin will display the Author's ads within their own authored content, depending on the values you specify above.
61 |
62 | If your authors don't set up their own ads then the site ads will be displayed with their content and you'll get 100 % of the revenue.
63 |
64 | If you need values other than the defaults listed above, no problem! You can simply ask about that in our support forums, our team will gladly help with that!
65 |
66 | ##### Filter Ads
67 |
68 | This feature will allow you to filter the ad code provided by users, for security purposes.
69 |
70 | ##### Ad Locations
71 |
72 | Here you can select where ad code will be displayed on your site, from the following options:
73 |
74 | * Before Post Content
75 | * After Post Content
76 | * Before Page Content
77 | * After Page Content
78 |
79 |
80 |
81 | ##### Ads per page
82 |
83 | Set the maximum number of ads you want displayed in any given page.
84 |
85 | ##### "Before" and "After" Ad Code
86 |
87 | Here is where you specify your site's ad code, the ads that will be displayed according to the Site value in the Ad Sharing setting above. As you can see, you can easily copy and paste in Google Adsense or any other standard ad code.
88 |
89 | ##### Message
90 |
91 | Enter the message you want to display for users when they go to the Advertising menu in their profile.
92 |
93 | Don't forget to click the '_Save Changes_' button when you're done.
94 |
95 | You can also reset the settings to default at any time by clicking the '_Reset_' button.
96 |
97 | ##### Author Advertising
98 |
99 | With everything configured, users with an Author user role will see a new menu item at _Profile > Advertising_.
100 |
101 | In this page, authors will see the Message you specified in the settings along with "_Before_" and "_After_" Ad Code.
102 |
103 | The code they enter here will be displayed along with their authored content depending on the percentages you specified above.
104 |
105 |
106 | ### For Multisite use:
107 |
108 | In your Network Admin dashboard, go to _Settings > Advertising_ to configure the plugin settings.
109 |
110 |
111 |
112 | You'll see all the same settings as described above for single-site.
113 |
114 | Additionally, you'll see a Main Blog drop-down where you can decide whether or not to show ads on the main blog.
115 |
116 |
117 |
118 | Once you've saved your Advertising settings in Network Admin, your Users will be able to set up their own ads using **Settings > Advertising** area of their blog. They'll see settings similar to the Author Advertising page in single-site as shown above.
119 |
120 | * If they don't set up their own ads you'll get 100% of the revenue.
121 |
--------------------------------------------------------------------------------
/ad-sharing.php:
--------------------------------------------------------------------------------
1 | page_ads;
40 | }
41 |
42 | function increase() {
43 | $this->page_ads = $this->page_ads + 1;
44 | }
45 | }
46 |
47 | $ad_sharing_page_ads = new Ad_Sharing_Page_Ads();
48 |
49 | /**
50 | * Escaping for textarea values.
51 | *
52 | * @since 3.1
53 | *
54 | * Added for compatibility with WordPress 3.0.*
55 | *
56 | * @param string $text
57 | *
58 | * @return string
59 | */
60 | if ( ! function_exists( 'esc_textarea' ) ) {
61 | function esc_textarea( $text ) {
62 | $safe_text = htmlspecialchars( $text, ENT_QUOTES );
63 |
64 | return apply_filters( 'esc_textarea', $safe_text, $text );
65 | }
66 | }
67 |
68 | /**
69 | * Retrieve the currently-queried object. Wrapper for $wp_query->get_queried_object()
70 | *
71 | * @uses WP_Query::get_queried_object
72 | *
73 | * @since 3.1.0
74 | * @access public
75 | *
76 | * Added for compatibility with WordPress 3.0.*
77 | *
78 | * @return object
79 | */
80 | if ( ! function_exists( 'get_queried_object' ) ) {
81 | function get_queried_object() {
82 | global $wp_query;
83 |
84 | return $wp_query->get_queried_object();
85 | }
86 | }
87 |
88 | /**
89 | * Plugin main class
90 | **/
91 | class Ad_Sharing {
92 |
93 | /**
94 | * PHP5 constructor
95 | **/
96 | function __construct() {
97 | if ( is_multisite() ) {
98 | add_action( 'network_admin_menu', array( &$this, 'plug_network_pages' ) );
99 | add_action( 'admin_menu', array( &$this, 'plug_pages' ) );
100 | } else {
101 | add_action( 'admin_menu', array( &$this, 'plug_singlesite_pages' ) );
102 | }
103 |
104 | add_action( 'admin_init', array( &$this, 'process' ) );
105 | add_action( 'wp_footer', array( &$this, 'advertising_quarter' ) );
106 | add_filter( 'the_content', array( &$this, 'display_ads' ), 20, 1 );
107 |
108 | // load text domain
109 | if ( defined( 'WPMU_PLUGIN_DIR' ) && file_exists( WPMU_PLUGIN_DIR . '/ad-sharing.php' ) ) {
110 | load_muplugin_textdomain( 'ad_sharing', 'ad-sharing-files/languages' );
111 | } else {
112 | load_plugin_textdomain( 'ad_sharing', false, dirname( plugin_basename( __FILE__ ) ) . '/ad-sharing-files/languages' );
113 | }
114 | }
115 |
116 | /**
117 | * Add settings page to network admin
118 | **/
119 | function plug_network_pages() {
120 | add_submenu_page( 'settings.php', __( 'Advertising', 'ad_sharing' ), __( 'Advertising', 'ad_sharing' ), 'manage_network_options', 'admin-advertising', array(
121 | &$this,
122 | 'admin_output'
123 | ) );
124 | }
125 |
126 | /**
127 | * Add settings page to site admin
128 | **/
129 | function plug_pages() {
130 | global $wp_version;
131 | if ( version_compare( $wp_version, '3.0.9', '>' ) ) {
132 | add_submenu_page( 'ms-admin.php', __( 'Advertising', 'ad_sharing' ), __( 'Advertising', 'ad_sharing' ), 'manage_network_options', 'admin-advertising', array(
133 | &$this,
134 | 'admin_output'
135 | ) );
136 | }
137 | add_submenu_page( 'options-general.php', __( 'Advertising', 'ad_sharing' ), __( 'Advertising', 'ad_sharing' ), 'manage_options', 'user-advertising', array(
138 | &$this,
139 | 'user_output'
140 | ) );
141 | }
142 |
143 | /**
144 | * Add settings page to site admin
145 | **/
146 | function plug_singlesite_pages() {
147 | add_submenu_page( 'options-general.php', __( 'Advertising', 'ad_sharing' ), __( 'Advertising', 'ad_sharing' ), 'manage_options', 'admin-advertising', array(
148 | &$this,
149 | 'admin_output'
150 | ) );
151 | if ( ! current_user_can( 'edit_others_posts' ) ) {
152 | add_submenu_page( 'profile.php', __( 'Advertising', 'ad_sharing' ), __( 'Advertising', 'ad_sharing' ), 'edit_posts', 'user-advertising', array(
153 | &$this,
154 | 'user_output'
155 | ) );
156 | }
157 | }
158 |
159 | /**
160 | * Change advertising quarter
161 | *
162 | * On each page load the quarter is incremented and the ads will be displayed depending on the current quarter
163 | **/
164 | function advertising_quarter() {
165 | $advertising_quarter = $this->get_option( 'advertising_quarter' );
166 |
167 | if ( in_array( $advertising_quarter, array( 1, 2, 3 ) ) ) {
168 | $advertising_quarter ++;
169 | } else {
170 | $advertising_quarter = '1';
171 | }
172 |
173 | $this->update_option( 'advertising_quarter', $advertising_quarter );
174 | }
175 |
176 | /**
177 | * Get plugin option
178 | *
179 | * If multisite, get_option will be used. If is singlesite, get_user_option will be used instead
180 | **/
181 | function get_option( $option, $default = false, $user_id = 0 ) {
182 | global $authordata;
183 |
184 | if ( is_multisite() ) {
185 | return get_option( $option, $default );
186 | } elseif ( ! empty( $user_id ) ) {
187 | return get_user_option( $option, $user_id );
188 | } elseif ( ! empty( $authordata->ID ) ) {
189 | return get_user_option( $option, $authordata->ID );
190 | } else {
191 | $queried_object = get_queried_object();
192 |
193 | if ( isset( $queried_object->post_author ) ) {
194 | return get_user_option( $option, $queried_object->post_author );
195 | } else {
196 | return $default;
197 | }
198 | }
199 | }
200 |
201 | /**
202 | * Update plugin option
203 | *
204 | * If multisite, update_option will be used. If is singlesite, update_user_option will be used instead
205 | **/
206 | function update_option( $option, $newvalue, $user_id = 0 ) {
207 | global $authordata;
208 |
209 | if ( is_multisite() ) {
210 | return update_option( $option, $newvalue );
211 | } elseif ( ! empty( $user_id ) ) {
212 | return update_user_option( $user_id, $option, $newvalue );
213 | } elseif ( ! empty( $authordata->ID ) ) {
214 | return update_user_option( $authordata->ID, $option, $newvalue );
215 | } else {
216 | $queried_object = get_queried_object();
217 |
218 | if ( isset( $queried_object->post_author ) ) {
219 | return update_user_option( $queried_object->post_author, $option, $newvalue );
220 | } else {
221 | return false;
222 | }
223 | }
224 | }
225 |
226 | /**
227 | * Return ad code depending on the current advertising quarter and the advertising share option
228 | **/
229 | function get_ad_code( $ad_type ) {
230 | $advertising_share = get_site_option( 'advertising_share' );
231 | $advertising_quarter = $this->get_option( 'advertising_quarter' );
232 |
233 | switch ( $advertising_quarter ) {
234 | case '1':
235 | $ad_code_type = 'user';
236 | break;
237 |
238 | case '2':
239 | if ( $advertising_share == '75' ) {
240 | $ad_code_type = 'user';
241 | } else {
242 | $ad_code_type = 'admin';
243 | }
244 | break;
245 |
246 | case '3':
247 | if ( $advertising_share == '25' ) {
248 | $ad_code_type = 'admin';
249 | } else {
250 | $ad_code_type = 'user';
251 | }
252 | break;
253 |
254 | case '4':
255 | default:
256 | $ad_code_type = 'admin';
257 | break;
258 | }
259 |
260 | switch ( $ad_code_type ) {
261 | case 'user':
262 | if ( 'before' == $ad_type ) {
263 | if ( $before_code = $this->get_option( 'advertising_before_code' ) ) {
264 | $ad_code = $before_code;
265 | } else {
266 | $ad_code = get_site_option( 'advertising_before_code' );
267 | }
268 | }
269 |
270 | if ( 'after' == $ad_type ) {
271 | if ( $after_code = $this->get_option( 'advertising_after_code' ) ) {
272 | $ad_code = $after_code;
273 | } else {
274 | $ad_code = get_site_option( 'advertising_after_code' );
275 | }
276 | }
277 | break;
278 |
279 | case 'admin':
280 | default:
281 | if ( 'before' == $ad_type ) {
282 | if ( $before_code = get_site_option( 'advertising_before_code' ) ) {
283 | $ad_code = $before_code;
284 | } else {
285 | $ad_code = $this->get_option( 'advertising_before_code' );
286 | }
287 | }
288 |
289 | if ( 'after' == $ad_type ) {
290 | if ( $after_code = get_site_option( 'advertising_after_code' ) ) {
291 | $ad_code = $after_code;
292 | } else {
293 | $ad_code = $this->get_option( 'advertising_after_code' );
294 | }
295 | }
296 | break;
297 | }
298 |
299 | return ( ! $ad_code ) ? '' : $ad_code;
300 | }
301 |
302 | /**
303 | * Ad ads to post content
304 | **/
305 | function display_ads( $content ) {
306 | global $wpdb, $ad_sharing_page_ads, $post;
307 |
308 | if ( ! in_the_loop() ) {
309 | return $content;
310 | }
311 |
312 | $advertising_ads_per_page = (int) get_site_option( 'advertising_ads_per_page' );
313 |
314 | // if we site admin doesn't want ads to be displayed on main blog?
315 | if ( is_multisite() ) {
316 | $advertising_main_blog = get_site_option( 'advertising_main_blog', 'hide' );
317 | if ( 1 == $wpdb->blogid && 'hide' == $advertising_main_blog ) {
318 | return $content;
319 | }
320 | }
321 |
322 | if ( 'page' == $post->post_type ) {
323 | if ( get_site_option( 'advertising_location_before_page_content' ) == '1' ) {
324 | $page_ads = $ad_sharing_page_ads->get_count();
325 | if ( $page_ads < $advertising_ads_per_page ) {
326 | $content = $this->get_ad_code( 'before' ) . $content;
327 | $ad_sharing_page_ads->increase();
328 | }
329 | }
330 | if ( get_site_option( 'advertising_location_after_page_content' ) == '1' ) {
331 | $page_ads = $ad_sharing_page_ads->get_count();
332 | if ( $page_ads < $advertising_ads_per_page ) {
333 | $content = $content . $this->get_ad_code( 'after' );
334 | $ad_sharing_page_ads->increase();
335 | }
336 | }
337 | } elseif ( 'post' == $post->post_type ) {
338 | if ( get_site_option( 'advertising_location_before_post_content' ) == '1' ) {
339 | $page_ads = $ad_sharing_page_ads->get_count();
340 | if ( $page_ads < $advertising_ads_per_page ) {
341 | $content = $this->get_ad_code( 'before' ) . $content;
342 | $ad_sharing_page_ads->increase();
343 | }
344 | }
345 | if ( get_site_option( 'advertising_location_after_post_content' ) == '1' ) {
346 | $page_ads = $ad_sharing_page_ads->get_count();
347 | if ( $page_ads < $advertising_ads_per_page ) {
348 | $content = $content . $this->get_ad_code( 'after' );
349 | $ad_sharing_page_ads->increase();
350 | }
351 | }
352 | }
353 |
354 | return $content;
355 | }
356 |
357 | /**
358 | * Save plugin settings
359 | **/
360 | function process() {
361 | global $plugin_page, $wp_version;
362 |
363 | $action = isset( $_GET['action'] ) ? $_GET['action'] : '';
364 |
365 | // are we on the plugin network option page and are we saving the settings
366 | if ( 'admin-advertising' == $plugin_page && 'process' == $action ) {
367 | check_admin_referer( 'ad-sharing-process_admin_options' );
368 |
369 | if ( isset( $_POST['Reset'] ) ) {
370 |
371 | update_site_option( 'advertising_share', '50' );
372 | update_site_option( 'advertising_before_code', '' );
373 | update_site_option( 'advertising_after_code', '' );
374 | update_site_option( 'advertising_message', '' );
375 | update_site_option( 'advertising_ads_per_page', '1' );
376 | update_site_option( 'advertising_filter_ads', '1' );
377 | update_site_option( 'advertising_location_before_post_content', '0' );
378 | update_site_option( 'advertising_location_after_post_content', '0' );
379 | update_site_option( 'advertising_location_before_page_content', '0' );
380 | update_site_option( 'advertising_location_after_page_content', '0' );
381 | if ( is_multisite() ) {
382 | update_site_option( 'advertising_main_blog', 'hide' );
383 | }
384 |
385 | } else {
386 |
387 | $advertising_before_code = ! empty( $_POST['advertising_before_code'] ) ? stripslashes( $_POST['advertising_before_code'] ) : '';
388 | $advertising_after_code = ! empty( $_POST['advertising_after_code'] ) ? stripslashes( $_POST['advertising_after_code'] ) : '';
389 | $advertising_message = ! empty( $_POST['advertising_message'] ) ? stripslashes( $_POST['advertising_message'] ) : '';
390 | $advertising_location_before_post_content = ! empty( $_POST['advertising_location_before_post_content'] ) ? stripslashes( $_POST['advertising_location_before_post_content'] ) : '';
391 | $advertising_location_after_post_content = ! empty( $_POST['advertising_location_after_post_content'] ) ? stripslashes( $_POST['advertising_location_after_post_content'] ) : '';
392 | $advertising_location_before_page_content = ! empty( $_POST['advertising_location_before_page_content'] ) ? stripslashes( $_POST['advertising_location_before_page_content'] ) : '';
393 | $advertising_location_after_page_content = ! empty( $_POST['advertising_location_after_page_content'] ) ? stripslashes( $_POST['advertising_location_after_page_content'] ) : '';
394 |
395 | update_site_option( 'advertising_before_code', $advertising_before_code );
396 | update_site_option( 'advertising_after_code', $advertising_after_code );
397 | update_site_option( 'advertising_message', $advertising_message );
398 | update_site_option( 'advertising_share', stripslashes( $_POST['advertising_share'] ) );
399 | update_site_option( 'advertising_ads_per_page', stripslashes( $_POST['advertising_ads_per_page'] ) );
400 | update_site_option( 'advertising_filter_ads', stripslashes( $_POST['advertising_filter_ads'] ) );
401 | update_site_option( 'advertising_location_before_post_content', $advertising_location_before_post_content );
402 | update_site_option( 'advertising_location_after_post_content', $advertising_location_after_post_content );
403 | update_site_option( 'advertising_location_before_page_content', $advertising_location_before_page_content );
404 | update_site_option( 'advertising_location_after_page_content', $advertising_location_after_page_content );
405 | if ( is_multisite() ) {
406 | update_site_option( 'advertising_main_blog', stripslashes( $_POST['advertising_main_blog'] ) );
407 | }
408 | }
409 |
410 | if ( is_multisite() ) {
411 | $settings_page = version_compare( $wp_version, '3.0.9', '>' ) ? 'network/settings.php' : 'ms-admin.php';
412 | } else {
413 | $settings_page = 'options-general.php';
414 | }
415 |
416 | wp_redirect( admin_url( $settings_page . '?page=admin-advertising&updated=true&updatedmsg=' . urlencode( __( 'Changes saved.', 'ad_sharing' ) ) ) );
417 |
418 | // are we on the plugin site option page and are we saving the settings
419 | } elseif ( 'user-advertising' == $plugin_page && 'process' == $action ) {
420 | check_admin_referer( 'ad-sharing-process_user_options' );
421 |
422 | $user_id = get_current_user_id();
423 |
424 | if ( isset( $_POST['Reset'] ) ) {
425 | $this->update_option( 'advertising_before_code', '', $user_id );
426 | $this->update_option( 'advertising_after_code', '', $user_id );
427 | } else {
428 | $this->update_option( 'advertising_before_code', $this->filter_ad( stripslashes( $_POST['advertising_before_code'] ) ), $user_id );
429 | $this->update_option( 'advertising_after_code', $this->filter_ad( stripslashes( $_POST['advertising_after_code'] ) ), $user_id );
430 | }
431 |
432 | if ( is_multisite() ) {
433 | wp_redirect( admin_url( 'options-general.php?page=user-advertising&updated=true' ) );
434 | } else {
435 | wp_redirect( admin_url( 'profile.php?page=user-advertising&updated=true' ) );
436 | }
437 |
438 | }
439 | }
440 |
441 | /**
442 | * Filter ad code for safety
443 | **/
444 | function filter_ad( $code ) {
445 | if ( get_site_option( 'advertising_filter_ads' ) == '1' && ! empty( $code ) ) {
446 | if ( strpos( $code, '
478 | ";
481 | }
482 |
483 | } else {
484 | $code = wp_kses_post( $code );
485 | }
486 | }
487 |
488 | return $code;
489 | }
490 |
491 | /**
492 | * Network option page content
493 | **/
494 | function admin_output() {
495 | $options_permission = is_multisite() ? 'manage_network_options' : 'manage_options';
496 |
497 | if ( ! current_user_can( $options_permission ) ) {
498 | echo '' . __( 'Nice Try...', 'ad_sharing' ) . '
';
499 |
500 | return;
501 | }
502 |
503 | if ( isset( $_GET['updated'] ) ) {
504 | echo '' . urldecode( $_GET['updatedmsg'] ) . '
';
505 | }
506 |
507 | // retrieve options to be displayed
508 | $advertising_before_code = get_site_option( 'advertising_before_code' );
509 | if ( 'empty' == $advertising_before_code ) {
510 | $advertising_before_code = '';
511 | }
512 |
513 | $advertising_after_code = get_site_option( 'advertising_after_code' );
514 | if ( 'empty' == $advertising_after_code ) {
515 | $advertising_after_code = '';
516 | }
517 |
518 | $advertising_message = get_site_option( 'advertising_message' );
519 | if ( $advertising_message == 'empty' ) {
520 | $advertising_message = '';
521 | }
522 | ?>
523 |
524 |
666 |
667 | ' . __( 'Nice Try...' ) . '
';
678 |
679 | return;
680 | }
681 |
682 | $advertising_message = stripslashes( get_site_option( 'advertising_message' ) );
683 | $advertising_message = ( 'empty' !== $advertising_message ) ? $advertising_message : '';
684 |
685 | $show_settings = (
686 | get_site_option( 'advertising_location_before_post_content' ) == '1' ||
687 | get_site_option( 'advertising_location_before_page_content' ) == '1' ||
688 | get_site_option( 'advertising_location_after_post_content' ) == '1' ||
689 | get_site_option( 'advertising_location_after_page_content' ) == '1'
690 | );
691 |
692 | if ( ! $show_settings ) {
693 | _e( 'No settings currently available', 'ad_sharing' );
694 |
695 | return true;
696 | }
697 |
698 | $user_id = get_current_user_id();
699 | ?>
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
739 |
740 |
741 |
742 |
743 |
744 |
745 |
746 | ' . __( 'Please install the latest version of our free Update Notifications plugin which helps you stay up-to-date with the most stable, secure versions of WPMU DEV themes and plugins. More information » ', 'wpmudev' ) . '
';
760 | }
761 | }
762 | }
763 |
--------------------------------------------------------------------------------