68de
The :download_link template tag generates a protected link to a file stored on the server or to a file stored on a remote server. When the link is clicked, a download record is generated and the file is downloaded.
# Basic Examples
{exp:link_vault:download_link file_name="file.zip" entry_id="520" member_id="23"}
{exp:link_vault:download_link file_name="file.zip" url_only="true"}
{exp:link_vault:download_link file_name="file.zip" cf:category="catname"}
{exp:link_vault:download_link file_name="file.zip" url_only="true" cf:category="catname"}
{exp:link_vault:download_link file_name="http://othersite.com/somefile.zip" remote="true" }
{exp:link_vault:download_link file_name="file.zip" expires="2013-01-01" expires_text="Not available" }
{exp:link_vault:download_link file_name="fonts.zip" show_file_name="true" }
{exp:link_vault:download_link file_path='/the/full/system/path/to/file.zip' text='Download now' }
{exp:link_vault:download_link directory='/the/full/system/path/to/' file_name='file.zip' text='Click this' }
{exp:link_vault:download_link directory='relative/to/docroot/' file_name='yes.mp3' text='Download song' }
{exp:link_vault:download_link file_path='http://example.com/music/horsemask-sonata.mp3' text='Download my song'}
# Sample Output
Download Now!
# Show the file name
{exp:link_vault:download_link directory='../downloads/' file_name='burrito-recipe.pdf' url_only='true' }
# Sample Output
http://example.com/?file=burrito-recipe.pdf&ACT=30&lv=eomDdQoswRC%2FqjxKLXR2Te0hebW7dtx%2B38g3i3hh3hs1fm
{exp:link_vault:download_link file_name="file.zip" class="my-link-style"}
{exp:link_vault:download_link file_name="file.zip" url_only="true"}
Result:
http://site.com/?ACT=30&e=1928&file=eomDdQoswRC%2FqjxKLXR2Te0hebW7dtx%2B
{exp:link_vault:download_link file_name="file.zip" url_only="true" action_only="true"}
{exp:link_vault:download_link file_path="mega/uploads/file.zip" entry_id="1234"}
# Remote File Examples
{exp:link_vault:download_link file_name="http://www.site.ly/a.txt" text="view file" remote="true"}
{exp:link_vault:download_link file_name="http://mysite.com/monkeys.zip" remote="true"}
# Amazon S3 Examples
{exp:link_vault:download_link s3_bucket='images' file_path='animals/monkeys.png' text='Get Monkeys'}
{exp:link_vault:download_link s3_bucket='tutes' file_path='video.flv' cf:file_category='tutorial'}
The :download_button template tag generates a button contained within a mostly hidden form. When the button is clicked, a download record is generated and the file is downloaded.
# Regular Examples
{exp:link_vault:download_button file_name='file.zip'}
{exp:link_vault:download_button file_name='file.zip' directory='misc-files/apps/' }
{exp:link_vault:download_button file_name='file.zip' class='greenbtn rounded' }
{exp:link_vault:download_button file_name='file.zip' text='Click to Download' }
{exp:link_vault:download_button file_path='http://www.site.com/file.zip' entry_id='1234' remote='true' }
{exp:link_vault:download_button file_path='http://www.site.com/file.zip' cf:user_agent='Chrome 11.0'}
# Amazon S3 Examples
{exp:link_vault:download_button s3_bucket='stock-photos' file_path='call-center-lady.png'}
{exp:link_vault:download_button s3_bucket='horses' file_path='directory/names/horse.gif' }
The :download_count template tag returns the total download count for a specified entry ID or file. It can also be used to return the number of hack attempts on a file or leech attempts for a file.
{exp:link_vault:download_count entry_id='1234' }
{exp:link_vault:download_count file_name='photos.zip' directory='alternative/directory/' }
{exp:link_vault:download_count file_name='photos.zip' member_id='312' }
{exp:link_vault:download_count file_name='photos.zip' table_name='leeches' }
{exp:link_vault:download_count entry_id='1234' start_date='2012-01-01' end_date='2012-02-14' }
class=”full-width”The :file_size template tag returns a file size for a specified file that is stored locally.
# Basic Usage
{exp:link_vault:file_size file_name='file.zip' directory='files/other-directory/' }
{exp:link_vault:file_size file_path='images/random/animals/reggy.jpg' }
{exp:link_vault:file_size file_path='http://example.com/url/to/file.tar.gz' }
# Sample Output
3 GB
14 KB
20 MB
The :url template tag generates a protected link by encrypting the true URL. It doesn’t have to be associated with a download and it will not be logged in any way. It is simply a way to mask the destination of a link. As of Link Vault 1.1.0, the :url template tag supports Link Vault custom fields.
{exp:link_vault:url url='http://example.com/link/i/want/to/track' }
{exp:link_vault:url url='http://example.com/remote/content/im/sharing' cf:page='{segment_1}/{segment_2}' }
The :pretty_url template tag accepts a URL and description text. The description text is made into a URL friendly unique identifier that Link Vault uses to redirect the user to the specified URL. This template tag accepts custom field parameters and the encrypted data is attached to the URL.
{exp:link_vault:pretty_url url='http://site.com/long/url/or/blog/title' text='visit my blog'}
http://site.com?go=visit-my-blog&ACT=46
{exp:link_vault:pretty_url url='http://site.com/advertisement/link' text='visit our sponsor'}
http://site.com?go=visit-our-sponsor&ACT=46
The :click_count template tag queries the number of clicks that particular URL has received. This tag only works if link click logging is enabled in the Link Vault module settings.
{exp:link_vault:click_count url='http://example.com/tracked/site/link' }
{exp:link_vault:click_count url='http://twitter.com/devot_ee' start_date='2012-01-01' end_date='2012-12-31' }
{exp:link_vault:click_count url='http://ellislab.com' member_id='8170' }
The template tag pair queries the link_vault_downloads for downloads or link clicks. It can also query the link_vault_leeches table for leech attempts.
# Member ID 5's 10 most recent downloads of 'logos.zip'.
{exp:link_vault:records member_id='5' file_name='logos.zip' limit='10'}
{count}
{id}
{site_id}
{entry_id}
{unix_time format='%m-%d-%Y %H:%i'}
{member_id}
{remote_ip}
{directory}
{file_name}
{is_link_click}
# sample custom fields
{cf_screen_name}
{cf_download_page}
{cf_user_agent}
{/exp:link_vault:records}
# Top encrypted link clicks (non-downloads)
{exp:link_vault:records table='link_clicks' group_by='url' order_by='census' sort='desc' }
{count}. {url} : {census} clicks.
{/exp:link_vault:records}
# Top 10 downloaded files
{exp:link_vault:records group_by='file_name' order_by='census' sort='desc' limit='10'}
{count}. {file_name} was downloaded {census} times.
{/exp:link_vault:records}
# Top 5 users with the most downloads
{exp:link_vault:records group_by='member_id'
count_variable='download_count'
order_by='download_count'
sort='desc'
limit='5'}
{count}. Member {member_id} has downloaded {download_count} files.
{/exp:link_vault:records}
# All leech attempts by member with ID 300, most recent first
{exp:link_vault:records table='leeches' member_id='300' order_by='unix_time' sort='desc'}
Leech attempt for {file_name} file on {unix_time format='%m/%d/%Y'}
{/exp:link_vault:records}
# 15 most recent downloads with a variable prefix
{exp:link_vault:records order_by='date' sort='desc' limit='15' variable_prefix='md_' }
{if md_no_results}No downloads ever!
{/if}
Member {md_member_id} downloaded {md_file_name} at {md_unix_time format='%m-%d-%Y %H:%i'}
{/exp:link_vault:records}
If you’d like to override the stored module settings, here is a list of configuration variables you can place in config.php.
$config['link_vault_salt'] = '3j4h5j6kd';
$config['link_vault_hidden_folder'] = '/local/files/';
$config['link_vault_leech_url'] = 'http://mysite.com/no-leeching';
$config['link_vault_missing_url'] = 'http://mysite.com/file-is-missing';
$config['link_vault_block_leeching'] = 0;
$config['link_vault_log_leeching'] = 1;
$config['link_vault_log_link_clicks'] = 1;
$config['link_vault_debug'] = TRUE;
$config['link_vault_aws_access_key'] = 'MYAMAZONWEBSERVICESACCESSKEY';
$config['link_vault_aws_secret_key'] = 'thisismyamazonwebservicessecretkey';
$config['link_vault_download_protocol'] = 'https';
This hook is called immediately before a file is downloaded. The only parameter is the array of record data which can be manipulated within your extension but your method MUST return the record array.
$log_record_data = $this->EE->extensions->call('link_vault_download_start', $log_record_data);
This hook is called immediately after a file is downloaded and the download is logged.
$edata = $this->EE->extensions->call('link_vault_download_end', $log_record_data, $log_id);
This hook is called immediately before a remote download attempt is logged and the user’s browser attempts to download the file. This hook accepts the record data array as a parameter. You can manipulate the record data in your extension and your hook method MUST return the record data array upon completion.
$log_record_data = $this->EE->extensions->call('link_vault_remote_download_start', $log_record_data);
This hook is called immediately before redirecting to a secure S3 URL. The hook must return the $log_record_data.
$log_record_data = $this->EE->extensions->call('link_vault_s3_download_start', $log_record_data);
This hook is called immediately before logging a leech attempt.
$record_data = $this->EE->extensions->call('link_vault_log_leech_start', $record_data);
This hook is called immediately after logging a leech attempt before the module checks to see if file leeching is allowed. Any value returned by the hook is not used in the module.
$edata = $this->EE->extensions->call('link_vault_log_leech_end', $record_data, $log_id);
This hook is called immediately before logging a link click. You can use this hook to modify the data that will be stored in the database row or manually populate a custom field. The record data array must be returned at the end of the hook method.
$record_data = $this->EE->extensions->call('link_vault_link_click_start', $record_data);