Ticket #184: truncate_album_collection_fix.patch

File truncate_album_collection_fix.patch, 7.7 KB (added by sidtheduck, 5 months ago)
  • plog-includes/plog-functions.php

     
    55        exit(); 
    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>'; 
    1815 
     
    2118                        $row = get_collection_by_id($id); 
    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; 
    3031                case 'slideshow': 
     
    3637                        $row = get_collection_by_id($row['parent_id']); 
    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; 
    4346                        } 
    4447 
     48                        if ($GLOBALS['plogger_mode'] == "slideshow") { 
     49                                $breadcrumbs = str_replace($album_name, $album_link . $sep . '<strong>' . plog_tr('Slideshow') . '</strong>', $breadcrumbs); 
     50                        } 
     51 
    4552                break; 
    4653                case 'picture': 
    4754                        $row = get_picture_by_id($id); 
    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: 
    6689                $breadcrumbs = $collections_name; 
     
    482505                } 
    483506        } 
    484507 
     508function get_active_collections_albums() { 
     509        $return = array( 
     510                "collections" => '', 
     511                "albums" => ''); 
     512 
     513        $sql = "SELECT parent_collection,parent_album,COUNT(*) AS imagecount 
     514        FROM `".TABLE_PREFIX."pictures` GROUP BY parent_collection,parent_album"; 
     515        $result = run_query($sql); 
     516        while($row = mysql_fetch_assoc($result)) { 
     517                $image_collection_count[$row["parent_collection"]] = $row["imagecount"]; 
     518                $image_album_count[$row["parent_album"]] = $row["imagecount"]; 
     519        } 
     520        $return['collections'] = array_keys($image_collection_count); 
     521        $return['albums'] = array_keys($image_album_count); 
     522        return $return; 
     523} 
     524 
    485525        function generate_thumb($path, $prefix, $type = THUMB_SMALL) { 
    486526                global $config; 
    487527                global $thumbnail_config; 
  • plogger.php

     
    7070 
    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'] : ''; 
    7676 
     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} 
     101 
    77102$allowed_levels = array('collections','collection','album','picture','search'); 
    78103if (!in_array($GLOBALS['plogger_level'],$allowed_levels)) { 
    79104        $GLOBALS['plogger_level'] = 'collections';