function myStrRep($orig, $find, $rep) { $index = getMatchIndex($orig, $find); if ($index == -1) { echo "{$find} not found in {$orig}"; } else { echo replaceString($orig, $find, $rep, $index); } }
function displayFile($file_name, $replaces = null, $loop = array()) { $lines = file($file_name); foreach ($lines as $line_num => $line) { if (!isset($loop[$line_num + 1])) { echo replaceString($line, $replaces); } else { foreach ($loop[$line_num + 1] as $replaces) { echo replaceString($line, $replaces); } } } }
function displayFile($file_name, $replaces = null, $escape = false, $loop = array()) { $lines = file("../template/" . $file_name); foreach ($lines as $line_num => $line) { if (!isset($loop[$line_num + 1])) { echo replaceString($line, $replaces, $escape); } else { foreach ($loop[$line_num + 1] as $loop_replaces) { echo replaceString($line, $loop_replaces, $escape); } } } }
function parseMask($replaced_phone_code, $phone_code, $replaced_mask) { //var_dump($replaced_phone_code, $phone_code, $replaced_mask); $phone_code = str_replace('(8~0)', '', $phone_code); $phone_code_strrlen = strlen($phone_code); if ($phone_code_strrlen == 3) { $replaced_mask = '+___(___)__-__-__'; } elseif ($phone_code_strrlen == 4) { $replaced_mask = '+___(____)_-__-__'; } elseif ($phone_code_strrlen == 5) { $replaced_mask = '+___(_____)__-__'; } $r = $replaced_phone_code . '' . $phone_code; $new_mask = replaceString($r, $replaced_mask); return $new_mask; }
$numOfComments = $_POST["numberOfComments"]; } $commentArray = array(); $i = 0; foreach ($theXML as $item) { $commentArray[$i++] = $item; } if (isset($_POST["commentPage"]) && is_numeric($_POST["commentPage"]) && $_POST["commentPage"]) { $page = min(intval((count($commentArray) - 1) / $numOfComments) + 1, $_POST["commentPage"]); } $commentArray = array_reverse($commentArray); for ($i = ($page - 1) * $numOfComments; $i <= min(count($commentArray) - 1, ($page - 1) * $numOfComments + $numOfComments - 1); $i++) { $theName = replaceString(interpretFromXML($commentArray[$i]->name)); $id = $commentArray[$i]->id; $theDate = $commentArray[$i]->date; $theComment = replaceString(interpretFromXML($commentArray[$i]->comment)); $starSize = $commentArray[$i]->rating * 100 / 5; echo "\n\t\t\t\t\t\t\t\t<p><span class='userName'>{$theName}</span> said <span class='commentDate'>({$theDate})</span>:</p>\n\t\t\t\t\t\t\t\t<p class='report'><a href='report.php?id={$id}'>Report</a></p>\n\t\t\t\t\t\t\t\t<div style='\n\t\t\t\t\t\t\t\t\twidth: {$starSize}" . "px;\n\t\t\t\t\t\t\t\t\theight: 19.05px;\n\t\t\t\t\t\t\t\t\tbackground-image: url(\"stars.png\");\n\t\t\t\t\t\t\t\t\tbackground-size: cover;\n\t\t\t\t\t\t\t\t'></div>\n\t\t\t\t\t\t\t\t<br/>\n\t\t\t\t\t\t\t\t<div class='comment'>\n\t\t\t\t\t\t\t\t\t<p class='commentParagraph'>{$theComment}</p>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t"; } echo "<br/>"; echo "<p class='centerText'>Page {$page}/" . intval((count($commentArray) - 1) / $numOfComments + 1) . "</p>"; if ($page > 1) { echo "\n\t\t\t\t\t\t\t\t<form class='centerText' method='post'>\n\t\t\t\t\t\t\t\t\t<input type='hidden' name='commentPage' value=" . ($page - 1) . " />\n\t\t\t\t\t\t\t\t\t<input type='hidden' name='numberOfComments' value=" . $numOfComments . " />\n\t\t\t\t\t\t\t\t\t<input type='submit' class='pageLink' value=' Previous page...'/>\n\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t"; } if (count($commentArray) - 1 > ($page - 1) * $numOfComments + $numOfComments) { echo "\n\t\t\t\t\t\t\t\t<form class='centerText' method='post'>\n\t\t\t\t\t\t\t\t\t<input type='hidden' name='commentPage' value=" . ($page + 1) . " />\n\t\t\t\t\t\t\t\t\t<input type='hidden' name='numberOfComments' value=" . $numOfComments . " />\n\t\t\t\t\t\t\t\t\t<input type='submit' class='pageLink' value=' Next page...'/>\n\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t"; } if (intval(count($commentArray) / $numOfComments) > 0) { echo "\n\t\t\t\t\t\t\t\t<form class='centerText' method='post'>\n\t\t\t\t\t\t\t\t\t<input type='submit' class='pageLink' value='Go to...'/>\n\t\t\t\t\t\t\t\t\t<input type='text' name='commentPage' value='{$page}' />\n\t\t\t\t\t\t\t\t\t<input type='hidden' name='numberOfComments' value=" . $numOfComments . " />\n\t\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t"; } } else {
function displayPageFile($template_filename, $replaces = null) { $subject = file_get_contents($template_filename); echo replaceString($subject, $replaces); }
<link rel="stylesheet" type="text/css" href="main.css" /> <title>Report</title> </head> <body id="reportBody"> <div id="mainDiv"> <div id="reportDiv" class="block"> <?php include 'functions.php'; $theString = '<wrapper>' . file_get_contents("reviews.xml") . '</wrapper>'; $theXML = simplexml_load_string($theString); $id = $_GET["id"]; $item = null; foreach ($theXML as $currentItem) { if ($id == $currentItem->id) { $item = $currentItem; break; } } if ($item != null) { $theName = replaceString(interpretFromXML($item->name)); $theDate = $item->date; $theComment = replaceString(interpretFromXML($item->comment)); echo "\n\t\t\t\t\t\t\t<p><span class='userName'>{$theName}</span> said <span class='commentDate'>({$theDate})</span>:</p>\n\t\t\t\t\t\t\t<br/>\n\t\t\t\t\t\t\t<div class='comment'>\n\t\t\t\t\t\t\t\t<p class='commentParagraph'>{$theComment}</p>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<form action='post-report.php' method='post'>\n\t\t\t\t\t\t\t\t<br/>\n\t\t\t\t\t\t\t\tWhat's wrong with this post?\n\t\t\t\t\t\t\t\t<input type='hidden' name='id' value='{$id}' />\n\t\t\t\t\t\t\t\t<textarea id='comment' name='reason' ></textarea>\n\t\t\t\t\t\t\t\t<br/>\n\t\t\t\t\t\t\t\t<br/>\n\t\t\t\t\t\t\t\t<input type='submit' value='Report this post' />\n\t\t\t\t\t\t\t</form>\n\t\t\t\t\t\t\t"; } else { header("Location: review.php"); } ?> </div> </body> </html>
<?php function replaceString($theString) { $theString = str_replace("<", "|(LESSTHAN)|", $theString); $theString = str_replace(">", "|(GREATERTHAN)|", $theString); $theString = str_replace("&", "|(AMPERSAND)|", $theString); return $theString; } $id = $_POST['id']; $reason = replaceString($_POST['reason']); $string = "<theComment>\n <id>{$id}</id>\n <reason>{$reason}</reason>\n</theComment>\n"; while (!file_put_contents("reports.xml", $string, FILE_APPEND | LOCK_EX)) { } header("Location: review.php");
if ($theReportedXML != null) { foreach ($theReportedXML as $report) { $reportID = $report->id; $itemID = $item->id; if (intval($reportID) == intval($itemID)) { $show = true; $reportedItem = $report; break; } } } if ($show) { $id = $item->id; $ip = $item->ip; $name = replaceString(interpretFromXML($item->name)); $rating = $item->rating; $date = $item->date; $comment = replaceString(interpretFromXML($item->comment)); $starSize = $rating * 100 / 5; if ($reportedItem != null) { echo "<br/><br/><p class='reportedItem'>The following item was reported for the reason: \n\t\t\t\t\t\t\t\t<a href='dismiss-report.php?id={$id}" . ($reported ? "&showReports=true" : "") . "' class='action'>DISMISS</a><br/>\n\t\t\t\t\t\t\t\t<div class='reportedText'>" . replaceString(interpretFromXML($reportedItem->reason)) . '</div></p>'; } echo "\n\t\t\t\t\t\t\t<a class='action' href='delete-post.php?id={$id}" . ($reported ? "&showReports=true" : "") . "'>DELETE</a><br/>\n\t\t\t\t\t\t\t<span>Comment id: <span class='commentID'>{$id}</span><br/>\n\t\t\t\t\t\t\tIP address: <span class='properties'>{$ip}</span><br/>\n\t\t\t\t\t\t\tName: <span class='properties'>{$name}</span><br/>\n\t\t\t\t\t\t\tRating: {$rating} \n\t\t\t\t\t\t\t<div style='\n\t\t\t\t\t\t\t\twidth: {$starSize}" . "px;\n\t\t\t\t\t\t\t\theight: 19.05px;\n\t\t\t\t\t\t\t\tbackground-image: url(\"stars.png\");\n\t\t\t\t\t\t\t\tbackground-size: cover;\n\t\t\t\t\t\t\t\tdisplay: inline-block;\n\t\t\t\t\t\t\t'></div><br/>\n\t\t\t\t\t\t\tTime: <span class='properties'>{$date}</span><br/>\n\t\t\t\t\t\t\tComment:<br/>\n\t\t\t\t\t\t\t\t<div class='comment'>\"{$comment}\"</div>\n\t\t\t\t\t\t\t<br/><br/>\n\t\t\t\t\t\t"; } } } else { echo "<h1>There is no comments yet</h1>"; } ?> </body> </html>
function prettyJson($json, $table = null) { $result = ''; $level = 0; $in_quotes = false; $in_escape = false; $ends_line_level = NULL; $json_length = strlen($json); for ($i = 0; $i < $json_length; $i++) { $char = $json[$i]; $new_line_level = NULL; $post = ""; if ($ends_line_level !== NULL) { $new_line_level = $ends_line_level; $ends_line_level = NULL; } if ($in_escape) { $in_escape = false; } else { if ($char === '"') { $in_quotes = !$in_quotes; } else { if (!$in_quotes) { switch ($char) { case '}': case ']': $level--; $ends_line_level = NULL; $new_line_level = $level; break; case '{': case '[': $level++; case ',': $ends_line_level = $level; break; case ':': $post = " "; break; case " ": case "\t": case "\n": case "\r": $char = ""; $ends_line_level = $new_line_level; $new_line_level = NULL; break; } } else { if ($char === '\\') { $in_escape = true; } } } } if ($new_line_level !== NULL) { $result .= "\n" . str_repeat("\t", $new_line_level); } $result .= $char . $post; } return replaceString($result, $table); }
<?php function replaceString($theString) { $theString = str_replace("<", "|(LESSTHAN)|", $theString); $theString = str_replace(">", "|(GREATERTHAN)|", $theString); $theString = str_replace("&", "|(AMPERSAND)|", $theString); return $theString; } function toXML($id, $ip, $name, $rating, $date, $comment) { return "<theComment>\n <id>{$id}</id>\n <ip>{$ip}</ip>\n <name>{$name}</name>\n <rating>{$rating}</rating>" . "\n <date>{$date}</date>\n <comment>{$comment}</comment>\n</theComment>\n"; } if (isset($_POST["theName"]) && strlen($_POST["theName"]) > 0 && isset($_POST["comment"])) { $theName = replaceString($_POST["theName"]); $theComment = replaceString($_POST["comment"]); $theRating = $_POST["rating"]; date_default_timezone_set("America/New_York"); $date = date("\\o\\n m/d/Y \\a\\t h:iA"); $averageStars = $theRating; $numOfStars = 1; $id = 0; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } if (is_file("average-stars.str")) { $data = file_get_contents("average-stars.str");