Index: trunk/extensions/DataTransclusion/OpenLibrarySource.php |
— | — | @@ -52,7 +52,25 @@ |
53 | 53 | } |
54 | 54 | |
55 | 55 | if ( !isset( $spec['fieldNames'] ) ) { |
56 | | - $spec['fieldNames'] = 'author,date,publisher,title,url'; |
| 56 | + $spec['fieldNames'] = array( |
| 57 | + 'author', |
| 58 | + 'date', |
| 59 | + 'publisher', |
| 60 | + 'title', |
| 61 | + 'url', |
| 62 | + 'city', |
| 63 | + 'edition', |
| 64 | + 'ISBN10', |
| 65 | + 'ISBN13', |
| 66 | + 'LCC', |
| 67 | + 'LCCN', |
| 68 | + 'DDC', |
| 69 | + 'pages', |
| 70 | + 'series', |
| 71 | + 'subtitle', |
| 72 | + 'language', |
| 73 | + 'editor', |
| 74 | + ); |
57 | 75 | } |
58 | 76 | |
59 | 77 | if ( !isset( $spec['sourceInfo'] ) ) { |
— | — | @@ -76,8 +94,9 @@ |
77 | 95 | |
78 | 96 | public function flattenRecord( $rec ) { |
79 | 97 | $r = array(); |
80 | | - $r['date'] = $rec['details']['publish_date']; |
81 | | - |
| 98 | + |
| 99 | + $r['date'] = @$rec['details']['publish_date']; //TODO: split into year/month/day |
| 100 | + |
82 | 101 | $r['title'] = $rec['details']['title']; |
83 | 102 | if ( @$rec['details']['title_prefix'] ) { |
84 | 103 | $r['title'] = trim( $rec['details']['title_prefix'] ) |
— | — | @@ -86,18 +105,89 @@ |
87 | 106 | |
88 | 107 | $r['url'] = $rec['info_url']; |
89 | 108 | |
| 109 | + $r['pages'] = @$rec['details']['number_of_pages']; |
| 110 | + $r['edition'] = @$rec['details']['edition_name']; |
| 111 | + |
90 | 112 | $r['publisher'] = ""; |
91 | | - foreach ( $rec['details']['publishers'] as $publisher ) { |
92 | | - if ( $r['publisher'] != "" ) $r['publisher'] .= '; '; |
93 | | - $r['publisher'] .= $publisher; |
| 113 | + if ( isset( $rec['details']['publishers'] ) ) { |
| 114 | + foreach ( $rec['details']['publishers'] as $publisher ) { |
| 115 | + if ( $r['publisher'] != "" ) $r['publisher'] .= '; '; |
| 116 | + $r['publisher'] .= $publisher; |
| 117 | + } |
94 | 118 | } |
95 | 119 | |
96 | 120 | $r['author'] = ""; |
97 | | - foreach ( $rec['details']['authors'] as $author ) { |
98 | | - if ( $r['author'] != "" ) $r['author'] .= ', '; |
99 | | - $r['author'] .= $author['name']; |
| 121 | + if ( isset( $rec['details']['authors'] ) ) { |
| 122 | + foreach ( $rec['details']['authors'] as $author ) { |
| 123 | + if ( $r['author'] != "" ) $r['author'] .= ', '; |
| 124 | + |
| 125 | + if ( $author['key'] != "/authors/OL2693863A" ) { //"Journal" is not a real author. |
| 126 | + $r['author'] .= $author['name']; |
| 127 | + } |
| 128 | + } |
100 | 129 | } |
| 130 | + |
| 131 | + $r['editor'] = ""; |
| 132 | + if ( isset( $rec['details']['editors'] ) ) { |
| 133 | + foreach ( $rec['details']['editors'] as $editor ) { |
| 134 | + if ( $r['editor'] != "" ) $r['editor'] .= ', '; |
| 135 | + $r['editor'] .= $editor; |
| 136 | + } |
| 137 | + } |
| 138 | + |
| 139 | + if ( empty( $r['author'] ) && empty( $r['editor'] ) ) { |
| 140 | + if ( isset( $rec['details']['by_statement'] ) ) { |
| 141 | + $r['author'] = $rec['details']['by_statement']; //XXX ugly... |
| 142 | + } |
| 143 | + } |
| 144 | + |
| 145 | + $r['city'] = ""; |
| 146 | + if ( isset( $rec['details']['publish_places'] ) ) { |
| 147 | + foreach ( $rec['details']['publish_places'] as $place ) { |
| 148 | + if ( $r['city'] != "" ) $r['city'] .= '/'; |
| 149 | + $r['city'] .= $place; |
| 150 | + } |
| 151 | + } |
| 152 | + |
| 153 | + $r['LCC'] = ""; |
| 154 | + if ( isset( $rec['details']['lc_classifications'] ) ) { |
| 155 | + foreach ( $rec['details']['lc_classifications'] as $place ) { |
| 156 | + if ( $r['LCC'] != "" ) $r['LCC'] .= ' / '; |
| 157 | + $r['LCC'] .= $place; |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + $r['DDC'] = ""; |
| 162 | + if ( isset( $rec['details']['dewey_decimal_class'] ) ) { |
| 163 | + $r['DDC'] .= $rec['details']['dewey_decimal_class'][ 0 ]; |
| 164 | + } |
101 | 165 | |
| 166 | + $r['LCCN'] = ""; |
| 167 | + if ( isset( $rec['details']['lccn'] ) ) { |
| 168 | + $r['LCCN'] .= $rec['details']['lccn'][ 0 ]; |
| 169 | + } |
| 170 | + |
| 171 | + $r['ISBN10'] = ""; |
| 172 | + if ( isset( $rec['details']['isbn_10'] ) ) { |
| 173 | + $r['ISBN10'] .= $rec['details']['isbn_10'][ 0 ]; |
| 174 | + } |
| 175 | + |
| 176 | + $r['ISBN13'] = ""; |
| 177 | + if ( isset( $rec['details']['isbn_13'] ) ) { |
| 178 | + $r['ISBN13'] .= $rec['details']['isbn_13'][ 0 ]; |
| 179 | + } |
| 180 | + |
| 181 | + $r['series'] = ""; |
| 182 | + if ( isset( $rec['details']['series'] ) ) { |
| 183 | + $r['series'] .= $rec['details']['series'][ 0 ]; |
| 184 | + } |
| 185 | + |
| 186 | + $r['language'] = ""; |
| 187 | + if ( isset( $rec['details']['languages'] ) ) { |
| 188 | + $r['language'] .= $rec['details']['languages'][ 0 ][ 'key' ]; |
| 189 | + $r['language'] = preg_replace( '!^.*/!', '', $r['language'] ); |
| 190 | + } |
| 191 | + |
102 | 192 | return $r; |
103 | 193 | } |
104 | 194 | |