| 1 |
<?php |
| 2 |
|
| 3 |
// Hook for adding admin menus |
| 4 |
|
| 5 |
add_action("plugins_loaded", "register_ad_widgets"); |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
// Creating the dynamic widget for the widgets page |
| 10 |
|
| 11 |
function register_ad_widgets() { |
| 12 |
|
| 13 |
if(get_option('ad_widget_1_enable')) { register_sidebar_widget(__('Ad Widget : 1'), 'ad_widget_1_create'); } |
| 14 |
|
| 15 |
if(get_option('ad_widget_2_enable')) { register_sidebar_widget(__('Ad Widget : 2'), 'ad_widget_2_create'); } |
| 16 |
|
| 17 |
if(get_option('ad_widget_3_enable')) { register_sidebar_widget(__('Ad Widget : 3'), 'ad_widget_3_create'); } |
| 18 |
|
| 19 |
if(get_option('ad_widget_4_enable')) { register_sidebar_widget(__('Ad Widget : 4'), 'ad_widget_4_create'); } |
| 20 |
|
| 21 |
if(get_option('ad_widget_5_enable')) { register_sidebar_widget(__('Ad Widget : 5'), 'ad_widget_5_create'); } |
| 22 |
|
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
function ad_widget_1_create($args) { |
| 28 |
|
| 29 |
extract($args); |
| 30 |
|
| 31 |
echo $before_widget; |
| 32 |
|
| 33 |
echo get_option('ad_widget_1'); |
| 34 |
|
| 35 |
echo $after_widget; |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
function ad_widget_2_create($args) { |
| 42 |
|
| 43 |
extract($args); |
| 44 |
|
| 45 |
echo $before_widget; |
| 46 |
|
| 47 |
echo get_option('ad_widget_2'); |
| 48 |
|
| 49 |
echo $after_widget; |
| 50 |
|
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
function ad_widget_3_create($args) { |
| 56 |
|
| 57 |
extract($args); |
| 58 |
|
| 59 |
echo $before_widget; |
| 60 |
|
| 61 |
echo get_option('ad_widget_3'); |
| 62 |
|
| 63 |
echo $after_widget; |
| 64 |
|
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
function ad_widget_4_create($args) { |
| 70 |
|
| 71 |
extract($args); |
| 72 |
|
| 73 |
echo $before_widget; |
| 74 |
|
| 75 |
echo get_option('ad_widget_4'); |
| 76 |
|
| 77 |
echo $after_widget; |
| 78 |
|
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
function ad_widget_5_create($args) { |
| 84 |
|
| 85 |
extract($args); |
| 86 |
|
| 87 |
echo $before_widget; |
| 88 |
|
| 89 |
echo get_option('ad_widget_5'); |
| 90 |
|
| 91 |
echo $after_widget; |
| 92 |
|
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
// action function for adding the administrative page |
| 98 |
|
| 99 |
function smart_add_adspage() { ?> |
| 100 |
|
| 101 |
<div class="wrap"> |
| 102 |
|
| 103 |
<h2>WP-INSERT : Manage Ads</h2> |
| 104 |
|
| 105 |
<?php show_support_options(); ?> |
| 106 |
|
| 107 |
<form method="post" action="options.php"> |
| 108 |
|
| 109 |
<?php wp_nonce_field('update-options'); ?> |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
<table class="form-table"> |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
<tr valign="top"> |
| 118 |
|
| 119 |
<th scope="row"><b>In post ads</b></th> |
| 120 |
|
| 121 |
<td>Paste your ads below to make them appear automatically in your posts.</td> |
| 122 |
|
| 123 |
</tr> |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
<tr valign="top"> |
| 128 |
|
| 129 |
<th scope="row">Ad code to insert<br/><b>( Above the post )</b><br/> |
| 130 |
|
| 131 |
<br/><input id="ad_top_enable" name="ad_top_enable" type="checkbox" value="1"<?php if(get_option('ad_top_enable')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 132 |
|
| 133 |
<td><textarea id="ad_top" name="ad_top" style="width:350px;height:150px;"><?php echo get_option('ad_top'); ?></textarea><br/> |
| 134 |
|
| 135 |
<small>( Paste your ad-sense or similar code in the box above )</small></td> |
| 136 |
|
| 137 |
</tr> |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
<tr valign="top"> |
| 142 |
|
| 143 |
<th scope="row">Ad code to insert<br/><b>( Below the post )</b><br/> |
| 144 |
|
| 145 |
<br/><input id="ad_bottom_enable" name="ad_bottom_enable" type="checkbox" value="1"<?php if(get_option('ad_bottom_enable')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 146 |
|
| 147 |
<td><textarea id="ad_bottom" name="ad_bottom" style="width:350px;height:150px;"><?php echo get_option('ad_bottom'); ?></textarea><br/> |
| 148 |
|
| 149 |
<small>( Paste your ad-sense or similar code in the box above )</small></td> |
| 150 |
|
| 151 |
</tr> |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
<tr valign="top"> |
| 156 |
|
| 157 |
<th scope="row">Ad code to insert<br/><b>( Left of the post )</b><br/> |
| 158 |
|
| 159 |
<br/><input id="ad_left_enable" name="ad_left_enable" type="checkbox" value="1"<?php if(get_option('ad_left_enable')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 160 |
|
| 161 |
<td><textarea id="ad_left" name="ad_left" style="width:350px;height:150px;"><?php echo get_option('ad_left'); ?></textarea><br/> |
| 162 |
|
| 163 |
<small>( Paste your ad-sense or similar code in the box above )</small></td> |
| 164 |
|
| 165 |
</tr> |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
<tr valign="top"> |
| 170 |
|
| 171 |
<th scope="row">Ad code to insert<br/><b>( Right of the post )</b><br/> |
| 172 |
|
| 173 |
<br/><input id="ad_right_enable" name="ad_right_enable" type="checkbox" value="1"<?php if(get_option('ad_right_enable')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 174 |
|
| 175 |
<td><textarea id="ad_right" name="ad_right" style="width:350px;height:150px;"><?php echo get_option('ad_right'); ?></textarea><br/> |
| 176 |
|
| 177 |
<small>( Paste your ad-sense or similar code in the box above )</small></td> |
| 178 |
|
| 179 |
</tr> |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
<tr valign="top"> |
| 184 |
|
| 185 |
<th scope="row"></th> |
| 186 |
|
| 187 |
<td><input id="ad_enable_single" name="ad_enable_single" type="checkbox" value="1"<?php if(get_option('ad_enable_single')) echo ' checked="checked"'; ?>/> Show Ads only on single posts and pages<br/></td> |
| 188 |
|
| 189 |
</tr> |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
<tr valign="top"> |
| 194 |
|
| 195 |
<th scope="row"><b>Ad Widgets</b></th> |
| 196 |
|
| 197 |
<td>Paste your ads below and use the widgets section to insert the ads into your sidebar.</td> |
| 198 |
|
| 199 |
</tr> |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
<tr valign="top"> |
| 204 |
|
| 205 |
<th scope="row">Ad code to insert<br/><b>( Ad widget : 1 )</b><br/> |
| 206 |
|
| 207 |
<br/><input id="ad_widget_1_enable" name="ad_widget_1_enable" type="checkbox" value="1"<?php if(get_option('ad_widget_1_enable')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 208 |
|
| 209 |
<td><textarea id="ad_widget_1" name="ad_widget_1" style="width:350px;height:150px;"><?php echo get_option('ad_widget_1'); ?></textarea><br/> |
| 210 |
|
| 211 |
<small>( Paste your ad-sense or similar code in the box above )</small></td> |
| 212 |
|
| 213 |
</tr> |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
<tr valign="top"> |
| 218 |
|
| 219 |
<th scope="row">Ad code to insert<br/><b>( Ad widget : 2 )</b><br/> |
| 220 |
|
| 221 |
<br/><input id="ad_widget_2_enable" name="ad_widget_2_enable" type="checkbox" value="1"<?php if(get_option('ad_widget_2_enable')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 222 |
|
| 223 |
<td><textarea id="ad_widget_2" name="ad_widget_2" style="width:350px;height:150px;"><?php echo get_option('ad_widget_2'); ?></textarea><br/> |
| 224 |
|
| 225 |
<small>( Paste your ad-sense or similar code in the box above )</small></td> |
| 226 |
|
| 227 |
</tr> |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
<tr valign="top"> |
| 232 |
|
| 233 |
<th scope="row">Ad code to insert<br/><b>( Ad widget : 3 )</b><br/> |
| 234 |
|
| 235 |
<br/><input id="ad_widget_3_enable" name="ad_widget_3_enable" type="checkbox" value="1"<?php if(get_option('ad_widget_3_enable')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 236 |
|
| 237 |
<td><textarea id="ad_widget_3" name="ad_widget_3" style="width:350px;height:150px;"><?php echo get_option('ad_widget_3'); ?></textarea><br/> |
| 238 |
|
| 239 |
<small>( Paste your ad-sense or similar code in the box above )</small></td> |
| 240 |
|
| 241 |
</tr> |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
<tr valign="top"> |
| 246 |
|
| 247 |
<th scope="row">Ad code to insert<br/><b>( Ad widget : 4 )</b><br/> |
| 248 |
|
| 249 |
<br/><input id="ad_widget_4_enable" name="ad_widget_4_enable" type="checkbox" value="1"<?php if(get_option('ad_widget_4_enable')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 250 |
|
| 251 |
<td><textarea id="ad_widget_4" name="ad_widget_4" style="width:350px;height:150px;"><?php echo get_option('ad_widget_4'); ?></textarea><br/> |
| 252 |
|
| 253 |
<small>( Paste your ad-sense or similar code in the box above )</small></td> |
| 254 |
|
| 255 |
</tr> |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
<tr valign="top"> |
| 260 |
|
| 261 |
<th scope="row">Ad code to insert<br/><b>( Ad widget : 5 )</b><br/> |
| 262 |
|
| 263 |
<br/><input id="ad_widget_5_enable" name="ad_widget_5_enable" type="checkbox" value="1"<?php if(get_option('ad_widget_5_enable')) echo ' checked="checked"'; ?>/> Enabled</th> |
| 264 |
|
| 265 |
<td><textarea id="ad_widget_5" name="ad_widget_5" style="width:350px;height:150px;"><?php echo get_option('ad_widget_5'); ?></textarea><br/> |
| 266 |
|
| 267 |
<small>( Paste your ad-sense or similar code in the box above )</small></td> |
| 268 |
|
| 269 |
</tr> |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
</table> |
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
<input type="hidden" name="action" value="update" /> |
| 278 |
|
| 279 |
<input type="hidden" name="page_options" value="ad_top,ad_top_enable,ad_bottom,ad_bottom_enable,ad_left,ad_left_enable,ad_right,ad_right_enable,ad_enable_single,ad_widget_5_enable,ad_widget_4_enable,ad_widget_3_enable,ad_widget_2_enable,ad_widget_1_enable,ad_widget_5,ad_widget_4,ad_widget_3,ad_widget_2,ad_widget_1" /> |
| 280 |
|
| 281 |
<p class="submit"> |
| 282 |
|
| 283 |
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" /> |
| 284 |
|
| 285 |
</p> |
| 286 |
|
| 287 |
</form> |
| 288 |
|
| 289 |
</div> |
| 290 |
|
| 291 |
<?php } |
| 292 |
|
| 293 |
//Actual insertion of ads into content takes place here. |
| 294 |
|
| 295 |
add_filter('the_content', 'insert_into_content'); |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
function insert_into_content($content) { |
| 300 |
|
| 301 |
if(!is_singular() && get_option('ad_enable_single')) { return $content; } |
| 302 |
|
| 303 |
else { |
| 304 |
|
| 305 |
$output = '<table><tr>'; |
| 306 |
|
| 307 |
if(get_option('ad_left_enable') && get_option('ad_right_enable')) {$cellspan=' colspan="3"';} else if(get_option('ad_left_enable') || get_option('ad_right_enable')) {$cellspan=' colspan="2"';} else {$cellspan='';} |
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
if(get_option('ad_top_enable')) { |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
$output .= '<td'.$cellspan.' align="center">'.get_option('ad_top').'</td></tr><tr>'; |
| 316 |
|
| 317 |
} |
| 318 |
|
| 319 |
if(get_option('ad_left_enable')) { |
| 320 |
|
| 321 |
$output .= '<td valign="top">'.get_option('ad_left').'</td>'; |
| 322 |
|
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
$output .= '<td>'.$content.'</td>'; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
if(get_option('ad_right_enable')) { |
| 332 |
|
| 333 |
$output .= '<td valign="top">'.get_option('ad_right').'</td>'; |
| 334 |
|
| 335 |
} |
| 336 |
|
| 337 |
if(get_option('ad_bottom_enable')) { |
| 338 |
|
| 339 |
$output .= '</tr><tr><td'.$cellspan.' align="center">'.get_option('ad_bottom').'</td>'; |
| 340 |
|
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
$output .= '</tr></table>'; |
| 346 |
|
| 347 |
return $output; |
| 348 |
|
| 349 |
} |
| 350 |
|
| 351 |
} |
| 352 |
|
| 353 |
?> |