Plugin Directory

Changeset 1881036


Ignore:
Timestamp:
05/24/2018 07:09:33 PM (8 years ago)
Author:
Tunapanda
Message:

use admin-ajax rather than hard linking to the plugin directory

Location:
wp-h5p-xapi/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • wp-h5p-xapi/trunk/plugin.php

    r1358053 r1881036  
    1818            "endpoint_url"=>get_option("h5pxapi_endpoint_url"),
    1919            "username"=>get_option("h5pxapi_username"),
    20             "password"=>get_option("h5pxapi_password")
     20            "password"=>get_option("h5pxapi_password"),
     21                        "alerts" => get_option("h5pxapi_alerts"),
    2122        );
    2223    }
  • wp-h5p-xapi/trunk/process-xapi-statement.php

    r1527353 r1881036  
    1414use h5pxapi\WpUtil;
    1515
    16 require_once WpUtil::getWpLoadPath();
     16// require_once WpUtil::getWpLoadPath();
    1717
    1818$statementObject=json_decode(stripslashes($_REQUEST["statement"]),TRUE);
     
    2222    unset($statementObject["context"]["extensions"]);
    2323
    24 if (has_filter("h5p-xapi-pre-save")) {
     24if ( has_filter("h5p-xapi-pre-save")) {
    2525    $statementObject=apply_filters("h5p-xapi-pre-save",$statementObject);
    2626
     
    9696}
    9797
    98 do_action("h5p-xapi-post-save",$statementObject);
     98$h5pxapi_response_message = apply_filters("h5p-xapi-post-save",$statementObject);
    9999
    100100$response=array(
  • wp-h5p-xapi/trunk/readme.txt

    r1506632 r1881036  
    22Contributors: Tunapanda
    33Donate link: http://www.tunapanda.org/contribute
    4 Tags: xapi, h5p, admin, learning, integration, lms, learning management system
     4Tags: xapi, h5p, admin, learning, integration, lrs, learning management system
    55Requires at least: 3.8.1
    6 Tested up to: 4.6.1
    7 Stable tag: trunk
     6Tested up to: 4.9.6
     7Stable tag: /Users/jake/projects/svn/wp-h5p-xapi/wp-h5p-xapi/trunk/wp-h5p-xapi.phptrunk
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
    1010
    11 This plugin stores all xAPI statements generaded by H5P in a remote LRS.
     11This plugin stores all xAPI statements generated by H5P in a remote LRS.
    1212
    1313== Description ==
  • wp-h5p-xapi/trunk/src/template/settings.tpl.php

    r1310920 r1881036  
    9595                </td>
    9696            </tr>
     97            <tr valign="top">
     98                <th scope="row">Alerts On <small>(un-checking will make debug statements happen to console instead of alert)</small></th>
     99                <td>
     100                    <input type="checkbox" name="h5pxapi_alerts"
     101                       <?php echo (get_option("h5pxapi_alerts") == "on" )? 'checked="checked"' : ''; ?> />
     102                   
     103                </td>
     104            </tr>
    97105        </table>
    98106
  • wp-h5p-xapi/trunk/wp-h5p-xapi.js

    r1527353 r1881036  
    2626    function showError(message, code) {
    2727        console.error("Unable to save xAPI statement");
    28 
    29         alert("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code);
     28                if( xapi_settings.alerts == true ){
     29                    alert("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code);
     30                } else {
     31                    console.log("Unable to save result data.\n\nMessage: " + message + "\n" + "Code: " + code);
     32                }
    3033    }
    3134
     
    7275     */
    7376    function onXapi(event) {
    74         if (!WP_H5P_XAPI_STATEMENT_URL)
     77        if (!xapi_settings.ajax_url)
    7578            return;
    7679
    7780        showSpinner();
    7881
    79         var data = {};
     82        var data = {
     83            action: 'xapi_event'
     84        };
    8085        /*console.log("on xapi, statement:");
    8186        console.log(JSON.stringify(event.data.statement));*/
     
    9499        }
    95100
    96         if (WP_H5P_XAPI_CONTEXTACTIVITY)
    97             event.data.statement.context.contextActivities.grouping.push(WP_H5P_XAPI_CONTEXTACTIVITY);
     101        if (xapi_settings.context_activity)
     102            event.data.statement.context.contextActivities.grouping.push(xapi_settings.context_activity);
    98103
    99104        data.statement = JSON.stringify(event.data.statement);
     
    102107        $.ajax({
    103108            type: "POST",
    104             url: WP_H5P_XAPI_STATEMENT_URL,
     109            url: xapi_settings.ajax_url,
    105110            data: data,
    106111            dataType: "json",
  • wp-h5p-xapi/trunk/wp-h5p-xapi.php

    r1542843 r1881036  
    11<?php
    22
    3 require_once __DIR__."/src/utils/Template.php";
    4 require_once __DIR__."/plugin.php";
     3require_once __DIR__ . "/src/utils/Template.php";
     4require_once __DIR__ . "/plugin.php";
    55
    66use h5pxapi\Template;
     
    1111GitHub Plugin URI: https://github.com/tunapanda/wp-h5p-xapi
    1212Description: Send H5P achievements to an xAPI repo.
    13 Version: 0.1.6
    14 */
     13Version: 0.1.7
     14 */
    1515
    1616/**
    1717 * Enqueue scripts and stylesheets.
    1818 */
    19 function h5pxapi_enqueue_scripts() {
    20     wp_register_script("wp-h5p-xapi",plugins_url()."/wp-h5p-xapi/wp-h5p-xapi.js",array("jquery"));
    21     wp_enqueue_script("wp-h5p-xapi");
    2219
    23     wp_register_style("wp-h5p-xapi",plugins_url()."/wp-h5p-xapi/wp-h5p-xapi.css");
    24     wp_enqueue_style("wp-h5p-xapi");
     20function h5pxapi_enqueue_scripts()
     21{
     22    wp_register_script("wp-h5p-xapi", plugins_url() . "/wp-h5p-xapi/wp-h5p-xapi.js", array("jquery"));
     23    wp_enqueue_script("wp-h5p-xapi");
    2524
    26     $s="";
    27     $s.="<script>\n";
     25    wp_register_style("wp-h5p-xapi", plugins_url() . "/wp-h5p-xapi/wp-h5p-xapi.css");
     26    wp_enqueue_style("wp-h5p-xapi");
    2827
    29     $settings=h5pxapi_get_auth_settings();
     28    $xapi_js_settings = array();
    3029
    31     if ($settings && $settings["endpoint_url"])
    32         $s.="WP_H5P_XAPI_STATEMENT_URL='".plugins_url()."/wp-h5p-xapi/process-xapi-statement.php';";
     30    $settings = h5pxapi_get_auth_settings();
    3331
    34     else
    35         $s.="WP_H5P_XAPI_STATEMENT_URL=null;";
     32    $xapi_js_settings['ajax_url'] = admin_url('admin-ajax.php');
    3633
    37     $s.="\n";
     34    // Permalink is not available in the admin interface.
     35    if (get_permalink()) {
     36        $xapi_js_settings['context_activity'] = array(
     37            'id' => get_permalink(),
     38            'definition' => array(
     39                'type' => 'http://activitystrea.ms/schema/1.0/page',
     40                'name' => array(
     41                    'en' => wp_title("|", false),
     42                ),
     43                'moreInfo' => get_permalink(),
     44            ),
     45        );
     46    }
    3847
    39     // Permalink is not available in the admin interface.
    40     if (get_permalink()) {
    41         $s.="WP_H5P_XAPI_CONTEXTACTIVITY= {
    42             'id': '".get_permalink()."',
    43             'definition': {
    44                 'type': 'http://activitystrea.ms/schema/1.0/page',
    45                 'name': {
    46                     'en': '".wp_title("|",FALSE)."'
    47                 },
    48                 'moreInfo': '".get_permalink()."'
    49             }
    50         };";
    51     } else {
    52         $s.="WP_H5P_XAPI_CONTEXTACTIVITY=null;";
    53     }
    54     $s.="\n";
    55     $s.="</script>";
     48    wp_localize_script('wp-h5p-xapi', 'xapi_settings', $xapi_js_settings);
    5649
    57     echo $s;
    5850}
    5951
     
    6153 * Create the admin menu.
    6254 */
    63 function h5pxapi_admin_menu() {
    64     $settings=apply_filters("h5p-xapi-auth-settings",NULL);
     55function h5pxapi_admin_menu()
     56{
     57    $settings = apply_filters("h5p-xapi-auth-settings", null);
    6558
    66     if (!$settings) {
    67         add_options_page(
    68             'H5P xAPI',
    69             'H5P xAPI',
    70             'manage_options',
    71             'h5pxapi_settings',
    72             'h5pxapi_create_settings_page'
    73         );
    74     }
     59    if (!$settings) {
     60        add_options_page(
     61            'H5P xAPI',
     62            'H5P xAPI',
     63            'manage_options',
     64            'h5pxapi_settings',
     65            'h5pxapi_create_settings_page'
     66        );
     67    }
    7568}
    7669
     
    7871 * Admin init.
    7972 */
     73
    8074function h5pxapi_admin_init() {
    8175    register_setting("h5pxapi","h5pxapi_endpoint_url");
    8276    register_setting("h5pxapi","h5pxapi_username");
    8377    register_setting("h5pxapi","h5pxapi_password");
     78  register_setting("h5pxapi", "h5pxapi_alerts");
     79
    8480}
    8581
     
    8783 * Create settings page.
    8884 */
    89 function h5pxapi_create_settings_page() {
    90     wp_register_style("wp-h5p-xapi",plugins_url()."/wp-h5p-xapi/wp-h5p-xapi.css");
    91     wp_enqueue_style("wp-h5p-xapi");
     85function h5pxapi_create_settings_page()
     86{
     87    wp_register_style("wp-h5p-xapi", plugins_url() . "/wp-h5p-xapi/wp-h5p-xapi.css");
     88    wp_enqueue_style("wp-h5p-xapi");
    9289
    93     $template=new Template(__DIR__."/src/template/settings.tpl.php");
    94     $template->show();
     90    $template = new Template(__DIR__ . "/src/template/settings.tpl.php");
     91    $template->show();
    9592}
    9693
    97 add_action('wp_enqueue_scripts','h5pxapi_enqueue_scripts');
    98 add_action('admin_enqueue_scripts','h5pxapi_enqueue_scripts');
    99 add_action('admin_menu','h5pxapi_admin_menu');
    100 add_action('admin_init','h5pxapi_admin_init');
     94function h5pxapi_event_handler()
     95{
     96    require_once __DIR__.'/process-xapi-statement.php';
     97    wp_die();
     98}
    10199
    102 function h5pxapi_response_message($message) {
    103     global $h5pxapi_response_message;
     100add_action('wp_enqueue_scripts', 'h5pxapi_enqueue_scripts');
     101add_action('admin_enqueue_scripts', 'h5pxapi_enqueue_scripts');
     102add_action('admin_menu', 'h5pxapi_admin_menu');
     103add_action('admin_init', 'h5pxapi_admin_init');
     104add_action('wp_ajax_xapi_event', 'h5pxapi_event_handler');
     105add_action('wp_ajax_nopriv_xapi_event', 'h5pxapi_event_handler');
    104106
    105     $h5pxapi_response_message=$message;
     107function h5pxapi_response_message($message)
     108{
     109    global $h5pxapi_response_message;
     110
     111    $h5pxapi_response_message = $message;
    106112}
Note: See TracChangeset for help on using the changeset viewer.