/**
 * Export action. Monitor backened and create a new export.
 *
 * @since Astoundify Crowdfunding 0.1-alpha
 *
 * @return void
 */
function atcf_export_campaign()
{
    $crowdfunding = crowdfunding();
    $campaign_id = absint($_POST['edd_export_campaign_id']);
    if (0 != $campaign_id) {
        require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/class-export.php';
        require $crowdfunding->includes_dir . 'class-export-campaigns.php';
        $campaign_export = new ATCF_Campaign_Export($campaign_id);
        $campaign_export->export();
    }
}
/**
 * If there is any custom gateway functionality included,
 * and the gateway is active, load the extra files.
 *
 * @since Astoundify Crowdfunding 1.1
 *
 * @return void
 */
function atcf_load_gateway_support()
{
    if (!class_exists('Easy_Digital_Downloads')) {
        return;
    }
    $crowdfunding = crowdfunding();
    $active_gateways = edd_get_enabled_payment_gateways();
    foreach ($active_gateways as $gateway => $gateway_args) {
        if (@file_exists($crowdfunding->includes_dir . 'gateways/' . $gateway . '.php')) {
            require $crowdfunding->includes_dir . 'gateways/' . $gateway . '.php';
        }
    }
}
/**
 * Load Admin Scripts
 *
 * @since Astoundify Crowdfunding 1.3
 *
 * @return void
 */
function atcf_load_admin_scripts($hook)
{
    global $pagenow, $typenow;
    if (!in_array($pagenow, array('post.php', 'post-new.php'))) {
        return;
    }
    if ('download' != $typenow) {
        return;
    }
    $crowdfunding = crowdfunding();
    wp_enqueue_script('atcf-admin-scripts', $crowdfunding->plugin_url . '/assets/js/crowdfunding-admin.js', array('jquery', 'edd-admin-scripts'));
}
/**
 * Request Data
 *
 * @since Astoundify Crowdfunding 0.8
 *
 * @return void
 */
function atcf_shortcode_profile_request_data()
{
    global $edd_options, $post;
    if ('GET' !== strtoupper($_SERVER['REQUEST_METHOD'])) {
        return;
    }
    if (empty($_GET['action']) || 'atcf-request-data' !== $_GET['action']) {
        return;
    }
    if (!wp_verify_nonce($_GET['_wpnonce'], 'atcf-request-data')) {
        return;
    }
    $user = wp_get_current_user();
    $errors = new WP_Error();
    $crowdfunding = crowdfunding();
    $campaign = absint($_GET['campaign']);
    $campaign = atcf_get_campaign($campaign);
    if ($user->ID != $campaign->data->post_author) {
        $errors->add('non-owner', __('You are not the author of this campaign, and cannot request the data.', 'atcf'));
    }
    if (!empty($errors->errors)) {
        wp_die($errors);
    }
    if (0 != $campaign->ID) {
        require_once EDD_PLUGIN_DIR . 'includes/admin/reporting/class-export.php';
        require $crowdfunding->includes_dir . 'class-export-campaigns.php';
        $campaign_export = new ATCF_Campaign_Export($campaign->ID);
        $campaign_export->export();
    }
    $url = isset($edd_options['profile_page']) ? get_permalink($edd_options['profile_page']) : get_permalink();
    $redirect = apply_filters('atcf_shortcode_profile_info_success_redirect', add_query_arg(array('exported' => $campaign->ID, 'success' => 'true'), $url));
    wp_safe_redirect($redirect);
    exit;
}
Exemplo n.º 5
0
/**
 * Base page/form. All fields are loaded through an action,
 * so the form can be extended for ever, fields can be removed, added, etc.
 *
 * @since Astoundify Crowdfunding 0.1-alpha
 *
 * @param $atts
 * @return $form
 */
function atcf_shortcode_submit($atts = array())
{
    global $edd_options;
    $atts = shortcode_atts(array('campaign_id' => false), $atts);
    $crowdfunding = crowdfunding();
    $campaign = $atts['campaign_id'] === false ? null : atcf_get_campaign($atts['campaign_id']);
    $is_draft = false;
    $is_editing = false;
    if (is_null($campaign)) {
        global $post;
        // If the current $post is a download, we know this is
        // either a draft, pending or published campaign
        if ('download' == $post->post_type) {
            $is_draft = 'draft' == $post->post_status;
            $is_editing = !$is_draft;
            $campaign = atcf_get_campaign($post);
        }
    }
    $args = array('campaign' => $campaign, 'previewing' => $is_draft, 'editing' => $is_editing);
    ob_start();
    /** Allow things to change the content of the shortcode. */
    if (apply_filters('atcf_shortcode_submit_hide', false, $args)) {
        do_action('atcf_shortcode_submit_hidden', $args);
        $form = ob_get_clean();
        return $form;
    }
    ?>
	<?php 
    do_action('atcf_shortcode_submit_before', $args, $args['campaign']);
    ?>

	<form action="" method="post" class="atcf-submit-campaign" enctype="multipart/form-data">

		<?php 
    foreach (atcf_shortcode_submit_fields() as $key => $field) {
        /** If we _aren't_ editing, and the field should only be shown on edit, skip... */
        if (!$is_editing && 'only' === $field['editable']) {
            continue;
        }
        /** If we _are_ editing, and the field is not editable, skip... */
        if ($is_editing && $field['editable'] === false) {
            continue;
        }
        $field = apply_filters('atcf_shortcode_submit_field', $key, $field, $args, $args['campaign']);
        $field = apply_filters('atcf_shortcode_submit_field_before_render_' . $key, $field);
        do_action('atcf_shortcode_submit_field_before_' . $key, $key, $field, $args, $args['campaign']);
        do_action('atcf_shortcode_submit_field_' . $field['type'], $key, $field, $args, $args['campaign']);
        do_action('atcf_shortcode_submit_field_after_' . $key, $key, $field, $args, $args['campaign']);
    }
    ?>

		<p class="atcf-submit-campaign-submit">
			<button type="submit" name="submit" value="submit" class="button">
				<?php 
    echo $is_editing ? sprintf(_x('Update %s', 'edit "campaign"', 'atcf'), edd_get_label_singular()) : sprintf(_x('Submit %s', 'submit "campaign"', 'atcf'), edd_get_label_singular());
    ?>
			</button>

			<?php 
    if (is_user_logged_in() && !$is_editing) {
        ?>
			<button type="submit" name="submit" value="preview" class="button button-secondary">
				<?php 
        _e('Save and Preview', 'atcf');
        ?>
			</button>
			<?php 
    }
    ?>

			<input type="hidden" name="action" value="atcf-campaign-submit" />
			<?php 
    wp_nonce_field('atcf-campaign-submit');
    ?>

			<?php 
    if ($is_editing || $is_draft) {
        ?>
				<input type="hidden" name="campaign_id" value="<?php 
        echo $campaign->ID;
        ?>
" />
			<?php 
    }
    ?>
		</p>
	</form>

	<?php 
    do_action('atcf_shortcode_submit_after', $args, $args['campaign']);
    ?>

<?php 
    $form = ob_get_clean();
    return $form;
}