------------------------------------------------------------
revno: 861
committer: Jon Phillips <[email protected]>
branch nick: aikiframework
timestamp: Sun 2011-06-19 16:37:47 -0500
message:
Finished adding basic phpdoc to the rest of the codebase and closed out this
task. Learned a lot:
https://blueprints.launchpad.net/aikiframework/+spec/complete-phpdoc-conversion
Next, I will comb through the /assets folder and learn some more
modified:
src/libs/bot.php
src/libs/forms.php
src/libs/image.php
src/libs/input.php
src/libs/installer.php
src/libs/membership.php
--
lp:aikiframework
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk
Your team Aiki Framework Developers is subscribed to branch lp:aikiframework.
To unsubscribe from this branch go to
https://code.launchpad.net/~aikiframework-devel/aikiframework/trunk/+edit-subscription
=== modified file 'src/libs/bot.php'
--- src/libs/bot.php 2011-06-19 20:30:20 +0000
+++ src/libs/bot.php 2011-06-19 21:37:47 +0000
@@ -28,11 +28,16 @@
*
* @todo rename class to Bot
*
- * @todo implement these removed methods:
- * public function import_javascript;
- * public function import_image;
- * public function create_mockup_from_psd;
- * public function create_mockup_from_svg;
+ * @todo implement these removed methods:
+ * * public function import_javascript;
+ * * public function import_image;
+ * * public function create_mockup_from_psd;
+ * * public function create_mockup_from_svg;
+ *
+ * @todo this code needs review, this is a misc. class, should consider
+ * changing to import.php and split out the debug code into debug.php
+ * @todo another consideration is that this is an extension and not in the
+ * aiki core
*/
class bot
{
=== modified file 'src/libs/forms.php'
--- src/libs/forms.php 2011-06-15 02:54:01 +0000
+++ src/libs/forms.php 2011-06-19 21:37:47 +0000
@@ -24,18 +24,21 @@
*
* @category Aiki
* @package Library
+ *
+ * @todo rename this class to Forms
+ * @todo redo this entire class!
*/
class forms
{
/**
* keeps track of the value of the Submit button in forms
- * @global string $submit_button
+ * @var string
*/
public $submit_button;
/**
* specifies the edit type of the form, e.g. 'save'
- * @global string $edit_type
+ * @var string
*/
public $edit_type;
@@ -50,18 +53,18 @@
* @global array $aiki The global aiki object
* @return string
*/
-
- public function displayForms($text){
+ public function displayForms($text)
+ {
global $db, $aiki;
//match all forms as (#(form : action : id)#)
- if ( preg_match_all("/\(\#\(form\:(.*)\)\#\)/Us", $text, $forms)){
-
- foreach ($forms['1'] as $form_data){
-
- if ($form_data){
-
+ if ( preg_match_all("/\(\#\(form\:(.*)\)\#\)/Us", $text, $forms))
+ {
+ foreach ($forms['1'] as $form_data)
+ {
+ if ($form_data)
+ {
$form_output = '';
$form_sides = explode(":", $form_data);
@@ -178,8 +181,8 @@
* @global array $aiki The global config object
* @return string
*/
-
- public function createForm ($form, $form_array, $record_id=""){
+ public function createForm ($form, $form_array, $record_id="")
+ {
global $db, $membership, $aiki, $config;
@@ -249,10 +252,12 @@
$form .= "<div class='$intwalker[0] field'>";
if (isset($form_data) and isset($form_data->$intwalker[0])){
- //To stop the L10n Function
- //TODO: apply such function to stop other types of aiki markup check input.php line 29
- //instead preg_matching forms
-
+ /**
+ * To stop the L10n Function
+ * @TODO: apply such function to stop other types of aiki
+ * markup check input.php line 29
+ * instead preg_matching forms
+ */
$form_data->$intwalker[0] = str_replace("_", "_", $form_data->$intwalker[0]);
}
@@ -584,8 +589,9 @@
return $form;
}
- }
+ } // end of createForm function
+
/**
* Generate a form that will insert a new record into the database.
*
@@ -596,8 +602,8 @@
* @global array $membership The global membership object
* @return string
*/
-
- public function create_insert_form(&$form, $form_array ){
+ public function create_insert_form(&$form, $form_array )
+ {
global $db, $aiki, $membership;
$formOutput = '';
@@ -615,11 +621,11 @@
$formOutput = $this->createForm ($form, $form_array);
}
-
return $formOutput;
}
+
/**
* Generate a form that will update a record in the database.
*
@@ -629,8 +635,8 @@
* @global array $aiki The global aiki object
* @return string
*/
-
- public function create_update_form(&$form, $form_array, $record_id){
+ public function create_update_form(&$form, $form_array, $record_id)
+ {
global $aiki;
$formOutput = '';
@@ -666,12 +672,11 @@
$formOutput = $this->createForm ($form, $form_array, $record_id);
}
-
return $formOutput;
-
}
+
/**
* Fills the form with the specified values.
*
@@ -681,8 +686,8 @@
* @global array $aiki The global aiki object
* @return string
*/
-
- public function fill_form($html, $sql){
+ public function fill_form($html, $sql)
+ {
global $db, $aiki;
$viewrow = $db->get_row($sql);
@@ -710,13 +715,10 @@
}
-
-
-
$get_text_areas = preg_match_all("|<textarea[^>]+>(.*)</textarea+>|Us",$html, $input_matchs );
- foreach($input_matchs[0] as $input){
-
+ foreach($input_matchs[0] as $input)
+ {
$name = $aiki->get_string_between($input, 'name="', '"');
if (in_array($name, $arraykeys)){
@@ -725,9 +727,9 @@
}
}
-
return $html;
- }
+ } // end of fill_form function
+
/**
* Generates a form automatically from a given table.
@@ -736,8 +738,8 @@
* @global array $aiki The global aiki object
* @global array $db The global database object
*/
-
- public function auto_generate($table){
+ public function auto_generate($table)
+ {
global $aiki, $db;
$table = addslashes($table);
@@ -798,7 +800,6 @@
echo "Form for db table: <b>$table</b> created successfully";
}
-
- }
-
-}
+ } // end of auto_generate function
+
+} // end of Forms class
=== modified file 'src/libs/image.php'
--- src/libs/image.php 2011-06-15 02:54:01 +0000
+++ src/libs/image.php 2011-06-19 21:37:47 +0000
@@ -21,40 +21,41 @@
/**
- * BriefDescription
+ * A utility class to manipulate images.
*
* @category Aiki
* @package Library
+ *
+ * @todo rename class to Image
*/
class image
{
-
-
/**
* Converts an svg file to png
+ *
+ * @link http://librsvg.sourceforge.net/
*
- * @param string filename with fullpath
- * @param int png width
- * @param int png height
+ * @param string $file filename with fullpath
+ * @param int $newwidth png width
+ * @param int $newheight png height
*
* @return string
*/
- public function rsvg_convert_svg_png($file, $newwidth, $newhight){
-
+ public function rsvg_convert_svg_png($file, $newwidth, $newheight)
+ {
$file = str_replace(" ", "\ ", $file);
$file = str_replace("(", "\(", $file);
$file = str_replace(")", "\)", $file);
//check if rsvg exists
exec("rsvg -v", $checkversion);
- if ($newwidth < $newhight){
- $size = $newhight;
- }else{
+ if ($newwidth < $newheight)
+ $size = $newheight;
+ else
$size = $newwidth;
- }
-
- if ($checkversion[0]){
-
+
+ if ($checkversion[0])
+ {
$filenopath = explode("/", $file);
$filenopath = array_reverse($filenopath);
@@ -64,24 +65,39 @@
$filenamepng = str_replace($filenopath[0], $fileno, $file);
-
- exec("rsvg --width $newwidth --height $newhight $file $filenamepng", $output);
-
- }else{
+ exec("rsvg --width $newwidth --height $newheight ".
+ "$file $filenamepng", $output);
+
+ } else {
+ /**
+ * @todo rip out this error, a user should never seen this.
+ */
$output = "<b>Fatal Error: </b>Can't find (rsvg)";
}
-
return $filenamepng;
}
-
- public function display_watermarked_image($fimage, $watermark_file, $minValueWaterMark){
+ /**
+ * Outputs an image with a watermark over it.
+ *
+ * @param string $fimage path to an image
+ * @param string $watermark_file path to the watermark to overlay image
+ * @param integer $minValueWaterMark
+ *
+ */
+ public function display_watermarked_image($fimage,
+ $watermark_file,
+ $minValueWaterMark)
+ {
$size = getimagesize($fimage);
- if ($minValueWaterMark and $size["0"] < $minValueWaterMark and $size["1"] < $minValueWaterMark){
-
- }else{
-
+ if ($minValueWaterMark and
+ $size["0"] < $minValueWaterMark and
+ $size["1"] < $minValueWaterMark)
+ {
+ // nothing?
+ } else
+ {
$watermark_file_size = getimagesize($watermark_file);
$watermark_width = $watermark_file_size["0"];
@@ -89,7 +105,6 @@
$watermark = imagecreatefrompng($watermark_file);
-
imagealphablending($watermark, false);
imagesavealpha($watermark, true);
@@ -98,14 +113,24 @@
$dest_x = 5;
$dest_y = $size[1] - $watermark_height - 5;
- imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
+ imagecopy($image, $watermark, $dest_x, $dest_y,
+ 0, 0, $watermark_width, $watermark_height);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
}
- }
-
-
+ } // end of display_watermarked_image function
+
+
+ /**
+ * Resizes and iamge
+ * @param string $path path to image to resize
+ * @param string $filename name of file
+ * @param integer $newvalue get maximum new size
+ * @param string $imageprefix prefix to the new image
+ *
+ * @todo should really allow one to specify new height or width
+ */
public function imageresize($path,$filename,$newvalue,$imageprefix)
{
$filename2 =$path.$filename;
@@ -113,69 +138,63 @@
$width = $size["0"];
$height = $size["1"];
$type = $size["mime"];
- if ($width < $height){
- $newhight = $newvalue;
+
+ if ($width < $height)
+ {
+ $newheight = $newvalue;
$newwidth = round(($newvalue * $width)/$height);
- }elseif ($width == $height) {
- $newhight = $newvalue;
- $newwidth = $newvalue;
- }else{
- $newwidth = $newvalue;
- $newhight = round(($newvalue * $height)/$width);
+ } elseif ($width == $height) {
+ $newheight = $newvalue;
+ $newwidth = $newvalue;
+ } else {
+ $newwidth = $newvalue;
+ $newheight = round(($newvalue * $height)/$width);
}
- if ($width < $newwidth or $height < $newhight){
- $newhight = $height;
+ if ($width < $newwidth or $height < $newheight)
+ {
+ $newheight = $height;
$newwidth = $width;
}
-
-
- switch ($type){
+ switch ($type)
+ {
case "image/jpeg":
- $thumb = imagecreatetruecolor($newwidth, $newhight);
-
+ $thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename2);
- imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newhight, $width, $height);
+ imagecopyresampled($thumb, $source, 0, 0, 0, 0,
+ $newwidth, $newheight, $width, $height);
imagejpeg($thumb,$path.$imageprefix.$filename);
-
imagedestroy($thumb);
imagedestroy($source);
break;
+
case "image/gif":
- $thumb = imagecreatetruecolor($newwidth, $newhight);
-
+ $thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromgif($filename2);
- imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newhight, $width, $height);
+ imagecopyresampled($thumb, $source, 0, 0, 0, 0,
+ $newwidth, $newheight, $width, $height);
imagegif($thumb,$path.$imageprefix.$filename);
-
imagedestroy($thumb);
imagedestroy($source);
break;
case "image/png":
-
- $thumb = imagecreatetruecolor($newwidth, $newhight);
-
+ $thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefrompng($filename2);
-
imagealphablending($source, false);
imagesavealpha($source, true);
-
imagealphablending($thumb, false);
imagesavealpha($thumb, true);
-
- imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newhight, $width, $height);
+ imagecopyresampled($thumb, $source, 0, 0, 0, 0,
+ $newwidth, $newheight, $width, $height);
imagepng($thumb,$path.$imageprefix.$filename);
-
imagedestroy($thumb);
imagedestroy($source);
break;
}
-
- }
-
-
-}
+ } // end of imageresize
+
+} // end of Image class
=== modified file 'src/libs/input.php'
--- src/libs/input.php 2011-06-15 02:54:01 +0000
+++ src/libs/input.php 2011-06-19 21:37:47 +0000
@@ -25,62 +25,91 @@
*
* @category Aiki
* @package Library
+ *
+ * @todo rename class to Input
+ * @todo consider this being part of a larger form class
+ * @todo consider separating out the validation into its own class
+ * so we can have some generic form validation handlers
*/
class input
{
- public function input(){
+ /**
+ * Handle input
+ *
+ * @global aiki $aiki global aiki instance
+ * @global CreateLayout $layout global layout instance
+ */
+ public function input()
+ {
global $aiki, $layout;
- foreach ($_GET as $key => $req){
+ foreach ($_GET as $key => $req)
+ {
$req = addslashes($req);
$_GET[$key] = $req;
}
-
- foreach ($_POST as $key => $req){
-
+ foreach ($_POST as $key => $req)
+ {
if (!is_array($req)){
$req = addslashes($req);
}
$_POST[$key] = str_replace("_", "_", $req);
- switch ($key){
-
+ switch ($key)
+ {
case "process":
$key_request = "process";
$process_type = $req;
break;
-
}
-
}
- if (isset($key_request)){
- switch ($key_request){
-
+ if (isset($key_request))
+ {
+ switch ($key_request)
+ {
case "process":
$this->form_handler($process_type, $_POST);
break;
-
}
}
- }
-
- public function validate($data){
-
- foreach ($data as $key => $req){
- if (!is_array($req)){
+ } // end of input function
+
+
+ /**
+ * Validate data
+ *
+ * @param array $data data for validation
+ * @return array
+ */
+ public function validate($data)
+ {
+ foreach ($data as $key => $req)
+ {
+ if (!is_array($req))
+ {
$req = addslashes($req);
$data[$key] = $req;
}
}
-
return $data;
}
- public function form_handler($type, $post){
+
+ /**
+ * A form handler
+ *
+ * @param string $type type of form handler
+ * @param array $post post data
+ * @global membership $membership global membership instance
+ *
+ * @todo this function does not look complete, need to investigate
+ */
+ public function form_handler($type, $post)
+ {
global $membership;
$post = $this->validate($post);
@@ -88,14 +117,19 @@
case "login":
$membership->login($post['username'], $post['password']);
break;
-
}
}
- public function requests($text){
-
+ /**
+ * Handle requests
+ *
+ * @param string $text text for handling
+ * @return string
+ */
+ public function requests($text)
+ {
$text = $this->get_handler($text);
$text = $this->post_handler($text);
@@ -103,64 +137,68 @@
}
- public function get_handler($text){
-
- if (!isset($_POST['add_to_form']) and !preg_match ("/\<form(.*)GET\[(.*)\](.*)\<\/form\>/Us", $text)){
-
+ /**
+ * A general form GET handler.
+ *
+ * @param string $text text for handling
+ * @return string
+ */
+ public function get_handler($text)
+ {
+ if (!isset($_POST['add_to_form']) and
+ !preg_match ("/\<form(.*)GET\[(.*)\](.*)\<\/form\>/Us", $text))
+ {
$get_matchs = preg_match_all('/GET\[(.*)\]/Us', $text, $gets);
- }else{
-
+ } else
+ {
$get_matchs = 0;
}
- if ($get_matchs > 0){
-
- foreach ($gets[1] as $get){
-
- if (isset($_GET["$get"])){
-
+ if ($get_matchs > 0)
+ {
+ foreach ($gets[1] as $get)
+ {
+ if (isset($_GET["$get"]))
+ {
$text = str_replace("GET[$get]", $_GET["$get"], $text);
}
-
}
-
$text = preg_replace('/GET\[(.*)\]/Us', '', $text);
-
}
-
return $text;
}
- public function post_handler($text){
-
- if (!isset($_POST['add_to_form']) and !preg_match ("/\<form(.*)POST\[(.*)\](.*)\<\/form\>/Us", $text)){
-
+ /**
+ * A general form POST handler.
+ *
+ * @param string $text text for handling
+ * @return string
+ */
+ public function post_handler($text)
+ {
+ if (!isset($_POST['add_to_form']) and
+ !preg_match ("/\<form(.*)POST\[(.*)\](.*)\<\/form\>/Us", $text))
+ {
$post_matchs = preg_match_all('/POST\[(.*)\]/Us', $text, $posts);
- }else{
+ } else {
$post_matchs = 0;
}
- if ($post_matchs > 0){
-
- foreach ($posts[1] as $post){
-
- if (isset($_POST["$post"])){
-
+ if ($post_matchs > 0)
+ {
+ foreach ($posts[1] as $post)
+ {
+ if (isset($_POST["$post"]))
+ {
$text = str_replace("POST[$post]", $_POST["$post"], $text);
}
-
}
-
$text = preg_replace('/POST\[(.*)\]/Us', '', $text);
-
}
-
-
return $text;
}
-
-}
+} // end of Input class
=== modified file 'src/libs/installer.php'
--- src/libs/installer.php 2011-06-16 02:07:53 +0000
+++ src/libs/installer.php 2011-06-19 21:37:47 +0000
@@ -15,6 +15,8 @@
* @category Aiki
* @package Library
* @filesource
+ *
+ * @todo look at modularizing the installer for maintainability
*/
if(!defined('IN_AIKI')){die('No direct script access allowed');}
=== modified file 'src/libs/membership.php'
--- src/libs/membership.php 2011-06-15 02:54:01 +0000
+++ src/libs/membership.php 2011-06-19 21:37:47 +0000
@@ -25,79 +25,124 @@
*
* @category Aiki
* @package Library
+ *
+ * @todo rename the class to Membership
*/
class membership
{
+ /**
+ * @var string permissions for auser
+ */
public $permissions;
+ /**
+ * @var string a user's fullname
+ */
public $full_name;
+ /**
+ * @var string the username of a user
+ */
public $username;
+ /**
+ * @var intege the unique id of a user
+ */
public $userid;
+ /**
+ * @var string really a number in a string for group level
+ */
public $group_level;
+ /**
+ * @var string stored session variable
+ */
public $guest_session = '';
+ /**
+ * @var string after user login, stored session variable
+ */
public $user_session = '';
- public function membership(){
+ /**
+ * Handles general session startup and setup of a guest or user/member.
+ *
+ * @global array $db global db instance
+ * @global array $config global config instance
+ */
+ public function membership()
+ {
global $db, $config;
- if (isset ($config["allow_guest_sessions"]) and $config["allow_guest_sessions"] != false){
+ if (isset ($config["allow_guest_sessions"]) and
+ $config["allow_guest_sessions"] != false)
+ {
session_start();
}elseif (@$_COOKIE["PHPSESSID"]){
session_start();
}
- if (!isset($username) and isset($_SESSION['aikiuser']))
- $username = $db->get_var("SELECT user_name FROM aiki_users_sessions where user_session='".$_SESSION['aikiuser']."'");
+ if (!isset($username) and
+ isset($_SESSION['aikiuser']))
+ {
+ $username = $db->get_var("SELECT user_name FROM aiki_users_sessions where user_session='".$_SESSION['aikiuser']."'");
+ }
- if (isset($username)){
+ if (isset($username))
+ {
$this->getUserPermissions($username);
- }else{
+ } else {
$this->group_level = '1000000000';
$this->permissions = '';
}
$time_now = time();
- if (isset ($config["allow_guest_sessions"]) and $config["allow_guest_sessions"]){
-
- if (!isset($_SESSION['aikiuser']) and !isset($_SESSION['guest'])){
-
+ if (isset ($config["allow_guest_sessions"]) and
+ $config["allow_guest_sessions"])
+ {
+ if (!isset($_SESSION['aikiuser']) and !isset($_SESSION['guest']))
+ {
$user_ip = $this->get_ip();
$_SESSION['guest'] = $this->generate_session(100);
$insert_session = $db->query("INSERT INTO aiki_users_sessions VALUES ('', '', 'guest' , '$time_now', '$time_now' , '".$_SESSION['guest']."', '1', '$user_ip', '$user_ip')");
- }else{
-
+ } else {
$update_guest = $db->query("UPDATE `aiki_users_sessions` SET `last_hit` = '$time_now' WHERE `user_session`='".$_SESSION['guest']."' LIMIT 1");
}
- }elseif(isset($_SESSION['aikiuser'])){
-
+ }elseif(isset($_SESSION['aikiuser']))
+ {
$update_guest = $db->query("UPDATE `aiki_users_sessions` SET `last_hit` = '$time_now' WHERE `user_session`='".$_SESSION['aikiuser']."' LIMIT 1");
-
}
- if (isset($config["session_timeout"])){
+ if (isset($config["session_timeout"]))
$timeout = $config["session_timeout"];
- }else{
+ else
$timeout = 7200;
- }
$last_hour = time()."-$timeout";
- $make_offline = $db->query("DELETE FROM `aiki_users_sessions` WHERE last_hit < $last_hour");
+ $make_offline = $db->query(
+ "DELETE FROM `aiki_users_sessions` WHERE last_hit < $last_hour");
- if (isset($_SESSION['aikiuser'])){
+ if (isset($_SESSION['aikiuser']))
$this->user_session = $_SESSION['aikiuser'];
- }
- if (isset($_SESSION['guest'])){
+ if (isset($_SESSION['guest']))
$this->guest_session = $_SESSION['guest'];
- }
-
- }
-
- public function login ($username, $password){
+
+ } // end of membership function
+
+
+ /**
+ * Handles the login or a user.
+ *
+ * @param string $username name of user
+ * @param string $password a user's password
+ * @global array $db a global db instance
+ * @global CreateLayout $layout a global layout instance
+ * @global array $config a global config instance
+ * @global aiki $aiki a global aiki instance
+ */
+ public function login ($username, $password)
+ {
global $db, $layout, $config, $aiki;
$password = stripslashes($password);
@@ -105,63 +150,88 @@
$time_now = time();
- if (!isset($_SESSION['aikiuser']) and !isset($_SESSION['guest']) and !isset($_COOKIE["PHPSESSID"])){
+ if (!isset($_SESSION['aikiuser']) and
+ !isset($_SESSION['guest']) and
+ !isset($_COOKIE["PHPSESSID"]))
+ {
session_start();
}
$get_user = $db->get_row("SELECT * FROM aiki_users where username='$username' and password='$password' limit 1");
- if($get_user and $get_user->username == $username and $get_user->password == $password){
-
+ if($get_user and $get_user->username == $username and
+ $get_user->password == $password)
+ {
$host_name = $_SERVER['HTTP_HOST'];
$user_ip = $this->get_ip();
- if (isset ($config["allow_guest_sessions"]) and $config["allow_guest_sessions"]){
+ if (isset ($config["allow_guest_sessions"]) and
+ $config["allow_guest_sessions"])
+ {
$_SESSION['aikiuser'] = $_SESSION['guest'];
- }else{
+ } else {
$_SESSION['aikiuser'] = $this->generate_session(100);
}
- if (isset ($config["allow_guest_sessions"]) and $config["allow_guest_sessions"]){
+ if (isset ($config["allow_guest_sessions"]) and
+ $config["allow_guest_sessions"])
+ {
$register_user = $db->query("UPDATE `aiki_users_sessions` SET `user_id`='".$get_user->userid."', `user_name` = '".$get_user->username."', `user_ip`='$user_ip' WHERE `user_session`='".$_SESSION['aikiuser']."' LIMIT 1");
- }else{
+ } else {
$register_user = $db->query("INSERT INTO aiki_users_sessions VALUES ('', '".$get_user->userid."', '".$get_user->username."' , '$time_now', '$time_now' ,'".$_SESSION['aikiuser']."', '1', '$user_ip', '$user_ip')");
}
- if ($config["allow_multiple_sessions"] == false){
+ if ($config["allow_multiple_sessions"] == false)
+ {
$delete_previous_open_sessions =$db->query("DELETE FROM `aiki_users_sessions` WHERE `user_session`!='".$_SESSION['aikiuser']."' and `user_name` = '".$get_user->username."' and `user_id`='".$get_user->userid."'");
}
-
$this->getUserPermissions($get_user->username);
$update_acces = $db->query("UPDATE `aiki_users` SET `last_login`= NOW(),`last_ip`='$user_ip', `logins_number`=`logins_number`+1 WHERE `userid`='".$get_user->userid."' LIMIT 1");
- if ($get_user->logins_number == 0){
+ if ($get_user->logins_number == 0)
+ {
$update_acces = $db->query("UPDATE `aiki_users` SET `first_login`= NOW(),`first_ip`='$user_ip' WHERE `userid`='".$get_user->userid."' LIMIT 1");
}
- } else{
+ } else {
$aiki->message->set_login_error("Wrong username or password.");
}
- }
-
- public function isUserLogged ($userid){
+ } // handle login function
+
+
+ /**
+ * Checks to see if a user is logged in.
+ *
+ * @param integer $userid id of a user
+ * @global array $db global db user
+ * @return bool
+ */
+ public function isUserLogged ($userid)
+ {
global $db;
$user_session = $db->get_var("SELECT user_id FROM aiki_users_sessions where user_session='".$_SESSION['aikiuser']."'");
- if ($user_session == $userid){
+ if ($user_session == $userid)
return true;
- }else{
+ else
return false;
- }
}
+
+ /**
+ * Get a user's permissions.
+ *
+ * @param string $user name of user
+ * @global array $db global db instance
+ */
public function getUserPermissions ($user){
global $db;
$user = addslashes($user);
$user = $db->get_row("SELECT userid, usergroup, full_name, username FROM aiki_users where username='$user'");
- if ($user->userid and $this->isUserLogged($user->userid)){
+ if ($user->userid and $this->isUserLogged($user->userid))
+ {
$group_permissions = $db->get_row("SELECT group_permissions, group_level FROM aiki_users_groups where id='".$user->usergroup."'");
$this->full_name = $user->full_name;
@@ -171,41 +241,74 @@
$this->permissions = $group_permissions->group_permissions;
- }else{
+ } else {
$this->permissions = "";
}
//unset the browser session if the session
//record was deleted from aiki_users_sessions
- if (!isset($group_permissions) or !$group_permissions){
+ if (!isset($group_permissions) or !$group_permissions)
+ {
unset($_SESSION['guest']);
unset($_SESSION['aikiuser']);
}
}
- public function get_ip(){
- if ( isset($_SERVER["REMOTE_ADDR"]) ) {
+
+ /**
+ * Attempt to get a user's ip address.
+ *
+ * @return string
+ */
+ public function get_ip()
+ {
+ if ( isset($_SERVER["REMOTE_ADDR"]) )
+ {
return $_SERVER["REMOTE_ADDR"];
- } else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ) {
+ } else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) )
+ {
return $_SERVER["HTTP_X_FORWARDED_FOR"];
- } else if ( isset($_SERVER["HTTP_CLIENT_IP"]) ) {
+ } else if ( isset($_SERVER["HTTP_CLIENT_IP"]) )
+ {
return $_SERVER["HTTP_CLIENT_IP"];
}
}
- //Generate session
- public function generate_session($strlen){
+
+ /**
+ * Generate a safer session.
+ *
+ * @param integer $strlen length of session string
+ * @return string
+ */
+ public function generate_session($strlen)
+ {
return substr(md5(uniqid(rand(),true)),1,$strlen);
}
- public function NewPassword($key){
+ /**
+ * Generate a new password.
+ *
+ * @param string $key some random key
+ * @global array $db global db instance
+ * @global aiki $aiki global aiki instance
+ * @global array $config global config instance
+ * @return string
+ *
+ * @todo good to remove the html if possible.
+ * @todo rename this function to newPassword
+ * @todo check to make sure that the returned string is being output
+ * with a message class.
+ */
+ public function NewPassword($key)
+ {
global $db, $aiki, $config;
$is_user = $db->get_var("select userid, username from aiki_users where randkey = '$key'");
- if ($is_user){
-
+ if ($is_user)
+ {
$form = '
<div id="form_container">
<form method="post" enctype="multipart/form-data" id="reset_password_form" name="reset_password_form">
@@ -230,35 +333,49 @@
</div>
';
- if (!isset($_POST['password']) and !isset($_POST['password_confirm']) and !isset($_POST['key'])){
-
+ if (!isset($_POST['password']) and
+ !isset($_POST['password_confirm']) and
+ !isset($_POST['key']))
+ {
return $form;
-
- }else{
-
- if ($_POST['password'] and $_POST['password_confirm'] and $_POST['key'] and $_POST['password_confirm'] == $_POST['password']){
-
+ } else {
+ if ($_POST['password'] and
+ $_POST['password_confirm'] and
+ $_POST['key'] and
+ $_POST['password_confirm'] == $_POST['password'])
+ {
$password = md5(md5($_POST['password']));
$update = $db->query("update aiki_users set password = '$password' where randkey = '".$_POST['key']."'");
return $aiki->message->ok("Your password has been reset. You can now log in to your account.", NULL, false);
- }else{
+ } else {
$error_message = $aiki->message->error("The two passwords do not match. Please try again.", NULL, false);
return $error_message . $form;
}
-
-
}
-
}else{
return "The key was incorrect or has expired.";
}
- }
-
- public function ResetPassword($input){
+ } // end of newPassword function
+
+
+ /**
+ * Resets a user's password and alerts them.
+ *
+ * @param string $input input string for attempting password reset
+ * @global array $db global db instance
+ * @global aiki $aiki global aiki instance
+ * @global array $config global config options instance
+ * @return string
+ *
+ * @todo really the view should be separated out from this function
+ * @todo rename this function resetPassword
+ */
+ public function ResetPassword($input)
+ {
global $db, $aiki, $config;
$vars_array = str_replace('"', '', $input);
@@ -271,34 +388,36 @@
$subject = trim($vars_array['3']);
$message = trim($vars_array['4']);
- if (!$username and !$email){
+ if (!$username and !$email)
return '';
- }
- if (!$username){
+ if (!$username)
+ {
return $aiki->message->warning('You must provide your username in order to reset your password.', NULL, false);
}
- if (!$email){
+ if (!$email)
+ {
return $aiki->message->warning('You must enter the email address you used to sign up for the account.', NULL, false);
}
-
-
$is_user = $db->get_var("select userid from aiki_users where username = '$username' and email = '$email'");
- if (!$is_user){
-
+ if (!$is_user)
+ {
$is_user = $db->get_var("select userid from aiki_users where username = '$username'");
- if (!$is_user){
-
+ if (!$is_user)
+ {
return $aiki->message->error("The user $username doesn't exist. Make sure you typed the name correctly.", NULL, false);
- }else{
-
+ } else {
return $aiki->message->error("The email address and username do not match what we have on file.", NULL, false);
}
- }else{
+ } else {
+ /**
+ * @todo emailing should be separated out into its own class
+ * and function.
+ */
$randkey = md5(uniqid(rand(),true));
$add_rand_key = $db->query("update aiki_users set randkey = '$randkey' where userid = '$is_user' limit 1");
@@ -317,14 +436,24 @@
}
-
- }
-
- public function LogOut(){
+ } // end of resetPassword function
+
+
+ /**
+ * Handle logging out a user.
+ *
+ * @global array $db a global db instance
+ * @global aiki $aiki a global aiki instance
+ * @return string
+ *
+ * @todo rename this function to logOut
+ */
+ public function LogOut()
+ {
global $db, $aiki;
- if (isset($_SESSION['aikiuser'])){
-
+ if (isset($_SESSION['aikiuser']))
+ {
$delete_session_data = $db->query("DELETE FROM aiki_users_sessions where user_session='".$_SESSION['aikiuser']."'");
unset($_SESSION['aikiuser']);
@@ -333,11 +462,12 @@
session_unset();
return $aiki->message->ok("Logged out.", NULL, false);
- }else{
+ } else {
return $aiki->message->warning("You are already logged out.", NULL, false);
}
-
- }
-
-}
+ } // end of logOut function
+
+} // end of membership class
+
+// NOTE: closing php necessary in this file
?>
_______________________________________________
Mailing list: https://launchpad.net/~aikiframework-devel
Post to : [email protected]
Unsubscribe : https://launchpad.net/~aikiframework-devel
More help : https://help.launchpad.net/ListHelp