diff -uNr a/mp-wp/.htaccess b/mp-wp/.htaccess --- a/mp-wp/.htaccess 23164212887a9fa35d330f33bce2c3b96604e7331b79f2a0de7f8b845556cc06bc5fbee0b01b16e026461aa92302f92d971fbd39ec267528a65c421684226688 +++ b/mp-wp/.htaccess 1794794b2197805ec99a93d1e3269d6095ef597bb19229a41d5859f615e84ecbd3f2afb414bcb3bfc217e835c6b744a2cbef04b2ea1f36f45330d093227417c3 @@ -20,7 +20,7 @@ RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule . /index.php [L] +RewriteRule . /index.php [QSA,L] # END WordPress diff -uNr a/mp-wp/manifest b/mp-wp/manifest --- a/mp-wp/manifest 14d47d8eb66fd8266c00a6911255bbf873aa47dd418bf20975c6432f3190ec9914708760fe5d327c693a579b193b1c808698cbba3be3a2138d3b62257ad77f13 +++ b/mp-wp/manifest 00b581121b09f282560a29d90fbb53a6ad22a7799428554bb1d17584200fb45310a8022757daf326c1709b2032434fb9eb4c507743af87e517adda50e2974365 @@ -7,3 +7,4 @@ 605926 mp-wp_comments_filtering diana_coman Recent comments widget should show only people's comments (no track/pingbacks); theme default changed to show trackbacks/pingbacks as last/at the bottom in an article's comments list. 629903 mp-wp_remove-textselectionjs-pop3-etc-r2 jfw Remove the unreliable JS-based selection (reground: including wrapper spans), posting by POP3 login, and a stray .php.orig file. Neutralize and comment the example pingback updater. 629903 mp-wp_svg-screenshots-and-errorreporting-r2 jfw Allow .svg extensions in theme screenshot search. Don't clobber the user's errorreporting level without WP_DEBUG. (Reground following antecedent.) +631542 mp-wp_add-embeddable-codeblocks-and-server-side-selection billymg Add embeddable codeblocks and the server-side select mechanism to the "footnotes" plugin (now "mp-wp content processing") diff -uNr a/mp-wp/wp-content/plugins/footnotes.php b/mp-wp/wp-content/plugins/footnotes.php --- a/mp-wp/wp-content/plugins/footnotes.php 8e2449d4ac26ea05f080cec9d025ef8a8585221ee30da439b37ff1578d084e1c63cbe3f89e3d6868c19d0fa9f73a9af99b444251e7a854f6c87e316628d94859 +++ b/mp-wp/wp-content/plugins/footnotes.php 5f8bedbdaf66b24223d250d56acc0050ad7df6b7abade9d7834e835142ec46a5baff035c48fece400e10db78116d2af885d2ebfb8522f4ffcee876d58a0969a3 @@ -1,49 +1,29 @@ styles = array( 'decimal' => '1,2...10', @@ -56,111 +36,168 @@ ); // Define default options - $this->default_options = array('superscript'=>true, - 'pre_backlink'=>' [', - 'backlink'=>'↩', - 'post_backlink'=>']', - 'pre_identifier'=>'', - 'list_style_type'=>'decimal', - 'list_style_symbol'=>'†', - 'post_identifier'=>'', - 'pre_footnotes'=>'', - 'post_footnotes'=>'', - 'style_rules'=>'ol.footnotes{font-size:0.8em; color:#666666;}', - 'no_display_home'=>false, - 'no_display_archive'=>false, - 'no_display_date'=>false, - 'no_display_category'=>false, - 'no_display_search'=>false, - 'no_display_feed'=>false, - 'combine_identical_notes'=>false, - 'priority'=>11, - 'version'=>WP_FOOTNOTES_VERSION); + $this->default_options = array( + 'pre_backlink'=>' [', + 'backlink'=>'↩', + 'post_backlink'=>']', + 'pre_identifier'=>'', + 'list_style_type'=>'decimal', + 'list_style_symbol'=>'†', + 'post_identifier'=>'', + 'pre_footnotes'=>'', + 'post_footnotes'=>'' + ); // Get the current settings or setup some defaults if needed - if (!$this->current_options = get_option('swas_footnote_options')){ - $this->current_options = $this->default_options; - update_option('swas_footnote_options', $this->current_options); - } else { + $this->options = get_option('mp_wp_cpp_options'); + if (!$this->options) { + $this->options = $this->default_options; + update_option('mp_wp_cpp_options', $this->options); + } else { // Set any unset options - if ($this->current_options['version'] != WP_FOOTNOTES_VERSION) { - foreach ($this->default_options as $key => $value) { - if (!isset($this->current_options[$key])) { - $this->current_options[$key] = $value; - } + $updated = false; + foreach ($this->default_options as $key => $value) { + if (!isset($this->options[$key])) { + $this->options[$key] = $value; + $updated = true; } - $this->current_options['version'] = WP_FOOTNOTES_VERSION; - update_option('swas_footnote_options', $this->current_options); + } + if ($updated) { + update_option('mp_wp_cpp_options', $this->options); } } -/* - if (!empty($_POST['save_options'])){ - $footnotes_options['superscript'] = (array_key_exists('superscript', $_POST)) ? true : false; - $footnotes_options['pre_backlink'] = $_POST['pre_backlink']; - $footnotes_options['backlink'] = $_POST['backlink']; - $footnotes_options['post_backlink'] = $_POST['post_backlink']; - $footnotes_options['pre_identifier'] = $_POST['pre_identifier']; - $footnotes_options['list_style_type'] = $_POST['list_style_type']; - $footnotes_options['post_identifier'] = $_POST['post_identifier']; - $footnotes_options['list_style_symbol'] = $_POST['list_style_symbol']; - $footnotes_options['pre_footnotes'] = stripslashes($_POST['pre_footnotes']); - $footnotes_options['post_footnotes'] = stripslashes($_POST['post_footnotes']); - $footnotes_options['style_rules'] = stripslashes($_POST['style_rules']); - $footnotes_options['no_display_home'] = (array_key_exists('no_display_home', $_POST)) ? true : false; - $footnotes_options['no_display_archive'] = (array_key_exists('no_display_archive', $_POST)) ? true : false; - $footnotes_options['no_display_date'] = (array_key_exists('no_display_date', $_POST)) ? true : false; - $footnotes_options['no_display_category'] = (array_key_exists('no_display_category', $_POST)) ? true : false; - $footnotes_options['no_display_search'] = (array_key_exists('no_display_search', $_POST)) ? true : false; - $footnotes_options['no_display_feed'] = (array_key_exists('no_display_feed', $_POST)) ? true : false; - $footnotes_options['combine_identical_notes'] = (array_key_exists('combine_identical_notes', $_POST)) ? true : false; - $footnotes_options['priority'] = $_POST['priority']; - update_option('swas_footnote_options', $footnotes_options); - }elseif(!empty($_POST['reset_options'])){ - update_option('swas_footnote_options', ''); - update_option('swas_footnote_options', $this->default_options); - } -*/ - // Hook me up - add_action('the_content', array($this, 'process'), $this->current_options['priority']); - add_action('admin_menu', array($this, 'add_options_page')); // Insert the Admin panel. + add_action('the_content', array($this, 'process_codeblocks'), self::MP_WP_CODEBLOCKS_PRIORITY); + add_action('the_content', array($this, 'process_footnotes'), self::MP_WP_FOOTNOTES_PRIORITY); + add_filter('the_content', array($this, 'server_side_selection')); add_action('wp_head', array($this, 'insert_styles')); } + + /** + * Finds the selection from the query params. + * @param $data string The content of the post. + * @return string The new content with the highlighted selection. + */ + function server_side_selection($data) { + //bookend code goes here + $b_code = ''; + $b_code .= $_GET["b"]; + $e_code = $_GET["e"].''; + + //change page ; last to first to preserve indexes. + $b_pos = strpos($data,$_GET["b"]); + $e_pos = strpos($data,$_GET["e"], $b_pos); + if ($e_pos>0) + $data = substr_replace($data, $e_code, $e_pos, strlen($_GET["e"])); + if ($b_pos>0) + $data = substr_replace($data, $b_code, $b_pos, strlen($_GET["b"])); + return $data; + } + + /** + * Searches the text and apply markup to codeblocks. + * Adds line number links and diff syntax highlighting. + * @param $data string The content of the post. + * @return string The new content with formatted codeblocks. + */ + function process_codeblocks($data) { + global $post; + + // Regex extraction of all codeblocks (or return if there are none) + if ( !preg_match_all("/\[([a-z]+)\[(.*)(\]\])/Us", $data, $codeblocks, PREG_SET_ORDER) ) { + return $data; + } + + for ($i = 0; $i < count($codeblocks); $i++) { + $codeblocks[$i]['snippet'] = $this->format_snippet($codeblocks[$i][2], $codeblocks[$i][1], $i+1); + } + + foreach ($codeblocks as $key => $value) { + $data = substr_replace($data, $value['snippet'], strpos($data,$value[0]),strlen($value[0])); + } + + return $data; + } + + function format_snippet($snippet, $syntax, $snippet_number) { + $highlighting_functions = array( + 'plaintext' => 'highlight_as_plain_text', + 'diff' => 'highlight_as_diff' + ); + + if (is_null($highlighting_functions[$syntax])) { + $syntax = 'plaintext'; + } + + $code_lines = explode("\r\n", $snippet); + + foreach ($code_lines as $idx => $line) { + $line_number = sprintf('S%d-L%d', $snippet_number, $idx+1); + $line_link = sprintf('%d', $line_number, $line_number, $idx+1); + $line_open = sprintf('%s', $line_link); + $line_close = ''; + + $code_lines[$idx] = $this->$highlighting_functions[$syntax]($line_open, $line, $line_close); + } + + $formatted_snippet = implode("\n", $code_lines); + + $formatted_snippet = sprintf( + '%s%s%s', + '
', + $formatted_snippet, + '
' + ); + + return $formatted_snippet; + } + + function highlight_as_plain_text($line_open, $line, $line_close) { + return sprintf('%s%s%s', $line_open, $line, $line_close); + } + + function highlight_as_diff($line_open, $line, $line_close) { + if (substr($line, 0, 5) == 'diff ') { + $highlighted_line = sprintf('%s%s%s', $line_open, $line, $line_close); + } elseif (substr($line, 0, 4) == '--- ' || substr($line, 0, 4) == '+++ ' || substr($line, 0, 3) == '@@ ') { + $highlighted_line = sprintf('%s%s%s', $line_open, $line, $line_close); + } elseif (substr($line, 0, 1) == '-') { + $highlighted_line = sprintf('%s%s%s', $line_open, $line, $line_close); + } elseif (substr($line, 0, 1) == '+') { + $highlighted_line = sprintf('%s%s%s', $line_open, $line, $line_close); + } else { + $highlighted_line = sprintf('%s%s%s', $line_open, $line, $line_close); + } + + return $highlighted_line; + } + /** * Searches the text and extracts footnotes. * Adds the identifier links and creats footnotes list. * @param $data string The content of the post. * @return string The new content with footnotes generated. */ - function process($data) { + function process_footnotes($data) { global $post; // Check for and setup the starting number $start_number = (preg_match("||",$data,$start_number_array)==1) ? $start_number_array[1] : 1; // Regex extraction of all footnotes (or return if there are none) - if (!preg_match_all("/(".preg_quote(WP_FOOTNOTES_OPEN)."|)(.*)(".preg_quote(WP_FOOTNOTES_CLOSE)."|<\/footnote>)/Us", $data, $identifiers, PREG_SET_ORDER)) { + if (!preg_match_all("/(".preg_quote(self::MP_WP_FOOTNOTES_OPEN)."|)(.*)(".preg_quote(self::MP_WP_FOOTNOTES_CLOSE)."|<\/footnote>)/Us", $data, $identifiers, PREG_SET_ORDER)) { return $data; } - // Check whether we are displaying them or not - $display = true; - if ($this->current_options['no_display_home'] && is_home()) $display = false; - if ($this->current_options['no_display_archive'] && is_archive()) $display = false; - if ($this->current_options['no_display_date'] && is_date()) $display = false; - if ($this->current_options['no_display_category'] && is_category()) $display = false; - if ($this->current_options['no_display_search'] && is_search()) $display = false; - if ($this->current_options['no_display_feed'] && is_feed()) $display = false; - $footnotes = array(); // Check if this post is using a different list style to the settings if ( array_key_exists(get_post_meta($post->ID, 'footnote_style', true), $this->styles) ) { $style = get_post_meta($post->ID, 'footnote_style', true); } else { - $style = $this->current_options['list_style_type']; + $style = $this->options['list_style_type']; } // Create 'em @@ -173,25 +210,11 @@ $identifiers[$i]['text'] = $identifiers[$i][2]; } - - // if we're combining identical notes check if we've already got one like this & record keys - if ($this->current_options['combine_identical_notes']){ - for ($j=0; $jID; $id_num = ($style == 'decimal') ? $value['use_footnote']+$start_number : $this->convert_num($value['use_footnote']+$start_number, $style, count($footnotes)); $id_href = ( ($use_full_link) ? get_permalink($post->ID) : '' ) . "#footnote_".$value['use_footnote']."_".$post->ID; - -// $id_title = str_replace('"', """, htmlentities(strip_tags($value['text']), ENT_QUOTES, 'UTF-8')); - $id_title = str_replace('"', '`', strip_tags($value['text'])); - $id_replace = $this->current_options['pre_identifier'].''.$id_num.''.$this->current_options['post_identifier']; - if ($this->current_options['superscript']) $id_replace = ''.$id_replace.''; - if ($display) $data = substr_replace($data, $id_replace, strpos($data,$value[0]),strlen($value[0])); - else $data = substr_replace($data, '', strpos($data,$value[0]),strlen($value[0])); + $id_replace = ''.$this->options['pre_identifier'].''.$id_num.''.$this->options['post_identifier'].''; + $data = substr_replace($data, $id_replace, strpos($data,$value[0]),strlen($value[0])); } // Display footnotes - if ($display) { - $start = ($start_number != 1) ? 'start="'.$start_number.'" ' : ''; - $data = $data.$this->current_options['pre_footnotes']; - - $data = $data . '
    '; - foreach ($footnotes as $key => $value) { - $data = $data.'
  1. current_options['list_style_type']) { - $data = $data . ' style="list-style-type:' . $style . ';"'; - } - $data = $data . '>'; - if ($style == 'symbol') { - $data = $data . '' . $this->convert_num($key+$start_number, $style, count($footnotes)) . ' '; - } - $data = $data.$value['text']; - if (!is_feed()){ - foreach($value['identifiers'] as $identifier){ - $data = $data.$this->current_options['pre_backlink'].''.$this->current_options['backlink'].''.$this->current_options['post_backlink']; - } + $start = ($start_number != 1) ? 'start="'.$start_number.'" ' : ''; + $data = $data.$this->options['pre_footnotes']; + + $data = $data . '
      '; + foreach ($footnotes as $key => $value) { + $data = $data.'
    1. options['list_style_type']) { + $data = $data . ' style="list-style-type:' . $style . ';"'; + } + $data = $data . '>'; + if ($style == 'symbol') { + $data = $data . '' . $this->convert_num($key+$start_number, $style, count($footnotes)) . ' '; + } + $data = $data.$value['text']; + if (!is_feed()){ + foreach($value['identifiers'] as $identifier){ + $data = $data.$this->options['pre_backlink'].''.$this->options['backlink'].''.$this->options['post_backlink']; } - $data = $data . '
    2. '; } - $data = $data . '
    ' . $this->current_options['post_footnotes']; + $data = $data . '
  2. '; } - return $data; - } - - /** - * Really insert the options page. - */ - function footnotes_options_page() { - $this->current_options = get_option('swas_footnote_options'); - foreach ($this->current_options as $key=>$setting) { - $new_setting[$key] = htmlentities($setting); - } - $this->current_options = $new_setting; - unset($new_setting); - include (dirname(__FILE__) . '/options.php'); - } + $data = $data . '
' . $this->options['post_footnotes']; - /** - * Insert the options page into the admin area. - */ - function add_options_page() { - // Add a new menu under Options: - add_options_page('Footnotes', 'Footnotes', 8, __FILE__, array($this, 'footnotes_options_page')); - } - - function upgrade_post($data){ - $data = str_replace('',WP_FOOTNOTES_OPEN,$data); - $data = str_replace('',WP_FOOTNOTES_CLOSE,$data); return $data; } - function insert_styles(){ + function insert_styles() { ?> current_options['list_style_symbol']; + $sym .= $this->options['list_style_symbol']; } return $sym; } @@ -318,7 +344,7 @@ * @param string $case Upper or lower case. * @return string The roman numeral */ - function roman($num, $case= 'upper'){ + function roman($num, $case= 'upper') { $num = (int) $num; $conversion = array('M'=>1000, 'CM'=>900, 'D'=>500, 'CD'=>400, 'C'=>100, 'XC'=>90, 'L'=>50, 'XL'=>40, 'X'=>10, 'IX'=>9, 'V'=>5, 'IV'=>4, 'I'=>1); $roman = ''; @@ -331,7 +357,7 @@ return ($case == 'lower') ? strtolower($roman) : $roman; } - function alpha($num, $case='upper'){ + function alpha($num, $case='upper') { $j = 1; for ($i = 'A'; $i <= 'ZZ'; $i++){ if ($j == $num){ diff -uNr a/mp-wp/xmlrpc.php b/mp-wp/xmlrpc.php --- a/mp-wp/xmlrpc.php 4f496f538195a62e0f48c2d27dd787923795583c1ae1419c1135d132ca848efe79b148f31de66d9414829b034981427920b317952be6fe23a097447815b14000 +++ b/mp-wp/xmlrpc.php d26b211e8c163bae44b267a173ba2724e8475a6ee44ea0fd0caed998d85de6de1589efae5a82efe598ed884b0e0db2c9b8b5b6d644fef1142546d9fb1df16849 @@ -3326,7 +3326,8 @@ $comment_post_ID = (int) $post_ID; $comment_author = $title; $this->escape($comment_author); - $comment_author_url = $pagelinkedfrom; + $select_tail = "?b=".substr(rawurlencode(strip_tags($excerpt)),0,12)."&e=".substr(rawurlencode(strip_tags($excerpt)),0,-4)."#select"; + $comment_author_url = $pagelinkedfrom.$select_tail; $comment_content = $context; $this->escape($comment_content); $comment_type = 'pingback';