TinyPortal

Development => Block Codes => Topic started by: GTS on June 21, 2006, 07:55:15 PM

Title: Last Upload Block
Post by: GTS on June 21, 2006, 07:55:15 PM
Hi there.

Since the release of the next TP version will probably still take a while, i've made a block similar to the "Last Upload" block on the left side here, myself.
It has less info as the one here, but at least i now have the latest file on my frontpage :D

The following code has to be in a phpbox:

$tp_prefix=$settings['tp_prefix'];

$request = db_query("SELECT * FROM {$tp_prefix}dlmanager WHERE type = 'dlitem' ORDER BY 'created' DESC LIMIT 1", __FILE__, __LINE__);
$row=mysql_fetch_array($request);

echo "<a href=\"?action=tpmod;dl=get". $row['id'] ."\"><img src=\"". $row['icon']."\" /></a><br />";
echo "<b><a href=\"?action=tpmod;dl=get". $row['id'] ."\">". $row['name'] ."</a></b>";
echo "<hr />";
echo "<font size=\"1\">Uploaded: <br />";
echo "<i>". timeformat($row['created']) ."</i><br />";
echo "Downloads: <b>". $row['downloads'] ."</b><br />";
echo "Views: <b>". $row['views'] ."</b><br />";
echo "</font>";


You also could change it to a "most popular file" block by simply replacing the line
$request = db_query("SELECT * FROM {$tp_prefix}dlmanager WHERE type = 'dlitem' ORDER BY 'created' DESC LIMIT 1", __FILE__, __LINE__);

with
$request = db_query("SELECT * FROM {$tp_prefix}dlmanager WHERE type = 'dlitem' ORDER BY 'downloads' DESC LIMIT 1", __FILE__, __LINE__);


And, if you don't want to link direclty to the file, but to the details page of the file, you need to replace the line:
echo "<b><a href=\"?action=tpmod;dl=get". $row['id'] ."\">". $row['name'] ."</a></b>";

with
echo "<b><a href=\"?action=tpmod;dl=item". $row['id'] ."\">". $row['name'] ."</a></b>";


You can see it in action on the page in my signature :)

Regards,

GTS

Edit: added some customizations
Title: Re: Last Upload Block
Post by: bloc on June 22, 2006, 09:50:26 AM
Nice. :)

This is pretty much how the new blocktype "modules" works too. You can have last upload, most downloaded or most viewed. Either one file or a listing. :)
Title: Re: Last Upload Block
Post by: Crip on June 22, 2006, 10:34:51 AM
That's a nifty block..php power to ya! ;)
Title: Re: Last Upload Block
Post by: stormlrd on June 22, 2006, 11:05:55 AM
Slick one of the things I want to smooth out is the download section on my forum along with a themeshop plugin hint hint :P
Title: Re: Last Upload Block
Post by: Crip on June 22, 2006, 12:03:54 PM
Quote from: StormLrd on June 22, 2006, 11:05:55 AM
Slick one of the things I want to smooth out is the download section on my forum along with a themeshop plugin hint hint :P

You will like TP_v0.9.5 - it's awesome! :up: :coolsmiley:
Title: Re: Last Upload Block
Post by: stormlrd on June 22, 2006, 12:08:18 PM
Quote from: crip on June 22, 2006, 12:03:54 PM
You will like TP_v0.9.5 - it's awesome! :up: :coolsmiley:

Yes Im enjoying it so far lol :D
Title: Re: Last Upload Block
Post by: GTS on June 22, 2006, 12:14:35 PM
Heheh, getting complimented now and then sure is nice ;)

Quote from: StormLrd on June 22, 2006, 12:08:18 PM
Quote from: crip on June 22, 2006, 12:03:54 PM
You will like TP_v0.9.5 - it's awesome! :up: :coolsmiley:

Yes Im enjoying it so far lol :D

bah, i want it too :D
Title: Re: Last Upload Block
Post by: erikman on June 22, 2006, 12:16:49 PM
Great script, GTS :D :D
Title: Re: Last Upload Block
Post by: alhaudhie on August 23, 2009, 04:53:26 PM
i try to change DESC LIMIT 1", __FILE__, __LINE__); to show 2 latests upload file.. but failed.. anybody can suggest the right way?

DESC LIMIT 2", __FILE__, __LINE__);
Title: Re: Last Upload Block
Post by: IchBin on August 23, 2009, 05:52:50 PM
If you have more than one result you need to run it through a loop.
$tp_prefix=$settings['tp_prefix'];

$request = db_query("SELECT * FROM {$tp_prefix}dlmanager WHERE type = 'dlitem' ORDER BY 'created' DESC LIMIT 2", __FILE__, __LINE__);
$rows=mysql_fetch_array($request);

foreach ($rows as $row)
{
echo "<a href=\"?action=tpmod;dl=get". $row['id'] ."\"><img src=\"". $row['icon']."\" /></a><br />";
echo "<b><a href=\"?action=tpmod;dl=get". $row['id'] ."\">". $row['name'] ."</a></b>";
echo "<hr />";
echo "<font size=\"1\">Uploaded: <br />";
echo "<i>". timeformat($row['created']) ."</i><br />";
echo "Downloads: <b>". $row['downloads'] ."</b><br />";
echo "Views: <b>". $row['views'] ."</b><br />";
echo "</font>";
}