public function image_comic($cid, $page, $getLink) { $sql = 'SELECT t1.meta, t1.pages, t1.`index`, t2.`index` as itemid' . ' FROM index_chapter AS t1' . ' LEFT JOIN index_title AS t2 ON t1.tid = t2.id' . ' WHERE cid = ' . $this->db->escape($cid); $r = $this->db->query($sql)->row(); $meta = json_decode($r->meta, true); $c_index = $r->index; $itemid = $r->itemid; $pages = $r->pages; if ($meta) { $m = ($page - 1) / 10 % 10 + ($page - 1) % 10 * 3; $img = page_convert($page) . '_' . substr($meta['code'], $m, 3); $url = "http://img" . $meta['sid'] . ".8comic.com/" . $meta['did'] . "/" . $itemid . "/" . $meta['num'] . "/" . $img . ".jpg"; if ($getLink) { return $url; } if (!$this->CI->grab->render_image(['url' => $url, 'referer' => $this->url['title']])) { $this->CI->grab->signal_comic_error($cid); elog('site_8comic - image error, cid=' . $cid); show_404(); } } else { header('HTTP/404 File Not Found'); exit; } }
function requestRecommendation($user_id, $author, $email, $message) { if (!checkLock("peer")) { return 6; } $config = $GLOBALS['config']; $user_id = escape($user_id); $author = escape($author); $email = escape($email); if (!validEmail($email)) { return 1; } if (strlen($author) <= 3) { return 2; } //make sure there aren't too many recommendations already $result = mysql_query("SELECT COUNT(*) FROM recommendations WHERE user_id = '{$user_id}'"); $row = mysql_fetch_row($result); if ($row[0] >= $config['max_recommend']) { return 4; //too many recommendations } //ensure this email hasn't been asked with this user already $result = mysql_query("SELECT COUNT(*) FROM recommendations WHERE user_id = '{$user_id}' AND email = '{$email}'"); $row = mysql_fetch_row($result); if ($row[0] > 0) { return 5; //email address already asked } lockAction("peer"); //first create an instance $instance_id = customCreate(customGetCategory('recommend', true), $user_id); //insert into recommendations table $auth = escape(uid(64)); mysql_query("INSERT INTO recommendations (user_id, instance_id, author, email, auth, status, filename) VALUES ('{$user_id}', '{$instance_id}', '{$author}', '{$email}', '{$auth}', '0', '')"); $recommend_id = mysql_insert_id(); $userinfo = getUserInformation($user_id); //array (username, email address, name) //send email now $content = page_db("request_recommendation"); $content = str_replace('$USERNAME$', $userinfo[0], $content); $content = str_replace('$USEREMAIL$', $userinfo[1], $content); $content = str_replace('$NAME$', $userinfo[2], $content); $content = str_replace('$AUTHOR$', $author, $content); $content = str_replace('$EMAIL$', $email, $content); $content = str_replace('$MESSAGE$', page_convert($message), $content); $content = str_replace('$AUTH$', $auth, $content); $content = str_replace('$SUBMIT_ADDRESS$', $config['site_address'] . "/recommend.php?id={$recommend_id}&user_id={$user_id}&auth={$auth}", $content); $result = one_mail("Recommendation request", $content, $email); if ($result) { return 0; } else { return 3; } }
function retrieveMessage($user_id, $box_id, $message_id) { $box_id = escape($box_id); $message_id = escape($message_id); $result = mysql_query("SELECT messages.sender_id, messages.receiver_id, messages.subject, messages.body, messages.time FROM message_boxes_contents LEFT JOIN messages ON message_boxes_contents.message_id = messages.id WHERE message_boxes_contents.box_id = '{$box_id}' AND messages.id = '{$message_id}'"); if ($row = mysql_fetch_row($result)) { $sender_id = escape($row[0]); $receiver_id = escape($row[1]); $subject = $row[2]; $body = page_convert($row[3]); $time = $row[4]; $sender_name = ""; $sender_username = ""; $receiver_name = ""; $receiver_username = ""; $result = mysql_query("SELECT username, name FROM users WHERE id = '{$sender_id}'"); if ($row = mysql_fetch_row($result)) { $sender_username = $row[0]; $sender_name = $row[1]; } $result = mysql_query("SELECT username, name FROM users WHERE id = '{$receiver_id}'"); if ($row = mysql_fetch_row($result)) { $receiver_username = $row[0]; $receiver_name = $row[1]; } return array($sender_id, $sender_name, $sender_username, $receiver_id, $receiver_name, $receiver_username, $subject, $body, $time); } return false; }
function latexAppendQuestion($name, $desc, $type, $answer) { $typeArray = getTypeArray($type); $question_string = ""; if ($typeArray['type'] == "text") { if ($name != "") { $question_string .= '\\textbf{' . latexSpecialChars($name) . '}'; //add main in bold } if ($desc != "") { if ($name != "") { $question_string .= '\\newline'; } $question_string .= '\\emph{' . latexSpecialChars($desc) . '}'; //add description in italics } $question_string .= '\\newline\\newline'; return $question_string; } else { if ($typeArray['type'] == "latex") { $question_string .= $desc; return $question_string; } else { if ($typeArray['type'] == "code") { $question_string .= '\\text{' . get_html_to_latex(page_convert($desc)) . '}'; return $question_string; } else { if ($typeArray['type'] == "repeat") { $num = $typeArray['num']; $subtype_array = explode("|", $typeArray['subtype']); $desc_array = explode("|", $desc); $name_array = explode("|", $name); if ($answer != '') { $answer_array = toArray($answer, "|", "="); } else { $answer_array = array_fill(0, count($name_array) * $num, ''); } //find minimum length, which will be the number to repeat for $min_length = min(count($subtype_array), count($desc_array), count($name_array)); for ($i = 0; $i < $min_length * $num; $i++) { $index = $i % $min_length; $n = intval($i / $min_length); $thisName = getRepeatThisValue($name_array, $index, $n); $thisDesc = getRepeatThisValue($desc_array, $index, $n); $thisType = str_replace(",", ";", getRepeatThisValue($subtype_array, $index, $n)); $question_string .= latexAppendQuestion($thisName, $thisDesc, $thisType, $answer_array[$i]); } } else { if ($name != "") { $question_string .= '\\textbf{' . latexSpecialChars($name) . '}'; //add question in bold } //add description (in bold) for essays and short answer if (($typeArray['type'] == "essay" || $typeArray['type'] == "short") && $desc != "") { if ($name != "") { $question_string .= '\\newline'; } $question_string .= '\\emph{' . latexSpecialChars($desc) . '}'; //add description in italics } //add a separator depending on main type of the question if ($typeArray['type'] == "essay") { $question_string .= "\n\n"; } if ($typeArray['type'] == "select" && $typeArray['method'] != "dropdown") { //in this case, we add tick marks and check the correct ones $choices = explode(";", $desc); //get answer as array in case we're using multiple selection $config = $GLOBALS['config']; $answerArray = explode($config['form_array_delimiter'], $answer); //this is used to indent the answer choices $question_string .= "\n\\begin{quote}\n"; //output each choice with check box before it on a separate line in the quote for ($i = 0; $i < count($choices); $i++) { $choice = $choices[$i]; if ($i != 0) { $question_string .= "\\\\\n "; } if (in_array($choice, $answerArray)) { $question_string .= '\\xbox'; } else { $question_string .= '\\tickbox'; } $question_string .= " \\hspace{4pt} " . latexSpecialChars($choice); } $question_string .= "\\end{quote}"; } else { //append the response if ($typeArray['type'] == "essay") { if ($answer != "") { $question_string .= '\\begin{quote} ' . latexSpecialChars($answer) . '\\end{quote}'; } else { $question_string .= '\\vspace{5ex}'; } } else { if ($answer != "") { $question_string .= '\\begin{quote} ' . latexSpecialChars($answer) . ' \\end{quote}'; } else { $question_string .= '\\vspace{1ex}'; } } } $question_string .= "\n\n"; } } } } return $question_string; }
function page_db($page) { return page_convert(page_db_part($page)); }
function writeField($id, $answer_id, $name, $desc, $type, $answer = "", $mutable = true, $repeat_id = 256) { //see if style provides this function $styleFunction = style_function("writeField"); if ($styleFunction !== FALSE) { return $styleFunction($str); } $mutableString = ""; if (!$mutable) { $mutableString = "readonly=\"readonly\""; } //trim the string fields $name = trim($name); $desc = trim($desc); $type = trim($type); $fieldName = "a_" . $id . "_" . $answer_id . "_" . $repeat_id; $type_array = getTypeArray($type); $maxLength = $type_array['length']; $lengthRemaining = $maxLength - strlen($answer); if ($type_array['type'] == "essay") { $height = ""; if ($type_array['size'] == "large") { $height = "height:200px"; } else { if ($type_array['size'] == "huge") { $height = "height:400px"; } } echo '<label for="">'; if ($type_array['status'] != "optional") { echo "<em>*</em>"; } echo "{$name}</label>"; echo "<textarea "; if ($type_array['showchars']) { echo "onKeyDown=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" "; echo "onKeyUp=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" "; } echo "name=\"{$fieldName}\" {$mutableString} style=\"resize:vertical;{$height}\" />" . htmlspecialchars($answer) . "</textarea>"; echo "<p class=\"formHint\">{$desc}"; if ($type_array['showchars']) { echo "<br />Characters Remaining: <input type=\"text\" name=\"countdown{$fieldName}\" style=\"background-color:none;border:solid 1px #FFFFFF;font-size:10px;max-width:50px;color:#71777D\" value=\"{$lengthRemaining}\" readonly=\"readonly\" class=\"changeBackground\" />"; } echo "</p>"; } else { if ($type_array['type'] == "short") { echo '<label for="">'; if ($type_array['status'] != "optional") { echo "<em>*</em>"; } echo "{$name}</label>"; echo "<input "; if ($type_array['showchars']) { echo "onKeyDown=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" "; echo "onKeyUp=\"limitText(this.form.{$fieldName}, this.form.countdown{$fieldName}, {$maxLength});\" maxlength=\"{$maxLength}\" "; } echo "type=\"text\" name=\"{$fieldName}\" {$mutableString} value=\"" . htmlspecialchars($answer) . "\" /> "; echo "<p class=\"formHint\">{$desc}"; if ($type_array['showchars']) { echo "<br />Characters remaining: <input type=\"text\" name=\"countdown{$fieldName}\" style=\"background-color:none;border:solid 1px #FFFFFF;font-size:10px;max-width:50px;color:#71777D\" value=\"{$lengthRemaining}\" readonly=\"readonly\" class=\"changeBackground\" />"; } echo "</p>"; } else { if ($type_array['type'] == "select") { echo '<p class="label">'; if ($type_array['status'] != "optional") { echo "<em>*</em>"; } echo "{$name}</p>"; $choices = explode(";", $desc); $tname = "checkbox"; if ($type_array['method'] == "multiple") { $tname = "checkbox"; $fieldName .= "[]"; //for multiple selection, PHP needs to know with an [] at the end of field name echo "<ul>"; } else { if ($type_array['method'] == "single") { $tname = "radio"; echo "<ul>"; } else { if ($type_array['method'] == "dropdown") { $tname = false; echo "<select name=\"{$fieldName}\"{$mutableString}>"; } } } //for checkboxes, answer will be an array separated by $config['form_array_delimiter'] // we just explode it anyway for convenience and get one element if it's single selection $config = $GLOBALS['config']; $answerArray = explode($config['form_array_delimiter'], $answer); foreach ($choices as $choice) { $selectedString = ""; if (in_array($choice, $answerArray)) { if ($tname === false) { $selectedString = " selected"; } else { $selectedString = " checked"; } } if ($tname == false) { echo "<option{$selectedString} value=\"{$choice}\">{$choice}</option>"; } else { echo "<li><label for=\"\"><input{$selectedString} type=\"{$tname}\" name=\"{$fieldName}\"{$mutableString} value=\"{$choice}\" /> {$choice}</label></li>"; } } if ($tname == false) { //select echo "</select>"; } else { echo "</ul>"; } //need to add some sort of hint factor for selects (change hint so that it is a type variable) } else { if ($type_array['type'] == "text") { echo '<label for="">'; if ($type_array['status'] != "optional") { echo "<em>*</em>"; } echo "{$name}</label>{$desc}"; } else { if ($type_array['type'] == "repeat") { $num = $type_array['num']; $subtype_array = explode("|", $type_array['subtype']); $desc_array = explode("|", $desc); $name_array = explode("|", $name); if ($answer != '') { $answer_array = toArray($answer, "|", "="); } else { $answer_array = array_fill(0, count($name_array) * $num, ''); } //find minimum length, which will be the number to repeat for $min_length = min(count($subtype_array), count($desc_array), count($name_array)); for ($i = 0; $i < $min_length * $num; $i++) { $index = $i % $min_length; $n = intval($i / $min_length); $thisName = getRepeatThisValue($name_array, $index, $n); $thisDesc = getRepeatThisValue($desc_array, $index, $n); $thisType = str_replace(",", ";", getRepeatThisValue($subtype_array, $index, $n)); if ($type_array['globalstatus'] == 1) { $thisType .= "; status:optional"; } writeField($id, $answer_id, $thisName, $thisDesc, $thisType, $answer_array[$i], $mutable, $i); } } else { if ($type_array['type'] == "code") { echo page_convert($desc); } else { if ($type_array['type'] == "upload") { echo '<label for="">'; if ($type_array['status'] != "optional") { echo "<em>*</em>"; } echo "{$name}</label>"; echo "<input type=\"file\" name=\"{$fieldName}\" {$mutableString} />"; echo "<p class=\"formHint\">{$desc}<br />Currently Uploaded: "; if ($answer != "") { $answer_parts = explode(":", $answer, 3); $file_id = $answer_parts[1]; $file_name = $answer_parts[2]; echo "<a href=\"../download.php?file={$file_id}&filename={$file_name}\">View Here</a>"; } else { echo "None"; } echo '</p>'; } } } } } } } }