Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/views/helpers/link.php
blob: e42d1d63a78b677e0d279c23246b9f676f17d762 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
/*
* This helper builds links to all parts of the site that aren't covered
* by function-specific components/helpers
*/
class LinkHelper extends Helper
{
    var $helpers = array('Html');

    function addonDisplay($name, $addon="", $attributes="") {
        $link = $this->Html->link($name, "/addon/$addon", $attributes);
        return $this->output($link);
    }
    
    function addonBrowse($tag="", $attributes="", $name="") {
        if (empty($name)) {
            $link = $this->Html->link($tag, "/browse/" . $tag, $attributes);
        }
        else {
            $link = $this->Html->link($name, "/browse/" . $tag, $attributes);
        }
            
        return $this->output($link);
    }
    
    /**
     * Make an email link that displays the real email by javascript
     * including noscript fallback for spam protection.
     * Relies on emailLink from addons.js.
     * 
     * @param string Email address to link to
     * @param string js_id (Unique) Javascript ID for the email field
     * @param sting spanclass CSS class to give to email string
     */
    function email($email = '', $js_id = '', $spanclass = 'email') {
        if (!$email) return false;
        if (!$js_id) $js_id = md5($email); // ugly but unique.

        $noscriptemail = str_replace(array('@', '.'), array(' at ', ' dot '), $email);

        // unsanitize and re-encode email so html entities are not shown in plain text by javascript code
        $email = addslashes($this->Html->unsanitize($email));
        $emailparts = explode('@', $email, 2);
        
        $o = '<span id="'.$js_id.'" class="'.$spanclass.'">'.$noscriptemail."</span>\n"
        . "<script language=\"JavaScript\">"
        . "emailLink('{$js_id}', '{$emailparts[0]}', '{$emailparts[1]}');"
        . "</script>\n";

        return $this->output($o);
    }

    /**
     * Create a link to a collection.
     * @param array $coll Collection (from collection model)
     * @param string $app (optional) application to link to, defaults to current app
     */
    function collection($coll, $app = null) {
        if (empty($coll)) return false;

        $url = '/collection/';
        if (!empty($coll['Collection']['nickname']))
            $url .= $coll['Collection']['nickname'];
        else
            $url .= $coll['Collection']['uuid'];

        if (!empty($app)) {
            return $this->Html->linkNoLocaleNoApp($coll['Translation']['name']['string'],
                sprintf('/%s/%s%s', LANG, $app, $url));
        } else {
            return $this->Html->link($coll['Translation']['name']['string'], $url);
        }
    }
}
?>