You are here

function biblio_citeproc_style_manager_form in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 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 10

Code

function biblio_citeproc_style_manager_form($form, &$form_state) {
  $form = array();
  $options = 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 = drupal_realpath($style_zip_file->uri);
      $options = _get_csl_list_from_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['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'),
    '#submit' => array(
      'biblio_citeproc_set_site_default',
    ),
  );
  $form['update_installed'] = array(
    '#type' => 'submit',
    '#value' => t('Update installed styles'),
    '#submit' => array(
      'biblio_citeproc_update_installed',
    ),
  );
  $form['update_available'] = array(
    '#type' => 'submit',
    '#value' => t('Update available styles'),
    '#submit' => array(
      'biblio_citeproc_update_available',
    ),
  );
  $form['edit'] = array(
    '#type' => 'submit',
    '#value' => t('Edit selected'),
    '#submit' => array(
      'biblio_citeproc_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',
    ),
  );
  $result = db_select('biblio_citeproc_styles', 'csl')
    ->fields('csl', array(
    'filename',
    'title',
    'id',
    'sha1',
    'title',
    'summary',
    'changed',
    'updated',
  ))
    ->orderBy('filename', 'ASC')
    ->execute();
  $details = array();
  $titles = array();
  foreach ($result as $style) {
    $details[$style->filename] = $style;
    $titles[] = $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(
    '#markup' => empty($details) ? '' : $details[variable_get('biblio_citeproc_style', 'ieee.csl')]->title,
  );
  $form['current_summary'] = array(
    '#markup' => empty($details) ? '' : $details[variable_get('biblio_citeproc_style', 'ieee.csl')]->summary,
  );
  $timestamp = $details[variable_get('biblio_citeproc_style', 'ieee.csl')]->updated;
  $updated = $timestamp ? ' (' . t('Last updated:') . ' ' . format_date($timestamp, 'medium') . ')' : '';
  $form['current_update'] = array(
    '#markup' => $updated,
  );
  return $form;
}