Commit ff7ec148 authored by Patrick Schmalstig's avatar Patrick Schmalstig
Browse files

Fixed MANTIS-5745 (Fix mass-import to drop in correct subgallery + allow file name titles)

parent 68a238b5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -386,7 +386,7 @@ class Module_cms_galleries extends Standard_crud_module
        $fields = new Tempcode();
        $supported = get_option('valid_images') . ',' . get_allowed_video_file_types();
        $fields->attach(form_input_upload_multi(do_lang_tempcode('UPLOAD'), do_lang_tempcode('DESCRIPTION_ARCHIVE_MEDIA', escape_html(str_replace(',', ', ', $supported))), 'file', true, null, null, true, str_replace(' ', '', $supported)));
        $fields->attach(form_input_line(do_lang_tempcode('TITLE'), do_lang_tempcode('DESCRIPTION_GALLERY_IMPORT_TITLE'), 'set_title', '', get_option('gallery_media_title_required') == '2'));
        $fields->attach(form_input_line(do_lang_tempcode('TITLE'), (get_option('gallery_media_title_required') == '2') ? do_lang_tempcode('DESCRIPTION_GALLERY_IMPORT_TITLE_REQUIRED') : do_lang_tempcode('DESCRIPTION_GALLERY_IMPORT_TITLE'), 'set_title', '', false/*When required, title can be left blank to auto-generate from file names or EXIF*/));
        $hidden = new Tempcode();
        handle_max_file_size($hidden);

+7 −5
Original line number Diff line number Diff line
@@ -293,10 +293,10 @@ GALLERIES_SUBCAT_NARROWIN=Narrow-in when browsing
CONFIG_OPTION_galleries_subcat_narrowin=If set, all images/videos/multimedia files will initially be shown when browsing galleries, then entering galleries will progressively filter the selection (i.e. navigation by filtering). If unset, images/videos/multimedia files will be seen only when you enter their specific gallery (i.e. navigation by gallery). This option does not affect carousel-mode galleries.
GALLERY_IMPORT_SUCCESS_EDIT_TITLES_INLINE={1} media {1|file has|files have} been imported. You can quickly change individual titles using inline editing links in the gallery.
GALLERY_MEDIA_TITLE_REQUIRED=Require media titles
CONFIG_OPTION_gallery_media_title_required=Require image/video/multimedia file titles to be filled in. If the set title field is required then the set-titling system (automatic titles that include set numbering, e.g. 3 of 10) will always be used when mass-importing.
CONFIG_OPTION_gallery_media_title_required_VALUE_0=Not required
CONFIG_OPTION_gallery_media_title_required_VALUE_1=Required title field
CONFIG_OPTION_gallery_media_title_required_VALUE_2=Required title field, and also the set title field for mass-import
CONFIG_OPTION_gallery_media_title_required=Require image/video/multimedia file titles to be filled in. For mass-importing, if the set title field is required and a title is provided, then the set-titling system (automatic titles that include set numbering, e.g. 3 of 10) will be used. If the set title field is required and a title is not provided, then the title will either come from EXIF metadata if available, or the file name.
CONFIG_OPTION_gallery_media_title_required_VALUE_0=Do not require
CONFIG_OPTION_gallery_media_title_required_VALUE_1=Require title on single entries only
CONFIG_OPTION_gallery_media_title_required_VALUE_2=Require title on single entries and mass-import
CONFIG_OPTION_enable_ecards=Whether to enable e-cards on gallery images (e-cards allow you to send the image via the recommend addon).
ENABLE_ECARDS=Enable e-cards
CONFIG_OPTION_gallery_mode_is=The mode for new galleries. Existing galleries will continue to use what they already do, unless edited to be different.
@@ -349,7 +349,8 @@ MULTIMEDIA_FILE=Multimedia file
GALLERY_FEATURES=Gallery feature availability
MEDIA_FEATURES=Media feature availability
CAN_MASS_UPLOAD=Did you know you can also <a href="{1}">upload in bulk</a>?
DESCRIPTION_GALLERY_IMPORT_TITLE=A title for the media set. The media will be given a title of this plus a numbering suffix.
DESCRIPTION_GALLERY_IMPORT_TITLE=A title for the media set. The media will be given a title of this plus a numbering suffix. If left blank, then media will be titled according to what is in EXIF metadata, otherwise blank.
DESCRIPTION_GALLERY_IMPORT_TITLE_REQUIRED=A title for the media set. The media will be given a title of this plus a numbering suffix. If left blank, then media will be titled according to what is in EXIF metadata, otherwise it will be derived from the file name.
MEDIA_FILE_IN_SET={1} ({2} of {3})
PRIVILEGE_autocomplete_keyword_gallery=Autocomplete searches based on any gallery keywords
PRIVILEGE_autocomplete_title_gallery=Autocomplete searches based on any gallery titles
@@ -400,3 +401,4 @@ CONFIG_OPTION_homepage_slider_fullscreen=Make the slider fullscreen. Only availa
DESCRIPTION_CLOSED_CAPTIONS=A WebVTT file (<kbd>.vtt</kbd>) or the URL to a WebVTT file containing closed captions for the video.
DESCRIPTION_THUMBNAIL=You must upload a thumbnail (width: {1} pixels) for this video, unless your server can auto-generate one from the media file.
DESCRIPTION_PRIVACY_GALLERIES=Handle data pertaining to your galleries and the images, videos, and multimedia you uploaded to your or others' galleries.
MEDIA_FILE_FALLBACK_TITLE={1} entry {2}
 No newline at end of file
+27 −5
Original line number Diff line number Diff line
@@ -121,6 +121,10 @@ function image_get_defaults__post(bool $is_edit = false, string $url = '', ?stri
 */
function image_get_default_metadata(string $url = '', ?string $filename = null, string $title = '', string $cat = '') : array
{
    if (($filename === null) && ($url != '')) {
        $filename = rawurldecode(basename($url));
    }

    if ($title == '') {
        if ($url != '') {
            $path = convert_url_to_path($url);
@@ -141,6 +145,7 @@ function image_get_default_metadata(string $url = '', ?string $filename = null,
    return [
        $title,
        $cat,
        /*$filename,*/
    ];
}

@@ -1984,7 +1989,7 @@ function reorganise_uploads__gallery_videos(array $where = [], bool $tolerate_er
 * Intended for bulk operations, where many mixed media files are imported with common settings and other settings derived from metadata/defaults.
 *
 * @param  URLPATH $url The URL to the file (must be a URL relative to the base URL)
 * @param  ID_TEXT $cat The gallery to add to
 * @param  ID_TEXT $_cat The gallery to add to
 * @param  MEMBER $member_id The ID of the member adding gallery media
 * @param  integer $allow_rating Post param indicating whether or not ratings should be allowed
 * @param  integer $allow_comments_reviews Post param combination indicating whether to allow comments or reviews
@@ -1995,9 +2000,10 @@ function reorganise_uploads__gallery_videos(array $where = [], bool $tolerate_er
 * @param  array $additional_access Array of additional members who should have access to this content
 * @param  ?string $filename The filename (null: derive from $url)
 * @param  ?TIME $time Timestamp to use (null: now)
 * @param  string $fallback_title The fallback title to use if a title is required but we could not get one (blank: none)
 * @return ?array A pair: The media type, The media ID (null: error)
 */
function add_gallery_media_wrap(string $url, string $cat, int $member_id, int $allow_rating, int $allow_comments_reviews, int $allow_trackbacks, bool $watermark, string $notes, string $privacy_level, array $additional_access, ?string $filename = null, ?int $time = null) : ?array
function add_gallery_media_wrap(string $url, string $_cat, int $member_id, int $allow_rating, int $allow_comments_reviews, int $allow_trackbacks, bool $watermark, string $notes, string $privacy_level, array $additional_access, ?string $filename = null, ?int $time = null, string $fallback_title = '') : ?array
{
    require_code('exif');

@@ -2021,7 +2027,15 @@ function add_gallery_media_wrap(string $url, string $cat, int $member_id, int $a
            $length,
            $title,
            $cat,
        ) = video_get_default_metadata($url, '', $filename, null, null, null, '', $cat);
        ) = video_get_default_metadata($url, '', $filename, null, null, null, '', $_cat);

        if (($title == '') && (get_option('gallery_media_title_required') == '2')) {
            if ($filename !== null) {
                $title = pathinfo($filename, PATHINFO_FILENAME);
            } else {
                $title = $fallback_title;
            }
        }

        $thumb_url = video_get_default_thumb_url($url, '', $filename);

@@ -2062,7 +2076,7 @@ function add_gallery_media_wrap(string $url, string $cat, int $member_id, int $a
        // Images cleanup pipeline
        $maximum_dimension = intval(get_option('maximum_image_size'));
        $watermark = (post_param_integer('watermark', 0) == 1);
        $watermarks = $watermark ? find_gallery_watermarks($cat) : null;
        $watermarks = $watermark ? find_gallery_watermarks($_cat) : null;
        if (url_is_local($url)) {
            handle_images_cleanup_pipeline(get_custom_file_base() . '/' . rawurldecode($url), null, IMG_RECOMPRESS_LOSSLESS, $maximum_dimension, $watermarks);
        }
@@ -2070,7 +2084,15 @@ function add_gallery_media_wrap(string $url, string $cat, int $member_id, int $a
        list(
            $title,
            $cat,
        ) = image_get_default_metadata($url, $filename);
        ) = image_get_default_metadata($url, $filename, '', $_cat);

        if (($title == '') && (get_option('gallery_media_title_required') == '2')) {
            if ($filename !== null) {
                $title = pathinfo($filename, PATHINFO_FILENAME);
            } else {
                $title = $fallback_title;
            }
        }

        $id = add_image($title, $cat, '', $url, 1, $allow_rating, $allow_comments_reviews, $allow_trackbacks, $notes, null, $time);
        $path = convert_url_to_path($url);
+8 −1
Original line number Diff line number Diff line
@@ -57,6 +57,7 @@ class Hook_task_import_gallery_media

        task_log($this, 'Processing ' . integer_format(count($files)) . ' files for importing into gallery ' . $cat);

        $media_number = 0;
        foreach ($files as $path => $filename) {
            if ((is_image($path, IMAGE_CRITERIA_WEBSAFE, has_privilege($member_id, 'comcode_dangerous'))) || (is_video($path, has_privilege($member_id, 'comcode_dangerous')))) {
                list($new_path, $new_url, $new_filename) = find_unique_path('uploads/galleries', filter_naughty($filename), true);
@@ -78,10 +79,16 @@ class Hook_task_import_gallery_media
                    $new_url = $test;
                }

                $fallback_title = '';
                if ($set_title == '') {
                    $fallback_title = do_lang('MEDIA_FILE_FALLBACK_TITLE', $cat, ($media_number + 1));
                }

                // Add to database
                $import_details = add_gallery_media_wrap($new_url, $cat, $member_id, $allow_rating, $allow_comments_reviews, $allow_trackbacks, $watermark, $notes, $privacy_level, $additional_access, $new_filename);
                $import_details = add_gallery_media_wrap($new_url, $cat, $member_id, $allow_rating, $allow_comments_reviews, $allow_trackbacks, $watermark, $notes, $privacy_level, $additional_access, $new_filename, null, $fallback_title);

                if ($import_details !== null) {
                    $media_number++;
                    $media_imported[] = $import_details;
                }
            } else {