]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Update the `thr-parent` field in the `item` table
[friendica.git] / mod / photos.php
index 4fa8aca082cfcc4e229d54de5b85af90222abb0a..af40ea30371a43f4e89a1dfdaf56e33487fdcc2d 100644 (file)
@@ -16,7 +16,7 @@ function photos_init(&$a) {
 
        if($a->argc > 1) {
                $nick = $a->argv[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",
+               $r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
                        dbesc($nick)
                );
 
@@ -36,10 +36,12 @@ function photos_init(&$a) {
 
                        $o .= '<div class="vcard">';
                        $o .= '<div class="fn">' . $a->data['user']['username'] . '</div>';
-                       $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?rev=' . urlencode($a->data['user']['picdate']) . '" alt="' . $a->data['user']['username'] . '" /></div>';
+                       $o .= '<div id="profile-photo-wrapper"><img class="photo" style="width: 175px; height: 175px;" src="' . $a->get_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg') . '" alt="' . $a->data['user']['username'] . '" /></div>';
                        $o .= '</div>';
-                       
-                       if(! intval($a->data['user']['hidewall'])) {
+
+                       $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);     
+
+                       if($albums_visible) {
                                $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>';
                                        
@@ -67,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;
@@ -306,7 +289,8 @@ function photos_post(&$a) {
                        $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
 
 
-               if((x($_POST,'rotate') !== false) && (intval($_POST['rotate']) == 1)) {
+               if((x($_POST,'rotate') !== false) && 
+                  ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
                        logger('rotate');
 
                        $r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1",
@@ -316,7 +300,8 @@ function photos_post(&$a) {
                        if(count($r)) {
                                $ph = new Photo($r[0]['data'], $r[0]['type']);
                                if($ph->is_valid()) {
-                                       $ph->rotate(270);
+                                       $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
+                                       $ph->rotate($rotate_deg);
 
                                        $width  = $ph->getWidth();
                                        $height = $ph->getHeight();
@@ -325,8 +310,8 @@ function photos_post(&$a) {
                                                dbesc($ph->imageString()),
                                                intval($height),
                                                intval($width),
-                               dbesc($resource_id),
-                               intval($page_owner_uid)
+                                               dbesc($resource_id),
+                                               intval($page_owner_uid)
                                        );
 
                                        if($width > 640 || $height > 640) {
@@ -338,8 +323,8 @@ function photos_post(&$a) {
                                                        dbesc($ph->imageString()),
                                                        intval($height),
                                                        intval($width),
-                               dbesc($resource_id),
-                               intval($page_owner_uid)
+                                                       dbesc($resource_id),
+                                                       intval($page_owner_uid)
                                                );
                                        }
 
@@ -352,8 +337,8 @@ function photos_post(&$a) {
                                                        dbesc($ph->imageString()),
                                                        intval($height),
                                                        intval($width),
-                               dbesc($resource_id),
-                               intval($page_owner_uid)
+                                                       dbesc($resource_id),
+                                                       intval($page_owner_uid)
                                                );
                                        }       
                                }
@@ -707,6 +692,24 @@ function photos_post(&$a) {
        logger('mod/photos.php: photos_post(): loading the contents of ' . $src , LOGGER_DEBUG);
 
        $imagedata = @file_get_contents($src);
+
+
+
+       $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
+               intval($a->data['user']['uid'])
+       );
+
+       $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
+
+       if(($limit !== false) && (($r[0]['total'] + strlen($imagedata)) > $limit)) {
+               notice( upgrade_message() . EOL );
+               @unlink($src);
+               $foo = 0;
+               call_hooks('photo_post_end',$foo);
+               killme();
+       }
+               
+
        $ph = new Photo($imagedata, $type);
 
        if(! $ph->is_valid()) {
@@ -721,6 +724,12 @@ function photos_post(&$a) {
        $ph->orient($src);
        @unlink($src);
 
+       $max_length = get_config('system','max_image_length');
+       if(! $max_length)
+               $max_length = MAX_IMAGE_LENGTH;
+       if($max_length > 0)
+               $ph->scaleImage($max_length);
+
        $width  = $ph->getWidth();
        $height = $ph->getHeight();
 
@@ -934,7 +943,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>';
@@ -949,8 +958,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'],
@@ -960,16 +967,29 @@ 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>';
 
 
+               $r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ",
+                       intval($a->data['user']['uid'])
+               );
+
+
+               $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
+               if($limit !== false) {
+                       $usage_message = sprintf( t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
+               }
+               else {
+                       $usage_message = sprintf( t('You have used %1$.2f Mbytes of photo storage.'), $r[0]['total'] / 1024000 );
+               }
+
 
                $tpl = get_markup_template('photos_upload.tpl');
                $o .= replace_macros($tpl,array(
                        '$pagename' => t('Upload Photos'),
                        '$sessid' => session_id(),
+                       '$usage' => $usage_message,
                        '$nickname' => $a->data['user']['nickname'],
                        '$newalbum' => t('New album name: '),
                        '$existalbumtext' => t('or existing album name: '),
@@ -1154,15 +1174,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)
@@ -1251,7 +1268,8 @@ 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'),
+                               '$rotatecw' => t('Rotate CW (right)'),
+                               '$rotateccw' => t('Rotate CCW (left)'),
                                '$album' => template_escape($ph[0]['album']),
                                '$newalbum' => t('New album name'), 
                                '$nickname' => $a->data['user']['nickname'],