Skip to content

Commit

Permalink
added credential fetching, some diagnostics, and did a settings tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhunt committed Dec 23, 2021
1 parent 7e9c559 commit 6e05f3c
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 46 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Change List
=========
Version 3.1.51 (Build 2021122200)
- added some more modern diagnostics
- moved recorder order and some player settings from general to legacy
- added credential fetching

Version 3.1.50 (Build 2021120900)
- Fixed issues causing errors in php 8 on poodlltools

Expand Down
2 changes: 2 additions & 0 deletions classes/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
class constants {
const MOD_FRANKY = 'filter_poodll';
const M_COMP = 'filter_poodll';
const M_COMPONENT = 'filter_poodll';
const M_URL = 'filter/poodll';
const CLOUDPOODLL = 'https://cloud.poodll.com';
// const CLOUDPOODLL = 'https://cloudpoodll.poodll.com';
// const CLOUDPOODLL = 'http://localhost/moodle';
Expand Down
7 changes: 7 additions & 0 deletions classes/diagnosticstools.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,15 @@ public function compile_properties() {
$ds['data_field_version'] = get_config('datafield_poodll', 'version');
$ds['repository_poodll'] = get_config('repository_poodll', 'version');
$ds['atto_cloudpoodll_version'] = get_config('atto_cloudpoodll', 'version');
$ds['tinymce_cloudpoodll_version'] = get_config('tinymce_cloudpoodll', 'version');
$ds['assignsubmission_cloudpoodll_version'] = get_config('assignsubmission_cloudpoodll', 'version');
$ds['assignfeedback_cloudpoodll_version'] = get_config('assignfeedback_cloudpoodll', 'version');
$ds['qtype_cloudpoodll_version'] = get_config('qtype_cloudpoodll', 'version');
$ds['mod_readaloud_version'] = get_config('mod_readaloud', 'version');
$ds['mod_solo_version'] = get_config('mod_solo', 'version');
$ds['mod_minilesson_version'] = get_config('mod_minilesson', 'version');
$ds['mod_wordcards_version'] = get_config('mod_wordcards', 'version');
$ds['mod_pchat_version'] = get_config('mod_pchat', 'version');

//Registration Key info
$lm = new \filter_poodll\licensemanager();
Expand Down
120 changes: 77 additions & 43 deletions classes/settingstools.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function fetch_jumpcat_items($poodllcat) {
}

public static function fetch_general_items() {
global $CFG;
global $CFG, $OUTPUT;
$items = array();

$items[] = new \admin_setting_heading('filter_poodll_registration_settings',
Expand All @@ -54,17 +54,50 @@ public static function fetch_general_items() {
$items[] = new \admin_setting_configtext('filter_poodll/cpapiuser', get_string('cpapiuser', 'filter_poodll'),
get_string('cpapiuser_details', 'filter_poodll'), '');

//we show a summary of the users apps if we can get the info
$apiuser = get_config('filter_poodll', 'cpapiuser');
$apisecret = get_config('filter_poodll', 'cpapisecret');
if ($apiuser && $apisecret) {
$cloudpoodll_apiuser = get_config('filter_poodll', 'cpapiuser');
$cloudpoodll_apisecret = get_config('filter_poodll', 'cpapisecret');
$show_below_apisecret='';

//if we have an API user and secret we fetch token
if(!empty($cloudpoodll_apiuser) && !empty($cloudpoodll_apisecret)) {
$lm = new \filter_poodll\licensemanager();
$tokeninfo = $lm->fetch_token_for_display($apiuser, $apisecret);
} else {
$tokeninfo = get_string('cpapisecret_details', 'filter_poodll');
$tokeninfo = $lm->fetch_token_for_display($cloudpoodll_apiuser, $cloudpoodll_apisecret);
$show_below_apisecret=$tokeninfo;
//if we have no API user and secret we show a "fetch from elsewhere on site" or "take a free trial" link
}else{
$amddata=['apppath'=>$CFG->wwwroot . '/' .constants::M_URL];
$cp_components=['qtype_cloudpoodll','mod_readaloud','mod_wordcards','mod_solo','mod_minilesson','mod_englishcentral','mod_pchat',
'atto_cloudpoodll','tinymce_cloudpoodll', 'assignsubmission_cloudpoodll','assignfeedback_cloudpoodll'];
foreach($cp_components as $cp_component){
switch($cp_component){
case 'filter_poodll':
$apiusersetting='cpapiuser';
$apisecretsetting='cpapisecret';
break;
case 'mod_englishcentral':
$apiusersetting='poodllapiuser';
$apisecretsetting='poodllapisecret';
break;
default:
$apiusersetting='apiuser';
$apisecretsetting='apisecret';
}
$cloudpoodll_apiuser=get_config($cp_component,$apiusersetting);
if(!empty($cloudpoodll_apiuser)){
$cloudpoodll_apisecret=get_config($cp_component,$apisecretsetting);
if(!empty($cloudpoodll_apisecret)){
$amddata['apiuser']=$cloudpoodll_apiuser;
$amddata['apisecret']=$cloudpoodll_apisecret;
break;
}
}
}
$show_below_apisecret=$OUTPUT->render_from_template( constants::M_COMPONENT . '/managecreds',$amddata);
}


$items[] = new \admin_setting_configtext('filter_poodll/cpapisecret', get_string('cpapisecret', 'filter_poodll'),
$tokeninfo, '');
$show_below_apisecret, '');

//Adding Amazon AWS regions
$options = self::fetch_awsregion_options();
Expand All @@ -78,38 +111,6 @@ public static function fetch_general_items() {
$items[] = new \admin_setting_configcheckbox('filter_poodll_cloudnotifications',
get_string('usecloudnotifications', 'filter_poodll'), get_string('usecloudnotifications_desc', 'filter_poodll'), 1);


$items[] = new \admin_setting_heading('filter_poodll_recorderorder_heading', get_string('recorderorder', 'filter_poodll'),
get_string('recorderorder_desc', 'filter_poodll'));

//PoodLL player type settings.
$items[] = new \admin_setting_configtext('filter_poodll_recorderorder_audio',
get_string('recorderorder_audio', 'filter_poodll'),
get_string('recorderorder_audio_desc', 'filter_poodll'), 'media,mobile,flashaudio,red5,upload', PARAM_TEXT);

//PoodLL player type settings.
$items[] = new \admin_setting_configtext('filter_poodll_recorderorder_video',
get_string('recorderorder_video', 'filter_poodll'),
get_string('recorderorder_video_desc', 'filter_poodll'), 'media,mobile,red5,upload', PARAM_TEXT);

//PoodLL player type settings.
$items[] = new \admin_setting_configtext('filter_poodll_recorderorder_whiteboard',
get_string('recorderorder_whiteboard', 'filter_poodll'),
get_string('recorderorder_whiteboard_desc', 'filter_poodll'), 'upload', PARAM_TEXT);

//PoodLL player type settings.
$items[] = new \admin_setting_configtext('filter_poodll_recorderorder_snapshot',
get_string('recorderorder_snapshot', 'filter_poodll'),
get_string('recorderorder_snapshot_desc', 'filter_poodll'), 'snapshot,upload', PARAM_TEXT);

//Allow Adobe Flash on Android
$items[] =
new \admin_setting_configcheckbox('filter_poodll_flash_on_android', get_string('flashonandroid', 'filter_poodll'),
get_string('flashonandroid_desc', 'filter_poodll'), 0);

$items[] = new \admin_setting_configcheckbox('filter_poodll_download_media_ok',
get_string('showdownloadicon', 'filter_poodll'), get_string('showdownloadicon_desc', 'filter_poodll'), 0);

//html5 recorder settings.
$items[] = new \admin_setting_heading('filter_poodll_html5recorder_settings',
get_string('filter_poodll_html5recorder_heading', 'filter_poodll'), '');
Expand All @@ -125,8 +126,10 @@ public static function fetch_general_items() {
get_string('skinstyleaudio_details', 'filter_poodll'), '');
$items[] = new \admin_setting_configtext('filter_poodll/skinstylevideo', get_string('skinstylevideo', 'filter_poodll'),
get_string('skinstylevideo_details', 'filter_poodll'), '');
$items[] = new \admin_setting_configcheckbox('filter_poodll_html5ondsafari', get_string('html5ondsafari', 'filter_poodll'),
get_string('html5ondsafaridetails', 'filter_poodll'), 0);

$items[] = new \admin_setting_configcheckbox('filter_poodll_download_media_ok',
get_string('showdownloadicon', 'filter_poodll'), get_string('showdownloadicon_desc', 'filter_poodll'), 0);


//PoodLL Whiteboard
$items[] = new \admin_setting_heading('filter_poodll_whiteboard_setting',
Expand Down Expand Up @@ -233,6 +236,37 @@ public static function fetch_legacy_items() {
global $CFG;
$items = array();

$items[] = new \admin_setting_heading('filter_poodll_recorderorder_heading', get_string('recorderorder', 'filter_poodll'),
get_string('recorderorder_desc', 'filter_poodll'));

//PoodLL player type settings.
$items[] = new \admin_setting_configtext('filter_poodll_recorderorder_audio',
get_string('recorderorder_audio', 'filter_poodll'),
get_string('recorderorder_audio_desc', 'filter_poodll'), 'media,mobile,flashaudio,red5,upload', PARAM_TEXT);

//PoodLL player type settings.
$items[] = new \admin_setting_configtext('filter_poodll_recorderorder_video',
get_string('recorderorder_video', 'filter_poodll'),
get_string('recorderorder_video_desc', 'filter_poodll'), 'media,mobile,red5,upload', PARAM_TEXT);

//PoodLL player type settings.
$items[] = new \admin_setting_configtext('filter_poodll_recorderorder_whiteboard',
get_string('recorderorder_whiteboard', 'filter_poodll'),
get_string('recorderorder_whiteboard_desc', 'filter_poodll'), 'upload', PARAM_TEXT);

//PoodLL player type settings.
$items[] = new \admin_setting_configtext('filter_poodll_recorderorder_snapshot',
get_string('recorderorder_snapshot', 'filter_poodll'),
get_string('recorderorder_snapshot_desc', 'filter_poodll'), 'snapshot,upload', PARAM_TEXT);

//Allow Adobe Flash on Android
$items[] =
new \admin_setting_configcheckbox('filter_poodll_flash_on_android', get_string('flashonandroid', 'filter_poodll'),
get_string('flashonandroid_desc', 'filter_poodll'), 0);

$items[] = new \admin_setting_configcheckbox('filter_poodll_html5ondsafari', get_string('html5ondsafari', 'filter_poodll'),
get_string('html5ondsafaridetails', 'filter_poodll'), 0);

//PoodLL Network Settings.
$items[] = new \admin_setting_heading('filter_poodll_network_settings',
get_string('filter_poodll_network_heading', 'filter_poodll'), '');
Expand Down
46 changes: 46 additions & 0 deletions fetchcbpage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* A Free Trial Jumper
*
*
* @package filter_poodll
* @copyright Justin Hunt ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/


require_once(dirname(dirname(dirname(__FILE__))).'/config.php');

use \filter_poodll\constants;

require_login(0, false);
$systemcontext = context_system::instance();
$PAGE->set_context($systemcontext);
$PAGE->set_url('/' . CONSTANTS::M_URL . '/fetchcbpage.php');

if(has_capability('moodle/site:config',$systemcontext)){

$amddata=['poodllcbsite'=>'poodllcom','wwwroot'=>$CFG->wwwroot,
'first_name'=>$USER->firstname,'last_name'=>$USER->lastname,'email'=>$USER->email,'country'=>$USER->country];
echo $OUTPUT->header();
echo $OUTPUT->render_from_template( constants::M_COMPONENT . '/fetchcbpage',$amddata);
echo $OUTPUT->footer();
}else{
echo "no permission to do that action";
}
6 changes: 5 additions & 1 deletion lang/en/filter_poodll.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,8 @@
$string['no_subscriptions'] = 'No subscriptions.';
$string['failedfetchsubreport'] = 'Failed to fetch subscription report';


$string['freetrial'] = "Get Cloud Poodll API Credentials and a Free Trial";
$string['freetrial_desc'] = "A dialog should appear that allows you to register for a free trial with Poodll. After registering you should login to the members dashboard to get your API user and secret. And to register your site URL.";
$string['memberdashboard'] = "Member Dashboard";
$string['memberdashboard_desc'] = "";
$string['fillcredentials']="Set API user and secret with existing credentials";
28 changes: 28 additions & 0 deletions templates/fetchcbpage.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

<h2>{{#str}}freetrial, filter_poodll{{/str}}</h2>
<div class="filter_poodll_freetrial_desc">
{{#str}}freetrial_desc, filter_poodll{{/str}}
</div>
{{^element.frozen}}
{{#js}}
require(['jquery'],function($) {
//set up checkout links
$.getScript('https://js.chargebee.com/v2/chargebee.js', function(){
var chargebee = Chargebee.init({'site': '{{poodllcbsite}}', isItemsModel: true});
var cart = chargebee.getCart()
var planPriceId = 'Poodll-Free-Trial-USD-Daily';
var planPriceQuantity = 1
var product = chargebee.initializeProduct(planPriceId, planPriceQuantity)
cart.replaceProduct(product);
var customer = {email: "{{email}}", billing_address: {first_name: "{{first_name}}",last_name: "{{last_name}}", country: "{{country}}"}};
cart.setCustomer(customer);
// Passing values for custom fields
product.setCustomData({cf_startsiteurl: "{{{wwwroot}}}"});

// Opening the checkout
cart.proceedToCheckout();
});

});
{{/js}}
{{/element.frozen}}
20 changes: 20 additions & 0 deletions templates/managecreds.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="filter_poodll_credsmanager">
<!-- If API user then show a link + js to poke creds in -->
{{#apiuser}}<a href="#" class="cloudpoodll_poke_creds">{{#str}}fillcredentials, filter_poodll{{/str}}</a>{{/apiuser}}
<!-- if no API user then the user sees a link to a page which will allow them to take a free trial -->
{{^apiuser}}<a href="{{{apppath}}}/fetchcbpage.php" target="_blank">{{#str}}freetrial, filter_poodll{{/str}} [&#x2197;]</a>{{/apiuser}}
</div>
{{^element.frozen}}
{{#js}}
require(['jquery'],function($) {
//set up fetch from elsewhere
$(".filter_poodll_credsmanager .cloudpoodll_poke_creds").on("click", function() {
event.preventDefault();
var apiuser = document.getElementById('id_s_filter_poodll_cpapiuser');
var apisecret = document.getElementById('id_s_filter_poodll_cpapisecret');
apiuser.value='{{{apiuser}}}';
apisecret.value='{{{apisecret}}}';
});
});
{{/js}}
{{/element.frozen}}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021120900;
$plugin->version = 2021122200;
$plugin->requires = 2016052300;//moodle 3.1.0
$plugin->component = 'filter_poodll';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '3.1.50 (Build 2021120900)';
$plugin->release = '3.1.51 (Build 2021122200)';

0 comments on commit 6e05f3c

Please sign in to comment.