Les archives de FluxBB.fr
Vous n'êtes pas identifié(e).
Pages : 1
Auteur : PascL
Cette mod permet d'afficher en infobulle la définition d'un mot au survol de celui-ci.
Les mots et les définitions correspondantes sont enregistrés dans la base de données à partir du plugin d'administration. Du BBcode peut être inséré dans les définitions.
L'affichage des définitions ne se fait que dans viewtopic (pas dans les prévisualisations de post ou edit) et peuvent être activés/désactivés dans le plugin d'administration.
L'affichage se fait par OverLib, en Javascript, celui-ci doit être activé pour voir les définitions.
Bouh !
StarShip Renaissance
Hors ligne
Ceci est une très bonne idée je le met en place dès demain 
Tu l'a deja installer sur un forum ou l'on peut voir une démo ?
Hors ligne
Un petit exemple en image :
Attention, c'est sensible à la casse.
Par exemple, entrez W3C dans la base de données ne fera pas s'afficher l'infobulle pour w3c ou W3c ou w3C.
Idée venant de là : http://www.punbb.fr/forums/viewtopic.php?id=6743
Dernière modification par PascL (19-01-2008 23:02:09)
Bouh !
StarShip Renaissance
Hors ligne
Tu pense qu'il y aurais moyen d'apporter des modifications afin que les min/maj soit ignorées ?
Cela serait judicieux non ? tu doit y avoir pensé je suppose.
Hors ligne
Intéressant. Si je comprend bien c'est un peu comme le remplacement des mots sauf que au lieu de les remplacer, ça créer une "Mini-Page" en javascript.
Pas mal.
M@x.
...
Hors ligne
L'installation est simple et rapide, cela ma pris 1 minute.
A noter qu'il faut changer le nom du plugin dans ~/plugins/ pour pouvoir l'activer dans la panneau d'administration. En tout cas moi il me l'a demandé 
Changer AMP_PunDef.php par AP_PunDef.php
Bonnes continuations à tous.
Hors ligne
Tit pierre :
pour les min/maj, ça doit être faisable en utilisant preg_replace au lieu de str_replace mais je me suis pas penché dessus.
pour le nom du plugin, j'ai corrigé le nom du fichier en ligne. Merci de l'info.
M@x :
Je préfère dire qu'OverLib est une infobulle qui accepte le HTML (et qu'on peut copier/coller) plutôt que mini-page 
Bouh !
StarShip Renaissance
Hors ligne
Ou avec str_ireplace sous php5.
Hors ligne
C'est beau la php mania 
Hors ligne
Salut,
dans ton lisezmoi.txt a la ligne :
#---------[ 14. BEFORE, ADD ]---------------------------------------------
#
require PUN_ROOT.'include/parser.php';
/* PUNDEF START */
if($pun_config['o_pundef'] == '1')
...
j'ai du commenter la ligne : require PUN_ROOT.'include/parser.php';
sinon ca me mettais une erreur.
Sinon ton mod est bien sympathique. Il serait encore plus interressant si le mot clé pouvait être automatique souligné. Sinon on ne peut pas savoir qu'il y a un "lien".
Si c'est moi qui poste, ok je penserais a souligner le mot, mais pour les autres posteurs qui ne savent pas que j'ai mis une definition sur ce mot.
Dernière modification par zimzag (07-02-2008 20:53:08)
Hors ligne
il suffit de modifier ton css pour souligner les liens dans les messages
Hors ligne
YEAH ! super pascL !
kendo-iaido.fr
Hors ligne
le plus rapide et le plus vilain que j'ai trouvé c'est l'horrible balise <u></u>
/* PUNDEF START */
function pun_def($msg,$hide_smilies,$nombre,$mot,$definition)
{
$a = "<u><a onmouseover=\"return overlib('";
$b = "', STICKY, MOUSEOFF);\" onmouseout=\"return nd();\">";
$c = "</a></u>";
...
Hors ligne
J'ai eu un problème de récursivité avec ce mod.
Si la définition d'un acronyme utilise un autre acronyme déjà définit qui fait également appel a ce dernier, ça plantouille et ca affiche le code au lieu de la définition.
ex: je crée l'acronyme TEST qui contient le mot : PATATE
puis ensuite je crée l'acronyme PATATE qui contient le mot : TEST
Pour finir j'ecris dans mon message les 2 acronymes TEST et PATATE
Ca fait planter le mod.
Dernière modification par zimzag (22-02-2008 19:00:02)
Hors ligne
bonjour,
cela ne semble pas marcher avec la version 1.2.21, pourtant le lien est généré mais la bulle ne s'affiche pas. Quelqu'un a réussi de la faire marcher avec la 1.2.21?
merci
Hors ligne
J'ai essayé sur une version flubb 1.4.7, évidement ça ne marche pas.
Est-ce que quelqu'un se sent de faire une adaptation pour fluxbb 1.4.xx ?
Hors ligne
Bon j'ai essayé plusieurs fois et je me casse les dents, j'essaye de me dépatouiller avec le code mais mes connaissances sont limitées.
En clair une fois tout installé une erreur apparait quand j'essaye d'aller sur une discussion :
Dans l'administration j'ai la possibilité de désactiver le plugin, le problème persiste.
Voici mon parser :
<?php
/**
* Copyright (C) 2008-2012 FluxBB
* based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
et mon viewtopic (car j'ai l'impression que le problème est plus ici)
[code]<?php
/**
* Copyright (C) 2008-2012 FluxBB
* based on code by Rickard Andersson copyright (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
define('PUN_ROOT', dirname(__FILE__).'/');
require PUN_ROOT.'include/common.php';
if ($pun_user['g_read_board'] == '0')
message($lang_common['No view']);
$action = isset($_GET['action']) ? $_GET['action'] : null;
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
$pid = isset($_GET['pid']) ? intval($_GET['pid']) : 0;
if ($id < 1 && $pid < 1)
message($lang_common['Bad request']);
// Load the viewtopic.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
require PUN_ROOT.'include/parser.php';
// If a post ID is specified we determine topic ID and page number so we can redirect to the correct message
if ($pid)
{
$result = $db->query('SELECT topic_id, posted FROM '.$db->prefix.'posts WHERE id='.$pid) or error('Unable to fetch topic ID', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message($lang_common['Bad request']);
list($id, $posted) = $db->fetch_row($result);
// Determine on what page the post is located (depending on $forum_user['disp_posts'])
$result = $db->query('SELECT COUNT(id) FROM '.$db->prefix.'posts WHERE topic_id='.$id.' AND posted<'.$posted) or error('Unable to count previous posts', __FILE__, __LINE__, $db->error());
$num_posts = $db->result($result) + 1;
$_GET['p'] = ceil($num_posts / $pun_user['disp_posts']);
}
// If action=new, we redirect to the first new post (if any)
else if ($action == 'new')
{
if (!$pun_user['is_guest'])
{
// We need to check if this topic has been viewed recently by the user
$tracked_topics = get_tracked_topics();
$last_viewed = isset($tracked_topics['topics'][$id]) ? $tracked_topics['topics'][$id] : $pun_user['last_visit'];
$result = $db->query('SELECT MIN(id) FROM '.$db->prefix.'posts WHERE topic_id='.$id.' AND posted>'.$last_viewed) or error('Unable to fetch first new post info', __FILE__, __LINE__, $db->error());
$first_new_post_id = $db->result($result);
if ($first_new_post_id)
{
header('Location: viewtopic.php?pid='.$first_new_post_id.'#p'.$first_new_post_id);
exit;
}
}
// If there is no new post, we go to the last post
header('Location: viewtopic.php?id='.$id.'&action=last');
exit;
}
// If action=last, we redirect to the last post
else if ($action == 'last')
{
$result = $db->query('SELECT MAX(id) FROM '.$db->prefix.'posts WHERE topic_id='.$id) or error('Unable to fetch last post info', __FILE__, __LINE__, $db->error());
$last_post_id = $db->result($result);
if ($last_post_id)
{
header('Location: viewtopic.php?pid='.$last_post_id.'#p'.$last_post_id);
exit;
}
}
// Fetch some info about the topic
if (!$pun_user['is_guest'])
$result = $db->query('SELECT t.subject, t.closed, t.num_replies, t.sticky, t.first_post_id, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, s.user_id AS is_subscribed FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'topic_subscriptions AS s ON (t.id=s.topic_id AND s.user_id='.$pun_user['id'].') LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
else
$result = $db->query('SELECT t.subject, t.closed, t.num_replies, t.sticky, t.first_post_id, f.id AS forum_id, f.forum_name, f.moderators, fp.post_replies, 0 AS is_subscribed FROM '.$db->prefix.'topics AS t INNER JOIN '.$db->prefix.'forums AS f ON f.id=t.forum_id LEFT JOIN '.$db->prefix.'forum_perms AS fp ON (fp.forum_id=f.id AND fp.group_id='.$pun_user['g_id'].') WHERE (fp.read_forum IS NULL OR fp.read_forum=1) AND t.id='.$id.' AND t.moved_to IS NULL') or error('Unable to fetch topic info', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($result))
message($lang_common['Bad request']);
$cur_topic = $db->fetch_assoc($result);
// Sort out who the moderators are and if we are currently a moderator (or an admin)
$mods_array = ($cur_topic['moderators'] != '') ? unserialize($cur_topic['moderators']) : array();
$is_admmod = ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_moderator'] == '1' && array_key_exists($pun_user['username'], $mods_array))) ? true : false;
// Can we or can we not post replies?
if ($cur_topic['closed'] == '0')
{
if (($cur_topic['post_replies'] == '' && $pun_user['g_post_replies'] == '1') || $cur_topic['post_replies'] == '1' || $is_admmod)
$post_link = "\t\t\t".'<p class="postlink conr"><a href="post.php?tid='.$id.'">'.$lang_topic['Post reply'].'</a></p>'."\n";
else
$post_link = '';
}
else
{
$post_link = $lang_topic['Topic closed'];
if ($is_admmod)
$post_link .= ' / <a href="post.php?tid='.$id.'">'.$lang_topic['Post reply'].'</a>';
$post_link = "\t\t\t".'<p class="postlink conr">'.$post_link.'</p>'."\n";
}
// Add/update this topic in our list of tracked topics
if (!$pun_user['is_guest'])
{
$tracked_topics = get_tracked_topics();
$tracked_topics['topics'][$id] = time();
set_tracked_topics($tracked_topics);
}
// Determine the post offset (based on $_GET['p'])
$num_pages = ceil(($cur_topic['num_replies'] + 1) / $pun_user['disp_posts']);
$p = (!isset($_GET['p']) || $_GET['p'] <= 1 || $_GET['p'] > $num_pages) ? 1 : intval($_GET['p']);
$start_from = $pun_user['disp_posts'] * ($p - 1);
// Generate paging links
$paging_links = '<span class="pages-label">'.$lang_common['Pages'].' </span>'.paginate($num_pages, $p, 'viewtopic.php?id='.$id);
if ($pun_config['o_censoring'] == '1')
$cur_topic['subject'] = censor_words($cur_topic['subject']);
$quickpost = false;
if ($pun_config['o_quickpost'] == '1' &&
($cur_topic['post_replies'] == '1' || ($cur_topic['post_replies'] == '' && $pun_user['g_post_replies'] == '1')) &&
($cur_topic['closed'] == '0' || $is_admmod))
{
// Load the post.php language file
require PUN_ROOT.'lang/'.$pun_user['language'].'/post.php';
$required_fields = array('req_message' => $lang_common['Message']);
if ($pun_user['is_guest'])
{
$required_fields['req_username'] = $lang_post['Guest name'];
if ($pun_config['p_force_guest_email'] == '1')
$required_fields['req_email'] = $lang_common['Email'];
}
$quickpost = true;
}
if (!$pun_user['is_guest'] && $pun_config['o_topic_subscriptions'] == '1')
{
if ($cur_topic['is_subscribed'])
// I apologize for the variable naming here. It's a mix of subscription and action I guess :-)
$subscraction = "\t\t".'<p class="subscribelink clearb"><span>'.$lang_topic['Is subscribed'].' - </span><a href="misc.php?action=unsubscribe&tid='.$id.'">'.$lang_topic['Unsubscribe'].'</a></p>'."\n";
else
$subscraction = "\t\t".'<p class="subscribelink clearb"><a href="misc.php?action=subscribe&tid='.$id.'">'.$lang_topic['Subscribe'].'</a></p>'."\n";
}
else
$subscraction = '';
if ($pun_config['o_feed_type'] == '1')
$page_head = array('feed' => '<link rel="alternate" type="application/rss+xml" href="extern.php?action=feed&tid='.$id.'&type=rss" title="'.$lang_common['RSS topic feed'].'" />');
else if ($pun_config['o_feed_type'] == '2')
$page_head = array('feed' => '<link rel="alternate" type="application/atom+xml" href="extern.php?action=feed&tid='.$id.'&type=atom" title="'.$lang_common['Atom topic feed'].'" />');
require PUN_ROOT.'include/parser.php';
/* PUNDEF START */
if($pun_config['o_pundef'] == '1')
{
$def_sql=$db->query('SELECT * FROM '.$db->prefix.'definitions') or error('Unable to fetch definitions', __FILE__, __LINE__, $db->error());
if (!$db->num_rows($def_sql))
{
}
else
{
$mot=array();
$definition=array();
$nbdef=0;
while($cur_def = $db->fetch_assoc($def_sql))
{
$mot[$nbdef]=$cur_def['mot'];
$definition[$nbdef]=pun_htmlspecialchars(parse_message($cur_def['def_over'],($pun_config['o_smilies'] == '1') ? 0 : 1));
$definition[$nbdef]=str_replace("\\","\\\\",$definition[$nbdef]); // double tous les \
$definition[$nbdef]=str_replace("'","\'",$definition[$nbdef]); // ajoute un \ à chaque apostrophe
$definition[$nbdef]=str_replace("\r","\\\r",$definition[$nbdef]); // ajoute des \ à la fin de chaque ligne
$nbdef++;
}
}
}
/* PUNDEF END */
$page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), pun_htmlspecialchars($cur_topic['forum_name']), pun_htmlspecialchars($cur_topic['subject']));
define('PUN_ALLOW_INDEX', 1);
define('PUN_ACTIVE_PAGE', 'index');
require PUN_ROOT.'header.php';
?>
<div class="linkst">
<div class="inbox crumbsplus">
<ul class="crumbs">
<li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
<li><span>» </span><a href="viewforum.php?id=<?php echo $cur_topic['forum_id'] ?>"><?php echo pun_htmlspecialchars($cur_topic['forum_name']) ?></a></li>
<li><span>» </span><a href="viewtopic.php?id=<?php echo $id ?>"><strong><?php echo pun_htmlspecialchars($cur_topic['subject']) ?></strong></a></li>
</ul>
<div class="pagepost">
<p class="pagelink conl"><?php echo $paging_links ?></p>
<?php echo $post_link ?>
</div>
<div class="clearer"></div>
</div>
</div>
<?php
//require PUN_ROOT.'include/parser.php';
$post_count = 0; // Keep track of post numbers
// Retrieve a list of post IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data
$result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$id.' ORDER BY id LIMIT '.$start_from.','.$pun_user['disp_posts']) or error('Unable to fetch post IDs', __FILE__, __LINE__, $db->error());
$post_ids = array();
for ($i = 0;$cur_post_id = $db->result($result, $i);$i++)
$post_ids[] = $cur_post_id;
if (empty($post_ids))
error('The post table and topic table seem to be out of sync!', __FILE__, __LINE__);
// Retrieve the posts (and their respective poster/online status)
$result = $db->query('SELECT u.email, u.title, u.url, u.location, u.signature, u.email_setting, u.num_posts, u.registered, u.admin_note, p.id, p.poster AS username, p.poster_id, p.poster_ip, p.poster_email, p.message, p.hide_smilies, p.posted, p.edited, p.edited_by, g.g_id, g.g_user_title, o.user_id AS is_online FROM '.$db->prefix.'posts AS p INNER JOIN '.$db->prefix.'users AS u ON u.id=p.poster_id INNER JOIN '.$db->prefix.'groups AS g ON g.g_id=u.group_id LEFT JOIN '.$db->prefix.'online AS o ON (o.user_id=u.id AND o.user_id!=1 AND o.idle=0) WHERE p.id IN ('.implode(',', $post_ids).') ORDER BY p.id', true) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
while ($cur_post = $db->fetch_assoc($result))
{
$post_count++;
$user_avatar = '';
$user_info = array();
$user_contacts = array();
$post_actions = array();
$is_online = '';
$signature = '';
// If the poster is a registered user
if ($cur_post['poster_id'] > 1)
{
if ($pun_user['g_view_users'] == '1')
$username = '<a href="profile.php?id='.$cur_post['poster_id'].'">'.pun_htmlspecialchars($cur_post['username']).'</a>';
else
$username = pun_htmlspecialchars($cur_post['username']);
$user_title = get_title($cur_post);
if ($pun_config['o_censoring'] == '1')
$user_title = censor_words($user_title);
// Format the online indicator
$is_online = ($cur_post['is_online'] == $cur_post['poster_id']) ? '<strong>'.$lang_topic['Online'].'</strong>' : '<span>'.$lang_topic['Offline'].'</span>';
if ($pun_config['o_avatars'] == '1' && $pun_user['show_avatars'] != '0')
{
if (isset($user_avatar_cache[$cur_post['poster_id']]))
$user_avatar = $user_avatar_cache[$cur_post['poster_id']];
else
$user_avatar = $user_avatar_cache[$cur_post['poster_id']] = generate_avatar_markup($cur_post['poster_id']);
}
// We only show location, register date, post count and the contact links if "Show user info" is enabled
if ($pun_config['o_show_user_info'] == '1')
{
if ($cur_post['location'] != '')
{
if ($pun_config['o_censoring'] == '1')
$cur_post['location'] = censor_words($cur_post['location']);
$user_info[] = '<dd><span>'.$lang_topic['From'].' '.pun_htmlspecialchars($cur_post['location']).'</span></dd>';
}
$user_info[] = '<dd><span>'.$lang_topic['Registered'].' '.format_time($cur_post['registered'], true).'</span></dd>';
if ($pun_config['o_show_post_count'] == '1' || $pun_user['is_admmod'])
$user_info[] = '<dd><span>'.$lang_topic['Posts'].' '.forum_number_format($cur_post['num_posts']).'</span></dd>';
// Now let's deal with the contact links (Email and URL)
if ((($cur_post['email_setting'] == '0' && !$pun_user['is_guest']) || $pun_user['is_admmod']) && $pun_user['g_send_email'] == '1')
$user_contacts[] = '<span class="email"><a href="mailto:'.$cur_post['email'].'">'.$lang_common['Email'].'</a></span>';
else if ($cur_post['email_setting'] == '1' && !$pun_user['is_guest'] && $pun_user['g_send_email'] == '1')
$user_contacts[] = '<span class="email"><a href="misc.php?email='.$cur_post['poster_id'].'">'.$lang_common['Email'].'</a></span>';
if ($cur_post['url'] != '')
{
if ($pun_config['o_censoring'] == '1')
$cur_post['url'] = censor_words($cur_post['url']);
$user_contacts[] = '<span class="website"><a href="'.pun_htmlspecialchars($cur_post['url']).'">'.$lang_topic['Website'].'</a></span>';
}
}
if ($pun_user['is_admmod'])
{
$user_info[] = '<dd><span><a href="moderate.php?get_host='.$cur_post['id'].'" title="'.$cur_post['poster_ip'].'">'.$lang_topic['IP address logged'].'</a></span></dd>';
if ($cur_post['admin_note'] != '')
$user_info[] = '<dd><span>'.$lang_topic['Note'].' <strong>'.pun_htmlspecialchars($cur_post['admin_note']).'</strong></span></dd>';
}
}
// If the poster is a guest (or a user that has been deleted)
else
{
$username = pun_htmlspecialchars($cur_post['username']);
$user_title = get_title($cur_post);
if ($pun_user['is_admmod'])
$user_info[] = '<dd><span><a href="moderate.php?get_host='.$cur_post['id'].'" title="'.$cur_post['poster_ip'].'">'.$lang_topic['IP address logged'].'</a></span></dd>';
if ($pun_config['o_show_user_info'] == '1' && $cur_post['poster_email'] != '' && !$pun_user['is_guest'] && $pun_user['g_send_email'] == '1')
$user_contacts[] = '<span class="email"><a href="mailto:'.$cur_post['poster_email'].'">'.$lang_common['Email'].'</a></span>';
}
// Generation post action array (quote, edit, delete etc.)
if (!$is_admmod)
{
if (!$pun_user['is_guest'])
$post_actions[] = '<li class="postreport"><span><a href="misc.php?report='.$cur_post['id'].'">'.$lang_topic['Report'].'</a></span></li>';
if ($cur_topic['closed'] == '0')
{
if ($cur_post['poster_id'] == $pun_user['id'])
{
if ((($start_from + $post_count) == 1 && $pun_user['g_delete_topics'] == '1') || (($start_from + $post_count) > 1 && $pun_user['g_delete_posts'] == '1'))
$post_actions[] = '<li class="postdelete"><span><a href="delete.php?id='.$cur_post['id'].'">'.$lang_topic['Delete'].'</a></span></li>';
if ($pun_user['g_edit_posts'] == '1')
$post_actions[] = '<li class="postedit"><span><a href="edit.php?id='.$cur_post['id'].'">'.$lang_topic['Edit'].'</a></span></li>';
}
if (($cur_topic['post_replies'] == '' && $pun_user['g_post_replies'] == '1') || $cur_topic['post_replies'] == '1')
$post_actions[] = '<li class="postquote"><span><a href="post.php?tid='.$id.'&qid='.$cur_post['id'].'">'.$lang_topic['Quote'].'</a></span></li>';
}
}
else
{
$post_actions[] = '<li class="postreport"><span><a href="misc.php?report='.$cur_post['id'].'">'.$lang_topic['Report'].'</a></span></li>';
$post_actions[] = '<li class="postdelete"><span><a href="delete.php?id='.$cur_post['id'].'">'.$lang_topic['Delete'].'</a></span></li>';
$post_actions[] = '<li class="postedit"><span><a href="edit.php?id='.$cur_post['id'].'">'.$lang_topic['Edit'].'</a></span></li>';
$post_actions[] = '<li class="postquote"><span><a href="post.php?tid='.$id.'&qid='.$cur_post['id'].'">'.$lang_topic['Quote'].'</a></span></li>';
}
// Perform the main parsing of the message (BBCode, smilies, censor words etc)
$cur_post['message'] = parse_message($cur_post['message'], $cur_post['hide_smilies']);
/* PUNDEF START */
if($pun_config['o_pundef'] == '1')
$cur_post['message'] = pun_def($cur_post['message'],$cur_post['hide_smilies'],$nbdef,$mot,$definition);
/* PUNDEF END */
// Do signature parsing/caching
if ($pun_config['o_signatures'] == '1' && $cur_post['signature'] != '' && $pun_user['show_sig'] != '0')
{
if (isset($signature_cache[$cur_post['poster_id']]))
$signature = $signature_cache[$cur_post['poster_id']];
else
{
$signature = parse_signature($cur_post['signature']);
$signature_cache[$cur_post['poster_id']] = $signature;
}
}
?>
<div id="p<?php echo $cur_post['id'] ?>" class="blockpost<?php echo ($post_count % 2 == 0) ? ' roweven' : ' rowodd' ?><?php if ($cur_post['id'] == $cur_topic['first_post_id']) echo ' firstpost'; ?><?php if ($post_count == 1) echo ' blockpost1'; ?>">
<h2><span><span class="conr">#<?php echo ($start_from + $post_count) ?></span> <a href="viewtopic.php?pid=<?php echo $cur_post['id'].'#p'.$cur_post['id'] ?>"><?php echo format_time($cur_post['posted']) ?></a></span></h2>
<div class="box">
<div class="inbox">
<div class="postbody">
<div class="postleft">
<dl>
<dt><strong><?php echo $username ?></strong></dt>
<dd class="usertitle"><strong><?php echo $user_title ?></strong></dd>
<?php if ($user_avatar != '') echo "\t\t\t\t\t\t".'<dd class="postavatar">'.$user_avatar.'</dd>'."\n"; ?>
<?php if (count($user_info)) echo "\t\t\t\t\t\t".implode("\n\t\t\t\t\t\t", $user_info)."\n"; ?>
<?php if (count($user_contacts)) echo "\t\t\t\t\t\t".'<dd class="usercontacts">'.implode(' ', $user_contacts).'</dd>'."\n"; ?>
</dl>
</div>
<div class="postright">
<h3><?php if ($cur_post['id'] != $cur_topic['first_post_id']) echo $lang_topic['Re'].' '; ?><?php echo pun_htmlspecialchars($cur_topic['subject']) ?></h3>
<div class="postmsg">
<?php echo $cur_post['message']."\n" ?>
<?php if ($cur_post['edited'] != '') echo "\t\t\t\t\t\t".'<p class="postedit"><em>'.$lang_topic['Last edit'].' '.pun_htmlspecialchars($cur_post['edited_by']).' ('.format_time($cur_post['edited']).')</em></p>'."\n"; ?>
</div>
<?php if ($signature != '') echo "\t\t\t\t\t".'<div class="postsignature postmsg"><hr />'.$signature.'</div>'."\n"; ?>
</div>
</div>
</div>
<div class="inbox">
<div class="postfoot clearb">
<div class="postfootleft"><?php if ($cur_post['poster_id'] > 1) echo '<p>'.$is_online.'</p>'; ?></div>
<?php if (count($post_actions)) echo "\t\t\t\t".'<div class="postfootright">'."\n\t\t\t\t\t".'<ul>'."\n\t\t\t\t\t\t".implode("\n\t\t\t\t\t\t", $post_actions)."\n\t\t\t\t\t".'</ul>'."\n\t\t\t\t".'</div>'."\n" ?>
</div>
</div>
</div>
</div>
<?php
}
?>
<div class="postlinksb">
<div class="inbox crumbsplus">
<div class="pagepost">
<p class="pagelink conl"><?php echo $paging_links ?></p>
<?php echo $post_link ?>
</div>
<ul class="crumbs">
<li><a href="index.php"><?php echo $lang_common['Index'] ?></a></li>
<li><span>» </span><a href="viewforum.php?id=<?php echo $cur_topic['forum_id'] ?>"><?php echo pun_htmlspecialchars($cur_topic['forum_name']) ?></a></li>
<li><span>» </span><a href="viewtopic.php?id=<?php echo $id ?>"><strong><?php echo pun_htmlspecialchars($cur_topic['subject']) ?></strong></a></li>
</ul>
<?php echo $subscraction ?>
<div class="clearer"></div>
</div>
</div>
<?php
// Display quick post if enabled
if ($quickpost)
{
$cur_index = 1;
?>
<div id="quickpost" class="blockform">
<h2><span><?php echo $lang_topic['Quick post'] ?></span></h2>
<div class="box">
<form id="quickpostform" method="post" action="post.php?tid=<?php echo $id ?>" onsubmit="this.submit.disabled=true;if(process_form(this)){return true;}else{this.submit.disabled=false;return false;}">
<div class="inform">
<fieldset>
<legend><?php echo $lang_common['Write message legend'] ?></legend>
<div class="infldset txtarea">
<input type="hidden" name="form_sent" value="1" />
<?php if ($pun_config['o_topic_subscriptions'] == '1' && ($pun_user['auto_notify'] == '1' || $cur_topic['is_subscribed'])): ?> <input type="hidden" name="subscribe" value="1" />
<?php endif; ?>
<?php
if ($pun_user['is_guest'])
{
$email_label = ($pun_config['p_force_guest_email'] == '1') ? '<strong>'.$lang_common['Email'].' <span>'.$lang_common['Required'].'</span></strong>' : $lang_common['Email'];
$email_form_name = ($pun_config['p_force_guest_email'] == '1') ? 'req_email' : 'email';
?>
<label class="conl required"><strong><?php echo $lang_post['Guest name'] ?> <span><?php echo $lang_common['Required'] ?></span></strong><br /><input type="text" name="req_username" value="<?php if (isset($_POST['req_username'])) echo pun_htmlspecialchars($username); ?>" size="25" maxlength="25" tabindex="<?php echo $cur_index++ ?>" /><br /></label>
<label class="conl<?php echo ($pun_config['p_force_guest_email'] == '1') ? ' required' : '' ?>"><?php echo $email_label ?><br /><input type="text" name="<?php echo $email_form_name ?>" value="<?php if (isset($_POST[$email_form_name])) echo pun_htmlspecialchars($email); ?>" size="50" maxlength="80" tabindex="<?php echo $cur_index++ ?>" /><br /></label>
<div class="clearer"></div>
<?php
echo "\t\t\t\t\t\t".'<label class="required"><strong>'.$lang_common['Message'].' <span>'.$lang_common['Required'].'</span></strong><br />';
}
else
echo "\t\t\t\t\t\t".'<label>';
?>
<textarea name="req_message" rows="7" cols="75" tabindex="<?php echo $cur_index++ ?>"></textarea></label>
<ul class="bblinks">
<li><span><a href="help.php#bbcode" onclick="window.open(this.href); return false;"><?php echo $lang_common['BBCode'] ?></a> <?php echo ($pun_config['p_message_bbcode'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li>
<li><span><a href="help.php#img" onclick="window.open(this.href); return false;"><?php echo $lang_common['img tag'] ?></a> <?php echo ($pun_config['p_message_bbcode'] == '1' && $pun_config['p_message_img_tag'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li>
<li><span><a href="help.php#smilies" onclick="window.open(this.href); return false;"><?php echo $lang_common['Smilies'] ?></a> <?php echo ($pun_config['o_smilies'] == '1') ? $lang_common['on'] : $lang_common['off']; ?></span></li>
</ul>
</div>
</fieldset>
</div>
<p class="buttons"><input type="submit" name="submit" tabindex="<?php echo $cur_index++ ?>" value="<?php echo $lang_common['Submit'] ?>" accesskey="s" /> <input type="submit" name="preview" value="<?php echo $lang_topic['Preview'] ?>" tabindex="<?php echo $cur_index++ ?>" accesskey="p" /></p>
</form>
</div>
</div>
<?php
}
// Increment "num_views" for topic
if ($pun_config['o_topic_views'] == '1')
$db->query('UPDATE '.$db->prefix.'topics SET num_views=num_views+1 WHERE id='.$id) or error('Unable to update topic', __FILE__, __LINE__, $db->error());
$forum_id = $cur_topic['forum_id'];
$footer_style = 'viewtopic';
require PUN_ROOT.'footer.php';
[/code]
exit;
// Global variables
/* regular expression to match nested BBCode LIST tags
'%
\[list # match opening bracket and tag name of outermost LIST tag
(?:=([1a*]))?+ # optional attribute capture in group 1
\] # closing bracket of outermost opening LIST tag
( # capture contents of LIST tag in group 2
(?: # non capture group for either contents or whole nested LIST
[^\[]*+ # unroll the loop! consume everything up to next [ (normal *)
(?: # (See "Mastering Regular Expressions" chapter 6 for details)
(?! # negative lookahead ensures we are NOT on [LIST*] or [/list]
\[list # opening LIST tag
(?:=[1a*])?+ # with optional attribute
\] # closing bracket of opening LIST tag
| # or...
\[/list\] # a closing LIST tag
) # end negative lookahead assertion (we are not on a LIST tag)
\[ # match the [ which is NOT the start of LIST tag (special)
[^\[]*+ # consume everything up to next [ (normal *)
)*+ # finish up "unrolling the loop" technique (special (normal*))*
| # or...
(?R) # recursively match a whole nested LIST element
)* # as many times as necessary until deepest nested LIST tag grabbed
) # end capturing contents of LIST tag into group 2
\[/list\] # match outermost closing LIST tag
%iex' */
$re_list = '%\[list(?:=([1a*]))?+\]((?:[^\[]*+(?:(?!\[list(?:=[1a*])?+\]|\[/list\])\[[^\[]*+)*+|(?R))*)\[/list\]%ie';
// Here you can add additional smilies if you like (please note that you must escape single quote and backslash)
$smilies = array(
':)' => 'smile.png',
'=)' => 'smile.png',
':|' => 'neutral.png',
'=|' => 'neutral.png',
':(' => 'sad.png',
'=(' => 'sad.png',
':D' => 'big_smile.png',
'=D' => 'big_smile.png',
':o' => 'yikes.png',
':O' => 'yikes.png',
';)' => 'wink.png',
':/' => 'hmm.png',
':P' => 'tongue.png',
':p' => 'tongue.png',
':lol:' => 'lol.png',
':mad:' => 'mad.png',
':rolleyes:' => 'roll.png',
':cool:' => 'cool.png');
//
// Make sure all BBCodes are lower case and do a little cleanup
//
function preparse_bbcode($text, &$errors, $is_signature = false)
{
global $pun_config, $lang_common, $lang_post, $re_list;
if ($is_signature)
{
global $lang_profile;
if (preg_match('%\[/?(?:quote|code|list|h)\b[^\]]*\]%i', $text))
$errors[] = $lang_profile['Signature quote/code/list/h'];
}
// If the message contains a code tag we have to split it up (text within shouldn't be touched)
if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
list($inside, $text) = extract_blocks($text, '[code]', '[/code]');
// Tidy up lists
$temp = preg_replace($re_list, 'preparse_list_tag(\'$2\', \'$1\')', $text);
// If the regex failed
if ($temp === null)
$errors[] = $lang_common['BBCode list size error'];
else
$text = str_replace('*'."\0".']', '*]', $temp);
if ($pun_config['o_make_links'] == '1')
$text = do_clickable($text);
// If we split up the message before we have to concatenate it together again (code tags)
if (isset($inside))
{
$outside = explode("\1", $text);
$text = '';
$num_tokens = count($outside);
for ($i = 0; $i < $num_tokens; ++$i)
{
$text .= $outside[$i];
if (isset($inside[$i]))
$text .= '[code]'.$inside[$i].'[/code]';
}
unset($inside);
}
$temp_text = false;
if (empty($errors))
$temp_text = preparse_tags($text, $errors, $is_signature);
if ($temp_text !== false)
$text = $temp_text;
// Remove empty tags
while (($new_text = strip_empty_bbcode($text)) !== false)
{
if ($new_text != $text)
{
$text = $new_text;
if ($new_text == '')
{
$errors[] = $lang_post['Empty after strip'];
break;
}
}
else
break;
}
return pun_trim($text);
}
//
// Strip empty bbcode tags from some text
//
function strip_empty_bbcode($text)
{
// If the message contains a code tag we have to split it up (empty tags within are fine)
if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
list($inside, $text) = extract_blocks($text, '[code]', '[/code]');
// Remove empty tags
while (($new_text = preg_replace('%\[(b|u|s|ins|del|em|i|h|colou?r|quote|img|url|email|list|topic|post|forum|user)(?:\=[^\]]*)?\]\s*\[/\1\]%', '', $text)) !== NULL)
{
if ($new_text != $text)
$text = $new_text;
else
break;
}
// If we split up the message before we have to concatenate it together again (code tags)
if (isset($inside))
{
$parts = explode("\1", $text);
$text = '';
foreach ($parts as $i => $part)
{
$text .= $part;
if (isset($inside[$i]))
$text .= '[code]'.$inside[$i].'[/code]';
}
}
// Remove empty code tags
while (($new_text = preg_replace('%\[(code)\]\s*\[/\1\]%', '', $text)) !== NULL)
{
if ($new_text != $text)
$text = $new_text;
else
break;
}
return $text;
}
//
// Check the structure of bbcode tags and fix simple mistakes where possible
//
function preparse_tags($text, &$errors, $is_signature = false)
{
global $lang_common, $pun_config;
// Start off by making some arrays of bbcode tags and what we need to do with each one
// List of all the tags
$tags = array('quote', 'code', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'img', 'list', '*', 'h', 'topic', 'post', 'forum', 'user');
// List of tags that we need to check are open (You could not put b,i,u in here then illegal nesting like [b][i][/b][/i] would be allowed)
$tags_opened = $tags;
// and tags we need to check are closed (the same as above, added it just in case)
$tags_closed = $tags;
// Tags we can nest and the depth they can be nested to
$tags_nested = array('quote' => $pun_config['o_quote_depth'], 'list' => 5, '*' => 5);
// Tags to ignore the contents of completely (just code)
$tags_ignore = array('code');
// Block tags, block tags can only go within another block tag, they cannot be in a normal tag
$tags_block = array('quote', 'code', 'list', 'h', '*');
// Inline tags, we do not allow new lines in these
$tags_inline = array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'h', 'topic', 'post', 'forum', 'user');
// Tags we trim interior space
$tags_trim = array('img');
// Tags we remove quotes from the argument
$tags_quotes = array('url', 'email', 'img', 'topic', 'post', 'forum', 'user');
// Tags we limit bbcode in
$tags_limit_bbcode = array(
'*' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'list', 'img', 'code', 'topic', 'post', 'forum', 'user'),
'list' => array('*'),
'url' => array('img'),
'email' => array('img'),
'topic' => array('img'),
'post' => array('img'),
'forum' => array('img'),
'user' => array('img'),
'img' => array(),
'h' => array('b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'topic', 'post', 'forum', 'user'),
);
// Tags we can automatically fix bad nesting
$tags_fix = array('quote', 'b', 'i', 'u', 's', 'ins', 'del', 'em', 'color', 'colour', 'url', 'email', 'h', 'topic', 'post', 'forum', 'user');
$split_text = preg_split('%(\[[\*a-zA-Z0-9-/]*?(?:=.*?)?\])%', $text, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$open_tags = array('fluxbb-bbcode');
$open_args = array('');
$opened_tag = 0;
$new_text = '';
$current_ignore = '';
$current_nest = '';
$current_depth = array();
$limit_bbcode = $tags;
$count_ignored = array();
foreach ($split_text as $current)
{
if ($current == '')
continue;
// Are we dealing with a tag?
if (substr($current, 0, 1) != '[' || substr($current, -1, 1) != ']')
{
// It's not a bbcode tag so we put it on the end and continue
// If we are nested too deeply don't add to the end
if ($current_nest)
continue;
$current = str_replace("\r\n", "\n", $current);
$current = str_replace("\r", "\n", $current);
if (in_array($open_tags[$opened_tag], $tags_inline) && strpos($current, "\n") !== false)
{
// Deal with new lines
$split_current = preg_split('%(\n\n+)%', $current, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);
$current = '';
if (!pun_trim($split_current[0], "\n")) // The first part is a linebreak so we need to handle any open tags first
array_unshift($split_current, '');
for ($i = 1; $i < count($split_current); $i += 2)
{
$temp_opened = array();
$temp_opened_arg = array();
$temp = $split_current[$i - 1];
while (!empty($open_tags))
{
$temp_tag = array_pop($open_tags);
$temp_arg = array_pop($open_args);
if (in_array($temp_tag , $tags_inline))
{
array_push($temp_opened, $temp_tag);
array_push($temp_opened_arg, $temp_arg);
$temp .= '[/'.$temp_tag.']';
}
else
{
array_push($open_tags, $temp_tag);
array_push($open_args, $temp_arg);
break;
}
}
$current .= $temp.$split_current[$i];
$temp = '';
while (!empty($temp_opened))
{
$temp_tag = array_pop($temp_opened);
$temp_arg = array_pop($temp_opened_arg);
if (empty($temp_arg))
$temp .= '['.$temp_tag.']';
else
$temp .= '['.$temp_tag.'='.$temp_arg.']';
array_push($open_tags, $temp_tag);
array_push($open_args, $temp_arg);
}
$current .= $temp;
}
if (array_key_exists($i - 1, $split_current))
$current .= $split_current[$i - 1];
}
if (in_array($open_tags[$opened_tag], $tags_trim))
$new_text .= pun_trim($current);
else
$new_text .= $current;
continue;
}
// Get the name of the tag
$current_arg = '';
if (strpos($current, '/') === 1)
{
$current_tag = substr($current, 2, -1);
}
else if (strpos($current, '=') === false)
{
$current_tag = substr($current, 1, -1);
}
else
{
$current_tag = substr($current, 1, strpos($current, '=')-1);
$current_arg = substr($current, strpos($current, '=')+1, -1);
}
$current_tag = strtolower($current_tag);
// Is the tag defined?
if (!in_array($current_tag, $tags))
{
// It's not a bbcode tag so we put it on the end and continue
if (!$current_nest)
$new_text .= $current;
continue;
}
// We definitely have a bbcode tag
// Make the tag string lower case
if ($equalpos = strpos($current,'='))
{
// We have an argument for the tag which we don't want to make lowercase
if (strlen(substr($current, $equalpos)) == 2)
{
// Empty tag argument
$errors[] = sprintf($lang_common['BBCode error empty attribute'], $current_tag);
return false;
}
$current = strtolower(substr($current, 0, $equalpos)).substr($current, $equalpos);
}
else
$current = strtolower($current);
// This is if we are currently in a tag which escapes other bbcode such as code
// We keep a count of ignored bbcodes (code tags) so we can nest them, but
// only balanced sets of tags can be nested
if ($current_ignore)
{
// Increase the current ignored tags counter
if ('['.$current_ignore.']' == $current)
$count_ignored[$current_tag]++;
// Decrease the current ignored tags counter
if ('[/'.$current_ignore.']' == $current)
$count_ignored[$current_tag]--;
if ('[/'.$current_ignore.']' == $current && $count_ignored[$current_tag] == 0)
{
// We've finished the ignored section
$current = '[/'.$current_tag.']';
$current_ignore = '';
$count_ignored = array();
}
$new_text .= $current;
continue;
}
if ($current_nest)
{
// We are currently too deeply nested so lets see if we are closing the tag or not
if ($current_tag != $current_nest)
continue;
if (substr($current, 1, 1) == '/')
$current_depth[$current_nest]--;
else
$current_depth[$current_nest]++;
if ($current_depth[$current_nest] <= $tags_nested[$current_nest])
$current_nest = '';
continue;
}
// Check the current tag is allowed here
if (!in_array($current_tag, $limit_bbcode) && $current_tag != $open_tags[$opened_tag])
{
$errors[] = sprintf($lang_common['BBCode error invalid nesting'], $current_tag, $open_tags[$opened_tag]);
return false;
}
if (substr($current, 1, 1) == '/')
{
// This is if we are closing a tag
if ($opened_tag == 0 || !in_array($current_tag, $open_tags))
{
// We tried to close a tag which is not open
if (in_array($current_tag, $tags_opened))
{
$errors[] = sprintf($lang_common['BBCode error no opening tag'], $current_tag);
return false;
}
}
else
{
// Check nesting
while (true)
{
// Nesting is ok
if ($open_tags[$opened_tag] == $current_tag)
{
array_pop($open_tags);
array_pop($open_args);
$opened_tag--;
break;
}
// Nesting isn't ok, try to fix it
if (in_array($open_tags[$opened_tag], $tags_closed) && in_array($current_tag, $tags_closed))
{
if (in_array($current_tag, $open_tags))
{
$temp_opened = array();
$temp_opened_arg = array();
$temp = '';
while (!empty($open_tags))
{
$temp_tag = array_pop($open_tags);
$temp_arg = array_pop($open_args);
if (!in_array($temp_tag, $tags_fix))
{
// We couldn't fix nesting
$errors[] = sprintf($lang_common['BBCode error no closing tag'], array_pop($temp_opened));
return false;
}
array_push($temp_opened, $temp_tag);
array_push($temp_opened_arg, $temp_arg);
if ($temp_tag == $current_tag)
break;
else
$temp .= '[/'.$temp_tag.']';
}
$current = $temp.$current;
$temp = '';
array_pop($temp_opened);
array_pop($temp_opened_arg);
while (!empty($temp_opened))
{
$temp_tag = array_pop($temp_opened);
$temp_arg = array_pop($temp_opened_arg);
if (empty($temp_arg))
$temp .= '['.$temp_tag.']';
else
$temp .= '['.$temp_tag.'='.$temp_arg.']';
array_push($open_tags, $temp_tag);
array_push($open_args, $temp_arg);
}
$current .= $temp;
$opened_tag--;
break;
}
else
{
// We couldn't fix nesting
$errors[] = sprintf($lang_common['BBCode error no opening tag'], $current_tag);
return false;
}
}
else if (in_array($open_tags[$opened_tag], $tags_closed))
break;
else
{
array_pop($open_tags);
array_pop($open_args);
$opened_tag--;
}
}
}
if (in_array($current_tag, array_keys($tags_nested)))
{
if (isset($current_depth[$current_tag]))
$current_depth[$current_tag]--;
}
if (in_array($open_tags[$opened_tag], array_keys($tags_limit_bbcode)))
$limit_bbcode = $tags_limit_bbcode[$open_tags[$opened_tag]];
else
$limit_bbcode = $tags;
$new_text .= $current;
continue;
}
else
{
// We are opening a tag
if (in_array($current_tag, array_keys($tags_limit_bbcode)))
$limit_bbcode = $tags_limit_bbcode[$current_tag];
else
$limit_bbcode = $tags;
if (in_array($current_tag, $tags_block) && !in_array($open_tags[$opened_tag], $tags_block) && $opened_tag != 0)
{
// We tried to open a block tag within a non-block tag
$errors[] = sprintf($lang_common['BBCode error invalid nesting'], $current_tag, $open_tags[$opened_tag]);
return false;
}
if (in_array($current_tag, $tags_ignore))
{
// It's an ignore tag so we don't need to worry about what's inside it
$current_ignore = $current_tag;
$count_ignored[$current_tag] = 1;
$new_text .= $current;
continue;
}
// Deal with nested tags
if (in_array($current_tag, $open_tags) && !in_array($current_tag, array_keys($tags_nested)))
{
// We nested a tag we shouldn't
$errors[] = sprintf($lang_common['BBCode error invalid self-nesting'], $current_tag);
return false;
}
else if (in_array($current_tag, array_keys($tags_nested)))
{
// We are allowed to nest this tag
if (isset($current_depth[$current_tag]))
$current_depth[$current_tag]++;
else
$current_depth[$current_tag] = 1;
// See if we are nested too deep
if ($current_depth[$current_tag] > $tags_nested[$current_tag])
{
$current_nest = $current_tag;
continue;
}
}
// Remove quotes from arguments for certain tags
if (strpos($current, '=') !== false && in_array($current_tag, $tags_quotes))
{
$current = preg_replace('%\['.$current_tag.'=("|\'|)(.*?)\\1\]\s*%i', '['.$current_tag.'=$2]', $current);
}
if (in_array($current_tag, array_keys($tags_limit_bbcode)))
$limit_bbcode = $tags_limit_bbcode[$current_tag];
$open_tags[] = $current_tag;
$open_args[] = $current_arg;
$opened_tag++;
$new_text .= $current;
continue;
}
}
// Check we closed all the tags we needed to
foreach ($tags_closed as $check)
{
if (in_array($check, $open_tags))
{
// We left an important tag open
$errors[] = sprintf($lang_common['BBCode error no closing tag'], $check);
return false;
}
}
if ($current_ignore)
{
// We left an ignore tag open
$errors[] = sprintf($lang_common['BBCode error no closing tag'], $current_ignore);
return false;
}
return $new_text;
}
//
// Preparse the contents of [list] bbcode
//
function preparse_list_tag($content, $type = '*')
{
global $lang_common, $re_list;
if (strlen($type) != 1)
$type = '*';
if (strpos($content,'[list') !== false)
{
$content = preg_replace($re_list, 'preparse_list_tag(\'$2\', \'$1\')', $content);
}
$items = explode('[*]', str_replace('\"', '"', $content));
$content = '';
foreach ($items as $item)
{
if (pun_trim($item) != '')
$content .= '[*'."\0".']'.str_replace('[/*]', '', pun_trim($item)).'[/*'."\0".']'."\n";
}
return '[list='.$type.']'."\n".$content.'[/list]';
}
//
// Truncate URL if longer than 55 characters (add http:// or ftp:// if missing)
//
function handle_url_tag($url, $link = '', $bbcode = false)
{
$url = pun_trim($url);
// Deal with [url][img]http://example.com/test.png[/img][/url]
if (preg_match('%<img src=\\\\"(.*?)\\\\"%', $url, $matches))
return handle_url_tag($matches[1], $url, $bbcode);
$full_url = str_replace(array(' ', '\'', '`', '"'), array('%20', '', '', ''), $url);
if (strpos($url, 'www.') === 0) // If it starts with www, we add http://
$full_url = 'http://'.$full_url;
else if (strpos($url, 'ftp.') === 0) // Else if it starts with ftp, we add ftp://
$full_url = 'ftp://'.$full_url;
else if (strpos($url, '/') === 0) // Allow for relative URLs that start with a slash
$full_url = get_base_url(true).$full_url;
else if (!preg_match('#^([a-z0-9]{3,6})://#', $url)) // Else if it doesn't start with abcdef://, we add http://
$full_url = 'http://'.$full_url;
// Ok, not very pretty :-)
if ($bbcode)
{
if ($full_url == $link)
return '[url]'.$link.'[/url]';
else
return '[url='.$full_url.']'.$link.'[/url]';
}
else
{
if ($link == '' || $link == $url)
{
$url = pun_htmlspecialchars_decode($url);
$link = utf8_strlen($url) > 55 ? utf8_substr($url, 0 , 39).' … '.utf8_substr($url, -10) : $url;
$link = pun_htmlspecialchars($link);
}
else
$link = stripslashes($link);
return '<a href="'.$full_url.'">'.$link.'</a>';
}
}
//
// Turns an URL from the [img] tag into an <img> tag or a <a href...> tag
//
function handle_img_tag($url, $is_signature = false, $alt = null)
{
global $lang_common, $pun_user;
if ($alt == null)
$alt = basename($url);
$img_tag = '<a href="'.$url.'"><'.$lang_common['Image link'].' - '.$alt.'></a>';
if ($is_signature && $pun_user['show_img_sig'] != '0')
$img_tag = '<img class="sigimage" src="'.$url.'" alt="'.$alt.'" />';
else if (!$is_signature && $pun_user['show_img'] != '0')
$img_tag = '<span class="postimg"><img src="'.$url.'" alt="'.$alt.'" /></span>';
return $img_tag;
}
//
// Parse the contents of [list] bbcode
//
function handle_list_tag($content, $type = '*')
{
global $re_list;
if (strlen($type) != 1)
$type = '*';
if (strpos($content,'[list') !== false)
{
$content = preg_replace($re_list, 'handle_list_tag(\'$2\', \'$1\')', $content);
}
$content = preg_replace('#\s*\[\*\](.*?)\[/\*\]\s*#s', '<li><p>$1</p></li>', pun_trim($content));
if ($type == '*')
$content = '<ul>'.$content.'</ul>';
else
if ($type == 'a')
$content = '<ol class="alpha">'.$content.'</ol>';
else
$content = '<ol class="decimal">'.$content.'</ol>';
return '</p>'.$content.'<p>';
}
//
// Convert BBCodes to their HTML equivalent
//
function do_bbcode($text, $is_signature = false)
{
global $lang_common, $pun_user, $pun_config, $re_list;
if (strpos($text, '[quote') !== false)
{
$text = preg_replace('%\[quote\]\s*%', '</p><div class="quotebox"><blockquote><div><p>', $text);
$text = preg_replace('%\[quote=("|&\#039;|"|\'|)(.*?)\\1\]%se', '"</p><div class=\"quotebox\"><cite>".str_replace(array(\'[\', \'\\"\'), array(\'[\', \'"\'), \'$2\')." ".$lang_common[\'wrote\']."</cite><blockquote><div><p>"', $text);
$text = preg_replace('%\s*\[\/quote\]%S', '</p></div></blockquote></div><p>', $text);
}
if (!$is_signature)
{
$pattern[] = $re_list;
$replace[] = 'handle_list_tag(\'$2\', \'$1\')';
}
$pattern[] = '%\[b\](.*?)\[/b\]%ms';
$pattern[] = '%\[i\](.*?)\[/i\]%ms';
$pattern[] = '%\[u\](.*?)\[/u\]%ms';
$pattern[] = '%\[s\](.*?)\[/s\]%ms';
$pattern[] = '%\[del\](.*?)\[/del\]%ms';
$pattern[] = '%\[ins\](.*?)\[/ins\]%ms';
$pattern[] = '%\[em\](.*?)\[/em\]%ms';
$pattern[] = '%\[colou?r=([a-zA-Z]{3,20}|\#[0-9a-fA-F]{6}|\#[0-9a-fA-F]{3})](.*?)\[/colou?r\]%ms';
$pattern[] = '%\[h\](.*?)\[/h\]%ms';
$replace[] = '<strong>$1</strong>';
$replace[] = '<em>$1</em>';
$replace[] = '<span class="bbu">$1</span>';
$replace[] = '<span class="bbs">$1</span>';
$replace[] = '<del>$1</del>';
$replace[] = '<ins>$1</ins>';
$replace[] = '<em>$1</em>';
$replace[] = '<span style="color: $1">$2</span>';
$replace[] = '</p><h5>$1</h5><p>';
if (($is_signature && $pun_config['p_sig_img_tag'] == '1') || (!$is_signature && $pun_config['p_message_img_tag'] == '1'))
{
$pattern[] = '%\[img\]((ht|f)tps?://)([^\s<"]*?)\[/img\]%e';
$pattern[] = '%\[img=([^\[]*?)\]((ht|f)tps?://)([^\s<"]*?)\[/img\]%e';
if ($is_signature)
{
$replace[] = 'handle_img_tag(\'$1$3\', true)';
$replace[] = 'handle_img_tag(\'$2$4\', true, \'$1\')';
}
else
{
$replace[] = 'handle_img_tag(\'$1$3\', false)';
$replace[] = 'handle_img_tag(\'$2$4\', false, \'$1\')';
}
}
$pattern[] = '%\[url\]([^\[]*?)\[/url\]%e';
$pattern[] = '%\[url=([^\[]+?)\](.*?)\[/url\]%e';
$pattern[] = '%\[email\]([^\[]*?)\[/email\]%';
$pattern[] = '%\[email=([^\[]+?)\](.*?)\[/email\]%';
$pattern[] = '%\[topic\]([1-9]\d*)\[/topic\]%e';
$pattern[] = '%\[topic=([1-9]\d*)\](.*?)\[/topic\]%e';
$pattern[] = '%\[post\]([1-9]\d*)\[/post\]%e';
$pattern[] = '%\[post=([1-9]\d*)\](.*?)\[/post\]%e';
$pattern[] = '%\[forum\]([1-9]\d*)\[/forum\]%e';
$pattern[] = '%\[forum=([1-9]\d*)\](.*?)\[/forum\]%e';
$pattern[] = '%\[user\]([1-9]\d*)\[/user\]%e';
$pattern[] = '%\[user=([1-9]\d*)\](.*?)\[/user\]%e';
$replace[] = 'handle_url_tag(\'$1\')';
$replace[] = 'handle_url_tag(\'$1\', \'$2\')';
$replace[] = '<a href="mailto:$1">$1</a>';
$replace[] = '<a href="mailto:$1">$2</a>';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?id=$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?id=$1\', \'$2\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?pid=$1#p$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewtopic.php?pid=$1#p$1\', \'$2\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewforum.php?id=$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/viewforum.php?id=$1\', \'$2\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/profile.php?id=$1\')';
$replace[] = 'handle_url_tag(\''.get_base_url(true).'/profile.php?id=$1\', \'$2\')';
// This thing takes a while! :)
$text = preg_replace($pattern, $replace, $text);
return $text;
}
//
// Make hyperlinks clickable
//
function do_clickable($text)
{
$text = ' '.$text;
$text = ucp_preg_replace('%(?<=[\s\]\)])(<)?(\[)?(\()?([\'"]?)(https?|ftp|news){1}://([\p{L}\p{N}\-]+\.([\p{L}\p{N}\-]+\.)*[\p{L}\p{N}]+(:[0-9]+)?(/(?:[^\s\[]*[^\s.,?!\[;:-])?)?)\4(?(3)(\)))(?(2)(\]))(?(1)(>))(?![^\s]*\[/(?:url|img)\])%uie', 'stripslashes(\'$1$2$3$4\').handle_url_tag(\'$5://$6\', \'$5://$6\', true).stripslashes(\'$4$10$11$12\')', $text);
$text = ucp_preg_replace('%(?<=[\s\]\)])(<)?(\[)?(\()?([\'"]?)(www|ftp)\.(([\p{L}\p{N}\-]+\.)*[\p{L}\p{N}]+(:[0-9]+)?(/(?:[^\s\[]*[^\s.,?!\[;:-])?)?)\4(?(3)(\)))(?(2)(\]))(?(1)(>))(?![^\s]*\[/(?:url|img)\])%uie', 'stripslashes(\'$1$2$3$4\').handle_url_tag(\'$5.$6\', \'$5.$6\', true).stripslashes(\'$4$10$11$12\')', $text);
return substr($text, 1);
}
//
// Convert a series of smilies to images
//
function do_smilies($text)
{
global $pun_config, $smilies;
$text = ' '.$text.' ';
foreach ($smilies as $smiley_text => $smiley_img)
{
if (strpos($text, $smiley_text) !== false)
$text = ucp_preg_replace('%(?<=[>\s])'.preg_quote($smiley_text, '%').'(?=[^\p{L}\p{N}])%um', '<img src="'.pun_htmlspecialchars(get_base_url(true).'/img/smilies/'.$smiley_img).'" width="15" height="15" alt="'.substr($smiley_img, 0, strrpos($smiley_img, '.')).'" />', $text);
}
return substr($text, 1, -1);
}
//
// Parse message text
//
function parse_message($text, $hide_smilies)
{
global $pun_config, $lang_common, $pun_user;
if ($pun_config['o_censoring'] == '1')
$text = censor_words($text);
// Convert applicable characters to HTML entities
$text = pun_htmlspecialchars($text);
// If the message contains a code tag we have to split it up (text within shouldn't be touched)
if (strpos($text, '[code]') !== false && strpos($text, '[/code]') !== false)
list($inside, $text) = extract_blocks($text, '[code]', '[/code]');
if ($pun_config['p_message_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false)
$text = do_bbcode($text);
if ($pun_config['o_smilies'] == '1' && $pun_user['show_smilies'] == '1' && $hide_smilies == '0')
$text = do_smilies($text);
// Deal with newlines, tabs and multiple spaces
$pattern = array("\n", "\t", ' ', ' ');
$replace = array('<br />', '    ', '  ', '  ');
$text = str_replace($pattern, $replace, $text);
// If we split up the message before we have to concatenate it together again (code tags)
if (isset($inside))
{
$parts = explode("\1", $text);
$text = '';
foreach ($parts as $i => $part)
{
$text .= $part;
if (isset($inside[$i]))
{
$num_lines = (substr_count($inside[$i], "\n"));
$text .= '</p><div class="codebox"><pre'.(($num_lines > 28) ? ' class="vscroll"' : '').'><code>'.pun_trim($inside[$i], "\n\r").'</code></pre></div><p>';
}
}
}
return clean_paragraphs($text);
}
//
// Clean up paragraphs and line breaks
//
function clean_paragraphs($text)
{
// Add paragraph tag around post, but make sure there are no empty paragraphs
$text = '<p>'.$text.'</p>';
// Replace any breaks next to paragraphs so our replace below catches them
$text = preg_replace('%(</?p>)(?:\s*?<br />){1,2}%i', '$1', $text);
$text = preg_replace('%(?:<br />\s*?){1,2}(</?p>)%i', '$1', $text);
// Remove any empty paragraph tags (inserted via quotes/lists/code/etc) which should be stripped
$text = str_replace('<p></p>', '', $text);
$text = preg_replace('%<br />\s*?<br />%i', '</p><p>', $text);
$text = str_replace('<p><br />', '<br /><p>', $text);
$text = str_replace('<br /></p>', '</p><br />', $text);
$text = str_replace('<p></p>', '<br /><br />', $text);
return $text;
}
//
// Parse signature text
//
function parse_signature($text)
{
global $pun_config, $lang_common, $pun_user;
if ($pun_config['o_censoring'] == '1')
$text = censor_words($text);
// Convert applicable characters to HTML entities
$text = pun_htmlspecialchars($text);
if ($pun_config['p_sig_bbcode'] == '1' && strpos($text, '[') !== false && strpos($text, ']') !== false)
$text = do_bbcode($text, true);
if ($pun_config['o_smilies_sig'] == '1' && $pun_user['show_smilies'] == '1')
$text = do_smilies($text);
// Deal with newlines, tabs and multiple spaces
$pattern = array("\n", "\t", ' ', ' ');
$replace = array('<br />', '    ', '  ', '  ');
$text = str_replace($pattern, $replace, $text);
return clean_paragraphs($text);
}
/* PUNDEF START */
function pun_def($msg,$hide_smilies,$nombre,$mot,$definition)
{
$a = "<a onmouseover=\"return overlib('";
$b = "', STICKY, MOUSEOFF);\" onmouseout=\"return nd();\">";
$c = "</a>";
$misage=$msg;
$def=array();
for ($j=0;$j<$nombre;$j++)
$def[$j]=$a.$definition[$j].$b.$mot[$j].$c;
$misage = str_replace($mot,$def, $misage);
return $misage;
}
/* PUNDEF END */Merci d'avance ! 
Hors ligne
Pages : 1