Committer: gprochaev
LJSUP-9517. Edit Entries page redesignU trunk/cgi-bin/LJ/Widget/EntryForm.pm U trunk/cgi-bin/ljlib.pl U trunk/htdocs/editjournal.bml U trunk/htdocs/editjournal.bml.text U trunk/htdocs/update.bml
Modified: trunk/cgi-bin/LJ/Widget/EntryForm.pm =================================================================== --- trunk/cgi-bin/LJ/Widget/EntryForm.pm 2011-08-22 06:30:01 UTC (rev 19800) +++ trunk/cgi-bin/LJ/Widget/EntryForm.pm 2011-08-22 07:18:09 UTC (rev 19801) @@ -3,6 +3,11 @@ use strict; use base 'LJ::Widget'; +use LJ::Fotki::Photo; +use LJ::Fotki::Album; +use LJ::Widget::Fotki::Upload; + + sub set_data { my ($self, $opts, $head, $onload, $errors, $js) = @_; $self->{'opts'} = $opts; @@ -1359,6 +1364,106 @@ return $out; } +sub render_ljphoto_block { + my ($self) = @_; + + my $opts = $self->opts; + my $out = ''; + + my $remote = $self->remote (); + + # in case of insert one photo or photo album + my $insert_photos = []; + + my $albums_id = $opts->{'albums_id'}; + my $photos_id = $opts->{'photos_id'}; + + my @photos = grep { $_ } map { + my $photo = LJ::Fotki::Photo->new ( url_id => $_, userid => $remote->userid ); + $photo; + } split (/,/, $photos_id); + + foreach my $album_id (split /,/, $albums_id) { + my $album = LJ::Fotki::Album->new ( url_id => $album_id, userid => $remote->userid ); + next unless $album; + push @photos, @{$album->get_all_photos() || []}; + } + + $insert_photos = [ grep { $_ } map { + my $photo = $_; + + my $res = $photo->is_valid ? { + photo_desc => $photo->desc, + photo_title => $photo->title, + photo_url => @photos > 1 ? $photo->u100_url : $photo->u600_url, + photo_id => $photo->url_id, + } : undef; + $res; + } @photos ]; + + my $photo_sizes = LJ::JSON->to_json ( LJ::Fotki::Photo->get_photo_sizes() ); + my $album_list = []; + my $album_list_json = ''; + my $available_space = ''; + $album_list = LJ::Fotki::Album->get_albums ($remote->userid); + $album_list = [ + map { + my $album = $_; + my $main_photo = $album->main_photo_url; + { + album_title => $album->title, + album_id => $album->url_id, + } + } @$album_list + ]; + $album_list_json = LJ::JSON->to_json ( $album_list ); + my $spaces = LJ::Fotki::UserSpace->get_spaces ( $remote ); + $available_space = $spaces->[2] || 0; + + my $auth_token = LJ::Auth->sessionless_auth_token ($LJ::DOMAIN_WEB."/pics/upload", user => $remote ? $remote->user : undef); + my $user_groups = LJ::JSON->to_json (LJ::Widget::Fotki::Photo->get_user_groups ($remote)); + my $ljphoto_enabled = $remote->can_upload_photo(); + + LJ::Widget::Fotki::Upload->render(); + + $out .= <<JS; +<script type="text/javascript"> + window.ljphotoEnabled = $ljphoto_enabled; + jQuery('#updateForm').photouploader({ + availableSpace: '$available_space', + sizesData: $photo_sizes, + albumsData: $album_list_json, + privacyData: $user_groups, + type: 'upload', + guid: '$auth_token' + }); +</script> +JS + + if (@$insert_photos) { + my $insert_photos_json = LJ::JSON->to_json ( $insert_photos ); + $out .= <<JS; +<script type="text/javascript"> + jQuery('#updateForm') + .photouploader({ + insertPhotosData: $insert_photos_json, + type: 'add' + }) + .bind('htmlready', function (event, htmlOutput) { + if (window.switchedRteOn) { + CKEDITOR.instances.draft.insertHtml(htmlOutput); + } else { + jQuery('#draft').val(jQuery('#draft').val() + htmlOutput); + } + }) + .photouploader('show'); +</script> +JS + } + + return $out; +} + sub render_body { my ($self) = @_; @@ -1504,6 +1609,8 @@ } else { $$js .= 'usePlainText();'; } + my $ljphoto_enabled = $remote ? $remote->can_upload_photo() : 0; + $$js .= "window.ljphotoEnabled = $ljphoto_enabled;"; $$js = $self->wrap_js($$js); } @@ -1518,6 +1625,10 @@ $out .= LJ::run_hook('entryform_pre_submitbar', $opts); $out .= $self->render_submitbar_block; + ## Show a new photoalbums interface only for logged-in users + $out .= $self->render_ljphoto_block + if $remote && $remote->can_upload_photo(); + $out .= "</div><!-- end #entry-form-wrapper -->\n\n"; return $out; Modified: trunk/cgi-bin/ljlib.pl =================================================================== --- trunk/cgi-bin/ljlib.pl 2011-08-22 06:30:01 UTC (rev 19800) +++ trunk/cgi-bin/ljlib.pl 2011-08-22 07:18:09 UTC (rev 19801) @@ -1267,6 +1267,12 @@ $after_sql = "AND jitemid > $afterid"; } + my $before_sql = ''; + my $beforeid = $opts->{'beforeid'} + 0; + if ($beforeid) { + $before_sql = "AND jitemid < $beforeid"; + } + my $posterwhere; if ($opts->{'posterid'} && $opts->{'posterid'} =~ /^(\d+)$/) { $posterwhere = " AND posterid=$1"; @@ -1288,7 +1294,7 @@ DATE_FORMAT(logtime, "$dateformat") AS 'system_alldatepart', allowmask, eventtime, logtime FROM log2 USE INDEX ($sort_key) - WHERE journalid=$userid $sql_select $secwhere $jitemidwhere $securitywhere $posterwhere $after_sql $suspend_where + WHERE journalid=$userid $sql_select $secwhere $jitemidwhere $securitywhere $posterwhere $after_sql $before_sql $suspend_where ORDER BY journalid, $sort_key $sql_limit }; Modified: trunk/htdocs/editjournal.bml =================================================================== --- trunk/htdocs/editjournal.bml 2011-08-22 06:30:01 UTC (rev 19800) +++ trunk/htdocs/editjournal.bml 2011-08-22 07:18:09 UTC (rev 19801) @@ -3,6 +3,7 @@ body<= <?_code { +#line 7 use strict; use vars qw(%GET %POST); BML::decl_params(_default => qr/./); @@ -26,9 +27,10 @@ my $mode = $GET{'mode'} || $POST{'mode'} || "init"; if ($GET{'itemid'} || $POST{'itemid'}) { $mode = "edit"; } + my $only_me_checked = LJ::did_post() ? $POST{'only_me'} : $GET{'only_me'}; my $ret; - my $getextra = $GET{'authas'} ? "?authas=$GET{'authas'}" : undef; + my $getextra = undef; LJ::need_res(qw( stc/entry.css @@ -41,63 +43,67 @@ js/scanner.js )); - # are they asking to be authed as someone else? - my $authas = $GET{'authas'} || $remote->{'user'}; - my $u = LJ::get_authas_user($authas); - return LJ::bad_input("You could not be authenticated as the specified user.") - unless $u; - return LJ::bad_input("You must be authenticated as a person.") - unless $u->is_personal || $u->is_identity; + unless $remote->is_personal || $remote->is_identity; # are we modify a community post? my $usejournal = $GET{'usejournal'} || $POST{'usejournal'} || $GET{'journal'}; - undef $usejournal if $usejournal eq $u->{'user'}; # ignore if it's the user + undef $usejournal if $usejournal eq $remote->{'user'}; # ignore if it's the user + my $usejournal_u = LJ::load_user ($usejournal) || $remote; + my ($year, $month, $day) = ($POST{'year'} || $GET{'year'}, $POST{'month'} || $GET{'month'}, $POST{'day'} || $GET{'day'}); + my $ymd = join "-", ($year, $month, $day); + + my $show = $GET{'show'} || undef; + # extra get arguments my $getextra; - $getextra .= "authas=$authas&" if $authas ne $u->{'user'}; $getextra .= "usejournal=$usejournal&" if $usejournal; + $getextra .= "year=$year&month=$month&day=$day&" if $year && $month && $day; + $getextra .= "only_me=$only_me_checked&" if $only_me_checked; chop $getextra; $getextra = "?$getextra" if $getextra; + my $start_from = $GET{'start_from'} || 0; + my $items_per_page = 2; + my $entry_chooser = sub { - my $ret; my $ref = shift; my %opts = @_; - my %res = %$ref; + my $ret; + + my @res = @$ref; my $show_ad = $opts{show_ad} ? 1 : 0; + $ret .= ($opts{'prev'} > 0) ? "<a href='$LJ::SITEROOT/editjournal.bml$getextra" . ($getextra ? "&" : "?") . "start_from=$opts{prev}'>prev</a>, " : ""; + $ret .= "<a href='$LJ::SITEROOT/editjournal.bml$getextra" . ($getextra ? "&" : "?") . "start_from=$opts{next}'>next</a><br/>" + if @res; + $ret .= "<table style='width: 100%;'><tr><td>"; - my %props = (); - for (my $i=1; $i<=$res{'prop_count'}; $i++) { - $props{$res{"prop_${i}_itemid"}}->{$res{"prop_${i}_name"}} = $res{"prop_${i}_value"}; - } + foreach my $e_raw (@res) { + my $entry = LJ::Entry->new_from_item_hash (LJ::load_user($usejournal) || $remote, $e_raw); - my $ev_count = $res{'events_count'}; - for (my $i=1; $i<=$ev_count; $i++) { - my $itemid = $res{"events_${i}_itemid"}; - my $ditemid = $itemid * 256 + $res{"events_${i}_anum"}; + my $edit_disable = 0; + if ( + ($e_raw->{'posterid'} != $remote->userid) + || ($remote->is_readonly || ($usejournal_u && $usejournal_u->is_readonly)) + ) { + $edit_disable++; + } - $ret .= "<?hr?><table><tr valign='top'><td align='middle'>"; - $ret .= "<form method='post' action='editjournal.bml$getextra'>\n"; - $ret .= LJ::html_hidden('itemid',$ditemid,'mode',"edit"); - $ret .= LJ::html_submit("itemid-$ditemid",'Edit this Entry'); - $ret .= "</form>"; - $ret .= "</td><td>"; + my $poster = $usejournal ? LJ::ljuser(LJ::load_userid($entry->posterid)) : ""; - $ret .= " <b><label for='itemid-$ditemid'>" . $res{"events_${i}_eventtime"} . "</label></b>"; - $ret .= " (Posted by: " . LJ::ljuser($res{"events_${i}_poster"}) . ")" if $usejournal; + $ret .= "<?hr?><table width='100%'><tr valign='top'><td>"; ### security indicator my $sec = ' '; - if ($res{"events_${i}_security"} eq "private") { + if ($entry->security eq "private") { $sec .= BML::fill_template("securityprivate"); - } elsif ($res{"events_${i}_security"} eq "usemask") { - if ($res{"events_${i}_allowmask"} == 0) { # custom security with no group -- essentially private + } elsif ($entry->security eq "usemask") { + if ($entry->allowmask == 0) { # custom security with no group -- essentially private $sec .= BML::fill_template("securityprivate"); - } elsif ($res{"events_${i}_allowmask"} > 1) { # custom group + } elsif ($entry->allowmask > 1) { # custom group $sec .= BML::fill_template("securitygroups"); } else { # friends only $sec .= BML::fill_template("securityprotected"); @@ -105,19 +111,36 @@ } $ret .= $sec; - if (my $subj = $res{"events_${i}_subject"}) { - LJ::CleanHTML::clean_subject_all(\$subj); - $ret .= " <i>" . LJ::ehtml($subj) . "</i>"; - } + $ret .= "<a href='$LJ::SITEROOT/editjournal.bml$getextra" . ($getextra ? "&" : "?") . "mode=edit&itemid=".$entry->ditemid."'>"; + if (my $subj = $entry->subject_text) { + $ret .= LJ::ehtml($subj); + } else { + $ret .= BML::ml('.event.no_subject.title'); + } + $ret .= "</a>"; $ret .= "<br />\n"; + my ($year, $mon, $mday, $hour, $min) = split(/\D/, LJ::TimeUtil->alldatepart_s2($entry->{'eventtime'})); + my $monthlong = LJ::Lang::month_long($mon); + $ret .= $poster . " <label for='itemid-$entry->ditemid'>" . "$monthlong $mday, $year, $hour:$min" . "</label></br>"; - my $event = LJ::ehtml(LJ::durl($res{"events_${i}_event"})); + my $event = LJ::ehtml(LJ::durl($entry->event_raw)); $event =~ s!\n!<br />!g; $ret .= $event; - if (my $taglist = $props{$itemid}{'taglist'}) { - $ret .= "<br/><b>Tags:</b> " . LJ::ehtml($taglist); + if (my @taglist = $entry->tags) { + $ret .= "<br/><b>Tags:</b> " . LJ::ehtml(join ",", @taglist); } + $ret .= "</td><td align='right'>"; + $ret .= "<form method='post' action='editjournal.bml$getextra'>\n"; + $ret .= LJ::form_auth(); + $ret .= LJ::html_hidden('itemid',$entry->ditemid,'mode',"edit"); + if (!$edit_disable) { + $ret .= LJ::html_submit("itemid-$entry->ditemid", 'Edit this Entry'); + } else { + $ret .= LJ::html_submit("action:delete", 'Delete this Entry'); + } + $ret .= "</form>"; $ret .= "</td></tr></table>\n"; + } $ret .= "</td>"; if ($show_ad) { @@ -125,12 +148,10 @@ $ret .= "<td valign='top'>$ad</td>" if $ad; } $ret .= "</tr></table>"; - return $ret; }; - if ($mode eq "edit") - { + if ($mode eq "edit") { # user object for community if we're modifying one my $usejournal_u; if ($usejournal) { @@ -150,7 +171,7 @@ my $anum = $ditemid % 256; my $itemid = int($ditemid / 256); - my $u_for_entry = $usejournal ? $usejournal_u : $u; + my $u_for_entry = $usejournal ? $usejournal_u : $remote; my $entry_obj = LJ::Entry->new($u_for_entry, ditemid => $ditemid); # do getevents request @@ -158,14 +179,14 @@ LJ::do_request({ 'mode' => 'getevents', 'selecttype' => 'one', 'ver' => $LJ::PROTOCOL_VER, - 'user' => $u->{'user'}, + 'user' => $remote->{'user'}, 'usejournal' => $usejournal, 'itemid' => $itemid, - ($POST{'my_posts_only'}) ? ('posterid' => $u->{'userid'}) : (), + ($POST{'my_posts_only'}) ? ('posterid' => $remote->{'userid'}) : (), }, \%res, { "noauth" => 1, - 'u' => $u } + 'u' => $remote } ); # was there a protocol error? @@ -185,14 +206,14 @@ my $disabled_save = 0; my $disabled_delete = 0; my $disabled_spamdelete = 0; - if ($usejournal && $res{'events_1_poster'} ne $u->{'user'}) { - $disabled_delete = ! LJ::can_delete_journal_item($u, $usejournal_u, $itemid); + if ($usejournal && $res{'events_1_poster'} ne $remote->{'user'}) { + $disabled_delete = ! LJ::can_delete_journal_item($remote, $usejournal_u, $itemid); $disabled_save++; } - $disabled_spamdelete = $disabled_delete || !$usejournal || ($res{'events_1_poster'} eq $u->{'user'}); + $disabled_spamdelete = $disabled_delete || !$usejournal || ($res{'events_1_poster'} eq $remote->{'user'}); # read-only posters and journals cannot be edited - if (!$disabled_save && ($u->is_readonly || ($usejournal_u && $usejournal_u->is_readonly))) { + if (!$disabled_save && ($remote->is_readonly || ($usejournal_u && $usejournal_u->is_readonly))) { $disabled_save++; } @@ -220,7 +241,7 @@ my %req = ( 'ver' => $LJ::PROTOCOL_VER, - 'username' => $u->{'user'}, + 'username' => $remote->{'user'}, 'usejournal' => $usejournal, 'itemid' => $itemid, ); @@ -235,7 +256,7 @@ # if the action is to delete it, then let's note that if ($POST{'action:delete'} || $POST{'action:deletespam'}) { # now log the event created above - ($usejournal ? $usejournal_u : $u)->log_event('delete_entry', { + ($usejournal ? $usejournal_u : $remote)->log_event('delete_entry', { remote => $remote, actiontarget => $ditemid, method => 'web', @@ -249,7 +270,7 @@ delete $req{$k}; } my $err = 0; - my $res = LJ::Protocol::do_request('editevent', \%req, \$err, { 'noauth' => 1, 'u' => $u }); + my $res = LJ::Protocol::do_request('editevent', \%req, \$err, { 'noauth' => 1, 'u' => $remote }); # check response unless ($res) { @@ -257,7 +278,7 @@ } my $deleted = $req{event} ? 0 : 1; - my $journalu = $usejournal ? $usejournal_u : $u; + my $journalu = $usejournal ? $usejournal_u : $remote; my $j_base = $journalu->journal_base; my $entry_url = LJ::item_link($journalu, $itemid, $res->{anum}); @@ -426,105 +447,6 @@ LIKE_FAQ $ret .= $js; - ## Show a new photoalbums interface only for logged-in users - my $remote = LJ::get_remote (); - if ($remote) { - # in case of insert one photo or photo album - my $insert_photos = []; - if ($remote) { - my $albums_id = $POST{'albums_id'} || $GET{'albums_id'}; - my $photos_id = $POST{'photos_id'} || $GET{'photos_id'}; - - my @photos = grep { $_ } map { - my $photo = LJ::Fotki::Photo->new ( url_id => $_, userid => $remote->userid ); - $photo; - } split (/,/, $photos_id); - - foreach my $album_id (split /,/, $albums_id) { - my $album = LJ::Fotki::Album->new ( url_id => $album_id, userid => $remote->userid ); - next unless $album; - push @photos, @{$album->get_all_photos() || []}; - } - - $insert_photos = [ grep { $_ } map { - my $photo = $_; - - my $res = $photo->is_valid ? { - photo_desc => $photo->desc, - photo_title => $photo->title, - photo_url => @photos > 1 ? $photo->u100_url : $photo->u600_url, - photo_id => $photo->url_id, - } : undef; - $res; - } @photos ]; - } - - my $photo_sizes = LJ::JSON->to_json ( LJ::Fotki::Photo->get_photo_sizes() ); - my $album_list = []; - my $album_list_json = ''; - my $available_space = ''; - $album_list = LJ::Fotki::Album->get_albums ($remote->userid); - $album_list = [ - map { - my $album = $_; - my $main_photo = $album->main_photo_url; - { - album_title => $album->title, - album_id => $album->url_id, - } - } @$album_list - ]; - $album_list_json = LJ::JSON->to_json ( $album_list ); - my $spaces = LJ::Fotki::UserSpace->get_spaces ( $remote ); - $available_space = $spaces->[2] || 0; - - my $auth_token = LJ::Auth->sessionless_auth_token ($LJ::DOMAIN_WEB."/pics/upload", user => $remote ? $remote->user : undef); - my $user_groups = LJ::JSON->to_json (LJ::Widget::Fotki::Photo->get_user_groups ($remote)); - my $comm = LJ::load_user($LJ::LJPHOTO_ALLOW_FROM_COMMUNITY); - my $ljphoto_enabled = $remote && $remote->is_mutual_friend($comm) ? 1 : 0; - - LJ::Widget::Fotki::Upload->render(); - - $ret .= <<JS; - <script type="text/javascript"> - window.ljphotoEnabled = $ljphoto_enabled; - jQuery('#updateForm').photouploader({ - availableSpace: '$available_space', - sizesData: $photo_sizes, - albumsData: $album_list_json, - privacyData: $user_groups, - type: 'upload', - guid: '$auth_token' - }); - </script> -JS - - if (@$insert_photos) { - my $insert_photos_json = LJ::JSON->to_json ( $insert_photos ); - $ret .= <<JS; - <script type="text/javascript"> - jQuery('#updateForm') - .photouploader({ - insertPhotosData: $insert_photos_json, - - type: 'add' - }) - .bind('htmlready', function (event, htmlOutput) { - if (window.switchedRteOn) { - CKEDITOR.instances.draft.insertHtml(htmlOutput); - } else { - jQuery('#draft').val(jQuery('#draft').val() + htmlOutput); - } - }) - .photouploader('show'); - </script> -JS - - } - } - - - $ret .= "</td>"; my $ad = LJ::get_ads({ location => 'bml.editjournal', ljadwrapper => 1 }); if ($ad) { @@ -543,7 +465,7 @@ # -- this is a hack, should be done by weblib and pushed into \$$head above # in a way which is compatible with both this page and update.bml my $is_sup = LJ::SUP->is_remote_sup() ? 1 : 0; - $$head .= qq{ + $$head .= qq| <script type="text/javascript"> //<![CDATA[ function initUpdateBml() { @@ -553,7 +475,7 @@ //]]> LiveJournal.qotdText = "$escaped_qotd_text"; </script> -}; +|; $ret .= LJ::Widget::SettingWindow->render; @@ -573,10 +495,10 @@ my %req = ( 'mode' => 'getevents', 'ver' => $LJ::PROTOCOL_VER, - 'user' => $u->{'user'}, + 'user' => $remote->{'user'}, 'usejournal' => $usejournal, 'truncate' => 300, - ($POST{'my_posts_only'}) ? ('posterid' => $u->{'userid'}) : (), + ($POST{'my_posts_only'}) ? ('posterid' => $remote->{'userid'}) : (), ); # last 1 @@ -596,7 +518,7 @@ } # do getevents request - LJ::do_request(\%req, \%res, { 'noauth' => 1, 'u' => $u }); + LJ::do_request(\%req, \%res, { 'noauth' => 1, 'u' => $remote }); # check response unless ($res{'success'} eq "OK") { @@ -630,84 +552,81 @@ $ret .= "<table style='width: 100%;'><tr><td>"; - # user switcher - $ret .= "<form action='editjournal.bml' method='get'>\n"; - $ret .= LJ::make_authas_select($remote, { 'authas' => $GET{'authas'}, 'type' => 'P' }); - $ret .= "</form>\n\n"; - # header $ret .= "<?p " . BML::ml('.desc', {'aopts' => "href='$LJ::SITEROOT/editprivacy.bml'"}) . " p?>\n"; # edit form - $ret .= "<form action='editjournal.bml$getextra' method='post'>\n"; - $ret .= LJ::html_hidden("mode","edit"); - $ret .= "<?standout <table>\n"; - # view type - $ret .= "<tr valign=\"top\"><td>$ML{'.viewwhat'}</td>\n<td>\n"; - $ret .= LJ::html_check({ 'type' => 'radio', 'name' => 'selecttype', 'id' => 'selecttype-last', - 'value' => 'last', 'selected' => 1 }); - $ret .= "<label for='selecttype-last'>$ML{'.recententry'}</label><br />\n"; - $ret .= LJ::html_check({ 'type' => 'radio', 'name' => 'selecttype', - 'id' => 'selecttype-lastn', 'value' => 'lastn' }) . " "; - $ret .= LJ::html_text({ 'name' => 'howmany', 'size' => '3', 'maxlength' => '2', 'value' => '20', - 'onchange' => "checkRadioButton('selecttype-lastn');" }) . " "; - $ret .= "<label for='selecttype-lastn'>$ML{'.recententries'}</label><br />\n"; + $ret .= "<form action='editjournal.bml$getextra' method='post'>\n"; + $ret .= "Show entries + <input type='text' name='year' value='$year'> + <input type='text' name='month' value='$month'> + <input type='text' name='day' value='$day'> + or <a href='editjournal.bml?show=recent&mode=init'>back to recent entries</a><br/>"; + $ret .= LJ::html_text({ 'name' => 'usejournal', 'size' => '20', 'maxlength' => '15', 'value' => $GET{'usejournal'} || $POST{'usejournal'} }); + $ret .= LJ::html_submit(undef, $ML{'.btn.search'}); + $ret .= "<br/>" . LJ::html_check({ name => 'only_me', id => 'only_me', + value => '1', selected => $only_me_checked }); + $ret .= "<label for='only_me'>Only my entries</label><br/>"; + $ret .= "</form>\n"; + $ret .= "<br/>"; - $ret .= LJ::html_check({ 'type' => 'radio', 'name' => 'selecttype', - 'id' => 'selecttype-day', 'value' => 'day' }); - $ret .= "<label for='selecttype-day'>$ML{'.certainday'}</label>"; + my $err = ''; + my $usejournal_u = LJ::load_user ($usejournal || $remote->{'user'}); + my @recent_entries = (); + my %entry_ids = (); + my $prev_page_id = ($start_from > 0) ? ($start_from + $items_per_page) : 0; + my $ymd = join "/", ($year, $month, $day); + my %ymd_req = ($year && $month && $day && $show ne 'recent') ? ( ymd => $ymd ) : (); + while ($LJ::MAX_SCROLLBACK_LASTN = 50000, + my @recent = LJ::get_recent_items({ + itemshow => $items_per_page, + err => \$err, + userid => $usejournal_u->{userid}, + clusterid => $usejournal_u->{clusterid}, + remote => $remote, + dateformat => 'S2', + beforeid => $start_from, + order => 'logtime', + %ymd_req, + ($only_me_checked) ? ('posterid' => $remote->{'userid'}) : (), + })) { - my @time = localtime(time); - my $mday = sprintf("%02d", $time[3]); - my $mon = sprintf("%02d", $time[4] + 1); - my $year = $time[5] + 1900; + ## do not process entries twice + @recent = grep { $entry_ids{$_->{'itemid'}} ? 0 : 1 } @recent; + last unless @recent; - $ret .= LJ::html_text({ 'name' => 'year', 'size' => '5', 'maxlength' => '4', 'value' => $year, - 'onchange' => "checkRadioButton('selecttype-day');" }) . "-"; - $ret .= LJ::html_text({ 'name' => 'month', 'size' => '3', 'maxlength' => '2', 'value' => $mon, - 'onchange' => "checkRadioButton('selecttype-day');" }) . "-"; - $ret .= LJ::html_text({ 'name' => 'day', 'size' => '3', 'maxlength' => '2', 'value' => $mday, - 'onchange' => "checkRadioButton('selecttype-day');" }) . "\n"; + ## store fetched itemids + foreach my $item (@recent) { + $entry_ids{$item->{'itemid'}} = 1; + } - $ret .= "</td></tr>\n"; + ## Filter records uneditable for remote user + @recent = grep { + my $entry = LJ::Entry->new_from_item_hash ($usejournal_u, $_); + my $poster = $entry->poster; + if ($poster eq $remote || $remote->can_manage ($usejournal_u)) { + 1; + } else { + 0; + } + } @recent; - # use journal - $ret .= "<tr valign=\"top\"><td align='right'>$ML{'.in'}</td>\n<td>\n"; - $ret .= LJ::html_text({ 'name' => 'usejournal', 'size' => '20', 'maxlength' => '15', 'value' => $GET{'usejournal'} }) . " "; - $ret .= " (optional)</br>"; - $ret .= LJ::html_check({ 'name' => 'my_posts_only', 'value' => 1 }); - $ret .= " $ML{'.my_posts_only'}"; - $ret .= "</td></tr>"; + push @recent_entries, @recent; - # submit button - $ret .= "<tr><td> </td><td>" . LJ::html_submit(undef, $ML{'.btn.proceed'}) . "</td></tr>\n"; + my @temp_sort = sort { $a->{itemid} <=> $b->{itemid} } @recent_entries; + $start_from = $temp_sort[0]->{'itemid'}; - $ret .= "</table> standout?>\n"; - $ret .= "</form>\n"; - - my %res; - my %req = ( - mode => 'getevents', - ver => $LJ::PROTOCOL_VER, - user => $u->user, - usejournal => $usejournal, - truncate => 300, - selecttype => 'lastn', - howmany => 5, - ($POST{'my_posts_only'}) ? ('posterid' => $u->{'userid'}) : (), - ); - - # do getevents request - LJ::do_request(\%req, \%res, { noauth => 1, u => $u }); - - if ($res{success} eq "OK" && $res{events_count} > 0) { - $ret .= $entry_chooser->(\%res); + if (@recent_entries == $items_per_page) { + last; + } } + $ret .= $entry_chooser->(\@recent_entries, prev => $prev_page_id, 'next' => $start_from); + my $ad = LJ::get_ads({ location => 'bml.editjournal', ljadwrapper => 1 }); if ($ad) { $ret .= "</td><td valign='top'>$ad"; Modified: trunk/htdocs/editjournal.bml.text =================================================================== --- trunk/htdocs/editjournal.bml.text 2011-08-22 06:30:01 UTC (rev 19800) +++ trunk/htdocs/editjournal.bml.text 2011-08-22 07:18:09 UTC (rev 19801) @@ -3,10 +3,14 @@ .btn.proceed=Proceed... +.btn.search=Search... + .certainday=Certain Day: .desc=Please use the form below to find the entry you would like to edit. +.event.no_subject.title=No Subject + .in=In community: .my_posts_only=Posted by me only Modified: trunk/htdocs/update.bml =================================================================== --- trunk/htdocs/update.bml 2011-08-22 06:30:01 UTC (rev 19800) +++ trunk/htdocs/update.bml 2011-08-22 07:18:09 UTC (rev 19801) @@ -4,10 +4,6 @@ use vars qw(%GET %POST %ML); BML::decl_params(_default => qr/./); - use LJ::Fotki::Photo; - use LJ::Fotki::Album; - use LJ::Widget::Fotki::Upload; - # $_[0] is a pre-request scratch area # put variables here so that we can access them later # outside of this _code block @@ -310,6 +306,8 @@ 'altlogin' => $GET{altlogin} ? 1 : 0, 'prop_opt_preformatted' => $opt_preformatted ? 1 : 0, 'qid' => $qid, + 'albums_id' => $POST{'albums_id'} || $GET{'albums_id'}, + 'photos_id' => $POST{'photos_id'} || $GET{'photos_id'}, }; if ($remote) { @@ -377,101 +375,6 @@ LIKE_FAQ $$body .= $js; - ## Show a new photoalbums interface only for logged-in users - my $remote = LJ::get_remote (); - if ($remote && $remote->can_upload_photo()) { - # in case of insert one photo or photo album - my $insert_photos = []; - - my $albums_id = $POST{'albums_id'} || $GET{'albums_id'}; - my $photos_id = $POST{'photos_id'} || $GET{'photos_id'}; - - my @photos = grep { $_ } map { - my $photo = LJ::Fotki::Photo->new ( url_id => $_, userid => $remote->userid ); - $photo; - } split (/,/, $photos_id); - - foreach my $album_id (split /,/, $albums_id) { - my $album = LJ::Fotki::Album->new ( url_id => $album_id, userid => $remote->userid ); - next unless $album; - push @photos, @{$album->get_all_photos() || []}; - } - - $insert_photos = [ grep { $_ } map { - my $photo = $_; - - my $res = $photo->is_valid ? { - photo_desc => $photo->desc, - photo_title => $photo->title, - photo_url => @photos > 1 ? $photo->u100_url : $photo->u600_url, - photo_id => $photo->url_id, - } : undef; - $res; - } @photos ]; - - my $photo_sizes = LJ::JSON->to_json ( LJ::Fotki::Photo->get_photo_sizes() ); - my $album_list = []; - my $album_list_json = ''; - my $available_space = ''; - $album_list = LJ::Fotki::Album->get_albums ($remote->userid); - $album_list = [ - map { - my $album = $_; - my $main_photo = $album->main_photo_url; - { - album_title => $album->title, - album_id => $album->url_id, - } - } @$album_list - ]; - $album_list_json = LJ::JSON->to_json ( $album_list ); - my $spaces = LJ::Fotki::UserSpace->get_spaces ( $remote ); - $available_space = $spaces->[2] || 0; - - my $auth_token = LJ::Auth->sessionless_auth_token ($LJ::DOMAIN_WEB."/pics/upload", user => $remote ? $remote->user : undef); - my $user_groups = LJ::JSON->to_json (LJ::Widget::Fotki::Photo->get_user_groups ($remote)); - my $ljphoto_enabled = $remote->can_upload_photo(); - - LJ::Widget::Fotki::Upload->render(); - - $$body .= <<JS; - <script type="text/javascript"> - window.ljphotoEnabled = $ljphoto_enabled; - jQuery('#updateForm').photouploader({ - availableSpace: '$available_space', - sizesData: $photo_sizes, - albumsData: $album_list_json, - privacyData: $user_groups, - type: 'upload', - guid: '$auth_token' - }); - </script> -JS - - if (@$insert_photos) { - my $insert_photos_json = LJ::JSON->to_json ( $insert_photos ); - $$body .= <<JS; - <script type="text/javascript"> - jQuery('#updateForm') - .photouploader({ - insertPhotosData: $insert_photos_json, - - type: 'add' - }) - .bind('htmlready', function (event, htmlOutput) { - if (window.switchedRteOn) { - CKEDITOR.instances.draft.insertHtml(htmlOutput); - } else { - jQuery('#draft').val(jQuery('#draft').val() + htmlOutput); - } - }) - .photouploader('show'); - </script> -JS - - } - } - $$body .= LJ::Widget::SettingWindow->render; return;