full.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. /**
  3. * Displays a plugin on the admin screen.
  4. *
  5. * This file renders a plugin for the admin screen, including active/deactive,
  6. * manifest details & display plugin settings.
  7. *
  8. * @uses $vars['entity']
  9. * @uses $vars['display_reordering'] Do we display the priority reordering links?
  10. *
  11. * @package Elgg.Core
  12. * @subpackage Plugins
  13. */
  14. /* @var ElggPlugin $plugin */
  15. $plugin = $vars['entity'];
  16. $reordering = elgg_extract('display_reordering', $vars, false);
  17. $priority = $plugin->getPriority();
  18. $active = $plugin->isActive();
  19. $can_activate = $plugin->canActivate();
  20. $max_priority = _elgg_get_max_plugin_priority();
  21. $actions_base = '/action/admin/plugins/';
  22. $css_id = preg_replace('/[^a-z0-9-]/i', '-', $plugin->getID());
  23. // build reordering links
  24. $links = '';
  25. $classes = array('elgg-plugin');
  26. if ($reordering) {
  27. $classes[] = 'elgg-state-draggable';
  28. // top and up link only if not at top
  29. if ($priority > 1) {
  30. $top_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', array(
  31. 'plugin_guid' => $plugin->guid,
  32. 'priority' => 'first',
  33. 'is_action' => true
  34. ));
  35. $links .= "<li>" . elgg_view('output/url', array(
  36. 'href' => $top_url,
  37. 'text' => elgg_echo('top'),
  38. 'is_action' => true,
  39. 'is_trusted' => true,
  40. )) . "</li>";
  41. $up_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', array(
  42. 'plugin_guid' => $plugin->guid,
  43. 'priority' => '-1',
  44. 'is_action' => true
  45. ));
  46. $links .= "<li>" . elgg_view('output/url', array(
  47. 'href' => $up_url,
  48. 'text' => elgg_echo('up'),
  49. 'is_action' => true,
  50. 'is_trusted' => true,
  51. )) . "</li>";
  52. }
  53. // down and bottom links only if not at bottom
  54. if ($priority < $max_priority) {
  55. $down_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', array(
  56. 'plugin_guid' => $plugin->guid,
  57. 'priority' => '+1',
  58. 'is_action' => true
  59. ));
  60. $links .= "<li>" . elgg_view('output/url', array(
  61. 'href' => $down_url,
  62. 'text' => elgg_echo('down'),
  63. 'is_action' => true,
  64. 'is_trusted' => true,
  65. )) . "</li>";
  66. $bottom_url = elgg_http_add_url_query_elements($actions_base . 'set_priority', array(
  67. 'plugin_guid' => $plugin->guid,
  68. 'priority' => 'last',
  69. 'is_action' => true
  70. ));
  71. $links .= "<li>" . elgg_view('output/url', array(
  72. 'href' => $bottom_url,
  73. 'text' => elgg_echo('bottom'),
  74. 'is_action' => true,
  75. 'is_trusted' => true,
  76. )) . "</li>";
  77. }
  78. } else {
  79. $classes[] = 'elgg-state-undraggable';
  80. }
  81. // activate / deactivate links
  82. // always let them deactivate
  83. $options = array(
  84. 'is_action' => true,
  85. 'is_trusted' => true,
  86. );
  87. if ($active) {
  88. $classes[] = 'elgg-state-active';
  89. $action = 'deactivate';
  90. $options['text'] = elgg_echo('admin:plugins:deactivate');
  91. $options['class'] = "elgg-button elgg-button-cancel";
  92. if (!$can_activate) {
  93. $classes[] = 'elgg-state-active';
  94. $options['class'] = 'elgg-button elgg-state-warning';
  95. }
  96. } else if ($can_activate) {
  97. $classes[] = 'elgg-state-inactive';
  98. $action = 'activate';
  99. $options['text'] = elgg_echo('admin:plugins:activate');
  100. $options['class'] = "elgg-button elgg-button-submit";
  101. } else {
  102. $classes[] = 'elgg-state-inactive';
  103. $action = '';
  104. $options['text'] = elgg_echo('admin:plugins:cannot_activate');
  105. $options['class'] = "elgg-button elgg-button-disabled";
  106. $options['disabled'] = 'disabled';
  107. }
  108. if ($action) {
  109. $url = elgg_http_add_url_query_elements($actions_base . $action, array(
  110. 'plugin_guids[]' => $plugin->guid
  111. ));
  112. $options['href'] = $url;
  113. }
  114. $action_button = elgg_view('output/url', $options);
  115. // Display categories and make category classes
  116. $categories = $plugin->getManifest()->getCategories();
  117. $categories_html = '';
  118. if ($categories) {
  119. $base_url = elgg_get_site_url() . "admin/plugins?category=";
  120. foreach ($categories as $category) {
  121. $css_class = preg_replace('/[^a-z0-9-]/i', '-', $category);
  122. $classes[] = "elgg-plugin-category-$css_class";
  123. $url = $base_url . urlencode($category);
  124. $friendly_category = htmlspecialchars(ElggPluginManifest::getFriendlyCategory($category));
  125. $categories_html .= "<li class=\"elgg-plugin-category prm\"><a href=\"$url\">$friendly_category</a></li>";
  126. }
  127. }
  128. $screenshots_html = '';
  129. $screenshots = $plugin->getManifest()->getScreenshots();
  130. if ($screenshots) {
  131. $base_url = elgg_get_plugins_path() . $plugin->getID() . '/';
  132. foreach ($screenshots as $screenshot) {
  133. $desc = elgg_echo($screenshot['description']);
  134. $alt = htmlentities($desc, ENT_QUOTES, 'UTF-8');
  135. $screenshot_img = elgg_view('output/img', array(
  136. 'src' => "admin_plugin_screenshot/{$plugin->getID()}/thumbnail/{$screenshot['path']}",
  137. 'alt' => $alt,
  138. ));
  139. $screenshot_link = elgg_view('output/url', array(
  140. 'href' => "admin_plugin_screenshot/{$plugin->getID()}/full/{$screenshot['path']}",
  141. 'text' => $screenshot_img,
  142. 'class' => 'elgg-lightbox',
  143. ));
  144. $screenshots_html .= "<li class=\"elgg-plugin-screenshot prm ptm\">$screenshot_link</li>";
  145. }
  146. }
  147. // metadata
  148. $description = elgg_view('output/longtext', array('value' => $plugin->getManifest()->getDescription()));
  149. $author = '<span>' . elgg_echo('admin:plugins:label:author') . '</span>: '
  150. . elgg_view('output/text', array('value' => $plugin->getManifest()->getAuthor()));
  151. $version = htmlspecialchars($plugin->getManifest()->getVersion());
  152. $website = elgg_view('output/url', array(
  153. 'href' => $plugin->getManifest()->getWebsite(),
  154. 'text' => $plugin->getManifest()->getWebsite(),
  155. 'is_trusted' => true,
  156. ));
  157. $resources = array(
  158. 'repository' => $plugin->getManifest()->getRepositoryURL(),
  159. 'bugtracker' => $plugin->getManifest()->getBugTrackerURL(),
  160. 'donate' => $plugin->getManifest()->getDonationsPageURL(),
  161. );
  162. $resources_html = "<ul class=\"elgg-plugin-resources\">";
  163. foreach ($resources as $id => $href) {
  164. if ($href) {
  165. $resources_html .= "<li class=\"prm\">";
  166. $resources_html .= elgg_view('output/url', array(
  167. 'href' => $href,
  168. 'text' => elgg_echo("admin:plugins:label:$id"),
  169. 'is_trusted' => true,
  170. ));
  171. $resources_html .= "</li>";
  172. }
  173. }
  174. $resources_html .= "</ul>";
  175. $copyright = elgg_view('output/text', array('value' => $plugin->getManifest()->getCopyright()));
  176. $license = elgg_view('output/text', array('value' => $plugin->getManifest()->getLicense()));
  177. // show links to text files
  178. $files = $plugin->getAvailableTextFiles();
  179. $docs = '';
  180. if ($files) {
  181. $docs = '<ul class="elgg-menu elgg-menu-hz">';
  182. foreach ($files as $file => $path) {
  183. $url = 'admin_plugin_text_file/' . $plugin->getID() . "/$file";
  184. $link = elgg_view('output/url', array(
  185. 'text' => $file,
  186. 'href' => $url,
  187. 'is_trusted' => true,
  188. ));
  189. $docs .= "<li>$link</li>";
  190. }
  191. $docs .= '</ul>';
  192. }
  193. ?>
  194. <div class="<?php echo implode(' ', $classes); ?>" id="<?php echo $css_id; ?>">
  195. <div class="elgg-image-block">
  196. <div class="elgg-image-alt">
  197. <?php if ($links) : ?>
  198. <ul class="elgg-menu elgg-menu-metadata">
  199. <?php echo $links; ?>
  200. </ul>
  201. <?php endif; ?>
  202. <div class="clearfloat float-alt mtm">
  203. <?php echo $action_button; ?>
  204. </div>
  205. </div>
  206. <div class="elgg-body">
  207. <?php
  208. $settings_view_old = 'settings/' . $plugin->getID() . '/edit';
  209. $settings_view_new = 'plugins/' . $plugin->getID() . '/settings';
  210. if (elgg_view_exists($settings_view_old) || elgg_view_exists($settings_view_new)) {
  211. $link = elgg_get_site_url() . "admin/plugin_settings/" . $plugin->getID();
  212. $settings_link = "<a class='elgg-plugin-settings' href='$link'>[" . elgg_echo('settings') . "]</a>";
  213. } else {
  214. $settings_link = '';
  215. }
  216. ?>
  217. <div class="elgg-head">
  218. <h3><?php echo $plugin->getManifest()->getName() . " $version $settings_link"; ?></h3>
  219. </div>
  220. <?php
  221. if ($plugin->getManifest()->getApiVersion() < 1.8) {
  222. $reqs = $plugin->getManifest()->getRequires();
  223. if (!$reqs) {
  224. $message = elgg_echo('admin:plugins:warning:elgg_version_unknown');
  225. echo "<p class=\"elgg-state-error\">$message</p>";
  226. }
  227. }
  228. if (!$can_activate) {
  229. if ($active) {
  230. $message = elgg_echo('admin:plugins:warning:unmet_dependencies_active');
  231. echo "<p class=\"elgg-state-warning\">$message</p>";
  232. } else {
  233. $message = elgg_echo('admin:plugins:warning:unmet_dependencies');
  234. echo "<p class=\"elgg-state-error\">$message</p>";
  235. }
  236. }
  237. ?>
  238. <div><?php echo $description; ?></div>
  239. <p><?php echo $author . ' - ' . $website; ?></p>
  240. <?php
  241. echo $resources_html;
  242. echo $docs;
  243. ?>
  244. <div class="pts">
  245. <?php
  246. echo elgg_view('output/url', array(
  247. 'href' => "#elgg-plugin-manifest-$css_id",
  248. 'text' => elgg_echo("admin:plugins:label:moreinfo"),
  249. 'rel' => 'toggle',
  250. ));
  251. ?>
  252. </div>
  253. </div>
  254. </div>
  255. <div class="elgg-plugin-more hidden" id="elgg-plugin-manifest-<?php echo $css_id; ?>">
  256. <?php
  257. if ($screenshots_html) {
  258. ?>
  259. <div><ul><?php echo $screenshots_html; ?></ul></div>
  260. <?php
  261. }
  262. if ($categories_html) {
  263. ?>
  264. <div><?php echo elgg_echo('admin:plugins:label:categories') . ": <ul class=\"elgg-plugin-categories\">$categories_html</ul>"; ?></div>
  265. <?php
  266. }
  267. ?>
  268. <div><?php echo elgg_echo('admin:plugins:label:copyright') . ": " . $copyright; ?></div>
  269. <div><?php echo elgg_echo('admin:plugins:label:licence') . ": " . $license; ?></div>
  270. <div><?php echo elgg_echo('admin:plugins:label:location') . ": " . htmlspecialchars($plugin->getPath()) ?></div>
  271. <?php
  272. $contributors = elgg_view('object/plugin/elements/contributors', array('plugin' => $plugin));
  273. if (!empty($contributors)) {
  274. echo '<div>' . elgg_echo('admin:plugins:label:contributors') . ':';
  275. echo $contributors;
  276. echo '</div>';
  277. }
  278. ?>
  279. <div><?php echo elgg_echo('admin:plugins:label:dependencies'); ?>:
  280. <?php
  281. echo elgg_view('object/plugin/elements/dependencies', array('plugin' => $plugin));
  282. ?>
  283. </div>
  284. </div>
  285. </div>