| 1 |
<?php |
| 2 |
/** |
| 3 |
* The template used to display a simple donation button/link. |
| 4 |
* |
| 5 |
* Override this template by copying it to yourtheme/charitable/shortcodes/donate-button.php |
| 6 |
* |
| 7 |
* @author David Bisset |
| 8 |
* @package Charitable/Templates/Shortcodes |
| 9 |
* @since 1.8.2 |
| 10 |
* @version 1.8.13 |
| 11 |
*/ |
| 12 |
|
| 13 |
// Exit if accessed directly. |
| 14 |
if ( ! defined( 'ABSPATH' ) ) { |
| 15 |
exit; |
| 16 |
} |
| 17 |
|
| 18 |
/* |
| 19 |
* The destination URL is carried in a data attribute and read back by the click |
| 20 |
* handler rather than being interpolated into the inline JavaScript. |
| 21 |
* |
| 22 |
* esc_url() is a URL escaper, not a JavaScript string escaper. It encodes a literal |
| 23 |
* apostrophe as `'` and leaves named entities such as `'` intact -- correct |
| 24 |
* inside href="", but both are decoded back into a real apostrophe by the HTML parser |
| 25 |
* when it reads an attribute value, which would close a single-quoted JS string and |
| 26 |
* let the remainder of the URL run as script. Keeping the handler free of any |
| 27 |
* user-controlled data removes that context altogether. |
| 28 |
*/ |
| 29 |
$charitable_button_onclick = $view_args['new_tab'] |
| 30 |
? "window.open(this.getAttribute('data-charitable-url'));" |
| 31 |
: "location.href=this.getAttribute('data-charitable-url');"; |
| 32 |
|
| 33 |
// if the type is a button, use a button element, otherwise use a link. |
| 34 |
if ( 'link' === $view_args['type'] ) : |
| 35 |
?> |
| 36 |
|
| 37 |
<a<?php echo $view_args['new_tab'] ? ' target="_blank"' : ''; ?> href="<?php echo esc_url( $view_args['url'] ); ?>" class="<?php echo esc_attr( $view_args['css'] ); ?>"><?php echo esc_html( $view_args['label'] ); ?></a> |
| 38 |
|
| 39 |
<?php else : ?> |
| 40 |
|
| 41 |
<input onclick="<?php echo esc_attr( $charitable_button_onclick ); ?>" data-charitable-url="<?php echo esc_url( $view_args['url'] ); ?>" id="charitable-donate-button-<?php echo intval( $view_args['campaign'] ); ?>" class="<?php echo esc_attr( $view_args['css'] ); ?>" type="button" value="<?php echo esc_attr( $view_args['label'] ); ?>" /> |
| 42 |
|
| 43 |
<?php endif; ?> |
| 44 |
|