X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=planetlab%2Fincludes%2Fplc_functions.php;h=8de54c5b9fd516d9a26eb1f4529eb2b99c287b44;hb=c0e69680677e153e96e0302633e97e31b1e2c7a6;hp=c72c598d3d7e3a054c17d323f529253954ea0257;hpb=05411893eee11af861e93000f4064d9a6ea23455;p=plewww.git diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index c72c598..8de54c5 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -1,9 +1,14 @@ 'Nodegroups', 'url'=>l_nodegr function tablook_event() { return array('image'=>'/planetlab/icons/event.png','height'=>18);} function tablook_comon() { return array('image'=>'/planetlab/icons/comon.png','height'=>18);} -//////////////////// + //////////////////////////////////////////////////////////// validation functions function topdomain ($hostname) { @@ -212,24 +226,27 @@ function topdomain ($hostname) { return $exploded[0]; } -function is_valid_email_addr ($email) { - if (ereg("^.+@.+\\..+$", $email) ) { - return true; - } else { - return false; - } -} - -function is_valid_url ($url) { - if (ereg("^(http|https)://.+\..+$", strtolower($url) ) ) { - return true; - } else { - return false; - } -} +//// with php-5.3 on f12, ereg is marked deprecated, using PCRE instead +//// looks unused +// function is_valid_email_addr ($email) { +// if (preg_match("/^.+@.+\\..+$/", $email) ) { +// return true; +// } else { +// return false; +// } +//} +// +//// looks unused +//function is_valid_url ($url) { +// if (preg_match("/^(http|https):\/\/.+\..+$/", strtolower($url) ) ) { +// return true; +// } else { +// return false; +// } +//} function is_valid_ip ($ip) { - if (ereg("^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$", $ip ) ) { + if (preg_match("/^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$/", $ip ) ) { // it's at least in the right format, now check to see if // each part is equal to less than 255 $parts= explode( '.', $ip ); @@ -297,6 +314,19 @@ function plc_role_global_hash ($api) { return $hash; } +// because GetRoles does not correctly support filters, it's really painful to do this +function sort_roles ($r1, $r2) { return $r2['role_id'] - $r1['role_id']; } +function roles_except ($roles, $exception_ids) { + $result=array(); + if ($roles) foreach ($roles as $role) { + if ( ! in_array ($role['role_id'],$exception_ids) ) { + $result[]=$role; + } + } + usort($result,sort_roles); + return $result; +} + //////////////////////////////////////////////////////////// nodegroups // hash by 'tagname=value' function plc_nodegroup_global_hash ($api,$tagnames=NULL) { @@ -344,20 +374,27 @@ function plc_itemize ($messages, $class="") { return $formatted; } -////////// +////////// just return a truncated text function truncate ($text,$numb,$etc = "...") { - if (strlen($text) > $numb) { - $text = substr($text, 0, $numb); - $text = $text.$etc; - } - return $text; + if (strlen($text) <= $numb) return $text; + return substr($text, 0, $numb).$etc; } -function html_div ($text,$class="") { - $html="
"; + print "
" . $message . ""; print_r ($object); print ""; } +function plc_debug_txt ($message,$txt) { + print "
" . $message . ""; + $txt=str_replace(" ","<SPC>",$txt); + $txt=str_replace("\t","<TAB>",$txt); + $txt=str_replace("\n","<LF>",$txt); + $txt=str_replace("\r","<CR>",$txt); + print $txt . "<EOF>"; + print ""; +} + +$plc_prof_start=0.; +$plc_prof_time=0.; +$plc_prof_counter=0; +function plc_debug_prof_start () { + global $plc_prof_counter, $plc_prof_start, $plc_prof_time; + $plc_prof_counter=0; + plc_debug(strftime("[0] %T (start)") ,"heating up"); + $plc_prof_time=microtime(true); + $plc_prof_start=$plc_prof_time; +} +function plc_debug_prof ($message,$object) { + global $plc_prof_counter, $plc_prof_start, $plc_prof_time; + $plc_prof_counter+=1; + $now=microtime(true); + $timelabel=strftime("%T"); + $prof_message=sprintf("[%d] %s (%2.3f s -- %2.3f s) ",$plc_prof_counter,$timelabel, + ($now-$plc_prof_time),($now-$plc_prof_start)); + plc_debug($prof_message.$message,$object); + $plc_prof_time=$now; +} +function plc_debug_prof_end () { + plc_debug_prof ("end","cooling down"); +} + if (! function_exists ("drupal_set_error")) { function drupal_set_error ($text) { drupal_set_message ("$text"); @@ -439,6 +510,18 @@ function plc_redirect ($url) { exit (); } +//////////////////// the options for an nodetype - suitable for plekit/form +function node_type_selectors ($api,$nodetype) { + $builtin_types = array ( "regular" => "Regular/Shared", + "reservable" => "Reservable (requires to get leases)"); + foreach ($builtin_types as $value=>$display) { + $selector=array('display'=>$display, 'value'=>$value); + if ($value == $nodetype) $selector['selected']=true; + $selectors []= $selector; + } + return $selectors; +} + //////////////////// the options for an interface - suitable for plekit/form //>>> GetNetworkMethods() //[u'static', u'dhcp', u'proxy', u'tap', u'ipmi', u'unknown'] @@ -502,4 +585,10 @@ function count_english_warning ($objs, $name) { if (count ($objs) == 0) $x=plc_warning_html($x . ' !!'); return $x; } + +//////////////////// outlining reservable nodes +function reservable_mark () { return "-R-";} +function reservable_legend () { return "reservable nodes are marked with " . reservable_mark (); } + + ?>