mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-12-18 02:16:03 +01:00
Embedding field
This commit is contained in:
parent
88a48c10d5
commit
797fd8ad13
@ -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',
|
||||
'<iframe width="%%tb_width%%" height="%%tb_height%%" src="http://www.youtube.com/embed/$2" frameborder="0" allowfullscreen></iframe>'
|
||||
'/^https?:\/\/(\w+\.)?youtube\.com\/watch\?v=([a-zA-Z0-9-]{10,11})(&.+)?$/i',
|
||||
// '<iframe width="%%tb_width%%" height="%%tb_height%%" src="http://www.youtube.com/embed/$2" frameborder="0" allowfullscreen></iframe>',
|
||||
'<object style="float: left;margin: 10px 20px;" width="%%tb_width%%" height="%%tb_height%%"><param name="movie" value="http://www.youtube.com/v/$2?fs=1&hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/-EBs2Os9ZXw?fs=1&hl=en_US" type="application/x-shockwave-flash" width="%%tb_width%%" height="%%tb_height%%" allowscriptaccess="always" allowfullscreen="true"></embed></object>'
|
||||
)
|
||||
);
|
||||
// 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").
|
||||
|
@ -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;
|
||||
|
||||
@ -313,8 +314,13 @@
|
||||
'<a class="post_no"' . ($index?'':' onclick="citeReply(' . $this->id . ');"') . ' href="' . ($index ? $this->link('q') : 'javascript:void(0);') . '">'.$this->id.'</a>' .
|
||||
'</p>';
|
||||
|
||||
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
|
||||
if(!empty($this->file) && $this->file != 'deleted') {
|
||||
$built .= '<p class="fileinfo">File: <a href="' . $config['uri_img'] . $this->file .'">' . $this->file . '</a> <span class="unimportant">(' .
|
||||
// Filesize
|
||||
format_bytes($this->filesize) .
|
||||
@ -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,7 +447,16 @@
|
||||
public function build($index=false) {
|
||||
global $board, $config;
|
||||
|
||||
$built = '<p class="fileinfo">File: <a href="' . $config['uri_img'] . $this->file .'">' . $this->file . '</a> <span class="unimportant">(' .
|
||||
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
|
||||
'<p class="fileinfo">File: <a href="' . $config['uri_img'] . $this->file .'">' . $this->file . '</a> <span class="unimportant">(' .
|
||||
// Filesize
|
||||
format_bytes($this->filesize) .
|
||||
// File dimensions
|
||||
@ -456,6 +472,7 @@
|
||||
$built .= ', ' . $this->filename . ')</span></p>' .
|
||||
// Thumbnail
|
||||
'<a href="' . $config['uri_img'] . $this->file.'"><img src="' . $config['uri_thumb'] . $this->thumb.'" style="width:'.$this->thumbx.'px;height:'.$this->thumby.'px;" /></a>';
|
||||
}
|
||||
|
||||
$built .= '<div class="post op"><p class="intro"' . (!$index?' id="' . $this->id . '"':'') . '>';
|
||||
|
||||
|
@ -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'])) {
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
12
mod.php
12
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) . '<hr/>';
|
||||
}
|
||||
@ -1110,9 +1110,9 @@
|
||||
openBoard($report['uri']);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
$po->body .=
|
||||
@ -1926,9 +1926,9 @@
|
||||
|
||||
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) . '<hr/>';
|
||||
}
|
||||
|
30
post.php
30
post.php
@ -197,8 +197,34 @@
|
||||
if(!$OP && !threadExists($post['thread']))
|
||||
error($config['error']['nonexistant']);
|
||||
|
||||
// Check for an embed field
|
||||
if($config['enable_enbedding'] && isset($_POST['embed']) && !empty($_POST['embed'])) {
|
||||
// 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.
|
||||
$post['no_longer_require_an_image_for_op'] = true;
|
||||
}
|
||||
}
|
||||
if(!isset($post['embed'])) {
|
||||
error($config['error']['invalid_embed']);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for a file
|
||||
if($OP) {
|
||||
if($OP && !isset($post['no_longer_require_an_image_for_op'])) {
|
||||
if(!isset($_FILES['file']['tmp_name']) || empty($_FILES['file']['tmp_name']))
|
||||
error($config['error']['noimage']);
|
||||
}
|
||||
@ -208,7 +234,7 @@
|
||||
$post['email'] = utf8tohtml($_POST['email']);
|
||||
$post['body'] = $_POST['body'];
|
||||
$post['password'] = $_POST['password'];
|
||||
$post['has_file'] = $OP || (isset($_FILES['file']) && !empty($_FILES['file']['tmp_name']));
|
||||
$post['has_file'] = ($OP && !isset($post['no_longer_require_an_image_for_op'])) || (isset($_FILES['file']) && !empty($_FILES['file']['tmp_name']));
|
||||
|
||||
$post['mod'] = isset($_POST['mod']) && $_POST['mod'];
|
||||
if($post['has_file'])
|
||||
|
@ -64,6 +64,16 @@
|
||||
<input type="file" name="file"/>
|
||||
</td>
|
||||
</tr>
|
||||
{config[enable_enbedding]?
|
||||
<tr>
|
||||
<th>
|
||||
Embed
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="embed" size="30" maxlength="80" autocomplete="off" />
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
{mod?
|
||||
<tr>
|
||||
<th>
|
||||
|
@ -22,5 +22,6 @@ CREATE TABLE IF NOT EXISTS `posts_{board}` (
|
||||
`ip` varchar(45) NOT NULL,
|
||||
`sticky` int(1) NOT NULL,
|
||||
`locked` int(1) NOT NULL,
|
||||
`embed` text,
|
||||
UNIQUE KEY `id` (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
|
@ -63,6 +63,16 @@
|
||||
<input type="file" name="file"/>
|
||||
</td>
|
||||
</tr>
|
||||
{config[enable_enbedding]?
|
||||
<tr>
|
||||
<th>
|
||||
Embed
|
||||
</th>
|
||||
<td>
|
||||
<input type="text" name="embed" size="30" maxlength="80" autocomplete="off" />
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
{mod?
|
||||
<tr>
|
||||
<th>
|
||||
|
Loading…
Reference in New Issue
Block a user