]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
hide private group if desired
[friendica.git] / mod / photos.php
old mode 100755 (executable)
new mode 100644 (file)
index 4406780..3ce6f99
@@ -38,21 +38,22 @@ 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>';
                        }
-                       $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>';
                        }
@@ -286,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);
@@ -299,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),
@@ -329,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();
@@ -977,9 +1032,16 @@ function photos_content(&$a) {
 
                $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',
@@ -1069,7 +1131,7 @@ function photos_content(&$a) {
                if($can_post && ($ph[0]['uid'] == $owner_uid)) {
                        $tools = array(
                                'edit'  => array($a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $datum . (($cmd === 'edit') ? '' : '/edit'), (($cmd === 'edit') ? t('View photo') : t('Edit photo'))),
-                               'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'] . '?form_security_token=' . get_form_security_token('profile_photo'), t('Use as profile photo')),
+                               'profile'=>array($a->get_baseurl() . '/profile_photo/use/'.$ph[0]['resource-id'], t('Use as profile photo')),
                        );
 
                        // lock
@@ -1081,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)
@@ -1167,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'],
@@ -1389,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',