]> git.mxchange.org Git - friendica.git/blobdiff - mod/photos.php
Implement Smarty3
[friendica.git] / mod / photos.php
index af40ea30371a43f4e89a1dfdaf56e33487fdcc2d..8ac4d8590371f1ed89da07f1d63221e261d7cc58 100644 (file)
@@ -4,14 +4,18 @@ 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');
 
 
 function photos_init(&$a) {
 
+       if($a->argc > 1)
+               auto_redir($a, $a->argv[1]);
 
        if((get_config('system','block_public')) && (! local_user()) && (! remote_user())) {
                return;
        }
+
        $o = '';
 
        if($a->argc > 1) {
@@ -25,20 +29,21 @@ function photos_init(&$a) {
 
                $a->data['user'] = $r[0];
 
+               $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_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg') . '" alt="' . $a->data['user']['username'] . '" /></div>';
+               $o .= '</div>';
+
+
                $sql_extra = permissions_sql($a->data['user']['uid']);
 
-               $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra ",
+               $albums = q("SELECT distinct(`album`) AS `album` FROM `photo` WHERE `uid` = %d $sql_extra order by created desc",
                        intval($a->data['user']['uid'])
                );
 
                if(count($albums)) {
                        $a->data['albums'] = $albums;
 
-                       $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_cached_avatar_image($a->get_baseurl() . '/photo/profile/' . $a->data['user']['uid'] . '.jpg') . '" alt="' . $a->data['user']['username'] . '" /></div>';
-                       $o .= '</div>';
-
                        $albums_visible = ((intval($a->data['user']['hidewall']) && (! local_user()) && (! remote_user())) ? false : true);     
 
                        if($albums_visible) {
@@ -101,13 +106,25 @@ function photos_post(&$a) {
                $can_post = true;
        else {
                if($community_page && remote_user()) {
-                       $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                               intval(remote_user()),
-                               intval($page_owner_uid)
-                       );
-                       if(count($r)) {
-                               $can_post = true;
-                               $visitor = remote_user();
+                       $cid = 0;
+                       if(is_array($_SESSION['remote'])) {
+                               foreach($_SESSION['remote'] as $v) {
+                                       if($v['uid'] == $page_owner_uid) {
+                                               $cid = $v['cid'];
+                                               break;
+                                       }
+                               }
+                       }
+                       if($cid) {
+
+                               $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
+                                       intval($cid),
+                                       intval($page_owner_uid)
+                               );
+                               if(count($r)) {
+                                       $can_post = true;
+                                       $visitor = $cid;
+                               }
                        }
                }
        }
@@ -469,7 +486,25 @@ function photos_post(&$a) {
                                                                        intval($profile_uid)
                                                                );
                                                        }
-                                                       elseif(strstr($name,'_') || strstr($name,' ')) {
+                                                       else {
+                                                               $newname = str_replace('_',' ',$name);
+
+                                                               //select someone from this user's contacts by name
+                                                               $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
+                                                                               dbesc($newname),
+                                                                               intval($page_owner_uid)
+                                                               );
+
+                                                               if(! $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),
+                                                                                       dbesc($name),
+                                                                                       intval($page_owner_uid)
+                                                                       );
+                                                               }
+                                                       }
+/*                                                     elseif(strstr($name,'_') || strstr($name,' ')) {
                                                                $newname = str_replace('_',' ',$name);
                                                                $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
                                                                        dbesc($newname),
@@ -482,7 +517,7 @@ function photos_post(&$a) {
                                                                        dbesc($name),
                                                                        intval($page_owner_uid)
                                                                );
-                                                       }
+                                                       }*/
                                                        if(count($r)) {
                                                                $newname = $r[0]['name'];
                                                                $profile = $r[0]['url'];
@@ -569,7 +604,7 @@ function photos_post(&$a) {
                                        $arr['tag']           = $tagged[4];
                                        $arr['inform']        = $tagged[2];
                                        $arr['origin']        = 1;
-                                       $arr['body']          = '[url=' . $tagged[1] . ']' . $tagged[0] . '[/url]' . ' ' . t('was tagged in a') . ' ' . '[url=' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . ']' . t('photo') . '[/url]' . ' ' . t('by') . ' ' . '[url=' . $owner_record['url'] . ']' . $owner_record['name'] . '[/url]' ;
+                                       $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['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
@@ -871,6 +906,7 @@ function photos_content(&$a) {
        $visitor        = 0;
        $contact        = null;
        $remote_contact = false;
+       $contact_id     = 0;
 
        $owner_uid = $a->data['user']['uid'];
 
@@ -880,15 +916,26 @@ function photos_content(&$a) {
                $can_post = true;
        else {
                if($community_page && remote_user()) {
-                       $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                               intval(remote_user()),
-                               intval($owner_uid)
-                       );
-                       if(count($r)) {
-                               $can_post = true;
-                               $contact  = $r[0];
-                               $remote_contact = true;
-                               $visitor = remote_user();
+                       if(is_array($_SESSION['remote'])) {
+                               foreach($_SESSION['remote'] as $v) {
+                                       if($v['uid'] == $owner_uid) {
+                                               $contact_id = $v['cid'];
+                                               break;
+                                       }
+                               }
+                       }
+                       if($contact_id) {
+
+                               $r = q("SELECT `uid` FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
+                                       intval($contact_id),
+                                       intval($owner_uid)
+                               );
+                               if(count($r)) {
+                                       $can_post = true;
+                                       $contact = $r[0];
+                                       $remote_contact = true;
+                                       $visitor = $cid;
+                               }
                        }
                }
        }
@@ -896,15 +943,25 @@ function photos_content(&$a) {
        // perhaps they're visiting - but not a community page, so they wouldn't have write access
 
        if(remote_user() && (! $visitor)) {
-               $contact_id = $_SESSION['visitor_id'];
-               $groups = init_groups_visitor($contact_id);
-               $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
-                       intval(remote_user()),
-                       intval($owner_uid)
-               );
-               if(count($r)) {
-                       $contact = $r[0];
-                       $remote_contact = true;
+               $contact_id = 0;
+               if(is_array($_SESSION['remote'])) {
+                       foreach($_SESSION['remote'] as $v) {
+                               if($v['uid'] == $owner_uid) {
+                                       $contact_id = $v['cid'];
+                                       break;
+                               }
+                       }
+               }
+               if($contact_id) {
+                       $groups = init_groups_visitor($contact_id);
+                       $r = q("SELECT * FROM `contact` WHERE `blocked` = 0 AND `pending` = 0 AND `id` = %d AND `uid` = %d LIMIT 1",
+                               intval($contact_id),
+                               intval($owner_uid)
+                       );
+                       if(count($r)) {
+                               $contact = $r[0];
+                               $remote_contact = true;
+                       }
                }
        }
 
@@ -970,22 +1027,28 @@ function photos_content(&$a) {
                $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'])
-               );
-
-
+               $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 );
                }
-               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');
+
+               if($a->theme['template_engine'] === 'internal') {
+                       $albumselect_e = template_escape($albumselect);
+                       $aclselect_e = (($visitor) ? '' : template_escape(populate_acl($a->user, $celeb)));
+               }
+               else {
+                       $albumselect_e = $albumselect;
+                       $aclselect_e = (($visitor) ? '' : populate_acl($a->user, $celeb));
+               }
+
                $o .= replace_macros($tpl,array(
                        '$pagename' => t('Upload Photos'),
                        '$sessid' => session_id(),
@@ -994,9 +1057,9 @@ function photos_content(&$a) {
                        '$newalbum' => t('New album name: '),
                        '$existalbumtext' => t('or existing album name: '),
                        '$nosharetext' => t('Do not show a status post for this upload'),
-                       '$albumselect' => template_escape($albumselect),
+                       '$albumselect' => $albumselect_e,
                        '$permissions' => t('Permissions'),
-                       '$aclselect' => (($visitor) ? '' : template_escape(populate_acl($a->user, $celeb))),
+                       '$aclselect' => $aclselect_e,
                        '$uploader' => $ret['addon_text'],
                        '$default' => (($ret['default_upload']) ? $default_upload : ''),
                        '$uploadurl' => $ret['post_url']
@@ -1020,8 +1083,13 @@ function photos_content(&$a) {
                        $a->set_pager_itemspage(20);
                }
 
+               if($_GET['order'] === 'posted')
+                       $order = 'ASC';
+               else
+                       $order = 'DESC';
+
                $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s' 
-                       AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` DESC LIMIT %d , %d",
+                       AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
                        intval($owner_uid),
                        dbesc($album),
                        intval($a->pager['start']),
@@ -1034,10 +1102,18 @@ function photos_content(&$a) {
                        if(($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) {
                                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;
+                                       }
+
                                        $o .= replace_macros($edit_tpl,array(
                                                '$nametext' => t('New album name: '),
                                                '$nickname' => $a->data['user']['nickname'],
-                                               '$album' => template_escape($album),
+                                               '$album' => $album_e,
                                                '$hexalbum' => bin2hex($album),
                                                '$submit' => t('Submit'),
                                                '$dropsubmit' => t('Delete Album')
@@ -1055,10 +1131,17 @@ function photos_content(&$a) {
                        }
                }
 
+               if($_GET['order'] === 'posted')
+                       $o .=  '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '" >' . t('Show Newest First') . '</a></div>';
+               else
+                       $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted" >' . t('Show Oldest First') . '</a></div>';
+
+
                if($can_post) {
                        $o .= '<div class="photos-upload-link" ><a href="' . $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/upload/' . bin2hex($album) . '" >' . t('Upload New Photos') . '</a></div>';
                }
 
+
                $tpl = get_markup_template('photo_album.tpl');
                if(count($r))
                        $twist = 'rotright';
@@ -1070,14 +1153,24 @@ function photos_content(&$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'];
+                               }
+
                                $o .= replace_macros($tpl,array(
                                        '$id' => $rr['id'],
                                        '$twist' => ' ' . $twist . rand(2,4),
-                                       '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
+                                       '$photolink' => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id']
+                                               . (($_GET['order'] === 'posted') ? '?f=&order=posted' : ''),
                                        '$phototitle' => t('View Photo'),
                                        '$imgsrc' => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . $rr['scale'] . '.' .$ext,
-                                       '$imgalt' => template_escape($rr['filename']),
-                                       '$desc'=> template_escape($rr['desc'])
+                                       '$imgalt' => $imgalt_e,
+                                       '$desc'=> $desc_e
                                ));
 
                }
@@ -1118,8 +1211,14 @@ function photos_content(&$a) {
                $prevlink = '';
                $nextlink = '';
 
+               if($_GET['order'] === 'posted')
+                       $order = 'ASC';
+               else
+                       $order = 'DESC';
+
+
                $prvnxt = q("SELECT `resource-id` FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `scale` = 0 
-                       $sql_extra ORDER BY `created` DESC ",
+                       $sql_extra ORDER BY `created` $order ",
                        dbesc($ph[0]['album']),
                        intval($owner_uid)
                ); 
@@ -1137,8 +1236,8 @@ function photos_content(&$a) {
                                }
                        }
                        $edit_suffix = ((($cmd === 'edit') && ($can_post)) ? '/edit' : '');
-                       $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix;
-                       $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix;
+                       $prevlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$prv]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
+                       $nextlink = $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $prvnxt[$nxt]['resource-id'] . $edit_suffix . (($_GET['order'] === 'posted') ? '?f=&order=posted' : '');
                }
 
 
@@ -1197,6 +1296,12 @@ function photos_content(&$a) {
 
                // Do we have an item for this photo?
 
+               // FIXME! - replace following code to display the conversation with our normal 
+               // conversation functions so that it works correctly and tracks changes
+               // in the evolving conversation code.
+               // The difference is that we won't be displaying the conversation head item
+               // as a "post" but displaying instead the photo it is linked to
+
                $linked_items = q("SELECT * FROM `item` WHERE `resource-id` = '%s' $sql_extra LIMIT 1",
                        dbesc($datum)
                );
@@ -1266,20 +1371,32 @@ function photos_content(&$a) {
                $edit = Null;
                if(($cmd === 'edit') && ($can_post)) {
                        $edit_tpl = get_markup_template('photo_edit.tpl');
+
+                       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]);
+                       }
+
                        $edit = replace_macros($edit_tpl, array(
                                '$id' => $ph[0]['id'],
                                '$rotatecw' => t('Rotate CW (right)'),
                                '$rotateccw' => t('Rotate CCW (left)'),
-                               '$album' => template_escape($ph[0]['album']),
+                               '$album' => $album_e,
                                '$newalbum' => t('New album name'), 
                                '$nickname' => $a->data['user']['nickname'],
                                '$resource_id' => $ph[0]['resource-id'],
                                '$capt_label' => t('Caption'),
-                               '$caption' => template_escape($ph[0]['desc']),
+                               '$caption' => $caption_e,
                                '$tag_label' => t('Add a Tag'),
                                '$tags' => $link_item['tag'],
                                '$permissions' => t('Permissions'),
-                               '$aclselect' => template_escape(populate_acl($ph[0])),
+                               '$aclselect' => $aclselect_e,
                                '$help_tags' => t('Example: @bob, @Barbara_Jensen, @jim@example.com, #California, #camping'),
                                '$item_id' => ((count($linked_items)) ? $link_item['id'] : 0),
                                '$submit' => t('Submit'),
@@ -1324,7 +1441,9 @@ function photos_content(&$a) {
                                                        '$comment' => t('Comment'),
                                                        '$submit' => t('Submit'),
                                                        '$preview' => t('Preview'),
-                                                       '$ww' => ''
+                                                       '$sourceapp' => t($a->sourcename),
+                                                       '$ww' => '',
+                                                       '$rand_num' => random_digits(12)
                                                ));
                                        }
                                }
@@ -1336,6 +1455,8 @@ function photos_content(&$a) {
                        $like = '';
                        $dislike = '';
 
+
+
                        // display comments
                        if(count($r)) {
 
@@ -1363,7 +1484,10 @@ function photos_content(&$a) {
                                                        '$myphoto' => $contact['thumb'],
                                                        '$comment' => t('Comment'),
                                                        '$submit' => t('Submit'),
-                                                       '$ww' => ''
+                                                       '$preview' => t('Preview'),
+                                                       '$sourceapp' => t($a->sourcename),
+                                                       '$ww' => '',
+                                                       '$rand_num' => random_digits(12)
                                                ));
                                        }
                                }
@@ -1379,26 +1503,6 @@ function photos_content(&$a) {
 
                                        $redirect_url = $a->get_baseurl() . '/redir/' . $item['cid'] ;
                        
-                                       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'),
-                                                               '$ww' => ''
-                                                       ));
-                                               }
-                                       }
-
 
                                        if(local_user() && ($item['contact-uid'] == local_user()) 
                                                && ($item['network'] == 'dfrn') && (! $item['self'] )) {
@@ -1419,23 +1523,57 @@ function photos_content(&$a) {
 
                                        $drop = '';
 
-                                       if(($item['contact-id'] == remote_user()) || ($item['uid'] == local_user()))
+                                       if(($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()))
                                                $drop = replace_macros(get_markup_template('photo_drop.tpl'), array('$id' => $item['id'], '$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']);
+                                       }
+
                                        $comments .= replace_macros($template,array(
                                                '$id' => $item['item_id'],
                                                '$profile_url' => $profile_link,
-                                               '$name' => template_escape($profile_name),
+                                               '$name' => $name_e,
                                                '$thumb' => $profile_avatar,
                                                '$sparkle' => $sparkle,
-                                               '$title' => template_escape($item['title']),
-                                               '$body' => template_escape(bbcode($item['body'])),
+                                               '$title' => $title_e,
+                                               '$body' => $body_e,
                                                '$ago' => relative_date($item['created']),
                                                '$indent' => (($item['parent'] != $item['item_id']) ? ' comment' : ''),
                                                '$drop' => $drop,
                                                '$comment' => $comment
                                        ));
+
+                                       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)
+                                                       ));
+                                               }
+                                       }
                                }
                        }
 
@@ -1443,20 +1581,34 @@ function photos_content(&$a) {
                }
                
                $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;
+               }
+
                $o .= replace_macros($photo_tpl, array(
                        '$id' => $ph[0]['id'],
-                       '$album' => array($album_link,template_escape($ph[0]['album'])),
+                       '$album' => $album_e,
                        '$tools' => $tools,
                        '$lock' => $lock,
                        '$photo' => $photo,
                        '$prevlink' => $prevlink,
                        '$nextlink' => $nextlink,
                        '$desc' => $ph[0]['desc'],
-                       '$tags' => template_escape($tags),
+                       '$tags' => $tags_e,
                        '$edit' => $edit,       
                        '$likebuttons' => $likebuttons,
-                       '$like' => template_escape($like),
-                       '$dislike' => template_escape($dislike),
+                       '$like' => $like_e,
+                       '$dislike' => $dikslike_e,
                        '$comments' => $comments,
                        '$paginate' => $paginate,
                ));
@@ -1500,16 +1652,25 @@ function photos_content(&$a) {
                                $twist = 'rotright';
                        $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'];
+                       }
+
                        $photos[] = array(
                                'id'       => $rr['id'],
                                'twist'    => ' ' . $twist . rand(2,4),
                                'link'          => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/image/' . $rr['resource-id'],
                                'title'         => t('View Photo'),
                                'src'           => $a->get_baseurl() . '/photo/' . $rr['resource-id'] . '-' . ((($rr['scale']) == 6) ? 4 : $rr['scale']) . '.' . $ext,
-                               'alt'           => template_escape($rr['filename']),
+                               'alt'           => $alt_e,
                                'album' => array(
                                        'link'  => $a->get_baseurl() . '/photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($rr['album']),
-                                       'name'  => template_escape($rr['album']),
+                                       'name'  => $name_e,
                                        'alt'   => t('View Album'),
                                ),
                                
@@ -1518,7 +1679,13 @@ function photos_content(&$a) {
        }
        
        $tpl = get_markup_template('photos_recent.tpl'); 
-       $o .= replace_macros($tpl,array(
+
+       $includes = array(
+               '$photo_top' => 'photo_top.tpl',
+       );
+       $includes = set_template_includes($a->theme['template_engine'], $includes);
+
+       $o .= replace_macros($tpl,$includes + array(
                '$title' => t('Recent Photos'),
                '$can_post' => $can_post,
                '$upload' => array(t('Upload New Photos'), $a->get_baseurl().'/photos/'.$a->data['user']['nickname'].'/upload'),