diff options
-rw-r--r-- | include/api_zot.php | 22 | ||||
-rw-r--r-- | include/channel.php | 83 | ||||
-rw-r--r-- | include/text.php | 2 | ||||
-rw-r--r-- | view/js/main.js | 16 | ||||
-rwxr-xr-x | view/tpl/jot-header.tpl | 10 | ||||
-rwxr-xr-x | view/tpl/jot.tpl | 2 |
6 files changed, 106 insertions, 29 deletions
diff --git a/include/api_zot.php b/include/api_zot.php index 6a5b9a268..b332aea71 100644 --- a/include/api_zot.php +++ b/include/api_zot.php @@ -6,6 +6,8 @@ api_register_func('api/export/basic','api_export_basic', true); api_register_func('api/red/channel/export/basic','api_export_basic', true); api_register_func('api/z/1.0/channel/export/basic','api_export_basic', true); + api_register_func('api/red/item/export/page','api_item_export_page', true); + api_register_func('api/z/1.0/item/export/page','api_item_export_page', true); api_register_func('api/red/channel/list','api_channel_list', true); api_register_func('api/z/1.0/channel/list','api_channel_list', true); api_register_func('api/red/channel/stream','api_channel_stream', true); @@ -80,6 +82,26 @@ json_return_and_die(identity_basic_export(api_user(),$sections)); } + function api_item_export_page($type) { + if(api_user() === false) { + logger('api_item_export_page: no user'); + return false; + } + $page = intval($_REQUEST['page']); + $records = intval($_REQUEST['records']); + if(! $records) { + $records = 50; + } + if(! $_REQUEST['since']) + $start = NULL_DATE; + else { + $start = datetime_convert(date_default_timezone_get(),'UTC', $_REQUEST['since']); + } + $finish = datetime_convert(date_default_timezone_get(),'UTC', (($_REQUEST['until']) ? $_REQUEST['until'] : 'now')); + + json_return_and_die(channel_export_items_page(api_user(),$start,$finish,$page,$records)); + } + function api_network_stream($type) { if(api_user() === false) { diff --git a/include/channel.php b/include/channel.php index 95a3f96cf..466d2eab9 100644 --- a/include/channel.php +++ b/include/channel.php @@ -1080,6 +1080,7 @@ function identity_basic_export($channel_id, $sections = null) { return $ret; } + /** * @brief Export items for a year, or a month of a year. * @@ -1102,23 +1103,50 @@ function identity_export_year($channel_id, $year, $month = 0) { else $target_month = '01'; + $mindate = datetime_convert('UTC', 'UTC', $year . '-' . $target_month . '-01 00:00:00'); + if($month && $month < 12) + $maxdate = datetime_convert('UTC', 'UTC', $year . '-' . $target_month_plus . '-01 00:00:00'); + else + $maxdate = datetime_convert('UTC', 'UTC', $year+1 . '-01-01 00:00:00'); + + return channel_export_items_date($channel_id,$mindate,$maxdate); + +} + +/** + * @brief Export items within an arbitrary date range. + * + * Date/time is in UTC. + * + * @param int $channel_id The channel ID + * @param string $start + * @param string $finish + * @return array + */ + +function channel_export_items_date($channel_id, $start, $finish) { + + if(! $start) + return array(); + else + $start = datetime_convert('UTC', 'UTC', $start); + + $finish = datetime_convert('UTC', 'UTC', (($finish) ? $finish : 'now')); + if($finish < $start) + return array(); + $ret = array(); $ch = channelx_by_n($channel_id); if($ch) { $ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()]; } - $mindate = datetime_convert('UTC', 'UTC', $year . '-' . $target_month . '-01 00:00:00'); - if($month && $month < 12) - $maxdate = datetime_convert('UTC', 'UTC', $year . '-' . $target_month_plus . '-01 00:00:00'); - else - $maxdate = datetime_convert('UTC', 'UTC', $year+1 . '-01-01 00:00:00'); - $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created < '%s' and resource_type = '' order by created", + $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created <= '%s' and resource_type = '' order by created", intval(ITEM_TYPE_POST), intval($channel_id), - dbesc($mindate), - dbesc($maxdate) + dbesc($start), + dbesc($finish) ); if($r) { @@ -1132,39 +1160,57 @@ function identity_export_year($channel_id, $year, $month = 0) { return $ret; } + + /** - * @brief Export items within an arbitrary date range. + * @brief Export items with pagination * - * Date/time is in UTC. * * @param int $channel_id The channel ID - * @param string $start - * @param string $finish + * @param int $page + * @param int $limit (default 50) * @return array */ -function channel_export_items($channel_id, $start, $finish) { + +function channel_export_items_page($channel_id, $start, $finish, $page = 0, $limit = 50) { + + if(intval($page) < 1) { + $page = 0; + } + + if(intval($limit) < 1) { + $limit = 1; + } + + if(intval($limit) > 5000) { + $limit = 5000; + } if(! $start) - return array(); + $start = NULL_DATE; else $start = datetime_convert('UTC', 'UTC', $start); $finish = datetime_convert('UTC', 'UTC', (($finish) ? $finish : 'now')); if($finish < $start) - return array(); + return []; - $ret = array(); + $offset = intval($limit) * intval($page); + + $ret = []; $ch = channelx_by_n($channel_id); if($ch) { $ret['relocate'] = [ 'channel_address' => $ch['channel_address'], 'url' => z_root()]; } - $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and created >= '%s' and created <= '%s' and resource_type = '' order by created", + $r = q("select * from item where ( item_wall = 1 or item_type != %d ) and item_deleted = 0 and uid = %d and resource_type = '' and created >= '%s' and created <= '%s' order by created limit %d offset %d", intval(ITEM_TYPE_POST), intval($channel_id), dbesc($start), - dbesc($finish) + dbesc($finish), + intval($limit), + intval($offset) ); if($r) { @@ -1179,6 +1225,7 @@ function channel_export_items($channel_id, $start, $finish) { } + /** * @brief Loads a profile into the App structure. * diff --git a/include/text.php b/include/text.php index ad5f84b54..ec3eb7b10 100644 --- a/include/text.php +++ b/include/text.php @@ -3246,7 +3246,7 @@ function flatten_array_recursive($arr) { $ret = array_merge($ret, $tmp); } } - elseif($a) { + elseif(isset($a)) { $ret[] = $a; } } diff --git a/view/js/main.js b/view/js/main.js index 4e4431f33..b1af29846 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -784,16 +784,26 @@ function updateConvItems(mode,data) { collapseHeight(); } + if(bParam_mid && mode === 'replace') + scrollToItem(); + + $(document.body).trigger("sticky_kit:recalc"); +} + +function scrollToItem() { // auto-scroll to a particular comment in a thread (designated by mid) when in single-thread mode // use the same method to generate the submid as we use in ThreadItem, // base64_encode + replace(['+','='],['','']); + if(justifiedGalleryActive) + return; + var submid = ((bParam_mid.length) ? bParam_mid : 'abcdefg'); var encoded = ((submid.substr(0,4) == 'b64.') ? true : false); var submid_encoded = ((encoded) ? submid.substr(4) : window.btoa(submid)); submid_encoded = submid_encoded.replace(/[\+\=]/g,''); - if($('.item_' + submid_encoded).length && !$('.item_' + submid_encoded).hasClass('toplevel_item') && mode == 'replace') { + if($('.item_' + submid_encoded).length && !$('.item_' + submid_encoded).hasClass('toplevel_item')) { if($('.collapsed-comments').length) { var scrolltoid = $('.collapsed-comments').attr('id').substring(19); $('#collapsed-comments-' + scrolltoid + ' .autotime').timeago(); @@ -801,11 +811,9 @@ function updateConvItems(mode,data) { $('#hide-comments-' + scrolltoid).html(aStr.showfewer); $('#hide-comments-total-' + scrolltoid).hide(); } - $('html, body').animate({ scrollTop: $('.item_' + submid_encoded).offset().top - $('nav').outerHeight() }, 'slow'); + $('html, body').animate({ scrollTop: $('.item_' + submid_encoded).offset().top - $('nav').outerHeight(true) }, 'slow'); $('.item_' + submid_encoded).addClass('item-highlight'); } - - $(document.body).trigger("sticky_kit:recalc"); } function collapseHeight() { diff --git a/view/tpl/jot-header.tpl b/view/tpl/jot-header.tpl index 9a44f1a54..afaaa62d9 100755 --- a/view/tpl/jot-header.tpl +++ b/view/tpl/jot-header.tpl @@ -427,7 +427,9 @@ var activeCommentText = ''; var imageparent = document.getElementById($(image).parent()[0].id); $(imageparent).toggleClass('embed-photo-selected-photo'); var href = $(imageparent).attr('href'); - $.post("embedphotos/photolink", {href: href}, + $.post( + "embedphotos/photolink", + {href: href}, function(ddata) { if (ddata['status']) { addeditortext(ddata['photolink']); @@ -437,10 +439,8 @@ var activeCommentText = ''; } return false; }, - 'json'); - $('#embedPhotoModalBodyAlbumDialog').html(''); - $('#embedPhotoModalBodyAlbumDialog').off('click'); - $('#embedPhotoModal').modal('hide'); + 'json' + ); } }); $('#embedPhotoModalBodyAlbumListDialog').addClass('d-none'); diff --git a/view/tpl/jot.tpl b/view/tpl/jot.tpl index 12509fc59..b4616db6d 100755 --- a/view/tpl/jot.tpl +++ b/view/tpl/jot.tpl @@ -302,7 +302,7 @@ {{if $embedPhotos}} <div class="modal" id="embedPhotoModal" tabindex="-1" role="dialog" aria-labelledby="embedPhotoLabel" aria-hidden="true"> - <div class="modal-dialog"> + <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h3 class="modal-title" id="embedPhotoModalLabel">{{$embedPhotosModalTitle}}</h3> |