]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Features to src
[friendica.git] / mod / photos.php
index 67a8735a59e9e4035c74300f77e804740030cf89..a9ba835cfe5509adfeb3fe7f36d7cdae81d6c440 100644 (file)
@@ -1,8 +1,17 @@
 <?php
-
+/**
+ * @file mod/photos.php
+ */
+use Friendica\App;
+use Friendica\Content\Features;
+use Friendica\Core\System;
 use Friendica\Core\Config;
+use Friendica\Core\Worker;
+use Friendica\Database\DBM;
+use Friendica\Network\Probe;
+use Friendica\Object\Contact;
+use Friendica\Object\Photo;
 
-require_once 'include/Photo.php';
 require_once 'include/photos.php';
 require_once 'include/items.php';
 require_once 'include/acl_selectors.php';
@@ -11,7 +20,6 @@ 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';
 
 function photos_init(App $a) {
 
@@ -19,7 +27,7 @@ function photos_init(App $a) {
                auto_redir($a, $a->argv[1]);
        }
 
-       if ((get_config('system', 'block_public')) && (! local_user()) && (! remote_user())) {
+       if ((Config::get('system', 'block_public')) && (! local_user()) && (! remote_user())) {
                return;
        }
 
@@ -27,11 +35,11 @@ function photos_init(App $a) {
 
        if ($a->argc > 1) {
                $nick = $a->argv[1];
-               $user = qu("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
+               $user = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `blocked` = 0 LIMIT 1",
                        dbesc($nick)
                );
 
-               if (! dbm::is_result($user)) {
+               if (! DBM::is_result($user)) {
                        return;
                }
 
@@ -41,7 +49,7 @@ function photos_init(App $a) {
 
                $profile = get_profiledata_by_nick($nick, $a->profile_uid);
 
-               $account_type = account_type($profile);
+               $account_type = Contact::getAccountType($profile);
 
                $tpl = get_markup_template("vcard-widget.tpl");
 
@@ -94,7 +102,7 @@ function photos_init(App $a) {
                                '$title'    => t('Photo Albums'),
                                '$recent'   => t('Recent Photos'),
                                '$albums'   => $albums['albums'],
-                               '$baseurl'  => z_root(),
+                               '$baseurl'  => System::baseUrl(),
                                '$upload'   => array(t('Upload New Photos'), 'photos/' . $a->data['user']['nickname'] . '/upload'),
                                '$can_post' => $can_post
                        ));
@@ -151,11 +159,11 @@ function photos_post(App $a) {
                        }
                        if ($contact_id) {
 
-                               $r = qu("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
+                               $r = q("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)) {
+                               if (DBM::is_result($r)) {
                                        $can_post = true;
                                        $visitor = $contact_id;
                                }
@@ -168,12 +176,12 @@ function photos_post(App $a) {
                killme();
        }
 
-       $r = qu("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
+       $r = q("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 (! dbm::is_result($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();
@@ -190,11 +198,11 @@ function photos_post(App $a) {
                        return; // NOTREACHED
                }
 
-               $r = qu("SELECT `album` FROM `photo` WHERE `album` = '%s' AND `uid` = %d",
+               $r = q("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
@@ -265,7 +273,7 @@ function photos_post(App $a) {
                                        dbesc($album)
                                );
                        }
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                foreach ($r as $rr) {
                                        $res[] = "'" . dbesc($rr['rid']) . "'" ;
                                }
@@ -287,7 +295,7 @@ function photos_post(App $a) {
                        $r = q("SELECT `parent-uri` FROM `item` WHERE `resource-id` IN ( $str_res ) AND `uid` = %d",
                                intval($page_owner_uid)
                        );
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                foreach ($r as $rr) {
                                        q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d",
                                                dbesc(datetime_convert()),
@@ -302,7 +310,7 @@ function photos_post(App $a) {
                                        // send the notification upstream/downstream as the case may be
 
                                        if ($rr['visible']) {
-                                               proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
+                                               Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
                                        }
                                }
                        }
@@ -353,7 +361,7 @@ function photos_post(App $a) {
                                dbesc($a->argv[2])
                        );
                }
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        q("DELETE FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'",
                                intval($page_owner_uid),
                                dbesc($r[0]['resource-id'])
@@ -362,7 +370,7 @@ function photos_post(App $a) {
                                dbesc($r[0]['resource-id']),
                                intval($page_owner_uid)
                        );
-                       if (dbm::is_result($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()),
@@ -372,14 +380,14 @@ function photos_post(App $a) {
                                create_tags_from_itemuri($i[0]['uri'], $page_owner_uid);
                                delete_thread_uri($i[0]['uri'], $page_owner_uid);
 
-                               $url = App::get_baseurl();
+                               $url = System::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);
+                                       Worker::add(PRIORITY_HIGH, "Notifier", "drop", $drop_id);
                                }
                        }
                }
@@ -415,9 +423,9 @@ function photos_post(App $a) {
                                dbesc($resource_id),
                                intval($page_owner_uid)
                        );
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                $ph = new Photo($r[0]['data'], $r[0]['type']);
-                               if ($ph->is_valid()) {
+                               if ($ph->isValid()) {
                                        $rotate_deg = ( (intval($_POST['rotate']) == 1) ? 270 : 90 );
                                        $ph->rotate($rotate_deg);
 
@@ -467,7 +475,7 @@ function photos_post(App $a) {
                        dbesc($resource_id),
                        intval($page_owner_uid)
                );
-               if (dbm::is_result($p)) {
+               if (DBM::is_result($p)) {
                        $ext = $phototypes[$p[0]['type']];
                        $r = q("UPDATE `photo` SET `desc` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
                                dbesc($desc),
@@ -524,8 +532,8 @@ function photos_post(App $a) {
                        $arr['visible']       = $visibility;
                        $arr['origin']        = 1;
 
-                       $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]'
+                       $arr['body']          = '[url=' . System::baseUrl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $p[0]['resource-id'] . ']'
+                                               . '[img]' . System::baseUrl() . '/photo/' . $p[0]['resource-id'] . '-' . $p[0]['scale'] . '.'. $ext . '[/img]'
                                                . '[/url]';
 
                        $item_id = item_store($arr);
@@ -538,7 +546,7 @@ function photos_post(App $a) {
                                intval($page_owner_uid)
                        );
                }
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        $old_tag    = $r[0]['tag'];
                        $old_inform = $r[0]['inform'];
                }
@@ -605,7 +613,7 @@ function photos_post(App $a) {
                                                                                intval($page_owner_uid)
                                                                );
 
-                                                               if (! dbm::is_result($r)) {
+                                                               if (! DBM::is_result($r)) {
                                                                        //select someone by attag or nick and the name passed in
                                                                        $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
                                                                                        dbesc($name),
@@ -615,7 +623,7 @@ function photos_post(App $a) {
                                                                }
                                                        }
 
-                                                       if (dbm::is_result($r)) {
+                                                       if (DBM::is_result($r)) {
                                                                $newname = $r[0]['name'];
                                                                $profile = $r[0]['url'];
                                                                $notify = 'cid:' . $r[0]['id'];
@@ -639,7 +647,7 @@ function photos_post(App $a) {
                                                }
                                        } elseif (strpos($tag, '#') === 0) {
                                                $tagname = substr($tag, 1);
-                                               $str_tags .= '#[url=' . App::get_baseurl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
+                                               $str_tags .= '#[url=' . System::baseUrl() . "/search?tag=" . $tagname . ']' . $tagname . '[/url]';
                                        }
                                }
                        }
@@ -711,8 +719,8 @@ function photos_post(App $a) {
                                        $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=' . 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['body']          = sprintf( t('%1$s was tagged in %2$s by %3$s'), '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]', '[url=' . System::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=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . '[img]' . System::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");
@@ -722,12 +730,12 @@ function photos_post(App $a) {
                                        $arr['object'] .= '</link></object>' . "\n";
 
                                        $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>';
+                                               . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '</id>';
+                                       $arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="'.$p[0]['type'].'" href="' . System::baseUrl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.' . $ext . '" />') . '</link></target>';
 
                                        $item_id = item_store($arr);
                                        if ($item_id) {
-                                               proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $item_id);
+                                               Worker::add(PRIORITY_HIGH, "Notifier", "tag", $item_id);
                                        }
                                }
                        }
@@ -772,7 +780,7 @@ function photos_post(App $a) {
                dbesc($album),
                intval($page_owner_uid)
        );
-       if ((! dbm::is_result($r)) || ($album == t('Profile Photos'))) {
+       if ((! DBM::is_result($r)) || ($album == t('Profile Photos'))) {
                $visible = 1;
        } else {
                $visible = 0;
@@ -803,12 +811,12 @@ function photos_post(App $a) {
                $type       = $_FILES['userfile']['type'];
        }
        if ($type == "") {
-               $type = guess_image_type($filename);
+               $type = Photo::guessImageType($filename);
        }
 
        logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
 
-       $maximagesize = get_config('system','maximagesize');
+       $maximagesize = Config::get('system','maximagesize');
 
        if (($maximagesize) && ($filesize > $maximagesize)) {
                notice( sprintf(t('Image exceeds size limit of %s'), formatBytes($maximagesize)) . EOL);
@@ -830,27 +838,9 @@ function photos_post(App $a) {
 
        $imagedata = @file_get_contents($src);
 
-
-       $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'",
-                       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()) {
+       if (! $ph->isValid()) {
                logger('mod/photos.php: photos_post(): unable to process image' , LOGGER_DEBUG);
                notice( t('Unable to process image.') . EOL );
                @unlink($src);
@@ -862,7 +852,7 @@ function photos_post(App $a) {
        $exif = $ph->orient($src);
        @unlink($src);
 
-       $max_length = get_config('system', 'max_image_length');
+       $max_length = Config::get('system', 'max_image_length');
        if (! $max_length) {
                $max_length = MAX_IMAGE_LENGTH;
        }
@@ -906,7 +896,7 @@ function photos_post(App $a) {
 
        /// @TODO merge these 2 if() into one?
        if ($exif && $exif['GPS']) {
-               if (feature_enabled($channel_id,'photo_location')) {
+               if (Features::isEnabled($channel_id,'photo_location')) {
                        $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
                        $lon = getGps($exif['GPS']['GPSLongitude'], $exif['GPS']['GPSLongitudeRef']);
                }
@@ -941,8 +931,8 @@ function photos_post(App $a) {
        $arr['visible']       = $visible;
        $arr['origin']        = 1;
 
-       $arr['body']          = '[url=' . App::get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
-                               . '[img]' . App::get_baseurl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
+       $arr['body']          = '[url=' . System::baseUrl() . '/photos/' . $owner_record['nickname'] . '/image/' . $photo_hash . ']'
+                               . '[img]' . System::baseUrl() . "/photo/{$photo_hash}-{$smallest}.".$ph->getExt() . '[/img]'
                                . '[/url]';
 
        $item_id = item_store($arr);
@@ -950,7 +940,7 @@ function photos_post(App $a) {
        photo_albums($page_owner_uid, true);
 
        if ($visible) {
-               proc_run(PRIORITY_HIGH, "include/notifier.php", 'wall-new', $item_id);
+               Worker::add(PRIORITY_HIGH, "Notifier", 'wall-new', $item_id);
        }
 
        call_hooks('photo_post_end',intval($item_id));
@@ -976,14 +966,14 @@ function photos_content(App $a) {
        // photos/name/image/xxxxx/edit
 
 
-       if ((get_config('system', 'block_public')) && (! local_user()) && (! remote_user())) {
+       if ((Config::get('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 );
@@ -1045,7 +1035,7 @@ function photos_content(App $a) {
                                        intval($contact_id),
                                        intval($owner_uid)
                                );
-                               if (dbm::is_result($r)) {
+                               if (DBM::is_result($r)) {
                                        $can_post = true;
                                        $contact = $r[0];
                                        $remote_contact = true;
@@ -1073,7 +1063,7 @@ function photos_content(App $a) {
                                intval($contact_id),
                                intval($owner_uid)
                        );
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                $contact = $r[0];
                                $remote_contact = true;
                        }
@@ -1143,15 +1133,6 @@ function photos_content(App $a) {
                ));
 
                $usage_message = '';
-               $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'",
-                               intval($a->data['user']['uid'])
-                       );
-                       $usage_message = sprintf(t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
-               }
-
 
                // Private/public post links for the non-JS ACL form
                $private_post = 1;
@@ -1177,13 +1158,8 @@ function photos_content(App $a) {
 
                $tpl = get_markup_template('photos_upload.tpl');
 
-               if ($a->theme['template_engine'] === 'internal') {
-                       $albumselect_e = template_escape($albumselect);
-                       $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user)));
-               } else {
-                       $albumselect_e = $albumselect;
-                       $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
-               }
+               $albumselect_e = $albumselect;
+               $aclselect_e = (($visitor) ? '' : populate_acl($a->user));
 
                $o .= replace_macros($tpl,array(
                        '$pagename' => t('Upload Photos'),
@@ -1229,7 +1205,7 @@ function photos_content(App $a) {
                        intval($owner_uid),
                        dbesc($album)
                );
-               if (dbm::is_result($r)) {
+               if (DBM::is_result($r)) {
                        $a->set_pager_total(count($r));
                        $a->set_pager_itemspage(20);
                }
@@ -1258,11 +1234,7 @@ function photos_content(App $a) {
                                if ($can_post) {
                                        $edit_tpl = get_markup_template('album_edit.tpl');
 
-                                       if ($a->theme['template_engine'] === 'internal') {
-                                               $album_e = template_escape($album);
-                                       } else {
-                                               $album_e = $album;
-                                       }
+                                       $album_e = $album;
 
                                        $o .= replace_macros($edit_tpl,array(
                                                '$nametext' => t('New album name: '),
@@ -1288,7 +1260,7 @@ function photos_content(App $a) {
 
                $photos = array();
 
-               if (dbm::is_result($r))
+               if (DBM::is_result($r))
                        $twist = 'rotright';
                        foreach ($r as $rr) {
                                if ($twist == 'rotright') {
@@ -1299,13 +1271,8 @@ function photos_content(App $a) {
 
                                $ext = $phototypes[$rr['type']];
 
-                               if ($a->theme['template_engine'] === 'internal') {
-                                       $imgalt_e = template_escape($rr['filename']);
-                                       $desc_e = template_escape($rr['desc']);
-                               } else {
-                                       $imgalt_e = $rr['filename'];
-                                       $desc_e = $rr['desc'];
-                               }
+                               $imgalt_e = $rr['filename'];
+                               $desc_e = $rr['desc'];
 
                                $photos[] = array(
                                        'id' => $rr['id'],
@@ -1350,13 +1317,13 @@ function photos_content(App $a) {
                        dbesc($datum)
                );
 
-               if (! dbm::is_result($ph)) {
+               if (! DBM::is_result($ph)) {
                        $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
                                LIMIT 1",
                                intval($owner_uid),
                                dbesc($datum)
                        );
-                       if (dbm::is_result($ph)) {
+                       if (DBM::is_result($ph)) {
                                notice(t('Permission denied. Access to this item may be restricted.'));
                        } else {
                                notice(t('Photo not available') . EOL );
@@ -1376,13 +1343,13 @@ function photos_content(App $a) {
                        else
                                $order = 'DESC';
 
-                       $prvnxt = qu("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0
+                       $prvnxt = q("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)
                        );
 
-                       if (dbm::is_result($prvnxt)) {
+                       if (DBM::is_result($prvnxt)) {
                                foreach ($prvnxt as $z => $entry) {
                                        if ($entry['resource-id'] == $ph[0]['resource-id']) {
                                                $prv = $z - 1;
@@ -1473,10 +1440,10 @@ function photos_content(App $a) {
 
                $map = null;
 
-               if (dbm::is_result($linked_items)) {
+               if (DBM::is_result($linked_items)) {
                        $link_item = $linked_items[0];
 
-                       $r = qu("SELECT COUNT(*) AS `total`
+                       $r = q("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
@@ -1488,12 +1455,12 @@ function photos_content(App $a) {
 
                        );
 
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
                                $a->set_pager_total($r[0]['total']);
                        }
 
 
-                       $r = qu("SELECT `item`.*, `item`.`id` AS `item_id`,
+                       $r = q("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`
@@ -1570,15 +1537,9 @@ function photos_content(App $a) {
                                $public_post_link = '&public=1';
                        }
 
-                       if ($a->theme['template_engine'] === 'internal') {
-                               $album_e = template_escape($ph[0]['album']);
-                               $caption_e = template_escape($ph[0]['desc']);
-                               $aclselect_e = template_escape(populate_acl($ph[0]));
-                       } else {
-                               $album_e = $ph[0]['album'];
-                               $caption_e = $ph[0]['desc'];
-                               $aclselect_e = populate_acl($ph[0]);
-                       }
+                       $album_e = $ph[0]['album'];
+                       $caption_e = $ph[0]['desc'];
+                       $aclselect_e = populate_acl($ph[0]);
 
                        $edit = replace_macros($edit_tpl, array(
                                '$id' => $ph[0]['id'],
@@ -1624,14 +1585,14 @@ function photos_content(App $a) {
                                $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") : ''),
+                                       '$nolike' => (Features::isEnabled(local_user(), 'dislike') ? t("I don't like this \x28toggle\x29") : ''),
                                        '$wait' => t('Please wait'),
                                        '$return_path' => $a->query_string,
                                ));
                        }
 
                        $comments = '';
-                       if (! dbm::is_result($r)) {
+                       if (! DBM::is_result($r)) {
                                if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) {
                                        $comments .= replace_macros($cmnt_tpl, array(
                                                '$return_path' => '',
@@ -1665,7 +1626,7 @@ function photos_content(App $a) {
                        );
 
                        // display comments
-                       if (dbm::is_result($r)) {
+                       if (DBM::is_result($r)) {
 
                                foreach ($r as $item) {
                                        builtin_activity_puller($item, $conv_responses);
@@ -1730,15 +1691,9 @@ function photos_content(App $a) {
                                                'delete' => t('Delete'),
                                        );
 
-                                       if ($a->theme['template_engine'] === 'internal') {
-                                               $name_e = template_escape($profile_name);
-                                               $title_e = template_escape($item['title']);
-                                               $body_e = template_escape(bbcode($item['body']));
-                                       } else {
-                                               $name_e = $profile_name;
-                                               $title_e = $item['title'];
-                                               $body_e = bbcode($item['body']);
-                                       }
+                                       $name_e = $profile_name;
+                                       $title_e = $item['title'];
+                                       $body_e = bbcode($item['body']);
 
                                        $comments .= replace_macros($template,array(
                                                '$id' => $item['item_id'],
@@ -1781,24 +1736,17 @@ function photos_content(App $a) {
 
 
                $response_verbs = array('like');
-               if (feature_enabled($owner_uid, 'dislike')) {
+               if (Features::isEnabled($owner_uid, 'dislike')) {
                        $response_verbs[] = 'dislike';
                }
                $responses = get_responses($conv_responses,$response_verbs, '', $link_item);
 
                $photo_tpl = get_markup_template('photo_view.tpl');
 
-               if ($a->theme['template_engine'] === 'internal') {
-                       $album_e = array($album_link,template_escape($ph[0]['album']));
-                       $tags_e = template_escape($tags);
-                       $like_e = template_escape($like);
-                       $dislike_e = template_escape($dislike);
-               } else {
-                       $album_e = array($album_link, $ph[0]['album']);
-                       $tags_e = $tags;
-                       $like_e = $like;
-                       $dislike_e = $dislike;
-               }
+               $album_e = array($album_link, $ph[0]['album']);
+               $tags_e = $tags;
+               $like_e = $like;
+               $dislike_e = $dislike;
 
                $o .= replace_macros($photo_tpl, array(
                        '$id' => $ph[0]['id'],
@@ -1833,18 +1781,18 @@ function photos_content(App $a) {
        // Default - show recent photos with upload link (if applicable)
        //$o = '';
 
-       $r = qu("SELECT `resource-id`, max(`scale`) AS `scale` FROM `photo` WHERE `uid` = %d AND `album` != '%s' AND `album` != '%s'
+       $r = q("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'),
                dbesc( t('Contact Photos'))
        );
-       if (dbm::is_result($r)) {
+       if (DBM::is_result($r)) {
                $a->set_pager_total(count($r));
                $a->set_pager_itemspage(20);
        }
 
-       $r = qu("SELECT `resource-id`, ANY_VALUE(`id`) AS `id`, ANY_VALUE(`filename`) AS `filename`,
+       $r = q("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'
@@ -1857,7 +1805,7 @@ function photos_content(App $a) {
        );
 
        $photos = array();
-       if (dbm::is_result($r)) {
+       if (DBM::is_result($r)) {
                $twist = 'rotright';
                foreach ($r as $rr) {
                        //hide profile photos to others
@@ -1871,13 +1819,8 @@ function photos_content(App $a) {
 
                        $ext = $phototypes[$rr['type']];
 
-                       if ($a->theme['template_engine'] === 'internal') {
-                               $alt_e = template_escape($rr['filename']);
-                               $name_e = template_escape($rr['album']);
-                       } else {
-                               $alt_e = $rr['filename'];
-                               $name_e = $rr['album'];
-                       }
+                       $alt_e = $rr['filename'];
+                       $name_e = $rr['album'];
 
                        $photos[] = array(
                                'id'            => $rr['id'],