Committer: wisest-owl
LJSUP-8713. New Photo-hostingU branches/fotki/cgi-bin/Apache/LiveJournal.pm U branches/fotki/cgi-bin/LJ/Widget/EntryForm.pm U branches/fotki/cgi-bin/ljlib.pl U branches/fotki/htdocs/update.bml
Modified: branches/fotki/cgi-bin/Apache/LiveJournal.pm =================================================================== --- branches/fotki/cgi-bin/Apache/LiveJournal.pm 2011-07-22 08:09:25 UTC (rev 19510) +++ branches/fotki/cgi-bin/Apache/LiveJournal.pm 2011-07-22 08:23:25 UTC (rev 19511) @@ -622,6 +622,56 @@ return $bml_handler->("$LJ::HOME/htdocs/$file"); } + if ($opts->{'mode'} eq "ljphotoalbums" && $opts->{'user'} ne 'pics') { + my $burl = LJ::remote_bounce_url(); + return remote_domsess_bounce() if LJ::remote_bounce_url(); + LJ::Request->notes("_journal" => $opts->{'user'}); + + my $u = LJ::load_user($opts->{user}); + if ($u) { + LJ::Request->notes("journalid" => $u->{userid}); + } else { + LJ::Request->pnotes ('error' => 'baduser'); + LJ::Request->pnotes ('remote' => LJ::get_remote()); + return LJ::Request::NOT_FOUND; + } + + ## For beta-testers only. + my $comm = LJ::load_user($LJ::LJPHOTO_ALLOW_FROM_COMMUNITY); + + my %post_params = LJ::Request->post_params; + if (!$remote && !LJ::Auth->check_sessionless_auth_token ( + $LJ::DOMAIN_WEB."/pics/upload", + auth_token => $post_params{'form_auth'}, + user => $opts->{user}) + ) { + LJ::Request->pnotes ('error' => 'members'); + LJ::Request->pnotes ('remote' => LJ::load_user($opts->{'user'})); + return LJ::Request::FORBIDDEN; + } + + LJ::set_remote (LJ::load_user($opts->{'user'})); + $remote = LJ::get_remote(); + + unless ($remote && $remote->is_mutual_friend($comm)) { + LJ::Request->pnotes ('error' => 'members'); + LJ::Request->pnotes ('remote' => LJ::get_remote()); + return LJ::Request::FORBIDDEN; + } + ## + + unless ($u->is_person) { + LJ::Request->pnotes ('error' => 'e404'); + LJ::Request->pnotes ('remote' => LJ::get_remote()); + return LJ::Request::FORBIDDEN; + } + + # handle normal URI mappings + if (my $bml_file = $LJ::URI_MAP{"/pics"}) { + return LJ::URI->bml_handler($bml_file); + } + } + if ($opts->{'mode'} eq "wishlist") { return $bml_handler->("$LJ::HOME/htdocs/wishlist.bml"); } @@ -673,6 +723,12 @@ return redir(LJ::Session->setdomsess_handler()); } + if (LJ::Request->uri eq '/crossdomain.xml') { + LJ::Request->handler("perl-script"); + LJ::Request->set_handlers(PerlHandler => \&crossdomain_content); + return LJ::Request::OK; + } + if ($uuri =~ m#^/(\d+)\.html$#) { # my $u = LJ::load_user($user); unless ($u) { @@ -688,6 +744,9 @@ $mode = "entry"; } + } elsif ($uuri =~ m#^/pics#) { + $mode = "ljphotoalbums"; + } elsif ($uuri =~ m#^/(\d\d\d\d)(?:/(\d\d)(?:/(\d\d))?)?(/?)$#) { my ($year, $mon, $day, $slash) = ($1, $2, $3, $4); unless ($slash) { @@ -908,7 +967,7 @@ LJ::Request->handler("perl-script"); LJ::Request->push_handlers(PerlHandler => \&Apache::LiveJournal::Interface::Api::handler); return LJ::Request::OK; - + LJ::Request->pnotes ('error' => 'e404'); LJ::Request->pnotes ('remote' => LJ::get_remote()); return LJ::Request::NOT_FOUND; Modified: branches/fotki/cgi-bin/LJ/Widget/EntryForm.pm =================================================================== --- branches/fotki/cgi-bin/LJ/Widget/EntryForm.pm 2011-07-22 08:09:25 UTC (rev 19510) +++ branches/fotki/cgi-bin/LJ/Widget/EntryForm.pm 2011-07-22 08:23:25 UTC (rev 19511) @@ -148,7 +148,7 @@ push @ret, qw( js/ippu.js js/lj_ippu.js - stc/fck/fckeditor.js + js/ck/ckeditor.js js/rte.js stc/display_none.css ); @@ -623,7 +623,7 @@ my $switch_rte_link = BML::ml("entryform.htmlokay.rich4", { 'opts' => 'href="javascript:void(0);" '. 'onclick="return useRichText(\'draft\', \'' . - $LJ::WSTATPREFIX. '\');"' + $LJ::JSPREFIX. '\');"' }); my $switch_rte_tab = ''; @@ -1011,6 +1011,41 @@ $out .= LJ::help_icon_html("adult_content", "", " "); return $out; }, + 'give_features' => sub { + my $out = ''; + + return unless LJ::is_enabled("give_features"); + + my @give_menu = ( + "enable" => BML::ml('entryform.give.enable'), + "disable" => BML::ml('entryform.give.disable'), + ); + + $out .= "<label for='prop_give_features' class='left options'>" . + BML::ml('entryform.give') . "</label>\n"; + + my $is_enabled; + if ($opts->{'mode'} eq "edit") { + $is_enabled = $opts->{'prop_give_features'}; + } else { + my $journalu = LJ::load_user($opts->{'usejournal'}) || $remote; + $is_enabled = $journalu ? 1 : 0; + } + + $out .= LJ::html_select({ + name => 'prop_give_features', + id => 'prop_give_features', + class => 'select', + selected => ($is_enabled) ? "enable" : "disable", + tabindex => $self->tabindex, + }, @give_menu); + + $out .= LJ::help_icon_html("give", "", " "); + return $out; + }, + 'blank' => sub { + return ''; + }, 'lastfm_logo' => sub { return unless $self->should_show_lastfm; return qq{ @@ -1418,6 +1453,13 @@ 'Poll_AccountLevelNotice' => 'poll.accountlevelnotice', 'Poll_PollWizardTitle' => 'poll.pollwizardtitle', 'Poll' => 'poll', + 'LJLike_name' => 'ljlike.name', + 'LJLike_dialogText' => 'ljlike.dialog.text', + 'LJLike_button_google' => 'ljlike.button.google', + 'LJLike_button_facebook' => 'ljlike.button.facebook', + 'LJLike_button_vkontakte' => 'ljlike.button.vkontakte', + 'LJLike_button_twitter' => 'ljlike.button.twitter', + 'LJLike_button_give' => 'ljlike.button.give', ); my %langmap_translated = map { $_ => BML::ml("fcklang.$langmap{$_}") } @@ -1427,21 +1469,10 @@ my $jnorich = LJ::ejs(LJ::deemp(BML::ml('entryform.htmlokay.norich2'))); $out .= $self->wrap_js(qq{ - FCKeditor_IsCompatibleBrowser = (function(FCKeditor_IsCompatibleBrowser) { - return function() { - if (/iPad|iPhone/.test(navigator.userAgent)) { - return false; - } - return FCKeditor_IsCompatibleBrowser(); - }; - }(FCKeditor_IsCompatibleBrowser)); - var FCKLang = FCKLang || {}; - jQuery.extend(FCKLang, $langmap); - if (!FCKeditor_IsCompatibleBrowser()) { - document.getElementById('htmltools').style.display = 'block'; - document.write("$jnorich"); - usePlainText('draft'); - } + var CKLang = CKEDITOR.lang[CKEDITOR.lang.detect()] || {}; + jQuery.extend(CKLang, $langmap); + document.getElementById('htmltools').style.display = 'block'; + usePlainText('draft'); }); $out .= qq{ @@ -1452,7 +1483,7 @@ }; if ($opts->{'richtext_default'}) { - $$onload .= 'useRichText("draft", "' . LJ::ejs($LJ::WSTATPREFIX) . '");'; + $$onload .= 'useRichText("draft", "' . LJ::ejs($LJ::JSPREFIX) . '");'; } } Modified: branches/fotki/cgi-bin/ljlib.pl =================================================================== --- branches/fotki/cgi-bin/ljlib.pl 2011-07-22 08:09:25 UTC (rev 19510) +++ branches/fotki/cgi-bin/ljlib.pl 2011-07-22 08:23:25 UTC (rev 19511) @@ -104,6 +104,7 @@ "comet_history", "pingrel", "eventrates", "eventratescounters", "friending_actions_q", + "fotki_albums", "fotki_photos", "fotki_tags", "fotki_tags_map", ); # keep track of what db locks we have out @@ -291,6 +292,7 @@ "captcha_audio" => 3, "captcha_image" => 4, "fotobilder" => 5, + "photoalbums" => 6, }->{$name}; # FIXME: add hook support, so sites can't define their own # general code gets priority on numbers, say, 1-200, so verify Modified: branches/fotki/htdocs/update.bml =================================================================== --- branches/fotki/htdocs/update.bml 2011-07-22 08:09:25 UTC (rev 19510) +++ branches/fotki/htdocs/update.bml 2011-07-22 08:23:25 UTC (rev 19511) @@ -182,6 +182,36 @@ } + # 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 => $photo->u100_url, + photo_id => $photo->url_id, + } : undef; + $res; + } @photos ]; + } + # try to call a hook to fill in the fields my $override_fields = LJ::run_hook('update_fields', \%GET); my $opt_preformatted = 0; @@ -330,7 +360,101 @@ $$body .= " warningbar?><br /></div>"; } - $$body .= "\n\n<form method='post' action='update.bml$getextra' id='updateForm' name='updateForm'>\n\n"; + my $remote = LJ::get_remote (); + my $photo_sizes = LJ::JSON->to_json ( LJ::Fotki::Photo->get_photo_sizes() ); + my $album_list = []; + my $album_list_json = ''; + my $available_space = ''; + if ($remote) { + $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::Photo->get_spaces ( $remote ); + $available_space = $spaces->[2] || 0; + } + ##### + # TODO If remote not exist? + ##### + my $auth_token = LJ::Auth->sessionless_auth_token ($LJ::DOMAIN_WEB."/pics/upload", user => $remote ? $remote->user : undef); + LJ::need_res('stc/pics/pics.css', 'js/swfupload/swfupload.js', 'js/swfupload/swfupload.queue.js', 'js/jquery/jquery.lj.photouploader.js'); + $$body .= <<JS; +<script type="text/javascript"> +// TODO: remove after new PhotoHosting release +window.ljphotoEnabled = true; + + jQuery('#content').photouploader({ + availableSpace: '$available_space', + sizesData: $photo_sizes, + albumsData: $album_list_json, + + type: 'upload', + guid: '$auth_token', + ml: { +JS + $$body .= "'fotki.album.add.images': '".BML::ml('fotki.album.albums')."'," + ."'fotki.album.link.click.to.upload': '".BML::ml('fotki.album.link.click.to.upload')."'," + ."'fotki.album.add.photos': '".BML::ml('fotki.album.add.photos')."'," + ."'fotki.album.upgrade': '".BML::ml('fotki.album.upgrade')."'," + ."'fotki.album.add.image.name': '".BML::ml('fotki.album.add.image.name')."'," + ."'fotki.album.description': '".BML::ml('fotki.album.description')."'," + ."'fotki.album.album_cover': '".BML::ml('fotki.album.album_cover')."'," + ."'fotki.album.remove.this.image': '".BML::ml('fotki.album.remove.this.image')."'," + ."'fotki.album.select_album': '".BML::ml('fotki.album.select_album')."'," + ."'fotki.album.new.album.name': '".BML::ml('fotki.album.new.album.name')."'," + ."'fotki.album.post.images': '".BML::ml('fotki.album.post.images')."'," + ."'fotki.album.save.images': '".BML::ml('fotki.album.save.images')."'," + ."'fotki.privacy': '".BML::ml('fotki.privacy')."'," + ."'fotki.album.resize.to.post': '".BML::ml('fotki.album.resize.to.post')."'," + ."'fotki.album.stop.upload.confirm': '".BML::ml('fotki.album.stop.upload.confirm')."'," + ."'fotki.album.close.without.saving.confirm': '".BML::ml('fotki.album.close.without.saving.confirm')."'," + ."'fotki.album.create.new': '".BML::ml('fotki.album.create.new')."'"; + $$body .= <<JS; + } + }); +</script> +JS + + if (@$insert_photos) { + my $insert_photos_json = LJ::JSON->to_json ( $insert_photos ); + $$body .= <<JS; +<script type="text/javascript"> + jQuery('#content') + .photouploader({ + insertPhotosData: $insert_photos_json, + + type: 'add', + ml: { +JS + $$body .= "'fotki.album.remove.image': '".BML::ml('fotki.album.remove.image')."'," + ."'fotki.album.close.without.saving.confirm': '".BML::ml('fotki.album.close.without.saving.confirm')."'," + ."'fotki.album.create.new': '".BML::ml('fotki.album.create.new')."'"; + $$body .= <<JS; + } + }) + .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 .= "\n\n<form method='post' action='update.bml$getextra' id='updateForm' name='updateForm'>\n\n"; $$body .= LJ::form_auth(); if ($opts->{require_tos}){