Ticket #124: better_404_errors.patch

File better_404_errors.patch, 4.3 KB (added by sidtheduck, 4 months ago)
  • plog-includes/plog-functions.php

     
    679679        return $thumburl; 
    680680} 
    681681 
     682function check_picture_id($id) { 
     683        $sql = "SELECT `parent_album` FROM ".TABLE_PREFIX."pictures WHERE `id` = ".intval($id); 
     684        $result = run_query($sql); 
     685        if (mysql_num_rows($result) > 0) { 
     686                return true; 
     687        } else { 
     688                $GLOBALS['plogger_level'] = "404"; 
     689                return false; 
     690        } 
     691} 
     692 
    682693function get_picture_by_id($id, $album_id = null) { 
    683694        global $config; 
    684695 
     
    761772        return $pictures; 
    762773} 
    763774 
     775function check_album_id($id) { 
     776        $sql = "SELECT `thumbnail_id` FROM ".TABLE_PREFIX."albums WHERE `id` = ".intval($id); 
     777        $result = run_query($sql); 
     778        if (mysql_num_rows($result) > 0) { 
     779                return true; 
     780        } else { 
     781                $GLOBALS['plogger_level'] = "404"; 
     782                return false; 
     783        } 
     784} 
     785 
    764786function get_album_by_id($id) { 
    765787        global $config; 
    766788 
     
    817839        return $album; 
    818840} 
    819841 
     842function check_collection_id($id) { 
     843        $sql = "SELECT `thumbnail_id` FROM ".TABLE_PREFIX."collections WHERE `id` = ".intval($id); 
     844        $result = run_query($sql); 
     845        if (mysql_num_rows($result) > 0) { 
     846                return true; 
     847        } else { 
     848                $GLOBALS['plogger_level'] = "404"; 
     849                return false; 
     850        } 
     851} 
     852 
    820853function get_collection_by_id($id) { 
    821854        global $config; 
    822855 
     
    14561489                'from' => $from, 
    14571490                'limit' => $lim)); 
    14581491        } else if ($GLOBALS["plogger_level"] == "album") { 
    1459                 plogger_init_pictures(array( 
    1460                 'type' => 'album', 
    1461                 'value' => $id, 
    1462                 'from' => $from, 
    1463                 'limit' => $lim, 
    1464                 'sortby' => isset($_SESSION['plogger_sortby']) ? $_SESSION['plogger_sortby'] : '', 
    1465                 'sortdir' => isset($_SESSION['plogger_sortdir']) ? $_SESSION['plogger_sortdir'] : '')); 
     1492                if (check_album_id($id)) { 
     1493                        plogger_init_pictures(array( 
     1494                        'type' => 'album', 
     1495                        'value' => $id, 
     1496                        'from' => $from, 
     1497                        'limit' => $lim, 
     1498                        'sortby' => isset($_SESSION['plogger_sortby']) ? $_SESSION['plogger_sortby'] : '', 
     1499                        'sortdir' => isset($_SESSION['plogger_sortdir']) ? $_SESSION['plogger_sortdir'] : '')); 
     1500                } 
    14661501        } else if ($GLOBALS["plogger_level"] == "collection") { 
    1467                 plogger_init_albums(array( 
    1468                 'from' => $from, 
    1469                 'limit' => $lim, 
    1470                 'collection_id' => $id, 
    1471                 'sortby' => !empty($config['album_sortby']) ? $config['album_sortby'] : 'id', 
    1472                 'sortdir' => !empty($config['album_sortdir']) ? $config['album_sortdir'] : 'DESC')); 
     1502                if (check_collection_id($id)) { 
     1503                        plogger_init_albums(array( 
     1504                        'from' => $from, 
     1505                        'limit' => $lim, 
     1506                        'collection_id' => $id, 
     1507                        'sortby' => !empty($config['album_sortby']) ? $config['album_sortby'] : 'id', 
     1508                        'sortdir' => !empty($config['album_sortdir']) ? $config['album_sortdir'] : 'DESC')); 
     1509                } 
    14731510        } else if ($GLOBALS["plogger_level"] == "picture") { 
    1474                 // first lets load the thumbnail of the picture at the correct size 
    1475                 plogger_init_picture(array('id' => $id)); 
     1511                if (check_picture_id($id)) { 
     1512                        // first lets load the thumbnail of the picture at the correct size 
     1513                        plogger_init_picture(array('id' => $id)); 
     1514                } 
    14761515        } else { 
    14771516                // Show all of the collections 
    14781517                plogger_init_collections(array( 
     
    14911530        $row = mysql_fetch_assoc($result); 
    14921531 
    14931532        if (!$row) { 
    1494                 $GLOBALS['plogger_level'] = "404"; 
    14951533                return false; 
    14961534        } 
    14971535 
     
    16801718        $result = run_query("SELECT p.*, 
    16811719        UNIX_TIMESTAMP(`date_submitted`) AS `unix_date_submitted`, 
    16821720        UNIX_TIMESTAMP(`EXIF_date_taken`) AS `unix_exif_date_taken` " . $sql); 
    1683         if (!mysql_num_rows($result)){ 
    1684                 $GLOBALS['plogger_level'] = "404"; 
    1685                 return false; 
    1686         } 
     1721 
    16871722        $GLOBALS["available_pictures"] = mysql_num_rows($result); 
    16881723        $GLOBALS["picture_counter"] = 0; 
    16891724        $GLOBALS["picture_dbh"] = $result; 
     
    18291864        $sql = "SELECT * FROM `".TABLE_PREFIX."collections` 
    18301865        $cond $ordering LIMIT $from,$lim"; 
    18311866        $result = run_query($sql); 
    1832         if (!mysql_num_rows($result)){ 
    1833                 $GLOBALS['plogger_level'] = "404"; 
    1834                 return false; 
    1835         } 
     1867 
    18361868        $GLOBALS["available_collections"] = mysql_num_rows($result); 
    18371869        $GLOBALS["collection_counter"] = 0; 
    18381870        $GLOBALS["collection_dbh"] = $result; 
     
    18781910        WHERE `parent_id` = '$collection_id' $cond $order LIMIT $from,$lim"; 
    18791911 
    18801912        $result = run_query($sql); 
    1881         if (!mysql_num_rows($result)){ 
    1882                 $GLOBALS['plogger_level'] = "404"; 
    1883                 return false; 
    1884         } 
     1913 
    18851914        $GLOBALS["available_albums"] = mysql_num_rows($result); 
    18861915        $GLOBALS["album_counter"] = 0; 
    18871916        $GLOBALS["album_dbh"] = $result;