Exemplo n.º 1
0
 /**
  * Fired when the plugin is activated or when an update is needed.
  * @param boolean $network_wide True if WPMU superadmin uses "Network Activate" action,
  * false if WPMU is disabled or plugin is activated on an individual blog.
  */
 public static function activate($network_wide)
 {
     $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';
         global $options_meta;
         foreach ($options_meta as $name => $meta) {
             $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']}");
         }
     }
     /** Set a flag to flush permalinks (needs to be done a bit later, than this activation itself): */
     update_option('leyka_permalinks_flushed', 0);
     update_option('leyka_last_ver', LEYKA_VERSION);
 }
Exemplo n.º 2
0
    public function donation_data_metabox(WP_Post $donation)
    {
        $donation = new Leyka_Donation($donation);
        $campaign = new Leyka_Campaign($donation->campaign_id);
        ?>

	<fieldset class="leyka-set campaign">
		<legend><?php 
        _e('Campaign Data', 'leyka');
        ?>
</legend>

        <div class="leyka-ddata-string">			
			<label><?php 
        _e('Campaign', 'leyka');
        ?>
:</label>
			<div class="leyka-ddata-field">
			<?php 
        if ($campaign->id && $campaign->status == 'publish') {
            ?>
			<span class="text-line">
            <span class="campaign-name"><?php 
            echo $campaign->title;
            ?>
</span> <span class="campaign-actions"><a href="<?php 
            echo admin_url('/post.php?action=edit&post=' . $campaign->id);
            ?>
"><?php 
            _e('Edit campaign', 'leyka');
            ?>
</a> <a href="<?php 
            echo $campaign->url;
            ?>
" target="_blank"><?php 
            _e('Preview campaign', 'leyka');
            ?>
</a></span></span>

			<?php 
        } else {
            echo '<span class="text-line">' . __('the campaign has been removed or drafted', 'leyka') . '</span>';
        }
        ?>
			</div>
		</div>

		<div class="leyka-ddata-string">
			<label><?php 
        _e('Donation purpose', 'leyka');
        ?>
:</label>
			<div class="leyka-ddata-field"><span class="text-line">
			<?php 
        echo $campaign->id ? $campaign->payment_title : $donation->title;
        ?>
			</span></div>
        </div>

		<div class="set-action">
            <div id="campaign-select-trigger" class="button"><?php 
        _e('Connect this donation to another campaign', 'leyka');
        ?>
</div>

            <div id="campaign-select-fields" style="display: none;">
                <label for="campaign-select"></label>
                <input id="campaign-select"
                       type="text"
                       data-nonce="<?php 
        echo wp_create_nonce('leyka_get_campaigns_list_nonce');
        ?>
"
                       placeholder="<?php 
        _e('Please, enter campaign title', 'leyka');
        ?>
"
                       value="<?php 
        echo htmlentities($campaign->title, ENT_COMPAT, 'UTF-8');
        ?>
"
                    />
                <input id="campaign-id" type="hidden" name="campaign-id" value="<?php 
        echo $campaign->id;
        ?>
" />
                <div id="cancel-campaign-select" class="button"><?php 
        _e('Cancel', 'leyka');
        ?>
</div>
            </div>
		</div> <!-- .set-action -->
        
	</fieldset>
	
	<fieldset class="leyka-set donor">
		<legend><?php 
        _e('Donor Data', 'leyka');
        ?>
</legend>
		
		<div class="leyka-ddata-string">
            <label for="donor-name"><?php 
        _e('Name', 'leyka');
        ?>
:</label>
			<div class="leyka-ddata-field">

            <?php 
        if ($donation->type == 'correction') {
            ?>

                <input type="text" id="donor-name" name="donor-name" placeholder="<?php 
            _e("Enter donor's name, or leave it empty for anonymous donation", 'leyka');
            ?>
" value="<?php 
            echo $donation->donor_name;
            ?>
" />
            <?php 
        } else {
            ?>

                <span class="fake-input"><?php 
            echo $donation->donor_name ? $donation->donor_name : __('Anonymous', 'leyka');
            ?>
</span>
            <?php 
        }
        ?>

            </div>
        </div>
			
		<div class="leyka-ddata-string">
            <label for="donor-email"><?php 
        _e('Email', 'leyka');
        ?>
:</label>
			<div class="leyka-ddata-field">
            <?php 
        if ($donation->type == 'correction') {
            ?>

                <input type="text" id="donor-email" name="donor-email" placeholder="<?php 
            _e("Enter donor's email", 'leyka');
            ?>
" value="<?php 
            echo $donation->donor_email;
            ?>
" />
                <div id="donor_email-error" class="field-error"></div>

            <?php 
        } else {
            ?>

                <span class="fake-input"><?php 
            echo $donation->donor_email ? $donation->donor_email : '&ndash;';
            ?>
</span>
            <?php 
        }
        ?>
            </div>
        </div>
			
	</fieldset>
	
	<fieldset class="leyka-set donation">
		<legend><?php 
        _e('Donation Data', 'leyka');
        ?>
</legend>
        
        <div class="leyka-ddata-string">
            <label><?php 
        _e('Amount', 'leyka');
        ?>
:</label>
			<div class="leyka-ddata-field">
            <?php 
        if ($donation->type == 'correction') {
            ?>

                <input type="text" id="donation-amount" name="donation-amount" placeholder="<?php 
            _e("Enter a donation's amount", 'leyka');
            ?>
" value="<?php 
            echo $donation->amount;
            ?>
" /> <?php 
            echo $donation->currency_label;
            ?>

                <div id="donation_amount-error" class="field-error"></div>

            <?php 
        } else {
            ?>

                <span class="fake-input"><?php 
            echo $donation->amount ? $donation->amount . ' ' . $donation->currency_label : '';
            ?>
</span>
            <?php 
        }
        ?>
            </div>
        </div>

        <div class="leyka-ddata-string">
            <label><?php 
        _e('Payment method', 'leyka');
        ?>
:</label>
			<div class="leyka-ddata-field">
            <?php 
        if ($donation->type == 'correction') {
            ?>

                <select id="donation-pm" name="donation-pm">
                    <option value="" selected="selected"><?php 
            _e('Select a payment method', 'leyka');
            ?>
</option>
                    <?php 
            foreach (leyka_get_gateways() as $gateway) {
                /** @var Leyka_Gateway $gateway */
                $pm_list = $gateway->get_payment_methods();
                if ($pm_list) {
                    ?>

                            <optgroup label="<?php 
                    echo $gateway->name;
                    ?>
">
                            <?php 
                    foreach ($pm_list as $pm) {
                        ?>
                                <option value="<?php 
                        echo $pm->full_id;
                        ?>
" <?php 
                        echo $donation->gateway_id == $gateway->id && $donation->pm_id == $pm->id ? 'selected="selected"' : '';
                        ?>
><?php 
                        echo $pm->name;
                        ?>
</option>
                            <?php 
                    }
                    ?>
                            </optgroup>

                        <?php 
                }
                ?>

                    <?php 
            }
            ?>
                    <option value="custom" <?php 
            echo $donation->gw_id == '' && $donation->pm_id ? 'selected="selected"' : '';
            ?>
><?php 
            _e('Custom payment info', 'leyka');
            ?>
</option>
                </select>

                <input type="text" id="custom-payment-info" name="custom-payment-info" placeholder="<?php 
            _e('Enter some info about source of a new donation', 'leyka');
            ?>
" <?php 
            echo $donation->gw_id == '' && $donation->pm_id ? '' : 'style="display: none;"';
            ?>
 value="<?php 
            echo $donation->gw_id == '' ? $donation->pm_id : '';
            ?>
" />

            <?php 
        } else {
            ?>

                <span class="fake-input">
                <?php 
            $pm = leyka_get_pm_by_id($donation->payment_method);
            $gateway = leyka_get_gateway_by_id($donation->gateway_id);
            echo ($pm ? $pm->label : __('Unknown payment method', 'leyka')) . ' (' . ($gateway ? $gateway->label : __('unknown gateway', 'leyka')) . ')';
            ?>
			    </span>
            <?php 
        }
        ?>
            </div>
        </div>

        <div class="leyka-ddata-string">
            <?php 
        leyka_get_gateway_by_id($donation->gateway_id)->display_donation_specific_data_fields($donation);
        ?>
        </div>

        <div class="leyka-ddata-string">
            <label><?php 
        _e('Payment type', 'leyka');
        ?>
:</label>
			<div class="leyka-ddata-field">
                <span class="fake-input"><?php 
        echo leyka_get_payment_type_label($donation->payment_type);
        // "single", "rebill", "correction"
        ?>
</span>
            </div>
        </div>
        <?php 
        if ($donation->init_recurring_donation_id) {
            ?>
        <div class="leyka-ddata-string">
            <label><?php 
            _e('Initial donation of the recurring subscription', 'leyka');
            ?>
:</label>
            <div class="leyka-ddata-field">
                <a href="<?php 
            echo admin_url('post.php?post=' . $donation->init_recurring_donation_id . '&action=edit');
            ?>
">#<?php 
            echo $donation->init_recurring_donation_id;
            ?>
</a></span>
            </div>
        </div>
        <?php 
        }
        ?>

        <div class="leyka-ddata-string">
            <label for="donation-date-view"><?php 
        _e('Donation date', 'leyka');
        ?>
:</label>
			<div class="leyka-ddata-field">
            <?php 
        if ($donation->type == 'correction') {
            ?>

                <input type="text" id="donation-date-view" value="<?php 
            echo date(get_option('date_format'), $donation->date_timestamp);
            ?>
" />
                <input type="hidden" id="donation-date" name="donation_date" value="<?php 
            echo date('Y-m-d', $donation->date_timestamp);
            ?>
" />
            <?php 
        } else {
            ?>

                <span class="fake-input"><?php 
            echo $donation->date;
            ?>
</span>
            <?php 
        }
        ?>
            </div>
        </div>
	</fieldset>

	<?php 
    }
$pm_available = leyka_options()->opt('pm_available');
$active_gateways = array();
foreach ($pm_available as $pm_full_id) {
    $gateway_id = explode('-', $pm_full_id);
    $gateway_id = reset($gateway_id);
    // Strict standards
    if (!in_array($gateway_id, $active_gateways)) {
        $active_gateways[] = $gateway_id;
    }
}
?>


            <div id="pm-settings-wrapper">
            <?php 
foreach (leyka_get_gateways() as $gateway) {
    /** @var $gateway Leyka_Gateway */
    ?>


                <div id="gateway-<?php 
    echo $gateway->id;
    ?>
" class="gateway-settings" <?php 
    echo in_array($gateway->id, $active_gateways) ? '' : 'style="display:none;"';
    ?>
>
                    <h3 class="accordion-section-title">
                        <?php 
    echo leyka_gateway_admin_icon_markup($gateway) . $gateway->title;
    ?>
Exemplo n.º 4
0
 /**
  * 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);
     }
     /** Fix the typo in one option's name */
     if ($leyka_last_ver && $leyka_last_ver <= '2.2.7.2') {
         update_option('leyka_agree_to_terms_needed', get_option('leyka_argee_to_terms_needed'));
         delete_option('leyka_argee_to_terms_needed');
     }
     /** Set a flag to flush permalinks (needs to be done a bit later, than this activation itself): */
     update_option('leyka_permalinks_flushed', 0);
     update_option('leyka_last_ver', LEYKA_VERSION);
 }