SimplePortal

Customization => Custom Coding => Topic started by: Nabil on December 19, 2008, 06:45:23 AM

Title: How to make an Ad Block out of HTML Block
Post by: Nabil on December 19, 2008, 06:45:23 AM
hi everyone , after I had some problems with installing the Ad Management Mod with my custom Theme , I thought of making an ad Block from HTML block , the idea is simple just write '#ad' as a title and the block will turn into an ad block ,  its a normal block the only difference you won't see the frames like a block and also no title bar, it will display only the contents which could be a Banner , a google Ad Sense advertisment etc. here is the Code :
in SportalBlocks1-1.template.php find :
Code: [Select]
echo '
<div class="tborder">
<table class="bordercolor" width="100%">
<tr class="catbg">
<td style="padding: 5px;">';
if(empty($block['force_view']))
echo '
<a style="float:right;" href="javascript:void(0);" onclick="doCollapseObject(\'sp_block' . $block['id'], '\', \'', $settings['csect_cookie'], '\')"><img id="img_sp_block', $block['id'], '" src="', $settings['images_url'], $block['collapsed'] ? '/expand.gif' : '/collapse.gif', '" alt="*" border="0" /></a>';
echo '
', parse_bbc($block['label']), '
</td>
</tr>
<tr class="windowbg" ', (empty($block['force_view']) ? 'id="sp_block' . $block['id'] . '"' : '') , $block['collapsed'] ? ' style="display:none;"' : '', '>
<td style="padding: 5px;">';

if(in_array($block['type'], array('sp_bbc', 'sp_html', 'sp_php')))
{
$block['type']($block['content']);
}
else
{
$parameters = explode(',', $block['parameters']);
$block['type']($parameters);
}

echo '
</td>
</tr>
</table>
</div>

<br />';

Replace with :
Code: [Select]
////////////// AD BLOCK Check //////////////
$adblock=$block['label'];
if (substr($adblock,0,3)=='#ad'){
echo '<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td align="center">';
if(in_array($block['type'], array('sp_bbc', 'sp_html', 'sp_php')))
{
$block['type']($block['content']);
}
else
{
$parameters = explode(',', $block['parameters']);
$block['type']($parameters);
}

echo '
</td>
</tr>
</table>';
} else {

echo '
<div class="tborder">
<table class="bordercolor" width="100%">
<tr class="catbg">
<td style="padding: 5px;">';
if(empty($block['force_view']))
echo '
<a style="float:right;" href="javascript:void(0);" onclick="doCollapseObject(\'sp_block' . $block['id'], '\', \'', $settings['csect_cookie'], '\')"><img id="img_sp_block', $block['id'], '" src="', $settings['images_url'], $block['collapsed'] ? '/expand.gif' : '/collapse.gif', '" alt="*" border="0" /></a>';
echo '
', parse_bbc($block['label']), '
</td>
</tr>
<tr class="windowbg" ', (empty($block['force_view']) ? 'id="sp_block' . $block['id'] . '"' : '') , $block['collapsed'] ? ' style="display:none;"' : '', '>
<td style="padding: 5px;">';

if(in_array($block['type'], array('sp_bbc', 'sp_html', 'sp_php')))
{
$block['type']($block['content']);
}
else
{
$parameters = explode(',', $block['parameters']);
$block['type']($parameters);
}

echo '
</td>
</tr>
</table>
</div>

<br />';
}
////////////// END ///////////


Title: Re: How to make an Ad Block out of HTML Block
Post by: jb3398 on December 23, 2008, 05:34:12 PM
Nice do you have an example of this mod in action, a url link.
Title: Re: How to make an Ad Block out of HTML Block
Post by: Nabil on December 23, 2008, 06:45:18 PM
Quote
Nice do you have an example of this mod in action, a url link.
it is not a Mod , it is a change I have made on adding a html block function (a function found in Simple Portal) the change will hide/remove the borders and the title bar of a block letting only the inside of a block to be seen , like the following image .. you can see , that the ad is displayed as it is without a block surrounding it.
Title: Re: How to make an Ad Block out of HTML Block
Post by: artificialive on February 06, 2009, 07:57:29 AM
Hi there,
i found out that your modification is interesting and useful.
however, i have tried but it don't seem to be materialized.
anyone can help me to testify the mod i have done, pleasee?

attached is the SPortalBlocks1-1.template.php

thanks very much.
Title: Re: How to make an Ad Block out of HTML Block
Post by: Nabil on February 07, 2009, 02:49:49 AM
I have tested your 'SPortalBlocks1-1.template' , it works
so what's the problem?
Title: Re: How to make an Ad Block out of HTML Block
Post by: artificialive on February 09, 2009, 05:53:53 AM
Im not sure why.
Well im a newbie on SMF.
Im using the overviewlight theme by dziner studio.
i cant find the SPortalBlocks1-1.template.php file anywhere except from the default theme directory.
Is there any other location of the SPortalBlocks1-1.template.php file that i should edit?

thanks a lot  :nervous-happy:
Title: Re: How to make an Ad Block out of HTML Block
Post by: Nabil on February 09, 2009, 10:20:39 AM
Quote
Is there any other location of the SPortalBlocks1-1.template.php file that i should edit?

I have it in my Theme's Directory
Title: Re: How to make an Ad Block out of HTML Block
Post by: artificialive on February 09, 2009, 11:44:59 AM
Hi Nabil,
thanks for trying to help me out. but i cant find the file in my Theme's directory.
Uploaded the file to my Theme's directory though, but it didnt work.
Anyway, u can see it here at my site. the ad has the header '#ad'.
http://ftmk.putrabytes.com (http://ftmk.putrabytes.com)

Title: Re: How to make an Ad Block out of HTML Block
Post by: Manu on February 09, 2009, 11:48:14 AM
Im not sure why.
Well im a newbie on SMF.
Im using the overviewlight theme by dziner studio.
i cant find the SPortalBlocks1-1.template.php file anywhere except from the default theme directory.
Is there any other location of the SPortalBlocks1-1.template.php file that i should edit?

thanks a lot  :nervous-happy:

I'm using the Overview Multicolor, and the my SPortalBlocks1-1.template.php is only in the folder of the default.

Hi Nabil,
thanks for trying to help me out. but i cant find the file in my Theme's directory.
Uploaded the file to my Theme's directory though, but it didnt work.
Anyway, u can see it here at my site. the ad has the header '#ad'.
http://ftmk.putrabytes.com (http://ftmk.putrabytes.com)



Could it be you have add '#ad' as title of the block instead of a name for the block? Don't know how to explain it in English.  :-[
Title: Re: How to make an Ad Block out of HTML Block
Post by: artificialive on February 09, 2009, 01:12:08 PM
Hi Manu,
Im not sure what do u mean, but im putting '#ad' as my block name.
Attached is the image on how i filled up the html block.

Is there anything wrong?
Title: Re: How to make an Ad Block out of HTML Block
Post by: Manu on February 09, 2009, 04:32:45 PM
Now I see I was wrong.
The '#ad' should remove all the borders of the block itself.  :-[
I think that's something for our Dev's, cause that's to much php for me.  :-[
Sorry, but here I can't help you.  :-[
Title: Re: How to make an Ad Block out of HTML Block
Post by: Nabil on February 09, 2009, 05:13:15 PM
it did not work in your case as I can see from the attached image because you didn't write at the beginning the '<?php' , the php block is not like a normal php site you should write that symbol , just write something like
<?php
///////////// ///////////////////
?>


at the begining of your code and it will go

by the way the name of the block is not only limited to #ad , you can give it #adname1 or #adname2 or #adname3   , any name after #ad

I can also see in the image that you have givin the name '#ad'
write #ad not '#ad'
Title: Re: How to make an Ad Block out of HTML Block
Post by: artificialive on February 10, 2009, 09:36:50 AM
Hello,
thanks for all the replies.  It really helped!
Now the ads are borderless  :D
Thank you, thank you.
Title: Re: How to make an Ad Block out of HTML Block
Post by: Blue on February 17, 2009, 06:49:26 AM
Hi I tried this on a SPortalBlocks2.template but it didn't work. Here is the code:

Code: [Select]
$adblock=$block['label'];
if (substr($adblock,0,3)=='#ad'){
echo '<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td align="center">';
if(in_array($block['type'], array('sp_bbc', 'sp_html', 'sp_php')))
   {
      $block['type']($block['content']);
   }
   else
   {
      $parameters = explode(',', $block['parameters']);
      $block['type']($parameters);
   }

   echo '
                     </td>
                  </tr>
               </table>';
} else {
echo '
<div class="tborder">
<table class="bordercolor" width="100%">
<tr class="catbg">
<td style="padding: 5px;">';
if(empty($block['force_view']))
echo '
<a style="float: right;" href="javascript:void(0);" onclick="doCollapseObject(\'sp_block' . $block['id'], '\', \'', $settings['csect_cookie'], '\')"><img id="img_sp_block', $block['id'], '" src="', $settings['images_url'], $block['collapsed'] ? '/expand.gif' : '/collapse.gif', '" alt="*" border="0" /></a>';
echo '
', parse_bbc($block['label']), '
</td>
</tr>
<tr class="windowbg" ', (empty($block['force_view']) ? 'id="sp_block' . $block['id'] . '"' : '') , $block['collapsed'] ? ' style="display:none;"' : '', '>
<td style="padding: 5px;">';

if(in_array($block['type'], array('sp_bbc', 'sp_html', 'sp_php')))
{
$block['type']($block['content']);
}
else
{
$parameters = explode(',', $block['parameters']);
$block['type']($parameters);
}

echo '
</td>
</tr>
</table>
</div>

<br />';
}

Can someone help me? ;D
Title: Re: How to make an Ad Block out of HTML Block
Post by: Blue on February 26, 2009, 09:41:07 AM
anyone? :'(
Title: Re: How to make an Ad Block out of HTML Block
Post by: Nabil on February 26, 2009, 01:13:43 PM
That Code is made for sp with smf 1.x.x  , so it has to be modified to work with smf2 , but I did a simple test  with sp & smf2 , replaced SportalBlocks1-1.template.php instead of  SportalBlocks2.template.php by renaming it to  SportalBlocks2.template.php , I didn't see any change actually , so you can apply the code for SportalBlocks1-1.template.php and use it instead of  SportalBlocks2.template.php , but keep a backup copy of the Original SportalBlocks2.template.php , do this at your own risk I didnt test all the Blocks , just php and html
Title: Re: How to make an Ad Block out of HTML Block
Post by: Contra on February 27, 2009, 07:21:59 PM
worked perfect for me!
Title: Re: How to make an Ad Block out of HTML Block
Post by: fl4pj4ck on February 27, 2009, 09:52:59 PM
1) I have edited the file SPortalBlocks1
2) I have created a block for google adsense ads, the block type is set to "HTML"
3) I put the google ads code within the blocks
4) I have named the block #adFirst

what I'm doing wrong?
Title: Re: How to make an Ad Block out of HTML Block
Post by: Nabil on March 01, 2009, 11:36:51 AM
Quote
I have edited the file SPortalBlocks1

you mean SPortalBlocks1-1.template.php dont you?

this is how a google code inside a HTML block looks like

Code: [Select]
<script type="text/javascript"><!--
google_ad_client = "pub-6566546455656
/* 728x90, text only */
google_ad_slot = "zttzztzt";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pgad.goolesyztztndcaion.com/pagea/show_ads.js">
</script><br>
Title: Re: How to make an Ad Block out of HTML Block
Post by: fl4pj4ck on March 01, 2009, 03:37:37 PM
yes, that's what I meant

this block wont show either using #ad or the regular block, I'm just getting empty space, like it's not being recognized
Title: Re: How to make an Ad Block out of HTML Block
Post by: Nabil on March 02, 2009, 03:48:07 AM
Can I see your SPortalBlocks1-1.template.php  ?
Title: Re: How to make an Ad Block out of HTML Block
Post by: fl4pj4ck on March 02, 2009, 07:28:09 AM
Can I see your SPortalBlocks1-1.template.php  ?

Quote
<?php
/*

File: SPortalBlocks1-1.template.php
Version: SimplePortal 2.1.1 for SMF 1.x

*/

function template_portal_above()
{
   global $context, $modSettings;

   sp_collapse_script();

   echo '
   <table cellpadding="5px" width="100%">
      <tr>';
   
   if(!empty($modSettings['showleft']) && !empty($context['SPortal']['blocks']['Left']))
   {
      echo '
         <td valign="top"', !empty($modSettings['leftwidth']) ? ' width="' . $modSettings['leftwidth'] . '"' : '', '>';
      
      foreach ($context['SPortal']['blocks']['Left'] as $block)
         template_block($block);

      echo '
         </td>';
   }

   echo '
         <td valign="top">';

   foreach ($context['SPortal']['blocks']['Middle-Top'] as $block)
      template_block($block);
}

function template_portal_below()
{
   global $context, $modSettings;

   echo '
            <br />';
   
   foreach ($context['SPortal']['blocks']['Middle-Bottom'] as $block)
      template_block($block);

   echo '
         </td>';

   if(!empty($modSettings['showright']) && !empty($context['SPortal']['blocks']['Right']))
   {
      echo '
         <td valign="top"', !empty($modSettings['rightwidth']) ? ' width="' . $modSettings['rightwidth'] . '"' : '', '>';

      foreach ($context['SPortal']['blocks']['Right'] as $block)
         template_block($block);

      echo '
         </td>';
   }
   echo '
      </tr>
   </table>';
}

function template_block($block)
{
   global $settings;

   if(empty($block['force_view']))
      $block['collapsed'] = sp_collapse_state('sp_block' . $block['id']);
   else
      $block['collapsed'] = false;

   if ($block['type'] == 'sp_boardNews')
   {
      $parameters = explode(',', $block['parameters']);
      $block['type']($parameters);

      echo '
            <br />';

      return;
   }

/*
   echo '
            <div class="tborder">
               <table class="bordercolor" width="100%">
                  <tr class="catbg">
                     <td style="padding: 5px;">';
   if(empty($block['force_view']))
      echo '
                        <a style="float:right;" href="javascript:void(0);" onclick="doCollapseObject(\'sp_block' . $block['id'], '\', \'', $settings['csect_cookie'], '\')"><img id="img_sp_block', $block['id'], '" src="', $settings['images_url'], $block['collapsed'] ? '/expand.gif' : '/collapse.gif', '" alt="*" border="0" /></a>';
   echo '
                        ', parse_bbc($block['label']), '
                     </td>
                  </tr>
                  <tr class="windowbg" ', (empty($block['force_view']) ? 'id="sp_block' . $block['id'] . '"' : '') , $block['collapsed'] ? ' style="display:none;"' : '', '>
                     <td style="padding: 5px;">';

   if(in_array($block['type'], array('sp_bbc', 'sp_html', 'sp_php')))
   {
      $block['type']($block['content']);
   }
   else
   {
      $parameters = explode(',', $block['parameters']);
      $block['type']($parameters);
   }

   echo '
                     </td>
                  </tr>
               </table>
            </div>

            <br />';
*/

////////////// AD BLOCK Check //////////////
$adblock=$block['label'];
if (substr($adblock,0,3)=='#ad'){
echo '<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr><td align="center">';
if(in_array($block['type'], array('sp_bbc', 'sp_html', 'sp_php')))
   {
      $block['type']($block['content']);
   }
   else
   {
      $parameters = explode(',', $block['parameters']);
      $block['type']($parameters);
   }

   echo '
                     </td>
                  </tr>
               </table>';
} else {

   echo '
            <div class="tborder">
               <table class="bordercolor" width="100%">
                  <tr class="catbg">
                     <td style="padding: 5px;">';
   if(empty($block['force_view']))
      echo '
                        <a style="float:right;" href="javascript:void(0);" onclick="doCollapseObject(\'sp_block' . $block['id'], '\', \'', $settings['csect_cookie'], '\')"><img id="img_sp_block', $block['id'], '" src="', $settings['images_url'], $block['collapsed'] ? '/expand.gif' : '/collapse.gif', '" alt="*" border="0" /></a>';
   echo '
                        ', parse_bbc($block['label']), '
                     </td>
                  </tr>
                  <tr class="windowbg" ', (empty($block['force_view']) ? 'id="sp_block' . $block['id'] . '"' : '') , $block['collapsed'] ? ' style="display:none;"' : '', '>
                     <td style="padding: 5px;">';

   if(in_array($block['type'], array('sp_bbc', 'sp_html', 'sp_php')))
   {
      $block['type']($block['content']);
   }
   else
   {
      $parameters = explode(',', $block['parameters']);
      $block['type']($parameters);
   }

   echo '
                     </td>
                  </tr>
               </table>
            </div>

            <br />';
}
            ////////////// END ///////////

}

function sp_collapse_state($block_id)
{
   global $settings;

   if(isset($settings['collapsed_sects']) && !empty($settings['collapsed_sects']))
   {
      if(array_search($block_id, $settings['collapsed_sects']) === false)
         return false;
      else
         return true;
   }

   return false;
}

function sp_collapse_script()
{
   global $settings, $context;

   $csect_cookie = 'SMF_user_' . $context['user']['id'] . '_CSect';

   if(isset($_COOKIE[$csect_cookie]) && !empty($_COOKIE[$csect_cookie]))
       $settings['collapsed_sects'] = explode("\n", $_COOKIE[$csect_cookie]);
   $settings['csect_cookie'] = $csect_cookie;

   echo'
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[

var dom_engine = \'\';
if (document.getElementById)
   dom_engine = 1;               // mozilla, opera etc..
else if (document.all)
   dom_engine = 0;               // IE (pls die, kthx)
else if (document.layers)
   dom_engine = 2;               // NS4, should never happen :P

var active_menu = "";
var mouse_over_menu = "";

function getObject(id)
{
   if(dom_engine == 1)
      obj = document.getElementById(id);
   else if(dom_engine == 0)
      obj = document.all[id];
   else if(dom_engine == 2)
      obj = document.layers[id];
      
   return obj;
}

function getCookieFromDocument(cookie_name)
{
   cname = cookie_name + "=";
   clength = document.cookie.length;
   begin = 0;
   
   while (begin < clength) {
       vbegin = begin + cname.length;
       if (document.cookie.substring(begin, vbegin) == cname) {
      var end = document.cookie.indexOf (";", vbegin);
      if (end == -1) {
          end = clength;
      }
      return unescape(document.cookie.substring(vbegin, end));
       }
       begin = document.cookie.indexOf(" ", begin) + 1;
       if (begin == 0)   {
      break;
       }
   }
   return null;
}

function setCookieToDocument(cookie_name, cookie_expiredate, cookie_value)
{
    document.cookie=cookie_name+"="+escape(cookie_value)+"; expires="+cookie_expiredate.toGMTString()+"; path=/";
}

function saveObjectToCookie(obj, mode, cookiename)
{
   var already_collapsed=getCookieFromDocument(cookiename);
   var temp = new Array();
   cookieExpireDate = new Date();
   cookieExpireDate.setTime(cookieExpireDate.getTime() + 86400*1000*300);         // 300 days expiration date

   if (already_collapsed) {
       already_collapsed = already_collapsed.split("\n");

       for (i in already_collapsed) {
      if (already_collapsed != obj && already_collapsed != "")
          temp[temp.length] = already_collapsed;
       }
   }

   if (mode)
       temp[temp.length] = obj;

   setCookieToDocument(cookiename, cookieExpireDate, temp.join("\n"));
}

function doCollapseObject(id, cookiename)
{
   obj = getObject(id);   
   imageid = getObject("img_" + id);
   tempobj = getObject(id);
         
   if (obj.style.display == "none") {   // object is collapsed, show it, clear the cookie
       obj.style.display = "";
       saveObjectToCookie(id, 0, cookiename);
       if (imageid) {
      imageid.src = imageid.src.replace(\'expand.gif\', \'collapse.gif\');
       }
   } else {            // hide the object, save it to the cookie
       obj.style.display = "none";
       saveObjectToCookie(id, 1, cookiename);
       if (imageid) {
      imageid.src = imageid.src.replace(\'collapse.gif\', \'expand.gif\');
       }
   }
   return false;
}
   // ]]></script>';
}

?>

there it is, thanks a lot
Title: Re: How to make an Ad Block out of HTML Block
Post by: Nabil on March 02, 2009, 08:25:39 AM
your SPortalBlocks1-1.template.php file works as expected , do you have it in your Custom Theme Directory?
Title: Re: How to make an Ad Block out of HTML Block
Post by: fl4pj4ck on March 02, 2009, 09:30:15 AM
your SPortalBlocks1-1.template.php file works as expected , do you have it in your Custom Theme Directory?

no, I have it in /Themes/default
but now checked with all 3 files in /Themes/kelo and still "no go" :(
Title: Re: How to make an Ad Block out of HTML Block
Post by: Nabil on March 02, 2009, 11:14:19 AM
I have tested your file with another Theme , where the  SPortalBlocks1-1.template.php  in the default Theme , it works also 100% as expected with no problem at all, I beleive it has nothing to do with the SPortalBlocks1-1.template.php , see if the Code you are using in the Block if it really displays something or not , test it with a normal block
Title: Re: How to make an Ad Block out of HTML Block
Post by: fl4pj4ck on March 02, 2009, 03:58:56 PM
have a look at the bottom here: http://polacywlimerick.com/forum/index.php
here's my code:
Quote
<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxx";
google_ad_slot = "xxxxxxxxxxx";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pgad.goolesyztztndcaion.com/pagea/show_ads.js">
</script><br>
Title: Re: How to make an Ad Block out of HTML Block
Post by: Nabil on March 03, 2009, 05:12:15 AM
the Google Code seems like a usual Code , nothing unusual , but
it doesn't show anything
Quote
this block wont show either using #ad or the regular block, I'm just getting empty space
and since this is the case also with a normal Block , then we can
say with 100% its a google script problem
SimplePortal 2.3.8 © 2008-2024, SimplePortal