Support.php 2.77 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 1/28/16
 * Time: 8:05 AM
 */

namespace qfq;

Carsten  Rose's avatar
Carsten Rose committed
11
require_once(__DIR__ . '/Sanitize.php');
12
13
14

class Support {

15
16
17
18
    /**
     * @param array $queryArray Empty or prefilled assoc array with url parameter
     */
    public static function appendTypo3ParameterToArray(array &$queryArray) {
19
20
//        if (isset($_GET['id']))
//            $queryArray['id'] = self::getCurrentPage();
21
22
        if (isset($GLOBALS["TSFE"]->id))
            $queryArray['id'] = $GLOBALS["TSFE"]->id;
23
24
25
26
27
28
29
30
31

        if (isset($_GET['L']))
            $queryArray['L'] = $_GET['L'];

        if (isset($_GET['type']))
            $queryArray['type'] = $_GET['type'];

    }

32
    /**
33
34
     * Builds a urlencoded query string of an assoc array.
     *
35
     * @param array $queryArray
36
     * @return string Querystring (e.g.: id=23&type=99
37
38
39
40
41
42
43
44
45
46
47
48
49
50
     */
    public static function arrayToQueryString(array $queryArray) {
        $items = array();

        foreach ($queryArray as $key => $value) {
            if (is_int($key)) {
                $items[] = urlencode($value);
            } else {
                $items[] = $key . '=' . urlencode($value);
            }
        }

        return implode('&', $items);
    }
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

    /**
     * Extract Tag from $tag (might contain further attributes) and wrap it around $value. If $flagOmitEmpty==true && $value=='': return ''.
     *
     * @param $tag
     * @param $value
     * @param bool|false $omitIfValueEmpty
     * @return string
     */
    public static function wrapTag($tag, $value, $omitIfValueEmpty = false) {
        if ($omitIfValueEmpty && $value === "")
            return '';

        // a) <div class="container-fluid">, b) <label>
        $arr = explode(' ', $tag);

        $tagPlain = (count($arr) === 1) ? substr($arr[0], 1, strlen($arr[0]) - 2) : substr($arr[0], 1);
        $closing = '</' . $tagPlain . '>';

        return $tag . $value . $closing;
    }

    /**
     * Wraps some $inner fragment with a CSS styled $tooltipText . CSS is configured in 'Resources/Public/qfq-jqw.css'.
     * 
     * Based on: http://www.w3schools.com/howto/howto_css_tooltip.asp
     * 
     * @param $inner
     * @param $tooltipText
     * @return string
     */
    public static function appendTooltip($inner, $tooltipText) {

        return $inner . "<img src='" . GFX_INFO . "' title='$tooltipText'>";
    }

87
88
89
90
91
92
    /**
     * If the given $file does not start with a '/', it's relative and the Typo3 Extension path will be added.
     * @param $file
     * @return string
     */
    public static function ifRelativePathPrependExtensionPath($file) {
93

94
95
96
97
98
99
        if ($file[0] !== '/') {
            if (isset($_SERVER['SCRIPT_FILENAME']))
                $file = dirname($_SERVER['SCRIPT_FILENAME']) . '/typo3conf/ext/qfq/' . $file;
        }
        return $file;
    }
100
}