/** Display widget */ public function widget($args, $instance) { extract($args, EXTR_SKIP); $title = apply_filters('widget_title', $instance['title']); if (!$instance['campaign_id']) { $query = new WP_Query(array('post_type' => Leyka_Campaign_Management::$post_type, 'posts_per_page' => 1)); if (!$query->have_posts()) { return; } $campaign_id = $query->posts[0]->ID; } elseif ((int) $instance['campaign_id'] === 0) { $campaign_id = null; } else { $campaign_id = (int) $instance['campaign_id']; } $args = array('show_title' => !!$instance['show_title'], 'show_thumb' => !!$instance['show_thumb'], 'show_excerpt' => !!$instance['show_excerpt'], 'show_scale' => !!$instance['show_scale'], 'show_button' => !!$instance['show_button']); $css_id = 'leyka_campaign_card_widget-' . uniqid(); $html = leyka_get_campaign_card($campaign_id, $args); if (!$html) { return; } $campaign = new Leyka_Campaign($campaign_id); if (!leyka_form_is_screening(false)) { // Don't increase campaign views counter if we're on a page with this campaign's donation form $campaign->increase_views_counter(); } /** @var $before_widget */ echo $before_widget; if ($title) { /** * @var $before_title * @var $after_title */ echo $before_title . $title . $after_title; } echo '<div id="' . esc_attr($css_id) . '">' . $html . "</div>"; /** @var $after_widget */ echo $after_widget; }
<?php if (!defined('WPINC')) { die; } /** * Leyka Template: Embed Campaign Card * Description: A template for an embed campaign cards. On a main website, normally, it is not in use. **/ $campaign = new Leyka_Campaign(get_post()); ?> <!DOCTYPE html> <html class="embed" <?php language_attributes(); ?> > <head> <style> * { margin: 0; padding: 0; -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; } #embedded-card { width: 100%; font: 14px/21px "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif;
function leyka_recalculate_total_funded_action() { if (!wp_verify_nonce($_GET['nonce'], 'leyka_recalculate_total_funded_amount')) { wp_die(__('Error: incorrect request parameters', 'leyka')); } if (empty($_GET['campaign_id'])) { wp_die(__('Error: campaign ID is missing', 'leyka')); } $campaign = new Leyka_Campaign((int) $_GET['campaign_id']); $campaign->update_total_funded_amount(); wp_die($campaign->total_funded); }
function leyka_print_donation_elements($content) { global $post; $autoprint = leyka_options()->opt('donation_form_mode'); if (!is_singular(Leyka_Campaign_Management::$post_type) || !$autoprint) { return $content; } $campaign = new Leyka_Campaign($post); if ($campaign->ignore_global_template_settings) { return $content; } $post_content = $content; $content = ''; // Scale on top of form: if (leyka_options()->opt('scale_widget_place') == 'top' || leyka_options()->opt('scale_widget_place') == 'both') { $content .= do_shortcode("[leyka_scale show_button='1']"); } $content .= $post_content; // Scale below form: if (!empty($campaign->target) && (leyka_options()->opt('scale_widget_place') == 'bottom' || leyka_options()->opt('scale_widget_place') == 'both')) { $content .= do_shortcode("[leyka_scale show_button='0']"); } $content .= get_leyka_payment_form_template_html($post); // Payment form $campaign->increase_views_counter(); // Increase campaign views counter // Donations list: if (leyka_options()->opt('leyka_donations_history_under_forms')) { $list = leyka_get_donors_list($post->ID); if ($list) { $label = apply_filters('leyka_donations_list_title', __('Our sincere thanks', 'leyka'), $post->ID); $content .= '<h3 class="leyka-donations-list-title">' . $label . '</h3>' . $list; } } return $content; }
/** Save a base submission info and return new donation ID, so gateway can add it's specific data to the logs. */ public function log_submission() { if (empty($_POST['leyka_campaign_id']) || (int) $_POST['leyka_campaign_id'] <= 0) { return false; } $campaign = new Leyka_Campaign((int) $_POST['leyka_campaign_id']); $pm_data = leyka_pf_get_payment_method_value(); $donation_id = Leyka_Donation::add(apply_filters('leyka_new_donation_data', array('purpose_text' => $campaign->payment_title, 'gateway_id' => $pm_data['gateway_id']))); $campaign->increase_submits_counter(); if (is_wp_error($donation_id)) { return false; } else { do_action('leyka_log_donation-' . $pm_data['gateway_id'], $donation_id); return $donation_id; } }
/** Save donation data metabox */ public function save_donation_data($donation_id) { // Maybe donation is inserted trough API: if (empty($_POST['post_type']) || $_POST['post_type'] != Leyka_Donation_Management::$post_type) { return false; } if (empty($_POST['_donation_edit_nonce']) || !wp_verify_nonce($_POST['_donation_edit_nonce'], 'donation_status_metabox')) { return $donation_id; } if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $donation_id; } if (!current_user_can('edit_donation', $donation_id)) { return $donation_id; } remove_action('save_post', array($this, 'save_donation_data')); $donation = new Leyka_Donation($donation_id); if ($donation->status != $_POST['donation_status']) { $donation->status = $_POST['donation_status']; } if (isset($_POST['campaign-id']) && $donation->campaign_id != (int) $_POST['campaign-id']) { $old_campaign = new Leyka_Campaign($donation->campaign_id); $new_campaign = new Leyka_Campaign((int) $_POST['campaign-id']); $donation->campaign_id = (int) $_POST['campaign-id']; $old_campaign->update_total_funded_amount($donation)->refresh_target_state(); $new_campaign->update_total_funded_amount($donation)->refresh_target_state(); } // It's a new correction donation, set a title from it's campaign: $campaign = new Leyka_Campaign($donation->campaign_id); $donation_title = $campaign->payment_title ? $campaign->payment_title : ($campaign->title ? $campaign->title : sprintf(__('Donation #%s', 'leyka'), $donation_id)); if ($donation->title != $donation_title) { $donation->title = $donation_title; } if (isset($_POST['donor-name']) && $donation->donor_name != $_POST['donor-name']) { $donation->donor_name = $_POST['donor-name']; } if (isset($_POST['donor-email']) && $donation->donor_email != $_POST['donor-email']) { $donation->donor_email = $_POST['donor-email']; } if (isset($_POST['donation-amount']) && (double) $donation->amount != (double) $_POST['donation-amount']) { $donation->amount = (double) $_POST['donation-amount']; } if (!$donation->currency) { $donation->currency = 'rur'; } if (isset($_POST['donation-pm']) && ($donation->pm != $_POST['donation-pm'] || $_POST['donation-pm'] == 'custom')) { if ($_POST['donation-pm'] == 'custom') { $donation->gateway_id = ''; if ($donation->pm_id != $_POST['custom-payment-info']) { $donation->pm_id = $_POST['custom-payment-info']; } } else { $parts = explode('-', $_POST['donation-pm']); $donation->gateway_id = $parts[0]; $donation->pm = $parts[1]; } } if (isset($_POST['donation_date']) && $donation->date_timestamp != strtotime($_POST['donation_date'])) { $donation->date = $_POST['donation_date']; } if (isset($_POST['payment-type']) && $donation->payment_type != $_POST['payment-type']) { $donation->payment_type = $_POST['payment-type']; } do_action("leyka_{$donation->gateway_id}_save_donation_data", $donation); add_action('save_post', array($this, 'save_donation_data')); return true; }
function leyka_get_payment_form($campaign = null, $args = array()) { global $post; $defaults = array('template' => null); $args = wp_parse_args($args, $defaults); if (!$campaign) { $campaign = $post; } elseif (is_int($campaign)) { $campaign = get_post($campaign); } if ($campaign->post_type != Leyka_Campaign_Management::$post_type) { return ''; } $campaign = new Leyka_Campaign($campaign); $campaign->increase_views_counter(); // Increase campaign views counter return get_leyka_payment_form_template_html($campaign, $args['template']); }
function leyka_fake_scale_ultra($campaign) { if (!is_a($campaign, 'Leyka_Campaign')) { $campaign = new Leyka_Campaign($campaign); } $curr_label = leyka_get_currency_label('rur'); $collected = number_format(intval($campaign->get_collected_amount()), 0, '.', ' '); ?> <div class="leyka-scale-ultra-fake"> <div class="leyka-scale-scale"> <div class="target"> </div> </div> <div class="leyka-scale-label"><span> <?php printf(_x('Collected: %s', 'Label on ultra-compact fake scale', 'leyka'), "<b>{$collected}</b> {$curr_label}"); ?> </span></div> </div> <?php }
protected function _get_calculated_target_state() { $target = get_post_meta($this->_id, 'campaign_target', true); return empty($target) ? 'no_target' : (Leyka_Campaign::get_campaign_collected_amount($this->_id) >= $target ? 'is_reached' : 'in_progress'); }