Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/site/app/views/helpers/link.php
blob: 3c17cc5072fccc1fa8027d0777f3cc83572d7d37 (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
<?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);
    }
}
?>