wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r21803: LJSUP-11820: Add ability to add photos f...

Committer: wisest-owl
LJSUP-11820: Add ability to add photos from album

U   trunk/cgi-bin/LJ/Widget/EntryForm.pm
Modified: trunk/cgi-bin/LJ/Widget/EntryForm.pm
===================================================================
--- trunk/cgi-bin/LJ/Widget/EntryForm.pm	2012-04-26 09:59:21 UTC (rev 21802)
+++ trunk/cgi-bin/LJ/Widget/EntryForm.pm	2012-04-26 10:24:27 UTC (rev 21803)
@@ -804,9 +804,7 @@
                 $BML::ML{'entryform.insert.image2'}
             </a>
         </li>
-    } : "";
-
-    $insert_image .= ($remote && ($remote->prop ('fotki_migration_status') != LJ::Pics::Migration::MIGRATION_STATUS_NONE()) && $remote->can_use_ljphoto) ? qq{
+    } : qq{ 
     <li class='image'>
         <a
             href='javascript:void(0);'
@@ -816,7 +814,7 @@
             $BML::ML{'entryform.insert.image2'}
         </a>
     </li>
-    } : "";
+    };
 
     my $insert_media = '';
     unless ($LJ::DISABLED{embed_module}) {
@@ -1628,79 +1626,103 @@
 
     my $remote = $self->remote ();
 
-    # in case of insert one photo or photo album
-    my $insert_photos = [];
+    my ($migration_status, $ljphoto_enabled, $ljphoto_upload_enabled, $photouploader_params_out, $insert_photos)
+        = (0, 0, 0, "", []);
 
-    my $albums_id = $opts->{'albums_id'};
-    my $photos_id = $opts->{'photos_id'};
+    my $photouploader_params;
+    my $photouploader_params_out;
 
-    my @photos = grep { $_ } map {
-        my $photo = LJ::Pics::Photo->load_and_check_auth( $remote, $_ );
-        $photo;
-    } split (/,/, $photos_id);
+    if ($remote) {
+        # in case of insert one photo or photo album
 
-    foreach my $album_id (split /,/, $albums_id) {
-        my $album = LJ::Pics::Album->load_and_check_auth( $remote, $album_id );
-        next unless $album;
-        push @photos, $album->photos;
-    }
+        my $albums_id = $opts->{'albums_id'};
+        my $photos_id = $opts->{'photos_id'};
 
-    $insert_photos = [ grep { $_ } map {
-            my $photo = $_;
+        my @photos = grep { $_ } map {
+            my $photo = LJ::Pics::Photo->load_and_check_auth( $remote, $_ );
+            $photo;
+        } split (/,/, $photos_id);
 
-            my $res = $photo ? {
-                photo_desc  => $photo->prop('description'),
-                photo_title => $photo->prop('title'),
-                photo_url   => $photo->image_url( 'size' => @photos > 1 ? 100 : 600 ),
-                photo_id    => $photo->photo_id_displayed,
-            } : undef;
-            $res;
-        } @photos ];
+        foreach my $album_id (split /,/, $albums_id) {
+            my $album = LJ::Pics::Album->load_and_check_auth( $remote, $album_id );
+            next unless $album;
+            push @photos, $album->photos;
+        }
 
-    my @photo_sizes = map { {
-        'size'       => $_,
-        'text'       => LJ::Lang::ml("fotki.size.$_.text"),
-        'is_default' => ( $_ == $remote->prop ('user_selected_image_size') ) ? 1 : 0,
-    } } @LJ::Pics::Photo::DISPLAYED_SIZES;
+        $insert_photos = [ grep { $_ } map {
+                my $photo = $_;
 
-    my $album_list = [];
-    my $available_space = '';
-    $album_list = [ LJ::Pics::Album->list( 'userid' => $remote->userid ) ];
-    $album_list = [
-        map {
-            my $album = $_;
-            {
-                album_title => $album->album_title,
-                album_id    => $album->album_id_displayed,
-            }
-        } @$album_list
-    ];
-    my $available_space = LJ::Widget::Fotki::UserSpace->display_space(
-        LJ::Pics->get_free_space($remote) );
+                my $res = $photo ? {
+                    photo_desc  => $photo->prop('description'),
+                    photo_title => $photo->prop('title'),
+                    photo_url   => $photo->image_url( 'size' => @photos > 1 ? 100 : 600 ),
+                    photo_id    => $photo->photo_id_displayed,
+                } : undef;
+                $res;
+            } @photos ];
 
-    my $auth_token =
-        LJ::Auth->sessionless_auth_token( '/' . $remote->username );
+        my @photo_sizes = map { {
+            'size'       => $_,
+            'text'       => LJ::Lang::ml("fotki.size.$_.text"),
+            'is_default' => ( $_ == $remote->prop ('user_selected_image_size') ) ? 1 : 0,
+        } } @LJ::Pics::Photo::DISPLAYED_SIZES;
 
-    my $ljphoto_upload_enabled = $remote->can_upload_photo();
-    my $ljphoto_enabled = 0;
-    $ljphoto_enabled = 1 if $remote && $remote->can_use_ljphoto && !LJ::Pics::Migration->user_under_maintenance ($remote);
+        my $album_list = [];
+        my $available_space = '';
+        $album_list = [ LJ::Pics::Album->list( 'userid' => $remote->userid ) ];
+        $album_list = [
+            map {
+                my $album = $_;
+                {
+                    album_title => $album->album_title,
+                    album_id    => $album->album_id_displayed,
+                }
+            } @$album_list
+        ];
+        my $available_space = LJ::Widget::Fotki::UserSpace->display_space(
+            LJ::Pics->get_free_space($remote) );
 
-    LJ::Widget::Fotki::Upload->render();
+        my $auth_token =
+            LJ::Auth->sessionless_auth_token( '/' . $remote->username );
 
-    my $photouploader_params = {
-        'action'          => 'add_new_post',
-        'availableSpace'  => $available_space,
-        'sizesData'       => \@photo_sizes,
-        'albumsData'      => $album_list,
-        'privacyData'     => LJ::Widget::Fotki::Photo->get_user_groups($remote),
-        'type'            => 'upload',
-        'guid'            => $auth_token,
-    };
+        $ljphoto_upload_enabled = $remote->can_upload_photo();
+        $ljphoto_enabled = 1 if $remote && $remote->can_use_ljphoto && !LJ::Pics::Migration->user_under_maintenance ($remote);
 
-    my $photouploader_params_out = LJ::JSON->to_json($photouploader_params);
+        $photouploader_params = {
+            'action'          => 'add_new_post',
+            'availableSpace'  => $available_space,
+            'sizesData'       => \@photo_sizes,
+            'albumsData'      => $album_list,
+            'privacyData'     => LJ::Widget::Fotki::Photo->get_user_groups($remote),
+            'type'            => 'upload',
+            'guid'            => $auth_token,
+        };
 
-    my $migration_status = $remote ? ($remote->prop ('fotki_migration_status') || 0) : 0;
+        $photouploader_params_out = LJ::JSON->to_json($photouploader_params);
 
+        $migration_status = $remote ? ($remote->prop ('fotki_migration_status') || 0) : 0;
+    } else {
+        my @photo_sizes = map { {
+            'size'       => $_,
+            'text'       => LJ::Lang::ml("fotki.size.$_.text"),
+            'is_default' => ( $remote && $_ == $remote->prop ('user_selected_image_size') ) ? 1 : 0,
+        } } @LJ::Pics::Photo::DISPLAYED_SIZES;
+
+
+        $photouploader_params = {
+            'action'          => 'add_new_post',
+            'sizesData'       => \@photo_sizes,
+            'albumsData'      => [],
+            'privacyData'     => LJ::Widget::Fotki::Photo->get_user_groups($remote),
+            'type'            => 'upload',
+            'guid'            => '',
+        };
+
+        $photouploader_params_out = LJ::JSON->to_json($photouploader_params);
+    }
+
+    LJ::Widget::Fotki::Upload->render();
+
     $out .= <<JS ;
 <script type="text/javascript">
     window.ljphotoMigrationStatus = $migration_status;
@@ -1936,8 +1958,7 @@
     $out .= $self->render_submitbar_block;
 
     ## Show a new photoalbums interface only for logged-in users
-    $out .= $self->render_ljphoto_block
-        if $remote && $remote->can_use_ljphoto();
+    $out .= $self->render_ljphoto_block;
 
     $out .= "</div><!-- end #entry-form-wrapper -->\n\n";
 

Tags: livejournal, pm, wisest-owl
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments