diff --git a/inc/config.php b/inc/config.php index 721d0974..78941116 100644 --- a/inc/config.php +++ b/inc/config.php @@ -491,7 +491,8 @@ 'password', 'sticky', 'lock', - 'raw' + 'raw', + 'embed' ); // Custom flood filters. Detect flood attacks and reject new posts if there's a positive match. @@ -583,16 +584,21 @@ // Characters used to generate a random password (with Javascript) $config['genpassword_chars'] = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+'; + // Enable embedding (see below) + $config['enable_enbedding'] = false; + // Custom embedding (YouTube, vimeo, etc.) + // It's very important that you match the full string (with ^ and $) or things will not work correctly. $config['embedding'] = Array( Array( - '/^https?:\/\/(\w+\.)?youtube\.com\/watch\?v=([a-zA-Z0-9-]{10,11})(&|$)/i', - '' + '/^https?:\/\/(\w+\.)?youtube\.com\/watch\?v=([a-zA-Z0-9-]{10,11})(&.+)?$/i', + // '', + '' ) ); // Embedding width and height - $config['embed_width'] = 200; - $config['embed_height'] = 164; + $config['embed_width'] = 300; + $config['embed_height'] = 246; // Enable IP range bans (eg. "127.*.0.1", "127.0.0.*", and "12*.0.0.1" all match "127.0.0.1"). diff --git a/inc/display.php b/inc/display.php index 2f0c15a2..7ec95ef3 100644 --- a/inc/display.php +++ b/inc/display.php @@ -186,7 +186,7 @@ } class Post { - public function __construct($id, $thread, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $root=null, $mod=false) { + 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; if(!isset($root)) $root = $config['root']; @@ -208,6 +208,7 @@ $this->filesize = $filesize; $this->filename = $filename; $this->ip = $ip; + $this->embed = $embed; $this->root = $root; $this->mod = $mod; @@ -312,28 +313,33 @@ // JavaScript cite ''.$this->id.'' . '
'; - - // File info - if(!empty($this->file) && $this->file != 'deleted') { + + if($this->embed) { + // Embedded video (or something else; doesn't have to be a video really) + $built .= + // Actual embedding + $this->embed; + } elseif(!empty($this->file) && $this->file != 'deleted') { + // File info $built .= 'File: ' . $this->file . ' (' . - // Filesize - format_bytes($this->filesize) . - // File dimensions - ($this->filex && $this->filey ? - ', ' . $this->filex . 'x' . $this->filey - : '' ); - // Aspect Ratio - if($config['show_ratio'] && $this->filex && $this->filey) { - $fraction = fraction($this->filex, $this->filey, ':'); - $built .= ', ' . $fraction; - } - // Filename - $built .= ', ' . $this->filename . ')
' . - - // Thumbnail - ''; - } elseif($this->file == 'deleted') { - $built .= ''; + // Filesize + format_bytes($this->filesize) . + // File dimensions + ($this->filex && $this->filey ? + ', ' . $this->filex . 'x' . $this->filey + : '' ); + // Aspect Ratio + if($config['show_ratio'] && $this->filex && $this->filey) { + $fraction = fraction($this->filex, $this->filey, ':'); + $built .= ', ' . $fraction; + } + // Filename + $built .= ', ' . $this->filename . ')' . + + // Thumbnail + ''; + } elseif($this->file == 'deleted') { + $built .= ''; } $built .= $this->postControls(); @@ -346,7 +352,7 @@ }; class Thread { - public function __construct($id, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $locked, $root=null, $mod=false, $hr=true) { + public function __construct($id, $subject, $email, $name, $trip, $capcode, $body, $time, $thumb, $thumbx, $thumby, $file, $filex, $filey, $filesize, $filename, $ip, $sticky, $locked, $embed, $root=null, $mod=false, $hr=true) { global $config; if(!isset($root)) $root = $config['root']; @@ -372,6 +378,7 @@ $this->ip = $ip; $this->sticky = $sticky; $this->locked = $locked; + $this->embed = $embed; $this->root = $root; $this->mod = $mod; $this->hr = $hr; @@ -440,22 +447,32 @@ public function build($index=false) { global $board, $config; - $built = 'File: ' . $this->file . ' (' .
- // Filesize
- format_bytes($this->filesize) .
- // File dimensions
- ($this->filex && $this->filey ?
- ', ' . $this->filex . 'x' . $this->filey
- : '' );
- // Aspect Ratio
- if($config['show_ratio'] && $this->filex && $this->filey) {
- $fraction = fraction($this->filex, $this->filey, ':');
- $built .= ', ' . $fraction;
+ if($this->embed) {
+ // Embedded video (or something else; doesn't have to be a video really)
+ $built =
+ // Actual embedding
+ $this->embed;
+ } else {
+ // Image, not embedded shit
+ $built =
+ // File link
+ ' File: ' . $this->file . ' (' .
+ // Filesize
+ format_bytes($this->filesize) .
+ // File dimensions
+ ($this->filex && $this->filey ?
+ ', ' . $this->filex . 'x' . $this->filey
+ : '' );
+ // Aspect Ratio
+ if($config['show_ratio'] && $this->filex && $this->filey) {
+ $fraction = fraction($this->filex, $this->filey, ':');
+ $built .= ', ' . $fraction;
+ }
+ // Filename
+ $built .= ', ' . $this->filename . ')
'; diff --git a/inc/functions.php b/inc/functions.php index c23168d9..a2ea8168 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -94,18 +94,6 @@ if($config['memcached']['enabled']) memcached_open(); - - // Test custom fields and stuff - if(isset($config['fields'])) { - $error_func = function_exists('error') ? 'error' : 'basic_error_function_because_the_other_isnt_loaded_yet'; - - foreach($config['fields'] as $index => $field) { - if(!is_array($field)) - $error_func(sprintf("Error parsing custom fields. Field at index %d is not an array!", $index)); - if(!isset($field['name'])) - $error_func(sprintf("Error parsing custom fields. Field at index %d doesn't have a name!", $index)); - } - } } function basic_error_function_because_the_other_isnt_loaded_yet($message) { @@ -428,8 +416,7 @@ function post($post, $OP) { global $pdo, $board; - - $query = prepare(sprintf("INSERT INTO `posts_%s` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :time, :time, :thumb, :thumbwidth, :thumbheight, :file, :width, :height, :filesize, :filename, :filehash, :password, :ip, :sticky, :locked)", $board['uri'])); + $query = prepare(sprintf("INSERT INTO `posts_%s` VALUES ( NULL, :thread, :subject, :email, :name, :trip, :capcode, :body, :time, :time, :thumb, :thumbwidth, :thumbheight, :file, :width, :height, :filesize, :filename, :filehash, :password, :ip, :sticky, :locked, :embed)", $board['uri'])); // Basic stuff $query->bindValue(':subject', $post['subject']); @@ -459,6 +446,12 @@ $query->bindValue(':capcode', NULL, PDO::PARAM_NULL); } + if(!empty($post['embed'])) { + $query->bindValue(':embed', $post['embed']); + } else { + $query->bindValue(':embed', NULL, PDO::PARAM_NULL); + } + if($OP) { // No parent thread, image $query->bindValue(':thread', null, PDO::PARAM_NULL); @@ -611,9 +604,9 @@ if($query->rowcount() < 1 && $page > 1) return false; while($th = $query->fetch()) { - $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['capcode'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $th['locked'], $mod ? '?/' : $config['root'], $mod); + $thread = new Thread($th['id'], $th['subject'], $th['email'], $th['name'], $th['trip'], $th['capcode'], $th['body'], $th['time'], $th['thumb'], $th['thumbwidth'], $th['thumbheight'], $th['file'], $th['filewidth'], $th['fileheight'], $th['filesize'], $th['filename'], $th['ip'], $th['sticky'], $th['locked'], $th['embed'], $mod ? '?/' : $config['root'], $mod); - $posts = prepare(sprintf("SELECT `id`, `subject`, `email`, `name`, `trip`, `capcode`, `body`, `time`, `thumb`, `thumbwidth`, `thumbheight`, `file`, `filewidth`, `fileheight`, `filesize`, `filename`,`ip` FROM `posts_%s` WHERE `thread` = ? ORDER BY `id` DESC LIMIT ?", $board['uri'])); + $posts = prepare(sprintf("SELECT * FROM `posts_%s` WHERE `thread` = ? ORDER BY `id` DESC LIMIT ?", $board['uri'])); $posts->bindValue(1, $th['id']); $posts->bindValue(2, ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview']), PDO::PARAM_INT); $posts->execute() or error(db_error($posts)); @@ -623,7 +616,7 @@ if($po['file']) $num_images++; - $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['capcode'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $mod ? '?/' : $config['root'], $mod)); + $thread->add(new Post($po['id'], $th['id'], $po['subject'], $po['email'], $po['name'], $po['trip'], $po['capcode'], $po['body'], $po['time'], $po['thumb'], $po['thumbwidth'], $po['thumbheight'], $po['file'], $po['filewidth'], $po['fileheight'], $po['filesize'], $po['filename'], $po['ip'], $po['embed'], $mod ? '?/' : $config['root'], $mod)); } if($posts->rowCount() == ($th['sticky'] ? $config['threads_preview_sticky'] : $config['threads_preview'])) { @@ -962,7 +955,7 @@ while($page <= $config['max_pages'] && $content = index($page)) { $filename = $board['dir'] . ($page==1 ? $config['file_index'] : sprintf($config['file_page'], $page)); if(file_exists($filename)) $md5 = md5_file($filename); - + $content['pages'] = $pages; $content['pages'][$page-1]['selected'] = true; $content['btn'] = getPageButtons($content['pages']); @@ -1231,15 +1224,15 @@ global $board, $config; $id = round($id); - $query = prepare(sprintf("SELECT `id`,`thread`,`subject`,`name`,`email`,`trip`,`capcode`,`body`,`time`,`thumb`,`thumbwidth`,`thumbheight`,`file`,`filewidth`,`fileheight`,`filesize`,`filename`,`ip`,`sticky`,`locked` FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`time`", $board['uri'])); + $query = prepare(sprintf("SELECT * FROM `posts_%s` WHERE (`thread` IS NULL AND `id` = :id) OR `thread` = :id ORDER BY `thread`,`time`", $board['uri'])); $query->bindValue(':id', $id, PDO::PARAM_INT); $query->execute() or error(db_error($query)); while($post = $query->fetch()) { if(!isset($thread)) { - $thread = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $mod ? '?/' : $config['root'], $mod); + $thread = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $post['embed'], $mod ? '?/' : $config['root'], $mod); } else { - $thread->add(new Post($post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $mod ? '?/' : $config['root'], $mod)); + $thread->add(new Post($post['id'], $thread->id, $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], $mod ? '?/' : $config['root'], $mod)); } } diff --git a/mod.php b/mod.php index 6de6c8f1..ce486525 100644 --- a/mod.php +++ b/mod.php @@ -822,9 +822,9 @@ $temp = ''; while($post = $query->fetch()) { if(!$post['thread']) { - $po = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], '?/', $mod, false); + $po = new Thread($post['id'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['sticky'], $post['locked'], $post['embed'], '?/', $mod, false); } else { - $po = new Post($post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], '?/', $mod); + $po = new Post($post['id'], $post['thread'], $post['subject'], $post['email'], $post['name'], $post['trip'], $post['capcode'], $post['body'], $post['time'], $post['thumb'], $post['thumbwidth'], $post['thumbheight'], $post['file'], $post['filewidth'], $post['fileheight'], $post['filesize'], $post['filename'], $post['ip'], $post['embed'], '?/', $mod); } $temp .= $po->build(true) . '