Skip to content

Instantly share code, notes, and snippets.

@archon810
Created July 29, 2012 17:05
Show Gist options
  • Save archon810/3200265 to your computer and use it in GitHub Desktop.
Save archon810/3200265 to your computer and use it in GitHub Desktop.
Index: embed-github-gist.php
===================================================================
--- embed-github-gist.php (revision 641938)
+++ embed-github-gist.php (working copy)
@@ -35,11 +35,13 @@
* Build a cache key
* @param int $id GitHub Gist ID
* @param string $bump Bump value to force cache expirey.
+ * @param int $height Height of the box
*/
-function embed_github_gist_build_cache_key($id, $bump = null, $file=null) {
+function embed_github_gist_build_cache_key($id, $bump = null, $file=null, $height = null) {
$key = 'embed_github_gist-' . $id;
if ( $bump ) $key .= '-' . $bump;
if ( $file ) $key .= '-' . $file;
+ if ( $height ) $key .= '-' . $height;
return $key;
}
@@ -64,18 +66,20 @@
* @param int $ttl How long to cache (in seconds)
* @param string $bump Bump value to force cache expirey.
* @param string $file Name of file
+ * @param int $height Height of the box
*/
-function embed_github_gist($id, $ttl = null, $bump = null, $file = null) {
+function embed_github_gist($id, $ttl = null, $bump = null, $file = null, $height = null) {
$gist = '';
if ( !class_exists('WP_Http') ) {
require_once ABSPATH.WPINC.'/class-http.php';
}
- $key = embed_github_gist_build_cache_key($id, $bump, $file);
+ $key = embed_github_gist_build_cache_key($id, $bump, $file, $height);
if ( embed_github_gist_bypass_cache() || false === ( $gist = get_transient($key) ) ) {
$http = new WP_Http;
- $args = array('sslverify' => false);
+
+ $args = array('sslverify' => false);
if (defined('EMBED_GISTHUB_USERNAME') && defined('EMBED_GISTHUB_PASSWORD')) {
$args['headers'] = array( 'Authorization' => 'Basic '.base64_encode(EMBED_GISTHUB_USERNAME.':'.EMBED_GISTHUB_PASSWORD) );
}
@@ -107,7 +111,9 @@
}
$gist = '';
-
+ if ($height)
+ $gist .= "<style>#gist$id div.gist-data {height: ${height}px; overflow:auto} </style>";
+
if (count($files)) {
if ( embed_github_gist_prefer_inline_html() ) {
foreach ($files as $name => $fileInfo) {
@@ -152,6 +158,7 @@
'file' => null,
'ttl' => null,
'bump' => null,
+ 'height' => null,
), $atts));
if ( ! $id ) {
@@ -161,7 +168,7 @@
}
}
}
- return $id ? embed_github_gist($id, $ttl, $bump, $file) : $content;
+ return $id ? embed_github_gist($id, $ttl, $bump, $file, $height) : $content;
}
/**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment