SimplePortal

Customization => Custom Coding => Topic started by: comatose on May 13, 2009, 09:14:02 PM

Title: Picture Titles on Gallery or Attachment Blocks
Post by: comatose on May 13, 2009, 09:14:02 PM
Basically if the name is too long, the title breaks the block (i notice in the gallery and attachment blocks), there should be some restriction to the name size, like it would cut it off at a certain number of characters, like instead of:

"This is an Amazing Awesome Picture That Everyone Will Enjoy" it would be "This is an Amazing Aweso..." or "dfp3iohpi234ri34fb34pfb34bf34fi3bif43pfb34" it would be "dfp3iohpi234ri34fb34pfb..."

i know this isnt exactly a bug, but whatever the users do, it shouldnt break the block and in my case its constantly broken, this is especially bad with attachments since most users don't really care about the name of the file, thank you.
Title: Re: Picture Titles on Gallery or Attachment Blocks
Post by: ???1031 on May 14, 2009, 05:13:54 AM
Which SP Version and SMF Version do you use?
SPortal1-1.php
Search for
Code: [Select]
$items = array();
while ($row = mysql_fetch_assoc($request))
{
$filename = preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($row['filename']));
Replace with
Code: [Select]
$items = array();
$currentMaxLength = 20;
while ($row = mysql_fetch_assoc($request))
{
$filename = $row['filename'];
if(strlen($filename) > $currentMaxLength)
$filename = substr($filename, $currentMaxLength) . '...';
$filename = preg_replace('~&#(\\d{1,7}|x[0-9a-fA-F]{1,6});~', '&#\\1;', htmlspecialchars($filename));

Or
SPortal2.php
Search for
Code: [Select]
foreach ($items as $item)
echo '
<li>', sp_embed_image('attach'), ' <a href="', $item['file']['href'], '">', $item['file']['filename'], '</a></li>
<li class="smalltext">', $txt['downloads'], ': ', $item['file']['downloads'], '</li>
<li class="smalltext">', $txt['filesize'], ': ', $item['file']['filesize'], '</li>';
Replace with
Code: [Select]
$currentMaxLength = 20;
foreach ($items as $item)
{
if(strlen($item['file']['filename']) > $currentMaxLength)
$item['file']['filename'] = substr($item['file']['filename'], $currentMaxLength) . '...';
echo '
<li>', sp_embed_image('attach'), ' <a href="', $item['file']['href'], '">', $item['file']['filename'], '</a></li>
<li class="smalltext">', $txt['downloads'], ': ', $item['file']['downloads'], '</li>
<li class="smalltext">', $txt['filesize'], ': ', $item['file']['filesize'], '</li>';
}
Search for
Code: [Select]
foreach ($items as $item)
{
  echo !$direction ? '
<tr>' : '', '
<td>
<div class="sp_image smalltext">
<a href="', $item['file']['href'], '">', $item['file']['filename'], '</a><br />
Replace with
Code: [Select]
$currentMaxLength = 20;
foreach ($items as $item)
{
if(strlen($item['file']['filename']) > $currentMaxLength)
$item['file']['filename'] = substr($item['file']['filename'], $currentMaxLength) . '...';
  echo !$direction ? '
<tr>' : '', '
<td>
<div class="sp_image smalltext">
<a href="', $item['file']['href'], '">', $item['file']['filename'], '</a><br />

It's untested ;) so use on own risk
SimplePortal 2.3.8 © 2008-2024, SimplePortal