You are here

function drush_jquery_plugin_update in jQuery plugins 7

Drush callback; update jQuery plugins.

File

./jquery_plugin.drush.inc, line 17

Code

function drush_jquery_plugin_update() {

  // Update jQuery Tools plugins.
  $ch = curl_init('http://flowplayer.org/tools/download/index.html');

  // Support gzip-encoded response.
  curl_setopt($ch, CURLOPT_ENCODING, '');
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
  $source = curl_exec($ch);
  curl_close($ch);
  $doc = new DOMDocument();

  // Ignore parse warnings.
  @$doc
    ->loadHTML($source);
  $xpath = new DOMXpath($doc);
  $anchors = $xpath
    ->query('//table//a');
  foreach ($anchors as $anchor) {
    $href = $anchor
      ->getAttribute('href');
    if (strpos($href, '.min.js') && substr_count($href, '/') == 5) {
      $ch = curl_init('http://flowplayer.org' . $href);
      $handle = fopen(drupal_get_path('module', 'jquery_plugin') . '/' . strtok(basename($href), '?'), 'w');

      // Support gzip-encoded response.
      curl_setopt($ch, CURLOPT_ENCODING, '');
      curl_setopt($ch, CURLOPT_FILE, $handle);
      curl_exec($ch);
      curl_close($ch);
      fclose($handle);
    }
  }
}