Passed
Push — scrutinizer-code-quality ( 09f5a1...c4c5fb )
by Adam
56:05 queued 14:08
created

Sugar_Smarty::__construct()   B

Complexity

Conditions 6
Paths 32

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 6.0073
Metric Value
cc 6
eloc 16
nc 32
nop 0
dl 0
loc 23
ccs 16
cts 17
cp 0.9412
crap 6.0073
rs 8.5906
1
<?php
2 1
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
/*********************************************************************************
4
 * SugarCRM Community Edition is a customer relationship management program developed by
5
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6
7
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
8
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
9
 *
10
 * This program is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU Affero General Public License version 3 as published by the
12
 * Free Software Foundation with the addition of the following permission added
13
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
14
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
15
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
16
 *
17
 * This program is distributed in the hope that it will be useful, but WITHOUT
18
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
20
 * details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License along with
23
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
 * 02110-1301 USA.
26
 *
27
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
28
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
29
 *
30
 * The interactive user interfaces in modified source and object code versions
31
 * of this program must display Appropriate Legal Notices, as required under
32
 * Section 5 of the GNU Affero General Public License version 3.
33
 *
34
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
35
 * these Appropriate Legal Notices must retain the display of the "Powered by
36
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
37
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
38
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39
 ********************************************************************************/
40
41
42 1
require_once('include/Smarty/Smarty.class.php');
43
44 1
if(!defined('SUGAR_SMARTY_DIR'))
45
{
46 1
	define('SUGAR_SMARTY_DIR', sugar_cached('smarty/'));
47
}
48
49
/**
50
 * Smarty wrapper for Sugar
51
 * @api
52
 */
53
class Sugar_Smarty extends Smarty
54
{
55 196
	public function __construct()
56
	{
57 196
        parent::__construct();
58 196
		if(!file_exists(SUGAR_SMARTY_DIR))mkdir_recursive(SUGAR_SMARTY_DIR, true);
59 196
		if(!file_exists(SUGAR_SMARTY_DIR . 'templates_c'))mkdir_recursive(SUGAR_SMARTY_DIR . 'templates_c', true);
60 196
		if(!file_exists(SUGAR_SMARTY_DIR . 'configs'))mkdir_recursive(SUGAR_SMARTY_DIR . 'configs', true);
61 196
		if(!file_exists(SUGAR_SMARTY_DIR . 'cache'))mkdir_recursive(SUGAR_SMARTY_DIR . 'cache', true);
62
63 196
		$this->template_dir = '.';
64 196
		$this->compile_dir = SUGAR_SMARTY_DIR . 'templates_c';
65 196
		$this->config_dir = SUGAR_SMARTY_DIR . 'configs';
66 196
		$this->cache_dir = SUGAR_SMARTY_DIR . 'cache';
67 196
		$this->request_use_auto_globals = true; // to disable Smarty from using long arrays
68
69 196
		if(file_exists('custom/include/Smarty/plugins'))
70
        {
71
			$plugins_dir[] = 'custom/include/Smarty/plugins';
72
        }
73 196
		$plugins_dir[] = 'include/Smarty/plugins';
74 196
		$this->plugins_dir = $plugins_dir;
75
76 196
		$this->assign("VERSION_MARK", getVersionedPath(''));
77 196
	}
78
79
	/**
80
	 * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
81
	 */
82
	public function Sugar_Smarty(){
83
		$deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
84
		if(isset($GLOBALS['log'])) {
85
			$GLOBALS['log']->deprecated($deprecatedMessage);
86
		}
87
		else {
88
			trigger_error($deprecatedMessage, E_USER_DEPRECATED);
89
		}
90
		self::__construct();
91
	}
92
93
	/**
94
	 * Override default _unlink method call to fix Bug 53010
95
	 *
96
	 * @param string $resource
97
     * @param integer $exp_time
98
     */
99
    function _unlink($resource, $exp_time = null)
100
    {
101
        if(file_exists($resource)) {
102
            return parent::_unlink($resource, $exp_time);
103
        }
104
105
        // file wasn't found, so it must be gone.
106
        return true;
107
    }
108
}
109