diff --git a/CHANGES.txt b/CHANGES.txt index 1ae765c..ae8f131 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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) diff --git a/classes/generico_utils.php b/classes/generico_utils.php index ec89102..eda1663 100644 --- a/classes/generico_utils.php +++ b/classes/generico_utils.php @@ -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; + } } \ No newline at end of file diff --git a/filter.php b/filter.php index 14a1535..878131c 100644 --- a/filter.php +++ b/filter.php @@ -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); diff --git a/lang/en/filter_generico.php b/lang/en/filter_generico.php index daef293..a062ec2 100644 --- a/lang/en/filter_generico.php +++ b/lang/en/filter_generico.php @@ -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 here.'; \ No newline at end of file +$string['jumpcat_explanation']='The full set of Generico filter settings can be found here.'; + +//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 API tab in your members area on Poodll.com. "; diff --git a/presets/popuprecorder.txt b/presets/popuprecorder.txt new file mode 100644 index 0000000..1ea6b0d --- /dev/null +++ b/presets/popuprecorder.txt @@ -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":"\n\n\n\n
\n
\n
\n
\n
Record Audio
\n \n
\n
\n
\n
\n \n
\n
\n
","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":""} \ No newline at end of file diff --git a/settings.php b/settings.php index 4a48f5f..4fe5d58 100644 --- a/settings.php +++ b/settings.php @@ -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' ); diff --git a/version.php b/version.php index de351ad..9aeefdd 100644 --- a/version.php +++ b/version.php @@ -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)';