PageRenderTime 47ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/phpexcel/PHPExcel/Settings.php

https://bitbucket.org/kudutest1/moodlegit
PHP | 332 lines | 101 code | 55 blank | 176 comment | 10 complexity | 7c522222f7a2be5daf0174168b3acf81 MD5 | raw file
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2012 PHPExcel
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. *
  21. * @category PHPExcel
  22. * @package PHPExcel_Settings
  23. * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version ##VERSION##, ##DATE##
  26. */
  27. /** PHPExcel root directory */
  28. if (!defined('PHPEXCEL_ROOT')) {
  29. /**
  30. * @ignore
  31. */
  32. define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
  33. require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  34. }
  35. class PHPExcel_Settings
  36. {
  37. /** constants */
  38. /** Available Zip library classes */
  39. const PCLZIP = 'PHPExcel_Shared_ZipArchive';
  40. const ZIPARCHIVE = 'ZipArchive';
  41. /** Optional Chart Rendering libraries */
  42. const CHART_RENDERER_JPGRAPH = 'jpgraph';
  43. /** Optional PDF Rendering libraries */
  44. const PDF_RENDERER_TCPDF = 'tcPDF';
  45. const PDF_RENDERER_DOMPDF = 'DomPDF';
  46. const PDF_RENDERER_MPDF = 'mPDF';
  47. private static $_chartRenderers = array(
  48. self::CHART_RENDERER_JPGRAPH,
  49. );
  50. private static $_pdfRenderers = array(
  51. self::PDF_RENDERER_TCPDF,
  52. self::PDF_RENDERER_DOMPDF,
  53. self::PDF_RENDERER_MPDF,
  54. );
  55. /**
  56. * Name of the class used for Zip file management
  57. * e.g.
  58. * ZipArchive
  59. *
  60. * @var string
  61. */
  62. private static $_zipClass = self::ZIPARCHIVE;
  63. /**
  64. * Name of the external Library used for rendering charts
  65. * e.g.
  66. * jpgraph
  67. *
  68. * @var string
  69. */
  70. private static $_chartRendererName = NULL;
  71. /**
  72. * Directory Path to the external Library used for rendering charts
  73. *
  74. * @var string
  75. */
  76. private static $_chartRendererPath = NULL;
  77. /**
  78. * Name of the external Library used for rendering PDF files
  79. * e.g.
  80. * mPDF
  81. *
  82. * @var string
  83. */
  84. private static $_pdfRendererName = NULL;
  85. /**
  86. * Directory Path to the external Library used for rendering PDF files
  87. *
  88. * @var string
  89. */
  90. private static $_pdfRendererPath = NULL;
  91. /**
  92. * Set the Zip handler Class that PHPExcel should use for Zip file management (PCLZip or ZipArchive)
  93. *
  94. * @param string $zipClass The Zip handler class that PHPExcel should use for Zip file management
  95. * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
  96. * @return boolean Success or failure
  97. */
  98. public static function setZipClass($zipClass) {
  99. if (($zipClass === self::PCLZIP) ||
  100. ($zipClass === self::ZIPARCHIVE)) {
  101. self::$_zipClass = $zipClass;
  102. return TRUE;
  103. }
  104. return FALSE;
  105. } // function setZipClass()
  106. /**
  107. * Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive)
  108. * for Zip file management
  109. *
  110. * @return string Name of the Zip handler Class that PHPExcel is configured to use
  111. * for Zip file management
  112. * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
  113. */
  114. public static function getZipClass() {
  115. return self::$_zipClass;
  116. } // function getZipClass()
  117. /**
  118. * Return the name of the method that is currently configured for cell cacheing
  119. *
  120. * @return string Name of the cacheing method
  121. */
  122. public static function getCacheStorageMethod() {
  123. return PHPExcel_CachedObjectStorageFactory::getCacheStorageMethod();
  124. } // function getCacheStorageMethod()
  125. /**
  126. * Return the name of the class that is currently being used for cell cacheing
  127. *
  128. * @return string Name of the class currently being used for cacheing
  129. */
  130. public static function getCacheStorageClass() {
  131. return PHPExcel_CachedObjectStorageFactory::getCacheStorageClass();
  132. } // function getCacheStorageClass()
  133. /**
  134. * Set the method that should be used for cell cacheing
  135. *
  136. * @param string $method Name of the cacheing method
  137. * @param array $arguments Optional configuration arguments for the cacheing method
  138. * @return boolean Success or failure
  139. */
  140. public static function setCacheStorageMethod($method = PHPExcel_CachedObjectStorageFactory::cache_in_memory,
  141. $arguments = array()) {
  142. return PHPExcel_CachedObjectStorageFactory::initialize($method, $arguments);
  143. } // function setCacheStorageMethod()
  144. /**
  145. * Set the locale code to use for formula translations and any special formatting
  146. *
  147. * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk")
  148. * @return boolean Success or failure
  149. */
  150. public static function setLocale($locale='en_us') {
  151. return PHPExcel_Calculation::getInstance()->setLocale($locale);
  152. } // function setLocale()
  153. /**
  154. * Set details of the external library that PHPExcel should use for rendering charts
  155. *
  156. * @param string $libraryName Internal reference name of the library
  157. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  158. * @param string $libraryBaseDir Directory path to the library's base folder
  159. * @return boolean Success or failure
  160. */
  161. public static function setChartRenderer($libraryName, $libraryBaseDir) {
  162. if (!self::setChartRendererName($libraryName))
  163. return FALSE;
  164. return self::setChartRendererPath($libraryBaseDir);
  165. } // function setChartRenderer()
  166. /**
  167. * Identify to PHPExcel the external library to use for rendering charts
  168. *
  169. * @param string $libraryName Internal reference name of the library
  170. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  171. * @return boolean Success or failure
  172. */
  173. public static function setChartRendererName($libraryName) {
  174. if (!in_array($libraryName,self::$_chartRenderers)) {
  175. return FALSE;
  176. }
  177. self::$_chartRendererName = $libraryName;
  178. return TRUE;
  179. } // function setChartRendererName()
  180. /**
  181. * Tell PHPExcel where to find the external library to use for rendering charts
  182. *
  183. * @param string $libraryBaseDir Directory path to the library's base folder
  184. * @return boolean Success or failure
  185. */
  186. public static function setChartRendererPath($libraryBaseDir) {
  187. if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
  188. return FALSE;
  189. }
  190. self::$_chartRendererPath = $libraryBaseDir;
  191. return TRUE;
  192. } // function setChartRendererPath()
  193. /**
  194. * Return the Chart Rendering Library that PHPExcel is currently configured to use (e.g. jpgraph)
  195. *
  196. * @return string|NULL Internal reference name of the Chart Rendering Library that PHPExcel is
  197. * currently configured to use
  198. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  199. */
  200. public static function getChartRendererName() {
  201. return self::$_chartRendererName;
  202. } // function getChartRendererName()
  203. /**
  204. * Return the directory path to the Chart Rendering Library that PHPExcel is currently configured to use
  205. *
  206. * @return string|NULL Directory Path to the Chart Rendering Library that PHPExcel is
  207. * currently configured to use
  208. */
  209. public static function getChartRendererPath() {
  210. return self::$_chartRendererPath;
  211. } // function getChartRendererPath()
  212. /**
  213. * Set details of the external library that PHPExcel should use for rendering PDF files
  214. *
  215. * @param string $libraryName Internal reference name of the library
  216. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  217. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  218. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  219. * @param string $libraryBaseDir Directory path to the library's base folder
  220. * @return boolean Success or failure
  221. */
  222. public static function setPdfRenderer($libraryName, $libraryBaseDir) {
  223. if (!self::setPdfRendererName($libraryName))
  224. return FALSE;
  225. return self::setPdfRendererPath($libraryBaseDir);
  226. } // function setPdfRenderer()
  227. /**
  228. * Identify to PHPExcel the external library to use for rendering PDF files
  229. *
  230. * @param string $libraryName Internal reference name of the library
  231. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  232. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  233. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  234. * @return boolean Success or failure
  235. */
  236. public static function setPdfRendererName($libraryName) {
  237. if (!in_array($libraryName,self::$_pdfRenderers)) {
  238. return FALSE;
  239. }
  240. self::$_pdfRendererName = $libraryName;
  241. return TRUE;
  242. } // function setPdfRendererName()
  243. /**
  244. * Tell PHPExcel where to find the external library to use for rendering PDF files
  245. *
  246. * @param string $libraryBaseDir Directory path to the library's base folder
  247. * @return boolean Success or failure
  248. */
  249. public static function setPdfRendererPath($libraryBaseDir) {
  250. if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
  251. return FALSE;
  252. }
  253. self::$_pdfRendererPath = $libraryBaseDir;
  254. return TRUE;
  255. } // function setPdfRendererPath()
  256. /**
  257. * Return the PDF Rendering Library that PHPExcel is currently configured to use (e.g. dompdf)
  258. *
  259. * @return string|NULL Internal reference name of the PDF Rendering Library that PHPExcel is
  260. * currently configured to use
  261. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  262. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  263. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  264. */
  265. public static function getPdfRendererName() {
  266. return self::$_pdfRendererName;
  267. } // function getPdfRendererName()
  268. /**
  269. * Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use
  270. *
  271. * @return string|NULL Directory Path to the PDF Rendering Library that PHPExcel is
  272. * currently configured to use
  273. */
  274. public static function getPdfRendererPath() {
  275. return self::$_pdfRendererPath;
  276. } // function getPdfRendererPath()
  277. }