RBA Cash Rate: 4.35% · 1AUD = 0.67 USD · Inflation: 4.1%  
Leading Digital Marketing Experts | 1300 235 433 | Aggregation Enquires Welcome | Book Appointment
Example Interest Rates: Home Loan Variable: 5.20% (5.24%*) • Home Loan Fixed: 5.48% (6.24%*) • Fixed: 5.48% (6.24%*) • Variable: 5.20% (5.24%*) • Investment IO: 5.78% (6.81%*) • Investment PI: 5.49% (6.32%*)

Downloads Application and API

Downloads Application and API

In aggregating content to BeliefMedia as we retire old websites, we've had to put serious thought into how certain functionality was handled and maintained. One of the most significant features we were never happy with in the past was how downloads were handled. While there's a plethora of WordPress plugins available that'll handle file downloads in different ways, there weren't any that managed downloads the way we wanted them to. Back when we didn't have the time to create a solution ourselves, we settled on WP-Filebase - a relatively full featured WP plugin. However, the plugin hijacked the admin panel with the constant haggling to upgrade into a premium product, and it was notoriously unreliable and slow. Additionally, it was intrinsically connected to WordPress meaning there was no portability.

Note: This API endpoint is now retired. Another post will follow at some point that showcases the Platform Download Manager. The article is maintained as a reference only.

With a requirement to supply our clients with a customized full-featured and portable solution - and with a need to provide the service we want on our own site (in particular for downloads associated with our client marketing platform) - we built our own standalone file download application that seamlessly integrates with WordPress while maintaining platform autonomy. Partners can download a copy by logging into the client portal.

Application Features

A small number of the features we included in our application are as follow.

  • Version control. This permits a featured change log.
  • Integration with plugins and shortcodes to render upgrade information on users' blogs.
  • An API to display select information on all or individual downloads. API provides paginated responses.
  • Ability to package the product up and supply it to clients.
  • Caching to speed up responses.
  • Client only, private, expiring, or password protected downloads.
  • Daily reports are generated to measure the success of new products/downloads.
  • Download RSS feeds.
  • Track various details associated with each download by a user.
  • Easy migration between platforms.
  • Podcast integration.
  • Reference downloads in WordPress with a single shortcode (the download links at the bottom of all our pages are created as follows [download plugin="250" shortcode="251" php="252"]). Other file types are supported (.mp3, .pdf etc). A styled box will render with download links.

When additional features are required we'll simply build them in.

Application API

Our application makes an API available to return downloads in any number of ways. While the API data returned is minimal without an API key, basic information is available to anybody. Despite your likely lack of interest, what follows is a couple of basic examples (provided primarily for our clients that might require a similar feature).

Of course, WordPress itself provides a brilliant RESTful API, but we avoided integration simply so the application wasn't WordPress-dependent. Our system works with Joomla, Drupal, and any other application or CMS seamlessly.

API Examples

API Endpoint: http://api.beliefmedia.com/downloads/json.php [ Download ].

Without any URL parameters, the API returns all downloads as JSON data with basic information such as the title, description, version, and download link. Parameters for unregistered use are basic: pg (current page), num (number items), and order (use 0 for date descending).

A simple PHP request to return the last 5 public downloads attached to published posts is as follows. Pagination information and other details are returned in the resulting array.

1
<?php 
2
/*
3
 BeliefMedia Downloads API (simple PHP request)
4
 http://www.beliefmedia.com/downloads-api
5
*/
6
 
7
function beliefmedia_get_downloads($page = '1', $num = '5', $order = 0) {
8
 
9
  /* Request URL */
10
  $url = 'http://api.beliefmedia.com/downloads/json.php';
11
  $url .= '?order=' . $order;
12
  if ($page != '') $url .= '&pg=' . $page;
13
  if ($num != '') $url .= '&num=' . $num;
14
 
15
  $data = file_get_contents($url);
16
  $data = json_decode($data, true);
17
 
18
 return ($data['status'] == '200') ? $data : false;
19
}
20
 
21
/* Print results in array */
22
echo 'pre' . print_r(beliefmedia_get_downloads($page = '1', $num = 5, $order = 0), true) . '/pre';

Displaying the latest downloads in WordPress can be accomplished with the following shortcode.

1
<?php 
2
/*
3
 BeliefMedia Downloads API (Sample shortcode to show 5 latest downloads)
4
 http://www.beliefmedia.com/downloads-api
5
*/
6
 
7
function beliefmedia_get_latest_downloads($atts) {
8
  $atts = shortcode_atts(array(
9
    'page' => '1',
10
    'num' => '5',
11
    'order' => '0',
12
    'description' => true,
13
    'updated' => true,
14
    'cache' => 3600 * 8
15
  ), $atts);
16
 
17
 $transient = 'bmldl_' . md5(serialize($atts));
18
 $cachedresult =  get_transient($transient);
19
 if ($cachedresult !== false ) {
20
  return $cachedresult;
21
 
22
  } else {
23
 
24
  /* Request URL */
25
  $url = 'http://api.beliefmedia.com/downloads/json.php';
26
  $url .= '?order=' . $atts['order'];
27
  if ($atts['page'] != '') $url .= '&pg=' . $atts['page'];
28
  if ($atts['num'] != '') $url .= '&num=' . $atts['num'];
29
 
30
  $data = @file_get_contents($url);
31
  $data = json_decode($data, true);
32
 
33
  /* If okay, we'll build a list for the example */
34
  if ($data['status'] == '200') {
35
 
36
    foreach ($data['downloads'] AS $data) {
37
       $result .= '<li><a href=&quot;' . $data['permalink'] . '&quot;><strong>' . $data['title'] . '</strong></a> (' . $data['type'] . ', V' . $data['version'] . ')';
38
       if ($atts['description'] !== false) $result .= '<br><span style=&quot;font-size: 0.9em&quot;>' . $data['description'] . '</span>';
39
       if ($atts['updated'] !== false) $result .= '<span style=&quot;font-size: 0.9em&quot;> Last Updated: ' . date('jS F Y, g:ia', $data['lastupdated']) . ' GMT.</span>';
40
       $result .= '</li>';
41
    } $return = '<ul>' . $result . '</ul>';
42
 
43
  } else {
44
 
45
    /* Most likely 400/401/402 code */
46
    $return = '<p>API Error. Unavailable.</p>';
47
 
48
    /* Try again in 15 mins */
49
    $atts['cache'] = 900;
50
 
51
  }
52
 
53
 set_transient($transient, $return, $atts['cache']);
54
 return $return;
55
 }
56
}
57
add_shortcode('latestdownloads', 'beliefmedia_get_latest_downloads');

The result:

[latestdownloads]

Available attributes for this sample shortcode are page, num, order, description, updated, and cache. Usage is as follows: [latestdownloads].

Considerations

  • The API has made it easy to reference paginated lists of our articles that include downloads (Code, Plugins, Shortcodes, PHP Snippets).
  • We can now provide product upgrade notices without having to link into WP's system. We do this by defining a product key in each plugin. The function we use will compare the returned version against that which is defined in the product. If the plugin is out of date, we'll render a banner or notice in the WP dashboard.
  • Clients that use the product can use the application to render new or revised downloads or product updates on their website, Intranet, or WP control panel.
  • The API is new. Please report errors.
  • When we write code for a client, those client-protected downloads are available from the portal. The same update features apply.
  • When a download includes a YouTube tutorial or video introduction, the TY video ID will be provided in the response.
  • If you're a finance or real-estate partner, this is the same system used to deliver bank information downloads.

Download our 650-page guide on Finance Marketing. We'll show you exactly how we generate Billions in volume for our clients.

  E. Australia Standard Time [ UTC+10, Default ] [ CHECK TO CHANGE ]

  Want to have a chat?
 

RELATED READING

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest

Leave a comment