Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPLOAD/inc/languages/english/admin/mybbfancybox.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
$l['setting_mybbfancybox_use_separate_gallery_for_linked_images'] = 'Create a separate gallery for linked-to images?';
$l['setting_mybbfancybox_use_separate_gallery_for_linked_images_desc'] = 'YES for linked-to images (as URLs) to be placed into a separate gallery from other images (whether per-post or globally, depending on the below "Per-post gallery?" setting), NO (default) to put all images into the same gallery (again, whether per-post or global)';

$l['setting_mybbfancybox_video_filetypes'] = 'Video (or other) MIME types';
$l['setting_mybbfancybox_video_filetypes_desc'] = 'Provide, one per line, a list of attachment MIME types (as specified via MyBB\'s ACP "Attachment Types" configuration) which should be included in the FancyBox gallery as well as images. Typically, these will be video attachments.';

$l['setting_mybbfancybox_protect_images'] = 'Protect images?';
$l['setting_mybbfancybox_protect_images_desc'] = 'YES to disable right-click and use simple image protection, NO (default) to enable right-click';

Expand Down
84 changes: 84 additions & 0 deletions UPLOAD/inc/plugins/mybbfancybox.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ function mybbfancybox_install()
'optionscode' => 'yesno',
'value' => 0
),
'video_filetypes' => array(
'optionscode' => 'textarea',
'value' => ''
),
'protect_images' => array(
'optionscode' => 'yesno',
'value' => 0
Expand Down Expand Up @@ -327,6 +331,8 @@ function mybbfancybox_init()
$plugins->add_hook("parse_message_end","mybbfancybox_post");
}

$plugins->add_hook('postbit', 'mybbfancybox_postbit');

if (defined('THIS_SCRIPT') && THIS_SCRIPT == 'showthread.php') {
// Add hook
$plugins->add_hook('showthread_start', 'mybbfancybox_start');
Expand All @@ -336,6 +342,10 @@ function mybbfancybox_init()
// Add hook
$plugins->add_hook('portal_start', 'mybbfancybox_start');
}

if (defined('THIS_SCRIPT') && THIS_SCRIPT == 'attachment.php') {
$plugins->add_hook('attachment_end', 'mybbfancybox_attachment_end');
}
}

/**
Expand All @@ -360,6 +370,9 @@ function mybbfancybox_start()
// Apply required changes in postbit_attachments_thumbnails_thumbnail template (replace all content)
$templates->cache['postbit_attachments_thumbnails_thumbnail'] = '<a href="attachment.php?aid={$attachment[\'aid\']}" data-fancybox="'.$gallerystr.'" data-type="image" data-caption="<b>{$lang->postbit_attachment_filename}</b> {$attachment[\'filename\']} - <b>{$lang->postbit_attachment_size}</b> {$attachment[\'filesize\']} - <b>{$lang->mybbfancybox_uploaded}</b> {$attachdate} - <b>{$lang->mybbfancybox_views}</b> {$attachment[\'downloads\']}{$lang->mybbfancybox_views_symbol_after}"><img src="attachment.php?thumbnail={$attachment[\'aid\']}" class="attachment" alt="" title="{$lang->postbit_attachment_filename} {$attachment[\'filename\']}&#13;{$lang->postbit_attachment_size} {$attachment[\'filesize\']}&#13;{$lang->mybbfancybox_uploaded} {$attachdate}&#13;{$lang->mybbfancybox_views} {$attachment[\'downloads\']}{$lang->mybbfancybox_views_symbol_after}" /></a>&nbsp;&nbsp;&nbsp;';

// Apply required changes to support videos in the gallery (replace all content)
$templates->cache['postbit_attachments_attachment'] = '<br />{$attachment[\'icon\']}&nbsp;&nbsp;<a href="attachment.php?aid={$attachment[\'aid\']}" data-filetype="{$attachment[\'filetype\']}" target="_blank" title="{$attachdate}">{$attachment[\'filename\']}</a> ({$lang->postbit_attachment_size} {$attachment[\'filesize\']} / {$lang->postbit_attachment_downloads} {$attachment[\'downloads\']})';

// Apply required changes in postbit_attachments_images_image template (replace all content)
$templates->cache['postbit_attachments_images_image'] = '<a href="attachment.php?aid={$attachment[\'aid\']}" target="_blank" data-fancybox="'.$gallerystr.'" data-type="image" ><img src="attachment.php?aid={$attachment[\'aid\']}" class="attachment" alt="" title="{$lang->postbit_attachment_filename} {$attachment[\'filename\']}&#13;{$lang->postbit_attachment_size} {$attachment[\'filesize\']}&#13;{$lang->mybbfancybox_uploaded} {$attachdate}&#13;{$lang->mybbfancybox_views} {$attachment[\'downloads\']}{$lang->mybbfancybox_views_symbol_after}" /></a>&nbsp;&nbsp;&nbsp;';

Expand Down Expand Up @@ -442,6 +455,11 @@ function mybbfancybox_start()

$buttons = "\n\t\tbuttons: [ {$buttons} ],";

$filetypes_a = array_map('trim', explode("\n", $mybb->settings['mybbfancybox_video_filetypes']));
if ($filetypes_a) {
$video_mimetypes = '["'.implode('", "', array_map('addslashes', $filetypes_a)).'"]';
} else $video_mimetypes = '[]';

$headerinclude .= <<<EOF


Expand All @@ -450,6 +468,7 @@ function mybbfancybox_start()
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/mybbfancybox.js"></script>
<script type="text/javascript">
<!--
var video_mimetypes = {$video_mimetypes};
MyBBFancyBox.setup({
clickToEnlarge: "{$lang->mybbfancybox_click_to_enlarge}",
CLOSE: "{$lang->mybbfancybox_close}",
Expand Down Expand Up @@ -624,3 +643,68 @@ function mybbfancybox_print_peekers($peekers)

return $peekers;
}

function mybbfancybox_filename_to_mimetype($filename)
{
global $cache;
static $attachtypes = null;

if (is_null($attachtypes)) {
$attachtypes = (array)$cache->read('attachtypes');
}
$ext = get_extension(my_strtolower($filename));

return empty($attachtypes[$ext]) ? false : $attachtypes[$ext]['mimetype'];
}

function mybbfancybox_postbit(&$post)
{
global $attachcache;

// Convert the mime type stored for this attachment in the database (which
// is whatever it was uploaded as) into the mime type specified for
// attachments with this file extension in the ACP's Attachment Types
// settings module.
if (!empty($attachcache)) {
global $cache;

$attachtypes = (array)$cache->read('attachtypes');
foreach ($attachcache as &$post_attachments) {
foreach ($post_attachments as &$attachment) {
$mimetype = mybbfancybox_filename_to_mimetype($attachment['filename']);
if ($mimetype !== null) {
$attachment['filetype'] = $mimetype;
}
}
}
}
}

function mybbfancybox_attachment_end()
{
global $mybb, $uploadspath_abs, $attachment;

if (trim($mybb->settings['mybbfancybox_video_filetypes'])
&&
!isset($mybb->input['thumbnail'])
&&
file_exists($uploadspath_abs.'/'.$attachment['attachname'])
) {
$mimetype = mybbfancybox_filename_to_mimetype($attachment['filename']);
if ($mimetype === false) {
return;
}
$mimetypes = array_map('trim', explode("\n", $mybb->settings['mybbfancybox_video_filetypes']));
if (in_array($mimetype, $mimetypes)) {
header("Content-type: {$mimetype}");
header("Content-disposition: inline; filename=\"".preg_replace('([\\r\\n"])', '', $attachment['filename']).'"');
header("Content-length: {$attachment['filesize']}");
$handle = fopen($uploadspath_abs."/".$attachment['attachname'], 'rb');
while (!feof($handle)) {
echo fread($handle, 8192);
}
fclose($handle);
exit;
}
}
}
9 changes: 9 additions & 0 deletions UPLOAD/jscripts/mybbfancybox.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ var MyBBFancyBox = (function ($, m) {
}
});

for (let i = 0; i < video_mimetypes.length; i++) {
$('.post_content a[data-filetype="'+video_mimetypes[i].replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0')+'"]').each(function () {
var pid = $(this).parents('.post_content').find('.scaleimages').attr('id').split('_')[1];
var gallerystr = options.perpostgallery ? ('data-' + pid) : 'gallery';
$(this).attr('data-fancybox', gallerystr);
$(this).attr('data-options', '{"type" : "iframe", "iframe" : {"preload" : false, "css" : {"width" : "100%", "height" : "100%"}}}' );
});
}

// Load default language ENG (English)
$.fancybox.defaults.lang = 'en';
$.fancybox.defaults.i18n.en = lang;
Expand Down