public function Execute(Template $template, Session $session, $request) { /* Create the ancestors Bar */ $template = CreateAncestors($template, $template['L_SENDMESSAGE']); $dba = DBA::Open(); /* If the user is allowed to see his/her/any user CP */ if ($session['user'] instanceof Member) { if ($template['enablepms'] == 1) { /* Private Messages folder */ $template->pmsg_folders = new PMFolders(); /* Hide specific fun features if they are not allowed */ if ($template['privallowbbcode'] == 0) { $template->bbcode = array('hide' => TRUE); } if ($template['privallowsmilies'] == 0) { $template->smilies = array('hide' => TRUE); } if ($template['privallowicons'] == 0) { $template->post_icons = array('hide' => TRUE); } /* Set the post icons and the emoticons */ $template->posticons = DBA::Open()->Query("SELECT * FROM " . POSTICONS); $template->emoticons = DBA::Open()->Query("SELECT * FROM " . EMOTICONS); if (!isset($request['do'])) { $template['act'] = 'send_pm'; } else { if ($request['do'] == 'reply') { $template['act'] = 'reply_msg'; $template->post_options = array('hide' => true); $template->post_icons = array('hide' => true); $template->forward_username = array('hide' => true); $template['msg_id'] = intval($request['id']); $msg = $dba->GetRow("SELECT * FROM " . PMSGS . " WHERE id = " . intval($request['id'])); $bbcode = new BBParser(NULL, TRUE); $template['subject'] = 'Re: ' . stripslashes($msg['name']); $template['message'] = '[quote=' . $msg['poster_name'] . ']' . $bbcode->Revert($msg['body_text']) . '[/quote]'; } else { if ($request['do'] == 'forward') { $template['act'] = 'send_pm'; $template->post_options = array('hide' => true); $msg = $dba->GetRow("SELECT * FROM " . PMSGS . " WHERE id = " . intval($request['id'])); $bbcode = new BBParser(NULL, TRUE); $template['subject'] = 'Fwd: ' . stripslashes($msg['name']); $template['message'] = '[quote=' . $msg['poster_name'] . ']' . $bbcode->Revert($msg['body_text']) . '[/quote]'; } } } /* Set the Buddy List */ $template->buddy_list = new FriendsList(); /* Assign some template variables */ $template->content = array('file' => 'usercp.html'); $template->usercp = array('file' => 'usercp/sendmessage.html'); } else { return new Error($template['L_FEATUREDENIED'], $template); } } else { return new Error($template['L_NEEDLOGGEDIN'], $template); } return TRUE; }
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; }
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; }
$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) { /* Private Messages folder */ $template->pmsg_folders = new PMFolders(); /* Assign some template variables */ $template['id'] = $session['user']['id']; $template['username'] = $session['user']['name']; $template['email'] = $session['user']['email']; $template['homepage'] = $session['user']['homepage']; if ($session['user']['signature'] != '') { $parser = new BBParser($session['user']['signature']); $template['signature'] = $parser->Revert($session['user']['signature']); } else { $template['signature'] = $session['user']['signature']; } $template['icq'] = $session['user']['icq']; $template['aim'] = $session['user']['aim']; $template['msn'] = $session['user']['msn']; $template['yahoo'] = $session['user']['yahoo']; $template['location'] = $session['user']['location']; $template['occupation'] = $session['user']['occupation']; $template['interests'] = $session['user']['interests']; $template['biography'] = $session['user']['biography']; /* Get the birthday info */ $template['year'] = $session['user']['birthday'] != 0 ? date("Y", $session['user']['birthday']) : NULL; $template['month'] = $session['user']['birthday'] != 0 ? date("n", $session['user']['birthday']) : -1; $template['day'] = $session['user']['birthday'] != 0 ? date("j", $session['user']['birthday']) : -1; $template->content = array('file' => 'usercp.html'); $template->usercp = array('file' => 'usercp/profile.html'); } else { return new Error($template['L_NEEDLOGGEDIN'], $template); } /* Set the number of queries */ $template['num_queries'] = $session->dba->num_queries; return TRUE; }
public function Execute(Template $template, Session $session, $request) { /* Set the post vars session */ $session['post_vars'] = $request; /* Create the ancestors bar (if we run into any trouble */ $template = CreateAncestors($template, $template['L_POSTTHREAD']); /* 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']; /* Get our parent forum */ try { $parent_id = intval($request['forum_id']); @($parent = $this->dba->GetRow("SELECT * FROM " . FORUMS . " WHERE id = {$parent_id}")); } catch (DBA_Exception $e) { return new TplException($e, $template); } /* Quote all of the REQUEST variables */ foreach ($request as $key => $val) { $request[$key] = $this->dba->Quote($val); } /* Parse the Message */ $parser = new BBParser(substr($request['message'], 0, $template['postmaxchars'])); //$parser->addOmit('omit', 'omit'); $request['message'] = $parser->Execute(); /* Set the post icon */ if (isset($request['posticon']) && intval($request['posticon']) != 0 && $request['posticon'] != '-1') { try { $posticon = $this->dba->GetValue("SELECT image FROM " . POSTICONS . " WHERE id = " . intval($request['posticon'])); } catch (DBA_Exception $e) { return new TplException($e, $template); } } else { $posticon = 'clear.gif'; } /* Is it a poll, if so, deal with it. */ $polloptions = array(); $poll = 0; $poll_question = ''; if (isset($request['polloptions'])) { if ($user_perms >= $parent['can_pollcreate']) { $poll = 1; if ($request['poll_question'] == '') { return new Error($template['L_MUSTHAVEPOLLQUESTION'], $template); } $poll_question = BB::Open($request['poll_question'])->Execute(); $opts = explode("\n", $request['polloptions']); if (count($opts) <= $parent['maxpolloptions']) { foreach ($opts as $key => $option) { preg_match('~\\[color=(.*?)\\](.*?)\\[\\/color\\]~is', $option, $matches); $polloptions[] = array_key_exists(1, $matches) ? array('color' => $matches[1], 'option' => $matches[2]) : array('color' => 'blue', 'option' => $option); } } else { return new Error(sprintf($template['L_TOOMANYPOLLOPTIONS'], count($opts), $parent['maxpolloptions']) . '<meta http-equiv="refresh" content="1; url=' . $_SERVER['HTTP_REFERER'] . '">', $template); } } } /* Bring in the forums clas */ $forum = new Forum(); $stack = $forum->getForums(); /* Check if the forum that we are adding this thread to is NOT the root forum */ if ($parent['row_left'] != 1) { /* Set a shorter version of the $parent variable */ $f = $parent; /* 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 suspended or locked */ if (($f['suspend'] == 1 && $session['user']['perms'] & ADMIN || $f['suspend'] != 1) && $f['is_link'] != 1 && ($f['row_lock'] != 1 || $f['row_lock'] == 1 && $session['user']['perms'] >= MOD)) { /* Fix some cariables if they are not set */ $request['attach_files'] = !isset($request['attach_files']) ? 0 : $request['attach_files']; /* The status of the Thread is sticky/announcement/normal */ $status = isset($request['status']) ? intval($request['status']) : 1; /* Check if the user has permission to make sticky or announcement threads */ if ($status == 2) { $status = $user_perms >= $f['can_sticky'] ? 2 : 1; } else { if ($status == 3) { $status = $user_perms >= $f['can_announce'] ? 3 : 1; } } /* Get the number of threads on the same level as this one */ if ($this->getNumOnLevel($parent_id) > 0) { $left = $parent['row_right']; } else { $left = $parent['row_left'] + 1; } /* Set a depth variable, and the the right value */ $depth = $parent['row_level'] + 1; $right = $left + 1; /* Timestamp */ $time = time(); /* If this user can post */ if ($user_perms >= $f['can_post']) { try { /* Make room for the thread in the Forums table by updating the right values */ @$this->dba->Query("UPDATE " . FORUMS . " SET row_right = row_right+2 WHERE row_left < {$left} AND row_right >= {$left}"); // Good /* Keep updating the Forums table by changing all of the necessary left AND right values */ @$this->dba->Query("UPDATE " . FORUMS . " SET row_left = row_left+2, row_right=row_right+2 WHERE row_left >= {$left}"); // Good /* Make room in the Posts table for this thread */ @$this->dba->Query("UPDATE " . POSTS . " SET row_right = row_right+2 WHERE row_left < {$left} AND row_right >= {$left}"); /* Keep updating the Posts table */ @$this->dba->Query("UPDATE " . POSTS . " SET row_left = row_left+2, row_right=row_right+2 WHERE row_left > {$left}"); /* Finally insert our thread into the Posts table */ @$this->dba->Query("INSERT INTO " . POSTS . " (row_left, row_right, name, forum_id, parent_id, row_level, description, body_text, created, poster_name, poster_id, row_type, attach, icon, poll, poll_question, row_status) VALUES ({$left}, {$right}, '" . stripslashes($request['title']) . "', " . $f['id'] . ", {$parent_id}, {$depth}, '" . $parser->Revert(stripslashes(substr($request['message'], 0, 50))) . "..." . "', '" . stripslashes($request['message']) . "', " . $time . ", '" . $session['user']['name'] . "', " . $session['user']['id'] . ", 2, " . intval($request['attach_files']) . ", '{$posticon}', {$poll}, '{$poll_question}', {$status})"); } catch (DBA_Exception $e) { return new TplException($e, $template); } /* Change the REQUEST title variable to make it shorter for the forums last post info */ $request['title'] = strlen($request['title']) > 29 ? substr($request['title'], 0, 29) . '...' : $request['title']; /* Get the id of the thread that we just inserted into the database */ $last_post = $this->lastPostByUser($user_id); $last_post_id = $last_post['id']; try { /* Update the Forums post & thread count, and last post info for this thread*/ @$this->dba->Query("UPDATE " . FORUMS . " SET posts = posts+1, threads = threads+1, thread_created = {$time}, thread_name = '" . $request['title'] . "', thread_id = " . $last_post_id . ", thread_uname = '" . $session['user']['name'] . "', thread_uid = " . $session['user']['id'] . " WHERE id = {$parent_id}"); /* Update the users's post count */ 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); } /* If there are files to attach, try to attach them */ if (intval($request['attach_files']) == 1) { if ($user_perms >= $f['can_attach']) { if (@$this->Upload($last_post_id, array('attach1', 'attach2', 'attach3', 'attach4')) instanceof SetError) { $p = new Prune(); /* Remove everything that we just added to the db */ $p->KillSingle($last_post, 1); return new Error($upload->message, $template); } } } /* If there are poll options, add them to the database */ if (isset($request['polloptions'])) { /* Does the user have permission to create the poll? */ if ($user_perms >= $f['can_pollcreate']) { foreach ($polloptions as $option) { try { @$this->dba->Query("INSERT INTO " . POLLOPTIONS . " (poll_id, name, color) VALUES ({$last_post_id}, '" . $option['option'] . "', '" . $option['color'] . "')"); } catch (DBA_Exception $e) { return new TplException($e, $template); } } } } } else { return new Error($template['L_PERMCANTPOST'], $template); } /* Assuming that we've made it this far, unset the post vars session */ unset($session['post_vars']); /* If we've gotten to this point, reload the page to our recently added thread :) */ return new Error($template['L_ADDEDTHREAD'] . '<meta http-equiv="refresh" content="1; url=viewthread.php?id=' . $last_post_id . '">', $template); } else { return new Error($template['L_PERMCANTPOST'], $template); } } // end check forum login required } else { return new Error($template['L_ERRORPOSTING'], $template); } }