Completed
Push — master ( 23153f...eb881d )
by Angus
03:14
created

asset_helper.php ➔ css_url()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 6
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2
3
/**
4
 * Sekati CodeIgniter Asset Helper
5
 *
6
 * @package        Sekati
7
 * @author         Jason M Horwitz
8
 * @copyright      Copyright (c) 2013, Sekati LLC.
9
 * @license        http://www.opensource.org/licenses/mit-license.php
10
 * @link           http://sekati.com
11
 * @version        v1.2.7
12
 * @filesource
13
 *
14
 * @usage        $autoload['config'] = array('asset');
15
 *                $autoload['helper'] = array('asset');
16
 * @example        <img src="<?=asset_url();?>imgs/photo.jpg" />
17
 * @example        <?=img('photo.jpg')?>
18
 *
19
 * @install        Copy config/asset.php to your CI application/config directory
20
 *                & helpers/asset_helper.php to your application/helpers/ directory.
21
 *                Then add both files as autoloads in application/autoload.php:
22
 *
23
 *                $autoload['config'] = array('asset');
24
 *                $autoload['helper'] = array('asset');
25
 *
26
 *                Autoload CodeIgniter's url_helper in application/config/autoload.php:
27
 *                $autoload['helper'] = array('url');
28
 *
29
 * @notes          Organized assets in the top level of your CodeIgniter 2.x app:
30
 *                    - assets/
31
 *                        -- css/
32
 *                        -- download/
33
 *                        -- img/
34
 *                        -- js/
35
 *                        -- less/
36
 *                        -- swf/
37
 *                        -- upload/
38
 *                        -- xml/
39
 *                    - application/
40
 *                        -- config/asset.php
41
 *                        -- helpers/asset_helper.php
42
 */
43
44
// ------------------------------------------------------------------------
45
// URL HELPERS
46
47
/**
48
 * Get asset URL
49
 *
50
 * @access  public
51
 * @return  string
52
 */
53
54
if (!function_exists('asset_url')) {
55
	function asset_url()
56
	{
57
		//get an instance of CI so we can access our configuration
58
		$CI =& get_instance();
59
60
		//return the full asset path
61
		return $CI->config->slash_item('static_url')/* . $CI->config->item('asset_path')*/;
62
	}
63
}
64
65
/**
66
 * Get css URL
67
 *
68
 * @access  public
69
 * @return  string
70
 */
71 View Code Duplication
if (!function_exists('css_url')) {
72
	function css_url()
73
	{
74
		$CI =& get_instance();
75
76
		return $CI->config->slash_item('static_url') . $CI->config->item('css_path');
77
	}
78
}
79
80
/**
81
 * Get less URL
82
 *
83
 * @access  public
84
 * @return  string
85
 */
86 View Code Duplication
if (!function_exists('less_url')) {
87
	function less_url()
88
	{
89
		$CI =& get_instance();
90
91
		return $CI->config->slash_item('static_url') . $CI->config->item('less_path');
92
	}
93
}
94
95
/**
96
 * Get js URL
97
 *
98
 * @access  public
99
 * @return  string
100
 */
101 View Code Duplication
if (!function_exists('js_url')) {
102
	function js_url()
103
	{
104
		$CI =& get_instance();
105
106
		return $CI->config->slash_item('static_url') . $CI->config->item('js_path');
107
	}
108
}
109
110
/**
111
 * Get image URL
112
 *
113
 * @access  public
114
 * @return  string
115
 */
116 View Code Duplication
if (!function_exists('img_url')) {
117
	function img_url()
118
	{
119
		$CI =& get_instance();
120
121
		return $CI->config->slash_item('static_url') . $CI->config->item('img_path');
122
	}
123
}
124
125
/**
126
 * Get SWF URL
127
 *
128
 * @access  public
129
 * @return  string
130
 */
131 View Code Duplication
if (!function_exists('swf_url')) {
132
	function swf_url()
133
	{
134
		$CI =& get_instance();
135
136
		return $CI->config->slash_item('static_url') . $CI->config->item('swf_path');
137
	}
138
}
139
140
/**
141
 * Get Upload URL
142
 *
143
 * @access  public
144
 * @return  string
145
 */
146 View Code Duplication
if (!function_exists('upload_url')) {
147
	function upload_url()
148
	{
149
		$CI =& get_instance();
150
151
		return base_url() . $CI->config->item('upload_path');
152
	}
153
}
154
155
/**
156
 * Get Download URL
157
 *
158
 * @access  public
159
 * @return  string
160
 */
161 View Code Duplication
if (!function_exists('download_url')) {
162
	function download_url()
163
	{
164
		$CI =& get_instance();
165
166
		return base_url() . $CI->config->item('download_path');
167
	}
168
}
169
170
/**
171
 * Get XML URL
172
 *
173
 * @access  public
174
 * @return  string
175
 */
176 View Code Duplication
if (!function_exists('xml_url')) {
177
	function xml_url()
178
	{
179
		$CI =& get_instance();
180
181
		return base_url() . $CI->config->item('xml_path');
182
	}
183
}
184
185
186
// ------------------------------------------------------------------------
187
// PATH HELPERS
188
189
/**
190
 * Get asset Path
191
 *
192
 * @access  public
193
 * @return  string
194
 */
195
if (!function_exists('asset_path')) {
196
	function asset_path()
197
	{
198
		//get an instance of CI so we can access our configuration
199
		$CI =& get_instance();
200
201
		return FCPATH . $CI->config->item('asset_path');
202
	}
203
}
204
205
/**
206
 * Get CSS Path
207
 *
208
 * @access  public
209
 * @return  string
210
 */
211
if (!function_exists('css_path')) {
212
	function css_path()
213
	{
214
		//get an instance of CI so we can access our configuration
215
		$CI =& get_instance();
216
217
		return FCPATH . $CI->config->item('css_path');
218
	}
219
}
220
221
/**
222
 * Get LESS Path
223
 *
224
 * @access  public
225
 * @return  string
226
 */
227
if (!function_exists('less_path')) {
228
	function less_path()
229
	{
230
		//get an instance of CI so we can access our configuration
231
		$CI =& get_instance();
232
233
		return FCPATH . $CI->config->item('less_path');
234
	}
235
}
236
237
/**
238
 * Get JS Path
239
 *
240
 * @access  public
241
 * @return  string
242
 */
243
if (!function_exists('js_path')) {
244
	function js_path()
245
	{
246
		//get an instance of CI so we can access our configuration
247
		$CI =& get_instance();
248
249
		return FCPATH . $CI->config->item('js_path');
250
	}
251
}
252
253
/**
254
 * Get image Path
255
 *
256
 * @access  public
257
 * @return  string
258
 */
259
if (!function_exists('img_path')) {
260
	function img_path()
261
	{
262
		//get an instance of CI so we can access our configuration
263
		$CI =& get_instance();
264
265
		return FCPATH . $CI->config->item('img_path');
266
	}
267
}
268
269
/**
270
 * Get SWF Path
271
 *
272
 * @access  public
273
 * @return  string
274
 */
275
if (!function_exists('swf_path')) {
276
	function swf_path()
277
	{
278
		$CI =& get_instance();
279
280
		return FCPATH . $CI->config->item('swf_path');
281
	}
282
}
283
284
/**
285
 * Get XML Path
286
 *
287
 * @access  public
288
 * @return  string
289
 */
290
if (!function_exists('xml_path')) {
291
	function xml_path()
292
	{
293
		$CI =& get_instance();
294
295
		return FCPATH . $CI->config->item('xml_path');
296
	}
297
}
298
299
/**
300
 * Get the Absolute Upload Path
301
 *
302
 * @access  public
303
 * @return  string
304
 */
305 View Code Duplication
if (!function_exists('upload_path')) {
306
	function upload_path()
307
	{
308
		$CI =& get_instance();
309
310
		return FCPATH . $CI->config->item('upload_path');
311
	}
312
}
313
314
/**
315
 * Get the Relative (to app root) Upload Path
316
 *
317
 * @access  public
318
 * @return  string
319
 */
320 View Code Duplication
if (!function_exists('upload_path_relative')) {
321
	function upload_path_relative()
322
	{
323
		$CI =& get_instance();
324
325
		return './' . $CI->config->item('upload_path');
326
	}
327
}
328
329
/**
330
 * Get the Absolute Download Path
331
 *
332
 * @access  public
333
 * @return  string
334
 */
335 View Code Duplication
if (!function_exists('download_path')) {
336
	function download_path()
337
	{
338
		$CI =& get_instance();
339
340
		return FCPATH . $CI->config->item('download_path');
341
	}
342
}
343
344
/**
345
 * Get the Relative (to app root) Download Path
346
 *
347
 * @access  public
348
 * @return  string
349
 */
350 View Code Duplication
if (!function_exists('download_path_relative')) {
351
	function download_path_relative()
352
	{
353
		$CI =& get_instance();
354
355
		return './' . $CI->config->item('download_path');
356
	}
357
}
358
359
360
// ------------------------------------------------------------------------
361
// EMBED HELPERS
362
363
/**
364
 * Load CSS
365
 * Creates the <link> tag that links all requested css file
366
 * @access  public
367
 *
368
 * @param   string
369
 *
370
 * @return  string
371
 */
372
if (!function_exists('css')) {
373
	function css($file, $media = 'all')
374
	{
375
		return '<link rel="stylesheet" type="text/css" href="' . css_url() . $file . '" media="' . $media . '">' . "\n";
376
	}
377
}
378
379
/**
380
 * Load LESS
381
 * Creates the <link> tag that links all requested LESS file
382
 * @access  public
383
 *
384
 * @param   string
385
 *
386
 * @return  string
387
 */
388
if (!function_exists('less')) {
389
	function less($file)
390
	{
391
		return '<link rel="stylesheet/less" type="text/css" href="' . less_url() . $file . '">' . "\n";
392
	}
393
}
394
395
/**
396
 * Load JS
397
 * Creates the <script> tag that links all requested js file
398
 * @access  public
399
 *
400
 * @param          string
401
 * @param    array $atts Optional, additional key/value attributes to include in the SCRIPT tag
402
 *
403
 * @return  string
404
 */
405
if (!function_exists('js')) {
406
	function js($file, $atts = array())
407
	{
408
		$element = '<script type="text/javascript" src="' . js_url() . $file . '"';
409
410
		foreach ($atts as $key => $val)
411
			$element .= ' ' . $key . '="' . $val . '"';
412
		$element .= '></script>' . "\n";
413
414
		return $element;
415
	}
416
}
417
418
/**
419
 * Load Image
420
 * Creates an <img> tag with src and optional attributes
421
 * @access  public
422
 *
423
 * @param          string
424
 * @param    array $atts Optional, additional key/value attributes to include in the IMG tag
425
 *
426
 * @return  string
427
 */
428
if (!function_exists('img')) {
429
	function img($file, $atts = array())
430
	{
431
		$url = '<img src="' . img_url() . $file . '"';
432
		foreach ($atts as $key => $val)
433
			$url .= ' ' . $key . '="' . $val . '"';
434
		$url .= " />\n";
435
436
		return $url;
437
	}
438
}
439
440
/**
441
 * Load Minified JQuery CDN w/ failover
442
 * Creates the <script> tag that links all requested js file
443
 * @access  public
444
 *
445
 * @param   string
446
 *
447
 * @return  string
448
 */
449
if (!function_exists('jquery')) {
450
	function jquery($version = '')
451
	{
452
		// Grab Google CDN's jQuery, with a protocol relative URL; fall back to local if offline
453
		$out = '<script src="//ajax.googleapis.com/ajax/libs/jquery/' . $version . '/jquery.min.js"></script>' . "\n";
454
		$out .= '<script>window.jQuery || document.write(\'<script src="' . js_url() . 'jquery-' . $version . '.min.js"><\/script>\')</script>' . "\n";
455
456
		return $out;
457
	}
458
}
459
460
/**
461
 * Load Google Analytics
462
 * Creates the <script> tag that links all requested js file
463
 * @access  public
464
 *
465
 * @param   string
466
 *
467
 * @return  string
468
 */
469
if (!function_exists('google_analytics')) {
470
	function google_analytics($ua = '')
471
	{
472
		// Change UA-XXXXX-X to be your site's ID
473
		$out = "<!-- Google Webmaster Tools & Analytics -->\n";
474
		$out .= '<script type="text/javascript">';
475
		$out .= '	var _gaq = _gaq || [];';
476
		$out .= "    _gaq.push(['_setAccount', '$ua']);";
477
		$out .= "    _gaq.push(['_trackPageview']);";
478
		$out .= '    (function() {';
479
		$out .= "      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;";
480
		$out .= "      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';";
481
		$out .= "      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);";
482
		$out .= "    })();";
483
		$out .= "</script>";
484
485
		return $out;
486
	}
487
}
488
489
/* End of file asset_helper.php */
490