You are here

function biblio_citeproc_style_manager_form in Bibliography Module 6.2

Same name and namespace in other branches
  1. 7 modules/CiteProc/biblio_citeproc.admin.inc \biblio_citeproc_style_manager_form()
  2. 7.2 modules/CiteProc/biblio_citeproc.admin.inc \biblio_citeproc_style_manager_form()
1 string reference to 'biblio_citeproc_style_manager_form'
biblio_citeproc_menu in modules/CiteProc/biblio_citeproc.module

File

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

Code

function biblio_citeproc_style_manager_form($form) {
  $form = array();
  $options = array();
  $tree = array();
  $cache = cache_get('biblio_citeproc_styles');
  if (!$cache || $cache->expire < time()) {
    if (!($style_zip_file = variable_get('biblio_citeproc_styles_zip_file', FALSE))) {
      $style_zip_file = _get_zip_from_github();
    }
    if ($style_zip_file) {

      //    $file = realpath($style_zip_file->uri);
      $options = _get_csl_list_from_zip($style_zip_file);
    }
    if (!empty($options)) {

      //expire 30 days from now
      $expire = time() + 2592000;
      cache_set('biblio_citeproc_styles', $options, 'cache', $expire);
    }
  }
  else {
    $options = $cache->data;
  }
  $form['remote_names'] = array(
    '#type' => 'value',
    '#value' => $options,
  );
  asort($options);
  $form['available_styles'] = array(
    '#type' => 'select',
    '#title' => t('Available styles'),
    '#size' => 15,
    '#multiple' => TRUE,
    '#description' => t('Choose the styles you would like to download and install.'),
  );
  $form['install'] = array(
    '#type' => 'submit',
    '#value' => '<--',
    '#description' => t('Install the selected styles from GitHub'),
  );
  $form['remove'] = array(
    '#type' => 'submit',
    '#value' => '-->',
    '#description' => t('Un-install the selected styles'),
  );
  $form['default'] = array(
    '#type' => 'submit',
    '#value' => t('Set as site default'),
  );
  $form['edit'] = array(
    '#type' => 'submit',
    '#value' => t('Edit selected'),
  );
  $form['install_all'] = array(
    '#type' => 'submit',
    '#value' => t('Install all'),
  );
  $form['#attributes']['enctype'] = 'multipart/form-data';
  $form['import_csl_file'] = array(
    '#type' => 'file',
    '#title' => t('Import Local CSL file'),
    '#default_value' => '',
    '#size' => 60,
  );
  $form['import'] = array(
    '#type' => 'submit',
    '#value' => t('Import'),
    '#submit' => array(
      'biblio_citeproc_csl_file_import_submit',
    ),
  );
  $query = "SELECT filename,id,sha1,title FROM {biblio_citeproc_styles} ORDER BY filename ASC";
  $result = db_query($query);
  $titles = array();
  $installed = array();
  while ($style = db_fetch_object($result)) {
    $installed[$style->id] = $style->filename;
    $titles[$style->filename] = $style->title;
  }

  // now remove the installed titles from the available titles list
  $options = array_diff($options, $titles);
  $form['available_styles']['#options'] = $options;
  $form['installed_styles'] = array(
    '#type' => 'select',
    '#title' => t('Installed styles'),
    '#size' => 15,
    '#options' => biblio_get_styles(),
    '#multiple' => TRUE,
    '#description' => t('Currently installed styles.'),
  );
  $form['current_default'] = array(
    '#value' => $titles[variable_get('biblio_citeproc_style', 'cse.csl')],
  );
  return $form;
}