function _install_csl in Bibliography Module 7.2
Same name and namespace in other branches
- 6.2 modules/CiteProc/biblio_citeproc.admin.inc \_install_csl()
- 7 modules/CiteProc/biblio_citeproc.admin.inc \_install_csl()
3 calls to _install_csl()
- biblio_citeproc_csl_file_import_submit in modules/
CiteProc/ biblio_citeproc.admin.inc - biblio_citeproc_style_manager_form_submit in modules/
CiteProc/ biblio_citeproc.admin.inc - _install_from_zip in modules/
CiteProc/ biblio_citeproc.admin.inc
File
- modules/
CiteProc/ biblio_citeproc.admin.inc, line 231
Code
function _install_csl($name, $csl, $sha = NULL, $all = 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 && !empty($parent)) {
$csl_file_contents = db_query("SELECT csl FROM biblio_citeproc_styles WHERE id = :parent", array(
':parent' => $parent,
))
->fetchField();
if (!$csl_file_contents) {
drupal_set_message(t('You do not have the parent style file: !parent_id installed. You must install !parent_id before you can use !csl_id', array(
'!parent_id' => basename($parent),
'!csl_id' => $name,
)), 'error');
}
}
$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,
);
if (!array_key_exists($record['id'], $installed)) {
db_insert('biblio_citeproc_styles')
->fields($record)
->execute();
$installed[$record['id']] = TRUE;
}
elseif ($record['sha1'] != $installed[$record['id']]->sha1) {
db_update('biblio_citeproc_styles')
->condition('id', $record['id'])
->fields($record)
->execute();
}
elseif ($record['sha1'] == $installed[$record['id']]->sha1) {
$message = t('The CSL file you supplied: !name, is already installed', array(
'!name' => $name,
));
drupal_set_message($message, 'warning');
}
}
else {
drupal_set_message(t('I could not parse the CSL provided as valid XML', 'error'));
}
}