|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MySociety\TheyWorkForYou\Utility; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Member Utilities |
|
7
|
|
|
* |
|
8
|
|
|
* Utility functions related to members |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
class Member |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Find Member Image |
|
16
|
|
|
* |
|
17
|
|
|
* Return the member's image and associated information. |
|
18
|
|
|
* |
|
19
|
|
|
* @param string $pid The member's ID. |
|
20
|
|
|
* @param bool $smallonly Should the function only return a small sized image? |
|
21
|
|
|
* @param bool|string $substitute_missing Should the function substitute a placeholder if no image can be found? |
|
22
|
|
|
* |
|
23
|
|
|
* @return array Array of the member's image URL and image size. |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
5 |
|
public static function findMemberImage($pid, $smallonly = false, $substitute_missing = false) { |
|
27
|
5 |
|
$image = null; $sz = null; |
|
28
|
5 |
|
if (!$smallonly && is_file(BASEDIR . '/images/mpsL/' . $pid . '.jpeg')) { |
|
29
|
|
|
$image = IMAGEPATH . 'mpsL/' . $pid . '.jpeg'; |
|
30
|
|
|
$sz = 'L'; |
|
31
|
5 |
|
} elseif (!$smallonly && is_file(BASEDIR . '/images/mpsL/' . $pid . '.jpg')) { |
|
32
|
|
|
$image = IMAGEPATH . 'mpsL/' . $pid . '.jpg'; |
|
33
|
|
|
$sz = 'L'; |
|
34
|
5 |
|
} elseif (!$smallonly && is_file(BASEDIR . '/images/mpsL/' . $pid . '.png')) { |
|
35
|
|
|
$image = IMAGEPATH . 'mpsL/' . $pid . '.png'; |
|
36
|
|
|
$sz = 'L'; |
|
37
|
5 |
|
} elseif (is_file(BASEDIR . '/images/mps/' . $pid . '.jpeg')) { |
|
38
|
1 |
|
$image = IMAGEPATH . 'mps/' . $pid . '.jpeg'; |
|
39
|
1 |
|
$sz = 'S'; |
|
40
|
5 |
|
} elseif (is_file(BASEDIR . '/images/mps/' . $pid . '.jpg')) { |
|
41
|
1 |
|
$image = IMAGEPATH . 'mps/' . $pid . '.jpg'; |
|
42
|
1 |
|
$sz = 'S'; |
|
43
|
5 |
|
} elseif (is_file(BASEDIR . '/images/mps/' . $pid . '.png')) { |
|
44
|
1 |
|
$image = IMAGEPATH . 'mps/' . $pid . '.png'; |
|
45
|
1 |
|
$sz = 'S'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
//if no image, use a dummy one |
|
49
|
5 |
|
if (!$image && $substitute_missing) { |
|
50
|
5 |
|
if ($smallonly) { |
|
51
|
5 |
|
if ($substitute_missing === "lord") { |
|
52
|
2 |
|
$image = IMAGEPATH . "unknownlord.png"; |
|
53
|
|
|
} else { |
|
54
|
4 |
|
$image = IMAGEPATH . "unknownperson.png"; |
|
55
|
|
|
} |
|
56
|
5 |
|
$sz = 'S'; |
|
57
|
|
|
} else { |
|
58
|
1 |
|
if ($substitute_missing === "lord") { |
|
59
|
1 |
|
$image = IMAGEPATH . "unknownlord_large.png"; |
|
60
|
|
|
} else { |
|
61
|
1 |
|
$image = IMAGEPATH . "unknownperson_large.png"; |
|
62
|
|
|
} |
|
63
|
1 |
|
$sz = 'L'; |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
5 |
|
return array($image, $sz); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|