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('