function _install_csl in Bibliography Module 7
Same name and namespace in other branches
- 6.2 modules/CiteProc/biblio_citeproc.admin.inc \_install_csl()
- 7.2 modules/CiteProc/biblio_citeproc.admin.inc \_install_csl()
5 calls to _install_csl()
- biblio_citeproc_csl_file_import_submit in modules/
CiteProc/ biblio_citeproc.admin.inc - biblio_citeproc_update_installed_batch in modules/
CiteProc/ biblio_citeproc.admin.inc - _install_all_from_zip in modules/
CiteProc/ biblio_citeproc.admin.inc - _install_csl_from_github in modules/
CiteProc/ biblio_citeproc.admin.inc - _install_selected_from_zip in modules/
CiteProc/ biblio_citeproc.admin.inc
File
- modules/
CiteProc/ biblio_citeproc.admin.inc, line 329
Code
function _install_csl($name = NULL, $csl = NULL, $sha = NULL, $all = FALSE, $update = FALSE) {
static $installed = array();
if (empty($installed)) {
$result = db_select('biblio_citeproc_styles', 'csl')
->fields('csl', array(
'filename',
'id',
'sha1',
'title',
))
->orderBy('filename', 'ASC')
->execute();
$installed = array();
foreach ($result as $style) {
$installed[$style->id] = $style;
}
}
$xml = simplexml_load_string($csl);
if ($xml) {
$parent = '';
foreach ($xml->info->link as $link) {
$attrs = $link
->attributes();
if (isset($attrs['rel']) && $attrs['rel'] == 'independent-parent') {
$parent = (string) $attrs['href'];
}
}
if (!$all && !$update && !empty($parent)) {
$csl_file_contents = db_query("SELECT csl FROM {biblio_citeproc_styles} WHERE id = :parent", array(
':parent' => $parent,
))
->fetchField();
if (!$csl_file_contents) {
_install_csl_from_github(basename($parent) . '.csl');
}
}
$sha1 = isset($sha) ? $sha : sha1($csl);
$record = array(
'filename' => $name,
'parent' => $parent,
'title' => trim((string) $xml->info->title),
'summary' => (string) $xml->info->summary,
'csl' => $csl,
'sha1' => $sha1,
'id' => (string) $xml->info->id,
'updated' => time(),
'changed' => 0,
);
if (!array_key_exists($record['id'], $installed)) {
db_insert('biblio_citeproc_styles')
->fields($record)
->execute();
$installed[$record['id']] = TRUE;
return 1;
}
elseif ($record['sha1'] != $installed[$record['id']]->sha1) {
db_update('biblio_citeproc_styles')
->condition('id', $record['id'])
->fields($record)
->execute();
return 2;
}
elseif ($record['sha1'] == $installed[$record['id']]->sha1 && $update == FALSE) {
$message = t('The CSL file you supplied: !name, is already installed', array(
'!name' => $name,
));
drupal_set_message(check_plain($message), 'warning');
}
}
else {
drupal_set_message(t('I could not parse the CSL provided as valid XML'), 'error');
}
}