Plugin Directory

Changeset 1460530


Ignore:
Timestamp:
07/26/2016 12:08:21 AM (10 years ago)
Author:
findshorty
Message:

1.03 - downloads column and custom logs

Location:
dwnldr/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • dwnldr/trunk/dwnldr.php

    r1460223 r1460530  
    99Description: Lightweight download manager - link to your attachment page: your URLs are hidden & your downloads are logged. Simples!
    1010Author: Ian Young
    11 Version: 1.02
     11Version: 1.03
    1212Author URI: http://findshorty.com/
    1313*/
     
    2121    public function __construct() {
    2222        add_action('template_redirect', array($this, 'check_attachment'));
     23        add_action('manage_media_custom_column', array($this,'display_dwnldr_column'), 10, 2 );
    2324        add_action('admin_init', array($this, 'add_list_download_log_metabox'));
    2425        add_action('admin_init', array($this, 'load_textdomain') );
     26        add_filter('manage_media_columns', array($this,'add_dwnldr_column') );
    2527    }
    2628   
    2729    public function load_textdomain() {
    2830        load_plugin_textdomain( 'dwnldr', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
     31    }
     32   
     33    public function add_dwnldr_column($cols) {
     34        $cols["dwnlds"] = "Downloads";
     35        return $cols;
     36    }
     37   
     38    public function display_dwnldr_column($col, $id) {
     39        if('dwnlds'==$col) {
     40            global $post;
     41            $mime = get_post_mime_type( $post->ID );
     42            $extarr = explode('/',$mime);
     43            $ext = array_pop($extarr);
     44            $extensions = apply_filters('dwnldr_extensions', $this->dwnldr_extensions);
     45            if(in_array($ext, $extensions)) {
     46                $logs = get_post_meta($id, '_download_log', false);
     47                echo '<a href="'.admin_url('post.php?post='.$id.'&action=edit#dwnldr_logs').'">'.count($logs).'</a>';
     48            }
     49        }
    2950    }
    3051   
     
    3758        $logs = get_post_meta($post->ID,'_download_log',false);
    3859        $latestlogs = array_slice(array_reverse($logs),0,20);
     60        // do we have any custom items?
     61        $checklog = $latestlogs[0];
     62        $has_custom = count(array_keys($checklog))>4;
    3963        if(!empty($latestlogs)) {
    4064            ?>
    41             <table class="widefat" cellspacing="0">
     65            <table class="widefat dwnldr_logs" cellspacing="0">
    4266                <thead>
    4367                    <tr>
    44                         <th colspan="4"><strong><?php _e('Total downloads','dwnldr'); ?></strong> =&gt; <?php echo number_format(count($logs),0); ?></th>
     68                        <th colspan="<?php echo $has_custom ? 5 : 4; ?>"><strong><?php _e('Total downloads','dwnldr'); ?></strong> =&gt; <?php echo number_format(count($logs),0); ?></th>
    4569                    </tr>
    4670                    <tr>
     
    4973                        <th scope="col" class="manage-column"><?php _e('IP','dwnldr'); ?></th>
    5074                        <th scope="col" class="manage-column"><?php _e('Browser','dwnldr'); ?></th>
     75                        <?php
     76                        if($has_custom):
     77                        ?>
     78                        <th scope="col" class="manage-column"><?php _e('Custom','dwnldr'); ?></th>
     79                        <?php
     80                        endif;
     81                        ?>
    5182                    </tr>
    5283                </thead>
     
    6596                        <td><?php echo $log['ip']; ?></td>
    6697                        <td><span title="<?php echo htmlentities($log['browser_info']); ?>"><?php echo htmlentities(substr($log['browser_info'], 0, 64).'&hellip;'); ?></span></td>
     98                        <?php
     99                        if($has_custom):
     100                            unset($log['time'],$log['user'],$log['ip'],$log['browser_info']);
     101                        ?>
     102                        <td><?php
     103                            foreach($log as $key => $val):
     104                                echo '<strong>'.$key.'</strong> => '.$val.'<br />';
     105                            endforeach;
     106                            ?></td>
     107                        <?php
     108                        endif;
     109                        ?>
    67110                    </tr>
    68111                    <?php
  • dwnldr/trunk/readme.txt

    r1460223 r1460530  
    1818dwnldr will log who's downloaded it and when, and force the download without exposing your download's URL.
    1919
    20 You can find your logs on the attachment page in the dashboard. If you're viewing your media library as a grid, make sure you click the "View attachment page" link from within the dialog.
    21 
    2220== Installation ==
    2321
     
    3028== Frequently Asked Questions ==
    3129
    32 To change the file extensions that you want to allow people to download (instead of serving up the attachment page for that file), add the following to your theme's functions.php file.
     30**Where are the logs?**
     31
     32You can find your logs on the "edit post" page in the dashboard.
     33If you're viewing your media library as a grid, make sure you click the "Edit more details" link from within the dialog.
     34If your media library is in list format, you'll see a Downloads column showing you the total downloads for that item.
     35Clicking the download count, or the edit link, will take you to the edit post page, and the logs are towards the bottom.
     36
     37**Can I change the file extensions people can download?**
     38
     39Yes - to change the file extensions that you want to allow people to download (instead of serving up the attachment page for that file), add the following to your theme's functions.php file.
    3340
    3441    add_filter('dwnldr_extensions', 'my_dwnldr_extensions');
     
    3643        return array('.pdf','.jpg','.jpeg', etc...);
    3744    }
     45
     46**Can I add to the log?**
    3847
    3948You can also change, or add to, the data you want to log when a person downloads a file with the following.
     
    5059== Changelog ==
    5160
     61= 1.03 =
     62
     63Added custom logs to download log table
     64Added "Downloads" count column to media library table
     65
    5266= 1.02 =
    5367
Note: See TracChangeset for help on using the changeset viewer.