forum.coppermine-gallery.net

Support => cpg1.5.x Support => cpg1.5 upload => Topic started by: jayhunter on September 03, 2010, 11:24:36 am

Title: Making title field mandatory when uploading
Post by: jayhunter on September 03, 2010, 11:24:36 am
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
Title: Re: Making title field mandatory when uploading
Post by: Αndré on September 03, 2010, 12:18:48 pm
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? :)
Title: Re: Making title field mandatory when uploading
Post by: jayhunter on September 03, 2010, 02:02:53 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
Code: [Select]
        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
Code: [Select]
        $result = add_picture($album, $filepath, $picture_name, 0, '', '', '', '', '', '', '', $category);
.. replace with
Code: [Select]
        $result = add_picture($album, $filepath, $picture_name, 0, equalize_filename($picture_name), '', '', '', '', '', '', $category);

Works great for me ..
But thanks for offering help André
Title: Re: Making title field mandatory when uploading
Post by: Αndré on September 03, 2010, 02:09:02 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.


Actually found my solution (2.):
Great :)


Now you can mark your thread as solved (http://forum.coppermine-gallery.net/index.php/topic,55415.msg270631.html#msg270631). Thanks.