Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: MOD: preselect an album to upload to via link  (Read 6818 times)

0 Members and 1 Guest are viewing this topic.

divestoclimb

  • Contributor
  • Coppermine newbie
  • ***
  • Offline Offline
  • Posts: 16
MOD: preselect an album to upload to via link
« on: December 15, 2008, 11:33:09 pm »

The users of my gallery sometimes were picking the wrong album to place their uploaded images into, so I came up with a modified uploading scheme where users can select an album to upload to by clicking on a link, and that choice is remembered for the image placement phase of the upload process. Such a link can be put in the description for the album. For example, http://your-coppermine-gallery.net/upload.php?album=11 would present exactly the same uploading screen but all photos uploaded from here will get placed into album #11, and the drop-down box to select an album will be hidden (you will, however, be able to enter a title, description, etc.).

This mod was made against Coppermine 1.4.19. In upload.php, find the following code:
Code: [Select]
        create_form($data);
        close_form($lang_continue);
        endtable();
and above it add the following:
Code: [Select]
if(array_key_exists("album", $_GET) and is_numeric($_GET["album"])) {
    array_push($data, array("album", $_GET["album"], 4));
}

Find this code section:
Code: [Select]
            // Add the control device.
            $form_array[] = array('control', 'phase_1', 4);

        } else {

            // Unknown form number.
            cpg_die(ERROR, $lang_upload_php['reg_instr_1'], __FILE__, __LINE__);

        }

    }

    // Create the form.
    create_form($form_array);
and above it add the following:
Code: [Select]
    if(array_key_exists("album", $_GET) and is_numeric($_GET["album"])) {
array_push($form_array, array("album", $_GET["album"], 4));
    }

Now here's where it gets a little tricky. Look for this comment, followed shortly by the following four lines:
Code: [Select]
        // Prepare success data for user.
[...]

        $form_array = array(
             array('unique_ID', $unique_ID, 4),
             array('control', 'phase_2', 4)
        );
Replace the last four lines above with the following:
Code: [Select]
        $form_array = array(
            array('unique_ID', $unique_ID, 4)
        );

if(array_key_exists("album", $_POST) and is_numeric($_POST["album"])) {
    array_push($form_array, array("preset_album", $_POST["album"], 4));
}

array_push($form_array,
    array('control', 'phase_2', 4)
);

Find this code:
Code: [Select]
    $form_array = array(
    array($lang_upload_php['album'], 'album', 2),
    array($lang_upload_php['pic_title'], 'title', 0, 255, 1, $title),
    array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length'], (isset($iptc['Caption'])) ? $iptc['Caption'] : ''),
    array($lang_upload_php['keywords'], 'keywords', 0, 255, 1,(isset($iptc['Keywords'])) ? implode(' ',$iptc['Keywords']): ''),
    array('control', 'phase_2', 4),
    array('unique_ID', $_POST['unique_ID'], 4),
    );
And replace it with the following:
Code: [Select]
    $form_array = array();
    if(array_key_exists("preset_album", $_POST) and is_numeric($_POST["preset_album"])) {
array_push($form_array, array("album", $_POST["preset_album"], 4));
    } else {
array_push($form_array, array($lang_upload_php['album'], 'album', 2));
    }
    array_push($form_array,
    array($lang_upload_php['pic_title'], 'title', 0, 255, 1, $title),
    array($captionLabel, 'caption', 3, $CONFIG['max_img_desc_length'], (isset($iptc['Caption'])) ? $iptc['Caption'] : ''),
    array($lang_upload_php['keywords'], 'keywords', 0, 255, 1,(isset($iptc['Keywords'])) ? implode(' ',$iptc['Keywords']): ''),
    array('control', 'phase_2', 4),
    array('unique_ID', $_POST['unique_ID'], 4)
    );
The last few lines are almost identical, the only difference is that the comma was removed from the end of the last array element (if you fail to do this you'll get a PHP syntax error).

An interesting side note: notice how my modification switches from using the parameter "album" to "preset_album" and then back to "album" again. If you change all occurrences of "preset_album" to "album" in my code above, users will never be prompted for a title or description--instead, they will be told that their upload was successful and after clicking continue the images they uploaded will automatically get placed in the selected album. It would be a little weird, though, because users would be asked to click "Continue" three times in a row without filling out any new information.
Logged
Pages: [1]   Go Up
 

Page created in 0.018 seconds with 19 queries.