Mihalism Multi Host: Ads or Content in Public Gallery Section

This is a very simple modification for Mihalism Multi Host (MMH) that will allow you to include content interspersed in the public gallery section. Provided is a simple method that includes content on each row in the gallery and in a random position of that row.

This mod does not include content in the user galleries or in the admin section but it would be simple enough to do for them. Further, adding content in an ordered way and at set intervals, could also be done with ease.

This example is based on a four column table (which is standard and hard coded in MMH). Ok, lets get down to it:

Step 1, Create a template file for the content you want to insert:

In the directory source/public_html create the file global_ad.tpl in this file include the following:

<!– BEGIN: GLOBAL GALLERY AD LAYOUT –>

<template id=”global_gallery_ad_layout_1″>
<# TABLE_BREAK #>
<td class=”<# TDCLASS #>” valign=”top” style=”text-align:center;”>
<strong><# FILE_TITLE #></strong>
<br /><br />
Sample Text #1 – Replace with text, markup or javascript
</td>
</template>

<template id=”global_gallery_ad_layout_2″>
<# TABLE_BREAK #>
<td class=”<# TDCLASS #>” valign=”top” style=”text-align:center;”>
<strong><# FILE_TITLE #></strong>
<br /><br />
Sample Text #2 – Replace with text, markup or javascript
</td>
</template>

<template id=”global_gallery_ad_layout_3″>
<# TABLE_BREAK #>
<td class=”<# TDCLASS #>” valign=”top” style=”text-align:center;”>
<strong><# FILE_TITLE #></strong>
<br /><br />
Sample Text #3 – Replace with text, markup or javascript
</td>
</template>

<!– END: GLOBAL GALLERY AD LAYOUT –>

The above code allows for three different content items. You can include markup, javascipt or straight text by replacing the text shown in bold: “Sample Text – Replace with text, markup or javascript”. How many content items you want is up to you. Adding another is as simple as copying one of the template sections and changing the end number in template id. To have fewer just remove the template markup for one or more items.

Step 2, Add the code to insert content:

In the root directory you will find the file gallery.php – load this with your favorite editor to get down to hacking.

  1. On or near line 20, just before the while loop: while ($row = $mmhclass->db->fetch_array($sql)) { insert the following: $ad_place_in_row = rand(1,4); // Get random position for ad on first row
  2. Just bellow the while loop there is an if condition with the line: $break_line = true; Right after that add the following: $ad_place_in_row = rand(1,4); // Reset random position for new row
  3. Now, just after the while loop you will see the line: $tdcount++; add the following block of code after that line (now aproximately line 28/29):
  4. /* begin ad placement */
    if ($tdcount == $ad_place_in_row) {

    $mmhclass->templ->templ_vars[] = array(
    “FILE_TITLE” => ‘Title of Content (or empty)‘,
    “TDCLASS” => $tdclass = (($tdclass == “tdrow1”) ? “tdrow2” : “tdrow1”),
    “TABLE_BREAK” => (($break_line == true) ? “</tr><tr>” : NULL),
    );

    $ad_number = rand(1,3);
    $gallery_html .= $mmhclass->templ->parse_template(“global_ad”, “global_gallery_ad_layout_$ad_number”);
    unset($mmhclass->templ->templ_vars, $break_line);

    if ($tdcount >= 4) {
    $tdcount = 0;
    $break_line = true;
    $ad_place_in_row = rand(1,4);
    }

    $tdcount++;
    }
    /* end ad placement */

In the code in section C of step 2 you may notice the assignment for “FILE_TITLE” – here you can add a standard title that will display above your content.  Replace the bolded text with your preferred title.  You may also remove all the bolded text and just leave the two single quotes to have no title. Further, you can remove that whole assignment and replace the <strong><# FILE_TITLE #></strong> in the template file to a title you want.

If you have opted to have more or less items in the template file be sure to update the random ad_number: $ad_number = rand(1,3); to accommodate how many content items you have in your template. If you’ve decided to have just one item you can remove the random code and edit the line right after it: $gallery_html .= $mmhclass->templ->parse_template("global_ad", "global_gallery_ad_layout_$ad_number"); to $gallery_html .= $mmhclass->templ->parse_template("global_ad", "global_gallery_ad_layout_1"); to allow for just one item.

Step 3, Bask in the glory of happiness:

Thats it.  It is as simple as that.

As you most likely noticed the code included in gallery.php is almost exactly the same as the existing code.  This may not be the prettiest or most efficient way to do it but the reasoning behind it was to keep the mod as easy and unintrusive as possible.

If this ends up useful for someone and there is the need I can include a file for download.  I could also provide  further examples such as including the content at a set interval, if desired.  Oh, and please let me know if this made any sense at all.

2 thoughts on “Mihalism Multi Host: Ads or Content in Public Gallery Section

  1. toppy Post author

    Thanks Preetish. Mihalism Multi Host has reached version 5.0.2. since the article. I'd like to check out the changes and see where the mod stands before I release anything else on it.

Comments are closed.