Changeset 536

Show
Ignore:
Timestamp:
05/08/08 17:44:19 (7 months ago)
Author:
sidtheduck
Message:

+ Fix for ticket #157 - cleaning up notices, undefined indexes, and undefined variables

Location:
trunk
Files:
13 modified

Legend:

Unmodified
Added
Removed
  • trunk/admin/index.php

    r519 r536  
    11<?php 
    2  
    3 session_start(); 
    4  
    52require_once("../plog-functions.php"); 
    63require_once("../plog-globals.php"); 
  • trunk/admin/plog-admin-functions.php

    r532 r536  
    7171        $create_path = $dest_collection_name."/".$dest_album_name; 
    7272 
    73         while (is_file($config['basedir'].'images/'.$create_path."/".$unique_filename_base . "." . $filename_ext)){ 
    74                 $unique_filename_base = $filename_base . " (" . ++$i .")"; 
     73        while (is_file($config['basedir'].'images/'.$create_path."/".$unique_filename_base.".".$filename_ext)){ 
     74                $unique_filename_base = SmartStripSlashes($filename_base)." (" . ++$i .")"; 
    7575        } 
    7676 
     
    190190         
    191191        $picture_id = intval($picture_id); 
    192         $value = mysql_real_escape_string($value); 
     192        $value = mysql_real_escape_string(trim($value)); 
    193193 
    194194        $query = "UPDATE ".TABLE_PREFIX."pictures SET $field = '$value' WHERE id='$picture_id'"; 
     
    263263 
    264264                // make sure that the file is actually located inside our images directory 
    265                 $full_path = realpath($config['basedir'] . 'images/' . $picture['path']); 
     265                $full_path = realpath($config['basedir'] . 'images/' . SmartStripSlashes($picture['path'])); 
    266266                // also check whether this image is in the correct folder 
    267267                $relative_path = substr($full_path,0,strlen($config['basedir'])); 
    268                 $basename = basename($picture['path']); 
     268                $basename = SmartStripSlashes(basename($picture['path'])); 
    269269                if ($relative_path == $config['basedir']) { 
    270270                        foreach($thumbnail_config as $tkey => $tval) { 
     
    349349        }; 
    350350 
    351         $target_name = strtolower(sanitize_filename(SmartStripSlashes($name))); 
     351        $target_name = strtolower(sanitize_filename($name)); 
    352352         
    353353 
     
    408408        while($row = mysql_fetch_assoc($result)) { 
    409409 
    410                 $filename = basename(SmartStripSlashes($row['path'])); 
     410                $filename = basename($row['path']); 
    411411                $album_path = $row['album_path']; 
    412412 
     
    433433         
    434434        $collection_id = intval($collection_id); 
    435         $value = mysql_real_escape_string($value); 
     435        $value = mysql_real_escape_string(trim($value)); 
    436436 
    437437        $query = "UPDATE ".TABLE_PREFIX."collections SET $field = '$value' WHERE id='$collection_id'"; 
     
    473473        // if there are then .. how did they get there? Probably not through plogger and in this case do we  
    474474        // really want to delete those? 
    475         $source_collection_name = $collection["collection_path"]; 
     475        $source_collection_name = SmartStripSlashes($collection["collection_path"]); 
    476476 
    477477        $collection_directory = realpath($config['basedir'] . 'images/'.$source_collection_name); 
     
    512512        }; 
    513513 
    514         $album_folder = strtolower(sanitize_filename(SmartStripSlashes($album_name))); 
     514        $album_folder = strtolower(sanitize_filename($album_name)); 
    515515 
    516516        // first try to create the directory to hold the images, if that fails, then the album 
    517517        // will be unusable anyway 
    518         $create_path = $config["basedir"] . "images/".$row["collection_path"]."/".$album_folder; 
     518        $create_path = $config["basedir"] . "images/".SmartStripSlashes($row["collection_path"])."/".$album_folder; 
    519519 
    520520        if (!makeDirs($create_path, 0777)) { 
     
    605605 
    606606                $filename = basename($row['path']); 
    607                 $new_path = $source_collection_name."/".$target_name."/".$filename; 
     607                $new_path = mysql_real_escape_string(SmartStripSlashes($source_collection_name."/".$target_name."/".$filename)); 
    608608 
    609609                // update database 
     
    624624        }; 
    625625         
    626         $value = mysql_real_escape_string(SmartStripSlashes($value)); 
     626        $value = mysql_real_escape_string(trim(SmartStripSlashes($value))); 
    627627        $errors = $output = ""; 
    628628        $album_id = intval($album_id); 
     
    690690 
    691691        while($row = mysql_fetch_assoc($result)) { 
    692                 $filename = basename($row['path']); 
     692                $filename = SmartStripSlashes(basename($row['path'])); 
    693693 
    694694                $old_path = $source_path."/".$filename; 
     
    741741        // if there are then .. how did they get there? Probably not through plogger and in this case do we  
    742742        // really want to delete those? 
    743         $source_album_name = $album["album_path"]; 
    744         $source_collection_name = $album["collection_path"]; 
     743        $source_album_name = SmartStripSlashes($album["album_path"]); 
     744        $source_collection_name = SmartStripSlashes($album["collection_path"]); 
    745745 
    746746        $album_directory = realpath($config['basedir'] . 'images/'.$source_collection_name."/".$source_album_name); 
     
    748748        $album_path = explode('/',substr($album_directory,strlen($config['basedir']))); 
    749749        // it needs to have 3 parts - images, collection name and album name, if it doesn't, then there is something 
    750         // wrong with either collectio or album name and it's probably not safe to try to delete the directory 
     750        // wrong with either collection or album name and it's probably not safe to try to delete the directory 
    751751        if ($relative_path == $config['basedir'] && sizeof($album_path) == 3) { 
    752752                @chmod($album_directory,0777); 
     
    769769        $email = mysql_real_escape_string($email); 
    770770        $url = mysql_real_escape_string($url); 
    771         $comment = mysql_real_escape_string($comment); 
     771        $comment = mysql_real_escape_string(trim($comment)); 
    772772 
    773773        $query = "UPDATE ".TABLE_PREFIX."comments SET author = '$author', comment = '$comment', 
     
    11351135        $auto_graphic = "../graphics/auto.gif"; 
    11361136         
    1137         $output .= '<form class="edit" action="'.$_SERVER["PHP_SELF"].'?level=albums&amp;id='.$album["parent_id"].'" method="post">'; 
     1137        $output = '<form class="edit" action="'.$_SERVER["PHP_SELF"].'?level=albums&amp;id='.$album["parent_id"].'" method="post">'; 
    11381138         
    11391139        $images = '<option class="thumboption" value="0" style="padding-left: 100px; background-image: url('.$auto_graphic.');  
     
    11701170 
    11711171function plog_picture_manager($id,$from,$limit) { 
     1172        $output = ''; 
    11721173 
    11731174        plogger_init_pictures(array( 
     
    12661267 
    12671268function plog_album_manager($id,$from,$limit) { 
    1268          
     1269        $output = ''; 
    12691270         
    12701271        plogger_init_albums(array( 
     
    13431344 
    13441345function plog_collection_manager($from,$limit) { 
     1346        $output = ''; 
    13451347 
    13461348        plogger_init_collections(array( 
     
    14121414 
    14131415function plog_comment_manager($id,$from,$limit) { 
     1416        $output = ''; 
    14141417 
    14151418        plogger_init_picture(array( 
  • trunk/admin/plog-admin.php

    r520 r536  
    11<?php 
    2  
    3 //session_start(); 
    42header("Content-Type: text/html; charset=utf-8"); 
    53global $inHead; 
  • trunk/admin/plog-feedback.php

    r509 r536  
    1616         
    1717        $possible_values = array("5"=>5, "10"=>10, "20"=>20, "50"=>50); 
    18         $output= plog_tr('Entries per page') . ' <select onchange="'.$java.'" name="entries_per_page">'; 
     18        $output = plog_tr('Entries per page') . ' <select onchange="'.$java.'" name="entries_per_page">'; 
    1919         
    2020        foreach ($possible_values as $key => $value) 
     
    3737 
    3838// perform the delete function on the selected items 
    39 if (isset($_REQUEST['delete_checked']) || $_REQUEST['action'] == 'delete_checked') { 
     39if (isset($_REQUEST['delete_checked']) || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete_checked')) { 
    4040                 
    4141        if (isset($_REQUEST["Selected"])) { 
     
    5757}; 
    5858 
    59 if (isset($_REQUEST['approve_checked']) || $_REQUEST['action'] == 'approve_checked') { 
     59if (isset($_REQUEST['approve_checked']) || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'approve_checked')) { 
    6060        // set the approval bit to 1 for all selected comments 
    6161                 
     
    236236                        else { 
    237237                                if (in_array($key, $allowedCommentKeys)) 
    238                                                 $output .= "<td><p id=\"comment-$key-" . $row[id] ."\">$value&nbsp;</p></td>"; 
     238                                                $output .= "<td><p id=\"comment-$key-" . $row['id'] ."\">$value&nbsp;</p></td>"; 
    239239                        } 
    240240                } 
  • trunk/admin/plog-import.php

    r445 r536  
    5151 
    5252$output = ''; 
     53$counter = $imported = 0; 
    5354 
    5455// Check if update has been clicked, handle erroneous conditions, or upload 
    5556//print_r($_POST); 
    5657 
    57 if (isset($_POST["upload"])){ 
    58          
    59         $destinations = $_POST["destinations"]; 
    60         $captions = $_POST["captions"]; 
    61         $descriptions = $_POST["descriptions"]; 
    62         $files = $_POST["files"]; 
    63         $selected = $_POST["Selected"]; 
    64          
    65         $counter = $imported = 0; 
     58if (isset($_POST['upload'])){ 
     59         
     60        $destinations = isset($_POST['destinations']) ? $_POST['destinations'] : ''; 
     61        $captions = $_POST['captions']; 
     62        $descriptions = $_POST['descriptions']; 
     63        $files = $_POST['files']; 
     64        $selected = $_POST['Selected']; 
    6665 
    6766        global $config; 
     
    6968        $files = get_files($config['basedir'] . 'uploads'); 
    7069 
    71         if ($_POST["destination_radio"] == "new" && $_POST["new_album_name"] == ""){ 
     70        if ($_POST['destination_radio'] == "new" && $_POST["new_album_name"] == ""){ 
    7271            $output .= '<p class="errors">' . plog_tr('New album name not specified!') . '</p>'; 
    7372        } 
     
    145144                        $directories[md5($dirname)] = $dirname; 
    146145        }                 
    147                  
    148         // here we will check which group of pictures we are editing, grouped by directory 
     146 
     147                // here we will check which group of pictures we are editing, grouped by directory 
    149148        if (count($directories) > 0) { 
    150149                $output .= '<div class="actions">' . plog_tr('Would you like to import anything else?'); 
     
    155154                                 $output .= '<li><a class="folder" href="'.$_SERVER['PHP_SELF']."?directory=$dirkey".'">'.basename($group).'</a></li>'; 
    156155                } 
    157                  
     156                         
     157                        $upload_directory = $config['basedir'] . 'uploads'; 
    158158                $dirkey = md5($upload_directory); 
    159159                  $output .= '<li><a class="folder" href="'.$_SERVER['PHP_SELF']."?directory=$dirkey".'">' . plog_tr('All Pictures') . '</a></li>'; 
  • trunk/admin/plog-manage.php

    r509 r536  
    3030 
    3131function generate_move_menu($level) { 
    32          
    3332        if ($level == "albums") $parent = "collections"; 
    3433        if ($level == "pictures") $parent = "albums"; 
    35         $output .= '<input class="submit" type="submit" name="move_checked" value="' . plog_tr("Move Checked To") . '"/>'; 
     34        $output = '<input class="submit" type="submit" name="move_checked" value="' . plog_tr("Move Checked To") . '"/>'; 
    3635         
    3736        if ($level == "pictures") { 
     
    5251 
    5352function generate_albums_menu($albums) { 
    54         $output .= '<select name="group_id">'; 
     53        $output = '<select name="group_id">'; 
    5554        foreach($albums as $album_id => $album) { 
    56                 if ($_REQUEST["albums_menu"] == $album_id || $_REQUEST["new_album_name"] == $album['album_name'])  
    57                         $selected = " selected"; else $selected = ""; 
     55                $selected = ''; 
     56                // if we are on the current album then set it to be the default option 
     57                if (isset($_REQUEST["albums_menu"]) && isset($_REQUEST["new_album_name"])){ 
     58                        if ($albums_menu == $album_id || $new_album_name == $album['album_name']){ 
     59                                $selected = " selected"; 
     60                        } 
     61                } 
    5862                                                 
    5963                $output .= "<option value=\"".$album_id."\"$selected>".SmartStripSlashes($album['collection_name'])." : ".SmartStripSlashes($album['album_name'])."" ; 
  • trunk/admin/plog-options.php

    r530 r536  
    4242                `use_mod_rewrite`='".intval(@$_POST["use_mod_rewrite"])."', 
    4343                `square_thumbs`='".intval($square_thumbs)."', 
    44                 `comments_notify`='".intval($_POST["comments_notify"])."', 
     44                `comments_notify`='".intval(@$_POST["comments_notify"])."', 
    4545                `comments_moderate`='".intval($comments_moderate)."', 
    4646                `gallery_url`='".mysql_real_escape_string($_POST["gallery_url"])."', 
  • trunk/admin/plog-themes.php

    r491 r536  
    2828$inHead = '<script type="text/javascript" src="js/plogger.js"></script>'; 
    2929 
    30 $output.= "<h1>" . plog_tr("Manage Themes") . "</h1>"; 
     30$output = "<h1>" . plog_tr("Manage Themes") . "</h1>"; 
    3131 
    32 $output.= "<p>$theme_url</p>"; 
     32// what is this? 
     33//$output.= "<p>$theme_url</p>"; 
    3334 
    34 $theme_dir = $config["basedir"] . 'themes/'; 
     35$theme_dir = $config['basedir'] . 'themes/'; 
    3536 
    3637// scan list of folders within theme directory 
    3738$theme_list = read_dir($theme_dir); 
    3839 
    39 if ($_REQUEST["activate"]) { // activate new theme by setting configuration dir 
     40if (isset($_REQUEST['activate'])) { // activate new theme by setting configuration dir 
    4041        // insert into database 
    4142        $new_theme_dir = basename($_REQUEST["activate"]); 
     
    4950                } else { 
    5051                        $output .= '<p class="errors">' . plog_tr("Error Activating Theme!") . '</p>'; 
    51                 }; 
     52                } 
    5253 
    5354                // update config variable if page doesn't refresh 
     
    5556        } else { 
    5657                        $output .= '<p class="errors">' . plog_tr("No such theme") . '</p>'; 
    57         }; 
     58        } 
    5859} 
    5960 
    6061// Output table header 
    61 $output.= '<table id="theme-table" cellpadding="5" width="100%"><tr class="header"><td class="table-header-left">Theme</td><td class="table-header-middle">Description</td><td class="table-header-middle">Author</td><td class="table-header-right">&nbsp;</td></tr>'; 
     62$output .= '<table id="theme-table" cellpadding="5" width="100%"><tr class="header"><td class="table-header-left">Theme</td><td class="table-header-middle">Description</td><td class="table-header-middle">Author</td><td class="table-header-right">&nbsp;</td></tr>'; 
    6263$counter = 0; 
    6364 
     
    9091                        $output .= "<td>" .plog_tr("Active Theme") . "</td>"; 
    9192                else 
    92                         $output .= "<td><a href=\"${_SERVER[PHP_SELF]}?activate=$theme_folder_basename\">" . plog_tr('Activate') . "</a></td>"; 
    93                  
    94                  
     93                        $output .= "<td><a href=\"${_SERVER['PHP_SELF']}?activate=$theme_folder_basename\">" . plog_tr('Activate') . "</a></td>";                
     94 
    9595                $output .= "</tr>"; 
    9696                 
  • trunk/admin/plog-upload.php

    r530 r536  
    1010 
    1111function generate_albums_menu($albums) { 
     12        $albums_menu = isset($_REQUEST['albums_menu']) ?  $_REQUEST['albums_menu'] : ''; 
     13        $new_album_name = isset($_REQUEST['new_album_name']) ?  $_REQUEST['new_album_name'] : ''; 
    1214        $output =  '<select name="albums_menu" onclick="var k=document.getElementsByName(\'destination_radio\');k[0].checked=true;">'; 
    1315        foreach($albums as $album_id => $album) { 
    1416 
    15                 if ($_REQUEST["albums_menu"] == $album_id || $_REQUEST["new_album_name"] == $album['album_name'])  
     17                if ($albums_menu == $album_id || $new_album_name == $album['album_name'])  
    1618                                                $selected = " selected='selected'"; else $selected = ""; 
    1719                                                 
     
    3840} 
    3941 
     42$output = ''; 
     43 
    4044// Check if update has been clicked, handle erroneous conditions, or upload 
    41 if (isset($_REQUEST["upload"])){ 
     45if (isset($_REQUEST['upload'])){ 
    4246        foreach($_REQUEST as $key => $val) $_REQUEST[$key] = stripslashes($val); 
    4347         
     
    175179        else 
    176180                 display($output_error, "upload"); 
    177 }; 
     181} 
    178182?> 
  • trunk/plog-comment.php

    r509 r536  
    5353 
    5454// redirect back to picture page 
    55 if ($rv["errors"]) { 
     55if (isset($rv['errors'])) { 
    5656        // will this work? 
    57         $_SESSION["comment_post_error"] = $rv["errors"]; 
     57        $_SESSION['comment_post_error'] = $rv['errors']; 
    5858} 
    5959else if ($config['comments_moderate']) { 
    60         $_SESSION["comment_moderated"] = 1; 
     60        $_SESSION['comment_moderated'] = 1; 
    6161} 
    6262 
  • trunk/plog-functions.php

    r534 r536  
    961961                 
    962962                // try to detect slideshow. Downside is that you cannot have a picture with that name 
    963                 if ('slideshow' == $names['picture']) { 
     963                if (isset($names['picture']) && $names['picture'] == 'slideshow') { 
    964964                        return array('level' => 'album','mode' => 'slideshow','id' => $album['id']); 
    965965                } 
    966966                 
    967967                // deal with http://plogger/collection/album/sorted/field/asc and friends 
    968                 if ('sorted' == $names['picture']) { 
     968                if (isset($names['picture']) && $names['picture'] == 'sorted') { 
    969969                        if (isset($names['arg1'])) { 
    970970                                $_SESSION['plogger_sortby'] = $names['arg1']; 
     
    11661166        } else { 
    11671167                $approved = 1; 
     1168                $notify_msg = ''; 
    11681169        } 
    11691170         
     
    17291730function plogger_rss_link() { 
    17301731        global $config; 
     1732        $rss_link = ''; 
    17311733         
    17321734        if ($config["use_mod_rewrite"]) { 
     
    21862188 
    21872189function plogger_collection_album_count() { 
    2188         if (isset($GLOBALS["album_count"][$GLOBALS["current_collection"]["id"]])) { 
    2189                 return $GLOBALS["album_count"][$GLOBALS["current_collection"]["id"]]; 
     2190        if (isset($GLOBALS['album_count']) && isset($GLOBALS['current_collection']['id'])) { 
     2191                return $GLOBALS['album_count'][$GLOBALS['current_collection']['id']]; 
    21902192        } else { 
    21912193                return 0; 
     
    22532255 
    22542256function plogger_album_picture_count() { 
    2255         $row = $GLOBALS["current_album"]; 
    2256         // XXX: surely this can be optimized? 
    2257         $numquery = "SELECT COUNT(*) AS `num_pictures` FROM `".TABLE_PREFIX."pictures` WHERE `parent_album`='".$row["id"]."'"; 
    2258         $numresult = run_query($numquery); 
    2259         return mysql_result($numresult, 'num_pictures'); 
     2257        if (isset($GLOBALS['current_album'])) { 
     2258                $row = $GLOBALS['current_album']; 
     2259                // XXX: surely this can be optimized? 
     2260                $numquery = "SELECT COUNT(*) AS `num_pictures` FROM `".TABLE_PREFIX."pictures` WHERE `parent_album`='".$row['id']."'"; 
     2261                $numresult = run_query($numquery); 
     2262                return mysql_result($numresult, 'num_pictures'); 
     2263        } 
    22602264} 
    22612265 
     
    22952299 
    22962300function plogger_get_next_picture_link() { 
     2301        global $config; 
     2302 
    22972303        $next_url = plogger_get_next_picture_url(); 
    22982304 
    22992305        if ($next_url) 
    2300         if ($config["embedded"] == 0) { 
     2306        if ($config['embedded'] == 0) { 
    23012307                  $next_link = '<a id="next-button" accesskey="." href="'.$next_url.'#prev-button">' . plog_tr('Next') . ' &raquo;</a>';     
    23022308        } else { 
     
    23102316 
    23112317function plogger_get_prev_picture_link() { 
     2318        global $config; 
     2319 
    23122320        $prev_url = plogger_get_prev_picture_url(); 
    23132321         
    23142322        if ($prev_url)  
    2315         if ($config["embedded"] == 0) { 
     2323        if ($config['embedded'] == 0) { 
    23162324                  $prev_link = '<a id="prev-button" accesskey="," href="'.$prev_url.'#next-button">&laquo; ' . plog_tr('Previous') . '</a>'; 
    23172325        } else { 
  • trunk/plog-print.php

    r496 r536  
    66 
    77$picture = get_picture_by_id($_GET['id']); 
     8$GLOBALS['plogger_level'] = "picture"; 
     9$GLOBALS['plogger_id'] = $_GET['id']; 
     10$GLOBALS['plogger_mode'] = "print"; 
    811 
    912?> 
     
    1821 
    1922        <body onload="window.print();"> 
    20                 <div><img src="<?php echo $picture["url"]; ?>" alt="<?php echo $picture["caption"]; ?>" /></div> 
     23                <div><img src="<?php echo $picture['url']; ?>" alt="<?php echo $picture['caption']; ?>" /></div> 
    2124        </body> 
    2225 
  • trunk/plog-rss.php

    r509 r536  
    131131$parts = parse_url($_SERVER["REQUEST_URI"]); 
    132132parse_str($parts["query"],$query_parts); 
    133 generate_RSS_feed($level, $id, $query_parts["searchterms"]); 
     133if (isset($query_parts["searchterms"])) { 
     134        generate_RSS_feed($level, $id, $query_parts["searchterms"]); 
     135} else { 
     136        generate_RSS_feed($level, $id); 
     137} 
    134138 
    135139?>