PageRenderTime 36ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/rsx_plugins_table.php

https://github.com/funkaoshi/rsx_plugins_table
PHP | 132 lines | 86 code | 33 blank | 13 comment | 12 complexity | befaba7f94cc3ac6435a056ad409032c MD5 | raw file
  1. <?php
  2. // Either copy classTextile.php to your plugin directory, or uncomment the following
  3. // line and edit it to give the location where classTextile.php can be found
  4. #ini_set('include_path', ini_get('include_path') . ':/full/path/to/textile');
  5. // Plugin name is optional. If unset, it will be extracted from the current file name.
  6. // Uncomment and edit this line to override:
  7. # $plugin['name'] = 'abc_plugin';
  8. $plugin['version'] = '1.2';
  9. $plugin['author'] = 'Ramanan Sivaranjan';
  10. $plugin['author_uri'] = 'http://funkaoshi.com/';
  11. $plugin['description'] = 'Display a list of plugins currently installed.';
  12. compile_plugin();
  13. exit;
  14. ?>
  15. # --- BEGIN PLUGIN HELP ---
  16. <h1>RSX Plugins Table</h1>
  17. <p>This plugin will display a table containing the basic information about
  18. the plugins you currently have installed in your textpattern system. The table
  19. can be styled using CSS, as the table has been given the class
  20. <code>plugins-table</code>. There are currently no special options or
  21. switches. To use, simply include the tag <code>&lt;txp:rsx_plugins_table
  22. /&gt;</code> anywhere you want this table to be displayed.</p>
  23. <p>You can use the parameter <code>show_inactive</code> to decide if you want
  24. to list active or inactive plugins. If it is set to 1, which is the default,
  25. inactive plugins will be listed as well as active plugins. If it is set to 0,
  26. then only active plugins are displayed.</p>
  27. <p>You can use the parameter <code>show_description</code> to decide if you want
  28. to include the description of the plugin in your table or not. If it is set to 1,
  29. which is the default, the description of the plugin will be listed. If it is set
  30. to 0, then no description will be listed.</p>
  31. # --- END PLUGIN HELP ---
  32. <?php
  33. # --- BEGIN PLUGIN CODE ---
  34. function rsx_plugins_table($atts)
  35. {
  36. extract(lAtts(array('show_inactive' => 1, 'show_description' => 1),$atts));
  37. $out = '';
  38. $even = false;
  39. $rs = safe_rows("name, author, author_uri, version, description, status"
  40. , "txp_plugin"
  41. , "1=1");
  42. if ($rs) {
  43. $out .= '<table>';
  44. $out .= '<tr><th>Name</th><th>Author</th><th>Version</th>';
  45. if ( $show_description )
  46. $out .='<th>Description</th>';
  47. $out .= $show_inactive ? '<th>Active?</th></tr>' : '</tr>';
  48. foreach($rs as $var) {
  49. extract($var);
  50. if ( $status || !$status && $show_inactive) {
  51. $out .= '<tr class="'.($even ? 'even' : 'odd').'">';
  52. $out .= '<td>'.$name.'</td>';
  53. $out .= '<td><a href="'.$author_uri.'">'.$author.'</a></td>';
  54. $out .= '<td>'.$version.'</td>';
  55. if ( $show_description )
  56. $out .= '<td>'.$description.'</td>';
  57. if ( $show_inactive )
  58. $out .= '<td>'.($status ? 'Yes' : 'No').'</td>';
  59. $out .= '</tr>';
  60. $even = ($even ? false : true);
  61. }
  62. }
  63. $out .= '</table>';
  64. }
  65. return $out;
  66. }
  67. # --- END PLUGIN CODE ---
  68. // -----------------------------------------------------
  69. function extract_section($lines, $section) {
  70. $result = "";
  71. $start_delim = "# --- BEGIN PLUGIN $section ---";
  72. $end_delim = "# --- END PLUGIN $section ---";
  73. $start = array_search($start_delim, $lines) + 1;
  74. $end = array_search($end_delim, $lines);
  75. $content = array_slice($lines, $start, $end-$start);
  76. return join("\n", $content);
  77. }
  78. function compile_plugin() {
  79. global $plugin;
  80. if (!isset($plugin['name'])) {
  81. $plugin['name'] = basename(__FILE__, '.php');
  82. }
  83. # Read the contents of this file, and strip line ends
  84. $content = file(__FILE__);
  85. for ($i=0; $i < count($content); $i++) {
  86. $content[$i] = rtrim($content[$i]);
  87. }
  88. $plugin['help'] = extract_section($content, 'HELP');
  89. $plugin['code'] = extract_section($content, 'CODE');
  90. @include('classTextile.php');
  91. if (class_exists('Textile')) {
  92. $textile = new Textile();
  93. $plugin['help'] = $textile->TextileThis($plugin['help']);
  94. }
  95. $plugin['md5'] = md5( $plugin['code'] );
  96. // to produce a copy of the plugin for distribution, load this file in a browser.
  97. echo chr(60)."?php\n\n".'$'."plugin='" . base64_encode(serialize($plugin)) . "'\n?".chr(62);
  98. }
  99. ?>