-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhoto.php
More file actions
100 lines (76 loc) · 2.56 KB
/
Copy pathPhoto.php
File metadata and controls
100 lines (76 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace L3\Bundle\PhotoBundle;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class Photo extends AbstractExtension {
private $tokens = array();
private $uidToQuery = array();
private $cheminRepimage = "";
private $cheminReptoken = "";
public function __construct($cheminRepimage,$cheminReptoken)
{
$this->cheminRepimage = $cheminRepimage;
$this->cheminReptoken = $cheminReptoken;
}
public function getCheminRepimage()
{
return $this->cheminRepimage;
}
public function setCheminRepimage($cheminRepimage)
{
$this->cheminRepimage = $cheminRepimage;
return $this;
}
public function getCheminReptoken()
{
return $this->cheminReptoken;
}
public function setCheminReptoken($cheminReptoken)
{
$this->cheminReptoken = $cheminReptoken;
return $this;
}
public function getFunctions() {
return array(
new TwigFunction('photo', array($this, 'photo'))
);
}
public function photo($uid) {
return $this->cheminRepimage. $this->requestToken($uid);
}
/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName() {
return 'photo_extension';
}
public function preLoadToken($uid) {
$this->uidToQuery[] = $uid;
}
private function loadToken() {
if(count($this->uidToQuery) < 1) return;
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => json_encode($this->uidToQuery)
)
);
$context = stream_context_create($opts);
//$result = json_decode(file_get_contents('http://apps-php-test.univ-lille3.fr/~ppelisset/Lille3Photo/web/token/add', false, $context), true);
$result = json_decode(file_get_contents($this->cheminReptoken, false, $context), true);
foreach($result as $uid => $token) {
$this->tokens[$uid] = $token;
}
$this->uidToQuery = array();
}
private function requestToken($uid) {
$this->loadToken();
if(array_key_exists($uid, $this->tokens)) return $this->tokens[$uid];
//$this->tokens[$uid] = file_get_contents('http://apps-php-test.univ-lille3.fr/~ppelisset/Lille3Photo/web/token/add/' . $uid);
$this->tokens[$uid] = file_get_contents($this->cheminReptoken . "/" . $uid);
return $this->tokens[$uid];
}
}