<?php
class favicon
{
    const DIRECTORY = 'web/skin/favicon/';
    
    ////////////////////////////////////////////////////////////////////////////
    // Construct and destruct functions.
    
    ////////////////////////////////////////////////////////////////////////////
    // Overload functions.

    ////////////////////////////////////////////////////////////////////////////
    // Interface functions.
    
    public static function get_list()
    {
        $list = glob(self::DIRECTORY . '*.ico');
        
        foreach ($list as &$l)
        {
            $l = pathinfo($l, PATHINFO_FILENAME);
        }
        
        return $list;
    }
    
    public static function save($name, array $file)
    {
        if (!preg_match('~(ico)$~i', $file['name']))
        {
            throw new exception();
        }
        
        $temp = self::DIRECTORY . '_' . pathinfo($file['name'], PATHINFO_BASENAME);
        $target = self::DIRECTORY . $name . '.ico';
        folder::move($file['tmp_name'], $target);
        folder::mode($target, 0775);
    }
    
    public static function delete($name)
    {
        if (is_file($file = self::DIRECTORY . $name . '.ico'))
        {
            folder::delete($file);
        }
    }
    
    ////////////////////////////////////////////////////////////////////////////
    // Internal functions.
}
