Page MenuHomeCode

azhar_profilephoto.php
No OneTemporary

azhar_profilephoto.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
*
* photo class.
*
* 0.1 2010-01-03 21:00 Autogenerated by Pluton Scaffolding
*
*/
class ProfilePhoto {
public $id;
public $user_id;
public $name;
public $description;
public $safe;
public $avatar;
function __construct ($id = '') {
if ($id) {
$this->id = $id;
$this->loadFromDatabase();
}
}
//Loads the object photo (ie fill the properties) from the $_POST array
function loadFromForm ($readBoolean = true) {
if (array_key_exists('user_id', $_POST)) $this->user_id = $_POST['user_id'];
if (array_key_exists('name', $_POST)) $this->name = $_POST['name'];
if (array_key_exists('description', $_POST)) $this->description = $_POST['description'];
if ($readBoolean) {
$this->safe = $_POST['safe'] ? true : false;
$this->avatar = $_POST['avatar'] ? true : false;
}
}
//Loads the object photo (ie fill the properties) from the database
function loadFromDatabase () {
global $db;
$sql = "SELECT * FROM azhar_profiles_photos WHERE photo_id = '" . $this->id . "'";
if ( !($result = $db->sql_query($sql)) ) message_die(SQL_ERROR, "Unable to query azhar_profiles_photos", '', __LINE__, __FILE__, $sql);
if (!$row = $db->sql_fetchrow($result)) {
$this->lastError = "photo unkwown: " . $this->id;
return false;
}
$this->user_id = $row['user_id'];
$this->name = $row['photo_name'];
$this->description = $row['photo_description'];
$this->safe = $row['photo_safe'];
$this->avatar = $row['photo_avatar'];
return true;
}
function promoteToAvatar () {
global $db;
$sql = "UPDATE " . TABLE_PROFILES_PHOTOS . " SET photo_avatar = 0 WHERE user_id = " . $this->user_id;
$db->sql_query_express($sql);
$this->avatar = 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);
$name = $db->sql_escape($this->name);
$description = $db->sql_escape($this->description);
$safe = $this->safe ? 1 : 0;
$avatar = $this->avatar ? 1 : 0;
if ($id) {
//Updates
$sql = "REPLACE INTO " . TABLE_PROFILES_PHOTOS . " (`photo_id`, `user_id`, `photo_name`, `photo_description`, `photo_safe`, `photo_avatar`) VALUES ('$id', '$user_id', '$name', '$description', $safe, $avatar)";
} else {
//Inserts
$sql = "INSERT INTO " . TABLE_PROFILES_PHOTOS . " (`user_id`, `photo_name`, `photo_description`, `photo_safe`, `photo_avatar`) VALUES ('$user_id', '$name', '$description', $safe, $avatar)";
}
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();
}
}
function delete () {
global $db;
//Deletes from disk
$pic_tn = DIR_PHOTOS . '/' . $this->name;
$pic_genuine = DIR_PHOTOS . '/tn/' . $this->name;
unlink($pic_tn);
unlink($pic_genuine);
//Deletes from database
$id = $db->sql_escape($this->id);
$sql = "DELETE FROM " . TABLE_PROFILES_PHOTOS . " WHERE photo_id = '$id' LIMIT 1";
if (!$db->sql_query($sql)) {
message_die(SQL_ERROR, "Can't delete photo", '', __LINE__, __FILE__, $sql);
}
}
static function get_photos ($user_id, $allowUnsafe = true) {
global $db;
$sql = "SELECT photo_id FROM " . TABLE_PROFILES_PHOTOS . " WHERE user_id = " . $db->sql_escape($user_id);
if (!$allowUnsafe) $sql .= " AND photo_safe = 0";
if (!$result = $db->sql_query($sql)) {
message_die(SQL_ERROR, "Unable to get photos", '', __LINE__, __FILE__, $sql);
}
while ($row = $db->sql_fetchrow($result)) {
$photos[] = new ProfilePhoto($row[0]);
}
return $photos;
}
/*
*
*
*/
static function get_avatar ($user_id, $username = '') {
global $db;
$user_id = $db->sql_escape($user_id);
$sql = "SELECT photo_description, photo_name FROM " . TABLE_PROFILES_PHOTOS . " WHERE user_id = '$user_id' and photo_avatar = 1";
if (!$result = $db->sql_query($sql)) {
message_die(SQL_ERROR, "Unable to get avatar", '', __LINE__, __FILE__, $sql);
}
if ($row = $db->sql_fetchrow($result)) {
if (!$username) $username = getname($user_id);
$description = $row['photo_description'] ? "$row[photo_description] ($username's avatar)" : "$username's avatar";
$url = '/' . DIR_PHOTOS . '/tn/' . $row['photo_name'];
return "<img src=\"$url\" title=\"$username\" alt=\"$description\" />";
} else {
return null;
}
}
}
?>

File Metadata

Mime Type
text/x-php
Expires
Sat, Feb 22, 20:21 (15 h, 51 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
24466
Default Alt Text
azhar_profilephoto.php (5 KB)

Event Timeline