* @brief This file contains the Photo class for image processing
*/
+use Friendica\App;
+
require_once("include/photos.php");
class Photo {
$this->image->destroy();
return;
}
- imagedestroy($this->image);
+ if (is_resource($this->image)) {
+ imagedestroy($this->image);
+ }
}
}
do {
// FIXME - implement horizantal bias for scaling as in followin GD functions
- // to allow very tall images to be constrained only horizontally.
+ // to allow very tall images to be constrained only horizontally.
$this->image->scaleImage($dest_width, $dest_height);
} while ($this->image->nextImage());
return;
}
+ // if script dies at this point check memory_limit setting in php.ini
$this->image = imagerotate($this->image,$degrees,0);
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
- public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '') {
+ public function store($uid, $cid, $rid, $filename, $album, $scale, $profile = 0, $allow_cid = '', $allow_gid = '', $deny_cid = '', $deny_gid = '', $desc = '') {
$r = q("SELECT `guid` FROM `photo` WHERE `resource-id` = '%s' AND `guid` != '' LIMIT 1",
dbesc($rid)
`allow_cid` = '%s',
`allow_gid` = '%s',
`deny_cid` = '%s',
- `deny_gid` = '%s'
+ `deny_gid` = '%s',
+ `desc` = '%s'
WHERE `id` = %d",
intval($uid),
dbesc($allow_gid),
dbesc($deny_cid),
dbesc($deny_gid),
+ dbesc($desc),
intval($x[0]['id'])
);
} else {
$r = q("INSERT INTO `photo`
- (`uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `datasize`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
- VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s')",
+ (`uid`, `contact-id`, `guid`, `resource-id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `datasize`, `data`, `scale`, `profile`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `desc`)
+ VALUES (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', '%s', '%s', '%s', '%s')",
intval($uid),
intval($cid),
dbesc($guid),
dbesc($allow_cid),
dbesc($allow_gid),
dbesc($deny_cid),
- dbesc($deny_gid)
+ dbesc($deny_gid),
+ dbesc($desc)
);
}
* @return array Returns array of the different avatar sizes
*/
function update_contact_avatar($avatar, $uid, $cid, $force = false) {
-
- $r = q("SELECT `avatar`, `photo`, `thumb`, `micro` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
+ $r = q("SELECT `avatar`, `photo`, `thumb`, `micro`, `nurl` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid));
if (!dbm::is_result($r)) {
return false;
} else {
q("UPDATE `contact` SET `avatar` = '%s', `photo` = '%s', `thumb` = '%s', `micro` = '%s', `avatar-date` = '%s' WHERE `id` = %d",
dbesc($avatar), dbesc($photos[0]), dbesc($photos[1]), dbesc($photos[2]),
dbesc(datetime_convert()), intval($cid));
+
+ // Update the public contact (contact id = 0)
+ if ($uid != 0) {
+ $pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
+ if (dbm::is_result($pcontact)) {
+ update_contact_avatar($avatar, 0, $pcontact['id'], $force);
+ }
+ }
+
return $photos;
}
}
$photo_failure = true;
}
- $photo = App::get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt();
- $thumb = App::get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt();
- $micro = App::get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt();
+ $suffix = '?ts='.time();
+
+ $photo = App::get_baseurl() . '/photo/' . $hash . '-4.' . $img->getExt() . $suffix;
+ $thumb = App::get_baseurl() . '/photo/' . $hash . '-5.' . $img->getExt() . $suffix;
+ $micro = App::get_baseurl() . '/photo/' . $hash . '-6.' . $img->getExt() . $suffix;
+
+ // Remove the cached photo
+ $a = get_app();
+ $basepath = $a->get_basepath();
+
+ if (is_dir($basepath."/photo")) {
+ $filename = $basepath.'/photo/'.$hash.'-4.'.$img->getExt();
+ if (file_exists($filename)) {
+ unlink($filename);
+ }
+ $filename = $basepath.'/photo/'.$hash.'-5.'.$img->getExt();
+ if (file_exists($filename)) {
+ unlink($filename);
+ }
+ $filename = $basepath.'/photo/'.$hash.'-6.'.$img->getExt();
+ if (file_exists($filename)) {
+ unlink($filename);
+ }
+ }
} else {
$photo_failure = true;
}
return array("width" => $dest_width, "height" => $dest_height);
}
-function store_photo($a, $uid, $imagedata = "", $url = "") {
+function store_photo(App $a, $uid, $imagedata = "", $url = "") {
$r = q("SELECT `user`.`nickname`, `user`.`page-flags`, `contact`.`id` FROM `user` INNER JOIN `contact` on `user`.`uid` = `contact`.`uid`
WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1",
intval($uid));