function drush_xkcd_display

8.0.x xkcd.drush.inc drush_xkcd_display($url)
6.x xkcd.drush.inc drush_xkcd_display($url)
7.x xkcd.drush.inc drush_xkcd_display($url)
4.x xkcd.drush.inc drush_xkcd_display($url)
5.x xkcd.drush.inc drush_xkcd_display($url)
master xkcd.drush.inc drush_xkcd_display($url)

Retrieve and display a table of metadata for an XKCD cartoon, then retrieve and display the cartoon using a specified image viewer.

Parameters

A string with the URL of the cartoon to display.:

1 call to drush_xkcd_display()
drush_xkcd_fetch in examples/xkcd.drush.inc
Example drush command callback. This is where the action takes place.

File

examples/xkcd.drush.inc, line 152
Example drush command.

Code

function drush_xkcd_display($url) {
  $xkcd_response = @json_decode(file_get_contents($url . '/info.0.json'));
  if (!empty($xkcd_response->num)) {
    $data = (array) $xkcd_response;
    $data['date'] = $data['year'] . '/' . $data['month'] . '/' . $data['day'];
    unset($data['safe_title'], $data['news'], $data['link'], $data['year'], $data['month'], $data['day']);
    drush_print_table(drush_key_value_to_array_table($data));
    $img = drush_download_file($data['img']);
    drush_register_file_for_deletion($img);
    drush_shell_exec(drush_get_option('image-viewer', 'display') . ' ' . $img);
  }
  else {
    drush_set_error('DRUSH_XKCD_METADATA_FAIL', dt('Unable to retrieve cartoon metadata.'));
  }
}