function main() { if (!isset($_GET['url']) || !preg_match('#^http.?://.+\\.tumblr\\.com.*#i', $_GET['url'])) { echo $_GET['url']; exit('Hello Visitor!'); } $strPageSource = getPageSource(encode_cjk_url($_GET['url'])); #get HTML page source code !$strPageSource && echoImageNotFoundTextFileAndExit($_GET['url']); $arrImagesUrls = parseImagesUrls($strPageSource); #parse urls of images $intCountOfImagesUrls = count($arrImagesUrls); $intCountOfImagesUrls === 0 && echoImageNotFoundTextFileAndExit($_GET['url']); #no image url found, echo error message as txt file. $intCountOfImagesUrls === 1 && redirectAndExit(array_pop($arrImagesUrls)); #we got just one image url to be fetch, so no need for fetching, just redirect the browser to it. $arrContentAndUrlOfValidImages = fetchImages($arrImagesUrls); #not every url is available, so try every one. $intCountOfValidImagesUrls = count($arrContentAndUrlOfValidImages['validImagesUrls']); #check out the number of available urls $intCountOfValidImagesUrls === 0 && echoImageNotFoundTextFileAndExit($_GET['url']); $intCountOfValidImagesUrls === 1 && redirectAndExit(array_pop($arrContentAndUrlOfValidImages['validImagesUrls'])); #if we got just one available url, no need to pack the image cause we could just redirect the browser. //when we got multiple images to deal with $strZipString = makeZipPack($arrContentAndUrlOfValidImages['imageStrings'], $arrContentAndUrlOfValidImages['validImagesUrls']); outputZipPackAsFileDownload($strZipString); }
function main() { (!isset($_GET['url']) || !filter_var($_GET['url'], FILTER_VALIDATE_URL)) && exit('Hello World!'); $strPageSource = getPageSource($_GET['url']); #get HTML page source code !$strPageSource && echoImageNotFoundTextFileAndExit($_GET['url']); $arrImagesUrls = parseImagesUrls($strPageSource); #parse urls of images $intCountOfImagesUrls = count($arrImagesUrls); $intCountOfImagesUrls === 0 && echoImageNotFoundTextFileAndExit($_GET['url']); #no image url found, echo error message as txt file. $intCountOfImagesUrls === 1 && redirectAndExit(array_pop($arrImagesUrls)); #we got just one image url to be fetch, so no need for fetching, just redirect the browser to it. $arrContentAndUrlOfValidImages = fetchImages($arrImagesUrls); #not every url is available, so try every one. $intCountOfValidImagesUrls = count($arrContentAndUrlOfValidImages['validImagesUrls']); #check out the number of available urls $intCountOfValidImagesUrls === 0 && echoImageNotFoundTextFileAndExit($_GET['url']); $intCountOfValidImagesUrls === 1 && redirectAndExit(array_pop($arrContentAndUrlOfValidImages['validImagesUrls'])); #if we got just one available url, no need to pack the image cause we could just redirect the browser. //when we got multiple images to deal with $strZipString = makeZipPack($arrContentAndUrlOfValidImages['imageStrings'], $arrContentAndUrlOfValidImages['validImagesUrls']); outputZipPackAsFileDownload($strZipString); }
// don't bother doing any of this if the user is already logged in if (Session::getUser()) { redirectAndExit("index"); } if (!isset($_POST["token"])) { redirectAndExit("index"); } $token = $_POST["token"]; $usernameFieldName = FormFieldRandomizer::getUsernameFieldNameForToken($token); $passwordFieldName = FormFieldRandomizer::getPasswordFieldNameForToken($token); if (!isset($_POST[$usernameFieldName], $_POST[$passwordFieldName])) { redirectAndExit("index"); } $username = $_POST[$usernameFieldName]; $password = $_POST[$passwordFieldName]; $user = Session::login($username, $password); if (!$user) { setcookie("LoginError", "1"); setcookie("Username", $username); redirectAndExit("index"); } if ($user->premade) { $token = PasswordChangeToken::generate($user); $user->passwordChangeToken = $token; $user->save(); setcookie("User", $user->id); setcookie("PasswordChangeToken", $token); redirectAndExit("premade"); } redirectAndExit("index");
} if (!$errors) { $pdo = getPDO(); // Decide if we are editing or adding if ($postId) { editPost($pdo, $title, $body, $postId); } else { $userId = getAuthUserId($pdo); $postId = addPost($pdo, $title, $body, $userId); if ($postId === false) { $errors[] = 'Post operation failed'; } } } if (!$errors) { redirectAndExit('edit-post.php?post_id=' . $postId); } } ?> <!DOCTYPE html> <html> <head> <title> A blog application | New post </title> <?php php > (require 'templates/head.php'); ?> </head> <body> <?php require 'templates/top-menu.php';
require_once 'lib/view-post.php'; session_start(); //Get the post ID if (isset($_GET['post_id'])) { $postId = $_GET['post_id']; } else { //so we always have a post ID var defined $postId = 0; } //Content to db, run query, error handling $pdo = getPDO(); $row = getPostRow($pdo, $postId); $commentCount = $row['comment_count']; //if the post does not exist, lets's deal with that here if (!row) { redirectAndExit('index.php?not-found=1'); } $errors = null; if ($_POST) { switch ($_GET['action']) { case 'add-comment': $commentData = array('name' => $_POST['comment-name'], 'website' => $_POST['comment-website'], 'text' => $_POST['comment-text']); $errors = handleAddComment($pdo, $postId, $commentData); break; case 'delete-comment': $deleteResponse = $_POST['delete-comment']; handleDeleteComment($pdo, $postId, $deleteResponse); break; } } else { $commentData = array('name' => '', 'website' => '', 'text' => '');
$postId = $_GET['post_id']; } else { $postId = 0; } $pdo = getPDO(); $row = getPostRow($pdo, $postId); // If the post does not exist, let's deal with that here if (!$row) { redirectAndExit('index.php?not-found=1'); } $errors = null; if ($_POST) { $commentData = array('name' => $_POST['comment-name'], 'website' => $_POST['comment-website'], 'text' => $_POST['comment-text']); $errors = addCommentToPost($pdo, $postId, $commentData); if (!$errors) { redirectAndExit('view-post.php?post_id=' . $postId); } } $bodyText = HTMLEscape($row['body']); $paraText = str_replace("\n", "</p><p>", $bodyText); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>A Blog Application | <?php echo HTMLEscape($row['title']); ?> </title> </head>
<?php require_once 'lib/common.php'; session_start(); logout(); redirectAndExit('index.php');
require_once 'lib/common.php'; require_once 'lib/list-posts.php'; session_start(); // Don't let non-auth users access this screen if (!isLoggedin()) { redirectAndExit('index.php'); } if ($_POST) { $deleteResponse = $_POST['delete-post']; if ($deleteResponse) { $keys = array_keys($deleteResponse); $deletePostId = $keys[0]; if ($deletePostId) { deletePost(getPDO(), $deletePostId); redirectAndExit('list-posts.php'); } } } // Connect to the database, run a query $pdo = getPDO(); $posts = getAllPosts($pdo); ?> <!DOCTYPE html> <html> <head> <title> A blog application | Blog posts</title> <?php
if ($_POST) { // Here's the install $pdo = getPDO(); list($rowCounts, $error) = installBlog($pdo); $password = ''; if (!$error) { $username = '******'; list($password, $error) = createUser($pdo, $username); } $_SESSION['count'] = $rowCounts; $_SESSION['error'] = $error; $_SESSION['username'] = $username; $_SESSION['password'] = $password; $_SESSION['try-install'] = true; // ... and here we redirect from POST to GET redirectAndExit('install.php'); } // Let's see if we've just installed $attempted = false; if (isset($_SESSION['try-install'])) { $attempted = true; $count = $_SESSION['count']; $error = $_SESSION['error']; $username = $_SESSION['username']; $password = $_SESSION['password']; // Unset session variables, so we only report the install/failure once unset($_SESSION['count']); unset($_SESSION['error']); unset($_SESSION['username']); unset($_SESSION['password']); unset($_SESSION['try-install']);