SimplePortal

Customization => Blocks and Modifications => Block Requests => Topic started by: thehj on May 21, 2009, 11:20:06 AM

Title: latest attachments block with extension type limit
Post by: thehj on May 21, 2009, 11:20:06 AM
there are 2 blocks:
latest attachments
latest attached pictures

is it possible to create a block for latest attachments were you can type the extensions you want to be displayed...

for example, i want these files to be viewed in the block
.doc, .pdf, .ppt....

so when i choose "latest attachments" as the type of the block there will be a text box to insert .doc, .pdf, .ppt.....


thank you very much in advance ;D

/me edit only the Topic
Title: Re: latest attachments block --- more options :)
Post by: thehj on May 22, 2009, 01:11:25 AM
 :( :'(
Title: Re: latest attachments block --- more options :)
Post by: ???1031 on May 22, 2009, 04:43:28 AM
Please don't post within 24hour...

Require:
Simple Portal: 2.2+
SMF Version 1.1.8+

Create an PHP Block and insert this code =D.
Code: [Select]
/*
Name: Recent Attachments with Extension Limit
Author: DIN1031
Version: 1.0.0
Last updated: 22-05-09 10:45 CET

Requirements:
SMF Version: 1.1.8+
Simple Portal: 2.2+
*/

// Current Setup System

// How many attachments shoult be shown?
$parameters['limit'] = 5;
// Seperate the extenstion by , please don't forget space is a letter :P
$parameters['extensions'] = 'txt,pdf,xml,gif,xhtml,html';

/* NOW HERE START THE SCRIPT IF YOU NOT KNOW WHAT YOU DO GO NOT ON */

function sp_attachmentRecentExtenstion($parameters, $id, $return_parameters = false)
{
global $db_prefix, $modSettings, $scripturl, $txt, $settings, $user_info;

$block_parameters = array(
'limit' => 'int',
'extensions' => 'text',
);

if ($return_parameters)
return $block_parameters;

$limit = empty($parameters['limit']) ? 5 : (int) $parameters['limit'];
$extensions = empty($parameters['extensions']) ? array() : explode(',', $parameters['extensions']);
$boards = boardsAllowedTo('view_attachments');

// Standard arrays :)
$sql_extension_search = array();
$sql_extension_field = array();
if (!empty($extensions))
{
foreach ($extensions as $ext)
{
$len = strlen($ext) + 1;
if (empty($sql_extension_field[$len]))
{
$extension_length[$len] = array();
$sql_extension_field[$len] = 'RIGHT(att.filename, '. $len .') AS extenstion_' . $len;
}
$extension_length[$len][] = '.' . strtolower($ext);
}
// Okay Merge them to the serach :D
foreach ($extension_length as $len => $insert)
$sql_extension_search[] = 'RIGHT(LOWER(att.filename), '. $len .')' . (count($insert) == 1 ? ' = \'' . implode($insert) . '\'' : ' IN (\'' . implode("', '", $insert) . '\')');
}
if (empty($boards))
{
echo '
', $txt['error_sp_no_attachments_found'];
return;
}
elseif ($boards[0] == 0)
$boards = '';
else
$boards = ' AND m.ID_BOARD IN (' . implode(',', $boards) . ')';

$request = db_query("
SELECT
att.ID_ATTACH, att.ID_MSG, att.filename, IFNULL(att.size, 0) AS filesize, att.downloads, mem.ID_MEMBER,
" . (!empty($sql_extension_field) ? implode(', ', $sql_extension_field) . ', ' : '') . "
IFNULL(mem.realName, m.posterName) AS posterName, m.ID_TOPIC, m.subject, t.ID_BOARD, m.posterTime,
att.width, att.height" . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? "" : ", IFNULL(thumb.ID_ATTACH, 0) AS id_thumb, thumb.width AS thumb_width, thumb.height AS thumb_height") . "
FROM {$db_prefix}attachments AS att
INNER JOIN {$db_prefix}messages AS m ON (m.ID_MSG = att.ID_MSG)
INNER JOIN {$db_prefix}topics AS t ON (t.ID_TOPIC = m.ID_TOPIC)
LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.ID_MEMBER)" . (empty($modSettings['attachmentShowImages']) || empty($modSettings['attachmentThumbnails']) ? "" : "
LEFT JOIN {$db_prefix}attachments AS thumb ON (thumb.ID_ATTACH = att.ID_THUMB)") . "
LEFT JOIN {$db_prefix}boards AS b ON (b.ID_BOARD = t.ID_BOARD)
WHERE att.attachmentType = 0
" . (!empty($sql_extension_search) ? "AND (" . implode(' OR ', $sql_extension_search) . ")" : '') . "
AND $user_info[query_see_board]
$boards
ORDER BY att.ID_ATTACH DESC
LIMIT $limit", __FILE__, __LINE__);
$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']));

$items[$row['ID_ATTACH']] = array(
'member' => array(
'id' => $row['ID_MEMBER'],
'name' => $row['posterName'],
'link' => empty($row['ID_MEMBER']) ? $row['posterName'] : '<a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">' . $row['posterName'] . '</a>',
),
'file' => array(
'filename' => $filename,
'filesize' => round($row['filesize'] /1024, 2) . $txt['smf211'],
'downloads' => $row['downloads'],
'href' => $scripturl . '?action=dlattach;topic=' . $row['ID_TOPIC'] . '.0;attach=' . $row['ID_ATTACH'],
'link' => '<img src="' . $settings['images_url'] . '/icons/clip.gif" alt="" /> <a href="' . $scripturl . '?action=dlattach;topic=' . $row['ID_TOPIC'] . '.0;attach=' . $row['ID_ATTACH'] . '">' . $filename . '</a>',
'is_image' => !empty($row['width']) && !empty($row['height']) && !empty($modSettings['attachmentShowImages']),
),
'topic' => array(
'id' => $row['ID_TOPIC'],
'subject' => $row['subject'],
'href' => $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'],
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.msg' . $row['ID_MSG'] . '#msg' . $row['ID_MSG'] . '">' . $row['subject'] . '</a>',
'time' => timeformat($row['posterTime']),
),
);
}
mysql_free_result($request);

if (empty($items))
{
echo '
', $txt['error_sp_no_attachments_found'];
return;
}

echo '
<ul class="sp_list">';

foreach ($items as $item)
echo '
<li>', sp_embed_image('attach'), ' <a href="', $item['file']['href'], '">', $item['file']['filename'], '</a></li>
<li class="smalltext">', $txt['sp-downloadsCount'], ': ', $item['file']['downloads'], '</li>
<li class="smalltext">', $txt['sp-downloadsSize'], ': ', $item['file']['filesize'], '</li>';

echo '
</ul>';
}
sp_attachmentRecentExtenstion($parameters, $id);

Require:
Simple Portal 2.2+
SMF version 2.0RC1+

Code: [Select]
/*
Name: Recent Attachments with Extension Limit
Author: DIN1031
Version: 1.0.0
Last updated: 22-05-09 10:50 CET

Requirements:
SMF Version: 2.0RC1+
Simple Portal: 2.2+
*/

// Current Setup System

// How many attachments shoult be shown?
$parameters['limit'] = 5;
// Seperate the extenstion by , please don't forget space is a letter :P
$parameters['extensions'] = 'txt,pdf,xml,gif,xhtml,html';

/* NOW HERE START THE SCRIPT IF YOU NOT KNOW WHAT YOU DO GO NOT ON */

function sp_attachmentRecentExtenstion($parameters, $id, $return_parameters = false)
{
global $txt;

$block_parameters = array(
'limit' => 'int',
'extensions' => 'text',
);

if ($return_parameters)
return $block_parameters;

$limit = empty($parameters['limit']) ? 5 : (int) $parameters['limit'];
$extensions = empty($parameters['extensions']) ? array() : explode(',', $parameters['extensions']);

$items = ssi_recentAttachments($limit, $extensions, 'array');

if (empty($items))
{
echo '
', $txt['error_sp_no_attachments_found'];
return;
}

echo '
<ul class="sp_list">';

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>';

echo '
</ul>';
}
sp_attachmentRecentExtenstion($parameters, $id);



At the top of the code there are settings for this block ;).

Bye
DIN1031
Title: Re: latest attachments block with extension type limit
Post by: thehj on May 22, 2009, 09:22:15 AM
"Please don't post within 24hour..."
sorry :(

IT WORKS :D, thank you very very much, respect
SimplePortal 2.3.8 © 2008-2024, SimplePortal