Settings.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <?php
  2. /** PHPExcel root directory */
  3. if (!defined('PHPEXCEL_ROOT')) {
  4. /**
  5. * @ignore
  6. */
  7. define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
  8. require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
  9. }
  10. /**
  11. * PHPExcel_Settings
  12. *
  13. * Copyright (c) 2006 - 2015 PHPExcel
  14. *
  15. * This library is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU Lesser General Public
  17. * License as published by the Free Software Foundation; either
  18. * version 2.1 of the License, or (at your option) any later version.
  19. *
  20. * This library is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. * Lesser General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Lesser General Public
  26. * License along with this library; if not, write to the Free Software
  27. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. *
  29. * @category PHPExcel
  30. * @package PHPExcel_Settings
  31. * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
  32. * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
  33. * @version ##VERSION##, ##DATE##
  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;
  71. /**
  72. * Directory Path to the external Library used for rendering charts
  73. *
  74. * @var string
  75. */
  76. private static $chartRendererPath;
  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;
  85. /**
  86. * Directory Path to the external Library used for rendering PDF files
  87. *
  88. * @var string
  89. */
  90. private static $pdfRendererPath;
  91. /**
  92. * Default options for libxml loader
  93. *
  94. * @var int
  95. */
  96. private static $libXmlLoaderOptions = null;
  97. /**
  98. * Set the Zip handler Class that PHPExcel should use for Zip file management (PCLZip or ZipArchive)
  99. *
  100. * @param string $zipClass The Zip handler class that PHPExcel should use for Zip file management
  101. * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
  102. * @return boolean Success or failure
  103. */
  104. public static function setZipClass($zipClass)
  105. {
  106. if (($zipClass === self::PCLZIP) ||
  107. ($zipClass === self::ZIPARCHIVE)) {
  108. self::$zipClass = $zipClass;
  109. return true;
  110. }
  111. return false;
  112. }
  113. /**
  114. * Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive)
  115. * or Zip file management
  116. *
  117. * @return string Name of the Zip handler Class that PHPExcel is configured to use
  118. * for Zip file management
  119. * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
  120. */
  121. public static function getZipClass()
  122. {
  123. return self::$zipClass;
  124. }
  125. /**
  126. * Return the name of the method that is currently configured for cell cacheing
  127. *
  128. * @return string Name of the cacheing method
  129. */
  130. public static function getCacheStorageMethod()
  131. {
  132. return PHPExcel_CachedObjectStorageFactory::getCacheStorageMethod();
  133. }
  134. /**
  135. * Return the name of the class that is currently being used for cell cacheing
  136. *
  137. * @return string Name of the class currently being used for cacheing
  138. */
  139. public static function getCacheStorageClass()
  140. {
  141. return PHPExcel_CachedObjectStorageFactory::getCacheStorageClass();
  142. }
  143. /**
  144. * Set the method that should be used for cell cacheing
  145. *
  146. * @param string $method Name of the cacheing method
  147. * @param array $arguments Optional configuration arguments for the cacheing method
  148. * @return boolean Success or failure
  149. */
  150. public static function setCacheStorageMethod($method = PHPExcel_CachedObjectStorageFactory::cache_in_memory, $arguments = array())
  151. {
  152. return PHPExcel_CachedObjectStorageFactory::initialize($method, $arguments);
  153. }
  154. /**
  155. * Set the locale code to use for formula translations and any special formatting
  156. *
  157. * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk")
  158. * @return boolean Success or failure
  159. */
  160. public static function setLocale($locale = 'en_us')
  161. {
  162. return PHPExcel_Calculation::getInstance()->setLocale($locale);
  163. }
  164. /**
  165. * Set details of the external library that PHPExcel should use for rendering charts
  166. *
  167. * @param string $libraryName Internal reference name of the library
  168. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  169. * @param string $libraryBaseDir Directory path to the library's base folder
  170. *
  171. * @return boolean Success or failure
  172. */
  173. public static function setChartRenderer($libraryName, $libraryBaseDir)
  174. {
  175. if (!self::setChartRendererName($libraryName)) {
  176. return false;
  177. }
  178. return self::setChartRendererPath($libraryBaseDir);
  179. }
  180. /**
  181. * Identify to PHPExcel the external library to use for rendering charts
  182. *
  183. * @param string $libraryName Internal reference name of the library
  184. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  185. *
  186. * @return boolean Success or failure
  187. */
  188. public static function setChartRendererName($libraryName)
  189. {
  190. if (!in_array($libraryName, self::$chartRenderers)) {
  191. return false;
  192. }
  193. self::$chartRendererName = $libraryName;
  194. return true;
  195. }
  196. /**
  197. * Tell PHPExcel where to find the external library to use for rendering charts
  198. *
  199. * @param string $libraryBaseDir Directory path to the library's base folder
  200. * @return boolean Success or failure
  201. */
  202. public static function setChartRendererPath($libraryBaseDir)
  203. {
  204. if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
  205. return false;
  206. }
  207. self::$chartRendererPath = $libraryBaseDir;
  208. return true;
  209. }
  210. /**
  211. * Return the Chart Rendering Library that PHPExcel is currently configured to use (e.g. jpgraph)
  212. *
  213. * @return string|NULL Internal reference name of the Chart Rendering Library that PHPExcel is
  214. * currently configured to use
  215. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  216. */
  217. public static function getChartRendererName()
  218. {
  219. return self::$chartRendererName;
  220. }
  221. /**
  222. * Return the directory path to the Chart Rendering Library that PHPExcel is currently configured to use
  223. *
  224. * @return string|NULL Directory Path to the Chart Rendering Library that PHPExcel is
  225. * currently configured to use
  226. */
  227. public static function getChartRendererPath()
  228. {
  229. return self::$chartRendererPath;
  230. }
  231. /**
  232. * Set details of the external library that PHPExcel should use for rendering PDF files
  233. *
  234. * @param string $libraryName Internal reference name of the library
  235. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  236. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  237. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  238. * @param string $libraryBaseDir Directory path to the library's base folder
  239. *
  240. * @return boolean Success or failure
  241. */
  242. public static function setPdfRenderer($libraryName, $libraryBaseDir)
  243. {
  244. if (!self::setPdfRendererName($libraryName)) {
  245. return false;
  246. }
  247. return self::setPdfRendererPath($libraryBaseDir);
  248. }
  249. /**
  250. * Identify to PHPExcel the external library to use for rendering PDF files
  251. *
  252. * @param string $libraryName Internal reference name of the library
  253. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  254. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  255. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  256. *
  257. * @return boolean Success or failure
  258. */
  259. public static function setPdfRendererName($libraryName)
  260. {
  261. if (!in_array($libraryName, self::$pdfRenderers)) {
  262. return false;
  263. }
  264. self::$pdfRendererName = $libraryName;
  265. return true;
  266. }
  267. /**
  268. * Tell PHPExcel where to find the external library to use for rendering PDF files
  269. *
  270. * @param string $libraryBaseDir Directory path to the library's base folder
  271. * @return boolean Success or failure
  272. */
  273. public static function setPdfRendererPath($libraryBaseDir)
  274. {
  275. if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
  276. return false;
  277. }
  278. self::$pdfRendererPath = $libraryBaseDir;
  279. return true;
  280. }
  281. /**
  282. * Return the PDF Rendering Library that PHPExcel is currently configured to use (e.g. dompdf)
  283. *
  284. * @return string|NULL Internal reference name of the PDF Rendering Library that PHPExcel is
  285. * currently configured to use
  286. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  287. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  288. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  289. */
  290. public static function getPdfRendererName()
  291. {
  292. return self::$pdfRendererName;
  293. }
  294. /**
  295. * Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use
  296. *
  297. * @return string|NULL Directory Path to the PDF Rendering Library that PHPExcel is
  298. * currently configured to use
  299. */
  300. public static function getPdfRendererPath()
  301. {
  302. return self::$pdfRendererPath;
  303. }
  304. /**
  305. * Set options for libxml loader
  306. *
  307. * @param int $options Options for libxml loader
  308. */
  309. public static function setLibXmlLoaderOptions($options = null)
  310. {
  311. if (is_null($options) && defined('LIBXML_DTDLOAD')) {
  312. $options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
  313. }
  314. if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
  315. @libxml_disable_entity_loader((bool) $options);
  316. }
  317. self::$libXmlLoaderOptions = $options;
  318. }
  319. /**
  320. * Get defined options for libxml loader.
  321. * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
  322. *
  323. * @return int Default options for libxml loader
  324. */
  325. public static function getLibXmlLoaderOptions()
  326. {
  327. if (is_null(self::$libXmlLoaderOptions) && defined('LIBXML_DTDLOAD')) {
  328. self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
  329. } elseif (is_null(self::$libXmlLoaderOptions)) {
  330. self::$libXmlLoaderOptions = true;
  331. }
  332. if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
  333. @libxml_disable_entity_loader((bool) self::$libXmlLoaderOptions);
  334. }
  335. return self::$libXmlLoaderOptions;
  336. }
  337. }