/**
  * Add the general tab settings fields. 
  *
  * @param   array[] $fields
  * @return  array
  * @access  public
  * @since   1.0.0
  */
 public function add_general_fields($fields = array())
 {
     if (!charitable_is_settings_view('general')) {
         return array();
     }
     $general_fields = array('section' => array('title' => '', 'type' => 'hidden', 'priority' => 10000, 'value' => 'general'), 'section_locale' => array('title' => __('Currency & Location', 'charitable'), 'type' => 'heading', 'priority' => 2), 'country' => array('title' => __('Base Country', 'charitable'), 'type' => 'select', 'priority' => 4, 'default' => 'AU', 'options' => charitable_get_location_helper()->get_countries()), 'currency' => array('title' => __('Currency', 'charitable'), 'type' => 'select', 'priority' => 10, 'default' => 'AUD', 'options' => charitable_get_currency_helper()->get_all_currencies()), 'currency_format' => array('title' => __('Currency Format', 'charitable'), 'type' => 'select', 'priority' => 12, 'default' => 'left', 'options' => array('left' => '$23.00', 'right' => '23.00$', 'left-with-space' => '$ 23.00', 'right-with-space' => '23.00 $')), 'decimal_separator' => array('title' => __('Decimal Separator', 'charitable'), 'type' => 'select', 'priority' => 14, 'default' => '.', 'options' => array('.' => 'Period (12.50)', ',' => 'Comma (12,50)')), 'thousands_separator' => array('title' => __('Thousands Separator', 'charitable'), 'type' => 'select', 'priority' => 16, 'default' => ',', 'options' => array(',' => __('Comma (10,000)', 'charitable'), '.' => __('Period (10.000)', 'charitable'), '' => __('None', 'charitable'))), 'decimal_count' => array('title' => __('Number of Decimals', 'charitable'), 'type' => 'number', 'priority' => 18, 'default' => 2, 'class' => 'short'), 'section_donation_form' => array('title' => __('Donation Form', 'charitable'), 'type' => 'heading', 'priority' => 20), 'donation_form_display' => array('title' => __('Display Options', 'charitable'), 'type' => 'select', 'priority' => 22, 'default' => 'separate_page', 'options' => array('separate_page' => __('Show on a Separate Page', 'charitable'), 'same_page' => __('Show on the Same Page', 'charitable'), 'modal' => __('Reveal in a Modal', 'charitable')), 'help' => __('Choose how you want a campaign\'s donation form to show.', 'charitable')), 'section_pages' => array('title' => __('Pages', 'charitable'), 'type' => 'heading', 'priority' => 30), 'login_page' => array('title' => __('Login Page', 'charitable'), 'type' => 'select', 'priority' => 32, 'default' => 'wp', 'options' => array('wp' => __('Use WordPress Login', 'charitable'), 'pages' => array('options' => charitable_get_admin_settings()->get_pages(), 'label' => __('Choose a Static Page', 'charitable'))), 'help' => __('Allow users to login via the normal WordPress login page or via a static page. The static page should contain the <code>[charitable_login]</code> shortcode.', 'charitable')), 'registration_page' => array('title' => __('Registration Page', 'charitable'), 'type' => 'select', 'priority' => 34, 'default' => 'wp', 'options' => array('wp' => __('Use WordPress Registration Page', 'charitable'), 'pages' => array('options' => charitable_get_admin_settings()->get_pages(), 'label' => __('Choose a Static Page', 'charitable'))), 'help' => __('Allow users to register via the default WordPress login or via a static page. The static page should contain the <code>[charitable_registration]</code> shortcode.', 'charitable')), 'profile_page' => array('title' => __('Profile Page', 'charitable'), 'type' => 'select', 'priority' => 36, 'options' => charitable_get_admin_settings()->get_pages(), 'help' => __('The static page should contain the <code>[charitable_profile]</code> shortcode.', 'charitable')), 'donation_receipt_page' => array('title' => __('Donation Receipt Page', 'charitable'), 'type' => 'select', 'priority' => 38, 'default' => 'auto', 'options' => array('auto' => __('Automatic', 'charitable'), 'pages' => array('options' => charitable_get_admin_settings()->get_pages(), 'label' => __('Choose a Static Page', 'charitable'))), 'help' => __('Choose the page that users will be redirected to after donating. Leave it set to automatic to use the built-in Charitable receipt. If you choose a static page, it should contain the <code>[donation_receipt]</code> shortcode.', 'charitable')));
     $fields = array_merge($fields, $general_fields);
     return $fields;
 }
Ejemplo n.º 2
0
 function setUp()
 {
     parent::setUp();
     $this->currency_helper = charitable_get_currency_helper();
     $this->set_currency_format('left');
     $this->set_currency('AUD');
     $this->set_decimal_count(2);
     $this->set_decimal_separator('.');
     $this->set_thousands_separator(',');
 }
 /**
  * Return list of donation IDs together with the number of donations they have made.
  *
  * @return  object[]
  * @access  public
  * @since   1.4.0
  */
 public function get_donations()
 {
     $records = $this->query();
     /**
      * Return Donations objects.
      */
     if ('donations' == $this->get('output')) {
         return array_map('charitable_get_donation', $records);
     }
     $currency_helper = charitable_get_currency_helper();
     /**
      * When the currency uses commas for decimals and periods for thousands,
      * the amount returned from the database needs to be sanitized.
      */
     if ($currency_helper->is_comma_decimal()) {
         foreach ($records as $i => $row) {
             $records[$i]->amount = $currency_helper->sanitize_database_amount($row->amount);
         }
     }
     return $records;
 }
 /**
  * Returns a summary of the donation, including all the campaigns that were donated to.  
  *
  * @return  string
  * @access  public
  * @since   1.0.0
  */
 public function get_donation_summary()
 {
     if (!$this->has_valid_donation()) {
         return '';
     }
     $output = "";
     foreach ($this->donation->get_campaign_donations() as $campaign_donation) {
         $line_item = sprintf('%s: %s%s', $campaign_donation->campaign_name, charitable_get_currency_helper()->get_monetary_amount($campaign_donation->amount), PHP_EOL);
         $output .= apply_filters('charitable_donation_summary_line_item_email', $line_item, $campaign_donation);
     }
     return $output;
 }
 /**
  * Save benefactors when saving campaign.
  *
  * @param   WP_Post     $post       Post object.
  * @return  void
  * @access  public
  * @since   1.0.0
  */
 public function save_benefactors(WP_Post $post)
 {
     if (!isset($_POST['_campaign_benefactor'])) {
         return;
     }
     $currency_helper = charitable_get_currency_helper();
     $benefactors = $_POST['_campaign_benefactor'];
     foreach ($benefactors as $campaign_benefactor_id => $data) {
         /* If the contribution amount was not set, we won't create a benefactor object. */
         if (empty($data['contribution_amount'])) {
             continue;
         }
         $data['campaign_id'] = $post->ID;
         $data['contribution_amount_is_percentage'] = intval(false !== strpos($data['contribution_amount'], '%'));
         $data['contribution_amount'] = $currency_helper->sanitize_monetary_amount($data['contribution_amount']);
         /* If the contribution amount was set to 0, we won't create a benefactor object. */
         if (0 == $data['contribution_amount']) {
             continue;
         }
         if (isset($data['date_created']) && strlen($data['date_created'])) {
             $data['date_created'] = date('Y-m-d 00:00:00', strtotime($data['date_created']));
         }
         /** Sanitize end date of benefactor relationship. If the campaign has an end date, then the benefactor 
             relationship should end then or before then (not after) **/
         $campaign_end_date = get_post_meta($post->ID, '_campaign_end_date', true);
         if (isset($data['date_deactivated']) && strlen($data['date_deactivated'])) {
             $date_deactivated = strtotime($data['date_deactivated']);
             $data['date_deactivated'] = strtotime($campaign_end_date) < $date_deactivated ? $campaign_end_date : date('Y-m-d 00:00:00', $date_deactivated);
         } elseif (0 != $campaign_end_date) {
             $data['date_deactivated'] = $campaign_end_date;
         }
         /* Insert or update benefactor record */
         if (0 == $campaign_benefactor_id) {
             charitable_get_table('benefactors')->insert($data);
         } else {
             charitable_get_table('benefactors')->update($campaign_benefactor_id, $data);
         }
     }
 }
/**
 * Sanitize an amount, converting it into a float.
 *
 * @param   string $amount
 * @return  float|WP_Error
 * @since   1.4.0
 */
function charitable_sanitize_amount($amount)
{
    return charitable_get_currency_helper()->sanitize_monetary_amount($amount);
}
Ejemplo n.º 7
0
 * @since   1.0.0
 */
$widget_title = apply_filters('widget_title', $view_args['title']);
$campaigns_count = Charitable_Campaigns::query(array('posts_per_page' => -1, 'fields' => 'ids'))->found_posts;
$campaigns_text = $campaigns_count == 1 ? __('Campaign', 'charitable') : __('Campaigns', 'charitable');
echo $view_args['before_widget'];
if (!empty($widget_title)) {
    echo $view_args['before_title'] . $widget_title . $view_args['after_title'];
}
?>
<ul class="donation-stats">
    <li>
        <?php 
printf('<span class="figure">%d</span> %s', $campaigns_count, $campaigns_text);
?>
    </li>
    <li>                
        <?php 
printf('<span class="figure">%s</span> %s', charitable_get_currency_helper()->get_monetary_amount(charitable_get_table('campaign_donations')->get_total(), 0), __('Donated', 'charitable'));
?>
    </li>
    <li>
        <?php 
printf('<span class="figure">%d</span> %s', charitable_get_table('donors')->count_all(), __('Donors', 'charitable'));
?>
        
    </li>
</ul>

<?php 
echo $view_args['after_widget'];
 /**
  * Sanitize the campaign goal.
  *
  * @param   string  $value
  * @return  string|int
  * @access  public
  * @static
  * @since   1.0.0
  */
 public static function sanitize_campaign_goal($value)
 {
     if (empty($value) || !$value) {
         return 0;
     }
     return charitable_get_currency_helper()->sanitize_monetary_amount($value);
 }
Ejemplo n.º 9
0
    echo charitable_get_currency_helper()->get_monetary_amount($campaign_donation->amount);
    ?>
</td>
            </tr>
        <?php 
}
?>
        </tbody>
        <tfoot>
            <tr>
                <th><?php 
_e('Total', 'charitable');
?>
</th>
                <td><?php 
echo charitable_get_currency_helper()->get_monetary_amount($donation->get_total_donation_amount());
?>
</td>
            </tr>
            <tr>
                <th><?php 
_e('Payment Method', 'charitable');
?>
</th>
                <td><?php 
echo $donation->get_gateway_label();
?>
</td>
            </tr>
            <tr>
                <th><?php 
 /**
  * Return the donation amount.
  *
  * @return  float
  * @access  public
  * @static
  * @since   1.0.0
  */
 public static function get_donation_amount()
 {
     $amount = isset($_POST['donation_amount']) ? $_POST['donation_amount'] : 0;
     if (0 === $amount || 'custom' == $amount) {
         $amount = isset($_POST['custom_donation_amount']) ? $_POST['custom_donation_amount'] : 0;
     }
     $amount = charitable_get_currency_helper()->sanitize_monetary_amount($amount);
     return apply_filters('charitable_donation_form_amount', $amount);
 }
 /**
  * Return a string describing the campaign's donation summary. 
  *
  * @return  string
  * @access  public
  * @since   1.0.0
  */
 public function get_donation_summary()
 {
     $currency_helper = charitable_get_currency_helper();
     if ($this->has_goal()) {
         $ret = sprintf(_x('%s donated of %s goal', 'amount donated of goal', 'charitable'), '<span class="amount">' . $currency_helper->get_monetary_amount($this->get_donated_amount()) . '</span>', '<span class="goal-amount">' . $currency_helper->get_monetary_amount($this->get('goal')) . '</span>');
     } else {
         $ret = sprintf(_x('%s donated', 'amount donated', 'charitable'), '<span class="amount">' . $currency_helper->get_monetary_amount($this->get_donated_amount()) . '</span>');
     }
     return apply_filters('charitable_donation_summary', $ret, $this);
 }
 /**
  * Loads public facing scripts and stylesheets.
  *
  * @return 	void
  * @access 	public
  * @since 	1.0.0
  */
 public function setup_scripts()
 {
     if (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) {
         $suffix = '';
         $version = '';
     } else {
         $suffix = '.min';
         $version = charitable()->get_version();
     }
     $assets_dir = charitable()->get_path('assets', false);
     /* Main Charitable script. */
     $vars = apply_filters('charitable_javascript_vars', array('ajaxurl' => admin_url('admin-ajax.php'), 'loading_gif' => $assets_dir . '/images/charitable-loading.gif', 'currency_format_num_decimals' => esc_attr(charitable_get_option('decimal_count', 2)), 'currency_format_decimal_sep' => esc_attr(charitable_get_option('decimal_separator', '.')), 'currency_format_thousand_sep' => esc_attr(charitable_get_option('thousands_separator', ',')), 'currency_format' => esc_attr(charitable_get_currency_helper()->get_accounting_js_format()), 'error_invalid_amount' => sprintf(__('You must donate more than %s.', 'charitable'), charitable_format_money('0')), 'error_required_fields' => __('Please fill out all required fields.', 'charitable'), 'error_unknown' => __('Your donation could not be processed. Please reload the page and try again.', 'charitable'), 'error_invalid_cc_number' => __('The credit card passed is not valid.', 'charitable'), 'error_invalid_cc_expiry' => __('The credit card expiry date is not valid.', 'charitable')));
     /* Accounting.js */
     wp_register_script('accounting', $assets_dir . 'js/libraries/accounting' . $suffix . '.js', array('jquery-core'), $version, true);
     wp_register_script('charitable-script', $assets_dir . 'js/charitable' . $suffix . '.js', array('accounting', 'jquery-core'), $version, true);
     wp_localize_script('charitable-script', 'CHARITABLE_VARS', $vars);
     /* Credit card validation */
     wp_register_script('charitable-credit-card', $assets_dir . 'js/charitable-credit-card' . $suffix . '.js', array('charitable-script'), $version, true);
     /* Enqueue credit card & 
     
     			/* Main styles */
     wp_register_style('charitable-styles', $assets_dir . 'css/charitable' . $suffix . '.css', array(), $version);
     wp_enqueue_style('charitable-styles');
     /* Lean Modal is registered but NOT enqueued yet. */
     if ('modal' == charitable_get_option('donation_form_display', 'separate_page')) {
         wp_register_script('lean-modal', $assets_dir . 'js/libraries/leanModal' . $suffix . '.js', array('jquery-core'), $version);
         wp_register_style('lean-modal-css', $assets_dir . 'css/modal' . $suffix . '.css', array(), $version);
     }
     /* pupload Fields is also registered but NOT enqueued. */
     $upload_vars = array('remove_image' => _x('Remove', 'remove image button text', 'charitable'), 'max_file_uploads_single' => __('You can only upload %d file', 'charitable'), 'max_file_uploads_plural' => __('You can only upload a maximum of %d files', 'charitable'), 'max_file_size' => __('%1$s exceeds the max upload size of %2$s', 'charitable'), 'upload_problem' => __('%s failed to upload. Please try again.', 'charitable'));
     wp_register_script('charitable-plup-fields', $assets_dir . 'js/charitable-plupload-fields' . $suffix . '.js', array('jquery-ui-sortable', 'wp-ajax-response', 'plupload-all'), $version, true);
     wp_localize_script('charitable-plup-fields', 'CHARITABLE_UPLOAD_VARS', $upload_vars);
     wp_register_style('charitable-plup-styles', $assets_dir . 'css/charitable-plupload-fields' . $suffix . '.css', array(), $version);
 }
Ejemplo n.º 13
0
 /**
  * @deprecated
  */
 public function get_currency_helper()
 {
     charitable_get_deprecated()->deprecated_function(__METHOD__, '1.4.0', 'charitable_get_currency_helper');
     return charitable_get_currency_helper();
 }
/**
 * Formats the monetary amount. 
 * 
 * @param   string $amount
 * @return  string
 * @since   1.1.5
 */
function charitable_format_money($amount)
{
    return charitable_get_currency_helper()->get_monetary_amount($amount);
}