Shortcodes, adding to the forum

From e107 Wiki
Jump to: navigation, search

e107 Wiki: English | Русский | Deutsch | Français | Magyar | Português | Български | Česky | Nederlands | Ελληνικά | Italiano | Norske | Polska | Slovenščina | Español | Svenska | Translate: Wiki | Page

logo_wiki.png

Current Release 1.0.4 | e107.org | Download | Changelog | Forum | Plugins | Themes | RSS Feed of Latest Changes | Atom Feed of Latest Changes


e107 Shortcode Guide
Main page > I : First Aid > II : Development > III : Administration > IV : How To's > V : Plugin Writing > VI : Theming & Shortcodes


This page is a stub. You can help e107 by expanding it.


Contents

Adding Shortcodes to the Forum

The principles of adding shortcodes to the forum are much the same as adding them elsewhere; however there are some forum-specific codes. These are listed here.


The following is an extract from a forum post which give an idea of modifying the layout of a forum thread:

You will need to identify the correct template file to edit - the defaults are in e107_plugins/forum/templates; however some themes override them with alternative files of the same names, in which case they will be in the theme directory.

Probably forum_viewtopic_template.php will be what you want.

Look at this in a text editor (even Notepad will do), and you should be able to see the correspondence with your forum layout.

At line 89 in the default file is a line starting: $FORUMTHREADSTYLE = .... the text which follows sets the format of each post. It is a mix of HTML and shortcodes, so you do need to at least understand a bit of HTML.

A little way down you will see: {EXTENDED=location.text}: {EXTENDED=location.value}

this is displaying information from the extended user fields - location.text is the 'description', and location.value is the actual value.

You can add fields in a similar format to pull out your other extended user fields.

Adding a custom picture to the forum

It is possible to create a shortcode which displays a picture (or 'badge') against a user in the forum, dependent on the user class(es) they belong to. An example of this is the 'Support Team' picture used in the E107 forums.

Creating the shortcode

Create a file called 'xxxxx.sc' where xxxxx is the code you will be using to show the special picture (eg. support.sc).

Put the following code into that page

           /*
            * file support.sc
            */
           // set global to $post_info for forum & $user for profile
           global $post_info, $user;
 
           // --> EDIT THE FOLLOWING <--
           // use the following to list the classes with their pictures, from most important (1) to least important (4)
 
           // this is the most important userclass
           $rank_no1 = "Owner";
           // this is the picture that needs to be showed with this userclass on forum/profile (examples used)
           $rank_no1_pic = "<img src='".THEME_ABS."yourranks/owner.gif' />";
 
           $rank_no2 = "Administrator";
           $rank_no2_pic = "<img src='".THEME_ABS."yourranks/administrator.gif' />";
 
           $rank_no3 = "Moderator";
           $rank_no3_pic = "<img src='".THEME_ABS."yourranks/moderator.gif' />";
 
           $rank_no4 = "Forum mod";
           $rank_no4_pic = "<img src='".THEME_ABS."yourranks/forum_mod.gif' />";
           // --> STOP EDIT <--
 
           if(check_class($rank_no4, $post_info['user_class'], TRUE) || check_class($rank_no4, $user['user_class'], TRUE))
           {
              $output = "<div align='center'>$rank_no4_pic</div>";
           }
           if(check_class($rank_no3, $post_info['user_class'], TRUE) || check_class($rank_no3, $user['user_class'], TRUE))
           {
              $output = "<div align='center'>$rank_no3_pic</div>";
           }
           if(check_class($rank_no2, $post_info['user_class'], TRUE) || check_class($rank_no2, $user['user_class'], TRUE))
           {
               $output = "<div align='center'>$rank_no2_pic</div>";
           }
           if(check_class($rank_no1, $post_info['user_class'], TRUE) || check_class($rank_no1, $user['user_class'], TRUE))
           {
                   $output = "<div align='center'>$rank_no1_pic</div>";
           }
           return $output;
 
 // End of code extract             

Once you have prepared this file, and the associated graphics, proceed as follows:

  1. Upload this file to e107_files/shortcode/
  2. Go to e107_plugins/forum/templates/
  3. Open/edit the file 'forum_viewtopic_template.php'
  4. Find '$FORUMTHREADSTYLE'
  5. Under the {POSTS} add your shortcode - {SUPPORT}
  6. Add the shortcode also under {POSTS} under '$FORUMREPLYSTYLE'
  7. The images work in the forum now, if you want them to show in the profiles continue:
  8. Go to e107_themes/templates/
  9. Open 'user_template.php'
  10. Find the entry '{$sendpm}' add your shortcode under it (i tried it in different places, but some issues resulted - nothing showed up)
  11. Go to the top of the page
  12. Directly under the entry
 $sc_style['USER_SIGNATURE']['post'] = "</td></tr>";
ADD
 $sc_style['SUPPORT']['pre'] = "<tr><td colspan='2' class='forumheader3' style='text-align:left'>";
 $sc_style['SUPPORT']['post'] = "</td></tr>";
this way the layout of your profile is not messed up.

You're finished

Further explanation

Just take there are 3 userclasses (examples from e107)

the e107 developers (highest rank within the classes) the e107 moderators (2nd rank within classes) the e107 support team (3rd rank within classes)

If someone belongs to more than 1 group (eg 2dopey is both support and moderator), we want the picture for the highest rank within the classes to be showed. In the forums we want a picture of a moderator for 2dopey, not support as this is of a lower rank.

I used the ranks to make the distinction as to what should be showed. If a developer is also a moderator, we want the picture of developer to show, not a moderator. Therefore a ranking of these classes is made within this script.