function _install_csl in Bibliography Module 6.2
Same name and namespace in other branches
- 7 modules/CiteProc/biblio_citeproc.admin.inc \_install_csl()
- 7.2 modules/CiteProc/biblio_citeproc.admin.inc \_install_csl()
4 calls to _install_csl()
- biblio_citeproc_csl_file_import_submit in modules/
CiteProc/ biblio_citeproc.admin.inc - _install_csl_from_github in modules/
CiteProc/ biblio_citeproc.admin.inc - _install_from_zip 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 253
Code
function _install_csl($name, $csl, $sha = NULL, $all = FALSE) {
static $installed = array();
if (empty($installed)) {
$query = "SELECT filename,id,sha1,title FROM {biblio_citeproc_styles} ORDER BY filename ASC";
$result = db_query($query);
$installed = array();
while ($style = db_fetch_object($result)) {
$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_result(db_query("SELECT csl FROM {biblio_citeproc_styles} WHERE id = '%s'", $parent));
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_query("INSERT INTO {biblio_citeproc_styles} (filename, parent, title, summary, csl, sha1, id) VALUES ('%s', '%s', '%s', '%s', '%s', %b, '%s')", $record);
$installed[$record['id']] = TRUE;
}
elseif ($record['sha1'] != $installed[$record['id']]->sha1) {
db_query("UPDATE {biblio_citeproc_styles} SET filename = '%s', parent = '%s', title = '%s', summary = '%s', csl = %b, sha1 = '%s' WHERE id = '%s'", $record);
}
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'));
}
}