Settings.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2013 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 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
  24. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  25. * @version 1.7.9, 2013-06-02
  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. {
  100. if (($zipClass === self::PCLZIP) ||
  101. ($zipClass === self::ZIPARCHIVE)) {
  102. self::$_zipClass = $zipClass;
  103. return TRUE;
  104. }
  105. return FALSE;
  106. } // function setZipClass()
  107. /**
  108. * Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive)
  109. * or Zip file management
  110. *
  111. * @return string Name of the Zip handler Class that PHPExcel is configured to use
  112. * for Zip file management
  113. * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
  114. */
  115. public static function getZipClass()
  116. {
  117. return self::$_zipClass;
  118. } // function getZipClass()
  119. /**
  120. * Return the name of the method that is currently configured for cell cacheing
  121. *
  122. * @return string Name of the cacheing method
  123. */
  124. public static function getCacheStorageMethod()
  125. {
  126. return PHPExcel_CachedObjectStorageFactory::getCacheStorageMethod();
  127. } // function getCacheStorageMethod()
  128. /**
  129. * Return the name of the class that is currently being used for cell cacheing
  130. *
  131. * @return string Name of the class currently being used for cacheing
  132. */
  133. public static function getCacheStorageClass()
  134. {
  135. return PHPExcel_CachedObjectStorageFactory::getCacheStorageClass();
  136. } // function getCacheStorageClass()
  137. /**
  138. * Set the method that should be used for cell cacheing
  139. *
  140. * @param string $method Name of the cacheing method
  141. * @param array $arguments Optional configuration arguments for the cacheing method
  142. * @return boolean Success or failure
  143. */
  144. public static function setCacheStorageMethod(
  145. $method = PHPExcel_CachedObjectStorageFactory::cache_in_memory,
  146. $arguments = array()
  147. )
  148. {
  149. return PHPExcel_CachedObjectStorageFactory::initialize($method, $arguments);
  150. } // function setCacheStorageMethod()
  151. /**
  152. * Set the locale code to use for formula translations and any special formatting
  153. *
  154. * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk")
  155. * @return boolean Success or failure
  156. */
  157. public static function setLocale($locale='en_us')
  158. {
  159. return PHPExcel_Calculation::getInstance()->setLocale($locale);
  160. } // function setLocale()
  161. /**
  162. * Set details of the external library that PHPExcel should use for rendering charts
  163. *
  164. * @param string $libraryName Internal reference name of the library
  165. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  166. * @param string $libraryBaseDir Directory path to the library's base folder
  167. *
  168. * @return boolean Success or failure
  169. */
  170. public static function setChartRenderer($libraryName, $libraryBaseDir)
  171. {
  172. if (!self::setChartRendererName($libraryName))
  173. return FALSE;
  174. return self::setChartRendererPath($libraryBaseDir);
  175. } // function setChartRenderer()
  176. /**
  177. * Identify to PHPExcel the external library to use for rendering charts
  178. *
  179. * @param string $libraryName Internal reference name of the library
  180. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  181. *
  182. * @return boolean Success or failure
  183. */
  184. public static function setChartRendererName($libraryName)
  185. {
  186. if (!in_array($libraryName,self::$_chartRenderers)) {
  187. return FALSE;
  188. }
  189. self::$_chartRendererName = $libraryName;
  190. return TRUE;
  191. } // function setChartRendererName()
  192. /**
  193. * Tell PHPExcel where to find the external library to use for rendering charts
  194. *
  195. * @param string $libraryBaseDir Directory path to the library's base folder
  196. * @return boolean Success or failure
  197. */
  198. public static function setChartRendererPath($libraryBaseDir)
  199. {
  200. if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
  201. return FALSE;
  202. }
  203. self::$_chartRendererPath = $libraryBaseDir;
  204. return TRUE;
  205. } // function setChartRendererPath()
  206. /**
  207. * Return the Chart Rendering Library that PHPExcel is currently configured to use (e.g. jpgraph)
  208. *
  209. * @return string|NULL Internal reference name of the Chart Rendering Library that PHPExcel is
  210. * currently configured to use
  211. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  212. */
  213. public static function getChartRendererName()
  214. {
  215. return self::$_chartRendererName;
  216. } // function getChartRendererName()
  217. /**
  218. * Return the directory path to the Chart Rendering Library that PHPExcel is currently configured to use
  219. *
  220. * @return string|NULL Directory Path to the Chart Rendering Library that PHPExcel is
  221. * currently configured to use
  222. */
  223. public static function getChartRendererPath()
  224. {
  225. return self::$_chartRendererPath;
  226. } // function getChartRendererPath()
  227. /**
  228. * Set details of the external library that PHPExcel should 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. * @param string $libraryBaseDir Directory path to the library's base folder
  235. *
  236. * @return boolean Success or failure
  237. */
  238. public static function setPdfRenderer($libraryName, $libraryBaseDir)
  239. {
  240. if (!self::setPdfRendererName($libraryName))
  241. return FALSE;
  242. return self::setPdfRendererPath($libraryBaseDir);
  243. } // function setPdfRenderer()
  244. /**
  245. * Identify to PHPExcel the external library to use for rendering PDF files
  246. *
  247. * @param string $libraryName Internal reference name of the library
  248. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  249. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  250. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  251. *
  252. * @return boolean Success or failure
  253. */
  254. public static function setPdfRendererName($libraryName)
  255. {
  256. if (!in_array($libraryName,self::$_pdfRenderers)) {
  257. return FALSE;
  258. }
  259. self::$_pdfRendererName = $libraryName;
  260. return TRUE;
  261. } // function setPdfRendererName()
  262. /**
  263. * Tell PHPExcel where to find the external library to use for rendering PDF files
  264. *
  265. * @param string $libraryBaseDir Directory path to the library's base folder
  266. * @return boolean Success or failure
  267. */
  268. public static function setPdfRendererPath($libraryBaseDir)
  269. {
  270. if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
  271. return FALSE;
  272. }
  273. self::$_pdfRendererPath = $libraryBaseDir;
  274. return TRUE;
  275. } // function setPdfRendererPath()
  276. /**
  277. * Return the PDF Rendering Library that PHPExcel is currently configured to use (e.g. dompdf)
  278. *
  279. * @return string|NULL Internal reference name of the PDF Rendering Library that PHPExcel is
  280. * currently configured to use
  281. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  282. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  283. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  284. */
  285. public static function getPdfRendererName()
  286. {
  287. return self::$_pdfRendererName;
  288. } // function getPdfRendererName()
  289. /**
  290. * Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use
  291. *
  292. * @return string|NULL Directory Path to the PDF Rendering Library that PHPExcel is
  293. * currently configured to use
  294. */
  295. public static function getPdfRendererPath()
  296. {
  297. return self::$_pdfRendererPath;
  298. } // function getPdfRendererPath()
  299. }