PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/plugins/serverbuddy-by-pluginbuddy/classes/admin.php

https://github.com/digitalstrategyworks/Reese-WordPress
PHP | 163 lines | 103 code | 28 blank | 32 comment | 13 complexity | 9d4531f1ea596168f1a843ca9a481cab MD5 | raw file
  1. <?php
  2. if ( !class_exists( 'pluginbuddy_skylerbuddy_admin' ) ) {
  3. class pluginbuddy_skylerbuddy_admin {
  4. function pluginbuddy_skylerbuddy_admin( &$parent ) {
  5. $this->_parent = &$parent;
  6. $this->_var = &$parent->_var;
  7. $this->_name = &$parent->_name;
  8. $this->_options = &$parent->_options;
  9. $this->_pluginPath = &$parent->_pluginPath;
  10. $this->_pluginURL = &$parent->_pluginURL;
  11. $this->_selfLink = &$parent->_selfLink;
  12. add_action( 'admin_menu', array( &$this, 'admin_menu' ) ); // Add menu in admin.
  13. }
  14. function alert() {
  15. $args = func_get_args();
  16. return call_user_func_array( array( $this->_parent, 'alert' ), $args );
  17. }
  18. function video() {
  19. $args = func_get_args();
  20. return call_user_func_array( array( $this->_parent, 'video' ), $args );
  21. }
  22. function tip() {
  23. $args = func_get_args();
  24. return call_user_func_array( array( $this->_parent, 'tip' ), $args );
  25. }
  26. function log() {
  27. $args = func_get_args();
  28. return call_user_func_array( array( $this->_parent, 'log' ), $args );
  29. }
  30. function title( $title ) {
  31. echo '<h2><img src="' . $this->_pluginURL .'/images/icon.png" style="vertical-align: -7px;"> ' . $title . '</h2>';
  32. }
  33. function nonce() {
  34. wp_nonce_field( $this->_parent->_var . '-nonce' );
  35. }
  36. /**
  37. * savesettings()
  38. *
  39. * Saves a form into the _options array.
  40. *
  41. * Use savepoint to set the root array key path. Accepts variable depth, dividing array keys with pound signs.
  42. * Ex: $_POST['savepoint'] value something like array_key_name#subkey
  43. * <input type="hidden" name="savepoint" value="files#exclusions" /> to set the root to be $this->_options['files']['exclusions']
  44. *
  45. * All inputs with the name beginning with pound will act as the array keys to be set in the _options with the associated posted value.
  46. * Ex: $_POST['#key_name'] or $_POST['#key_name#subarray_key_name'] value is the array value to set.
  47. * <input type="text" name="#name" /> will save to $this->_options['name']
  48. * <input type="text" name="#group#17#name" /> will save to $this->_options['groups'][17]['name']
  49. */
  50. function savesettings() {
  51. check_admin_referer( $this->_parent->_var . '-nonce' );
  52. if ( !empty( $_POST['savepoint'] ) ) {
  53. $savepoint_root = stripslashes( $_POST['savepoint'] ) . '#';
  54. } else {
  55. $savepoint_root = '';
  56. }
  57. $posted = stripslashes_deep( $_POST ); // Unescape all the stuff WordPress escaped. Sigh @ WordPress for being like PHP magic quotes.
  58. foreach( $posted as $index => $item ) {
  59. if ( substr( $index, 0, 1 ) == '#' ) {
  60. $savepoint_subsection = &$this->_options;
  61. $savepoint_levels = explode( '#', $savepoint_root . substr( $index, 1 ) );
  62. foreach ( $savepoint_levels as $savepoint_level ) {
  63. $savepoint_subsection = &$savepoint_subsection{$savepoint_level};
  64. }
  65. $savepoint_subsection = $item;
  66. }
  67. }
  68. $this->_parent->save();
  69. $this->alert( 'Settings saved...' );
  70. }
  71. function admin_scripts() {
  72. //wp_enqueue_script( 'jquery' );
  73. wp_enqueue_script( 'pluginbuddy-tooltip-js', $this->_parent->_pluginURL . '/js/tooltip.js' );
  74. wp_print_scripts( 'pluginbuddy-tooltip-js' );
  75. wp_enqueue_script( 'pluginbuddy-'.$this->_var.'-admin-js', $this->_parent->_pluginURL . '/js/admin.js' );
  76. wp_print_scripts( 'pluginbuddy-'.$this->_var.'-admin-js' );
  77. echo '<link rel="stylesheet" href="'.$this->_pluginURL . '/css/admin.css" type="text/css" media="all" />';
  78. }
  79. /**
  80. * get_feed()
  81. *
  82. * Gets an RSS or other feed and inserts it as a list of links...
  83. *
  84. * $feed string URL to the feed.
  85. * $limit integer Number of items to retrieve.
  86. * $append string HTML to include in the list. Should usually be <li> items including the <li> code.
  87. * $replace string String to replace in every title returned. ie twitter includes your own username at the beginning of each line.
  88. * $cache_time int Amount of time to cache the feed, in seconds.
  89. */
  90. function get_feed( $feed, $limit, $append = '', $replace = '', $cache_time = 300 ) {
  91. require_once(ABSPATH.WPINC.'/feed.php');
  92. $rss = fetch_feed( $feed );
  93. if (!is_wp_error( $rss ) ) {
  94. $maxitems = $rss->get_item_quantity( $limit ); // Limit
  95. $rss_items = $rss->get_items(0, $maxitems);
  96. echo '<ul class="pluginbuddy-nodecor">';
  97. $feed_html = get_transient( md5( $feed ) );
  98. if ( $feed_html == '' ) {
  99. foreach ( (array) $rss_items as $item ) {
  100. $feed_html .= '<li>- <a href="' . $item->get_permalink() . '">';
  101. $title = $item->get_title(); //, ENT_NOQUOTES, 'UTF-8');
  102. if ( $replace != '' ) {
  103. $title = str_replace( $replace, '', $title );
  104. }
  105. if ( strlen( $title ) < 30 ) {
  106. $feed_html .= $title;
  107. } else {
  108. $feed_html .= substr( $title, 0, 32 ) . ' ...';
  109. }
  110. $feed_html .= '</a></li>';
  111. }
  112. set_transient( md5( $feed ), $feed_html, $cache_time ); // expires in 300secs aka 5min
  113. }
  114. echo $feed_html;
  115. echo $append;
  116. echo '</ul>';
  117. } else {
  118. echo 'Temporarily unable to load feed...';
  119. }
  120. }
  121. function view_tools() {
  122. //$this->_parent->versions_confirm();
  123. require( 'view_tools.php' );
  124. }
  125. /** admin_menu()
  126. *
  127. * Initialize menu for admin section.
  128. *
  129. */
  130. function admin_menu() {
  131. add_management_page( $this->_parent->_name.' ServerBuddy', 'ServerBuddy', 'administrator', $this->_parent->_var . '-tools', array(&$this, 'view_tools'));
  132. }
  133. } // End class
  134. $pluginbuddy_skylerbuddy_admin = new pluginbuddy_skylerbuddy_admin( $this );
  135. }