cab720a04a322a416aa2f67c223f6dd3878b4bf1.svn-base 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <?php
  2. /**
  3. * PHPExcel
  4. *
  5. * Copyright (c) 2006 - 2014 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 - 2014 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. * 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. } // function setZipClass()
  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. } // function getZipClass()
  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. } // function getCacheStorageMethod()
  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. } // function getCacheStorageClass()
  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(
  151. $method = PHPExcel_CachedObjectStorageFactory::cache_in_memory,
  152. $arguments = array()
  153. )
  154. {
  155. return PHPExcel_CachedObjectStorageFactory::initialize($method, $arguments);
  156. } // function setCacheStorageMethod()
  157. /**
  158. * Set the locale code to use for formula translations and any special formatting
  159. *
  160. * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk")
  161. * @return boolean Success or failure
  162. */
  163. public static function setLocale($locale='en_us')
  164. {
  165. return PHPExcel_Calculation::getInstance()->setLocale($locale);
  166. } // function setLocale()
  167. /**
  168. * Set details of the external library that PHPExcel should use for rendering charts
  169. *
  170. * @param string $libraryName Internal reference name of the library
  171. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  172. * @param string $libraryBaseDir Directory path to the library's base folder
  173. *
  174. * @return boolean Success or failure
  175. */
  176. public static function setChartRenderer($libraryName, $libraryBaseDir)
  177. {
  178. if (!self::setChartRendererName($libraryName))
  179. return FALSE;
  180. return self::setChartRendererPath($libraryBaseDir);
  181. } // function setChartRenderer()
  182. /**
  183. * Identify to PHPExcel the external library to use for rendering charts
  184. *
  185. * @param string $libraryName Internal reference name of the library
  186. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  187. *
  188. * @return boolean Success or failure
  189. */
  190. public static function setChartRendererName($libraryName)
  191. {
  192. if (!in_array($libraryName,self::$_chartRenderers)) {
  193. return FALSE;
  194. }
  195. self::$_chartRendererName = $libraryName;
  196. return TRUE;
  197. } // function setChartRendererName()
  198. /**
  199. * Tell PHPExcel where to find the external library to use for rendering charts
  200. *
  201. * @param string $libraryBaseDir Directory path to the library's base folder
  202. * @return boolean Success or failure
  203. */
  204. public static function setChartRendererPath($libraryBaseDir)
  205. {
  206. if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
  207. return FALSE;
  208. }
  209. self::$_chartRendererPath = $libraryBaseDir;
  210. return TRUE;
  211. } // function setChartRendererPath()
  212. /**
  213. * Return the Chart Rendering Library that PHPExcel is currently configured to use (e.g. jpgraph)
  214. *
  215. * @return string|NULL Internal reference name of the Chart Rendering Library that PHPExcel is
  216. * currently configured to use
  217. * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
  218. */
  219. public static function getChartRendererName()
  220. {
  221. return self::$_chartRendererName;
  222. } // function getChartRendererName()
  223. /**
  224. * Return the directory path to the Chart Rendering Library that PHPExcel is currently configured to use
  225. *
  226. * @return string|NULL Directory Path to the Chart Rendering Library that PHPExcel is
  227. * currently configured to use
  228. */
  229. public static function getChartRendererPath()
  230. {
  231. return self::$_chartRendererPath;
  232. } // function getChartRendererPath()
  233. /**
  234. * Set details of the external library that PHPExcel should use for rendering PDF files
  235. *
  236. * @param string $libraryName Internal reference name of the library
  237. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  238. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  239. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  240. * @param string $libraryBaseDir Directory path to the library's base folder
  241. *
  242. * @return boolean Success or failure
  243. */
  244. public static function setPdfRenderer($libraryName, $libraryBaseDir)
  245. {
  246. if (!self::setPdfRendererName($libraryName))
  247. return FALSE;
  248. return self::setPdfRendererPath($libraryBaseDir);
  249. } // function setPdfRenderer()
  250. /**
  251. * Identify to PHPExcel the external library to use for rendering PDF files
  252. *
  253. * @param string $libraryName Internal reference name of the library
  254. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  255. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  256. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  257. *
  258. * @return boolean Success or failure
  259. */
  260. public static function setPdfRendererName($libraryName)
  261. {
  262. if (!in_array($libraryName,self::$_pdfRenderers)) {
  263. return FALSE;
  264. }
  265. self::$_pdfRendererName = $libraryName;
  266. return TRUE;
  267. } // function setPdfRendererName()
  268. /**
  269. * Tell PHPExcel where to find the external library to use for rendering PDF files
  270. *
  271. * @param string $libraryBaseDir Directory path to the library's base folder
  272. * @return boolean Success or failure
  273. */
  274. public static function setPdfRendererPath($libraryBaseDir)
  275. {
  276. if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
  277. return FALSE;
  278. }
  279. self::$_pdfRendererPath = $libraryBaseDir;
  280. return TRUE;
  281. } // function setPdfRendererPath()
  282. /**
  283. * Return the PDF Rendering Library that PHPExcel is currently configured to use (e.g. dompdf)
  284. *
  285. * @return string|NULL Internal reference name of the PDF Rendering Library that PHPExcel is
  286. * currently configured to use
  287. * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
  288. * PHPExcel_Settings::PDF_RENDERER_DOMPDF
  289. * or PHPExcel_Settings::PDF_RENDERER_MPDF
  290. */
  291. public static function getPdfRendererName()
  292. {
  293. return self::$_pdfRendererName;
  294. } // function getPdfRendererName()
  295. /**
  296. * Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use
  297. *
  298. * @return string|NULL Directory Path to the PDF Rendering Library that PHPExcel is
  299. * currently configured to use
  300. */
  301. public static function getPdfRendererPath()
  302. {
  303. return self::$_pdfRendererPath;
  304. } // function getPdfRendererPath()
  305. /**
  306. * Set default options for libxml loader
  307. *
  308. * @param int $options Default options for libxml loader
  309. */
  310. public static function setLibXmlLoaderOptions($options = null)
  311. {
  312. if (is_null($options) && defined(LIBXML_DTDLOAD)) {
  313. $options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
  314. }
  315. if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
  316. @libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
  317. }
  318. self::$_libXmlLoaderOptions = $options;
  319. } // function setLibXmlLoaderOptions
  320. /**
  321. * Get default options for libxml loader.
  322. * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
  323. *
  324. * @return int Default options for libxml loader
  325. */
  326. public static function getLibXmlLoaderOptions()
  327. {
  328. if (is_null(self::$_libXmlLoaderOptions) && defined(LIBXML_DTDLOAD)) {
  329. self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
  330. }
  331. if (version_compare(PHP_VERSION, '5.2.11') >= 0) {
  332. @libxml_disable_entity_loader(self::$_libXmlLoaderOptions == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
  333. }
  334. return self::$_libXmlLoaderOptions;
  335. } // function getLibXmlLoaderOptions
  336. }