本文整理汇总了PHP中leyka_options函数的典型用法代码示例。如果您正苦于以下问题:PHP leyka_options函数的具体用法?PHP leyka_options怎么用?PHP leyka_options使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了leyka_options函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: leyka_save_settings
function leyka_save_settings($tab_name)
{
$options_names = array();
foreach (leyka_opt_alloc()->get_tab_options($tab_name) as $entry) {
if (is_array($entry)) {
foreach ($entry as $key => $option) {
if ($key == 'section') {
$options_names = array_merge($options_names, $option['options']);
} else {
$options_names[] = $option;
}
}
} else {
$options_names[] = $entry;
}
}
foreach ($options_names as $name) {
$option_type = leyka_options()->get_type_of($name);
if ($option_type == 'checkbox') {
leyka_options()->opt($name, isset($_POST["leyka_{$name}"]) ? 1 : 0);
} elseif ($option_type == 'multi_checkbox') {
if (isset($_POST["leyka_{$name}"]) && leyka_options()->opt($name) != $_POST["leyka_{$name}"]) {
leyka_options()->opt($name, (array) $_POST["leyka_{$name}"]);
}
} elseif ($option_type == 'html' || $option_type == 'rich_html') {
if (isset($_POST["leyka_{$name}"]) && leyka_options()->opt($name) != $_POST["leyka_{$name}"]) {
leyka_options()->opt($name, esc_attr(stripslashes($_POST["leyka_{$name}"])));
}
} else {
if (isset($_POST["leyka_{$name}"]) && leyka_options()->opt($name) != $_POST["leyka_{$name}"]) {
leyka_options()->opt($name, esc_attr(stripslashes($_POST["leyka_{$name}"])));
}
}
}
}
示例2: leyka_render_section_area
function leyka_render_section_area($section)
{
?>
<div class="leyka-options-section <?php
echo $section['is_default_collapsed'] ? 'collapsed' : '';
?>
" id="<?php
echo $section['name'];
?>
">
<div class="header"><h3><?php
echo esc_attr($section['title']);
?>
</h3></div>
<div class="content">
<?php
foreach ($section['options'] as $option) {
$option_info = leyka_options()->get_info_of($option);
do_action("leyka_render_{$option_info['type']}", $option, $option_info);
}
?>
</div>
</div>
<?php
}
示例3: _handle_service_calls
public function _handle_service_calls($call_type = '')
{
if (empty($_POST['orderId'])) {
$message = __("This message has been sent because a call to your RBK Money callback was made without orderId parameter given. The details of the call are below.", 'leyka') . "\n\r\n\r";
$message .= "THEIR_POST:\n\r" . print_r($_POST, true) . "\n\r\n\r";
$message .= "GET:\n\r" . print_r($_GET, true) . "\n\r\n\r";
$message .= "SERVER:\n\r" . print_r($_SERVER, true) . "\n\r\n\r";
wp_mail(get_option('admin_email'), __('RBK Money - orderId missing!', 'leyka'), $message);
status_header(200);
die;
}
$donation = new Leyka_Donation((int) stripslashes($_POST['orderId']));
if (!$donation) {
status_header(200);
die;
}
// Test for e-sign:
if (leyka_options()->opt('rbk_use_hash')) {
$sign = hash(leyka_options()->opt('rbk_hash_type'), implode('::', array(leyka_options()->opt('rbk_eshop_id'), $_POST['orderId'], $_POST['serviceName'], leyka_options()->opt('rbk_eshop_account'), $donation->amount, mb_strtoupper($donation->currency), $_POST['paymentStatus'], $_POST['userName'], $donation->donor_email, $_POST['paymentData'], leyka_options()->opt('rbk_secret_key'))));
if (empty($_POST['hash']) || $sign != trim(mb_strtolower($_POST['hash']))) {
$message = __("This message has been sent because a call to your RBK Money callback was called with wrong data hash. This could mean someone is trying to hack your payment site. The details of the call are below.", 'leyka') . "\n\r\n\r";
$message .= "POST:\n\r" . print_r($_POST, true) . "\n\r\n\r";
$message .= "GET:\n\r" . print_r($_GET, true) . "\n\r\n\r";
$message .= "SERVER:\n\r" . print_r($_SERVER, true) . "\n\r\n\r";
wp_mail(get_option('admin_email'), __('RBK Money hash check failed!', 'leyka'), $message);
status_header(200);
die;
}
}
// Single payment:
switch ($_POST['paymentStatus']) {
case 4:
$new_status = 'failed';
break;
case 5:
$new_status = 'funded';
break;
default:
$new_status = 'submitted';
}
if ($donation->status != $new_status) {
$donation->add_gateway_response($_POST);
$donation->status = $new_status;
if (!$donation->donor_email && !empty($_POST['userEmail'])) {
$donation->donor_email = $_POST['userEmail'];
}
if (!$donation->donor_name && !empty($_POST['userName'])) {
$donation->donor_name = $_POST['userName'];
}
Leyka_Donation_Management::send_all_emails($donation->id);
}
status_header(200);
die;
}
示例4: leyka_add_gateway_metabox
function leyka_add_gateway_metabox($post, $args)
{
// $post is always null
/** @var Leyka_Gateway $gateway */
$gateway = $args['args']['gateway'];
$pm_active = leyka_options()->opt('pm_available');
?>
<div>
<?php
foreach ($gateway->get_payment_methods() as $pm) {
?>
<div>
<input type="checkbox" name="leyka_pm_available[]" value="<?php
echo $pm->full_id;
?>
" class="pm-active" id="<?php
echo $pm->full_id;
?>
" data-pm-label="<?php
echo $pm->title_backend;
?>
" data-pm-label-backend="<?php
echo $pm->label_backend;
?>
" <?php
echo in_array($pm->full_id, $pm_active) ? 'checked="checked"' : '';
?>
>
<label for="<?php
echo $pm->full_id;
?>
"><?php
echo $pm->title_backend;
?>
</label>
</div>
<?php
}
?>
</div>
<?php
}
示例5: process_form
public function process_form($gateway_id, $pm_id, $donation_id, $form_data)
{
load_textdomain('leyka', LEYKA_PLUGIN_DIR . 'lang/leyka-' . get_locale() . '.mo');
// Localize a quittance first
header('HTTP/1.1 200 OK');
header('Content-Type: text/html; charset=utf-8');
$campaign = new Leyka_Campaign($form_data['leyka_campaign_id']);
$quittance_html = str_replace(array('#BACK_TO_DONATION_FORM_TEXT#', '#PRINT_THE_QUITTANCE_TEXT#', '#QUITTANCE_RECEIVED_TEXT#', '#SUCCESS_URL#', '#PAYMENT_COMMENT#', '#PAYER_NAME#', '#RECEIVER_NAME#', '#SUM#', '#INN#', '#KPP#', '#ACC#', '#RECEIVER_BANK_NAME#', '#BIC#', '#CORR#'), array(__('Return to the donation form', 'leyka'), __('Print the quittance', 'leyka'), __("OK, I've received the quittance", 'leyka'), get_permalink(leyka_options()->opt('quittance_redirect_page')), $campaign->payment_title . " (№ {$donation_id})", $form_data['leyka_donor_name'], leyka_options()->opt('org_full_name'), (int) $form_data['leyka_donation_amount'], leyka_options()->opt('org_inn'), leyka_options()->opt('org_kpp'), leyka_options()->opt('org_bank_account'), leyka_options()->opt('org_bank_name'), leyka_options()->opt('org_bank_bic'), leyka_options()->opt('org_bank_corr_account')), $this->_payment_methods[$pm_id]->get_quittance_html());
for ($i = 0; $i < 10; $i++) {
$quittance_html = str_replace("#INN_{$i}#", substr(leyka_options()->opt('org_inn'), $i, 1), $quittance_html);
}
for ($i = 0; $i < 20; $i++) {
$quittance_html = str_replace("#ACC_{$i}#", substr(leyka_options()->opt('org_bank_account'), $i, 1), $quittance_html);
}
for ($i = 0; $i < 9; $i++) {
$quittance_html = str_replace("#BIC_{$i}#", substr(leyka_options()->opt('org_bank_bic'), $i, 1), $quittance_html);
}
for ($i = 0; $i < 20; $i++) {
$quittance_html = str_replace("#CORR_{$i}#", substr(leyka_options()->opt('org_bank_corr_account'), $i, 1), $quittance_html);
}
die($quittance_html);
}
示例6: _handle_service_calls
public function _handle_service_calls($call_type = '')
{
error_log_yandex_phyz("\n\n---- {$call_type} ----\n\n" . print_r($_REQUEST, true));
$donation_id = (int) @$_POST['label'];
// Donation ID
$amount = (int) @$_POST['withdraw_amount'];
error_log_yandex_phyz("Label={$donation_id}\n");
error_log_yandex_phyz("Amount={$amount}\n");
if (!$donation_id) {
error_log_yandex_phyz("Label is empty\n");
return;
}
$donation = new Leyka_Donation($donation_id);
error_log_yandex_phyz("Donation initialized\n");
error_log_yandex_phyz(print_r($donation, TRUE) . "\n");
$params_to_sha1 = implode('&', array(@$_POST['notification_type'], @$_POST['operation_id'], @$_POST['amount'], @$_POST['currency'], @$_POST['datetime'], @$_POST['sender'], @$_POST['codepro'], leyka_options()->opt('yandex_money_secret'), @$_POST['label']));
error_log_yandex_phyz("Params_to_sha1={$params_to_sha1}\n");
$sha1 = sha1($params_to_sha1);
error_log_yandex_phyz("sha1={$sha1}\n");
if ($sha1 != @$_POST['sha1_hash']) {
error_log_yandex_phyz("Invalid response sha1_hash\n");
$this->_check_order_answer(1, __('Sorry, there is some tech error on our side. Your payment will be cancelled.', 'leyka'), __('Invalid response sha1_hash', 'leyka'));
} elseif ($donation) {
error_log_yandex_phyz("Donation OK\n");
error_log_yandex_phyz('$donation->sum=' . $donation->sum . "\n");
error_log_yandex_phyz('$donation->status=' . $donation->status . "\n");
if ($donation->sum != $amount) {
error_log_yandex_phyz("Donation sum is unmatched\n");
$this->_check_order_answer(1, __('Sorry, there is some tech error on our side. Your payment will be cancelled.', 'leyka'), __('Donation sum is unmatched', 'leyka'));
} elseif ($donation->status != 'funded') {
error_log_yandex_phyz("Donation is funded\n");
if (!empty($_POST['notification_type'])) {
// Update a donation's actual PM, if needed
$actual_pm = $_POST['notification_type'] == 'card-incoming' ? 'yandex_phyz_card' : 'yandex_phyz_money';
if ($donation->pm_id != $_POST['notification_type']) {
$donation->pm_id = $actual_pm;
}
}
$donation->add_gateway_response($_POST);
$donation->status = 'funded';
Leyka_Donation_Management::send_all_emails($donation->id);
} else {
error_log_yandex_phyz("Already funded\n");
}
$this->_check_order_answer();
} else {
error_log_yandex_phyz("There is no donation in Leyka DB\n");
$this->_check_order_answer(1, __('Sorry, there is some tech error on our side. Your payment will be cancelled.', 'leyka'), __('Unregistered donation ID', 'leyka'));
}
}
示例7: load_textdomain
$locale = 'en_US';
}
load_textdomain('leyka', LEYKA_PLUGIN_DIR . "lang/leyka-{$locale}.mo");
do_action('leyka_init_actions');
} else {
// $locale = is_admin() ? pll_default_language('locale') : pll_current_language('locale');
if (is_admin() && !did_action('leyka_init_actions')) {
do_action('leyka_init_actions');
if (count(pll_languages_list()) > 1) {
// Register user-defined strings:
foreach (leyka_options()->get_options_names() as $option) {
$option_data = leyka_options()->get_info_of($option);
if ($option_data['type'] == 'text') {
pll_register_string($option_data['title'], $option_data['value'], 'leyka');
} elseif ($option_data['type'] == 'textarea' || $option_data['type'] == 'html' || $option_data['type'] == 'rich_html') {
pll_register_string($option_data['title'], leyka_options()->opt($option), 'leyka', true);
}
}
}
}
add_action('leyka_default_success_page_created', function ($page_id) {
// echo '<pre>' . print_r($page_id, 1) . '</pre>';
// die('<pre>' . print_r(pll_default_language(), 1) . '</pre>');
// ... get localized strings from PL and update success page params
});
// leyka_donation post type must not be included - there's no need to translate it:
$leyka_post_types = array(Leyka_Campaign_Management::$post_type);
if ($leyka_post_types != $polylang->options['post_types']) {
$polylang->options['post_types'] = $polylang->options['post_types'] + $leyka_post_types;
update_option('polylang', $polylang->options);
}
示例8: add_action
</div>
</form>
</div>
</div>
<?php
}
//add agree modal to footer
add_action('wp_footer', function () {
?>
<div id="leyka-agree-text" class="leyka-oferta-text leyka-custom-modal">
<div class="leyka-modal-close">
<?php
echo tst_material_icon('close');
?>
</div>
<div class="leyka-oferta-text-frame">
<div class="leyka-oferta-text-flow">
<?php
echo apply_filters('leyka_terms_of_service_text', leyka_options()->opt('terms_of_service_text'));
?>
</div>
</div>
</div>
<?php
});
leyka_pf_footer();
?>
</div><!-- #leyka-payment-form -->
示例9: foreach
foreach ($icons as $i) {
$list[] = "<li>{$i}</li>";
}
echo '<ul class="leyka-pm-icons cf">' . implode('', $list) . '</ul>';
}
?>
</div> <!-- .leyka-pm-fields -->
<?php
echo "<div class='leyka-pm-desc'>" . apply_filters('leyka_the_content', leyka_pf_get_pm_description()) . "</div>";
?>
</form>
</div>
</div>
<?php
}
?>
<?php
if (leyka_options()->opt('show_campaign_sharing')) {
leyka_share_campaign_block();
}
leyka_pf_footer();
?>
</div><!-- #leyka-payment-form -->
示例10: _callback_answer
/** Wrapper method to answer checkOrder and paymentAviso service calls */
private function _callback_answer($is_error = false, $callback_type = 'co', $message = '', $tech_message = '')
{
$is_error = !!$is_error;
$tech_message = $tech_message ? $tech_message : $message;
$callback_type = $callback_type == 'co' ? 'checkOrderResponse' : 'paymentAvisoResponse';
if ($is_error) {
die('<?xml version="1.0" encoding="UTF-8"?>
<' . $callback_type . ' performedDatetime="' . date(DATE_ATOM) . '"
code="1000" invoiceId="' . $_POST['invoiceId'] . '"
shopId="' . leyka_options()->opt('yandex_shop_id') . '"
message="' . $message . '"
techMessage="' . $tech_message . '"/>');
}
die('<?xml version="1.0" encoding="UTF-8"?>
<' . $callback_type . ' performedDatetime="' . date(DATE_ATOM) . '"
code="0" invoiceId="' . $_POST['invoiceId'] . '"
shopId="' . leyka_options()->opt('yandex_shop_id') . '"/>');
}
示例11: settings_screen
/** Displaying settings **/
public function settings_screen()
{
/* Capability test */
if (!current_user_can('leyka_manage_options')) {
wp_die(__('You do not have permissions to access this page.', 'leyka'));
}
$current_stage = $this->get_current_settings_tab();
require LEYKA_PLUGIN_DIR . 'inc/settings-pages/leyka-settings-common.php';
/* Page actions */
do_action('leyka_pre_settings_actions', $current_stage);
/** Process settings change */
if (!empty($_POST["leyka_settings_{$current_stage}_submit"])) {
do_action("leyka_settings_{$current_stage}_submit", $current_stage);
}
?>
<div class="wrap">
<h2 class="nav-tab-wrapper"><?php
echo $this->settings_tabs_menu();
?>
</h2>
<div id="tab-container">
<form method="post" action="<?php
echo admin_url(add_query_arg('stage', $current_stage, 'admin.php?page=leyka_settings'));
?>
" id="leyka-settings-form">
<?php
wp_nonce_field("leyka_settings_{$current_stage}", '_leyka_nonce');
if (file_exists(LEYKA_PLUGIN_DIR . "inc/settings-pages/leyka-settings-{$current_stage}.php")) {
require LEYKA_PLUGIN_DIR . "inc/settings-pages/leyka-settings-{$current_stage}.php";
} else {
do_action("leyka_settings_pre_{$current_stage}_fields");
foreach (leyka_opt_alloc()->get_tab_options($current_stage) as $option) {
// Render each option/section
if (is_array($option) && !empty($option['section'])) {
do_action('leyka_render_section', $option['section']);
} else {
// is this case possible?
$option_info = leyka_options()->get_info_of($option);
do_action("leyka_render_{$option_info['type']}", $option, $option_info);
}
}
do_action("leyka_settings_post_{$current_stage}_fields");
?>
<p class="submit">
<input type="submit" name="<?php
echo "leyka_settings_{$current_stage}";
?>
_submit" value="<?php
_e('Save settings', 'leyka');
?>
" class="button-primary" />
</p>
<?php
}
?>
</form>
<!-- --><?php
//do_action("leyka_settings_post_{$current_stage}_form");
?>
</div>
</div><!-- close .wrap -->
<?php
}
示例12: leyka_is_min_payment_settings_complete
function leyka_is_min_payment_settings_complete()
{
$pm_list = leyka_get_pm_list(true);
if (!$pm_list) {
return false;
}
$gateway_options_valid = array();
// Array of already validated gateways
foreach ($pm_list as $pm) {
/** @var $pm Leyka_Payment_Method */
$gateway = leyka_get_gateway_by_id($pm->gateway_id);
if (!$pm || !$gateway) {
continue;
}
$min_settings_complete = true;
foreach ($pm->get_pm_options_names() as $option_name) {
if (!leyka_options()->is_valid($option_name)) {
$min_settings_complete = false;
break;
}
}
if (!isset($gateway_options_valid[$gateway->id])) {
foreach ($gateway->get_options_names() as $option_name) {
if (!leyka_options()->is_valid($option_name)) {
$gateway_options_valid[$gateway->id] = false;
break;
}
}
if (!isset($gateway_options_valid[$gateway->id])) {
$gateway_options_valid[$gateway->id] = true;
}
}
if ($min_settings_complete && !empty($gateway_options_valid[$gateway->id])) {
return true;
}
}
return false;
}
示例13: activate
/**
* Fired when the plugin is activated or when an update is needed.
*/
public static function activate()
{
$leyka_last_ver = get_option('leyka_last_ver');
if ($leyka_last_ver && $leyka_last_ver == LEYKA_VERSION) {
// Already at last version
return;
}
if (!$leyka_last_ver || $leyka_last_ver < '2.1') {
/** Upgrade options structure in the DB */
if (get_option('leyka_modules')) {
delete_option('leyka_modules');
}
if (get_option('leyka_options_installed')) {
delete_option('leyka_options_installed');
}
require_once LEYKA_PLUGIN_DIR . 'inc/leyka-options-meta.php';
foreach (leyka_options()->get_options_names() as $name) {
$option = get_option("leyka_{$name}");
if (is_array($option) && isset($option['type']) && isset($option['title'])) {
// Update option data
update_option("leyka_{$name}", $option['value']);
}
}
// Mostly to initialize gateways' and PM's options before updating them:
// if( !did_action('leyka_init_actions') )
// do_action('leyka_init_actions');
/** Upgrade gateway and PM options structure in the DB */
foreach (leyka_get_gateways() as $gateway) {
/** @var $gateway Leyka_Gateway */
delete_option("leyka_{$gateway->id}_payment_methods");
foreach ($gateway->get_options_names() as $name) {
$option = get_option("leyka_{$name}");
if (is_array($option) && isset($option['type']) && isset($option['title'])) {
// Update option data
update_option("leyka_{$name}", $option['value']);
}
}
foreach ($gateway->get_payment_methods() as $pm) {
/** @var $pm Leyka_Payment_Method */
foreach ($pm->get_pm_options_names() as $name) {
$option = get_option("leyka_{$name}");
if (is_array($option) && isset($option['type']) && isset($option['title'])) {
// Update option data
update_option("leyka_{$name}", $option['value']);
}
}
}
}
}
if (!$leyka_last_ver || $leyka_last_ver <= '2.2.5') {
// Initialize pm_order option if needed:
if (!get_option('leyka_pm_order')) {
$pm_order = array();
foreach ((array) get_option('leyka_pm_available') as $pm_full_id) {
if ($pm_full_id) {
$pm_order[] = "pm_order[]={$pm_full_id}";
}
}
update_option('leyka_pm_order', implode('&', $pm_order));
}
// Remove an unneeded scripts for settings pages:
$settings_pages_dir = dir(LEYKA_PLUGIN_DIR . 'inc/settings-pages/');
while (false !== ($script = $settings_pages_dir->read())) {
if ($script != '.' && $script != '..' && !in_array($script, array('leyka-settings-common.php', 'leyka-settings-payment.php'))) {
unlink(LEYKA_PLUGIN_DIR . 'inc/settings-pages/' . $script);
}
}
$settings_pages_dir->close();
// Remove an obsolete plugin options:
$options = array(array('old' => 'chronopay_card_description', 'new' => 'chronopay-chronopay_card_description'), array('old' => 'chronopay_card_rebill_description', 'new' => 'chronopay-chronopay_card_rebill_description'), array('old' => 'bank_order_description', 'new' => 'quittance-bank_order_description'), array('old' => 'bankcard_description', 'new' => 'rbk-bankcard_description'), array('old' => 'rbkmoney_description', 'new' => 'rbk-rbkmoney_description'), array('old' => 'rbk_all_description', 'new' => 'rbk-rbk_all_description'), array('old' => 'robokassa_card_description', 'new' => 'robokassa-BANKOCEAN2_description'), array('old' => 'robokassa_yandex_money_description', 'new' => 'robokassa-YandexMerchantOcean_description'), array('old' => 'robokassa_webmoney_description', 'new' => 'robokassa-WMR_description'), array('old' => 'robokassa_qiwi_description', 'new' => 'robokassa-Qiwi30Ocean_description'), array('old' => 'robokassa_all_description', 'new' => 'robokassa-Other_description'), array('old' => 'text_box_description', 'new' => 'text-text_box_description'), array('old' => 'yandex_card_description', 'new' => 'yandex-yandex_card_description'), array('old' => 'yandex_money_description', 'new' => 'yandex-yandex_money_description'), array('old' => 'yandex_wm_description', 'new' => 'yandex-yandex_wm_description'), array('old' => 'yandex_phyz_card_description', 'new' => 'yandex_phyz-yandex_phyz_card_description'), array('old' => 'yandex_phyz_money_description', 'new' => 'yandex_phyz-yandex_phyz_money_description'));
foreach ($options as $option) {
$old_value = get_option("leyka_{$option['old']}");
$new_value = get_option("leyka_{$option['new']}");
if ($old_value && $old_value != $new_value) {
update_option("leyka_{$option['new']}", $old_value);
}
delete_option("leyka_{$option['old']}");
}
}
/**
* Fix the bug when total_funded amount of campaign was calculated incorrectly
* if there were correctional donations for that campaign.
*/
if ($leyka_last_ver && $leyka_last_ver >= '2.2.5' && $leyka_last_ver <= '2.2.7.2') {
function leyka_update_campaigns_total_funded()
{
set_time_limit(3600);
wp_suspend_cache_addition(true);
$campaigns = get_posts(array('post_type' => Leyka_Campaign_Management::$post_type, 'nopaging' => true, 'post_status' => 'any'));
foreach ($campaigns as $campaign) {
$campaign = new Leyka_Campaign($campaign);
$campaign->update_total_funded_amount();
}
wp_suspend_cache_addition(false);
}
add_action('init', 'leyka_update_campaigns_total_funded', 100);
}
//.........这里部分代码省略.........
示例14: _set_dynamic_attributes
protected function _set_dynamic_attributes()
{
$this->_custom_fields = array('box_details' => apply_filters('leyka_the_content', leyka_options()->opt_safe('text_box_details')));
}
示例15: leyka_do_donations_export
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()));
}
}