Exemplo n.º 1
0
function watupro_init()
{
    global $user_ID, $wpdb;
    if (get_option('watupro_debug_mode')) {
        $wpdb->show_errors();
    }
    require WATUPRO_PATH . "/helpers/htmlhelper.php";
    if (!session_id()) {
        @session_start();
    }
    // define table names
    define('WATUPRO_EXAMS', $wpdb->prefix . "watupro_master");
    define('WATUPRO_TAKEN_EXAMS', $wpdb->prefix . "watupro_taken_exams");
    define('WATUPRO_QUESTIONS', $wpdb->prefix . "watupro_question");
    define('WATUPRO_STUDENT_ANSWERS', $wpdb->prefix . "watupro_student_answers");
    define('WATUPRO_USER_CERTIFICATES', $wpdb->prefix . "watupro_user_certificates");
    define('WATUPRO_CATS', $wpdb->prefix . "watupro_cats");
    define('WATUPRO_QCATS', $wpdb->prefix . "watupro_qcats");
    define('WATUPRO_GRADES', $wpdb->prefix . "watupro_grading");
    define('WATUPRO_CERTIFICATES', $wpdb->prefix . "watupro_certificates");
    define('WATUPRO_ANSWERS', $wpdb->prefix . "watupro_answer");
    define('WATUPRO_GROUPS', $wpdb->prefix . "watupro_groups");
    define('WATUPRO_DEPENDENCIES', $wpdb->prefix . "watupro_dependencies");
    define('WATUPRO_PAYMENTS', $wpdb->prefix . "watupro_payments");
    define('WATUPRO_USER_FILES', $wpdb->prefix . "watupro_user_files");
    define('WATUPRO_BUNDLES', $wpdb->prefix . "watupro_bundles");
    // bundles of paid quizzes
    // pagination definitions - let's use something more understandable than 0,1,2,3
    define('WATUPRO_PAGINATE_ONE_PER_PAGE', 0);
    define('WATUPRO_PAGINATE_ALL_ON_PAGE', 1);
    define('WATUPRO_PAGINATE_PAGE_PER_CATEGORY', 2);
    define('WATUPRO_PAGINATE_CUSTOM_NUMBER', 3);
    load_plugin_textdomain('watupro', false, WATUPRO_RELATIVE_PATH . '/languages/');
    // need to redirect the user?
    if (!empty($user_ID)) {
        $redirect = get_user_meta($user_ID, "watupro_redirect", true);
        update_user_meta($user_ID, "watupro_redirect", "");
        if (!empty($redirect)) {
            echo "<meta http-equiv='refresh' content='0;url={$redirect}' />";
            exit;
        }
    }
    $manage_caps = current_user_can('manage_options') ? 'manage_options' : 'watupro_manage_exams';
    define('WATUPRO_MANAGE_CAPS', $manage_caps);
    $version = get_bloginfo('version');
    if ($version <= 3.3 or get_option('watupro_always_load_scripts') == "1") {
        add_action('wp_enqueue_scripts', 'watupro_vc_scripts');
    }
    add_action('admin_enqueue_scripts', 'watupro_vc_scripts');
    add_action('wp_enqueue_scripts', 'watupro_vc_jquery');
    add_action('register_form', 'watupro_group_field');
    // select user group
    add_shortcode('WATUPRO-LEADERBOARD', 'watupro_leaderboard');
    add_shortcode('watupro-leaderboard', 'watupro_leaderboard');
    add_shortcode('WATUPRO-MYEXAMS', 'watupro_myexams_code');
    add_shortcode('watupro-myexams', 'watupro_myexams_code');
    add_shortcode('WATUPRO-MYCERTIFICATES', 'watupro_mycertificates_code');
    add_shortcode('watupro-mycertificates', 'watupro_mycertificates_code');
    add_shortcode('WATUPROLIST', 'watupro_listcode');
    add_shortcode('watuprolist', 'watupro_listcode');
    add_shortcode('WATUPRO', 'watupro_shortcode');
    add_shortcode('watupro', 'watupro_shortcode');
    add_shortcode('watupro-userinfo', 'watupro_userinfo');
    // prepare the custom filter on the content
    watupro_define_filters();
    // handle view certificate in new way - since version 3.7
    add_action('template_redirect', 'watupro_certificate_redirect');
    // replace title & meta tags on shared final screen
    add_action('template_redirect', 'watupro_share_redirect');
    // handle file downloads
    add_action('template_redirect', array('WatuPROFileHandler', 'download'));
    if (watupro_intel() and !empty($_POST['stripe_bundle_pay'])) {
        WatuPROPayment::Stripe(true);
    }
    // process Stripe payment if any
    $db_version = get_option("watupro_db_version");
    if ($db_version < 4.53) {
        watupro_activate(true);
    }
}
Exemplo n.º 2
0
 static function can_access($exam)
 {
     // always access public exams
     if (!$exam->require_login) {
         return true;
     }
     if ($exam->require_login and !is_user_logged_in()) {
         return false;
     }
     // admin can always access
     if (current_user_can('manage_options') or current_user_can('watupro_manage_exams')) {
         if (empty($_POST['action']) and $exam->fee > 0) {
             echo "<b>" . __('Note: This quiz requires payment, but you are administrator and do not need to go through it.', 'watupro') . "</b>";
         }
         return true;
     }
     // USER GROUP CHECKS
     $allowed = WTPCategory::has_access($exam);
     if (!$allowed) {
         echo "<!-- not in allowed user group -->";
         return false;
     }
     // INTELLIGENCE MODULE RESTRICTIONS
     if (watupro_intel()) {
         if ($exam->fee > 0) {
             require_once WATUPRO_PATH . "/i/models/payment.php";
             if (!empty($_POST['stripe_pay'])) {
                 WatuPROPayment::Stripe();
             }
             // process Stripe payment if any
             if (!WatuPROPayment::valid_payment($exam)) {
                 self::$output_sent = WatuPROPayment::render($exam);
                 return false;
             }
         }
         require_once WATUPRO_PATH . "/i/models/dependency.php";
         if (!WatuPRODependency::check($exam)) {
             echo "<!-- WATUPROCOMMENT unsatisfied dependencies -->";
             return false;
         }
     }
     return true;
 }