<?php
/*
Plugin Name: adf.ly WordPress Plugin
Plugin URI: http://ninjaplugins.com/wordpress/adfly
Description: Monetize your site with <a href="http://adf.ly/?id=8714">adf.ly</a>, this plugin able to convert your links to adf.ly, no need to do it manually.
Version: 0.1
Author: NinjaPlugins
Author URI: http://ninjaplugins.com
License: GPL2
*/
/*
adf.ly WordPress Plugin
Options:
- Enable adf.ly
- Convert outgoing links only/all links to adf.ly
- Ad type: Intestitial or banner
- adf.ly id (http://adf.ly/tools.php?easylink)
*/
add_action('wp_footer', 'np_adfly_get_script');
//get options
function np_adfly_get_options(){
$explode = explode('/',get_option('home'));
$options = array(
'np_adfly_id' => get_option('np_adfly_id'),
'np_adfly_type' => get_option('np_adfly_type'),
'np_adfly_convert' => (get_option('np_adfly_convert') == 'outgoing') ? $explode[2]:''
);
return $options;
}
function np_adfly_get_script(){
if(!get_option('np_adfly_enable')){
return false;
}
//get plugin options
$options = np_adfly_get_options();
//populate script;
$script = "<script>\n";
$script .= "var adfly_id = ".$options['np_adfly_id'].";\n";
$script .= "var adfly_advert = '".$options['np_adfly_type']."';\n";
$script .= "var exclude_domains = ['".$options['np_adfly_convert']."'];\n";
$script .= "</script>\n";
$script .= "<script src=\"http://adf.ly/js/link-converter.js\"></script>\n";
echo $script;
}
//Let's create the options menu
// create custom plugin settings menu
add_action('admin_menu', 'np_adfly_create_menu');
function np_adfly_create_menu() {
//create new top-level menu
add_options_page('adf.ly Plugin Settings', 'adf.ly Settings', 'administrator', __FILE__, 'np_adfly_settings_page',plugins_url('/images/icon.png', __FILE__));
//call register settings function
add_action( 'admin_init', 'np_adfly_register_mysettings' );
}
function np_adfly_register_mysettings() {
//register our settings
register_setting( 'np-adfly-settings-group', 'np_adfly_enable' );
register_setting( 'np-adfly-settings-group', 'np_adfly_id' );
register_setting( 'np-adfly-settings-group', 'np_adfly_convert' );
register_setting( 'np-adfly-settings-group', 'np_adfly_type' );
}
function np_adfly_settings_page() {
?>
<div class="wrap">
<h2>adf.ly WordPress Plugin by NinjaPlugins</h2>
<form method="post" action="options.php">
<?php settings_fields( 'np-adfly-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Enable Plugin</th>
<td><input type="checkbox" <?php if( get_option('np_adfly_enable' ) == 1){ echo 'checked'; }; ?> value="1" name="np_adfly_enable"/></td>
</tr>
<tr valign="top">
<th scope="row">adf.ly id
<td><input type="text" name="np_adfly_id" value="<?php echo get_option('np_adfly_id'); ?>" /> <br/>(to get it, login to adfly, then go to <a href="http://adf.ly/tools.php?easylink">http://adf.ly/tools.php?easylink</a> find http://adf.ly/xxxx/www.google.com). xxxx is your adf.ly id.</th>
</td>
</tr>
<tr valign="top">
<th scope="row">Convert</th>
<td>
<select name="np_adfly_convert">
<option value="outgoing" <?php if(get_option('np_adfly_convert') == 'outgoing') { echo 'selected="selected"';}?>>Outgoing Links Only</options>
<option value="all" <?php if(get_option('np_adfly_convert') == 'all') { echo 'selected="selected"';}?>>All Links</options>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row">Ad Type</th>
<td>
<select name="np_adfly_type">
<option value="int" <?php if(get_option('np_adfly_type') == 'int') { echo 'selected="selected"';}?>>Interstitial Ad</options>
<option value="banner" <?php if(get_option('np_adfly_type') == 'banner') { echo 'selected="selected"';}?>>Banner Ad</options>
</select>
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
<p>
Feedback, bug report, and suggestions are greatly appreciated. Please submit any question to <a href="http://ninjaplugins.com">NinjaPlugins</a>.
</p>
</form>
</div>
<?php } ?>