[BETA] Random Forum Image

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment!
Get Involved

[BETA] Random Forum Image

Postby Freitag » Mon Jan 07, 2008 5:20 am

MOD Title: Random Forum Image
MOD Description: Since phpBB3 now includes the feature to include a forum image by default that in phpBB2 required the Forum Icon MOD with ACP, I'm trying to port my random image mod to the new layout.

MOD Version: 0.0.0

MOD Download: see included text below...
Last Stable version: N/A

Demo Board: You can see this mod in action here - look at the programming and Anime forums.
Demo Username: N/A
Demo Password: N/A


Part 1 is to make the code work. DONE

Part 2 is to learn this new MODX format and make a real mod of it. IN PROGRESS

So far 100% compatible with both ProSilver and SubSilver since no template files are edited.

Still learning my way around the geography of 3...

The following is my first attempt at putting the instructions into MODX format. Copy the following and save it as "Random_Forum_Image_MOD.xml"

Code: Select all
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
      <?xml-stylesheet type="text/xsl" href="modx.prosilver.en.xsl"?>
      <!--For security purposes, please check: http://www.phpbb.com/mods/ for the latest version of this MOD. Although MODs are checked before being allowed in the MODs Database there is no guarantee that there are no security problems within the MOD. No support will be given for MODs not found within the MODs Database which can be found at http://www.phpbb.com/mods/-->
      <mod xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.phpbb.com/mods/xml/modx-1.0.xsd">
         <header>
            <license>http://opensource.org/licenses/gpl-license.php GNU General Public License v2</license>
            <title lang="en">Random Forum Image MOD</title>
            <description lang="en">This MOD allows an administrator to set up a group of images for a forum - one of which will be chosen on each page refresh</description>
            <author-notes lang="en"><![CDATA[I originally wrote this as a MOD to a MOD in phpB2]]></author-notes>
            <author-group>
               <author>
                  <realname>Freitag</realname>
                  
                  <username>Freitag</username>
                  
                  <contributions />
               </author>
            </author-group>
            <mod-version>
               <major>0</major>
               <minor>0</minor>
               <revision>0</revision>
               <release>0</release>
            </mod-version>
            <installation>
               <level>easy</level>
               <time>120</time>
               <target-version>
                  <target-primary>3.0.RC1</target-primary>
                  <target-major allow="exact">3</target-major>
                  <target-minor allow="exact">0</target-minor>
               </target-version>
            </installation>
            <history>
            </history>
            <meta name="modx file generator" content="Geoffreak's Easy phpBB3 MODX Script Generator @ http://www.geoffreak.org" />
         </header>
         <action-group>
            <open src="acp\acp_forums.php">
               <edit>
                  <find><![CDATA[            $template->assign_vars(array(]]></find>
                  <action type="before-add"><![CDATA[/* BEGIN Added by Freitag for random image (hence "ri_" in temp variable names) */
$forum_image = random_image_parser( $row[ 'forum_image' ] );
/* END Added by Freitag for random forum image */
]]></action>
                  <find><![CDATA[               'FORUM_IMAGE'            => $forum_data['forum_image'],
               'FORUM_IMAGE_SRC'         => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
]]></find>
                  <action type="replace-with"><![CDATA[/* BEGIN Added by Freitag for random forum image
               'FORUM_IMAGE'            => $forum_data['forum_image'],
               'FORUM_IMAGE_SRC'         => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
*/

               'FORUM_IMAGE'            => $forum_data['forum_image'],
               'FORUM_IMAGE_SRC'         => ($forum_image) ? $phpbb_root_path . $forum_image : '',
/* END Added by Freitag for random forum image */
]]></action>
                  <find><![CDATA[            $template->assign_block_vars('forums', array(]]></find>
                  <action type="before-add"><![CDATA[/* BEGIN Added by Freitag for random image in temp variable names) */
$forum_image = random_image_parser( $row[ 'forum_image' ] );
/* END Added by Freitag for random forum image */
]]></action>
                  <find><![CDATA[               'FORUM_IMAGE'      => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
               'FORUM_IMAGE_SRC'   => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
]]></find>
                  <action type="replace-with"><![CDATA[/* BEGIN Added by Freitag for random forum image
               'FORUM_IMAGE'      => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
               'FORUM_IMAGE_SRC'   => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
*/
               'FORUM_IMAGE'      => ($forum_image) ? '<img src="' . $phpbb_root_path . $forum_image . '" alt="" />' : '',
               'FORUM_IMAGE_SRC'   => ($forum_image) ? $phpbb_root_path . $forum_image : '',
/* END Added by Freitag for random forum image */
]]></action>
               </edit>
            </open>
            <open src="includes\functions.php">
               <edit>
                  <find><![CDATA[?>]]></find>
                  <action type="before-add"><![CDATA[/* BEGIN Added by Freitag for random image (hence "ri_" in temp variable names) */
/**
* Handler for random forum image parsing. This function is called from two places in Forum ACP and one from the Forum display
* This function does not support hooks.
*/
function random_image_parser( $ri_temp1 )
{
   $forum_image = $ri_temp1; /* Get the base value into the usable variable */
   if( strstr( $forum_image, "[" ) )
   {
      /* if the base name contains [ and ] then it is assumed the name is in the format
       * like the following:
       *
       * images/image_name[1-4].png
       *
       * which implies that there are 4 (four) images that are named
       * images/image_name1.png, images/image_name2.png, images/image_name3.png, and images/image_name4.png,
       * from which to choose one random image for display
       *
       * And then modify the name of the usable variable to be the generated image name
       */

      preg_match( "/[(d)-(d)]/", $forum_image, $ri_span );
      $ri_num = rand($ri_span[1], $ri_span[2]);

      $ri_temp2 = $forum_image;
      $ri_base = substr( $ri_temp2, 0, strpos( $ri_temp2, "[" ) );
      $ri_suffix = substr( $ri_temp2, strpos( $ri_temp2, "]" ) 1 );

      $forum_image = $ri_base . $ri_num . $ri_suffix;
   }

   return $forum_image;
}
/* END Added by Freitag for random forum image */
]]></action>
               </edit>
            </open>
            <open src="includes\functions_display.php">
               <edit>
                  <find><![CDATA[      $template->assign_block_vars('forumrow', array(]]></find>
                  <action type="before-add"><![CDATA[/* BEGIN Added by Freitag for random image in temp variable names) */
$forum_image = random_image_parser( $row[ 'forum_image' ] );
/* END Added by Freitag for random forum image */]]></action>
                  <find><![CDATA[         'FORUM_IMAGE'         => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
         'FORUM_IMAGE_SRC'      => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',]]></find>
                  <action type="replace-with"><![CDATA[/* BEGIN Added by Freitag for random forum image
         'FORUM_IMAGE'         => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
         'FORUM_IMAGE_SRC'      => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
*/
         'FORUM_IMAGE'         => ($forum_image) ? '<img src="' . $phpbb_root_path . $forum_image . '" alt="' . $user->lang[$folder_alt] . '" />' : '',
         'FORUM_IMAGE_SRC'      => ($forum_image) ? $phpbb_root_path . $forum_image : '',
/* END Added by Freitag for random forum image */]]></action>
               </edit>
            </open>
         
            <diy-instructions lang="en">Those are the code changes. Make sure to clear your cache....

To use this MOD
First upload several images like so..
icon_name1.png
icon_name2.png
icon_name3.png
icon_name4.png
icon_name5.png


Then in the Forum tab of the ACP, edit the forum settings and enter the path to the image in the following format:
images/icon_name[1-5].png

The square brackets are the flag that you have multiple files. The hyphen designated the range. Any standard image suffix will work, I just happen to like PNGs. Also, you don't have to start at "1" - you can use any range of numbers as long as you have the files named right.

When your forum page refreshes one of the images will be chosen at random each time.

So far 100% compatible with both ProSilver and SubSilver since no template files are edited.
            </diy-instructions></action-group>
      </mod>
Image
User avatar
Freitag
Registered User
 
Posts: 141
Joined: Mon Jul 11, 2005 10:17 pm

Return to [3.0.x] MODs in Development

Who is online

Users browsing this forum: MSNbot Media and 24 guests