Fixed static reference PHP syntax for compatibility with the server environment.
authorjond@apple.com <jond@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Dec 2015 20:53:04 +0000 (20:53 +0000)
committerjond@apple.com <jond@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Dec 2015 20:53:04 +0000 (20:53 +0000)
* wp-content/plugins/table-of-contents.php:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192901 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Websites/webkit.org/ChangeLog
Websites/webkit.org/wp-content/plugins/table-of-contents.php

index ee33cba..3e548a2 100644 (file)
@@ -1,5 +1,11 @@
 2015-12-01  Jonathan Davis  <jond@apple.com>
 
+        Fixed static reference PHP syntax for compatibility with the server environment.
+
+        * wp-content/plugins/table-of-contents.php:
+
+2015-12-01  Jonathan Davis  <jond@apple.com>
+
         Fixed PHP syntax for compatibility with the server environment.
 
         * wp-content/plugins/social-meta.php:
index f0e61aa..bd46587 100644 (file)
@@ -10,35 +10,37 @@ Author: Jonathan Davis
 WebKitTableOfContents::init();
 
 class WebKitTableOfContents {
-    
+
     private static $editing = false;
     private static $toc = array();
     private static $attr_regex = '\{((?:[ ]*[#.][-_:a-zA-Z0-9]+){1,})[ ]*\}';
-    
+
     public function init() {
         add_filter( 'wp_insert_post_data', array( 'WebKitTableOfContents', 'wp_insert_post_data' ), 20, 2 );
         add_action( 'wp_insert_post', array( 'WebKitTableOfContents', 'wp_insert_post' ) );
     }
 
-    public function hasIndex() {
+    public static function hasIndex() {
         $toc = get_post_meta( get_the_ID(), 'toc', true );
-        array_walk($toc, function ( $value, $key ) {
-            list($level, $anchor) = explode('::', $key);
-            if ( $level < 4 ) self::$toc[ $key ] = $value;
-        });
+        array_walk($toc, array('WebKitTableOfContents', 'filterIndex'));
         return ( ! empty(self::$toc) && count(self::$toc) > 2 );
     }
-        
+
+    public static function filterIndex($value, $key) {
+        list($level, $anchor) = explode('::', $key);
+        if ( $level < 4 ) self::$toc[ $key ] = $value;
+    }
+
     public static function renderMarkup() {
         if ( ! is_page() ) return;
-        
+
         if ( empty(self::$toc) || ! self::hasIndex() )
             return;
-        
+
         $depth = 0;
         $parent = 0;
         $markup = '<input type="checkbox" id="table-of-contents-toggle" class="menu-toggle"><menu class="table-of-contents"><menuitem class="list"><h6><label for="table-of-contents-toggle">Contents</label></h6>';
-        
+
         foreach ( self::$toc as $name => $heading ) {
             list($level, $anchor) = explode('::', $name);
             if ( empty($level) || $level > 3 ) continue;
@@ -48,65 +50,65 @@ class WebKitTableOfContents {
                 $depth = $level;
             } elseif ( $level == $depth )
                 $markup .= '</li>';
-            
 
-        
+
+
             if ( $level > $depth ) {
                 $markup .= '<ul class="level-' . $level . '">';
-                $depth = $level;                
+                $depth = $level;
                 $parent = $depth;
             }
-            
+
             $markup .= sprintf('<li><a href="#%s">%s</a>', $anchor, $heading);
-            
+
         }
         $markup .= '</ul></menuitem></menu>';
 
         return $markup;
     }
-    
+
     public static function markup() {
         echo self::renderMarkup();
     }
-    
-       public function wp_insert_post_data( $post_data, $record ) {
-        
+
+    public function wp_insert_post_data( $post_data, $record ) {
+
         if ( ! in_array($post_data['post_type'], array('page')) )
             return $post_data;
-        
+
         $post_data['post_content'] = self::parse($post_data['post_content']);
-               
+
         self::$editing = isset( $record['ID'] ) ? $record['ID'] : false;
-        
+
         return $post_data;
     }
-    
+
     public static function wp_insert_post( $post_id ) {
         if ( empty(self::$toc) ) return;
         if ( self::$editing && self::$editing != $post_id ) return;
-        update_post_meta($post_id, 'toc', self::$toc);        
+        update_post_meta($post_id, 'toc', self::$toc);
     }
-    
+
     public static function parse( $content ) {
         $markup = preg_replace_callback('{
                 ^<h([1-6])[^>]*>(.+?)<\/h[1-6]>* # HTML tags
                 |
-                       ^(\#{1,6})      # $1 = string of #\'s
-                       [ ]*
-                       (.+?)           # $2 = Header text
-                       [ ]*
-                       \#*                     # optional closing #\'s (not counted)
-                       (?:[ ]+ ' . self::$attr_regex . ' )?     # $3 = id/class attributes
-                       [ ]*
-                       \n+
-                       }xm',
+                ^(\#{1,6})    # $1 = string of #\'s
+                [ ]*
+                (.+?)        # $2 = Header text
+                [ ]*
+                \#*            # optional closing #\'s (not counted)
+                (?:[ ]+ ' . self::$attr_regex . ' )?     # $3 = id/class attributes
+                [ ]*
+                \n+
+            }xm',
             array('WebKitTableOfContents', 'index'),
             $content
         );
-        
+
         return $markup;
     }
-    
+
     public static function index( $matches ) {
         list($marked, $level, $heading) = $matches;
         $anchor = sanitize_title_with_dashes($heading);