FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » FUDforum Suggestions » Add several browser to load several images
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Add several browser to load several images [message #25709 is a reply to message #25708] Fri, 17 June 2005 21:30 Go to previous messageGo to previous message
aircool51 is currently offline  aircool51   United States
Messages: 19
Registered: March 2005
Karma:
Junior Member
Here is the entire file:



<?php
/**
* copyright : (C) 2001-2004 Advanced Internet Designs Inc.
* email : forum(at)prohost(dot)org
* $Id: post.php.t,v 1.133 2005/03/18 01:58:51 hackie Exp $
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
**/

function flood_check()
{
$check_time = __request_timestamp__-$GLOBALS['FLOOD_CHECK_TIME'];

if (($v = q_singleval("SELECT post_stamp FROM fud26_msg WHERE ip_addr='".get_ip()."' AND poster_id="._uid." AND post_stamp>".$check_time." ORDER BY post_stamp DESC LIMIT 1"))) {
return (($v + $GLOBALS['FLOOD_CHECK_TIME']) - __request_timestamp__);
}

return;
}

if (_uid === '_uid') {
exit('sorry, you can not access this page');
}function tmpl_draw_select_opt($values, $names, $selected)
{
$vls = explode("\n", $values);
$nms = explode("\n", $names);

if (count($vls) != count($nms)) {
exit("FATAL ERROR: inconsistent number of values inside a select<br>\n");
}

$options = '';
foreach ($vls as $k => $v) {
$options .= '<option value="'.$v.'"'.($v == $selected ? ' selected' : '' ) .'>'.$nms[$k].'</option>';
}

return $options;
}function tmpl_draw_radio_opt($name, $values, $names, $selected, $sep)
{
$vls = explode("\n", $values);
$nms = explode("\n", $names);

if (count($vls) != count($nms)) {
exit("FATAL ERROR: inconsistent number of values<br>\n");
}

$checkboxes = '';
foreach ($vls as $k => $v) {
$checkboxes .= '<input type="radio" name="'.$name.'" value="'.$v.'" '.($v == $selected ? 'checked ' : '' ) .'>'.$nms[$k].$sep;
}

return $checkboxes;
}$GLOBALS['__revfs'] = array('&quot;', '&lt;', '&gt;', '&amp;');
$GLOBALS['__revfd'] = array('"', '<', '>', '&');

function reverse_fmt($data)
{
$s = $d = array();
foreach ($GLOBALS['__revfs'] as $k => $v) {
if (strpos($data, $v) !== false) {
$s[] = $v;
$d[] = $GLOBALS['__revfd'][$k];
}
}

return $s ? str_replace($s, $d, $data) : $data;
}function tmpl_post_options($arg, $perms=0)
{
$post_opt_html = 'El código <b>HTML</b> está <b>DESHABILITADO</b>';
$post_opt_fud = 'El <b>FUDcode</b> está <b>DESHABILITADO</b>';
$post_opt_images = 'Las <b>Imágenes</b> están <b>DESHABILITADAS</b>';
$post_opt_smilies = 'Los <b>smilies</b> están <b>DESHABILITADOS</b>';
$edit_time_limit = '';

if (is_int($arg)) {
if ($arg & 16) {
$post_opt_fud = 'El <b><a href=" index.php?section=readingposting&amp;t=help_index&amp;'._rsid.'#sty le " target="_blank">FUDcode</b> está <b>HABILITADO</a></b>';
} else if (!($arg & Cool) {
$post_opt_html = 'El código <b>HTML</b> está <b>HABILITADO</b>';
}
if ($perms & 16384) {
$post_opt_smilies = 'Los <a href=" index.php?section=readingposting&amp;t=help_index&amp;'._rsid.'#sml " target="_blank"><b>smilies</b> están <b>HABILITADOS</b></a>';
}
if ($perms & 32768) {
$post_opt_images = 'Las <b>Imágenes</b> están <b>HABILITADAS</b>';
}
$edit_time_limit = $GLOBALS['EDIT_TIME_LIMIT'] ? '<br><b>Editando Límite de Tiempo</b>: <b>'.$GLOBALS['EDIT_TIME_LIMIT'].'</b> minutos' : '<br><b>Editando Límite de Tiempo</b>: <b>Ilimitado</b>';
} else if ($arg == 'private') {
$o =& $GLOBALS['FUD_OPT_1'];

if ($o & 4096) {
$post_opt_fud = 'El <b><a href=" index.php?section=readingposting&amp;t=help_index&amp;'._rsid.'#sty le " target="_blank">FUDcode</b> está <b>HABILITADO</a></b>';
} else if (!($o & 2048)) {
$post_opt_html = 'El código <b>HTML</b> está <b>HABILITADO</b>';
}
if ($o & 16384) {
$post_opt_images = 'Las <b>Imágenes</b> están <b>HABILITADAS</b>';
}
if ($o & 8192) {
$post_opt_smilies = 'Los <a href=" index.php?section=readingposting&amp;t=help_index&amp;'._rsid.'#sml " target="_blank"><b>smilies</b> están <b>HABILITADOS</b></a>';
}
} else if ($arg == 'sig') {
$o =& $GLOBALS['FUD_OPT_1'];

if ($o & 131072) {
$post_opt_fud = 'El <b><a href=" index.php?section=readingposting&amp;t=help_index&amp;'._rsid.'#sty le " target="_blank">FUDcode</b> está <b>HABILITADO</a></b>';
} else if (!($o & 65536)) {
$post_opt_html = 'El código <b>HTML</b> está <b>HABILITADO</b>';
}
if ($o & 524288) {
$post_opt_images = 'Las <b>Imágenes</b> están <b>HABILITADAS</b>';
}
if ($o & 262144) {
$post_opt_smilies = 'Los <a href=" index.php?section=readingposting&amp;t=help_index&amp;'._rsid.'#sml " target="_blank"><b>smilies</b> están <b>HABILITADOS</b></a>';
}
}

return '<span class="SmallText"><b>Opciones del foro</b><br />
'.$post_opt_html.'<br />
'.$post_opt_fud.'<br />
'.$post_opt_images.'<br />
'.$post_opt_smilies.$edit_time_limit.'</span>';
}$GLOBALS['seps'] = array(' '=>' ', "\n"=>"\n", "\r"=>"\r", "'"=>"'", '"'=>'"', '['=>'[', ']'=>']', '('=>'(', ';'=>';', ')'=>')', "\t"=>"\t", '='=>'=', '>'=>'>', '<'=>'<');

function fud_substr_replace($str, $newstr, $pos, $len)
{
return substr($str, 0, $pos).$newstr.substr($str, $pos+$len);
}

function tags_to_html($str, $allow_img=1, $no_char=0)
{
if (!$no_char) {
$str = htmlspecialchars($str);
}

$str = nl2br($str);

$ostr = '';
$pos = $old_pos = 0;

while (($pos = strpos($str, '[', $pos)) !== false) {
if (isset($GLOBALS['seps'][$str[$pos + 1]])) {
++$pos;
continue;
}

if (($epos = strpos($str, ']', $pos)) === false) {
break;
}
if (!($epos-$pos-1)) {
$pos = $epos + 1;
continue;
}
$tag = substr($str, $pos+1, $epos-$pos-1);
if (($pparms = strpos($tag, '=')) !== false) {
$parms = substr($tag, $pparms+1);
if (!$pparms) { /*[= exception */
$pos = $epos+1;
continue;
}
$tag = substr($tag, 0, $pparms);
} else {
$parms = '';
}

$tag = strtolower($tag);

switch ($tag) {
case 'quote title':
$tag = 'quote';
break;
case 'list type':
$tag = 'list';
break;
}

if ($tag[0] == '/') {
if (isset($end_tag[$pos])) {
if( ($pos-$old_pos) ) $ostr .= substr($str, $old_pos, $pos-$old_pos);
$ostr .= $end_tag[$pos];
$pos = $old_pos = $epos+1;
} else {
$pos = $epos+1;
}

continue;
}

$cpos = $epos;
$ctag = '[/'.$tag.']';
$ctag_l = strlen($ctag);
$otag = '['.$tag;
$otag_l = strlen($otag);
$rf = 1;
$nt_tag = 0;
while (($cpos = strpos($str, '[', $cpos)) !== false) {
if (isset($end_tag[$cpos]) || isset($GLOBALS['seps'][$str[$cpos + 1]])) {
++$cpos;
continue;
}

if (($cepos = strpos($str, ']', $cpos)) === false) {
if (!$nt_tag) {
break 2;
} else {
break;
}
}

if (strcasecmp(substr($str, $cpos, $ctag_l), $ctag) == 0) {
--$rf;
} else if (strcasecmp(substr($str, $cpos, $otag_l), $otag) == 0) {
++$rf;
} else {
$nt_tag++;
++$cpos;
continue;
}

if (!$rf) {
break;
}
$cpos = $cepos;
}

if (!$cpos || ($rf && $str[$cpos] == '<')) { /* left over [ handler */
++$pos;
continue;
}

if ($cpos !== false) {
if (($pos-$old_pos)) {
$ostr .= substr($str, $old_pos, $pos-$old_pos);
}
switch ($tag) {
case 'notag':
$ostr .= '<span name="notag">'.substr($str, $epos+1, $cpos-1-$epos).'</span>';
$epos = $cepos;
break;
case 'url':
if (!$parms) {
$url = substr($str, $epos+1, ($cpos-$epos)-1);
} else {
$url = $parms;
}

if (!strncasecmp($url, 'www.', 4)) {
$url = 'http://'. $url;
} else if (strpos(strtolower($url), 'javascript:') !== false) {
$ostr .= substr($str, $pos, $cepos - $pos + 1);
$epos = $cepos;
$str[$cpos] = '<';
break;
} else {
$url = str_replace('://', '://', $url);
}

$end_tag[$cpos] = '</a>';
$ostr .= '<a href="'.$url.'" target="_blank">';
break;
case 'i':
case 'u':
case 'b':
case 's':
case 'sub':
case 'sup':
case 'del':
$end_tag[$cpos] = '</'.$tag.'>';
$ostr .= '<'.$tag.'>';
break;
case 'email':
if (!$parms) {
$parms = str_replace('@', '@', substr($str, $epos+1, ($cpos-$epos)-1));
$ostr .= '<a href="mailto:'.$parms.'" target="_blank">'.$parms.'</a>';
$epos = $cepos;
$str[$cpos] = '<';
} else {
$end_tag[$cpos] = '</a>';
$ostr .= '<a href="mailto:'.str_replace('@', '@', $parms).'" target="_blank">';
}
break;
case 'color':
case 'size':
case 'font':
if ($tag == 'font') {
$tag = 'face';
}
$end_tag[$cpos] = '</font>';
$ostr .= '<font '.$tag.'="'.$parms.'">';
break;
case 'code':
$param = substr($str, $epos+1, ($cpos-$epos)-1);

$ostr .= '<div class="pre"><pre>'.reverse_nl2br($param).'</pre></div>';
$epos = $cepos;
$str[$cpos] = '<';
break;
case 'pre':
$param = substr($str, $epos+1, ($cpos-$epos)-1);

$ostr .= '<pre>'.reverse_nl2br($param).'</pre>';
$epos = $cepos;
$str[$cpos] = '<';
break;
case 'php':
$param = trim(reverse_fmt(reverse_nl2br(substr($str, $epos+1, ($cpos-$epos)-1))));

if (strncmp($param, '<?php', 5)) {
if (strncmp($param, '<?', 2)) {
$param = "<?php\n" . $param;
} else {
$param = "<?php\n" . substr($param, 3);
}
}
if (substr($param, -2) != '?>') {
$param .= "\n?>";
}

$ostr .= '<span name="php">'.trim(@highlight_string($param, true)).'</span>';
$epos = $cepos;
$str[$cpos] = '<';
break;
case 'img':
case 'imgl':
case 'imgr':
if (!$allow_img) {
$ostr .= substr($str, $pos, ($cepos-$pos)+1);
} else {
$class = ($tag == 'img') ? '' : 'class="'.$tag{3}.'" ';

if (!$parms) {
$parms = substr($str, $epos+1, ($cpos-$epos)-1);
if (strpos(strtolower($parms), 'javascript:') === false) {
$ostr .= '<img '.$class.'src="'.$parms.'" border=0 alt="'.$parms.'">';
} else {
$ostr .= substr($str, $pos, ($cepos-$pos)+1);
}
} else {
if (strpos(strtolower($parms), 'javascript:') === false) {
$ostr .= '<img '.$class.'src="'.$parms.'" border=0 alt="'.substr($str, $epos+1, ($cpos-$epos)-1).'">';
} else {
$ostr .= substr($str, $pos, ($cepos-$pos)+1);
}
}
}
$epos = $cepos;
$str[$cpos] = '<';
break;
case 'quote':
if (!$parms) {
$parms = 'Cita:';
}
$ostr .= '<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1"><tr><td class="SmallText"><b>'.$parms.'</b></td></tr><tr><td class="quote"><br />';
$end_tag[$cpos] = '<br /></td></tr></table>';
break;
case 'align':
$end_tag[$cpos] = '</div>';
$ostr .= '<div align="'.$parms.'">';
break;
case 'list':
$tmp = substr($str, $epos, ($cpos-$epos));
$tmp_l = strlen($tmp);
$tmp2 = str_replace(array('[*]', '<br />'), array('<li>', ''), $tmp);
$tmp2_l = strlen($tmp2);
$str = str_replace($tmp, $tmp2, $str);

$diff = $tmp2_l - $tmp_l;
$cpos += $diff;

if (isset($end_tag)) {
foreach($end_tag as $key => $val) {
if ($key < $epos) {
continue;
}

$end_tag[$key+$diff] = $val;
}
}

switch (strtolower($parms)) {
case '1':
case 'a':
$end_tag[$cpos] = '</ol>';
$ostr .= '<ol type="'.$parms.'">';
break;
case 'square':
case 'circle':
case 'disc':
$end_tag[$cpos] = '</ul>';
$ostr .= '<ul type="'.$parms.'">';
break;
default:
$end_tag[$cpos] = '</ul>';
$ostr .= '<ul>';
}
break;
case 'spoiler':
$rnd = rand();
$end_tag[$cpos] = '</div></div>';
$ostr .= '<div class="dashed" style="padding: 3px;" align="center" width="100%"><a href="javascript://" OnClick="javascript: layerVis(\''.$rnd.'\', 1);">'
.($parms ? $parms : 'Mostrar Spoiler').'</a><div align="left" id="'.$rnd.'" style="display: none;">';
break;
case 'acronym':
$end_tag[$cpos] = '</acronym>';
$ostr .= '<acronym title="'.($parms ? $parms : ' ').'">';
break;
}

$str[$pos] = '<';
$pos = $old_pos = $epos+1;
} else {
$pos = $epos+1;
}
}
$ostr .= substr($str, $old_pos, strlen($str)-$old_pos);

/* url paser */
$pos = 0;
$ppos = 0;
while (($pos = @strpos($ostr, '://', $pos)) !== false) {
if ($pos < $ppos) {
break;
}
// check if it's inside any tag;
$i = $pos;
while (--$i && $i > $ppos) {
if ($ostr[$i] == '>' || $ostr[$i] == '<') {
break;
}
}
if (!$pos || $ostr[$i] == '<') {
$pos += 3;
continue;
}

// check if it's inside the a tag
if (($ts = strpos($ostr, '<a ', $pos)) === false) {
$ts = strlen($ostr);
}
if (($te = strpos($ostr, '</a>', $pos)) == false) {
$te = strlen($ostr);
}
if ($te < $ts) {
$ppos = $pos += 3;
continue;
}

// check if it's inside the pre tag
if (($ts = strpos($ostr, '<pre>', $pos)) === false) {
$ts = strlen($ostr);
}
if (($te = strpos($ostr, '</pre>', $pos)) == false) {
$te = strlen($ostr);
}
if ($te < $ts) {
$ppos = $pos += 3;
continue;
}

// check if it's inside the span tag
if (($ts = strpos($ostr, '<span>', $pos)) === false) {
$ts = strlen($ostr);
}
if (($te = strpos($ostr, '</span>', $pos)) == false) {
$te = strlen($ostr);
}
if ($te < $ts) {
$ppos = $pos += 3;
continue;
}

$us = $pos;
$l = strlen($ostr);
while (1) {
--$us;
if ($ppos > $us || $us >= $l || isset($GLOBALS['seps'][$ostr[$us]])) {
break;
}
}

unset($GLOBALS['seps']['=']);
$ue = $pos;
while (1) {
++$ue;
if ($ue >= $l || isset($GLOBALS['seps'][$ostr[$ue]])) {
break;
}

if ($ostr[$ue] == '&') {
if ($ostr[$ue+4] == ';') {
$ue += 4;
continue;
}
if ($ostr[$ue+3] == ';' || $ostr[$ue+5] == ';') {
break;
}
}

if ($ue >= $l || isset($GLOBALS['seps'][$ostr[$ue]])) {
break;
}
}
$GLOBALS['seps']['='] = '=';

$url = substr($ostr, $us+1, $ue-$us-1);
if (!strncasecmp($url, 'javascript', strlen('javascript')) || ($ue - $us - 1) < 9) {
$pos = $ue;
continue;
}
$html_url = '<a href="'.$url.'" target="_blank">'.$url.'</a>';
$html_url_l = strlen($html_url);
$ostr = fud_substr_replace($ostr, $html_url, $us+1, $ue-$us-1);
$ppos = $pos;
$pos = $us+$html_url_l;
}

/* email parser */
$pos = 0;
$ppos = 0;
while (($pos = @strpos($ostr, '@', $pos)) !== false) {
if ($pos < $ppos) {
break;
}

// check if it's inside any tag;
$i = $pos;
while (--$i && $i>$ppos) {
if ( $ostr[$i] == '>' || $ostr[$i] == '<') {
break;
}
}
if ($i < 0 || $ostr[$i]=='<') {
++$pos;
continue;
}


// check if it's inside the a tag
if (($ts = strpos($ostr, '<a ', $pos)) === false) {
$ts = strlen($ostr);
}
if (($te = strpos($ostr, '</a>', $pos)) == false) {
$te = strlen($ostr);
}
if ($te < $ts) {
$ppos = $pos += 1;
continue;
}

// check if it's inside the pre tag
if (($ts = strpos($ostr, '<div class="pre"><pre>', $pos)) === false) {
$ts = strlen($ostr);
}
if (($te = strpos($ostr, '</pre></div>', $pos)) == false) {
$te = strlen($ostr);
}
if ($te < $ts) {
$ppos = $pos += 1;
continue;
}

for ($es = ($pos - 1); $es > ($ppos - 1); $es--) {
if (
( ord($ostr[$es]) >= ord('A') && ord($ostr[$es]) <= ord('z') ) ||
( ord($ostr[$es]) >= ord(0) && ord($ostr[$es]) <= ord(9) ) ||
( $ostr[$es] == '.' || $ostr[$es] == '-' || $ostr[$es] == '\'')
) { continue; }
++$es;
break;
}
if ($es == $pos) {
$ppos = $pos += 1;
continue;
}
if ($es < 0) {
$es = 0;
}

for ($ee = ($pos + 1); @isset($ostr[$ee]); $ee++) {
if (
( ord($ostr[$ee]) >= ord('A') && ord($ostr[$ee]) <= ord('z') ) ||
( ord($ostr[$ee]) >= ord(0) && ord($ostr[$ee]) <= ord(9) ) ||
( $ostr[$ee] == '.' || $ostr[$ee] == '-' )
) { continue; }
break;
}
if ($ee == ($pos+1)) {
$ppos = $pos += 1;
continue;
}

$email = str_replace('@', '@', substr($ostr, $es, $ee-$es));
$email_url = '<a href="mailto:'.$email.'" target="_blank">'.$email.'</a>';
$email_url_l = strlen($email_url);
$ostr = fud_substr_replace($ostr, $email_url, $es, $ee-$es);
$ppos = $es+$email_url_l;
$pos = $ppos;
}

return $ostr;
}

function html_to_tags($fudml)
{
while (preg_match('!<span name="php">(.*?)</span>!is', $fudml, $res)) {
$tmp = trim(html_entity_decode(strip_tags(str_replace('<br />', "\n", $res[1]))));
$m = md5($tmp);
$php[$m] = $tmp;
$fudml = str_replace($res[0], " <?php
n
".$m."n
?>
", $fudml);
}

if (strpos($fudml, '<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1"><tr><td class="SmallText"><b>') !== false) {
$fudml = str_replace(array('<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1"><tr><td class="SmallText"><b>','</b></td></tr><tr><td class="quote"><br />','<br /></td></tr></table>'), array('
', '

', '
'), $fudml);
// old bad code
$fudml = str_replace(array('<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1"><tr><td class="SmallText"><b>','</b></td></tr><tr><td class="quote"><br>','<br></td></tr></table>'), array('
', '

', '
'), $fudml);
}

/* old format */
if (preg_match('!<div class="dashed" style="padding: 3px;" align="center" width="100%"><a href="javascript://" OnClick="javascript: layerVis\(\'.*?\', 1\);">.*?</a><div align="left" id="(.*?)" style="visibility: hidden;">!is', $fudml)) {
$fudml = preg_replace('!\<div class\="dashed" style\="padding: 3px;" align\="center" width\="100%"\>\<a href\="javascript://" OnClick\="javascript: layerVis\(\'.*?\', 1\);">(.*?)\</a\>\<div align\="left" id\=".*?" style\="visibility: hidden;"\>!is', '
\1
', $fudml);
}

/* new format */
if (preg_match('!<div class="dashed" style="padding: 3px;" align="center" width="100%"><a href="javascript://" OnClick="javascript: layerVis\(\'.*?\', 1\);">.*?</a><div align="left" id="(.*?)" style="display: none;">!is', $fudml)) {
$fudml = preg_replace('!\<div class\="dashed" style\="padding: 3px;" align\="center" width\="100%"\>\<a href\="javascript://" OnClick\="javascript: layerVis\(\'.*?\', 1\);">(.*?)\</a\>\<div align\="left" id\=".*?" style\="display: none;"\>!is', '
\1
', $fudml);
}

$fudml = str_replace('<font face=', '<font font=', $fudml);
foreach (array('color', 'font', 'size') as $v) {
while (preg_match('!<font '.$v.'=".+?">.*?</font>!is', $fudml, $m)) {
$fudml = preg_replace('!<font '.$v.'="(.+?)">(.*?)</font>!is', '['.$v.'=\1]\2[/'.$v.']', $fudml);
}
}

while (preg_match('!<acronym title=".+?">.*?</acronym>!is', $fudml)) {
$fudml = preg_replace('!<acronym title="(.+?)">(.*?)</acronym>!is', '\2', $fudml);
}
while (preg_match('!<(o|u)l type=".+?">.*?</\\1l>!is', $fudml)) {
$fudml = preg_replace('!<(o|u)l type="(.+?)">(.*?)</\\1l>!is', '
    \3
', $fudml);
}

$fudml = str_replace(
array(
'<b>', '</b>', '<i>', '</i>', '<u>', '</u>', '<s>', '</s>', '<sub>', '</sub>', '<sup>', '</sup>', '<del>', '</del>',
'<div class="pre"><pre>', '</pre></div>', '<div align="center">', '<div align="left">', '<div align="right">', '</div>',
'<ul>', '</ul>', '<span name="notag">', '</span>', '<li>', '@', '://', '<br />', '<pre>', '</pre>'
),
array(
'', '', '', '', '', '', '', '', '', '', '', '', '', '',
'
', '
', '[align=center]', '[align=left]', '
', '
', '
    ', '
',
'', '', '[*]', '@', '://', '', '
', '
'
),
$fudml);

while (preg_match('!<img src="(.*?)" border=0 alt="\\1">!is', $fudml)) {
$fudml = preg_replace('!<img src="(.*?)" border=0 alt="\\1">!is', '\1', $fudml);
}
while (preg_match('!<img class="(r|l)" src="(.*?)" border=0 alt="\\2">!is', $fudml)) {
$fudml = preg_replace('!<img class="(r|l)" src="(.*?)" border=0 alt="\\2">!is', '\2[/img\1]', $fudml);
}
while (preg_match('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', $fudml)) {
$fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">\\1</a>!is', '\1', $fudml);
}
while (preg_match('!<a href="(.+?)" target="_blank">\\1</a>!is', $fudml)) {
$fudml = preg_replace('!<a href="(.+?)" target="_blank">\\1</a>!is', '\1', $fudml);
}

if (strpos($fudml, '<img src="') !== false) {
$fudml = preg_replace('!<img src="(.*?)" border=0 alt="(.*?)">!is', '\2', $fudml);
}
if (strpos($fudml, '<img class="') !== false) {
$fudml = preg_replace('!<img class="(r|l)" src="(.*?)" border=0 alt="(.*?)">!is', '\3[/img\1]', $fudml);
}
if (strpos($fudml, '<a href="mailto:') !== false) {
$fudml = preg_replace('!<a href="mailto:(.+?)" target="_blank">(.+?)</a>!is', '\2', $fudml);
}
if (strpos($fudml, '<a href="') !== false) {
$fudml = preg_replace('!<a href="(.+?)" target="_blank">(.+?)</a>!is', '\2', $fudml);
}

if (isset($php)) {
$fudml = str_replace(array_keys($php), array_values($php), $fudml);
}

/* unhtmlspecialchars */
return reverse_fmt($fudml);
}


function filter_ext($file_name)
{
include $GLOBALS['FORUM_SETTINGS_PATH'] . 'file_filter_regexp';
if (empty($GLOBALS['__FUD_EXT_FILER__'])) {
return;
}
if (($p = strrpos($file_name, '.')) === false) {
return 1;
}
return !in_array(strtolower(substr($file_name, ($p + 1))), $GLOBALS['__FUD_EXT_FILER__']);
}

function safe_tmp_copy($source, $del_source=0, $prefx='')
{
if (!$prefx) {
$prefx = getmypid();
}

$umask = umask(($GLOBALS['FUD_OPT_2'] & 8388608 ? 0177 : 0111));
if (!move_uploaded_file($source, ($name = tempnam($GLOBALS['TMP'], $prefx.'_')))) {
return;
}
umask($umask);
if ($del_source) {
@unlink($source);
}
umask($umask);

return basename($name);
}

function reverse_nl2br(&$data)
{
if (strpos($data, '<br />') !== false) {
return str_replace('<br />', '', $data);
}
return $data;
}function apply_custom_replace($text)
{
if (!defined('__fud_replace_init')) {
make_replace_array();
}
if (empty($GLOBALS['__FUD_REPL__'])) {
return $text;
}

return preg_replace($GLOBALS['__FUD_REPL__']['pattern'], $GLOBALS['__FUD_REPL__']['replace'], $text);
}

function make_replace_array()
{
$GLOBALS['__FUD_REPL__']['pattern'] = $GLOBALS['__FUD_REPL__']['replace'] = array();
$a =& $GLOBALS['__FUD_REPL__']['pattern'];
$b =& $GLOBALS['__FUD_REPL__']['replace'];

$c = uq('SELECT with_str, replace_str FROM fud26_replace WHERE replace_str IS NOT NULL AND with_str IS NOT NULL AND LENGTH(replace_str)>0');
while ($r = db_rowarr($c)) {
$a[] = $r[1];
$b[] = $r[0];
}

define('__fud_replace_init', 1);
}

function make_reverse_replace_array()
{
$GLOBALS['__FUD_REPLR__']['pattern'] = $GLOBALS['__FUD_REPLR__']['replace'] = array();
$a =& $GLOBALS['__FUD_REPLR__']['pattern'];
$b =& $GLOBALS['__FUD_REPLR__']['replace'];

$c = uq('SELECT replace_opt, with_str, replace_str, from_post, to_msg FROM fud26_replace');
while ($r = db_rowarr($c)) {
if (!$r[0]) {
$a[] = $r[3];
$b[] = $r[4];
} else if ($r[0] && strlen($r[1]) && strlen($r[2])) {
$a[] = '/'.str_replace('/', '\\/', preg_quote(stripslashes($r[1]))).'/';
preg_match('/\/(.+)\/(.*)/', $r[2], $regs);
$b[] = str_replace('\\/', '/', $regs[1]);
}
}

define('__fud_replacer_init', 1);
}

function apply_reverse_replace($text)
{
if (!defined('__fud_replacer_init')) {
make_reverse_replace_array();
}
if (empty($GLOBALS['__FUD_REPLR__'])) {
return $text;
}
return preg_replace($GLOBALS['__FUD_REPLR__']['pattern'], $GLOBALS['__FUD_REPLR__']['replace'], $text);
}function fud_wrap_tok($data)
{
$wa = array();
$len = strlen($data);

$i=$j=$p=0;
$str = '';
while ($i < $len) {
switch ($data{$i}) {
case ' ':
case "\n":
case "\t":
if ($j) {
$wa[] = array('word'=>$str, 'len'=>($j+1));
$j=0;
$str ='';
}

$wa[] = array('word'=>$data[$i]);

break;
case '<':
if (($p = strpos($data, '>', $i)) !== false) {
if ($j) {
$wa[] = array('word'=>$str, 'len'=>($j+1));
$j=0;
$str ='';
}
$s = substr($data, $i, ($p - $i) + 1);
if ($s == '<pre>') {
$s = substr($data, $i, ($p = (strpos($data, '</pre>', $p) + 6)) - $i);
--$p;
} else if ($s == '<span name="php">') {
$s = substr($data, $i, ($p = (strpos($data, '</span>', $p) + 7)) - $i);
--$p;
}

$wa[] = array('word' => $s);

$i = $p;
$j = 0;
} else {
$str .= $data[$i];
$j++;
}
break;

case '&':
if (($e = strpos($data, ';', $i))) {
$st = substr($data, $i, ($e - $i + 1));
if (($st{1} == '#' && is_numeric(substr($st, 3, -1))) || !strcmp($st, '&nbsp;') || !strcmp($st, '&gt;') || !strcmp($st, '&lt;') || !strcmp($st, '&quot;')) {
if ($j) {
$wa[] = array('word'=>$str, 'len'=>($j+1));
$j=0;
$str ='';
}

$wa[] = array('word' => $st, 'sp' => 1);
$i=$e;
$j=0;
break;
}
} /* fall through */
default:
$str .= $data[$i];
$j++;
}
$i++;
}

if ($j) {
$wa[] = array('word'=>$str, 'len'=>($j+1));
}

return $wa;
}

function fud_wordwrap(&$data)
{
if (!$GLOBALS['WORD_WRAP'] || $GLOBALS['WORD_WRAP'] >= strlen($data)) {
return;
}

$wa = fud_wrap_tok($data);
$m = (int) $GLOBALS['WORD_WRAP'];
$l = 0;
$data = '';
foreach($wa as $v) {
if (isset($v['len']) && $v['len'] > $m) {
if ($v['len'] + $l > $m) {
$l = 0;
$data .= ' ';
}
$data .= wordwrap($v['word'], $m, ' ', 1);
$l += $v['len'];
} else {
if (isset($v['sp'])) {
if ($l > $m) {
$data .= ' ';
$l = 0;
}
++$l;
} else if (!isset($v['len'])) {
$l = 0;
} else {
$l += $v['len'];
}
$data .= $v['word'];
}
}
}function init_spell($type, $dict)
{
$pspell_config = pspell_config_create($dict);
pspell_config_mode($pspell_config, $type);
pspell_config_personal($pspell_config, $GLOBALS['FORUM_SETTINGS_PATH']."forum.pws");
pspell_config_ignore($pspell_config, 2);
define('__FUD_PSPELL_LINK__', pspell_new_config($pspell_config));

return true;
}

function tokenize_string($data)
{
if (!($len = strlen($data))) {
return array();
}
$wa = array();

$i = $p = 0;
$seps = array(','=>1,' '=>1,'/'=>1,'\\'=>1,'.'=>1,'=>1,'=>1,'!'=>1,'>'=>1,'?'=>1,"\n"= >1,"\r"=>1,"\t"=>1,")"=>1,"("=>1,"}"=>1,"{"=>1,"["=>1, "]"=>1,"*"=>1,";"=>1,'='=>1,':'=>1,'1'=>1,'2'=>1,'3'=>1,'4'=>1,'5'= >1,'6'=>1,'7'=>1,'8'=>1,'9'=>1,'0'=>1);

while ($i < $len) {
if (isset($seps[$data{$i}])) {
if (isset($str)) {
$wa[] = array('token'=>$str, 'check'=>1);
unset($str);
}
$wa[] = array('token'=>$data[$i], 'check'=>0);
} else if ($data{$i} == '<') {
if (($p = strpos($data, '>', $i)) !== false) {
if (isset($str)) {
$wa[] = array('token'=>$str, 'check'=>1);
unset($str);
}

$wrd = substr($data,$i,($p-$i)+1);
$p3=$l=null;

if ($wrd == '<pre>') {
$l = 'pre';
} else if ($wrd == '<table border="0" align="center" width="90%" cellpadding="3" cellspacing="1">') {
$l = 1;
$p3 = $p;

while ($l > 0) {
$p3 = strpos($data, 'table', $p3);

if ($data[$p3-1] == '<') {
$l++;
} else if ($data[$p3-1] == '/' && $data[$p3-2] == '<') {
$l--;
}

$p3 = strpos($data, '>', $p3);
}
}

if ($p3) {
$p = $p3;
$wrd = substr($data, $i, ($p-$i)+1);
} else if ($l && ($p2 = strpos($data, '</'.$l.'>', $p))) {
$p = $p2+1+strlen($l)+1;
$wrd = substr($data,$i,($p-$i)+1);
}

$wa[] = array('token'=>$wrd, 'check'=>0);
$i = $p;
} else {
$str .= $data[$i];
}
} else if ($data{$i} == '&') {
if (isset($str)) {
$wa[] = array('token'=>$str, 'check'=>1);
unset($str);
}

$regs = array();
if (preg_match('!(\&[A-Za-z0-9]{2,5}\;)!', substr($data,$i,6), $regs)) {
$wa[] = array('token'=>$regs[1], 'check'=>0);
$i += strlen($regs[1])-1;
} else {
$wa[] = array('token'=>$data[$i], 'check'=>0);
}
} else if (isset($str)) {
$str .= $data[$i];
} else {
$str = $data[$i];
}
$i++;
}

if (isset($str)) {
$wa[] = array('token'=>$str, 'check'=>1);
}

return $wa;
}

function draw_spell_sug_select($v,$k,$type)
{
$sel_name = 'spell_chk_'.$type.'_'.$k;
$data = '<select name="'.$sel_name.'">';
$data .= '<option value="'.htmlspecialchars($v['token']).'">'.htmlspecialchars($v['token']).' </option>';
$i = 0;
foreach(pspell_suggest(__FUD_PSPELL_LINK__, $v['token']) as $va) {
$data .= '<option value="'.$va.'">'.++$i.') '.$va.'</option>';
}

if (!$i) {
$data .= '<option value="">no alternatives</option>';
}

$data .= '</select>';

return $data;
}

function spell_replace($wa,$type)
{
$data = '';

foreach($wa as $k => $v) {
if( $v['check']==1 && isset($_POST['spell_chk_'.$type.'_'.$k]) && strlen($_POST['spell_chk_'.$type.'_'.$k])) {
$data .= $_POST['spell_chk_'.$type.'_'.$k];
} else {
$data .= $v['token'];
}
}

return $data;
}

function spell_check_ar($wa,$type)
{
foreach($wa as $k => $v) {
if ($v['check'] > 0 && !pspell_check(__FUD_PSPELL_LINK__, $v['token'])) {
$wa[$k]['token'] = draw_spell_sug_select($v, $k, $type);
}
}

return $wa;
}

function reasemble_string($wa)
{
$data = '';
foreach($wa as $v) {
$data .= $v['token'];
}

return $data;
}

function check_data_spell($data, $type, $dict)
{
if (!$data || (!defined('__FUD_PSPELL_LINK__') && !init_spell(PSPELL_FAST, $dict))) {
return $data;
}

return reasemble_string(spell_check_ar(tokenize_string($data), $type));
}function is_notified($user_id, $thread_id)
{
return q_singleval('SELECT * FROM fud26_thread_notify WHERE thread_id='.$thread_id.' AND user_id='.$user_id);
}

function thread_notify_add($user_id, $thread_id)
{
db_li('INSERT INTO fud26_thread_notify (user_id, thread_id) VALUES ('.$user_id.', '.$thread_id.')', $ret);
}

function thread_notify_del($user_id, $thread_id)
{
q('DELETE FROM fud26_thread_notify WHERE thread_id='.$thread_id.' AND user_id='.$user_id);
}$GLOBALS['__error__'] = 0;
$GLOBALS['__err_msg__'] = array();

function set_err($err, $msg)
{
$GLOBALS['__err_msg__'][$err] = $msg;
$GLOBALS['__error__'] = 1;
}

function is_post_error()
{
return $GLOBALS['__error__'];
}

function get_err($err, $br=0)
{
if (isset($err, $GLOBALS['__err_msg__'][$err])) {
return ($br ? '<span class="ErrorText">'.$GLOBALS['__err_msg__'][$err].'</span><br />' : '<br /><span class="ErrorText">'.$GLOBALS['__err_msg__'][$err].'</span>');
}
}

function post_check_images()
{
if ($GLOBALS['MAX_IMAGE_COUNT'] && $GLOBALS['MAX_IMAGE_COUNT'] < count_images($_POST['msg_body'])) {
return -1;
}

return 0;
}

function check_post_form()
{
/* make sure we got a valid subject */
if (!strlen(trim($_POST['msg_subject']))) {
set_err('msg_subject', 'Se requiere asunto');
}

/* make sure the number of images [img] inside the body do not exceed the allowed limit */
if (post_check_images()) {
set_err('msg_body', 'Se permite un máximo de '.$GLOBALS['MAX_IMAGE_COUNT'].' imágenes por mensaje, por favor reduzca el número de imágenes');
}

if (defined('fud_bad_sq')) {
unset($_POST['submitted']);
set_err('msg_session', '<h4 align="center" class="ErrorText">Your session had expired, please re-submit the form. Sorry for the inconvenience.</h4>');
}

return $GLOBALS['__error__'];
}

function check_ppost_form($msg_subject)
{
if (!strlen(trim($msg_subject))) {
set_err('msg_subject', 'Se requiere asunto');
}

if (post_check_images()) {
set_err('msg_body', 'Se permite un máximo de '.$GLOBALS['MAX_IMAGE_COUNT'].' imágenes por mensaje, por favor reduzca el número de imágenes');
}
$GLOBALS['recv_user_id'] = array();
/* hack for login names containing HTML entities ex. { */
if (($hack = strpos($_POST['msg_to_list'], '&#')) !== false) {
$hack_str = preg_replace('!&#([0-9]+);!', '&#\1#', $_POST['msg_to_list']);
} else {
$hack_str = $_POST['msg_to_list'];
}
foreach(explode(';', $hack_str) as $v) {
$v = trim($v);
if (strlen($v)) {
if ($hack !== false) {
$v = preg_replace('!&#([0-9]+)#!', '&#\1;', $v);
}
if (!($obj = db_sab('SELECT u.users_opt, u.id, ui.ignore_id FROM fud26_users u LEFT JOIN fud26_user_ignore ui ON ui.user_id=u.id AND ui.ignore_id='._uid.' WHERE u.alias='.strnull(addslashes(char_fix(htmlspecialchars($v))))))) {
set_err('msg_to_list', 'No hay un usuario llamado "'.char_fix(htmlspecialchars($v)).'" en este foro');
break;
}
if (!empty($obj->ignore_id)) {
set_err('msg_to_list', 'Ud no puede enviar un mensaje privado a "'.char_fix(htmlspecialchars($v)).'", porque este usuario lo está ignorando.');
break;
} else if (!($obj->users_opt & 32) && !$GLOBALS['is_a']) {
set_err('msg_to_list', 'You cannot send a private message to "'.htmlspecialchars($v).'", because this person is not accepting private messages.');
break;
} else {
$GLOBALS['recv_user_id'][] = $obj->id;
}
}
}

if (empty($_POST['msg_to_list'])) {
set_err('msg_to_list', 'No se puede enviar mensaje, falta remitente');
}

if (defined('fud_bad_sq')) {
unset($_POST['btn_action']);
set_err('msg_session', '<h4 align="center" class="ErrorText">Your session had expired, please re-submit the form. Sorry for the inconvenience.</h4>');
}

return $GLOBALS['__error__'];
}

function check_femail_form()
{
if (empty($_POST['femail']) || validate_email($_POST['femail'])) {
set_err('femail', 'Por favor ingrese una dirección de e-mail válida para su amigo.');
}
if (empty($_POST['subj'])) {
set_err('subj', 'No puede enviar un e-mail sin asunto.');
}
if (empty($_POST['body'])) {
set_err('body', 'No puede enviar un e-mail sin el cuerpo del mensaje.');
}
if (defined('fud_bad_sq')) {
unset($_POST['posted']);
set_err('msg_session', '<h4 align="center" class="ErrorText">Your session had expired, please re-submit the form. Sorry for the inconvenience.</h4>');
}

return $GLOBALS['__error__'];
}

function count_images($text)
{
$text = strtolower($text);
$a = substr_count($text, '');<br />
	$b = substr_count($text, '');

return (($a > $b) ? $b : $a);
}function poll_delete($id)
{
if (!$id) {
return;
}

q('UPDATE fud26_msg SET poll_id=0 WHERE poll_id='.$id);
q('DELETE FROM fud26_poll_opt WHERE poll_id='.$id);
q('DELETE FROM fud26_poll_opt_track WHERE poll_id='.$id);
q('DELETE FROM fud26_poll WHERE id='.$id);
}

function poll_fetch_opts($id)
{
$a = array();
$c = uq('SELECT id,name FROM fud26_poll_opt WHERE poll_id='.$id);
while ($r = db_rowarr($c)) {
$a[$r[0]] = $r[1];
}

return $a;
}

function poll_del_opt($id, $poll_id)
{
q('DELETE FROM fud26_poll_opt WHERE poll_id='.$poll_id.' AND id='.$id);
q('DELETE FROM fud26_poll_opt_track WHERE poll_id='.$poll_id.' AND poll_opt='.$id);
if ($GLOBALS['FUD_OPT_3'] & 1024 || __dbtype__ != 'mysql') {
q('UPDATE fud26_poll SET total_votes=(SELECT SUM(count) FROM fud26_poll_opt WHERE id='.$id.') WHERE id='.$poll_id);
} else {
q('UPDATE fud26_poll SET total_votes='.(int) q_singleval('SELECT SUM(count) FROM fud26_poll_opt WHERE id='.$id).' WHERE id='.$poll_id);
}
}

function poll_activate($poll_id, $frm_id)
{
q('UPDATE fud26_poll SET forum_id='.$frm_id.' WHERE id='.$poll_id);
}

function poll_sync($poll_id, $name, $max_votes, $expiry)
{
q("UPDATE fud26_poll SET name='".addslashes(htmlspecialchars($name))."', expiry_date=".intzero($expiry).", max_votes=".intzero($max_votes)." WHERE id=".$poll_id);
}

function poll_add($name, $max_votes, $expiry, $uid=_uid)
{
return db_qid("INSERT INTO fud26_poll (name, owner, creation_date, expiry_date, max_votes) VALUES ('".addslashes(htmlspecialchars($name))."', ".$uid.", ".__request_timestamp__.", ".intzero($expiry).", ".intzero($max_votes).")");
}

function poll_opt_sync($id, $name)
{
q("UPDATE fud26_poll_opt SET name='".addslashes($name)."' WHERE id=".$id);
}

function poll_opt_add($name, $poll_id)
{
return db_qid("INSERT INTO fud26_poll_opt (poll_id,name) VALUES(".$poll_id.", '".addslashes($name)."')");
}

function poll_validate($poll_id, $msg_id)
{
if (($mid = (int) q_singleval('SELECT id FROM fud26_msg WHERE poll_id='.$poll_id)) && $mid != $msg_id) {
return 0;
}
return $poll_id;
}function frm_updt_counts($frm_id, $replies, $threads, $last_post_id)
{
$threads = !$threads ? '' : ', thread_count=thread_count+'.$threads;
$last_post_id = !$last_post_id ? '' : ', last_post_id='.$last_post_id;

q('UPDATE fud26_forum SET post_count=post_count+'.$replies.$threads.$last_post_id.' WHERE id='.$frm_id);
}function msg_get($id)
{
if (($r = db_sab('SELECT * FROM fud26_msg WHERE id='.$id))) {
$r->body = read_msg_body($r->foff, $r->length, $r->file_id);
return $r;
}
error_dialog('Invalid Message', 'The message you are trying to view does not exist.');
}

function poll_cache_rebuild($poll_id, &$data)
{
if (!$poll_id) {
$data = null;
return;
}

if (!$data) { /* rebuild from cratch */
$c = uq('SELECT id, name, count FROM fud26_poll_opt WHERE poll_id='.$poll_id);
while ($r = db_rowarr($c)) {
$data[$r[0]] = array($r[1], $r[2]);
}
if (!$data) {
$data = null;
}
} else { /* register single vote */
$data[$poll_id][1] += 1;
}
}class fud_msg
{
var $id, $thread_id, $poster_id, $reply_to, $ip_addr, $host_name, $post_stamp, $subject, $attach_cnt, $poll_id,
$update_stamp, $icon, $apr, $updated_by, $login, $length, $foff, $file_id, $msg_opt,
$file_id_preview, $length_preview, $offset_preview, $body, $mlist_msg_id;
}

$GLOBALS['CHARSET'] = 'ISO-8859-15';

class fud_msg_edit extends fud_msg
{
function add_reply($reply_to, $th_id=null, $perm, $autoapprove=1)
{
if ($reply_to) {
$this->reply_to = $reply_to;
$fd = db_saq('SELECT t.forum_id, f.message_threshold, f.forum_opt FROM fud26_msg m INNER JOIN fud26_thread t ON m.thread_id=t.id INNER JOIN fud26_forum f ON f.id=t.forum_id WHERE m.id='.$reply_to);
} else {
$fd = db_saq('SELECT t.forum_id, f.message_threshold, f.forum_opt FROM fud26_thread t INNER JOIN fud26_forum f ON f.id=t.forum_id WHERE t.id='.$th_id);
}

return $this->add($fd[0], $fd[1], $fd[2], $perm, $autoapprove);
}

function add($forum_id, $message_threshold, $forum_opt, $perm, $autoapprove=1)
{
if (!$this->post_stamp) {
$this->post_stamp = __request_timestamp__;
}

if (!isset($this->ip_addr)) {
$this->ip_addr = get_ip();
}
$this->host_name = $GLOBALS['FUD_OPT_1'] & 268435456 ? "'".addslashes(get_host($this->ip_addr))."'" : 'NULL';
$this->thread_id = isset($this->thread_id) ? $this->thread_id : 0;
$this->reply_to = isset($this->reply_to) ? $this->reply_to : 0;

$file_id = write_body($this->body, $length, $offset, $forum_id);

/* determine if preview needs building */
if ($message_threshold && $message_threshold < strlen($this->body)) {
$thres_body = trim_html($this->body, $message_threshold);
$file_id_preview = write_body($thres_body, $length_preview, $offset_preview, $forum_id);
} else {
$file_id_preview = $offset_preview = $length_preview = 0;
}

poll_cache_rebuild($this->poll_id, $poll_cache);
$poll_cache = ($poll_cache ? serialize($poll_cache) : null);

$this->id = db_qid("INSERT INTO fud26_msg (
thread_id,
poster_id,
reply_to,
ip_addr,
host_name,
post_stamp,
subject,
attach_cnt,
poll_id,
icon,
msg_opt,
file_id,
foff,
length,
file_id_preview,
offset_preview,
length_preview,
mlist_msg_id,
poll_cache
) VALUES(
".$this->thread_id.",
".$this->poster_id.",
".(int)$this->reply_to.",
'".$this->ip_addr."',
".$this->host_name.",
".$this->post_stamp.",
".strnull(addslashes($this->subject)).",
".(int)$this->attach_cnt.",
".(int)$this->poll_id.",
".strnull(addslashes($this->icon)).",
".$this->msg_opt.",
".$file_id.",
".(int)$offset.",
".(int)$length.",
".$file_id_preview.",
".$offset_preview.",
".$length_preview.",
".strnull($this->mlist_msg_id).",
".strnull(addslashes($poll_cache))."
)");

$thread_opt = (int) ($perm & 4096 && isset($_POST['thr_locked']));

if (!$this->thread_id) { /* new thread */
if ($perm & 64 && isset($_POST['thr_ordertype'], $_POST['thr_orderexpiry'])) {
if ((int)$_POST['thr_ordertype']) {
$thread_opt |= (int) $_POST['thr_ordertype'];
$thr_orderexpiry = (int) $_POST['thr_orderexpiry'];
}
}

$this->thread_id = th_add($this->id, $forum_id, $this->post_stamp, $thread_opt, (isset($thr_orderexpiry) ? $thr_orderexpiry : 0));

q('UPDATE fud26_msg SET thread_id='.$this->thread_id.' WHERE id='.$this->id);
} else {
th_lock($this->thread_id, $thread_opt & 1);
}

if ($autoapprove && $forum_opt & 2) {
$this->approve($this->id);
}

return $this->id;
}

function sync($id, $frm_id, $message_threshold, $perm)
{
$file_id = write_body($this->body, $length, $offset, $frm_id);

/* determine if preview needs building */
if ($message_threshold && $message_threshold < strlen($this->body)) {
$thres_body = trim_html($this->body, $message_threshold);
$file_id_preview = write_body($thres_body, $length_preview, $offset_preview, $forum_id);
} else {
$file_id_preview = $offset_preview = $length_preview = 0;
}

poll_cache_rebuild($this->poll_id, $poll_cache);
$poll_cache = ($poll_cache ? serialize($poll_cache) : null);

q("UPDATE fud26_msg SET
file_id=".$file_id.",
foff=".(int)$offset.",
length=".(int)$length.",
mlist_msg_id=".strnull(addslashes($this->mlist_msg_id)).",
file_id_preview=".$file_id_preview.",
offset_preview=".$offset_preview.",
length_preview=".$length_preview.",
updated_by=".$id.",
msg_opt=".$this->msg_opt.",
attach_cnt=".(int)$this->attach_cnt.",
poll_id=".(int)$this->poll_id.",
update_stamp=".__request_timestamp__.",
icon=".strnull(addslashes($this->icon))." ,
poll_cache=".strnull(addslashes($poll_cache)).",
subject=".strnull(addslashes($this->subject))."
WHERE id=".$this->id);

/* determine wether or not we should deal with locked & sticky stuff
* current approach may seem a little redundant, but for (most) users who
* do not have access to locking & sticky this eliminated a query.
*/
$th_data = db_saq('SELECT orderexpiry, thread_opt, root_msg_id FROM fud26_thread WHERE id='.$this->thread_id);
$locked = (int) isset($_POST['thr_locked']);
if (isset($_POST['thr_ordertype'], $_POST['thr_orderexpiry']) || (($th_data[1] ^ $locked) & 1)) {
$thread_opt = (int) $th_data[1];
$orderexpiry = isset($_POST['thr_orderexpiry']) ? (int) $_POST['thr_orderexpiry'] : 0;

/* confirm that user has ability to change lock status of the thread */
if ($perm & 4096) {
if ($locked && !($thread_opt & $locked)) {
$thread_opt |= 1;
} else if (!$locked && $thread_opt & 1) {
$thread_opt &= ~1;
}
}

/* confirm that user has ability to change sticky status of the thread */
if ($th_data[2] == $this->id && isset($_POST['thr_ordertype'], $_POST['thr_orderexpiry']) && $perm & 64) {
if (!$_POST['thr_ordertype'] && $thread_opt>1) {
$orderexpiry = 0;
$thread_opt &= ~6;
} else if ($thread_opt < 2 && (int) $_POST['thr_ordertype']) {
$thread_opt |= $_POST['thr_ordertype'];
} else if (!($thread_opt & (int) $_POST['thr_ordertype'])) {
$thread_opt = $_POST['thr_ordertype'] | ($thread_opt & 1);
}
}

/* Determine if any work needs to be done */
if ($thread_opt != $th_data[1] || $orderexpiry != $th_data[0]) {
q("UPDATE fud26_thread SET thread_opt=".$thread_opt.", orderexpiry=".$orderexpiry." WHERE id=".$this->thread_id);
/* Avoid rebuilding the forum view whenever possible, since it's a rather slow process
* Only rebuild if expiry time has changed or message gained/lost sticky status
*/
$diff = $thread_opt ^ $th_data[1];
if (($diff > 1 && !($diff & 6)) || $orderexpiry != $th_data[0]) {
rebuild_forum_view($frm_id);
}
}
}

if ($GLOBALS['FUD_OPT_1'] & 16777216) {
delete_msg_index($this->id);
index_text((preg_match('!^Re: !i', $this->subject) ? '': $this->subject), $this->body, $this->id);
}
}

function delete($rebuild_view=1, $mid=0, $th_rm=0)
{
if (!$mid) {
$mid = $this->id;
}

if (!db_locked()) {
db_lock('fud26_thr_exchange WRITE, fud26_thread_view WRITE, fud26_level WRITE, fud26_forum WRITE, fud26_forum_read WRITE, fud26_thread WRITE, fud26_msg WRITE, fud26_attach WRITE, fud26_poll WRITE, fud26_poll_opt WRITE, fud26_poll_opt_track WRITE, fud26_users WRITE, fud26_thread_notify WRITE, fud26_msg_report WRITE, fud26_thread_rate_track WRITE');
$ll = 1;
}

if (!($del = db_sab('SELECT
fud26_msg.id, fud26_msg.attach_cnt, fud26_msg.poll_id, fud26_msg.thread_id, fud26_msg.reply_to, fud26_msg.apr, fud26_msg.poster_id,
fud26_thread.replies, fud26_thread.root_msg_id AS root_msg_id, fud26_thread.last_post_id AS thread_lip, fud26_thread.forum_id,
fud26_forum.last_post_id AS forum_lip FROM fud26_msg LEFT JOIN fud26_thread ON fud26_msg.thread_id=fud26_thread.id LEFT JOIN fud26_forum ON fud26_thread.forum_id=fud26_forum.id WHERE fud26_msg.id='.$mid))) {
if (isset($ll)) {
db_unlock();
}
return;
}

/* attachments */
if ($del->attach_cnt) {
$res = q('SELECT location FROM fud26_attach WHERE message_id='.$mid." AND attach_opt=0");
while ($loc = db_rowarr($res)) {
@unlink($loc[0]);
}
unset($res);
q('DELETE FROM fud26_attach WHERE message_id='.$mid." AND attach_opt=0");
}

q('DELETE FROM fud26_msg_report WHERE msg_id='.$mid);

if ($del->poll_id) {
poll_delete($del->poll_id);
}

/* check if thread */
if ($del->root_msg_id == $del->id) {
$th_rm = 1;
/* delete all messages in the thread if there is more then 1 message */
if ($del->replies) {
$rmsg = q('SELECT id FROM fud26_msg WHERE thread_id='.$del->thread_id.' AND id != '.$del->id);
while ($dim = db_rowarr($rmsg)) {
fud_msg_edit::delete(false, $dim[0], 1);
}
unset($rmsg);
}

q('DELETE FROM fud26_thread_notify WHERE thread_id='.$del->thread_id);
q('DELETE FROM fud26_thread WHERE id='.$del->thread_id);
q('DELETE FROM fud26_thread_rate_track WHERE thread_id='.$del->thread_id);
q('DELETE FROM fud26_thr_exchange WHERE th='.$del->thread_id);

if ($del->apr) {
/* we need to determine the last post id for the forum, it can be null */
$lpi = (int) q_singleval('SELECT fud26_thread.last_post_id FROM fud26_thread INNER JOIN fud26_msg ON fud26_thread.last_post_id=fud26_msg.id AND fud26_msg.apr=1 WHERE forum_id='.$del->forum_id.' AND moved_to=0 ORDER BY fud26_msg.post_stamp DESC LIMIT 1');
q('UPDATE fud26_forum SET last_post_id='.$lpi.', thread_count=thread_count-1, post_count=post_count-'.$del->replies.'-1 WHERE id='.$del->forum_id);
}
} else if (!$th_rm && $del->apr) {
q('UPDATE fud26_msg SET reply_to='.$del->reply_to.' WHERE thread_id='.$del->thread_id.' AND reply_to='.$mid);

/* check if the message is the last in thread */
if ($del->thread_lip == $del->id) {
list($lpi, $lpd) = db_saq('SELECT id, post_stamp FROM fud26_msg WHERE thread_id='.$del->thread_id.' AND apr=1 AND id!='.$del->id.' ORDER BY post_stamp DESC LIMIT 1');
q('UPDATE fud26_thread SET last_post_id='.$lpi.', last_post_date='.$lpd.', replies=replies-1 WHERE id='.$del->thread_id);
} else {
q('UPDATE fud26_thread SET replies=replies-1 WHERE id='.$del->thread_id);
}

/* check if the message is the last in the forum */
if ($del->forum_lip == $del->id) {
$lp = db_saq('SELECT fud26_thread.last_post_id, fud26_thread.last_post_date FROM fud26_thread_view INNER JOIN fud26_thread ON fud26_thread_view.forum_id=fud26_thread.forum_id AND fud26_thread_view.thread_id=fud26_thread.id WHERE fud26_thread_view.forum_id='.$del->forum_id.' AND fud26_thread_view.page=1 AND fud26_thread.moved_to=0 ORDER BY fud26_thread.last_post_date DESC LIMIT 1');
if (!isset($lpd) || $lp[1] > $lpd) {
$lpi = $lp[0];
}
q('UPDATE fud26_forum SET post_count=post_count-1, last_post_id='.$lpi.' WHERE id='.$del->forum_id);
} else {
q('UPDATE fud26_forum SET post_count=post_count-1 WHERE id='.$del->forum_id);
}
}

q('DELETE FROM fud26_msg WHERE id='.$mid);

if ($del->apr) {
if ($del->poster_id) {
user_set_post_count($del->poster_id);
}

if ($rebuild_view) {
rebuild_forum_view($del->forum_id);

/* needed for moved thread pointers */
$r = q('SELECT forum_id, id FROM fud26_thread WHERE root_msg_id='.$del->root_msg_id);
while (($res = db_rowarr($r))) {
if ($th_rm) {
q('DELETE FROM fud26_thread WHERE id='.$res[1]);
}
rebuild_forum_view($res[0]);
}
unset($r);
}
}

if (isset($ll)) {
db_unlock();
}
}

function approve($id)
{
/* fetch info about the message, poll (if one exists), thread & forum */
$mtf = db_sab('SELECT
m.id, m.poster_id, m.apr, m.subject, m.foff, m.length, m.file_id, m.thread_id, m.poll_id, m.attach_cnt,
m.post_stamp, m.reply_to, m.mlist_msg_id, m.msg_opt,
t.forum_id, t.last_post_id, t.root_msg_id, t.last_post_date,
m2.post_stamp AS frm_last_post_date,
f.name AS frm_name,
u.alias, u.email, u.sig,
n.id AS nntp_id, ml.id AS mlist_id
FROM fud26_msg m
INNER JOIN fud26_thread t ON m.thread_id=t.id
INNER JOIN fud26_forum f ON t.forum_id=f.id
LEFT JOIN fud26_msg m2 ON f.last_post_id=m2.id
LEFT JOIN fud26_users u ON m.poster_id=u.id
LEFT JOIN fud26_mlist ml ON ml.forum_id=f.id AND (ml.mlist_opt & 2) > 0
LEFT JOIN fud26_nntp n ON n.forum_id=f.id AND (n.nntp_opt & 2) > 0
WHERE m.id='.$id.' AND m.apr=0');

/* nothing to do or bad message id */
if (!$mtf) {
return;
}

if ($mtf->alias) {
$mtf->alias = reverse_fmt($mtf->alias);
} else {
$mtf->alias = $GLOBALS['ANON_NICK'];
}

q("UPDATE fud26_msg SET apr=1 WHERE id=".$mtf->id);

if ($mtf->poster_id) {
user_set_post_count($mtf->poster_id);
}

$last_post_id = $mtf->post_stamp > $mtf->frm_last_post_date ? $mtf->id : 0;

if ($mtf->root_msg_id == $mtf->id) { /* new thread */
rebuild_forum_view($mtf->forum_id);
$threads = 1;
} else { /* reply to thread */
if ($mtf->post_stamp > $mtf->last_post_date) {
th_inc_post_count($mtf->thread_id, 1, $mtf->id, $mtf->post_stamp);
} else {
th_inc_post_count($mtf->thread_id, 1);
}
rebuild_forum_view($mtf->forum_id, q_singleval('SELECT page FROM fud26_thread_view WHERE forum_id='.$mtf->forum_id.' AND thread_id='.$mtf->thread_id));
$threads = 0;
}

/* update forum thread & post count as well as last_post_id field */
frm_updt_counts($mtf->forum_id, 1, $threads, $last_post_id);

if ($mtf->poll_id) {
poll_activate($mtf->poll_id, $mtf->forum_id);
}

$mtf->body = read_msg_body($mtf->foff, $mtf->length, $mtf->file_id);

if ($GLOBALS['FUD_OPT_1'] & 16777216) {
index_text((preg_match('!Re: !i', $mtf->subject) ? '': $mtf->subject), $mtf->body, $mtf->id);
}

/* handle notifications */
if ($mtf->root_msg_id == $mtf->id) {
if (empty($mtf->frm_last_post_date)) {
$mtf->frm_last_post_date = 0;
}

/* send new thread notifications to forum subscribers */
$c = uq('SELECT u.email
FROM fud26_forum_notify fn
INNER JOIN fud26_users u ON fn.user_id=u.id AND (u.users_opt & 134217728) = 0
INNER JOIN fud26_group_cache g1 ON g1.user_id=2147483647 AND g1.resource_id='.$mtf->forum_id.'
LEFT JOIN fud26_forum_read r ON r.forum_id=fn.forum_id AND r.user_id=fn.user_id
LEFT JOIN fud26_group_cache g2 ON g2.user_id=fn.user_id AND g2.resource_id='.$mtf->forum_id.'
LEFT JOIN fud26_mod mm ON mm.forum_id='.$mtf->forum_id.' AND mm.user_id=u.id
WHERE
fn.forum_id='.$mtf->forum_id.' AND fn.user_id!='.(int)$mtf->poster_id.'
'.($GLOBALS['FUD_OPT_3'] & 64 ? 'AND (CASE WHEN (r.last_view IS NULL AND (u.last_read=0 OR u.last_read >= '.$mtf->frm_last_post_date.')) OR r.last_view > '.$mtf->frm_last_post_date.' THEN 1 ELSE 0 END)=1' : '').'
AND (((CASE WHEN g2.id IS NOT NULL THEN g2.group_cache_opt ELSE g1.group_cache_opt END) & 2) > 0 OR (u.users_opt & 1048576) > 0 OR mm.id IS NOT NULL)');
$notify_type = 'frm';
} else {
/* send new reply notifications to thread subscribers */
$c = uq('SELECT u.email, r.msg_id, u.id
FROM fud26_thread_notify tn
INNER JOIN fud26_users u ON tn.user_id=u.id AND (u.users_opt & 134217728) = 0
INNER JOIN fud26_group_cache g1 ON g1.user_id=2147483647 AND g1.resource_id='.$mtf->forum_id.'
LEFT JOIN fud26_read r ON r.thread_id=tn.thread_id AND r.user_id=tn.user_id
LEFT JOIN fud26_group_cache g2 ON g2.user_id=tn.user_id AND g2.resource_id='.$mtf->forum_id.'
LEFT JOIN fud26_mod mm ON mm.forum_id='.$mtf->forum_id.' AND mm.user_id=u.id
WHERE
tn.thread_id='.$mtf->thread_id.' AND tn.user_id!='.(int)$mtf->poster_id.'
'.($GLOBALS['FUD_OPT_3'] & 64 ? 'AND (r.msg_id='.$mtf->last_post_id.' OR (r.msg_id IS NULL AND '.$mtf->post_stamp.' > u.last_read))' : '').'
AND (((CASE WHEN g2.id IS NOT NULL THEN g2.group_cache_opt ELSE g1.group_cache_opt END) & 2) > 0 OR (u.users_opt & 1048576) > 0 OR mm.id IS NOT NULL)');
$notify_type = 'thr';
}
$tl = $to = array();
while ($r = db_rowarr($c)) {
$to[] = $r[0];

if (isset($r[2]) && !$r[1]) {
$tl[] = $r[2];
}
}
unset($c);
if ($tl) {
/* this allows us to mark the message we are sending notification about as read, so that we do not re-notify the user
* until this message is read.
*/
db_li('INSERT INTO fud26_read (thread_id, msg_id, last_view, user_id) SELECT '.$mtf->thread_id.', 0, 0, id FROM fud26_users WHERE id IN('.implode(',', $tl).')', $dummy);
}
if ($to) {
send_notifications($to, $mtf->id, $mtf->subject, $mtf->alias, $notify_type, ($notify_type == 'thr' ? $mtf->thread_id : $mtf->forum_id), $mtf->frm_name, $mtf->forum_id);
}

// Handle Mailing List and/or Newsgroup syncronization.
if (($mtf->nntp_id || $mtf->mlist_id) && !$mtf->mlist_msg_id) {
fud_use('email_msg_format.inc', true);

$from = $mtf->poster_id ? reverse_fmt($mtf->alias).' <'.$mtf->email.'>' : $GLOBAL
[Message index]
 
Read Message icon14.gif
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Moderator/UserManager selection
Next Topic: Group Editor Selection for Group Manager
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 02:53:02 GMT 2024

Total time taken to generate the page: 0.05462 seconds