changed git call from https to git readonly
[atutor.git] / mods / atutor_opencaps / opencaps / include / matterhorn.inc.php
1 <?php
2 /*
3  * OpenCaps
4  * http://opencaps.atrc.utoronto.ca
5  * 
6  * Copyright 2010 Heidi Hazelton
7  * Adaptive Technology Resource Centre, University of Toronto
8  * 
9  * Licensed under the Educational Community License (ECL), Version 2.0. 
10  * You may not use this file except in compliance with this License.
11  * http://www.opensource.org/licenses/ecl2.php
12  * 
13  */
14
15 if (!defined('INCLUDE_PATH')) {
16         define('INCLUDE_PATH', 'include/');
17 }
18
19
20 /* digest auth */
21 function matterhornAuth($rid, $uri, $content='') {
22         global $remote_systems, $this_proj;
23                 
24     $username = $remote_systems[$rid]['username'];
25     $password = $remote_systems[$rid]['password'];
26                 
27         $ch = curl_init();
28     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
29     
30     curl_setopt($ch, CURLOPT_URL, $remote_systems[$rid]['url'].$uri);
31     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
32     curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);   
33         curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Requested-Auth: Digest")); 
34         
35     if ($content == "media") {
36         curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
37         
38         $temp_file = 'projects/'.$this_proj->id.'/media'; //use tempname();
39         $fh = fopen($temp_file, 'w');
40                 curl_setopt($ch, CURLOPT_FILE, $fh);
41                 curl_exec($ch);
42                 curl_close($ch);
43                 fclose($fh); 
44                 return $temp_file;
45                 
46     } else if (!empty($content)) {
47             curl_setopt($ch, CURLOPT_POST, 1);
48         curl_setopt($ch, CURLOPT_POSTFIELDS, $content);   
49     }
50         
51     $response = curl_exec($ch);
52     $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
53
54     curl_close($ch);
55
56         return $response;
57
58 }
59
60
61 ?>