Skip to content

Commit

Permalink
Adding new ACP settings (#48)
Browse files Browse the repository at this point in the history
* Adding new ACP settings

* ACP settings - uninstall procedure for new settings

* For #48

* JS For New Settings

...replace individual settings with serialized multiple select.
  • Loading branch information
Eldenroot committed Mar 15, 2019
1 parent 05b8288 commit 7230ede
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 27 deletions.
36 changes: 35 additions & 1 deletion inc/languages/english/admin/mybbfancybox.lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
*/

// Plugin page (name + plugin description)
$l['mybbfancybox'] = 'MyBB Fancybox';
$l['mybbfancybox_description'] = 'FancyBox JavaScript library for presenting images in a fancy way. Fully responsive, touch-enabled and customizable.';

Expand All @@ -22,4 +23,37 @@
$l['mybbfancybox_open_image_urls_description'] = 'YES (default) to automatically detect links to images in posts and enable them to be viewed in the MyBB Fancybox modal, NO to disable';

$l['mybbfancybox_allowed_extensions_title'] = 'Allowed image extensions';
$l['mybbfancybox_allowed_extensions_description'] = 'Leave blank (default) to use the default image extensions (.jpg, .gif, .png, .jpeg, .bmp, .apng) or enter a comma separated list of extensions to allow.<br />(This setting has no affect if the above setting is set to NO)';
$l['mybbfancybox_allowed_extensions_description'] = 'Leave blank (default) to use the default image extensions (.jpg, .gif, .png, .jpeg, .bmp, .apng) or enter a comma separated list of extensions to allow.<br />(This setting has no affect if the above setting is set to NO)';

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

$l['mybbfancybox_watermark_title'] = 'Display watermark in images?';
$l['mybbfancybox_watermark_description'] = 'YES to enable displaying a watermark in images (CSS class .watermark in mybbfancybox.css stylesheet is used), NO (default) to disable';

$l['mybbfancybox_watermark_exclude_low_resolution_images_title'] = 'Do not display watermark in small resolution images?';
$l['mybbfancybox_watermark_exclude_low_resolution_images_description'] = 'YES (default) to not add watermark into small resolution images, NO to disable';

$l['mybbfancybox_loop_title'] = 'Enable infinite gallery navigation?';
$l['mybbfancybox_loop_description'] = 'YES (default) to enable infinite navigation between images in gallery, NO to disable';

$l['mybbfancybox_infobar_title'] = 'Display image counter?';
$l['mybbfancybox_infobar_description'] = 'YES (default) to display image counter in the top left corner, NO to hide';

$l['mybbfancybox_arrows_title'] = 'Display arrows for navigation?';
$l['mybbfancybox_arrows_description'] = 'YES (default) to display arrows at the screen edges for simple navigation between images, NO to hide';

$l['mybbfancybox_thumbs_title'] = 'Display thumbnails sidebox?';
$l['mybbfancybox_thumbs_description'] = 'YES to automatically display thumbnails sidebox, NO (default) to hide';

// Buttons
$l['mybbfancybox_buttons_title'] = 'Button Selection';
$l['mybbfancybox_buttons_description'] = 'Only selected buttons will display in the MyBB Fancybox modal';

$l['mybbfancybox_button_slideshow_title'] = 'Slideshow';
$l['mybbfancybox_button_fullscreen_title'] = 'Full Screen';
$l['mybbfancybox_button_thumbs_title'] = 'Thumbnails';
$l['mybbfancybox_button_share_title'] = 'Share';
$l['mybbfancybox_button_download_title'] = 'Download';
$l['mybbfancybox_button_zoom_title'] = 'Zoom';
$l['mybbfancybox_button_close_title'] = 'Close';
159 changes: 156 additions & 3 deletions inc/plugins/mybbfancybox.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ function mybbfancybox_install()
);
$db->insert_query('settinggroups', $setting_group);
$gid = (int) $db->insert_id();


// Open image URLs settings
$mybbfancybox_setting = array(
'name' => 'mybbfancybox_open_image_urls',
'title' => $lang->mybbfancybox_open_image_urls_title,
Expand All @@ -151,6 +152,113 @@ function mybbfancybox_install()
'gid' => $gid
);
$db->insert_query('settings', $mybbfancybox_setting);

// FancyBox basic settings - lines #37-48 in mybbfancybox.js in /jscripts folder
$mybbfancybox_setting = array(
'name' => 'mybbfancybox_protect_images',
'title' => $lang->mybbfancybox_protect_images_title,
'description' => $lang->mybbfancybox_protect_images_description,
'optionscode' => 'yesno', // false or true value
'value' => '0',
'disporder' => '3',
'gid' => $gid
);
$db->insert_query('settings', $mybbfancybox_setting);

$mybbfancybox_setting = array(
'name' => 'mybbfancybox_watermark',
'title' => $lang->mybbfancybox_watermark_title,
'description' => $lang->mybbfancybox_watermark_description,
'optionscode' => 'yesno', // CSS class watermark or leave blank to disable
'value' => '0',
'disporder' => '4',
'gid' => $gid
);
$db->insert_query('settings', $mybbfancybox_setting);

$mybbfancybox_setting = array(
'name' => 'mybbfancybox_watermark_exclude_low_resolution_images',
'title' => $lang->mybbfancybox_watermark_exclude_low_resolution_images_title,
'description' => $lang->mybbfancybox_watermark_exclude_low_resolution_images_description,
'optionscode' => 'yesno', // This will be coded later, I have a working code but must be implemented into FancyBox JS file - need to test first
'value' => '1',
'disporder' => '5',
'gid' => $gid
);
$db->insert_query('settings', $mybbfancybox_setting);

$mybbfancybox_setting = array(
'name' => 'mybbfancybox_loop',
'title' => $lang->mybbfancybox_loop_title,
'description' => $lang->mybbfancybox_loop_description,
'optionscode' => 'yesno', // false or true value
'value' => '1',
'disporder' => '6',
'gid' => $gid
);
$db->insert_query('settings', $mybbfancybox_setting);

$mybbfancybox_setting = array(
'name' => 'mybbfancybox_infobar',
'title' => $lang->mybbfancybox_infobar_title,
'description' => $lang->mybbfancybox_infobar_description,
'optionscode' => 'yesno', // false or true value
'value' => '1',
'disporder' => '7',
'gid' => $gid
);
$db->insert_query('settings', $mybbfancybox_setting);

$mybbfancybox_setting = array(
'name' => 'mybbfancybox_arrows',
'title' => $lang->mybbfancybox_arrows_title,
'description' => $lang->mybbfancybox_arrows_description,
'optionscode' => 'yesno', // false or true value
'value' => '1',
'disporder' => '8',
'gid' => $gid
);
$db->insert_query('settings', $mybbfancybox_setting);

$mybbfancybox_setting = array(
'name' => 'mybbfancybox_thumbs',
'title' => $lang->mybbfancybox_thumbs_title,
'description' => $lang->mybbfancybox_thumbs_description,
'optionscode' => 'yesno', // false or true value
'value' => '0',
'disporder' => '9',
'gid' => $gid
);
$db->insert_query('settings', $mybbfancybox_setting);

$buttonSetting = <<<EOF
php
<select multiple name=\"upsetting[mybbfancybox_buttons][]\" size=\"7\">
<option value=\"slideShow\" ".(is_array(unserialize(\$setting['value'])) ? (\$setting['value'] != "" && in_array("slideShow", unserialize(\$setting['value'])) ? "selected=\"selected\"":""):"").">{$lang->mybbfancybox_button_slideshow_title}</option>
<option value=\"fullScreen\" ".(is_array(unserialize(\$setting['value'])) ? (\$setting['value'] != "" && in_array("fullScreen", unserialize(\$setting['value'])) ? "selected=\"selected\"":""):"").">{$lang->mybbfancybox_button_fullscreen_title}</option>
<option value=\"thumbs\" ".(is_array(unserialize(\$setting['value'])) ? (\$setting['value'] != "" && in_array("thumbs", unserialize(\$setting['value'])) ? "selected=\"selected\"":""):"").">{$lang->mybbfancybox_button_thumbs_title}</option>
<option value=\"share\" ".(is_array(unserialize(\$setting['value'])) ? (\$setting['value'] != "" && in_array("share", unserialize(\$setting['value'])) ? "selected=\"selected\"":""):"").">{$lang->mybbfancybox_button_share_title}</option>
<option value=\"download\" ".(is_array(unserialize(\$setting['value'])) ? (\$setting['value'] != "" && in_array("download", unserialize(\$setting['value'])) ? "selected=\"selected\"":""):"").">{$lang->mybbfancybox_button_download_title}</option>
<option value=\"zoom\" ".(is_array(unserialize(\$setting['value'])) ? (\$setting['value'] != "" && in_array("zoom", unserialize(\$setting['value'])) ? "selected=\"selected\"":""):"").">{$lang->mybbfancybox_button_zoom_title}</option>
<option value=\"close\" ".(is_array(unserialize(\$setting['value'])) ? (\$setting['value'] != "" && in_array("close", unserialize(\$setting['value'])) ? "selected=\"selected\"":""):"").">{$lang->mybbfancybox_button_close_title}</option>
</select>
EOF;

// Settings for buttons - lines #50-58 in mybbfancybox.js in /jscripts folder
$mybbfancybox_setting = array(
'name' => 'mybbfancybox_buttons',
'title' => $lang->mybbfancybox_buttons_title,
'description' => $lang->mybbfancybox_buttons_description,
'optionscode' => $db->escape_string($buttonSetting),
'value' => $db->escape_string(serialize(array('slideShow', 'fullScreen', 'thumbs', 'share', 'download', 'zoom', 'close'))),
'disporder' => '10',
'gid' => $gid
);
$db->insert_query('settings', $mybbfancybox_setting);

// Rebuild settings
rebuild_settings();
}

// Plugin uninstallation
Expand All @@ -177,7 +285,7 @@ function mybbfancybox_uninstall()
update_theme_stylesheet_list(1, false, true);

// Delete plugin settings in ACP
$db->write_query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('mybbfancybox_open_image_urls','mybbfancybox_allowed_extensions')");
$db->write_query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('mybbfancybox_open_image_urls','mybbfancybox_allowed_extensions','mybbfancybox_protect_images','mybbfancybox_watermark','mybbfancybox_watermark_exclude_low_resolution_images','mybbfancybox_loop','mybbfancybox_infobar','mybbfancybox_arrows','mybbfancybox_thumbs','mybbfancybox_buttons')");
$db->write_query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name = 'mybbfancybox'");

// Rebuild settings
Expand All @@ -190,6 +298,10 @@ function mybbfancybox_init()
{
global $mybb, $plugins;

if (defined('IN_ADMINCP')) {
$plugins->add_hook('admin_config_settings_change', 'mybbfancybox_admin_config_settings_change');
}

// Open image URL link in posts
// Check ACP settings
if ($mybb->settings['mybbfancybox_open_image_urls'] == '1') {
Expand Down Expand Up @@ -217,6 +329,31 @@ function mybbfancybox_showthread_start()
// Apply required changes in postbit_attachments_images_image template (replace all content)
$templates->cache['postbit_attachments_images_image'] = '<a target="_blank" data-fancybox="data-{$attachment[\'pid\']}" 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;';

$watermark = '';
if ($mybb->settings['mybbfancybox_watermark']) {
$watermark = 'watermark';
}

foreach (array(
//'mybbfancybox_watermark_exclude_low_resolution_images' => '?',
'mybbfancybox_protect_images' => 'protect',
'mybbfancybox_loop' => 'loop',
'mybbfancybox_infobar' => 'infobar',
'mybbfancybox_arrows' => 'arrows',
'mybbfancybox_thumbs' => 'thumbs',
) as $key => $var) {
$$var = $mybb->settings[$key] ? 'true' : 'false';
}

$buttonArray = (array) unserialize($mybb->settings['mybbfancybox_buttons']);

if (!empty($buttonArray) &&
count($buttonArray) > 0) {
$buttons = "'".implode("','", $buttonArray)."'";
}

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

$headerinclude .= <<<EOF
Expand All @@ -238,6 +375,13 @@ function mybbfancybox_showthread_start()
DOWNLOAD: "{$lang->mybbfancybox_download}",
SHARE: "{$lang->mybbfancybox_share}",
ZOOM: "{$lang->mybbfancybox_zoom}",
}, {
protect: {$protect},
slideClass: "{$watermark}",
loop: {$loop},
infobar: {$infobar},
arrows: {$arrows},
thumbs: {$thumbs},{$buttons}
});
// -->
</script>
Expand Down Expand Up @@ -305,4 +449,13 @@ function mybbfancybox_post($message)

$message = preg_replace($find, $replace, $message);
return $message;
}
}

function mybbfancybox_admin_config_settings_change()
{
global $mybb;

if (isset($mybb->input['upsetting']['mybbfancybox_open_image_urls'])) {
$mybb->input['upsetting']['mybbfancybox_buttons'] = serialize($mybb->input['upsetting']['mybbfancybox_buttons']);
}
}
47 changes: 24 additions & 23 deletions jscripts/mybbfancybox.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,27 @@ var MyBBFancybox = (function($, m) {
DOWNLOAD: 'Download',
SHARE: 'Share',
ZOOM: 'Zoom',
},
options = {
slideClass: '',
loop: true,
protect: false,
keyboard: true,
arrows: true,
infobar: true,
thumbs: {
autoStart: false,
hideOnClose: true,
},
buttons: [
'slideShow',
'fullScreen',
'thumbs',
'share',
'download',
'zoom',
'close',
],
};

/**
Expand All @@ -35,37 +56,17 @@ var MyBBFancybox = (function($, m) {
$.fancybox.defaults.i18n.en = lang;

// FancyBox default settings
$('[data-fancybox]').fancybox({
slideClass : '', // Watermark CSS class (leave empty or use "watermark" CSS class)
loop : true, // Enable infinite gallery navigation
protect: false, // Disable right-click and use simple image protection for images
keyboard: true, // Enable keyboard navigation
arrows: true, // Display navigation arrows at the screen edges
infobar: true, // Should display counter at the top left corner
thumbs : { // Thumbnails sidebox option
autoStart : false, // Show or hide sidebar with thumbnails of images
hideOnClose : true, // Automatically hide thumbnails box on close
},

buttons : [ //Buttons displayed in FancyBox - to hide any of them just comment them out
'slideShow', // Slideshow button
'fullScreen', // Full screen button
'thumbs', // Thumbnails button
'share', // Share button
'download', // Download button
'zoom', // Zoom button
'close' // Close button
]
});
$('[data-fancybox]').fancybox(options);
}

/**
* setup localization
*
* @return void
*/
function setup(l) {
function setup(l, o) {
$.extend(lang, l || {});
$.extend(options, o || {});
}

m.setup = setup;
Expand Down

0 comments on commit 7230ede

Please sign in to comment.