<?php
/*
 * $RCSfile: GalleryUnknownItem.class,v $
 *
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2005 Bharat Mediratta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 */
/**
 * @version $Revision: 1.21 $ $Date: 2005/08/23 03:49:03 $
 * @package GalleryCore
 * @author Bharat Mediratta <bharat@menalto.com>
 */

/**
 * Load the parent class
 */
GalleryCoreApi::relativeRequireOnce('modules/core/classes/GalleryDataItem.class');

/**
 * A subclass of DataItem for containing unknown objects.
 *
 * These are objects that we know nothing about.  Currently this
 * is exactly the same as a DataItem, although that may change.
 *
 * @g2 <class-name>GalleryUnknownItem</class-name>
 * @g2 <parent-class-name>GalleryDataItem</parent-class-name>
 * @g2 <schema>
 * @g2   <schema-major>1</schema-major>
 * @g2   <schema-minor>0</schema-minor>
 * @g2 </schema>
 * @g2 <requires-id/>
 *
 * @package GalleryCore
 * @subpackage Classes
 */
class GalleryUnknownItem_core extends GalleryDataItem {

    /*
     * ****************************************
     *                 Members
     * ****************************************
     */

    /*
     * ****************************************
     *                 Methods
     * ****************************************
     */

    /**
     * Create a new GalleryUnknownItem from an image file
     *
     * @param int the id of the parent GalleryItem
     * @param string the path to the source image
     * @param string the mime type
     * @param string the desired name of the new item
     * @param boolean (optional) a boolean true if we should symlink instead
     *        of copy (default is false).
     * @return object GalleryStatus a status code
     */
    function create($parentId, $inputFileName, $mimeType, $targetName=null, $symlink=false) {
	/* Create our data item */
	$ret = parent::create($parentId, $inputFileName, $mimeType, $targetName, $symlink);
	if ($ret->isError()) {
	    return $ret->wrap(__FILE__, __LINE__);
	}

	/* We're linkable */
	$this->setIsLinkable(true);

	return GalleryStatus::success();
    }

    /**
     * @see GalleryEntity::itemTypeName
     * @staticvar mimeMap array(mimeTypePattern=>array(CapName,name))
     */
    function itemTypeName($localized = true) {
	global $gallery;
	static $mimeMap;

	if (!isset($mimeMap)) {
	    $mimeMap = array(
		':^audio/:'
		    => array($gallery->i18n('Audio'), $gallery->i18n('audio')),
		':^application/(zip|mac-[cb].*|x-((us|g)?tar|gzip|compress|cpio|stuffit|shar))$:'
		    => array($gallery->i18n('Archive'), $gallery->i18n('archive')),
		':^(text/|application/(pdf|postscript|photoshop|msword)$):'
		    => array($gallery->i18n('Document'), $gallery->i18n('document')),
		':application/vnd.ms-excel:'
		    => array($gallery->i18n('Spreadsheet'), $gallery->i18n('spreadsheet')),
	    );
	}

	$core = null;
	if ($localized) {
	    list ($ret, $core) = GalleryCoreApi::loadPlugin('module', 'core');
	    if ($ret->isError()) {
		$core = null;
	    }
	}
	foreach ($mimeMap as $pattern => $result) {
	    if (preg_match($pattern, $this->_mimeType)) {
		return isset($core) ?
		    array($core->translate($result[0]), $core->translate($result[1])) : $result;
	    }
	}
	return isset($core) ? array($core->translate('Unknown'), $core->translate('unknown'))
			    : array('Unknown', 'unknown');
    }
}

include(dirname(__FILE__) . '/interfaces/GalleryUnknownItem.inc');
?>
