TutorialMS Community Forum

Full Version: [MOD] Create your own tags for custom tutorials
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
You will need to know PHP to make your own but you should be able to follow the example if you don't. This example will show you how you can make a tag that will allow HTML.

Open /includes/classes/template.php and go to the bottom (if you haven't changed this script it is line 835), and right before the part that says "// change the url tags", put this code

Code:
// allow HTML
      preg_match_all('/\[html](.*)\[\/html\]/sU', $code, $html_values);
      $number_html = count($html_values[1]);
      $i = 0;
      while($i < $number_html) {
         $full_html = html_entity_decode($html_values[1][$i]);
         $code = str_replace('[html]'.$html_values[1][$i].'[/html]', $full_html, $code);  
         $i++;
}


This will allow you to allow html between the tags [html][/html], of course if you want to make your own tag then you can modify this bit or add it again, to whatever you want to have (if you know PHP)

Now save that.

Open /admin/add_own_tutorials.php and go to line 181 if you haven't edited it. If you have edited it, then I am showing the 4 lines that are already there, so add the lines I have marked. Also open /admin/edit_own_tutorials but instead of line 181, it is line 193, do the same thing.

Code:
tags[24] = '[size=]';
tags[25] = '[/size]';
tags[26] = false;
tags[27] = '[page /]';
// ADD THESE LINES BELOW
tags[28] = '[html]';
tags[29] = '[/html]';
tags[30] = false;
// ADD THESE LINES ABOVE

Now go to line 253 (if you have added the part above), and add the marked line.
Also go to line 271, in /admin/edit_own_tutorials.php, and do the same thing.

Code:
<a href="java script:OnTagButtonClick(9)"><img style="border: 1px solid #b5ddff;" border="0" src="images/buttons/image.jpg" /></a>
<a href="java script:OnTagButtonClick(15)"><img style="border: 1px solid #b5ddff;" border="0" src="images/buttons/code.jpg" /></a>
// ADD THIS LINE BELOW
<a href="java script:OnTagButtonClick(28)">HTML</a>
// ADD THIS LINE ABOVE
Note: remove the spaces in javascript, I had to do that so this would post.

Now it will have a text link to add the [html] tag and it will show as HTML in your custom tutorial.
do the same with edit_own_tutorials.php
Here is how to add the bbcode underline to your tutorials:
Before you begin back up all of your work!
Open includes/classes/template.php
Find
Code:
// change the url tags

Before Add
Code:
// allow underline
              preg_match_all('/\[u](.*)\[\/u\]/sU', $code, $underline_values);
              $number_underline = count($underline_values[1]);
              $i = 0;
              while($i < $number_underline) {
                 $full_underline = '<u>'.$underline_values[1][$i].'</u>';
                 $code = str_replace('[u]'.$underline_values[1][$i].'[/u]', $full_underline, $code);  
                 $i++;
        }

Open admin/add_own_tutorial.php + admin/edit_own_tutorial.php
Find
Code:
tags[27] = '[page /]';

After Add
Code:
tags[28] = '[u]';
tags[29] = '[/u]';
tags[30] = false;

Find
Code:
<a href="javascript:OnTagButtonClick(15)"><img style="border: 1px solid #b5ddff;" border="0" src="images/buttons/code.jpg"  /></a>

After Add
Code:
<a href="javascript:OnTagButtonClick(28)"><img style="border: 1px solid #b5ddff;" border=:"0" src=
"images/buttons/underline.gif" alt="Underline" /></a>

The following image may be used unless you decide to use an alternative
[Image: underline.gif]

Save
Upload Files to Server
Thanks to the help of Scott here is how you can add youtube videos via bbcode into tutorials. Before you begin remeber to back up all of your work in case a mistake is made somewhere!

Open includes/classes/template.php
Find

Code:
// change the url tags

Before Add

Code:
// add youtube video
      if(preg_match_all('/\[youtube\](.*)\[\/youtube\]/sU', $code, $youtube_values)) {
         $number_youtube = count($youtube_values[1]);
         $i = 0;
         while($i < $number_youtube) {
            $full_youtube = '<object width="425" height="350">
   <param name="movie" value="http://www.youtube.com/v/'.$youtube_values[1][$i].'"></param>
   <embed src="http://www.youtube.com/v/'.$youtube_values[1][$i].'" type="application/x-shockwave-flash" width="425" height="350"></embed>
</object>
<a href="http://youtube.com/watch?v='.$youtube_values[1][$i].'" target="_blank">'.$youtube_values[2][$i].'</a>';
            $code = str_replace('[youtube]'.$youtube_values[1][$i].'[/youtube]', $full_youtube, $code);
            $i++;
         }
        }


Open admin/add_own_tutorial.php + admin/edit_own_tutorial.php
Find

Code:
tags[27] = '[page /]';

After Add

Code:
tags[28] = '[youtube]';
tags[29] = '[/youtube]';
tags[30] = false;

Find

Code:
<a href="javascript:OnTagButtonClick(15)"><img style="border: 1px solid #b5ddff;" border="0" src="images/buttons/code.jpg"  /></a>

After Add

Code:
<a href="javascript:OnTagButtonClick(31)"><img style="border: 1px solid #b5ddff;" border=:"0" src=
"images/buttons/youtube.jpg" alt="Youtube" /></a>

The following image may be used unless you decide to use an alternative
[Image: youtube.jpg]

Save
Upload Files to Server
Hey Scott,
Ran into a slight problem here. My background color for the web page is black and the text for everything with the bb 'code' tag is black, making the text seem invisible. My text throught out the site is white and I would prefer for the text code to be white as well, or possibly even black. I am able to change the text color of "Code:" by means of adding a color attribute to the div in the template read_tutorial_code_tags. How ever, you are unable to give the other text below "Code:" and the break line a color.

Any idea how I will be able to give this text a color?

Thanks in advance,
Kevin
Can you post a link to the page you are referring to.
http://tuthut.net/tutorials/read_tutorial/36/

Notice how the code text is black. I would like to change that color.
Well the highlighter uses the PHP function highlight_string ( http://ca3.php.net/highlight_string ).

So you can do one of the following things:

- Change the background color for code to white (or any light colour)
- Remove the highlight_string() function (I will give you the file and line # if you want that), and set all code as one colour
- Set the colours used by highlight_string() using a php.ini file or ini_set() function
Can we go with option 2 or 3? #2 sounds a bit more easier but if you could just explain a little what I will need to do and where I think I can manage.
Thanks for your time.
It is on line #707 in /includes/classes/template.php

It should look like

Code:
$highlight_code = highlight_string(html_entity_decode(preg_replace('/\<br \/\>/', '', $code_values[1][$i])), true);

but be changed to
Code:
$highlight_code = html_entity_decode(preg_replace('/\<br \/\>/', '', $code_values[1][$i]));
Pages: 1 2 3
Reference URL's