<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[813] sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer: Code Reference: allow for mixed text and code in examples</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://meta.trac.wordpress.org/changeset/813">813</a></dd>
<dt>Author</dt> <dd>coffee2code</dd>
<dt>Date</dt> <dd>2014-08-26 08:04:21 +0000 (Tue, 26 Aug 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Code Reference: allow for mixed text and code in examples
* Enable shortcode support in comments
* Allow for mixed code and text in examples
* Move functions and handling related to user submitted content into inc/user-content.php
* Add padding around comments</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperfunctionsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperinctemplatetagsphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperscssmainscss">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperstylesheetsmaincss">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperincusercontentphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperfunctionsphp"></a>
<div class="modfile"><h4>Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php (812 => 813)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php 2014-08-26 03:21:21 UTC (rev 812)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/functions.php 2014-08-26 08:04:21 UTC (rev 813)
</span><span class="lines">@@ -31,6 +31,11 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><ins>+ * User-submitted content (comments, examples, etc).
+ */
+require __DIR__ . '/inc/user-content.php';
+
+/**
</ins><span class="cx"> * Set the content width based on the theme's design and stylesheet.
</span><span class="cx"> */
</span><span class="cx"> if ( ! isset( $content_width ) ) {
</span><span class="lines">@@ -57,19 +62,14 @@
</span><span class="cx">
</span><span class="cx"> add_filter( 'the_excerpt', __NAMESPACE__ . '\\lowercase_P_dangit_just_once' );
</span><span class="cx"> add_filter( 'the_content', __NAMESPACE__ . '\\make_doclink_clickable', 10, 5 );
</span><del>- add_filter( 'comments_open', __NAMESPACE__ . '\\can_user_post_example', 10, 2 );
</del><span class="cx">
</span><span class="cx"> // Add the handbook's 'Watch' action link.
</span><span class="cx"> if ( class_exists( 'WPorg_Handbook_Watchlist' ) && method_exists( 'WPorg_Handbook_Watchlist', 'display_action_link' ) ) {
</span><span class="cx"> add_action( 'wporg_action_links', array( 'WPorg_Handbook_Watchlist', 'display_action_link' ) );
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // Temporarily disable comments
- //add_filter( 'comments_open', '__return_false' );
-
</del><span class="cx"> add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items', 10, 2 );
</span><span class="cx">
</span><del>- treat_comments_as_examples();
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -355,102 +355,9 @@
</span><span class="cx"> wp_enqueue_style( 'wp-dev-sass-compiled', get_template_directory_uri() . '/stylesheets/main.css', array( 'wporg-developer-style' ), '20140819' );
</span><span class="cx"> wp_enqueue_script( 'wporg-developer-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true );
</span><span class="cx"> wp_enqueue_script( 'wporg-developer-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true );
</span><del>-
- if ( is_singular() && ( '0' != get_comments_number() || post_type_has_source_code() ) ) {
- wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery', 'syntaxhighlighter-core', 'syntaxhighlighter-brush-php' ), '20140515', true );
- wp_enqueue_style( 'syntaxhighlighter-core' );
- wp_enqueue_style( 'syntaxhighlighter-theme-default' );
-
- wp_enqueue_script( 'wporg-developer-code-examples', get_template_directory_uri() . '/js/code-example.js', array(), '20140423', true );
- if ( get_option( 'thread_comments' ) ) {
- wp_enqueue_script( 'comment-reply' );
- }
- }
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Handles adding/removing hooks to enable comments as examples.
- *
- * Mostly gives users greater permissions in terms of comment content.
- *
- * In order to submit code examples, users must be able to post with less restrictions.
- */
-function treat_comments_as_examples() {
- // Restricts commenting to logged in users.
- add_filter( 'comments_open', __NAMESPACE__ . '\\prevent_invalid_comment_submissions', 10, 2 );
-
- if ( ! current_user_can( 'unfiltered_html' ) ) {
- remove_filter( 'pre_comment_content', 'wp_filter_kses' );
- add_filter( 'pre_comment_content', 'wp_filter_post_kses' );
- }
-
- // Force comment registration to be true
- add_filter( 'pre_option_comment_registration', '__return_true' );
-
- // Force comment moderation to be true
- add_filter( 'pre_option_comment_moderation', '__return_true' );
-
- // Remove reply to link
- add_filter( 'comment_reply_link', '__return_empty_string' );
-
-/* foreach ( array( 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
- add_filter( $filter, 'balanceTags', 50 );
- }*/
-
- remove_filter( 'comment_text', 'capital_P_dangit', 31 );
-
- remove_filter( 'comment_text', 'wptexturize' );
- remove_filter( 'comment_text', 'convert_chars' );
- remove_filter( 'comment_text', 'make_clickable', 9 );
- remove_filter( 'comment_text', 'force_balance_tags', 25 );
- remove_filter( 'comment_text', 'convert_smilies', 20 );
- remove_filter( 'comment_text', 'wpautop', 30 );
-
- remove_filter( 'pre_comment_content', 'wp_rel_nofollow', 15 );
-
- // Be more permissive with content of examples.
- // Note: the content gets fully escaped via 'get_comment_text'.
- if ( post_type_supports_examples() ) {
- if ( current_user_can( 'unfiltered_html' ) ) {
- remove_filter( 'pre_comment_content', 'wp_filter_post_kses' );
- } else {
- remove_filter( 'pre_comment_content', 'wp_filter_kses' );
- }
- }
-
- add_filter( 'get_comment_text', __NAMESPACE__ . '\\escape_example_content' );
-}
-
-/**
- * Escapes the entirety of the content for examples.
- *
- * @param string $text The comment/example content.
- * @return string
- */
-function escape_example_content( $text ) {
- // Only proceed if the post type is one that has examples.
- if ( ! post_type_supports_examples() ) {
- return $text;
- }
-
- return htmlentities( $text );
-}
-
-/**
- * Disables commenting to invalid or non-users.
- *
- * @param bool $status Default commenting status for post.
- * @return bool False if commenter isn't a user, otherwise the passed in status.
- */
-function prevent_invalid_comment_submissions( $status, $post_id ) {
- if ( $_POST && ( ! is_user_logged_in() || ! is_user_member_of_blog() ) ) {
- return false;
- }
-
- return $status;
-}
-
-/**
</del><span class="cx"> * Allows for "Wordpress" just for the excerpt value of the capital_P_dangit function.
</span><span class="cx"> *
</span><span class="cx"> * WP.org has a global output buffer that runs capital_P_dangit() over displayed
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperinctemplatetagsphp"></a>
<div class="modfile"><h4>Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php (812 => 813)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php 2014-08-26 03:21:21 UTC (rev 812)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/template-tags.php 2014-08-26 08:04:21 UTC (rev 813)
</span><span class="lines">@@ -92,8 +92,8 @@
</span><span class="cx">
</span><span class="cx"> <li id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
</span><span class="cx"> <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
</span><del>- <div class="comment-content code-example-container">
- <pre class="brush: php; toolbar: false;"><?php comment_text(); /* Fully escaped via filter */ ?></pre>
</del><ins>+ <div class="comment-content">
+ <?php comment_text(); ?>
</ins><span class="cx"> </div>
</span><span class="cx"> <!-- .comment-content -->
</span><span class="cx">
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperincusercontentphp"></a>
<div class="addfile"><h4>Added: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php (0 => 813)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php 2014-08-26 08:04:21 UTC (rev 813)
</span><span class="lines">@@ -0,0 +1,117 @@
</span><ins>+<?php
+/**
+ * Code Reference user submitted content (comments, examples, etc).
+ *
+ * @package wporg-developer
+ */
+
+/**
+ * Class to handle user submitted content.
+ */
+class DevHub_User_Submitted_Content {
+
+ /**
+ * Initializer
+ */
+ public function init() {
+ add_action( 'init', array( __CLASS__, 'do_init' ) );
+ }
+
+ /**
+ * Handles adding/removing hooks to enable comments as examples.
+ *
+ * Mostly gives users greater permissions in terms of comment content.
+ *
+ * In order to submit code examples, users must be able to post with less restrictions.
+ */
+ function do_init() {
+
+ // Restricts commenting to logged in users.
+ add_filter( 'comments_open', array( __CLASS__, 'prevent_invalid_comment_submissions' ), 10, 2 );
+
+ // Sets whether submitting examples is open for the user
+ add_filter( 'comments_open', '\DevHub\\can_user_post_example', 10, 2 );
+
+ // Enqueue scripts and styles
+ add_action( 'wp_enqueue_scripts', array( __CLASS__, 'scripts_and_styles' ), 11 );
+
+ // Force comment registration to be true
+ add_filter( 'pre_option_comment_registration', '__return_true' );
+
+ // Force comment moderation to be true
+ add_filter( 'pre_option_comment_moderation', '__return_true' );
+
+ // Remove reply to link
+ add_filter( 'comment_reply_link', '__return_empty_string' );
+
+ // Disable smilie conversion
+ remove_filter( 'comment_text', 'convert_smilies', 20 );
+
+ // Disable capital_P_dangit
+ remove_filter( 'comment_text', 'capital_P_dangit', 31 );
+
+ // Enable shortcodes for comments
+ add_filter( 'comment_text', 'do_shortcode');
+
+ // Make 'php' the default language
+ add_filter( 'syntaxhighlighter_shortcodeatts', array( __CLASS__, 'syntaxhighlighter_shortcodeatts' ) );
+
+ // Tweak code contained in shortcode
+ add_filter( 'syntaxhighlighter_precode', array( __CLASS__, 'syntaxhighlighter_precode' ) );
+
+ }
+
+ /**
+ * Enqueues scripts and styles.
+ */
+ public function scripts_and_styles() {
+ if ( is_singular() && ( '0' != get_comments_number() || \DevHub\post_type_has_source_code() ) ) {
+ wp_enqueue_script( 'wporg-developer-function-reference', get_template_directory_uri() . '/js/function-reference.js', array( 'jquery', 'syntaxhighlighter-core', 'syntaxhighlighter-brush-php' ), '20140515', true );
+ wp_enqueue_style( 'syntaxhighlighter-core' );
+ wp_enqueue_style( 'syntaxhighlighter-theme-default' );
+
+ wp_enqueue_script( 'wporg-developer-code-examples', get_template_directory_uri() . '/js/code-example.js', array(), '20140423', true );
+ if ( get_option( 'thread_comments' ) ) {
+ wp_enqueue_script( 'comment-reply' );
+ }
+ }
+ }
+
+ /**
+ * Disables commenting to invalid or non-users.
+ *
+ * @param bool $status Default commenting status for post.
+ * @return bool False if commenter isn't a user, otherwise the passed in status.
+ */
+ public static function prevent_invalid_comment_submissions( $status, $post_id ) {
+ if ( $_POST && ( ! is_user_logged_in() || ! is_user_member_of_blog() ) ) {
+ return false;
+ }
+
+ return $status;
+ }
+
+ /**
+ * Sets the default language for SyntaxHighlighter shortcode.
+ *
+ * @param array $atts Shortcode attributes.
+ * @return array
+ */
+ public static function syntaxhighlighter_shortcodeatts( $atts ) {
+ $atts['language'] = 'php';
+ return $atts;
+ }
+
+ /**
+ * Subverts capital_P_dangit for SyntaxHighlighter shortcode.
+ *
+ * @param string $code
+ * @return string
+ */
+ public static function syntaxhighlighter_precode( $code ) {
+ return str_replace( 'Wordpress', 'Wordpress', $code );
+ }
+
+} // DevHub_User_Submitted_Content
+
+DevHub_User_Submitted_Content::init();
</ins><span class="cx">Property changes on: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/user-content.php
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<ins>+native
</ins><span class="cx">\ No newline at end of property
</span><a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperscssmainscss"></a>
<div class="modfile"><h4>Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss (812 => 813)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss 2014-08-26 03:21:21 UTC (rev 812)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/scss/main.scss 2014-08-26 08:04:21 UTC (rev 813)
</span><span class="lines">@@ -972,15 +972,14 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .comment-list li {
</span><del>- padding: 24px 24px 0 24px;
- padding: 1.5rem 1.5rem 0 1.5rem;
</del><ins>+ padding: 2rem 1.5rem 1rem;
</ins><span class="cx"> border: 0 solid #eee;
</span><span class="cx"> border-bottom-width: 1px;
</span><span class="cx"> background: #fff;
</span><del>- }
</del><span class="cx">
</span><del>- .comment-list li:first-child {
- padding-top: 0;
</del><ins>+ &:first-child {
+ padding-top: 1rem;
+ }
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> .comment-list .avatar {
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgdeveloperstylesheetsmaincss"></a>
<div class="modfile"><h4>Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css (812 => 813)</h4>
<pre class="diff"><span>
<span class="info">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css 2014-08-26 03:21:21 UTC (rev 812)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/stylesheets/main.css 2014-08-26 08:04:21 UTC (rev 813)
</span><span class="lines">@@ -1161,14 +1161,13 @@
</span><span class="cx"> padding: 0;
</span><span class="cx"> }
</span><span class="cx"> .devhub-wrap .comment-list li {
</span><del>- padding: 24px 24px 0 24px;
- padding: 1.5rem 1.5rem 0 1.5rem;
</del><ins>+ padding: 2rem 1.5rem 1rem;
</ins><span class="cx"> border: 0 solid #eee;
</span><span class="cx"> border-bottom-width: 1px;
</span><span class="cx"> background: #fff;
</span><span class="cx"> }
</span><del>-.devhub-wrap .comment-list li {
- padding-top: 0;
</del><ins>+.devhub-wrap .comment-list li:first-child {
+ padding-top: 1rem;
</ins><span class="cx"> }
</span><span class="cx"> .devhub-wrap .comment-list .avatar {
</span><span class="cx"> float: left;
</span></span></pre>
</div>
</div>
</body>
</html>