]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Merge branch 'develop' into rewrites/dbm_is_result
[friendica.git] / mod / photos.php
index 19d3d1c6c4be9a3cd22adba2ee14607e4badc8c3..d4b2a3b19f9169c7af633540aa4e86f07ecf1bc2 100644 (file)
@@ -10,7 +10,7 @@ require_once('include/tags.php');
 require_once('include/threads.php');
 require_once('include/Probe.php');
 
-function photos_init(&$a) {
+function photos_init(App &$a) {
 
        if ($a->argc > 1)
                auto_redir($a, $a->argv[1]);
@@ -21,11 +21,9 @@ function photos_init(&$a) {
 
        nav_set_selected('home');
 
-       $o = '';
-
        if ($a->argc > 1) {
                $nick = $a->argv[1];
-               $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
+               $user = qu("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
                        dbesc($nick)
                );
 
@@ -50,15 +48,7 @@ function photos_init(&$a) {
                        '$pdesc' => (($profile['pdesc'] != "") ? $profile['pdesc'] : ""),
                ));
 
-
-               $sql_extra = permissions_sql($a->data['user']['uid']);
-
-               $albums = qu("SELECT count(distinct `resource-id`) AS `total`, `album` FROM `photo` USE INDEX (`uid_album_created`) WHERE `uid` = %d  AND `album` != '%s' AND `album` != '%s'
-                       $sql_extra GROUP BY `album` ORDER BY `created` DESC",
-                       intval($a->data['user']['uid']),
-                       dbesc('Contact Photos'),
-                       dbesc( t('Contact Photos'))
-               );
+               $albums = photo_albums($a->data['user']['uid']);
 
                $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);
 
@@ -122,7 +112,7 @@ function photos_init(&$a) {
 
 
 
-function photos_post(&$a) {
+function photos_post(App &$a) {
 
        logger('mod-photos: photos_post: begin' , LOGGER_DEBUG);
 
@@ -142,24 +132,24 @@ function photos_post(&$a) {
                $can_post = true;
        else {
                if ($community_page && remote_user()) {
-                       $cid = 0;
+                       $contact_id = 0;
                        if (is_array($_SESSION['remote'])) {
                                foreach ($_SESSION['remote'] as $v) {
                                        if ($v['uid'] == $page_owner_uid) {
-                                               $cid = $v['cid'];
+                                               $contact_id = $v['cid'];
                                                break;
                                        }
                                }
                        }
-                       if ($cid) {
+                       if ($contact_id) {
 
-                               $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                                       intval($cid),
+                               $r = qu("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
+                                       intval($contact_id),
                                        intval($page_owner_uid)
                                );
                                if (dbm::is_result($r)) {
                                        $can_post = true;
-                                       $visitor = $cid;
+                                       $visitor = $contact_id;
                                }
                        }
                }
@@ -170,12 +160,12 @@ function photos_post(&$a) {
                killme();
        }
 
-       $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
+       $r = qu("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
                WHERE `user`.`uid` = %d AND `self` = 1 LIMIT 1",
                intval($page_owner_uid)
        );
 
-       if (! count($r)) {
+       if (! dbm::is_result($r)) {
                notice( t('Contact information unavailable') . EOL);
                logger('photos_post: unable to locate contact record for page owner. uid=' . $page_owner_uid);
                killme();
@@ -192,11 +182,11 @@ function photos_post(&$a) {
                        return; // NOTREACHED
                }
 
-               $r = q("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
+               $r = qu("SELECT count(*) FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
                        dbesc($album),
                        intval($page_owner_uid)
                );
-               if (! count($r)) {
+               if (! dbm::is_result($r)) {
                        notice( t('Album not found.') . EOL);
                        goaway($_SESSION['photo_return']);
                        return; // NOTREACHED
@@ -356,7 +346,7 @@ function photos_post(&$a) {
                                dbesc($r[0]['resource-id']),
                                intval($page_owner_uid)
                        );
-                       if (count($i)) {
+                       if (dbm::is_result($i)) {
                                q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
                                        dbesc(datetime_convert()),
                                        dbesc(datetime_convert()),
@@ -366,7 +356,7 @@ function photos_post(&$a) {
                                create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
                                delete_thread_uri($i[0]['uri'], $page_owner_uid);
 
-                               $url = $a->get_baseurl();
+                               $url = App::get_baseurl();
                                $drop_id = intval($i[0]['id']);
 
                                if ($i[0]['visible'])
@@ -506,8 +496,8 @@ function photos_post(&$a) {
                        $arr['visible']       = $visibility;
                        $arr['origin']        = 1;
 
-                       $arr['body']          = '[url=' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
-                                               . '[img]' . $a->get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
+                       $arr['body']          = '[url=' . App::get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
+                                               . '[img]' . App::get_baseurl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
                                                . '[/url]';
 
                        $item_id = item_store($arr);
@@ -625,7 +615,7 @@ function photos_post(&$a) {
                                                }
                                        } elseif (strpos($tag,'#') === 0) {
                                                $tagname = substr($tag, 1);
-                                               $str_tags .= '#[url='.$a->get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
+                                               $str_tags .= '#[url='.App::get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
                                        }
                                }
                        }
@@ -691,12 +681,12 @@ function photos_post(&$a) {
                                        $arr['visible']       = 1;
                                        $arr['verb']          = ACTIVITY_TAG;
                                        $arr['object-type']   = ACTIVITY_OBJ_PERSON;
-                                       $arr['target-type']   = ACTIVITY_OBJ_PHOTO;
+                                       $arr['target-type']   = ACTIVITY_OBJ_IMAGE;
                                        $arr['tag']           = $tagged[4];
                                        $arr['inform']        = $tagged[2];
                                        $arr['origin']        = 1;
-                                       $arr['body']          = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
-                                       $arr['body'] .= "\n\n" . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
+                                       $arr['body']          = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('a photo') . '[/url]', '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]') ;
+                                       $arr['body'] .= "\n\n" . '[url=' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . App::get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '[/img][/url]' . "\n" ;
 
                                        $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
                                        $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
@@ -704,9 +694,9 @@ function photos_post(&$a) {
                                                $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
                                        $arr['object'] .= '</link></object>' . "\n";
 
-                                       $arr['target'] = '<target><type>' . ACTIVITY_OBJ_PHOTO . '</type><title>' . $p[0]['desc'] . '</title><id>'
-                                               . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
-                                       $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
+                                       $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
+                                               . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
+                                       $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . App::get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
 
                                        $item_id = item_store($arr);
                                        if ($item_id) {
@@ -758,7 +748,7 @@ function photos_post(&$a) {
                dbesc($album),
                intval($page_owner_uid)
        );
-       if ((! count($r)) || ($album == t('Profile Photos')))
+       if ((! dbm::is_result($r)) || ($album == t('Profile Photos')))
                $visible = 1;
        else
                $visible = 0;
@@ -918,8 +908,8 @@ function photos_post(&$a) {
        $arr['visible']       = $visible;
        $arr['origin']        = 1;
 
-       $arr['body']          = '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
-                               . '[img]' . $a->get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
+       $arr['body']          = '[url=' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
+                               . '[img]' . App::get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
                                . '[/url]';
 
        $item_id = item_store($arr);
@@ -938,7 +928,7 @@ function photos_post(&$a) {
 
 
 
-function photos_content(&$a) {
+function photos_content(App &$a) {
 
        // URLs:
        // photos/name
@@ -1022,7 +1012,7 @@ function photos_content(&$a) {
                                        $can_post = true;
                                        $contact = $r[0];
                                        $remote_contact = true;
-                                       $visitor = $cid;
+                                       $visitor = $contact_id;
                                }
                        }
                }
@@ -1337,7 +1327,7 @@ function photos_content(&$a) {
                        $order = 'DESC';
 
 
-               $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
+               $prvnxt = qu("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
                        $sql_extra ORDER BY `created` $order ",
                        dbesc($ph[0]['album']),
                        intval($owner_uid)
@@ -1433,7 +1423,7 @@ function photos_content(&$a) {
 
                if (count($linked_items)) {
                        $link_item = $linked_items[0];
-                       $r = q("SELECT COUNT(*) AS `total`
+                       $r = qu("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 and `item`.`moderated` = 0
                                AND `contact`.`blocked` = 0 AND `contact`.`pending` = 0
@@ -1449,7 +1439,7 @@ function photos_content(&$a) {
                                $a->set_pager_total($r[0]['total']);
 
 
-                       $r = q("SELECT `item`.*, `item`.`id` AS `item_id`,
+                       $r = qu("SELECT `item`.*, `item`.`id` AS `item_id`,
                                `contact`.`name`, `contact`.`photo`, `contact`.`url`, `contact`.`network`,
                                `contact`.`rel`, `contact`.`thumb`, `contact`.`self`,
                                `contact`.`id` AS `cid`, `contact`.`uid` AS `contact-uid`
@@ -1583,7 +1573,7 @@ function photos_content(&$a) {
                        }
 
                        $comments = '';
-                       if (! count($r)) {
+                       if (! dbm::is_result($r)) {
                                if ($can_post || can_write_wall($a,$owner_uid)) {
                                        if ($link_item['last-child']) {
                                                $comments .= replace_macros($cmnt_tpl,array(
@@ -1798,7 +1788,7 @@ function photos_content(&$a) {
        // Default - show recent photos with upload link (if applicable)
        //$o = '';
 
-       $r = q("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
+       $r = qu("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
                $sql_extra GROUP BY `resource-id`",
                intval($a->data['user']['uid']),
                dbesc('Contact Photos'),
@@ -1809,7 +1799,7 @@ function photos_content(&$a) {
                $a->set_pager_itemspage(20);
        }
 
-       $r = q("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
+       $r = qu("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
                WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
                $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
                intval($a->data['user']['uid']),
@@ -1819,8 +1809,6 @@ function photos_content(&$a) {
                intval($a->pager['itemspage'])
        );
 
-
-
        $photos = array();
        if (dbm::is_result($r)) {
                $twist = 'rotright';
@@ -1872,4 +1860,3 @@ function photos_content(&$a) {
 
        return $o;
 }
-