Commit 016da889 authored by Nigel McNie's avatar Nigel McNie Committed by Nigel McNie

Set artefact to be dirty when creating (though not sure what difference

it makes...). Added is_note_private method, which says whether the
artefact needs to use the note field for its own purposes. Used by the
ProfileIcon artefact
parent e8c3448b
......@@ -55,6 +55,7 @@ class PluginArtefactInternal extends PluginArtefact {
'jabberusername',
'occupation',
'industry',
'profileicon'
);
}
......@@ -117,6 +118,18 @@ class ArtefactTypeProfile extends ArtefactType {
$this->ctime = time();
$this->atime = time();
$this->artefacttype = $type;
if (empty($id)) {
$this->dirty = true;
$this->ctime = $this->mtime = time();
if (empty($data)) {
$data = array();
}
foreach ((array)$data as $field => $value) {
if (property_exists($this, $field)) {
$this->{$field} = $value;
}
}
}
}
public function render($format, $options) {
......@@ -440,5 +453,11 @@ class ArtefactTypeJabberusername extends ArtefactTypeProfileField {}
class ArtefactTypeOccupation extends ArtefactTypeProfileField {}
class ArtefactTypeIndustry extends ArtefactTypeProfileField {}
class ArtefactTypeProfileIcon extends ArtefactTypeProfileField {
public static function is_note_private() {
return true;
}
}
?>
......@@ -27,7 +27,7 @@
defined('INTERNAL') || die();
$config = new StdClass;
$config->version = 2006112700;
$config->version = 2007010800;
$config->release = '0.1';
?>
......@@ -114,7 +114,9 @@ abstract class ArtefactType {
$this->id = $id;
}
else {
$this->ctime = time();
$this->ctime = $this->mtime = time();
$this->dirty = true;
exit;
}
if (empty($data)) {
$data = array();
......@@ -499,6 +501,13 @@ abstract class ArtefactType {
*/
public static abstract function is_singular();
/**
* Whether the 'note' field is for the artefact's private use
*/
public static function is_note_private() {
return false;
}
// ******************** HELPER FUNCTIONS ******************** //
protected function get_artefact_type() {
......
......@@ -487,5 +487,93 @@ function byteserving_send_file($filename, $mimetype, $ranges) {
}
}
/**
* Given a path under dataroot, an ID and a size, return the path to a file
* matching all criteria.
*
* If the file with the ID exists but not of the correct size, this function
* will make a copy that is resized to the correct size.
*/
function get_dataroot_image_path($path, $id, $size) {
$dataroot = get_config('dataroot');
$imagepath = $dataroot . $path;
if (!is_dir($imagepath) || !is_readable($imagepath)) {
log_debug('directory ' . $imagepath . ' is not a directory or is not readable');
return false;
}
$imagepath .= "/$id";
log_debug('directory is ' . $imagepath);
if ($size && !preg_match('/\d+x\d+/', $size)) {
log_debug('whoopsie with the size ' . $size);
throw new UserException('Invalid size for image specified');
}
// If the image is already available, return the path to it
$path = $imagepath . '/' . ($size ? "$size/" : '') . $id;
if (is_readable($path)) {
log_debug('the image is available at ' . $path);
return $path;
}
if ($size) {
// Image is not available in this size. If there is a base image for
// it, we can make one however.
$originalimage = $imagepath . "/$id";
if (is_readable($imagepath . "/$id")) {
log_debug('creating correct sized image');
list($width, $height) = explode('x', $size);
switch (get_mime_type($originalimage)) {
case 'jpg':
$ih = imagecreatefromjpeg($
$extn = strtolower(substr($filename, -3));
switch($extn) {
case 'jpg':
$old = @ImageCreateFromJPEG($view);
break;
case 'png':
$old = @ImageCreateFromPNG($view);
break;
}
if (empty($old)) {
return false;
} else {
$old_x = ImageSX($old);
$old_y = ImageSY($old);
// make new thumbnail
if ($old_y > $old_x) {
$new_y = $height; // max height of
thumb
$new_x = ($old_x * $new_y)/$old_y; // retain aspect ratio
}
else {
$new_x = $width; // max width of thumb
$new_y = ($old_y * $new_x)/$old_x; // retain aspect ratio
}
// $new = ImageCreate($new_x, $new_y);
$new = ImageCreateTrueColor($new_x, $new_y);
@ImageCopyResized($new, $old, 0, 0, 0, 0, $new_x, $new_y,
$old_x, $old_y);
}
imageInterlace($new);
touch(SGN_DIR_ROOT.$thumbname);
$result = ImagePNG($new,SGN_DIR_ROOT.$thumbname);
return $thumbname;
return '';
}
}
// Image not available in any size
log_debug('image is not available in any size');
return false;
}
?>
......@@ -28,6 +28,7 @@ define('INTERNAL', 1);
define('PUBLIC', 1);
require('init.php');
require_once('file.php');
$type = param_alpha('type');
......@@ -47,13 +48,25 @@ switch ($type) {
exit;
break;
case 'user':
if (false) { // @todo find their real profile image
}
else {
header('Content-type: ' . 'image/gif');
readfile(theme_get_image_path('images/no_userphoto40x40.gif'));
case 'profileicon':
$id = param_integer('id');
$size = param_variable('size', '');
if ($size && !preg_match('/\d+x\d+/', $size)) {
throw new UserException('Invalid size for image specified');
}
log_debug('looking for image for user, id = ' . $id . ' and size = ' . $size);
if ($path = get_dataroot_image_path('artefact/internal/profileicons', $id, $size)) {
$type = get_mime_type($path);
if ($type) {
header('Content-type: ' . $type);
readfile($path);
exit;
}
}
header('Content-type: ' . 'image/gif');
readfile(theme_get_image_path('images/no_userphoto40x40.gif'));
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment