Link.php 22.4 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
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

/*
 * u:url
 * m:mailto
 * p:page
 * 
 * t:text
 * a:AltText
 * o:ToolTip
 * 
 * r:render   
 * g:target
 * c:class  [n|i|e]:<class>
 * 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  
60
 *
61
62
63
64
65
66
 * A:    A:[u:p:m]
 * G:    G:[N|..]
 */

class Link {

67
    private $mailto = "", $url = "", $image = "", $text = "", $altText = "", $imageTitle = "", $question = "", $target = "", $additionalUrlParams = "";
68
69
    private $toolTip = array();
    private $modeRender = 0, $picturePosition = "l", $modeHash = false, $encryption = 1;
70
71
    private $linkClass = "", $defaultLinkClass = "";
    private $linkClassSelector = array("i" => "internal", "e" => "external");
72
    private $renderControl, $link = "";
73

74
75
76
    //TODO: delete muss noch implementiert werden
    private $delete = '';

Carsten  Rose's avatar
Carsten Rose committed
77
    /**
78
     * @var Sip
Carsten  Rose's avatar
Carsten Rose committed
79
80
81
     */
    private $sip = null;

82
83
84
85
86
    /**
     * @var Store
     */
    private $store = null;

87
88
89
90
91
92
93
94
95
96
97
98
    // Simulate global variable: will be set much earlier in other functions. Will be shown in error messages.
    private $fr_error;

    /**
     * @var Utils
     */
    private $utils;
    /**
     * @var string
     */
    private $pageAlias = '';

99
100
101
    private $cssLinkClassInternal = '';
    private $cssLinkClassExternal = '';

102
103
104
    /**
     * __construct
     *
105
106
     * @param $fr_error
     * @param Sip $sip
107
     */
108
    public function __construct($fr_error, Sip $sip) {
109
        $this->fr_error = $fr_error;
Carsten  Rose's avatar
Carsten Rose committed
110
        $this->sip = $sip;
111
        $this->store = Store::getInstance();
112
        $this->toolTip = ['', ''];
113
114
        $this->cssLinkClassInternal = $this->store->getVar(SYSTEM_CSS_LINK_CLASS_INTERNAL, STORE_SYSTEM);
        $this->cssLinkClassExternal = $this->store->getVar(SYSTEM_CSS_LINK_CLASS_EXTERNAL, STORE_SYSTEM);
115
116
        $this->initRenderControl();

117
    }
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

    /**
     * Initializes RenderControl Array
     *
     * @param    void
     * @return    void
     */
    private function initRenderControl() {

        $this->utils = new Utils();

        /*
         * 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
137
         *  r=render mode, u=url, t:text and/or image.
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
         *
         *                  [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;
171
    }
172
173
174
175
176
177
178
179

    /**
     * Build the whole link
     *
     * @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 Link
     */
180
    public function renderLink($str) {
181
182

        // str="u:http://www.example.com|c:i|t:delete"
183
        $param = explode("|", $str);
184
185

        // Parse all parameter, fill variables
186
        foreach ($param as $item) {
187
            $arr = explode(":", $item, 2);
188
189

            // set class defaults
190
191
192
            $this->parseItem($arr[0], $arr[1]);
        }

193
        // if there is no url or mailto definition: {{global.pageId}}
194
195
        if (!$this->url && !$this->mailto)
            $this->url = "?" . $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3);
196
197
198

        $this->doCssClass();

199
200
//        $htmlUrl = $this->doUrl($count, $hash);
        $htmlUrl = $this->doUrl();
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
        $htmlImage = $this->doImage();

        // Compose Image & Text
        $distance = ' ';
        $this->text = ($this->picturePosition == "l") ? $htmlImage . $distance . $this->text : $this->text . $distance . $htmlImage;

        // ToolTip
        $extraSpan = array();
        if ($this->toolTip) {
            $extraSpan[0] = "<span " . $this->toolTip[0] . ">" . $this->toolTip[1];
            $extraSpan[1] = "</span>";
        }

        // Create 'fake' modes for encrypted 'mailto'
        $prefix = "";
        if ($this->mailto) {
            $prefix = "1";
            $this->url = "dummy";
        }
        // Create 'fake' mode for ajax delete
        if ($this->delete) {
            $prefix = "2";
        }
        // Compose URL
        // get Render Mode via Array renderControl
        $mode = $prefix . $this->renderControl[$this->modeRender][$this->url ? 1 : 0][$this->text ? 1 : 0];
        // 0-4 URL, plain email
        // 10-14 encrypted email
        switch ($mode) {
            // 0: No Output
            case '0':
            case '10':
            case '20':
                $this->link = "";
                break;

            // 1: 'text'
            case '1':
                $this->link = $extraSpan[0] . $this->text . $extraSpan[1];
                break;
            case '11':
242
                $this->link = $extraSpan[0] . $this->encryptMailtoJS($this->mailto, $this->text, $this->linkClass, false) . $extraSpan[1];
243
244
245
246
247
248
249
                break;

            // 2: 'url'
            case '2':
                $this->link = $extraSpan[0] . $this->url . $extraSpan[1];
                break;
            case '12':
250
                $this->link = $extraSpan[0] . $this->encryptMailtoJS($this->mailto, $this->text, $this->linkClass, false) . $extraSpan[1];
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
                break;

            // 3: <a href=url>url</a>
            case '3':
                $this->link = $htmlUrl . $this->url . '</a>' . $this->toolTip[1];
                break;
            case '13':
                $this->link = $this->encryptMailtoJS($this->mailto, $this->mailto, $this->linkClass, TRUE);
                break;

            // 4: <a href=url>Text</a>
            case '4':
                $this->link = $htmlUrl . $this->text . '</a>' . $this->toolTip[1];
                break;
            case '14':
                $this->link = $this->encryptMailtoJS($this->mailto, $this->text, $this->linkClass, TRUE);
                break;
            case '21':
            case '22':
            case '23':
            case '24':
272
273
            //TODO: Alter Code, umstellen auf JS Client von RO. Vorlage koennte 'Delete' in Subrecord sein.
            $this->link = "<a href=\"javascript: void(0);\" onClick=\"var del = new FR.Delete({recordId:'',hash:'',forward:'" . $this->pageAlias . "'});\" " . $this->linkClass . ">" . $this->text . "</a>";
274
275
276
277
        }

        return $this->link;

278
    }
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293

    /**
     * Parse Item of link string, fill class global variables.
     *
     * @param    string $key :    F.e.: 'u'
     * @param    string $value :  F.e.: 'http://www.nzz.ch'
     * @throws SyntaxReportException
     */
    private function parseItem($key, $value) {

        switch ($key) {
            // URL
            case "u":
                if ($this->url || $this->mailto) throw new SyntaxReportException ("Multiple URL, PAGE or MAILTO defined : '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->url = $value;
294
                $this->defaultLinkClass = $this->cssLinkClassExternal;
295
296
297
298
                break;
            case "m":
                if ($this->url || $this->mailto) throw new SyntaxReportException ("Multiple URL, PAGE or MAILTO defined : '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->mailto = $value;
299
                $this->defaultLinkClass = $this->cssLinkClassExternal;
300
301
302
                break;
            case "p":
                if ($this->url || $this->mailto) throw new SyntaxReportException ("Multiple URL, PAGE or MAILTO defined : '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
303
                $this->pageAlias = $value ? $value : $this->store->getVar(TYPO3_PAGE_ID, STORE_TYPO3); // If no pageid|pagealias is defined, take current page
Carsten  Rose's avatar
Carsten Rose committed
304
//                $this->url = "?" . $this->pageAlias;
305
                $this->defaultLinkClass = $this->cssLinkClassInternal;
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
                break;
            // Text
            case "t":
                $this->text = $value;
                break;
            case "a":
                $this->altText = $value;
                break;
            case "o":
                $this->toolTip = $this->utils->createToolTip($value);
                break;

            // Image
            case "P":
                if ($this->image) throw new SyntaxReportException ("Multiple images defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->image = $value;
                $this->AltText = "Grafic: " . $value;
                $this->imageTitle = $value;
                break;
            case "B":
                if ($this->image) throw new SyntaxReportException ("Multiple images defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->image = PATH_ICONS . "bullet-" . ($value ? $value : "green") . '.gif';
                $this->defaultAltText = "Bullet: " . $value;
                $this->imageTitle = $value;
                break;
            case "C":
                if ($this->image) throw new SyntaxReportException ("Multiple images defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->image = PATH_ICONS . "checked-" . ($value ? $value : "green") . '.gif';
                $this->defaultAltText = "Checked: " . $value;
                $this->imageTitle = $value;
                break;
            case "D":
                if ($this->image) throw new SyntaxReportException ("Multiple images defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->image = PATH_ICONS . 'delete.gif';
                $this->defaultAltText = "Delete";
                $this->imageTitle = "Delete";
                $this->delete = true;
                // Include Extjs library
                $this->utils->loadJSlib($this->fr_error);
                break;
            case "E":
                if ($this->image) throw new SyntaxReportException ("Multiple images defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->image = PATH_ICONS . 'edit.gif';
                $this->defaultAltText = "Edit";
                $this->imageTitle = "Edit";
                break;
            case "H":
                if ($this->image) throw new SyntaxReportException ("Multiple images defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->image = PATH_ICONS . 'help.gif';
                $this->defaultAltText = "Help";
                $this->imageTitle = "Help";
                break;
            case "I":
                if ($this->image) throw new SyntaxReportException ("Multiple images defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->image = PATH_ICONS . 'info.gif';
                $this->defaultAltText = "Information";
                $this->imageTitle = "Information";
                break;
            case "N":
                if ($this->image) throw new SyntaxReportException ("Multiple images defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->image = PATH_ICONS . 'new.gif';
                $this->defaultAltText = "New";
                $this->imageTitle = "New";
                break;
            case "S":
                if ($this->image) throw new SyntaxReportException ("Multiple images defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->image = PATH_ICONS . 'show.gif';
                $this->defaultAltText = "Details";
                $this->imageTitle = "Details";
                break;

            // Misc
            case "r":
                if ($this->modeRender) throw new SyntaxReportException ("Multiple render modes defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->modeRender = $value;
                break;
            case "g":
                if ($this->target) throw new SyntaxReportException ("Multiple 'target' defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->target = $value;
                break;
            case "c":
                if ($this->linkClass) throw new SyntaxReportException ("Multiple linkClass defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->linkClass = $value;
                break;
            case "q":
                if ($this->question) throw new SyntaxReportException ("Multiple question defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->question = $value ? $value : "Please confirm";
                break;
            case "e":
                if ($this->encryption != 1) throw new SyntaxReportException ("Multiple encryption defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->encryption = $value ? $value : "1";
                break;
            case "h":
                if ($this->modeHash) throw new SyntaxReportException ("Multiple modeHash defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->modeHash = TRUE;
                break;
            case "U":    //if($this->additionalUrlParams) throw new syntaxException ( "Multiple additionalUrlParams defined: '$key'","",__FILE__,__LINE__, "Column: " . $fthis->r_error["columnIndex"], $this->fr_error);
403
                $this->additionalUrlParams = $value;
404
405
406
407
408
409
410
411
412
413
                break;
            case "R":
                if ($this->picturePosition != "l") throw new SyntaxReportException ("Multiple picturePosition defined: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
                $this->picturePosition = "r";
                break;

            // A,G
            case "G":
            case "A":
                $arr = explode(":", $value, 2);
414
            // set class defaults
415
416
417
418
419
420
421
422
423
                $this->parseItem($arr[0], $arr[1]);
                break;
            case "" :
                break;
            default:
                throw new SyntaxReportException ("Unknown link qualifier: '$key'", "", __FILE__, __LINE__, "Column: " . $this->fr_error["columnIndex"], $this->fr_error);

        }

424
    }
425
426
427
428
429
430
431
432
433

    /**
     * Parse CSS Class Settings
     *
     * @param    void
     *
     * @return    void
     */
    private function doCssClass() {
434
        $class = '';
435

436
437
438
439
440
441
442
443
444
445
446
        switch ($this->linkClass) {
            case 'n':
                $class = '';
                break;
            case 'i':
            case 'e':
                $class = $this->linkClassSelector[$this->linkClass];
                break;
            default:
                $class = ($this->linkClass == '') ? $this->defaultLinkClass : $this->linkClass;
                break;
447
        }
448
449

        $this->linkClass = ($class == '') ? '' : ' class="' . $this->linkClass . '"';
450
    }
451
452

    /**
453
454
455
456
     * 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
457
458
     *
     * @return string
459
     * @throws SyntaxReportException
460
     */
461
    private function doUrl() {
462
463
464
465
466
467
468
        // build URL
        $htmlUrl = "";

        if ($this->url) {

            if ($this->modeHash) {

Carsten  Rose's avatar
Carsten Rose committed
469
                $this->url = $this->sip->queryStringToSip('id=' . $this->pageAlias . '&' . $this->additionalUrlParams);
470

471
            } else {
472

473
474
475
476
477
478
479
                if ($this->additionalUrlParams) {
                    // Append '&' or '?' depending if there is already a '?'
                    $this->url .= (strpos($this->url, '?') >= 0) ? '&' : '?';
                    // Append all additional params.
                    $this->url .= $this->additionalUrlParams;
                }
            }
480
481
        }

482
483
        // If there is no encryption: handle the mailto as an ordinary URL
        if ($this->mailto) {
484

485
486
487
488
489
490
            if ($this->encryption == 0) {
                $this->url = "mailto:" . $this->mailto;
                $this->mailto = "";
            } else {
                throw new SyntaxReportException ("Oops, sorry: encrypted mail not implemented ...", "", __FILE__, __LINE__,
                    "Column: " . $this->fr_error["columnIndex"], $this->fr_error);
491
492
493
            }
        }

494
495
        // target
        if ($this->target) $this->target = ' target="' . $this->target . '"';
496

497
498
499
500
501
502
503
        // question
        if ($this->question) $this->question = ' onclick="return confirm(\'' . $this->question . '\')"';

        $htmlUrl = '<a href="' . $this->url . '"' . $this->linkClass . $this->target . $this->question . $this->toolTip[0] . '>';

        return ($htmlUrl);
    }
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526

    /**
     * Create Image HTML Tag
     * @return string $htmlImage
     * @internal param $void
     *
     */
    private function doImage() {
        $htmlImage = "";

        // Build Image
        if ($this->image) {

            if ($this->altText) $this->altText = ' alttext="' . $this->altText . '"';

            if ($this->image) $this->image = ' src="' . $this->image . '"';

            if ($this->imageTitle) $this->imageTitle = ' title="' . $this->imageTitle . '"';

            $htmlImage = '<img' . $this->image . $this->altText . $this->imageTitle . ' />';
        }

        return ($htmlImage);
527
    }
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544

    /**
     *  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>';
     *
     * @param    string $mailto Email address to encrypt.
     * @param    string $text Text to wrap <a href..>, </a> around.
     * @param    string $class Optional class definition
545
     * @param    bool $href TRUE: create a '<a>',   false: just encrypt or show the email, no link.
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
     *
     * @return    string The complete Link
     */
    private function encryptMailtoJS($mailto, $text, $class = "", $href = TRUE) {

        // Prepare CSS Definition
        if ($class) $class = str_replace('"', "'", $class);

        // Split $mailto
        $tmp = $this->splitAndAddDelimter($mailto, "@");
        $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++;
            }
            $dw .= ' + "' . $class . str_replace('"', '\\"', $this->toolTip[0]) . '>"';
            $closeDw = '"</a>")';
        } else {
            $dw = 'document.write(';
            $closeDw = ')';
        }

        // Wrap mailto around text
        if ($mailto == $text) {
            // 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
            $tt .= $dw . ' + "' . $text . '" + ' . $closeDw . chr(10);
        }

        $tt .= '//--></script>';
        if ($href) $tt .= $this->toolTip[1];

        return ($tt);
591
    }
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614

    /**
     * Split a string around the $delimiter.
     *
     * Append the delimiter to each part except the last one.
     *
     * @param $mailto
     * @param $delimiter
     * @return array
     */
    private function splitAndAddDelimter($mailto, $delimiter) {
        $value = '';

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

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

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

        return ($arr);
615
    }
616
}