1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
/**
|
4
|
|
|
* Elgg plugin project creation action
|
5
|
|
|
*/
|
6
|
|
|
|
7
|
|
|
namespace Elgg\CommunityPlugins;
|
8
|
|
|
|
9
|
|
|
use PluginProject;
|
10
|
|
|
use PluginRelease;
|
11
|
|
|
|
12
|
|
|
elgg_make_sticky_form('community_plugins');
|
13
|
|
|
|
14
|
|
|
// Get variables
|
15
|
|
|
$title = strip_tags(get_input("title"));
|
16
|
|
|
$description = plugins_strip_tags(get_input("description"));
|
17
|
|
|
$tags = get_input("tags");
|
18
|
|
|
$summary = strip_tags(elgg_substr(get_input('summary'), 0, 250));
|
19
|
|
|
$homepage = strip_tags(get_input('homepage'));
|
20
|
|
|
$donate = strip_tags(get_input('donate'));
|
21
|
|
|
$repo = strip_tags(get_input('repo'));
|
22
|
|
|
$license = get_input('license');
|
23
|
|
|
$plugincat = get_input('plugincat', 'uncategorized');
|
24
|
|
|
$project_access_id = get_input("project_access_id", ACCESS_PUBLIC);
|
25
|
|
|
$plugin_type = get_input('plugin_type');
|
26
|
|
|
if ($plugin_type != 'theme' && $plugin_type != 'languagepack') {
|
27
|
|
|
$plugin_type = 'plugin';
|
28
|
|
|
}
|
29
|
|
|
|
30
|
|
|
$release_notes = plugins_strip_tags(get_input('release_notes'));
|
31
|
|
|
$elgg_version = get_input('elgg_version', false);
|
32
|
|
|
$comments = get_input('comments', 'yes');
|
33
|
|
|
$version = strip_tags(get_input('version'));
|
34
|
|
|
$recommended = get_input('recommended', array());
|
35
|
|
|
$release_access_id = get_input('release_access_id', ACCESS_PUBLIC);
|
36
|
|
|
|
37
|
|
|
$user = elgg_get_logged_in_user_entity();
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
// validate data
|
41
|
|
|
if (!$title) {
|
42
|
|
|
register_error(elgg_echo('plugins:error:notitle'));
|
43
|
|
|
forward(REFERER);
|
44
|
|
|
}
|
45
|
|
|
$licenses = elgg_get_config('gpllicenses');
|
46
|
|
|
if ($license == 'none' || !array_key_exists($license, $licenses)) {
|
47
|
|
|
register_error(elgg_echo('plugins:error:badlicense'));
|
48
|
|
|
forward(REFERER);
|
49
|
|
|
}
|
50
|
|
|
$mimetype = get_mimetype('upload');
|
51
|
|
|
if (!$mimetype) {
|
52
|
|
|
register_error(elgg_echo('plugins:error:badformat'));
|
53
|
|
|
forward(REFERER);
|
54
|
|
|
}
|
55
|
|
|
|
56
|
|
|
// version is sent but null, so get_input doesn't use defaults.
|
57
|
|
|
if (!$version) {
|
58
|
|
|
register_error(elgg_echo('plugins:error:no_version'));
|
59
|
|
|
forward(REFERER);
|
60
|
|
|
}
|
61
|
|
|
|
62
|
|
|
// we require an elgg version now
|
63
|
|
|
if (!$elgg_version) {
|
64
|
|
|
register_error(elgg_echo('plugins:error:no_elgg_version'));
|
65
|
|
|
forward(REFERER);
|
66
|
|
|
}
|
67
|
|
|
|
68
|
|
|
// Create the plugin project
|
69
|
|
|
$plugin_project = new PluginProject();
|
70
|
|
|
$plugin_project->owner_guid = $user->getGUID();
|
71
|
|
|
$plugin_project->container_guid = $user->getGUID();
|
72
|
|
|
$plugin_project->access_id = $project_access_id;
|
73
|
|
|
$plugin_project->title = $title;
|
74
|
|
|
$plugin_project->description = $description;
|
75
|
|
|
$plugin_project->tags = string_to_tag_array($tags);
|
76
|
|
|
$plugin_project->plugincat = $plugincat;
|
77
|
|
|
$plugin_project->license = $license;
|
78
|
|
|
$plugin_project->summary = $summary;
|
79
|
|
|
$plugin_project->homepage = $homepage;
|
80
|
|
|
$plugin_project->repo = $repo;
|
81
|
|
|
$plugin_project->donate = $donate;
|
82
|
|
|
$plugin_project->digg = 0;
|
83
|
|
|
$plugin_project->plugin_type = $plugin_type;
|
84
|
|
|
$plugin_project->save();
|
85
|
|
|
|
86
|
|
|
// Extract file and save to default filestore (for now)
|
87
|
|
|
$prefix = "plugins/";
|
88
|
|
|
$filestorename = $prefix . strtolower(time() . $_FILES['upload']['name']);
|
89
|
|
|
$release = new PluginRelease();
|
90
|
|
|
$release->title = $plugin_project->title;
|
91
|
|
|
$release->setFilename($filestorename);
|
92
|
|
|
$release->setMimetype($mimetype);
|
93
|
|
|
$release->originalfilename = $_FILES['upload']['name'];
|
94
|
|
|
$release->access_id = $release_access_id;
|
95
|
|
|
$release->container_guid = $plugin_project->getGUID();
|
96
|
|
|
$release->version = $version;
|
97
|
|
|
$release->release_notes = $release_notes;
|
98
|
|
|
$release->elgg_version = $elgg_version;
|
99
|
|
|
$release->comments = $comments;
|
100
|
|
|
$release->save();
|
101
|
|
|
|
102
|
|
View Code Duplication |
if ($release->saveArchive('upload') != TRUE) {
|
|
|
|
|
103
|
|
|
register_error(elgg_echo("plugins:error:uploadfailed"));
|
104
|
|
|
forward(REFERER);
|
105
|
|
|
}
|
106
|
|
|
|
107
|
|
View Code Duplication |
if (!$plugin_project->getGUID() || !$release->getGUID()) {
|
|
|
|
|
108
|
|
|
register_error(elgg_echo("plugins:error:uploadfailed"));
|
109
|
|
|
forward(REFERER);
|
110
|
|
|
}
|
111
|
|
|
|
112
|
|
|
$release->setRecommended($recommended);
|
113
|
|
|
|
114
|
|
|
// check for any project images and associate them with the project
|
115
|
|
|
$max_num_images = 4;
|
116
|
|
View Code Duplication |
for ($i = 1; $i <= $max_num_images; $i++) {
|
|
|
|
|
117
|
|
|
if (!array_key_exists("image_$i", $_FILES)) {
|
118
|
|
|
continue;
|
119
|
|
|
}
|
120
|
|
|
|
121
|
|
|
$desc = get_input("image_{$i}_desc");
|
122
|
|
|
|
123
|
|
|
$plugin_project->saveImage("image_$i", $desc, $i);
|
124
|
|
|
}
|
125
|
|
|
|
126
|
|
|
elgg_create_river_item(array(
|
127
|
|
|
'view' => 'river/object/plugin_project/create',
|
128
|
|
|
'action_type' => 'create',
|
129
|
|
|
'subject_guid' => $user->getGUID(),
|
130
|
|
|
'object_guid' => $plugin_project->getGUID(),
|
131
|
|
|
));
|
132
|
|
|
|
133
|
|
|
system_message(elgg_echo("plugins:project:saved"));
|
134
|
|
|
|
135
|
|
|
elgg_clear_sticky_form('community_plugins');
|
136
|
|
|
forward($plugin_project->getURL());
|
137
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.