X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=mod%2Fphotos.php;h=a6552994e5258c9aa1ef788ae98b8251e9fb3026;hb=edc68f487607a5a7c8602a7e51ee5559acb82114;hp=082947bdbfc9c5c5f78ff597b41acffa7ce42afc;hpb=54e2c1ca81b99d4ac418e9287e00440de1fdc664;p=friendica.git diff --git a/mod/photos.php b/mod/photos.php index 082947bdbf..a6552994e5 100644 --- a/mod/photos.php +++ b/mod/photos.php @@ -5,6 +5,7 @@ require_once('include/acl_selectors.php'); require_once('include/bbcode.php'); require_once('include/security.php'); + function photos_init(&$a) { @@ -15,7 +16,7 @@ function photos_init(&$a) { if($a->argc > 1) { $nick = $a->argv[1]; - $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1", + $r = q("SELECT `user`.*, `contact`.`avatar-date` AS picdate FROM `user` LEFT JOIN `contact` on `contact`.`uid` = `user`.`uid` WHERE `user`.`nickname` = '%s' AND `user`.`blocked` = 0 LIMIT 1", dbesc($nick) ); @@ -35,7 +36,7 @@ function photos_init(&$a) { $o .= '
'; $o .= '
' . $a->data['user']['username'] . '
'; - $o .= '
' . $a->data['user']['username'] . '
'; + $o .= '
' . $a->data['user']['username'] . '
'; $o .= '
'; if(! intval($a->data['user']['hidewall'])) { @@ -105,6 +106,8 @@ function photos_post(&$a) { logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA); logger('mod_photos: FILES ' . print_r($_FILES,true), LOGGER_DATA); + $phototypes = Photo::supportedTypes(); + $can_post = false; $visitor = 0; @@ -287,6 +290,7 @@ function photos_post(&$a) { if(($a->argc > 2) && ((x($_POST,'desc') !== false) || (x($_POST,'newtag') !== false)) || (x($_POST,'albname') !== false)) { + $desc = ((x($_POST,'desc')) ? notags(trim($_POST['desc'])) : ''); $rawtags = ((x($_POST,'newtag')) ? notags(trim($_POST['newtag'])) : ''); $item_id = ((x($_POST,'item_id')) ? intval($_POST['item_id']) : 0); @@ -300,13 +304,68 @@ function photos_post(&$a) { if(! strlen($albname)) $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y'); + + + if((x($_POST,'rotate') !== false) && (intval($_POST['rotate']) == 1)) { + logger('rotate'); + + $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1", + dbesc($resource_id), + intval($page_owner_uid) + ); + if(count($r)) { + $ph = new Photo($r[0]['data'], $r[0]['type']); + if($ph->is_valid()) { + $ph->rotate(270); + + $width = $ph->getWidth(); + $height = $ph->getHeight(); + + $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0 limit 1", + dbesc($ph->imageString()), + intval($height), + intval($width), + dbesc($resource_id), + intval($page_owner_uid) + ); + + if($width > 640 || $height > 640) { + $ph->scaleImage(640); + $width = $ph->getWidth(); + $height = $ph->getHeight(); + $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1 limit 1", + dbesc($ph->imageString()), + intval($height), + intval($width), + dbesc($resource_id), + intval($page_owner_uid) + ); + } + + if($width > 320 || $height > 320) { + $ph->scaleImage(320); + $width = $ph->getWidth(); + $height = $ph->getHeight(); + + $x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2 limit 1", + dbesc($ph->imageString()), + intval($height), + intval($width), + dbesc($resource_id), + intval($page_owner_uid) + ); + } + } + } + } $p = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ORDER BY `scale` DESC", dbesc($resource_id), intval($page_owner_uid) ); if(count($p)) { + $ext = $phototypes[$p[0]['type']]; $r = q("UPDATE `photo` SET `desc` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d", dbesc($desc), dbesc($albname), @@ -331,7 +390,7 @@ function photos_post(&$a) { $title = ''; $uri = item_new_uri($a->get_hostname(),$page_owner_uid); - + $arr = array(); $arr['uid'] = $page_owner_uid; @@ -357,7 +416,7 @@ function photos_post(&$a) { $arr['origin'] = 1; $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']' - . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.jpg' . '[/img]' + . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]' . '[/url]'; $item_id = item_store($arr); @@ -526,17 +585,17 @@ function photos_post(&$a) { $arr['inform'] = $tagged[2]; $arr['origin'] = 1; $arr['body'] = '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]' . ' ' . t('was tagged in a') . ' ' . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('photo') . '[/url]' . ' ' . t('by') . ' ' . '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]' ; - $arr['body'] .= "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.jpg' . '[/img][/url]' . "\n" ; + $arr['body'] .= "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ; $arr['object'] = '' . ACTIVITY_OBJ_PERSON . '' . $tagged[0] . '' . $tagged[1] . '/' . $tagged[0] . ''; $arr['object'] .= '' . xmlify('' . "\n"); if($tagged[3]) - $arr['object'] .= xmlify('' . "\n"); + $arr['object'] .= xmlify('' . "\n"); $arr['object'] .= '' . "\n"; $arr['target'] = '' . ACTIVITY_OBJ_PHOTO . '' . $p[0]['desc'] . '' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ''; - $arr['target'] .= '' . xmlify('' . "\n" . '') . ''; + $arr['target'] .= '' . xmlify('' . "\n" . '') . ''; $item_id = item_store($arr); if($item_id) { @@ -607,7 +666,7 @@ function photos_post(&$a) { $str_group_deny = perms2str(((is_array($_REQUEST['group_deny'])) ? $_REQUEST['group_deny'] : explode(',',$_REQUEST['group_deny']))); $str_contact_deny = perms2str(((is_array($_REQUEST['contact_deny'])) ? $_REQUEST['contact_deny'] : explode(',',$_REQUEST['contact_deny']))); - $ret = array('src' => '', 'filename' => '', 'filesize' => 0); + $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => ''); call_hooks('photo_post_file',$ret); @@ -615,15 +674,17 @@ function photos_post(&$a) { $src = $ret['src']; $filename = $ret['filename']; $filesize = $ret['filesize']; + $type = $ret['type']; } else { $src = $_FILES['userfile']['tmp_name']; $filename = basename($_FILES['userfile']['name']); $filesize = intval($_FILES['userfile']['size']); + $type = $_FILES['userfile']['type']; } + if ($type=="") $type=guess_image_type($filename); - - logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ' . $filesize . ' bytes', LOGGER_DEBUG); + logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG); $maximagesize = get_config('system','maximagesize'); @@ -646,7 +707,7 @@ function photos_post(&$a) { logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG); $imagedata = @file_get_contents($src); - $ph = new Photo($imagedata); + $ph = new Photo($imagedata, $type); if(! $ph->is_valid()) { logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG); @@ -716,7 +777,7 @@ function photos_post(&$a) { $arr['origin'] = 1; $arr['body'] = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']' - . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.jpg" . '[/img]' + . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]' . '[/url]'; $item_id = item_store($arr); @@ -759,8 +820,8 @@ function photos_content(&$a) { notice( t('Public access denied.') . EOL); return; } - - + + require_once('include/bbcode.php'); require_once('include/security.php'); require_once('include/conversation.php'); @@ -770,6 +831,8 @@ function photos_content(&$a) { return; } + $phototypes = Photo::supportedTypes(); + $_SESSION['photo_return'] = $a->cmd; // @@ -936,7 +999,7 @@ function photos_content(&$a) { $a->set_pager_itemspage(20); } - $r = q("SELECT `resource-id`, `id`, `filename`, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s' + $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s' AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d", intval($owner_uid), dbesc($album), @@ -983,13 +1046,15 @@ function photos_content(&$a) { $twist = 'rotleft'; else $twist = 'rotright'; + + $ext = $phototypes[$rr['type']]; $o .= replace_macros($tpl,array( '$id' => $rr['id'], '$twist' => ' ' . $twist . rand(2,4), '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'], '$phototitle' => t('View Photo'), - '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.jpg', + '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext, '$imgalt' => template_escape($rr['filename']), '$desc'=> template_escape($rr['desc']) )); @@ -1103,9 +1168,9 @@ function photos_content(&$a) { $prevlink = array($prevlink, '') ; $photo = array( - 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg', + 'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']], 'title'=> t('View Full Size'), - 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.jpg' + 'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis') ); if($nextlink) @@ -1185,6 +1250,7 @@ function photos_content(&$a) { $edit_tpl = get_markup_template('photo_edit.tpl'); $edit = replace_macros($edit_tpl, array( '$id' => $ph[0]['id'], + '$rotate' => t('Rotate CW'), '$album' => template_escape($ph[0]['album']), '$newalbum' => t('New album name'), '$nickname' => $a->data['user']['nickname'], @@ -1393,7 +1459,7 @@ function photos_content(&$a) { $a->set_pager_itemspage(20); } - $r = q("SELECT `resource-id`, `id`, `filename`, `album`, max(`scale`) AS `scale` FROM `photo` + $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s' $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d", intval($a->data['user']['uid']), @@ -1413,13 +1479,14 @@ function photos_content(&$a) { $twist = 'rotleft'; else $twist = 'rotright'; - + $ext = $phototypes[$rr['type']]; + $photos[] = array( 'id' => $rr['id'], 'twist' => ' ' . $twist . rand(2,4), 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'], 'title' => t('View Photo'), - 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.jpg', + 'src' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext, 'alt' => template_escape($rr['filename']), 'album' => array( 'link' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),