Commit 6e91bee0 authored by Mario's avatar Mario
Browse files

some work on streamlining mod photos

parent c6d872d1
Pipeline #429042 passed with stage
in 3 minutes and 2 seconds
......@@ -42,9 +42,6 @@ class Activity {
if ($x['type'] === ACTIVITY_OBJ_EVENT) {
return self::fetch_event($x);
}
if ($x['type'] === ACTIVITY_OBJ_PHOTO) {
return self::fetch_image($x);
}
call_hooks('encode_object', $x);
}
......@@ -194,6 +191,7 @@ class Activity {
}
static function fetch_image($x) {
$ret = [
'type' => 'Image',
'id' => $x['id'],
......@@ -2264,7 +2262,6 @@ class Activity {
$s['app'] = escape_tags($generator['name']);
}
if (!$response_activity) {
$a = self::decode_taxonomy($act->obj);
if ($a) {
......@@ -2399,7 +2396,7 @@ class Activity {
}
if ($act->obj['type'] === 'Image') {
if ($act->obj['type'] === 'Image' && strpos($s['body'],'zrl=') === false) {
$ptr = null;
......
......@@ -1142,6 +1142,7 @@ class Libzot {
}
$deliveries = null;
if (array_key_exists('recipients', $env) && count($env['recipients'])) {
......
......@@ -29,7 +29,7 @@ class Search extends Controller {
require_once('include/conversation.php');
require_once('include/items.php');
require_once('include/security.php');
$format = (($_REQUEST['format']) ? $_REQUEST['format'] : '');
if ($format !== '') {
......@@ -38,10 +38,10 @@ class Search extends Controller {
$observer = App::get_observer();
$observer_hash = (($observer) ? $observer['xchan_hash'] : '');
$o = '<div class="generic-content-wrapper-styled">' . "\r\n";
$o .= '<h3>' . t('Search') . '</h3>';
$o = '<div class="generic-content-wrapper-styled">' . "\r\n";
$o .= '<h2>' . t('Search') . '</h2>';
if (x(App::$data, 'search'))
$search = trim(App::$data['search']);
......
......@@ -4,6 +4,9 @@
* @brief Functions related to photo handling.
*/
use Zotlabs\Lib\Activity;
require_once('include/permissions.php');
require_once('include/items.php');
require_once('include/photo/photo_driver.php');
......@@ -259,7 +262,7 @@ function photo_upload($channel, $observer, $args) {
$link = array();
$r0 = $ph->save($p);
$link[0] = array(
$url[0] = array(
'rel' => 'alternate',
'type' => $type,
'href' => z_root() . '/photo/' . $photo_hash . '-0.' . $ph->getExt(),
......@@ -278,7 +281,7 @@ function photo_upload($channel, $observer, $args) {
$ph->scaleImage(1024);
$r1 = $ph->storeThumbnail($p, PHOTO_RES_1024);
$link[1] = array(
$url[1] = array(
'rel' => 'alternate',
'type' => $type,
'href' => z_root() . '/photo/' . $photo_hash . '-1.' . $ph->getExt(),
......@@ -292,7 +295,7 @@ function photo_upload($channel, $observer, $args) {
$ph->scaleImage(640);
$r2 = $ph->storeThumbnail($p, PHOTO_RES_640);
$link[2] = array(
$url[2] = array(
'rel' => 'alternate',
'type' => $type,
'href' => z_root() . '/photo/' . $photo_hash . '-2.' . $ph->getExt(),
......@@ -306,7 +309,7 @@ function photo_upload($channel, $observer, $args) {
$ph->scaleImage(320);
$r3 = $ph->storeThumbnail($p, PHOTO_RES_320);
$link[3] = array(
$url[3] = array(
'rel' => 'alternate',
'type' => $type,
'href' => z_root() . '/photo/' . $photo_hash . '-3.' . $ph->getExt(),
......@@ -353,7 +356,7 @@ function photo_upload($channel, $observer, $args) {
$large_photos = feature_enabled($channel['channel_id'], 'large_photos');
linkify_tags($args['body'], $channel_id);
$found_tags = linkify_tags($args['body'], $channel_id);
if($large_photos) {
$scale = 1;
......@@ -382,22 +385,62 @@ function photo_upload($channel, $observer, $args) {
. $tag . z_root() . "/photo/{$photo_hash}-{$scale}." . $ph->getExt() . '[/zmg]'
. '[/zrl]';
// Create item object
$object = array(
'type' => ACTIVITY_OBJ_PHOTO,
'title' => $title,
'created' => $p['created'],
'edited' => $p['edited'],
'id' => z_root() . '/item/' . $photo_hash,
'link' => $link,
'body' => $summary
);
$url[] = [
'type' => 'Link',
'mediaType' => 'text/html',
'href' => z_root() . '/photos/' . $channel['channel_address'] . '/image/' . $photo_hash
];
$post_tags = [];
if($found_tags) {
foreach($found_tags as $result) {
$success = $result['success'];
if($success['replaced']) {
$post_tags[] = array(
'uid' => $channel['channel_id'],
'ttype' => $success['termtype'],
'otype' => TERM_OBJ_POST,
'term' => $success['term'],
'url' => $success['url']
);
}
}
}
$target = array(
'type' => ACTIVITY_OBJ_ALBUM,
'title' => (($album) ? $album : '/'),
'id' => z_root() . '/photos/' . $channel['channel_address'] . '/album/' . bin2hex($album)
);
//// Create item object
$object = [
'type' => 'Image',
'name' => $title,
'summary' => $p['description'],
'published' => datetime_convert('UTC','UTC',$p['created'],ATOM_TIME),
'updated' => datetime_convert('UTC','UTC',$p['edited'],ATOM_TIME),
// This is a placeholder and will get over-ridden by the item mid, which is critical for sharing as a conversational item over activitypub
'id' => z_root() . '/photo/' . $photo_hash,
'url' => $url,
'source' => [ 'content' => $summary, 'mediaType' => 'text/bbcode' ],
'content' => bbcode($summary)
];
if ($post_tags) {
$object['tag'] = Activity::encode_taxonomy(['term' => $post_tags]);
}
$public = (($ac['allow_cid'] || $ac['allow_gid'] || $ac['deny_cid'] || $ac['deny_gid']) ? false : true);
if ($public) {
$object['to'] = [ ACTIVITY_PUBLIC_INBOX ];
$object['cc'] = [ z_root() . '/followers/' . $channel['channel_address'] ];
}
else {
$object['to'] = Activity::map_acl(array_merge($ac, ['item_private' => 1 - intval($public) ]));
}
$target = [
'type' => 'orderedCollection',
'name' => ((strlen($album)) ? $album : '/'),
'id' => z_root() . '/album/' . $channel['channel_address'] . ((isset($args['folder'])) ? '/' . $args['folder'] : EMPTY_STR)
];
// Create item container
if($args['item']) {
......@@ -415,7 +458,9 @@ function photo_upload($channel, $observer, $args) {
$item['tgt_type'] = ACTIVITY_OBJ_ALBUM;
$item['target'] = json_encode($target);
if ($post_tags) {
$arr['term'] = $post_tags;
}
$force = true;
}
$r = q("select id, edited from item where mid = '%s' and uid = %d limit 1",
......@@ -469,6 +514,10 @@ function photo_upload($channel, $observer, $args) {
'body' => $summary
];
if ($post_tags) {
$arr['term'] = $post_tags;
}
$arr['plink'] = $mid;
if($lat && $lon)
......
......@@ -1714,19 +1714,33 @@ function prepare_body(&$item,$attach = false,$opts = false) {
$photo = '';
$is_photo = ((($item['verb'] === ACTIVITY_POST) && ($item['obj_type'] === ACTIVITY_OBJ_PHOTO)) ? true : false);
if($is_photo) {
if ($is_photo) {
$object = json_decode($item['obj'],true);
$ptr = null;
if (array_key_exists('url',$object) && is_array($object['url'])) {
if (array_key_exists(0,$object['url'])) {
foreach ($object['url'] as $link) {
if(array_key_exists('width',$link) && $link['width'] >= 640 && $link['width'] <= 1024) {
$ptr = $link;
}
}
if (! $ptr) {
$ptr = $object['url'][0];
}
}
else {
$ptr = $object['url'];
}
// if original photo width is <= 640px prepend it to item body
if($object['link'][0]['width'] && $object['link'][0]['width'] <= 640) {
$s .= '<div class="inline-photo-item-wrapper"><a href="' . zid(rawurldecode($object['id'])) . '" target="_blank" rel="nofollow noopener" ><img class="inline-photo-item" style="max-width:' . $object['link'][0]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['link'][0]['href'])) . '"></a></div>' . $s;
}
// if original photo width is > 640px make it a cover photo
if($object['link'][0]['width'] && $object['link'][0]['width'] > 640) {
$scale = ((($object['link'][1]['width'] == 1024) || ($object['link'][1]['height'] == 1024)) ? 1 : 0);
$photo = '<a href="' . zid(rawurldecode($object['id'])) . '" target="_blank" rel="nofollow noopener"><img style="max-width:' . $object['link'][$scale]['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($object['link'][$scale]['href'])) . '"></a>';
// if original photo width is > 640px make it a cover photo
if ($ptr) {
if (array_key_exists('width',$ptr) && $ptr['width'] > 640) {
$photo = '<a href="' . zid(rawurldecode($object['id'])) . '" target="_blank" rel="nofollow noopener"><img style="max-width:' . $ptr['width'] . 'px; width:100%; height:auto;" src="' . zid(rawurldecode($ptr['href'])) . '"></a>';
}
else {
$item['body'] = '[zmg]' . $ptr['href'] . '[/zmg]' . "\n\n" . $item['body'];
}
}
}
}
......
......@@ -8,11 +8,12 @@ $(document).ready(function() {
UploadInit();
}
$("#photo-edit-newtag").contact_autocomplete(baseurl + '/acl', 'a', false, function(data) {
$("#photo-edit-newtag").val('@' + data.name);
});
//$("#photo-edit-newtag").contact_autocomplete(baseurl + '/acl', 'a', false, function(data) {
//$("#photo-edit-newtag").val('@' + data.name);
//});
$(".comment-edit-form textarea").editor_autocomplete(baseurl+"/acl?f=&n=1");
$('textarea').editor_autocomplete(baseurl+"/acl");
$('textarea').bbco_autocomplete('bbcode');
showHideBodyTextarea();
......@@ -70,12 +71,12 @@ function UploadInit() {
progress: function(e,data) {
// there will only be one file, the one we are looking for
// there will only be one file, the one we are looking for
$(data.files).each( function() {
var idx = this.count;
// Dynamically update the percentage complete displayed in the file upload list
// Dynamically update the percentage complete displayed in the file upload list
$('#upload-progress-' + idx).html(Math.round(data.loaded / data.total * 100) + '%');
$('#upload-progress-bar-' + idx).css('background-size', Math.round(data.loaded / data.total * 100) + '%');
......@@ -283,7 +284,7 @@ function UploadFile(file, idx) {
$('#upload-progress-' + idx).html('<span style="color: red;">ERROR</span>');
});
// POST to the entire cloud path
// POST to the entire cloud path
xhr.open('post', $('#photos-upload-form').attr( 'action' ), true);
var formfields = $("#photos-upload-form").serializeArray();
......
......@@ -321,10 +321,8 @@ var activeCommentText = '';
postSaveChanges('clean');
{{if $popup}}
return;
{{/if}}
{{if $reset}}
$("#profile-jot-text").focus();
{{else if $reset}}
$(".jothidden").hide();
$("#profile-jot-text").removeClass('jot-expanded');
$("#profile-jot-tools").addClass('d-none');
......
......@@ -66,10 +66,12 @@
<label id="photo-edit-caption-label" for="photo-edit-caption">{{$edit.capt_label}}</label>
<input id="photo-edit-caption" class="form-control" type="text" name="desc" value="{{$edit.caption}}" />
</div>
{{*
<div class="form-group">
<label id="photo-edit-tags-label" for="photo-edit-newtag">{{$edit.tag_label}}</label>
<input name="newtag" id="photo-edit-newtag" class="form-control" title="{{$edit.help_tags}}" type="text" />
</div>
*}}
<div class="form-group">
{{include file="field_select.tpl" field=$edit.album_select}}
</div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment