Comparing filenames in item file loop

I'm trying to compare original filenames/extensions within an item record's file loop.

I've got this so far:

while(loop_files_for_item()){
   $file = get_current_file();
   $extension = pathinfo($file->original_filename, PATHINFO_EXTENSION);
   $name = pathinfo($file->original_filename, PATHINFO_FILENAME);
}

...which obviously doesn't entirely get the job done.

Basically, I'd like to compare filenames to selectively show or hide manually-created thumbnails for documents being rendered in the Docs Viewer.

For example, if I have uploaded a PDF file named document.pdf and a dummy image called document.jpg (or perhaps document_cover.jpg), I'd like to not display the jpg on the items/show.php page (the purpose of the manually-created thumbnail is just to use in exhibits, etc).

An added bonus would be some method to check if the Document Viewer is being loaded on a particular items/show page, but that's less of an issue for now.

Thanks - E

By the way, I'm currently just using jQuery to see if the Doc Viewer is engaged and then hiding the div containing the thumbnails.

jQuery.fn.exists = function(){return this.length>0;}

if (jQuery("iframe[src^='http://docs.google.com/viewer?']").exists()) {
    jQuery("#item-images").hide();
}

But I'd feel slightly better if I could do this all server-side.

You're on the right track. Something like this should work:

while(loop_files_for_item()){
   $file = get_current_file();
   $extension = pathinfo($file->original_filename, PATHINFO_EXTENSION);
   // don't include jpg files
   if (preg_match('/^(jpg|jpeg)$/i', $extension)) {
      continue;
   }
   // display the file...
}

You can detect that the document viewer will load by comparing the item's file extensions to DocsViewerPlugin::$_supportedFiles. If there's at least one match, the plugin will load the viewer.

And what if I wanted to (instead/also) base it on a specific filename using the $name variable above?

The main issue I'm having (and it's obviously not an Omeka issue so much as a PHP skills issue) is trying to compare each of the $name results (for example by looking for a full/partial/pattern match in the filename).

Match $name against a predefined name pattern:

if (preg_match('/^document(_cover)?$/', $name)) {
    continue;
}