Settings.php 12 KB

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