Help with Filename to File Title Help with Filename to File Title
 

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

Help with Filename to File Title

Started by Walker, December 22, 2007, 05:20:31 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Walker

I would like to take the existing function:
CHANGE 2003_11_23_13_20_20.jpg TO 11/23/2003 13:20

And have it do this instead:
CHANGE 2003_11_23_13_20_20.jpg TO 11/23/2003 @ 1:20 PM

I found "function filename_to_title()" in util.php where I believe the changes will need to be made, but I don't know how to make those changes or exactly where to put them.
I know that I need something along the lines of "IF $7>=13 SET $hour==($7-12) AND SET $ap=PM", but how to translate that to work in php?
Also needed would be if statements to handle if $7==00, $7==12, and $7<=11

The final output would look like this:
$replacement = "$3/$5/$1 @ $hour:$9" $ap;


I did find this describing If...Else Statements in PHP but could not figure out how to make it work here.
http://www.w3schools.com/php/php_if_else.asp

Any help would be greatly appreciated.

Nibbler

Do it like this, using actual date functions. Makes it more flexible.


$newtitle = str_replace("%20", " ", $filename);
preg_match($pattern, $filename, $m);
$newtitle = date('m/d/Y @ g:i A', mktime($m[7], $m[9], 0, $m[3], $m[5], $m[1]));

Walker

Thank you very much Nibbler!  Worked a treat.
I knew that there should be a simpler, cleaner way than my "IF" idea, but I am no programmer.
I decided that I wanted to include the seconds so I modified it a bit and this is how I implemented it:

Find in Util.php:
case 2: // CHANGE 2003_11_23_13_20_20.jpg TO 11/23/2003 13:20
        $newtitle = str_replace("%20", " ", $filename);
        $replacement = "$3/$5/$1 $7:$9";
        $newtitle = preg_replace($pattern, $replacement, $filename);
        break;

Replace with:
case 2: // CHANGE 2003_11_23_13_20_20.jpg TO 11/23/2003 @ 1:20:20 PM
        $newtitle = str_replace("%20", " ", $filename);
preg_match($pattern, $filename, $m);
$newtitle = date('m/d/Y @ g:i:s A', mktime($m[7], $m[9], $m[11], $m[3], $m[5], $m[1]));
        break;


I have only one (very minor) problem now.  The text on the Admin Tools page still says "Change 2003_11_23_13_20_20.jpg to 11/23/2003 13:20".
I am the only admin so it is not a big deal, but it would be nice if the text reflected the changes actually being made.
Instead of changing "case 2" I tried just adding a "case 4" but the 5th option does not show up in admin tools.
Again, very minor, but I'd still like to make the change just for the sake of completeness and learning something new.

Thanks again Nibbler

Nibbler

Look further up the file and add in an extra line for 4.


        'filename_to_title' => array('filename_to_title', $lang_util_php['filename_title'],'

                <strong>'.$lang_util_php['filename_how'].' (2):</strong><br />
        <input type="radio" name="parsemode" id="parsemode1" value="0" checked="checked" class="nobg" /><label for="parsemode1" class="clickable_option">' . $lang_util_php['filename_remove'] . '</label><br />
                <input type="radio" name="parsemode" id="parsemode2" value="1" class="nobg" /><label for="parsemode2" class="clickable_option">'.$lang_util_php['filename_euro'].'</label><br />
                <input type="radio" name="parsemode" id="parsemode3" value="2" class="nobg" /><label for="parsemode3" class="clickable_option">'.$lang_util_php['filename_us'].'</label><br />
                <input type="radio" name="parsemode" id="parsemode4" value="3" class="nobg" /><label for="parsemode4" class="clickable_option">'.$lang_util_php['filename_time'].'</label><br /><br />'),


Walker

Perfect.  Thank you.

I also found where I could change the text in english.php, and by adding a new line for 'filename_ap' there I now have a 5th option in Admin Tools displaying the correct text.

I really appreciate your help.  Other than a High School class in BASIC 13 years ago, I have no programming or web design experience at all.  I've really been enjoying learning how to integrate smf/tp and cpg sharing a header, creating a theme for cpg to match smf/tp, and applying several other mods/tweaks to make it all do exactly what I want.  I couldn't have done it without the help on the forums here, at smf and tp, and of course Google.

As I keep learning, hopefully I will reach a point where I will be able to contribute something unique of my own to the community.

Cheers