]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Friendicaland
[friendica.git] / mod / photos.php
index 42cad42f9c9bed557c40077a1877f09b87a20ee5..8d13f859a8560483094bf6a56fe796c8265127f7 100644 (file)
@@ -69,30 +69,11 @@ function photos_init(&$a) {
                $a->page['aside'] .= $o;
 
 
-               $a->page['htmlhead'] .= "<script> var ispublic = '" . t('everybody') . "';" ;
-
-               $a->page['htmlhead'] .= <<< EOT
-
-               $(document).ready(function() {
-
-                       $('#contact_allow, #contact_deny, #group_allow, #group_deny').change(function() {
-                               var selstr;
-                               $('#contact_allow option:selected, #contact_deny option:selected, #group_allow option:selected, #group_deny option:selected').each( function() {
-                                       selstr = $(this).text();
-                                       $('#jot-perms-icon').removeClass('unlock').addClass('lock');
-                                       $('#jot-public').hide();
-                               });
-                               if(selstr == null) { 
-                                       $('#jot-perms-icon').removeClass('lock').addClass('unlock');
-                                       $('#jot-public').show();
-                               }
-
-                       }).trigger('change');
-
-               });
+               $tpl = get_markup_template("photos_head.tpl");
+               $a->page['htmlhead'] .= replace_macros($tpl,array(
+                       '$ispublic' => t('everybody')
+               ));
 
-               </script>
-EOT;
        }
 
        return;
@@ -120,13 +101,25 @@ function photos_post(&$a) {
                $can_post = true;
        else {
                if($community_page && remote_user()) {
-                       $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                               intval(remote_user()),
-                               intval($page_owner_uid)
-                       );
-                       if(count($r)) {
-                               $can_post = true;
-                               $visitor = remote_user();
+                       $cid = 0;
+                       if(is_array($_SESSION['remote'])) {
+                               foreach($_SESSION['remote'] as $v) {
+                                       if($v['uid'] == $page_owner_uid) {
+                                               $cid = $v['cid'];
+                                               break;
+                                       }
+                               }
+                       }
+                       if($cid) {
+
+                               $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
+                                       intval($cid),
+                                       intval($page_owner_uid)
+                               );
+                               if(count($r)) {
+                                       $can_post = true;
+                                       $visitor = $cid;
+                               }
                        }
                }
        }
@@ -740,8 +733,7 @@ function photos_post(&$a) {
                killme();
        }
 
-        if($ph->getType() != 'image/png')
-            $ph->orient($src);
+       $ph->orient($src);
        @unlink($src);
 
        $max_length = get_config('system','max_image_length');
@@ -891,6 +883,7 @@ function photos_content(&$a) {
        $visitor        = 0;
        $contact        = null;
        $remote_contact = false;
+       $contact_id     = 0;
 
        $owner_uid = $a->data['user']['uid'];
 
@@ -900,15 +893,26 @@ function photos_content(&$a) {
                $can_post = true;
        else {
                if($community_page && remote_user()) {
-                       $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                               intval(remote_user()),
-                               intval($owner_uid)
-                       );
-                       if(count($r)) {
-                               $can_post = true;
-                               $contact  = $r[0];
-                               $remote_contact = true;
-                               $visitor = remote_user();
+                       if(is_array($_SESSION['remote'])) {
+                               foreach($_SESSION['remote'] as $v) {
+                                       if($v['uid'] == $owner_uid) {
+                                               $contact_id = $v['cid'];
+                                               break;
+                                       }
+                               }
+                       }
+                       if($contact_id) {
+
+                               $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
+                                       intval($contact_id),
+                                       intval($owner_uid)
+                               );
+                               if(count($r)) {
+                                       $can_post = true;
+                                       $contact = $r[0];
+                                       $remote_contact = true;
+                                       $visitor = $cid;
+                               }
                        }
                }
        }
@@ -916,15 +920,25 @@ function photos_content(&$a) {
        // perhaps they're visiting - but not a community page, so they wouldn't have write access
 
        if(remote_user() && (! $visitor)) {
-               $contact_id = $_SESSION['visitor_id'];
-               $groups = init_groups_visitor($contact_id);
-               $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                       intval(remote_user()),
-                       intval($owner_uid)
-               );
-               if(count($r)) {
-                       $contact = $r[0];
-                       $remote_contact = true;
+               $contact_id = 0;
+               if(is_array($_SESSION['remote'])) {
+                       foreach($_SESSION['remote'] as $v) {
+                               if($v['uid'] == $owner_uid) {
+                                       $contact_id = $v['cid'];
+                                       break;
+                               }
+                       }
+               }
+               if($contact_id) {
+                       $groups = init_groups_visitor($contact_id);
+                       $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
+                               intval($contact_id),
+                               intval($owner_uid)
+                       );
+                       if(count($r)) {
+                               $contact = $r[0];
+                               $remote_contact = true;
+                       }
                }
        }
 
@@ -963,7 +977,7 @@ function photos_content(&$a) {
                $selname = (($datum) ? hex2bin($datum) : '');
 
 
-               $albumselect = '<select id="photos-upload-album-select" name="album" size="4">';
+               $albumselect = '';
 
                
                $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
@@ -978,8 +992,6 @@ function photos_content(&$a) {
 
                $celeb = ((($a->user['page-flags'] == PAGE_SOAPBOX) || ($a->user['page-flags'] == PAGE_COMMUNITY)) ? true : false);
 
-               $albumselect .= '</select>';
-
                $uploader = '';
 
                $ret = array('post_url' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'],
@@ -989,7 +1001,7 @@ function photos_content(&$a) {
 
                call_hooks('photo_upload_form',$ret);
 
-               $default_upload = '<input type="file" name="userfile" />        <div class="photos-upload-submit-wrapper" >
+               $default_upload = '<input id="photos-upload-choose" type="file" name="userfile" />      <div class="photos-upload-submit-wrapper" >
                <input type="submit" name="submit" value="' . t('Submit') . '" id="photos-upload-submit" /> </div>';
 
 
@@ -1042,8 +1054,13 @@ function photos_content(&$a) {
                        $a->set_pager_itemspage(20);
                }
 
+               if($_GET['order'] === 'posted')
+                       $order = 'ASC';
+               else
+                       $order = 'DESC';
+
                $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",
+                       AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
                        intval($owner_uid),
                        dbesc($album),
                        intval($a->pager['start']),
@@ -1077,10 +1094,17 @@ function photos_content(&$a) {
                        }
                }
 
+               if($_GET['order'] === 'posted')
+                       $o .=  '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '" >' . t('Show Newest First') . '</a></div>';
+               else
+                       $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted" >' . t('Show Oldest First') . '</a></div>';
+
+
                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';
@@ -1095,7 +1119,8 @@ function photos_content(&$a) {
                                $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'],
+                                       '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
+                                               . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
                                        '$phototitle' => t('View Photo'),
                                        '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
                                        '$imgalt' => template_escape($rr['filename']),
@@ -1140,8 +1165,14 @@ function photos_content(&$a) {
                $prevlink = '';
                $nextlink = '';
 
+               if($_GET['order'] === 'posted')
+                       $order = 'ASC';
+               else
+                       $order = 'DESC';
+
+
                $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0 
-                       $sql_extra ORDER BY `created` DESC ",
+                       $sql_extra ORDER BY `created` $order ",
                        dbesc($ph[0]['album']),
                        intval($owner_uid)
                ); 
@@ -1159,8 +1190,8 @@ function photos_content(&$a) {
                                }
                        }
                        $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
-                       $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix;
-                       $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix;
+                       $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
+                       $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
                }
 
 
@@ -1196,15 +1227,12 @@ 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( $cmd === 'edit') {
+                       $tpl = get_markup_template('photo_edit_head.tpl');
+                       $a->page['htmlhead'] .= replace_macros($tpl,array(
+                               '$prevlink' => $prevlink,
+                               '$nextlink' => $nextlink
+                       ));
                }
 
                if($prevlink)
@@ -1349,6 +1377,7 @@ function photos_content(&$a) {
                                                        '$comment' => t('Comment'),
                                                        '$submit' => t('Submit'),
                                                        '$preview' => t('Preview'),
+                                                       '$sourceapp' => t($a->sourcename),
                                                        '$ww' => ''
                                                ));
                                        }
@@ -1388,6 +1417,7 @@ function photos_content(&$a) {
                                                        '$myphoto' => $contact['thumb'],
                                                        '$comment' => t('Comment'),
                                                        '$submit' => t('Submit'),
+                                                       '$sourceapp' => t($a->sourcename),
                                                        '$ww' => ''
                                                ));
                                        }
@@ -1419,6 +1449,7 @@ function photos_content(&$a) {
                                                                '$myphoto' => $contact['thumb'],
                                                                '$comment' => t('Comment'),
                                                                '$submit' => t('Submit'),
+                                                               '$sourceapp' => t($a->sourcename),
                                                                '$ww' => ''
                                                        ));
                                                }
@@ -1444,7 +1475,7 @@ function photos_content(&$a) {
 
                                        $drop = '';
 
-                                       if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
+                                       if(($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()))
                                                $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$delete' => t('Delete')));