/** * Generate XML for pictorial link with image swapping. * * If uri is null, plain picture is displayed * Width and height of images are auto detected. * If using image swapping, images are preloaded with javascript. * * @param string uri URI to open * @param string filename Filename for image to display. * @param string attr Additional HTML attributes, e.g. "target=main width='100%'" * @param string m_over Filename for image to display when mouse is over image. * Can contain onmouse* -- will merge with our code (our code * will be executed first!). Except for onmouse* $attr is only * added to <img tag. Cannot contain onmouse* code. Refer to $onmouse_merge * @param array otherswap Swap other image: array ($name, $normal, $m_over). * @param array onmouse_merge Addition onmouseover/out code to merge with our: * array ($m_name_merge, $m_out_merge). */ public static function a_img($uri, $filename, $attr = false, $m_over = false, $otherswap = false, $onmouse_merge = false) { // $uri is false, just output picture if (!$uri) { return xml_gen::img($filename); } // Number of times xml_gen::a_img() has been called with $m_over. static $called; // Init $swap_out = false; $swap_over = false; // Generate onmouse* code if ($m_over || $otherswap) { // Increment called var $called++; // Has mouse over? if ($m_over) { $swap_out = "swp('spluf{$called}','spl_f{$called}'); "; $swap_over = "swp('spluf{$called}','splof{$called}'); "; } // Otherswap? if ($otherswap) { list($os_name, $os_normal, $os_m_over) = $otherswap; if (!$os_name || !$os_normal || !$os_m_over) { die("{$otherswap} requires array with three string."); } $swap_out .= "swp('{$os_name}','spl_q{$called}'); "; $swap_over .= "swp('{$os_name}','sploq{$called}'); "; } } // Onmouse* merge`? if ($onmouse_merge) { list($merge_over, $merge_out) = $onmouse_merge; if (!$merge_over || !$merge_out) { die("{$onmouse_merge} requires array with two strings."); } $swap_out .= $merge_out; $swap_over .= $merge_over; } // Set name only if swapping $name = $m_over || $otherswap ? "name='spluf{$called}'" : ""; // Output link and picture $result = xml_gen::a($uri, xml_gen::img($filename, "{$name} {$attr}"), "onclick='this.blur()' onmouseout=\"{$swap_out}\" onmouseover=\"{$swap_over}\""); // If no m_over, return result if (!$m_over && !$otherswap) { return $result; } // Else preload images $result .= "<script type='text/javascript'>\n<!--\n\n"; // On first a_img() call, we insert the swp() javascript function. if ($called == 1) { $result .= "function swp(id,name) { if (document.images) document.images[id].src = eval(name+'.src'); }\n\n"; } // Insert preload code. if ($m_over) { $result .= "if (document.images) {\r\n spl_f{$called} = new Image; spl_f{$called}.src = '{$filename}';\r\n splof{$called} = new Image; splof{$called}.src = '{$m_over}';\r\n }"; } // Insert preload code - otherswap if ($otherswap) { $result .= "if (document.images) {\r\n spl_q{$called} = new Image; spl_q{$called}.src = '{$os_normal}';\r\n sploq{$called} = new Image; sploq{$called}.src = '{$os_m_over}';\r\n }"; } return $result . "\n\n// -->\n</script>"; }
/** * Common XHTML header * * @param string title Title * @param string up Uri to up button or false * @param string play Uri to play button or false * @param bool sort Sort buttons active * @param bool numbers Show numbers button active */ protected function head($title, $up = false, $play = false, $sort = false, $numbers = false) { echo parent::head($title); // initialize tool tips $this->tool_tips = new tool_tips(); $g = new xml_gen(); // generate menu xml // up button $menu_xml[] = $up ? $g->a_img($up, 'images/up.png', "alt='Up one level' title='Up one level'", 'images/up-c.png') : $g->img('images/up-g.png'); // play button $menu_xml[] = $play ? $g->a_img("./?action=play&location={$play}", 'images/play.png', "alt='Play all tracks' title='Play all tracks'", 'images/play-c.png') : $g->img('images/play-g.png'); // spacer $menu_xml[] = $g->space(); // search button $menu_xml[] = $g->a_img("./?action=search", 'images/search.png', "alt='Search Metadata' title='Search Metadata'", 'images/search-c.png'); // stats button $menu_xml[] = $g->a_img("./?action=stats", 'images/stats.png', "alt='Statictics' title='Statictics'", 'images/stats-c.png'); // config button $menu_xml[] = $g->a_img('./?action=config', 'images/config.png', "alt='Configuration' title='Configuration'", 'images/config-c.png'); // all music link artist search $amg_link = $this->action != 'toc' ? "javascript:document.forms.AMG.submit()" : "http://www.allmusic.com/"; $menu_xml[] = $g->a_img($amg_link, 'images/amg.png', "alt='All Music Guide' title='All Music Guide'", 'images/amg-c.png'); // google image search $goo_link = $this->action != 'toc' ? "javascript:google()" : "http://www.google.com/"; $menu_xml[] = $g->a_img($goo_link, 'images/google.png', "alt='Google Image Search' title='Google Image Search'", 'images/google-c.png'); // spacer $menu_xml[] = $g->space(); // numbers button $img = @$_COOKIE['show_numbers'] ? 'numb' : 'num0'; $menu_xml[] = $numbers ? $g->a_img($_SERVER['REQUEST_URI'] . '&set_show_numbers=1', "images/{$img}.png", "alt='Toggle track numbers' title='Toggle track numbers'", "images/{$img}-c.png") : $g->img("images/{$img}-g.png"); // playing time button $img = @$_COOKIE['show_playtime'] ? 'time' : 'time0'; $menu_xml[] = $sort ? $g->a_img($_SERVER['REQUEST_URI'] . '&set_show_playtime=1', "images/{$img}.png", "alt='Toggle playing time' title='Toggle playing time'", "images/{$img}-c.png") : $g->img("images/{$img}-g.png"); // sort alpha button $img = $this->get_sort_mode(); $menu_xml[] = $sort ? $g->a_img($_SERVER['REQUEST_URI'] . '&set_sort_alpha=1', "images/{$img}.png", "alt='Toggle sort moder' title='Toggle sort mode'", "images/{$img}-c.png") : $g->img("images/{$img}-g.png"); // sort desc button $img = $this->get_sort_direction(); $menu_xml[] = $sort ? $g->a_img($_SERVER['REQUEST_URI'] . "&set_sort_mode=1", "images/{$img}.png", "alt='Toggle sort direction' title='Toggle sort direction'", "images/{$img}-c.png") : $g->img("images/{$img}-g.png"); // output menu and title in main table $this->t = new table(2, "id='main'"); $this->t->data(null, "id='menu'"); $t = new table(1); foreach ($menu_xml as $xml) { $t->data($xml); } $t->done(); $this->t->data($g->h1($title), "id='body'"); // all music guide code $search_string = ereg("^[#@!\\+]?([^:]+)", $title, $regs) ? $regs[1] : ""; // first part of title - split by :, remove special chars echo "\n <form action='http://www.allmusic.com/cg/amg.dll' method='post' target='AMG' name='AMG'>\n <input type='hidden' name='P' value='amg' />\n <input type='hidden' name='uid' value='SEARCH' />\n <input type='hidden' name='sql' value=\"{$search_string}\" />\n <input type='hidden' id='buttons' name='opt1' value='1' />\n </form>\n "; // google image search code $search_string = urlencode(utf8_decode(str_replace(":", '', $title))); echo "\n <script type='text/javascript'>\n <!--\n function google()\n {\n window.open('http://images.google.com/images?as_q={$search_string}&svnum=10&hl=en&imgsz=medium|large|xlarge&safe=off', 'google2', 'resizable,scrollbars,menubar,status,toolbar,location')\n window.open('http://images.google.com/images?as_q={$search_string}&svnum=10&hl=en&imgsz=xxlarge&safe=off', 'google1', 'resizable,scrollbars,menubar,status,toolbar,location')\n }\n //-->\n </script>\n "; // maximize browser window? if ($this->browser_behaviour == 'maximize') { echo "\n <script type='text/javascript'>\n <!--\n self.moveTo(0,0);\n self.resizeTo(screen.availWidth, screen.availHeight);\n // -->\n </script>\n "; } }