|
Page 1 of 1
|
glenflet
Joined: May 2008
Posts: 16
Location: Gosford
|
PHP Based Code To HTML With BBcode
]I wrote this PHP script to convert JAVA, PYTHON, VISUAL BASIC, and VISUAL BASIC .NET to formated html, using a style sheet.
i.e.
- // Sample Class provide to demostrate how to create Abritute methods in Java
- public class Sample1
- {
- // internal variables
- private int age;
- // Asscesor or Get Method
- public int getAge()
- {
- return age;
- }
- // Mutator or Set Method
- public void setAge(int value)
- {
- age = value;
- }
- }
is converted to
- <span class="Comment">// Sample Class provide to demostrate how to create Abritute methods in Java</span><br>
- <span class="Keywords">public</span> <span class="Keywords">class</span> Sample1<br>
- {<br>
- <span class="Comment">// internal variables</span><br>
- <span class="Keywords">private</span> <span class="Keywords">int</span> age<span class="Operator">;</span><br>
- <span class="Comment">// Asscesor or Get Method</span><br>
- <span class="Keywords">public</span> <span class="Keywords">int</span> getAge<span class="Operator">(</span><span class="Operator">)</span><br>
- {<br>
- <span class="Keywords">return</span> age<span class="Operator">;</span><br>
- }<br>
- <span class="Comment">// Mutator or Set Method</span><br>
- <span class="Keywords">public</span> <span class="Keywords">void</span> setAge<span class="Operator">(</span><span class="Keywords">int</span> value<span class="Operator">)</span><br>
- {<br>
- age <span class="Operator">=</span> value<span class="Operator">;</span><br>
- }<br>
- }<br>
see this page for the output to user http://learntoprogram.net84.net/ind...itute&lang=java
I want to adapt this script so that it works with both, IcyPhoenix and phpBB3 BBcode for the [Code] tag.
Can someone give me some help with this, Thank you.
Also feel free to use this code your self, under the trems of either the CDDL or GPL
Also the code takes both a string for the code input or a filename that points to a source file, it also takes a language ID.
Description: |
This is an archive of the code with all every thing I've done with it as of Sat 20 Sep 2008 11:31:31 EST. |
Download |
Filename: |
phpcode2html.tar.gz |
Filesize: |
2.97 KB |
Downloaded: |
352 Time(s) |
|
#1 Sat 20 Sep, 2008 03:36 |
|
Sponsors
|
Icy Phoenix is an open source project, you can show your appreciation and support future development by donating to the project.
|
|
Inactive User
|
Re: PHP Based Code To HTML With BBcode
Moved to "Other Mods Support" - - -
|
#2 Sat 20 Sep, 2008 08:36 |
|
glenflet
Joined: May 2008
Posts: 16
Location: Gosford
|
Re: PHP Based Code To HTML With BBcode
I worked out how to do this with pbpBB3 BBcode, but I'm not sure how to do it with Icy Phoenix, can some one help m
EDIT: Tue 23 Sep, 2008 23:39
I found out My so called succes was not what it seams, the varable passing didn't work proply, it only worked because my test language was the defualt language.
So i need halp with passing, singal variable to phpBB3 BBcode, I aslo need to known how if possible to pass mulitable variables in phpBB3.
|
#3 Tue 23 Sep, 2008 08:09 |
|
Mighty Gorgon
Luca Libralato
Joined: August 2006
Posts: 7191
Location: Borgo San Michele
|
Re: PHP Based Code To HTML With BBcode
Hi,
to be able to use these scripts within Icy Phoenix you need to alter bbcode.php and add highlighting there.
You can refer to CODE part in that file and apply what you need.
Regarding phpBB 3... I don't know.
____________ Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
|
#4 Thu 25 Sep, 2008 10:02 |
|
Inactive User
|
Re: PHP Based Code To HTML With BBcode
It may also be helpful if you add your attachments in .zip format only - Not everyone uses exotic compression.
|
#5 Thu 25 Sep, 2008 11:41 |
|
glenflet
Joined: May 2008
Posts: 16
Location: Gosford
|
Re: PHP Based Code To HTML With BBcode
I Include the followign file in the BBcode.php
<?php
/**
*
* @package PHPCode2Html
* @version 1.0
* @copyright (c) 2008 Glen Fletcher
* @license DUAL LICENSE CDDL+GPL (http://www.opensource.org/licenses/cddl1.php, Common Development and Distribution License (CDDL)) & (http://opensource.org/licenses/GPL-license.php GNU Public License)
*
*/
include("phpjava2html.php");
include("phppython2html.php");
include("phpvb2html.php");
include("phpvb_net2html.php");
/**
*
* Main Function
*
*
* @param $filename - The Filename of the source file
* @param $lang - The Language of the source file, string = "JAVA", "PYTHON", "VB", or "VB.NET" assumes JAVA
*
* @return The Content of the source file in html format.
*/
function source2html($filename, $lang = "JAVA")
{
$line = "";
if (file_exists($filename))
{
$file = fopen($filename, "r");
while (!feof($file))
{
$line = fgets($file,4096);
$lines = $lines . $line;
}
fclose($file);
$lines = code2html($lines, $lang);
}
return $lines;
}
/**
*
* Code Converter
*
*
* @param $lines - The Source Code
* @param $lang - The Language of the source file, string = "JAVA", "PYTHON", "VB", or "VB.NET" assumes JAVA
*
* @return The Content of the source file in html format.
*/
function code2html($lines, $lang = "JAVA")
{
$lines = ereg_replace("<", "<", $lines);
$lines = ereg_replace(">", ">", $lines);
switch ($lang)
{
case "JAVA":
$lines = java2html($lines);
break;
case "PYTHON":
$lines = python2html($lines);
break;
case "VB":
$lines = vb2html($lines);
break;
case "VB.NET":
$lines = vb_net2html($lines);
break;
default: // Assume Java, if fail
$lines = java2html($lines);
break;
}
return $lines;
}
?>
I put the following in the syntax = php if statment
else
{
$text = code2html($text,strtoupper($item['params']['syntax']));
}
However when I tested it with lang = python, I get a blank code box, wwhy would this happen
I got the following HTML Output
div class="code"><div class="code-header" id="codehdr2_2789d6ba" style="position: relative;">Code: [<a href="javascript:void(0)" onclick="ShowHide('code_2789d6ba','code2_2789d6ba',''); ShowHide('codehdr_2789d6ba', 'codehdr2_2789d6ba', '')">Hide</a>]</div><div class="code-header" id="codehdr_2789d6ba" style="position: relative; display: none;">Code: [<a href="javascript:void(0)" onclick="ShowHide('code_2789d6ba','code2_2789d6ba','');ShowHide('codehdr_2789d6ba','codehdr2_2789d6ba','')">Show</a>]</div><div class="code-content" id="code_2789d6ba" style="position: relative;"><ol class="code-list" start="1"></ol></div></div>
from
[code linenumbers=true syntax=python]def Hello():
return "Hello World"[/code]
|
#6 Fri 26 Sep, 2008 04:18 |
|
Mighty Gorgon
Luca Libralato
Joined: August 2006
Posts: 7191
Location: Borgo San Michele
|
Re: PHP Based Code To HTML With BBcode
Try to add your code here:
$php_syntax = false;
if(isset($item['params']['syntax']))
{
if ($item['params']['syntax'] == 'php')
{
$html = strtr($text, array_flip(get_html_translation_table(HTML_ENTITIES)));
$html = highlight_string($html, true);
$html_search = array('<code>', '</code>', '<font color="', '</font', ' ', '<code style="color:#0000BB"></code>', '<code style="color:#0000BB"> </code>');
$xhtml_replace = array('', '', '<code style="color:', '</code', ' ', '', '');
$html = str_replace ($html_search, $xhtml_replace, $html);
$php_syntax = true;
}
}
Add an elseif statement to check the syntax you want to apply, and then just apply the function to $html var.
Remember that we are in linenumbers = false now... but first try to apply the code there just to check if it works, then we will try to extend it to other parts.
____________ Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
|
#7 Fri 26 Sep, 2008 13:16 |
|
glenflet
Joined: May 2008
Posts: 16
Location: Gosford
|
Re: PHP Based Code To HTML With BBcode
Ok I've got every thing working now, thanks for the help.
How to Install this BBcode
EXTRACT phpcode2html.zip to includes/phpcode2html/
COPY code.css to templates/mg_themes/
OPEN includes/BBcode.php
FIND
global $db, $board_config, $phpbb_root_path, $phpEx, $lang;
ADD AFTER
include($phpbb_root_path . 'includes/phpcode2html/phpcode2html.'. $phpEx);
FIND
$html_search = array('<font color="', '</font', ' ', '<code style="color:#0000BB"></code>', '<code style="color:#0000BB"> </code>', '> <');
$xhtml_replace = array('<code style="color:', '</code', ' ', '', '', '> <');
$html = str_replace($html_search, $xhtml_replace, $html);
//PHP Highlight - End
}
ADD AFTER
else
{
$text = html_entity_decode($text);
$text = ereg_replace(html_entity_decode(" ")," ",$text);
//Add Span based Code highlighting using style sheets
$html = code2html($text,strtoupper($item['params']['syntax']));
$html = ereg_replace("<br />n", " </span></li>n<li class="code-row"><span class="code-row-text">",$html);
$html = "<li class="code-row"><span class="code-row-text">" . $html;
}
FIND
if ($item['params']['syntax'] == 'php')
{
$html = strtr($text, array_flip(get_html_translation_table(HTML_ENTITIES)));
$html = highlight_string($html, true);
$html_search = array('<code>', '</code>', '<font color="', '</font', ' ', '<code style="color:#0000BB"></code>', '<code style="color:#0000BB"> </code>');
$xhtml_replace = array('', '', '<code style="color:', '</code', ' ', '', '');
$html = str_replace ($html_search, $xhtml_replace, $html);
$php_syntax = true;
}
ADD AFTER
else
{
$text = html_entity_decode($text);
$text = ereg_replace(html_entity_decode(" ")," ",$text);
//Add Span based Code highlighting using style sheets
$html = code2html($text,strtoupper($item['params']['syntax']));
$code_syntax = true;
}
FIND ALL
REPLACE WITH
OPEN templates/mg_themes/
FIND
ADD AFTER
NOTE You need to repeat this step for any other installed styles, Also, if you have other style directory's code.css should be copyed to them as well
Description: |
Code highlighting style sheet |
Download |
Filename: |
code.css.zip |
Filesize: |
260 Bytes |
Downloaded: |
324 Time(s) |
Description: |
Special Version of phpcode2html designed for use with BBcode there are a few necessary changes to my original code |
Download |
Filename: |
phpcode2html.zip |
Filesize: |
7.2 KB |
Downloaded: |
309 Time(s) |
Last edited by glenflet on Mon 29 Sep, 2008 03:11; edited 2 times in total |
#8 Sat 27 Sep, 2008 05:13 |
|
Mighty Gorgon
Luca Libralato
Joined: August 2006
Posts: 7191
Location: Borgo San Michele
|
Re: PHP Based Code To HTML With BBcode
That's nice, thanks for sharing.
I will move this to Icy Phoenix Customizations.
____________ Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
|
#9 Sun 28 Sep, 2008 12:03 |
|
xmenfile
Joined: September 2007
Posts: 482
Location: Right in front of my computer
|
Re: PHP Based Code To HTML With BBcode
Thanks for this mod. I have installed and get this message
Parse error: syntax error, unexpected T_STRING in /home1/vietnico/public_html/test/includes/bbcode.php on line 2333
I looked at my bbcode. php and it's this line and not sure this a typo or not.
$html = ereg_replace("<br />n", " </span></li>n<li class="code-row"><span class="code-row-text">",$html);
Let me know,
Thank you,
xmenfile
|
#10 Sun 28 Sep, 2008 17:04 |
|
glenflet
Joined: May 2008
Posts: 16
Location: Gosford
|
Re: PHP Based Code To HTML With BBcode
Sorry that was a small error on my part
I losted the escape charaters when I copyied the code into the post.
change
$html = ereg_replace("<br />n", " </span></li>n<li class="code-row"><span class="code-row-text">",$html);
to
$html = ereg_replace("<br />n", " </span></li>n<li class="code-row"><span class="code-row-text">",$html);
also change your next line to the following it will be incorret as well
$html = "<li class="code-row"><span class="code-row-text">" . $html;
|
#11 Mon 29 Sep, 2008 03:07 |
|
glenflet
Joined: May 2008
Posts: 16
Location: Gosford
|
Re: PHP Based Code To HTML With BBcode
I've Recently Made Several improvements to PHP Code 2 Html, so if your useing it you may want to update to this version it has no known errors.
Description: |
PHP Code 2 Html Ver. 1.2 |
Download |
Filename: |
phpcode2html.zip |
Filesize: |
7.23 KB |
Downloaded: |
240 Time(s) |
|
#12 Mon 06 Oct, 2008 10:18 |
|
Mighty Gorgon
Luca Libralato
Joined: August 2006
Posts: 7191
Location: Borgo San Michele
|
Re: PHP Based Code To HTML With BBcode
Thanks for sharing, I'm sure CODING dedicated forums will appreciate this.
Good job.
____________ Luca
SEARCH is the quickest way to get support.
Icy Phoenix ColorizeIt - CustomIcy - HON
|
#13 Fri 10 Oct, 2008 13:14 |
|
|
Page 1 of 1
|
Was this topic useful?
Was this topic useful?
Link this topic |
URL |
|
BBCode |
|
HTML |
|
You cannot post new topics You cannot reply to topics You cannot edit your posts You cannot delete your posts You cannot vote in polls You cannot attach files You can download files You cannot post calendar events
|
|
|
|