collapse collapse

* Simple Portal Archived Forum

This is an Archive Forum.

The content in this forum may be out-of-date or have been superseded by newer information, and links in forum pages to other sites may not work.
This forum contains archives for future reference.

Visit our thread at Simple Machines Forum for current support.

* User Info

 
 
Welcome, Guest. Please login or register.

* Who's Online

  • Dot Guests: 218
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.

* Shoutbox

Refresh History
  • Shoutbox is not for support!
  • {OCS}MasterSeal: Yup, Still adore SP
    April 21, 2019, 07:08:06 PM
  • {OCS}MasterSeal: STILL love SP :)
    November 24, 2018, 05:05:50 AM
  • ♦ Ninja ZX-10RR ♦: <3 aegersz
    September 13, 2018, 03:36:09 PM
  • aegersz: I STILL <3 LOVE SimplePortal
    September 13, 2018, 07:11:39 AM
  • aegersz: o LOVE you guys - Simple Portal rocks !
    May 09, 2018, 05:18:59 AM
  • Chen Zhen: our apologies for the site being down.. please read server issues topic
    March 22, 2018, 05:32:38 AM
  • {OCS}MasterSeal: LOL PLEASE forget I just posted that. I found the answer in my own dang post back in 2015. lol sorry!
    July 04, 2017, 10:47:55 PM
  • {OCS}MasterSeal: I know this SB isnt' for support, but I just have a general question. Who would I contact to find out where SP stores its block info? Is it DB driven or files? I searched the site but came up with nothing. probably my fault any insight is appreciated.
    July 04, 2017, 10:43:36 PM
  • ♦ Ninja ZX-10RR ♦: Excuse me but what does Simpleportal have to deal with that?
    February 05, 2017, 08:21:14 PM
  • WhiteEagle: of course IMHO that site appears to be dead :(
    February 04, 2017, 01:08:05 PM
  • WhiteEagle: If I can get that, then I'll use it for that site...
    February 04, 2017, 01:07:35 PM
  • WhiteEagle: decided to not use SMF for any projects, unless I can get a copy of the premium version of the fanfiction archive plugin
    February 04, 2017, 01:06:54 PM
  • expertdecisions: cloudflare
    January 28, 2017, 08:01:47 AM
  • aegersz: SM release 2.0.13 !
    January 12, 2017, 06:00:13 AM
  • raffo: Tks Emanuele, even if I didn't understand the fix :D
    November 07, 2016, 02:01:20 AM
  • emanuele: [link]
    November 01, 2016, 12:43:50 PM
  • emanuele: raffo: the English support board is a good place. ;)
    November 01, 2016, 12:43:38 PM
  • raffo: Where can I find the fix for the shoutbox?
    November 01, 2016, 05:06:09 AM
  • {OCS}MasterSeal: To the SP team, I make a point to come here and thank you as much as possible for your work.  so again, THANK YOU!
    October 28, 2016, 10:38:05 AM
  • emanuele: That's indeed funny, the limit is present only in the patch and not the full install.
    October 22, 2016, 06:14:58 PM

* Recent Posts

Adding Forums Button to Nav bar by jirapon
[August 01, 2019, 09:07:12 AM]


Re: Board Icons by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 04:03:41 PM]


MOVED: Czech translation???? by ♦ Ninja ZX-10RR ♦
[July 30, 2019, 03:04:51 PM]


Board Icons by jirapon
[July 30, 2019, 07:28:44 AM]


Re: Thankyou Simpleportal, by ♦ Ninja ZX-10RR ♦
[July 29, 2019, 09:41:29 AM]

NEED HELP? If you're looking for support with Simple Portal, look no further than the Support Board!

Author Topic: latest attachments block with extension type limit  (Read 2095 times)

0 Members and 1 Guest are viewing this topic.

Offline thehj

  • Semi Newbie
  • *
  • Posts: 21
  • SMF Version: 2 RC1-1
  • SP Version: 2.2.2
latest attachments block with extension type limit
« 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

* ディン1031 edit only the Topic
« Last Edit: May 22, 2009, 04:45:41 AM by ディン1031 »

Offline thehj

  • Semi Newbie
  • *
  • Posts: 21
  • SMF Version: 2 RC1-1
  • SP Version: 2.2.2
Re: latest attachments block --- more options :)
« Reply #1 on: May 22, 2009, 01:11:25 AM »
 :( :'(

Offline ディン1031

  • ... feel not as a dev at the moment ...
  • Comrade
  • *
  • Posts: 789
  • Gender: Male
  • Overworked <<
  • SMF Version: None
  • SP Version: None
Re: latest attachments block --- more options :)
« Reply #2 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('~&amp;#(\\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
« Last Edit: May 22, 2009, 04:52:29 AM by ディン1031 »
Again... I'm having time problems...

Normal Monday to Friday I'm at office from 6:00-16:00 (On my local time ;P).

Offline thehj

  • Semi Newbie
  • *
  • Posts: 21
  • SMF Version: 2 RC1-1
  • SP Version: 2.2.2
Re: latest attachments block with extension type limit
« Reply #3 on: May 22, 2009, 09:22:15 AM »
"Please don't post within 24hour..."
sorry :(

IT WORKS :D, thank you very very much, respect