1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class PluginRelease extends ElggFile { |
4
|
|
|
|
5
|
|
|
const SUBTYPE = 'plugin_release'; |
6
|
|
|
|
7
|
|
|
protected function initializeAttributes() { |
8
|
|
|
parent::initializeAttributes(); |
9
|
|
|
|
10
|
|
|
$this->attributes['subtype'] = self::SUBTYPE; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Get the plugin project for this release |
15
|
|
|
* @return PluginProject |
16
|
|
|
*/ |
17
|
|
|
public function getProject() { |
18
|
|
|
return get_entity($this->container_guid); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function isRecommendedRelease($elgg_version) { |
22
|
|
|
$recommended = (array) $this->recommended; |
23
|
|
|
|
24
|
|
|
return in_array($elgg_version, $recommended); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function updateDownloadCount() { |
28
|
|
|
create_annotation($this->guid, 'download', 1, 'integer', 0, ACCESS_PUBLIC); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function saveArchive($name) { |
32
|
|
|
$uf = get_uploaded_file($name); |
33
|
|
|
if (!$uf) { |
34
|
|
|
return FALSE; |
35
|
|
|
} |
36
|
|
|
$this->open("write"); |
37
|
|
|
$this->write($uf); |
38
|
|
|
$this->close(); |
39
|
|
|
|
40
|
|
|
return true; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* |
45
|
|
|
* @param array $recommended - an array of elgg versions this release is recommended for |
46
|
|
|
*/ |
47
|
|
|
public function setRecommended($recommended) { |
48
|
|
|
$project = $this->getProject(); |
49
|
|
|
|
50
|
|
|
$recommended = (array) $recommended; |
51
|
|
|
|
52
|
|
|
// update recommended if required |
53
|
|
|
if ($recommended) { |
|
|
|
|
54
|
|
|
$saved_r = array(); // the actual value saved - we don't set recommended on unless elgg_version is set |
55
|
|
|
foreach ($recommended as $ev) { |
56
|
|
|
if (!in_array($ev, (array) $this->elgg_version)) { |
57
|
|
|
continue; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
$saved_r[] = $ev; |
61
|
|
|
|
62
|
|
|
// remove recommended for this elgg version from other releases |
63
|
|
|
$existing_releases = $project->getReleasesByElggVersion($ev); |
64
|
|
|
if ($existing_releases) { |
65
|
|
|
foreach ($existing_releases as $r) { |
66
|
|
|
$r_recommended = (array) $r->recommended; |
67
|
|
|
if (($key = array_search($ev, $r_recommended)) !== false) { |
68
|
|
|
unset($r_recommended[$key]); |
69
|
|
|
} |
70
|
|
|
$r->recommended = $r_recommended; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$this->recommended = $saved_r; |
76
|
|
|
} |
77
|
|
|
else { |
78
|
|
|
$this->recommended = array(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Sets the hash that is used to uniquely identify this plugin |
84
|
|
|
*/ |
85
|
|
|
public function setHash() { |
86
|
|
|
$archiveName = $this->getFilenameOnFilestore(); |
87
|
|
|
|
88
|
|
|
$zip = new ZipArchive(); |
89
|
|
|
$result = $zip->open($archiveName); |
90
|
|
|
if ($result !== true) { |
91
|
|
|
return false; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
for ($i = 0; $i < $zip->numFiles; $i++) { |
95
|
|
|
$filename = $zip->getNameIndex($i); |
96
|
|
|
if (stripos($filename, 'manifest.xml') !== false) { |
97
|
|
|
$manifest = $zip->getFromIndex($i); |
98
|
|
|
$id = substr($filename, 0, strpos($filename, '/')); |
99
|
|
|
break; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
$zip->close(); |
104
|
|
|
|
105
|
|
|
if (!isset($manifest)) { |
106
|
|
|
return false; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
try { |
110
|
|
|
$manifest = new ElggPluginManifest($manifest); |
111
|
|
|
$author = $manifest->getAuthor(); |
112
|
|
|
$version = $manifest->getVersion(); |
113
|
|
|
|
114
|
|
|
$this->hash = md5($id . $version . $author); |
115
|
|
|
} catch (Exception $e) { |
116
|
|
|
// skip invalid manifests |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.