You are here

function _get_github_repo_tree in Bibliography Module 6.2

Same name and namespace in other branches
  1. 7 modules/CiteProc/biblio_citeproc.admin.inc \_get_github_repo_tree()

File

modules/CiteProc/biblio_citeproc.admin.inc, line 212

Code

function _get_github_repo_tree($url = '') {
  $options = array();
  $tree = array();
  $treeURL = 'https://api.github.com/repos/citation-style-language/styles/contents';
  if (!empty($url)) {
    $treeURL = $url;
  }
  $result = drupal_http_request($treeURL);
  if ($result->code == 200) {
    $tree = json_decode($result->data);
  }
  else {
    $message = t('Attempt to get list of styles from GitHub resulted in an HTTP error: !code. ', array(
      '!code' => $result->code,
    ));
    $cache = cache_get('biblio_citeproc_styles');
    if ($cache) {
      $message .= t('I will use cached data instead.');
      $mess_type = 'warning';
      $options = $cache->data;
    }
    else {
      $message .= t('I have no cached data, so you will not be able to install new styles at this time.');
      $mess_type = 'error';
    }
    drupal_set_message($message, $mess_type);
  }
  foreach ($tree as $file) {
    if ($file->type == 'file' && strstr($file->name, '.csl')) {
      $options[$file->path] = basename($file->name);
    }
    elseif ($file->type == 'dir') {
      $options = array_merge($options, _get_github_repo_tree($file->url));
    }
  }
  return $options;
}