]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Merge branch 'master', remote-tracking branch 'remotes/upstream/master'
[friendica.git] / mod / photos.php
index 12225b5c5a183c5169d0f32d415a003a92a7cde9..3ce6f9934d27f8d4eb2d5d002ecf87a6b276f953 100644 (file)
@@ -38,20 +38,25 @@ function photos_init(&$a) {
                        $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg" alt="' . $a->data['user']['username'] . '" /></div>';
                        $o .= '</div>';
                        
-                       $o .= '<div id="side-bar-photos-albums" class="widget">';
-                       $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
+                       if(! intval($a->data['user']['hidewall'])) {
+                               $o .= '<div id="side-bar-photos-albums" class="widget">';
+                               $o .= '<h3>' . '<a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '">' . t('Photo Albums') . '</a></h3>';
                                        
-                       $o .= '<ul>';
-                       foreach($albums as $album) {
+                               $o .= '<ul>';
+                               foreach($albums as $album) {
 
-                               // don't show contact photos. We once translated this name, but then you could still access it under
-                               // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
+                                       // don't show contact photos. We once translated this name, but then you could still access it under
+                                       // a different language setting. Now we store the name in English and check in English (and translated for legacy albums).
 
-                               if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
-                                       continue;
-                               $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>'; 
+                                       if((! strlen($album['album'])) || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
+                                               continue;
+                                       $o .= '<li>' . '<a href="photos/' . $a->argv[1] . '/album/' . bin2hex($album['album']) . '" >' . $album['album'] . '</a></li>'; 
+                               }
+                               $o .= '</ul>';
+                       }
+                       if(local_user() && $a->data['user']['uid'] == local_user()) {
+                               $o .= '<div id="photo-albums-upload-link"><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload" >' .t('Upload New Photos') . '</a></div>';
                        }
-                       $o .= '</ul>';
 
                        $o .= '</div>';
                }
@@ -94,7 +99,7 @@ EOT;
 
 function photos_post(&$a) {
 
-       logger('mod-photos: photos_post(): begin' , 'LOGGER_DEBUG');
+       logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
 
 
        logger('mod_photos: REQUEST ' . print_r($_REQUEST,true), LOGGER_DATA);
@@ -282,6 +287,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);
@@ -295,7 +301,61 @@ 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']);
+                               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),
@@ -325,7 +385,6 @@ function photos_post(&$a) {
                        // Create item container
 
                        $title = '';
-                       $basename = basename($filename);
                        $uri = item_new_uri($a->get_hostname(),$page_owner_uid);
 
                        $arr = array();
@@ -567,7 +626,7 @@ function photos_post(&$a) {
        $album    = notags(trim($_REQUEST['album']));
        $newalbum = notags(trim($_REQUEST['newalbum']));
 
-       logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , 'LOGGER_DEBUG');
+       logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
 
        if(! strlen($album)) {
                if(strlen($newalbum))
@@ -639,13 +698,13 @@ function photos_post(&$a) {
                return;
        }
 
-       logger('mod/photos.php: photos_post(): loading the contents of ' . $src , 'LOGGER_DEBUG');
+       logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
 
        $imagedata = @file_get_contents($src);
        $ph = new Photo($imagedata);
 
        if(! $ph->is_valid()) {
-               logger('mod/photos.php: photos_post(): unable to process image' , 'LOGGER_DEBUG');
+               logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
                notice( t('Unable to process image.') . EOL );
                @unlink($src);
                $foo = 0;
@@ -665,7 +724,7 @@ function photos_post(&$a) {
        $r = $ph->store($page_owner_uid, $visitor, $photo_hash, $filename, $album, 0 , 0, $str_contact_allow, $str_group_allow, $str_contact_deny, $str_group_deny);
 
        if(! $r) {
-               logger('mod/photos.php: photos_post(): image store failed' , 'LOGGER_DEBUG');
+               logger('mod/photos.php: photos_post(): image store failed' , LOGGER_DEBUG);
                notice( t('Image upload failed.') . EOL );
                killme();
        }
@@ -744,6 +803,7 @@ function photos_content(&$a) {
        // URLs:
        // photos/name
        // photos/name/upload
+       // photos/name/upload/xxxxx (xxxxx is album name)
        // photos/name/album/xxxxx
        // photos/name/album/xxxxx/edit
        // photos/name/image/xxxxx
@@ -860,14 +920,21 @@ function photos_content(&$a) {
                        notice( t('Permission denied.'));
                        return;
                }
+
+
+               $selname = (($datum) ? hex2bin($datum) : '');
+
+
                $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
 
-               $albumselect .= '<option value="" selected="selected" >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
+               
+               $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
                if(count($a->data['albums'])) {
                        foreach($a->data['albums'] as $album) {
                                if(($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos')))
                                        continue;
-                               $albumselect .= '<option value="' . $album['album'] . '">' . $album['album'] . '</option>';
+                               $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
+                               $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
                        }
                }
 
@@ -958,11 +1025,23 @@ function photos_content(&$a) {
                                }
                        }
                }
+
+               if($can_post) {
+                       $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album) . '" >' . t('Upload New Photos') . '</a></div>';
+               }
+
                $tpl = get_markup_template('photo_album.tpl');
                if(count($r))
+                       $twist = 'rotright';
                        foreach($r as $rr) {
+                               if($twist == 'rotright')
+                                       $twist = 'rotleft';
+                               else
+                                       $twist = 'rotright';
+
                                $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',
@@ -1064,13 +1143,24 @@ function photos_content(&$a) {
                        
                }
 
+               if(! $cmd !== 'edit') {
+                       $a->page['htmlhead'] .= '<script>
+                               $(document).keydown(function(event) {' . "\n";
+
+                       if($prevlink)
+                               $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 37) { event.preventDefault(); window.location.href = \'' . $prevlink . '\'; }' . "\n";
+                       if($nextlink)
+                               $a->page['htmlhead'] .= 'if(event.ctrlKey && event.keyCode == 39) { event.preventDefault(); window.location.href = \'' . $nextlink . '\'; }' . "\n";
+                       $a->page['htmlhead'] .= '});</script>';
+               }
+
                if($prevlink)
                        $prevlink = array($prevlink, '<div class="icon prev"></div>') ;
 
                $photo = array(
                        'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.jpg',
                        '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'] . '.jpg' . '?f=&_u=' . datetime_convert('','','','ymdhis')
                );
 
                if($nextlink)
@@ -1086,7 +1176,7 @@ function photos_content(&$a) {
                        $link_item = $linked_items[0];
                        $r = q("SELECT COUNT(*) AS `total`
                                FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
-                               WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
+                               WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
                                AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                                AND `item`.`uid` = %d 
                                $sql_extra ",
@@ -1105,7 +1195,7 @@ function photos_content(&$a) {
                                `contact`.`rel`, `contact`.`thumb`, `contact`.`self`, 
                                `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
                                FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
-                               WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0
+                               WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
                                AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
                                AND `item`.`uid` = %d
                                $sql_extra
@@ -1150,6 +1240,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'],
@@ -1203,6 +1294,7 @@ function photos_content(&$a) {
                                                        '$myphoto' => $contact['thumb'],
                                                        '$comment' => t('Comment'),
                                                        '$submit' => t('Submit'),
+                                                       '$preview' => t('Preview'),
                                                        '$ww' => ''
                                                ));
                                        }
@@ -1371,9 +1463,16 @@ function photos_content(&$a) {
 
        $photos = array();
        if(count($r)) {
+               $twist = 'rotright';
                foreach($r as $rr) {
+                       if($twist == 'rotright')
+                               $twist = 'rotleft';
+                       else
+                               $twist = 'rotright';
+
                        $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',