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 1.8.0, 2014-03-02
26: */
27:
28: /** PHPExcel root directory */
29: if (!defined('PHPEXCEL_ROOT')) {
30: /**
31: * @ignore
32: */
33: define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
34: require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
35: }
36:
37:
38: class PHPExcel_Settings
39: {
40: /** constants */
41: /** Available Zip library classes */
42: const PCLZIP = 'PHPExcel_Shared_ZipArchive';
43: const ZIPARCHIVE = 'ZipArchive';
44:
45: /** Optional Chart Rendering libraries */
46: const CHART_RENDERER_JPGRAPH = 'jpgraph';
47:
48: /** Optional PDF Rendering libraries */
49: const PDF_RENDERER_TCPDF = 'tcPDF';
50: const PDF_RENDERER_DOMPDF = 'DomPDF';
51: const PDF_RENDERER_MPDF = 'mPDF';
52:
53:
54: private static $_chartRenderers = array(
55: self::CHART_RENDERER_JPGRAPH,
56: );
57:
58: private static $_pdfRenderers = array(
59: self::PDF_RENDERER_TCPDF,
60: self::PDF_RENDERER_DOMPDF,
61: self::PDF_RENDERER_MPDF,
62: );
63:
64:
65: /**
66: * Name of the class used for Zip file management
67: * e.g.
68: * ZipArchive
69: *
70: * @var string
71: */
72: private static $_zipClass = self::ZIPARCHIVE;
73:
74:
75: /**
76: * Name of the external Library used for rendering charts
77: * e.g.
78: * jpgraph
79: *
80: * @var string
81: */
82: private static $_chartRendererName = NULL;
83:
84: /**
85: * Directory Path to the external Library used for rendering charts
86: *
87: * @var string
88: */
89: private static $_chartRendererPath = NULL;
90:
91:
92: /**
93: * Name of the external Library used for rendering PDF files
94: * e.g.
95: * mPDF
96: *
97: * @var string
98: */
99: private static $_pdfRendererName = NULL;
100:
101: /**
102: * Directory Path to the external Library used for rendering PDF files
103: *
104: * @var string
105: */
106: private static $_pdfRendererPath = NULL;
107:
108: /**
109: * Default options for libxml loader
110: *
111: * @var int
112: */
113: private static $_libXmlLoaderOptions = null;
114:
115: /**
116: * Set the Zip handler Class that PHPExcel should use for Zip file management (PCLZip or ZipArchive)
117: *
118: * @param string $zipClass The Zip handler class that PHPExcel should use for Zip file management
119: * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
120: * @return boolean Success or failure
121: */
122: public static function setZipClass($zipClass)
123: {
124: if (($zipClass === self::PCLZIP) ||
125: ($zipClass === self::ZIPARCHIVE)) {
126: self::$_zipClass = $zipClass;
127: return TRUE;
128: }
129: return FALSE;
130: } // function setZipClass()
131:
132:
133: /**
134: * Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive)
135: * or Zip file management
136: *
137: * @return string Name of the Zip handler Class that PHPExcel is configured to use
138: * for Zip file management
139: * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive
140: */
141: public static function getZipClass()
142: {
143: return self::$_zipClass;
144: } // function getZipClass()
145:
146:
147: /**
148: * Return the name of the method that is currently configured for cell cacheing
149: *
150: * @return string Name of the cacheing method
151: */
152: public static function getCacheStorageMethod()
153: {
154: return PHPExcel_CachedObjectStorageFactory::getCacheStorageMethod();
155: } // function getCacheStorageMethod()
156:
157:
158: /**
159: * Return the name of the class that is currently being used for cell cacheing
160: *
161: * @return string Name of the class currently being used for cacheing
162: */
163: public static function getCacheStorageClass()
164: {
165: return PHPExcel_CachedObjectStorageFactory::getCacheStorageClass();
166: } // function getCacheStorageClass()
167:
168:
169: /**
170: * Set the method that should be used for cell cacheing
171: *
172: * @param string $method Name of the cacheing method
173: * @param array $arguments Optional configuration arguments for the cacheing method
174: * @return boolean Success or failure
175: */
176: public static function setCacheStorageMethod(
177: $method = PHPExcel_CachedObjectStorageFactory::cache_in_memory,
178: $arguments = array()
179: )
180: {
181: return PHPExcel_CachedObjectStorageFactory::initialize($method, $arguments);
182: } // function setCacheStorageMethod()
183:
184:
185: /**
186: * Set the locale code to use for formula translations and any special formatting
187: *
188: * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk")
189: * @return boolean Success or failure
190: */
191: public static function setLocale($locale='en_us')
192: {
193: return PHPExcel_Calculation::getInstance()->setLocale($locale);
194: } // function setLocale()
195:
196:
197: /**
198: * Set details of the external library that PHPExcel should use for rendering charts
199: *
200: * @param string $libraryName Internal reference name of the library
201: * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
202: * @param string $libraryBaseDir Directory path to the library's base folder
203: *
204: * @return boolean Success or failure
205: */
206: public static function setChartRenderer($libraryName, $libraryBaseDir)
207: {
208: if (!self::setChartRendererName($libraryName))
209: return FALSE;
210: return self::setChartRendererPath($libraryBaseDir);
211: } // function setChartRenderer()
212:
213:
214: /**
215: * Identify to PHPExcel the external library to use for rendering charts
216: *
217: * @param string $libraryName Internal reference name of the library
218: * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
219: *
220: * @return boolean Success or failure
221: */
222: public static function setChartRendererName($libraryName)
223: {
224: if (!in_array($libraryName,self::$_chartRenderers)) {
225: return FALSE;
226: }
227:
228: self::$_chartRendererName = $libraryName;
229:
230: return TRUE;
231: } // function setChartRendererName()
232:
233:
234: /**
235: * Tell PHPExcel where to find the external library to use for rendering charts
236: *
237: * @param string $libraryBaseDir Directory path to the library's base folder
238: * @return boolean Success or failure
239: */
240: public static function setChartRendererPath($libraryBaseDir)
241: {
242: if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
243: return FALSE;
244: }
245: self::$_chartRendererPath = $libraryBaseDir;
246:
247: return TRUE;
248: } // function setChartRendererPath()
249:
250:
251: /**
252: * Return the Chart Rendering Library that PHPExcel is currently configured to use (e.g. jpgraph)
253: *
254: * @return string|NULL Internal reference name of the Chart Rendering Library that PHPExcel is
255: * currently configured to use
256: * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH
257: */
258: public static function getChartRendererName()
259: {
260: return self::$_chartRendererName;
261: } // function getChartRendererName()
262:
263:
264: /**
265: * Return the directory path to the Chart Rendering Library that PHPExcel is currently configured to use
266: *
267: * @return string|NULL Directory Path to the Chart Rendering Library that PHPExcel is
268: * currently configured to use
269: */
270: public static function getChartRendererPath()
271: {
272: return self::$_chartRendererPath;
273: } // function getChartRendererPath()
274:
275:
276: /**
277: * Set details of the external library that PHPExcel should use for rendering PDF files
278: *
279: * @param string $libraryName Internal reference name of the library
280: * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
281: * PHPExcel_Settings::PDF_RENDERER_DOMPDF
282: * or PHPExcel_Settings::PDF_RENDERER_MPDF
283: * @param string $libraryBaseDir Directory path to the library's base folder
284: *
285: * @return boolean Success or failure
286: */
287: public static function setPdfRenderer($libraryName, $libraryBaseDir)
288: {
289: if (!self::setPdfRendererName($libraryName))
290: return FALSE;
291: return self::setPdfRendererPath($libraryBaseDir);
292: } // function setPdfRenderer()
293:
294:
295: /**
296: * Identify to PHPExcel the external library to use for rendering PDF files
297: *
298: * @param string $libraryName Internal reference name of the library
299: * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
300: * PHPExcel_Settings::PDF_RENDERER_DOMPDF
301: * or PHPExcel_Settings::PDF_RENDERER_MPDF
302: *
303: * @return boolean Success or failure
304: */
305: public static function setPdfRendererName($libraryName)
306: {
307: if (!in_array($libraryName,self::$_pdfRenderers)) {
308: return FALSE;
309: }
310:
311: self::$_pdfRendererName = $libraryName;
312:
313: return TRUE;
314: } // function setPdfRendererName()
315:
316:
317: /**
318: * Tell PHPExcel where to find the external library to use for rendering PDF files
319: *
320: * @param string $libraryBaseDir Directory path to the library's base folder
321: * @return boolean Success or failure
322: */
323: public static function setPdfRendererPath($libraryBaseDir)
324: {
325: if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) {
326: return FALSE;
327: }
328: self::$_pdfRendererPath = $libraryBaseDir;
329:
330: return TRUE;
331: } // function setPdfRendererPath()
332:
333:
334: /**
335: * Return the PDF Rendering Library that PHPExcel is currently configured to use (e.g. dompdf)
336: *
337: * @return string|NULL Internal reference name of the PDF Rendering Library that PHPExcel is
338: * currently configured to use
339: * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF,
340: * PHPExcel_Settings::PDF_RENDERER_DOMPDF
341: * or PHPExcel_Settings::PDF_RENDERER_MPDF
342: */
343: public static function getPdfRendererName()
344: {
345: return self::$_pdfRendererName;
346: } // function getPdfRendererName()
347:
348: /**
349: * Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use
350: *
351: * @return string|NULL Directory Path to the PDF Rendering Library that PHPExcel is
352: * currently configured to use
353: */
354: public static function getPdfRendererPath()
355: {
356: return self::$_pdfRendererPath;
357: } // function getPdfRendererPath()
358:
359: /**
360: * Set default options for libxml loader
361: *
362: * @param int $options Default options for libxml loader
363: */
364: public static function setLibXmlLoaderOptions($options = null)
365: {
366: if (is_null($options)) {
367: $options = LIBXML_DTDLOAD | LIBXML_DTDATTR;
368: }
369: @libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
370: self::$_libXmlLoaderOptions = $options;
371: } // function setLibXmlLoaderOptions
372:
373: /**
374: * Get default options for libxml loader.
375: * Defaults to LIBXML_DTDLOAD | LIBXML_DTDATTR when not set explicitly.
376: *
377: * @return int Default options for libxml loader
378: */
379: public static function getLibXmlLoaderOptions()
380: {
381: if (is_null(self::$_libXmlLoaderOptions)) {
382: self::setLibXmlLoaderOptions(LIBXML_DTDLOAD | LIBXML_DTDATTR);
383: }
384: @libxml_disable_entity_loader($options == (LIBXML_DTDLOAD | LIBXML_DTDATTR));
385: return self::$_libXmlLoaderOptions;
386: } // function getLibXmlLoaderOptions
387: }
388: