Changeset 559

Show
Ignore:
Timestamp:
07/15/08 14:08:55 (5 months ago)
Author:
sidtheduck
Message:

+ Partial fix for ticket #184 - truncating the collections and albums if only 1 album or 1 collection is present

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/plog-includes/plog-functions.php

    r557 r559  
    66} 
    77 
    8 function generate_breadcrumb($collections = 'Collections', $sep = ' » ', $translate = true) { 
     8function generate_breadcrumb($collections = 'Collections', $sep = ' » '){ 
    99        global $config; 
    1010 
    1111        $id = $GLOBALS['plogger_id']; 
    1212 
    13         if ($translate === true){ 
    14                 $collections = plog_tr(SmartStripSlashes($collections)); 
    15         } 
    1613        $collections_link = '<a href="'.generate_url("collections").'">' . $collections . '</a>'; 
    1714        $collections_name = '<strong>' . $collections . '</strong>'; 
     
    2219                        $collection_name = '<strong>' . SmartStripSlashes($row['name']) . '</strong>'; 
    2320 
    24                         $breadcrumbs = $collections_link . $sep . $collection_name; 
     21                        if ($config['truncate_breadcrumb'] == "collection"){ 
     22                                $breadcrumbs = $collection_name; 
     23                        } else { 
     24                                $breadcrumbs = $collections_link . $sep . $collection_name; 
     25                        } 
    2526 
    2627                        // Does this ever happen?  Collection level + slideshow mode ends in SQL error 
    27                         if ($GLOBALS['plogger_mode'] == "slideshow") $breadcrumbs .= $sep . '<strong>' . plog_tr('Slideshow'); 
     28                        //if ($GLOBALS['plogger_mode'] == "slideshow") $breadcrumbs .= $sep . '<strong>' . plog_tr('Slideshow'); 
    2829 
    2930                break; 
     
    3738                        $collection_link = '<a accesskey="/" href="' . generate_url("collection", $row['id']) . '">' . SmartStripSlashes($row['name']) . '</a>'; 
    3839 
    39                         if ($GLOBALS['plogger_mode'] == "slideshow") { 
    40                                 $breadcrumbs = $collections_link . $sep . $collection_link . $sep . $album_link . $sep . '<strong>' . plog_tr('Slideshow') . '</strong>'; 
     40                        if ($config['truncate_breadcrumb'] == "album"){ 
     41                                $breadcrumbs = $album_name; 
     42                        } else if ($config['truncate_breadcrumb'] == "collection"){ 
     43                                $breadcrumbs = $collection_link . $sep . $album_name; 
    4144                        } else { 
    4245                                $breadcrumbs = $collections_link . $sep . $collection_link . $sep . $album_name; 
     46                        } 
     47 
     48                        if ($GLOBALS['plogger_mode'] == "slideshow") { 
     49                                $breadcrumbs = str_replace($album_name, $album_link . $sep . '<strong>' . plog_tr('Slideshow') . '</strong>', $breadcrumbs); 
    4350                        } 
    4451 
     
    4855                        $picture_name = '<span id="image_name"><strong>' . SmartStripSlashes(get_caption_filename($row)) . '</strong></span>'; 
    4956 
    50                         $row = get_album_by_id($row["parent_album"]); 
     57                        $row = get_album_by_id($row['parent_album']); 
    5158                        $album_link = '<a accesskey="/" href="' . generate_url("album", $row['id']) . '">' . SmartStripSlashes($row['name']) . '</a>'; 
    5259 
    53                         $row = get_collection_by_id($row["parent_id"]); 
     60                        $row = get_collection_by_id($row['parent_id']); 
    5461                        $collection_link = '<a accesskey="/" href="' . generate_url("collection", $row['id']) . '">' . SmartStripSlashes($row['name']) . '</a>'; 
    5562 
    56                         $breadcrumbs = $collections_link . $sep . $collection_link . $sep . $album_link . $sep . $picture_name; 
     63                        if ($config['truncate_breadcrumb'] == "album"){ 
     64                                $breadcrumbs = $album_link . $sep . $picture_name; 
     65                        } else if ($config['truncate_breadcrumb'] == "collection") { 
     66                                $breadcrumbs = $collection_link . $sep . $album_link . $sep . $picture_name; 
     67                        } else { 
     68                                $breadcrumbs = $collections_link . $sep . $collection_link . $sep . $album_link . $sep . $picture_name; 
     69                        } 
    5770 
    5871                        // Does this ever happen?  Picture level + slideshow adds 'Slideshow' to breadcrumbs only 
    59                         if ($GLOBALS['plogger_mode'] == "slideshow") $breadcrumbs .= $sep . '<strong>' . plog_tr('Slideshow'); 
     72                        //if ($GLOBALS['plogger_mode'] == "slideshow") $breadcrumbs .= $sep . '<strong>' . plog_tr('Slideshow'); 
    6073 
    6174                break; 
    6275                case 'search': 
    63                         $breadcrumbs = $collections_link . $sep . '<strong>'.plog_tr('Search').'</strong>' . $sep . plog_tr('You searched for') . ' <strong>'.htmlspecialchars(SmartStripSlashes($_GET['searchterms'])).'</strong>.'; 
     76                        if ($config['truncate_breadcrumb'] == "album"){ 
     77                                $row = get_album_by_id($id); 
     78                                $album_link = '<a accesskey="/" href="' . generate_url("album", $row['id']) . '">' . SmartStripSlashes($row['name']) . '</a>'; 
     79                                $breadcrumbs = $album_link . $sep . '<strong>'.plog_tr('Search').'</strong>' . $sep . plog_tr('You searched for') . ' <strong>'.htmlspecialchars(SmartStripSlashes($_GET['searchterms'])).'</strong>.'; 
     80                        } else if ($config['truncate_breadcrumb'] == "collection") { 
     81                                $row = get_collection_by_id($id); 
     82                                $collection_link = '<a accesskey="/" href="' . generate_url("collection", $row['id']) . '">' . SmartStripSlashes($row['name']) . '</a>'; 
     83                                $breadcrumbs = $collection_link . $sep . '<strong>'.plog_tr('Search').'</strong>' . $sep . plog_tr('You searched for') . ' <strong>'.htmlspecialchars(SmartStripSlashes($_GET['searchterms'])).'</strong>.'; 
     84                        } else { 
     85                                $breadcrumbs = $collections_link . $sep . '<strong>'.plog_tr('Search').'</strong>' . $sep . plog_tr('You searched for') . ' <strong>'.htmlspecialchars(SmartStripSlashes($_GET['searchterms'])).'</strong>.'; 
     86                        } 
    6487                break; 
    6588                default: 
     
    503526                } 
    504527        } 
     528 
     529function get_active_collections_albums() { 
     530        $return = array( 
     531                "collections" => '', 
     532                "albums" => ''); 
     533 
     534        $sql = "SELECT parent_collection,parent_album,COUNT(*) AS imagecount 
     535        FROM `".TABLE_PREFIX."pictures` GROUP BY parent_collection,parent_album"; 
     536        $result = run_query($sql); 
     537        while($row = mysql_fetch_assoc($result)) { 
     538                $image_collection_count[$row["parent_collection"]] = $row["imagecount"]; 
     539                $image_album_count[$row["parent_album"]] = $row["imagecount"]; 
     540        } 
     541        $return['collections'] = array_keys($image_collection_count); 
     542        $return['albums'] = array_keys($image_album_count); 
     543        return $return; 
     544} 
    505545 
    506546        function generate_thumb($path, $prefix, $type = THUMB_SMALL) { 
  • trunk/plogger.php

    r555 r559  
    7171// use plogger specific variables to avoid name clashes if Plogger is embedded 
    7272 
    73 $GLOBALS['plogger_level'] = isset($_GET["level"]) ? $_GET["level"] : ''; 
    74 $GLOBALS['plogger_id'] = isset($_GET["id"]) ? intval($_GET["id"]) : 0; 
    75 $GLOBALS['plogger_mode'] = isset($_GET["mode"]) ? $_GET["mode"] : ''; 
     73$GLOBALS['plogger_level'] = isset($_GET['level']) ? $_GET['level'] : ''; 
     74$GLOBALS['plogger_id'] = isset($_GET['id']) ? intval($_GET['id']) : 0; 
     75$GLOBALS['plogger_mode'] = isset($_GET['mode']) ? $_GET['mode'] : ''; 
     76 
     77// count collections and albums with pictures in them 
     78$active = get_active_collections_albums(); 
     79 
     80// if only 1 active album, truncate the "collection" & "collections" portion of Plogger 
     81if (count($active['albums']) == 1) { 
     82        $config['truncate_breadcrumb'] = 'album'; 
     83        if ($GLOBALS['plogger_level']!="picture") { 
     84                if ($GLOBALS['plogger_level']!="search") { 
     85                        $GLOBALS['plogger_level'] = "album"; 
     86                } 
     87                $GLOBALS['plogger_id'] = $active['albums'][0]; 
     88        } 
     89// if only 1 active collection, truncate the "collections" portion of Plogger 
     90} else if (count($active['collections']) == 1) { 
     91        $config['truncate_breadcrumb'] = 'collection'; 
     92        if ($GLOBALS['plogger_level']!="album" && $GLOBALS['plogger_level']!='picture') { 
     93                if ($GLOBALS['plogger_level']!="search") { 
     94                        $GLOBALS['plogger_level'] = "collection"; 
     95                } 
     96                $GLOBALS['plogger_id'] = $active['collections'][0]; 
     97        } 
     98} else { 
     99        $config['truncate_breadcrumb'] = false; 
     100} 
    76101 
    77102$allowed_levels = array('collections','collection','album','picture','search');