PageRenderTime 42ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/concrete/core/libraries/file/types.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 182 lines | 132 code | 24 blank | 26 comment | 15 complexity | a96810a248c6046eca09aba78a2feef0 MD5 | raw file
  1. <?php
  2. defined('C5_EXECUTE') or die("Access Denied.");
  3. /**
  4. * @package Core
  5. * @subpackage Files
  6. * @author Andrew Embler <andrew@concrete5.org>
  7. * @copyright Copyright (c) 2003-2009 Concrete5. (http://www.concrete5.org)
  8. * @license http://www.concrete5.org/license/ MIT License
  9. *
  10. */
  11. /**
  12. * @package Core
  13. * @subpackage Files
  14. * @author Andrew Embler <andrew@concrete5.org>
  15. * @category Concrete
  16. * @copyright Copyright (c) 2003-2009 Concrete5. (http://www.concrete5.org)
  17. * @license http://www.concrete5.org/license/ MIT License
  18. *
  19. */
  20. class Concrete5_Library_FileTypeList {
  21. public function getInstance() {
  22. static $instance;
  23. if (!isset($instance)) {
  24. $v = __CLASS__;
  25. $instance = new $v;
  26. }
  27. return $instance;
  28. }
  29. protected $types = array();
  30. protected $importerAttributes = array();
  31. public function define($extension, $name, $type, $customImporter = false, $inlineFileViewer = false, $editor = false, $pkgHandle = false) {
  32. $ext = explode(',', $extension);
  33. foreach($ext as $e) {
  34. $ft = new FileType();
  35. $ft->name = $name;
  36. $ft->extension = $e;
  37. $ft->customImporter = $customImporter;
  38. $ft->editor = $editor;
  39. $ft->type = strtolower($type);
  40. $ft->view = $inlineFileViewer;
  41. $ft->pkgHandle = $pkgHandle;
  42. $this->types[$e] = $ft;
  43. }
  44. }
  45. public function defineImporterAttribute($akHandle, $akName, $akType, $akIsEditable) {
  46. $obj = new stdClass;
  47. $obj->akHandle = $akHandle;
  48. $obj->akName = $akName;
  49. $obj->akType = $akType;
  50. $obj->akIsEditable = $akIsEditable;
  51. $this->importerAttributes[$akHandle] = $obj;
  52. }
  53. public function getImporterAttribute($akHandle) {
  54. $ftl = FileTypeList::getInstance();
  55. return $ftl->importerAttributes[$akHandle];
  56. }
  57. /**
  58. * Can take an extension or a filename
  59. * Returns any registered information we have for the particular file type, based on its registration
  60. */
  61. public static function getType($ext) {
  62. $ftl = FileTypeList::getInstance();
  63. if (strpos($ext, '.') !== false) {
  64. // filename
  65. $h = Loader::helper('file');
  66. $ext = $h->getExtension($ext);
  67. }
  68. $ext = strtolower($ext);
  69. if (is_object($ftl->types[$ext])) {
  70. return $ftl->types[$ext];
  71. } else {
  72. $ft = new FileType(); // generic
  73. return $ft;
  74. }
  75. }
  76. }
  77. class Concrete5_Library_FileType {
  78. // File Type Constants
  79. const T_IMAGE = 1;
  80. const T_VIDEO = 2;
  81. const T_TEXT = 3;
  82. const T_AUDIO = 4;
  83. const T_DOCUMENT = 5;
  84. const T_APPLICATION = 6;
  85. const T_UNKNOWN = 99;
  86. public $pkgHandle = false;
  87. public function __construct() {
  88. $this->type = FileType::T_UNKNOWN;
  89. $this->name = $this->mapGenericTypeText($this->type);
  90. }
  91. public function getPackageHandle() {return $this->pkgHandle;}
  92. public function getName() {return $this->name;}
  93. public function getExtension() {return $this->extension;}
  94. public function getCustomImporter() {return $this->customImporter;}
  95. public function getGenericType() {return $this->type;}
  96. public function getView() {return $this->view;}
  97. public function getEditor() { return $this->editor;}
  98. protected function mapGenericTypeText($type) {
  99. switch($type) {
  100. case FileType::T_IMAGE:
  101. return t('Image');
  102. break;
  103. case FileType::T_VIDEO:
  104. return t('Video');
  105. break;
  106. case FileType::T_TEXT:
  107. return t('Text');
  108. break;
  109. case FileType::T_AUDIO:
  110. return t('Audio');
  111. break;
  112. case FileType::T_DOCUMENT:
  113. return t('Document');
  114. break;
  115. case FileType::T_APPLICATION:
  116. return t('Application');
  117. break;
  118. case FileType::T_UNKNOWN:
  119. return t('File');
  120. break;
  121. }
  122. }
  123. public function getGenericTypeText($type) {
  124. if ($type > 0) {
  125. return FileType::mapGenericTypeText($type);
  126. } else if (!empty($this->type)) {
  127. return FileType::mapGenericTypeText($this->type);
  128. }
  129. }
  130. public function getCustomInspector() {
  131. $script = 'file/types/' . $this->getCustomImporter();
  132. if ($this->pkgHandle != false) {
  133. Loader::library($script, $this->pkgHandle);
  134. } else {
  135. Loader::library($script);
  136. }
  137. $class = Object::camelcase($this->getCustomImporter()) . 'FileTypeInspector';
  138. $cl = new $class;
  139. return $cl;
  140. }
  141. /**
  142. * Returns a thumbnail for this type of file
  143. */
  144. public function getThumbnail($level, $fullImageTag = true) {
  145. $width = constant("AL_THUMBNAIL_WIDTH_LEVEL{$level}");
  146. $height = constant("AL_THUMBNAIL_HEIGHT_LEVEL{$level}");
  147. if (file_exists(DIR_AL_ICONS . '/' . $this->extension . '.png')) {
  148. $url = REL_DIR_AL_ICONS . '/' . $this->extension . '.png';
  149. } else {
  150. $url = AL_ICON_DEFAULT;
  151. }
  152. if ($fullImageTag == true) {
  153. return '<img src="' . $url . '" class="ccm-generic-thumbnail" width="' . $width . '" height="' . $height . '" />';
  154. } else {
  155. return $url;
  156. }
  157. }
  158. }