diff --git a/components/library.php b/components/library.php index 8cf6f043b3c807902a9c439a5d6fa33c6c02a16e..0dc2f051b15bca20ec4c6011c1933fae421eca06 100644 --- a/components/library.php +++ b/components/library.php @@ -98,11 +98,27 @@ if (isset($_REQUEST['search']) && (trim($_REQUEST['search']) != "")) { $book['author'] = htmlentities2($book['author']); $book['onloan'] = ($book['onloan'] == 't') ? true : false; - // Extract amazon data (maybe this should be stored in separate field in the db?) - $simple_xml = simplexml_load_string($book['amazon_data']); - //FIXME: figure out how to tell if there was usable amazon data after all - //$book['description'] = $simple_xml->Items->Item->EditorialReviews->EditorialReview->Content; + if (!isset($book['description'])) { + // no book description in the database, try using Amazon data + + // Extract amazon data (maybe this should be stored in separate fields in the db?) + $simple_xml = simplexml_load_string($book['amazon_data']); + + $book['description'] = @$simple_xml->Items->Item->EditorialReviews->EditorialReview->Content; + if (isset($book['description'])) { + // tidy description markup + $tidy_config['doctype'] = 'omit'; + $tidy_config['output-xhtml'] = true; + $tidy_config['show-body-only'] = true; + $tidy_config['logical-emphasis'] = true; + $book['description'] = tidy_repair_string($book['description'], $tidy_config); + + // update db so we don't have to do this next time + $DB->Execute("UPDATE books SET description=? WHERE id=?", array($book['description'],$book['id'])); + } + } + $smarty->assign("book", $book); diff --git a/templates/library-book.tpl b/templates/library-book.tpl new file mode 100644 index 0000000000000000000000000000000000000000..ecb16a9efc566d519ea3b3598f27f7948ce38cf5 --- /dev/null +++ b/templates/library-book.tpl @@ -0,0 +1,23 @@ + +<div class="box"> + <div class="boxhead"><h2>{$book.title}</h2></div> + <div class="boxcontent"> + +{if $editable == true} + <form action="" method="POST"> + <input type="text" name="title" value="{$book.title}" /> + <input type="text" name="author" value="{$book.author}" /> + <input type="text" name="publisher" value="{$book.publisher}" /> + <textarea name="description" value="{$book.description}" /> + </form> +{/if} + <strong>{if $book.onloan}On loan{else}Book Available{/if}</strong> + {if $book.image_url != ""}<img class="emblem" src="{$book.image_url|escape}" alt="{$book.title|escape}" />{/if} + <p>Author: {$book.author}</p> + {if isset($book.description)} + <div>{$book.description}</div> + {/if} + <div class="clear"></div> + </div> + <div class="hollowfoot"><div><div></div></div></div> +</div> diff --git a/templates/library.tpl b/templates/library.tpl index cc736d00237c1b0adeb1caa973b01b712f3033b7..1ff2ea9ab9cc50500f26cb6d0ef17db5eae8e9c0 100644 --- a/templates/library.tpl +++ b/templates/library.tpl @@ -13,20 +13,9 @@ {/foreach} {elseif $mode == 'display'} -<div class="box"> - <div class="boxhead"><h2>{$book.title}</h2></div> - <div class="boxcontent"> - {if $book.image_url != ""}<img class="emblem" src="{$book.image_url|escape}" alt="{$book.title|escape}" />{/if} - <p>{$book.author}</p> - <p>{$book.description}</p> - {if $book.onloan}<p>On loan</p>{else}<p>Book Available</p>{/if} - {if $editable==true} - <p>Loan stuff to people maybe</p> - {/if} - <div class="clear"></div> - </div> - <div class="hollowfoot"><div><div></div></div></div> -</div> + +{include file=library-book.tpl book=$book} + {elseif $mode == 'search'} <h3>Search Results</h3> {if $results|@count < 1}<p>No results found</p> @@ -49,4 +38,4 @@ {if $librarian == true} <p><a href="{$baseurl}/Knowledge/Library/Admin">Library Admin</a></p> {/if} -<p>Images provided by <a href="http://www.amazon.co.uk">Amazon</a></p> +<p>Images and descriptions provided by <a href="http://www.amazon.co.uk">Amazon</a></p>