function __construct(Leyka_Payment_Method $payment_method, $current_currency = null) { if (!leyka()->form_is_screening) { leyka()->form_is_screening = true; } $this->_pm = $payment_method; $this->_pm_name = $payment_method->id; $this->_current_currency = $current_currency; $this->_form_action = get_option('permalink_structure') ? home_url('leyka-process-donation') : home_url('?page=leyka-process-donation'); }
/** Different ajax handler functions */ function leyka_submit_donation() { if (empty($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'leyka_payment_form')) { die(json_encode(array('status' => 0, 'message' => __('Wrong nonce in submitted form data', 'leyka')))); } leyka()->clear_session_errors(); // Clear all previous submits errors, if there are some $pm = explode('-', $_POST['leyka_payment_method']); if (!$pm || count($pm) < 2) { die(json_encode(array('status' => 0, 'message' => __('Wrong gateway or/and payment method in submitted form data', 'leyka')))); } $donation_id = leyka()->log_submission(); do_action('leyka_payment_form_submission-' . $pm[0], $pm[0], implode('-', array_slice($pm, 1)), $donation_id, $_POST); $payment_vars = array_merge(apply_filters('leyka_submission_form_data-' . $pm[0], $_POST, $pm[1], $donation_id), array('status' => 1, 'donation_id' => $donation_id)); // echo '<pre>' . print_r($payment_vars, 1) . '</pre>'; die(json_encode($payment_vars)); }
require_once LEYKA_PLUGIN_DIR . 'inc/leyka-class-options-controller.php'; require_once LEYKA_PLUGIN_DIR . 'inc/leyka-core.php'; require_once LEYKA_PLUGIN_DIR . 'inc/leyka-gateways-api.php'; require_once LEYKA_PLUGIN_DIR . 'inc/leyka-class-campaign.php'; require_once LEYKA_PLUGIN_DIR . 'inc/leyka-class-donation.php'; require_once LEYKA_PLUGIN_DIR . 'inc/leyka-class-payment-form.php'; require_once LEYKA_PLUGIN_DIR . 'inc/leyka-ajax.php'; require_once LEYKA_PLUGIN_DIR . 'inc/leyka-shortcodes.php'; require_once LEYKA_PLUGIN_DIR . 'inc/leyka-widgets.php'; /** Automatically include all sub-dirs of /leyka/gateways/ */ $gateways_dir = dir(LEYKA_PLUGIN_DIR . 'gateways/'); if (!$gateways_dir) { // ?.. } else { while (false !== ($gateway_id = $gateways_dir->read())) { $file_addr = LEYKA_PLUGIN_DIR . "gateways/{$gateway_id}/leyka-class-{$gateway_id}-gateway.php"; if ($gateway_id != '.' && $gateway_id != '..' && file_exists($file_addr)) { require_once $file_addr; } } $gateways_dir->close(); } register_activation_hook(__FILE__, array('Leyka', 'activate')); // Activation add_action('plugins_loaded', array('Leyka', 'activate')); // Any update needed register_deactivation_hook(__FILE__, array('Leyka', 'deactivate')); // Deactivate leyka(); // All systems go //restore_error_handler(); // Finally, restore errors handler to previous one
function leyka_get_current_template_data($campaign = null, $template = null, $is_service = false) { global $post; if (!$campaign) { $campaign = $post; } elseif (is_int($campaign)) { $campaign = get_post($campaign); } // Get campaign-specific template, if needed: if (!$template) { if (!is_a($campaign, 'Leyka_Campaign')) { $campaign = new Leyka_Campaign($campaign); } $template = $campaign->template; } if (!$template || $template == 'default') { $template = leyka_options()->opt('donation_form_template'); } $template = leyka()->get_template($template, !!$is_service); return $template ? $template : false; }
function leyka_add_gateway_chronopay() { // Use named function to leave a possibility to remove/replace it on the hook leyka()->add_gateway(Leyka_Chronopay_Gateway::get_instance()); }
/** Helpers **/ static function get_status_labels($status = false) { $labels = leyka()->get_donation_statuses(); if (empty($status)) { return $labels; } elseif ($status == 'publish') { return $labels['funded']; } else { return !empty($labels[$status]) ? $labels[$status] : false; } }
function leyka_add_gateway_yandex_phyz() { // Use named function to leave a possibility to remove/replace it on the hook leyka()->add_gateway(Leyka_Yandex_Phyz_Gateway::get_instance()); }
function leyka_add_gateway_cp() { leyka()->add_gateway(Leyka_CP_Gateway::get_instance()); }
static function get_target_state_label($state = false) { $labels = leyka()->get_campaign_target_states(); if (!$state) { return $labels; } else { return !empty($labels[$state]) ? $labels[$state] : false; } }
function leyka_do_donations_export() { if (empty($_GET['leyka-donations-export-csv-excel'])) { return; } // Just in case that export will require some time: ini_set('max_execution_time', 99999); set_time_limit(99999); ob_start(); $meta_query = array('relation' => 'AND'); if (!empty($_GET['campaign'])) { $meta_query[] = array('key' => 'leyka_campaign_id', 'value' => (int) $_GET['campaign']); } if (!empty($_GET['payment_type'])) { $meta_query[] = array('key' => 'leyka_payment_type', 'value' => $_GET['payment_type']); } if (!empty($_GET['gateway_pm'])) { if (strpos($_GET['gateway_pm'], 'gateway__') !== false) { $meta_query[] = array('key' => 'leyka_gateway', 'value' => str_replace('gateway__', '', $_GET['gateway_pm'])); } elseif (strpos($_GET['gateway_pm'], 'pm__') !== false) { $meta_query[] = array('key' => 'leyka_payment_method', 'value' => str_replace('pm__', '', $_GET['gateway_pm'])); } } $args = array('post_type' => Leyka_Donation_Management::$post_type, 'post_status' => isset($_GET['post_status']) && in_array($_GET['post_status'], array_keys(leyka()->get_donation_statuses())) ? $_GET['post_status'] : 'any', 'm' => $_GET['month-year'], 's' => $_GET['search_string'], 'meta_query' => $meta_query, 'nopaging' => true); $donations = get_posts(apply_filters('leyka_donations_export_query_args', $args)); function leyka_prep($text) { return '"' . str_replace(array(';', '"'), array('', ''), $text) . '"'; } if (isset($_GET['export-tech'])) { $domain = str_replace(array('http:', 'https:'), '', home_url()); ob_clean(); header('Content-type: application/vnd.ms-excel'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Pragma: no-cache'); header('Content-Disposition: attachment; filename="donations-tech-' . $domain . '-' . date('d.m.Y-H.i.s') . '.csv"'); echo iconv('UTF-8', apply_filters('leyka_donations_tech_export_content_charset', 'windows-1251'), "sep=;\n" . implode(';', array('hash', 'Domain', 'Org_name', 'Timestamp', 'Date', 'Email_hash', 'Donor_name hash', 'Sum', 'Currency', 'Gateway_pm', 'Donation_status', 'Campaign_title', 'Campaign_URL', 'Payment_title', 'Target_sum', 'Campaign_target_state', 'Campaign_is_finished'))); foreach ($donations as $donation) { $donation = new Leyka_Donation($donation); $campaign = new Leyka_Campaign($donation->campaign_id); // @ to avoid notices about illegal chars that happen in the line sometimes: echo @iconv('UTF-8', apply_filters('leyka_donations_tech_export_content_charset', 'windows-1251'), "\r\n" . implode(';', array(leyka_prep(hash('sha256', $domain . $donation->date_timestamp . $donation->sum . $donation->id)), leyka_prep($domain), leyka_prep(leyka_options()->opt('org_full_name')), leyka_prep($donation->date_timestamp), leyka_prep(date('d.m.Y H:i:s', $donation->date_timestamp)), leyka_prep(hash('sha256', $donation->donor_email)), leyka_prep(hash('sha256', $donation->donor_name)), leyka_prep((int) $donation->sum), leyka_prep($donation->currency), $donation->payment_type == 'correction' ? leyka_prep($donation->pm_id) : leyka_prep($donation->gateway_label . '-' . $donation->pm_id), leyka_prep($donation->status), leyka_prep($campaign->title), leyka_prep($campaign->url), leyka_prep($campaign->payment_title), leyka_prep((int) $campaign->target), leyka_prep($campaign->target_state), leyka_prep((int) $campaign->is_finished)))); } die(''); } else { function leyka_prepare_donation_data_for_export($donation_data) { foreach ($donation_data as &$data) { $data = leyka_prep($data); } return $donation_data; } add_filter('leyka_donations_export_line', 'leyka_prepare_donation_data_for_export'); ob_clean(); header('Content-type: application/vnd.ms-excel'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Pragma: no-cache'); header('Content-Disposition: attachment; filename="donations-' . date('d.m.Y-H.i.s') . '.csv"'); echo iconv('UTF-8', apply_filters('leyka_donations_export_content_charset', 'windows-1251'), "sep=;\n" . implode(';', apply_filters('leyka_donations_export_headers', array('ID', 'Имя донора', 'Email', 'Тип платежа', 'Способ платежа', 'Сумма', 'Дата пожертвования', 'Статус', 'Кампания')))); foreach ($donations as $donation) { $donation = new Leyka_Donation($donation); $campaign = new Leyka_Campaign($donation->campaign_id); echo @iconv('UTF-8', apply_filters('leyka_donations_export_content_charset', 'windows-1251'), "\r\n" . implode(';', apply_filters('leyka_donations_export_line', array($donation->id, $donation->donor_name, $donation->donor_email, $donation->payment_type_label, $donation->payment_method_label, $donation->sum . ' ' . $donation->currency_label, $donation->date, $donation->status_label, $campaign->title)))); } die(''); } }
function leyka_add_gateway_robokassa() { leyka()->add_gateway(Leyka_Robokassa_Gateway::get_instance()); }
/** * Get all possible campaign target states. **/ function leyka_get_campaign_target_states_list() { return leyka()->get_campaign_target_states(); }
function leyka_do_donations_export() { if (empty($_GET['leyka-donations-export-csv-excel'])) { return; } // Just in case that export will require some time: ini_set('max_execution_time', 99999); set_time_limit(99999); ob_start(); $meta_query = array('relation' => 'AND'); if (!empty($_GET['campaign'])) { $meta_query[] = array('key' => 'leyka_campaign_id', 'value' => (int) $_GET['campaign']); } if (!empty($_GET['payment_type'])) { $meta_query[] = array('key' => 'leyka_payment_type', 'value' => $_GET['payment_type']); } if (!empty($_GET['gateway_pm'])) { if (strpos($_GET['gateway_pm'], 'gateway__') !== false) { $meta_query[] = array('key' => 'leyka_gateway', 'value' => str_replace('gateway__', '', $_GET['gateway_pm'])); } elseif (strpos($_GET['gateway_pm'], 'pm__') !== false) { $meta_query[] = array('key' => 'leyka_payment_method', 'value' => str_replace('pm__', '', $_GET['gateway_pm'])); } } $args = array('post_type' => Leyka_Donation_Management::$post_type, 'post_status' => isset($_GET['post_status']) && in_array($_GET['post_status'], array_keys(leyka()->get_donation_statuses())) ? $_GET['post_status'] : 'any', 'm' => $_GET['month-year'], 'meta_query' => $meta_query, 'posts_per_page' => 200); $donations = new WP_Query(apply_filters('leyka_donations_export_query_args', $args)); $total_pages = $donations->found_posts / 200; $total_pages = $total_pages - (int) $total_pages > 0 ? (int) $total_pages + 1 : $total_pages; $posts_page = $total_pages > 0 ? 1 : 0; $donations = $donations->get_posts(); require_once LEYKA_PLUGIN_DIR . 'inc/excel-writer/SimpleExcel.php'; $excel = new SimpleExcel('csv'); $domain = str_replace(array('http:', 'https:'), '', home_url()); function prep($text) { return '"' . str_replace(array(';', '"'), array('', ''), $text) . '"'; } if (isset($_GET['export-tech'])) { // Technical export mode column headings $excel->writer->addRow(array('hash', 'Domain', 'Org_name', 'Timestamp', 'Date', 'Email_hash', 'Donor_name hash', 'Sum', 'Currency', 'Gateway_pm', 'Donation_status', 'Campaign_title', 'Campaign_URL', 'Payment_title', 'Target_sum', 'Campaign_target_state', 'Campaign_is_finished')); } else { // Normal export mode column headings $excel->writer->addRow(array(apply_filters('leyka_donations_export_headers', array('ID', 'Имя донора', 'Email', 'Тип платежа', 'Способ платежа', 'Сумма', 'Дата пожертвования', 'Статус', 'Кампания')))); } while ($posts_page && $posts_page <= $total_pages) { // Main loop too fill the export file foreach ($donations as $donation) { $donation = new Leyka_Donation($donation); $campaign = new Leyka_Campaign($donation->campaign_id); if (isset($_GET['export-tech'])) { $excel->writer->addRow(array(prep(wp_hash($domain . $donation->date_timestamp . $donation->sum . $donation->id)), prep($domain), prep(leyka_options()->opt('org_full_name')), prep($donation->date_timestamp), prep(date(get_option('date_format') . ', H:i', $donation->date_timestamp)), prep(wp_hash($donation->donor_email)), prep(wp_hash($donation->donor_name)), prep((int) $donation->sum), prep($donation->currency), $donation->payment_type == 'correction' ? prep($donation->pm_id) : prep($donation->gateway_label . '-' . $donation->pm_id), prep($donation->status), prep($campaign->title), prep($campaign->url), prep($campaign->payment_title), prep((int) $campaign->target), prep($campaign->target_state), prep((int) $campaign->is_finished))); } else { $excel->writer->addRow(apply_filters('leyka_donations_export_line', array($donation->id, $donation->donor_name, $donation->donor_email, $donation->payment_type_label, $donation->payment_method_label, $donation->sum . ' ' . $donation->currency_label, $donation->date, $donation->status_label, $campaign->title))); } } $posts_page++; $args['paged'] = $posts_page; $donations = get_posts(apply_filters('leyka_donations_export_query_args', $args)); wp_cache_flush(); } if (isset($_GET['export-tech'])) { $excel->writer->setDelimiter(';'); ob_clean(); header('Content-type: application/vnd.ms-excel'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Pragma: no-cache'); header('Content-Disposition: attachment; filename="donations-tech-' . $domain . '-' . date('d.m.Y-H.i.s') . '.csv"'); die(iconv('UTF-8', apply_filters('leyka_donations_export_content_charset', 'windows-1251'), "sep=;\n" . $excel->writer->saveString())); // ob_clean(); // // header('Content-type: application/vnd.ms-excel'); // header('Content-Transfer-Encoding: binary'); // header('Expires: 0'); // header('Pragma: no-cache'); // header('Content-Disposition: attachment; filename="donations-tech-'.$domain.'-'.date('d.m.Y-H.i.s').'.csv"'); // // die("sep=;\n".implode("\r\n", $file_lines)); } else { $excel->writer->setDelimiter(','); ob_clean(); header('Content-type: application/vnd.ms-excel'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Pragma: no-cache'); header('Content-Disposition: attachment; filename="donations-' . date('d.m.Y-H.i.s') . '.csv"'); die(iconv('UTF-8', apply_filters('leyka_donations_export_content_charset', 'windows-1251'), "sep=,\n" . $excel->writer->saveString())); } }
/** @return boolean True if at least one Leyka form is currently on the screen, false otherwise */ function leyka_form_is_screening($widgets_also = true) { $template = get_page_template_slug(); $content_has_shortcode = false; if (get_post()) { foreach (leyka_get_shortcodes() as $shortcode_tag) { if (has_shortcode(get_post()->post_content, $shortcode_tag)) { $content_has_shortcode = true; break; } } } $form_is_screening = leyka()->form_is_screening || is_singular(Leyka_Campaign_Management::$post_type) || stristr($template, 'home-campaign_one') !== false || stripos($template, 'leyka') !== false || $content_has_shortcode || (!!$widgets_also ? leyka_is_widget_active() : false); return $form_is_screening; }
public function leyka_fix() { if (!class_exists('Leyka')) { return; } $leyka = leyka(); if (!is_singular('leyka_campaign')) { remove_action('wp_enqueue_scripts', array($leyka, 'enqueue_styles')); remove_action('wp_enqueue_scripts', array($leyka, 'enqueue_scripts')); } }
function leyka_do_donations_export() { if (empty($_GET['leyka-donations-export-csv-excel'])) { return; } ob_start(); $meta_query = array('relation' => 'AND'); if (!empty($_GET['campaign'])) { $meta_query[] = array('key' => 'leyka_campaign_id', 'value' => (int) $_GET['campaign']); } if (!empty($_GET['payment_type'])) { $meta_query[] = array('key' => 'leyka_payment_type', 'value' => $_GET['payment_type']); } if (!empty($_GET['gateway_pm'])) { if (strpos($_GET['gateway_pm'], 'gateway__') !== false) { $meta_query[] = array('key' => 'leyka_gateway', 'value' => str_replace('gateway__', '', $_GET['gateway_pm'])); } elseif (strpos($_GET['gateway_pm'], 'pm__') !== false) { $meta_query[] = array('key' => 'leyka_payment_method', 'value' => str_replace('pm__', '', $_GET['gateway_pm'])); } } $args = array('post_type' => Leyka_Donation_Management::$post_type, 'post_status' => isset($_GET['post_status']) && in_array($_GET['post_status'], array_keys(leyka()->get_donation_statuses())) ? $_GET['post_status'] : 'any', 'm' => $_GET['month-year'], 'meta_query' => $meta_query, 'nopaging' => true); $donations = get_posts(apply_filters('leyka_donations_export_query_args', $args)); if (isset($_GET['export-tech'])) { function prep($text) { return '"' . str_replace(array(';', '"'), array('', ''), $text) . '"'; } $file_lines = array(array('hash', 'Domain', 'Org_name', 'Timestamp', 'Date', 'Email_hash', 'Donor_name hash', 'Sum', 'Currency', 'Gateway_pm', 'Donation_status', 'Campaign_title', 'Campaign_URL', 'Payment_title', 'Target_sum', 'Campaign_target_state', 'Campaign_is_finished')); for ($i = 0; $i < count($file_lines[0]); $i++) { $file_lines[0][$i] = prep($file_lines[0][$i]); } $domain = str_replace(array('http:', 'https:'), '', home_url()); foreach ($donations as $donation) { $donation = new Leyka_Donation($donation); $campaign = new Leyka_Campaign($donation->campaign_id); $donation_fields = array(prep(wp_hash($domain . $donation->date_timestamp . $donation->sum . $donation->id)), prep($domain), prep(leyka_options()->opt('org_full_name')), prep($donation->date_timestamp), prep(date(get_option('date_format') . ', H:i', $donation->date_timestamp)), prep(wp_hash($donation->donor_email)), prep(wp_hash($donation->donor_name)), prep((int) $donation->sum), prep($donation->currency), $donation->payment_type == 'correction' ? prep($donation->pm_id) : prep($donation->gateway_label . '-' . $donation->pm_id), prep($donation->status), prep($campaign->title), prep($campaign->url), prep($campaign->payment_title), prep((int) $campaign->target), prep($campaign->target_state), prep((int) $campaign->is_finished)); $file_lines[] = $donation_fields; } for ($i = 0; $i < count($file_lines); $i++) { $file_lines[$i] = implode(';', $file_lines[$i]); } ob_clean(); header('Content-type: application/vnd.ms-excel'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Pragma: no-cache'); header('Content-Disposition: attachment; filename="donations-tech-' . $domain . '-' . date('d.m.Y-H.i.s') . '.csv"'); die("sep=;\n" . implode("\r\n", $file_lines)); } else { $file_lines = array(apply_filters('leyka_donations_export_headers', array('ID', 'Имя донора', 'Email', 'Тип платежа', 'Способ платежа', 'Сумма', 'Дата пожертвования', 'Статус', 'Кампания'))); foreach ($donations as $donation) { $donation = new Leyka_Donation($donation); $campaign = new Leyka_Campaign($donation->campaign_id); $donation_fields = apply_filters('leyka_donations_export_line', array($donation->id, $donation->donor_name, $donation->donor_email, $donation->payment_type_label, $donation->payment_method_label, $donation->sum . ' ' . $donation->currency_label, $donation->date, $donation->status_label, $campaign->title)); $file_lines[] = $donation_fields; } require_once LEYKA_PLUGIN_DIR . 'inc/excel-writer/SimpleExcel.php'; $excel = new SimpleExcel('csv'); $excel->writer->setData($file_lines); $excel->writer->setDelimiter(','); ob_clean(); header('Content-type: application/vnd.ms-excel'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Pragma: no-cache'); header('Content-Disposition: attachment; filename="donations-' . date('d.m.Y-H.i.s') . '.csv"'); // Do iconv so Excel could open it: die(iconv('UTF-8', apply_filters('leyka_donations_export_content_charset', 'windows-1251'), "sep=,\n" . $excel->writer->saveString())); } }
public static function process_form_default($gateway_id, $pm_id, $donation_id, $form_data) { if (empty($form_data['leyka_donation_amount']) || (double) $form_data['leyka_donation_amount'] <= 0) { $error = new WP_Error('wrong_donation_amount', __('Donation amount must be specified to submit the form', 'leyka')); leyka()->add_payment_form_error($error); } $currency = $form_data['leyka_donation_currency']; if (empty($currency)) { $error = new WP_Error('wrong_donation_currency', __('Wrong donation currency in submitted form data', 'leyka')); leyka()->add_payment_form_error($error); } if (!empty($form_data['top_' . $currency]) && $form_data['leyka_donation_amount'] > $form_data['top_' . $currency]) { $top_amount_allowed = $form_data['top_' . $currency]; $error = new WP_Error('donation_amount_too_great', sprintf(__('Donation amount you entered is too great (maximum %s allowed)', 'leyka'), $top_amount_allowed . ' ' . leyka_options()->opt("currency_{$currency}_label"))); leyka()->add_payment_form_error($error); } if (!empty($form_data['bottom_' . $currency]) && $form_data['leyka_donation_amount'] < $form_data['bottom_' . $currency]) { $bottom_amount_allowed = $form_data['bottom_' . $currency]; $error = new WP_Error('donation_amount_too_small', sprintf(__('Donation amount you entered is too small (minimum %s allowed)', 'leyka'), $bottom_amount_allowed . ' ' . leyka_options()->opt("currency_{$currency}_label"))); leyka()->add_payment_form_error($error); } if (empty($form_data['leyka_agree']) && leyka_options()->opt('argee_to_terms_needed')) { $error = new WP_Error('terms_not_agreed', __('You must agree to the terms of donation service', 'leyka')); leyka()->add_payment_form_error($error); } }
</head> <body> <div> <?php echo apply_filters('leyka_gateway_redirect_message', __('<h3>Thank you!</h3><p>In a few seconds you will be redirected to the payment system website, where you can complete your donation.</p>', 'leyka')); ?> </div> <form id='leyka-auto-submit' action='<?php echo leyka()->payment_url; ?> ' method='post'> <?php foreach (leyka()->payment_vars as $name => $value) { echo "<input type='hidden' name='{$name}' value='{$value}' />"; } ?> <noscript> <div><?php echo __('If you are not redirected to the payment page automatically, please press this button', 'leyka'); ?> </div> <input type="submit" name="leyka-gateway-submit" value="<?php echo __('Proceed to the payment approval page', 'leyka'); ?> " /> </noscript>