Changeset 759 for branches/1.1dev/lib


Ignore:
Timestamp:
Feb 10, 2022 1:48:35 AM (2 years ago)
Author:
anonymous
Message:

Minor

Location:
branches/1.1dev/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/1.1dev/lib/Email.inc.php

    r735 r759  
    209209        // Apply regex pattern to search elements.
    210210        $search = array_keys($replacements);
    211         array_walk($search, create_function('&$v', '$v = "{" . mb_strtoupper($v) . "}";'));
     211        array_walk($search, function (&$v) {
     212            $v = sprintf('{%s}', mb_strtoupper($v));
     213        });
    212214
    213215        // Replacement values.
  • branches/1.1dev/lib/TemplateGlue.inc.php

    r382 r759  
    66
    77/**
    8  * Print URL to download file with BBEdit/Interarchy. "USER" must be a pre-set 
     8 * Print URL to download file with BBEdit/Interarchy. "USER" must be a pre-set
    99 * environment variable. Files must reside within and be relative to env "DOCUMENT_ROOT".
    1010 *
     
    2121
    2222/**
    23  * Prints an image tag for image specified in $src. 
     23 * Prints an image tag for image specified in $src.
    2424 *
    2525 * @param  string $src     File name of the image, including dir and file extension.
     
    3030{
    3131    $filepath = preg_match('!://!', $src) ? $src : getenv('DOCUMENT_ROOT') . $src;
    32    
     32
    3333    if (false === ($gis = @getimagesize($filepath)) || preg_match('/width|height/', $extra)) {
    3434        $image_size = '';
     
    3636        $image_size = $gis[3];
    3737    }
    38    
     38
    3939    return sprintf('<img src="%s" %s alt="%s" %s />',
    4040        $src,
     
    5252 * Finds the values of an enumeration or set column of a MySQL database, returning them in an array.
    5353 * Use this to generate a pull-down menu of options or to validate the existance
    54  * of options. (Quinn 10 Feb 2001) 
     54 * of options. (Quinn 10 Feb 2001)
    5555 *
    5656 * @param  string $db_table   database table to lookup
     
    6262{
    6363    $qid = dbQuery("SHOW COLUMNS FROM $db_table LIKE '$db_col'",false);
    64        
     64
    6565    $row = mysql_fetch_row($qid);
    66     if (preg_match('/^enum|^set/i', $row[1]) && preg_match_all("/'([^']*)'/", $row[1], $enum)) {
     66    if (isset($row[1]) && preg_match('/^enum|^set/i', $row[1]) && preg_match_all("/'([^']*)'/", $row[1], $enum)) {
    6767        natsort($enum[1]);
    6868        return $enum[1];
     
    7474/**
    7575 * Prints option fields for a select form. Works only with enum or set
    76  * data types in table columns. 
     76 * data types in table columns.
    7777 *
    7878 * @param  string $db_table   database table to lookup
     
    109109/**
    110110 * Prints checkbox fields. Works only with enum or set
    111  * data types in table columns. 
     111 * data types in table columns.
    112112 *
    113113 * @param  string $db_table      database table to lookup
     
    118118 */
    119119function printSetCheckboxes($db_table, $db_col, $preselected, $columns=1, $flag=null)
    120 {   
     120{
    121121    // Sometimes preselected comes as a comma list.
    122122    if (!is_array($preselected)) {
    123123        $preselected = explode(',', $preselected);
    124124    }
    125    
     125
    126126    // Checkbox POST data has the primary data in the keys, and 'on' as the values.
    127127    // Here we assume in all the values of an array are 'on' that we can find the data
     
    131131        $preselected = array_keys($preselected);
    132132    }
    133    
    134     // Retreive values of a Set or ENUM database column. 
     133
     134    // Retreive values of a Set or ENUM database column.
    135135    $values = getSetEnumFieldValues($db_table, $db_col);
    136    
     136
    137137    if (!empty($values)) {
    138138        ?>
     
    160160            $curr = $num_rows * $col_cnt + $lastrow_add + $row_cnt;
    161161            $col_cnt++;
    162        
     162
    163163            // Look for preselected value.
    164164            if (in_array($item, $preselected)) {
     
    189189/**
    190190 * Prints radio select fields. Works only with enum or set
    191  * data types in table columns. 
     191 * data types in table columns.
    192192 *
    193193 * @param  string $db_table      database table to lookup
     
    198198 */
    199199function printSetRadios($db_table, $db_col, $preselected, $columns=1, $flag=null)
    200 {   
     200{
    201201    // Sometimes preselected comes as a comma list.
    202202    if (!is_array($preselected)) {
    203203        $preselected = explode(',', $preselected);
    204204    }
    205    
     205
    206206    // Checkbox POST data has the primary data in the keys, and 'on' as the values.
    207207    // Here we assume in all the values of an array are 'on' that we can find the data
     
    211211        $preselected = array_keys($preselected);
    212212    }
    213    
    214     // Retreive values of a Set or ENUM database column. 
     213
     214    // Retreive values of a Set or ENUM database column.
    215215    $values = getSetEnumFieldValues($db_table, $db_col);
    216    
     216
    217217    if (!empty($values)) {
    218218        ?>
     
    240240            $curr = $num_rows * $col_cnt + $lastrow_add + $row_cnt;
    241241            $col_cnt++;
    242        
     242
    243243            // Look for preselected value.
    244244            if (in_array($item, $preselected)) {
     
    262262
    263263/**
    264  * Prints a pulldown menu containing the specified values and keys of a table. 
     264 * Prints a pulldown menu containing the specified values and keys of a table.
    265265 *
    266266 * @param  string $db_table         database table to lookup
     
    284284        <?php
    285285    }
    286    
     286
    287287    // When the 'blank' value needs a specific key->val pair.
    288288    if (is_array($blank)) {
     
    304304/**
    305305 * Prints checkbox fields. Works only with enum or set
    306  * data types in table columns. 
     306 * data types in table columns.
    307307 *
    308308 * @param  string $db_table         database table to lookup
     
    321321        $preselected = explode(',', $preselected);
    322322    }
    323    
     323
    324324    // Checkbox POST data has the primary data in the keys, and 'on' as the values.
    325325    // Here we assume in all the values of an array are 'on' that we can find the data
     
    329329        $preselected = array_keys($preselected);
    330330    }
    331    
     331
    332332    $qid = dbQuery("SELECT $key_column, $val_column FROM $db_table $extra_clause",false);
    333333    while ($row = mysql_fetch_assoc($qid)) {
    334334        $values[] = $row;
    335335    }
    336    
     336
    337337    // Rearrange array so sort is in vertical columns.
    338338//  if ($vert_columns) {
     
    360360        return false;
    361361    }
    362    
     362
    363363    // Initialize the HTML table generation vars.
    364364    $num_cells = sizeof($values) - 1;
     
    378378            $row_cnt++;
    379379        }
    380        
     380
    381381        if ($col_cnt < $cols_lastrow) {
    382382            $lastrow_add = $col_cnt;
     
    384384            $lastrow_add = $cols_lastrow;
    385385        }
    386        
     386
    387387        $curr = $num_rows * $col_cnt + $lastrow_add + $row_cnt;
    388388        $col_cnt++;
    389        
     389
    390390        // Look for preselected value.
    391391        if (in_array($box[$val_column], $preselected)) {
     
    394394            $checked = '';
    395395        }
    396        
     396
    397397        // Print a cell with named checkboxes.
    398398        $checkbox_name = oTxt(sprintf($name, $val_column, $box[$val_column]));
     
    400400        <?php
    401401    }
    402    
     402
    403403    if ($col_cnt < $columns) {
    404404        // This last cell must expand to fill the last blank cells.
  • branches/1.1dev/lib/Utilities.inc.php

    r756 r759  
    292292 *
    293293 * @param  string $text  A string for which to convert to color.
    294  *
    295  * @return string  A hexadecimal html color.
    296  */
    297 function getTextColor($text, $method=1)
     294 * @param  float  $n     Brightness value between 0-1.
     295 * @return string        A hexadecimal html color.
     296 */
     297function getTextColor($text, $method=1, $n=0.87)
    298298{
    299299    $hash = md5($text);
     
    310310    case 1 :
    311311    default :
    312         // Reduce all hex values slighly to avoid all white.
    313         array_walk($rgb, create_function('&$v', '$v = dechex(round(hexdec($v) * 0.87));'));
     312        // Reduce all hex values slightly to avoid all white.
     313        array_walk($rgb, function (&$v) use ($n) {
     314            $v = dechex(round(hexdec($v) * $n));
     315        });
    314316        break;
    315317    case 2 :
Note: See TracChangeset for help on using the changeset viewer.