Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 830 → Rev 831

/trunk/client/phorum/bibliotheque/phorum/mods/bbcode/settings.php
New file
0,0 → 1,44
<?php
// this Settings file was hacked together from the example module
// kindly created by Chris Eaton (tridus@hiredgoons.ca)
// Update history:
// Checkboxes added for "links in window" and "anti-spam tags" by Adam Sheik (www.cantonese.sheik.co.uk)
 
if(!defined("PHORUM_ADMIN")) return;
 
// save settings
if(count($_POST)){
$PHORUM["mod_bb_code"]["links_in_new_window"]=$_POST["links_in_new_window"] ? 1 : 0;
$PHORUM["mod_bb_code"]["rel_no_follow"]=$_POST["rel_no_follow"] ? 1 : 0;
$PHORUM["mod_bb_code"]["quote_hook"]=$_POST["quote_hook"] ? 1 : 0;
 
if(!phorum_db_update_settings(array("mod_bb_code"=>$PHORUM["mod_bb_code"]))){
$error="Database error while updating settings.";
}
else {
echo "Settings Updated<br />";
}
}
 
include_once "./include/admin/PhorumInputForm.php";
$frm =& new PhorumInputForm ("", "post", "Save");
$frm->hidden("module", "modsettings");
$frm->hidden("mod", "bbcode"); // this is the directory name that the Settings file lives in
 
if (!empty($error)){
echo "$error<br />";
}
$frm->addbreak("Edit settings for the BBCode module");
$frm->addmessage("When users post links on your forum, you can choose whether they open in a new window.");
$frm->addrow("Open links in new window: ", $frm->checkbox("links_in_new_window", "1", "", $PHORUM["mod_bb_code"]["links_in_new_window"]));
$frm->addmessage("Enable <a href=\"http://en.wikipedia.org/wiki/Blog_spam\" target=\"_blank\">
Google's new anti-spam protocol</a> for links posted on your forums.
<br/>
Note, this doesn't stop spam links being posted, but it does mean that
spammers don't get credit from Google from that link.");
$frm->addrow("Use 'rel=nofollow' anti-spam tag: ", $frm->checkbox("rel_no_follow", "1", "", $PHORUM["mod_bb_code"]["rel_no_follow"]));
$frm->addmessage("As of Phorum 5.1, there is the option to have quoted text altered by modules. Since it only makes sense to have one module modifying the quoted text, you can disable this one part of this module.");
 
$frm->addrow("Enable quote hook", $frm->checkbox("quote_hook", "1", "", $PHORUM["mod_bb_code"]["quote_hook"]));
$frm->show();
?>
/trunk/client/phorum/bibliotheque/phorum/mods/bbcode/info.txt
New file
0,0 → 1,4
hook: format|phorum_bb_code
hook: quote|phorum_bb_code_quote
title: BB Code Phorum Mod
desc: This module converts BB Code into HTML.
/trunk/client/phorum/bibliotheque/phorum/mods/bbcode/bbcode.php
New file
0,0 → 1,150
<?php
 
if(!defined("PHORUM")) return;
 
// BB Code Phorum Mod
function phorum_bb_code($data)
{
$PHORUM = $GLOBALS["PHORUM"];
 
$search = array(
"/\[img\]((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%# ]+?)\[\/img\]/is",
"/\[url\]((http|https|ftp|mailto):\/\/([a-z0-9\.\-@:]+)[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),\#%~ ]*?)\[\/url\]/is",
"/\[url=((http|https|ftp|mailto):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%# ]+?)\](.+?)\[\/url\]/is",
"/\[email\]([a-z0-9\-_\.\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+?)\[\/email\]/ies",
"/\[color=([\#a-z0-9]+?)\](.+?)\[\/color\]/is",
"/\[size=([+\-\da-z]+?)\](.+?)\[\/size\]/is",
"/\[b\](.+?)\[\/b\]/is",
"/\[u\](.+?)\[\/u\]/is",
"/\[i\](.+?)\[\/i\]/is",
"/\[s\](.+?)\[\/s\]/is",
"/\[center\](.+?)\[\/center\]/is",
"/\[hr\]/i",
"/\[code\](.+?)\[\/code\]/is",
"/\[sub\](.+?)\[\/sub\]/is",
"/\[sup\](.+?)\[\/sup\]/is",
);
 
// add extra tags to links, if enabled in the admin settings page
 
$extra_link_tags = "";
 
if(isset($PHORUM["mod_bb_code"])){ // check for settings file before using settings-dependent variables
if ($PHORUM["mod_bb_code"]["links_in_new_window"]){
$extra_link_tags .= "target=\"_blank\" ";
}
if ($PHORUM["mod_bb_code"]["rel_no_follow"]){
$extra_link_tags .= "rel=\"nofollow\" ";
}
}
 
$replace = array(
"<img src=\"$1\" />",
"[<a $extra_link_tags href=\"$1\">$3</a>]",
"<a $extra_link_tags href=\"$1\">$3</a>",
"'<a $extra_link_tags href=\"'.phorum_html_encode('mailto:$1').'\">'.phorum_html_encode('$1').'</a>'",
"<span style=\"color: $1\">$2</span>",
"<span style=\"font-size: $1\">$2</span>",
"<strong>$1</strong>",
"<u>$1</u>",
"<i>$1</i>",
"<s>$1</s>",
"<center class=\"bbcode\">$1</center>",
"<hr class=\"bbcode\" />",
"<pre class=\"bbcode\">$1</pre>",
"<sub class=\"bbcode\">$1</sub>",
"<sup class=\"bbcode\">$1</sup>",
);
 
$quote_search = array(
"/\[quote\]/is",
"/\[quote ([^\]]+?)\]/is",
"/\[quote=([^\]]+?)\]/is",
"/\[\/quote\]/is"
);
 
$quote_replace = array(
"<blockquote class=\"bbcode\">".$PHORUM["DATA"]["LANG"]["Quote"] . ":<div>",
"<blockquote class=\"bbcode\">".$PHORUM["DATA"]["LANG"]["Quote"] . ":<div><strong>$1</strong><br />",
"<blockquote class=\"bbcode\">".$PHORUM["DATA"]["LANG"]["Quote"] . ":<div><strong>$1</strong><br />",
"</div></blockquote>"
);
 
foreach($data as $message_id => $message){
 
if(isset($message["body"])){
 
// do BB Code here
$body = $message["body"];
 
$rnd=substr(md5($body.time()), 0, 4);
 
// convert bare urls into bbcode tags as best we can
// the haystack has to have a space in front of it for the preg to work.
$body = preg_replace("/([^='\"(\[url\]|\[img\])])((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%#]+)/i", "$1:$rnd:$2:/$rnd:", " $body");
 
// stip puncuation from urls
if(preg_match_all("!:$rnd:(.+?):/$rnd:!i", $body, $match)){
 
$urls = array_unique($match[1]);
 
foreach($urls as $key => $url){
// stip puncuation from urls
if(preg_match("|[^a-z0-9=&/\+_]+$|i", $url, $match)){
 
$extra = $match[0];
$true_url = substr($url, 0, -1 * (strlen($match[0])));
 
$body = str_replace("$url:/$rnd:", "$true_url:/$rnd:$extra", $body);
 
$url = $true_url;
}
 
$body = str_replace(":$rnd:$url:/$rnd:", "[url]{$url}[/url]", $body);
}
 
}
 
// no sense doing any of this if there is no [ in the body
if(strstr($body, "[")){
 
// convert bare email addresses into bbcode tags as best we can.
$body = preg_replace("/([a-z0-9][a-z0-9\-_\.\+]+@[a-z0-9\-]+\.[a-z0-9\-\.]+[a-z0-9])/i", "[email]$1[/email]", $body);
 
// clean up any BB code we stepped on.
$body = str_replace("[email][email]", "[email]", $body);
$body = str_replace("[/email][/email]", "[/email]", $body);
 
// fiddle with white space around quote and code tags.
$body=preg_replace("/\s*(\[\/*(code|quote)\])\s*/", "$1", $body);
 
// run the pregs defined above
$body = preg_replace($search, $replace, $body);
 
// quote has to be handled differently because they can be embedded.
// we only do quote replacement if we have matching start and end tags
if(strstr($body, "[quote") && substr_count($body, "[quote")==substr_count($body, "[/quote]")){
$body = preg_replace($quote_search, $quote_replace, $body);
}
 
 
}
 
 
$data[$message_id]["body"] = $body;
}
}
 
return $data;
}
 
 
function phorum_bb_code_quote ($array)
{
$PHORUM = $GLOBALS["PHORUM"];
 
if(isset($PHORUM["mod_bb_code"]) && $PHORUM["mod_bb_code"]["quote_hook"]){
return "[quote $array[0]]$array[1][/quote]";
}
}
?>