X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=planetlab%2Fincludes%2Fplc_functions.php;h=4befb9c8eae2ec08742b2c5e7c2f2526c18fe144;hb=14623fa47b3316b7b05f4a92e10bac9122423ec2;hp=53600ae66efa0697bd8877f388e6b355967b7e24;hpb=83825b76a210cf0403763c2955b562c1f9c4439f;p=plewww.git diff --git a/planetlab/includes/plc_functions.php b/planetlab/includes/plc_functions.php index 53600ae..4befb9c 100644 --- a/planetlab/includes/plc_functions.php +++ b/planetlab/includes/plc_functions.php @@ -2,9 +2,6 @@ // $Id$ -// will trash this eventually - //require_once 'plc_functions_trash.php'; - # note: this needs to be consistent with the value in Monitor/monitor/wrapper/plc.py global $PENDING_CONSORTIUM_ID; $PENDING_CONSORTIUM_ID = 0; @@ -81,6 +78,8 @@ function l_pcu ($pcu_id) { return "/db/sites/pcu.php?id=$pcu_id"; } function l_nodes () { return "/db/nodes/index.php"; } function l_nodes_peer ($peer_id) { return "/db/nodes/index.php?peerscope=$peer_id"; } function l_node ($node_id) { return "/db/nodes/node.php?id=$node_id"; } +function l_node_interfaces ($node_id) { return "/db/nodes/node.php?id=$node_id%show_details=0&show_interfaces=1"; } +function l_node_tags ($node_id) { return "/db/nodes/node.php?id=$node_id%show_details=0&show_tags=1"; } function l_node_t ($node_id,$text) { return href (l_node($node_id),$text); } function l_node_obj($node) { return href(l_node($node['node_id']),$node['hostname']); } function l_node_add () { return "/db/nodes/node_add.php"; } @@ -122,6 +121,7 @@ function l_sliver_t ($node_id,$slice_id,$text) { function l_persons () { return "/db/persons/index.php&active_line_tab=All Accounts"; } function l_persons_peer ($peer_id) { return "/db/persons/index.php?peerscope=$peer_id&active_line_tab=Local Accounts"; } function l_person ($person_id) { return "/db/persons/index.php?id=$person_id"; } +function l_person_roles ($person_id) { return "/db/persons/index.php?id=$person_id&show_details=0&show_roles=1"; } function l_person_t ($person_id,$text) { return href (l_person($person_id),$text); } function l_persons_site ($site_id) { return "/db/persons/index.php?site_id=$site_id"; } function l_persons_slice ($slice_id) { return "/db/persons/index.php?slice_id=$slice_id"; } @@ -215,7 +215,7 @@ function tab_nodegroups() { return array ('label'=>'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) { @@ -223,24 +223,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 ); @@ -308,6 +311,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) { @@ -355,14 +371,18 @@ 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; +} +// ditto but in case the text is too lare, returns a with its 'title' set to the full value +function truncate_and_popup ($text,$numb,$etc = "...") { + if (strlen($text) <= $numb) return $text; + $display=substr($text, 0, $numb).$etc; + return sprintf("%s",$text,$display); } + // generates <(atom) class=(class)> (text) function html_atom ($atom,$text,$class="") { $html="<$atom"; @@ -404,11 +424,35 @@ function bold_html ($text) { return html_span($text,'bold'); } // shows a php variable verbatim with a heading message function plc_debug ($message,$object) { - print "
" . $message . "
";
+  print "
" . $message . "
";
   print_r ($object);
   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"); @@ -516,4 +560,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 (); } + + ?>