aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor <pashev.igor@gmail.com>2010-12-28 22:34:13 +0300
committerIgor <pashev.igor@gmail.com>2010-12-28 22:34:13 +0300
commit9cc9ed16fadeead0d846b2b43ef961791c74fe05 (patch)
tree875932736a0b43a5078881554ba97bf1dbd5b331
parent902d6ec2f5208a799feff916fa9cd739807453cb (diff)
downloaddokuwiki-plugin-papers-9cc9ed16fadeead0d846b2b43ef961791c74fe05.tar.gz
Fixed export; example added
-rw-r--r--bibtex.php69
-rw-r--r--normalize.php14
2 files changed, 51 insertions, 32 deletions
diff --git a/bibtex.php b/bibtex.php
index 6979855..9fe5294 100644
--- a/bibtex.php
+++ b/bibtex.php
@@ -185,38 +185,6 @@ class BibtexParser
return $res;
}
-
- /*
- * Export sorted BiBTeX.
- * Do not use after $this->expand_years()
- *
- */
- public function export()
- {
- $res = '';
- $this->sort();
- foreach ($this->STRINGS as $key => $value)
- {
- $res .= '@STRING (' . $key . '="' . $value . '")' . "\n";
- }
-
- $res .= "\n\n";
-
- foreach ($this->ENTRIES as $ent)
- {
- $res .= '@' . mb_strtoupper($ent['entry']) . ' {' . $ent['id'] . ",\n";
- $fields = array();
- foreach($ent as $key => $value)
- {
- // Skip our special fields
- if (!in_array($key, array('id', 'entry')))
- $fields[] = mb_strtoupper($key) . '=' . $value;
- }
- $res .= implode(",\n", $fields);
- $res .= "\n}\n\n";
- }
- return $res;
- }
}
@@ -301,6 +269,43 @@ class BibtexParserTeam extends BibtexParser
usort($this->SELECTION, array($this, 'cmp_entries'));
}
+ public function sort_all()
+ {
+ usort($this->ENTRIES, array($this, 'cmp_entries'));
+ }
+
+ /*
+ * Export sorted BiBTeX.
+ * Do not use after $this->expand_years()
+ *
+ */
+ public function export()
+ {
+ $res = '';
+ $this->sort_all();
+ foreach ($this->STRINGS as $key => $value)
+ {
+ $res .= '@STRING (' . $key . '="' . $value . '")' . "\n";
+ }
+
+ $res .= "\n\n";
+
+ foreach ($this->ENTRIES as $ent)
+ {
+ $res .= '@' . mb_strtoupper($ent['entry']) . ' {' . $ent['id'] . ",\n";
+ $fields = array();
+ foreach($ent as $key => $value)
+ {
+ // Skip our special fields
+ if (!in_array($key, array('id', 'entry')))
+ $fields[] = mb_strtoupper($key) . '=' . $value;
+ }
+ $res .= implode(",\n", $fields);
+ $res .= "\n}\n\n";
+ }
+ return $res;
+ }
+
protected function format_field_default($field)
{
$this->entry[$field] = $this->latex2html(
diff --git a/normalize.php b/normalize.php
new file mode 100644
index 0000000..836ef78
--- /dev/null
+++ b/normalize.php
@@ -0,0 +1,14 @@
+<?php
+require_once('bibtex.php');
+
+if (2 == $argc) {
+ $bibtex = new BibtexParserTeam();
+ $bibtex->read_file($argv[1]);
+ print $bibtex->export();
+} else {
+ print_r($argv);
+}
+
+
+?>
+