[ Index ]

PHP Cross Reference of Wordpress 2.7.1

title

Body

[close]

/wp-admin/includes/ -> misc.php (source)

   1  <?php
   2  /**
   3   * Misc WordPress Administration API.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /**
  10   * {@internal Missing Short Description}}
  11   *
  12   * @since unknown
  13   *
  14   * @return unknown
  15   */
  16  function got_mod_rewrite() {
  17      $got_rewrite = apache_mod_loaded('mod_rewrite', true);
  18      return apply_filters('got_rewrite', $got_rewrite);
  19  }
  20  
  21  /**
  22   * {@internal Missing Short Description}}
  23   *
  24   * @since unknown
  25   *
  26   * @param unknown_type $filename
  27   * @param unknown_type $marker
  28   * @return array An array of strings from a file (.htaccess ) from between BEGIN and END markers.
  29   */
  30  function extract_from_markers( $filename, $marker ) {
  31      $result = array ();
  32  
  33      if (!file_exists( $filename ) ) {
  34          return $result;
  35      }
  36  
  37      if ( $markerdata = explode( "\n", implode( '', file( $filename ) ) ));
  38      {
  39          $state = false;
  40          foreach ( $markerdata as $markerline ) {
  41              if (strpos($markerline, '# END ' . $marker) !== false)
  42                  $state = false;
  43              if ( $state )
  44                  $result[] = $markerline;
  45              if (strpos($markerline, '# BEGIN ' . $marker) !== false)
  46                  $state = true;
  47          }
  48      }
  49  
  50      return $result;
  51  }
  52  
  53  /**
  54   * {@internal Missing Short Description}}
  55   *
  56   * Inserts an array of strings into a file (.htaccess ), placing it between
  57   * BEGIN and END markers. Replaces existing marked info. Retains surrounding
  58   * data. Creates file if none exists.
  59   *
  60   * @since unknown
  61   *
  62   * @param unknown_type $filename
  63   * @param unknown_type $marker
  64   * @param unknown_type $insertion
  65   * @return bool True on write success, false on failure.
  66   */
  67  function insert_with_markers( $filename, $marker, $insertion ) {
  68      if (!file_exists( $filename ) || is_writeable( $filename ) ) {
  69          if (!file_exists( $filename ) ) {
  70              $markerdata = '';
  71          } else {
  72              $markerdata = explode( "\n", implode( '', file( $filename ) ) );
  73          }
  74  
  75          $f = fopen( $filename, 'w' );
  76          $foundit = false;
  77          if ( $markerdata ) {
  78              $state = true;
  79              foreach ( $markerdata as $n => $markerline ) {
  80                  if (strpos($markerline, '# BEGIN ' . $marker) !== false)
  81                      $state = false;
  82                  if ( $state ) {
  83                      if ( $n + 1 < count( $markerdata ) )
  84                          fwrite( $f, "{$markerline}\n" );
  85                      else
  86                          fwrite( $f, "{$markerline}" );
  87                  }
  88                  if (strpos($markerline, '# END ' . $marker) !== false) {
  89                      fwrite( $f, "# BEGIN {$marker}\n" );
  90                      if ( is_array( $insertion ))
  91                          foreach ( $insertion as $insertline )
  92                              fwrite( $f, "{$insertline}\n" );
  93                      fwrite( $f, "# END {$marker}\n" );
  94                      $state = true;
  95                      $foundit = true;
  96                  }
  97              }
  98          }
  99          if (!$foundit) {
 100              fwrite( $f, "\n# BEGIN {$marker}\n" );
 101              foreach ( $insertion as $insertline )
 102                  fwrite( $f, "{$insertline}\n" );
 103              fwrite( $f, "# END {$marker}\n" );
 104          }
 105          fclose( $f );
 106          return true;
 107      } else {
 108          return false;
 109      }
 110  }
 111  
 112  /**
 113   * Updates the htaccess file with the current rules if it is writable.
 114   *
 115   * Always writes to the file if it exists and is writable to ensure that we
 116   * blank out old rules.
 117   *
 118   * @since unknown
 119   */
 120  function save_mod_rewrite_rules() {
 121      global $wp_rewrite;
 122  
 123      $home_path = get_home_path();
 124      $htaccess_file = $home_path.'.htaccess';
 125  
 126      // If the file doesn't already exists check for write access to the directory and whether of not we have some rules.
 127      // else check for write access to the file.
 128      if ((!file_exists($htaccess_file) && is_writable($home_path) && $wp_rewrite->using_mod_rewrite_permalinks()) || is_writable($htaccess_file)) {
 129          if ( got_mod_rewrite() ) {
 130              $rules = explode( "\n", $wp_rewrite->mod_rewrite_rules() );
 131              return insert_with_markers( $htaccess_file, 'WordPress', $rules );
 132          }
 133      }
 134  
 135      return false;
 136  }
 137  
 138  /**
 139   * {@internal Missing Short Description}}
 140   *
 141   * @since unknown
 142   *
 143   * @param unknown_type $file
 144   */
 145  function update_recently_edited( $file ) {
 146      $oldfiles = (array ) get_option( 'recently_edited' );
 147      if ( $oldfiles ) {
 148          $oldfiles = array_reverse( $oldfiles );
 149          $oldfiles[] = $file;
 150          $oldfiles = array_reverse( $oldfiles );
 151          $oldfiles = array_unique( $oldfiles );
 152          if ( 5 < count( $oldfiles ))
 153              array_pop( $oldfiles );
 154      } else {
 155          $oldfiles[] = $file;
 156      }
 157      update_option( 'recently_edited', $oldfiles );
 158  }
 159  
 160  /**
 161   * If siteurl or home changed, flush rewrite rules.
 162   *
 163   * @since unknown
 164   *
 165   * @param unknown_type $old_value
 166   * @param unknown_type $value
 167   */
 168  function update_home_siteurl( $old_value, $value ) {
 169      global $wp_rewrite;
 170  
 171      if ( defined( "WP_INSTALLING" ) )
 172          return;
 173  
 174      // If home changed, write rewrite rules to new location.
 175      $wp_rewrite->flush_rules();
 176  }
 177  
 178  add_action( 'update_option_home', 'update_home_siteurl', 10, 2 );
 179  add_action( 'update_option_siteurl', 'update_home_siteurl', 10, 2 );
 180  
 181  /**
 182   * {@internal Missing Short Description}}
 183   *
 184   * @since unknown
 185   *
 186   * @param unknown_type $url
 187   * @return unknown
 188   */
 189  function url_shorten( $url ) {
 190      $short_url = str_replace( 'http://', '', stripslashes( $url ));
 191      $short_url = str_replace( 'www.', '', $short_url );
 192      if ('/' == substr( $short_url, -1 ))
 193          $short_url = substr( $short_url, 0, -1 );
 194      if ( strlen( $short_url ) > 35 )
 195          $short_url = substr( $short_url, 0, 32 ).'...';
 196      return $short_url;
 197  }
 198  
 199  /**
 200   * {@internal Missing Short Description}}
 201   *
 202   * @since unknown
 203   *
 204   * @param unknown_type $vars
 205   */
 206  function wp_reset_vars( $vars ) {
 207      for ( $i=0; $i<count( $vars ); $i += 1 ) {
 208          $var = $vars[$i];
 209          global $$var;
 210  
 211          if (!isset( $$var ) ) {
 212              if ( empty( $_POST["$var"] ) ) {
 213                  if ( empty( $_GET["$var"] ) )
 214                      $$var = '';
 215                  else
 216                      $$var = $_GET["$var"];
 217              } else {
 218                  $$var = $_POST["$var"];
 219              }
 220          }
 221      }
 222  }
 223  
 224  /**
 225   * {@internal Missing Short Description}}
 226   *
 227   * @since unknown
 228   *
 229   * @param unknown_type $message
 230   */
 231  function show_message($message) {
 232      if( is_wp_error($message) ){
 233          if( $message->get_error_data() )
 234              $message = $message->get_error_message() . ': ' . $message->get_error_data();
 235          else
 236              $message = $message->get_error_message();
 237      }
 238      echo "<p>$message</p>\n";
 239  }
 240  
 241  ?>


Generated: Mon Mar 23 16:23:02 2009 Cross-referenced by PHPXref 0.7