📄 utils.php
字号:
* @param string The URL * @returns The HREF'ed URL * */function util_make_links ($data='') { if(empty($data)) { return $data; } $lines = split("\n",$data); while ( list ($key,$line) = each ($lines)) { // When we come here, we usually have form input // encoded in entities. Our aim is to NOT include // angle brackets in the URL // (RFC2396; http://www.w3.org/Addressing/URL/5.1_Wrappers.html) $line = str_replace('>', "\1", $line); $line = eregi_replace("([ \t]|^)www\."," http://www.",$line); $text = eregi_replace("([[:alnum:]]+)://([^[:space:]<\1]*)([[:alnum:]#?/&=])", "<a href=\"\\1://\\2\\3\" target=\"_new\">\\1://\\2\\3</a>", $line); $text = eregi_replace("([[:space:]]|^)(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "\\1<a href=\"mailto:\\2\" target=\"_new\">\\2</a>", $text); $text = str_replace("\1", '>', $text); $newText .= $text; } return $newText;}/** * show_priority_colors_key() - Show the priority colors legend * */function show_priority_colors_key() { global $Language; echo '<p /><strong> '.$Language->getText('common_utils','priority_colors').':</strong><br /> <table border="0"><tr>'; for ($i=1; $i<10; $i++) { echo ' <td bgcolor="'.html_get_priority_color($i).'">'.$i.'</td>'; } echo '</tr></table>';}/** * utils_buildcheckboxarray() - Build a checkbox array * * @param int Number of options to be in the array * @param string The name of the checkboxes * @param array An array of boxes to be pre-checked * */function utils_buildcheckboxarray($options,$name,$checked_array) { $option_count=count($options); $checked_count=count($checked_array); for ($i=1; $i<=$option_count; $i++) { echo ' <br /><input type="checkbox" name="'.$name.'" value="'.$i.'"'; for ($j=0; $j<$checked_count; $j++) { if ($i == $checked_array[$j]) { echo ' CHECKED'; } } echo '> '.$options[$i]; }}/** * utils_requiredField() - Adds the required field marker * * @return a string holding the HTML to mark a required field */function utils_requiredField() { return '<span><font color="red">*</font></span>';}/** * GraphResult() - Takes a database result set and builds a graph. * The first column should be the name, and the second column should be the values * Be sure to include HTL_Graphs.php before using this function * * @author Tim Perdue tperdue@valinux.com * @param int The databse result set ID * @param string The title of the graph * */Function GraphResult($result,$title) { $rows=db_numrows($result); if ((!$result) || ($rows < 1)) { echo 'None Found.'; } else { $names=array(); $values=array(); for ($j=0; $j<db_numrows($result); $j++) { if (db_result($result, $j, 0) != '' && db_result($result, $j, 1) != '' ) { $names[$j]= db_result($result, $j, 0); $values[$j]= db_result($result, $j, 1); } } /* This is another function detailed below */ GraphIt($names,$values,$title); }}/** * GraphIt() - Build a graph * * @author Tim Perdue tperdue@valinux.com * @param array An array of names * @param array An array of values * @param string The title of the graph * */Function GraphIt($name_string,$value_string,$title) { GLOBAL $HTML; $counter=count($name_string); /* Can choose any color you wish */ $bars=array(); for ($i = 0; $i < $counter; $i++) { $bars[$i]=$HTML->COLOR_LTBACK1; } $counter=count($value_string); /* Figure the max_value passed in, so scale can be determined */ $max_value=0; for ($i = 0; $i < $counter; $i++) { if ($value_string[$i] > $max_value) { $max_value=$value_string[$i]; } } if ($max_value < 1) { $max_value=1; } /* I want my graphs all to be 800 pixels wide, so that is my divisor */ $scale=(400/$max_value); /* I create a wrapper table around the graph that holds the title */ $title_arr=array(); $title_arr[]=$title; echo $GLOBALS['HTML']->listTableTop ($title_arr); echo '<tr><td>'; /* Create an associate array to pass in. I leave most of it blank */ $vals = array( 'vlabel'=>'', 'hlabel'=>'', 'type'=>'', 'cellpadding'=>'', 'cellspacing'=>'0', 'border'=>'', 'width'=>'', 'background'=>'', 'vfcolor'=>'', 'hfcolor'=>'', 'vbgcolor'=>'', 'hbgcolor'=>'', 'vfstyle'=>'', 'hfstyle'=>'', 'noshowvals'=>'', 'scale'=>$scale, 'namebgcolor'=>'', 'valuebgcolor'=>'', 'namefcolor'=>'', 'valuefcolor'=>'', 'namefstyle'=>'', 'valuefstyle'=>'', 'doublefcolor'=>''); /* This is the actual call to the HTML_Graphs class */ html_graph($name_string,$value_string,$bars,$vals); echo ' </td></tr> <!-- end outer graph table -->'; echo $GLOBALS['HTML']->listTableBottom();}/** * ShowResultSet() - Show a generic result set * Very simple, plain way to show a generic result set * * @param int The result set ID * @param string The title of the result set * @param bool The option to turn URL's into links * */function ShowResultSet($result,$title="Untitled",$linkify=false) { global $group_id,$HTML; if ($result) { $rows = db_numrows($result); $cols = db_numfields($result); echo ' <table border="0" width="100%">'; /* Create the title */ $cell_data=array(); $cell_data[] = array($title, 'colspan="'.$cols.'"'); echo $HTML->multiTableRow('',$cell_data, TRUE); /* Create the headers */ $cell_data=array(); for ($i=0; $i < $cols; $i++) { $cell_data[] = array(db_fieldname($result,$i)); } echo $HTML->multiTableRow('',$cell_data, TRUE); /* Create the rows */ for ($j = 0; $j < $rows; $j++) { echo '<tr '. $HTML->boxGetAltRowStyle($j) . '>'; for ($i = 0; $i < $cols; $i++) { if ($linkify && $i == 0) { $link = '<a href="'.$PHP_SELF.'?'; $linkend = '</a>'; if ($linkify == "bug_cat") { $link .= 'group_id='.$group_id.'&bug_cat_mod=y&bug_cat_id='.db_result($result, $j, 'bug_category_id').'">'; } else if($linkify == "bug_group") { $link .= 'group_id='.$group_id.'&bug_group_mod=y&bug_group_id='.db_result($result, $j, 'bug_group_id').'">'; } else if($linkify == "patch_cat") { $link .= 'group_id='.$group_id.'&patch_cat_mod=y&patch_cat_id='.db_result($result, $j, 'patch_category_id').'">'; } else if($linkify == "support_cat") { $link .= 'group_id='.$group_id.'&support_cat_mod=y&support_cat_id='.db_result($result, $j, 'support_category_id').'">'; } else if($linkify == "pm_project") { $link .= 'group_id='.$group_id.'&project_cat_mod=y&project_cat_id='.db_result($result, $j, 'group_project_id').'">'; } else { $link = $linkend = ''; } } else { $link = $linkend = ''; } echo '<td>'.$link . db_result($result, $j, $i) . $linkend.'</td>'; } echo '</tr>'; } echo '</table>'; } else { echo db_error(); }}/** * validate_email() - Validate an email address * * @param string The address string to validate * @returns true on success/false on error * */function validate_email ($address) { return (ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'. '[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.' . '[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$', $address));}/** * util_is_valid_filename() - Verifies whether a file has a valid filename * * @param string The file to verify * @returns true on success/false on error * */function util_is_valid_filename ($file) { //bad char test $invalidchars = eregi_replace("[-A-Z0-9_\.]","",$file); if (!empty($invalidchars)) { return false; } else { if (strstr($file,'..')) { return false; } else { return true; } }}/** * valid_hostname() - Validates a hostname string to make sure it doesn't contain invalid characters * * @param string The optional hostname string * @returns true on success/false on failur * */function valid_hostname ($hostname = "xyz") { //bad char test $invalidchars = eregi_replace("[-A-Z0-9\.]","",$hostname); if (!empty($invalidchars)) { return false; } //double dot, starts with a . or - if (ereg("\.\.",$hostname) || ereg("^\.",$hostname) || ereg("^\-",$hostname)) { return false; } $multipoint = explode(".",$hostname); if (!(is_array($multipoint)) || ((count($multipoint) - 1) < 1)) { return false; } return true;}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -