| 1 |
<?php |
| 2 |
/** |
| 3 |
* Charitable Public class. |
| 4 |
* |
| 5 |
* @package Charitable/Classes/Charitable_Public |
| 6 |
* @version 1.0.0 |
| 7 |
* @author Eric Daams |
| 8 |
* @copyright Copyright (c) 2015, Studio 164a |
| 9 |
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 13 |
|
| 14 |
if ( ! class_exists( 'Charitable_Public' ) ) : |
| 15 |
|
| 16 |
/** |
| 17 |
* Charitable Public class. |
| 18 |
* |
| 19 |
* @final |
| 20 |
* @since 1.0.0 |
| 21 |
*/ |
| 22 |
final class Charitable_Public { |
| 23 |
|
| 24 |
/** |
| 25 |
* The single instance of this class. |
| 26 |
* |
| 27 |
* @var Charitable_Public|null |
| 28 |
* @access private |
| 29 |
* @static |
| 30 |
*/ |
| 31 |
private static $instance = null; |
| 32 |
|
| 33 |
/** |
| 34 |
* Returns and/or create the single instance of this class. |
| 35 |
* |
| 36 |
* @return Charitable_Public |
| 37 |
* @access public |
| 38 |
* @since 1.2.0 |
| 39 |
*/ |
| 40 |
public static function get_instance() { |
| 41 |
if ( is_null( self::$instance ) ) { |
| 42 |
self::$instance = new Charitable_Public(); |
| 43 |
} |
| 44 |
|
| 45 |
return self::$instance; |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* Set up the class. |
| 50 |
* |
| 51 |
* @access private |
| 52 |
* @since 1.0.0 |
| 53 |
*/ |
| 54 |
private function __construct() { |
| 55 |
add_action( 'after_setup_theme', array( $this, 'load_template_files' ) ); |
| 56 |
add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts') ); |
| 57 |
add_filter( 'post_class', array( $this, 'campaign_post_class' ) ); |
| 58 |
add_filter( 'comments_open', array( $this, 'disable_comments_on_application_pages' ), 10, 2 ); |
| 59 |
|
| 60 |
/** |
| 61 |
* We are registering this object only for backwards compatibility. It |
| 62 |
* will be removed in or after Charitable 1.3. |
| 63 |
* |
| 64 |
* @deprecated |
| 65 |
*/ |
| 66 |
charitable()->register_object( Charitable_Session::get_instance() ); |
| 67 |
charitable()->register_object( Charitable_Templates::get_instance() ); |
| 68 |
|
| 69 |
do_action( 'charitable_public_start', $this ); |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Load the template functions after theme is loaded. |
| 74 |
* |
| 75 |
* This gives themes time to override the functions. |
| 76 |
* |
| 77 |
* @return void |
| 78 |
* @access public |
| 79 |
* @since 1.2.3 |
| 80 |
*/ |
| 81 |
public function load_template_files() { |
| 82 |
require_once( 'charitable-template-functions.php' ); |
| 83 |
require_once( 'charitable-template-hooks.php' ); |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Loads public facing scripts and stylesheets. |
| 88 |
* |
| 89 |
* @return void |
| 90 |
* @access public |
| 91 |
* @since 1.0.0 |
| 92 |
*/ |
| 93 |
public function wp_enqueue_scripts() { |
| 94 |
$vars = apply_filters( 'charitable_javascript_vars', array( |
| 95 |
'ajaxurl' => admin_url( 'admin-ajax.php' ), |
| 96 |
'currency_format_num_decimals' => esc_attr( charitable_get_option( 'decimal_count', 2 ) ), |
| 97 |
'currency_format_decimal_sep' => esc_attr( charitable_get_option( 'decimal_separator', '.' ) ), |
| 98 |
'currency_format_thousand_sep' => esc_attr( charitable_get_option( 'thousands_separator', ',' ) ), |
| 99 |
'currency_format' => esc_attr( charitable_get_currency_helper()->get_accounting_js_format() ), // For accounting.js |
| 100 |
) ); |
| 101 |
|
| 102 |
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
| 103 |
|
| 104 |
wp_register_script( 'accounting', charitable()->get_path( 'assets', false ) . 'js/libraries/accounting'. $suffix . '.js', array( 'jquery' ), charitable()->get_version(), true ); |
| 105 |
wp_enqueue_script( 'accounting' ); |
| 106 |
|
| 107 |
wp_register_script( 'charitable-script', charitable()->get_path( 'assets', false ) . 'js/charitable'. $suffix . '.js', array( 'jquery' ), charitable()->get_version(), true ); |
| 108 |
wp_localize_script( 'charitable-script', 'CHARITABLE_VARS', $vars ); |
| 109 |
wp_enqueue_script( 'charitable-script' ); |
| 110 |
|
| 111 |
wp_register_style( 'charitable-styles', charitable()->get_path( 'assets', false ) . 'css/charitable' . $suffix .'.css', array(), charitable()->get_version() ); |
| 112 |
wp_enqueue_style( 'charitable-styles' ); |
| 113 |
|
| 114 |
/* Lean Modal is registered but NOT enqueued yet. */ |
| 115 |
if ( 'modal' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) { |
| 116 |
wp_register_script( 'lean-modal', charitable()->get_path( 'assets', false ) . 'js/libraries/leanModal' . $suffix . '.js', array( 'jquery' ), charitable()->get_version() ); |
| 117 |
wp_register_style( 'lean-modal-css', charitable()->get_path( 'assets', false ) . 'css/modal' . $suffix .'.css', array(), charitable()->get_version() ); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
/** |
| 122 |
* Adds custom post classes when viewing campaign. |
| 123 |
* |
| 124 |
* @return string[] |
| 125 |
* @access public |
| 126 |
* @since 1.0.0 |
| 127 |
*/ |
| 128 |
public function campaign_post_class( $classes ) { |
| 129 |
$campaign = charitable_get_current_campaign(); |
| 130 |
|
| 131 |
if ( ! $campaign ) { |
| 132 |
return $classes; |
| 133 |
} |
| 134 |
|
| 135 |
$classes[] = $campaign->has_goal() ? 'campaign-has-goal' : 'campaign-has-no-goal'; |
| 136 |
$classes[] = $campaign->is_endless() ? 'campaign-is-endless' : 'campaign-has-end-date'; |
| 137 |
return $classes; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* Disable comments on application pages like the donation page. |
| 142 |
* |
| 143 |
* @param boolean $open |
| 144 |
* @param int $post_id |
| 145 |
* @return boolean |
| 146 |
* @access public |
| 147 |
* @since 1.3.0 |
| 148 |
*/ |
| 149 |
public function disable_comments_on_application_pages( $open, $post_id ) { |
| 150 |
/* If open is already false, just hit return. */ |
| 151 |
if ( ! $open ) { |
| 152 |
return $open; |
| 153 |
} |
| 154 |
|
| 155 |
if ( charitable_is_page( 'campaign_donation_page' ) |
| 156 |
|| charitable_is_page( 'campaign_widget_page' ) |
| 157 |
|| charitable_is_page( 'donation_receipt_page' ) |
| 158 |
|| charitable_is_page( 'donation_processing_page' ) ) { |
| 159 |
$open = false; |
| 160 |
} |
| 161 |
|
| 162 |
return $open; |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 166 |
endif; |