Changeset 111


Ignore:
Timestamp:
Apr 27, 2006 1:49:54 AM (18 years ago)
Author:
scdev
Message:

Q - Finished depreciating addslashes. array_map instances need to use array('DB', 'escapeString') as first argument.

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/bin/file_importer.php

    r42 r111  
    4343//                     added_datetime
    4444//                 ) VALUES (
    45 //                     '" . addslashes(0) . "',
    46 //                     '" . addslashes('hosting') . "',
    47 //                     '" . addslashes($file_date) . "',
    48 //                     '" . addslashes($amt[1]) . "',
    49 //                     '" . addslashes('Paid') . "',
    50 //                     '" . addslashes('') . "',
    51 //                     '" . addslashes($file_text) . "',
    52 //                     '" . addslashes($file_date) . "',
     45//                     '" . DB::escapeString(0) . "',
     46//                     '" . DB::escapeString('hosting') . "',
     47//                     '" . DB::escapeString($file_date) . "',
     48//                     '" . DB::escapeString($amt[1]) . "',
     49//                     '" . DB::escapeString('Paid') . "',
     50//                     '" . DB::escapeString('') . "',
     51//                     '" . DB::escapeString($file_text) . "',
     52//                     '" . DB::escapeString($file_date) . "',
    5353//                     NOW()
    5454//                 )
  • trunk/bin/module_maker/form_template.cli.php

    r106 r111  
    2828
    2929// Get DB table column info.
    30 $qid = DB::query("DESCRIBE " . addslashes($db_tbl));
     30$qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
    3131while ($row = mysql_fetch_row($qid)) {
    3232    $cols[] = $row;
  • trunk/bin/module_maker/list_template.cli.php

    r51 r111  
    4141
    4242// Get DB table column info.
    43 $qid = DB::query("DESCRIBE " . addslashes($db_tbl));
     43$qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
    4444while ($row = mysql_fetch_row($qid)) {
    4545    $cols[] = $row;
  • trunk/bin/module_maker/module.cli.php

    r87 r111  
    141141// Ensure requested table contains columns.
    142142// Get DB table column info.
    143 $qid = DB::query("DESCRIBE " . addslashes($db_tbl));
     143$qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
    144144while ($row = mysql_fetch_row($qid)) {
    145145    $cols[] = $row;
  • trunk/bin/module_maker/skel/admin.php

    r42 r111  
    146146        if (getFormdata('repeat', false)) {
    147147            // Display edit function with next available ID.
    148             $qid = DB::query("SELECT %PRIMARY_KEY% FROM %DB_TBL% WHERE %PRIMARY_KEY% > '" . addslashes(getFormData('%PRIMARY_KEY%')) . "' ORDER BY %PRIMARY_KEY% ASC LIMIT 1");
     148            $qid = DB::query("SELECT %PRIMARY_KEY% FROM %DB_TBL% WHERE %PRIMARY_KEY% > '" . DB::escapeString(getFormData('%PRIMARY_KEY%')) . "' ORDER BY %PRIMARY_KEY% ASC LIMIT 1");
    149149            if (list($next_id) = mysql_fetch_row($qid)) {
    150150                App::dieURL($_SERVER['PHP_SELF'] . '?op=edit&%PRIMARY_KEY%=' . $next_id);
     
    217217        SELECT *
    218218        FROM %DB_TBL%
    219         WHERE %PRIMARY_KEY% = '" . addslashes($id) . "'
     219        WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
    220220    ");
    221221    if (!$frm = mysql_fetch_assoc($qid)) {
     
    259259        SELECT <##>
    260260        FROM %DB_TBL%
    261         WHERE %PRIMARY_KEY% = '" . addslashes($id) . "'
     261        WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
    262262    ");
    263263    if (! list($name) = mysql_fetch_row($qid)) {
     
    268268
    269269    // Delete the record.
    270     DB::query("DELETE FROM %DB_TBL% WHERE %PRIMARY_KEY% = '" . addslashes($id) . "'");
     270    DB::query("DELETE FROM %DB_TBL% WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'");
    271271
    272272    App::raiseMsg(sprintf(_("The %ITEM_TITLE% <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
     
    336336    if (getFormData('filter_<##>', false)) {
    337337        // Limit by filter.
    338         $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . " <##> = '" . addslashes(getFormData('filter_<##>')) . "'";
     338        $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . " <##> = '" . DB::escapeString(getFormData('filter_<##>')) . "'";
    339339    }
    340340
     
    418418        DB::query("
    419419            UPDATE %DB_TBL% SET
    420                 rank = '" . addslashes($new_rank) . "'
    421             WHERE %PRIMARY_KEY% = '" . addslashes($id) . "'
     420                rank = '" . DB::escapeString($new_rank) . "'
     421            WHERE %PRIMARY_KEY% = '" . DB::escapeString($id) . "'
    422422        ");
    423423    }
  • trunk/bin/module_maker/skel/public.php

    r42 r111  
    3636    $qid = DB::query("
    3737        SELECT * FROM %DB_TBL%
    38         WHERE %PRIMARY_KEY% = '" . addslashes(getFormData('%PRIMARY_KEY%')) . "'
     38        WHERE %PRIMARY_KEY% = '" . DB::escapeString(getFormData('%PRIMARY_KEY%')) . "'
    3939        AND publish = 'true'
    4040        <##>AND (publish_date <= CURDATE() OR publish_date = '0000-00-00')
     
    5050        UPDATE %DB_TBL%
    5151        SET hit_count = hit_count + 1
    52         WHERE %PRIMARY_KEY% = '" . addslashes(getFormData('%PRIMARY_KEY%')) . "'
     52        WHERE %PRIMARY_KEY% = '" . DB::escapeString(getFormData('%PRIMARY_KEY%')) . "'
    5353    ");
    5454
  • trunk/bin/module_maker/sql.cli.php

    r44 r111  
    4646
    4747// Get DB table column info.
    48 $qid = DB::query("DESCRIBE " . addslashes($db_tbl));
     48$qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
    4949while ($row = mysql_fetch_row($qid)) {
    5050    $cols[] = $row;
     
    7070        } else if ('set' == $type) {
    7171            // Set types usually need to be converted to comma-delimited lists.
    72             $c[$field] = "'\" . dbArrayToList(\$frm['$field']) . \"'";
     72            $c[$field] = "'\" . escapedList(array_keys(\$frm['$field'])) . \"'";
    7373        } else if ('featured' == $field || 'publish' == $field || preg_match("/enum\('true'\)/", $col[1])) {
    7474            // Toggle types.
     
    7676        } else if ('added_by_user_id' == $field || 'modified_by_user_id' == $field) {
    7777            // Toggle types.
    78             $c[$field] = "'\" . addslashes(\$auth->getVal('user_id')) . \"'";
     78            $c[$field] = "'\" . DB::escapeString(\$auth->getVal('user_id')) . \"'";
    7979        } else if ('added_datetime' == $field || 'modified_datetime' == $field) {
    8080            // DB record insertion datetime.
     
    8282        } else {
    8383            // Default. Just insert data.
    84             $c[$field] = "'\" . addslashes(\$frm['$field']) . \"'";
     84            $c[$field] = "'\" . DB::escapeString(\$frm['$field']) . \"'";
    8585        }
    8686    }
     
    135135    DB::query("
    136136        UPDATE $db_tbl SET$key_eq_val
    137         WHERE $primary_key = '" . addslashes(\$frm['$primary_key']) . "'
     137        WHERE $primary_key = '" . DB::escapeString(\$frm['$primary_key']) . "'
    138138    ");
    139139E_O_F;
     
    148148$delim = 'WHERE';
    149149if (!empty($primary_key)) {
    150     $where_clause = "            $delim $primary_key = '\" . addslashes(\$frm['$primary_key']) . \"'\n";
     150    $where_clause = "            $delim $primary_key = '\" . DB::escapeString(\$frm['$primary_key']) . \"'\n";
    151151    $delim = 'AND';
    152152}
     
    155155        continue;
    156156    }
    157     $where_clause .= "            $delim $k = '\" . addslashes(\$frm['$k']) . \"'\n";
     157    $where_clause .= "            $delim $k = '\" . DB::escapeString(\$frm['$k']) . \"'\n";
    158158    $delim = 'AND';
    159159}
     
    183183if (!isset($op) || 'search' == $op) {
    184184$search_skip_columns = array('added_datetime', 'added_by_user_id', 'modified_datetime', 'modified_by_user_id', 'publish', 'featured');
    185 $search_columns = $db_tbl . '.' . join(" LIKE '%\" . addslashes(\$qry_words[\$i]) . \"%'\n                    OR $db_tbl.", array_diff(array_keys($c), $search_skip_columns));
     185$search_columns = $db_tbl . '.' . join(" LIKE '%\" . DB::escapeString(\$qry_words[\$i]) . \"%'\n                    OR $db_tbl.", array_diff(array_keys($c), $search_skip_columns));
    186186echo <<<E_O_F
    187187            \$where_clause .= (empty(\$where_clause) ? 'WHERE' : 'AND') . "
    188188                (
    189                     $search_columns LIKE '%" . addslashes(\$qry_words[\$i]) . "%'
     189                    $search_columns LIKE '%" . DB::escapeString(\$qry_words[\$i]) . "%'
    190190                )
    191191            ";
  • trunk/bin/module_maker/validation.cli.php

    r42 r111  
    2828
    2929// Get DB table column info.
    30 $qid = DB::query("DESCRIBE " . addslashes($db_tbl));
     30$qid = DB::query("DESCRIBE " . DB::escapeString($db_tbl));
    3131while ($row = mysql_fetch_row($qid)) {
    3232    $cols[] = $row;
  • trunk/lib/Auth_SQL.inc.php

    r103 r111  
    305305            SELECT *, " . $this->_params['db_primary_key'] . " AS user_id
    306306            FROM " . $this->_params['db_table'] . "
    307             WHERE " . $this->_params['db_username_column'] . " = '" . addslashes($username) . "'
    308             AND BINARY userpass = '" . addslashes($this->encryptPassword($password)) . "'
     307            WHERE " . $this->_params['db_username_column'] . " = '" . DB::escapeString($username) . "'
     308            AND BINARY userpass = '" . DB::escapeString($this->encryptPassword($password)) . "'
    309309        ");
    310310
     
    453453            $qid = DB::query("
    454454                SELECT 1 FROM " . $this->_params['db_table'] . "
    455                 WHERE " . $this->_params['db_primary_key'] . " = '" . addslashes($user_id) . "'
     455                WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
    456456                AND DATE_ADD(last_login_datetime, INTERVAL '" . $this->_params['login_timeout'] . "' SECOND) > NOW()
    457457                AND DATE_ADD(last_access_datetime, INTERVAL '" . $this->_params['idle_timeout'] . "' SECOND) > NOW()
     
    572572
    573573        if ($this->getParam('blocking')) {
    574             if (strlen(addslashes($reason)) > 255) {
     574            if (strlen(DB::escapeString($reason)) > 255) {
    575575                // blocked_reason field is varchar(255).
    576576                App::logMsg(sprintf('Blocked reason provided is greater than 255 characters: %s', $reason), LOG_WARNING, __FILE__, __LINE__);
     
    582582                UPDATE " . $this->_params['db_table'] . " SET
    583583                blocked = 'true',
    584                 blocked_reason = '" . addslashes($reason) . "'
    585                 WHERE " . $this->_params['db_primary_key'] . " = '" . addslashes($user_id) . "'
     584                blocked_reason = '" . DB::escapeString($reason) . "'
     585                WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
    586586            ");
    587587        }
     
    602602                blocked = '',
    603603                blocked_reason = ''
    604                 WHERE " . $this->_params['db_primary_key'] . " = '" . addslashes($user_id) . "'
     604                WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
    605605            ");
    606606        }
     
    620620            SELECT 1
    621621            FROM " . $this->_params['db_table'] . "
    622             WHERE " . $this->_params['db_username_column'] . " = '" . addslashes($username) . "'
     622            WHERE " . $this->_params['db_username_column'] . " = '" . DB::escapeString($username) . "'
    623623        ");
    624624        return (mysql_num_rows($qid) > 0);
     
    638638            SELECT " . $this->_params['db_username_column'] . "
    639639            FROM " . $this->_params['db_table'] . "
    640             WHERE " . $this->_params['db_primary_key'] . " = '" . addslashes($user_id) . "'
     640            WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
    641641        ");
    642642        if (list($username) = mysql_fetch_row($qid)) {
     
    717717        DB::query("
    718718            UPDATE " . $this->_params['db_table'] . "
    719             SET userpass = '" . addslashes($this->encryptPassword($password)) . "'
    720             WHERE " . $this->_params['db_primary_key'] . " = '" . addslashes($user_id) . "'
     719            SET userpass = '" . DB::escapeString($this->encryptPassword($password)) . "'
     720            WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
    721721        ");
    722722    }
     
    739739        $qid = DB::query("
    740740            SELECT * FROM " . $this->_params['db_table'] . "
    741             WHERE " . $this->_params['db_primary_key'] . " = '" . addslashes($user_id) . "'
     741            WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
    742742        ");
    743743        if (!$user_data = mysql_fetch_assoc($qid)) {
  • trunk/lib/Hierarchy.inc.php

    r92 r111  
    197197                    title
    198198                ) VALUES (
    199                     '" . addslashes($parent['node_type']) . "',
    200                     '" . addslashes($parent['node_id']) . "',
    201                     '" . addslashes($child_type) . "',
    202                     '" . addslashes($child_id) . "',
    203                     " . (is_null($relationship_type) ? "NULL" : "'" . addslashes($relationship_type) . "'") . ",
    204                     '" . addslashes($title) . "'
     199                    '" . DB::escapeString($parent['node_type']) . "',
     200                    '" . DB::escapeString($parent['node_id']) . "',
     201                    '" . DB::escapeString($child_type) . "',
     202                    '" . DB::escapeString($child_id) . "',
     203                    " . (is_null($relationship_type) ? "NULL" : "'" . DB::escapeString($relationship_type) . "'") . ",
     204                    '" . DB::escapeString($title) . "'
    205205                )
    206206            ");
     
    245245        DB::query("
    246246            DELETE FROM node_tbl
    247             WHERE child_type = '" . addslashes($child_type) . "'
    248             AND child_id = '" . addslashes($child_id) . "'
     247            WHERE child_type = '" . DB::escapeString($child_type) . "'
     248            AND child_id = '" . DB::escapeString($child_id) . "'
    249249        ");
    250250        App::logMsg(sprintf('deleteNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
     
    311311            $qid = DB::query("
    312312                SELECT title FROM node_tbl
    313                 WHERE child_type = '" . addslashes($child_type) . "'
    314                 AND child_id = '" . addslashes($child_id) . "'
    315                 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . addslashes($relationship_type) . "'") . "
     313                WHERE child_type = '" . DB::escapeString($child_type) . "'
     314                AND child_id = '" . DB::escapeString($child_id) . "'
     315                AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "
    316316            ");
    317317            list($title) = mysql_fetch_row($qid);
     
    321321        DB::query("
    322322            DELETE FROM node_tbl
    323             WHERE child_type = '" . addslashes($child_type) . "'
    324             AND child_id = '" . addslashes($child_id) . "'
    325             AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . addslashes($relationship_type) . "'") . "
     323            WHERE child_type = '" . DB::escapeString($child_type) . "'
     324            AND child_id = '" . DB::escapeString($child_id) . "'
     325            AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "
    326326        ");
    327327        App::logMsg(sprintf('moveNode: Deleted node %s %s.', $child_type, $child_id), LOG_DEBUG, __FILE__, __LINE__);
     
    359359                $type_constraint = array($type_constraint);
    360360            }
    361             $in_clause = "AND parent_type IN ('" . join("','", array_map('addslashes', $type_constraint)) . "')";
     361            $in_clause = "AND parent_type IN ('" . join("','", array_map(array('DB', 'escapeString'), $type_constraint)) . "')";
    362362        }
    363363
     
    365365            SELECT parent_type, parent_id
    366366            FROM node_tbl
    367             WHERE child_type = '" . addslashes($child_type) . "'
    368             AND child_id = '" . addslashes($child_id) . "'
     367            WHERE child_type = '" . DB::escapeString($child_type) . "'
     368            AND child_id = '" . DB::escapeString($child_id) . "'
    369369            $in_clause
    370             " . addslashes($order) . "
     370            " . DB::escapeString($order) . "
    371371        ");
    372372
     
    405405            SELECT child_type, child_id, title, subnode_quantity
    406406            FROM node_tbl
    407             WHERE child_type = '" . addslashes($child_type) . "'
    408             AND child_id = '" . addslashes($child_id) . "'
     407            WHERE child_type = '" . DB::escapeString($child_type) . "'
     408            AND child_id = '" . DB::escapeString($child_id) . "'
    409409        ");
    410410
     
    448448                $type_constraint = array($type_constraint);
    449449            }
    450             $in_clause = "AND child_type IN ('" . join("','", array_map('addslashes', $type_constraint)) . "')";
     450            $in_clause = "AND child_type IN ('" . join("','", array_map(array('DB', 'escapeString'), $type_constraint)) . "')";
    451451        }
    452452
     
    454454            SELECT *
    455455            FROM node_tbl
    456             WHERE parent_type = '" . addslashes($child_type) . "'
    457             AND parent_id = '" . addslashes($child_id) . "'
     456            WHERE parent_type = '" . DB::escapeString($child_type) . "'
     457            AND parent_id = '" . DB::escapeString($child_id) . "'
    458458            $in_clause
    459             " . addslashes($order) . "
     459            " . DB::escapeString($order) . "
    460460        ");
    461461
     
    497497                $type_constraint = array($type_constraint);
    498498            }
    499             $in_clause = "AND child_type IN ('" . join("','", array_map('addslashes', $type_constraint)) . "')";
     499            $in_clause = "AND child_type IN ('" . join("','", array_map(array('DB', 'escapeString'), $type_constraint)) . "')";
    500500        }
    501501
     
    503503            SELECT COUNT(*)
    504504            FROM node_tbl
    505             WHERE parent_type = '" . addslashes($child_type) . "'
    506             AND parent_id = '" . addslashes($child_id) . "'
     505            WHERE parent_type = '" . DB::escapeString($child_type) . "'
     506            AND parent_id = '" . DB::escapeString($child_id) . "'
    507507            $in_clause
    508508        ");
     
    585585            SELECT parent_type, parent_id, child_type, child_id, title, subnode_quantity
    586586            FROM node_tbl
    587             WHERE child_type = '" . addslashes($child_type) . "'
    588             AND child_id = '" . addslashes($child_id) . "'
     587            WHERE child_type = '" . DB::escapeString($child_type) . "'
     588            AND child_id = '" . DB::escapeString($child_id) . "'
    589589        ");
    590590        while ($row = mysql_fetch_assoc($qid)) {
     
    644644            $qid = DB::query("
    645645                SELECT 1 FROM node_tbl
    646                 WHERE parent_type = '" . addslashes($parent_type) . "'
    647                 AND parent_id = '" . addslashes($parent_id) . "'
    648                 AND child_type = '" . addslashes($child_type) . "'
    649                 AND child_id = '" . addslashes($child_id) . "'
    650                 AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . addslashes($relationship_type) . "'") . "
     646                WHERE parent_type = '" . DB::escapeString($parent_type) . "'
     647                AND parent_id = '" . DB::escapeString($parent_id) . "'
     648                AND child_type = '" . DB::escapeString($child_type) . "'
     649                AND child_id = '" . DB::escapeString($child_id) . "'
     650                AND relationship_type " . (is_null($relationship_type) ? "IS NULL" : "= '" . DB::escapeString($relationship_type) . "'") . "
    651651            ");
    652652        } else {
    653653            $qid = DB::query("
    654654                SELECT 1 FROM node_tbl
    655                 WHERE child_type = '" . addslashes($child_type) . "'
    656                 AND child_id = '" . addslashes($child_id) . "'
     655                WHERE child_type = '" . DB::escapeString($child_type) . "'
     656                AND child_id = '" . DB::escapeString($child_id) . "'
    657657            ");
    658658        }
     
    775775        DB::query("
    776776            UPDATE node_tbl
    777             SET subnode_quantity = subnode_quantity + '" . addslashes($num_children) . "'
    778             WHERE child_type = '" . addslashes($child_type) . "'
    779             AND child_id = '" . addslashes($child_id) . "'
     777            SET subnode_quantity = subnode_quantity + '" . DB::escapeString($num_children) . "'
     778            WHERE child_type = '" . DB::escapeString($child_type) . "'
     779            AND child_id = '" . DB::escapeString($child_id) . "'
    780780        ",false);
    781781        $qid = DB::query("
    782782            SELECT parent_type, parent_id
    783783            FROM node_tbl
    784             WHERE child_type = '" . addslashes($child_type) . "'
    785             AND child_id = '" . addslashes($child_id) . "'
     784            WHERE child_type = '" . DB::escapeString($child_type) . "'
     785            AND child_id = '" . DB::escapeString($child_id) . "'
    786786        ",false);
    787787        while ((list($parent_type, $parent_id) = mysql_fetch_row($qid)) && $parent_id > 0) {
  • trunk/lib/PageNumbers.inc.php

    r53 r111  
    190190    {
    191191        if (is_numeric($this->first_item) && is_numeric($this->_per_page)) {
    192             return ' LIMIT ' . addslashes($this->first_item) . ', ' . addslashes($this->_per_page) . ' ';
     192            return ' LIMIT ' . DB::escapeString($this->first_item) . ', ' . DB::escapeString($this->_per_page) . ' ';
    193193        } else {
    194194            App::logMsg(sprintf('Could not find SQL to LIMIT by %s %s.', $this->first_item, $this->_per_page), LOG_WARNING, __FILE__, __LINE__);
  • trunk/lib/RecordLock.inc.php

    r71 r111  
    156156            $qid = DB::query("
    157157                SELECT * FROM " . $this->getParam('db_table') . "
    158                 WHERE lock_id = '" . addslashes($record_table_or_lock_id) . "'
     158                WHERE lock_id = '" . DB::escapeString($record_table_or_lock_id) . "'
    159159            ");
    160160        } else {
     
    162162            $qid = DB::query("
    163163                SELECT * FROM " . $this->getParam('db_table') . "
    164                 WHERE record_table = '" . addslashes($record_table_or_lock_id) . "'
    165                 AND record_key = '" . addslashes($record_key) . "'
    166                 AND record_val = '" . addslashes($record_val) . "'
     164                WHERE record_table = '" . DB::escapeString($record_table_or_lock_id) . "'
     165                AND record_key = '" . DB::escapeString($record_key) . "'
     166                AND record_val = '" . DB::escapeString($record_val) . "'
    167167            ");
    168168        }
     
    199199
    200200        if (isset($this->data['lock_id'])) {
    201             $qid = DB::query("SELECT * FROM " . $this->getParam('db_table') . " WHERE lock_id = '" . addslashes($this->data['lock_id']) . "'");
     201            $qid = DB::query("SELECT * FROM " . $this->getParam('db_table') . " WHERE lock_id = '" . DB::escapeString($this->data['lock_id']) . "'");
    202202            if ($lock = mysql_fetch_assoc($qid)) {
    203203                return ($lock['set_by_admin_id'] == $this->_auth->getVal('user_id'));
     
    230230        DB::query("
    231231            DELETE FROM " . $this->getParam('db_table') . "
    232             WHERE record_table = '" . addslashes($record_table) . "'
    233             AND record_key = '" . addslashes($record_key) . "'
    234             AND record_val = '" . addslashes($record_val) . "'
     232            WHERE record_table = '" . DB::escapeString($record_table) . "'
     233            AND record_key = '" . DB::escapeString($record_key) . "'
     234            AND record_val = '" . DB::escapeString($record_val) . "'
    235235        ");
    236236
     
    245245                lock_datetime
    246246            ) VALUES (
    247                 '" . addslashes($record_table) . "',
    248                 '" . addslashes($record_key) . "',
    249                 '" . addslashes($record_val) . "',
    250                 '" . addslashes($title) . "',
    251                 '" . addslashes($this->_auth->getVal('user_id')) . "',
     247                '" . DB::escapeString($record_table) . "',
     248                '" . DB::escapeString($record_key) . "',
     249                '" . DB::escapeString($record_val) . "',
     250                '" . DB::escapeString($title) . "',
     251                '" . DB::escapeString($this->_auth->getVal('user_id')) . "',
    252252                NOW()
    253253            )
     
    274274        DB::query("
    275275            DELETE FROM " . $this->getParam('db_table') . "
    276             WHERE lock_id = '" . addslashes($this->data['lock_id']) . "'
     276            WHERE lock_id = '" . DB::escapeString($this->data['lock_id']) . "'
    277277        ");
    278278
     
    292292        if (isset($user_id)) {
    293293            // Delete specific user's locks.
    294             DB::query("DELETE FROM " . $this->getParam('db_table') . " WHERE set_by_admin_id = '" . addslashes($user_id) . "'");
     294            DB::query("DELETE FROM " . $this->getParam('db_table') . " WHERE set_by_admin_id = '" . DB::escapeString($user_id) . "'");
    295295            App::logMsg(sprintf('Record locks owned by %s %s have been deleted', $this->_auth->getVal('auth_name'), $this->_auth->getUsername($user_id)), LOG_DEBUG, __FILE__, __LINE__);
    296296        } else {
  • trunk/lib/RecordVersion.inc.php

    r49 r111  
    182182                version_datetime
    183183            ) VALUES (
    184                 '" . addslashes($record_table) . "',
    185                 '" . addslashes($record_key) . "',
    186                 '" . addslashes($record_val) . "',
    187                 '" . addslashes(gzcompress(serialize($record), 9)) . "',
    188                 '" . addslashes($title) . "',
    189                 '" . addslashes($notes) . "',
    190                 '" . addslashes($this->_auth->getVal('user_id')) . "',
     184                '" . DB::escapeString($record_table) . "',
     185                '" . DB::escapeString($record_key) . "',
     186                '" . DB::escapeString($record_val) . "',
     187                '" . DB::escapeString(gzcompress(serialize($record), 9)) . "',
     188                '" . DB::escapeString($title) . "',
     189                '" . DB::escapeString($notes) . "',
     190                '" . DB::escapeString($this->_auth->getVal('user_id')) . "',
    191191                NOW()
    192192            )
     
    210210        $qid = DB::query("
    211211            SELECT * FROM " . $this->getParam('db_table') . "
    212             WHERE version_id = '" . addslashes($version_id) . "'
     212            WHERE version_id = '" . DB::escapeString($version_id) . "'
    213213        ");
    214214        if (!$record = mysql_fetch_assoc($qid)) {
     
    227227
    228228        // SQLize the keys of the specified versioned record.
    229         $replace_keys = join(",\n", array_map('addslashes', array_keys($data)));
     229        $replace_keys = join(",\n", array_map(array('DB', 'escapeString'), array_keys($data)));
    230230
    231231        // SQLize the keys of the values of the specified versioned record. (These are more complex because we need to account for SQL null values.)
     
    233233        $comma = '';
    234234        foreach ($data as $v) {
    235             $replace_values .= is_null($v) ? "$comma\nNULL" : "$comma\n'" . addslashes($v) . "'";
     235            $replace_values .= is_null($v) ? "$comma\nNULL" : "$comma\n'" . DB::escapeString($v) . "'";
    236236            $comma = ',';
    237237        }
     
    268268        $qid = DB::query("
    269269            SELECT COUNT(*) FROM " . $this->getParam('db_table') . "
    270             WHERE record_table = '" . addslashes($record_table) . "'
    271             AND record_key = '" . addslashes($record_key) . "'
    272             AND record_val = '" . addslashes($record_val) . "'
     270            WHERE record_table = '" . DB::escapeString($record_table) . "'
     271            AND record_key = '" . DB::escapeString($record_key) . "'
     272            AND record_val = '" . DB::escapeString($record_val) . "'
    273273        ");
    274274        list($v_count) = mysql_fetch_row($qid);
     
    280280                $qid = DB::query("
    281281                    SELECT version_id FROM " . $this->getParam('db_table') . "
    282                     WHERE record_table = '" . addslashes($record_table) . "'
    283                     AND record_key = '" . addslashes($record_key) . "'
    284                     AND record_val = '" . addslashes($record_val) . "'
     282                    WHERE record_table = '" . DB::escapeString($record_table) . "'
     283                    AND record_key = '" . DB::escapeString($record_key) . "'
     284                    AND record_val = '" . DB::escapeString($record_val) . "'
    285285                    ORDER BY version_datetime ASC
    286286                    LIMIT " . ($v_count - $this->getParam('min_qty')) . "
     
    297297                $qid = DB::query("
    298298                    SELECT version_id FROM " . $this->getParam('db_table') . "
    299                     WHERE record_table = '" . addslashes($record_table) . "'
    300                     AND record_key = '" . addslashes($record_key) . "'
    301                     AND record_val = '" . addslashes($record_val) . "'
     299                    WHERE record_table = '" . DB::escapeString($record_table) . "'
     300                    AND record_key = '" . DB::escapeString($record_key) . "'
     301                    AND record_val = '" . DB::escapeString($record_val) . "'
    302302                    AND DATE_ADD(version_datetime, INTERVAL '" . $this->getParam('min_days') . "' DAY) < NOW()
    303303                    ORDER BY version_datetime ASC
     
    334334            SELECT version_id, saved_by_admin_id, version_datetime, version_title
    335335            FROM " . $this->getParam('db_table') . "
    336             WHERE record_table = '" . addslashes($record_table) . "'
    337             AND record_key = '" . addslashes($record_key) . "'
    338             AND record_val = '" . addslashes($record_val) . "'
     336            WHERE record_table = '" . DB::escapeString($record_table) . "'
     337            AND record_key = '" . DB::escapeString($record_key) . "'
     338            AND record_val = '" . DB::escapeString($record_val) . "'
    339339            ORDER BY version_datetime DESC
    340340        ");
     
    362362        $qid = DB::query("
    363363            SELECT * FROM " . $this->getParam('db_table') . "
    364             WHERE version_id = '" . addslashes($version_id) . "'
     364            WHERE version_id = '" . DB::escapeString($version_id) . "'
    365365        ");
    366366        return mysql_fetch_assoc($qid);
     
    381381        $qid = DB::query("
    382382            SELECT * FROM " . $this->getParam('db_table') . "
    383             WHERE version_id = '" . addslashes($version_id) . "'
     383            WHERE version_id = '" . DB::escapeString($version_id) . "'
    384384        ");
    385385        $record = mysql_fetch_assoc($qid);
     
    403403
    404404        $qid = DB::query("
    405             SELECT * FROM " . addslashes($record_table) . "
    406             WHERE " . addslashes($record_key) . " = '" . addslashes($record_val) . "'
     405            SELECT * FROM " . DB::escapeString($record_table) . "
     406            WHERE " . DB::escapeString($record_key) . " = '" . DB::escapeString($record_val) . "'
    407407        ");
    408408        if ($record = mysql_fetch_assoc($qid)) {
  • trunk/lib/SortOrder.inc.php

    r46 r111  
    143143
    144144        if (!empty($this->_columns[strtolower($this->sort_by)][strtolower($this->order)])) {
    145             return sprintf(' ORDER BY %s ', addslashes($this->_columns[strtolower($this->sort_by)][strtolower($this->order)]));
     145            return sprintf(' ORDER BY %s ', DB::escapeString($this->_columns[strtolower($this->sort_by)][strtolower($this->order)]));
    146146        } else {
    147147            App::logMsg(sprintf('Could not find SQL to sort by %s %s.', $this->sort_by, $this->order), LOG_WARNING, __FILE__, __LINE__);
  • trunk/lib/TemplateGlue.inc.php

    r64 r111  
    6666function getSetEnumFieldValues($db_table, $db_col)
    6767{
    68     $qid = DB::query("SHOW COLUMNS FROM " . addslashes($db_table) . " LIKE '" . addslashes($db_col) . "'",false);
     68    $qid = DB::query("SHOW COLUMNS FROM " . DB::escapeString($db_table) . " LIKE '" . DB::escapeString($db_col) . "'",false);
    6969
    7070    $row = mysql_fetch_row($qid);
  • trunk/lib/Utilities.inc.php

    r103 r111  
    105105/**
    106106 * Returns text with stylistic modifications. Warning: this will break some HTML attibutes!
    107  * FIXME: Allow a string such as this to be passted: <a href="javascript:openPopup('/foo/bar.php')">Click here</a>
     107 * TODO: Allow a string such as this to be passted: <a href="javascript:openPopup('/foo/bar.php')">Click here</a>
    108108 *
    109109 * @param  string   $txt  Text to clean.
     
    463463
    464464/**
    465  * Adds slashes to values of an array and converts the array to a
    466  * comma delimited list. If value provided is not an array or is empty
    467  * return nothing. This is useful for putting values coming in from
    468  * posted checkboxes into a SET column of a database.
    469  *
    470  * @param  array $array   Array to convert.
     465 * Adds slashes to values of an array and converts the array to a comma
     466 * delimited list. If value provided is a string return the string
     467 * escaped.  This is useful for putting values coming in from posted
     468 * checkboxes into a SET column of a database.
     469 *
     470 *
     471 * @param  array $in      Array to convert.
    471472 * @return string         Comma list of array values.
    472473 */
    473 function dbArrayToList($array)
    474 {
    475     if (is_array($array) && !empty($array)) {
    476         return join(',', array_map('addslashes', array_keys($array)));
    477     }
    478 }
    479 
    480 /**
    481  * Converts a human string date into a SQL-safe date.
    482  * Dates nearing infinity use the date 2038-01-01 so conversion to unix time
    483  * format remain within valid range.
     474function escapedList($in)
     475{
     476    if (is_array($in) && !empty($in)) {
     477        return "'" . join("', '", array_map(array('DB', 'escapeString'), $in)) . "'";
     478    } else {
     479        return DB::escapeString($in);
     480    }
     481}
     482
     483/**
     484 * Converts a human string date into a SQL-safe date.  Dates nearing
     485 * infinity use the date 2038-01-01 so conversion to unix time format
     486 * remain within valid range.
    484487 *
    485488 * @param  array $date     String date to convert.
  • trunk/services/admins.php

    r72 r111  
    154154        if (getFormdata('repeat', false)) {
    155155            // Display edit function with next available ID.
    156             $qid = DB::query("SELECT admin_id FROM admin_tbl WHERE admin_id > '" . addslashes(getFormData('admin_id')) . "' ORDER BY admin_id ASC LIMIT 1");
     156            $qid = DB::query("SELECT admin_id FROM admin_tbl WHERE admin_id > '" . DB::escapeString(getFormData('admin_id')) . "' ORDER BY admin_id ASC LIMIT 1");
    157157            if (list($next_id) = mysql_fetch_row($qid)) {
    158158                App::dieURL($_SERVER['PHP_SELF'] . '?op=edit&admin_id=' . $next_id);
     
    268268        SELECT *
    269269        FROM admin_tbl
    270         WHERE admin_id = '" . addslashes($id) . "'
     270        WHERE admin_id = '" . DB::escapeString($id) . "'
    271271    ");
    272272    if (!$frm = mysql_fetch_assoc($qid)) {
     
    325325    $qid = DB::query("
    326326        SELECT username, user_type from admin_tbl
    327         WHERE admin_id = '" . addslashes($id) . "'
     327        WHERE admin_id = '" . DB::escapeString($id) . "'
    328328    ");
    329329    if (! list($name, $user_type) = mysql_fetch_row($qid)) {
     
    347347    } else {
    348348        // Delete the record.
    349         DB::query("DELETE FROM admin_tbl WHERE admin_id = '" . addslashes($id) . "'");
     349        DB::query("DELETE FROM admin_tbl WHERE admin_id = '" . DB::escapeString($id) . "'");
    350350        App::raiseMsg(sprintf(_("The admin <strong>%s</strong> has been deleted."), $name), MSG_SUCCESS, __FILE__, __LINE__);
    351351    }
     
    373373            added_datetime
    374374        ) VALUES (
    375             '" . addslashes($frm['username']) . "',
    376             '" . addslashes($frm['first_name']) . "',
    377             '" . addslashes($frm['last_name']) . "',
    378             '" . addslashes($frm['email']) . "',
    379             '" . addslashes($frm['user_type']) . "',
    380             '" . addslashes($auth->getVal('user_id')) . "',
     375            '" . DB::escapeString($frm['username']) . "',
     376            '" . DB::escapeString($frm['first_name']) . "',
     377            '" . DB::escapeString($frm['last_name']) . "',
     378            '" . DB::escapeString($frm['email']) . "',
     379            '" . DB::escapeString($frm['user_type']) . "',
     380            '" . DB::escapeString($auth->getVal('user_id')) . "',
    381381            NOW()
    382382        )
     
    417417    DB::query("
    418418        UPDATE admin_tbl SET
    419             username = '" . addslashes($frm['username']) . "',
    420             first_name = '" . addslashes($frm['first_name']) . "',
    421             last_name = '" . addslashes($frm['last_name']) . "',
    422             email = '" . addslashes($frm['email']) . "',
    423             user_type = '" . addslashes($frm['user_type']) . "',
    424             modified_by_user_id = '" . addslashes($auth->getVal('user_id')) . "',
     419            username = '" . DB::escapeString($frm['username']) . "',
     420            first_name = '" . DB::escapeString($frm['first_name']) . "',
     421            last_name = '" . DB::escapeString($frm['last_name']) . "',
     422            email = '" . DB::escapeString($frm['email']) . "',
     423            user_type = '" . DB::escapeString($frm['user_type']) . "',
     424            modified_by_user_id = '" . DB::escapeString($auth->getVal('user_id')) . "',
    425425            modified_datetime = NOW()
    426         WHERE admin_id = '" . addslashes($frm['admin_id']) . "'
     426        WHERE admin_id = '" . DB::escapeString($frm['admin_id']) . "'
    427427    ");
    428428
     
    450450            $where_clause .= (empty($where_clause) ? 'WHERE' : 'AND') . "
    451451                (
    452                     admin_tbl.username LIKE '%" . addslashes($qry_words[$i]) . "%'
    453                     OR admin_tbl.first_name LIKE '%" . addslashes($qry_words[$i]) . "%'
    454                     OR admin_tbl.last_name LIKE '%" . addslashes($qry_words[$i]) . "%'
    455                     OR admin_tbl.email LIKE '%" . addslashes($qry_words[$i]) . "%'
     452                    admin_tbl.username LIKE '%" . DB::escapeString($qry_words[$i]) . "%'
     453                    OR admin_tbl.first_name LIKE '%" . DB::escapeString($qry_words[$i]) . "%'
     454                    OR admin_tbl.last_name LIKE '%" . DB::escapeString($qry_words[$i]) . "%'
     455                    OR admin_tbl.email LIKE '%" . DB::escapeString($qry_words[$i]) . "%'
    456456                )
    457457            ";
Note: See TracChangeset for help on using the changeset viewer.