$_GET['off'], 'category' => $_GET['g'], 'switch' => $_GET['x'], 'paging' => true, 'page_size' => $page_size, 'page' => $_GET['p'], 'cache_time' => 60*60, ); $ART = array( 'brief' => true ); $ARTIST = array( 'brief' => true ); $COUNT; if (!$LOAD_BROWSE_AS_LIBRARY) { // switch based on the switch var switch ($_GET['x']) { // VIEW SINGLE ITEM // display a single piece of art case 'art': $ART['show_image'] = true; display_single(display_art($_GET['art_id'])); break; // display a single artist case 'artist': $ARTIST['view_art'] = true; display_single(display_artist($_GET['artist_id'])); break; // ALPHA case 'art_alpha': do_browse_alpha('Art', 'title'); break; case 'artists_alpha': do_browse_alpha('Artist', 'last_name'); break; // CATEGORICAL case 'media': do_browse('Art', 'media'); break; case 'style': do_browse('Art', 'style'); break; case 'subject': do_browse('Art', 'subject'); break; case 'category': do_browse('Art', 'media_category'); break; case 'collection': do_browse('Art', 'collection'); break; case 'year': $PAGE['cat_mod'] = 14; do_browse('Art', 'date_of_work'); break; // SPECIAL // display by location case 'location': require_once 'Location.php'; set_categories('location','name'); $g_tmp = $PAGE['category']; // find location id $PAGE['category'] = end($b = (array)end(focus_db_fetch("SELECT location_id FROM location WHERE name = '".addslashes($g_tmp)."'"))); // display the matching objects $objects = FOCUS_DB_Object::fetchSimilar('Art', sql_suffix('location_id')); $PAGE['category'] = $g_tmp; $PAGE['cat_mod'] = 3; display($objects); break; // on no match, redirect to the gallery default: //focus_redirect('/collections/index.html'); } // display it $page->toHTML(); } /** DISPLAY FUNCTIONS **/ // set or get the settings function &settings(&$settings /* ... */) { // get the arguments $args = (array)array_slice(func_get_args(),1); while (list($_,$arg) = each($args)) { if ($arg{0} === '~') $settings[substr($arg,1)] = false; else if ($arg{0} === '=') list($_,$settings[substr($arg,1)]) = each($args); else $settings[$arg] = true; } } // display an array of objects function display($objects) { global $COUNT; if ($_GET['x'] != "year") { $COUNT = count($objects); } if (!empty($objects)) $class = get_class($objects[0]); if ($class === 'Artist') foreach ($objects AS $obj) $items[] = display_artist($obj); elseif ($class === 'Art') foreach ($objects AS $obj) $items[] = display_art($obj); display_page($items); } // display just one item function display_single($item) { global $tpl; if ($item === null) $tpl->touchBlock('invalid'); else $tpl->setVariable('single_item', $item); } // display an item on the page function display_page(&$items) { global $tpl, $PAGE, $COUNT; // browse by category if ($PAGE['categories']) { $q = get_query_string('[gp]'); $cat_count = count($PAGE['categories'])-1; $mod = $PAGE['cat_mod'] ? $PAGE['cat_mod'] : ($PAGE['alpha'] ? 10 : 5); if ($PAGE['alpha'] && $PAGE['categories']['Other']) { $tmp = $PAGE['categories']['Other']; unset($PAGE['categories']['Other']); $PAGE['categories']['Other'] = $tmp; } if($PAGE["alpha"]) { $count = 0; $cat_number = sizeof($PAGE['categories']); foreach (array_keys($PAGE['categories']) AS $i => $category) { $tpl->setVariable('category', $category); if ($category == $PAGE['category']) $tpl->setVariable('selected',"Selected"); else { $tpl->setVariable('query', $q); $tpl->setVariable('category_q', urlencode($category)); } $tpl->parse('category'.($category == $PAGE['category'] ? '_selected' : '')); if($count + 1 != $cat_number) $tpl->touchBlock("divider"); $tpl->parse('by_alpha'); $count++; } } else { foreach(array_keys($PAGE['categories']) AS $i => $category) { if ($category == $PAGE['category']) $selected = " selected"; else $selected = ""; $options .= "\n\t"; } $category_select = "\n"; $tpl->setVariable("category_select", $category_select); } } // paging if ($_GET['x'] != "year") $PAGE['count'] = $PAGE['categories'][$PAGE['category']]; else $PAGE['count'] = $COUNT; if ($PAGE['paging'] && $PAGE['count'] > $PAGE['page_size']) { $q = get_query_string('page'); // determine the page count $page_count = ceil($PAGE['count']/$PAGE['page_size']); // validate the page $PAGE['page'] = (int)min($PAGE['page'],$page_count); $PAGE['page'] = (int)max($PAGE['page'],1); // prev/next buttons //print("PAGE['page']: ".$PAGE['page']." \$page_count: $page_count"); $tpl->setVariable('no_prev', ($PAGE['page']>1?'':'!')); $tpl->setVariable('prev_page', $PAGE['page']-1); $tpl->setVariable('no_next', ($PAGE['page']<$page_count?'':'!')); $tpl->setVariable('next_page', $PAGE['page']+1); $tpl->setVariable('query2', $q); /*if ($PAGE['page'] > 1) $tpl->setVariable('no_prev', ''); else $tpl->setVariable('no_prev', '!'); $tpl->setVariable('prev_page', $PAGE['page']-1); if ($PAGE['page'] < $page_count) $tpl->setVariable('no_next', ''); else $tpl->setVariable('no_next', '!'); $tpl->setVariable('next_page', $PAGE['page']+1); $tpl->setVariable('query2', $q);*/ // page numbers for ($i=1; $i<=$page_count; $i++) { $tpl->setVariable('page_num', $i); $tpl->setVariable('query', $q); if($i == $PAGE['page']) $tpl->setVariable("selected", "Selected"); $tpl->parse('page'); } $tpl->parse('paging'); } /* // display the items $count = 1; foreach ((array)$items AS $item) { $tpl->setVariable('item', $item); $tpl->parse('item'); if($count == ceil($PAGE["page_size"] / 2)) { $tpl->touchBlock("column_spacer"); $tpl->parse('new_column'); } $count++; } */ /*print("
");
print_r($items);
print("
");*/ // ====REARRANGE ITEMS ARRAY TO PRINT ORDER TOP-BOTTOM, LEFT-RIGHT====\\ // maximum number of columns in table $max_columns = 2; // calculate size to split array into $split_size = ceil(sizeof($items)/$max_columns); if ($split_size < 1) $split_size = 1; // split array if (!empty($items)) $itemsSplit = array_chunk($items, $split_size, false); // New array to create @$itemsNew; // calculate maximum length of columns $max = 0; if (!empty($itemsSplit)) { foreach ($itemsSplit as $items) { if (count($items) > $max) $max = count($items); } // end foreach } // copy $items[0][0], $items[1][0], $items[1][0], $items[1][1], $items[2][0], $items[2][1] ... etc into $itemsNew (assuming $max_columns == 2) for($i = 0; $i < $max; $i++) { for($j = 0; $j < count($itemsSplit); $j++) { if (isset($itemsSplit[$j][$i])) $itemsNew[] = $itemsSplit[$j][$i]; } // end for } // end for /*print("
");
print_r($itemsSplit);
print_r($itemsNew);
print("
");*/ // fill in item table (Left-Right Top-Bottom) $index = 0; // index into $item array $item_count = count((array)$itemsNew); // number of items while ($index < $item_count) { // parse each for ($column = 0; ($column < $max_columns && $index < $item_count); $column++) { // parse each // set variables $tpl->setVariable('item', $itemsNew[$index]); $tpl->parse("item"); $index++; } // end for () $tpl->parse("item_row"); } // end while () } // display an artist function display_artist($artist) { require_once 'functions.inc'; global $ARTIST; static $tpl; if (!$tpl) $tpl = focus_load_template('browse_artist'); if (!is_object($artist)) { require_once 'Artist.php'; $artist = new Artist($artist); if (!$artist->isLoaded()) return null; } // display brief only if ($ARTIST['brief']) { if($_REQUEST["artist_id"]) { $tpl->setVariable('view_single_full_name', $artist->getFullName()); $tpl->setVariable("view_single_dates",$artist->getDates()); if(file_exists($_SERVER[DOCUMENT_ROOT] . "/images/artists/" . $artist->artist_id . ".jpg")) { $view_single_src = "/images/artists/" . $artist->artist_id . ".jpg"; } elseif(file_exists($_SERVER[DOCUMENT_ROOT] . "/images/artists/" . $artist->artist_id . ".GIF")) { $view_single_src = "/images/artists/" . $artist->artist_id . ".GIF"; } $tpl->setVariable("view_single_src",$view_single_src); $tpl->setVariable($artist->dump()); $tpl->setVariable("bio",$artist->bio); $tpl->parse("view_single"); } else { $tpl->setVariable('view_multiple_full_name', $artist->getFullName()); $tpl->setVariable("view_multiple_dates", $artist->getDates()); $tpl->setVariable('view_multiple_artist_id', $artist->artist_id); } // display full info } else { $tpl->setVariable($artist->dump()); } // display art by this artist if ($ARTIST['view_art']) { require_once 'Image.php'; foreach (FOCUS_DB_Object::fetchSimilar('Art'," AND artist_id = $artist->artist_id ORDER BY title") AS $art) { $tpl->setVariable($art->dump()); $tpl->setVariable('thumb', Image::getThumbPath($art->art_id)); $tpl->setVariable('art_artist_full_name', $artist->getFullName()); $tpl->setVariable('url_art_title', format_url_param($art->title)); if($art->date_of_work) $tpl->setVariable("art_date","(" . $art->date_of_work . ")"); $tpl->parse('art'); } } // return the template contents $tpl->parse(); $html = $tpl->get(); $tpl->blockdata = array(); return $html; } // display a piece of art function display_art($art) { require_once 'functions.inc'; global $ART; static $tpl; if (!$tpl) $tpl = focus_load_template('browse_art'); if (!is_object($art)) { require_once 'Art.php'; $art = new Art($art); if (!$art->isLoaded()) return null; } // display artist require_once 'Artist.php'; $artist = new Artist($art->artist_id); if ($artist->isLoaded()) { $tpl->setVariable('artist_full_name', $artist->getFullName()); $tpl->setVariable('artist_artist_id', $artist->artist_id); $tpl->setVariable('url_artist_full_name', format_url_param($artist->getFullName())); $tpl->parse("artist"); //print_r($tpl); //if($art->date_of_work) $tpl->setVariable("artist_date","(" . $art->date_of_work . ")"); } // display brief only if ($ART['brief']) { require_once 'Image.php'; if($_REQUEST["art_id"]) { $tpl->setVariable("view_single_title", "". $art->title); $tpl->setVariable("view_single_date", "(".$art->date_of_work.")"); $tpl->setVariable("view_single_art_id", $art->art_id); $tpl->setVariable("media", $art->media); if($art->style) $tpl->setVariable("style", $art->style); if($art->description) $tpl->setVariable("description", $art->description); if($art->hi && $art->wi) $art_size = $art->hi." x ".$art->wi; if($art->di) $art_size .= " x ".$art->di; if (!empty($art_size)) $tpl->setVariable("size", $art_size); } else { $tpl->setVariable('view_multiple_title', "". $art->title . " (" . $art->date_of_work .")"); $tpl->setVariable('view_multiple_art_id', $art->art_id); $tpl->setVariable('view_multiple_url_art_title', format_url_param($art->title)); } if(!$ART['show_image']) { $tpl->setVariable('thumbnail_src', Image::getThumbPath($art->art_id)); $tpl->setVariable('thumbnail_art_id', $art->art_id); $tpl->setVariable('thumbnail_url_art_title', format_url_param($art->title)); } // display full info } else { $tpl->setVariable($art->dump()); } // display images if ($ART['show_image']) { require_once 'Image.php'; $images = Image::fetchByArtId($art->art_id); $tpl->setVariable('donor_credit', $art->donor_credit); $num_images = count($images); if ($images[$num_images - 4]) { $use_this_image = $images[$num_images - 4]; } foreach ($images AS $image) { if ($use_this_image) { $tpl->setVariable('image', $use_this_image->getPath()); $tpl->setVariable('donor_credit', $art->donor_credit); $image_exists = true; $image_count++; } elseif ($image->gallery == 1) { $tpl->setVariable('image', $image->getPath()); $tpl->setVariable('donor_credit', $art->donor_credit); $image_exists = true; } else $image_count++; list($w,$h) = $image->getDimensions(); $sizes[] = sprintf('%dx%d', $w, $h); } if(!$image_exists) $tpl->setVariable("image","/images/no_image_240.gif"); // display zoom option if ($image_count) { ///////// // zoom option if ($images[0] && file_exists($_SERVER['DOCUMENT_ROOT'] . $images[0]->getPath())) { $min_width = 300; // for small image use first image that is at least min_width wide foreach ($images as $image) { if ($image->_width >= $min_width) { $small_image = $image->getPath(); break; } } //$small_image = $images[0]->getPath(); $large_image = $images[count($images) - 1]->getPath(); // get magnification magnitude $small_image_size = getimagesize($_SERVER['DOCUMENT_ROOT'] . $small_image); $large_image_size = getimagesize($_SERVER['DOCUMENT_ROOT'] . $large_image); // w1xh1 // w2xh2 // h1=(w1xh2/w2) $small_image_width = $min_width; $small_image_height = $min_width * $small_image_size[1] / $small_image_size[0]; $magnification_x = $large_image_size[0] / $small_image_width; $tpl->setVariable("magnification_x", $magnification_x); $magnification_y = $large_image_size[1] / $small_image_height; $tpl->setVariable("magnification_y", $magnification_y); $tpl->setVariable("small_image_width", $small_image_width); $tpl->setVariable("small_image_height", $small_image_height); $tpl->setVariable("x_center_offset", $small_image_size[0] / 32); $tpl->setVariable("y_center_offset", $small_image_size[1] / 32); $tpl->setVariable("small_image", $small_image); $tpl->setVariable("large_image", $large_image); $tpl->setVariable(get_object_vars($art)); $tpl->setVariable("min_width", $min_width); $tpl->parse("zoom_tool"); } else { $tpl->touchBlock("no_image_available"); } ///////// $tpl->setVariable('zoom_count', count($images)); $tpl->setVariable('zoom_sizes', implode(', ', $sizes)); $tpl->setCurrentBlock("image"); $tpl->setVariable('zoom_art_id', $art->art_id); $tpl->setVariable("zoom_artist_id",$art->artist_id); $tpl->setVariable('zoom_url_art_title', format_url_param($art->title)); $tpl->parseCurrentBlock("image"); $tpl->setCurrentBlock("zoom"); $tpl->setVariable('zoom_art_id', $art->art_id); $tpl->setVariable("zoom_artist_id",$art->artist_id); $tpl->setVariable('zoom_url_art_title', format_url_param($art->title)); $tpl->parseCurrentBlock("zoom"); } } // return the template contents $tpl->parse(); $html = $tpl->get(); $tpl->blockdata = array(); return $html; } // returns the query string with the selected key/value pair stripped function get_query_string(/*...*/) { $q = $_SERVER['QUERY_STRING']; foreach (func_get_args() AS $arg) $q = preg_replace("/(^$arg=[^&]*[&]?|&$arg=[^&]*)/",'',$q); return $q; } // fix the categories function set_categories_alpha_callback() { global $PAGE; $null_count = 0; $categories = array(); foreach ($PAGE['categories'] AS $key => $value) { $key = strtoupper($key); if ($key >= 'A' && $key <= 'Z') $categories[$key] += $value; else $null_count += $value; } if ($null_count) $categories['Other'] = $null_count; $PAGE['categories'] = $categories; } // fetch and set the categories function set_categories($table, $field, $where='', $callback=null) { global $PAGE,$tpl; // alpha browsing if ($PAGE['alpha']) $field = "IF($field >= 'A',LEFT($field,1),'Other')"; // get the filename $filename = $_SERVER['DOCUMENT_ROOT'].'/_browse_'.$_GET['x'].'.pdat'; // if year if ($_GET['x'] == "year") { /* $rows[] = array("year" => "1539 - 1799"); for($i = 1800;$i < 2000;$i+=10) { $start_year = $i; $end_year = $i + 9; $rows[] = array("year" => "$start_year - $end_year"); } $rows[] = array("year" => "2000 - " . date("Y",time())); foreach ($rows as $row) $PAGE['categories'][$row['year']] = $row['year']; */ $dates = explode(" - ",$_GET['g']); $start_date = $dates[0]; $end_date = $dates[1]; $tpl->setVariable("start_year", $start_date); $tpl->setVariable("end_year", $end_date); } // end if // try to load the categories from disk else if (file_exists($filename) && filemtime($filename) > (time()-$PAGE['cache_time'])) { ob_start(); readfile($filename); $PAGE['categories'] = unserialize(ob_get_contents()); ob_end_clean(); // load the categories from the database } else { $PAGE['categories'] = array(); foreach (focus_db_fetch_index("SELECT $field, COUNT(*) FROM $table WHERE 1 $where GROUP BY 1 ORDER BY 1") AS $cat) if ($cat[0]) $PAGE['categories'][$cat[0]] = $cat[1]; // save the categories $fh = fopen($filename,'w'); fwrite($fh,serialize($PAGE['categories'])); fclose($fh); } // set the category if necessary //if (!in_array((string)$PAGE['category'],$keys = array_keys($PAGE['categories']))) // $PAGE['category'] = $keys[0]; } // creates the sql suffix for an alpha browse function sql_suffix($field) { global $PAGE; $order_by = $field; if ($_GET['x'] != 'artists_alpha') $order_by .= ', title'; // do limit setting $page = (int)min($PAGE['page'],ceil($PAGE['categories'][$PAGE['category']]/$PAGE['page_size'])); $page = (int)max($page,1); // alpha browse if ($PAGE['alpha']) { if ($PAGE['category'] != 'Other') return " AND $field LIKE '".addslashes($PAGE['category'])."%' ORDER BY $order_by LIMIT ".($PAGE['page_size']*($page-1)).", ${PAGE['page_size']} "; else return " AND $field < 'A' ORDER BY $order_by LIMIT ".($PAGE['page_size']*($page-1)).", ${PAGE['page_size']} "; // full text browse } else if ($_GET['x'] == "year") { $dates = explode(" - ",$_GET['g']); $start_date = $dates[0]; $end_date = $dates[1]; $where = "date_of_work>=$start_date AND date_of_work<=$end_date"; return " AND $where ORDER BY $order_by LIMIT ".($PAGE['page_size']*($page-1)).", ${PAGE['page_size']} "; } else { if ($field == "collection") return " AND $field = '".addslashes($PAGE['category'])."' ORDER BY artist_id LIMIT ".($PAGE['page_size']*($page-1)).", ${PAGE['page_size']} "; else return " AND $field = '".addslashes($PAGE['category'])."' ORDER BY $order_by LIMIT ".($PAGE['page_size']*($page-1)).", ${PAGE['page_size']} "; } } // fetch the objects function do_browse_alpha($class, $field) { global $PAGE; $PAGE['alpha'] = true; do_browse($class, $field); } function do_browse($class, $field) { global $PAGE,$ARTIST,$ART; require_once "$class.php"; $class = strtolower($class); set_categories($class,$field); $dates = explode(" - ",$_GET['g']); $start_date = $dates[0]; $end_date = $dates[1]; if ($_GET['x'] == "year") { global $COUNT; $COUNT = count(focus_db_fetch("SELECT date_of_work FROM art WHERE date_of_work<=$end_date AND date_of_work>=$start_date")); } // end if display(FOCUS_DB_Object::fetchSimilar($class, sql_suffix($field))); }