コード例 #1
0
ファイル: class_export.inc.php プロジェクト: JalpMi/v2contact
 /**
  * See if there's a course to export based on $_POST variables. If so, trigger the export and XML download.
  * @param Boolean $triggerFileDownload If true, trigger a file download rather than just XML output as a page.
  */
 public static function tryExportCourse($triggerFileDownload = true)
 {
     // See if course is being exported
     if (isset($_POST["update"]) && $_POST["update"] == 'wpcw_export' && current_user_can('manage_options')) {
         // Now check course is valid. If not, then don't do anything, and let
         // normal form handle the errors.
         $courseID = WPCW_arrays_getValue($_POST, 'export_course_id');
         $courseDetails = WPCW_courses_getCourseDetails($courseID);
         if ($courseDetails) {
             $moduleList = false;
             // Work out what details to fetch and then export
             $whatToExport = WPCW_arrays_getValue($_POST, 'what_to_export');
             switch ($whatToExport) {
                 // Just the course title, description and settings (no units or modules)
                 case 'just_course':
                     break;
                     // Just the course settings and module settings (no units)
                 // Just the course settings and module settings (no units)
                 case 'course_modules':
                     $moduleList = WPCW_courses_getModuleDetailsList($courseDetails->course_id);
                     break;
                     // Basically case 'whole_course' - The whole course, modules and units
                 // Basically case 'whole_course' - The whole course, modules and units
                 default:
                     $moduleList = WPCW_courses_getModuleDetailsList($courseDetails->course_id);
                     if ($moduleList) {
                         // Grab units for each module, in the right order, and associate with each module object.
                         foreach ($moduleList as $module) {
                             // This might return false, but that's OK. We'll check for it later.
                             $module->units = WPCW_units_getListOfUnits($module->module_id);
                         }
                     }
                     break;
             }
             // If true, trigger a file download of the XML file.
             if ($triggerFileDownload) {
                 $exportFile = "wp-courseware-export-" . date("Y-m-d") . ".xml";
                 header('Content-Description: File Transfer');
                 header("Content-Disposition: attachment; filename={$exportFile}");
             }
             header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
             // When debugging, comment out the line above, and use the following line so that you can see
             // any error messages.
             // header('Content-Type: text/plain');
             $export = new WPCW_Export();
             echo $export->exportCourseDetails($courseDetails, $moduleList);
             die;
         }
     }
     // If get here, then normal WPCW processing takes place.
 }
コード例 #2
0
 /**
  * See if there's a course to export based on $_POST variables. If so, trigger the export and XML download.
  * @param Boolean $triggerFileDownload If true, trigger a file download rather than just XML output as a page.
  */
 public static function tryExportCourse($triggerFileDownload = true)
 {
     // See if course is being exported
     if (isset($_POST["update"]) && $_POST["update"] == 'wpcw_export' && current_user_can('manage_options')) {
         // Now check course is valid. If not, then don't do anything, and let
         // normal form handle the errors.
         $courseID = WPCW_arrays_getValue($_POST, 'export_course_id');
         $courseDetails = WPCW_courses_getCourseDetails($courseID);
         if ($courseDetails) {
             $moduleList = false;
             $questionList = false;
             // Work out what details to fetch and then export
             $whatToExport = WPCW_arrays_getValue($_POST, 'what_to_export');
             switch ($whatToExport) {
                 // Course Settings: Yes
                 // Module Settings: No
                 // 			 Units: No
                 // 	 	   Quizzes: No
                 case 'just_course':
                     break;
                     // Course Settings: Yes
                     // Module Settings: Yes
                     // 			 Units: No
                     // 	 	   Quizzes: No
                 // Course Settings: Yes
                 // Module Settings: Yes
                 // 			 Units: No
                 // 	 	   Quizzes: No
                 case 'course_modules':
                     $moduleList = WPCW_courses_getModuleDetailsList($courseDetails->course_id);
                     break;
                     // Course Settings: Yes
                     // Module Settings: Yes
                     // 			 Units: Yes
                     // 	 	   Quizzes: No
                 // Course Settings: Yes
                 // Module Settings: Yes
                 // 			 Units: Yes
                 // 	 	   Quizzes: No
                 case 'course_modules_and_units':
                     $moduleList = WPCW_courses_getModuleDetailsList($courseDetails->course_id);
                     if ($moduleList) {
                         // Grab units for each module, in the right order, and associate with each module object.
                         foreach ($moduleList as $module) {
                             // This might return false, but that's OK. We'll check for it later.
                             $module->units = WPCW_units_getListOfUnits($module->module_id);
                         }
                     }
                     break;
                     // Basically the whole course
                     // Course Settings: Yes
                     // Module Settings: Yes
                     // 			 Units: Yes
                     // 	 	   Quizzes: Yes
                 // Basically the whole course
                 // Course Settings: Yes
                 // Module Settings: Yes
                 // 			 Units: Yes
                 // 	 	   Quizzes: Yes
                 default:
                     $questionList = WPCW_questions_getAllQuestionsforCourse($courseDetails->course_id);
                     $moduleList = WPCW_courses_getModuleDetailsList($courseDetails->course_id);
                     if ($moduleList) {
                         // Grab units for each module, in the right order, and associate with each module object.
                         foreach ($moduleList as $module) {
                             // This might return false, but that's OK. We'll check for it later.
                             $module->units = WPCW_units_getListOfUnits($module->module_id);
                             // See if we have any units, and then check each for the associated quiz data.
                             // Update the unit objects with details of the quizzes
                             WPCW_Export::WPCW_quizzes_fetchQuizzesForUnits($module->units);
                         }
                     }
                     break;
             }
             // TODO ZZZ - DEBUG Tool - To enable debugging, comment this in so that the download is not triggered.
             $triggerFileDownload = true;
             // If true, trigger a file download of the XML file.
             if ($triggerFileDownload) {
                 $exportFile = "wp-courseware-export-" . sanitize_title($courseDetails->course_title) . '-' . date("Y-m-d") . ".xml";
                 header('Content-Description: File Transfer');
                 header("Content-Disposition: attachment; filename={$exportFile}");
                 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
             } else {
                 // When debugging, comment out the line above, and use the following line so that you can see
                 // any error messages.
                 header('Content-Type: text/plain');
             }
             $export = new WPCW_Export();
             echo $export->exportCourseDetails($courseDetails, $moduleList, $questionList);
             die;
         }
     }
     // If get here, then normal WPCW processing takes place.
 }
コード例 #3
0
/**
 * Initialisation functions for plugin.
 */
function WPCW_plugin_init()
{
    // Load translation support
    $domain = 'wp_courseware';
    // This is the translation locale.
    // Check the WordPress language directory for /wp-content/languages/wp_courseware/wp_courseware-en_US.mo first
    $locale = apply_filters('plugin_locale', get_locale(), $domain);
    load_textdomain($domain, WP_LANG_DIR . '/wp_courseware/' . $domain . '-' . $locale . '.mo');
    // Then load the plugin version
    load_plugin_textdomain($domain, FALSE, dirname(plugin_basename(__FILE__)) . '/language/');
    // Run setup
    WPCW_plugin_setup(false);
    // ### Admin
    if (is_admin()) {
        // Menus
        add_action('admin_menu', 'WPCW_menu_MainMenu');
        add_action('admin_head', 'WPCW_menu_MainMenu_cleanUnwantedEntries');
        // Network Only
        //add_action('network_admin_menu', 						'WPCW_menu_MainMenu_NetworkOnly');
        // Scripts and styles
        add_action('admin_print_scripts', 'WPCW_addCustomScripts_BackEnd');
        add_action('admin_print_styles', 'WPCW_addCustomCSS_BackEnd');
        // See if export has been requested
        WPCW_Export::tryExportCourse();
        // Post Related
        add_action('save_post', 'WPCW_units_saveUnitPostMetaData', 10, 2);
        // User Related
        add_action('manage_users_columns', 'WPCW_users_manageColumns');
        add_action('manage_users_custom_column', 'WPCW_users_addCustomColumnContent', 10, 3);
        // Unit Related
        add_filter('manage_course_unit_posts_columns', 'WPCW_units_manageColumns', 10);
        add_action('manage_course_unit_posts_custom_column', 'WPCW_units_addCustomColumnContent', 10, 2);
        // Unit Deletion
        add_filter('delete_post', 'WPCW_units_deleteUnitHandler');
        // Meta boxes
        add_action('add_meta_boxes', 'WPCW_units_showEditScreenMetaBoxes');
        // AJAX - Admin
        add_action('wp_ajax_wpcw_handle_unit_ordering_saving', 'WPCW_AJAX_handleUnitOrderingSaving');
        add_action('wp_ajax_wpcw_handle_unit_duplication', 'WPCW_AJAX_handleUnitDuplication');
        add_action('wp_ajax_wpcw_handle_question_new_tag', 'WPCW_AJAX_handleQuestionNewTag');
        add_action('wp_ajax_wpcw_handle_question_remove_tag', 'WPCW_AJAX_handleQuestionRemoveTag');
        add_action('wp_ajax_wpcw_handle_tb_action_question_pool', 'WPCW_AJAX_handleThickboxAction_QuestionPool');
        add_action('wp_ajax_wpcw_handle_tb_action_add_question', 'WPCW_AJAX_handleThickboxAction_QuestionPool_addQuestion');
        // AJAX - Frontend (yeah, WP requires they go here)
        add_action('wp_ajax_wpcw_handle_unit_track_progress', 'WPCW_AJAX_units_handleUserProgress');
        add_action('wp_ajax_wpcw_handle_unit_quiz_response', 'WPCW_AJAX_units_handleQuizResponse');
        add_action('wp_ajax_wpcw_handle_unit_quiz_retake_request', 'WPCW_AJAX_units_handleQuizRetakeRequest');
        add_action('wp_ajax_wpcw_handle_unit_quiz_jump_question', 'WPCW_AJAX_units_handleQuizJumpQuestion');
        add_action('wp_ajax_wpcw_handle_unit_quiz_timer_begin', 'WPCW_AJAX_units_handleQuizTimerBegin');
        // Notices about permalinks
        add_action('admin_notices', 'WPCW_plugin_permalinkCheck');
        // Notice about MS - Now disabled.
        //add_action('admin_notices', 							'WPCW_plugin_multisiteCheck');
        // CSV Export
        add_action('wp_loaded', 'WPCW_data_handleDataExport');
        // User - Global reset functionality
        add_action('load-users.php', 'WPCW_users_processUserResetAbility');
        add_action('admin_head', 'WPCW_users_processUserResetAbility_showSuccess');
        add_action('restrict_manage_users', 'WPCW_users_showUserResetAbility');
    } else {
        // Scripts and styles
        WPCW_addCustomScripts_FrontEnd();
        // Shortcodes
        add_shortcode('wpcourse', 'WPCW_shortcodes_showTrainingCourse');
        add_shortcode('wpcourse_progress', 'WPCW_shortcodes_showTrainingCourseProgress');
        // Post Content
        add_filter('the_content', 'WPCW_units_processUnitContent');
        // Templates - Course Units
        add_filter('single_template', 'WPCW_templates_units_filterTemplateForUnit');
    }
    // Action when admin has updated the course details.
    add_action('wpcw_course_details_updated', 'WPCW_actions_courses_courseDetailsUpdated');
    // Action when user has completed a unit/module/course
    add_action('wpcw_user_completed_unit', 'WPCW_actions_users_unitCompleted', 10, 3);
    add_action('wpcw_user_completed_module', 'WPCW_actions_users_moduleCompleted', 10, 3);
    add_action('wpcw_user_completed_course', 'WPCW_actions_users_courseCompleted', 10, 3);
    // Modified modules - when a module is created or edited
    add_action('wpcw_modules_modified', 'WPCW_actions_modules_modulesModified');
    // Action called when user has been created, and we check to see if that user should be added to
    // any of the defined courses.
    add_action('user_register', 'WPCW_actions_users_newUserCreated');
    // Action called when user has been deleted
    add_action('delete_user', 'WPCW_actions_users_userDeleted');
    // Action called when quiz has been completed and needs grading or needs attention as user is blocked.
    add_action('wpcw_quiz_needs_grading', 'WPCW_actions_userQuizNeedsGrading_notifyAdmin', 10, 2);
    add_action('wpcw_quiz_user_needs_unblocking', 'WPCW_actions_userQuizUserNeedsUnblocking_notifyAdmin', 10, 2);
    // Action called when quiz has been graded or needs attention
    add_action('wpcw_quiz_graded', 'WPCW_actions_userQuizGraded_notifyUser', 10, 4);
    // Common
    WPCW_plugin_registerCustomPostTypes();
    // Create correct URL for unit
    add_filter('post_type_link', 'WPCW_units_createCorrectUnitURL', 1, 3);
    // Create permalink for course units
    global $wp_rewrite;
    $unit_structure = '/%module_number%/%course_unit%/';
    // Handle module and course unit tags
    $wp_rewrite->add_rewrite_tag("%module_number%", '(module-[^/]+)', "module_number=");
    $wp_rewrite->add_rewrite_tag("%course_unit%", '([^/]+)', "course_unit=");
    // Make it happen to format links automatically for course units.
    $wp_rewrite->add_permastruct('course_unit', $unit_structure, false);
    // Ensure the URLs are flushed for the first time
    $flushRules = get_option('wpcw_flush_rules');
    if (!$flushRules) {
        update_option('wpcw_flush_rules', 'done');
        $wp_rewrite->flush_rules();
    }
    // Now load any extensions
    do_action('wpcw_extensions_load');
}
コード例 #4
0
ファイル: wp-courseware.php プロジェクト: JalpMi/v2contact
/**
 * Initialisation functions for plugin.
 */
function WPCW_plugin_init()
{
    // Load translation support
    $plugin_dir = basename(dirname(__FILE__)) . '/language/';
    load_plugin_textdomain('wp_courseware', false, $plugin_dir);
    // Run setup
    WPCW_plugin_setup(false);
    // Change preferences for updater
    if (WPCW_plugin_hasAdminRights()) {
        global $updater_wpcw;
        $updater_wpcw->setAccessKey(TidySettings_getSettingSingle(WPCW_DATABASE_SETTINGS_KEY, 'licence_key'));
        //$updater_wpcw->plugin_msg_blocked = false; // No message if blocked licence.
        $updater_wpcw->plugin_msg_expired = __('Your licence key has expired. Please visit <a href="http://www.flyplugins.com" target="_blank">FlyPlugins.com</a> to renew your licence.', 'wp_courseware');
        $updater_wpcw->plugin_msg_invalid = __('Please enter a valid licence key or visit <a href="http://www.flyplugins.com" target="_blank">FlyPlugins.com</a> to purchase a licence.', 'wp_courseware');
        $updater_wpcw->plugin_msg_limit_reached = __('You\'ve reached the maximum number of websites for this licence. Please visit <a href="http://www.flyplugins.com" target="_blank">FlyPlugins.com</a> to upgrade your licence.', 'wp_courseware');
    }
    // ### Admin
    if (is_admin()) {
        // Menus
        add_action('admin_menu', 'WPCW_menu_MainMenu');
        add_action('admin_head', 'WPCW_menu_MainMenu_cleanUnwantedEntries');
        // Network Only
        //add_action('network_admin_menu', 						'WPCW_menu_MainMenu_NetworkOnly');
        // Scripts and styles
        add_action('admin_print_scripts', 'WPCW_addCustomScripts_BackEnd');
        add_action('admin_print_styles', 'WPCW_addCustomCSS_BackEnd');
        // See if export has been requested
        WPCW_Export::tryExportCourse();
        // Post Related
        add_action('save_post', 'WPCW_units_saveUnitPostMetaData', 10, 2);
        // User Related
        add_action('manage_users_columns', 'WPCW_users_manageColumns');
        add_action('manage_users_custom_column', 'WPCW_users_addCustomColumnContent', 10, 3);
        // Unit Related
        add_filter('manage_course_unit_posts_columns', 'WPCW_units_manageColumns', 10);
        add_action('manage_course_unit_posts_custom_column', 'WPCW_units_addCustomColumnContent', 10, 2);
        // Unit Deletion
        add_filter('delete_post', 'WPCW_units_deleteUnitHandler');
        // Meta boxes
        add_action('add_meta_boxes', 'WPCW_units_showConversionMetaBox');
        // AJAX - Admin
        add_action('wp_ajax_wpcw_handle_unit_ordering_saving', 'WPCW_AJAX_handleUnitOrderingSaving');
        // AJAX - Frontend (yeah, WP requires they go here)
        add_action('wp_ajax_wpcw_handle_unit_track_progress', 'WPCW_AJAX_units_handleUserProgress');
        add_action('wp_ajax_wpcw_handle_unit_quiz_response', 'WPCW_AJAX_units_handleQuizResponse');
        // Notices about permalinks
        add_action('admin_notices', 'WPCW_plugin_permalinkCheck');
        add_action('admin_notices', 'WPCW_plugin_multisiteCheck');
        // CSV Export
        add_action('wp_loaded', 'WPCW_data_handleDataExport');
    } else {
        // Scripts and styles
        WPCW_addCustomScripts_FrontEnd();
        // Shortcodes
        add_shortcode('wpcourse', 'WPCW_shortcodes_showTrainingCourse');
        // Post Content
        add_filter('the_content', 'WPCW_units_processUnitContent');
    }
    // Action when admin has updated the course details.
    add_action('wpcw_course_details_updated', 'WPCW_actions_courses_courseDetailsUpdated');
    // Action when user has completed a unit/module/course
    add_action('wpcw_user_completed_unit', 'WPCW_actions_users_unitCompleted', 10, 3);
    add_action('wpcw_user_completed_module', 'WPCW_actions_users_moduleCompleted', 10, 3);
    add_action('wpcw_user_completed_course', 'WPCW_actions_users_courseCompleted', 10, 3);
    // Modified modules - when a module is created or edited
    add_action('wpcw_modules_modified', 'WPCW_actions_modules_modulesModified');
    // Action called when user has been created, and we check to see if that user should be added to
    // any of the defined courses.
    add_action('user_register', 'WPCW_actions_users_newUserCreated');
    // Action called when user has been deleted
    add_action('delete_user', 'WPCW_actions_users_userDeleted');
    // Action called when quiz has been completed and needs grading.
    add_action('wpcw_quiz_needs_grading', 'WPCW_actions_userQuizNeedsGrading_notifyAdmin', 10, 2);
    // Action called when quiz has been graded.
    add_action('wpcw_quiz_graded', 'WPCW_actions_userQuizGraded_notifyUser', 10, 4);
    // Common
    WPCW_plugin_registerCustomPostTypes();
    // Create correct URL for unit
    add_filter('post_type_link', 'WPCW_units_createCorrectUnitURL', 1, 3);
    // Create permalink for course units
    global $wp_rewrite;
    $unit_structure = '/%module_number%/%course_unit%/';
    // Handle module and course unit tags
    $wp_rewrite->add_rewrite_tag("%module_number%", '(module-[^/]+)', "module_number=");
    $wp_rewrite->add_rewrite_tag("%course_unit%", '([^/]+)', "course_unit=");
    // Make it happen to format links automatically for course units.
    $wp_rewrite->add_permastruct('course_unit', $unit_structure, false);
    // Ensure the URLs are flushed for the first time
    $flushRules = get_option('wpcw_flush_rules');
    if (!$flushRules) {
        update_option('wpcw_flush_rules', 'done');
        $wp_rewrite->flush_rules();
    }
    // Now load any extensions
    //do_action('wpcw_extensions_load');
}