From 041aff36b7feb4983a2cc5faed79e54863e06913 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 12 Aug 2014 21:51:32 -0700 Subject: provide a way to preserve photo timestamps when importing (rather than uploading) --- include/photo/photo_driver.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'include/photo') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index f5e915402..5fb08b814 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -287,6 +287,8 @@ abstract class photo_driver { $p['allow_gid'] = (($arr['allow_gid']) ? $arr['allow_gid'] : ''); $p['deny_cid'] = (($arr['deny_cid']) ? $arr['deny_cid'] : ''); $p['deny_gid'] = (($arr['deny_gid']) ? $arr['deny_gid'] : ''); + $p['created'] = (($arr['created']) ? $arr['created'] : datetime_convert()); + $p['edited'] = (($arr['edited']) ? $arr['edited'] : $p['created']); // temporary until we get rid of photo['profile'] and just use photo['photo_flags'] // but this will require updating all existing photos in the DB. @@ -328,8 +330,8 @@ abstract class photo_driver { intval($p['uid']), dbesc($p['xchan']), dbesc($p['resource_id']), - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc($p['created']), + dbesc($p['edited']), dbesc(basename($p['filename'])), dbesc($this->getType()), dbesc($p['album']), @@ -355,8 +357,8 @@ abstract class photo_driver { intval($p['uid']), dbesc($p['xchan']), dbesc($p['resource_id']), - dbesc(datetime_convert()), - dbesc(datetime_convert()), + dbesc($p['created']), + dbesc($p['edited']), dbesc(basename($p['filename'])), dbesc($this->getType()), dbesc($p['album']), -- cgit v1.2.3 From eb38f3f47460bfb00af3dcae815720b2970a31eb Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 13 Aug 2014 16:34:36 -0700 Subject: support title and description (and dates which were done earlier) for friendica photo import --- include/photo/photo_driver.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'include/photo') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 5fb08b814..daf1bfc25 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -289,6 +289,8 @@ abstract class photo_driver { $p['deny_gid'] = (($arr['deny_gid']) ? $arr['deny_gid'] : ''); $p['created'] = (($arr['created']) ? $arr['created'] : datetime_convert()); $p['edited'] = (($arr['edited']) ? $arr['edited'] : $p['created']); + $p['title'] = (($arr['title']) ? $arr['title'] : ''); + $p['description'] = (($arr['description']) ? $arr['description'] : ''); // temporary until we get rid of photo['profile'] and just use photo['photo_flags'] // but this will require updating all existing photos in the DB. @@ -320,6 +322,8 @@ abstract class photo_driver { `scale` = %d, `profile` = %d, `photo_flags` = %d, + `title` = '%s', + `description` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', @@ -342,6 +346,8 @@ abstract class photo_driver { intval($p['scale']), intval($p['profile']), intval($p['photo_flags']), + dbesc($p['title']), + dbesc($p['description']), dbesc($p['allow_cid']), dbesc($p['allow_gid']), dbesc($p['deny_cid']), @@ -351,8 +357,8 @@ abstract class photo_driver { } else { $r = q("INSERT INTO `photo` - ( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `profile`, `photo_flags`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) - VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s' )", + ( `aid`, `uid`, `xchan`, `resource_id`, `created`, `edited`, `filename`, type, `album`, `height`, `width`, `data`, `size`, `scale`, `profile`, `photo_flags`, `title`, `description`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid` ) + VALUES ( %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s' )", intval($p['aid']), intval($p['uid']), dbesc($p['xchan']), @@ -369,6 +375,8 @@ abstract class photo_driver { intval($p['scale']), intval($p['profile']), intval($p['photo_flags']), + dbesc($p['title']), + dbesc($p['description']), dbesc($p['allow_cid']), dbesc($p['allow_gid']), dbesc($p['deny_cid']), -- cgit v1.2.3 From 5547222da236c29fcb7bf6e3b6d8ed7421e1c57f Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 11 Sep 2014 15:50:35 -0700 Subject: add gif to supported image types (if it's supported) --- include/photo/photo_gd.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/photo') diff --git a/include/photo/photo_gd.php b/include/photo/photo_gd.php index 466f8c23a..fa1f700e9 100644 --- a/include/photo/photo_gd.php +++ b/include/photo/photo_gd.php @@ -10,7 +10,7 @@ class photo_gd extends photo_driver { $t = array(); $t['image/jpeg'] ='jpg'; if (imagetypes() & IMG_PNG) $t['image/png'] = 'png'; - + if (imagetypes() & IMG_GIF) $t['image/gif'] = 'gif'; return $t; } -- cgit v1.2.3 From a17eae941b2c3a7fa76b84a3ef10a0f8d4be6038 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Sun, 5 Oct 2014 21:38:47 +0000 Subject: image/jpeg > image/png --- include/photo/photo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/photo') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index daf1bfc25..d9777b1c4 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -623,7 +623,7 @@ function import_profile_photo($photo,$xchan,$thing = false) { $photo = $a->get_baseurl() . '/' . get_default_profile_photo(); $thumb = $a->get_baseurl() . '/' . get_default_profile_photo(80); $micro = $a->get_baseurl() . '/' . get_default_profile_photo(48); - $type = 'image/jpeg'; + $type = 'image/png'; } return(array($photo,$thumb,$micro,$type,$photo_failure)); -- cgit v1.2.3 From 60a89670f64c372122a154b0e5b601fed7d6bcbd Mon Sep 17 00:00:00 2001 From: nostupidzone Date: Tue, 7 Oct 2014 09:54:27 -0700 Subject: add ability to skip broken imagemagick on shared hosting --- include/photo/photo_driver.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'include/photo') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index d9777b1c4..e8afac119 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -2,8 +2,9 @@ function photo_factory($data, $type = null) { $ph = null; - - if(class_exists('Imagick')) { + $ignore_imagick = get_config('system', 'ignore_imagick'); + if(class_exists('Imagick') && !$ignore_imagick) { + logger('photo_factory: using Imagick', LOGGER_DEBUG); require_once('include/photo/photo_imagick.php'); $ph = new photo_imagick($data,$type); } @@ -480,11 +481,11 @@ abstract class photo_driver { * Guess image mimetype from filename or from Content-Type header * * @arg $filename string Image filename - * @arg $fromcurl boolean Check Content-Type header from curl request + * @arg $headers string Headers to check for Content-Type (from curl request) */ function guess_image_type($filename, $headers = '') { - logger('Photo: guess_image_type: '.$filename . ($fromcurl?' from curl headers':''), LOGGER_DEBUG); + logger('Photo: guess_image_type: '.$filename . ($headers?' from curl headers':''), LOGGER_DEBUG); $type = null; if ($headers) { $a = get_app(); @@ -494,13 +495,16 @@ function guess_image_type($filename, $headers = '') { list($k,$v) = array_map("trim", explode(":", trim($l), 2)); $hdrs[$k] = $v; } + logger('Curl headers: '.var_export($hdrs, true), LOGGER_DEBUG); if (array_key_exists('Content-Type', $hdrs)) $type = $hdrs['Content-Type']; } if (is_null($type)){ // FIXME!!!! + $ignore_imagick = get_config('system', 'ignore_imagick'); // Guessing from extension? Isn't that... dangerous? - if(class_exists('Imagick') && file_exists($filename) && is_readable($filename)) { + if(class_exists('Imagick') && !$ignore_imagick) { + logger('using imagemagick', LOGGER_DEBUG); /** * Well, this not much better, * but at least it comes from the data inside the image, @@ -552,7 +556,7 @@ function import_profile_photo($photo,$xchan,$thing = false) { if($photo) { $filename = basename($photo); - $type = guess_image_type($photo,true); + $type = guess_image_type($photo); if(! $type) $type = 'image/jpeg'; -- cgit v1.2.3 From 14d538c79329a7b6e4e8797977629672f7c47f28 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 7 Oct 2014 15:14:06 -0700 Subject: check the imagick version before using it. --- include/photo/photo_driver.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'include/photo') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index e8afac119..42997060b 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -2,13 +2,25 @@ function photo_factory($data, $type = null) { $ph = null; + $ignore_imagick = get_config('system', 'ignore_imagick'); + if(class_exists('Imagick') && !$ignore_imagick) { - logger('photo_factory: using Imagick', LOGGER_DEBUG); - require_once('include/photo/photo_imagick.php'); - $ph = new photo_imagick($data,$type); + $v = Imagick::getVersion(); + preg_match('/ImageMagick ([0-9]+\.[0-9]+\.[0-9]+)/', $v['versionString'], $m); + if(version_compare($m[1],'6.6.7') >= 0) { + require_once('include/photo/photo_imagick.php'); + $ph = new photo_imagick($data,$type); + } + else { + // earlier imagick versions have issues with scaling png's + // don't log this because it will just fill the logfile. + // leave this note here so those who are looking for why + // we aren't using imagick can find it + } } - else { + + if(! $ph) { require_once('include/photo/photo_gd.php'); $ph = new photo_gd($data,$type); } -- cgit v1.2.3 From ee6c53c2e54619a39e16ac2176835adea3b73778 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 7 Oct 2014 21:16:30 -0700 Subject: add imagick version check when guessing mimetype. It probably isn't important here, but let's make sure we have the right driver installed if we do something else with photos afterward. --- include/photo/photo_driver.php | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'include/photo') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 42997060b..c416c0df3 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -512,19 +512,30 @@ function guess_image_type($filename, $headers = '') { $type = $hdrs['Content-Type']; } if (is_null($type)){ -// FIXME!!!! + $ignore_imagick = get_config('system', 'ignore_imagick'); // Guessing from extension? Isn't that... dangerous? if(class_exists('Imagick') && !$ignore_imagick) { - logger('using imagemagick', LOGGER_DEBUG); - /** - * Well, this not much better, - * but at least it comes from the data inside the image, - * we won't be tricked by a manipulated extension - */ - $image = new Imagick($filename); - $type = $image->getImageMimeType(); - } else { + $v = Imagick::getVersion(); + preg_match('/ImageMagick ([0-9]+\.[0-9]+\.[0-9]+)/', $v['versionString'], $m); + if(version_compare($m[1],'6.6.7') >= 0) { + /** + * Well, this not much better, + * but at least it comes from the data inside the image, + * we won't be tricked by a manipulated extension + */ + $image = new Imagick($filename); + $type = $image->getImageMimeType(); + } + else { + // earlier imagick versions have issues with scaling png's + // don't log this because it will just fill the logfile. + // leave this note here so those who are looking for why + // we aren't using imagick can find it + } + } + + if(is_null($type)) { $ext = pathinfo($filename, PATHINFO_EXTENSION); $ph = photo_factory(''); $types = $ph->supportedTypes(); -- cgit v1.2.3 From f84453497bd5ef4eba8bca84917b8e82d784937a Mon Sep 17 00:00:00 2001 From: habeascodice Date: Tue, 7 Oct 2014 22:34:30 -0700 Subject: x --- include/photo/photo_driver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'include/photo') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 42997060b..15eac5a6d 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -8,6 +8,7 @@ function photo_factory($data, $type = null) { if(class_exists('Imagick') && !$ignore_imagick) { $v = Imagick::getVersion(); preg_match('/ImageMagick ([0-9]+\.[0-9]+\.[0-9]+)/', $v['versionString'], $m); + logger('image v='.$v.',v[ver]='.$v['versionString'].',matches='.var_export($m, true), LOGGER_DEBUG); if(version_compare($m[1],'6.6.7') >= 0) { require_once('include/photo/photo_imagick.php'); $ph = new photo_imagick($data,$type); -- cgit v1.2.3 From 9d5129de34b0c7877cbb4b84551e75c0aa95117a Mon Sep 17 00:00:00 2001 From: nostupidzone Date: Tue, 7 Oct 2014 23:59:26 -0700 Subject: put back local file check so body is fetched from z_ functions --- include/photo/photo_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/photo') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index c416c0df3..508d82957 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -515,7 +515,7 @@ function guess_image_type($filename, $headers = '') { $ignore_imagick = get_config('system', 'ignore_imagick'); // Guessing from extension? Isn't that... dangerous? - if(class_exists('Imagick') && !$ignore_imagick) { + if(class_exists('Imagick') && file_exists($filename) && is_readable($filename) && !$ignore_imagick) { $v = Imagick::getVersion(); preg_match('/ImageMagick ([0-9]+\.[0-9]+\.[0-9]+)/', $v['versionString'], $m); if(version_compare($m[1],'6.6.7') >= 0) { -- cgit v1.2.3 From c854f8c238da2df08b52249142ad24ef66e422d1 Mon Sep 17 00:00:00 2001 From: habeascodice Date: Sat, 11 Oct 2014 05:44:31 -0700 Subject: Revert "x" This reverts commit f84453497bd5ef4eba8bca84917b8e82d784937a. --- include/photo/photo_driver.php | 1 - 1 file changed, 1 deletion(-) (limited to 'include/photo') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 9cd05e26e..508d82957 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -8,7 +8,6 @@ function photo_factory($data, $type = null) { if(class_exists('Imagick') && !$ignore_imagick) { $v = Imagick::getVersion(); preg_match('/ImageMagick ([0-9]+\.[0-9]+\.[0-9]+)/', $v['versionString'], $m); - logger('image v='.$v.',v[ver]='.$v['versionString'].',matches='.var_export($m, true), LOGGER_DEBUG); if(version_compare($m[1],'6.6.7') >= 0) { require_once('include/photo/photo_imagick.php'); $ph = new photo_imagick($data,$type); -- cgit v1.2.3 From 1a5a5c7edb8697c93f8bababbafa80245378dd7e Mon Sep 17 00:00:00 2001 From: Habeas Codice Date: Thu, 13 Nov 2014 12:21:58 -0800 Subject: PostgreSQL support initial commit There were 11 main types of changes: - UPDATE's and DELETE's sometimes had LIMIT 1 at the end of them. This is not only non-compliant but it would certainly not do what whoever wrote it thought it would. It is likely this mistake was just copied from Friendica. All of these instances, the LIMIT 1 was simply removed. - Bitwise operations (and even some non-zero int checks) erroneously rely on MySQL implicit integer-boolean conversion in the WHERE clauses. This is non-compliant (and bad programming practice to boot). Proper explicit boolean conversions were added. New queries should use proper conventions. - MySQL has a different operator for bitwise XOR than postgres. Rather than add yet another dba_ func, I converted them to "& ~" ("AND NOT") when turning off, and "|" ("OR") when turning on. There were no true toggles (XOR). New queries should refrain from using XOR when not necessary. - There are several fields which the schema has marked as NOT NULL, but the inserts don't specify them. The reason this works is because mysql totally ignores the constraint and adds an empty text default automatically. Again, non-compliant, obviously. In these cases a default of empty text was added. - Several statements rely on a non-standard MySQL feature (http://dev.mysql.com/doc/refman/5.5/en/group-by-handling.html). These queries can all be rewritten to be standards compliant. Interestingly enough, the newly rewritten standards compliant queries run a zillion times faster, even on MySQL. - A couple of function/operator name translations were needed (RAND/RANDOM, GROUP_CONCAT/STRING_AGG, UTC_NOW, REGEXP/~, ^/#) -- assist functions added in the dba_ - INTERVALs: postgres requires quotes around the value, mysql requires that there are not quotes around the value -- assist functions added in the dba_ - NULL_DATE's -- Postgres does not allow the invalid date '0000-00-00 00:00:00' (there is no such thing as year 0 or month 0 or day 0). We use '0001-01-01 00:00:00' for postgres. Conversions are handled in Zot/item packets automagically by quoting all dates with dbescdate(). - char(##) specifications in the schema creates fields with blank spaces that aren't trimmed in the code. MySQL apparently treats char(##) as varchar(##), again, non-compliant. Since postgres works better with text fields anyway, this ball of bugs was simply side-stepped by using 'text' datatype for all text fields in the postgres schema. varchar was used in a couple of places where it actually seemed appropriate (size constraint), but without rigorously vetting that all of the PHP code actually validates data, new bugs might come out from under the rug. - postgres doesn't store nul bytes and a few other non-printables in text fields, even when quoted. bytea fields were used when storing binary data (photo.data, attach.data). A new dbescbin() function was added to handle this transparently. - postgres does not support LIMIT #,# syntax. All databases support LIMIT # OFFSET # syntax. Statements were updated to be standard. These changes require corresponding changes in the coding standards. Please review those before adding any code going forward. Still on my TODO list: - remove quotes from non-reserved identifiers and make reserved identifiers use dba func for quoting - Rewrite search queries for better results (both MySQL and Postgres) --- include/photo/photo_driver.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'include/photo') diff --git a/include/photo/photo_driver.php b/include/photo/photo_driver.php index 508d82957..e63125671 100644 --- a/include/photo/photo_driver.php +++ b/include/photo/photo_driver.php @@ -341,7 +341,7 @@ abstract class photo_driver { `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' - where id = %d limit 1", + where id = %d", intval($p['aid']), intval($p['uid']), @@ -354,7 +354,7 @@ abstract class photo_driver { dbesc($p['album']), intval($this->getHeight()), intval($this->getWidth()), - dbesc($this->imageString()), + dbescbin($this->imageString()), intval(strlen($this->imageString())), intval($p['scale']), intval($p['profile']), @@ -383,7 +383,7 @@ abstract class photo_driver { dbesc($p['album']), intval($this->getHeight()), intval($this->getWidth()), - dbesc($this->imageString()), + dbescbin($this->imageString()), intval(strlen($this->imageString())), intval($p['scale']), intval($p['profile']), @@ -428,7 +428,7 @@ abstract class photo_driver { `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' - where id = %d limit 1", + where id = %d", intval($aid), intval($uid), @@ -441,7 +441,7 @@ abstract class photo_driver { dbesc($album), intval($this->getHeight()), intval($this->getWidth()), - dbesc($this->imageString()), + dbescbin($this->imageString()), intval(strlen($this->imageString())), intval($scale), intval($profile), @@ -467,7 +467,7 @@ abstract class photo_driver { dbesc($album), intval($this->getHeight()), intval($this->getWidth()), - dbesc($this->imageString()), + dbescbin($this->imageString()), intval(strlen($this->imageString())), intval($scale), intval($profile), @@ -562,7 +562,7 @@ function import_profile_photo($photo,$xchan,$thing = false) { if($thing) $hash = photo_new_resource(); else { - $r = q("select resource_id from photo where xchan = '%s' and (photo_flags & %d ) and scale = 4 limit 1", + $r = q("select resource_id from photo where xchan = '%s' and (photo_flags & %d )>0 and scale = 4 limit 1", dbesc($xchan), intval(PHOTO_XCHAN) ); -- cgit v1.2.3