aboutsummaryrefslogtreecommitdiff
path: root/views/default/admin/components/plugin.php
blob: ff1abee1e956a7b45a6ce555e9e556ed0d6fa071 (plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/**
 * Displays a plugin on the admin screen.
 *
 * This file renders a plugin for the admin screen, including active/deactive,
 * manifest details & display plugin settings.
 *
 * @package Elgg.Core
 * @subpackage Plugins
 */

$plugin = $vars['plugin'];
$priority = $plugin->getPriority();
$active = $plugin->isActive();

$name = $plugin->manifest->getName();
$can_activate = $plugin->canActivate();
$max_priority = elgg_get_max_plugin_priority();
$actions_base = '/action/admin/plugins/';

$ts = time();
$token = generate_action_token($ts);
$active_class = ($active && $can_activate) ? 'active' : 'not_active';

// build reordering links
$links = '';

// top and up link only if not at top
if ($priority > 1) {
	$top_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', array(
		'plugin_guid' => $plugin->guid,
		'priority' => 'first',
		'is_action' => true
	));

	$links .= elgg_view('output/url', array(
		'href' 		=> $top_url,
		'text'		=> elgg_echo('top'),
		'is_action'	=> true
	));

	$up_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', array(
		'plugin_guid' => $plugin->guid,
		'priority' => '-1',
		'is_action' => true
	));

	$links .= elgg_view('output/url', array(
		'href' 		=> $up_url,
		'text'		=> elgg_echo('up'),
		'is_action'	=> true
	));
}

// down and bottom links only if not at bottom
if ($priority < $max_priority) {
	$down_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', array(
		'plugin_guid' => $plugin->guid,
		'priority' => '+1',
		'is_action' => true
	));

	$links .= elgg_view('output/url', array(
		'href' 		=> $down_url,
		'text'		=> elgg_echo('down'),
		'is_action'	=> true
	));

	$bottom_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', array(
		'plugin_guid' => $plugin->guid,
		'priority' => 'last',
		'is_action' => true
	));

	$links .= elgg_view('output/url', array(
		'href' 		=> $bottom_url,
		'text'		=> elgg_echo('bottom'),
		'is_action'	=> true
	));
}

// activate / deactivate links
if ($can_activate) {
	if ($active) {
		$action = 'deactivate';
		$class = 'elgg-cancel-button';
	} else {
		$action = 'activate';
		$class = 'elgg-submit-button';
	}

	$url = elgg_http_add_url_query_elements($actions_base . $action, array(
		'plugin_guids[]' => $plugin->guid,
		'is_action' => true
	));

	$action_button = elgg_view('output/url', array(
		'href' 		=> $url,
		'text'		=> elgg_echo($action),
		'is_action'	=> true,
		'class'		=> "elgg-button $class"
	));
} else {
	$action_button = elgg_view('output/url', array(
		'text'		=> elgg_echo('admin:plugins:cannot_activate'),
		'disabled'	=> 'disabled',
		'class'		=> "elgg-action-button disabled"
	));
}

// Display categories
$categories_html = '';
if ($categories) {
	$categories_arr = array();
	$base_url = elgg_get_site_url() . "pg/admin/plugins?category=";

	foreach ($categories as $category) {
		$url = $base_url . urlencode($category);
		$categories_arr[] = "<a href=\"$url\">" . htmlspecialchars($category) . '</a>';
	}

	$categories_html = implode(', ', $categories_arr);
}

// @todo We need to make a page handler to read these files in.
// this is broken.
$screenshot_html = '';
$screenshots = $plugin->manifest->getScreenshots();
if ($screenshots) {
	$base_url = elgg_get_plugins_path() . $plugin->getID() . '/';
	$limit = 4;
	foreach ($screenshots as $screenshot) {
		if ($limit <= 0) {
			break;
		}

		$screenshot_src = $plugin->getPath() . $screenshot['path'];
		$screenshots .= "<li class=\"plugin-screenshot\"><a href=\"$screenshot_src\"><img src=\"$screenshot_src\"></a></li>";

		$limit--;
	}
}

// metadata
$description = elgg_view('output/longtext', array('value' => $plugin->manifest->getDescription()));
$author = '<span>' . elgg_echo('admin:plugins:label:author') . '</span>: '
			. elgg_view('output/text', array('value' => $plugin->manifest->getAuthor()));
$version = htmlspecialchars($plugin->manifest->getVersion());
$website = elgg_view('output/url', array(
	'href' => $plugin->manifest->getWebsite(),
	'text' => $plugin->manifest->getWebsite()
));

$copyright = elgg_view('output/text', array('value' => $plugin->manifest->getCopyright()));
$license = elgg_view('output/text', array('value' => $plugin->manifest->getLicense()));

?>

<div class="plugin_details <?php echo $active_class ?>">
	<div class="admin_plugin_reorder">
	<?php echo "$links"; ?>
	</div><div class="clearfloat"></div>

	<div class="admin_plugin_enable_disable"><?php echo $action_button; ?></div>

<?php
$settings_view = 'settings/' . $plugin->getID() . '/edit';
if (elgg_view_exists($settings_view)) {
	$link = elgg_get_site_url() . "pg/admin/plugin_settings/" . $plugin->getID();
	$settings_link = "<a class='plugin_settings small link' href='$link'>[" . elgg_echo('settings') . "]</a>";
}
?>
	<h3><?php echo $plugin->manifest->getName() . " $version $settings_link"; ?></h3>
		<div class="plugin_description"><?php echo $description; ?></div>
		<p class="plugin_author"><?php echo $author . ' - ' . $website; ?></p>

		<?php
		if ($plugin->manifest->getApiVersion() < 1.8) {
			$reqs = $plugin->manifest->getRequires();
			if (!$reqs) {
				$message = elgg_echo('admin:plugins:warning:elgg_version_unknown');
				echo "<p class=\"plugin-cannot-activate\">$message</p>";
			}
		}

		if (!$can_activate) {
			$message = elgg_echo('admin:plugins:warning:unmet_dependencies');
			echo "<p class=\"plugin-cannot-activate\">$message</p>";
		}
		?>

		<p><a class="manifest_details small link"><?php echo elgg_echo("admin:plugins:label:moreinfo"); ?></a></p>

		<div class="manifest_file hidden">

		<div><?php echo elgg_echo('admin:plugins:label:location') . ": " . htmlspecialchars($plugin->getPath()) ?></div>
		<?php
		if ($categories_html) {
			?>
			<div><?php echo elgg_echo('admin:plugins:label:categories') . ": " . $categories_html; ?></div>
			<?php
		}

		if ($screenshots) {
			?>
			<div><ul><?php echo $screenshots; ?></ul></div>
			<?php
		}
		?>
		<div><?php echo elgg_echo('admin:plugins:label:copyright') . ": " . $copyright; ?></div>
		<div><?php echo elgg_echo('admin:plugins:label:licence') . ": " . $license; ?></div>

		<div><?php echo elgg_echo('admin:plugins:label:dependencies'); ?>:
		<?php
			echo elgg_view('admin/components/plugin_dependencies', array('plugin' => $plugin));
		?>
		</div>
	</div>
</div>