TikiMods

From IckyWiki

Jump to: navigation, search

Mods to Tiki

making it more useful to me for various reasons - EricaErkkila

deprecated: we don't use this anymore.

Contents

exif dates in image names for image uploads

NOTE: only works for local upload, either zip or single; will not work for URL uploads (which I can't get working even out of the box for some reason...)

What: in the image upload screen, adds an option to append or prepend a date found in the exif headers of an image onto the name of the image.

Why: I'm uploading a shitload of images and they end up all lumped into the same date. If I can at least get their 'real' (ie captured) date into the name, I can sort on name and they'll be roughly in order (unless the exif date wasn't found). I was doing this all manually until I decided that was stupid.

Caveats:

  • It can only tack on an exif date if found
  • Only works for some Kodak cameras, because I know the date fieldname for some of them. If your camera uses the same format (or you can find out what the field name is), you can mod the code as needed.
  • Current order of preference on dates (first one found is used, rest are ignored): DateTimeOriginal, DateTimeDigitized, DateTime

behavior

Behavior for single image uploads:
prepend exif date if found?Image NameUse filename?apppend exif date if found?exif date found in image?Result
noblanknononoerror message occurs: you must set name
noblanknonoyeserror message occurs: you must set name
noblanknoyesnoerror message occurs: you must set name
noblanknoyesyesjust exif date will be used
noblankyesnonojust filename will be used
noblankyesnoyesjust filename will be used
noblankyesyesnojust filename will be used
noblankyesyesyesfilename+exif date will be used
nosetnononojust name will be used
nosetnonoyesjust name will be used
nosetnoyesnojust name will be used
nosetnoyesyesname+exif date will be used
nosetyesnonojust filename will be used
nosetyesnoyesjust filename will be used
nosetyesyesnojust filename will be used
nosetyesyesyesfilename+exif date will be used
yesblanknononoerror message occurs: you must set name
yesblanknonoyesjust exif date will be used
yesblanknoyesnoerror message occurs: you must set name
yesblanknoyesyesexif date will be used twice
yesblankyesnonojust filename will be used
yesblankyesnoyesexif date+filename will be used
yesblankyesyesnojust filename will be used
yesblankyesyesyesexif date+filename+exif date will be used
yessetnononojust name will be used
yessetnonoyesexif date+name will be used
yessetnoyesnojust name will be used
yessetnoyesyesexif date+name+exif date will be used
yessetyesnonojust filename will be used
yessetyesnoyesexif date+filename will be used
yessetyesyesnojust filename will be used
yessetyesyesyesexif date+filename+exif date will be used


Behavior for batch image uploads:
prepend exif date if found?Image NameUse filename?apppend exif date if found?exif date found in image?Result
noblanknononojust filename will be used
noblanknonoyesjust filename will be used
noblanknoyesnojust filename will be used
noblanknoyesyesjust exif date will be used
noblankyesnonojust filename will be used
noblankyesnoyesjust filename will be used
noblankyesyesnojust filename will be used
noblankyesyesyesfilename+exif date will be used
nosetnononojust name will be used
nosetnonoyesjust name will be used
nosetnoyesnojust name will be used
nosetnoyesyesname+exif date will be used
nosetyesnonojust filename will be used
nosetyesnoyesjust filename will be used
nosetyesyesnojust filename will be used
nosetyesyesyesfilename+exif date will be used
yesblanknononojust filename will be used
yesblanknonoyesjust exif date will be used
yesblanknoyesnojust filename will be used
yesblanknoyesyesexif date will be used twice
yesblankyesnonojust filename will be used
yesblankyesnoyesexif date+filename will be used
yesblankyesyesnojust filename will be used
yesblankyesyesyesexif date+filename+exif date will be used
yessetnononojust name will be used
yessetnonoyesexif date+name will be used
yessetnoyesnojust name will be used
yessetnoyesyesexif date+name+exif date will be used
yessetyesnonojust filename will be used
yessetyesnoyesexif date+filename will be used
yessetyesyesnojust filename will be used
yessetyesyesyesexif date+filename+exif date will be used

code

OK, now the meat. I saved my new files as filename.epe in case updates to tiki overwrite my mods.


First, add checkboxes to the upload image page to turn on the option:

templates/tiki-upload_image.tpl

change:

    <input type="text" size ="50" name="name" /><br/>{tr}or use filename{/tr}: <input type="checkbox" name="use_filename" />

to:

     <input type="text" size ="50" name="name" /><br/>{tr}or use filename{/tr}: <input type="checkbox" name="use_filename" /><br/>{tr}append exif date if found{/tr}:<input type="checkbox" name="use_exif_date_append" /><br/>{tr}prepend exif date if found{/tr}:<input type="checkbox" name="use_exif_date_prepend" /></td></tr>

This adds checkboxes for the option.

tiki-upload_image.php

Right before the line:

  if (!empty($_REQUEST["url"])) {   

add this:

       
        $exif_date_name = '';
        $use_exif_date_append = '0';
        $use_exif_date_prepend = '0';
        if (isset($_REQUEST["use_exif_date_append"]) && $_REQUEST["use_exif_date_append"] == 'on')
        {
                $use_exif_date_append = '1';
        }
        if (isset($_REQUEST["use_exif_date_prepend"]) && $_REQUEST["use_exif_date_prepend"] == 'on')
        {
                $use_exif_date_prepend = '1';
        }

This initializes some variables we'll use later, plus determine if exif date is wanted.

Right before the line:

    if ($imagegallib->process_batch_image_upload($_REQUEST["galleryId"], $_FILES['userfile1']['tmp_name'], $user)

add this:

                                        $imagegallib->use_exif_date_append = $use_exif_date_append;
                                        $imagegallib->use_exif_date_prepend = $use_exif_date_prepend;
                                        $imagegallib->exif_name = "";
                                        $imagegallib->use_exif_filename = '0';
                                        if (isset($_REQUEST["use_filename"]) && $_REQUEST["use_filename"] == 'on') {
                                                $imagegallib->use_exif_filename = '1';
                                        }
                                        if ( !empty($_REQUEST["name"]) )
                                        {
                                                $imagegallib->exif_name = $_REQUEST["name"];
                                        }

This adds some variables to the imagegallib object so that when we call process_batch_image_upload, it'll know whether it needs to tack on date or use the image label (the latter is something it never did before, as they probably assumed nobody would want the same name on all images in a batch upload. Dammit, I do. Or at least, when adding a date, I might want the same label in front of them all with only date varying.

Then, right after this bit in the part that's grabbing an image (not thumbnail):

                        $fp = fopen($tmp_dest, "rb");
                        $data = fread($fp, filesize($tmp_dest));
                        fclose ($fp);

Add this:

                        $exif_info = read_exif_data($tmp_dest);
                        while(list($k,$v)=each($exif_info)) {
                                //echo "$k: $v\n";
                                if ($exif_date_name == '' && $k == 'DateTimeOriginal' && $v != '' )
                                {
                                        $exif_date_name=$v;
                                }
                                if ($exif_date_name == '' && $k == 'DateTimeDigitized' && $v != '' )
                                {
                                        $exif_date_name=$v;
                                }
                                if ($exif_date_name == '' && $k == 'DateTime' && $v != '' )
                                {
                                        $exif_date_name=$v;
                                }
                        }

This is the part that actually reads the exif header from the image, given filename. Note the limited number of date fields I know about.

Just before this:

    if ($error_msg) {
        $smarty->assign('msg', $error_msg);

        $smarty->display("error.tpl");
        die;
    }

add:

        if ($exif_date_name == '')
        {
                $use_exif_date_append = '0';
                $use_exif_date_prepend = '0';
        }

        if (empty($_REQUEST["name"]) && (!isset($_REQUEST["use_filename"]) || $_REQUEST["use_filename"] == 'off') && 
$use_exif_date_append == '0' && $use_exif_date_prepend == '0' ) {
                $error_msg = tra("You have to provide a name to the image");
        }

That will allow them to not enter an image name or check 'Use Filename' but just to have it tack the date on as name, if it's available. Note that if it didn't find a date, this will not be possible and they'll get an error message.

Change this:

    if (isset($_REQUEST["name"]) && !empty($_REQUEST["name"])) {
        $name = $_REQUEST["name"];
    } elseif (isset($filename)) {
        $name = $filename;
    } else {
        $name = "";
    }

To this:

       
    $name = "";
    if ($use_exif_date_prepend == '1') {
        $name = $exif_date_name;
    }
    if (isset($_REQUEST["name"]) && !empty($_REQUEST["name"])) {
        $name = $name . $_REQUEST["name"];
    } elseif (isset($filename)) {
        $name = $name . $filename;
    } else {
        $name = "";
    }
    if ($use_exif_date_append == '1') {
        $name = $name  . $exif_date_name;
    }

This is because it is entirely possible that the 'name' could now be blank, so we should set it accordingly. The last bit tacks on the date, if found and wanted.

lib/imagegals/imagegallib.php

Right after this:

                                // read image and delete it after
                                $this->readimagefromfile($tmpDir . "/" . $file);

Add this:

                                $exif_name = '';
                                $exif_date_name = '';
                                $exif_info = read_exif_data($tmpDir . "/" . $file);
                                while(list($k,$v)=each($exif_info)) {
                                        //echo "$k: $v\n";
                                        if ($exif_date_name == '' && $k == 'DateTimeOriginal' && $v != '' )
                                        {
                                                $exif_date_name=$v;
                                        }
                                        if ($exif_date_name == '' && $k == 'DateTimeDigitized' && $v != '' )
                                        {
                                                $exif_date_name=$v;
                                        }
                                        if ($exif_date_name == '' && $k == 'DateTime' && $v != '' )
                                        {
                                                $exif_date_name=$v;
                                        }
                                }

                                if ( $exif_date_name != '' && $this->use_exif_date_prepend == '1')
                                {
                                        $exif_name = $exif_date_name;
                                }
                                if ( $this->use_exif_filename == '1' )
                                {
                                        $exif_name = $exif_name . $file;
                                }
                                else if ( $this->exif_name != '' )
                                {
                                        $exif_name = $exif_name . $this->exif_name;
                                }
                                if ( $exif_date_name != '' && $this->use_exif_date_append == '1')
                                {
                                        $exif_name = $exif_name . $exif_date_name;
                                }
                                if ( $exif_name == '' )
                                {
                                        $exif_name = $file;
                                }

This grabs your exif date and handles the possible logic as noted in the table above for batch uploads.

Then, change this:

                                        $imageId = $this->insert_image($galleryId, $file,

To this:

                                        $imageId = $this->insert_image($galleryId, $exif_name,

This is just so that when inserted into Tiki, the batch image gets the desired name instead of always the filename.


our web icon (changing), openID support, jshead/jsurl support

code

templates/header.tpl

change:

{if $favicon}<link rel="icon" href="{$favicon}" />{/if}

to:

{* --- if $favicon --- *}{* --- <link rel="icon" href="{$favicon}" /> --- *}{* --- /if ---*}
<link rel="icon" href="icons/icon.gif"/>
<link rel="openid.server" href="http://pee.erkkila.org/cgi-bin/openID.cgi"/>

{if $jshead ne ''}{/if}
{if $jsurlhead ne ''}{/if}


templates/styles/simple/header.tpl

add after:

        </title>

this:

           {if $jshead ne ''}{/if}

Be SURE then to obtain lib/wiki-plugins/wikiplugin_jsfile.php and wikiplugin_jsurl.php and chmod 664 them. Possibly also wikiplugin_wikigraph.php? (unrelated)

  • openID support is to redirect requests for user.domain.com to the openID server.
  • the icon thing is to point to a different favorite icon location, which we have changing every so often via a cron job
  • jshead/jsurl are wiki plugins we're using for a few of the wiki pages (CPK in particular).

Enjoy! YMMV.

Personal tools