'auto',
'language' => 'de_DE',
'category' => 'text',
'button' => 'default', # none or compact
'tags' => array(),
//'hidden' => '',
//'description' => '',
);
$options += $defaults;
$mode = $options['mode'];
unset($options['mode']);
if (is_array($options['tags'])) {
$options['tags'] = implode(',', $options['tags']);
}
$rev = array();
foreach ($options as $key => $option) {
$rev[] = $key . ':' . $option;
}
$linkOptions = array(
'title' => env('HTTP_HOST'),
'class' => 'FlattrButton',
'style' => 'display:none;',
'rel' => 'flattr;' . implode(';', $rev)
);
$linkOptions = $attr + $linkOptions;
$js = "(function() {
var s = document.createElement('script'), t = document.getElementsByTagName('script')[0];
s.type = 'text/javascript';
s.async = true;
s.src = '" . static::API_URL . "js/0.6/load.js?mode=" . $mode . "';
t.parentNode.insertBefore(s, t);
})();";
$code = $this->Html->link('', $this->Html->url($url, true), $linkOptions);
//&uid=gargamel&language=sv_SE&category=text
// compact:
// static:
$code .= $this->Html->scriptBlock($js, array('inline' => true));
return $code;
}
//TODO: http://api.flattr.com/odapi/categories/json - parse
/**
* @deprecated!!!
* @param mixed $uid
* @param array $options:
* - tle, cat, lng, dsc, url, btn, tags, hidden (optional)
* @return string html with js script tag
*/
public function badge($uid = null, $options = array()) {
if (!$uid) {
$uid = Configure::read('Flattr.uid');
}
if (!isset($options['tle'])) {
$options['tle'] = __d('tools', 'Donate');
}
$vars = '';
$vars .= "var flattr_uid = '" . h($uid) . "';\r\n";
$vars .= "var flattr_tle = '" . $options['tle'] . "';\r\n";
if (!isset($options['dsc'])) {
$options['dsc'] = '';
}
$vars .= "var flattr_dsc = '" . $options['dsc'] . "';\r\n";
if (!isset($options['cat'])) {
$options['cat'] = 'text';
}
$vars .= "var flattr_cat = '" . $options['cat'] . "';\r\n";
if (!isset($options['lng'])) {
$options['lng'] = 'en_GB';
}
$vars .= "var flattr_lng = '" . $options['lng'] . "';\r\n";
if (isset($options['tags']) && count($options['tags']) > 0) {
//array_walk($options['tags'], 'Sanitize::paranoid');
$vars .= "var flattr_tag = '" . implode(', ', $options['tags']) . "';\r\n";
}
if (isset($options['url']) && ((version_compare(phpversion(), '5.2.0', '>=') && function_exists('filter_var')) ? filter_var($options['url'],
FILTER_VALIDATE_URL) : true)) {
$vars .= "var flattr_url = '" . $options['url'] . "';\r\n";
}
if (isset($options['btn']) && $options['btn'] === 'compact') {
$vars .= "var flattr_btn = 'compact';\r\n";
}
$code = $this->Html->scriptBlock($vars, array('inline' => true));
$code .= $this->Html->script(static::API_URL . 'button/load.js', array('inline' => true));
return $code;
}
}