1 (edited by Programming-Designs 2009-02-11 20:01)

Topic: [Solution] Ads between posts

This requires some modification of viewtopic.php but is pretty straight-forward. For a demonstration you can see it here: http://forums.programming-designs.com/t … t-timeval/

I recommend before continuing to keep a copy of viewtopic.php in case you make a mistake or want to revert back.

If you want an ad after the first post and last post of each topic do the following:

Step 1. Find line 304:

    ++$forum_page['item_count'];

After add:

    if($forum_page['item_count'] == 2){
        loadAdModule();
    }

Step 2. Then find ~line 552:

<?php endif; ?>        </div>
<?php

}

After add:

loadAdModule();

Step 3. Now at the top of the viewtopic.php (before everything else) add:

<?php
function loadAdModule()
{
    echo '<!--- Start here -->
<div class="admodule">           
    <!--- Ad code goes here -->

   <!--- End Ad code -->
</div>

<!--- End Here -->';
}
?>

Step 4. In between the ad code comments is where you place your adsense/yahoo publisher network code. Just save viewtopic.php and re-upload. Make sure your ad code does not have any backslashes (\) or single quotes ('). If you have backslashes add an additional slash (eg. \\). If you have single quotes use double quotes instead (eg. "). Otherwise you will probably get some syntax errors.

Step 5. In your default/current theme's css file you will need to add the following (you can customize it how you want):

div.admodule{
    margin: 5px 10px;
    text-align: center;
    padding: auto;
    border: 1px solid #eee;    
    background-color: #fafafa;
}

All done!

Alternative: Now if you want ads between EVERY post just replace step 1's code with this:

    if(($forum_page['item_count'] % 2) == 1){
        loadAdModule();
    }

And then make sure to skip step 2 (as that adds it after the last post which is unnecessary).

Re: [Solution] Ads between posts

thanks, very nice theme in your forum.

Re: [Solution] Ads between posts

1- can you make it look like a post. just change the user details at the left to the admin one, and post the ads as a post.
2- can you make extension out of it.

thanks

MyFootballCafe.com  is Now Online!

4 (edited by Programming-Designs 2009-02-12 19:37)

Re: [Solution] Ads between posts

SuperMAG wrote:

1- can you make it look like a post. just change the user details at the left to the admin one, and post the ads as a post.
2- can you make extension out of it.

thanks

1. I had actually started doing this mod by using the same style as a post but it didn't look right on my forums so I just made my own div instead (it was also easier).

2. Looking through the code I'm sure I could make an extension out of it (hooks in the right place). I haven't written an extension yet so I'd need to first setup a test environment for myself if I do plan on writing one and would probably take a day or so. Give me a few days and I'll consider it.

Re: [Solution] Ads between posts

Programming-Designs wrote:
SuperMAG wrote:

1- can you make it look like a post. just change the user details at the left to the admin one, and post the ads as a post.
2- can you make extension out of it.

thanks

1. I had actually started doing this mod by using the same style as a post but it didn't look right on my forums so I just made my own div instead (it was also easier).

2. Looking through the code I'm sure I could make an extension out of it (hooks in the right place). I haven't written an extension yet so I'd need to first setup a test environment for myself if I do plan on writing one and would probably take a day or so. Give me a few days and I'll consider it.


Just curious is this against adsense tos?  I thought were was suppose to be no more than 3 ads per page?

Thanks,

Gibs

Re: [Solution] Ads between posts

yea i know, thats why i said to post ads after XX number of posts, like if you have 15 posts you can make it after 5 posts.

MyFootballCafe.com  is Now Online!

Re: [Solution] Ads between posts

SuperMAG wrote:

yea i know, thats why i said to post ads after XX number of posts, like if you have 15 posts you can make it after 5 posts.

Yeah that would be easy. Instead of doing

    if(($forum_page['item_count'] % 2) == 1){
        loadAdModule();
    }

Just replace the 2 with whatever you want.

8 (edited by SuperMAG 2009-03-01 18:16)

Re: [Solution] Ads between posts

well thanks but could you please make it look like a post. check this code:

<?php
/***********************************************************************/

// Some info about your mod.
$mod_title      = 'Adsense after First Post';
$mod_version    = '1.1.1';
$release_date   = '2006-07-29';
$author         = 'Neal Poole';
$author_email   = 'smartys@gmail.com';

// Versions of PunBB this mod was created for. Minor variations (i.e. 1.2.4 vs 1.2.5) will be allowed, but a warning will be displayed.
$punbb_versions    = array('1.2.5', '1.2.6', '1.2.7', '1.2.8', '1.2.9', '1.2.10', '1.2.11', '1.2.12');

// Set this to false if you haven't implemented the restore function (see below)
$mod_restore    = true;


// This following function will be called when the user presses the "Install" button.
function install()
{
    global $db, $db_type, $pun_config;

    switch ($db_type)
    {
        default:
            $db->query("CREATE TABLE ".$db->prefix."adsense_config (
                        conf_name VARCHAR(255) not null default '',
                        conf_value TEXT,
                        PRIMARY KEY (conf_name)
                        ) TYPE = MyISAM;")
                        or error('Unable to create table adsense_config', __FILE__, __LINE__, $db->error());
                        
            $db->query('INSERT INTO '.$db->prefix.'adsense_config values ("google_bot_name", "AdBot"), ("google_bot_tag", "Google AdSense Posting Bot"),
                        ("google_adsense_enabled", 1), ("google_ad_client", NULL), ("google_ad_width", 728),
                        ("google_ad_height", 90), ("google_ad_format", "720x90_as"), ("google_ad_channel", NULL),
                        ("google_ad_type", "text"), ("google_color_border", "FFFFFF"), ("google_color_bg", "FFFFFF"),
                        ("google_color_link", "005CB1"), ("google_color_url", "005CB1"), ("google_color_text", "333333"),
                        ("google_alternate_color", "FFFFFF"), ("google_exclude_forums", NULL), ("google_exclude_groups", NULL)')
                        or error('Unable to create table adsense_config', __FILE__, __LINE__, $db->error());
            break;
    }

}

// This following function will be called when the user presses the "Restore" button (only if $mod_uninstall is true (see above))
function restore()
{
    global $db, $db_type, $pun_config;

    switch ($db_type)
    {
        default:
            $db->query("DROP TABLE ".$db->prefix."adsense_config") or error('Unable to drop table adsense_config', __FILE__, __LINE__, $db->error());
            break;
    }

}

/***********************************************************************/

// DO NOT EDIT ANYTHING BELOW THIS LINE!


// Circumvent maintenance mode
define('PUN_TURN_OFF_MAINT', 1);
define('PUN_ROOT', './');
require PUN_ROOT.'include/common.php';

// We want the complete error message if the script fails
if (!defined('PUN_DEBUG'))
    define('PUN_DEBUG', 1);

// Make sure we are running a PunBB version that this mod works with
$version_warning = false;
if(!in_array($pun_config['o_cur_version'], $punbb_versions))
{
    foreach ($punbb_versions as $temp)
    {
        if (substr($temp, 0, 3) == substr($pun_config['o_cur_version'], 0, 3))
        {
            $version_warning = true;
            break;
        }
    }

    if (!$version_warning)
        exit('You are running a version of PunBB ('.$pun_config['o_cur_version'].') that this mod does not support. This mod supports PunBB versions: '.implode(', ', $punbb_versions));
}


$style = (isset($cur_user)) ? $cur_user['style'] : $pun_config['o_default_style'];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $mod_title ?> installation</title>
<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_config['o_default_style'].'.css' ?>" />
</head>
<body>

<div id="punwrap">
<div id="puninstall" class="pun" style="margin: 10% 20% auto 20%">

<?php

if (isset($_POST['form_sent']))
{
    if (isset($_POST['install']))
    {
        // Run the install function (defined above)
        install();

?>
<div class="block">
    <h2><span>Installation successful</span></h2>
    <div class="box">
        <div class="inbox">
            <p>Your database has been successfully prepared for <?php echo pun_htmlspecialchars($mod_title) ?>. See readme.txt for further instructions.</p>
        </div>
    </div>
</div>
<?php

    }
    else
    {
        // Run the restore function (defined above)
        restore();

?>
<div class="block">
    <h2><span>Restore successful</span></h2>
    <div class="box">
        <div class="inbox">
            <p>Your database has been successfully restored.</p>
        </div>
    </div>
</div>
<?php

    }
}
else
{

?>
<div class="blockform">
    <h2><span>Mod installation</span></h2>
    <div class="box">
        <form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>?foo=bar">
            <div><input type="hidden" name="form_sent" value="1" /></div>
            <div class="inform">
                <p>This script will update your database to work with the following modification:</p>
                <p><strong>Mod title:</strong> <?php echo pun_htmlspecialchars($mod_title).' '.$mod_version ?></p>
                <p><strong>Author:</strong> <?php echo pun_htmlspecialchars($author) ?> (<a href="mailto:<?php echo pun_htmlspecialchars($author_email) ?>"><?php echo pun_htmlspecialchars($author_email) ?></a>)</p>
                <p><strong>Disclaimer:</strong> Mods are not officially supported by PunBB. Mods generally can't be uninstalled without running SQL queries manually against the database. Make backups of all data you deem necessary before installing.</p>
<?php if ($mod_restore): ?>                <p>If you've previously installed this mod and would like to uninstall it, you can click the restore button below to restore the database.</p>
<?php endif; ?><?php if ($version_warning): ?>                <p style="color: #a00"><strong>Warning:</strong> The mod you are about to install was not made specifically to support your current version of PunBB (<?php echo $pun_config['o_cur_version']; ?>). However, in most cases this is not a problem and the mod will most likely work with your version as well. If you are uncertain about installning the mod due to this potential version conflict, contact the mod author.</p>
<?php endif; ?>            </div>
            <p><input type="submit" name="install" value="Install" /><?php if ($mod_restore): ?><input type="submit" name="restore" value="Restore" /><?php endif; ?></p>
        </form>
    </div>
</div>
<?php

}

?>

</div>
</div>

</body>
</html>

This is from 1.2 mod. may be you can see how he did it. http://www.punres.org/files.php?pid=80

MyFootballCafe.com  is Now Online!