[SOLVED] Password protected news articles / blog posts
Posted: Fri Jun 17, 2011 10:18 pm
Hi. I've made a simple modifications for individual news articles / blog posts password protection.
So...
1. Lets make a UDT, called "passprotect"
2. Let's make a field definition (for eg.: in News module).
First field (password protect option on/off):
Second field (individual password for article):
3. Now lets go to the summary template:
Find something like this:
And modify it, into this:
First IF - if summary is empty - show me content
Second IF - but if the content is protected (the checkbox called "Checkpass" is selected in this article) - show me "more link" only, and hide the content.
4. Almost done. Lets go to our detail article template:
Find something like this:
And transform it into this:
Done. Its works fine for me.
Make a new article and fill the password field (Articlepass) and check the checkbox (Checkpass) to activate it.
Tell me if something goes wrong (maybe I've done some typo mistake etc.)
All best.
So...
1. Lets make a UDT, called "passprotect"
Code: Select all
// Params:
// passprot - password
// contentprot - protected content, smarty tag, etc.
session_start();
$passprot = $params['passprot']; //read password from field definition
$pass = $_POST[pass];
if ($pass)
{
if ($pass==$passprot)
{
$_SESSION[passprot] = $passprot;
echo $params['contentprot'];
}
else
{
echo 'Wrong password.';
}
}
else
{
echo '
<form method=post>
Enter the password: <INPUT TYPE="PASSWORD" NAME="pass" VALUE="'.$pass.'">
<INPUT TYPE="SUBMIT" VALUE="OK">
</FORM>
';
}
$action = $_GET[action];
if ($action=="logout")
{
session_destroy(); // auto log out
}
First field (password protect option on/off):
Code: Select all
*Name: Checkpass
*Type: Checkbox
*Public (yes)
Code: Select all
*Name: Articlepass
*Type: Text field/area (Normal field, no wysiwyg)
*Max. length: 255
*Public (yes)
Find something like this:
Code: Select all
{else if $entry->content}
<div class="NewsSummaryContent">
{eval var=$entry->content}
</div>
{/if}
Code: Select all
{else if $entry->content}
<div class="NewsSummaryContent">
{if $entry->checkpass==1}
Password protected article {$entry->morelink}
{else}
{eval var=$entry->content}
{/if}
</div>
{/if}
Second IF - but if the content is protected (the checkbox called "Checkpass" is selected in this article) - show me "more link" only, and hide the content.
4. Almost done. Lets go to our detail article template:
Find something like this:
Code: Select all
<div id="NewsPostDetailContent">
{eval var=$entry->content}
</div>
Code: Select all
<div id="NewsPostDetailContent">
{if $entry->checkpass==1}
{passprotect passprot==$entry->articlepass contentprot==$entry->content }
{else}
{eval var=$entry->content}
Make a new article and fill the password field (Articlepass) and check the checkbox (Checkpass) to activate it.
Tell me if something goes wrong (maybe I've done some typo mistake etc.)
All best.