G2IS - Update with Gallery permission + fix
Edit file: g2is.html
find:
Code: › {L_G2IS_BBCODE}<br /><select name="bbcode" onchange="toggleTextBoxes(this.selectedIndex);">{BBCODE_OPTIONS}</select>
replace with:
Code: › {L_G2IS_BBCODE}<br /><select name="bbcode" onchange="toggleTextBoxes(this);">{BBCODE_OPTIONS}</select>
Edit file: g2is.js
find:
Code: › var bbcode = (typeof(option) == 'undefined' ) ? document.getElementsByName('bbcode')[0].selectedIndex : option;
var view_resizes = ((bbcode == '2') || (bbcode == '4') || (bbcode == '5') || (bbcode == '10')) ? false : true;
replace with:
Code: › var bbcode = (typeof(option) == 'undefined' ) ? src_form.bbcode.value : option.value;
var view_resizes = ((bbcode == '0') || (bbcode == '3') || (bbcode == '6') || (bbcode == '7') || (bbcode == '8')) ? true : false;
find:
Code: › var mode = document.getElementsByName('bbcode')[0].selectedIndex;
mode = (typeof(mode) == 'undefined') ? src_form.bbcode.value : mode.toString();
replace with:
Code: › var mode = src_form.bbcode.value;
find:
Code: › item_size[0] = src_form.sizes.value;
}
after add:
Code: ›
itema = document.getElementById('_a').value;
find:
Code: › item = document.getElementById(item_id[i] + '_' + item_size[i]).value;
itemw = '&width=' + document.getElementById(item_id[i] + '_' + item_size[i] + '_w').value;
itemh = '&height=' + document.getElementById(item_id[i] + '_' + item_size[i] + '_h').value;
itema = document.getElementById(item_id[i] + '_0_a').value;
itemp = document.getElementById(item_id[i] + '_0_p').value;
replace with:
Code: ›
itemp = document.getElementById(item_id[i] + '_t_p').value;
if (document.getElementById(item_id[i] + '_' + item_size[i]))
{
item = document.getElementById(item_id[i] + '_' + item_size[i]).value;
itemw = '&width=' + document.getElementById(item_id[i] + '_' + item_size[i] + '_w').value;
itemh = '&height=' + document.getElementById(item_id[i] + '_' + item_size[i] + '_h').value;
}
Edit file: g2is.php
find:
Code: › $link_options = array(
'THUMB_LINK_IMAGE',
'THUMB_LINK_PAGE',
'THUMB_LINK_ALBUM',
'THUMB_LINK_LIGHT',
'THUMB_LINK_URL',
'THUMB_NO_LINK',
'FULL_LINK_PAGE',
'FULL_NO_LINK',
'TEXT_LINK_FULL',
'TEXT_LINK_PAGE',
'TEXT_LINK_ALBUM'
);
$link_opt_default = $link_options[0]; // prefered default link option
replace with:
Code: › $link_options = array(
'0' => 'THUMB_LINK_IMAGE',
'1' => 'THUMB_LINK_PAGE',
'2' => 'THUMB_LINK_ALBUM',
'3' => 'THUMB_LINK_LIGHT',
'4' => 'THUMB_LINK_URL',
'5' => 'THUMB_NO_LINK',
'6' => 'FULL_LINK_PAGE',
'7' => 'FULL_NO_LINK',
'8' => 'TEXT_LINK_FULL',
'9' => 'TEXT_LINK_PAGE',
'10' => 'TEXT_LINK_ALBUM'
);
$link_opt_default = 0; // prefered default link option
find:
Code: › $g2is_url = append_sid("{$phpbb_root_path}g2is.$phpEx", $form_target);
after add:
Code: › $rootAlbum_url = htmlspecialchars_decode("$g2is_url&albumId=$rootAlbumId");
find:
Code: › $itemCount = sizeof($itemIds);
// Make sure currentItem is within range
$currentItem = ($currentItem > $itemCount - 1) ? $itemCount - 1 : $currentItem;
// Display the desired items
if ($itemCount)
{
// First, determine the item limit if it exceeds the size of the item array
$sliceLimit = ($currentItem + $itemLimit > $itemCount) ? $itemCount : $currentItem + $itemLimit;
// Grab the current items of interest to be displayed on this page view
$itemIds = array_slice($itemIds, $currentItem, $sliceLimit);
$itemObjects = fetchEntities($itemIds);
// Recurse the desired items and build the display data
foreach ($itemObjects as $itemObject)
{
list($ret, $thumbnail) = GalleryCoreApi::fetchThumbnailsByItemIds(array($itemObject->getId()));
if (isset($ret))
{
trigger_error(sprintf($user->lang['G2_FETCHTHUMBSBYITEMS_FAILED'], $itemObject->getId()) . $user->lang['G2_ERROR'] . $ret->getAsHtml(), E_USER_ERROR);
}
list($ret, $resizes) = GalleryCoreApi::fetchResizesByItemIds(array($itemObject->getId()));
if (isset($ret))
{
trigger_error(sprintf($user->lang['G2_FETCHRESIZESBYITEMS_FAILED'], $itemObject->getId()) . $user->lang['G2_ERROR'] . $ret->getAsHtml(), E_USER_ERROR);
}
// Build options for the thumbnail
$index = 't';
list ($s_hidden_data, $void) = buildOptions($itemObject->getId(), $index, $thumbnail[$itemObject->getId()], $urlGenerator, false);
// Build options for the original image
$index = 0;
list ($s_hidden_data, $size_options) = buildOptions($itemObject->getId(), $index, $itemObject, $urlGenerator, true);
// Build options for the resized images
for ($i = 0, $size = sizeof($resizes); $i < $size; $i++)
{
$index++;
list ($s_hidden_data, $options) = buildOptions($itemObject->getId(), $index, $resizes[$itemObject->getId()][$i], $urlGenerator, false);
$size_options .= $options;
}
replace with:
Code: › if (sizeof($itemIds))
{
// Get item permissions
list ($ret, $acl) = GalleryCoreApi::fetchPermissionsForItems($itemIds);
if (isset($ret))
{
trigger_error(sprintf($user->lang['G2_FETCHPERMISSIONS_FAILED'], $itemObject->getId()) . $user->lang['G2_ERROR'] . $ret->getAsHtml(), E_USER_ERROR);
}
// Filter GalleryObjects
$itemObjects = array();
$GalleryItems = fetchEntities($itemIds);
foreach ($GalleryItems as $Item)
{
// PhotoItem only
if ($Item->getEntityType() == 'GalleryPhotoItem')
{
$itemObjects[] = $Item;
}
}
}
$itemCount = sizeof($itemObjects);
// Make sure currentItem is within range
$currentItem = ($currentItem > $itemCount - 1) ? $itemCount - 1 : $currentItem;
// Display the desired items
if ($itemCount)
{
// First, determine the item limit if it exceeds the size of the item array
$sliceLimit = ($currentItem + $itemLimit > $itemCount) ? $itemCount : $itemLimit;
// Grab the current items of interest to be displayed on this page view
$itemIds = array_slice($itemIds, $currentItem, $sliceLimit);
// Recurse the desired items and build the display data
foreach ($itemObjects as $itemObject)
{
$id = $itemObject->getId();
// Build options for the thumbnail
list($ret, $thumbnail) = GalleryCoreApi::fetchThumbnailsByItemIds(array($id));
if (isset($ret))
{
trigger_error(sprintf($user->lang['G2_FETCHTHUMBSBYITEMS_FAILED'], $itemObject->getId()) . $user->lang['G2_ERROR'] . $ret->getAsHtml(), E_USER_ERROR);
}
$index = 't';
list ($s_hidden_data, $void) = buildOptions($id, $index, $thumbnail[$id], $urlGenerator, true);
// Build options for the original image
$index = 0;
// Build options for the original image
if ( array_key_exists('core.viewSource', $acl[$id]) )
{
list ($s_hidden_data, $size_options) = buildOptions($id, $index, $itemObject, $urlGenerator);
}
// Build options for the resized images
if ( array_key_exists('core.viewResizes', $acl[$id]) )
{
list($ret, $resizes) = GalleryCoreApi::fetchResizesByItemIds(array($id));
if (isset($ret))
{
trigger_error(sprintf($user->lang['G2_FETCHRESIZESBYITEMS_FAILED'], $itemObject->getId()) . $user->lang['G2_ERROR'] . $ret->getAsHtml(), E_USER_ERROR);
}
$size = sizeof($resizes[$id]);
if ( $size )
{
if ( !array_key_exists('core.viewSource', $acl[$id]) )
{
$size--;
list ($s_hidden_data, $size_options) = buildOptions($id, $index, $resizes[$id][$size], $urlGenerator);
}
for ($i = 0; $i < $size; $i++)
{
$index++;
list ($s_hidden_data, $options) = buildOptions($id, $index, $resizes[$id][$i], $urlGenerator);
$size_options .= $options;
}
}
}
// Build Parent Album page link
$s_hidden_data['_a'] = $urlGenerator->generateUrl(array('itemId' => $itemObject->getParentId()), array('forceFullUrl' => true, 'forceSessionId' => false));
find:
Code: › 'ITEM_ID' => $itemObject->getId(),
replace with:
Code: › 'ITEM_ID' => $id,
find:
Code: › 'THUMB_URL' => $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $thumbnail[$itemObject->getId()]->getId()), array('forceFullUrl' => true, 'forceSessionId' => false)),
'THUMB_WIDTH' => $thumbnail[$itemObject->getId()]->getWidth(),
'THUMB_HEIGHT' => $thumbnail[$itemObject->getId()]->getHeight(),
'THUMB_LINK' => $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $itemObject->getId()), array('forceFullUrl' => true, 'forceSessionId' => false)),
replace with:
Code: › 'THUMB_URL' => $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $thumbnail[$id]->getId()), array('forceFullUrl' => true, 'forceSessionId' => false)),
'THUMB_WIDTH' => $thumbnail[$id]->getWidth(),
'THUMB_HEIGHT' => $thumbnail[$id]->getHeight(),
'THUMB_LINK' => $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $id), array('forceFullUrl' => true, 'forceSessionId' => false)),
find:
Code: › // Build bbcode link options
$index = 0;
$bbcode_options = '';
foreach ($link_options as $key)
{
$bbcode_options .= "<option value=\"$index\"";
$bbcode_options .= ($link_opt_default == $key) ? ' selected="selected">' : '>';
$bbcode_options .= $user->lang[$key] . '</option>';
$index++;
}
replace with:
Code: › // Build valid bbcode link options
$CanViewDevs = false;
foreach ($acl as $key)
{
$CanViewDevs = $CanViewDevs || $key['core.viewResizes'];
$CanViewDevs = $CanViewDevs || $key['core.viewSource'];
}
if ( !$CanViewDevs )
{
$link_options = array(
'2' => 'THUMB_LINK_ALBUM',
'4' => 'THUMB_LINK_URL',
'5' => 'THUMB_NO_LINK',
'10' => 'TEXT_LINK_ALBUM'
);
$link_opt_preferred = 2;
}
// Build bbcode link options
$bbcode_options = '';
foreach ($link_options as $key => $dat)
{
$bbcode_options .= "<option value=\"$key\"";
$bbcode_options .= ($link_opt_preferred == $key) ? ' selected="selected">' : '>';
$bbcode_options .= $lang[$dat] . '</option>';
}
find:
Code: › // Output common page data
$template->assign_vars(array(
'L_IMGSIZELIMIT' => ($config['max_post_img_width'] == 0 && $config['max_post_img_height'] == 0) ? $user->lang['G2IS_IMGUNLMTD'] : sprintf($user->lang['G2IS_IMGSIZE'], $config['max_post_img_width'], $config['max_post_img_height']),
'IN_UCP' => ($target_form == 'ucp') ? true : false,
'BBCODE_OPTIONS' => $bbcode_options,
'ROOT_COLOR' => ($currentAlbum == $rootAlbumId) ? '#00aeff' : '#696d78',
'PAGINATION' => generate_pagination($g2is_url, $itemCount, $itemLimit, $currentItem),
'PAGE_NUMBER' => on_page($itemCount, $itemLimit, $currentItem),
'TOTAL_ITEMS' => ($itemCount == 1) ? sprintf($user->lang['G2IS_ITEM'], $itemCount) : sprintf($user->lang['G2IS_ITEMS'], $itemCount),
'U_G2IS_REFRESH' => "$g2is_url&refresh=true",
'U_ROOT_ALBUM' => htmlspecialchars_decode("$g2is_url&albumId=$rootAlbumId"),
'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields, false, false, true),
'S_G2IS' => true)
);
replace with:
Code: › if ($itemCount)
{
$template->assign_vars(array(
'PAGINATION' => generate_pagination($g2is_url, $itemCount, $itemLimit, $currentItem),
'PAGE_NUMBER' => on_page($itemCount, $itemLimit, $currentItem),
'TOTAL_ITEMS' => ($itemCount == 1) ? $itemCount . ' ' . $user->lang['G2IS_ITEM'] : sprintf($user->lang['G2IS_ITEMS'], $itemCount))
);
}
else
{
// Display No Item message and jump to page generation
$template->assign_vars(array(
'TOTAL_ITEMS' => $user->lang['G2IS_NOITEM'])
);
}
// Output common page data
$template->assign_vars(array(
'L_IMGSIZELIMIT' => ($config['max_post_img_width'] == 0 && $config['max_post_img_height'] == 0) ? $user->lang['G2IS_IMGUNLMTD'] : sprintf($user->lang['G2IS_IMGSIZE'], $config['max_post_img_width'], $config['max_post_img_height']),
'IN_UCP' => ($target_form == 'ucp') ? true : false,
'BBCODE_OPTIONS' => $bbcode_options,
'ROOT_COLOR' => ($currentAlbum == $rootAlbumId) ? '#00aeff' : '#696d78',
'U_G2IS_REFRESH' => "$g2is_url&refresh=true",
'U_ROOT_ALBUM' => $rootAlbum_url,
'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields, false, false, true),
'S_G2IS' => true)
);
find:
Code: › function buildOptions($id, $index, $item, &$urlGenerator, $getRootLinks)
{
static $hidden_data = array();
$id = "_$id";
$hidden_data[$id . '_' . $index] = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $item->getId()), array('forceFullUrl' => true, 'forceSessionId' => false));
if ($getRootLinks)
{
$hidden_data[$id . '_' . $index . '_p'] = $urlGenerator->generateUrl(array('itemId' => $item->getId()), array('forceFullUrl' => true, 'forceSessionId' => false));
$hidden_data[$id . '_' . $index . '_a'] = $urlGenerator->generateUrl(array('itemId' => $item->getParentId()), array('forceFullUrl' => true, 'forceSessionId' => false));
}
$hidden_data[$id . '_' . $index . '_w'] = $item->getWidth();
$hidden_data[$id . '_' . $index . '_h'] = $item->getHeight();
$options = "<option value=\"$index\">" . $item->getWidth() . ' x ' . $item->getHeight() . '</option>';
return array($hidden_data, $options);
}
replace with:
Code: › function buildOptions($id, $index, $item, &$urlGenerator, $getRootLinks = false)
{
static $hidden_data = array();
$id = "_$id";
if ($getRootLinks)
{
$hidden_data[$id . '_' . $index . '_p'] = $urlGenerator->generateUrl(array('itemId' =>$item->getParentId()), array('forceFullUrl' => true, 'forceSessionId' => false));
}
$hidden_data[$id . '_' . $index] = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $item->getId()), array('forceFullUrl' => true, 'forceSessionId' => false));
$hidden_data[$id . '_' . $index . '_w'] = $item->getWidth();
$hidden_data[$id . '_' . $index . '_h'] = $item->getHeight();
$options = "<option value=\"$index\">" . $item->getWidth() . ' x ' . $item->getHeight() . '</option>';
return array($hidden_data, $options);
}
Note:
1. Have to add 2 entries to the language file, and add template code to display "No item" message.
2. Generate only one parent album link.
3. Move gallery page url generation for current item to thumbnail.
4. Modify function buildOptions.
5. Update g2is.js for code changes.