Changeset 105 for components/library.php
- Timestamp:
- 01/09/06 00:25:34 (7 years ago)
- Files:
-
- 1 modified
-
components/library.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
components/library.php
r97 r105 2 2 3 3 // this component is a mess. That's cause it's not finished yet :-) 4 5 // don't try to convert existing html entities 6 // this could be broken out someplace else 7 function htmlentities2($myHTML) { 8 $translation_table=get_html_translation_table (HTML_ENTITIES,ENT_QUOTES); 9 $translation_table[chr(38)] = '&'; 10 return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($myHTML, $translation_table)); 11 } 4 12 5 13 $library_index = array_search("Library", $pathlist); … … 14 22 $mode = "search"; 15 23 $search = $_REQUEST['search']; 16 $query = "SELECT *FROM books WHERE (title || ' ' || author || ' ' || keywords) ~* ? ORDER BY title ASC";24 $query = "SELECT id, title, onloan FROM books WHERE (title || ' ' || author || ' ' || keywords) ~* ? ORDER BY title ASC"; 17 25 $results = $DB->GetAll($query,array($search)); 26 27 foreach ($results as &$result) { 28 $result['title'] = htmlentities2($result['title']); 29 $result['onloan'] = ($result['onloan'] == 't') ? true : false; 30 } 31 32 $pathlist[] = "Search"; 18 33 $smarty->assign("results", $results); 34 19 35 } elseif (isset($pathlist[$library_index + 1]) && is_numeric($pathlist[$library_index + 1])) { 20 36 // We're displaying a specific book … … 22 38 $book_index = intval($pathlist[$library_index + 1]); 23 39 $results = $DB->GetAll("SELECT * FROM books WHERE id=? LIMIT 1", array($book_index)); 24 $smarty->assign("book", $results[0]); 25 // Edit the path list to make the breadcrumbs tastier 40 41 // Clean up ready for output 42 $book = $results[0]; 43 $book['title'] = htmlentities2($book['title']); 44 $book['author'] = htmlentities2($book['author']); 45 46 // Extract amazon data (maybe this should be stored in separate field in the db?) 47 $simple_xml = simplexml_load_string($book['amazon_data']); 48 $book['description'] = $simple_xml->Items->Item->EditorialReviews->EditorialReview->Content; 49 $smarty->assign("book", $book); 50 51 // Edit the path list to make the breadcrumbs tastier 26 52 $pathlist[$library_index + 1] = $results[0]['title']; 27 $smarty->assign("pathlist", $pathlist);28 53 } else { 29 $smarty->assign("randoms", $DB->GetAll("SELECT * FROM books WHERE image_url IS NOT NULL ORDER BY random() LIMIT 5")); 54 //Nothing being requested, just find some random books to put on main page 55 $smarty->assign("randoms", $DB->GetAll("SELECT * FROM books WHERE image_url IS NOT NULL ORDER BY random() LIMIT 4")); 30 56 } 31 57 … … 33 59 $smarty->assign("mode", $mode); 34 60 $smarty->assign("search", $search); 61 $smarty->assign("pathlist", $pathlist); 35 62 $output = $smarty->fetch("library.tpl"); 36 63 $output2 = $smarty->fetch("library-search.tpl");
