Newer
Older
Import / web / www.xiaofrog.com / gallery / modules / icons / classes / IconsImpl.class
<?php
/*
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2007 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.
 */

GalleryCoreApi::requireOnce('modules/icons/classes/IconsInterface_1_0.class');

/**
 * Implementation of the IconsInterface for including iconpack css
 * @package Icons
 * @subpackage Classes
 * @author Jesse Mullan <jmullan@visi.com>
 * @version $Revision: 15513 $
 */
class IconsImpl extends IconsInterface_1_0 {
    /**
     * @see IconsInterface_1_0::getIconPacks
     */
    function getIconPacks() {
	global $gallery;
	$platform =& $gallery->getPlatform();

	/*
	 * Load the plugin even if it's deactivated since we only need it for translation, and
	 * it's possible that this is getting called during the core upgrade, when we won't be
	 * able to properly deal with deactivated plugins.
	 */
	list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'icons', true);
	if ($ret) {
	    return array($ret, null);
	}

	$icons = array('' => $module->translate('None'));
	$dir = dirname(__FILE__) . '/../iconpacks';
	if ($platform->is_dir($dir) && $platform->is_readable($dir)
		&& $fd = $platform->opendir($dir)) {
	    while ($file = $platform->readdir($fd)) {
		$subdir = "$dir/$file";
		$iconinc = "$subdir/iconpack.inc";
		if ($platform->is_dir($subdir) && $platform->file_exists($iconinc)) {
		    require($iconinc);
		    $icons[$file] = $module->translate($iconData['name']);
		}
	    }
	}

	return array(null, $icons);
    }

    /**
     * @see IconsInterface_1_0::init
     */
    function init(&$template) {
	list ($ret, $iconpack) = GalleryCoreApi::getPluginParameter('module', 'icons', 'iconpack');
	if ($ret) {
	    return $ret;
	}
	if (!empty($iconpack)) {
	    global $gallery;
	    $translator =& $gallery->getTranslator();
	    $rtl = $translator->isRightToLeft() ? '-rtl' : '';
	    $template->style("modules/icons/iconpacks/$iconpack/icons$rtl.css");
	}

	return null;
    }
}
?>