GoldenLayout is a web based docker layout engine that aids in creating flexible user interfaces by enabling panels to be docked on the screen.
MediaStreamRecorder.js is a cross-browser implementation to record audio & video streams via WebRTC. The lib allows you to submit/upload recorded blobs in realtime to your server.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<script src="https://cdn.webrtc-experiment.com/MediaStreamRecorder.js"> </script> <script> var mediaConstraints = { audio: true, video: true }; navigator.getUserMedia(mediaConstraints, onMediaSuccess, onMediaError); function onMediaSuccess(stream) { var multiStreamRecorder = new MultiStreamRecorder(stream); multiStreamRecorder.video = yourVideoElement; // to get maximum accuracy multiStreamRecorder.audioChannels = 1; multiStreamRecorder.ondataavailable = function (blobs) { // blobs.audio // blobs.video }; multiStreamRecorder.start(3 * 1000); } function onMediaError(e) { console.error('media error', e); } </script> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?php foreach(array('video', 'audio') as $type) { if (isset($_FILES["${type}-blob"])) { $fileName = $_POST["${type}-filename"]; $uploadDirectory = "uploads/$fileName"; if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $uploadDirectory)) { echo("problem moving uploaded file"); } echo($uploadDirectory); } } ?> |
Dragdealer.js is a drag-based JavaScript component, embracing endless UI solutions.
The lib provides a huge amount of options to use it for a multitude of functions.
“Gisto is a code snippet manager that runs on GitHub Gists and adds additional features such as searching, tagging and sharing gists while including a rich code editor. All your data is stored on GitHub and you can access it from GitHub Gists at any time with changes carrying over to Gisto.”
The application is multi-platform.
jsPanel are multifunctional floating panels, that can also be used as a simple modal or tooltip. Panels can be minimized and maximized and have a huge amount of options.
Really impressive projectand well documented.
“Boba.js is a small, easily extensible JavaScript library that makes working with Google Analytics easier.”
1 2 3 4 5 6 7 8 9 10 11 12 13 |
tracker = new Boba tracker = new Boba({ siteName: 'Mandalore', pageName: 'Slave I', defaultCategory: 'category', defaultAction: 'action', defaultLabel: 'label', watch: [ ['click', '.js-track-solo', trackSolo], ['click', '.js-track-chewie', trackChewie] ] }) |
JSON Formatter & Validator helps debugging JSON data, either data you wrote by hand or data that has been output in one compact line :)
Due to Google AMP (Accelerated Mobile Pages) , I have been looking for a way to effectively do Syntax Highlighting without Javascript in pure PHP.
I was about to write my own, when I found an older article from phoboslab. Thanks Dominic for saving me some time ;) Its not perfect, but close enough.
A simple Syntax Highlighting Class that does just that. The class was not working with PHP 5.4.x+, as it uses preg_replace() with the /e modifier.
It will not cover all, but its better than nothing :) I will also add a section to my my AMP tweaks article to showcase the integration of Geshi.
Here an updated version using the preg_replace_callback() function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
class SyntaxHighlight { static $tokens = array();// This array will be filled from the regexp-callback public static function process($s) { $s = htmlspecialchars($s); // Workaround for escaped backslashes $s = str_replace('\\\\','\\\\<e>', $s); $regexp = array( // Punctuations '/([\-\!\%\^\*\(\)\+\|\~\=`\{\}\[\]\:\"\'<>\?\,\.\/]+)/' => '<span class="P">$1</span>', // Numbers (also look for Hex) '/(?<!\w)( (0x|\#)[\da-f]+| \d+| \d+(px|em|cm|mm|rem|s|\%) )(?!\w)/ix' => '<span class="N">$1</span>', // Make the bold assumption that an // all uppercase word has a special meaning '/(?<!\w|>|\#)( [A-Z_0-9]{2,} )(?!\w)/x' => '<span class="D">$1</span>', // Keywords '/(?<!\w|\$|\%|\@|>)( and|or|xor|for|do|while|foreach|as|return|die|exit|if|then|else| elseif|new|delete|try|throw|catch|finally|class|function|string| array|object|resource|var|bool|boolean|int|integer|float|double| real|string|array|global|const|static|public|private|protected| published|extends|switch|true|false|null|void|this|self|struct| char|signed|unsigned|short|long )(?!\w|=")/ix' => '<span class="K">$1</span>', // PHP/Perl-Style Vars: $var, %var, @var '/(?<!\w)( (\$|\%|\@)(\->|\w)+ )(?!\w)/ix' => '<span class="V">$1</span>' ); $s = preg_replace_callback( '/( \/\*.*?\*\/| \/\/.*?\n| \#.[^a-fA-F0-9]+?\n| \<\!\-\-[\s\S]+\-\-\>| (?<!\\\)".*?(?<!\\\)"| (?<!\\\)\'(.*?)(?<!\\\)\' )/isx' , array('SyntaxHighlight', 'replaceId'),$s); $s = preg_replace(array_keys($regexp), array_values($regexp), $s); // Paste the comments and strings back in again $s = str_replace(array_keys(SyntaxHighlight::$tokens), array_values(SyntaxHighlight::$tokens), $s); // Delete the "Escaped Backslash Workaround Token" (TM) // and replace tabs with four spaces. $s = str_replace(array('<e>', "\t"), array('', ' '), $s); return '<pre>'.$s.'</pre>' ; } // Regexp-Callback to replace every comment or string with a uniqid and save // the matched text in an array // This way, strings and comments will be stripped out and wont be processed // by the other expressions searching for keywords etc. static function replaceId($match) { $id = "##r" . uniqid() . "##"; // String or Comment? if(substr($match[1], 0, 2) == '//' || substr($match[1], 0, 2) == '/*' || substr($match[1], 0, 2) == '##' || substr($match[1], 0, 7) == '<!--') { SyntaxHighlight::$tokens[$id] = '<span class="C">' . $match[1] . '</span>'; } else { SyntaxHighlight::$tokens[$id] = '<span class="S">' . $match[1] . '</span>'; } return $id; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
pre { font-family: 'Courier New', 'Bitstream Vera Sans Mono', 'monospace'; font-size: 9pt; border-top: 1px solid #333; border-bottom: 1px solid #333; padding: 0.4em; color: #fff; } pre span.N{ color:#f2c47f; } /* Numbers */ pre span.S{ color:#42ff00; } /* Strings */ pre span.C{ color:#838383; } /* Comments */ pre span.K{ color:#ff0078; } /* Keywords */ pre span.V{ color:#70d6ff; } /* Vars */ pre span.D{ color:#ff9a5d; } /* Defines */ |
1 |
echo SyntaxHighlight::process( $your_code ); |
@GitHub portalzine/UtilityBelt/SyntaxHighlight
The AMP (Accelerated Mobile Pages Project) plugin for WordPress is still pretty young and under heavy development.
There are little things that can help to fix current validation problems. I have a couple of fresh AMP pages, that are already indexed by Google.
The currently registered Microformats template (schema.org-NewsArticle) requires an image.
The AMP-WP documentation explains how to add a featured image to your pages (documentation).
I extended that a bit, to link a default attachment image, I uploaded before. This needs to be added to your themes functions.php.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
function xyz_amp_add_custom_actions() { add_filter( 'the_content', 'xyz_amp_add_featured_image' ); } function xyz_amp_add_featured_image( $content ) { $your_attachment_id = 2016; if ( has_post_thumbnail() ) { $image = sprintf( '<p class="xyz-featured-image">%s</p>', get_the_post_thumbnail() ); }else{ $image = sprintf( '<p class="xyz-featured-image">%s</p>', wp_get_attachment_image( $your_attachment_id, 1280) ); $content = $image . $content ; } $content = $image . $content ; return preg_replace('/(<br>\s*){2,}/', '<br/>',$content); } |
Next we adjust the Microformats definition. This needs to be added to your themes functions.php.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
add_filter( 'amp_post_template_metadata', 'xyz_amp_modify_json_metadata', 10, 2 ); function xyz_amp_modify_json_metadata( $metadata, $post ) { if(empty($metadata['image'])){ $your_attachment_id = 2016; $imgMeta = wp_get_attachment_metadata($your_attachment_id ); $metadata['image'] = array( '@type' => 'ImageObject', 'url' => wp_get_attachment_url( $your_attachment_id ), 'height' => $imgMeta['height'], 'width' => $imgMeta['width'], ); } return $metadata; } |
Read the AMP-WP documentation first :) This forces AMP-WP to override the core template with your own. Use the default template as a reference.
1 2 3 4 5 6 7 8 |
add_filter( 'amp_post_template_file', 'xyz_amp_set_custom_template', 10, 3 ); function xyz_amp_set_custom_template( $file, $type, $post ) { if ( 'single' === $type ) { $file = dirname( __FILE__ ) . '/amp/amp_template.php'; } return $file; } |
Normally the core sanitizer should take care of that. I am sure a filter will be added in the future. For now, this is a quick workaround. You can use a RegExp or DOMDocument to alter the amp-content in your custom template and filter things that break validation.
1 2 3 4 |
$attributes = $element->attributes; while ($attributes->length) { $element->removeAttribute($attributes->item(0)->name); } |
I am using phpQuery for now, as it allows me to add quick fixes. DOMNode or QueryPath works nicely as well :) Will be looking at the core sanitizer and options later this week. All of this is currently added to the custom template.
1 2 |
require('your-libs/phpQuery/phpQuery.php'); $doc = phpQuery::newDocumentHTML($this->get( 'post_amp_content' )); |
1 |
$doc['.prettyphoto']->removeAttr("rel"); |
1 |
$doc['*']->removeAttr("align"); |
1 |
$doc['a[target="new"]']->attr("target","_blank"); |
Finally output the fixed content as HTML.
1 |
echo $doc->html(); // amphtml content; no kses |
The above examples need to be tweaked to your specific content requirements.
The custom template “post_amp_content” before:
1 |
echo $this->get( 'post_amp_content'); // amphtml content; no kses |
The custom template “post_amp_content” after:
1 2 3 4 5 6 |
require('your-libs/phpQuery/phpQuery.php'); $doc = phpQuery::newDocumentHTML($this->get( 'post_amp_content' )); $doc['.prettyphoto']->removeAttr("rel")->removeAttr("href"); $doc['*']->removeAttr("align"); $doc['a[target="new"]']->attr("target","_blank"); echo $doc->html(); // amphtml content; no kses |
From the AMP specification :”Note, that AMP document may also be linked to directly…”
This is being added to the custom template as well.
Next:
1 2 3 4 5 6 7 |
global $query_string; $posts = query_posts($query_string); if (have_posts()) : while (have_posts()) : the_post(); $next_post = get_next_post(); if (!empty( $next_post )): echo '<a class="next" href="'.amp_get_permalink( $next_post->ID ).'"> ↜ '.$next_post->post_title.'</a>'; endif; |
Previous:
1 2 3 4 5 |
$prev_post = get_previous_post(); if (!empty( $prev_post )): echo '<a class="prev" href="'.amp_get_permalink( $prev_post->ID ).'"> ↜ '.$prev_post->post_title.'</a>'; endif; |
You can find a simple pure PHP highlighter here. Not perfect, but a start. Don not forget to include the CSS :)
1 2 3 4 5 |
require_once("your-lib/SyntaxHighlight/SyntaxHighlight.php"); foreach(pq('pre') as $code) { pq($code)->html(SyntaxHighlight::process(pq($code)->text())); } |
I will extend on this as new validation errors or tweaks come up. The core sanitizer of AMP-WP still needs some work and should allow us to do some of the above directly, when the content is parsed / converted for AMP.