Changeset 105 for components/library.php

Show
Ignore:
Timestamp:
01/09/06 00:25:34 (7 years ago)
Author:
dez
Message:

Lots of chckens changes
Database dump

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • components/library.php

    r97 r105  
    22 
    33// 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 
     7function 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} 
    412 
    513$library_index = array_search("Library", $pathlist); 
     
    1422        $mode = "search"; 
    1523        $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"; 
    1725        $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"; 
    1833        $smarty->assign("results", $results); 
     34 
    1935} elseif (isset($pathlist[$library_index + 1]) && is_numeric($pathlist[$library_index + 1])) { 
    2036// We're displaying a specific book 
     
    2238        $book_index = intval($pathlist[$library_index + 1]); 
    2339        $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 
    2652        $pathlist[$library_index + 1] = $results[0]['title']; 
    27         $smarty->assign("pathlist", $pathlist); 
    2853} 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")); 
    3056} 
    3157 
     
    3359$smarty->assign("mode", $mode); 
    3460$smarty->assign("search", $search); 
     61$smarty->assign("pathlist", $pathlist); 
    3562$output = $smarty->fetch("library.tpl"); 
    3663$output2 = $smarty->fetch("library-search.tpl");