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: Making title field mandatory when uploading  (Read 8482 times)

0 Members and 1 Guest are viewing this topic.

jayhunter

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 29
Making title field mandatory when uploading
« 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
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Making title field mandatory when uploading
« Reply #1 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? :)
Logged

jayhunter

  • Contributor
  • Coppermine novice
  • ***
  • Offline Offline
  • Posts: 29
Re: Making title field mandatory when uploading
« Reply #2 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é
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Making title field mandatory when uploading
« Reply #3 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. Thanks.
Logged
Pages: [1]   Go Up
 

Page created in 0.018 seconds with 19 queries.