browscap.drush.inc 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @file
  4. * Browscap Drush integration.
  5. */
  6. /**
  7. * Implements hook_drush_command().
  8. */
  9. function browscap_drush_command() {
  10. $items['browscap-import'] = array(
  11. 'description' => 'Imports/updates browscap data via HTTP.',
  12. );
  13. $items['browscap-get-browser'] = array(
  14. 'description' => dt('Show browser information for a given user agent.'),
  15. 'arguments' => array(
  16. 'user agent' => 'Quote-enclosed user agent',
  17. ),
  18. 'required-arguments' => TRUE,
  19. 'examples' => array("drush browscap-get-browser 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; en) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.448 Mobile Safari/534.8+'"),
  20. 'outputformat' => array(
  21. 'default' => 'json',
  22. ),
  23. );
  24. return $items;
  25. }
  26. /**
  27. * Imports/updates browscap data via HTTP.
  28. */
  29. function drush_browscap_import() {
  30. drush_log(dt('Importing Browscap data...'), 'ok');
  31. switch (_browscap_import()) {
  32. case BROWSCAP_IMPORT_VERSION_ERROR:
  33. drush_set_error('BROWSCAP', dt('Could not check current available Browscap data version.'));
  34. break;
  35. case BROWSCAP_IMPORT_NO_NEW_VERSION:
  36. drush_log(dt('No new version of Browscap data to import.'), 'ok');
  37. break;
  38. case BROWSCAP_IMPORT_DATA_ERROR:
  39. drush_set_error('BROWSCAP', dt('Failed to retrieve or load Browscap data.'));
  40. break;
  41. case BROWSCAP_IMPORT_OK:
  42. drush_log(dt('Imported Browscap data successfully.'), 'ok');
  43. break;
  44. }
  45. }
  46. /**
  47. * Gets browser information for Drush output.
  48. *
  49. * @param string $user_agent
  50. * User agent.
  51. *
  52. * @return array
  53. * An array of information about the user agent.
  54. */
  55. function drush_browscap_get_browser($user_agent) {
  56. return browscap_get_browser($user_agent);
  57. }