Page Menu
Home
Code
Search
Configure Global Search
Log In
Files
F391058
profilephoto.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
profilephoto.php
View Options
<?php
/*
* Zed
* (c) 2010, Dereckson, some rights reserved
* Released under BSD license
*
* photo class.
*
* 0.1 2010-01-03 21:00 Autogenerated by Pluton Scaffolding
* 0.2 2010-02-02 00:52 Thumbnail ImageMagick generation code
*
*/
class
ProfilePhoto
{
public
$id
;
public
$perso_id
;
public
$name
;
public
$description
;
public
$avatar
;
function
__construct
(
$id
=
''
)
{
if
(
$id
)
{
$this
->
id
=
$id
;
$this
->
load_from_database
();
}
}
//Loads the object photo (ie fill the properties) from the $_POST array
function
load_from_form
(
$readBoolean
=
true
)
{
if
(
array_key_exists
(
'perso_id'
,
$_POST
))
$this
->
perso_id
=
$_POST
[
'perso_id'
];
if
(
array_key_exists
(
'name'
,
$_POST
))
$this
->
name
=
$_POST
[
'name'
];
if
(
array_key_exists
(
'description'
,
$_POST
))
$this
->
description
=
$_POST
[
'description'
];
if
(
$readBoolean
)
{
$this
->
avatar
=
$_POST
[
'avatar'
]
?
true
:
false
;
}
}
//Loads the object photo (ie fill the properties) from the database
function
load_from_database
()
{
global
$db
;
$id
=
$db
->
sql_escape
(
$this
->
id
);
$sql
=
"SELECT * FROM "
.
TABLE_PROFILES_PHOTOS
.
" WHERE photo_id = '"
.
$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
->
perso_id
=
$row
[
'perso_id'
];
$this
->
name
=
$row
[
'photo_name'
];
$this
->
description
=
$row
[
'photo_description'
];
$this
->
avatar
=
$row
[
'photo_avatar'
];
return
true
;
}
function
promote_to_avatar
()
{
global
$db
;
$sql
=
"UPDATE "
.
TABLE_PROFILES_PHOTOS
.
" SET photo_avatar = 0 WHERE perso_id = "
.
$this
->
perso_id
;
$db
->
sql_query_express
(
$sql
);
$this
->
avatar
=
true
;
}
//Saves the object to the database
function
save_to_database
()
{
global
$db
;
//Escapes fields
$id
=
$this
->
id
?
"'"
.
$db
->
sql_escape
(
$this
->
id
)
.
"'"
:
'NULL'
;
$perso_id
=
$db
->
sql_escape
(
$this
->
perso_id
);
$name
=
$db
->
sql_escape
(
$this
->
name
);
$description
=
$db
->
sql_escape
(
$this
->
description
);
$avatar
=
$this
->
avatar
?
1
:
0
;
//Saves
$sql
=
"REPLACE INTO "
.
TABLE_PROFILES_PHOTOS
.
" (`photo_id`, `perso_id`, `photo_name`, `photo_description`, `photo_avatar`) VALUES ($id, '$perso_id', '$name', '$description', $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
=
PHOTOS_DIR
.
'/'
.
$this
->
name
;
$pic_genuine
=
PHOTOS_DIR
.
'/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
);
}
}
/*
* Generates a thumbnail using ImageMagick binary
* @return boolean true if the thumbnail command returns 0 as program exit code ; otherwise, false
*/
function
generate_thumbnail
()
{
global
$Config
;
$sourceFile
=
PHOTOS_DIR
.
DIRECTORY_SEPARATOR
.
$this
->
name
;
$thumbnailFile
=
PHOTOS_DIR
.
DIRECTORY_SEPARATOR
.
'tn'
.
DIRECTORY_SEPARATOR
.
$this
->
name
;
$command
=
$Config
[
'ImageMagick'
][
'convert'
]
.
" $sourceFile -resize 1000x80 $thumbnailFile"
;
@
system
(
$command
,
$code
);
return
(
$code
==
0
);
}
static
function
get_photos
(
$perso_id
,
$allowUnsafe
=
true
)
{
global
$db
;
$sql
=
"SELECT photo_id FROM "
.
TABLE_PROFILES_PHOTOS
.
" WHERE perso_id = "
.
$db
->
sql_escape
(
$perso_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
;
}
/*
* Gets perso avatar
* @param integer $perso_id the perso to get the avatar ID
* @param string $username the username to put in title tag
*/
static
function
get_avatar
(
$perso_id
,
$username
=
''
)
{
global
$db
;
$perso_id
=
$db
->
sql_escape
(
$perso_id
);
$sql
=
"SELECT photo_description, photo_name FROM "
.
TABLE_PROFILES_PHOTOS
.
" WHERE perso_id = '$perso_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
=
get_name
(
$perso_id
);
$description
=
$row
[
'photo_description'
]
?
"$row[photo_description] ($username's avatar)"
:
"$username's avatar"
;
$url
=
PHOTOS_URL
.
'/tn/'
.
$row
[
'photo_name'
];
return
"<img src=
\"
$url
\"
title=
\"
$username
\"
alt=
\"
$description
\"
/>"
;
}
else
{
return
null
;
}
}
}
?>
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Feb 22, 20:21 (15 h, 16 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
23248
Default Alt Text
profilephoto.php (5 KB)
Attached To
rZEDHG ZedLegacy
Event Timeline
Log In to Comment