Link.php 24.9 KB
Newer Older
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
<?PHP
/***************************************************************
 *  Copyright notice
 *
 *  (c) 2010 Glowbase GmbH <support@glowbase.com>
 *  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.
 *
 *  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!
 ***************************************************************/

namespace qfq;

//use qfq;

require_once(__DIR__ . '/Define.php');
require_once(__DIR__ . '/Utils.php');
31
32
require_once(__DIR__ . '/../store/Store.php');
require_once(__DIR__ . '/../store/Sip.php');
33
require_once(__DIR__ . '/../exceptions/UserReportExtension.php');
34
35
36
37
38
39
40
41
42
43
44
45

/*
 * u:url
 * m:mailto
 * p:page
 * 
 * t:text
 * a:AltText
 * o:ToolTip
 * 
 * r:render   
 * g:target
46
 * c:class  [n|i|e|<class>]
47
48
49
50
51
52
53
54
55
56
57
58
59
60
 * q:question  <text>
 * e:encryption 0|1
 * 
 * E:edit
 * N:new
 * D:delete
 * H:Help
 * I:information
 * M:Magnifier
 * B:bullet
 * P:picture       [file]
 * C:checkbox    [name]
 * R:right 
 * h:hash  
61
 *
62
63
64
65
 * A:    A:[u:p:m]
 * G:    G:[N|..]
 */

66
67
68
69
70
71
72
73
74

const NAME_URL = 'url';
const NAME_MAIL = 'mail';
const NAME_PAGE = 'page';
const NAME_TEXT = 'text';
const NAME_ALT_TEXT = 'altText';
const NAME_TOOL_TIP = 'toolTip';
const NAME_IMAGE = 'image';
const NAME_IMAGE_TITLE = 'imageTitle';
75
76
const NAME_GLYPH = 'glyph';
const NAME_GLYPH_TITLE = 'glyphTitle';
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const NAME_DELETE = 'delete';
const NAME_RENDER = 'render';
const NAME_TARGET = 'target';
const NAME_LINK_CLASS = 'linkClass';
const NAME_LINK_CLASS_DEFAULT = 'linkClassDefault';
const NAME_QUESTION = 'question';
const NAME_ENCRYPTION = 'encryption';
const NAME_HASH = 'hash';
const NAME_URL_PARAM = 'param';
const NAME_RIGHT_PICTURE_POSITION = 'picturePosition';

/**
 * Class Link
 * @package qfq
 */
92
93
class Link {

94
95
96
    //TODO: delete muss noch implementiert werden
    private $delete = '';

Carsten  Rose's avatar
Carsten Rose committed
97
    /**
98
     * @var Sip
Carsten  Rose's avatar
Carsten Rose committed
99
100
101
     */
    private $sip = null;

102
103
104
105
106
    /**
     * @var Store
     */
    private $store = null;

107
108
109
110
111
112
113
114
    // Simulate global variable: will be set much earlier in other functions. Will be shown in error messages.
    private $fr_error;

    /**
     * @var Utils
     */
    private $utils;
    /**
115
     * @var array
116
     */
117
118
119
120
    private $renderControl = array();
    private $linkClassSelector = array("i" => "internal", "e" => "external");
    private $cssLinkClassInternal = '';
    private $cssLinkClassExternal = '';
121

122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
    private $callTable = [
        'u' => 'buildUrl',
        'm' => 'buildMail',
        'p' => 'buildPage',
        'P' => 'buildPicture',
        'B' => 'buildBullet',
        'C' => 'buildCheck',
        'D' => 'buildDelete',
        'E' => 'buildEdit',
        'H' => 'buildHelp',
        'I' => 'buildInfo',
        'N' => 'buildNew',
        'S' => 'buildShow',
    ];

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
    private $tableVarName = [
        'u' => NAME_URL,
        'm' => NAME_MAIL,
        'p' => NAME_PAGE,
        't' => NAME_TEXT,
        'a' => NAME_ALT_TEXT,
        'o' => NAME_TOOL_TIP,
        'P' => NAME_IMAGE,
        'B' => NAME_IMAGE,
        'C' => NAME_IMAGE,
        'D' => NAME_IMAGE,
        'E' => NAME_IMAGE,
        'H' => NAME_IMAGE,
        'I' => NAME_IMAGE,
        'N' => NAME_IMAGE,
        'S' => NAME_IMAGE,
        'r' => NAME_RENDER,
        'g' => NAME_TARGET,
        'c' => NAME_LINK_CLASS,
        'q' => NAME_QUESTION,
        'e' => NAME_ENCRYPTION,
        'h' => NAME_HASH,
        'U' => NAME_URL_PARAM,
        'R' => NAME_RIGHT_PICTURE_POSITION,
    ];

    private $varsDefault = array();

165
166
167
    /**
     * __construct
     *
168
169
     * @param $fr_error
     * @param Sip $sip
170
     * @param bool $phpUnit
171
     */
Carsten  Rose's avatar
Carsten Rose committed
172
    public function __construct($fr_error, Sip $sip, $phpUnit = false) {
173
        $this->fr_error = $fr_error;
Carsten  Rose's avatar
Carsten Rose committed
174
        $this->sip = $sip;
Carsten  Rose's avatar
Carsten Rose committed
175
        $this->store = Store::getInstance('', $phpUnit);
176
177
        $this->cssLinkClassInternal = $this->store->getVar(SYSTEM_CSS_LINK_CLASS_INTERNAL, STORE_SYSTEM);
        $this->cssLinkClassExternal = $this->store->getVar(SYSTEM_CSS_LINK_CLASS_EXTERNAL, STORE_SYSTEM);
178
179
        $this->utils = new Utils();

180
181
182
183
184
185
186
        $this->varsDefault[NAME_QUESTION] = 'Please confirm';
        $this->varsDefault[NAME_PAGE] = $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
        $this->varsDefault[NAME_ENCRYPTION] = '0';
        $this->varsDefault[NAME_RIGHT_PICTURE_POSITION] = 'l';
        $this->varsDefault[NAME_RENDER] = 0;
        $this->varsDefault[NAME_HASH] = 0;

187
188
189
190
191
192
193
194
        /*
         * mode:
         * 0: no output
         * 1: text
         * 2: url
         * 3: <a href=url>url</a>
         * 4: <a href=url>Text</a>
         *
Carsten  Rose's avatar
Carsten Rose committed
195
         *  r=render mode, u=url, t:text and/or image.
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
         *
         *                  [r][u][t] = mode
         */

        $this->renderControl[0][0][0] = 0;
        $this->renderControl[0][0][1] = 0;
        $this->renderControl[0][1][0] = 3;
        $this->renderControl[0][1][1] = 4;

        $this->renderControl[1][0][0] = 0;
        $this->renderControl[1][0][1] = 1;
        $this->renderControl[1][1][0] = 3;
        $this->renderControl[1][1][1] = 4;

        $this->renderControl[2][0][0] = 0;
        $this->renderControl[2][0][1] = 0;
        $this->renderControl[2][1][0] = 0;
        $this->renderControl[2][1][1] = 4;

        $this->renderControl[3][0][0] = 0;
        $this->renderControl[3][0][1] = 1;
        $this->renderControl[3][1][0] = 2;
        $this->renderControl[3][1][1] = 1;

        $this->renderControl[4][0][0] = 0;
        $this->renderControl[4][0][1] = 1;
        $this->renderControl[4][1][0] = 2;
        $this->renderControl[4][1][1] = 2;

        $this->renderControl[5][0][0] = 0;
        $this->renderControl[5][0][1] = 0;
        $this->renderControl[5][1][0] = 0;
        $this->renderControl[5][1][1] = 0;
229

230
    }
231
232
233
234

    /**
     * Build the whole link
     *
235
236
     * @param string $str Qualifier with params. 'report'-syntax. F.e.:  A:u:www.example.com|G:P:home.gif|t:Home"
     * @return string     The complete HTML encoded Link like <a href='http://example.com' class='external'><img src='iconf.gif' title='help text'>Description</a>
237
     * @throws UserReportException
238
     */
239
    public function renderLink($str) {
240
241
        $link = '';

242
        $vars = $this->initVars();
243
244

        // str="u:http://www.example.com|c:i|t:delete"
245
        $param = explode("|", $str);
246
247

        // Parse all parameter, fill variables
248
249
        foreach ($param as $item) {

250
251
252
253
            if ($item == '') {
                continue;
            }

254
            // set class defaults
255
            $this->parseItem($vars, $item);
256
257
        }

258
259
260
261
262
263
264
265
        $necessaryDefaults = [NAME_RENDER, NAME_RIGHT_PICTURE_POSITION, NAME_HASH, NAME_ENCRYPTION];
        foreach ($necessaryDefaults AS $keyName) {
            if ($vars[$keyName] == '') {
                $vars[$keyName] = $this->varsDefault[$keyName];
            }
        }


266
        // if there is no url or mailto definition: {{global.pageId}}
267
268
//        if ($vars[NAME_URL] == '' && $vars[NAME_MAIL] == '') {
//            $vars[NAME_URL] = "?" . $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
269
//        }
270

271
        $this->doCssClass($vars);
272

273
        $htmlUrl = $this->doHtmlUrl($vars);
274
        $htmlImage = $this->doHtmlImageGlyph($vars);
275

276
// Compose Image & Text
277
278
        if ($htmlImage != '') {
            $distance = ' ';
279
            $vars[NAME_TEXT] = ($vars[NAME_RIGHT_PICTURE_POSITION] == "l") ? $htmlImage . $distance . $vars[NAME_TEXT] : $vars[NAME_TEXT] . $distance . $htmlImage;
280
        }
281

282
283
// ToolTip
        $extraSpan = ['', ''];
284
285
        if ($vars[NAME_TOOL_TIP]) {
            $extraSpan[0] = "<span " . $vars[NAME_TOOL_TIP][0] . ">" . $vars[NAME_TOOL_TIP][1];
286
287
288
            $extraSpan[1] = "</span>";
        }

289
// Create 'fake' modes for encrypted 'mailto'
290
        $prefix = "";
291
        if ($vars[NAME_MAIL] != '') {
292
            $prefix = "1";
293
            $vars[NAME_URL] = "dummy";
294
        }
295
// Create 'fake' mode for ajax delete
296
        if ($vars[NAME_DELETE]) {
297
298
            $prefix = "2";
        }
299
300
// Compose URL
// get Render Mode via Array renderControl
301
302
303
        $modeRender = $vars[NAME_RENDER];
        $modeUrl = $vars[NAME_URL] ? 1 : 0;
        $modeText = $vars[NAME_TEXT] ? 1 : 0;
304
305
306
307

        if (isset($this->renderControl[$modeRender][$modeUrl][$modeText])) {
            $mode = $prefix . $this->renderControl[$modeRender][$modeUrl][$modeText];
        } else {
308
309
            throw new UserReportException ("Undefined combination of 'rendering mode' / 'url' / 'text': " .
                $modeRender . ' / ' . $modeUrl . ' / ' . $modeText, ERROR_UNDEFINED_RENDER_CONTROL_COMBINATION);
310
311
        }

312
313
// 0-4 URL, plain email
// 10-14 encrypted email
314
315
316
317
318
        switch ($mode) {
            // 0: No Output
            case '0':
            case '10':
            case '20':
319
            $link = "";
320
321
322
323
                break;

            // 1: 'text'
            case '1':
324
                $link = $extraSpan[0] . $vars[NAME_TEXT] . $extraSpan[1];
325
326
                break;
            case '11':
327
                $link = $extraSpan[0] . $this->encryptMailtoJS($vars, false) . $extraSpan[1];
328
329
330
331
                break;

            // 2: 'url'
            case '2':
332
                $link = $extraSpan[0] . $vars[NAME_URL] . $extraSpan[1];
333
334
                break;
            case '12':
335
                $link = $extraSpan[0] . $this->encryptMailtoJS($vars, false) . $extraSpan[1];
336
337
338
339
                break;

            // 3: <a href=url>url</a>
            case '3':
340
                $link = $htmlUrl . $vars[NAME_URL] . '</a>' . $vars[NAME_TOOL_TIP][1];
341
342
                break;
            case '13':
343
                $vars[NAME_TEXT] = $vars[NAME_MAIL];
344
                $link = $this->encryptMailtoJS($vars, TRUE);
345
346
347
348
                break;

            // 4: <a href=url>Text</a>
            case '4':
349
                $link = $htmlUrl . $vars[NAME_TEXT] . '</a>' . $vars[NAME_TOOL_TIP][1];
350
351
                break;
            case '14':
352
                $link = $this->encryptMailtoJS($vars, TRUE);
353
354
355
356
357
                break;
            case '21':
            case '22':
            case '23':
            case '24':
358
            //TODO: Alter Code, umstellen auf JS Client von RO. Vorlage koennte 'Delete' in Subrecord sein.
359
            $link = "<a href=\"javascript: void(0);\" onClick=\"var del = new FR.Delete({recordId:'',hash:'',forward:'" .
360
                $vars[NAME_PAGE] . "'});\" " . $vars[NAME_LINK_CLASS] . ">" . $vars[NAME_TEXT] . "</a>";
361
362
        }

363
364
365
366
        return $link;

    }

367
368
369
    /**
     * Cleans the standard vars used every time to render a link.
     *
370
     * @return array
371
     */
372
    private function initVars() {
373

374
375
376
377
378
379
380
381
        $vars = array();

        $vars[NAME_MAIL] = '';
        $vars[NAME_URL] = '';
        $vars[NAME_PAGE] = '';

        $vars[NAME_TEXT] = '';
        $vars[NAME_ALT_TEXT] = '';
382
        $vars[NAME_IMAGE] = '';
383
        $vars[NAME_IMAGE_TITLE] = '';
384
385
        $vars[NAME_GLYPH] = '';
        $vars[NAME_GLYPH_TITLE] = '';
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
        $vars[NAME_QUESTION] = '';
        $vars[NAME_TARGET] = '';
        $vars[NAME_TOOL_TIP] = ['', ''];
        $vars[NAME_URL_PARAM] = '';

        $vars[NAME_RENDER] = '';
        $vars[NAME_RIGHT_PICTURE_POSITION] = '';
        $vars[NAME_HASH] = '';
        $vars[NAME_ENCRYPTION] = '';
        $vars[NAME_DELETE] = '';

        $vars[NAME_LINK_CLASS] = ''; // class name
        $vars[NAME_LINK_CLASS_DEFAULT] = ''; // Depending of 'as page' or 'as url'. Only used if class is not explizit set.

        return $vars;
401
    }
402
403
404
405

    /**
     * Parse Item of link string, fill class global variables.
     *
406
407
408
     * @param array $vars
     * @param $item
     * @throws CodeException
409
     * @throws UserReportException
410
     */
411
    private function parseItem(array &$vars, $item) {
412
413

        $arr = explode(":", $item, 2);
414
415
416
        $key = isset($arr[0]) ? $arr[0] : '';
        $value = isset($arr[1]) ? $arr[1] : '';

417
418
419
420
421
422
423
        // Superclass
        if ($key === 'A' || $key === 'G') {
            $this->parseItem($vars, $value);
            return;
        }

        if (!isset($this->tableVarName[$key])) {
424
            throw new UserReportException ("Unknown link qualifier: '$key'", ERROR_UNKNOWN_LINK_QUALIFIER);
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
        $keyName = $this->tableVarName[$key];

        // A few keys do not have necessarily a value: fake the definition by manual assigning the default
        if ($value == '') {
            switch ($key) {
                case 'R':
                    $value = 'r';
                    break;
                case 'h':
                    $value = '1';
                    break;
                case 'p':
                    $value = $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3); // If no pageid|pagealias is defined, take current page
                    break;
                default:
                    break;
            }
        }

        // Take defaults
        if ($value === '' && isset($this->varsDefault[$keyName])) {
            $value = $this->varsDefault[$keyName];
        }

451
452
        //  Check for empty values. Some keys are allowed to be empty.
        if ($value === '' && strpos('uENDHIS', $key) === false) {
453
454
455
456
457
458
459
460
461
462
463
464
465
466
            throw new UserReportException ("Missing value for '$key'", ERROR_MISSING_VALUE);
        }

        // Value already defined?
        if ($vars[$keyName] !== '') {
            throw new UserReportException ("Multiple definitions for key '$key'", ERROR_MULTIPLE_DEFINITION);
        }

        // Store value
        $vars[$keyName] = $value;

        if ($vars[NAME_URL] && $vars[NAME_MAIL]) {
            throw new UserReportException ("Multiple URL / PAGE and MAILTO definition", ERROR_MULTIPLE_URL_PAGE_MAILTO_DEFINITION);
        }
467

468
469
470
471
472
        // Call special function
        if (isset($this->callTable[$key])) {
            $call = $this->callTable[$key];
            $this->$call($vars, $keyName, $value);
        }
473
    }
474
475
476
477

    /**
     * Parse CSS Class Settings
     *
478
     * @param array $vars
479
480
     * @return    void
     */
481
    private function doCssClass(array &$vars) {
482
        $class = '';
483

484
        switch ($vars[NAME_LINK_CLASS]) {
485
            case 'n':
486
                $vars[NAME_LINK_CLASS] = '';
487
488
489
                break;
            case 'i':
            case 'e':
490
            $vars[NAME_LINK_CLASS] = $this->linkClassSelector[$vars[NAME_LINK_CLASS]];
491
492
                break;
            default:
493
                $vars[NAME_LINK_CLASS] = ($vars[NAME_LINK_CLASS] == '') ? $vars[NAME_LINK_CLASS_DEFAULT] : $vars[NAME_LINK_CLASS];
494
                break;
495
        }
496
    }
497
498

    /**
499
500
501
502
     * Builds complete HTML anchor.
     * - <a href="mailto:info@example.com:>info@example.com</a>
     * - <a href="http://example.com:>http://example.com</a>
     * - If $this->modeHash is set, create a
503
     *
504
     * @param array $vars
505
     * @return string
506
     * @throws UserReportException
507
     */
508
    private function doHtmlUrl(array &$vars) {
Carsten  Rose's avatar
Carsten Rose committed
509
        $tags = '';
510
511
        // build URL
        $htmlUrl = "";
512
        $anchorTitle = '';
513

514
        if ($vars[NAME_URL] !== '') {
515

516
            if ($vars[NAME_HASH] === "1") {
517

518
                $vars[NAME_URL] = $this->sip->queryStringToSip($vars[NAME_PAGE] . '&' . $vars[NAME_URL_PARAM]);
519

520
            } else {
521

522
                if ($vars[NAME_URL_PARAM] != '') {
523
                    // Append '&' or '?' depending if there is already a '?'
524
                    $vars[NAME_URL] .= (strpos($vars[NAME_URL], '?') >= 0) ? '&' : '?';
525
                    // Append all additional params.
526
                    $vars[NAME_URL] .= $vars[NAME_URL_PARAM];
527
528
                }
            }
529
530
        }

531
        // If there is no encryption: handle the mailto as an ordinary URL
532
        if ($vars[NAME_MAIL] !== '') {
533

534
535
536
            if ($vars[NAME_ENCRYPTION] === '0') {
                $vars[NAME_URL] = "mailto:" . $vars[NAME_MAIL];
                $vars[NAME_MAIL] = "";
537
            } else {
538
                throw new UserReportException ("Oops, sorry: encrypted mail not implemented ...", ERROR_NOT_IMPLEMENTED);
539
540
541
            }
        }

542
543
544
545
546
547
548
549
        if ($vars[NAME_GLYPH] !== '') {
            $vars[NAME_LINK_CLASS] .= ' btn btn-default ';

            if ($vars[NAME_GLYPH_TITLE] !== '') {
                $anchorTitle = $vars[NAME_GLYPH_TITLE];
            }
        }

550
551
552
        $tags .= Support::doAttribute('href', $vars[NAME_URL]);
        $tags .= Support::doAttribute('class', $vars[NAME_LINK_CLASS]);
        $tags .= Support::doAttribute('target', $vars[NAME_TARGET]);
553
        $tags .= Support::doAttribute('title', $anchorTitle);
554
555
        if ($vars[NAME_QUESTION]) {
            $tags .= Support::doAttribute('onclick', 'confirm(\'' . $vars[NAME_QUESTION] . '\')');
Carsten  Rose's avatar
Carsten Rose committed
556
        }
557

558
        $htmlUrl = '<a ' . $tags . $vars[NAME_TOOL_TIP][0] . '>';
559
560
561

        return ($htmlUrl);
    }
562

563
564
565
566
567
568
569
570
571
572
    //
//<a class="btn btn-default" href="index.php?id=2&s=56fbdd30a0cd2" title='comment'>
//   <span class='glyphicon glyphicon-plus'></span>
//</a>
//
//<a href="index.php?id=2&s=56fb7f7703692" class="internal" >
//  <img src="typo3conf/ext/qfq/Resources/Public/icons/edit.gif" title="Edit" >
//</a>


573
574
575
    /**
     * Create Image HTML Tag
     *
576
577
     * @param array $vars
     * @return string
578
     */
579
    private function doHtmlImageGlyph(array $vars) {
580
        $tags = '';
581
        $html = '';
582
583

        // Build Image
584
        if ($vars[NAME_IMAGE] !== '') {
585
586
587
            $tags .= Support::doAttribute('alt', $vars[NAME_ALT_TEXT]);
            $tags .= Support::doAttribute('src', $vars[NAME_IMAGE]);
            $tags .= Support::doAttribute('title', $vars[NAME_IMAGE_TITLE]);
588
            $html .= '<img ' . $tags . '>';
589
590
        }

591
592
593
594
595
596
        if ($vars[NAME_GLYPH] !== '') {
            $tags = Support::doAttribute('class', 'glyphicon ' . $vars[NAME_GLYPH]);
            $html .= Support::wrapTag('<span ' . $tags . '>', '', false);
        }

        return $html;
597
    }
598
599
600
601
602
603
604
605
606
607
608
609
610
611

    /**
     *  Encrypt the mailto address via JS.
     *  Email address protected against email crawler (as long as they don't interpret JS).
     *
     *    <script language=javascript><!--
     *    var mm1 = name
     *    var mm2 = @domain.
     *    var ... = tld
     *    document.write("<a href=" + "mail" + "to:" + mm1 + mm2 + ... + ">" + name + "</a>")
     *    document.write("<a href=" + "mail" + "to:" + mm1 + mm2 + ... + ">" + @domain. + "</a>")
     *    document.write("<a href=" + "mail" + "to:" + mm1 + mm2 + ... + ">" + tld + "</a>")
     *    //--></script>';
     *
612
613
614
     * @param array $vars
     * @param bool|TRUE $href TRUE: create a '<a>',   false: just encrypt or show the email, no link.
     * @return string
615
     */
616
    private function encryptMailtoJS(array $vars, $href = TRUE) {
617
618

        // Split $mailto
619
        $tmp = $this->splitAndAddDelimter($vars[NAME_MAIL], "@");
620
621
622
623
624
625
626
627
628
629
630
631
        $arr = array_merge($this->splitAndAddDelimter($tmp[0], "."), $this->splitAndAddDelimter($tmp[1], "."));

        $tt = "<script language=javascript><!--" . chr(10);
        $ii = 0;
        if ($href) {
            $dw = 'document.write("<a href=" + "mail" + "to:"';
            foreach ($arr as $value) {
                // Setup JS Variables
                $tt .= 'var mm' . $ii . '= "' . $value . '"' . chr(10);
                // Compose $dw (documentwrite statement)
                $dw .= ' + mm' . $ii++;
            }
632
            $dw .= ' + "' . $vars[NAME_LINK_CLASS] . str_replace('"', '\\"', $vars[NAME_TOOL_TIP][0]) . '>"';
633
634
635
636
637
638
639
            $closeDw = '"</a>")';
        } else {
            $dw = 'document.write(';
            $closeDw = ')';
        }

        // Wrap mailto around text
640
        if ($vars[NAME_MAIL] == $vars[NAME_TEXT]) {
641
642
643
644
645
646
647
            // Text is an email: wrap every single part of mailto.
            $ii = 0;
            foreach ($arr as $value) {
                $tt .= $dw . " + mm" . $ii++ . ' + ' . $closeDw . chr(10);
            }
        } else {
            // Single wrap text
648
            $tt .= $dw . ' + "' . $vars[NAME_TEXT] . '" + ' . $closeDw . chr(10);
649
650
651
        }

        $tt .= '//--></script>';
652
        if ($href) $tt .= $vars[NAME_TOOL_TIP][1];
653
654

        return ($tt);
655
    }
656
657
658
659
660
661
662
663
664
665

    /**
     * Split a string around the $delimiter.
     *
     * Append the delimiter to each part except the last one.
     *
     * @param $mailto
     * @param $delimiter
     * @return array
     */
666
667
    private function splitAndAddDelimter($mailto, $delimiter) {
        //TODO: Ich verstehe die Funktion nicht - funktioniert das hier wirklich?
668
669
670
671
672
673
674
675
676
677
678
679
        $value = '';

        $arr = explode($delimiter, $mailto);            // split string

        foreach ($arr as $key => $value) {
            $arr[$key] = $value . $delimiter;
        }

        if (isset($key))
            $arr[$key] = $value;

        return ($arr);
680
    }
681
682

    /**
683
684
     * Called by $this->callTable
     *
685
686
687
688
689
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildUrl(&$vars, $key, $value) {
690
        $vars[NAME_LINK_CLASS_DEFAULT] = $this->cssLinkClassExternal;
691
692
693
    }

    /**
694
695
     * Called by $this->callTable
     *
696
697
698
699
700
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildMail(&$vars, $key, $value) {
701
        $vars[NAME_LINK_CLASS_DEFAULT] = $this->cssLinkClassExternal;
702
703
704
    }

    /**
705
706
     * Called by $this->callTable
     *
707
708
709
     * @param $vars
     * @param $key
     * @param $value
710
     * @throws UserReportException
711
712
713
     */
    private function buildPage(&$vars, $key, $value) {

714
715
716
        if ($vars[NAME_URL] != '') {
            throw new UserReportException ("Multiple definitions for key 'p'", ERROR_MULTIPLE_DEFINITION);
        }
717

718
719
720
        if (substr($value, 0, 3) !== 'id=') {
            $value = 'id=' . $value;
        }
721

722
723
        $vars[NAME_URL] = "?" . $value;
        $vars[NAME_LINK_CLASS_DEFAULT] = $this->cssLinkClassInternal;
724
725
726
    }

    /**
727
728
     * Called by $this->callTable
     *
729
730
731
732
733
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildPicture(&$vars, $key, $value) {
734
735
        $vars[NAME_ALT_TEXT] = "Grafic: " . $value;
        $vars[NAME_IMAGE_TITLE] = $value;
736
737
738
    }

    /**
739
740
     * Called by $this->callTable
     *
741
742
743
744
745
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildBullet(&$vars, $key, $value) {
746
747
        $vars[NAME_IMAGE] = PATH_ICONS . "bullet-" . $value . '.gif';
        $vars[NAME_IMAGE_TITLE] = $value;
748
749
750
    }

    /**
751
752
     * Called by $this->callTable
     *
753
754
755
756
757
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildCheck(&$vars, $key, $value) {
758
759
        $vars[NAME_IMAGE] = PATH_ICONS . "checked-" . $value . '.gif';
        $vars[NAME_IMAGE_TITLE] = $value;
760
761
762
    }

    /**
763
764
     * Called by $this->callTable
     *
765
766
767
768
769
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildDelete(&$vars, $key, $value) {
770
771
//        $vars[NAME_IMAGE] = PATH_ICONS . 'delete.gif';
//        $vars[NAME_IMAGE_TITLE] = "Delete";
772
        $vars[NAME_DELETE] = true;
773
774
775
776

        $vars[NAME_GLYPH] = GLYPH_ICON_DELETE;
        $vars[NAME_GLYPH_TITLE] = "Delete";

777
778
779
780
781
        // Include Extjs library
        $this->utils->loadJSlib($this->fr_error);
    }

    /**
782
783
     * Called by $this->callTable
     *
784
785
786
787
788
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildEdit(&$vars, $key, $value) {
789
790
791
792
//        $vars[NAME_IMAGE] = PATH_ICONS . 'edit.gif';
//        $vars[NAME_IMAGE_TITLE] = "Edit";
        $vars[NAME_GLYPH] = GLYPH_ICON_EDIT;
        $vars[NAME_GLYPH_TITLE] = "Edit";
793
794
    }

795

796
    /**
797
798
     * Called by $this->callTable
     *
799
800
801
802
803
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildHelp(&$vars, $key, $value) {
804
805
806
807
//        $vars[NAME_IMAGE] = PATH_ICONS . 'help.gif';
//        $vars[NAME_IMAGE_TITLE] = "Help";
        $vars[NAME_GLYPH] = GLYPH_ICON_HELP;
        $vars[NAME_GLYPH_TITLE] = "Help";
808
809
810
    }

    /**
811
812
     * Called by $this->callTable
     *
813
814
815
816
817
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildInfo(&$vars, $key, $value) {
818
819
820
821
822
823
//        $vars[NAME_IMAGE] = PATH_ICONS . 'info.gif';
//        $vars[NAME_IMAGE_TITLE] = "Information";

        $vars[NAME_GLYPH] = GLYPH_ICON_INFO;
        $vars[NAME_GLYPH_TITLE] = "Information";

824
825
826
    }

    /**
827
828
     * Called by $this->callTable
     *
829
830
831
832
833
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildNew(&$vars, $key, $value) {
834
835
836
837
838
839
//        $vars[NAME_IMAGE] = PATH_ICONS . 'new.gif';
//        $vars[NAME_IMAGE_TITLE] = "New";

        $vars[NAME_GLYPH] = GLYPH_ICON_NEW;
        $vars[NAME_GLYPH_TITLE] = "New";

840
841
842
    }

    /**
843
844
     * Called by $this->callTable
     *
845
846
847
848
849
     * @param $vars
     * @param $key
     * @param $value
     */
    private function buildShow(&$vars, $key, $value) {
850
851
852
853
854
855
//        $vars[NAME_IMAGE] = PATH_ICONS . 'show.gif';
//        $vars[NAME_IMAGE_TITLE] = "Details";

        $vars[NAME_GLYPH] = GLYPH_ICON_SHOW;
        $vars[NAME_GLYPH_TITLE] = "Details";

856
    }
857
}