/** * Default search functionality. * * @since 2.0.0 * @access public * @param int $Page Page number. */ public function index($Page = '') { $this->addJsFile('search.js'); $this->title(t('Search')); saveToConfig('Garden.Format.EmbedSize', '160x90', false); Gdn_Theme::section('SearchResults'); list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20)); $this->setData('_Limit', $Limit); $Search = $this->Form->getFormValue('Search'); $Mode = $this->Form->getFormValue('Mode'); if ($Mode) { $this->SearchModel->ForceSearchMode = $Mode; } try { $ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit); } catch (Gdn_UserException $Ex) { $this->Form->addError($Ex); $ResultSet = array(); } catch (Exception $Ex) { LogException($Ex); $this->Form->addError($Ex); $ResultSet = array(); } Gdn::userModel()->joinUsers($ResultSet, array('UserID')); // Fix up the summaries. $SearchTerms = explode(' ', Gdn_Format::text($Search)); foreach ($ResultSet as &$Row) { $Row['Summary'] = SearchExcerpt(Gdn_Format::plainText($Row['Summary'], $Row['Format']), $SearchTerms); $Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']); $Row['Format'] = 'Html'; } $this->setData('SearchResults', $ResultSet, true); $this->setData('SearchTerm', Gdn_Format::text($Search), true); if ($ResultSet) { $NumResults = count($ResultSet); } else { $NumResults = 0; } if ($NumResults == $Offset + $Limit) { $NumResults++; } // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'More Results'; $this->Pager->LessCode = 'Previous Results'; $this->Pager->ClientID = 'Pager'; $this->Pager->configure($Offset, $Limit, $NumResults, 'dashboard/search/%1$s/%2$s/?Search=' . Gdn_Format::url($Search)); // if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { // $this->setJson('LessRow', $this->Pager->toString('less')); // $this->setJson('MoreRow', $this->Pager->toString('more')); // $this->View = 'results'; // } $this->canonicalUrl(url('search', true)); $this->render(); }
/** * Default search functionality. * * @since 2.0.0 * @access public * @param int $Page Page number. */ public function index($Page = '') { $this->addJsFile('search.js'); $this->title(t('Search')); saveToConfig('Garden.Format.EmbedSize', '160x90', false); Gdn_Theme::section('SearchResults'); list($Offset, $Limit) = offsetLimit($Page, c('Garden.Search.PerPage', 20)); $this->setData('_Limit', $Limit); $Search = $this->Form->getFormValue('Search'); $Mode = $this->Form->getFormValue('Mode'); if ($Mode) { $this->SearchModel->ForceSearchMode = $Mode; } try { $ResultSet = $this->SearchModel->search($Search, $Offset, $Limit); } catch (Gdn_UserException $Ex) { $this->Form->addError($Ex); $ResultSet = array(); } catch (Exception $Ex) { LogException($Ex); $this->Form->addError($Ex); $ResultSet = array(); } Gdn::userModel()->joinUsers($ResultSet, array('UserID')); // Fix up the summaries. $SearchTerms = explode(' ', Gdn_Format::text($Search)); foreach ($ResultSet as &$Row) { $Row['Summary'] = searchExcerpt(htmlspecialchars(Gdn_Format::plainText($Row['Summary'], $Row['Format'])), $SearchTerms); $Row['Summary'] = Emoji::instance()->translateToHtml($Row['Summary']); $Row['Format'] = 'Html'; } $this->setData('SearchResults', $ResultSet, true); $this->setData('SearchTerm', Gdn_Format::text($Search), true); $this->setData('_CurrentRecords', count($ResultSet)); $this->canonicalUrl(url('search', true)); $this->render(); }
public static function ExceptionHandler($Exception) { $Message = $Exception->GetMessage(); $File = $Exception->GetFile(); $Line = $Exception->GetLine(); echo "Error: {$Message}\n"; echo $Exception->GetTraceAsString() . "\n"; echo "{$File}\n"; $FileArray = file($File); array_unshift($FileArray, ''); for ($LengthAfter = $Line + 3, $i = $Line - 2; $i < $LengthAfter; $i++) { $FileLine =& $FileArray[$i]; if ($FileLine !== Null) { $Px = ' '; if ($i == $Line) { $FileLine = substr($FileLine, 0, -1) . " // <-- HERE!\n"; $Px = '>>> '; } echo "{$Px}{$i}: {$FileLine}"; } } LogException($Exception); die; }
$text = $_POST['text']; $text = str_replace('[[br]]', "\n", $text); // convert marked newlines to real newlines $text = trim($text); // trim whitespace if ($text == "") { exit('empty'); } // error if empty $text = htmlspecialchars($text); // escape html chars $text = nl2br($text, false); // convert newlines to html if (strlen($text) > $MAXCHARS || substr_count($text, "<br>") > $MAXLINES) { // too many lines or too many characters. exit('toolong'); } $sql = GetSQL(); $text = $sql->real_escape_string($text); $sql->safequery("\n\t\t\tUPDATE Topics SET state=" . TopicStates::Live . ",\n\t\t\tcontent='{$text}', time=" . time() . " WHERE id=" . $g_account->page . "\n\t\t\tAND state=" . TopicStates::Composing); //$sql->safequery( "UPDATE Accounts SET serial=serial+1 WHERE id=". $g_account->id ); if ($sql->affected_rows == 0) { // their composition slot was deleted because // they took too long. exit('expired'); } exit('okay.'); } catch (Exception $e) { LogException("compose", $e); } exit('error');
/** * Return the timezone hour difference between the user and utc. * @return int The hour offset. */ public function hourOffset() { static $GuestHourOffset; if ($this->UserID > 0) { return $this->User->HourOffset; } else { if (!isset($GuestHourOffset)) { $GuestTimeZone = c('Garden.GuestTimeZone'); if ($GuestTimeZone) { try { $TimeZone = new DateTimeZone($GuestTimeZone); $Offset = $TimeZone->getOffset(new DateTime('now', new DateTimeZone('UTC'))); $GuestHourOffset = floor($Offset / 3600); } catch (Exception $Ex) { $GuestHourOffset = 0; LogException($Ex); } } } return $GuestHourOffset; } }
/** * A custom error handler that displays much more, very useful information when * errors are encountered in Garden. * @param Exception $Exception The exception that was thrown. */ function Gdn_ExceptionHandler($Exception) { try { $ErrorNumber = $Exception->getCode(); $Message = $Exception->getMessage(); $File = $Exception->getFile(); $Line = $Exception->getLine(); if (method_exists($Exception, 'getContext')) { $Arguments = $Exception->getContext(); } else { $Arguments = ''; } $Backtrace = $Exception->getTrace(); // Clean the output buffer in case an error was encountered in-page. @ob_end_clean(); // prevent headers already sent error if (!headers_sent()) { if ($ErrorNumber >= 100 && $ErrorNumber < 600) { header("HTTP/1.0 {$ErrorNumber}", TRUE, $ErrorNumber); } else { header('HTTP/1.0 500', TRUE, 500); } header('Content-Type: text/html; charset=utf-8'); } $SenderMessage = $Message; $SenderObject = 'PHP'; $SenderMethod = 'Gdn_ErrorHandler'; $SenderCode = FALSE; $SenderTrace = $Backtrace; $MessageInfo = explode('|', $Message); $MessageCount = count($MessageInfo); if ($MessageCount == 4) { list($SenderMessage, $SenderObject, $SenderMethod, $SenderCode) = $MessageInfo; } else { if ($MessageCount == 3) { list($SenderMessage, $SenderObject, $SenderMethod) = $MessageInfo; } elseif (function_exists('GetValueR')) { $IsError = GetValueR('0.function', $SenderTrace) == 'Gdn_ErrorHandler'; // not exception $N = $IsError ? '1' : '0'; $SenderMethod = GetValueR($N . '.function', $SenderTrace, $SenderMethod); $SenderObject = GetValueR($N . '.class', $SenderTrace, $SenderObject); } } $SenderMessage = strip_tags($SenderMessage); $Master = FALSE; // The parsed master view $CssPath = FALSE; // The web-path to the css file $ErrorLines = FALSE; // The lines near the error's line # $DeliveryType = defined('DELIVERY_TYPE_ALL') ? DELIVERY_TYPE_ALL : 'ALL'; if (array_key_exists('DeliveryType', $_POST)) { $DeliveryType = $_POST['DeliveryType']; } else { if (array_key_exists('DeliveryType', $_GET)) { $DeliveryType = $_GET['DeliveryType']; } } // Make sure all of the required custom functions and variables are defined. $PanicError = FALSE; // Should we just dump a message and forget about the master view? if (!defined('DS')) { $PanicError = TRUE; } if (!defined('PATH_ROOT')) { $PanicError = TRUE; } if (!defined('APPLICATION')) { define('APPLICATION', 'Garden'); } if (!defined('APPLICATION_VERSION')) { define('APPLICATION_VERSION', 'Unknown'); } $WebRoot = ''; // Try and rollback a database transaction. if (class_exists('Gdn', FALSE)) { $Database = Gdn::Database(); if (is_object($Database)) { $Database->RollbackTransaction(); } } if ($PanicError === FALSE) { // See if we can get the file that caused the error if (is_string($File) && is_numeric($ErrorNumber)) { $ErrorLines = @file($File); } // If this error was encountered during an ajax request, don't bother gettting the css or theme files if ($DeliveryType == DELIVERY_TYPE_ALL) { $CssPaths = array(); // Potential places where the css can be found in the filesystem. $MasterViewPaths = array(); $MasterViewName = 'error.master.php'; $MasterViewCss = 'error.css'; if (function_exists('Debug') && Debug()) { $MasterViewName = 'deverror.master.php'; } if (class_exists('Gdn', FALSE)) { $CurrentTheme = ''; // The currently selected theme $CurrentTheme = C('Garden.Theme', ''); $MasterViewName = C('Garden.Errors.MasterView', $MasterViewName); $MasterViewCss = substr($MasterViewName, 0, strpos($MasterViewName, '.')); if ($MasterViewCss == '') { $MasterViewCss = 'error'; } $MasterViewCss .= '.css'; if ($CurrentTheme != '') { // Look for CSS in the theme folder: $CssPaths[] = PATH_THEMES . DS . $CurrentTheme . DS . 'design' . DS . $MasterViewCss; // Look for Master View in the theme folder: $MasterViewPaths[] = PATH_THEMES . DS . $CurrentTheme . DS . 'views' . DS . $MasterViewName; } } // Look for CSS in the dashboard design folder. $CssPaths[] = PATH_APPLICATIONS . DS . 'dashboard' . DS . 'design' . DS . $MasterViewCss; // Look for Master View in the dashboard view folder. $MasterViewPaths[] = PATH_APPLICATIONS . DS . 'dashboard' . DS . 'views' . DS . $MasterViewName; $CssPath = FALSE; $Count = count($CssPaths); for ($i = 0; $i < $Count; ++$i) { if (file_exists($CssPaths[$i])) { $CssPath = $CssPaths[$i]; break; } } if ($CssPath !== FALSE) { $CssPath = str_replace(array(PATH_ROOT, DS), array('', '/'), $CssPath); $CssPath = ($WebRoot == '' ? '' : '/' . $WebRoot) . $CssPath; } $MasterViewPath = FALSE; $Count = count($MasterViewPaths); for ($i = 0; $i < $Count; ++$i) { if (file_exists($MasterViewPaths[$i])) { $MasterViewPath = $MasterViewPaths[$i]; break; } } if ($MasterViewPath !== FALSE) { include $MasterViewPath; $Master = TRUE; } } } if ($DeliveryType != DELIVERY_TYPE_ALL) { // This is an ajax request, so dump an error that is more eye-friendly in the debugger echo '<h1>FATAL ERROR IN: ', $SenderObject, '.', $SenderMethod, "();</h1>\n<div class=\"AjaxError\">\"" . $SenderMessage . "\"\n"; if ($SenderCode != '') { echo htmlentities($SenderCode, ENT_COMPAT, 'UTF-8') . "\n"; } if (is_array($ErrorLines) && $Line > -1) { echo "LOCATION: ", $File, "\n"; } $LineCount = count($ErrorLines); $Padding = strlen($Line + 5); for ($i = 0; $i < $LineCount; ++$i) { if ($i > $Line - 6 && $i < $Line + 4) { if ($i == $Line - 1) { echo '>>'; } echo '> ' . str_pad($i + 1, $Padding, " ", STR_PAD_LEFT), ': ', str_replace(array("\n", "\r"), array('', ''), $ErrorLines[$i]), "\n"; } } if (is_array($Backtrace)) { echo "BACKTRACE:\n"; $BacktraceCount = count($Backtrace); for ($i = 0; $i < $BacktraceCount; ++$i) { if (array_key_exists('file', $Backtrace[$i])) { $File = $Backtrace[$i]['file'] . ' ' . $Backtrace[$i]['line']; } echo '[' . $File . ']', ' ', array_key_exists('class', $Backtrace[$i]) ? $Backtrace[$i]['class'] : 'PHP', array_key_exists('type', $Backtrace[$i]) ? $Backtrace[$i]['type'] : '::', $Backtrace[$i]['function'], '();', "\n"; } } echo '</div>'; } else { // If the master view wasn't found, assume a panic state and dump the error. if ($Master === FALSE) { echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-ca"> <head> <title>Fatal Error</title> </head> <body> <h1>Fatal Error in ', $SenderObject, '.', $SenderMethod, '();</h1> <h2>', $SenderMessage, "</h2>\n"; if ($SenderCode != '') { echo '<code>', htmlentities($SenderCode, ENT_COMPAT, 'UTF-8'), "</code>\n"; } if (is_array($ErrorLines) && $Line > -1) { echo '<h3><strong>The error occurred on or near:</strong> ', $File, '</h3> <pre>'; $LineCount = count($ErrorLines); $Padding = strlen($Line + 4); for ($i = 0; $i < $LineCount; ++$i) { if ($i > $Line - 6 && $i < $Line + 4) { echo str_pad($i, $Padding, " ", STR_PAD_LEFT), ': ', htmlentities($ErrorLines[$i], ENT_COMPAT, 'UTF-8'); } } echo "</pre>\n"; } echo '<h2>Need Help?</h2> <p>If you are a user of this website, you can report this message to a website administrator.</p> <p>If you are an administrator of this website, you can get help at the <a href="http://vanillaforums.org/discussions/" target="_blank">Vanilla Community Forums</a>.</p> <h2>Additional information for support personnel:</h2> <ul> <li><strong>Application:</strong> ', APPLICATION, '</li> <li><strong>Application Version:</strong> ', APPLICATION_VERSION, '</li> <li><strong>PHP Version:</strong> ', PHP_VERSION, '</li> <li><strong>Operating System:</strong> ', PHP_OS, "</li>\n"; if (array_key_exists('SERVER_SOFTWARE', $_SERVER)) { echo '<li><strong>Server Software:</strong> ', $_SERVER['SERVER_SOFTWARE'], "</li>\n"; } if (array_key_exists('HTTP_REFERER', $_SERVER)) { echo '<li><strong>Referer:</strong> ', $_SERVER['HTTP_REFERER'], "</li>\n"; } if (array_key_exists('HTTP_USER_AGENT', $_SERVER)) { echo '<li><strong>User Agent:</strong> ', $_SERVER['HTTP_USER_AGENT'], "</li>\n"; } if (array_key_exists('REQUEST_URI', $_SERVER)) { echo '<li><strong>Request Uri:</strong> ', $_SERVER['REQUEST_URI'], "</li>\n"; } echo '</ul> </body> </html>'; } } // Attempt to log an error message no matter what. LogException($Exception); } catch (Exception $e) { print get_class($e) . " thrown within the exception handler.<br/>Message: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine(); exit; } }
/** * Formats a timestamp to the current user's timezone. * * @param int $Timestamp The timestamp in gmt. * @return int The timestamp according to the user's timezone. */ public static function ToTimezone($Timestamp) { static $GuestHourOffset; $Now = time(); // Alter the timestamp based on the user's hour offset $Session = Gdn::Session(); $HourOffset = 0; if ($Session->UserID > 0) { $HourOffset = $Session->User->HourOffset; } elseif (class_exists('DateTimeZone')) { if (!isset($GuestHourOffset)) { $GuestTimeZone = C('Garden.GuestTimeZone'); if ($GuestTimeZone) { try { $TimeZone = new DateTimeZone($GuestTimeZone); $Offset = $TimeZone->getOffset(new DateTime('now', new DateTimeZone('UTC'))); $GuestHourOffset = floor($Offset / 3600); } catch (Exception $Ex) { $GuestHourOffset = 0; LogException($Ex); } } } $HourOffset = $GuestHourOffset; } if ($HourOffset != 0) { $SecondsOffset = $HourOffset * 3600; $Timestamp += $SecondsOffset; $Now += $SecondsOffset; } return $Timestamp; }
/** * Default search functionality. * * @since 2.0.0 * @access public * @param int $Page Page number. */ public function Index($Page = '') { $this->AddJsFile('jquery.gardenmorepager.js'); $this->AddJsFile('search.js'); $this->Title(T('Search')); SaveToConfig('Garden.Format.EmbedSize', '160x90', FALSE); list($Offset, $Limit) = OffsetLimit($Page, C('Garden.Search.PerPage', 20)); $this->SetData('_Limit', $Limit); $Search = $this->Form->GetFormValue('Search'); $Mode = $this->Form->GetFormValue('Mode'); if ($Mode) { $this->SearchModel->ForceSearchMode = $Mode; } try { $ResultSet = $this->SearchModel->Search($Search, $Offset, $Limit); } catch (Gdn_UserException $Ex) { $this->Form->AddError($Ex); $ResultSet = array(); } catch (Exception $Ex) { LogException($Ex); $this->Form->AddError($Ex); $ResultSet = array(); } Gdn::UserModel()->JoinUsers($ResultSet, array('UserID')); $this->SetData('SearchResults', $ResultSet, TRUE); $this->SetData('SearchTerm', Gdn_Format::Text($Search), TRUE); if ($ResultSet) { $NumResults = count($ResultSet); } else { $NumResults = 0; } if ($NumResults == $Offset + $Limit) { $NumResults++; } // Build a pager $PagerFactory = new Gdn_PagerFactory(); $this->Pager = $PagerFactory->GetPager('MorePager', $this); $this->Pager->MoreCode = 'More Results'; $this->Pager->LessCode = 'Previous Results'; $this->Pager->ClientID = 'Pager'; $this->Pager->Configure($Offset, $Limit, $NumResults, 'dashboard/search/%1$s/%2$s/?Search=' . Gdn_Format::Url($Search)); if ($this->_DeliveryType != DELIVERY_TYPE_ALL) { $this->SetJson('LessRow', $this->Pager->ToString('less')); $this->SetJson('MoreRow', $this->Pager->ToString('more')); $this->View = 'results'; } $this->CanonicalUrl(Url('search', TRUE)); $this->Render(); }
} $appBuilderFactory = new \Conpago\AppBuilderFactory(); /** @var AppBuilder $appBuilder */ $appBuilder = $appBuilderFactory->createAppBuilder("Web", ".."); if ($c['devel']['debug'] == true) { $appBuilder->buildApp(); } else { $appBuilder->readPersistedApp(); } /** * @param AppBuilder $appBuilder * @param Exception $e * @param $is_debug * * @throws Exception */ function LogException(AppBuilder $appBuilder, \Exception $e, $is_debug) { try { $appBuilder->getLogger()->addCritical('Exception caught', ['exception' => $e]); } finally { if ($is_debug == true) { throw $e; } } } try { $appBuilder->getApp()->run(); } catch (\Exception $e) { LogException($appBuilder, $e, $is_debug); }
function ProcessException($ex) { global $DEBUG; global $RSS; global $sid; global $pageTitle; global $body; $log =& LogException($ex); $pageTitle = GetCap('capError'); if ($DEBUG) { print "<br>Exception:<br>" . $log->ToString(1); Dump(); } else { ob_end_clean(); $id = $log->ID(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr"> <head> <title><?php echo $pageTitle; ?> </title> </head> <body <?php echo $body; ?> > <center> <p> <?php echo GetCap('capProblemEncountered'); ?> <br/> <?php echo GetCap('capItWasRecordedAndItWillBeFixed'); ?> <br/> <?php echo GetCap('capProblemID') . ': ' . $id; ?> <br/> </p> </center> </body> </html> <?php } exit; }
<?php require_once "sql.php"; require_once "config.php"; require_once "util.php"; try { if (!isset($_POST['page'])) { exit('error'); } $g_account = LogIn(); if ($g_account->page != $_POST['page']) { exit('wrongpage'); } $sql = GetSQL(); $sql->safequery('UPDATE Accounts SET page=0 WHERE id=' . $g_account->id); exit('okay.'); } catch (Exception $e) { LogException("closeold", $e); } exit('error');
$score = GetScore($value['goods'], $value['bads']); if ($score < $GLOBALS['COMMENT_BURY_SCORE']) { // filter out shit scores. unset($output[$key]); } else { // translate goods,bads into final score $output[$key]['score'] = $score; unset($output[$key]['goods']); unset($output[$key]['bads']); } } // sort by score usort($output, "ScoreCmp2"); } else { if ($state == TopicStates::Live) { // filter out downvoted comments foreach ($output as $key => $value) { if ($value['vote'] === FALSE) { unset($output[$key]); } } // sort randomly shuffle($output); } } echo json_encode($output); exit; } catch (Exception $e) { LogException("liverefresh", $e); } exit('error');
if ($row[0] != TopicStates::Live) { $sql->safequery('UNLOCK TABLES'); exit('error'); // topic is invalid. } $sql->safequery('INSERT IGNORE INTO TopicVotes ( topicid, account, vote ) VALUES ( ' . $g_account->page . ', ' . $g_account->id . ", {$voteval} )"); if ($sql->affected_rows == 0) { $sql->safequery('UNLOCK TABLES'); exit('error'); // user already voted. } if ($voteval == '1') { $sql->safequery('UPDATE Topics SET goods=goods+1 WHERE id=' . $g_account->page); } else { if ($voteval == '0') { $sql->safequery('UPDATE Topics SET bads=bads+1 WHERE id=' . $g_account->page); } } $sql->safequery('UNLOCK TABLES'); if ($voteval == '1') { exit('good'); } else { if ($voteval == '0') { exit('cancer'); } } } catch (Exception $e) { LogException("topicvote", $e); } exit('error');
function ShowTopic() { global $g_account, $g_get_page; $page = $g_get_page ? $g_get_page : $g_account->page; echo '<script>'; echo 'matbox.SetPage( ' . $page . ', "none");'; echo '</script>'; if ($page == 0) { ?> <script>matbox.SetPage( 0, "nonew" );</script> <div class="topic nothing" id="topic"> no new matter. </div> <div class="panel"> <div class="button" onclick="matbox.GotoRandom()">archive</div> <div class="button" onclick="matbox.Loader.RefreshContent()">check again</div> </div> <?php return false; } try { $topic = new Topic($page, $g_account); } catch (Exception $e) { ?> <div class="topic nothing clickable" id="topic" onclick="matbox.Loader.RefreshContent()"> something messed up. </div> <?php LogException("readtopic", $e); die; } if (!$topic->valid) { ?> <div class="topic nothing clickable" id="topic" onclick="matbox.Loader.RefreshContent()"> that sample doesn't exist </div> <?php return false; } if ($topic->state == TopicStates::Deleted) { ?> <div class="topic nothing clickable" id="topic" onclick="matbox.Loader.RefreshContent()"> this matter was buried. </div> <?php return false; } if ($topic->state == TopicStates::Composing) { echo '<div class="topic composing" id="topic"> <div class="compose" contenteditable="true" id="composition"></div> </div>'; echo '<div class="submit" onclick="matbox.SubmitComposition()" id="submit">analyze</div>'; ?> <script> $("#composition").keydown( function() { if( matbox.Loader.IsLoading() ) return false; setTimeout( matbox.CompositionKeyPressed, 0 ); }); </script> <?php return true; } $badstring = mt_rand(0, 25) == 0 ? "cancer" : "bad"; echo '<div class="topic" id="topic">'; // replace embed tags $content = ReplaceEmbeds($topic->content); echo $content; if ($topic->state == TopicStates::Live) { echo '<script>matbox.SetPage( ' . $topic->id . ', "live")</script>'; if ($topic->vote === true) { echo '<div class="good" id="goodbutton"><div class="speshul_table"><div><img src="star.png" title="good"></div></div></div>'; echo '<div class="bad" id="badbutton"><div class="speshul_table"><div><img src="notbad.png" title="' . $badstring . '"></div></div></div>'; } else { if ($topic->vote === false) { echo '<div class="good" id="goodbutton"><div class="speshul_table"><div><img src="unstar.png" title="good"></div></div></div>'; echo '<div class="bad" id="badbutton"><div class="speshul_table"><div><img src="bad.png" title="' . $badstring . '"></div></div></div>'; } else { echo '<div class="good clickable" id="goodbutton" ><div class="speshul_table"><div><img src="unstar.png" title="good" onclick="matbox.VoteTopicGood()"></div></div></div>'; echo '<div class="bad clickable" id="badbutton" ><div class="speshul_table"><div><img src="notbad.png" title="' . $badstring . '" onclick="matbox.VoteTopicBad()"></div></div></div>'; } } } else { if ($topic->state == TopicStates::Old) { echo '<script>matbox.SetPage( ' . $topic->id . ',"old" )</script>'; // print score $score = GetScore($topic->goods, $topic->bads); echo '<div class="score ' . ScoreRank($score) . '" id="scorediv" title="' . ScoreRankName($score) . '"><div class="speshul_table"><div>' . $score . '</div></div></div>'; /*echo '<div class="new" id="newbutton" onclick="matbox.CloseOld()"></div>';*/ } } echo '</div>'; echo '<div class="replies" id="replies">'; echo '<div class="replylist" id="replylist">'; echo '</div>'; // replylist if ($topic->state == TopicStates::Live) { echo '<div class="reply" id="replyinputbox"> <div class="replyinput init" id="replyinput" contenteditable="true"></div> </div>'; } else { if ($topic->state == TopicStates::Old) { } } echo '</div>'; // replies echo '<div class="submit" onclick="matbox.SubmitComment()" id="submit">submit</div>'; echo '<div class="padding" id="padding"></div>'; return true; }
$g_account = LogIn(); if ($g_account->page != $_POST['page']) { exit('error'); } $sql = GetSQL(); $sql->safequery('LOCK TABLES Topics READ, Comments READ, CommentVotes WRITE'); $result = $sql->safequery('SELECT 1 FROM Topics WHERE id=' . $g_account->page . ' AND state=' . TopicStates::Live); if ($result->num_rows == 0) { $sql->safequery('UNLOCK TABLES'); exit('error'); // topic is closed or invalid. } $result = $sql->safequery("SELECT 1 FROM Comments WHERE id={$comment} AND topic=" . $g_account->page); if ($result->num_rows == 0) { $sql->safequery('UNLOCK TABLES'); exit('error'); // comment doesn't exist. } $sql->safequery("INSERT INTO CommentVotes ( commentid, account, vote )\n\t\tVALUES ( {$comment}, " . $g_account->id . ", {$voteval} )\n\t\tON DUPLICATE KEY UPDATE vote={$voteval}"); if ($sql->affected_rows == 0) { $sql->safequery('UNLOCK TABLES'); exit('error'); } $sql->safequery('UNLOCK TABLES'); exit('okay.'); } catch (Exception $e) { LogException("commentvote", $e); } exit("error");
$row = $result->fetch_row(); if (time() < $row[0] + $WAITTIME) { $sql->safequery('UNLOCK TABLES'); exit('pleasewait'); } $result = $sql->safequery('SELECT state FROM Topics WHERE id=' . $g_account->page); if ($result->num_rows == 0) { $sql->safequery('UNLOCK TABLES'); exit('error'); } $row = $result->fetch_row(); if ($row[0] == TopicStates::Old || $row[0] == TopicStates::Deleted) { $sql->safequery('UNLOCK TABLES'); exit('expired'); } $text = $sql->real_escape_string($text); $sql->safequery('INSERT INTO Comments (topic,account,goods,bads,time,content) VALUES (' . $g_account->page . ',' . $g_account->id . ',0,0,' . time() . ",'{$text}')"); if ($sql->affected_rows == 0) { // not sure how the above would error..? $sql->safequery('UNLOCK TABLES'); exit('error'); } $sql->safequery('UPDATE Accounts SET lastreply=' . time() . ' WHERE id=' . $g_account->id); $sql->safequery('UNLOCK TABLES'); exit('okay.'); } catch (Exception $e) { LogException("reply", $e); } exit('error');