From 19766c4e0e9238be1cd7b2610500257e7aea6137 Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 19 Jul 2013 06:20:22 -0400 Subject: [PATCH 1/8] Bugfix: Warning when in CLI-mode --- templates/themes/sitemap/info.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/themes/sitemap/info.php b/templates/themes/sitemap/info.php index e16448ee..43b529fa 100644 --- a/templates/themes/sitemap/info.php +++ b/templates/themes/sitemap/info.php @@ -23,7 +23,7 @@ 'name' => 'url', 'type' => 'text', 'comment' => '(with trailing slash)', - 'default' => 'http://' . $_SERVER['HTTP_HOST'] . $config['root'], + 'default' => (isset($_SERVER['HTTP_HOST']) ? 'http://' . $_SERVER['HTTP_HOST'] . $config['root'] : ''), 'size' => '20' ); From 0ba40a8fc2b7e798bf1b93e4f9c2972d3ba3f4cc Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 19 Jul 2013 09:39:22 -0400 Subject: [PATCH 2/8] I just realized that ImageMagick had a -auto-orient switch. No need for all that code. --- post.php | 68 ++------------------------------------------------------ 1 file changed, 2 insertions(+), 66 deletions(-) diff --git a/post.php b/post.php index 97fb263d..30db27b9 100644 --- a/post.php +++ b/post.php @@ -434,72 +434,8 @@ if (isset($_POST['delete'])) { if ($config['thumb_method'] == 'convert') { if ($post['extension'] == 'jpg' || $post['extension'] == 'jpeg') { $exif = exif_read_data($upload); - if (isset($exif['Orientation'])) { - switch($exif['Orientation']) { - case 1: - // Normal - $args = false; - break; - case 2: - // 888888 - // 88 - // 8888 - // 88 - // 88 - - $args = '-flop'; - break; - case 3: - - // 88 - // 88 - // 8888 - // 88 - // 888888 - - $args = '-flip -flop'; - break; - case 4: - // 88 - // 88 - // 8888 - // 88 - // 888888 - - $args = '-flip'; - break; - case 5: - // 8888888888 - // 88 88 - // 88 - - $args = '-rotate 90 -flop'; - break; - case 6: - // 88 - // 88 88 - // 8888888888 - - $args = '-rotate 90'; - break; - case 7: - // 88 - // 88 88 - // 8888888888 - - $args = '-rotate "-90" -flop'; - break; - case 8: - // 8888888888 - // 88 88 - // 88 - - $args = '-rotate "-90"'; - break; - } - - if ($args) - shell_exec('convert ' . escapeshellarg($upload) . ' ' . $args . ' ' . escapeshellarg($upload)); + if (isset($exif['Orientation']) && $exif['Orientation'] != 1) { + shell_exec('convert ' . escapeshellarg($upload) . ' -auto-orient ' . escapeshellarg($upload)); } } } From 30dc89278674b8bc83b4e44db920a1c7654c7cdd Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 19 Jul 2013 18:36:12 -0400 Subject: [PATCH 3/8] Only store video URLs in database, instead of the generated player HTML. --- inc/display.php | 29 +++++++++++++++++++++++++++++ post.php | 17 ++++------------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/inc/display.php b/inc/display.php index 2021dc8f..a7e4826e 100644 --- a/inc/display.php +++ b/inc/display.php @@ -241,6 +241,29 @@ function secure_link($href) { return $href . '/' . make_secure_link_token($href); } +function embed_html($link) { + global $config; + + foreach ($config['embedding'] as $embed) { + if ($html = preg_replace($embed[0], $embed[1], $link)) { + if ($html == $link) + continue; // Nope + + $html = str_replace('%%tb_width%%', $config['embed_width'], $html); + $html = str_replace('%%tb_height%%', $config['embed_height'], $html); + + return $html; + } + } + + if ($link[0] == '<') { + // Prior to v0.9.6-dev-8, HTML code for embedding was stored in the database instead of the link. + return $link; + } + + return 'Embedding error.'; +} + class Post { public function __construct($id, $thread, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $embed, $root=null, $mod=false) { global $config; @@ -269,6 +292,9 @@ class Post { $this->root = $root; $this->mod = $mod; + if ($this->embed) + $this->embed = embed_html($this->embed); + if ($this->mod) // Fix internal links // Very complicated regex @@ -365,6 +391,9 @@ class Thread { $this->mod = $mod; $this->hr = $hr; + if ($this->embed) + $this->embed = embed_html($this->embed); + if ($this->mod) // Fix internal links // Very complicated regex diff --git a/post.php b/post.php index 30db27b9..4e10c0cf 100644 --- a/post.php +++ b/post.php @@ -243,19 +243,10 @@ if (isset($_POST['delete'])) { // yep; validate it $value = $_POST['embed']; foreach ($config['embedding'] as &$embed) { - if ($html = preg_replace($embed[0], $embed[1], $value)) { - if ($html == $value) { - // Nope. - continue; - } - - // Width and height - $html = str_replace('%%tb_width%%', $config['embed_width'], $html); - $html = str_replace('%%tb_height%%', $config['embed_height'], $html); - - // Validated. It works. - $post['embed'] = $html; - // This looks messy right now, I know. I'll work on a better alternative later. + if (preg_match($embed[0], $value)) { + // Valid link + $post['embed'] = $value; + // This is bad, lol. $post['no_longer_require_an_image_for_op'] = true; break; } From 158a7c0e79a7d0e8000e8797a277c3fdbf463e0d Mon Sep 17 00:00:00 2001 From: Michael Foster Date: Fri, 19 Jul 2013 19:06:27 -0400 Subject: [PATCH 4/8] Experimental / Proof-of-concept: Don't load the YouTube player unless the video image is clicked. --- js/youtube.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 js/youtube.js diff --git a/js/youtube.js b/js/youtube.js new file mode 100644 index 00000000..482a9bc8 --- /dev/null +++ b/js/youtube.js @@ -0,0 +1,34 @@ +/* +* youtube +* https://github.com/savetheinternet/Tinyboard/blob/master/js/youtube.js +* +* Don't load the YouTube player unless the video image is clicked. +* This increases performance issues when many videos are embedded on the same page. +* Currently only compatiable with YouTube. +* +* Proof of concept. +* +* Released under the MIT license +* Copyright (c) 2013 Michael Save +* +* Usage: +* $config['embedding'] = array(); +* $config['embedding'][] = array( +* '/^https?:\/\/(\w+\.)?youtube\.com\/watch\?v=([a-zA-Z0-9\-_]{10,11})(&.+)?$/i', +* '
' +); +* $config['additional_javascript'][] = 'js/jquery.min.js'; +* $config['additional_javascript'][] = 'js/youtube.js'; +* +*/ + + +onready(function(){ + $('div.video-container a').attr('href', 'javascript:void(0)'); + $('div.video-container').click(function() { + var videoID = $(this).data('video'); + + $(this).html('