X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2FPhoto.php;h=1ed90bbf831ae50b8a815e80fc50c5b05890eeef;hb=3b2cd854837e5df38f75f323aab24e31098812d4;hp=5c3a52ffd5a0ef91ddfe17257bc0d49f781c93e7;hpb=181947f774c878f806a72de391fbab7fb5b273f5;p=friendica.git diff --git a/include/Photo.php b/include/Photo.php index 5c3a52ffd5..1ed90bbf83 100644 --- a/include/Photo.php +++ b/include/Photo.php @@ -5,6 +5,9 @@ */ use Friendica\App; +use Friendica\Core\Config; +use Friendica\Core\System; +use Friendica\Database\DBM; require_once("include/photos.php"); @@ -25,7 +28,7 @@ class Photo { /** * @brief supported mimetypes and corresponding file extensions */ - static function supportedTypes() { + public static function supportedTypes() { if (class_exists('Imagick')) { // Imagick::queryFormats won't help us a lot there... @@ -48,7 +51,7 @@ class Photo { public function __construct($data, $type=null) { $this->imagick = class_exists('Imagick'); - $this->types = $this->supportedTypes(); + $this->types = static::supportedTypes(); if (!array_key_exists($type, $this->types)){ $type='image/jpeg'; } @@ -118,7 +121,7 @@ class Photo { */ switch($this->getType()){ case "image/png": - $quality = get_config('system', 'png_quality'); + $quality = Config::get('system', 'png_quality'); if ((! $quality) || ($quality > 9)) { $quality = PNG_QUALITY; } @@ -134,7 +137,7 @@ class Photo { $this->image->setCompressionQuality($quality); break; case "image/jpeg": - $quality = get_config('system', 'jpeg_quality'); + $quality = Config::get('system', 'jpeg_quality'); if ((! $quality) || ($quality > 100)) { $quality = JPEG_QUALITY; } @@ -604,14 +607,14 @@ class Photo { switch($this->getType()){ case "image/png": - $quality = get_config('system', 'png_quality'); + $quality = Config::get('system', 'png_quality'); if ((!$quality) || ($quality > 9)) { $quality = PNG_QUALITY; } imagepng($this->image, null, $quality); break; case "image/jpeg": - $quality = get_config('system', 'jpeg_quality'); + $quality = Config::get('system', 'jpeg_quality'); if ((!$quality) || ($quality > 100)) { $quality = JPEG_QUALITY; } @@ -627,92 +630,24 @@ class Photo { 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) - ); - if (dbm::is_result($r)) { - $guid = $r[0]['guid']; + $r = dba::select('photo', array('guid'), array("`resource-id` = ? AND `guid` != ?", $rid, ''), array('limit' => 1)); + if (DBM::is_result($r)) { + $guid = $r['guid']; } else { $guid = get_guid(); } - $x = q("SELECT `id` FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `contact-id` = %d AND `scale` = %d LIMIT 1", - dbesc($rid), - intval($uid), - intval($cid), - intval($scale) - ); - if (dbm::is_result($x)) { - $r = q("UPDATE `photo` - SET `uid` = %d, - `contact-id` = %d, - `guid` = '%s', - `resource-id` = '%s', - `created` = '%s', - `edited` = '%s', - `filename` = '%s', - `type` = '%s', - `album` = '%s', - `height` = %d, - `width` = %d, - `datasize` = %d, - `data` = '%s', - `scale` = %d, - `profile` = %d, - `allow_cid` = '%s', - `allow_gid` = '%s', - `deny_cid` = '%s', - `deny_gid` = '%s', - `desc` = '%s' - WHERE `id` = %d", - - intval($uid), - intval($cid), - dbesc($guid), - dbesc($rid), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(basename($filename)), - dbesc($this->getType()), - dbesc($album), - intval($this->getHeight()), - intval($this->getWidth()), - dbesc(strlen($this->imageString())), - dbesc($this->imageString()), - intval($scale), - intval($profile), - dbesc($allow_cid), - dbesc($allow_gid), - dbesc($deny_cid), - dbesc($deny_gid), - dbesc($desc), - intval($x[0]['id']) - ); + $x = dba::select('photo', array('id'), array('resource-id' => $rid, 'uid' => $uid, 'contact-id' => $cid, 'scale' => $scale), array('limit' => 1)); + + $fields = array('uid' => $uid, 'contact-id' => $cid, 'guid' => $guid, 'resource-id' => $rid, 'created' => datetime_convert(), 'edited' => datetime_convert(), + 'filename' => basename($filename), 'type' => $this->getType(), 'album' => $album, 'height' => $this->getHeight(), 'width' => $this->getWidth(), + 'datasize' => strlen($this->imageString()), 'data' => $this->imageString(), 'scale' => $scale, 'profile' => $profile, + 'allow_cid' => $allow_cid, 'allow_gid' => $allow_gid, 'deny_cid' => $deny_cid, 'deny_gid' => $deny_gid, 'desc' => $desc); + + if (DBM::is_result($x)) { + $r = dba::update('photo', $fields, array('id' => $x['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`, `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($rid), - dbesc(datetime_convert()), - dbesc(datetime_convert()), - dbesc(basename($filename)), - dbesc($this->getType()), - dbesc($album), - intval($this->getHeight()), - intval($this->getWidth()), - dbesc(strlen($this->imageString())), - dbesc($this->imageString()), - intval($scale), - intval($profile), - dbesc($allow_cid), - dbesc($allow_gid), - dbesc($deny_cid), - dbesc($deny_gid), - dbesc($desc) - ); + $r = dba::insert('photo', $fields); } return $r; @@ -779,7 +714,7 @@ function guess_image_type($filename, $fromcurl=false) { */ function update_contact_avatar($avatar, $uid, $cid, $force = false) { $r = q("SELECT `avatar`, `photo`, `thumb`, `micro`, `nurl` FROM `contact` WHERE `id` = %d LIMIT 1", intval($cid)); - if (!dbm::is_result($r)) { + if (!DBM::is_result($r)) { return false; } else { $data = array($r[0]["photo"], $r[0]["thumb"], $r[0]["micro"]); @@ -796,7 +731,7 @@ function update_contact_avatar($avatar, $uid, $cid, $force = false) { // 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)) { + if (DBM::is_result($pcontact)) { update_contact_avatar($avatar, 0, $pcontact['id'], $force); } } @@ -814,7 +749,7 @@ function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) { intval($uid), intval($cid) ); - if (dbm::is_result($r) && strlen($r[0]['resource-id'])) { + if (DBM::is_result($r) && strlen($r[0]['resource-id'])) { $hash = $r[0]['resource-id']; } else { $hash = photo_new_resource(); @@ -857,9 +792,9 @@ function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) { $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; + $photo = System::baseUrl() . '/photo/' . $hash . '-4.' . $img->getExt() . $suffix; + $thumb = System::baseUrl() . '/photo/' . $hash . '-5.' . $img->getExt() . $suffix; + $micro = System::baseUrl() . '/photo/' . $hash . '-6.' . $img->getExt() . $suffix; // Remove the cached photo $a = get_app(); @@ -888,9 +823,9 @@ function import_profile_photo($photo, $uid, $cid, $quit_on_error = false) { } if ($photo_failure) { - $photo = App::get_baseurl() . '/images/person-175.jpg'; - $thumb = App::get_baseurl() . '/images/person-80.jpg'; - $micro = App::get_baseurl() . '/images/person-48.jpg'; + $photo = System::baseUrl() . '/images/person-175.jpg'; + $thumb = System::baseUrl() . '/images/person-80.jpg'; + $micro = System::baseUrl() . '/images/person-48.jpg'; } return(array($photo,$thumb,$micro)); @@ -985,7 +920,7 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") { WHERE `user`.`uid` = %d AND `user`.`blocked` = 0 AND `contact`.`self` = 1 LIMIT 1", intval($uid)); - if (!dbm::is_result($r)) { + if (!DBM::is_result($r)) { logger("Can't detect user data for uid ".$uid, LOGGER_DEBUG); return(array()); } @@ -1007,26 +942,13 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") { $a->save_timestamp($stamp1, "file"); } - $maximagesize = get_config('system', 'maximagesize'); + $maximagesize = Config::get('system', 'maximagesize'); if (($maximagesize) && (strlen($imagedata) > $maximagesize)) { logger("Image exceeds size limit of ".$maximagesize, LOGGER_DEBUG); return(array()); } -/* - $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", - intval($uid) - ); - - $limit = service_class_fetch($uid,'photo_upload_limit'); - - if (($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) { - logger("Image exceeds personal limit of uid ".$uid, LOGGER_DEBUG); - return(array()); - } -*/ - $tempfile = tempnam(get_temppath(), "cache"); $stamp1 = microtime(true); @@ -1052,7 +974,7 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") { $ph->orient($tempfile); unlink($tempfile); - $max_length = get_config('system', 'max_image_length'); + $max_length = Config::get('system', 'max_image_length'); if (! $max_length) { $max_length = MAX_IMAGE_LENGTH; } @@ -1079,18 +1001,18 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") { return(array()); } - $image = array("page" => App::get_baseurl().'/photos/'.$page_owner_nick.'/image/'.$hash, - "full" => App::get_baseurl()."/photo/{$hash}-0.".$ph->getExt()); + $image = array("page" => System::baseUrl().'/photos/'.$page_owner_nick.'/image/'.$hash, + "full" => System::baseUrl()."/photo/{$hash}-0.".$ph->getExt()); if ($width > 800 || $height > 800) { - $image["large"] = App::get_baseurl()."/photo/{$hash}-0.".$ph->getExt(); + $image["large"] = System::baseUrl()."/photo/{$hash}-0.".$ph->getExt(); } if ($width > 640 || $height > 640) { $ph->scaleImage(640); $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 1, 0, $defperm); if ($r) { - $image["medium"] = App::get_baseurl()."/photo/{$hash}-1.".$ph->getExt(); + $image["medium"] = System::baseUrl()."/photo/{$hash}-1.".$ph->getExt(); } } @@ -1098,7 +1020,7 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") { $ph->scaleImage(320); $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 2, 0, $defperm); if ($r) { - $image["small"] = App::get_baseurl()."/photo/{$hash}-2.".$ph->getExt(); + $image["small"] = System::baseUrl()."/photo/{$hash}-2.".$ph->getExt(); } } @@ -1123,7 +1045,7 @@ function store_photo(App $a, $uid, $imagedata = "", $url = "") { $r = $ph->store($uid, $visitor, $hash, $tempfile, t('Wall Photos'), 3, 0, $defperm); if ($r) { - $image["thumb"] = App::get_baseurl()."/photo/{$hash}-3.".$ph->getExt(); + $image["thumb"] = System::baseUrl()."/photo/{$hash}-3.".$ph->getExt(); } }