PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/exec-php/includes/config_ui.php

https://gitlab.com/Gashler/sg
PHP | 217 lines | 165 code | 31 blank | 21 comment | 20 complexity | 6828f559e27867370b1dba3e5ca2e451 MD5 | raw file
  1. <?php
  2. require_once(dirname(__FILE__).'/cache.php');
  3. require_once(dirname(__FILE__).'/const.php');
  4. require_once(dirname(__FILE__).'/l10n.php');
  5. require_once(dirname(__FILE__).'/script.php');
  6. // -----------------------------------------------------------------------------
  7. // the ExecPhp_ConfigUi class displays the config interface in the
  8. // admin menu
  9. // -----------------------------------------------------------------------------
  10. // use this guard to avoid error messages in WP admin panel if plugin
  11. // is disabled because of a version conflict but you still try to reload
  12. // the plugins config interface
  13. if (!class_exists('ExecPhp_ConfigUi')) :
  14. define('ExecPhp_ACTION_UPDATE_OPTIONS', 'execphp_update_options');
  15. class ExecPhp_ConfigUi
  16. {
  17. var $m_cache = NULL;
  18. var $m_script = NULL;
  19. // ---------------------------------------------------------------------------
  20. // init
  21. // ---------------------------------------------------------------------------
  22. // Sets up the Exec-Php config menu
  23. function ExecPhp_ConfigUi(&$cache, &$script)
  24. {
  25. $this->m_cache =& $cache;
  26. $this->m_script =& $script;
  27. $option =& $this->m_cache->get_option();
  28. $this->toggle_action($option->get_status());
  29. add_action('admin_menu', array(&$this, 'action_admin_menu'));
  30. }
  31. // ---------------------------------------------------------------------------
  32. // hooks
  33. // ---------------------------------------------------------------------------
  34. function action_admin_menu()
  35. {
  36. if (current_user_can(ExecPhp_CAPABILITY_EDIT_PLUGINS))
  37. {
  38. add_submenu_page('options-general.php',
  39. __s('Exec-PHP Settings', ExecPhp_PLUGIN_ID),
  40. __s('Exec-PHP', ExecPhp_PLUGIN_ID),
  41. ExecPhp_CAPABILITY_EDIT_PLUGINS, __FILE__,
  42. array(&$this, 'submenu_page_option_general'));
  43. add_filter('plugin_action_links', array(&$this, 'filter_plugin_actions_links'), 10, 2);
  44. }
  45. }
  46. function filter_plugin_actions_links($links, $file)
  47. {
  48. if ($file == ExecPhp_HOMEDIR. '/exec-php.php')
  49. {
  50. $settings_link = $settings_link = '<a href="options-general.php?page='. ExecPhp_HOMEDIR. '/includes/config_ui.php">' . __('Settings') . '</a>';
  51. array_unshift($links, $settings_link);
  52. }
  53. return $links;
  54. }
  55. function action_admin_footer_plugin_version()
  56. {
  57. $option =& $this->m_cache->get_option();
  58. $heading = __s('Exec-PHP Error.', ExecPhp_PLUGIN_ID);
  59. $text = __s('No necessary upgrade of the the Exec-PHP plugin could be performed. PHP code in your articles or widgets may be viewable to your blog readers. This is plugin version %1$s, previously there was version %2$s installed. Downgrading from a newer version to an older version of the plugin is not supported.', ExecPhp_PLUGIN_ID
  60. , ExecPhp_VERSION, $option->get_version());
  61. $this->m_script->print_message($heading, $text);
  62. }
  63. function action_admin_footer_unknown()
  64. {
  65. $option =& $this->m_cache->get_option();
  66. $heading = __s('Exec-PHP Error.', ExecPhp_PLUGIN_ID);
  67. $text = __s('An unknown error (%s) occured during execution of the Exec-PHP plugin. PHP code in your articles or widgets may be viewable to your blog readers. This error should never happen if you use the plugin with a compatible WordPress version and installed it as described in the documentation.', ExecPhp_PLUGIN_ID
  68. , $option->get_status());
  69. $this->m_script->print_message($heading, $text);
  70. }
  71. function toggle_action($status)
  72. {
  73. if ($status == ExecPhp_STATUS_PLUGIN_VERSION_MISMATCH)
  74. add_action('admin_footer', array(&$this, 'action_admin_footer_plugin_version'));
  75. else
  76. remove_action('admin_footer', array(&$this, 'action_admin_footer_plugin_version'));
  77. if ($status != ExecPhp_STATUS_OKAY
  78. && $status != ExecPhp_STATUS_PLUGIN_VERSION_MISMATCH)
  79. add_action('admin_footer', array(&$this, 'action_admin_footer_unknown'));
  80. else
  81. remove_action('admin_footer', array(&$this, 'action_admin_footer_unknown'));
  82. }
  83. // ---------------------------------------------------------------------------
  84. // interface
  85. // ---------------------------------------------------------------------------
  86. function print_request_users($display_id, $feature, $title, $introduction)
  87. {
  88. global $wp_version;
  89. if (version_compare($wp_version, '2.6.dev') >= 0)
  90. // since WP 2.6 it comes with its own progress animation
  91. $image_url = get_option('siteurl'). '/wp-admin/images/loading.gif';
  92. else
  93. $image_url = ExecPhp_HOME_URL. '/images/progress.gif';
  94. ?>
  95. <fieldset class="options">
  96. <table class="editform optiontable form-table">
  97. <tr valign="top" id="<?php echo $display_id; ?>-container" >
  98. <th scope="row"><?php echo $title; ?></th>
  99. <td>
  100. <label for="<?php echo ExecPhp_POST_WIDGET_SUPPORT; ?>">
  101. <?php echo $introduction; ?>
  102. <div class="execphp-user-list" id="<?php echo $display_id; ?>">
  103. <?php _es('The list can not be displayed because you may have disabled Javascript or your browser does not support Javascript.', ExecPhp_PLUGIN_ID); ?>
  104. </div>
  105. <script type="text/javascript">
  106. //<![CDATA[
  107. document.getElementById("<?php echo $display_id; ?>").innerHTML =
  108. "<p><img src=\"<?php echo $image_url; ?>\" alt=\"<?php escape_dquote(_es('An animated icon signaling that this information is still be loaded.', ExecPhp_PLUGIN_ID)); ?>\" /> <?php escape_dquote(_es('Loading user information...', ExecPhp_PLUGIN_ID)); ?></p>";
  109. ExecPhp_subscribeForFeature("<?php echo $feature; ?>");
  110. //]]>
  111. </script>
  112. </label>
  113. </td>
  114. </tr>
  115. </table>
  116. </fieldset>
  117. <?php
  118. }
  119. function submenu_page_option_general()
  120. {
  121. global $wpdb;
  122. global $wp_version;
  123. // executing form actions
  124. $option =& $this->m_cache->get_option();
  125. if (isset($_POST[ExecPhp_ACTION_UPDATE_OPTIONS]))
  126. {
  127. check_admin_referer(ExecPhp_ACTION_UPDATE_OPTIONS);
  128. $option->set_from_POST();
  129. $option->save();
  130. echo '<div id="message" class="updated fade"><p><strong>'.
  131. __s('Settings saved.', ExecPhp_PLUGIN_ID) . "</strong></p></div>\n";
  132. }
  133. $this->toggle_action($option->get_status());
  134. ?>
  135. <div class="wrap">
  136. <?php if (version_compare($wp_version, '2.7.dev') >= 0) : ?>
  137. <div id="icon-options-general" class="icon32"><br /></div>
  138. <?php endif; ?>
  139. <h2><?php _es('Exec-PHP Plugin', ExecPhp_PLUGIN_ID); ?></h2>
  140. <p><?php echo __s('Exec-PHP executes <code>&lt;?php ?&gt;</code> code in your posts, pages and text widgets. See the <a href="%s">local documentation</a> for further information. The latest version of the plugin, documentation and information can be found on the <a href="http://bluesome.net/post/2005/08/18/50/">official plugin homepage</a>.', ExecPhp_PLUGIN_ID, ExecPhp_HOME_URL. '/docs/'. __s('readme.html', ExecPhp_PLUGIN_ID)); ?></p>
  141. <?php if (version_compare($wp_version, '2.2.dev') >= 0) : ?>
  142. <h3><?php _es('Settings', ExecPhp_PLUGIN_ID); ?></h3>
  143. <form action="" method="post" id="<?php echo ExecPhp_ID_CONFIG_FORM; ?>"<?php if (version_compare($wp_version, '2.5.dev') >= 0 && version_compare($wp_version, '2.6.dev') < 0) : ?> class="wp-2-5"<?php endif; ?>>
  144. <?php wp_nonce_field(ExecPhp_ACTION_UPDATE_OPTIONS); ?>
  145. <fieldset class="options">
  146. <table class="editform optiontable form-table">
  147. <tr valign="top">
  148. <th scope="row"><?php _es('Execute PHP code in text widgets', ExecPhp_PLUGIN_ID); ?></th>
  149. <td>
  150. <label for="<?php echo ExecPhp_POST_WIDGET_SUPPORT; ?>">
  151. <input type="checkbox" name="<?php echo ExecPhp_POST_WIDGET_SUPPORT; ?>" id="<?php echo ExecPhp_POST_WIDGET_SUPPORT; ?>" value="true" <?php if ($option->get_widget_support()) : ?>checked="checked" <?php endif; ?>/>
  152. <?php _es('Executing PHP code in text widgets is not restricted to any user. By default users who can modify text widgets will also be able to execute PHP code in text widgets. Unselect this option to generally turn off execution of PHP code in text widgets.', ExecPhp_PLUGIN_ID); ?>
  153. </label>
  154. </td>
  155. </tr>
  156. </table>
  157. </fieldset>
  158. <p class="submit">
  159. <input type="submit" name="<?php echo ExecPhp_ACTION_UPDATE_OPTIONS; ?>" class="button-primary" value="<?php _es('Save Changes', ExecPhp_PLUGIN_ID) ?>" />
  160. </p>
  161. </form>
  162. <?php endif; ?>
  163. <h3><?php _es('Security Information', ExecPhp_PLUGIN_ID); ?></h3>
  164. <p><?php _es('The following lists show which users are allowed to write or execute PHP code in different cases. Allowing to write or execute PHP code can be adjusted by assigning the necessary capabilities to individual users or roles by using a role manager plugin.', ExecPhp_PLUGIN_ID); ?></p>
  165. <form action="" id="<?php echo ExecPhp_ID_INFO_FORM; ?>"<?php if (version_compare($wp_version, '2.5.dev') >= 0 && version_compare($wp_version, '2.6.dev') < 0) : ?> class="wp-2-5"<?php endif; ?>>
  166. <?php $this->print_request_users(ExecPhp_ID_INFO_SECURITY_HOLE,
  167. ExecPhp_REQUEST_FEATURE_SECURITY_HOLE,
  168. __s('Security Hole', ExecPhp_PLUGIN_ID),
  169. __s('The following list shows which users have either or both of the &quot;%1$s&quot; or &quot;%2$s&quot; capability and are allowed to change others PHP code by having the &quot;%3$s&quot; capability but do not have the &quot;%4$s&quot; capability for themself. This is a security hole, because the listed users can write and execute PHP code in articles of other users although they are not supposed to execute PHP code at all.', ExecPhp_PLUGIN_ID, ExecPhp_CAPABILITY_EDIT_OTHERS_POSTS, ExecPhp_CAPABILITY_EDIT_OTHERS_PAGES, ExecPhp_CAPABILITY_EDIT_OTHERS_PHP, ExecPhp_CAPABILITY_EXECUTE_ARTICLES)); ?>
  170. <?php if (version_compare($wp_version, '2.2.dev') >= 0) : ?>
  171. <?php $this->print_request_users(ExecPhp_ID_INFO_WIDGETS,
  172. ExecPhp_REQUEST_FEATURE_WIDGETS,
  173. __s('Executing PHP Code in Text Widgets', ExecPhp_PLUGIN_ID),
  174. __s('The following list shows which users have the &quot;%s&quot; capability and therefore are allowed to write and execute PHP code in text widgets. In case you have deselected the option &quot;Execute PHP code in text widgets&quot; from above, this list will appear empty.', ExecPhp_PLUGIN_ID, ExecPhp_CAPABILITY_EXECUTE_WIDGETS)); ?>
  175. <?php endif; ?>
  176. <?php $this->print_request_users(ExecPhp_ID_INFO_EXECUTE_ARTICLES,
  177. ExecPhp_REQUEST_FEATURE_EXECUTE_ARTICLES,
  178. __s('Executing PHP Code in Articles', ExecPhp_PLUGIN_ID),
  179. __s('The following list shows which users have the &quot;%s&quot; capability and therefore are allowed to execute PHP code in articles.', ExecPhp_PLUGIN_ID, ExecPhp_CAPABILITY_EXECUTE_ARTICLES)); ?>
  180. </form>
  181. </div>
  182. <?php
  183. }
  184. }
  185. endif;
  186. ?>