This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
  1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 
<?php

defined('C5_EXECUTE') or die("Access Denied.");

/**
 * @package Core
 * @subpackage Files
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2009 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */

/**
 * @package Core
 * @subpackage Files
 * @author Andrew Embler <[email protected]>
 * @category Concrete
 * @copyright  Copyright (c) 2003-2009 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 *
 */
class Concrete5_Library_FileTypeList {
    
    public function getInstance() {
        static $instance;
        if (!isset($instance)) {
            $v = __CLASS__;
            $instance = new $v;
        }
        return $instance;
    }
    
    protected $types = array();
    protected $importerAttributes = array();
    
    public function define($extension, $name, $type, $customImporter = false, $inlineFileViewer = false, $editor = false, $pkgHandle = false) {
        $ext = explode(',', $extension);
        foreach($ext as $e) {
            $ft = new FileType();
            $ft->name = $name;
            $ft->extension = $e;
            $ft->customImporter = $customImporter;
            $ft->editor = $editor;
            $ft->type = strtolower($type);
            $ft->view = $inlineFileViewer;
            $ft->pkgHandle = $pkgHandle;
            $this->types[$e] = $ft;
        }
    }
    
    public function defineImporterAttribute($akHandle, $akName, $akType, $akIsEditable) {
        $obj = new stdClass;
        $obj->akHandle = $akHandle;
        $obj->akName = $akName;
        $obj->akType = $akType;
        $obj->akIsEditable = $akIsEditable;     
        $this->importerAttributes[$akHandle] = $obj;
    }
    
    public function getImporterAttribute($akHandle) {
        $ftl = FileTypeList::getInstance();
        return $ftl->importerAttributes[$akHandle];
    }
        
    /** 
     * Can take an extension or a filename
     * Returns any registered information we have for the particular file type, based on its registration
     */
    public static function getType($ext) {
        $ftl = FileTypeList::getInstance(); 
        if (strpos($ext, '.') !== false) {
            // filename
            $h = Loader::helper('file');
            $ext = $h->getExtension($ext);
        }
        $ext = strtolower($ext);
        if (is_object($ftl->types[$ext])) {
            return $ftl->types[$ext];
        } else {
            $ft = new FileType(); // generic
            return $ft;
        }
    }
    
        
}

class Concrete5_Library_FileType {

    // File Type Constants
    const T_IMAGE = 1;
    const T_VIDEO = 2;
    const T_TEXT = 3;
    const T_AUDIO = 4;
    const T_DOCUMENT = 5;
    const T_APPLICATION = 6;
    const T_UNKNOWN = 99;
    
    public $pkgHandle = false;
    
    public function __construct() {
        $this->type = FileType::T_UNKNOWN;
        $this->name = $this->mapGenericTypeText($this->type);
    }
    
    public function getPackageHandle() {return $this->pkgHandle;}
    public function getName() {return $this->name;}
    public function getExtension() {return $this->extension;}
    public function getCustomImporter() {return $this->customImporter;}
    public function getGenericType() {return $this->type;}
    public function getView() {return $this->view;} 
    public function getEditor() { return $this->editor;}
    
    protected function mapGenericTypeText($type) {
        switch($type) {
            case FileType::T_IMAGE:
                return t('Image');
                break;
            case FileType::T_VIDEO:
                return t('Video');
                break;
            case FileType::T_TEXT:
                return t('Text');
                break;
            case FileType::T_AUDIO:
                return t('Audio');
                break;
            case FileType::T_DOCUMENT:
                return t('Document');
                break;
            case FileType::T_APPLICATION:
                return t('Application');
                break;
            case FileType::T_UNKNOWN:
                return t('File');
                break;

        }
    }
    
    public function getGenericTypeText($type) {
        if ($type > 0) {
            return FileType::mapGenericTypeText($type);
        } else if (!empty($this->type)) {
            return FileType::mapGenericTypeText($this->type);       
        }
    }
    
    public function getCustomInspector() {
        $script = 'file/types/' . $this->getCustomImporter();
        if ($this->pkgHandle != false) {
            Loader::library($script, $this->pkgHandle);
        } else {
            Loader::library($script);
        }
        $class = Object::camelcase($this->getCustomImporter()) . 'FileTypeInspector';
        $cl = new $class;
        return $cl;
    }
    
    /** 
     * Returns a thumbnail for this type of file
     */
    public function getThumbnail($level, $fullImageTag = true) {
        $width = constant("AL_THUMBNAIL_WIDTH_LEVEL{$level}");
        $height = constant("AL_THUMBNAIL_HEIGHT_LEVEL{$level}");
        if (file_exists(DIR_AL_ICONS . '/' . $this->extension . '.png')) {
            $url = REL_DIR_AL_ICONS . '/' . $this->extension . '.png';
        } else {
            $url = AL_ICON_DEFAULT;
        }
        if ($fullImageTag == true) {
            return '<img src="' . $url . '" class="ccm-generic-thumbnail" width="' . $width . '" height="' . $height . '" />';
        } else {
            return $url;
        }
    }
    
        

}