/**
 * Enqueues JavaScript files.
 *
 * @since 2.0
 * @global object $bp BuddyPress global settings
 */
function dpa_add_js()
{
    global $bp;
    if (!bp_is_current_component($bp->achievements->slug)) {
        return;
    }
    if (DPA_SLUG_CREATE == $bp->current_action && dpa_permission_can_user_create() || DPA_SLUG_ACHIEVEMENT_EDIT == $bp->current_action && dpa_permission_can_user_edit() || DPA_SLUG_ACHIEVEMENT_CHANGE_PICTURE == $bp->current_action && dpa_permission_can_user_change_picture() || DPA_SLUG_ACHIEVEMENT_GRANT == $bp->current_action && dpa_permission_can_user_grant()) {
        nxt_enqueue_script('achievements-admin-js', plugins_url('/js/admin.js', __FILE__), array(), ACHIEVEMENTS_VERSION);
    }
    if ($bp->is_single_item) {
        nxt_enqueue_script('achievements-detail-js', plugins_url('/js/detail.js', __FILE__), array(), ACHIEVEMENTS_VERSION);
    } else {
        nxt_enqueue_script('achievements-directory-js', plugins_url('/js/directory.js', __FILE__), array(), ACHIEVEMENTS_VERSION);
    }
}
/**
 * Loads the create Achievement page. Also implements controller logic.
 *
 * @global DPA_Achievement_Template $achievements_template Achievements template tag object
 * @global nxt_Error $achievements_errors Achievement creation error object
 * @global object $bp BuddyPress global settings
 * @since 2.0
 * @uses DPA_Achievement
 */
function dpa_screen_achievement_create()
{
    global $achievements_template, $achievements_errors, $bp, $current_blog;
    if (!bp_is_current_component($bp->achievements->slug) || DPA_SLUG_CREATE != $bp->current_action || !dpa_permission_can_user_create()) {
        return;
    }
    $bp->achievements->current_achievement = new DPA_Achievement();
    $achievement =& $bp->achievements->current_achievement;
    // Has form been submitted?
    if (empty($_POST['achievement-create'])) {
        $achievement->points = '';
        $achievement->action_count = 1;
        $achievement->is_active = 1;
        do_action('dpa_screen_achievement_create', $achievement);
        bp_core_load_template(apply_filters('dpa_screen_achievement_create_template', 'achievements/create'));
        return;
    }
    if (!nxt_verify_nonce($_POST['_nxtnonce'], 'achievement-create')) {
        nxt_nonce_ays('');
        die;
    }
    /* We can't use template tags because if the new details fail validation and do not save, the template loop will fetch the old version. */
    if ('badge' == stripslashes($_POST['achievement_type'])) {
        $achievement->action_count = 1;
        $achievement->action_id = -1;
    } else {
        $achievement->action_count = (int) $_POST['action_count'];
        $achievement->action_id = (int) $_POST['action_id'];
    }
    if (is_multisite() && bp_is_active('blogs')) {
        $achievement->site_id = (int) $_POST['site_id'];
    } else {
        $achievement->site_id = BP_ROOT_BLOG;
    }
    if (bp_is_active('groups')) {
        $achievement->group_id = (int) $_POST['group_id'];
    } else {
        $achievement->group_id = -1;
    }
    if (!empty($_POST['is_hidden'])) {
        $achievement->is_active = 2;
    } elseif (!empty($_POST['is_active'])) {
        $achievement->is_active = 1;
    } else {
        $achievement->is_active = 0;
    }
    $achievement->name = stripslashes($_POST['name']);
    $achievement->description = stripslashes($_POST['description']);
    $achievement->points = (int) $_POST['points'];
    $achievement->slug = stripslashes($_POST['slug']);
    $achievement->picture_id = -1;
    // A pictures is chosen on its own page, after creation.
    $achievements_errors = $achievement->save();
    if (!is_nxt_error($achievements_errors)) {
        $achievements_template->achievement = $achievement;
        // Required for dpa_record_activity()
        if (1 == $achievement->is_active) {
            dpa_record_activity($bp->loggedin_user->id, dpa_format_activity($bp->loggedin_user->id, $achievement->id), $achievement->id, 'achievement_created');
        }
        bp_core_add_message(__("Achievement created succesfully!", 'dpa'));
        do_action('dpa_screen_achievement_create_success', $achievement);
        if (dpa_permission_can_user_change_picture()) {
            bp_core_redirect(dpa_get_achievements_permalink() . '/' . $achievement->slug . '/' . DPA_SLUG_ACHIEVEMENT_CHANGE_PICTURE);
        } else {
            bp_core_redirect(dpa_get_achievements_permalink() . '/' . $achievement->slug);
        }
    } else {
        if (!$achievement->points) {
            $achievement->points = '';
        }
        if (!$achievement->action_count) {
            $achievement->action_count = '';
        }
        do_action('dpa_screen_achievement_create_fail', $achievement, $achievements_errors);
        bp_core_add_message(__('An error has occurred and the Achievement has not been created. See below for details.', 'dpa'), 'error');
        bp_core_load_template(apply_filters('dpa_screen_achievement_create_template', 'achievements/create'));
    }
}
Beispiel #3
0
    ?>
				<section id="breadcrumbs">
					<?php 
    lok_breadcrumbs();
    ?>
				</section><!--/#breadcrumbs -->
			<?php 
}
?>
			<section id="main" class="col-left"> 
		<div class="padder">

		<form action="" method="post" id="achievements-directory-form" class="dir-form">
			<h3><?php 
_e('Achievements Directory', 'dpa');
if (dpa_permission_can_user_create()) {
    ?>
 &nbsp;<a class="button" href="<?php 
    dpa_achievements_permalink();
    ?>
/<?php 
    echo DPA_SLUG_CREATE;
    ?>
"><?php 
    _e('Create an Achievement', 'dpa');
    ?>
</a><?php 
}
?>
</h3>