plug_admin_bar.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <?php
  2. if (!class_exists("plug_admin_bar")) {
  3. class plug_admin_bar {
  4. function __construct($ns) {
  5. $this->title = __("Admin bar", "dagsopt");
  6. $this->pluginname = $ns->pluginname;
  7. $this->file = $ns->file;
  8. $this->ns = $ns;
  9. }
  10. function start() {
  11. add_action('admin_bar_menu', array(&$this, 'bu_admin_link_first'), 1);
  12. add_action('admin_bar_menu', array(&$this, 'bu_admin_link_last'), 200);
  13. if (get_option($this->pluginname . "_admin_bar" . '_remove_comments', false)) {
  14. add_action('wp_before_admin_bar_render', array(&$this, 'bu_admin_link_remove_comments'), 210);
  15. }
  16. if (!function_exists('wp_get_current_user')) {
  17. include ABSPATH . "wp-includes/pluggable.php";
  18. }
  19. // remove_submenu_page('index.php','update-core.php');
  20. $current_user = wp_get_current_user();
  21. if (current_user_can('manage_options') && $current_user->user_login == "admin") {
  22. add_action('admin_menu', array(&$this, 'setup_menus'), 220);
  23. } else {
  24. add_action('admin_menu', array(&$this, 'remove_menus'), 220);
  25. add_action('wp_before_admin_bar_render', array(&$this, 'remove_menus2'), 210);
  26. }
  27. }
  28. function remove_menus2() {
  29. global $wp_admin_bar;
  30. if (get_option($this->pluginname . "_admin_bar" . '_remove_new-post', false)) {
  31. $wp_admin_bar->remove_menu("new-post");
  32. }
  33. if (get_option($this->pluginname . "_admin_bar" . '_remove_new-link', false)) {
  34. $wp_admin_bar->remove_menu("new-link");
  35. }
  36. if (get_option($this->pluginname . "_admin_bar" . '_remove_new-page', false)) {
  37. $wp_admin_bar->remove_menu("new-page");
  38. }
  39. if (get_option($this->pluginname . "_admin_bar" . '_remove_new-media', false)) {
  40. $wp_admin_bar->remove_menu("new-media");
  41. }
  42. if (get_option($this->pluginname . "_admin_bar" . '_remove_new-user', false)) {
  43. $wp_admin_bar->remove_menu("new-user");
  44. }
  45. }
  46. function setup_menus() {
  47. global $menu;
  48. $this->gmenu = $menu;
  49. }
  50. function remove_menus() {
  51. global $menu;
  52. /* $this->setup_menus();
  53. $rr = array();
  54. foreach($this->gmenu as $id => $mm){
  55. if(get_option($this->pluginname."_admin_bar".'_remove_'.$mm[5],false)){
  56. array_push($rr,$mm[5]);
  57. }
  58. }
  59. foreach($menu as $id => $menupoint){
  60. if(isset($menupoint[5]) && in_array($menupoint[5],$rr)){
  61. unset($menu[$id]);
  62. }
  63. }
  64. remove_submenu_page('index.php','update-core.php');
  65. remove_submenu_page('themes.php','update');
  66. remove_submenu_page('themes.php','checkupdate');
  67. remove_submenu_page('themes.php','custom-header');
  68. remove_submenu_page('themes.php','custom-background');
  69. remove_submenu_page('themes.php','theme-editor.php');
  70. remove_submenu_page('themes.php','themes.php');
  71. //add_submenu_page( 'themes.php', "Customize", "Customize", "", "customize.php", "");
  72. */
  73. }
  74. function bu_admin_link_first() {
  75. global $wp_admin_bar;
  76. if (get_option($this->pluginname . "_admin_bar" . '_dags_logo', true)) {
  77. $imageurl = get_option($this->pluginname . "_admin_bar_image", true);
  78. if (!$imageurl) {
  79. $imageurl = "/wp-content/plugins/dagsplug/logo.png";
  80. }
  81. if (is_admin()) {
  82. $wp_admin_bar->add_menu(array('id' => 'dags-logo', 'title' => '<img src="' . $imageurl . '" style="margin-top: 4px; height: 24px; background-color: #ffff00;">', 'href' => '/', 'meta' => array('title' => __('Home', 'dagsopt'))));
  83. } else {
  84. $wp_admin_bar->add_menu(array('id' => 'dags-logo', 'title' => '<img src="' . $imageurl . '" style="margin-top: 4px; height: 24px; background-color: #ffffff;">', 'href' => '/wp-admin/', 'meta' => array('title' => __('Home', 'dagsopt'))));
  85. }
  86. }
  87. }
  88. function bu_admin_link_remove_comments() {
  89. global $wp_admin_bar;
  90. $wp_admin_bar->remove_menu('comments');
  91. }
  92. function bu_admin_link_last() {
  93. global $wp_admin_bar;
  94. $wp_admin_bar->remove_node("wp-logo");
  95. if (get_option($this->pluginname . "_admin_bar" . '_dags_logo', true)) {
  96. }
  97. if (get_option($this->pluginname . "_admin_bar" . '_show_ip', true)) {
  98. $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'IP', 'title' => 'IP: ' . $_SERVER['SERVER_ADDR'], 'href' => admin_url('admin.php?page=' . $this->pluginname . '-options')));
  99. }
  100. if (current_user_can('manage_options') && get_option($this->pluginname . "_admin_bar_live_url")) {
  101. if (get_option($this->pluginname . "_admin_bar" . '_show_switcher', true)) {
  102. if ($_SERVER['HTTP_HOST'] == get_option($this->pluginname . "_admin_bar_live_url")) {
  103. $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option($this->pluginname . "_admin_bar_live_title"), 'href' => get_option($this->pluginname . "_admin_bar_live_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => 'active')));
  104. $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option($this->pluginname . "_admin_bar_stage_title"), 'href' => get_option($this->pluginname . "_admin_bar_stage_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
  105. $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option($this->pluginname . "_admin_bar_local_title"), 'href' => get_option($this->pluginname . "_admin_bar_local_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
  106. } else if ($_SERVER['HTTP_HOST'] == get_option($this->pluginname . "_admin_bar_stage_url")) {
  107. $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option($this->pluginname . "_admin_bar_live_title"), 'href' => get_option($this->pluginname . "_admin_bar_live_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
  108. $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option($this->pluginname . "_admin_bar_stage_title"), 'href' => get_option($this->pluginname . "_admin_bar_stage_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => 'active')));
  109. $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option($this->pluginname . "_admin_bar_local_title"), 'href' => get_option($this->pluginname . "_admin_bar_local_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
  110. } else {
  111. $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_live', 'title' => get_option($this->pluginname . "_admin_bar_live_title"), 'href' => get_option($this->pluginname . "_admin_bar_live_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
  112. $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_stage', 'title' => get_option($this->pluginname . "_admin_bar_stage_title"), 'href' => get_option($this->pluginname . "_admin_bar_stage_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => '')));
  113. $wp_admin_bar->add_menu(array('parent' => 'top-secondary', 'id' => 'DEV_local', 'title' => get_option($this->pluginname . "_admin_bar_local_title"), 'href' => get_option($this->pluginname . "_admin_bar_local_url") . $_SERVER['REQUEST_URI'], 'meta' => array('class' => 'active')));
  114. }
  115. }
  116. } else {
  117. }
  118. }
  119. function help() {
  120. ?>
  121. <?php echo (__("Server switcher : local > stage > live", "dagsopt")) ?><br>
  122. <?php echo (__("Swap WP for dags logo", "dagsopt")) ?><br>
  123. <?php echo (__("Show server ip", "dagsopt")) ?><br>
  124. <?php
  125. }
  126. function Option($pre) {
  127. update_option($pre . '_show_switcher', $_POST[$pre . '_show_switcher']);
  128. if (!empty($_POST[$pre . '_live_url'])) {
  129. update_option($pre . '_live_url', $_POST[$pre . '_live_url']);
  130. }
  131. if (!empty($_POST[$pre . '_live_title'])) {
  132. update_option($pre . '_live_title', $_POST[$pre . '_live_title']);
  133. }
  134. if (!empty($_POST[$pre . '_stage_url'])) {
  135. update_option($pre . '_stage_url', $_POST[$pre . '_stage_url']);
  136. }
  137. if (!empty($_POST[$pre . '_stage_title'])) {
  138. update_option($pre . '_stage_title', $_POST[$pre . '_stage_title']);
  139. }
  140. if (!empty($_POST[$pre . '_local_url'])) {
  141. update_option($pre . '_local_url', $_POST[$pre . '_local_url']);
  142. }
  143. if (!empty($_POST[$pre . '_local_title'])) {
  144. update_option($pre . '_local_title', $_POST[$pre . '_local_title']);
  145. }
  146. update_option($pre . '_image', $_POST[$pre . '_image']);
  147. update_option($pre . '_dags_logo', $_POST[$pre . '_dags_logo']);
  148. update_option($pre . '_show_ip', $_POST[$pre . '_show_ip']);
  149. update_option($pre . '_remove_comments', $_POST[$pre . '_remove_comments']);
  150. update_option($pre . '_remove_new-post', $_POST[$pre . '_remove_new-post']);
  151. update_option($pre . '_remove_new-link', $_POST[$pre . '_remove_new-link']);
  152. update_option($pre . '_remove_new-media', $_POST[$pre . '_remove_new-media']);
  153. update_option($pre . '_remove_new-page', $_POST[$pre . '_remove_new-page']);
  154. update_option($pre . '_remove_new-user', $_POST[$pre . '_remove_new-user']);
  155. foreach ($this->gmenu as $id => $mm) {
  156. update_option($pre . '_remove_' . $mm[5], $_POST[$pre . '_remove_' . $mm[5]]);
  157. }
  158. }
  159. function admin_line($pre) {
  160. ?>
  161. <table>
  162. <tr><td ><?php echo (__("Server switcher", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_show_switcher'); ?>" type="checkbox" id="<?php echo ($pre . '_show_switcher'); ?>" <?php if (get_option($pre . '_show_switcher', true)) {
  163. echo 'checked';
  164. }
  165. ?> />
  166. <?php if (get_option($pre . '_show_switcher', true)) {
  167. ?>
  168. <table>
  169. <tr><td ><input type="text" name="<?php echo ($pre . '_live_title'); ?>" value="<?php echo (get_option($pre . '_live_title', 'live')); ?>"></td><td><input type="text" name="<?php echo ($pre . '_live_url'); ?>" value="<?php echo (get_option($pre . '_live_url')); ?>"></td></tr>
  170. <tr><td><input type="text" name="<?php echo ($pre . '_stage_title'); ?>" value="<?php echo (get_option($pre . '_stage_title', 'stage')); ?>"></td><td><input type="text" name="<?php echo ($pre . '_stage_url'); ?>" value="<?php echo (get_option($pre . '_stage_url')); ?>"></td></tr>
  171. <tr><td><input type="text" name="<?php echo ($pre . '_local_title'); ?>" value="<?php echo (get_option($pre . '_local_title', 'local')); ?>"></td><td><input type="text" name="<?php echo ($pre . '_local_url'); ?>" value="<?php echo (get_option($pre . '_local_url')); ?>"></td></tr>
  172. </table>
  173. <?php
  174. }?>
  175. </td></tr>
  176. <tr><td ><?php echo (__("Dags logo", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_dags_logo'); ?>" type="checkbox" id="<?php echo ($pre . '_dags_logo'); ?>" <?php if (get_option($pre . '_dags_logo', true)) {
  177. echo 'checked';
  178. }
  179. ?> />
  180. <div >
  181. <div style="width: 300px; height: 100px; overflow: hidden">
  182. <img height="100" src="<?php echo (stripslashes(get_option($pre . "_image"))); ?>">
  183. </div>
  184. <?php echo (__("Login image:", "dagsopt")) ?><br>
  185. <input type="text" name="<?php echo ($pre . '_image'); ?>" class="valuereciever" value="<?php echo (stripslashes(get_option($pre . "_image"))); ?>" />
  186. <button class="button uploadbutton">Upload</button>
  187. </div>
  188. </td></tr>
  189. <tr><td ><?php echo (__("Show IP", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_show_ip'); ?>" type="checkbox" id="<?php echo ($pre . '_show_ip'); ?>" <?php if (get_option($pre . '_show_ip', true)) {
  190. echo 'checked';
  191. }
  192. ?> /></td></tr>
  193. <tr><td colspan="2"><a href="javascript:$('#dags_tools_menus').toggle();">Remove Menus</a></td></tr>
  194. <tr><td ></td><td>
  195. <table id="dags_tools_menus" style="display: none;">
  196. <tr><td colspan="2">Remove Admin Top Bar</td></tr>
  197. <tr><td ><?php echo (__("Comments", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_comments'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_comments'); ?>" <?php if (get_option($pre . '_remove_comments', false)) {
  198. echo 'checked';
  199. }
  200. ?> /></td></tr>
  201. <tr><td ><?php echo (__("New Post", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_new-post'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_new-post'); ?>" <?php if (get_option($pre . '_remove_new-post', false)) {
  202. echo 'checked';
  203. }
  204. ?> /></td></tr>
  205. <tr><td ><?php echo (__("New Link", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_new-link'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_new-link'); ?>" <?php if (get_option($pre . '_remove_new-link', false)) {
  206. echo 'checked';
  207. }
  208. ?> /></td></tr>
  209. <tr><td ><?php echo (__("New Media", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_new-media'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_new-media'); ?>" <?php if (get_option($pre . '_remove_new-media', false)) {
  210. echo 'checked';
  211. }
  212. ?> /></td></tr>
  213. <tr><td ><?php echo (__("New Page", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_new-page'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_new-page'); ?>" <?php if (get_option($pre . '_remove_new-page', false)) {
  214. echo 'checked';
  215. }
  216. ?> /></td></tr>
  217. <tr><td ><?php echo (__("New User", "dagsopt")) ?></td><td><input name="<?php echo ($pre . '_remove_new-user'); ?>" type="checkbox" id="<?php echo ($pre . '_remove_new-user'); ?>" <?php if (get_option($pre . '_remove_new-user', false)) {
  218. echo 'checked';
  219. }
  220. ?> /></td></tr>
  221. <tr><td colspan="2">Remove Admin Mode Bar</td></tr>
  222. <?php
  223. foreach ($this->gmenu as $id => $mm) {
  224. if (strstr($mm[2], "separator")) {
  225. continue;
  226. }
  227. ?>
  228. <tr><td ><?php echo ($mm[0]) ?> </td><td><input name="<?php echo ($pre . '_remove_' . $mm[5]); ?>" type="checkbox" id="<?php echo ($pre . '_remove_' . $mm[5]); ?>" <?php if (get_option($pre . '_remove_' . $mm[5], false)) {
  229. echo 'checked';
  230. }
  231. ?> /> <?php echo ($mm[5]); ?></td></tr>
  232. <?php
  233. }
  234. ?>
  235. </table>
  236. </td></tr>
  237. </table>
  238. <?php
  239. }
  240. }
  241. global $plug_admin_bar;
  242. $plug_admin_bar = new plug_admin_bar($this);
  243. $this->dagsopt['plug_admin_bar'] = $plug_admin_bar;
  244. }