maruto 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,859 @@
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category Mage
22
+ * @package Mage_Core
23
+ * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
24
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25
+ */
26
+
27
+ define('DS', DIRECTORY_SEPARATOR);
28
+ define('PS', PATH_SEPARATOR);
29
+ define('BP', dirname(dirname(__FILE__)));
30
+
31
+ Mage::register('original_include_path', get_include_path());
32
+
33
+ if (defined('COMPILER_INCLUDE_PATH')) {
34
+ $appPath = COMPILER_INCLUDE_PATH;
35
+ set_include_path($appPath . PS . Mage::registry('original_include_path'));
36
+ include_once "Mage_Core_functions.php";
37
+ include_once "Varien_Autoload.php";
38
+ } else {
39
+ /**
40
+ * Set include path
41
+ */
42
+ $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'local';
43
+ $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'community';
44
+ $paths[] = BP . DS . 'app' . DS . 'code' . DS . 'core';
45
+ $paths[] = BP . DS . 'lib';
46
+
47
+ $appPath = implode(PS, $paths);
48
+ set_include_path($appPath . PS . Mage::registry('original_include_path'));
49
+ include_once "Mage/Core/functions.php";
50
+ include_once "Varien/Autoload.php";
51
+ }
52
+
53
+ Varien_Autoload::register();
54
+
55
+ /**
56
+ * Main Mage hub class
57
+ *
58
+ * @author Magento Core Team <core@magentocommerce.com>
59
+ */
60
+ final class Mage
61
+ {
62
+ /**
63
+ * Registry collection
64
+ *
65
+ * @var array
66
+ */
67
+ static private $_registry = array();
68
+
69
+ /**
70
+ * Application root absolute path
71
+ *
72
+ * @var string
73
+ */
74
+ static private $_appRoot;
75
+
76
+ /**
77
+ * Application model
78
+ *
79
+ * @var Mage_Core_Model_App
80
+ */
81
+ static private $_app;
82
+
83
+ /**
84
+ * Config Model
85
+ *
86
+ * @var Mage_Core_Model_Config
87
+ */
88
+ static private $_config;
89
+
90
+ /**
91
+ * Event Collection Object
92
+ *
93
+ * @var Varien_Event_Collection
94
+ */
95
+ static private $_events;
96
+
97
+ /**
98
+ * Object cache instance
99
+ *
100
+ * @var Varien_Object_Cache
101
+ */
102
+ static private $_objects;
103
+
104
+ /**
105
+ * Is downloader flag
106
+ *
107
+ * @var bool
108
+ */
109
+ static private $_isDownloader = false;
110
+
111
+ /**
112
+ * Is developer mode flag
113
+ *
114
+ * @var bool
115
+ */
116
+ static private $_isDeveloperMode = false;
117
+
118
+ /**
119
+ * Is allow throw Exception about headers already sent
120
+ *
121
+ * @var bool
122
+ */
123
+ public static $headersSentThrowsException = true;
124
+
125
+ /**
126
+ * Is installed flag
127
+ *
128
+ * @var bool
129
+ */
130
+ static private $_isInstalled;
131
+
132
+ /**
133
+ * Gets the current Magento version string
134
+ * @link http://www.magentocommerce.com/blog/new-community-edition-release-process/
135
+ *
136
+ * @return string
137
+ */
138
+ public static function getVersion()
139
+ {
140
+ $i = self::getVersionInfo();
141
+ return trim("{$i['major']}.{$i['minor']}.{$i['revision']}.{$i['patch']}-{$i['stability']}{$i['number']}", '.-');
142
+ }
143
+
144
+ /**
145
+ * Gets the detailed Magento version information
146
+ * @link http://www.magentocommerce.com/blog/new-community-edition-release-process/
147
+ *
148
+ * @return array
149
+ */
150
+ public static function getVersionInfo()
151
+ {
152
+ return array(
153
+ 'major' => '1',
154
+ 'minor' => '4',
155
+ 'revision' => '0',
156
+ 'patch' => '0',
157
+ 'stability' => '',
158
+ 'number' => '',
159
+ );
160
+ }
161
+
162
+ /**
163
+ * Set all my static data to defaults
164
+ *
165
+ */
166
+ public static function reset()
167
+ {
168
+ self::$_registry = array();
169
+ self::$_app = null;
170
+ self::$_config = null;
171
+ self::$_events = null;
172
+ self::$_objects = null;
173
+ self::$_isDownloader = false;
174
+ self::$_isDeveloperMode = false;
175
+ // do not reset $headersSentThrowsException
176
+ }
177
+
178
+ /**
179
+ * Register a new variable
180
+ *
181
+ * @param string $key
182
+ * @param mixed $value
183
+ * @param bool $graceful
184
+ * @throws Mage_Core_Exception
185
+ */
186
+ public static function register($key, $value, $graceful = false)
187
+ {
188
+ if (isset(self::$_registry[$key])) {
189
+ if ($graceful) {
190
+ return;
191
+ }
192
+ self::throwException('Mage registry key "'.$key.'" already exists');
193
+ }
194
+ self::$_registry[$key] = $value;
195
+ }
196
+
197
+ /**
198
+ * Unregister a variable from register by key
199
+ *
200
+ * @param string $key
201
+ */
202
+ public static function unregister($key)
203
+ {
204
+ if (isset(self::$_registry[$key])) {
205
+ if (is_object(self::$_registry[$key]) && (method_exists(self::$_registry[$key], '__destruct'))) {
206
+ self::$_registry[$key]->__destruct();
207
+ }
208
+ unset(self::$_registry[$key]);
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Retrieve a value from registry by a key
214
+ *
215
+ * @param string $key
216
+ * @return mixed
217
+ */
218
+ public static function registry($key)
219
+ {
220
+ if (isset(self::$_registry[$key])) {
221
+ return self::$_registry[$key];
222
+ }
223
+ return null;
224
+ }
225
+
226
+ /**
227
+ * Set application root absolute path
228
+ *
229
+ * @param string $appRoot
230
+ * @throws Mage_Core_Exception
231
+ */
232
+ public static function setRoot($appRoot = '')
233
+ {
234
+ if (self::$_appRoot) {
235
+ return ;
236
+ }
237
+
238
+ if ('' === $appRoot) {
239
+ // automagically find application root by dirname of Mage.php
240
+ $appRoot = dirname(__FILE__);
241
+ }
242
+
243
+ $appRoot = realpath($appRoot);
244
+
245
+ if (is_dir($appRoot) and is_readable($appRoot)) {
246
+ self::$_appRoot = $appRoot;
247
+ } else {
248
+ self::throwException($appRoot . ' is not a directory or not readable by this user');
249
+ }
250
+ }
251
+
252
+ /**
253
+ * Retrieve application root absolute path
254
+ *
255
+ * @return string
256
+ */
257
+ public static function getRoot()
258
+ {
259
+ return self::$_appRoot;
260
+ }
261
+
262
+ /**
263
+ * Retrieve Events Collection
264
+ *
265
+ * @return Varien_Event_Collection $collection
266
+ */
267
+ public static function getEvents()
268
+ {
269
+ return self::$_events;
270
+ }
271
+
272
+ /**
273
+ * Varien Objects Cache
274
+ *
275
+ * @param string $key optional, if specified will load this key
276
+ * @return Varien_Object_Cache
277
+ */
278
+ public static function objects($key = null)
279
+ {
280
+ if (!self::$_objects) {
281
+ self::$_objects = new Varien_Object_Cache;
282
+ }
283
+ if (is_null($key)) {
284
+ return self::$_objects;
285
+ } else {
286
+ return self::$_objects->load($key);
287
+ }
288
+ }
289
+
290
+ /**
291
+ * Retrieve application root absolute path
292
+ *
293
+ * @param string $type
294
+ * @return string
295
+ */
296
+ public static function getBaseDir($type = 'base')
297
+ {
298
+ return self::getConfig()->getOptions()->getDir($type);
299
+ }
300
+
301
+ /**
302
+ * Retrieve module absolute path by directory type
303
+ *
304
+ * @param string $type
305
+ * @param string $moduleName
306
+ * @return string
307
+ */
308
+ public static function getModuleDir($type, $moduleName)
309
+ {
310
+ return self::getConfig()->getModuleDir($type, $moduleName);
311
+ }
312
+
313
+ /**
314
+ * Retrieve config value for store by path
315
+ *
316
+ * @param string $path
317
+ * @param mixed $store
318
+ * @return mixed
319
+ */
320
+ public static function getStoreConfig($path, $store = null)
321
+ {
322
+ return self::app()->getStore($store)->getConfig($path);
323
+ }
324
+
325
+ /**
326
+ * Retrieve config flag for store by path
327
+ *
328
+ * @param string $path
329
+ * @param mixed $store
330
+ * @return bool
331
+ */
332
+ public static function getStoreConfigFlag($path, $store = null)
333
+ {
334
+ $flag = strtolower(self::getStoreConfig($path, $store));
335
+ if (!empty($flag) && 'false' !== $flag) {
336
+ return true;
337
+ } else {
338
+ return false;
339
+ }
340
+ }
341
+
342
+ /**
343
+ * Get base URL path by type
344
+ *
345
+ * @param string $type
346
+ * @return string
347
+ */
348
+ public static function getBaseUrl($type = Mage_Core_Model_Store::URL_TYPE_LINK, $secure = null)
349
+ {
350
+ return self::app()->getStore()->getBaseUrl($type, $secure);
351
+ }
352
+
353
+ /**
354
+ * Generate url by route and parameters
355
+ *
356
+ * @param string $route
357
+ * @param array $params
358
+ * @return string
359
+ */
360
+ public static function getUrl($route = '', $params = array())
361
+ {
362
+ return self::getModel('core/url')->getUrl($route, $params);
363
+ }
364
+
365
+ /**
366
+ * Get design package singleton
367
+ *
368
+ * @return Mage_Core_Model_Design_Package
369
+ */
370
+ public static function getDesign()
371
+ {
372
+ return self::getSingleton('core/design_package');
373
+ }
374
+
375
+ /**
376
+ * Retrieve a config instance
377
+ *
378
+ * @return Mage_Core_Model_Config
379
+ */
380
+ public static function getConfig()
381
+ {
382
+ return self::$_config;
383
+ }
384
+
385
+ /**
386
+ * Add observer to even object
387
+ *
388
+ * @param string $eventName
389
+ * @param callback $callback
390
+ * @param array $arguments
391
+ * @param string $observerName
392
+ */
393
+ public static function addObserver($eventName, $callback, $data = array(), $observerName = '', $observerClass = '')
394
+ {
395
+ if ($observerClass == '') {
396
+ $observerClass = 'Varien_Event_Observer';
397
+ }
398
+ $observer = new $observerClass();
399
+ $observer->setName($observerName)->addData($data)->setEventName($eventName)->setCallback($callback);
400
+ return self::getEvents()->addObserver($observer);
401
+ }
402
+
403
+ /**
404
+ * Dispatch event
405
+ *
406
+ * Calls all observer callbacks registered for this event
407
+ * and multiobservers matching event name pattern
408
+ *
409
+ * @param string $name
410
+ * @param array $args
411
+ * @return Mage_Core_Model_App
412
+ */
413
+ public static function dispatchEvent($name, array $data = array())
414
+ {
415
+ Varien_Profiler::start('DISPATCH EVENT:'.$name);
416
+ $result = self::app()->dispatchEvent($name, $data);
417
+ #$result = self::registry('events')->dispatch($name, $data);
418
+ Varien_Profiler::stop('DISPATCH EVENT:'.$name);
419
+ return $result;
420
+ }
421
+
422
+ /**
423
+ * Retrieve model object
424
+ *
425
+ * @link Mage_Core_Model_Config::getModelInstance
426
+ * @param string $modelClass
427
+ * @param array $arguments
428
+ * @return Mage_Core_Model_Abstract
429
+ */
430
+ public static function getModel($modelClass = '', $arguments = array())
431
+ {
432
+ return self::getConfig()->getModelInstance($modelClass, $arguments);
433
+ }
434
+
435
+ /**
436
+ * Retrieve model object singleton
437
+ *
438
+ * @param string $modelClass
439
+ * @param array $arguments
440
+ * @return Mage_Core_Model_Abstract
441
+ */
442
+ public static function getSingleton($modelClass='', array $arguments=array())
443
+ {
444
+ $registryKey = '_singleton/'.$modelClass;
445
+ if (!self::registry($registryKey)) {
446
+ self::register($registryKey, self::getModel($modelClass, $arguments));
447
+ }
448
+ return self::registry($registryKey);
449
+ }
450
+
451
+ /**
452
+ * Retrieve object of resource model
453
+ *
454
+ * @param string $modelClass
455
+ * @param array $arguments
456
+ * @return Object
457
+ */
458
+ public static function getResourceModel($modelClass, $arguments = array())
459
+ {
460
+ return self::getConfig()->getResourceModelInstance($modelClass, $arguments);
461
+ }
462
+
463
+ /**
464
+ * Retrieve Controller instance by ClassName
465
+ *
466
+ * @param string $class
467
+ * @param Mage_Core_Controller_Request_Http $request
468
+ * @param Mage_Core_Controller_Response_Http $response
469
+ * @param array $invokeArgs
470
+ * @return Mage_Core_Controller_Front_Action
471
+ */
472
+ public static function getControllerInstance($class, $request, $response, array $invokeArgs = array())
473
+ {
474
+ return new $class($request, $response, $invokeArgs);
475
+ }
476
+
477
+ /**
478
+ * Retrieve resource vodel object singleton
479
+ *
480
+ * @param string $modelClass
481
+ * @param array $arguments
482
+ * @return object
483
+ */
484
+ public static function getResourceSingleton($modelClass = '', array $arguments = array())
485
+ {
486
+ $registryKey = '_resource_singleton/'.$modelClass;
487
+ if (!self::registry($registryKey)) {
488
+ self::register($registryKey, self::getResourceModel($modelClass, $arguments));
489
+ }
490
+ return self::registry($registryKey);
491
+ }
492
+
493
+ /**
494
+ * Deprecated, use self::helper()
495
+ *
496
+ * @param string $type
497
+ * @return object
498
+ */
499
+ public static function getBlockSingleton($type)
500
+ {
501
+ $action = self::app()->getFrontController()->getAction();
502
+ return $action ? $action->getLayout()->getBlockSingleton($type) : false;
503
+ }
504
+
505
+ /**
506
+ * Retrieve helper object
507
+ *
508
+ * @param string $name the helper name
509
+ * @return Mage_Core_Helper_Abstract
510
+ */
511
+ public static function helper($name)
512
+ {
513
+ if (strpos($name, '/') === false) {
514
+ $name .= '/data';
515
+ }
516
+
517
+ $registryKey = '_helper/' . $name;
518
+ if (!self::registry($registryKey)) {
519
+ $helperClass = self::getConfig()->getHelperClassName($name);
520
+ self::register($registryKey, new $helperClass);
521
+ }
522
+ return self::registry($registryKey);
523
+ }
524
+
525
+ /**
526
+ * Return new exception by module to be thrown
527
+ *
528
+ * @param string $module
529
+ * @param string $message
530
+ * @param integer $code
531
+ * @return Mage_Core_Exception
532
+ */
533
+ public static function exception($module = 'Mage_Core', $message = '', $code = 0)
534
+ {
535
+ $className = $module.'_Exception';
536
+ return new $className($message, $code);
537
+ }
538
+
539
+ /**
540
+ * Throw Exception
541
+ *
542
+ * @param string $message
543
+ * @param string $messageStorage
544
+ */
545
+ public static function throwException($message, $messageStorage = null)
546
+ {
547
+ if ($messageStorage && ($storage = self::getSingleton($messageStorage))) {
548
+ $storage->addError($message);
549
+ }
550
+ throw new Mage_Core_Exception($message);
551
+ }
552
+
553
+ /**
554
+ * Get initialized application object.
555
+ *
556
+ * @param string $code
557
+ * @param string $type
558
+ * @param string|array $options
559
+ * @return Mage_Core_Model_App
560
+ */
561
+ public static function app($code = '', $type = 'store', $options = array())
562
+ {
563
+ if (null === self::$_app) {
564
+ self::$_app = new Mage_Core_Model_App();
565
+ self::setRoot();
566
+ self::$_events = new Varien_Event_Collection();
567
+ self::$_config = new Mage_Core_Model_Config();
568
+
569
+ Varien_Profiler::start('self::app::init');
570
+ self::$_app->init($code, $type, $options);
571
+ Varien_Profiler::stop('self::app::init');
572
+ self::$_app->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS);
573
+ }
574
+ return self::$_app;
575
+ }
576
+
577
+ /**
578
+ * Front end main entry point
579
+ *
580
+ * @param string $code
581
+ * @param string $type
582
+ * @param string|array $options
583
+ */
584
+ public static function run($code = '', $type = 'store', $options=array())
585
+ {
586
+ try {
587
+ Varien_Profiler::start('mage');
588
+ self::setRoot();
589
+ self::$_app = new Mage_Core_Model_App();
590
+ self::$_events = new Varien_Event_Collection();
591
+ self::$_config = new Mage_Core_Model_Config();
592
+ self::$_app->run(array(
593
+ 'scope_code' => $code,
594
+ 'scope_type' => $type,
595
+ 'options' => $options,
596
+ ));
597
+ Varien_Profiler::stop('mage');
598
+ } catch (Mage_Core_Model_Session_Exception $e) {
599
+ header('Location: ' . self::getBaseUrl());
600
+ die();
601
+ } catch (Mage_Core_Model_Store_Exception $e) {
602
+ require_once(self::getBaseDir() . DS . 'errors' . DS . '404.php');
603
+ die();
604
+ } catch (Exception $e) {
605
+ if (self::isInstalled() || self::$_isDownloader) {
606
+ self::printException($e);
607
+ exit();
608
+ }
609
+ try {
610
+ self::dispatchEvent('mage_run_exception', array('exception' => $e));
611
+ if (!headers_sent()) {
612
+ header('Location:' . self::getUrl('install'));
613
+ } else {
614
+ self::printException($e);
615
+ }
616
+ } catch (Exception $ne) {
617
+ self::printException($ne, $e->getMessage());
618
+ }
619
+ }
620
+ }
621
+
622
+ /**
623
+ * Retrieve application installation flag
624
+ *
625
+ * @param string|array $options
626
+ * @return bool
627
+ */
628
+ public static function isInstalled($options = array())
629
+ {
630
+ if (self::$_isInstalled === null) {
631
+ self::setRoot();
632
+
633
+ if (is_string($options)) {
634
+ $options = array('etc_dir' => $options);
635
+ }
636
+ $etcDir = 'etc';
637
+ if (!empty($options['etc_dir'])) {
638
+ $etcDir = $options['etc_dir'];
639
+ }
640
+ $localConfigFile = self::getRoot() . DS . $etcDir . DS . 'local.xml';
641
+
642
+ self::$_isInstalled = false;
643
+
644
+ if (is_readable($localConfigFile)) {
645
+ $localConfig = simplexml_load_file($localConfigFile);
646
+ date_default_timezone_set('UTC');
647
+ if (($date = $localConfig->global->install->date) && strtotime($date)) {
648
+ self::$_isInstalled = true;
649
+ }
650
+ }
651
+ }
652
+ return self::$_isInstalled;
653
+ }
654
+
655
+ /**
656
+ * log facility (??)
657
+ *
658
+ * @param string $message
659
+ * @param integer $level
660
+ * @param string $file
661
+ */
662
+ public static function log($message, $level = null, $file = '')
663
+ {
664
+ if (!self::getConfig()) {
665
+ return;
666
+ }
667
+
668
+ try {
669
+ $logActive = self::getStoreConfig('dev/log/active');
670
+ if (empty($file)) {
671
+ $file = self::getStoreConfig('dev/log/file');
672
+ }
673
+ }
674
+ catch (Exception $e) {
675
+ $logActive = true;
676
+ }
677
+
678
+ if (!self::$_isDeveloperMode && !$logActive) {
679
+ return;
680
+ }
681
+
682
+ static $loggers = array();
683
+
684
+ $level = is_null($level) ? Zend_Log::DEBUG : $level;
685
+ $file = empty($file) ? 'system.log' : $file;
686
+
687
+ try {
688
+ if (!isset($loggers[$file])) {
689
+ $logFile = self::getBaseDir('var') . DS . 'log' . DS . $file;
690
+
691
+ if (!is_dir(self::getBaseDir('var').DS.'log')) {
692
+ mkdir(self::getBaseDir('var').DS.'log', 0777);
693
+ }
694
+
695
+ if (!file_exists($logFile)) {
696
+ file_put_contents($logFile, '');
697
+ chmod($logFile, 0777);
698
+ }
699
+
700
+ $format = '%timestamp% %priorityName% (%priority%): %message%' . PHP_EOL;
701
+ $formatter = new Zend_Log_Formatter_Simple($format);
702
+ $writer = new Zend_Log_Writer_Stream($logFile);
703
+ $writer->setFormatter($formatter);
704
+ $loggers[$file] = new Zend_Log($writer);
705
+ }
706
+
707
+ if (is_array($message) || is_object($message)) {
708
+ $message = print_r($message, true);
709
+ }
710
+
711
+ $loggers[$file]->log($message, $level);
712
+ }
713
+ catch (Exception $e) {
714
+ }
715
+ }
716
+
717
+ /**
718
+ * Write exception to log
719
+ *
720
+ * @param Exception $e
721
+ */
722
+ public static function logException(Exception $e)
723
+ {
724
+ if (!self::getConfig()) {
725
+ return;
726
+ }
727
+ $file = self::getStoreConfig('dev/log/exception_file');
728
+ self::log("\n" . $e->__toString(), Zend_Log::ERR, $file);
729
+ }
730
+
731
+ /**
732
+ * Set enabled developer mode
733
+ *
734
+ * @param bool $mode
735
+ * @return bool
736
+ */
737
+ public static function setIsDeveloperMode($mode)
738
+ {
739
+ self::$_isDeveloperMode = (bool)$mode;
740
+ return self::$_isDeveloperMode;
741
+ }
742
+
743
+ /**
744
+ * Retrieve enabled developer mode
745
+ *
746
+ * @return bool
747
+ */
748
+ public static function getIsDeveloperMode()
749
+ {
750
+ return self::$_isDeveloperMode;
751
+ }
752
+
753
+ /**
754
+ * Display exception
755
+ *
756
+ * @param Exception $e
757
+ */
758
+ public static function printException(Exception $e, $extra = '')
759
+ {
760
+ if (self::$_isDeveloperMode) {
761
+ print '<pre>';
762
+
763
+ if (!empty($extra)) {
764
+ print $extra . "\n\n";
765
+ }
766
+
767
+ print $e->getMessage() . "\n\n";
768
+ print $e->getTraceAsString();
769
+ print '</pre>';
770
+ } else {
771
+
772
+ $reportData = array(
773
+ !empty($extra) ? $extra . "\n\n" : '' . $e->getMessage(),
774
+ $e->getTraceAsString()
775
+ );
776
+
777
+ // retrieve server data
778
+ if (isset($_SERVER)) {
779
+ if (isset($_SERVER['REQUEST_URI'])) {
780
+ $reportData['url'] = $_SERVER['REQUEST_URI'];
781
+ }
782
+ if (isset($_SERVER['SCRIPT_NAME'])) {
783
+ $reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
784
+ }
785
+ }
786
+
787
+ // attempt to specify store as a skin
788
+ try {
789
+ $storeCode = self::app()->getStore()->getCode();
790
+ $reportData['skin'] = $storeCode;
791
+ }
792
+ catch (Exception $e) {}
793
+
794
+ require_once(self::getBaseDir() . DS . 'errors' . DS . 'report.php');
795
+ }
796
+
797
+ die();
798
+ }
799
+
800
+ /**
801
+ * Define system folder directory url by virtue of running script directory name
802
+ * Try to find requested folder by shifting to domain root directory
803
+ *
804
+ * @param string $folder
805
+ * @param boolean $exitIfNot
806
+ * @return string
807
+ */
808
+ public static function getScriptSystemUrl($folder, $exitIfNot = false)
809
+ {
810
+ $runDirUrl = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/');
811
+ $runDir = rtrim(dirname($_SERVER['SCRIPT_FILENAME']), DS);
812
+
813
+ $baseUrl = null;
814
+ if (is_dir($runDir.'/'.$folder)) {
815
+ $baseUrl = str_replace(DS, '/', $runDirUrl);
816
+ } else {
817
+ $runDirUrlArray = explode('/', $runDirUrl);
818
+ $runDirArray = explode('/', $runDir);
819
+ $count = count($runDirArray);
820
+
821
+ for ($i=0; $i < $count; $i++) {
822
+ array_pop($runDirUrlArray);
823
+ array_pop($runDirArray);
824
+ $_runDir = implode('/', $runDirArray);
825
+ if (!empty($_runDir)) {
826
+ $_runDir .= '/';
827
+ }
828
+
829
+ if (is_dir($_runDir.$folder)) {
830
+ $_runDirUrl = implode('/', $runDirUrlArray);
831
+ $baseUrl = str_replace(DS, '/', $_runDirUrl);
832
+ break;
833
+ }
834
+ }
835
+ }
836
+
837
+ if (is_null($baseUrl)) {
838
+ $errorMessage = "Unable detect system directory: $folder";
839
+ if ($exitIfNot) {
840
+ // exit because of infinity loop
841
+ exit($errorMessage);
842
+ } else {
843
+ self::printException(new Exception(), $errorMessage);
844
+ }
845
+ }
846
+
847
+ return $baseUrl;
848
+ }
849
+
850
+ /**
851
+ * Set is downloader flag
852
+ *
853
+ * @param bool $flag
854
+ */
855
+ public static function setIsDownloader($flag = true)
856
+ {
857
+ self::$_isDownloader = $flag;
858
+ }
859
+ }