Skip to content

Commit

Permalink
added support for cloud poodll widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhunt committed Sep 4, 2018
1 parent 9f7eeee commit 9f70918
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Change List
=========
Version 1.4.04(Build 2018090300)
-added Cloud Poodll support
-added Poodll Popup Recorder template

Version 1.4.03(Build 2018070900)
-added clear template preset (for clearing templates)

Expand Down
63 changes: 63 additions & 0 deletions classes/generico_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,67 @@ public static function setting_file_serve($filearea, $args, $forcedownload, $opt
public static function update_revision() {
set_config('revision', time(), 'filter_generico');
}

//We need a Poodll token to make cloudpoodll happen
public static function fetch_token($apiuser, $apisecret)
{

$cache = \cache::make_from_params(\cache_store::MODE_APPLICATION, 'filter_generico', 'token');
$tokenobject = $cache->get('recentpoodlltoken');
$tokenuser = $cache->get('recentpoodlluser');

//if we got a token and its less than expiry time
// use the cached one
if($tokenobject && $tokenuser && $tokenuser==$apiuser){
if($tokenobject->validuntil == 0 || $tokenobject->validuntil > time()){
return $tokenobject->token;
}
}

// Send the request & save response to $resp
$token_url ="https://cloud.poodll.com/local/cpapi/poodlltoken.php?username=$apiuser&password=$apisecret&service=cloud_poodll";
$token_response = self::curl_fetch($token_url);
if ($token_response) {
$resp_object = json_decode($token_response);
if($resp_object && property_exists($resp_object,'token')) {
$token = $resp_object->token;
//store the expiry timestamp and adjust it for diffs between our server times
if($resp_object->validuntil) {
$validuntil = $resp_object->validuntil - ($resp_object->poodlltime - time());
//we refresh one hour out, to prevent any overlap
$validuntil = $validuntil - (1 * HOURSECS);
}else{
$validuntil = 0;
}

//cache the token
$tokenobject = new \stdClass();
$tokenobject->token = $token;
$tokenobject->validuntil = $validuntil;
$cache->set('recentpoodlltoken', $tokenobject);
$cache->set('recentpoodlluser', $apiuser);

}else{
$token = '';
if($resp_object && property_exists($resp_object,'error')) {
//ERROR = $resp_object->error
}
}
}else{
$token='';
}
return $token;
}

//we use curl to fetch transcripts from AWS and Tokens from cloudpoodll
//this is our helper
public static function curl_fetch($url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
curl_close($curl);
return $data;
}
}
8 changes: 8 additions & 0 deletions filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ function filter_generico_callback(array $link){
//stash this for passing to js
$filterprops['AUTOID']=$autoid;

//If we need a Cloud Poodll token, lets fetch it
if(strpos($genericotemplate,'@@CLOUDPOODLLTOKEN@@') &&
!empty($conf['cpapiuser']) &&
!empty($conf['cpapisecret'])){
$token = \filter_poodll\poodlltools::fetch_token($conf['cpapiuser'],$conf['cpapisecret']);
$genericotemplate = str_replace('@@CLOUDPOODLLTOKEN@@',$token,$genericotemplate);
}

//If template requires a MOODLEPAGEID lets give them one
//this is legacy really. Now we have @@URLPARAM we could do it that way
$moodlepageid = optional_param('id',0,PARAM_INT);
Expand Down
10 changes: 9 additions & 1 deletion lang/en/filter_generico.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,12 @@
//Settings tree headings
$string['templates']='Templates';
$string['jumpcat_heading']='Generico filter settings';
$string['jumpcat_explanation']='The full set of Generico filter settings can be found <a href="{$a}">here</a>.';
$string['jumpcat_explanation']='The full set of Generico filter settings can be found <a href="{$a}">here</a>.';

//cloud poodll settings
$string['cpapi_heading'] = 'Cloud Poodll API Settings';
$string['cpapi_heading_desc'] = "Cloud Poodll allows you to embed recorders direct from cloud.poodll.com in widgets. This is optional and you do not need to fill this in.";
$string['cpapiuser'] = 'Cloud Poodll Username';
$string['cpapiuser_details'] = 'This is the same as your username at Poodll.com.';
$string['cpapisecret'] = 'Cloud Poodll API Secret';
$string['cpapisecret_details'] = "This is a special secret key that can be generated from the <a href='https://support.poodll.com/support/solutions/articles/19000083076-cloud-poodll-api-secret'>API tab</a> in your members area on Poodll.com. ";
1 change: 1 addition & 0 deletions presets/popuprecorder.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"Popup Recorder","key":"popuprecorder","version":"1.0.4","instructions":"Embeds a Popup recorder that you can download recording from on the page.","showatto":"1","showplayers":"0","requirecss":"","requirejs":"https://cdn.jsdelivr.net/gh/justinhunt/cloudpoodll@latest/amd/build/cloudpoodll.min.js","shim":"","defaults":"","amd":"1","body":"<!-- Button trigger modal -->\n<button type=\"button\" class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\"#@@AUTOID@@_trigger\">\n Audio Recorder\n</button>\n\n<!-- Modal -->\n<div class=\"modal fade\" id=\"@@AUTOID@@_trigger\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"exampleModalCenterTitle\" aria-hidden=\"true\">\n <div class=\"modal-dialog modal-dialog-centered\" role=\"document\">\n <div class=\"modal-content\">\n <div class=\"modal-header\">\n <h5 class=\"modal-title\" id=\"exampleModalLongTitle\">Record Audio</h5>\n <button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-label=\"Close\">\n <span aria-hidden=\"true\">&times;</span>\n </button>\n </div>\n <div class=\"modal-body\">\n <div id=\"@@AUTOID@@\" class=\"poodllrecorder\" data-parent=\"@@WWWROOT@@\" data-type=\"fresh\" data-width=\"380\" data-height=\"280\" data-id=\"@@AUTOID@@_widget\" data-media=\"audio\" data-token=\"@@CLOUDPOODLLTOKEN@@\" />\n </div>\n <div id=\"@@AUTOID@@_download\" style=\"display: none;\">\n <a id=\"@@AUTOID@@_download_button\" class=\"btn btn-success pf-popuprecorder-downloadbutton\" download>Download</a>\n <a id=\"@@AUTOID@@_reset_button\" href=\"#\" class=\"pf-popuprecorder-resetbutton\">New recording</a>\n </div> \n </div>\n </div>\n</div>","bodyend":"","script":"CloudPoodll = requiredjs_popuprecorder;\n\n//CloudPoodll.autoCreateRecorders();\nCloudPoodll.createRecorder(@@AUTOID@@);\n\nCloudPoodll.theCallback = function(message){\n console.log(message);\n switch(message.type){\n case 'filesubmitted':\n var dlink =\"https://cloud.poodll.com/local/cpapi/downloader.php?p=\"+message.mediaurl+\"&n=\"+message.mediafilename;\n $('#' + @@AUTOID@@ + '_download_button').attr('href',dlink);\n $('#' + @@AUTOID@@).hide();\n $('#' + @@AUTOID@@ + '_download').show(); \n }\n};\nCloudPoodll.initEvents();\n\n $('#' + @@AUTOID@@ + '_reset_button').click(function(){\n$('#' + @@AUTOID@@).empty(); \nCloudPoodll.createRecorder(@@AUTOID@@);\n$('#' + @@AUTOID@@).show();\n$('#' + @@AUTOID@@ + '_download').hide(); \n}\n);\n","style":".pf-popuprecorder-downloadbutton{\n margin: auto;\n text-align: center;\n display: block;\n}\n.poodllrecorder{\nmargin: auto;\n}\n.pf-popuprecorder-resetbutton{\n text-align: right;\n}","dataset":"","datasetvars":"","alternate":"","alternateend":""}
9 changes: 7 additions & 2 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@
get_string('templatecount_desc', 'filter_generico'),
\filter_generico\generico_utils::FILTER_GENERICO_TEMPLATE_COUNT, PARAM_INT,20));

//cloud poodll credentials
$settings_page->add(new admin_setting_heading('filter_generico_cpapi_settings', get_string('cpapi_heading', 'filter_generico'), get_string('cpapi_heading_desc', 'filter_generico')));
$settings_page->add(new admin_setting_configtext('filter_generico/cpapiuser', get_string('cpapiuser', 'filter_generico'),
get_string('cpapiuser_details', 'filter_generico'), ''));
$settings_page->add(new admin_setting_configtext('filter_generico/cpapisecret', get_string('cpapisecret', 'filter_generico'),
get_string('cpapisecret_details', 'filter_generico'), ''));

//add page to category
$ADMIN->add($generico_category_name, $settings_page);



$genericotemplatesadmin_settings = new admin_externalpage('genericotemplatesadmin', get_string('templates', 'filter_generico'),
$CFG->wwwroot . '/filter/generico/genericotemplatesadmin.php' );

Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

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

$plugin->version = 2018070900; // The current plugin version (Date: YYYYMMDDXX)
$plugin->version = 2018090300; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2011070100; // Requires this Moodle version
$plugin->component = 'filter_generico'; // Full name of the plugin (used for diagnostics)
$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Version 1.4.03(Build 2018070900)';
$plugin->release = 'Version 1.4.04(Build 2018090300)';

0 comments on commit 9f70918

Please sign in to comment.