Page MenuHomeCode

azhar_profilecomment.php
No OneTemporary

azhar_profilecomment.php

This document is not UTF8. It was detected as Shift JIS and converted to UTF8 for display.
<?php
/*
* Azh灑, faeries intranet
* (c) 2010, Wolf諍m, some rights reserved
* Released under BSD license
*
* ProfileComment class.
*
* 0.1 2010-01-03 01:02 Autogenerated by Pluton Scaffolding
*
*/
class ProfileComment {
public $id;
public $user_id;
public $author;
public $authorname; //should be read-only
public $date;
public $text;
function __construct ($id = '') {
if ($id) {
$this->id = $id;
$this->loadFromDatabase();
} else {
$this->date = time();
}
}
//Loads the object comment (ie fill the properties) from the $_POST array
function loadFromForm () {
if (array_key_exists('user_id', $_POST)) $this->user_id = $_POST['user_id'];
if (array_key_exists('author', $_POST)) $this->author = $_POST['author'];
if (array_key_exists('date', $_POST)) $this->date = $_POST['date'];
if (array_key_exists('text', $_POST)) $this->text = $_POST['text'];
}
//Loads the object comment (ie fill the properties) from the database
function loadFromDatabase () {
global $db;
$sql = "SELECT c.*, u.user_longname as author FROM " . TABLE_PROFILES_COMMENTS . " c, " . TABLE_USERS . " u WHERE c.comment_id = '" . $this->id . "' AND u.user_id = c.comment_author";
if ( !($result = $db->sql_query($sql)) ) message_die(SQL_ERROR, "Unable to query azhar_profiles_comments", '', __LINE__, __FILE__, $sql);
if (!$row = $db->sql_fetchrow($result)) {
$this->lastError = "comment unkwown: " . $this->id;
return false;
}
$this->user_id = $row['user_id'];
$this->author = $row['comment_author'];
$this->authorname = $row['author'];
$this->date = $row['comment_date'];
$this->text = $row['comment_text'];
return true;
}
//Saves the object to the database
function saveToDatabase () {
global $db;
$id = $db->sql_escape($this->id);
$user_id = $db->sql_escape($this->user_id);
$author = $db->sql_escape($this->author);
$date = $db->sql_escape($this->date);
$text = $db->sql_escape($this->text);
if ($id) {
//Updates
$sql = "REPLACE INTO " . TABLE_PROFILES_COMMENTS . " (`comment_id`, `user_id`, `comment_author`, `comment_date`, `comment_text`) VALUES ('$id', '$user_id', '$author', '$date', '$text')";
} else {
//Inserts
$sql = "INSERT INTO " . TABLE_PROFILES_COMMENTS . " (`user_id`, `comment_author`, `comment_date`, `comment_text`) VALUES ('$user_id', '$author', '$date', '$text')";
}
if (!$db->sql_query($sql)) {
message_die(SQL_ERROR, "Unable to save", '', __LINE__, __FILE__, $sql);
}
if (!$id) {
//Gets new record id value
$this->id = $db->sql_nextid();
}
}
//Publishes the comment
function publish () {
$this->saveToDatabase();
//TODO: triggers new profile comment notifier
}
static function get_comments ($user_id) {
global $db;
$sql = "SELECT comment_id FROM " . TABLE_PROFILES_COMMENTS . " WHERE user_id = " . $db->sql_escape($user_id);
if (!$result = $db->sql_query($sql)) {
message_die(SQL_ERROR, "Unable to get comments", '', __LINE__, __FILE__, $sql);
}
while ($row = $db->sql_fetchrow($result)) {
$comments[] = new ProfileComment($row[0]);
}
return $comments;
}
}
?>

File Metadata

Mime Type
text/x-php
Expires
Sat, Feb 22, 20:23 (23 h, 48 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
22754
Default Alt Text
azhar_profilecomment.php (3 KB)

Event Timeline