]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Bugfix Diaspora: We exited with the wrong return values and the guid for messages...
[friendica.git] / mod / photos.php
index e4548bb468e3abd1183a27c86d87d13f7e891f33..bf21b3437a3d625c9c388a5921dd5146cc37e088 100644 (file)
@@ -1,16 +1,18 @@
 <?php
-require_once('include/Photo.php');
-require_once('include/photos.php');
-require_once('include/items.php');
-require_once('include/acl_selectors.php');
-require_once('include/bbcode.php');
-require_once('include/security.php');
-require_once('include/redir.php');
-require_once('include/tags.php');
-require_once('include/threads.php');
-require_once('include/Probe.php');
-
-use \Friendica\Core\Config;
+
+use Friendica\App;
+use Friendica\Core\Config;
+use Friendica\Network\Probe;
+
+require_once 'include/Photo.php';
+require_once 'include/photos.php';
+require_once 'include/items.php';
+require_once 'include/acl_selectors.php';
+require_once 'include/bbcode.php';
+require_once 'include/security.php';
+require_once 'include/redir.php';
+require_once 'include/tags.php';
+require_once 'include/threads.php';
 
 function photos_init(App $a) {
 
@@ -18,7 +20,7 @@ function photos_init(App $a) {
                auto_redir($a, $a->argv[1]);
        }
 
-       if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
+       if ((get_config('system', 'block_public')) && (! local_user()) && (! remote_user())) {
                return;
        }
 
@@ -562,9 +564,9 @@ function photos_post(App $a) {
                                        if (isset($profile)) {
                                                unset($profile);
                                        }
-                                       if (strpos($tag,'@') === 0) {
+                                       if (strpos($tag, '@') === 0) {
                                                $name = substr($tag,1);
-                                               if ((strpos($name,'@')) || (strpos($name,'http://'))) {
+                                               if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
                                                        $newname = $name;
                                                        $links = @Probe::lrdd($name);
                                                        if (count($links)) {
@@ -573,7 +575,7 @@ function photos_post(App $a) {
                                                                                $profile = $link['@attributes']['href'];
                                                                        }
                                                                        if ($link['@attributes']['rel'] === 'salmon') {
-                                                                               $salmon = '$url:' . str_replace(',','%sc',$link['@attributes']['href']);
+                                                                               $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
                                                                                if (strlen($inform)) {
                                                                                        $inform .= ',';
                                                                                }
@@ -581,13 +583,13 @@ function photos_post(App $a) {
                                                                        }
                                                                }
                                                        }
-                                                       $taginfo[] = array($newname,$profile,$salmon);
+                                                       $taginfo[] = array($newname, $profile, $salmon);
                                                } else {
                                                        $newname = $name;
                                                        $alias = '';
                                                        $tagcid = 0;
-                                                       if (strrpos($newname,'+')) {
-                                                               $tagcid = intval(substr($newname,strrpos($newname, '+') + 1));
+                                                       if (strrpos($newname, '+')) {
+                                                               $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
                                                        }
 
                                                        if ($tagcid) {
@@ -613,20 +615,7 @@ function photos_post(App $a) {
                                                                        );
                                                                }
                                                        }
-                                                       /// @TODO maybe old-lost code to be removed
-/*                                                     elseif (strstr($name,'_') || strstr($name,' ')) {
-                                                               $newname = str_replace('_',' ',$name);
-                                                               $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
-                                                                       dbesc($newname),
-                                                                       intval($page_owner_uid)
-                                                               );
-                                                       } else {
-                                                               $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
-                                                                       dbesc($name),
-                                                                       dbesc($name),
-                                                                       intval($page_owner_uid)
-                                                               );
-                                                       }*/
+
                                                        if (dbm::is_result($r)) {
                                                                $newname = $r[0]['name'];
                                                                $profile = $r[0]['url'];
@@ -638,7 +627,7 @@ function photos_post(App $a) {
                                                        }
                                                }
                                                if ($profile) {
-                                                       if (substr($notify,0,4) === 'cid:') {
+                                                       if (substr($notify, 0, 4) === 'cid:') {
                                                                $taginfo[] = array($newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
                                                        } else {
                                                                $taginfo[] = array($newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
@@ -649,9 +638,9 @@ function photos_post(App $a) {
                                                        $profile = str_replace(',', '%2c', $profile);
                                                        $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
                                                }
-                                       } elseif (strpos($tag,'#') === 0) {
+                                       } elseif (strpos($tag, '#') === 0) {
                                                $tagname = substr($tag, 1);
-                                               $str_tags .= '#[url='.App::get_baseurl()."/search?tag=".$tagname.']'.$tagname.'[/url]';
+                                               $str_tags .= '#[url=' . App::get_baseurl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
                                        }
                                }
                        }
@@ -794,10 +783,10 @@ function photos_post(App $a) {
                $visible = 0;
        }
 
-       $str_group_allow   = perms2str(((is_array($_REQUEST['group_allow']))   ? $_REQUEST['group_allow']   : explode(',',$_REQUEST['group_allow'])));
-       $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',',$_REQUEST['contact_allow'])));
-       $str_group_deny    = perms2str(((is_array($_REQUEST['group_deny']))    ? $_REQUEST['group_deny']    : explode(',',$_REQUEST['group_deny'])));
-       $str_contact_deny  = perms2str(((is_array($_REQUEST['contact_deny']))  ? $_REQUEST['contact_deny']  : explode(',',$_REQUEST['contact_deny'])));
+       $str_group_allow   = perms2str(((is_array($_REQUEST['group_allow']))   ? $_REQUEST['group_allow']   : explode(',', $_REQUEST['group_allow'])));
+       $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',', $_REQUEST['contact_allow'])));
+       $str_group_deny    = perms2str(((is_array($_REQUEST['group_deny']))    ? $_REQUEST['group_deny']    : explode(',', $_REQUEST['group_deny'])));
+       $str_contact_deny  = perms2str(((is_array($_REQUEST['contact_deny']))  ? $_REQUEST['contact_deny']  : explode(',', $_REQUEST['contact_deny'])));
 
        $ret = array('src' => '', 'filename' => '', 'filesize' => 0, 'type' => '');
 
@@ -843,7 +832,7 @@ function photos_post(App $a) {
        $imagedata = @file_get_contents($src);
 
 
-       $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
+       $limit = service_class_fetch($a->data['user']['uid'], 'photo_upload_limit');
 
        if ($limit) {
                $r = q("SELECT SUM(OCTET_LENGTH(`data`)) AS `total` FROM `photo` WHERE `uid` = %d AND `scale` = 0 AND `album` != 'Contact Photos'",
@@ -874,7 +863,7 @@ function photos_post(App $a) {
        $exif = $ph->orient($src);
        @unlink($src);
 
-       $max_length = get_config('system','max_image_length');
+       $max_length = get_config('system', 'max_image_length');
        if (! $max_length) {
                $max_length = MAX_IMAGE_LENGTH;
        }
@@ -988,14 +977,14 @@ function photos_content(App $a) {
        // photos/name/image/xxxxx/edit
 
 
-       if ((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
+       if ((get_config('system', 'block_public')) && (! local_user()) && (! remote_user())) {
                notice( t('Public access denied.') . EOL);
                return;
        }
 
-       require_once('include/bbcode.php');
-       require_once('include/security.php');
-       require_once('include/conversation.php');
+       require_once 'include/bbcode.php';
+       require_once 'include/security.php';
+       require_once 'include/conversation.php';
 
        if (! x($a->data,'user')) {
                notice( t('No photos selected') . EOL );
@@ -1111,7 +1100,7 @@ function photos_content(App $a) {
 
        // tabs
        $is_owner = (local_user() && (local_user() == $owner_uid));
-       $o .= profile_tabs($a,$is_owner, $a->data['user']['nickname']);
+       $o .= profile_tabs($a, $is_owner, $a->data['user']['nickname']);
 
        /**
         * Display upload form
@@ -1155,7 +1144,7 @@ function photos_content(App $a) {
                ));
 
                $usage_message = '';
-               $limit = service_class_fetch($a->data['user']['uid'],'photo_upload_limit');
+               $limit = service_class_fetch($a->data['user']['uid'], 'photo_upload_limit');
                if ($limit !== false) {
 
                        $r = q("SELECT SUM(`datasize`) AS `total` FROM `photo` WHERE `uid` = %d AND `scale` = 0 AND `album` != 'Contact Photos'",
@@ -1253,7 +1242,10 @@ function photos_content(App $a) {
                        $order = 'DESC';
                }
 
-               $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
+               $r = q("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
+                       ANY_VALUE(`type`) AS `type`, max(`scale`) AS `scale`, ANY_VALUE(`desc`) as `desc`,
+                       ANY_VALUE(`created`) as `created`
+                       FROM `photo` WHERE `uid` = %d AND `album` = '%s'
                        AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
                        intval($owner_uid),
                        dbesc($album),
@@ -1284,11 +1276,8 @@ function photos_content(App $a) {
                                }
                        }
                } else {
-                       /// @TODO merge else+if into elseif and 2 into one?
-                       if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
-                               if ($can_post) {
-                                       $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
-                               }
+                       if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos')) && $can_post) {
+                               $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
                        }
                }
 
@@ -1427,8 +1416,8 @@ function photos_content(App $a) {
                }
 
                $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
-               $tools = null;
-               $lock = null;
+               $tools = null;
+               $lock = null;
 
                if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
                        $tools = array(
@@ -1539,7 +1528,7 @@ function photos_content(App $a) {
                $tags = null;
 
                if (count($linked_items) && strlen($link_item['tag'])) {
-                       $arr = explode(',',$link_item['tag']);
+                       $arr = explode(',', $link_item['tag']);
                        // parse tags and add links
                        $tag_str = '';
                        foreach ($arr as $t) {
@@ -1597,9 +1586,9 @@ function photos_content(App $a) {
                                '$album' => array('albname', t('New album name'), $album_e,''),
                                '$caption' => array('desc', t('Caption'), $caption_e, ''),
                                '$tags' => array('newtag', t('Add a Tag'), "", t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping')),
-                               '$rotate_none' => array('rotate',t('Do not rotate'),0,'', true),
-                               '$rotate_cw' => array('rotate',t('Rotate CW (right)'),1,''),
-                               '$rotate_ccw' => array('rotate',t('Rotate CCW (left)'),2,''),
+                               '$rotate_none' => array('rotate', t('Do not rotate'),0,'', true),
+                               '$rotate_cw' => array('rotate', t('Rotate CW (right)'),1,''),
+                               '$rotate_ccw' => array('rotate', t('Rotate CCW (left)'),2,''),
 
                                '$nickname' => $a->data['user']['nickname'],
                                '$resource_id' => $ph[0]['resource-id'],
@@ -1632,8 +1621,8 @@ function photos_content(App $a) {
 
                        $likebuttons = '';
 
-                       if ($can_post || can_write_wall($a,$owner_uid)) {
-                               $likebuttons = replace_macros($like_tpl,array(
+                       if ($can_post || can_write_wall($a, $owner_uid)) {
+                               $likebuttons = replace_macros($like_tpl, array(
                                        '$id' => $link_item['id'],
                                        '$likethis' => t("I like this \x28toggle\x29"),
                                        '$nolike' => (feature_enabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
@@ -1644,27 +1633,24 @@ function photos_content(App $a) {
 
                        $comments = '';
                        if (! dbm::is_result($r)) {
-                               /// @TODO merge into one if() ?
-                               if ($can_post || can_write_wall($a,$owner_uid)) {
-                                       if ($link_item['last-child']) {
-                                               $comments .= replace_macros($cmnt_tpl,array(
-                                                       '$return_path' => '',
-                                                       '$jsreload' => $return_url,
-                                                       '$type' => 'wall-comment',
-                                                       '$id' => $link_item['id'],
-                                                       '$parent' => $link_item['id'],
-                                                       '$profile_uid' =>  $owner_uid,
-                                                       '$mylink' => $contact['url'],
-                                                       '$mytitle' => t('This is you'),
-                                                       '$myphoto' => $contact['thumb'],
-                                                       '$comment' => t('Comment'),
-                                                       '$submit' => t('Submit'),
-                                                       '$preview' => t('Preview'),
-                                                       '$sourceapp' => t($a->sourcename),
-                                                       '$ww' => '',
-                                                       '$rand_num' => random_digits(12)
-                                               ));
-                                       }
+                               if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) {
+                                       $comments .= replace_macros($cmnt_tpl, array(
+                                               '$return_path' => '',
+                                               '$jsreload' => $return_url,
+                                               '$type' => 'wall-comment',
+                                               '$id' => $link_item['id'],
+                                               '$parent' => $link_item['id'],
+                                               '$profile_uid' =>  $owner_uid,
+                                               '$mylink' => $contact['url'],
+                                               '$mytitle' => t('This is you'),
+                                               '$myphoto' => $contact['thumb'],
+                                               '$comment' => t('Comment'),
+                                               '$submit' => t('Submit'),
+                                               '$preview' => t('Preview'),
+                                               '$sourceapp' => t($a->sourcename),
+                                               '$ww' => '',
+                                               '$rand_num' => random_digits(12)
+                                       ));
                                }
                        }
 
@@ -1686,30 +1672,27 @@ function photos_content(App $a) {
                                        builtin_activity_puller($item, $conv_responses);
                                }
 
-                               $like    = ((x($conv_responses['like'],$link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']],$conv_responses['like'][$link_item['uri'] . '-l'],'like',$link_item['id']) : '');
-                               $dislike = ((x($conv_responses['dislike'],$link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']],$conv_responses['dislike'][$link_item['uri'] . '-l'],'dislike',$link_item['id']) : '');
-
-                               /// @TODO merge into one if() ?
-                               if ($can_post || can_write_wall($a,$owner_uid)) {
-                                       if ($link_item['last-child']) {
-                                               $comments .= replace_macros($cmnt_tpl,array(
-                                                       '$return_path' => '',
-                                                       '$jsreload' => $return_url,
-                                                       '$type' => 'wall-comment',
-                                                       '$id' => $link_item['id'],
-                                                       '$parent' => $link_item['id'],
-                                                       '$profile_uid' =>  $owner_uid,
-                                                       '$mylink' => $contact['url'],
-                                                       '$mytitle' => t('This is you'),
-                                                       '$myphoto' => $contact['thumb'],
-                                                       '$comment' => t('Comment'),
-                                                       '$submit' => t('Submit'),
-                                                       '$preview' => t('Preview'),
-                                                       '$sourceapp' => t($a->sourcename),
-                                                       '$ww' => '',
-                                                       '$rand_num' => random_digits(12)
-                                               ));
-                                       }
+                               $like    = ((x($conv_responses['like'], $link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like',$link_item['id']) : '');
+                               $dislike = ((x($conv_responses['dislike'], $link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike',$link_item['id']) : '');
+
+                               if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) {
+                                       $comments .= replace_macros($cmnt_tpl,array(
+                                               '$return_path' => '',
+                                               '$jsreload' => $return_url,
+                                               '$type' => 'wall-comment',
+                                               '$id' => $link_item['id'],
+                                               '$parent' => $link_item['id'],
+                                               '$profile_uid' =>  $owner_uid,
+                                               '$mylink' => $contact['url'],
+                                               '$mytitle' => t('This is you'),
+                                               '$myphoto' => $contact['thumb'],
+                                               '$comment' => t('Comment'),
+                                               '$submit' => t('Submit'),
+                                               '$preview' => t('Preview'),
+                                               '$sourceapp' => t($a->sourcename),
+                                               '$ww' => '',
+                                               '$rand_num' => random_digits(12)
+                                       ));
                                }
 
 
@@ -1772,27 +1755,24 @@ function photos_content(App $a) {
                                                '$comment' => $comment
                                        ));
 
-                                       /// @TODO merge into one if() ?
-                                       if ($can_post || can_write_wall($a, $owner_uid)) {
-                                               if ($item['last-child']) {
-                                                       $comments .= replace_macros($cmnt_tpl, array(
-                                                               '$return_path' => '',
-                                                               '$jsreload' => $return_url,
-                                                               '$type' => 'wall-comment',
-                                                               '$id' => $item['item_id'],
-                                                               '$parent' => $item['parent'],
-                                                               '$profile_uid' =>  $owner_uid,
-                                                               '$mylink' => $contact['url'],
-                                                               '$mytitle' => t('This is you'),
-                                                               '$myphoto' => $contact['thumb'],
-                                                               '$comment' => t('Comment'),
-                                                               '$submit' => t('Submit'),
-                                                               '$preview' => t('Preview'),
-                                                               '$sourceapp' => t($a->sourcename),
-                                                               '$ww' => '',
-                                                               '$rand_num' => random_digits(12)
-                                                       ));
-                                               }
+                                       if (($can_post || can_write_wall($a, $owner_uid)) && $item['last-child']) {
+                                               $comments .= replace_macros($cmnt_tpl, array(
+                                                       '$return_path' => '',
+                                                       '$jsreload' => $return_url,
+                                                       '$type' => 'wall-comment',
+                                                       '$id' => $item['item_id'],
+                                                       '$parent' => $item['parent'],
+                                                       '$profile_uid' =>  $owner_uid,
+                                                       '$mylink' => $contact['url'],
+                                                       '$mytitle' => t('This is you'),
+                                                       '$myphoto' => $contact['thumb'],
+                                                       '$comment' => t('Comment'),
+                                                       '$submit' => t('Submit'),
+                                                       '$preview' => t('Preview'),
+                                                       '$sourceapp' => t($a->sourcename),
+                                                       '$ww' => '',
+                                                       '$rand_num' => random_digits(12)
+                                               ));
                                        }
                                }
                        }
@@ -1802,9 +1782,10 @@ function photos_content(App $a) {
 
 
                $response_verbs = array('like');
-               if (feature_enabled($owner_uid,'dislike'))
+               if (feature_enabled($owner_uid, 'dislike')) {
                        $response_verbs[] = 'dislike';
-               $responses = get_responses($conv_responses,$response_verbs,'',$link_item);
+               }
+               $responses = get_responses($conv_responses,$response_verbs, '', $link_item);
 
                $photo_tpl = get_markup_template('photo_view.tpl');
 
@@ -1814,7 +1795,7 @@ function photos_content(App $a) {
                        $like_e = template_escape($like);
                        $dislike_e = template_escape($dislike);
                } else {
-                       $album_e = array($album_link,$ph[0]['album']);
+                       $album_e = array($album_link, $ph[0]['album']);
                        $tags_e = $tags;
                        $like_e = $like;
                        $dislike_e = $dislike;
@@ -1841,11 +1822,11 @@ function photos_content(App $a) {
                        '$paginate' => $paginate,
                ));
 
-               $a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
-               $a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
-               $a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
-               $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
-               $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
+               $a->page['htmlhead'] .= "\n" . '<meta name="twitter:card" content="photo" />' . "\n";
+               $a->page['htmlhead'] .= '<meta name="twitter:title" content="' . $photo["album"] . '" />' . "\n";
+               $a->page['htmlhead'] .= '<meta name="twitter:image" content="' . $photo["href"] . '" />' . "\n";
+               $a->page['htmlhead'] .= '<meta name="twitter:image:width" content="' . $photo["width"] . '" />' . "\n";
+               $a->page['htmlhead'] .= '<meta name="twitter:image:height" content="' . $photo["height"] . '" />' . "\n";
 
                return $o;
        }
@@ -1864,7 +1845,9 @@ function photos_content(App $a) {
                $a->set_pager_itemspage(20);
        }
 
-       $r = qu("SELECT `resource-id`, `id`, `filename`, type, `album`, max(`scale`) AS `scale` FROM `photo`
+       $r = qu("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
+               ANY_VALUE(`type`) AS `type`, ANY_VALUE(`album`) AS `album`, max(`scale`) AS `scale`,
+               ANY_VALUE(`created`) AS `created` 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']),