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