|
|
Installation notes:This addon will add the ability to integrate a login box to your site, and let your registered users log in and post comments without specifying their names and passwords every time. This addon will install an example file and an example template too. Create file "./loginbox.php":
Place this in the file:
<?php
if (!defined('CN_INIT_LOGINBOX')) {
// Define variables and constants and include files
define('CN_INIT_LOGINBOX', true);
$cutepath = dirname(__FILE__);
chdir($cutepath);
if (isset($_GET['action'])) {
$action = $_GET['action'];
} elseif (isset($_POST['action'])) {
$action = $_POST['action'];
} else {
$action = '';
}
require_once($cutepath.'/inc/functions.inc.php');
// Start Session
session_start();
// Log user out if requested
if ($action == 'logout') {
session_destroy();
session_unset();
setcookie(session_name(), '');
unset($_SESSION);
$message = '<div style="color: green;">Logged Out</div>';
}
// Detect IP
$ip = '';
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
if ($ip == '') {
$ip = $_SERVER['REMOTE_ADDR'];
}
if ($ip == '') {
$ip = 'not detected';
}
$all_users = file($cutepath.'/data/users.db.php');
$is_logged_in = false;
if ($action == 'login') {
$md5_password = md5($password);
if (check_login($username, $md5_password)) {
$_SESSION['username'] = $username;
$_SESSION['md5_password'] = $md5_password;
$_SESSION['ip'] = $ip;
$_SESSION['login_referer'] = $HTTP_REFERER;
$is_logged_in = true;
$name = $_POST['name'] = $member_db[4];
$mail = $_POST['mail'] = $member_db[5];
$old_users_db = file($cutepath.'/data/users.db.php');
$modified_users = fopen($cutepath.'/data/users.db.php', 'w');
foreach ($old_users_db as $old_users_db_line) {
$old_users_db_arr = explode('|', $old_users_db_line);
if ($member_db[0] != $old_users_db_arr[0]) {
fwrite($modified_users, $old_users_db_line);
} else {
fwrite($modified_users, $old_users_db_arr[0].'|'.$old_users_db_arr[1].'|'.$old_users_db_arr[2].'|'.$old_users_db_arr[3].'|'.$old_users_db_arr[4].'|'.$old_users_db_arr[5].'|'.$old_users_db_arr[6].'|'.$old_users_db_arr[7].'|'.$old_users_db_arr[8].'|'.time().'||'.chr(10));
}
}
fclose($modified_users);
} else {
$message = '<div style="color: red;">Invalid login</div>';
}
} elseif (isset($_SESSION['username'])) {
if (check_login($_SESSION['username'], $_SESSION['md5_password'])) {
if ($_SESSION['ip'] != $ip) {
$message = '<div style="color: red;">Session IP doesn\'t match.</div>';
} else {
$is_logged_in = true;
$name = $_POST['name'] = $member_db[4];
$mail = $_POST['mail'] = $member_db[5];
}
} else {
$message = '<div style="color: red;">Invalid login</div>';
}
}
chdir(dirname($_SERVER['SCRIPT_FILENAME']));
} else {
if ($is_logged_in) {
?>
<p>
You are logged in as <?=htmlentities($_SESSION['username'])?>, <a href="<?=$PHP_SELF?>?action=logout">Log Out</a>
</p>
<?php
} else {
?>
<form name="login" action="<?=htmlentities($PHP_SELF)?>" method="post">
<input type="hidden" name="action" value="login" />
<?=$message?>
<label for="username">Username:</label>
<br />
<input type="text" name="username" id="username" value="<?=htmlentities($_SESSION['lastusername'])?>" style="width: 140px;" />
<br />
<label for="password">Password:</label>
<br />
<input type="password" name="password" id="password" style="width: 140px;" />
<br />
<input type="submit" style="width: 75px;" value='Login' accesskey="s" />
</form>
<?php
}
}
?>
Create file "./loginbox_example.php":
Place this in the file:
<?php
// This once should go at the top of the document. If you don't put it at the top,
// it will give an "Headers already sent by" error message.
include('./loginbox.php');
?>
<html>
<head>
<title>Login Box Example</title>
</head>
<body>
Some HTML before the login box...
<?php
// This include is exactly the same as the one at the top, but you should place
// this include at the place where you want the login box to show up.
include('./loginbox.php');
?>
...and some more HTML here...
<?php
// A normal include code to show your news with our example template
$template = 'loginbox_example';
include('./show_news.php');
?>
... And we'll finish, with some more HTML code ;)
</body>
</html>
Create file "./data/loginbox_example.tpl":
Place this in the file:
<?PHP
///////////////////// TEMPLATE loginbox_example /////////////////////
$template_active = <<<HTML
<table border="0" width="420" cellspacing="1" cellpadding="3">
<tr>
<td width="100%" style="text-align:justify">
<b>{title}</b>
</td>
</tr>
<tr>
<td width="100%" style="text-align:justify">
<font style="font-family:georgia, verdana, arial, sans-serif; color:#666; font-size:14;">{short-story}</font></td>
</tr>
<tr>
<td width="100%">
<table border="0" style="border-top: 1px dotted #f2f3f3" width="408" cellspacing="0">
<tr>
<td width="220"><i><font style="font-family:georgia, verdana, arial, sans-serif; font-size:11; color:black;">{date} by {author}</font></i><br> </td><td width="168" ><div align=right>
<font style="font-family:georgia, verdana, arial, sans-serif; font-size:11;">[full-link]Read More ...[/full-link] [com-link]comments ({comments-num})[/com-link]</font><br>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
HTML;
$template_full = <<<HTML
<table border="0" width="420" cellspacing="1" cellpadding="3">
<tr>
<td width="100%" style="text-align:justify">
<b>{title}</b>
</td>
</tr>
<tr>
<td width="100%" style="text-align:justify">
<font style="font-family:georgia, verdana, arial, sans-serif; color:#666; font-size:14;">{full-story}</font></td>
</tr>
<tr>
<td width="100%">
<table border="0" style="border-top: 1px dotted #f2f3f3" width="408" cellspacing="0">
<tr>
<td width="220"><i><font style="font-family:georgia, verdana, arial, sans-serif; font-size:11; color:black;">{date} by {author}</font></i><br> </td><td width="168"><div align=right>
<font style="font-family:georgia, verdana, arial, sans-serif; font-size:11;">{comments-num} comments</font><br>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<br />
HTML;
$template_comment = <<<HTML
<table border="0" width="400" height="40" cellspacing="" cellpadding="3">
<tr>
<td height="1" style="border-bottom-style: solid;border-bottom-width: 1px; border-bottom-color: black;">by <b>{author}</b> @ {date}</td>
</tr>
<tr>
<td height="40" valign="top" bgcolor="#F9F9F9" >{comment}</td>
</tr>
</table>
<br>
HTML;
$template_form = <<<HTML
[logged-in]You can add an comment, the username where you are logged in with will be used.[/logged-in]
<table border="0" width="342" cellspacing="0" cellpadding="0">
[not-logged-in]
<tr>
<td width="49" height="1">
name:
</td>
<td width="289" height="1"><input type="text" name="name" tabindex="1"></td>
</tr>
<tr>
<td width="49" height="1">
mail:
</td>
<td width="289" height="1"> <input type="text" name="mail" tabindex="2"> (optional)</td>
</tr>
</center>
[/not-logged-in]
<tr>
<td width="51" height="1">
<p align="left">smile:</p>
</td>
<center>
<td width="291" height="1" >
{smilies}
</td>
</tr>
<tr>
<td width="340" height="1" colspan="2"> <textarea cols="40" rows="6" name="comments" tabindex="3"></textarea><br />
<input type="submit" name="submit" value=" Add My Comment " accesskey="s">
</td>
</tr>
</table>
HTML;
$template_prev_next = <<<HTML
<p align="center">[prev-link]<< Previous[/prev-link] {pages} [next-link]Next >>[/next-link]</p>
HTML;
?>
Change block in "./inc/shows.inc.php":
Automatically Generated, be sure to be very precise on tabs and spaces.
Replace this:
// $comments = replace_comment("add", $comments); //commented because will mess up the <br />
$comments = preg_replace(array("'\"'", "'\''", "''"), array(""", "'", ""), $comments);
$name = replace_comment("add", preg_replace("/\n/", "",$name));
$mail = replace_comment("add", preg_replace("/\n/", "",$mail));
echo"<div style=\"text-align: center;\">This name is owned by a registered user and you must enter password to use it<br />
<form method=\"post\" action=\"\">Password: <input type=\"password\" name=\"password\" />
<input type=\"hidden\" name=\"name\" value=\"$name\" />
<input type=\"hidden\" name=\"comments\" value=\"$comments\" />
<input type=\"hidden\" name=\"mail\" value=\"$mail\" />
<input type=\"hidden\" name=\"ip\" value=\"$ip\" />
<input type=\"hidden\" name=\"subaction\" value=\"addcomment\" />
<input type=\"hidden\" name=\"show\" value=\"$show\" />
<input type=\"hidden\" name=\"ucat\" value=\"$ucat\" />
$user_post_query
<input type=\"submit\" /></form></div>";
$CN_HALT = TRUE;
break 2;
// exit();
With:
// Login Box v1.0 - changeblock - Old
// // $comments = replace_comment("add", $comments); //commented because will mess up the <br />
// $comments = preg_replace(array("'\"'", "'\''", "''"), array(""", "'", ""), $comments);
// $name = replace_comment("add", preg_replace("/\n/", "",$name));
// $mail = replace_comment("add", preg_replace("/\n/", "",$mail));
//
// echo"<div style=\"text-align: center;\">This name is owned by a registered user and you must enter password to use it<br />
// <form method=\"post\" action=\"\">Password: <input type=\"password\" name=\"password\" />
// <input type=\"hidden\" name=\"name\" value=\"$name\" />
// <input type=\"hidden\" name=\"comments\" value=\"$comments\" />
// <input type=\"hidden\" name=\"mail\" value=\"$mail\" />
// <input type=\"hidden\" name=\"ip\" value=\"$ip\" />
// <input type=\"hidden\" name=\"subaction\" value=\"addcomment\" />
// <input type=\"hidden\" name=\"show\" value=\"$show\" />
// <input type=\"hidden\" name=\"ucat\" value=\"$ucat\" />
// $user_post_query
// <input type=\"submit\" /></form></div>";
// $CN_HALT = TRUE;
// break 2;
// // exit();
// Login Box v1.0 - changeblock - New
if (!isset($member_db)) {
?>
You should be logged in to use this name.
<?php
$CN_HALT = true;
break 2;
}
// Login Box v1.0 - End changeblock
Add block in "./inc/shows.inc.php":
Automatically Generated, be sure to be very precise on tabs and spaces.
Add this:
// Login Box v1.0 - addblock
$template_form = preg_replace('/\\[logged-in\\](.*?)\\[\\/logged-in\\]/is', ($is_logged_in) ? '\\1' : '', $template_form);
$template_form = preg_replace('/\\[not-logged-in\\](.*?)\\[\\/not-logged-in\\]/is', ($is_logged_in) ? '' : '\\1', $template_form);
// Login Box v1.0 - End addblock
Between:
$template_form = str_replace("{smilies}", $smilies_form, $template_form);
And:
echo"<form method=\"post\" name=\"comment\" id=\"comment\" action=\"\">".$template_form."<div><input type=\"hidden\" name=\"subaction\" value=\"addcomment\" /><input type=\"hidden\" name=\"ucat\" value=\"$ucat\" /><input type=\"hidden\" name=\"show\" value=\"$show\" />$user_post_query</div></form>";
End installation notes:See the example files for instructions on how to use them. The tags [logged-in]...[/logged-in] and [not-logged-in]...[/not-logged-in] can be used in the Add Comment Form template, there is an template example too. Go Here for the example page. If you get "Session IP doesn't match" when logged in, and have register_globals turned off at your server, fix it by adding this to the index.php file, just below
extract($_ENV, EXTR_OVERWRITE);
extract($_GET, EXTR_OVERWRITE);
extract($_POST, EXTR_OVERWRITE);
extract($_COOKIE, EXTR_OVERWRITE);
extract($_SERVER, EXTR_OVERWRITE);It is an bug in CuteNews, that's why the installer doen't do it automatically.
 |