Test Failed
Push — master ( a28393...a400a4 )
by David
06:01 queued 03:02
created

Adapters/CodeIgniter/libraries/Dwootemplate.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Copyright (c) 2013-2016
4
 *
5
 * @category  Library
6
 * @package   Dwoo\Adapters\CodeIgniter\libraries
7
 * @author    Jordi Boggiano <[email protected]>
8
 * @author    David Sanchez <[email protected]>
9
 * @copyright 2008-2013 Jordi Boggiano
10
 * @copyright 2013-2016 David Sanchez
11
 * @license   http://dwoo.org/LICENSE Modified BSD License
12
 * @version   1.3.0
13
 * @date      2016-09-19
14
 * @link      http://dwoo.org/
15
 */
16
17
if (!defined('BASEPATH')) {
18
    exit('No direct script access allowed');
19
}
20
21
require 'dwoo/dwooAutoload.php';
22
23
/**
24
 * Creates an template interface from Codeigniter to DWOO.
25
 *
26
 * This software is provided 'as-is', without any express or implied warranty.
27
 * In no event will the authors be held liable for any damages arising from the use of this software.
28
 *
29
 * @author    Stefan Verstege <[email protected]>
30
 * @copyright Copyright (c) 2008, Stefan Verstege
31
 * @license   http://dwoo.org/LICENSE   Modified BSD License
32
 *
33
 * @link http://www.newmedia.nl/
34
 *
35
 * @version 1.1.0
36
 * @date    2009-07-18
37
 *
38
 * @uses the dwoo package from http://dwoo.org
39
 */
40
class Dwootemplate extends Dwoo_Core
41
{
42
    protected $dwoo_data = array();
43
44
    /**
45
     * Constructor for the DwooTemplate engine.
46
     */
47
    public function __construct()
48
    {
49
        // Call parents constructor
50
        parent::__construct();
51
52
        // Set the config settings
53
        $this->initialize();
54
55
        // Assign some defaults to dwoo
56
        $CI = get_instance();
57
        $this->dwoo_data = new Dwoo_Data();
58
        $this->dwoo_data->js_files = array();
59
        $this->dwoo_data->css_files = array();
60
        $this->dwoo_data->CI = $CI;
61
        $this->dwoo_data->site_url = $CI->config->site_url(); // so we can get the full path to CI easily
62
        $this->dwoo_data->uniqid = uniqid();
63
        $this->dwoo_data->timestamp = mktime();
64
65
        log_message('debug', 'Dwoo Template Class Initialized');
66
    }
67
68
    /**
69
     * Assign data to dwoo data object.
70
     *
71
     * @param string $key
72
     * @param mixed  $value
73
     */
74
    public function assign($key, $value)
75
    {
76
        $this->dwoo_data->$key = $value;
77
    }
78
79
    /**
80
     * Add Javascript files to template.
81
     *
82
     * @param string $js
83
     */
84
    public function add_js($js)
85
    {
86
        $current = $this->dwoo_data->js_files;
87
        $current[] = $js;
88
        $this->dwoo_data->js_files = $current;
89
    }
90
91
    /**
92
     * Add Css stylesheets to template.
93
     *
94
     * @param string $css
95
     */
96
    public function add_css($css)
97
    {
98
        $current = $this->dwoo_data->css_files;
99
        $current[] = $css;
100
        $this->dwoo_data->css_files = $current;
101
    }
102
103
    /**
104
     * Display or return the compiled template
105
     * Since we assign the results to the standard CI output module
106
     * you can also use the helper from CI in your templates!!
107
     *
108
     * @param string $sTemplate
109
     * @param bool   $return
110
     *
111
     * @return mixed
112
     */
113
    public function display($sTemplate, $return = false)
114
    {
115
        // Start benchmark
116
        $CI = get_instance();
117
        $CI->benchmark->mark('dwoo_parse_start');
118
119
        // Check if file exists
120
        if (!file_exists($this->template_dir.$sTemplate)) {
121
            $message = sprintf('Template file \'%s\' not found.', $sTemplate);
122
            show_error($message);
123
            log_message('error', $message);
124
        }
125
126
        // Create new template
127
        $tpl = new Dwoo_Template_File($this->template_dir.$sTemplate);
128
129
        // render the template
130
        $template = $this->get($tpl, $this->dwoo_data);
131
132
        // Finish benchmark
133
        $CI->benchmark->mark('dwoo_parse_end');
134
135
        // Return results or not ?
136
        if ($return == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
137
            $CI->output->final_output = $template;
138
        } else {
139
            return $template;
140
        }
141
    }
142
143
    /**
144
     * Toggle Codeigniter profiler on/off.
145
     */
146
    public function enable_profiler($toggle = true)
147
    {
148
        $CI = get_instance();
149
        $CI->output->enable_profiler($toggle);
150
    }
151
152
    /**
153
     * Set http header.
154
     *
155
     * @example $this->output->set_header("HTTP/1.1 200 OK");
156
     * @example $this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');
157
     *
158
     * @param string $header
159
     */
160
    public function set_header($header)
161
    {
162
        $CI = get_instance();
163
        $CI->output->set_header($header);
164
    }
165
166
    /**
167
     * Set status header.
168
     *
169
     * @example $this->output->set_status_header('401');
170
     * @example // Sets the header as: Unauthorized
171
     *
172
     * @param string $header
173
     */
174
    public function set_status_header($header)
175
    {
176
        $CI = get_instance();
177
        $CI->output->set_status_header($header);
178
    }
179
180
    /**
181
     * Assign the dwootemplate config items to the instance.
182
     */
183
    private function initialize()
184
    {
185
        $CI = get_instance();
186
        $CI->config->load('dwootemplate', true);
187
        $config = $CI->config->item('dwootemplate');
188
        foreach ($config as $key => $val) {
189
            $this->$key = $val;
190
        }
191
    }
192
}
193