Making title field mandatory when uploading Making title field mandatory when uploading
 

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]

Main Menu

Making title field mandatory when uploading

Started by jayhunter, September 03, 2010, 11:24:36 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jayhunter

Hi there!

Searched the website up and down but only found a threat on this topic where the author got banned because of not having obeyed the board rules.
Sorry for violating the board rules myself. I can't provide a working URL to my coppermine cause it's only available on an intranet.

Well, my question is basicly the Subject. Is there a way to make the tilte field mandatory to upload?
I also could solve this problem by automaticly having the file name as title.  Just need that title field filled with information.
Can anyone help me out and tell me where to change what?

Using CPG 1.5.8 default theme.
Please tell me if you need more information. Thanks.


Regards

Αndré

Since cpg1.5.x we have 2 different http upload possibilities. I currently see 3 different solutions:
1.) let the upload script die and return an error if no title was submitted (works only for simple upload and needs code modifications)
2.) modify the code to use the file name as default title, if no title was submitted (works for all upload methods but needs code modifications)
3.) create a script which will be called from time to time (e.g. via cronjob) that updates all empty titles with the file name (advantage: no code modifications)

What's your favorite method? :)

jayhunter

Quote from: Αndré on September 03, 2010, 12:18:48 PM
1.) let the upload script die and return an error if no title was submitted (works only for simple upload and needs code modifications)
2.) modify the code to use the file name as default title, if no title was submitted (works for all upload methods but needs code modifications)
3.) create a script which will be called from time to time (e.g. via cronjob) that updates all empty titles with the file name (advantage: no code modifications)

Would love to have 1. but need it for the flash uploader too.

Actually found my solution (2.):

Wrote a little function to clean the filename nicely and then use the result as title.
Added anywhere in upload.php

        function equalize_filename($filename) {
            if ($filename == "") return '';
            $newTitle = $filename;
            // Remove file extension
            $filename = substr($filename, 0, strrpos($filename, '.'));
            // Remove resolution details
            $filename = preg_replace("/[0-9]{1,}[p]|[0-9]{1,}[x][0-9]{1,}/", "", $filename);
            // Replace non-descriptive characters with spaces
            $filename = preg_replace("/[^a-zA-Z\.]/"," ", $filename);
            // Common characters with words of the same meaning
            $filename = preg_replace("/( and | und | en | et | y )/", " & ", $filename);
            // Make every word's first char uppercase
            $filename = ucwords($filename);
            // Remove double spaces and return the cleaned title
            $filename = trim(preg_replace("/[ ]{1,}/", " ", $filename));
            return $filename;
        }


Find in upload.php

        $result = add_picture($album, $filepath, $picture_name, 0, '', '', '', '', '', '', '', $category);

.. replace with

        $result = add_picture($album, $filepath, $picture_name, 0, equalize_filename($picture_name), '', '', '', '', '', '', $category);


Works great for me ..
But thanks for offering help André

Αndré

Quote from: jayhunter on September 03, 2010, 02:02:53 PM
Would love to have 1. but need it for the flash uploader too.
Doesn't work, as the files are first uploaded and after all files are uploaded, you'll have to enter the file details.


Quote from: jayhunter on September 03, 2010, 02:02:53 PM
Actually found my solution (2.):
Great :)


Now you can mark your thread as solved. Thanks.