public function Current() { $temp = $this->item->Current(); if ($this->revert == 1) { $parser = new BBParser($temp['answer']); $temp['answer'] = $parser->Revert(stripslashes($temp['answer'])); } $temp['question'] = stripslashes($temp['question']); $temp['answer'] = stripslashes($temp['answer']); return $temp; }
public function Execute(Template $template, Session $session, $request) { $dba = DBA::Open(); /* Create the ancestors bar (if we run into any trouble */ $template = CreateAncestors($template, $template['L_EDITPOST']); /* Set the user's permissions */ $user_perms = isset($session['user']['perms']) ? $session['user']['perms'] : ALL; if ($session['user'] instanceof Member) { $id = intval(@$request['id']); if (isset($request['id']) && $id != 0) { try { @($post = $dba->GetRow("SELECT * FROM " . POSTS . " WHERE id = {$id}")); } catch (DBA_Exception $e) { return new TplException($e, $template); } if (is_array($post) && !empty($post)) { /* Try and get the forum */ try { @($f = new Forum()); @($forum = $f->getForum($post['forum_id'])); } catch (DBA_Exception $e) { return new TplException($e, $template); } if ($user_perms >= $forum['can_edit'] && ($session['user']['id'] == $post['poster_id'] || $user_perms & ADMIN)) { /* Set the post icons and the emoticons */ $template->posticons = DBA::Open()->Query("SELECT * FROM " . POSTICONS); $template->emoticons = DBA::Open()->Query("SELECT * FROM " . EMOTICONS); /* Hide the part of this template that has to do with replying */ $template->post_thread = array('hide' => TRUE); /* Set the template */ $template->content = array('file' => 'newthread.html'); $parser = new BBParser($post['body_text']); $template['message'] = $parser->Revert($post['body_text']); $template['posttitle'] = $post['name']; /* Remove all of the extra features */ $template->poll_options = array('hide' => TRUE); $template->post_options = array('hide' => TRUE); $template->can_attach = array('hide' => TRUE); /* Set the thread action */ $template['a_add_thread'] = new Action('posting.php', 'update_post'); /* Set the post id */ $template['post_id'] = $post['id']; } else { return new Error($template['L_PERMSEDITPOST'], $template); } } else { return new Error($template['L_INVALIDPOSTID'], $template); } } else { return new Error($template['L_INVALIDPOSTID'], $template); } } else { return new Error($template['L_NEEDLOGGEDIN'], $template); } /* Set the number of queries */ $template['num_queries'] = $session->dba->num_queries; return TRUE; }
function AddFaq($category, $question, $answer, $db_handle) { $question = $db_handle->Quote($question); $parser = new BBParser($answer, FALSE, FALSE, TRUE, array('allowbbcode' => 1, 'allowsmilies' => 1)); $answer = $db_handle->Quote($parser->Execute()); $db_handle->Query("INSERT INTO " . FAQ . " (parent_id, question, answer) VALUES ({$category}, '{$question}', '{$answer}')") or exit("Could not execute the following query: <br /><br />INSERT INTO " . FAQ . " (parent_id, question, answer) VALUES ({$category}, '{$question}', '{$answer}')"); }
public function Current() { $temp = $this->ranks->Current(); $rank = new BBParser(NULL); $temp['rank'] = $rank->Revert($temp['rank']); $temp['group_id'] = intval($temp['group_id']); $temp['user'] = intval($temp['user_id']) == 0 ? '' : $this->dba->GetValue("SELECT name FROM " . USERS . " WHERE id = " . $temp['user_id']); if (intval($temp['group_id']) != 0) { $temp['rank_to'] = 1; } else { if (intval($temp['user_id']) != 0) { $temp['rank_to'] = 2; } else { $temp['rank_to'] = 3; } } return $temp; }
public function Execute(Template $template, Session $session, $request) { /* Can we pm? */ if ($template['enablepms'] == 1) { /* Create the ancestors bar (if we run into any trouble */ $template = CreateAncestors($template, $template['L_SAVEMESSAGE']); /* Open a connection to the database */ $this->dba = DBA::Open(); /* Parse the Message */ $request['message'] = substr($request['message'], 0, $template['pmmaxchars']); $parser = new BBParser($request['message'], FALSE, TRUE, TRUE, array('allowbbcode' => $template['privallowbbcode'], 'allowsmilies' => $template['privallowsmilies'])); $request['message'] = $parser->Execute(); /* Quote all of the REQUEST variables */ foreach ($request as $key => $val) { $request[$key] = $this->dba->Quote($val); } /* Set the post icon */ if (isset($request['posticon']) && intval($request['posticon']) != 0 && $request['posticon'] != '-1' && $template['privallowicons'] == 1) { try { $posticon = $this->dba->GetValue("SELECT image FROM " . POSTICONS . " WHERE id = " . intval($request['posticon'])); } catch (DBA_Exception $e) { $posticon = 'clear.gif'; } } else { $posticon = 'clear.gif'; } /* Get the message which will be to the left of this one */ $before = $this->dba->GetRow("SELECT * FROM " . PMSGS . " ORDER BY row_right DESC LIMIT 1"); /* Get the number of pms on the same level as this one */ if ($this->getNumOnLevel() > 0) { $left = $before['row_right'] + 1; } else { $left = 1; } /* Set the right value */ $right = $left + 1; /* Timestamp */ $time = time(); try { /* Make room for the pm in the pms table by updating the right values */ @$this->dba->Query("UPDATE " . PMSGS . " SET row_right = row_right+2 WHERE row_left < {$left} AND row_right >= {$left}"); // Good /* Keep updating the pms table by changing all of the necessary left AND right values */ @$this->dba->Query("UPDATE " . PMSGS . " SET row_left = row_left+2, row_right=row_right+2 WHERE row_left >= {$left}"); // Good /* Finally insert our thread into the Posts table */ @$this->dba->Query("INSERT INTO " . PMSGS . " (row_left, row_right, name, body_text, created, poster_name, poster_id, member_id, member_name, icon) VALUES ({$left}, {$right}, '" . $request['name'] . "', '" . $request['message'] . "', " . $time . ", '', 0, 0, '', '{$posticon}')"); } catch (DBA_Exception $e) { return new TplException($e, $template); } /* If we've gotten to this point, reload the page to our recently added thread :) */ return new Error($template['L_SENTPMESSAGE'] . '<meta http-equiv="refresh" content="2; url=admin.php?act=globalpm">', $template); } else { return new Error($template['L_FEATUREDENIED'], $template); } /* Set the number of queries */ $template['num_queries'] = $session->dba->num_queries; return TRUE; }
public function Execute(Template $template, Session $session, $request) { if ($session['user'] instanceof Member && $session['user']['perms'] & ADMIN) { if (!isset($request['parent_id']) || !@$request['parent_id']) { return new Error(sprintf($template['L_REQUIREDFIELDSSF'], $template['L_CATEGORY']), $template); } if (!isset($request['question']) || !@$request['question']) { return new Error(sprintf($template['L_REQUIREDFIELDSSF'], $template['L_QUESTION']), $template); } if (!isset($request['question']) || !@$request['message']) { return new Error(sprintf($template['L_REQUIREDFIELDSSF'], $template['L_ANSWER']), $template); } $dba = DBA::Open(); $parent_id = intval($request['parent_id']); $question = $dba->Quote($request['question']); $parser = new BBParser($request['message']); $answer = $dba->Quote($parser->Execute()); if (intval($request['add']) == 1) { if ($dba->Query("INSERT INTO " . FAQ . " (parent_id, question, answer) VALUES ({$parent_id}, '{$question}', '{$answer}')")) { header("Location: admin.php?act=faq"); } } else { $id = intval($request['id']); if ($dba->Query("UPDATE " . FAQ . " SET parent_id = {$parent_id}, question = '{$question}', answer = '{$answer}' WHERE id = {$id}")) { header("Location: admin.php?act=faq"); } } } }
// require_once __DIR__ . '/BBText.class.php'; // require_once __DIR__ . '/BBTag.class.php'; // require_once __DIR__ . '/BBEndTag.class.php'; require_once __DIR__ . '/BBParser.class.php'; require_once __DIR__ . '/BBDumper.class.php'; // require_once __DIR__ . '/BBCode.class.php'; // require_once __DIR__ . '/BBCodeReplace.class.php'; // require_once __DIR__ . '/BBCodeDefault.class.php'; // require_once __DIR__ . '/BBCodeRoot.class.php'; // require_once __DIR__ . '/BBCodeCallback.class.php'; $str = 'Before list [list] [*]Cow [/list] Less'; $parser = new BBParser(); $dumper = new BBDumper(); const TYPE_INLINE = 'inline'; const TYPE_BLOCK = 'block'; const TYPE_LISTITEM = 'listitem'; $normalTypes = array(TYPE_INLINE, TYPE_BLOCK); $inlineType = array(TYPE_INLINE); // simple replacement $bold = new BBCodeReplace('b', '<b>', '</b>', TYPE_INLINE, $inlineType); $italic = new BBCodeReplace('i', '<i>', '</i>', TYPE_INLINE, $inlineType); $underline = new BBCodeReplace('u', '<u>', '</u>', TYPE_INLINE, $inlineType); $block = new BBCodeReplace('block', '<div>', '</div>', TYPE_BLOCK, $normalTypes); $noparse = new BBCodeReplace('noparse', '<!-- noparse -->', '<!-- noparse end -->', TYPE_INLINE); $dumper->addHandlers(array($bold, $italic, $underline, $block, $noparse)); // the default handler. It handles if a tag has no handler or is not permitted in a certain context. $notag = new BBCodeDefault();
public function Current() { $row = $this->post_info->Current(); $this->count++; $row['count'] = $this->count; $row['created'] = relative_time($row['created']); if ($row['poster_id'] != 0) { $user = $this->dba->GetRow("SELECT * FROM " . USERS . " WHERE id = " . $row['poster_id']); if ($user['seen'] >= time() - Lib::GetSetting('sess.gc_maxlifetime')) { $row['online_status'] = $this->lang['L_ONLINE']; } else { $row['online_status'] = $this->lang['L_OFFLINE']; } $row['user_num_posts'] = $user['posts']; $row['user_rank'] = $user['rank'] != '' ? $user['rank'] : '--'; $row['avatar'] = $user['avatar'] != '' && $user['avatar'] != 0 ? '<img src="Uploads/Avatars/' . $user['id'] . '.gif" border="0" alt="" />' : ' '; $row['signature'] = $user['signature'] != '' && !is_null($user['signature']) && $row['allow_sigs'] == 1 ? '<br /><br />' . stripslashes($user['signature']) : ' '; } else { $row['poster_name'] = $this->lang['L_ADMINISTRATOR']; $row['online_status'] = '--'; $row['user_num_posts'] = '--'; $row['user_rank'] = '--'; } $row['name'] = stripslashes($row['name']); $row['name'] = $row['member_has_read'] == 0 ? '<span class="text-decoration:italic;">' . $row['name'] . '</span>' : $row['name']; $row['display'] = $this->pm['num_children'] == $this->count - 1 || $row['member_has_read'] == 0 ? 'block' : 'none'; $bbcode = new BBParser(stripslashes($row['body_text']), TRUE); //$row['quoted_text'] = str_replace("\r\n", '\n', addslashes($bbcode->Revert($row['body_text']))); $row['body_text'] = $bbcode->QuickExecute(); return $row; }
$str = str_replace($this->codes[$key], '<!-- EMO-' . $this->codes[$key] . ' --><img src="' . $this->images[$key] . '" alt="' . $this->alts[$key] . '" /><!-- /EMO -->', $str); } return $str; } } /* Make a font tag */ class BBFont { public function Execute($str) { return preg_replace('~\\[font=(.*?)\\](.*?)\\[\\/font\\]~is', '<span style="font-family: $1;">$2</span>', $str); } } /* EXAMPLE OF USE * The next part is a random block of text with all sorts of bb codes in it * This is just an example. * NOTE: you can also do $parser->addBBcode(*); AND/OR $parser->addCustom(new *); instead of having them all in the constructor * (The * being either all the vars which are required for that function or the class required for that function) */ $text = "hello, this [b]stuff[/b] is great.. [omit]yep, [i]this is being[/i] omitted[/omit] [i]<-- all stuff within omit tags, is removed, unexecuted, and then put right back in.[/i] [omit]blam![/omit]"; $text .= "[code][list][*]heya\n[*]damn\n[/list][list=1][*]grammy!\n[/list][list=a][*]loglo\n[*]franchulate[/list][/code]"; $text .= "[font=arial]email me:[/font] [email]info@bestwebever.com[/email] [php]helloo<b>hey, this shouldn't be bold btw</b>[/php] www.bestwebever.com :P :) :( "; echo '<strong>From:</strong> <PRE>' . $text . '</PRE>'; $parser = new BBParser($text); echo '<br /><br /><strong>To:</strong> ' . $parser->Execute(); echo '<br /><br /><strong>Revert:</strong> <PRE>' . $parser->Revert($parser->Execute()) . '</PRE>'; $parser = new BBParser($parser->Revert($parser->Execute())); echo '<br /><br /><strong>Re-Revert:</strong> ' . $parser->Execute(); /* * The final $parser->Execute(); is what displays the text */
public function Execute(Template $template, Session $session, $request) { /* Create the ancestors Bar */ $template = CreateAncestors($template, $template['L_PROFILE']); /* If the user is allowed to see his/her/any user CP */ if ($session['user'] instanceof Member) { /* Connect to the db */ $dba = DBA::Open(); /* Quote out the REQUEST fields */ foreach ($request as $key => $val) { $request[$key] = $request[$key] != '' ? $dba->Quote($val) : ''; } if (check_mail($request['email']) != $request['email']) { return new Error($template['L_INVALIDEMAIL'], $template); } if ($request['signature'] != '') { if ($template['allowbbcode'] == 1) { $parser = new BBParser($request['signature']); if ($template['allowbbimagecode'] != 1) { $parser->addOmit('img', 'img'); } $request['signature'] = $parser->Execute(); } } if ($request['month'] != -1 && $request['day'] != -1 && $request['year'] != '') { $birthday = mktime(0, 0, 0, intval($request['month']), intval($request['day']), intval($request['year'])); } else { $birthday = 0; } if ($dba->Query("UPDATE " . USERS . " SET email = '" . $request['email'] . "', signature = '" . $request['signature'] . "', birthday = '" . $birthday . "', homepage = '" . $request['homepage'] . "', icq = '" . $request['icq'] . "', aim = '" . $request['aim'] . "', msn = '" . $request['msn'] . "', yahoo = '" . $request['yahoo'] . "', location = '" . $request['location'] . "', occupation = '" . $request['occupation'] . "', interests = '" . $request['interests'] . "', biography = '" . $request['biography'] . "' WHERE id = " . intval($request['id']))) { return new Error($template['L_PROFILESUCCESS'] . '<meta http-equiv="refresh" content="2; url=member.php?act=profile">', $template); } } else { return new Error($template['L_NEEDLOGGEDIN'], $template); } /* Set the number of queries */ $template['num_queries'] = $session->dba->num_queries; return TRUE; }
public static function loadLibrary() { self::$bbcode = array('[b]' => '<b>', '[/b]' => '</b>', '[img]' => '<img src="', '[/img]' => '">"', '[url]' => '<a href="', '[/url]' => '">ссылка</a>', '[i]' => '<i>', '[/i]' => '</i>', '[s]' => '<s>', '[/s]' => '</s>', '[u]' => '<u>', '[/u]' => '</u>', '[hr]' => '<hr>'); self::$smiles = Database::GetOne("config", array("mod" => "smiles")); }
public function Execute(Template $template, Session $session, $request) { /* Create the ancestors bar (if we run into any trouble */ $template = CreateAncestors($template, $template['L_POSTREPLY']); /* Open a connection to the database */ $this->dba = DBA::Open(); /* Set the a variable to this user's permissions and id */ $user_perms = isset($session['user']['perms']) ? $session['user']['perms'] : ALL; $user_id = $session['user']['id']; /* Quote all of the REQUEST variables */ foreach ($request as $key => $val) { $request[$key] = $this->dba->Quote($val); } /* Parse the body text to replace bbcodes, emoticons, etc */ $parser = new BBParser(substr($request['message'], 0, $template['postmaxchars'])); //$parser->addOmit('omit', 'omit'); $request['message'] = $parser->Execute(); /* Get forums, etc */ try { $forum = new Forum(); $stack = $forum->getForums(); } catch (DBA_Exception $e) { return new TplException($e, $template); } /* Get the id of whatever you are replying to */ $parent_id = intval($request['replyto_id']); try { /* This gets a result from whatever the parent_id is */ @($parent = $this->dba->GetRow("SELECT * FROM " . POSTS . " WHERE id = {$parent_id}")); // todo error checking /* Even though the $parent could be the thread, we still need to get the thread, because we don't want to check if it is or not the thread */ @($thread = $this->dba->GetRow("SELECT * FROM " . POSTS . " WHERE row_left <= " . $parent['row_left'] . " AND row_right >= " . $parent['row_right'] . " AND row_type = 2")); /* Get the forum from the thread's parent_id */ @($f = $forum->getForum($thread['parent_id'])); } catch (DBA_Exception $e) { return new TplException($e, $template); } /* I came into the weirdest problem.. It seems to be that sqlite_escape_string make that Ø when nothing is passed to it. */ if ($request['title'] == 'Ø' || !$request['title']) { $title = 'Re: ' . stripslashes($this->dba->Quote($parent['name'])); } else { $title = stripslashes($request['title']); } /* Is this forum password-protected? */ if ($f['private'] == 1 && @$_SESSION['forum_logged'] != $f['id']) { $template['forum_id'] = $f['id']; $template->content = array('file' => 'forum_login.html'); } else { /* Check if the forum is locked or suspended, and if it is one of the above, check if the user is an admin or a moderator */ if (($f['suspend'] == 1 && $session['user']['perms'] & ADMIN || $f['suspend'] != 1) && ($thread['row_locked'] != 1 || $thread['row_locked'] == 1 && $f['is_link'] != 1 && $session['user']['perms'] >= MOD) && ($f['row_lock'] != 1 || $f['row_lock'] == 1 && $session['user']['perms'] >= MOD)) { /* If the parent_id is invalid */ if ($parent_id != 0 || !$parent_id) { /* Get the number of replies on the same level as this */ if ($this->getNumOnLevel($parent_id) > 0) { $left = $parent['row_right']; } else { $left = $parent['row_left'] + 1; } /* Get the depth and set the right value */ $depth = $parent['row_level'] + 1; $right = $left + 1; /* If this user has permission to post */ if ($user_perms >= $f['can_reply']) { /* Should we ammend to the thread? */ if (($thread['row_right'] - $thread['row_left'] - 1) / 2 == 0 && $thread['poster_id'] == $session['user']['id']) { try { /* Create new body text */ $body_text = stripslashes($this->dba->Quote($thread['body_text'])) . "\n<br />\n<br /><!-- OMIT --><strong>" . $title . "</strong>\n<br />" . stripslashes($request['message']) . "<!-- /OMIT -->"; /* Ammend to the thread */ @$this->dba->Query("UPDATE " . POSTS . " SET body_text = '{$body_text}' WHERE id = " . $thread['id']); } catch (DBA_Exception $e) { return new TplException($e, $template); } } else { $time = time(); try { /* Make space in the Forums table for the reply */ @$this->dba->Query("UPDATE " . FORUMS . " SET row_right = row_right+2 WHERE row_left < {$left} AND row_right >= {$left}"); /* Keep making space in the Forums table for the reply */ @$this->dba->Query("UPDATE " . FORUMS . " SET row_left = row_left+2, row_right=row_right+2 WHERE row_left >= {$left}"); /* Make space in the Posts table for the reply */ @$this->dba->Query("UPDATE " . POSTS . " SET row_right = row_right+2 WHERE row_left < {$left} AND row_right >= {$left}"); /* Keep making space in the Posts table for the reply */ @$this->dba->Query("UPDATE " . POSTS . " SET row_left = row_left+2, row_right=row_right+2 WHERE row_left >= {$left}"); /* Finally Insert the reply into the database */ @$this->dba->Query("INSERT INTO " . POSTS . " (row_left, row_right, name, parent_id, row_level, body_text, created, poster_name, poster_id, row_type, forum_id) VALUES ({$left}, {$right}, '{$title}', {$parent_id}, {$depth}, '" . stripslashes($request['message']) . "', " . time() . ", '" . $session['user']['name'] . "', " . $session['user']['id'] . ", 4, " . $f['id'] . ")"); /* Set the last reply info for the thread info */ @$this->dba->Query("UPDATE " . POSTS . " SET last_reply = " . $time . ", reply_uid = " . $session['user']['id'] . ", reply_uname = '" . $session['user']['name'] . "' WHERE id = " . $thread['id']); /* get the last post by this user */ $last_post_id = @$this->lastPostByUser($session['user']['id']); /* Update the post count for the forum */ $this->dba->Query("UPDATE " . FORUMS . " SET posts = posts+1, thread_created = {$time}, thread_name = '" . $title . "', thread_id = " . $thread['id'] . ", thread_uname = '" . $session['user']['name'] . "', thread_uid = " . $session['user']['id'] . " WHERE id = " . $f['id']); /* Update the user count if the user exists :) */ if ($user_id != 0) { $this->dba->Query("UPDATE " . USERS . " SET posts = posts+1 WHERE id = " . $session['user']['id']); } } catch (DBA_Exception $e) { return new TplException($e, $template); } } } else { return new Error($template['L_PERMCANTREPLY'], $template); } /* If we've gotten this far, reload the page :) */ return new Error($template['L_SUCCESSADDINGREPLY'] . '<meta http-equiv="refresh" content="1; url=viewthread.php?id=' . $thread['id'] . '">', $template); } else { return new Error($template['L_ERRORREPLYING'], $template); } } else { return new Error($template['L_PERMCANTREPLY'], $template); } } // end check forum login required }
public function Current() { $row = $this->post_info->Current(); $this->count++; $row['count'] = $this->count; $row['created'] = relative_time($row['created']); if ($row['poster_id'] != 0) { $user = $this->dba->GetRow("SELECT * FROM " . USERS . " WHERE id = " . $row['poster_id']); if ($user['seen'] >= time() - Lib::GetSetting('sess.gc_maxlifetime')) { $row['online_status'] = $this->lang['L_ONLINE']; } else { $row['online_status'] = $this->lang['L_OFFLINE']; } $row['user_num_posts'] = $user['posts']; $row['user_rank'] = $user['rank'] != '' ? $user['rank'] : '--'; $row['avatar'] = $user['avatar'] != '' && $user['avatar'] != 0 && $row['allow_avatars'] == 1 ? '<img src="Uploads/Avatars/' . $user['id'] . '.gif" border="0" alt="" />' : ' '; $row['signature'] = $user['signature'] != '' && !is_null($user['signature']) && $row['allow_sigs'] == 1 ? '<br /><br />' . stripslashes($user['signature']) : ' '; /* Set the user ranks */ $row['user_ranks'] = ''; foreach ($this->dba->Query("SELECT * FROM " . RANKS . " WHERE group_id = (SELECT group_id FROM " . USER_IN_GROUP . " WHERE id = " . $user['id'] . ")") as $rank) { $row['user_ranks'] .= $rank['rank'] . ' <br />'; } foreach ($this->dba->Query("SELECT * FROM " . RANKS . " WHERE user_id = " . $user['id']) as $rank) { $row['user_ranks'] .= $rank['rank'] . ' <br />'; } if ($this->session['user']['perms'] & ADMIN) { $row['delete'] = '<a href="admin.php?act=delete_single&type=1&id=' . $row['id'] . '"><img src="Images/' . $this->settings['imageset'] . '/Buttons/delete.gif" alt="" border="0" /></a>'; } } else { $row['online_status'] = '--'; $row['user_num_posts'] = '--'; $row['user_rank'] = '--'; $row['user_ranks'] = ''; } $row['name'] = stripslashes($row['name']); $bbcode = new BBParser(stripslashes($row['body_text']), TRUE); $row['body_text'] = $bbcode->QuickExecute(); $row['edited'] = intval($row['edited']) != 0 ? '<br /><br /><span class="smalltext"><em>' . $this->lang['L_EDITEDON'] . ' ' . date("F j, Y, g:i a", $row['edited']) . '</em></span>' : ' '; return $row; }