Skip to content

Commit

Permalink
Password protected posts!
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.automattic.com/wordpress/trunk@323 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
saxmatt committed Aug 20, 2003
1 parent f3d1d48 commit d41eaab
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
27 changes: 24 additions & 3 deletions b2-include/b2template.functions.php
Expand Up @@ -522,7 +522,10 @@ function the_title_unicode($before='',$after='') {
function get_the_title() {
global $id, $post;
$output = stripslashes($post->post_title);
return($output);
if (!empty($post->post_password)) { // if there's a password
$output = 'Protected: ' . $output;
}
return $output;
}

function the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
Expand Down Expand Up @@ -580,10 +583,22 @@ function the_content_unicode($more_link_text='(more...)', $stripteaser=0, $more_

function get_the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
global $id, $post, $more, $c, $withcomments, $page, $pages, $multipage, $numpages;
global $HTTP_SERVER_VARS, $preview;
global $HTTP_SERVER_VARS, $HTTP_COOKIE_VARS, $preview;
global $querystring_start, $querystring_equal, $querystring_separator;
global $pagenow;
$output = '';

if (!empty($post->post_password)) { // if there's a password
if ($HTTP_COOKIE_VARS['wp-postpass'] != $post->post_password) { // and it doesn't match the cookie
$output = "<form action='$siteurl/wp-pass.php' method='post'>
<p>This post is password protected. To view it please enter your password below:</p>
<p><label>Password: <input name='post_password' type='text' size='20' /></label> <input type='submit' name='Submit' value='Submit' /></p>
</form>
";
return $output;
}
}

if ($more_file != '') {
$file = $more_file;
} else {
Expand Down Expand Up @@ -666,9 +681,15 @@ function the_excerpt_unicode() {

function get_the_excerpt($fakeit = false) {
global $id, $post;
global $HTTP_SERVER_VARS, $preview;
global $HTTP_SERVER_VARS, $HTTP_COOKIE_VARS, $preview;
$output = '';
$output = $post->post_excerpt;
if (!empty($post->post_password)) { // if there's a password
if ($HTTP_COOKIE_VARS['wp-postpass'] != $post->post_password) { // and it doesn't match the cookie
$output = "There is no excerpt because this is a protected post.";
return $output;
}
}
//if we haven't got an excerpt, make one in the style of the rss ones
if (($output == '') && $fakeit) {
$output = get_the_content();
Expand Down
12 changes: 12 additions & 0 deletions wp-pass.php
@@ -0,0 +1,12 @@
<?php

/*
This is just a very simple script to set a cookie with a posted password and redirect back from whence the browser came.
It doesn't need to connect to the DB, or do anything fancy at all. Yum.
-- Matt
*/

setcookie('wp-postpass', $HTTP_POST_VARS['post_password'], time()+60*60*24*30);
header('Location: ' . $HTTP_SERVER_VARS['HTTP_REFERER']);

?>

0 comments on commit d41eaab

Please sign in to comment.