WP Plugin: Download Count

Nå har jeg lagd mitt første komplette frittstående plugin til Wordpress. Hva den gjør? Den lar deg opprette linker til filer og holde rede på hvor mange ganger noen har trykt på linken. Pluginet kommer med en engelsk readme foreløpig. Etterhvert kommer jeg nok til å oversette readme til norsk også, men til da får det holde med engelsk. Nedenfor finner du denne readme-en. Om noen spørsmål skulle dukke opp, bruk e-post eller kommentarfeltene.

Download wp-dlCount-plugin.zip
Lastet ned 1081 ganger.

Wp-dlCount Screenshot

Wp-dlCount Screenshot

English readme

VERSION

This version is the first of this plugin. It's running on my own blog, and has been tested for some days. The version running is 0.9.5.

REQUIREMENTS

There are no special requirements, except for running WordPress and you have to be able to create two tables in the wordpress-database. The two tables are written down below.

The plugin uses the wordpress-database, but you'll have to create the tables yourself. You'll need two of them. One to contain the files, and the other to count the downloads and som statistics. Their names are: wp_dlcount and wp_dlfile, relativly with what your table_prefix in wordpress is!

SQL-Queries:

  1. CREATE TABLE `wp_dlcount` (
  2. `TIME` INT(10) NOT NULL,
  3. `file` VARCHAR(40) character SET utf8 collate utf8_unicode_ci NOT NULL,
  4. PRIMARY KEY  (`TIME`)
  5. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  6.  
  7. CREATE TABLE `wp_dlfile` (
  8. `hashed` VARCHAR(40) collate utf8_unicode_ci NOT NULL,
  9. `filename` VARCHAR(255) collate utf8_unicode_ci NOT NULL,
  10. PRIMARY KEY  (`hashed`)
  11. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

So, that's all the creating you need actually, except copying the files over to the plugin directory.

INSTALLING

So after you have created the those two tables in your wordpress-database, you would also need to copy the files into your plugin dir, and activate it in your wp-admin-panel.

* Copy the whole download_count directory into /wp-content/plugins/

Now you can see under Options in the adminpanel, a link called Download Count. Press it and get a page up. There will be no list there at this point, since no files are added. This will come under USAGE.

USAGE

Now we will go through how to add files, and where to put the files.

There are three "codes" to use with this plugin. One to make link to a file and add the file to the database, one other to show how many is downloaded, and the last one to see a list of downloadable files with statistics.

WARNING: ALL these "codes" must be used within a post.

Syntax:
CODE-SYNTAX => Description

[ link:FILE] => Add file and get the link.
[ print_dl_list] => Get the list of all files, and the count
[ downloaded:FILE] => Get the count of downloaded-times.

(Note: No space between [ and the rest. Just to avoid the plugin to kick in, on this page.)

!!IMPORTANT!!
Now, there are two ways to do it with the download path:
#1 Have a static folder witch has all your downloadable files. And use only the basename of the file in both syntaxes.
#2 Set the $filedir IN THE CONSTRUCTOR of dlCount-plugin.php to this:
$this->filedir = '';
Now you have no static folder and can write your own path. Like this: [ link:./my/path/file.zip]

WARNING: If you're using method #2, you will get an error if you
have only / first, with no "." before it. So please do use ./ if you
use something at all.

EXAMPLE OF USAGE

My file email.zip has been downloaded [ downloaded:email.zip] times.
You can also download it:
[ link:email.zip]

Here is all my files, available for download:
[ print_dl_list]

COPYRIGHT NOTICE

This plugin is written by Mikael Brevik, and all rights are reserved for me, and me only! If you wish to edit this script, you should contanct
me, the author, at: mikaelb@mikaelb.net.

If you want to link back to my site (http://mikaelb.net) that's cool with me.

Have a fine day!

15 responser om “WP Plugin: Download Count”

  1. Ser bra ut, har dog ikke fått testet det ut enda.

    Men er det lov å spørre hvilken syntax highlight plugin du bruker?


  2. Hepp!

    Det kan du selvfølgelig gjøre...
    Foreløpig bruker jeg iG:Syntax Hiliter Plugin, men spørs om jeg kommer til å lage min egen en dag. Noe jeg ikke liker helt ved highlightern. Blant annet at instillingene resetter seg hele tiden.


  3. you say it only works in posts... does it work with pages? all my filles are set up in pages.


  4. Hey!

    Yes, it also works in pages. All input submittet by post or pages.


  5. dude it is a good plugin
    but in my wordpress it doesnt work!!!
    i did what you said above all the thing
    i have a static dir.
    but it doesnt work!!
    it says there is not such a file but it is?
    i cant undertake the situation dude??


  6. An e-mail is sent, and we'll find a answare for this.
    Two possible errors:
    - Wrong path.
    - MySQL error.


  7. Merk at det ikke skal være noe mellomrom imellom første hakeparentes ( [ ) som det er vist i Readme.txt og guiden her:

    [ link:FILE] => Add file and get the link.
    [ print_dl_list] => Get the list of all files, and the count
    [ downloaded:FILE] => Get the count of downloaded-times.

    Fant ikke feilen med en gang, men det var jo selvsagt logisk at det ikke skal finnes noe mellomrom.

    English: Notice that's there's not supposed to be any space between the first [ and the rest of the code-syntax.


  8. Vell, det burde kanskje vært nevnt at det ikke skal være noe mellomrom nei. Det ble skrevet i bloggen for å unngå at plugin skal slå seg inn. Men, ja. Kan føre opp det i teksten nå.


  9. [...] Visit [...]


  10. Hi, I'm having the same problem as BlueDevil... can you help? :)


  11. I replyed your e-mail, and hope it's working out for you.

    To all: Remember to check the directory configuration.


  12. I am looking to do this as a self contained function to use outside of WordPress. What would be the function to count the times a zip file is accessed?


  13. Hey,

    If you look beneeth the class you'll see

    1. <?php
    2. // Declare the class
    3. $download = new Download ();</p>
    4. <p>// Check the parent directory of the script, to only add filter when its not included.
    5. $path = $_SERVER['SCRIPT_FILENAME'];
    6. $path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path);</p>
    7. <p>// Not add_filter when i include it in index.php in the download_trach directory
    8. if(htmlentities($path) != 'download_track') {
    9.     add_filter('the_content', array($download, 'insert_downloaded'));
    10.     add_action('admin_head', array($download, 'add_css_admin') );
    11.     add_action('admin_menu', array($download, 'add_pages' ) );
    12. }
    13. ?>

    If you change that to something like:

    1. <?php
    2. // Declare the class
    3. $download = new Download ();</p>
    4. <p>// Check the parent directory of the script, to only add filter when its not included.
    5. $path = $_SERVER['SCRIPT_FILENAME'];
    6. $path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $path);</p>
    7. <p>// Not add_filter when i include it in index.php in the download_trach directory
    8. if(htmlentities($path) != 'download_track') {
    9.     $content = $download->insert_downloaded($content);
    10. }
    11. ?>

    And it'll work without WP. Might need some other mods. If so, contact me and I'll help you out.

    Good Luck!


  14. Good post.


  15. Ready to argue with the themes of education-all. All the same, you can very well write about it


Legg igjen respons

Fyll ut alle felt markert med *

Brukerinformasjon
  1. Kan bruke følgende html: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong> og [html] [css], [mysql] og [php] Hold posten ren og fin!

    Siter valgt tekst

E-post-varsel uten å skrive kommentar.

Info om posten

Innlegget ble postet 14.01.07 03:47 og ligger under kategorien PHP / MySQL. Du kan abonnere på kommentarene ved å bruke RSS 2.0 feed. Du kan legge til kommenter, eller trackback fra din blogg/side.

Resurser

Arkiver

Metainfo


Siste Flickr-bilder

  • Commentsystem (20070308)
  • Ukraina Aksjonen 2006 (20070306)
  • Mikael Brevik blogg (20070306)
  • Mikael Brevik (20070306)
  • Brukerdefinert side - AVIS2 (20070306)
  • Brevik Webutvikling (20070306)
  • skyscraper
  • visittkort