예제 #1
0
 /**
  * Creates an HTML link.
  *
  * If $url starts with "http://" this is treated as an external link. Else,
  * it is treated as a path to controller/action and parsed with the
  * HtmlHelper::url() method.
  *
  * If the $url is empty, $title is used instead.
  *
  * @param  mixed  $title The content to be wrapped by <a> tags or a node $item.
  * @param  mixed   $url Cake-relative URL or array of URL parameters, or external URL (starts with http://)
  * @param  array   $options Array of HTML attributes.
  * @param  string  $confirmMessage JavaScript confirmation message.
  * @param  boolean $escapeTitle	Whether or not $title should be HTML escaped.
  * @return string	An <a /> element.
  */
 function link($title, $url = null, $options = array())
 {
     if (Sl::isHere($url)) {
         $options = $this->addClass($options, 'sl-active');
     }
     if ($url !== null) {
         $url = $url !== false ? empty($options['webroot']) ? $this->url($url) : $this->webroot($url) : '';
     } else {
         $url = $this->url($title);
         $title = $url;
     }
     unset($options['webroot']);
     if (!empty($options['escape'])) {
         $title = h($title);
     }
     unset($options['escape']);
     if (!empty($options['confirm'])) {
         $confirmMessage = r("'", "\\'", r('"', '\\"', $options['confirm']));
         $url2 = r("'", "\\'", r('"', '\\"', $url));
         $options['onclick'] = "if (window.Ext) { Ext.Msg.confirm('', '{$confirmMessage}', function(btn){ if (btn == 'yes') Sl.go('{$url2}'); }); return false; } return confirm('{$confirmMessage}');";
     }
     unset($options['confirm']);
     return $url ? sprintf('<a href="%s"%s>%s</a>', $url, $this->_parseAttributes($options), $title) : sprintf('<a%s>%s</a>', $this->_parseAttributes($options), $title);
 }