This repository has been archived by the owner on Nov 19, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathclass.tx_t3jquery.php
709 lines (686 loc) · 25.3 KB
/
class.tx_t3jquery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
<?php
/***************************************************************
* Copyright notice
*
* Based on t3mootools from Peter Klein <[email protected]>
* (c) 2007-2010 Juergen Furrer ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
$confArr = tx_t3jquery::getConf();
if ($_POST['data']['jQueryVersion']) {
$t3jqueryversion = $_POST['data']['jQueryVersion'];
if ($_POST['data']['jQueryUiVersion']) {
$t3jqueryversion .= '-' . $_POST['data']['jQueryUiVersion'];
}
if ($_POST['data']['jQueryTOOLSVersion']) {
$t3jqueryversion .= '-' . $_POST['data']['jQueryTOOLSVersion'];
}
if ($_POST['data']['jQueryBootstrapVersion']) {
$t3jqueryversion .= '-' . $_POST['data']['jQueryBootstrapVersion'];
}
} else {
$t3jqueryversion = $confArr['jQueryVersion'];
if ($confArr['jQueryUiVersion']) {
$t3jqueryversion .= '-' . $confArr['jQueryUiVersion'];
}
if ($confArr['jQueryTOOLSVersion']) {
$t3jqueryversion .= '-' . $confArr['jQueryTOOLSVersion'];
}
if ($confArr['jQueryBootstrapVersion']) {
$t3jqueryversion .= '-' . $confArr['jQueryBootstrapVersion'];
}
}
define('T3JQUERYVERSION', $t3jqueryversion);
if (file_exists(PATH_site . tx_t3jquery::getJqPath() . tx_t3jquery::getJqName()) || ($confArr['integrateFromCDN'] && isset($confArr['locationCDN']))) {
// check if dontIntegrateOnUID fit to the actual page
if (tx_t3jquery::isIntegrated()) {
define('T3JQUERY', TRUE);
}
}
/**
* jQuery Javascript Loader functions
*
* You are encouraged to use this library in your own scripts!
*
* USE:
* The class is intended to be used without creating an instance of it.
* So: Don't instantiate - call functions with "tx_t3jquery::" prefixed the function name.
* So use tx_t3jquery::[method-name] to refer to the functions, eg. 'tx_t3jquery::addJqJS()'
*
* Example:
*
* if (t3lib_extMgm::isLoaded('t3jquery')) {
* require_once(t3lib_extMgm::extPath('t3jquery').'class.tx_t3jquery.php');
* }
*
*
* if (T3JQUERY === TRUE) {
* tx_t3jquery::addJqJS();
* } else {
* // Here you add your own version of jQuery library, which is used if the
* // "t3jquery" extension is not installed.
* $GLOBALS['TSFE']->additionalHeaderData[] = ..
* }
*
* @author Juergen Furrer ([email protected])
* @package TYPO3
* @subpackage t3jquery
*/
class tx_t3jquery
{
/**
* Adds the jquery script tag to the page headers first place
* For frontend usage only.
* @return void
*/
function addJqJS()
{
if (tx_t3jquery::getIntFromVersion(TYPO3_version) >= 4003000) {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess']['t3jquery'] = 'EXT:t3jquery/class.tx_t3jquery.php:&tx_t3jquery->addJqJsByHook';
} else {
$confArr = tx_t3jquery::getConf();
// Override the headerdata, THX to S. Delcroix (RVVN - [email protected])
$block = NULL;
if ($confArr['integrateFromCDN'] && isset($confArr['locationCDN'])) {
$params = array();
tx_t3jquery::getCdnScript($params);
if (isset($params['jsLibs'])) {
foreach ($params['jsLibs'] as $key => $param) {
$block .= '<script type="text/javascript" src="'.$param['file'].'"></script>';
}
}
if (isset($params['jsFiles'])) {
foreach ($params['jsFiles'] as $key => $param) {
$block .= '<script type="text/javascript" src="'.$param['file'].'"></script>';
}
}
} else {
$block .= tx_t3jquery::getJqJS();
}
if ($confArr['integrateToFooter']) {
$GLOBALS['TSFE']->additionalFooterData['t3jquery.lib'] = $block;
} else {
$GLOBALS['TSFE']->additionalHeaderData['t3jquery.lib'] = $block;
}
}
}
/**
* Get the used Section from Configuration
* @return boolean
*/
function getSection()
{
$confArr = tx_t3jquery::getConf();
if ($confArr['integrateToFooter']) {
return t3lib_PageRenderer::PART_FOOTER;
} else {
return t3lib_PageRenderer::PART_HEADER;
}
}
/**
* Return all scripts to include for CDN
* @param $params
* @return array
*/
function getCdnScript(&$params=array())
{
$confArr = tx_t3jquery::getConf();
// The dev version does not exist...
if (substr($confArr['jQueryTOOLSVersion'], -3) == 'dev') {
t3lib_div::devLog('jQuery TOOLS Version \''.$confArr['jQueryTOOLSVersion'].'\' not in CDN', 't3jquery', 1);
$confArr['jQueryTOOLSVersion'] = '1.2.5';
}
$temp_config = array();
// CDN version for jQuery (t3jquery 2.0.0)
if (preg_match("/x$/", $confArr['jQueryVersion'])) {
$temp_config = $this->jQueryTOOLSConfig = tx_t3jquery::getJqueryConfiguration();
$confArr['jQueryVersion'] = $temp_config['version']['cdn'];
}
// CDN version for jQueryUI (t3jquery 2.0.0)
if (preg_match("/x$/", $confArr['jQueryUiVersion'])) {
$temp_config = $this->jQueryTOOLSConfig = tx_t3jquery::getJqueryUiConfiguration();
$confArr['jQueryUiVersion'] = $temp_config['version']['cdn'];
}
// CDN version for TOOLS (t3jquery 2.0.0)
if (preg_match("/x$/", $confArr['jQueryTOOLSVersion'])) {
$temp_config = $this->jQueryTOOLSConfig = tx_t3jquery::getJqueryToolsConfiguration();
$confArr['jQueryTOOLSVersion'] = $temp_config['version']['cdn'];
}
// CDN version for Bootstrap (t3jquery 2.0.0)
if (preg_match("/x$/", $confArr['jQueryBootstrapVersion'])) {
$temp_config = $this->jQueryTOOLSConfig = tx_t3jquery::getJqueryBootstrapConfiguration();
$confArr['jQueryBootstrapVersion'] = $temp_config['version']['cdn'];
}
switch ($confArr['locationCDN']) {
case 'jquery' : {
// in jQuery TOOLS jQuery is included
if ($confArr['jQueryTOOLSVersion'] != '') {
$params['jsLibs']['jQueryTOOLS'] = array(
'file' => 'http://cdn.jquerytools.org/'.$confArr['jQueryTOOLSVersion'].'/jquery.tools.min.js',
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
} else {
$params['jsLibs']['jQuery'] = array(
'file' => 'http://code.jquery.com/jquery-'.$confArr['jQueryVersion'].'.min.js',
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
}
if ($confArr['jQueryUiVersion'] != '') {
$jsFile = 'http://code.jquery.com/ui/'.$confArr['jQueryUiVersion'].'/jquery-ui.min.js';
$params['jsFiles'][$jsFile] = array(
'file' => $jsFile,
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
}
if ($confArr['jQueryBootstrapVersion'] != '') {
if (tx_t3jquery::getIntFromVersion($confArr['jQueryBootstrapVersion']) < 3000000) {
if ($confArr['jQueryBootstrapVersion'] == '2.2.0') {
t3lib_div::devLog('jQuery Bootstrap \''.$confArr['jQueryBootstrapVersion'].'\' not available', 't3jquery', 1);
$confArr['jQueryBootstrapVersion'] = '2.2.2';
}
$jsFile = '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/'.$confArr['jQueryBootstrapVersion'].'/js/bootstrap.min.js';
} else {
$jsFile = '//netdna.bootstrapcdn.com/bootstrap/'.$confArr['jQueryBootstrapVersion'].'/js/bootstrap.min.js';
}
$params['jsFiles'][$jsFile] = array(
'file' => $jsFile,
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
}
break;
}
case 'google' : {
// in jQuery TOOLS jQuery is included
if ($confArr['jQueryTOOLSVersion'] != '') {
$params['jsLibs']['jQueryTOOLS'] = array(
'file' => 'http://cdn.jquerytools.org/'.$confArr['jQueryTOOLSVersion'].'/jquery.tools.min.js',
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
} else {
if ($confArr['jQueryVersion'] == '2.0.0b1') {
t3lib_div::devLog('jQuery \''.$confArr['jQueryVersion'].'\' not in Google-CDN', 't3jquery', 1);
$confArr['jQueryVersion'] = '1.9.1';
}
$params['jsLibs']['jQuery'] = array(
'file' => '//ajax.googleapis.com/ajax/libs/jquery/'.$confArr['jQueryVersion'].'/jquery.min.js',
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
}
if ($confArr['jQueryUiVersion'] != '') {
$jsFile = '//ajax.googleapis.com/ajax/libs/jqueryui/'.$confArr['jQueryUiVersion'].'/jquery-ui.min.js';
$params['jsFiles'][$jsFile] = array(
'file' => $jsFile,
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
}
if ($confArr['jQueryBootstrapVersion'] != '') {
if (tx_t3jquery::getIntFromVersion($confArr['jQueryBootstrapVersion']) < 3000000) {
if ($confArr['jQueryBootstrapVersion'] == '2.2.0') {
t3lib_div::devLog('jQuery Bootstrap \''.$confArr['jQueryBootstrapVersion'].'\' not available', 't3jquery', 1);
$confArr['jQueryBootstrapVersion'] = '2.2.2';
}
$jsFile = '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/'.$confArr['jQueryBootstrapVersion'].'/js/bootstrap.min.js';
} else {
$jsFile = '//netdna.bootstrapcdn.com/bootstrap/'.$confArr['jQueryBootstrapVersion'].'/js/bootstrap.min.js';
}
$params['jsFiles'][$jsFile] = array(
'file' => $jsFile,
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
}
break;
}
case 'msn' : {
// in jQuery TOOLS jQuery is included
if ($confArr['jQueryTOOLSVersion'] != '') {
$params['jsLibs']['jQueryTOOLS'] = array(
'file' => 'http://cdn.jquerytools.org/'.$confArr['jQueryTOOLSVersion'].'/jquery.tools.min.js',
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
} else {
if ($confArr['jQueryVersion'] == '2.0.0b1') {
t3lib_div::devLog('jQuery \''.$confArr['jQueryVersion'].'\' not in MSN-CDN', 't3jquery', 1);
$confArr['jQueryVersion'] = '1.9.1';
}
if (tx_t3jquery::getIntFromVersion($confArr['jQueryVersion']) < 1003002) {
t3lib_div::devLog('jQuery \''.$confArr['jQueryVersion'].'\' not in MSN-CDN', 't3jquery', 1);
$confArr['jQueryVersion'] = '1.3.2';
}
// The MSN CDN does not support 1.x.0 version it's only available under 1.x
if (preg_match("/\.0$/", $confArr['jQueryVersion'])) {
$confArr['jQueryVersion'] = substr($confArr['jQueryVersion'], 0, -2);
}
$params['jsLibs']['jQuery'] = array(
'file' => '//ajax.aspnetcdn.com/ajax/jquery/jquery-'.$confArr['jQueryVersion'].'.min.js',
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
}
if ($confArr['jQueryUiVersion'] != '') {
if (tx_t3jquery::getIntFromVersion($confArr['jQueryUiVersion']) < 1008005) {
t3lib_div::devLog('jQuery UI \''.$confArr['jQueryUiVersion'].'\' not in MSN-CDN', 't3jquery', 1);
$confArr['jQueryUiVersion'] = '1.8.5';
}
if (tx_t3jquery::getIntFromVersion($confArr['jQueryUiVersion']) == 1008024) {
t3lib_div::devLog('jQuery UI \''.$confArr['jQueryUiVersion'].'\' not in MSN-CDN', 't3jquery', 1);
$confArr['jQueryUiVersion'] = '1.8.23';
}
$jsFile = '//ajax.aspnetcdn.com/ajax/jquery.ui/'.$confArr['jQueryUiVersion'].'/jquery-ui.min.js';
$params['jsFiles'][$jsFile] = array(
'file' => $jsFile,
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
}
if ($confArr['jQueryBootstrapVersion'] != '') {
if (tx_t3jquery::getIntFromVersion($confArr['jQueryBootstrapVersion']) < 3000000) {
if ($confArr['jQueryBootstrapVersion'] == '2.2.0') {
t3lib_div::devLog('jQuery Bootstrap \''.$confArr['jQueryBootstrapVersion'].'\' not available', 't3jquery', 1);
$confArr['jQueryBootstrapVersion'] = '2.2.2';
}
$jsFile = '//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/'.$confArr['jQueryBootstrapVersion'].'/js/bootstrap.min.js';
} else {
$jsFile = '//netdna.bootstrapcdn.com/bootstrap/'.$confArr['jQueryBootstrapVersion'].'/js/bootstrap.min.js';
}
$params['jsFiles'][$jsFile] = array(
'file' => $jsFile,
'type' => 'text/javascript',
'section' => self::getSection(),
'forceOnTop' => TRUE,
'disableCompression' => FALSE,
'excludeFromConcatenation' => TRUE
);
}
break;
}
default : {
t3lib_div::devLog('Unknown CDN-Provider: \''.$confArr['locationCDN'].'\'', 't3jquery', 3);
break;
}
}
}
/**
* Returns the configuration of jQuery UI
* @return array
*/
function getJqueryConfiguration($version=NULL)
{
if ($version === NULL) {
$confArr = tx_t3jquery::getConf();
$version = $confArr['jQueryVersion'];
}
$configuration = t3lib_div::xml2array(t3lib_div::getUrl(t3lib_div::getFileAbsFileName('EXT:t3jquery/res/jquery/core/'.$version.'/jquery.xml')));
return $configuration;
}
/**
* Returns the configuration of jQuery UI
* @return array
*/
function getJqueryUiConfiguration($version=NULL)
{
if ($version === NULL) {
$confArr = tx_t3jquery::getConf();
$version = $confArr['jQueryUiVersion'];
}
$configuration = t3lib_div::xml2array(t3lib_div::getUrl(t3lib_div::getFileAbsFileName('EXT:t3jquery/res/jquery/ui/'.$version.'/jquery.xml')));
return $configuration;
}
/**
* Returns the configuration of jQuery TOOLS
* @return array
*/
function getJqueryToolsConfiguration($version=NULL)
{
if ($version === NULL) {
$confArr = tx_t3jquery::getConf();
$version = $confArr['jQueryTOOLSVersion'];
}
$configuration = t3lib_div::xml2array(t3lib_div::getUrl(t3lib_div::getFileAbsFileName('EXT:t3jquery/res/jquery/tools/'.$version.'/jquery.xml')));
return $configuration;
}
/**
* Returns the configuration of jQuery Bootstrap
* @return array
*/
function getJqueryBootstrapConfiguration($version=NULL)
{
if ($version === NULL) {
$confArr = tx_t3jquery::getConf();
$version = $confArr['jQueryBootstrapVersion'];
}
$configuration = t3lib_div::xml2array(t3lib_div::getUrl(t3lib_div::getFileAbsFileName('EXT:t3jquery/res/jquery/bootstrap/'.$version.'/jquery.xml')));
return $configuration;
}
/**
* Hook function for adding script
*
* @param array Params for hook
* @return void
*/
function addJqJsByHook($params)
{
$confArr = tx_t3jquery::getConf();
if (tx_t3jquery::isIntegrated()) {
if ($confArr['integrateFromCDN'] && isset($confArr['locationCDN'])) {
tx_t3jquery::getCdnScript($params);
} else {
$params['jsLibs']['jQuery'] = array(
'file' => tx_t3jquery::getJqJS(TRUE),
'type' => 'text/javascript',
'section' => self::getSection(),
'compress' => FALSE,
'forceOnTop' => TRUE,
'allWrap' => ''
);
}
define('T3JQUERY', TRUE);
} else {
t3lib_div::devLog('PID \'' . $GLOBALS['TSFE']->id . '\' in dontIntegrateOnUID', 't3jquery', 1);
define('T3JQUERY', FALSE);
}
}
/**
* Returns TRUE if the lib should be integrated
*
* @return boolean
*/
function isIntegrated()
{
$confArr = tx_t3jquery::getConf();
if (is_object($GLOBALS['TSFE']) and count($GLOBALS['TSFE']->rootLine) > 0) {
foreach ($GLOBALS['TSFE']->rootLine as $page) {
if (in_array($page['uid'], array_values(t3lib_div::trimExplode(',', $confArr['dontIntegrateInRootline'], TRUE)))) {
return FALSE;
}
}
}
return (! $confArr['dontIntegrateOnUID'] || ! is_object($GLOBALS['TSFE']) || ! in_array($GLOBALS['TSFE']->id, array_values(t3lib_div::trimExplode(',', $confArr['dontIntegrateOnUID'], TRUE))));
}
/**
* Returns the path configuration and JS
* @return string
*/
function getJqPath()
{
$confArr = tx_t3jquery::getConf();
if (preg_match("/\/$/", $confArr['configDir'])) {
return $confArr['configDir'];
} else {
return $confArr['configDir'] . '/';
}
}
/**
* Get the jQuery UI script tag.
* For frontend usage only.
* @param boolean If TRUE, only the URL is returned, not a full script tag
* @return string HTML Script tag to load the jQuery JavaScript library
*/
function getJqJS($urlOnly=FALSE)
{
$url = tx_t3jquery::getJqPath() . tx_t3jquery::getJqName();
if (file_exists(PATH_site . $url)) {
// Adding absRefPrefix here, makes sure that jquery gets included correctly
$url = $GLOBALS['TSFE']->absRefPrefix . $url;
if ($urlOnly) {
return $url;
} else {
return '<script type="text/javascript" src="' . $url . '"></script>';
}
} else {
t3lib_div::devLog('\'' . tx_t3jquery::getJqName() . '\' does not exists!', 't3jquery', 3);
}
return FALSE;
}
/**
* Get the jquery script tag.
* For backend usage only.
* @param boolean If TRUE, only the URL is returned, not a full script tag
* @return string HTML Script tag to load the jQuery JavaScript library
*/
function getJqJSBE($urlOnly=FALSE)
{
$file = tx_t3jquery::getJqPath() . tx_t3jquery::getJqName();
if (file_exists(PATH_site . $file)) {
$url = t3lib_div::resolveBackPath($GLOBALS['BACK_PATH'] . '../' . $file);
if ($urlOnly) {
return $url;
} else {
return '<script type="text/javascript" src="' . $url . '"></script>';
}
} else {
t3lib_div::devLog('\''.tx_t3jquery::getJqName().'\' does not exists!', 't3jquery', 3);
}
return FALSE;
}
/**
* Returns the name of the jQuery Lib file
*/
function getJqName()
{
$confArr = tx_t3jquery::getConf();
if ($_POST['data']['jqLibFilename']) {
$confArr['jqLibFilename'] = $_POST['data']['jqLibFilename'];
}
if (! isset($confArr['jqLibFilename'])) {
$confArr['jqLibFilename'] = 'jquery-###VERSION###.js';
}
$nameArr = array(
'###VERSION###' => T3JQUERYVERSION,
);
$filename = str_replace(array_keys($nameArr), array_values($nameArr), $confArr['jqLibFilename']);
return $filename;
}
/**
* Return the integer value of a version string
*
* @param string $versionString
* @return integer
*/
function getIntFromVersion($versionString=NULL)
{
if (class_exists(t3lib_utility_VersionNumber)) {
return t3lib_utility_VersionNumber::convertVersionNumberToInteger($versionString);
} else {
return t3lib_div::int_from_ver($versionString);
}
}
/**
* Get the configuration of t3jquery
* @return array
*/
function getConf()
{
return unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['t3jquery']);
}
/**
* Function to be used from TypoScript to add Javascript after the jquery.js
*
* This is a small wrapper for adding javascripts script after the jQuery Library.
* This is needed in some situations because headerdata added with "page.headerData"
* is placed BEFORE the headerdata which is added using PHP.
*
* Usage:
*
* includeLibs.t3jquery = EXT:t3jquery/class.tx_t3jquery.php
* page.10 = USER
* page.10.userFunc = tx_t3jquery->addJS
* page.10.jsfile = fileadmin/testscript.js
* page.10.jsurl = http://www.example.com/script.js
* page.10.jsdata = alert('Hello World!');
* page.10.forceOnTop = 0
* page.10.compress = 0
* page.10.type = text/javascript
* page.10.allWrap =
* page.10.jsinline = 0
* page.10.tofooter = 1
*
* @param string $content: Content input, ignore (just put blank string)
* @param array $conf: TypoScript configuration of the plugin!
* @return void
*/
function addJS($content, $conf)
{
// set the cObj from TSFE
$cObj = $GLOBALS['TSFE']->cObj;
// Set the tofooter to TRUE if integrateToFooter is set
$confArr = tx_t3jquery::getConf();
if ($confArr['integrateToFooter']) {
$conf['tofooter'] = 'footer';
}
// If the jQuery lib is not added to page yet, add it!
tx_t3jquery::addJqJS();
// where should be the data stored (footer or header) / Fix moveJsFromHeaderToFooter (add all scripts to the footer)
$conf['tofooter'] = ($conf['tofooter'] || $GLOBALS['TSFE']->config['config']['moveJsFromHeaderToFooter'] ? 'footer' : 'header');
$conf['compress'] = ($conf['compress'] || $conf['jsminify']);
$conf['type'] = $conf['type'] ? $conf['type'] : 'text/javascript';
// Append JS file
if ($conf['jsfile'] || $conf['jsfile.']) {
$jsfile = preg_replace('|^'.PATH_site.'|i','', t3lib_div::getFileAbsFileName($cObj->stdWrap($conf['jsfile'], $conf['jsfile.'])));
// Add the Javascript if file exists
if ($jsfile != '' && file_exists(PATH_site . $jsfile)) {
tx_t3jquery::addJsFile($jsfile, $conf);
} else {
t3lib_div::devLog('\''.$jsfile.'\' does not exists!', 't3jquery', 2);
}
}
// add JS URL
if ($conf['jsurl'] || $conf['jsurl.']) {
tx_t3jquery::addJsFile($cObj->stdWrap($conf['jsurl'], $conf['jsurl.']), $conf);
}
// add JS data
if ($conf['jsdata'] || $conf['jsdata.']) {
$jsdata = trim($cObj->stdWrap($conf['jsdata'], $conf['jsdata.']));
if ($jsdata != '') {
tx_t3jquery::addJsInlineCode(md5($jsdata), $jsdata, $conf);
}
}
// add JS ready code
if ($conf['jsready'] || $conf['jsready.']) {
$jsready = trim($cObj->stdWrap($conf['jsready'], $conf['jsready.']));
if ($jsready != '') {
$temp_js = 'jQuery(document).ready(function() {'.$jsready.'});';
tx_t3jquery::addJsInlineCode(md5($jsready), $temp_js, $conf);
}
}
}
/**
* Add JS-File to the HTML
*
* @param string $file
* @param array $conf
* @return void
*/
function addJsFile($file, $conf=array())
{
if (tx_t3jquery::getIntFromVersion(TYPO3_version) >= 4003000) {
$pagerender = $GLOBALS['TSFE']->getPageRenderer();
if ($conf['tofooter'] == 'footer') {
$pagerender->addJsFooterFile($file, $conf['type'], $conf['compress'], $conf['forceOnTop'], $conf['allWrap']);
} else {
$pagerender->addJsFile($file, $conf['type'], $conf['compress'], $conf['forceOnTop'], $conf['allWrap']);
}
} else {
$temp_file = '<script type="text/javascript" src="' . $file . '"></script>';
if ($conf['tofooter'] == 'footer') {
$GLOBALS['TSFE']->additionalFooterData['t3jquery.jsfile.'.$file] = $temp_file;
} else {
$GLOBALS['TSFE']->additionalHeaderData['t3jquery.jsfile.'.$file] = $temp_file;
}
}
}
/**
* Add inline code to the HTML
*
* @param string $name
* @param string $block
* @param array $conf
* @return void
*/
function addJsInlineCode($name, $block, $conf=array())
{
if ($conf['jsinline']) {
$GLOBALS['TSFE']->inlineJS['t3jquery.jsdata.' . $name] = $block;
} elseif (tx_t3jquery::getIntFromVersion(TYPO3_version) >= 4003000) {
$pagerender = $GLOBALS['TSFE']->getPageRenderer();
if ($conf['tofooter'] == 'footer') {
$pagerender->addJsFooterInlineCode($name, $block, $conf['compress'], $conf['forceOnTop']);
} else {
$pagerender->addJsInlineCode($name, $block, $conf['compress'], $conf['forceOnTop']);
}
} else {
if ($conf['compress']) {
$block = t3lib_div::minifyJavaScript($block);
}
if ($conf['tofooter'] == 'footer') {
$GLOBALS['TSFE']->additionalFooterData['t3jquery.jsdata.'.$name] = t3lib_div::wrapJS($block, TRUE);
} else {
$GLOBALS['TSFE']->additionalHeaderData['t3jquery.jsdata.'.$name] = t3lib_div::wrapJS($block, TRUE);
}
}
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3jquery/class.tx_t3jquery.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3jquery/class.tx_t3jquery.php']);
}
?>