Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: [ADDON] Template download + statistics (sNews 1.4)  (Read 9501 times)

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[ADDON] Template download + statistics (sNews 1.4)
« on: June 07, 2006, 10:54:00 am »

As asked, i make a new topic with this simple php script allowing you to protect your download directory and the possibility to have download statistics for your templates :)

1) make a new inc.mysql.php file:

Quote
$db_host = "****";
$db_user = "*****";
$db_pass = "*****";
$db_name = "*****";

/* connect to mysql */
$link = @mysql_connect($db_host, $db_user, $db_pass);

/* select database */
mysql_select_db($db_name, $link);
?>
2) Make a new download.php file:

Quote
$download_path = '/download/';
include("inc.mysql.php");

if (!empty($file)) {

  $result = mysql_query('SELECT filename FROM download');
  while ($row = mysql_fetch_assoc($result)) {
    if ($row["filename"] == $file) {
      $result = mysql_query("UPDATE download SET downloads=downloads+1 WHERE filename='" . $file . "'");
      header('Location: ' . $download_path . basename($file));
    }
  }
}
?>
3) make a new directory /download with all your zip files (templates) and chmod this directory with 511

4) Make a new table with these fields:

ID INT autoincrement
title VARCHAR(100)
filename VARCHAR(100)
downloads INT

You can add another fields for more statistic details if you want...

5) Fill this table like thits and for each template:

title "the best template of the world..."
filename "thebesttemplate.zip"
downloads 1

6) you can now use this link: your.website.com/downloads.php?file=thebesttemplate.zip

7) To show your statistics, you can play with this simple code:

Quote
$query = "SELECT * FROM download ORDER BY downloads DESC LIMIT 10";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
echo $r['title']." (".$r['downloads'].")
";
}
LIMIT 10 is only to show the top 10...;)


You can see the script in action on my website or that of Patric: http://p-ahlqvist.com/home/snews_designs/

Regards,
Avenir
Logged

mejobloggs

  • Full Member
  • ***
  • Karma: 0
  • Posts: 125
[ADDON] Template download + statistics (sNews 1.4)
« Reply #1 on: June 07, 2006, 11:21:00 pm »

WOOHOOOO

Thanks :)
Logged

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
[ADDON] Template download + statistics (sNews 1.4)
« Reply #2 on: June 08, 2006, 12:09:28 pm »

Nice little script ave :)

Code: [Select]
echo .$r['title']." (".$r['downloads'].")
";
should be

Code: [Select]
echo $r['title']." (".$r['downloads'].")
";
No dot before $r['title']  Just a little typo but it will cause an error if not removed.
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
[ADDON] Template download + statistics (sNews 1.4)
« Reply #3 on: June 08, 2006, 12:20:32 pm »

That's why it didn't work ;)....

I have my own little solution also if anyone should be interested... (I have actually made some PHP thingy's with some help from Ave.) this is made as I have not all designs in it's own article, but everyone in the same, so I can't use Ave's solution. I had to present the "top NO of downloads" with a link to either that one article or to the specific zip's of each listed object, I chose the latter. And here's how I did it:

First I made a little addition to the global settings in the snews.php:
Code: [Select]
$s['websitedownload'] = "http://url.com/download.php?file="; // Website url for download - Edit the link to your zip locationThen I added this in the index file code:
Code: [Select]
$query = "SELECT * FROM download ORDER BY downloads DESC LIMIT 5";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
echo "".$r['title']."     (".$r['downloads'].")
";
}
?>
So, this makes the top 5 downloads names listed on my frontpage, and if clicking you get the download link directly... I'm trying to connect a hover effect to these links aswell, so that you see a thumb of each design upon hovering before you click the download link .... But we'll see if that's possible as I'm no PHP guru, so to speak :)

Patric.

PS. See Luka... I did something in PHP, erhm :) DS.
Logged
"It's only dead fish that goes with the flow... "
Updated

Luka

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 36
  • Posts: 1717
    • http://www.snewscms.com
[ADDON] Template download + statistics (sNews 1.4)
« Reply #4 on: June 08, 2006, 12:24:07 pm »

Quote from: Patric
PS. See Luka... I did something in PHP, erhm :) DS.
Told ya I'll loose my job hehe :)
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4867
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
[ADDON] Template download + statistics (sNews 1.4)
« Reply #5 on: June 08, 2006, 01:05:17 pm »

Yea, right :) I'm right there behind you now... Keep a lookout ;)
Logged
"It's only dead fish that goes with the flow... "
Updated

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[ADDON] Template download + statistics (sNews 1.4)
« Reply #6 on: June 08, 2006, 01:16:07 pm »

Quote from: brauck
Nice little script ave :)

Code: [Select]
echo .$r['title']." (".$r['downloads'].")
";
should be

Code: [Select]
echo $r['title']." (".$r['downloads'].")
";
No dot before $r['title']  Just a little typo but it will cause an error if not removed.
thanks Brauck, i modified the first post :)
Logged

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
[ADDON] Template download + statistics (sNews 1.4)
« Reply #7 on: June 08, 2006, 11:08:39 pm »

Welcome, ave
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[ADDON] Template download + statistics (sNews 1.4)
« Reply #8 on: June 09, 2006, 11:50:23 am »

somebody knows how can i change

ht.tp://www.free-css-templates.com/download.php?file=template.zip

to

ht.tp://www.free-css-templates.com/template/
or
ht.tp://www.free-css-templates.com/template.zip

with the .htaccess file?

Thanks in advance for your help,
Avenir
Logged

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
[ADDON] Template download + statistics (sNews 1.4)
« Reply #9 on: June 09, 2006, 01:34:00 pm »

Sorry ave, no htaccess expertise here :(
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
[ADDON] Template download + statistics (sNews 1.4)
« Reply #10 on: June 09, 2006, 10:52:02 pm »

Hi Avenir!
Try with this code in your .htaccess file:
For the first case "ht.tp://www.free-css-templates.com/template/":
Code: [Select]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule  ^template/(.*)$  download.php?file=$1  [L]
For the second case "ht.tp://www.free-css-templates.com/template.zip":
Code: [Select]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule  ^(.*)$  download.php?file=$1  [L]
bram.

Quote from: avenir
somebody knows how can i change
ht.tp://www.free-css-templates.com/download.php?file=template.zip
to
ht.tp://www.free-css-templates.com/template/
or
ht.tp://www.free-css-templates.com/template.zip
with the .htaccess file?
Thanks in advance for your help,
Avenir
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Español

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[ADDON] Template download + statistics (sNews 1.4)
« Reply #11 on: June 10, 2006, 12:18:06 am »

thanks Bram for your help!

I tried that but when i click on an article, i have a blank page and i don't understand why...if you have another idea...thanks;)
Logged

bramsyuur

  • Hero Member
  • *****
  • Karma: 23
  • Posts: 873
    • http://snews.vietbee.net
[ADDON] Template download + statistics (sNews 1.4)
« Reply #12 on: June 10, 2006, 12:47:43 am »

Hi, again! :D
Sorry, try with this one:
Code: [Select]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^template/([^/\.]+)/?$ download.php?file=$1 [L]
Or...
Code: [Select]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ download.php?file=$1 [L]
bram.

Quote from: avenir
thanks Bram for your help!

I tried that but when i click on an article, i have a blank page and i don't understand why...if you have another idea...thanks;)
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Español

David

  • Hero Member
  • *****
  • Karma: 7
  • Posts: 567
[ADDON] Template download + statistics (sNews 1.4)
« Reply #13 on: June 10, 2006, 01:38:15 am »

sorry Bram but it doesn't works...perhaps because of the download script...i don't know...but it is not a serious problem…don't break your brain with that ;)

Thanks for your help!
Avenir
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
[ADDON] Template download + statistics (sNews 1.4)
« Reply #14 on: June 10, 2006, 06:00:32 am »

Quote
somebody knows how can i change
   ht.tp://www.free-css-templates.com/download.php?file=template.zip
   to
   ht.tp://www.free-css-templates.com/template/
   or
   ht.tp://www.free-css-templates.com/template.zip
with the .htaccess file?
avenir First, make sure you remove the dot between ht and tp at the beginning of the URLs. All URLs must begin with http://........

Question: Aside from this url, are all your site's urls currently displaying without the ?file= ? If not, then open your .htaccess file. Try setting the top lines to look like this:
Quote
#
#   php_value session.use_trans_sid 0
#


RewriteEngine On
RewriteBase /---------/
and replace the ---------- with the name of the directory containing your sNews site's files and folders.

If you have already done this, then I have no other solution at this point.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU
Pages: [1] 2