aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/DataFieldLinkEntry.class.php
blob: 702907fab5c8f7cd1eb3a4c8de4db517da2f3af3 (plain)
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
<?php
# Lifter002: DONE
# Lifter007: TEST

/**
 * @author  Jan-Hendrik Willms <tleilax+studip@gmail.com>
 * @author  Marcus Lunzenauer <mlunzena@uos.de>
 * @author  Martin Gieseking  <mgieseki@uos.de>
 * @license GPL2 or any later version
 */
class DataFieldLinkEntry extends DataFieldEntry
{
    protected $template = 'link.php';

    /**
     * Returns the display/rendered value of this datafield
     *
     * @param bool $entities Should html entities be encoded (defaults to true)
     * @return String containg the rendered value
     */
    public function getDisplayValue($entities = true)
    {
        if ($entities) {
            return formatLinks($this->getValue());
        }
        return $this->getValue();
    }

    /**
     * Sets the value from a post request
     *
     * @param mixed $submitted_value The value from request
     */
    public function setValueFromSubmit($submitted_value)
    {
        if ($submitted_value === 'http://') {
            $submitted_value = '';
        }
        $this->setValue($submitted_value);
    }

    /**
     * Returns whether the datafield contents are valid
     *
     * @return boolean indicating whether the datafield contents are valid
     */
    public function isValid()
    {
        return parent::isValid()
            && (!$this->getValue()
                || (filter_var($this->getValue(), FILTER_VALIDATE_URL)
                    && preg_match('%^(https?|ftp)://%', $this->getValue())));
    }
}