Skip to content

Instantly share code, notes, and snippets.

@ePirat
Created October 23, 2011 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ePirat/9f5bbc4d113e610fb875 to your computer and use it in GitHub Desktop.
Save ePirat/9f5bbc4d113e610fb875 to your computer and use it in GitHub Desktop.
Fixed ;)
<?php
//Get the correct ID for the plugin.
$thisfile = basename(__FILE__, ".php");
//Initiat Hooks
add_action('plugins-sidebar', 'createSideMenu', array($thisfile, 'Simple Members'));
add_action('edit-extras','members_protect_toggle',array());
add_action('changedata-save', 'members_protect_toggle_save', array());
add_action('index-pretemplate', 'start', array());
add_filter('content', 'members_content');
//What a useless function… Doh…
function start() {
session_start();
}
//Define and Initiat Plugin
register_plugin(
$thisfile, // ID of plugin, should be filename minus php
'Simple Members', # Title of plugin
'2.0', // Version of plugin
'OWS_Matthew', // Author of plugin
'http://OwassoWebSolutions.com', // Author URL
'This plugin creates a simple user system (Does not allow access to Administration Task!)', // Plugin Description
'plugins', // Page type of plugin
'members_admin' // Function that displays content
);
//Initiat Addministration Page
function members_admin() {
$errors = array();
if(isset($_POST['add_user'])){
$username = preg_replace('/[^A-Za-z]/', '', $_POST['username']);
$email = $_POST['email'];
$password = $_POST['password'];
$c_password = $_POST['c_password'];
if(file_exists('' . $username . '.xml')){
$errors[] = 'Username already exists';
}
if($username == ''){
$errors[] = 'Username is blank';
}
if($email == ''){
$errors[] = 'Email is blank';
}
if($password == '' || $c_password == ''){
$errors[] = 'Passwords are blank';
}
if($password != $c_password){
$errors[] = 'Passwords do not match';
}
if(count($errors) == 0){
$xml = new SimpleXMLElement('<user></user>');
$xml->addChild('password', md5($password));
$xml->addChild('email', $email);
$xml->asXML('../plugins/simple_members/' . $username . '.xml');
}
}
echo '
<h2>Simple Members Administration</h2>
<table>
<tr>
<th>Username:</th>
<th>Email:</th>
</tr>';
$files = glob('../plugins/simple_members/*.xml');
foreach($files as $file) {
$xml = new SimpleXMLElement($file, 0, true);
echo '
<tr>
<td>' . basename($file, '.xml') . '</td>
<td>' . $xml->email . '</td>
</tr>';
}
{
echo '</table>';
}
echo '<br />
<h3>Add a new Memeber:</h3>';
echo '<form method="post" action="">';
if(count($errors) > 0) {
echo '<ul>';
foreach($errors as $e) {
echo '<li>' . $e . '</li>';
}
echo '</ul>';
}
echo '
<p>Username <input type="text" name="username" size="20" /></p>
<p>Email <input type="text" name="email" size="20" /></p>
<p>Password <input type="password" name="password" size="20" /></p>
<p>Confirm Password <input type="password" name="c_password" size="20" /></p>
<p><input type="submit" name="add_user" value="add_user" /></p>
</form>';
}
//Display Login Form
function members_content($cont) {
//Login Process
$error = false;
if(isset($_POST['login'])){
$username = preg_replace('/[^A-Za-z]/', '', $_POST['username']);
$password = md5($_POST['password']);
if(file_exists('plugins/simple_members/' . $username . '.xml')){
$xml = new SimpleXMLElement('plugins/simple_members/' . $username . '.xml', 0, true);
if($password == $xml->password){
$_SESSION['username'] = $username;
}
}
$error = true;
}
global $data_index;
//print_r($data_index);
if (!isset($data_index->members_enable_protect)) {
//get_page_content();
return $cont;
}
if (isset($data_index->members_enable_protect)) {
if ( (isset($_SESSION['username'])) && (file_exists('plugins/simple_members/' . $_SESSION['username'] . '.xml')) ) {
return $cont;
}
}
if (isset($data_index->members_enable_protect)) {
if( (!isset($_SESSION['username'])) || (!file_exists('plugins/simple_members/' . $_SESSION['username'] . '.xml')) ){
?>
<form method="post" action="" name="login">
<p><?php if($error != '') {
echo '<div style="margin: 10px; height: 20px; text-align: center; background-color: orange; border: 3px solid yellow;"<p>Sorry, the credentials you\'ve entered are invalid.</p></div>';
}
?>
<p>Username:
<input type="text" name="username" size="20" />
</p>
<p>Password:
<input type="password" name="password" size="20" />
</p>
<p><input type="submit" value="Login" name="login" /></p>
</form>
<?
}
}
}
//Members enabled checkbox
function members_protect_toggle() {
global $data_edit;
$checked = '';
if (isset($data_edit->members_enable_protect)) {
$checked = 'checked="checked"';
}
{
echo '<tr>
<td><b>Members Only?</b> <input type="checkbox" name="s_enable_protect" value="1"';
echo $checked .'/>';
echo '</td>';
echo '</tr>';
}
}
//Process Members enabled checkbox
function members_protect_toggle_save() {
global $xml;
if (isset($_POST['s_enable_protect'])) {
$note = $xml->addChild('members_enable_protect');
$note->addCData(1);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment