Changeset 374316
- Timestamp:
- 04/18/2011 03:03:37 PM (15 years ago)
- Location:
- buysellads/trunk
- Files:
-
- 4 edited
-
buysellads.php (modified) (1 diff)
-
helpers/bsa.functions.php (modified) (6 diffs)
-
language/en_US/admin_lang.php (modified) (1 diff)
-
libraries/bsa.plugin.class.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
buysellads/trunk/buysellads.php
r323948 r374316 73 73 add_action( 'admin_menu', array( $bsa_plugin, 'bsa_admin' ) ); 74 74 add_action( ( (get_option( 'bsa_body_open' ) == 1) ? 'wp_body_open' : 'wp_footer' ), 'embed_bsa_async_js' ); 75 add_filter('the_content_feed', 'bsa_rss_ads'); 76 add_filter('the_excerpt_rss', 'bsa_rss_ads'); -
buysellads/trunk/helpers/bsa.functions.php
r323948 r374316 43 43 // If file_get_contents fails 44 44 // This can happen if allow_url_fopen is disabled 45 $data = ($data !== false ? $data : curl_get_contents($address)); 46 return $data; 45 return ($data !== false ? $data : curl_get_contents($address));; 47 46 } 48 47 } … … 159 158 { 160 159 // Decode & return json data 161 return json_decode( substr( $json_contents, 21, -2), true);160 return json_decode(cleanBSAJsonString($json_contents), true); 162 161 } 163 162 } … … 182 181 183 182 // If @file_get_contents($json_url) returns true 184 return $json_contents && isset($json['networks']) ? $json['networks'] : array(array("title"=>"BuySellAds.com","cdn"=>"s3.buysellads.com" ));183 return $json_contents && isset($json['networks']) ? $json['networks'] : array(array("title"=>"BuySellAds.com","cdn"=>"s3.buysellads.com", "rss" => "rss.buysellads.com")); 185 184 } 186 185 } … … 190 189 * 191 190 * @since 2.0 192 * @uses get_privatelabel_json() 193 * 191 * @param $json The json configuration to parse 194 192 * @return Array 195 193 */ 196 194 if (!function_exists('buysellads_cdns')) 197 195 { 198 function buysellads_cdns() 199 { 200 $json = get_privatelabel_json(); 196 function buysellads_cdns($json) 197 { 201 198 return array_map('buysellads_cdns_helper', $json); 202 199 } … … 204 201 205 202 /** 203 * Returns an array of RSS urls for the private labels 204 * 205 * @since 2.0 206 * @param $json The json configuration to parse 207 * @return Array 208 */ 209 if (!function_exists('buysellads_rss_urls')) 210 { 211 function buysellads_rss_urls($json) 212 { 213 return array_map('buysellads_rss_helper', $json); 214 } 215 } 216 217 /** 206 218 * Helper function to filter the CDNs 207 219 * … … 217 229 } 218 230 } 231 232 /** 233 * Helper function to filter the RSS urls 234 * 235 * @since 2.0 236 * 237 * @return String 238 */ 239 if (!function_exists('buysellads_rss_helper')) 240 { 241 function buysellads_rss_helper($network) 242 { 243 return $network['rss']; 244 } 245 } 246 247 /** 248 * Get the network for the specified CDN 249 * 250 * @since 2.0 251 * @param $networks An array of networks to search 252 * @param $cdn The cdn to search for 253 * @param Associative array 254 */ 255 if (!function_exists('buysellads_network_for_cdn')) 256 { 257 function buysellads_network_for_cdn($networks, $cdn) 258 { 259 foreach ($networks as $network) 260 { 261 if (stripos($network['cdn'], $cdn) !== false) 262 return $network; 263 } 264 265 return array(); 266 } 267 } 268 269 /** 270 * Returns a string without the bsa prefix. 271 * @since 2.0 272 * @uses strpos 273 * @uses strlen 274 * @uses substr 275 * @param $json A JSON string to clean 276 * @return String. 277 */ 278 if (!function_exists('cleanBSAJsonString')) 279 { 280 function cleanBSAJsonString($json = '') 281 { 282 $prefix = '_bsap.interpret_json('; 283 if (strpos($json, $prefix) === false) 284 return $json; 285 286 $l = strlen($prefix); 287 return substr($json, $l, strlen($json)-$l-2); 288 } 289 } 290 291 /** 292 * Adds the BSA ads to the top or bottom of each item in the RSS feed 293 * @since 2.0 294 * @param $content The content of the feed 295 * @return The content string 296 */ 297 if (!function_exists('bsa_rss_ads')) 298 { 299 function bsa_rss_ads($content) 300 { 301 $article = get_the_ID(); 302 if (get_option('bsa_rss_zone_top') == 1) 303 $content = bsa_rss_ad_on_top($article).$content; 304 if (get_option('bsa_rss_zone_bottom') == 1) 305 $content .= bsa_rss_ad_on_bottom($article); 306 307 return $content; 308 } 309 } 310 311 /** 312 * Returns an ad suitable for placement at the top of an RSS feed item 313 * @since 2.0 314 * @param $article The article for the ad 315 * @return String 316 */ 317 if (!function_exists('bsa_rss_ad_on_top')) 318 { 319 function bsa_rss_ad_on_top($article) 320 { 321 $zone = get_option('bsa_rss_zone_top_id'); 322 $site = get_option('bsa_site_key'); 323 return (empty($zone) || empty($site)) ? '' : bsa_rss_ad($zone, $site, $article).'<br />'; 324 } 325 } 326 327 /** 328 * Returns an ad suitable for placement at the bottom of an RSS feed item 329 * @since 2.0 330 * @param $article The article for the ad 331 * @return String 332 */ 333 if (!function_exists('bsa_rss_ad_on_bottom')) 334 { 335 function bsa_rss_ad_on_bottom($article) 336 { 337 $zone = get_option('bsa_rss_zone_bottom_id'); 338 $site = get_option('bsa_site_key'); 339 return (empty($zone) || empty($site)) ? '' : '<br />'.bsa_rss_ad($zone, $site, $article); 340 } 341 } 342 343 /** 344 * Returns an ad suitable for placement in a RSS feed 345 * @since 2.0 346 * @param $zone The zone for the ad 347 * @param $site The sitekey for the ad 348 * @param $article The unique article id 349 * @return String. 350 */ 351 if (!function_exists('bsa_rss_ad')) 352 { 353 function bsa_rss_ad($zone, $site, $article) 354 { 355 $random = rand(); 356 $rss = get_option( 'buysellads_rss', 'rss.buysellads.com'); 357 $network = 'BSA'; 358 $home = 'buysellads.com'; 359 return "<a href='http://${rss}/click.php?z=${zone}&k=${site}&a=${article}&c=${random}' target='_blank'><img src='http://${rss}/img.php?z=${zone}&k=${site}&a=${article}&c=${random}' border='0' alt='' /></a><p><a href='http://${home}/buy/detail/${site}/zone/${zone}' target='_blank'>Ads by ${network}</a></p>"; 360 } 361 } 362 363 ?> -
buysellads/trunk/language/en_US/admin_lang.php
r318292 r374316 21 21 $lang['submit_settings'] = 'Save Settings'; 22 22 $lang['network'] = 'Network'; 23 24 $lang['bsa_rss_zone_top_desc'] = 'Enable Ads in the header of each RSS feed item'; 25 $lang['bsa_rss_zone_top_id_desc'] = 'Enter the zone id for the ad zone that corresponds to the header of the RSS feed'; 26 $lang['bsa_rss_zone_bottom_desc'] = 'Enable Ads in the footer of each RSS feed item'; 27 $lang['bsa_rss_zone_bottom_id_desc'] = 'Enter the zone id for the ad zone that corresponds to the footer of the RSS feed'; -
buysellads/trunk/libraries/bsa.plugin.class.php
r319732 r374316 94 94 update_option( 'bsa_site_key', $bsa_site_key ); 95 95 update_option( 'bsa_body_open', $bsa_body_open ); 96 97 // The json configuration file 98 $private_label_json = get_privatelabel_json(); 96 99 97 100 // new cdn 98 101 $buysellads_cdn = $_POST['buysellads_cdn']; 99 $cdns = buysellads_cdns(); 102 $network = buysellads_network_for_cdn($private_label_json, $buysellads_cdn); 103 $cdns = buysellads_cdns($private_label_json); 100 104 101 105 // Make sure the CDN is valid before saving it. 102 106 update_option( 'buysellads_cdn' , (in_array($buysellads_cdn, $cdns) ? $buysellads_cdn : 's3.buysellads.com')); 107 108 // RSS options 109 $rss = buysellads_rss_urls($private_label_json); 110 update_option('buysellads_rss', (isset($network['rss']) && in_array($network['rss'], $rss) ? $network['rss'] : 'rss.buysellads.com')); 111 112 $bsa_rss_zone_top_id = $_POST['bsa_rss_zone_top_id']; 113 $bsa_rss_zone_top = $_POST['bsa_rss_zone_top']; 114 115 update_option('bsa_rss_zone_top_id', $bsa_rss_zone_top_id); 116 update_option('bsa_rss_zone_top', $bsa_rss_zone_top); 117 118 $bsa_rss_zone_bottom_id = $_POST['bsa_rss_zone_bottom_id']; 119 $bsa_rss_zone_bottom = $_POST['bsa_rss_zone_bottom']; 120 121 update_option('bsa_rss_zone_bottom_id', $bsa_rss_zone_bottom_id); 122 update_option('bsa_rss_zone_bottom', $bsa_rss_zone_bottom); 123 103 124 104 125 $json_data = get_buysellads_json(); … … 136 157 <td> 137 158 <select id="bsa_network" name="buysellads_cdn"> 138 <?php foreach(get_privatelabel_json() as $network): ?> 159 <?php $networks = get_privatelabel_json(); ?> 160 <?php foreach($networks as $network): ?> 139 161 <option <?php echo(stripos($network['cdn'], get_option('buysellads_cdn', 's3.buysellads.com')) === false ? '' : 'selected'); ?> value=<?php echo("\"{$network['cdn']}\""); ?> ><?php echo (htmlspecialchars($network['title'])); ?></option> 140 162 <?php endforeach; ?> … … 142 164 </td> 143 165 </tr> 166 <tr valign="top"> 167 <th scope="row"><label for="bsa_rss_zone_top"><?php echo $bsa_lang->line('rss_zone'); ?></label></th> 168 <td> 169 <input type="checkbox" value="1" id="bsa_rss_zone_top" name="bsa_rss_zone_top"<?php echo (get_option('bsa_rss_zone_top') == 1) ? ' checked="checked"': ''; ?>> Insert Ads in header of Feed 170 <p><span class="description"><?php echo $bsa_lang->line('bsa_rss_zone_top_desc'); ?></span></p> 171 </td> 172 </tr> 173 <tr valign="top"> 174 <th scope="row"> 175 <label for="bsa_rss_zone_top_id"><?php echo $bsa_lang->line('bsa_rss_zone_top_id'); ?></label> 176 </th> 177 <td> 178 <input type="text" class="regular-text" value="<?php echo get_option('bsa_rss_zone_top_id'); ?>" id="bsa_rss_zone_top_id" name="bsa_rss_zone_top_id"> 179 <span class="description"><?php echo $bsa_lang->line('bsa_rss_zone_top_id_desc'); ?></span> 180 </td> 181 </td> 182 </tr> 183 <tr valign="top"> 184 <th scope="row"><label for="bsa_rss_zone_bottom"></label></th> 185 <td> 186 <input type="checkbox" value="1" id="bsa_rss_zone_bottom" name="bsa_rss_zone_bottom"<?php echo (get_option('bsa_rss_zone_bottom') == 1) ? ' checked="checked"': ''; ?>> Insert Ads in footer of Feed 187 <p><span class="description"><?php echo $bsa_lang->line('bsa_rss_zone_bottom_desc'); ?></span></p> 188 </td> 189 </tr> 190 <tr valign="top"> 191 <th scope="row"> 192 <label for="bsa_rss_zone_bottom_id"><?php echo $bsa_lang->line('bsa_rss_zone_bottom_id'); ?></label> 193 </th> 194 <td> 195 <input type="text" class="regular-text" value="<?php echo get_option('bsa_rss_zone_bottom_id'); ?>" id="bsa_rss_zone_bottom_id" name="bsa_rss_zone_bottom_id"> 196 <span class="description"><?php echo $bsa_lang->line('bsa_rss_zone_bottom_id_desc'); ?></span> 197 </td> 198 </td> 199 </tr> 144 200 <tr valign="top"> 145 201 <th scope="row"><?php echo $bsa_lang->line('bsa_body_open'); ?></th>
Note: See TracChangeset
for help on using the changeset viewer.