get_array
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 29 Apr 2022 13:18:27 +0000 (15:18 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 29 Apr 2022 13:18:27 +0000 (15:18 +0200)
19 files changed:
planetlab/common/login.php
planetlab/includes/plc_visibletags2.php
planetlab/nodes/index.php
planetlab/nodes/nodes.php
planetlab/persons/index.php
planetlab/persons/persons.php
planetlab/sites/index.php
planetlab/sites/join_request.php
planetlab/sites/sites.php
planetlab/slices/index.php
planetlab/slices/slice.php
planetlab/slices/slices.php
plekit/php/columns.php
plekit/php/details.php
plekit/php/form.php
plekit/php/linetabs.php
plekit/php/plekit-utils.php
plekit/php/table.php
plekit/php/table2.php

index 92c7767..312b64b 100644 (file)
@@ -53,7 +53,7 @@ if (!empty($_SERVER['QUERY_STRING'])) {
   $self .= "?" . $_SERVER['QUERY_STRING'];
 }
 
-$url = htmlspecialchars($_REQUEST['url']);
+$url = htmlspecialchars(get_array($_REQUEST, 'url'));
 
 // XXX Use our own stylesheet instead of drupal.css
 print <<<EOF
index 6120b36..f2a3657 100644 (file)
@@ -9,7 +9,7 @@ class VisibleTags {
   var $api;
   var $type;
 
-  function __construct ($api,$type) {
+  function __construct ($api, $type) {
     $this->api=$api;
     $this->type=$type;
     $this->columns=NULL;
@@ -22,7 +22,7 @@ class VisibleTags {
       return $this->columns;
 
     // scan tag types to find relevant additional columns
-    $tag_types = $this->api->GetTagTypes(array('category'=>"$type*/ui*"));
+    $tag_types = $this->api->GetTagTypes(array('category'=>"$this->type*/ui*"));
 
     $columns = array();
     foreach ($tag_types as $tag_type) {
@@ -37,9 +37,9 @@ class VisibleTags {
       // split category and parse any setting
       $category_tokens=explode('/',$tag_type['category']);
       foreach ($category_tokens as $token) {
-       $assign=explode('=',$token);
-       if (count($assign)==2)
-         $column[$assign[0]]=$assign[1];
+             $assign=explode('=',$token);
+             if (count($assign)==2)
+               $column[$assign[0]]=$assign[1];
       }
       $columns []= $column;
     }
index 3a5cb1c..f141fcc 100644 (file)
@@ -4,8 +4,9 @@
 
 // Require login
 require_once 'plc_login.php';
+require_once 'plekit-utils.php';
 
-if ($_GET['id']) require ('node.php') ;
-else             require ('nodes.php');
+if (get_array($_GET, 'id')) require ('node.php') ;
+else                        require ('nodes.php');
 
 ?>
index 8a858b7..af17711 100644 (file)
@@ -32,11 +32,11 @@ drupal_set_html_head('
 
 // -------------------- 
 // recognized URL arguments
-$peerscope=$_GET['peerscope'];
-$pattern=$_GET['pattern'];
-$site_id=intval($_GET['site_id']);
-$slice_id=intval($_GET['slice_id']);
-$person_id=intval($_GET['person_id']);
+$peerscope = get_array($_GET, 'peerscope');
+$pattern = get_array($_GET, 'pattern');
+$site_id = intval(get_array($_GET, 'site_id'));
+$slice_id = intval(get_array($_GET, 'slice_id'));
+$person_id = intval(get_array($_GET, 'person_id'));
 
 // --- decoration
 $title="Nodes";
index ed8bc04..e36ca1d 100644 (file)
@@ -4,8 +4,9 @@
 
 // Require login
 require_once 'plc_login.php';
+require_once 'plekit-utils.php';
 
-if ($_GET['id']) require ('person.php') ;
-else             require ('persons.php');
+if (get_array($_GET, 'id')) require ('person.php') ;
+else                        require ('persons.php');
 
 ?>
index ef04dcd..5f6ecd5 100644 (file)
@@ -11,7 +11,7 @@ global $plc, $api;
 
 // Print header
 require_once 'plc_drupal.php';
-include 'plc_header.php'; 
+include 'plc_header.php';
 
 // Common functions
 require_once 'plc_functions.php';
@@ -20,12 +20,12 @@ require_once 'linetabs.php';
 require_once 'table.php';
 require_once 'nifty.php';
 
-// -------------------- 
+// --------------------
 // recognized URL arguments
-$peerscope=$_GET['peerscope'];
-$pattern=$_GET['pattern'];
-$site_id=intval($_GET['site_id']);
-$slice_id=intval($_GET['slice_id']);
+$peerscope=get_array($_GET, 'peerscope');
+$pattern=get_array($_GET, 'pattern');
+$site_id=intval(get_array($_GET, 'site_id'));
+$slice_id=intval(get_array($_GET, 'slice_id'));
 
 // --- decoration
 $title="Accounts";
@@ -85,7 +85,7 @@ if ($pattern) {
  }
 
 // server-side selection on peerscope
-$peerscope=new PeerScope ($api,$_GET['peerscope']);
+$peerscope=new PeerScope ($api, get_array($_GET, 'peerscope'));
 $person_filter=array_merge($person_filter,$peerscope->filter());
 $title .= ' - ' . $peerscope->label();
 
index a871948..e784e52 100644 (file)
@@ -4,8 +4,9 @@
 
 // Require login
 require_once 'plc_login.php';
+require_once 'plekit-utils.php';
 
-if ($_GET['id']) require ('site.php') ;
-else             require ('sites.php');
+if (get_array($_GET, 'id')) require ('site.php');
+else                        require ('sites.php');
 
 ?>
index f0b5562..717711f 100644 (file)
@@ -9,7 +9,7 @@ require_once 'plc_login.php';
 
 // Get session and API handles
 require_once 'plc_session.php';
-require_once 'plc_api.php'; 
+require_once 'plc_api.php';
 global $plc, $api, $adm;
 
 // Print header
@@ -42,7 +42,7 @@ function render_all_join_requests($api) {
   # http://www.frequency-decoder.com/demo/table-sort-revisited/custom-sort-functions/
   $headers['submitted']='sortEnglishDateTime';
   $headers['enabled']='string';
-  
+
   $nifty=new PlekitNifty ('pending','sites-pending','medium');
   $nifty->start();
   $table=new PlekitTable ('pending',$headers,2,
@@ -115,16 +115,16 @@ EOF;
   // don't render the tech part if that was the same as the pi
   $site_form = build_site_form(FALSE);
   $input = array ('site' => $site, 'address'=> $address, 'pi' => $pi, 'tech' => $tech);
-  
+
   $nifty=new PlekitNifty ('pending','site-pending','medium');
 
   $nifty->start();
   $details = new PlekitDetails(TRUE);
   $details->start();
 
-  // display the buttons 
+  // display the buttons
   $buttons_row =<<<EOF
-    <table width="100%" border=0 cellspacing="0" cellpadding="5"> <tr> 
+    <table width="100%" border=0 cellspacing="0" cellpadding="5"> <tr>
     <td align=center><input type="submit" name="submitted" value="Delete"></td>
     <td align=center><input type="submit" name="submitted" value="Update"></td>
     <td align=center><input type="submit" name="submitted" value="Approve"></td>
@@ -149,12 +149,12 @@ function notify_enabled_pi ($api, $pi_id, $pi, $site_id, $site) {
 You have filed a site registration with the %s platform.
 
 This registration has been approved, and your account was enabled
-You were granted a PI role, meaning that you will be responsible 
+You were granted a PI role, meaning that you will be responsible
 for managing personal accounts and slices for your site
 
 You can now enter the system at
 https://%s:%d/
-with %s as a login, 
+with %s as a login,
 and the password that you provided at registration-time
 
 You can directly access your site information at
@@ -166,7 +166,7 @@ https://%s:%d/db/nodes/node_add.php
 Our support team will be glad to answer any question that you might have
 They are reachable at mailto:%s
 EOF;
+
  $body=sprintf($template,
               PLC_NAME,
               PLC_WWW_HOST,PLC_WWW_SSL_PORT,
@@ -174,7 +174,7 @@ EOF;
               PLC_WWW_HOST,PLC_WWW_SSL_PORT,$site_id,
               PLC_WWW_HOST,PLC_WWW_SSL_PORT,
               PLC_MAIL_SUPPORT_ADDRESS);
-   
+
  $subject="Site registration for " . $site['name'] . " has been approved by " . PLC_NAME;
  $adm->NotifyPersons(array($pi_id),$subject,$body);
 }
@@ -189,15 +189,15 @@ if( !in_array( '10', $_roles ) ) {
 
     print("<p> not allowed to view this page </p>");
 }
-else if ($_GET['review'])
+else if (get_array($_GET, 'review'))
 {
 
     //print review page
     drupal_set_title('Join Request - Review');
     render_join_request_review($api, $_GET['site_id']);
-       
+
 }
-else if ($_POST['submitted'] )
+else if (get_array($_POST, 'submitted'))
 {
 
   // parse the form
@@ -252,12 +252,12 @@ else if ($_POST['submitted'] )
       } else {
        $messages [] = "Join request updated for site " . $site['name'] ;
       }
-      
+
       break;
     }
     case 'Approve': {
       // Thierry - august 22 2007
-      // keep it simple - the admin who approves is now supposed to check 
+      // keep it simple - the admin who approves is now supposed to check
       // the PI's email address, which makes the whole thing *a lot* simpler
       // enable the site, enable the PI, and VerifyPerson the thec if different from the PI
       $site['enabled'] = True;
@@ -271,7 +271,7 @@ else if ($_POST['submitted'] )
       } else {
        $messages[] = l_site_t ($site_id,"Site '" . $site['name'] . "' enabled");
       }
-      
+
       if (empty ($error) && $address_id) {
        // Update Address
        $api->UpdateAddress($address_id,$address);
@@ -280,7 +280,7 @@ else if ($_POST['submitted'] )
          $error .= $api->error();
          $messages [] = "Could not update address";
        }
-       
+
        foreach ( array("Billing","Shipping") as $address_type) {
          $api->AddAddressTypeToAddress($address_type,$address_id);
          $api_error=$api->error();
@@ -289,7 +289,7 @@ else if ($_POST['submitted'] )
            $messages [] = "Could not add address type " . $address_type;
          }
        }
-         
+
        // Update pi, and enable him
        $api->UpdatePerson ($pi_id,$pi);
        if ( $pi ['enabled' ] ) {
@@ -343,12 +343,12 @@ else if ($_POST['submitted'] )
     }
     print "</ul></div>";
   }
-       
+
   // Show errors if any
   if (!empty($error)) {
     print '<div class="messages error">' . $error . '</div>';
     drupal_set_title('Join Request - Review');
-    render_join_request_review($api, $_POST['site_id']);    
+    render_join_request_review($api, $_POST['site_id']);
   } else {
     drupal_set_title('All currently pending join requests');
     render_all_join_requests($api);
index d8632c3..1a8613f 100644 (file)
@@ -2,7 +2,7 @@
   // $Id$
   //
 
-  // Require login
+// Require login
 require_once 'plc_login.php';
 
 // Get session and API handles
@@ -20,10 +20,10 @@ require_once 'linetabs.php';
 require_once 'table.php';
 require_once 'nifty.php';
 
-// -------------------- 
+// --------------------
 // recognized URL arguments
-$peerscope=$_GET['peerscope'];
-$pattern=$_GET['pattern'];
+$peerscope = get_array($_GET, 'peerscope');
+$pattern = get_array($_GET, 'pattern');
 
 // --- decoration
 $title="Sites";
@@ -32,7 +32,7 @@ $tabs []= tab_sites();
 $tabs []= tab_sites_local();
 $tabs []= tab_mysite();
 
-// -------------------- 
+// --------------------
 $site_filter=array();
 
 function site_status ($site) {
@@ -40,32 +40,33 @@ function site_status ($site) {
   $class=($site['peer_id']) ? 'plc-foreign' : 'plc-warning';
 
   $messages=array();
-  
-  if (empty ($site['node_ids'])) 
+
+  if (empty ($site['node_ids']))
     $messages [] = "No node";
 
   // do all this stuff on local sites only
   if ( ! $site['peer_id'] ) {
-    
+
     // check that site is enabled
-    if ( ! $site['enabled']) 
+    if ( ! $site['enabled'])
       $messages [] = "Not enabled";
     global $PENDING_CONSORTIUM_ID;
     if ( $site['ext_consortium_id'] === $PENDING_CONSORTIUM_ID )
       $messages [] = "Pending registration";
-  
+
     // check that site has at least a PI and a tech
     global $api;
     $persons=$api->GetPersons(array("person_id"=>$site['person_ids']),array("role_ids"));
     $nb_pis=0;
-    $nb_tech=0;
-    if ( $persons) foreach ($persons as $person) {
-       if (in_array( '20', $person['role_ids'])) $nb_pis += 1;
-       if (in_array( '40', $person['role_ids'])) $nb_techs += 1;
+    $nb_techs=0;
+    if ( $persons)
+      foreach ($persons as $person) {
+        if (in_array( '20', $person['role_ids'])) $nb_pis += 1;
+        if (in_array( '40', $person['role_ids'])) $nb_techs += 1;
       }
     if ($nb_pis == 0) $messages [] = "No PI";
     if ($nb_techs == 0) $messages [] = "No Tech";
-    
+
     if (! $site['is_public']) $messages []= "Not public";
 
     // check number of slices
@@ -98,12 +99,12 @@ if (! plc_is_admin()) {
   $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" );
   $site_filter = array_merge ($site_filter, array ("enabled" => TRUE));
  } else {
-  $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" , 
+  $site_columns = array("site_id", "name", "abbreviated_name", "login_base" , "peer_id" ,
                        "is_public", "enabled", "ext_consortium_id",
                        "person_ids", "max_slices", "slice_ids", "node_ids");
  }
 
-if (plc_is_admin()) 
+if (plc_is_admin())
   $tabs['Joining Sites'] = array ('url'=>l_sites_pending(),
                                  'bubble'=>'Review pending join requests');
 
index 4aebbbf..c98f00b 100644 (file)
@@ -4,8 +4,9 @@
 
 // Require login
 require_once 'plc_login.php';
+require_once 'plekit-utils.php';
 
-if ($_GET['id']) require ('slice.php') ;
-else             require ('slices.php');
+if (get_array($_GET, 'id')) require ('slice.php') ;
+else                        require ('slices.php');
 
 ?>
index b194194..9d5eeee 100644 (file)
@@ -33,13 +33,13 @@ drupal_set_html_head('
 //error_reporting(0);
 
 $profiling=false;
-if ($_GET['profiling']) $profiling=true;
+if ($get_array($_GET, 'profiling')) $profiling=true;
 
 if ($profiling)  plc_debug_prof_start();
 
-// -------------------- 
+// --------------------
 // recognized URL arguments
-$slice_id=intval($_GET['id']);
+$slice_id=intval($get_array($_GET, 'id'));
 if ( ! $slice_id ) { plc_error('Malformed URL - id not set'); return; }
 
 ////////////////////
@@ -80,7 +80,7 @@ if ($profiling) plc_debug_prof('03: sites',count($sites));
 //////////////////////////////////////// building blocks for the renew area
 // Constants
 global $DAY;           $DAY = 24*60*60;
-global $WEEK;          $WEEK = 7 * $DAY; 
+global $WEEK;          $WEEK = 7 * $DAY;
 global $MAX_WEEKS;     $MAX_WEEKS= 8;          // weeks from today
 global $GRACE_DAYS;    $GRACE_DAYS=10;         // days for renewal promoted on top
 global $NOW;           $NOW=time();
@@ -98,7 +98,7 @@ function renew_needed ($slice) {
 
 function renew_area ($slice,$site,$visible) {
   global $DAY, $WEEK, $MAX_WEEKS, $GRACE_DAYS, $NOW;
+
   $current_exp=$slice['expires'];
   $current_text = gmstrftime("%A %b-%d-%y %T %Z", $current_exp);
   $max_exp= $NOW + ($MAX_WEEKS * $WEEK); // seconds since epoch
@@ -127,15 +127,15 @@ out more about your site's nodes, and how to contact your site's PI(s)
 and Technical Contact(s).</p>
 EOF;
      echo $message;
+
   } else {
     // xxx this is a rough cut and paste from the former UI
     // showing a datepicker view could be considered as well with some extra work
     // calculate possible extension lengths
     $selectors = array();
-    foreach ( array ( 1 => "One more week", 
-                     2 => "Two more weeks", 
-                     3 => "Three more weeks", 
+    foreach ( array ( 1 => "One more week",
+                     2 => "Two more weeks",
+                     3 => "Three more weeks",
                      4 => "One more month" ) as $weeks => $text ) {
       $candidate_exp = $current_exp + $weeks*$WEEK;
       if ( $candidate_exp < $max_exp) {
@@ -149,7 +149,7 @@ EOF;
     if ( empty( $selectors ) ) {
       print <<< EOF
 <div class='my-slice-renewal'>
-Slices cannot be renewed more than $MAX_WEEKS weeks from now, i.e. not beyond $max_text. 
+Slices cannot be renewed more than $MAX_WEEKS weeks from now, i.e. not beyond $max_text.
 For this reason, the current slice cannot be renewed any further into the future, try again closer to expiration date.
 </div>
 EOF;
@@ -160,7 +160,7 @@ EOF;
 <p>
 PlanetLab's security model requires that anyone who is concerned about a slice's activity be able to immediately learn about that slice. The details that you provide are your public explanation about why the slice behaves as it does. Be sure to describe the <span class='bold'>kind of traffic</span> that your slice generates, and how it handles material that is under <span class='bold'>copyright</span>, if relevant.
 </p><p>
-The PlanetLab Operations Centres regularly respond to concerns raised by third parties about site behaviour. Most incidents are resolved rapidly based upon the publicly posted slice details. However, when these details are not sufficiently clear or accurate, and we cannot immediately reach the slice owner, we must delete the slice. 
+The PlanetLab Operations Centres regularly respond to concerns raised by third parties about site behaviour. Most incidents are resolved rapidly based upon the publicly posted slice details. However, when these details are not sufficiently clear or accurate, and we cannot immediately reach the slice owner, we must delete the slice.
 </p>
 EOF;
 
@@ -177,7 +177,7 @@ print("<p><i>NOTE: Slices cannot be renewed beyond another $max_renewal_weeks we
 print ("</div>");
     }
   }
+
   $toggle->end();
 }
 
@@ -219,7 +219,7 @@ plekit_linetabs($tabs);
 ////////////////////////////////////////
 $peers->block_start($peer_id);
 
-//////////////////////////////////////// renewal area 
+//////////////////////////////////////// renewal area
 // (1) close to expiration : show on top and open
 
 if ($local_peer ) {
@@ -229,7 +229,7 @@ if ($local_peer ) {
 
 
 //////////////////////////////////////////////////////////// tab:details
-$toggle = 
+$toggle =
   new PlekitToggle ('my-slice-details',"Details",
                    array('bubble'=>
                          'Display and modify details for that slice',
@@ -271,7 +271,7 @@ $person_columns = array('email','person_id','first_name','last_name','roles');
 if (!empty($person_ids))
   $persons=$api->GetPersons(array('person_id'=>$slice['person_ids']),$person_columns);
 // just propose to add everyone else
-// xxx this is maybe too much for admins as it slows stuff down 
+// xxx this is maybe too much for admins as it slows stuff down
 // as regular persons can see only a fraction of the db anyway
 $potential_persons=
   $api->GetPersons(array('~person_id'=>$slice['person_ids'],
@@ -354,7 +354,7 @@ if ($privileges) {
                     'pagesize'=>8);
     // show search for admins only as other people won't get that many names to add
     if ( ! plc_is_admin() ) $options['search_area']=false;
-    
+
     $table=new PlekitTable('add_persons',$headers,'0',$options);
     $form=new PlekitForm(l_actions(),array('slice_id'=>$slice['slice_id']));
     $form->start();
@@ -505,7 +505,7 @@ if ($column_configuration == "") {
       $i++;
       $slice_column_configuration = $slice_conf[$i];
     }
-  }        
+  }
 }
 
 if ($sliceconf_exists == false)
@@ -535,7 +535,7 @@ foreach ($show_conf as $ss) {
     $show_reservable_info = FALSE;
   else if ($ss =="columns")
     $show_layout_info = '0';
-}        
+}
 
 $slice_nodes=array();
 $potential_nodes=array();
@@ -562,10 +562,10 @@ $toggle->start();
 
 //////////////////// reservable nodes area
 $leases_info="
-You have attached one or more reservable nodes to your slice. 
-Reservable nodes show up with the '$mark' mark. 
+You have attached one or more reservable nodes to your slice.
+Reservable nodes show up with the '$mark' mark.
 Your slivers will be available only during timeslots
-where you have obtained leases. 
+where you have obtained leases.
 You can manage your leases in the tab below.
 <br>
 This feature is still experimental; feedback is appreciated at <a href='mailto:devel@planet-lab.org'>devel@planet-lab.org</a>
@@ -578,20 +578,20 @@ if ($count && $privileges) {
   // having reservable nodes in white lists looks a bit off scope for now...
   $toggle_nodes=new PlekitToggle('my-slice-nodes-reserve',
                                 "Leases - " . count($reservable_nodes) . " reservable node(s)",
-                                array('visible'=>get_arg('show_nodes_resa'), 
+                                array('visible'=>get_arg('show_nodes_resa'),
                                       'info-text'=>$leases_info,
                                       'info-visible'=>$show_reservable_info));
   $toggle_nodes->start();
 
   // get settings from environment, otherwise set to defaults
   // when to start, in hours in the future from now
-  $leases_offset=$_GET['leases_offset'];
+  $leases_offset=$get_array($_GET, 'leases_offset');
   if ( ! $leases_offset ) $leases_offset=0;
   // how many timeslots to show
-  $leases_slots=$_GET['leases_slots'];
+  $leases_slots=$get_array($_GET, 'leases_slots');
   if ( ! $leases_slots ) $leases_slots = 36;
-  // offset in hours (in the future) from now 
-  $leases_w = $_GET['leases_w'];
+  // offset in hours (in the future) from now
+  $leases_w = $get_array($_GET, 'leases_w');
   if ( ! $leases_w) $leases_w=18;
   // number of timeslots to display
 
@@ -631,7 +631,7 @@ EOF;
 if ($profiling) plc_debug_prof('06: leases',0);
 
 //////////////////// node configuration panel
-if ($first_time_configuration) 
+if ($first_time_configuration)
 $column_conf_visible = '1';
 else
 $column_conf_visible = '0';
@@ -706,7 +706,7 @@ $notes [] = "For information about the different columns please see the <b>node
 /*
 $headers['peer']='string';
 $headers['hostname']='string';
-$short="-S-"; $long=Node::status_footnote(); $type='string'; 
+$short="-S-"; $long=Node::status_footnote(); $type='string';
        $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
 $short=reservable_mark(); $long=reservable_legend(); $type='string';
        $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
@@ -804,7 +804,7 @@ if ($privileges) {
 /*
     $headers['peer']='string';
     $headers['hostname']='string';
-    $short="-S-"; $long=Node::status_footnote(); $type='string'; 
+    $short="-S-"; $long=Node::status_footnote(); $type='string';
        $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
        $short=reservable_mark(); $long=reservable_legend(); $type='string';
        $headers[$short]=array('type'=>$type,'title'=>$long); $notes []= "$short = $long";
@@ -819,7 +819,7 @@ if ($privileges) {
 
     //$notes=array_merge($notes,$visibletags->notes());
 $notes [] = "For information about the different columns please see the <b>node table layout</b> tab above or <b>mouse over</b> the column headers";
-    
+
     $table=new PlekitTable('add_nodes',$headers,NULL, $table_options);
     $form=new PlekitForm(l_actions(),
                         array('slice_id'=>$slice['slice_id']));
@@ -938,7 +938,7 @@ if ($local_peer) {
   // we expose the previous values so that actions.php can know if changes are really needed
   // the code needs to be encoded as it may contain any character
   // as far as the code, this does not work too well b/c what actions.php receives
-  // seems to have spurrious \r chars, and the comparison between old and new values 
+  // seems to have spurrious \r chars, and the comparison between old and new values
   // is not reliable, which results in changes being made although the code hasn't changed
   // hve spent too much time on this, good enough for now...
   $details->form_start(l_actions(),array('action'=>'update-initscripts',
@@ -965,7 +965,7 @@ if ($local_peer) {
                  $details->form()->select_html('initscript',$selectors,array('label'=>'none')),
                  'initscript',
                  array('input_type'=>'select'));
-  if ($initscript && ! $is_found) 
+  if ($initscript && ! $is_found)
     // xxx better rendering ?
     $details->th_td('WARNING',plc_warning_html("Current name '" . $initscript . "' is not a known shared initscript name"));
   ////////// by contents
@@ -981,7 +981,7 @@ if ($local_peer) {
                  array('input_type'=>'textarea', 'width'=>$script_width,'height'=>$script_height));
   $details->tr_submit('unused','Update initscripts');
   $details->form_end();
-  $details->end();  
+  $details->end();
   $toggle->end();
 }
 
@@ -999,19 +999,19 @@ $tag_value_threshold=24;
   if ($profiling) plc_debug_prof('14: slice tags',count($tags));
   function get_tagname ($tag) { return $tag['tagname'];}
   $tagnames = array_map ("get_tagname",$tags);
-  
+
   $toggle = new PlekitToggle ('slice-tags',count_english_warning($tags,'tag'),
                              array('bubble'=>'Inspect and set tags on that slice',
                                    'visible'=>get_arg('show_tags')));
   $toggle->start();
-  
+
   $headers=array(
     "Name"=>"string",
     "Value"=>"string",
     "Node"=>"string",
     "NodeGroup"=>"string");
   if ($tags_privileges) $headers[plc_delete_icon()]="none";
-  
+
   $table_options=array("notes_area"=>false,"pagesize_area"=>false,"search_width"=>10);
   $table=new PlekitTable("slice_tags",$headers,'0',$table_options);
   $form=new PlekitForm(l_actions(),
@@ -1041,7 +1041,7 @@ $tag_value_threshold=24;
         $node_name = $_hostnames[$tag['node_id']];
       }
       $nodegroup_name="n/a";
-      if ($tag['nodegroup_id']) { 
+      if ($tag['nodegroup_id']) {
         $nodegroups=$api->GetNodeGroups(array('nodegroup_id'=>$tag['nodegroup_id']));
        if ($profiling) plc_debug_prof('15: nodegroup for slice tag',$nodegroup);
         if ($nodegroup) {
@@ -1065,7 +1065,7 @@ $tag_value_threshold=24;
     $table->cell($form->submit_html ("delete-slice-tags","Remove selected"),
                  array('hfill'=>true,'align'=>'right'));
     $table->row_end();
-    
+
     $table->row_start();
     function tag_selector ($tag) {
       return array("display"=>$tag['tagname'],"value"=>$tag['tag_type_id']);
@@ -1073,19 +1073,19 @@ $tag_value_threshold=24;
     $all_tags= $api->GetTagTypes( array ("category"=>"*slice*","-SORT"=>"+tagname"), array("tagname","tag_type_id"));
     if ($profiling) plc_debug_prof('16: tagtypes',count($all_tags));
     $selector_tag=array_map("tag_selector",$all_tags);
-    
-    function node_selector($node) { 
+
+    function node_selector($node) {
       return array("display"=>$node["hostname"],"value"=>$node['node_id']);
     }
     $selector_node=array_map("node_selector",$slice_nodes);
-    
+
     function nodegroup_selector($ng) {
       return array("display"=>$ng["groupname"],"value"=>$ng['nodegroup_id']);
     }
     $all_nodegroups = $api->GetNodeGroups( array("groupname"=>"*"), array("groupname","nodegroup_id"));
     if ($profiling) plc_debug_prof('17: nodegroups',count($all_nodegroups));
     $selector_nodegroup=array_map("nodegroup_selector",$all_nodegroups);
-    
+
     $table->cell($form->select_html("tag_type_id",$selector_tag,array('label'=>"Choose Tag")));
     $table->cell($form->text_html("value","",array('width'=>8)));
     $table->cell($form->select_html("node_id",$selector_node,array('label'=>"All Nodes")));
@@ -1093,7 +1093,7 @@ $tag_value_threshold=24;
     $table->cell($form->submit_html("add-slice-tag","Set Tag"),array('columns'=>2,'align'=>'left'));
     $table->row_end();
   }
-    
+
   $table->end();
   $form->end();
   $toggle->end();
index 2b10bc9..319f379 100644 (file)
@@ -23,12 +23,12 @@ require_once 'linetabs.php';
 require_once 'table.php';
 require_once 'nifty.php';
 
-// -------------------- 
+// --------------------
 // recognized URL arguments
-$peerscope=$_GET['peerscope'];
-$pattern=$_GET['pattern'];
-$site_id=intval($_GET['site_id']);
-$person_id=intval($_GET['person_id']);
+$peerscope=get_array($_GET, 'peerscope');
+$pattern=get_array($_GET, 'pattern');
+$site_id=intval(get_array($_GET, 'site_id'));
+$person_id=intval(get_array($_GET, 'person_id'));
 
 // --- decoration
 $title="Slices";
@@ -58,7 +58,7 @@ if ($pattern) {
  }
 
 // server-side selection on peerscope
-$peerscope=new PeerScope($api,$_GET['peerscope']);
+$peerscope=new PeerScope($api,get_array($_GET, 'peerscope'));
 $slice_filter=array_merge($slice_filter,$peerscope->filter());
 $title .= ' - ' . $peerscope->label();
 
@@ -95,8 +95,8 @@ global $person_hash;
 $person_hash=array();
 if ($persons) foreach ($persons as $person) $person_hash[$person['person_id']]=$person;
 
-function email_link_from_hash($person_id) { 
-  global $person_hash; 
+function email_link_from_hash($person_id) {
+  global $person_hash;
   return l_person_obj($person_hash[$person_id]);
 }
 
@@ -109,7 +109,7 @@ if ( ! $slices ) {
   drupal_set_message ('No slice found');
   return;
  }
-  
+
 $nifty=new PlekitNifty ('','objects-list','big');
 $nifty->start();
 if (plc_is_admin()) $headers["I"]="int";
@@ -123,7 +123,7 @@ $headers["Exp. d/m/y"]="date-dmy";
 # initial sort on hostnames
 if (plc_is_admin()) $slices_sort_column = 3;
 else $slices_sort_column = 2;
-    
+
 $table=new PlekitTable ("slices",$headers,$slices_sort_column,
                        array('search_width'=>20));
 $table->start();
index ac8e41f..bd46551 100644 (file)
@@ -95,22 +95,19 @@ return $this->all_headers;
 
 function get_headers() {
 
-return $this->all_headers;
+       return $this->all_headers;
 
 }
 
 function get_selected_period($label) {
 
-if ($this->all_headers[$label."w"]['visible'])
+       if (get_array2($this->all_headers, $label."w", 'visible'))
        return "w";
-else if ($this->all_headers[$label."m"]['visible'])
+       else if (get_array2($this->all_headers, $label."m", 'visible'))
        return "m";
-else if ($this->all_headers[$label."y"]['visible'])
+       else if (get_array2($this->all_headers, $label."y", 'visible'))
        return "y";
-else if ($this->all_headers[$label]['visible'])
-       return "";
-
-return "";
+       else return "";
 }
 
 function node_tags() {
@@ -119,7 +116,10 @@ function node_tags() {
 
        foreach ($this->all_headers as $h)
        {
-               if ($h['visible'] == true && $h['tagname'] != "" && !$h['fetched'] && $h['source']=="myplc")
+               if ($h['visible'] == true
+                && $h['tagname'] != ""
+                && !get_array($h, 'fetched')
+                && $h['source']=="myplc")
                        $fetched_tags[] = $h['tagname'];
        }
 
@@ -389,55 +389,44 @@ function fetch_live_data($all_nodes) {
 
 function cells($table, $node) {
 
-//$node_string = "";
-
-foreach ($this->all_headers as $h) {
-
-if (!$h['fixed']) {
-
-if ($h['visible'] != "") {
-
-if ($h['source'] == "comon")
-{
-       //print("<br>Searching for ".$h['tagname']."at ".$node);
-       if ($this->ComonData != "")
-               $value = $this->convert_data($this->ComonData[$node['hostname']][$h['tagname']], $h['tagname']);
-       else
-               $value = "n/a";
-
-        $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
-       //$node_string.= "\"".$value."\",";
-}
-else if ($h['source'] == "tophat")
-{
-       if ($this->TopHatData != "")
-               $value = $this->convert_data($this->TopHatData[$node['hostname']][$h['tagname']], $h['type']);
-       else
-               $value = "n/a";
 
-        $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
-       //$node_string.= "\"".$value."\",";
-}
-else
-{
-        //$value = $node[$h['tagname']];
-        $value = $this->convert_data($node[$h['tagname']], $h['type']);
-        $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
-       //$node_string.= "\"".$value."\",";
-}
-}
-else
-       if ($node[$h['tagname']])
-       {
-               $value = $this->convert_data($node[$h['tagname']], $h['type']);
-               $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
+       foreach ($this->all_headers as $h) {
+
+               if (! get_array($h, 'fixed')) {
+
+                       if ($h['visible'] != "") {
+
+                               if ($h['source'] == "comon") {
+                                               //print("<br>Searching for ".$h['tagname']."at ".$node);
+                                               if ($this->ComonData != "")
+                                                               $value = $this->convert_data($this->ComonData[$node['hostname']][$h['tagname']], $h['tagname']);
+                                               else
+                                                       $value = "n/a";
+
+                                                       $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
+                                               //$node_string.= "\"".$value."\",";
+                               } else if ($h['source'] == "tophat") {
+                                       if ($this->TopHatData != "")
+                                                       $value = $this->convert_data($this->TopHatData[$node['hostname']][$h['tagname']], $h['type']);
+                                       else
+                                               $value = "n/a";
+
+                                       $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
+                                       //$node_string.= "\"".$value."\",";
+                               } else {
+                                       //$value = $node[$h['tagname']];
+                                       $value = $this->convert_data($node[$h['tagname']], $h['type']);
+                                       $table->cell($value,array('name'=>$h['header'], 'display'=>'table-cell'));
+                               //$node_string.= "\"".$value."\",";
+                               }
+                       } else if (get_array($node, $h['tagname'])) {
+                               $value = $this->convert_data($node[$h['tagname']], $h['type']);
+                               $table->cell($value, array('name'=>$h['header'], 'display'=>'none'));
+                       } else {
+                               $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
+                       }
+               }
        }
-       else
-               $table->cell("n/a", array('name'=>$h['header'], 'display'=>'none'));
-}
-}
-
-//return $node_string;
 
 }
 
@@ -451,10 +440,10 @@ HTML
 
 function javascript_init() {
 
-print("<script type='text/javascript'>");
-print("highlightOption('AU');");
-print("overrideTitles();");
-print("</script>");
+       print("<script type='text/javascript'>");
+       print("highlightOption('AU');");
+       print("overrideTitles();");
+       print("</script>");
 
 }
 
@@ -507,18 +496,17 @@ print("<tr><th class='top'>Add/remove columns</th>");
 if ($showDescription)
        print("<th class='top'>Column description and configuration</th>");
 
-print("</tr><tr><td class='top' width='300px'>");
+       print("</tr><tr><td class='top' width='300px'>");
 
        print('<div id="scrolldiv">');
-print ("<table>");
+       print ("<table>");
        $prev_label="";
        $optionclass = "out";
-       foreach ($this->all_headers as $h)
-       {
+       foreach ($this->all_headers as $h) {
                if ($h['header'] == "hostname" || $h['header'] == "ID")
                        continue;
 
-               if ($h['fixed'])
+               if (get_array($h, 'fixed'))
                        $disabled = "disabled=true";
                else
                        $disabled = "";
index a3705a6..b6e03c4 100644 (file)
@@ -109,8 +109,8 @@ class PlekitDetails {
     if (!$options) $options = array();
     if ( ! ($this->editable && $form_varname) ) {
       // xxx hack: if input_type is select, look for the 'value' option to display current value
-      if ($options['input_type'] == "select")
-       $value=$options['value'];
+      if (get_array($options, 'input_type') == "select")
+             $value=$options['value'];
       return "<tr><th>$title</th><td>$value</td></tr>";
     } else {
       // use options if provided, otherwise the latest set_ function
index 6dc68c4..9ecee3c 100644 (file)
@@ -52,15 +52,18 @@ class PlekitForm {
   function end_html() { return "</form>"; }
 
   static function attributes ($options) {
-    $html="";
-    $names=array('id','size','selected', 'checked',
-                'onfocus','onselect', 'onchange',
+    $html = "";
+    $names = array('id','size','selected', 'checked',
+                'onfocus', 'onselect', 'onchange',
                 'onkeyup', 'onmouseup', 'onclick', 'onsubmit');
-    if ($options['selected']) $options['selected']='selected';
-    if ($options['checked']) $options['checked']='checked';
-    if ($options) foreach ($options as $key=>$value) {
-       if (in_array(strtolower($key),$names))
-         $html .= " $key='$value'";
+    if (get_array($options, 'selected'))
+      $options['selected'] = 'selected';
+    if (get_array($options, 'checked'))
+      $options['checked'] = 'checked';
+    if ($options)
+      foreach ($options as $key=>$value) {
+             if (in_array(strtolower($key), $names))
+               $html .= " $key='$value'";
       }
     return $html;
   }
@@ -105,17 +108,19 @@ class PlekitForm {
 
   static function select_html ($name,$selectors,$options=NULL) {
     if ( ! $options) $options=array();
-    if ( $options ['autosubmit'] ) $options['onChange']='submit()';
+    if (get_array($options, 'autosubmit'))
+      $options['onChange']='submit()';
     $html="";
     $html.="<select name='$name'";
-    if ($options['id']) $html .= " id='" . $options['id'] . "'";
-    $cbs=array('onFocus','onSelect','onChange');
+    if (get_array($options, 'id'))
+      $html .= " id='" . $options['id'] . "'";
+    $cbs = array('onFocus', 'onSelect', 'onChange');
     foreach ($cbs as $cb) {
-      if ($options[$cb])
-       $html .= " $cb='" . $options[$cb] . "'";
+      if (get_array($options, $cb))
+             $html .= " $cb='" . $options[$cb] . "'";
     }
     $html .= ">";
-    if ($options['label']) {
+    if (get_array($options, 'label')) {
       $encoded=htmlentities($options['label'],ENT_QUOTES);
       $html.="<option selected=selected value=''>$encoded</option>";
     }
@@ -124,8 +129,10 @@ class PlekitForm {
         $display=htmlentities($selector['display'],ENT_QUOTES);
         $value=$selector['value'];
         $html .= "<option value='$value'";
-        if ($selector['selected']) $html .= " selected=selected";
-        if ($selector['disabled']) $html .= " disabled=disabled";
+        if (get_array($selector, 'selected'))
+          $html .= " selected=selected";
+        if (get_array($selector, 'disabled'))
+          $html .= " disabled=disabled";
         $html .= ">$display</option>\n";
       }
     }
index d2be029..24a3834 100644 (file)
@@ -41,14 +41,14 @@ drupal_set_html_head('
 // plekit_linetabs($tabs);
 
 ////////// Notes: limited support for images
-// (*) for some reason, confirmation does not work with image tabs 
+// (*) for some reason, confirmation does not work with image tabs
 //     (the form gets submitted whatever the confirmation....)
-// (*) you need to tune the image size, which is wrong, as the image should rather be bottom-aligned 
+// (*) you need to tune the image size, which is wrong, as the image should rather be bottom-aligned
 
 function plekit_linetabs ($tabs, $id=NULL) {
   // do not output anything if $tabs has no entry (unpleasant rendering)
   if (empty ($tabs)) return;
-  $active_line_tab=$_GET['active_line_tab'];
+  $active_line_tab=get_array($_GET, 'active_line_tab');
   // need id to pass to the onclick function attached to the input buttons
   $id="linetabs";
   if (! $id) $id .= '-' + $id;
@@ -56,14 +56,18 @@ function plekit_linetabs ($tabs, $id=NULL) {
   print "<ul>";
   foreach ($tabs as $label=>$todo) {
     // in case we have a simple string, rewrite it as an array
-    if (is_string ($todo)) $todo=array('method'=>'GET','url'=>$todo);
+    if (is_string ($todo))
+      $todo = array('method'=>'GET', 'url'=>$todo);
     // the 'label' key, if set in the hash, supersedes key
-    if ($todo['label']) $label=$todo['label'];
+    if (get_array($todo, 'label'))
+      $label = $todo['label'];
     $tracer="";
-    if ($todo['id']) $tracer .= "id=".$todo['id'];
+    if (get_array($todo, 'id'))
+      $tracer .= "id=" . $todo['id'];
     print "<li $tracer>";
     // set default method
-    if ( ! $todo['method'] ) $todo['method']='GET';
+    if ( ! get_array($todo, 'method') )
+      $todo['method'] = 'GET';
     // extract var=value settings from url if any
     $full_url=$todo['url'];
     $split=plekit_split_url($full_url);
@@ -74,18 +78,20 @@ function plekit_linetabs ($tabs, $id=NULL) {
     $method=strtolower($todo['method']);
     print "<form action='$url' method='$method'><fieldset>";
     // set values
-    $values=$todo['values'];
+    $values = get_array($todo, 'values');
     if ( ! $values) $values = array();
-    if ($url_values) $values = array_merge($values,$url_values);
-    if ( $values ) foreach ($values as $key=>$value) {
-      if ($key != "active_line_tab")
-        print "<input type='hidden' name='$key' value='$value' />";
-    }
+    if ($url_values) 
+      $values = array_merge($values, $url_values);
+    if ( $values ) 
+      foreach ($values as $key=>$value) {
+        if ($key != "active_line_tab")
+          print "<input type='hidden' name='$key' value='$value' />";
+      }
     print "<input type='hidden' name='active_line_tab' value='$label' />";
     if ($label == $active_line_tab) $tracer = "class='linetabs-submit active'";
     else $tracer="class='linetabs-submit'";
-    // image and its companions 'height' 
-    if ($todo['image']) {
+    // image and its companions 'height'
+    if (get_array($todo, 'image')) {
       $what=$todo['image'];
       $type="type='image' src='$what'";
       if ($todo['height']) {
@@ -98,7 +104,8 @@ function plekit_linetabs ($tabs, $id=NULL) {
     $bubble=htmlspecialchars($todo['bubble'], ENT_QUOTES);
     print "<span title='$bubble'>";
     $message="";
-    if ($todo['confirm']) $message=htmlspecialchars($todo['confirm'], ENT_QUOTES) . " ?";
+    if (get_array($todo, 'confirm'))
+      $message=htmlspecialchars($todo['confirm'], ENT_QUOTES) . " ?";
     print "<input $tracer $type onclick='linetabs_namespace.submit(\"$id\",\"$message\")' />";
     print "</span>";
     print "</fieldset></form></li>\n";
index 7326117..031b7d9 100644 (file)
@@ -4,16 +4,41 @@
 
 // returns array ['url' => path, 'values' => hash (key=>value)* ]
 function plekit_split_url ($full_url) {
-  list($url,$args) = explode("?",$full_url);
-  $values=array();
-  if ($args) {
-    $pairs=explode("&",$args);
+  $exploded = explode("?", $full_url);
+  $url = $exploded[0];
+  $values = array();
+  if (get_array($exploded, 1)) {
+    $args = $exploded[1];
+    $pairs = explode("&", $args);
     foreach ($pairs as $pair) {
-      list ($name,$value) = explode("=",$pair);
-      $values[$name]=$value;
+      list ($name, $value) = explode("=", $pair);
+      $values[$name] = $value;
     }
   }
-  return array("url"=>$url,"values"=>$values);
+  return array("url"=>$url, "values"=>$values);
+}
+
+// at first I thought $_GET was an object, but it's an array
+function get_object($object, $prop, $default=null) {
+  if (property_exists($object, $prop)) {
+    return $object->$prop;
+  } else {
+    return $default;
+  }
+}
+
+function get_array($array, $prop, $default=null) {
+  if (! $array)
+    return $default;
+  if (array_key_exists($prop, $array)) {
+    return $array[$prop];
+  } else {
+    return $default;
+  }
+}
+
+function get_array2($array, $prop1, $prop2, $default=null) {
+  return get_array(get_array($array, $prop1), $prop2, $default);
 }
 
 ?>
index 0a21c40..14f4f14 100644 (file)
@@ -280,15 +280,20 @@ EOF;
   // (*) hfill
   // (*) align
   public function cell ($text,$options=NULL) { print $this->cell_html ($text,$options); }
-  public function cell_html ($text,$options=NULL) {
+  public function cell_html ($text, $options=NULL) {
     if (isset ($options['only-if']) && ! $options['only-if'] )
-      $text="n/a";
-    $html="";
+      $text = "n/a";
+    $html = "";
     $html .= "<td";
-    $option=$options['class']; if ($option) $html .= " class='$option'";
-    $option=$options['columns'];if ($option) $html .= " colspan='$option'";
-    $option=$options['hfill']; if ($option) $html .= " colspan='" . $this->columns() . "'";
-    $option=$options['align']; if ($option) $html .= " style='text-align:$option'";
+    $option = get_array($options, 'class');
+    if ($option)
+      $html .= " class='$option'";
+    $option = get_array($options, 'columns');
+      if ($option) $html .= " colspan='$option'";
+    $option = get_array($options, 'hfill');
+      if ($option) $html .= " colspan='" . $this->columns() . "'";
+    $option = get_array($options, 'align');
+       if ($option) $html .= " style='text-align:$option'";
     $html .= ">$text</td>";
     return $html;
   }
index a8a69de..a4af9ce 100644 (file)
@@ -311,13 +311,20 @@ EOF;
       $text="n/a";
     $html="";
     $html .= "<td";
-    $option=$options['class']; if ($option) $html .= " class='$option'";
-    $option=$options['columns'];if ($option) $html .= " colspan='$option'";
-    $option=$options['hfill']; if ($option) $html .= " colspan='" . $this->columns() . "'";
-    $option=$options['align']; if ($option) $html .= " style='text-align:$option'";
-    $option=$options['color'];  if ($option) $html .= " style='color:$option'";
-    $option=$options['display'];  if ($option) $html .= " style='display: $option'";
-    $option=$options['name'];   if ($option) $html .= " name='$option'";
+    $option=get_array($options, 'class');
+    if ($option) $html .= " class='$option'";
+    $option=get_array($options, 'columns');
+    if ($option) $html .= " colspan='$option'";
+    $option=get_array($options, 'hfill');
+    if ($option) $html .= " colspan='" . $this->columns() . "'";
+    $option=get_array($options, 'align');
+    if ($option) $html .= " style='text-align:$option'";
+    $option=get_array($options, 'color');
+    if ($option) $html .= " style='color:$option'";
+    $option=get_array($options, 'display');
+    if ($option) $html .= " style='display: $option'";
+    $option=get_array($options, 'name');
+    if ($option) $html .= " name='$option'";
     $html .= ">$text</td>";
     return $html;
   }