]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Merge pull request #3078 from Hypolite/issue/#3039-mod-2of3
[friendica.git] / mod / photos.php
index 317d7272b41d689889e7694942e8f748488e5601..60e5dee64361356ac0388ba62b40ab18768f8851 100644 (file)
@@ -10,7 +10,7 @@ require_once('include/tags.php');
 require_once('include/threads.php');
 require_once('include/Probe.php');
 
-function photos_init(App &$a) {
+function photos_init(App $a) {
 
        if ($a->argc > 1)
                auto_redir($a, $a->argv[1]);
@@ -112,7 +112,7 @@ function photos_init(App &$a) {
 
 
 
-function photos_post(App &$a) {
+function photos_post(App $a) {
 
        logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
 
@@ -182,11 +182,11 @@ function photos_post(App &$a) {
                        return; // NOTREACHED
                }
 
-               $r = qu("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
+               $r = qu("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
                        dbesc($album),
                        intval($page_owner_uid)
                );
-               if (! dbm::is_result($r)) {
+               if (!dbm::is_result($r)) {
                        notice( t('Album not found.') . EOL);
                        goaway($_SESSION['photo_return']);
                        return; // NOTREACHED
@@ -208,6 +208,9 @@ function photos_post(App &$a) {
                                dbesc($album),
                                intval($page_owner_uid)
                        );
+                       // Update the photo albums cache
+                       photo_albums($page_owner_uid, true);
+
                        $newurl = str_replace(bin2hex($album),bin2hex($newalbum),$_SESSION['photo_return']);
                        goaway($newurl);
                        return; // NOTREACHED
@@ -255,7 +258,7 @@ function photos_post(App &$a) {
                                );
                        }
                        if (dbm::is_result($r)) {
-                               foreach($r as $rr) {
+                               foreach ($r as $rr) {
                                        $res[] = "'" . dbesc($rr['rid']) . "'" ;
                                }
                        } else {
@@ -277,7 +280,7 @@ function photos_post(App &$a) {
                                intval($page_owner_uid)
                        );
                        if (dbm::is_result($r)) {
-                               foreach($r as $rr) {
+                               foreach ($r as $rr) {
                                        q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
                                                dbesc(datetime_convert()),
                                                dbesc($rr['parent-uri']),
@@ -294,7 +297,11 @@ function photos_post(App &$a) {
                                                proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
                                }
                        }
+
+                       // Update the photo albums cache
+                       photo_albums($page_owner_uid, true);
                }
+
                goaway('photos/' . $a->data['user']['nickname']);
                return; // NOTREACHED
        }
@@ -359,6 +366,9 @@ function photos_post(App &$a) {
                                $url = App::get_baseurl();
                                $drop_id = intval($i[0]['id']);
 
+                               // Update the photo albums cache
+                               photo_albums($page_owner_uid, true);
+
                                if ($i[0]['visible'])
                                        proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
                        }
@@ -370,10 +380,11 @@ function photos_post(App &$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);
-               $albname     = ((x($_POST,'albname')) ? notags(trim($_POST['albname'])) : '');
+               $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);
+               $albname     = ((x($_POST,'albname'))   ? notags(trim($_POST['albname'])) : '');
+               $origaname   = ((x($_POST,'origaname')) ? notags(trim($_POST['origaname'])) : '');
                $str_group_allow   = perms2str($_POST['group_allow']);
                $str_contact_allow = perms2str($_POST['contact_allow']);
                $str_group_deny    = perms2str($_POST['group_deny']);
@@ -457,6 +468,10 @@ function photos_post(App &$a) {
                                dbesc($resource_id),
                                intval($page_owner_uid)
                        );
+                       // Update the photo albums cache if album name was changed
+                       if ($albname !== $origaname) {
+                               photo_albums($page_owner_uid, true);
+                       }
                }
 
                /* Don't make the item visible if the only change was the album name */
@@ -803,22 +818,23 @@ function photos_post(App &$a) {
        $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();
+       if ($limit) {
+               $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'])
+               );
+               $size = $r[0]['total'];
+
+               if (($size + 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()) {
@@ -913,6 +929,8 @@ function photos_post(App &$a) {
                                . '[/url]';
 
        $item_id = item_store($arr);
+       // Update the photo albums cache
+       photo_albums($page_owner_uid, true);
 
        if ($visible)
                proc_run(PRIORITY_HIGH, "include/notifier.php", 'wall-new', $item_id);
@@ -928,7 +946,7 @@ function photos_post(App &$a) {
 
 
 
-function photos_content(App &$a) {
+function photos_content(App $a) {
 
        // URLs:
        // photos/name
@@ -1290,7 +1308,7 @@ function photos_content(App &$a) {
 
        }
 
-       /** 
+       /**
         * Display one photo
         */