"Fossies" - the Fresh Open Source Software Archive

Member "betterawstats/core/display_helpers.php" (18 Mar 2008, 30092 Bytes) of package /linux/www/old/betterawstats-1.0.zip:


The requested HTML page contains a <FORM> tag that is unusable on "Fossies" in "automatic" (rendered) mode so that page is shown as HTML source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "display_helpers.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 /**
    3  * betterawstats - an alternative display for awstats data
    4  *
    5  * @author      Oliver Spiesshofer, support at betterawstats dot com
    6  * @copyright   2008 Oliver Spiesshofer
    7  * @version     1.0
    8  * @link        http://betterawstats.com
    9 
   10  * Based on the GPL AWStats Totals script by:
   11  * Jeroen de Jong <jeroen@telartis.nl>
   12  * copyright   2004-2006 Telartis
   13  * version 1.13 (http://www.telartis.nl/xcms/awstats)
   14  *
   15  * This program is free software; you can redistribute it and/or
   16  * modify it under the terms of the GNU General Public License
   17  * as published by the Free Software Foundation; either version 2
   18  * of the License, or (at your option) any later version.
   19  *
   20  * This program is distributed in the hope that it will be useful,
   21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   23  * GNU General Public License for more details.
   24  *
   25  * You should have received a copy of the GNU General Public License
   26  * along with this program; if not, write to the Free Software
   27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   28  */
   29 
   30 /**
   31  * File contents:
   32  *
   33  * This file contains various functions which generate output to the browser.
   34  * Mainly it contains the index-function that builds the whole site. Other functions
   35  * create menus, links, images etc.
   36  */
   37 
   38 // this file can't be used on its own
   39 if (strpos ($_SERVER['PHP_SELF'], 'display_helpers.php') !== false) {
   40     die ('This file can not be used on its own!');
   41 }
   42 
   43 /*
   44 * Display Helper Function: run the menus and render the whole page
   45 * called by index.php and baw_action_get_fulltable() as well as config manager
   46 *
   47 * @param    arr     $settings   the 'set'-array from the config for a display section
   48 * @return   str     HTML
   49 *
   50 */
   51 function baw_display_index($settings = array()) {
   52     global $BAW_CONF, $BAW_CONF_DIS, $BAW_CONF_DIS_DEF, $BAW_MES, $BAW_LIB;
   53     global $BAW_DFILES, $BAW_CURR, $BAW_D;
   54 
   55     // this comes second since site_name is unknown otherwise
   56     echo baw_site_header($BAW_CURR['site_name']);
   57     $content = baw_top_menu_bar()
   58         . "<div class=\"contentbox\">\n";
   59     $tmp = array(); // temp array where we record which section has data to show/hide menu options
   60 
   61     // sort the charts according to order in config
   62     $BAW_CONF_DIS = baw_array_sorting($BAW_CONF_DIS, 'order', SORT_ASC);
   63     // ---------- CONTENT BOX --------------------------------------------------
   64     // this should be removed once we move to beta.
   65 
   66     if ($BAW_CURR['site_name'] == 'all_months') {
   67         $settings['section'] = "months";
   68         $section = $settings['section'];
   69         $function = "baw_display_$section";
   70         $temp_conf = $BAW_CONF_DIS[$section];
   71         $temp_conf['chart'] = true;
   72         $temp_conf['table'] = false;
   73         $temp_conf['name'] = $BAW_CONF_DIS_DEF[$section]['name'];
   74         baw_debug("Printing Stats for: " . $BAW_CONF_DIS_DEF[$section]['name']);
   75         $content .= $function($temp_conf);
   76     } else if ($BAW_CURR['site_name'] == 'all_days') {
   77         $settings['section'] = "days";
   78         $section = $settings['section'];
   79         $function = "baw_display_$section";
   80         $temp_conf = $BAW_CONF_DIS[$section];
   81         $temp_conf['chart'] = true;
   82         $temp_conf['table'] = false;
   83         $temp_conf['name'] = $BAW_CONF_DIS_DEF[$section]['name'];
   84         baw_debug("Printing Stats for: " . $BAW_CONF_DIS_DEF[$section]['name']);
   85         $content .= $function($temp_conf);
   86     } else if (isset($settings['section'])) {
   87         $section = $settings['section'];
   88         $function = "baw_display_$section";
   89         $temp_conf = $BAW_CONF_DIS[$section];
   90         $temp_conf['top_x'] = $BAW_CONF['maxlines'];
   91         $temp_conf['name'] = $BAW_CONF_DIS_DEF[$section]['name'];
   92         baw_debug("Printing Stats for: " . $BAW_CONF_DIS_DEF[$section]['name']);
   93         $content .= baw_section_header($section, $temp_conf['name'], false, 'menu_section')
   94             . $function($temp_conf)
   95             .  baw_section_footer();
   96     } else {
   97         $content .= "\n<!-- CONTENT START ++++++++++++++++++++++++++++++++++++++ -->\n";
   98         if ($BAW_CONF['layout_type'] == 'horizontal') {
   99             foreach ($BAW_LIB['item_groups'] as $group => $group_details) {
  100                 $group_items = $group_details['members'];
  101                 $menubuttons = "<div class=\"clearfix\">";
  102                 $stats_section = '';
  103                 $item_id = 0;
  104                 $count_members = count($group_details['members']);
  105                 foreach ($group_details['members'] as $item) {
  106                     $sect_data = $BAW_CONF_DIS[$item];
  107                     $sect_data['name'] = $item;
  108                     $function = "baw_display_$item";
  109                     if (function_exists($function)) {
  110                         baw_debug("Printing Stats for: $function");
  111                         $stats_html = $function($sect_data);
  112                         if ($sect_data['show'] == true &&
  113                             (strlen($stats_html)> 1 || !$BAW_CONF['hideempty'])) {
  114                             $stats_section .= "\n<!-- ITEM {$BAW_CONF_DIS_DEF[$item]['name']} START ++++++++++++++++++++++++++++++++++++++ -->\n";
  115                             $button_title = $BAW_CONF_DIS_DEF[$item]['name'];
  116                             if ($item_id == 0) {
  117                                 $button_class = "menu_button_active";
  118                             } else {
  119                                 $button_class = "menu_button_inactive";
  120                             }
  121                             $menubuttons .= "<div class=\"$button_class\" id=\"button_{$group}_$item_id\" onClick=\"toggleBox($item_id, '$group', $count_members, 'menu');\">$button_title</div>\n";
  122                             if ($item == 'weekdays' && !isset($BAW_CURR['wdays']['count'])) {
  123                                 $setarr = array('collapse' => false, 'chart' => false,'table' => false);
  124                                 baw_display_weekdays($setarr);
  125                             }
  126                             $title = $BAW_CONF_DIS_DEF[$item]['name'];
  127                             $collapse = $sect_data['collapse'];
  128                             $name = "{$group}_$item_id";
  129                             $collapse = false;
  130                             if ($item_id == 0) {
  131                                 $class = 'menu_section_active';
  132                             } else {
  133                                 $class = 'menu_section_inactive';
  134                             }
  135                             $stats_section .= baw_section_header($name, $title, $collapse, $class)
  136                                 . $stats_html
  137                                 . baw_section_footer();
  138                             $tmp[$item] = true;
  139                             $stats_section .= "\n<!-- ITEM $item END ++++++++++++++++++++++++++++++++++++++ -->\n";
  140                             $item_id++;
  141                         } else {
  142                             $tmp[$item] = false;
  143                         }
  144                     }
  145                 }
  146                 if (strlen($stats_section) > 1) {
  147                     $content .= "\n<!-- GROUP $group START ++++++++++++++++++++++++++++++++++++++ -->\n";
  148                     $content .= baw_section_header($group, $group_details['title'], false, 'group_title');
  149                     $menubuttons .= "</div>";
  150                     $content .= $menubuttons . "\n$stats_section\n";
  151                     $content .= baw_section_footer();
  152                     $content .= "\n<!-- GROUP $group END ++++++++++++++++++++++++++++++++++++++ -->\n";
  153                     $tmp[$group] = true;
  154                 } else {
  155                     $tmp[$group] = false;
  156                 }
  157             }
  158         } else {
  159             foreach ($BAW_CONF_DIS as $section => $sect_data) {
  160                 $stats_html = '';
  161                 $content .= "\n<!-- ITEM $section START ++++++++++++++++++++++++++++++++++++++ -->\n";
  162                 $title = $BAW_CONF_DIS_DEF[$section]['name'];
  163                 $collapse = $sect_data['collapse'];
  164                 $name = $section;
  165                 $sect_data['name'] = $section;
  166                 $function = "baw_display_$section";
  167                 if ($sect_data['show'] == true && function_exists($function)) {
  168                     baw_debug("Printing Stats for: baw_display_$section");
  169                     $stats_html = $function($sect_data);
  170                     if (strlen($stats_html)> 1) {
  171                         $content .= baw_section_header($name, $title, $collapse, 'menu_section')
  172                             . $stats_html
  173                             . baw_section_footer();
  174                         $tmp[$section] = true;
  175                     } else {
  176                         $tmp[$section] = false;
  177                     }
  178                 }
  179                 $content .= "\n<!-- ITEM $section END ++++++++++++++++++++++++++++++++++++++ -->\n";
  180             }
  181         }
  182         $content .= "\n<!-- CONTENT END ++++++++++++++++++++++++++++++++++++++ -->\n";
  183     }
  184 
  185     $content .= "</div>";
  186     baw_debug("Starting to build menu");
  187     // ---- MENU BOX -----------------------------------------------------------
  188     $menubox = "\n\n<!-- MENU START ++++++++++++++++++++++++++++++++++++++ -->\n"
  189         . "<div class=\"menubox\">\n"
  190         . baw_sites_dropdown();
  191     $qstrng = '';
  192     if (strlen($_SERVER['QUERY_STRING']) > 0) {
  193         $qstrng = '?' .$_SERVER['QUERY_STRING'];
  194     }
  195     $url = "{$BAW_CONF['site_url']}/index.php$qstrng";
  196     $menubox .= "    <ul class=\"menu\" >\n"
  197         . "        <li class=\"menu_even\">\n"
  198         . "            "
  199         . baw_create_link($BAW_MES[77], "$url#", array('class' => 'leftlink')) . "\n "
  200         . "        </li>\n";
  201     $c = 1; // top link was '0'
  202     if ($BAW_CURR['site_name'] == 'all_months' or $BAW_CURR['site_name'] == 'all_days') {
  203         $sites = array_keys($BAW_DFILES);
  204         foreach ($sites as $site) {
  205             $class = baw_even($c, 'menu_even', 'menu_odd');
  206             $menubox .= "        <li class=\"$class\">\n"
  207                 . "            " . baw_create_link($site, "$url#site_$site") . "\n"
  208                 . "        </li>\n";
  209             $c++;
  210         }
  211     } else {
  212         if ($BAW_CONF['layout_type'] == 'horizontal') {
  213             foreach ($BAW_LIB['item_groups'] as $group => $group_details) {
  214                 if ($tmp[$group]) {
  215                     $class = baw_even($c, 'menu_even', 'menu_odd');
  216                     $name = $group_details['title'];
  217                     $menubox .= "        <li class=\"$class\">\n"
  218                         . "            " . baw_create_link($name, "$url#h2_$group") . "\n"
  219                         . "        </li>\n";
  220                     $c++;
  221                 }
  222             }
  223         } else if (isset($settings['section'])) {
  224             // we are doing a full list
  225             $url = str_replace('&action=get_fulltable&what='. $settings['section'], '', $url);
  226             $menubox .= "        <li class=\"menu_odd\">\n"
  227                 .  baw_create_link($BAW_MES['back'], $url) . "\n"
  228                 . "        </li>\n";
  229         } else {
  230             $count_sections = count($BAW_CONF_DIS);
  231             foreach ($BAW_CONF_DIS as $section => $sect_data) {
  232                 if ($sect_data['show'] &&
  233                     ($tmp[$section] || !$BAW_CONF['hideempty'])) {
  234                     $class = baw_even($c, 'menu_even', 'menu_odd');
  235                     $name = $BAW_CONF_DIS_DEF[$section]['name'];
  236                     $menubox .= "        <li class=\"$class\">\n"
  237                         . "            " . baw_create_link($name, "$url#h2_$section", array('class' => 'leftlink')) . "\n"
  238                         . baw_display_list_icons ($section,  array('info'), false) . "\n"
  239                         . "        </li>\n";
  240                     $c++;
  241                 }
  242             }
  243         }
  244     }
  245 
  246     $menubox .= "    </ul>\n";
  247     $menubox_end = "\n</div>\n<!-- MENU END - SITE/DATE MENU START ++++++++++++++++++++++++++++++++++++++ -->\n";
  248     baw_debug("Menu finished");
  249     $finaltime = baw_ptime();
  250     $out = $menubox
  251         . baw_display_version("<br" . XHTML . "> in $finaltime, max menory: " . baw_byte_format(memory_get_peak_usage(true)))
  252         . $menubox_end . $content
  253         . baw_site_footer();
  254     return $out;
  255 }
  256 
  257 /*
  258 * Display Helper Function: display the menu bar on the top of the page
  259 * called by baw_display_index
  260 *
  261 * @return   str     HTML
  262 *
  263 */
  264 function baw_top_menu_bar() {
  265     global $BAW_MES, $BAW_CONF_DEF, $BAW_CONF, $BAW_CURR;
  266     // sites / dates dropdown
  267     $n1 = $n2 = '';
  268     if ($BAW_CONF['auto_submit_form' ]) {
  269         $n1 = "<noscript><div>\n";
  270         $n2 = "</div></noscript>\n";
  271     }
  272     $out = "\n<ul class=\"top_menu_bar\">\n"
  273         . "  <li>\n"
  274         . "    <form action=\"{$_SERVER['SCRIPT_NAME']}\" method=\"get\">\n"
  275         . "      <div>\n"
  276         . "         <input type=\"hidden\" name=\"site\" value=\"{$BAW_CURR['site_name']}\"" . XHTML . ">\n"
  277         . baw_date_dropdown();
  278     if (isset($_GET['action'])) {
  279         $out .= "         <input type=\"hidden\" name=\"action\" value=\"{$_GET['action']}\"" . XHTML . ">\n";
  280     }
  281     if (isset($_GET['what'])) {
  282         $out .= "         <input type=\"hidden\" name=\"what\" value=\"{$_GET['what']}\"" . XHTML . ">\n";
  283     }
  284     $out .= "         $n1<input type=\"submit\" value=\"{$BAW_MES[115]}\"" . XHTML . ">$n2\n"
  285         . "      </div>\n"
  286         . "    </form>\n";
  287 
  288     $out .= "  </li>\n";
  289 
  290     $out .= "  <li class=\"link\">\n"
  291         . baw_create_link(
  292             $BAW_MES['get_help'],
  293             'http://betterawstats.com/forum/',
  294             array('class'=>'rightlink')
  295     ). "\n";
  296     $out .= "  </li>\n";
  297 
  298     $out .= "  <li class=\"link\">\n"
  299         . baw_create_link(
  300         $BAW_MES['version_check'],
  301         "http://betterawstats.com/main/index.php?lang=eng&action=versioncheck&version="
  302             . $BAW_CONF_DEF[$BAW_MES['cfg_advanced_settings']]['version']['default']
  303     ) . "\n";
  304     $out .= "</li>\n";
  305 
  306     $out .= "  <li class=\"link\">";
  307     if ($BAW_CONF['online_config'] && (baw_is_writable($BAW_CONF['site_path'] . '/config.php'))) {
  308         $out .= baw_create_link(
  309                 $BAW_MES['config_editor'],
  310                 "{$BAW_CONF['site_url']}/index.php?action=config_editor"
  311             ) . "\n";
  312     } else if ($BAW_CONF['online_config']) {
  313         $out .= $BAW_MES['config_not_writable']. "\n";
  314     }
  315     $out .= "  </li>\n";
  316 
  317     @session_start();
  318     if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true) {
  319         $out .= "  <li class=\"link\">";
  320         if ($BAW_CONF['online_config'] && (baw_is_writable($BAW_CONF['site_path'] . '/config.php'))) {
  321             $out .= baw_create_link(
  322                     $BAW_MES['cfg_logout'],
  323                     "{$BAW_CONF['site_url']}/index.php?action=do_logout"
  324                 ) . "\n";
  325         }
  326         $out .= "  </li>\n";
  327     }
  328 
  329     $out .= "</ul>\n\n";
  330 
  331     return $out;
  332 }
  333 
  334 /*
  335 * Display Helper Function: display a text including the version and other info
  336 * called by baw_display_index
  337 *
  338 * @param    str     $text   text to be included in the message
  339 * @return   str     HTML
  340 *
  341 */
  342 function baw_display_version($text = '') {
  343     global $BAW_CONF_DEF, $BAW_MES;
  344 
  345     $link = baw_create_link('BetterAWstats', 'http://betterawstats.com');
  346     $out = "    <div class=\"version\">\n        "
  347         . sprintf($BAW_MES['created_by'], $link)
  348         . " {$BAW_CONF_DEF[$BAW_MES['cfg_advanced_settings']]['version']['default']}\n"
  349         . "        $text\n"
  350         . "    </div>";
  351     return $out;
  352 }
  353 
  354 /*
  355 * Display Helper Function: display links for left-hand menu block
  356 * called by baw_display_index
  357 *
  358 * @param    str     $section    which section is it? (for link)
  359 * @param    str     $text       text to use as alt of icon or instead of icon
  360 * @param    bol     $useicon    shall we display the icon?
  361 * @param    bol     $getonlyone shall we get only one or all three?
  362 * @param    bol     $btn        if true, we use alternative image with button layout
  363 * @return   str     HTML
  364 *
  365 */
  366 function baw_display_list_icons ($section, $exclude, $btn) {
  367     global $BAW_CONF_DIS, $BAW_CONF_DIS_DEF, $BAW_CONF, $BAW_MES, $BAW_CURR, $BAW_MES;
  368 
  369     if ($btn) {
  370         $btn_str = '_btn';
  371     } else {
  372         $btn_str = '';
  373     }
  374     $links_arr = array(
  375         'info' => array(
  376             'check' => @$BAW_MES["hlp_$section"],
  377             'image' => $BAW_CONF['site_url'] . "/icons/help.png",
  378             'msg' => htmlentities(@$BAW_MES["hlp_$section"]),
  379             'what' => 'span',
  380         ),
  381         'full_list' => array(
  382             'check' => @$BAW_CONF_DIS[$section]['top_x'],
  383             'image' => $BAW_CONF['site_url'] ."/icons/fulllist{$btn_str}.png",
  384             'msg' => $BAW_MES[80],
  385             'what' => $section,
  386         ),
  387         'versions' => array(
  388             'check' => @$BAW_CONF_DIS_DEF[$section]['hasversions'],
  389             'image' => $BAW_CONF['site_url'] ."/icons/versions{$btn_str}.png",
  390             'msg' => $BAW_MES['version_info'],
  391             'what' => @$BAW_CONF_DIS_DEF[$section]['hasversions'],
  392         ),
  393         'unknown' => array(
  394             'check' => @$BAW_CONF_DIS_DEF[$section]['hasunknown'],
  395             'image' => $BAW_CONF['site_url'] ."/icons/unknown{$btn_str}.png",
  396             'msg' => $BAW_MES['unknown_list'],
  397             'what' => @$BAW_CONF_DIS_DEF[$section]['hasunknown'],
  398         ),
  399     );
  400 
  401     $out = '';
  402     $i = 1;
  403     foreach ($links_arr as $link => $settings) {
  404         if ((!in_array($link, $exclude)) && isset($settings['check'])) {
  405             $icon = baw_create_image($settings['image'], array('title'=> $settings['msg'],'alt'=> $settings['msg'])) . " ";
  406             $class = "icon_indent_$i"; // we indent more for each icon
  407             if ($link == 'info') { // we have a hover-text
  408                 $out .= "    <span class=\"section_help $class\">$icon<span>{$settings['msg']}</span></span>\n";
  409                 $i++;
  410             } else { // we have a link
  411                 $out .= "            "
  412                     . baw_display_list_link($icon, $settings['msg'], $settings['what'], $class)
  413                     . "\n";
  414                 $i++;
  415             }
  416         }
  417     }
  418     return $out;
  419 }
  420 
  421 function baw_display_list_link($text, $title, $section, $class) {
  422     global $BAW_CONF, $BAW_CURR;
  423     $out = '';
  424     if ($BAW_CONF['module'] == 'drupal') {
  425         $url = "/{$BAW_CONF['drupal_base']}/details/$section/{$BAW_CURR['month']}/{$BAW_CURR['year']}";
  426     } else {
  427         $url = "{$BAW_CONF['site_url']}/index.php?site={$BAW_CURR['site_name']}&month={$BAW_CURR['month']}&year={$BAW_CURR['year']}"
  428             . "&action=get_fulltable&what=$section";
  429     }
  430     $out .= baw_create_link($text, $url, array('title'=>$title, 'class'=>$class), false, false);
  431     return $out;
  432 }
  433 
  434 /*
  435 * Display Helper Function: display only and the full table of one section
  436 * called by index.php
  437 *
  438 * @return   str     HTML
  439 *
  440 */
  441 function baw_action_get_fulltable() {
  442     global $BAW_CONF;
  443     $settings = array();
  444     $out = '';
  445     if (isset($_GET['what'])) {
  446         $what = $_GET['what'];
  447         $settings['section'] = $what;
  448     } else {
  449         $out = baw_display_index();
  450     }
  451     if (isset($_GET['sort'])) {
  452         $sort = $_GET['sort'];
  453         $settings['sort'] = $sort;
  454     };
  455     $out .= baw_display_index($settings);
  456     return $out;
  457 }
  458 
  459 /*
  460 * Display Helper Function: create a HTML link from parameters
  461 *
  462 * @param    str     $content    the text to be linked
  463 * @param    str     $url        the url to link to
  464 * @param    arr     $attr       var attributes to include in the links
  465 * @param    bol     $codehtml   do we use htmlspecialchars() on the content?
  466 * @param    bol     $shorten    do we shorten the content according to config?
  467 * @return   str     HTML
  468 *
  469 */
  470 function baw_create_link ($content, $url, $attr=array(), $codehtml = false, $shorten = true) {
  471     global $BAW_CONF;
  472     if ($url == '-') {
  473         return $url;
  474     }
  475     $attr_str = '';
  476     if (strlen($content) > $BAW_CONF['field_length'] && $shorten) {
  477         $content = substr($content, 0, $BAW_CONF['field_length']-3) . "...";
  478     }
  479     $url = htmlspecialchars($url);
  480     if ($codehtml) {
  481         $content = htmlspecialchars($content);
  482     }
  483     if (!isset($attr['title'])) {
  484         $attr['title'] = $content;
  485     }
  486     $check = strpos($url, $BAW_CONF['site_url']);
  487     if ($check !== 0) {
  488         if (isset($attr['class'])) {
  489             $attr['class'] .= " ext_link";
  490         } else {
  491             $attr['class'] = "ext_link";
  492         }
  493     }
  494     foreach ($attr as $key => $value) {
  495         $attr_str .= " $key=\"$value\"";
  496     }
  497     $out = "<a$attr_str href=\"$url\">$content</a>";
  498 
  499     return $out;
  500 }
  501 
  502 /*
  503 * Display Helper Function: create a HTML image from parameters
  504 *
  505 * @param    str     $url        the url of the image to link to
  506 * @param    arr     $attr       var attributes to include in the links
  507 * @return   str     HTML
  508 *
  509 */
  510 function baw_create_image($url, $attr=array()) {
  511     global $BAW_CONF;
  512 
  513     $hasalt = false;
  514     $attr_str = '';
  515     if (!isset($attr['alt'])) {
  516         $attr['alt'] = ' ';
  517     }
  518     foreach ($attr as $key => $value) {
  519         $attr_str .= " $key=\"$value\"";
  520     }
  521     if ($BAW_CONF['module'] !== 'drupal') {
  522         if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
  523             $url = $BAW_CONF['icons_url'] . $url;
  524         }
  525     }
  526     $out = "<img src=\"$url\"$attr_str" . XHTML . ">";
  527     return $out;
  528 }
  529 
  530 /*
  531 * Display Helper Function: create the HTML for a favicon of a given URL
  532 * Parses the URL, retrieves the domain and links to the favicon
  533 *
  534 * @param    str     $url        the url of the image to link to
  535 * @return   str     HTML
  536 *
  537 */
  538 function baw_get_favicon($url) {
  539     if ($url !== strip_tags($url)) { // we have a HTML link
  540         $pattern = '/<a .* href=\"(.*)\"/';
  541         $image = '';
  542         preg_match($pattern, $url, $match);
  543         if (isset($match[1])) {
  544             $url = $match[1];
  545         } else {
  546             return '';
  547         }
  548     }
  549     $image = '';
  550     $code = '';
  551     $url_arr = @parse_url($url);
  552     if (isset($url_arr['scheme']) && isset($url_arr['host'])) {
  553         $image = baw_create_image(
  554             $url_arr['scheme'] . "://". $url_arr['host']. '/favicon.ico',
  555             array('height' => 16, 'width'=> 16)
  556         );
  557     }
  558     return $image . $code;
  559 }
  560 
  561 /*
  562 * Display Helper Function: create the HTML of the site header
  563 * switches between HTML/XHTML, displays title, charset etc.
  564 *
  565 * @param    str     $title        title of the page to be used
  566 * @return   str     HTML
  567 *
  568 */
  569 function baw_site_header($title = '') {
  570     global $BAW_CONF_DEF, $BAW_CONF, $BAW_MES;
  571     if ($BAW_CONF['xhtml']) {
  572         $out = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
  573         $root_dec = " xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"";
  574     } else {
  575         $out = "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n";
  576         $root_dec = '';
  577     }
  578     $out .= "<html$root_dec>\n"
  579         ."    <head>\n"
  580         ."        <title>$title Better AWstats  v. {$BAW_CONF_DEF[$BAW_MES['cfg_advanced_settings']]['version']['default']}</title>\n"
  581         ."        <meta http-equiv=\"Content-Type\" content=\"text/html;charset={$BAW_MES['e']}\"" . XHTML . ">\n"
  582         ."        <link rel=\"stylesheet\" type=\"text/css\" href=\"{$BAW_CONF['site_url']}/style.css\"" . XHTML . ">\n"
  583         ."        <link rel=\"stylesheet\" type=\"text/css\" href=\"{$BAW_CONF['site_url']}/{$BAW_CONF['layout_type']}.css\"" . XHTML . ">\n"
  584         ."    </head>\n"
  585         ."    <body>\n"
  586         ."    <script type=\"text/javascript\" src=\"{$BAW_CONF['site_url']}/scripts.js\"></script>\n";
  587     return $out;
  588 }
  589 
  590 /*
  591 * Display Helper Function: create the HTML of the site footer
  592 *
  593 * @return   str     HTML
  594 *
  595 */
  596 function baw_site_footer() {
  597     $out ="</body></html>";
  598     return $out;
  599 }
  600 
  601 /*
  602 * Display Helper Function: create the HTML of the section header
  603 *
  604 * @param    str     $name        name of the section for the HTML ID
  605 * @param    str     $title       title to be displayed
  606 * @param    bol     $collapse    is it collapsed or not?
  607 * @param    str     $class       which CSS class do we use?
  608 * @return   str     HTML
  609 *
  610 */
  611 function baw_section_header($name, $title, $collapse, $class = 'menu_section') {
  612     global $BAW_CONF;
  613     $buttons = baw_show_expand_collapse($name, $collapse). "\n"
  614         . baw_display_list_icons($name, array(), true);
  615     if ($collapse) {
  616         $show = " style=\"display:none\"";
  617     } else {
  618         $show = "";
  619     }
  620     $out =  "<h2 class=\"$class\" id=\"h2_$name\">\n    $title\n    $buttons\n</h2>\n"
  621         . "<div class=\"$class\" id=\"box_$name\"$show>\n";
  622     return $out;
  623 }
  624 
  625 /*
  626 * Display Helper Function: create the HTML of the expand/collapse button
  627 *
  628 * @param    str     $name        name of the section for JS to identify it
  629 * @return   str     HTML
  630 *
  631 */
  632 function baw_show_expand_collapse($name, $collapse) {
  633     global $BAW_CONF, $BAW_MES;
  634 
  635     $url = $BAW_CONF['site_url'] . "/icons/expand.gif";
  636     $arr_show = array(
  637         'class' => "showhidebutton",
  638         'onclick' => "showElement('{$name}');",
  639         'title' => $BAW_MES['show'],
  640         'id' => "button_show_{$name}",
  641     );
  642     $arr_hide = array(
  643         'class' => "showhidebutton",
  644         'onclick' => "hideElement('{$name}');",
  645         'id' => "button_hide_{$name}",
  646         'title' => $BAW_MES['hide'],
  647     );
  648     if ($collapse) {
  649         $arr_hide += array('style' => "display:none");
  650     } else {
  651         $arr_show += array('style' => "display:none");
  652     }
  653     $url = $BAW_CONF['site_url'] . "/icons/expand.gif";
  654     $out = baw_create_image($url, $arr_show);
  655     $url = $BAW_CONF['site_url'] . "/icons/collapse.gif";
  656     $out .= baw_create_image($url, $arr_hide);
  657     return $out;
  658 }
  659 
  660 /*
  661 * Display Helper Function: create the HTML of footer of a section
  662 *
  663 * @return   str     HTML
  664 *
  665 */
  666 function baw_section_footer() {
  667     $out = "</div>\n";
  668     return $out;
  669 }
  670 
  671 /*
  672 * Display Helper Function: create a generic dropdown for HTML forms
  673 *
  674 * @param    str     $name        name of the dropdown for the form identification
  675 * @param    arr     $list        associative array of items to list (ID => NAME)
  676 * @param    str     $selected    entry which should be preselected
  677 * @param    str     $attr        any strng attribute that is added to the <select>
  678 * @return   str     HTML
  679 *
  680 */
  681 function baw_generic_dropdown($name, $list, $selected='', $attr='') {
  682     global $BAW_CONF;
  683     $js = '';
  684     if ($BAW_CONF['auto_submit_form' ]) {
  685         $js = " onchange=\"this.form.submit()\"";
  686     }
  687     $out = "<select $attr name=\"$name\"$js>\n";
  688     foreach ($list as $key => $value) {
  689         if (is_bool($selected)) {
  690             if ($selected) {
  691                 $selected = 'true';
  692             } else {
  693                 $selected = 'false';
  694             }
  695         }
  696         if ($key == $selected) {
  697             $sel = ' selected="selected"';
  698         } else {
  699             $sel = '';
  700         }
  701         $out .= "    <option value=\"$key\"$sel>$value</option>\n";
  702     }
  703     $out .= "</select>\n";
  704     return $out;
  705 }
  706 
  707 /*
  708 * Display Helper Function: create a year/date dropdown from the current list of
  709 * available datafile dates
  710 *
  711 * @return   str     HTML
  712 *
  713 */
  714 function baw_date_dropdown() {
  715     global $BAW_CURR;
  716     $out = '';
  717     $out .= baw_generic_dropdown('month', $BAW_CURR['months'], $BAW_CURR['month']);
  718     $out .= baw_generic_dropdown('year', $BAW_CURR['years'], $BAW_CURR['year']);
  719     return $out;
  720 }
  721 
  722 /*
  723 * Display Helper Function: create a dropdown of all sites available from the
  724 * datafiles
  725 *
  726 * @param    str     $selected        preselected item if available
  727 * @param    str     $fld_name        field name of <select>
  728 *
  729 * @return   str     HTML
  730 *
  731 */
  732 function baw_sites_dropdown() {
  733     global $BAW_CURR, $BAW_MES, $BAW_DFILES, $BAW_CONF;;
  734     $sites_temp = $BAW_DFILES;
  735     $n1 = $n2 = $js = '';
  736     if ($BAW_CONF['auto_submit_form' ]) {
  737         $n1 = "<noscript><div>";
  738         $n2 = "</div></noscript>";
  739         $js = " onchange=\"this.form.submit()\"";
  740     }
  741     $out = '';
  742     if (count($BAW_DFILES) > 1 && $BAW_CONF['limit_server'] == 'show_all') {
  743         $out .= "    <form action=\"{$_SERVER['SCRIPT_NAME']}\" method=\"get\">\n"
  744         . "        <div class=\"headline\">"; // the div is needed for validation
  745     } else {
  746         $out = "    <div class=\"headline\">";
  747         if ($BAW_CONF['limit_server'] == 'show_all' && count($BAW_DFILES) !== 1) {
  748             $out .= "<span>".$BAW_CONF['limit_server']."</span>";
  749         } else {
  750             $singlesite = key($BAW_DFILES);
  751             $out .= "<span>".$singlesite."</span>";
  752         }
  753         $out .= "</div>\n";
  754         return $out;
  755     }
  756     $sites_temp += array(
  757         'all_months' => $BAW_MES['all_months'],
  758         'all_days' => $BAW_MES['all_days']
  759     );
  760     $out .="\n<select name=\"site\"$js>\n";
  761     foreach ($sites_temp as $site => $filedata) {
  762         $sel = '';
  763         if ($BAW_CURR['site_name'] == $site) {
  764             $sel = ' selected="selected"';
  765         }
  766         $site_txt = $site;
  767         if ($site == 'all_months' || $site == 'all_days') {
  768             $site_txt = $BAW_MES[$site];
  769         }
  770         $out .= "    <option value=\"$site\"$sel>$site_txt</option>\n";
  771     }
  772     $out .= "</select>\n"
  773         . "$n1<input type=\"submit\" value=\"{$BAW_MES[115]}\"" . XHTML . ">$n2\n"
  774         . "<input type=\"hidden\" name=\"month\" value=\"{$BAW_CURR['month']}\"" . XHTML . ">\n"
  775         . "<input type=\"hidden\" name=\"year\" value=\"{$BAW_CURR['year']}\"" . XHTML . ">\n";
  776     if (isset($_GET['action'])) {
  777         $out .= "         <input type=\"hidden\" name=\"action\" value=\"{$_GET['action']}\"" . XHTML . ">\n";
  778     }
  779     if (isset($_GET['what'])) {
  780         $out .= "         <input type=\"hidden\" name=\"what\" value=\"{$_GET['what']}\"" . XHTML . ">\n";
  781     }
  782         $out .= "</div>\n"
  783         . "</form>\n";
  784     return $out;
  785 }
  786 ?>