function biblio_citeproc_install_style in Bibliography Module 7.2
Same name and namespace in other branches
- 7 modules/CiteProc/biblio_citeproc.module \biblio_citeproc_install_style()
1 call to biblio_citeproc_install_style()
- biblio_citeproc_install_default_styles in modules/
CiteProc/ biblio_citeproc.install
File
- modules/
CiteProc/ biblio_citeproc.module, line 122
Code
function biblio_citeproc_install_style($name, $csl) {
$xml = simplexml_load_string($csl);
$parent = '';
foreach ($xml->info->link as $link) {
$attrs = $link
->attributes();
if (isset($attrs['rel']) && $attrs['rel'] == 'independent-parent') {
$parent = (string) $attrs['href'];
}
}
$old_sha1 = NULL;
$old_sha1 = db_query('SELECT sha1 FROM {biblio_citeproc_styles} WHERE id = :id', array(
':id' => (string) $xml->info->id,
))
->fetchField();
$record = array(
'filename' => $name,
'parent' => $parent,
'title' => (string) $xml->info->title,
'summary' => (string) $xml->info->summary,
'csl' => $csl,
'sha1' => sha1($csl),
'id' => (string) $xml->info->id,
);
if ($old_sha1 && $old_sha1 == sha1($csl)) {
//style exists and has not changed
return;
}
elseif ($old_sha1 && $old_sha1 != sha1($csl)) {
// update an existing style
$query = db_update('biblio_citeproc_styles')
->fields($record)
->condition('id', $record['id']);
}
elseif (!$old_sha1) {
//install new style
$query = db_insert('biblio_citeproc_styles')
->fields(array(
'id',
'title',
'filename',
'summary',
'csl',
'sha1',
));
$query
->values($record);
}
$query
->execute();
}