Thread: [MyBB] AdSense Plugin

Results 1 to 10 of 10
  1. #1 [MyBB] AdSense Plugin 
    Super Donator


    Join Date
    Jun 2007
    Age
    31
    Posts
    2,158
    Thanks given
    316
    Thanks received
    282
    Rep Power
    779
    Well sadly MyBB 1.6 doesn't have any decent ad plugins (that I could find), so I decided to write my own. It is no where near complete, but it will display it just below the header on every page except the AdminCP. I'll work on allowing different types of ads, like right after the first post of a thread, or inside the first post of a thread, etc.

    Code:
    <?php
    /**
     * Ads 1.0
     * Copyright © 2010 Justin Conner ([email protected])
     * Feel free to contact me with any questions, comments, or concerns.
     */
     
    if(!defined("IN_MYBB")) {
    	die("You cannot access this file directly, try visiting the main site.");
    }
    
    $plugins->add_hook("pre_output_page", "display");
    
    function display($page) {
    	global $mybb;
    	
    	if($mybb->settings['enabled_ads'] == 1) {
    		$page = str_replace("<div id=\"content\">", "<div id=\"content\">".$mybb->settings['ad_code']." ", $page);
    	}
    	
    	return $page;
    }
    
    function ads_info() {
    	return array(
    		"name" => "ads",
    		"description" => "Displays ads, like Google AdSense, on your forums",
    		"website" => "",
    		"author" => "Justin Conner",
    		"authorsite" => "",
    		"version" => "1.0",
    		"guid" => "",
    		"combatibility" => "*"
    	);
    }
    
    function ads_activate() {
    	global $db;
    	
    	$ads_group = array(
    		'gid' => 'NULL',
    		'name' => 'ads',
    		'title' => 'Ads',
    		'description' => 'Settings for the Ads plugin',
    		'disporder' => '1',
    		'isdefault' => 'no'
    	);
    	$db->insert_query('settinggroups', $ads_group);
    	$gid = $db->insert_id();
    	
    	$ads_enable_setting = array(
    		'sid' => 'NULL',
    		'name' => 'enabled_ads',
    		'title' => 'Enable Ads Plugin',
    		'description' => 'If yes, your ads will be displayed on your site',
    		'optionscode' => 'yesno',
    		'value' => '1',
    		'disporder' => 1,
    		'gid' => intval($gid)
    	);
    	$db->insert_query('settings', $ads_enable_setting);
    	
    	$ads_adcode_setting = array(
    		'sid' => 'NULL',
    		'name' => 'ad_code',
    		'title' => 'Ad Code',
    		'description' => 'Code to display your add',
    		'optionscode' => 'textarea',
    		'value' => '',
    		'disporder' => 2,
    		'gid' => intval($gid)
    	);
    	$db->insert_query('settings', $ads_adcode_setting);
    	rebuild_settings();
    }
    
    function ads_deactivate() {
    	global $db;
    	
    	$db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('enabled_ads')");
    	$db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='ads'");
    	rebuild_settings();
    }
    ?>
    AdminCP Settings:


    Proof it works:
    Reply With Quote  
     

  2. #2  
    Banned
    Join Date
    May 2010
    Posts
    361
    Thanks given
    15
    Thanks received
    4
    Rep Power
    0
    Thats Spectacular You should see about becoming a mybb developer
    Reply With Quote  
     

  3. #3  
    Super Donator


    Join Date
    Jun 2007
    Age
    31
    Posts
    2,158
    Thanks given
    316
    Thanks received
    282
    Rep Power
    779
    Quote Originally Posted by carter View Post
    Thats Spectacular You should see about becoming a mybb developer
    I would if I had any motivation... I just did this so I could hope to get some revenue from sponsoring a friend's site
    Reply With Quote  
     

  4. #4  
    Registered Member
    Linux's Avatar
    Join Date
    Feb 2008
    Age
    28
    Posts
    597
    Thanks given
    104
    Thanks received
    103
    Rep Power
    1451
    Nice script!
    Reply With Quote  
     

  5. #5  
    Super Donator
    Chill's Avatar
    Join Date
    Feb 2010
    Age
    30
    Posts
    137
    Thanks given
    12
    Thanks received
    19
    Rep Power
    0
    Actually there is one for 1.4: MyBB - Mods - Adsense Ads. on Forumdisplay

    Only got to search: 14*

    Change to: 16*

    Then it works for 1.6 just fine. But I guess this is alright you could simple edit the header in the template so this isn't really a hard mod to make anyone could of made it by now. But good job I guess.

    I personally already upgraded like about 19 1.4 mods to 1.6 and they work just fine.
    Reply With Quote  
     

  6. #6  
    Registered Member
    Anthony`'s Avatar
    Join Date
    Sep 2008
    Age
    28
    Posts
    763
    Thanks given
    75
    Thanks received
    164
    Rep Power
    204
    Make sure you stay away from using the <center> tag in your plugins or modifications and such. Its a part of the guidelines when im writting SMF mods, its because since the <center> tag is deprecated, forum owners who want to keep their site W3C valid (and should) would probably be discouraged to find invalid markup in their website.

    Anyways, nice plugin, at one time I was thinking of writting my own MyBB plugins too.
    Reply With Quote  
     

  7. #7  
    Super Donator


    Join Date
    Jun 2007
    Age
    31
    Posts
    2,158
    Thanks given
    316
    Thanks received
    282
    Rep Power
    779
    Quote Originally Posted by Mr. S View Post
    Actually there is one for 1.4: MyBB - Mods - Adsense Ads. on Forumdisplay

    Only got to search: 14*

    Change to: 16*

    Then it works for 1.6 just fine. But I guess this is alright you could simple edit the header in the template so this isn't really a hard mod to make anyone could of made it by now. But good job I guess.

    I personally already upgraded like about 19 1.4 mods to 1.6 and they work just fine.
    I know how to convert a plugin, but I didn't feel like searching for a 1.4 plugin, and i know it's extremely easy to convert.

    Quote Originally Posted by Project Evolution View Post
    Make sure you stay away from using the <center> tag in your plugins or modifications and such. Its a part of the guidelines when im writting SMF mods, its because since the <center> tag is deprecated, forum owners who want to keep their site W3C valid (and should) would probably be discouraged to find invalid markup in their website.

    Anyways, nice plugin, at one time I was thinking of writting my own MyBB plugins too.
    Okay I'll remove the center tags then.
    Reply With Quote  
     

  8. #8  
    Registered Member
    Anthony`'s Avatar
    Join Date
    Sep 2008
    Age
    28
    Posts
    763
    Thanks given
    75
    Thanks received
    164
    Rep Power
    204
    Yea, instead just use CSS to center it.
    The text-align: center; attribute should do the trick.
    Reply With Quote  
     

  9. #9  
    Xenon
    Guest
    I'm almost positive myBB has a header template which you can edit can just insert your adsense code.
    Reply With Quote  
     

  10. #10  
    Super Donator


    Join Date
    Jun 2007
    Age
    31
    Posts
    2,158
    Thanks given
    316
    Thanks received
    282
    Rep Power
    779
    Quote Originally Posted by Banned View Post
    I'm almost positive myBB has a header template which you can edit can just insert your adsense code.
    Not that I could find, and either way, this is much better because I can allow other options through the settings page, and do all kinds of stuff without just slapping some AdSense code in a header
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •