68de Link Vault for ExpressionEngine Documentation | Software | Masuga Design - Expert ExpressionEngine Developers
 

Template Tags

:download_link

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.

Tag Parameters
  • file_name : The file name (commonly used with directory=”“)
  • directory : Enter a directory path if the file is not in the default hidden folder. (commonly used with file_name=”“)
  • file_path : If you don’t specify a file_name and directory independently, use this parameter to specify the complete path.
  • entry_id : An entry ID may be specified for logging purposes if download files are associated with a channel.
  • url_only : If value is ‘true’, only the URL will be returned. The default is ‘false’.
  • action_only : If value is ‘true’, the URL will exclude the site index from the beginning of the URL. Only the action number and the rest of the query string will be included in the returned URL.
  • class : CSS class for the link’s style
  • text : The text that is displayed in the link. The default is ‘Download’.
  • remote : Set this to “true” if the file is hosted on a remote server. The default is “false”.
  • cf: : ‘cf:’ is the prefix for any custom field created in the Link Vault control panel. (Examples: cf:user_agent, cf:download_page, cf:screen_name)
  • s3_bucket : If you’d like to fetch a file from your Amazon S3 account, specify the bucket here. To specify which file you’d like to fetch, use the ‘file_path’ parameter.
  • expires : Use this parameter to set an expiration date/time that the link will no longer show on the page upon page load. The date/time format must conform to one of the accepted PHP date/time formats.
  • expires_text : Use this parameter to specify some content that should be displayed if the link has expired.
  • show_file_name : Set this parameter to 'true' if you'd like the name of the file to appear in the generated URL. The query string parameter value created by this tag parameter is not used during processing.
Sample Code

# 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'}

:download_button

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.

Parameters
  • file_name : The file name (required)
  • directory : Enter a directory path if the file is not in the default hidden folder.
  • file_path : If you don’t specify a file_name and directory independently, use this parameter to specify the complete path.
  • entry_id : An entry ID may be specified for logging purposes if download files are associated with a channel.
  • action_only : If value is ‘true’, the URL will exclude the site index from the beginning of the URL. Only the action number and the rest of the query string will be included in the returned URL.
  • class : CSS class for the button’s style
  • text : The text that is displayed on the button. The default is ‘Download’.
  • remote : Set this to “true” if the file is hosted on a remote server. The default is “false”.
  • cf: : ‘cf:’ is the prefix for any custom field created in the Link Vault control panel. (Examples: cf:user_agent, cf:download_page, cf:screen_name)
  • s3_bucket : If you’d like to fetch a file from your Amazon S3 account, specify the bucket here. To specify which file you’d like to fetch, use the ‘file_path’ parameter.
  • expires : Use this parameter to set an expiration date/time that the button will no longer show on the page upon page load. The date/time format must conform to one of the accepted PHP date/time formats.
  • expires_text : Use this parameter to specify some content that should be displayed if the button has expired.
Sample Code

# 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' }

:download_count

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.

Parameters
  • file_name : The file name or URL.
  • entry_id : The channel entry ID for the file.
  • file_path : If you don’t specify a file_name and directory independently, use this parameter to specify the complete path.
  • directory : Enter a directory path if the file is not in the default hidden folder.
  • table_name : The name of the table in which to count. The default is ‘downloads’. The other option is ‘leeches’.
  • member_id : Specify a member_id to return the number of times a particular member has downloaded a file.
  • start_date : The starting date in a range of dates. (format : Y-m-d)
  • end_date : The end date in a range of date. (format : Y-m-d)
  • cf: : ‘cf:’ is the prefix for any custom field created in the Link Vault control panel. (Examples: cf:user_agent, cf:download_page, cf:screen_name)
Sample Code

{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' }

:file_size

class=”full-width”The :file_size template tag returns a file size for a specified file that is stored locally.

Parameters
  • file_name : The file name.
  • directory : Enter a directory path if the file is not in the default hidden folder.
  • file_path : If you don’t specify a file_name and directory independently, use this parameter to specify the complete path.
Sample Code

# 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

:url

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.

Parameters
  • url : The URL that is to be encrypted.
  • cf: : ‘cf:’ is the prefix for any custom field created in the Link Vault control panel. (Examples: cf:user_agent, cf:download_page, cf:screen_name)
Sample Code

{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}' }

:pretty_url

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.

Parameters
  • url : The URL that is to be encrypted.
  • text : A description of the URL's destination.
  • cf: : 'cf:' is the prefix for any custom field created in the Link Vault control panel. (Examples: cf:user_agent, cf:current_uri, cf:screen_name)
Sample Code

{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

:click_count

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.

Parameters
  • url : The URL for which you’d like the count.
  • member_id : Specify a member ID if you’d like limit the count to the number of times a particular member clicked a link.
  • start_date : The starting date in a range of dates. (format : Y-m-d)
  • end_date : The end date in a range of dates. (format : Y-m-d)
Sample Code

{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' }

:records

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.

Parameters
  • table : The data you’d like to query. Valid options are ‘downloads’ (default), ‘leeches’ and ‘link_clicks’.
  • directory : Return downloads where the file comes from a particular directory.
  • file_name : Return downloads for a particular file name.
  • url : Return link click statistics for a particular URL.
  • pretty_url_id : Return link click statistics for a particular pretty URL ID.
  • member_id : Specify a member ID if you’d like to list downloads for a particular member.
  • start_date : The starting date in a range of dates. (format : Y-m-d)
  • end_date : The end date in a range of dates. (format : Y-m-d)
  • group_by : Specify a link_vault_downloads column name to group the results. Using the group_by parameter creates the ‘census’ variable to store the count tally.
  • count_variable : If you’d like your ‘census’ variable to have a different name, specify the desired name in the count_variable parameter.
  • order_by : Order the results by a particular field. Any field in the link_vault_downloads table is valid. The default is ‘unix_time’.
  • sort : Valid options are ‘asc’ or ‘desc’. The default is ‘desc’.
  • limit : Limit the number of results returned. The default is 100.
  • cf: : You may search by custom fields with the ‘cf:’ prefix. (Examples: cf:user_agent, cf:download_page, cf:screen_name).
  • variable_prefix : If you are nesting the template tag inside another tag, you can use this parameter to add a prefix to the template variables in order to avoid conflicting with template variables from another tag.
Sample Code

# 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}

Configuration Variables

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';

Extension Hooks

link_vault_download_start

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);

link_vault_download_end

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);

link_vault_remote_download_start

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);

link_vault_s3_download_start

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);

link_vault_log_leech_start

This hook is called immediately before logging a leech attempt.


$record_data = $this->EE->extensions->call('link_vault_log_leech_start', $record_data);

link_vault_log_leech_end

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);

link_vault_link_click_start

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);

0