Best Phoronix-test-suite code snippet using pts_strings.sanitize
phodevi.php
Source:phodevi.php
...39 'windows' => false40 );41 // A variable that modules can use to override Phodevi caching support, etc42 public static $allow_phodevi_caching = true;43 protected static $sanitize_string = null;44 const no_caching = 1;45 const std_caching = 2;46 const smart_caching = 3;47 public static function read_name($device)48 {49 return phodevi::read_property($device, 'identifier');50 }51 public static function load_sensors()52 {53 if(!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300)54 {55 // Phodevi sensors don't work prior to PHP 5.356 self::$sensors = array();57 return false;58 }59 foreach(glob(dirname(__FILE__) . '/sensors/*') as $sensor_obj_file)60 {61 $sensor_obj_name = basename($sensor_obj_file, '.php');62 if(!class_exists($sensor_obj_name, false))63 {64 include($sensor_obj_file);65 }66 $type = call_user_func(array($sensor_obj_name, 'get_type'));67 $sensor = call_user_func(array($sensor_obj_name, 'get_sensor'));68 if($type != null && $sensor != null)69 {70 self::$sensors[$type][$sensor] = $sensor_obj_name;71 }72 }73 }74 public static function available_sensors($limit_sensors = false)75 {76 static $available_sensors = null;77 if($limit_sensors != false)78 {79 return self::select_sensors($limit_sensors);80 }81 else if($available_sensors == null)82 {83 $available_sensors = array();84 foreach(self::$sensors as $sensor_type => &$sensor)85 {86 foreach(array_keys($sensor) as $sensor_senses)87 {88 array_push($available_sensors, array($sensor_type, $sensor_senses, self::$sensors[$sensor_type][$sensor_senses]));89 }90 }91 }92 return $available_sensors;93 }94 public static function select_sensors($limit_sensors = false)95 {96 if(!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300)97 {98 // Phodevi sensors don't work prior to PHP 5.399 return array();100 }101 $selected = array();102 foreach(self::available_sensors() as $sensor)103 {104 if($limit_sensors == false || (is_array($limit_sensors) && in_array($sensor[2], $limit_sensors)))105 {106 array_push($selected, $sensor);107 }108 }109 return $selected;110 }111 public static function is_sensor_supported($sensor)112 {113 $supported = false;114 $sensors = self::supported_sensors();115 foreach($sensors as $s)116 {117 if($s[0] == $sensor[0] && $s[1] == $sensor[1])118 {119 $supported = true;120 break;121 }122 }123 return $supported;124 }125 public static function supported_sensors($limit_sensors = false)126 {127 static $supported_sensors = null;128 if($limit_sensors != false)129 {130 return self::select_sensors($limit_sensors);131 }132 else if($supported_sensors == null)133 {134 $supported_sensors = array();135 foreach(self::available_sensors($limit_sensors) as $sensor)136 {137 if(self::sensor_supported($sensor))138 {139 array_push($supported_sensors, $sensor);140 }141 }142 }143 return $supported_sensors;144 }145 public static function unsupported_sensors()146 {147 static $unsupported_sensors = null;148 if($unsupported_sensors == null)149 {150 $unsupported_sensors = array();151 $supported_sensors = self::supported_sensors();152 foreach(self::available_sensors() as $sensor)153 {154 if(!in_array($sensor, $supported_sensors))155 {156 array_push($unsupported_sensors, $sensor);157 }158 }159 }160 return $unsupported_sensors;161 }162 public static function read_sensor($sensor)163 {164 if($sensor instanceof phodevi_sensor)165 {166 $sensor_object = $sensor;167 }168 else169 {170 $sensor_object = new self::$sensors[$sensor[0]][$sensor[1]](null, null);171 }172 return $sensor_object->read_sensor();173 }174 public static function read_sensor_object_unit(&$sensor_object)175 {176 $sensor = array($sensor_object->get_type(), $sensor_object->get_sensor(), get_class($sensor_object));177 return self::read_sensor_unit($sensor);178 }179 public static function read_sensor_object_unit_short(&$sensor_object)180 {181 $sensor_unit = self::read_sensor_object_unit($sensor_object);182 switch($sensor_unit)183 {184 case 'Celsius':185 $sensor_unit = 'C';186 break;187 case 'Percent':188 $sensor_unit = '%';189 break;190 case 'Megabytes':191 $sensor_unit = 'MB';192 break;193 case 'Megahertz':194 $sensor_unit = 'MHz';195 break;196 case 'Volts':197 $sensor_unit = 'V';198 break;199 case 'Kilobytes/seconds':200 $sensor_unit = 'KBps';201 break;202 case 'Millivolts':203 $sensor_unit = 'mV';204 break;205 }206 return $sensor_unit;207 }208 public static function read_sensor_unit($sensor)209 {210 return call_user_func(array(self::$sensors[$sensor[0]][$sensor[1]], 'get_unit'));211 }212 public static function sensor_supported($sensor)213 {214 $sensor_object = new self::$sensors[$sensor[0]][$sensor[1]](null, null);215 return isset(self::$sensors[$sensor[0]][$sensor[1]]) && $sensor_object->support_check();216 }217 public static function sensor_object_identifier(&$sensor_object)218 {219 $sensor = array($sensor_object->get_type(), $sensor_object->get_sensor(), get_class($sensor_object));220 return self::sensor_identifier($sensor) . ($sensor_object->get_instance() != 0 ? '.' . $sensor_object->get_instance() : null);221 }222 public static function sensor_identifier($sensor)223 {224 return $sensor[0] . '.' . $sensor[1];225 }226 public static function sensor_object_name(&$sensor_object)227 {228 $sensor = array($sensor_object->get_type(), $sensor_object->get_sensor(), get_class($sensor_object));229 $name = self::sensor_name($sensor);230 $params = $sensor_object->get_readable_device_name();231 if($params !== NULL)232 {233 $name .= ' (' . $params . ')';234 }235 return $name;236 }237 public static function sensor_name($sensor)238 {239 $type = call_user_func(array(self::$sensors[$sensor[0]][$sensor[1]], 'get_type'));240 $sensor = call_user_func(array(self::$sensors[$sensor[0]][$sensor[1]], 'get_sensor'));241 if(strlen($type) < 4)242 {243 $formatted = strtoupper($type);244 }245 else246 {247 $formatted = ucwords($type);248 }249 switch($formatted)250 {251 case 'SYS':252 $formatted = 'System';253 break;254 case 'HDD':255 $formatted = 'Drive';256 break;257 }258 $formatted .= ' ';259 switch($sensor)260 {261 case 'temp':262 $formatted .= 'Temperature';263 break;264 case 'freq':265 $formatted .= 'Frequency';266 break;267 case 'memory':268 $formatted .= 'Memory Usage';269 break;270 case 'power':271 $formatted .= 'Power Consumption';272 break;273 default:274 $formatted .= ucwords(str_replace('-', ' ', $sensor));275 break;276 }277 return $formatted;278 }279 public static function system_hardware($return_as_string = true)280 {281 return self::system_information_parse(self::available_hardware_devices(), $return_as_string);282 }283 public static function system_software($return_as_string = true)284 {285 return self::system_information_parse(self::available_software_components(), $return_as_string);286 }287 public static function system_centralized_view($return_as_string = true)288 {289 $core_count = phodevi::read_property('cpu', 'physical-core-count');290 $thread_count = phodevi::read_property('cpu', 'thread-count');291 $sys = array(292 'Processor' => phodevi::read_property('cpu', 'model-and-speed'),293 array(294 'Core Count' => $core_count,295 'Thread Count' => !empty($core_count) && $core_count == $thread_count ? '' : $thread_count, // don't show thread count if it's same as core count296 'Extensions' => phodevi_cpu::instruction_set_extensions(),297 // 'Virtualization' => (phodevi_cpu::virtualization_technology() ? phodevi_cpu::virtualization_technology() : ''),298 'Cache Size' => phodevi::read_property('cpu', 'cache-size-string'),299 'Microcode'=> phodevi::read_property('cpu', 'microcode-version'),300 'Core Family' => phodevi::read_property('cpu', 'core-family-name'),301 'Scaling Driver'=> phodevi::read_property('cpu', 'scaling-governor'),302 ),303 'Graphics' => phodevi::read_name('gpu'),304 array(305 'Frequency' => phodevi::read_property('gpu', 'frequency'),306 'BAR1 / Visible vRAM' => phodevi::read_property('gpu', 'bar1-visible-vram'),307 'OpenGL' => phodevi::read_property('system', 'opengl-driver'),308 'Vulkan' => phodevi::read_property('system', 'vulkan-driver'),309 'OpenCL' => phodevi::read_property('system', 'opencl-driver'),310 'Display Driver' => phodevi::read_property('system', 'display-driver-string'),311 'Monitor' => phodevi::read_name('monitor'),312 'Screen' => phodevi::read_property('gpu', 'screen-resolution-string'),313 ),314 'Motherboard' => phodevi::read_name('motherboard'),315 array(316 'BIOS Version' => phodevi::read_property('motherboard', 'bios-version'),317 'Chipset' => phodevi::read_name('chipset'),318 'Audio' => phodevi::read_name('audio'),319 'Network' => phodevi::read_name('network'),320 'Platform Profile'=> phodevi::read_property('system', 'platform-profile'),321 ),322 'Memory' => phodevi::read_name('memory'),323 array(),324 'Disk' => phodevi::read_name('disk'),325 array(326 'File-System' => phodevi::read_property('system', 'filesystem'),327 'Mount Options' => phodevi::read_property('disk', 'mount-options-string'),328 //'Block Size' => phodevi::read_property('disk', 'block-size'),329 'Disk Scheduler' => phodevi::read_property('disk', 'scheduler'),330 'Disk Details' => phodevi::read_property('disk', 'extra-disk-details'),331 ),332 'Operating System' => phodevi::read_property('system', 'operating-system'),333 array(334 'Kernel' => phodevi::read_property('system', 'kernel-string'),335 'Desktop' => phodevi::read_property('system', 'desktop-environment'),336 'Display Server' => phodevi::read_property('system', 'display-server'),337 'Compiler' => phodevi::read_property('system', 'compiler'),338 'System Layer' => phodevi::read_property('system', 'system-layer'),339 'Security' => phodevi::read_property('system', 'security-features'),340 )341 );342 if($return_as_string)343 {344 $sys_string = null;345 $tabled = array();346 foreach($sys as $key => &$in)347 {348 $space_in = 2;349 if(is_array($in))350 {351 $tabled = array();352 foreach($in as $key => $value)353 {354 if(!empty($value))355 {356 if(isset($value[64]) && strpos($value, ' + ') !== false)357 {358 $values = explode(' + ', $value);359 $tabled[] = array(pts_client::cli_just_bold($key) . ':' . str_repeat(' ', (20 - strlen($key))), array_shift($values));360 foreach($values as $value)361 {362 $tabled[] = array(pts_client::cli_just_bold(' '), '+ ' . $value);363 }364 }365 else366 {367 $tabled[] = array(pts_client::cli_just_bold($key) . ':' . str_repeat(' ', (20 - strlen($key))), $value);368 //$sys_string .= ' ' . strtoupper($key) . ':' . $value . PHP_EOL;369 }370 }371 }372 }373 else374 {375 if(($x = strpos($in, ' (')))376 {377 $in = substr($in, 0, $x);378 }379 if(!empty($tabled))380 {381 $sys_string .= pts_user_io::display_text_table($tabled, ' ', 0, 17) . PHP_EOL;382 }383 if(isset($in[80]) && strpos($in, ' + ') !== false)384 {385 $values = explode(' + ', $in);386 $sys_string .= PHP_EOL . ' ' . pts_client::cli_colored_text(strtoupper($key), 'gray', true) . ': ' . str_repeat(' ', (22 - strlen($key))) . pts_client::cli_colored_text(array_shift($values), 'green', true);387 foreach($values as $value)388 {389 $sys_string .= PHP_EOL . str_repeat(' ', 22) . pts_client::cli_colored_text('+ ' . $value, 'green', true);390 }391 $sys_string .= PHP_EOL;392 }393 else394 {395 $sys_string .= PHP_EOL . ' ' . pts_client::cli_colored_text(strtoupper($key), 'gray', true) . ': ' . str_repeat(' ', (22 - strlen($key))) . pts_client::cli_colored_text($in, 'green', true) . PHP_EOL;396 }397 }398 }399 if(!empty($tabled))400 {401 $sys_string .= pts_user_io::display_text_table($tabled, ' ', 0, 17) . PHP_EOL;402 }403 return $sys_string;404 }405 return $sys;406 }407 public static function system_id_string()408 {409 $extra = null;410 foreach(array('CC', 'CXX', 'CFLAGS', 'CPPFLAGS', 'CXXFLAGS', 'USE_WINE') as $env)411 {412 $val = getenv($env);413 if(!empty($val))414 {415 $extra .= $env . '=' . $val . ';';416 }417 }418 $components = array(phodevi::read_property('cpu', 'model'), phodevi::read_property('system', 'operating-system'), phodevi::read_property('system', 'compiler'), $extra);419 return base64_encode(implode('__', $components));420 }421 public static function read_property($device, $read_property, $strip_string = true)422 {423 static $properties_table = array();424 $value = false;425 if(!isset($properties_table[$device]))426 {427 $properties_table[$device] = call_user_func(array('phodevi_' . $device, 'properties'));428 }429 if(!isset($properties_table[$device][$read_property]))430 {431 echo 'NOTICE: ' . $read_property . ' does not exist for ' . $device . '.' . PHP_EOL;432 }433 if(!($properties_table[$device][$read_property] instanceof phodevi_device_property))434 {435 return $properties_table[$device][$read_property];436 }437 $cache_code = $properties_table[$device][$read_property]->cache_code();438 if($cache_code != phodevi::no_caching && phodevi::$allow_phodevi_caching && isset(self::$device_cache[$device][$read_property]))439 {440 $value = self::$device_cache[$device][$read_property];441 }442 else443 {444 $dev_function_r = pts_arrays::to_array($properties_table[$device][$read_property]->get_device_function());445 $dev_function = $dev_function_r[0];446 $function_pass = array();447 for($i = 1; $i < count($dev_function_r); $i++)448 {449 array_push($function_pass, $dev_function_r[$i]);450 }451 if(method_exists('phodevi_' . $device, $dev_function))452 {453 $value = call_user_func_array(array('phodevi_' . $device, $dev_function), $function_pass);454 if(!is_array($value) && $value != null)455 {456 if($strip_string)457 {458 $value = pts_strings::strip_string($value);459 }460 if(function_exists('preg_replace'))461 {462 $value = preg_replace('/[^(\x20-\x7F)]*/','', $value);463 }464 }465 if($cache_code != phodevi::no_caching)466 {467 self::$device_cache[$device][$read_property] = $value;468 if($cache_code == phodevi::smart_caching)469 {470 // TODO: For now just copy the smart cache to other var, but come up with better yet efficient way471 self::$smart_cache[$device][$read_property] = $value;472 }473 }474 }475 }476 if(!empty(self::$sanitize_string) && !empty($value) && is_string($value))477 {478 $read_property_lower = strtolower($read_property);479 $device_lower = strtolower($device);480 foreach(self::$sanitize_string as $limit_or_index => $sanitize)481 {482 if(!is_numeric($limit_or_index) && $limit_or_index != $read_property && $limit_or_index != $device_lower)483 {484 // If index is set as property name, make sure reading the same property now or can skip it...485 continue;486 }487 $value = str_ireplace($sanitize, '', $value);488 }489 $value = trim($value);490 }491 return $value;492 }493 public static function read_all_properties()494 {495 $all_properties = array();496 $components = array();497 foreach(glob(__DIR__ . '/components/phodevi_*.php') as $file)498 {499 $components[] = substr(basename($file, '.php'), 8);500 }501 foreach($components as $device)502 {503 $properties = call_user_func(array('phodevi_' . $device, 'properties'));504 $all_properties[$device] = array();505 foreach($properties as $id => $property)506 {507 $dev_function_r = pts_arrays::to_array($property->get_device_function());508 $dev_function = $dev_function_r[0];509 $function_pass = array();510 for($i = 1; $i < count($dev_function_r); $i++)511 {512 array_push($function_pass, $dev_function_r[$i]);513 }514 if(method_exists('phodevi_' . $device, $dev_function))515 {516 $value = call_user_func_array(array('phodevi_' . $device, $dev_function), $function_pass);517 if(!is_array($value) && $value != null)518 {519 $value = pts_strings::strip_string($value);520 if(function_exists('preg_replace'))521 {522 $value = preg_replace('/[^(\x20-\x7F)]*/','', $value);523 }524 }525 $all_properties[$device][$id] = $value;526 }527 }528 }529 return $all_properties;530 }531 public static function set_property($device, $set_property, $pass_args = array())532 {533 $return_value = false;534 if(method_exists('phodevi_' . $device, 'set_property'))535 {536 $return_value = call_user_func(array('phodevi_' . $device, 'set_property'), $set_property, $pass_args);537 }538 return $return_value;539 }540 public static function create_vfs()541 {542 self::$vfs = new phodevi_vfs();543 }544 public static function set_sanitize_string($str)545 {546 self::$sanitize_string = array();547 // Multiple strings to remove can be delimited by a comma548 foreach(explode(',', $str) as $to_sanitize)549 {550 if(!empty($to_sanitize))551 {552 $to_sanitize = explode('=', $to_sanitize);553 if(count($to_sanitize) == 2)554 {555 // Limiting sanitize string to a particular Phodevi property556 self::$sanitize_string[strtolower($to_sanitize[0])] = $to_sanitize[1];557 }558 else559 {560 // Check all Phodevi properties561 self::$sanitize_string[] = $to_sanitize[0];562 }563 }564 }565 }566 public static function initial_setup()567 {568 phodevi::set_sanitize_string(pts_env::read('PHODEVI_SANITIZE'));569 // Operating System Detection570 $supported_operating_systems = pts_types::operating_systems();571 $uname_s = strtolower(php_uname('s'));572 foreach($supported_operating_systems as $os_check)573 {574 for($i = 0; $i < count($os_check); $i++)575 {576 if(strpos($uname_s, strtolower($os_check[$i])) !== false) // Check for OS577 {578 self::$operating_system = $os_check[0];579 self::$operating_systems[strtolower($os_check[0])] = true;580 break;581 }582 }...
error_report.php
Source:error_report.php
...27$stmt->bindValue(':system_id', SYSTEM_ID);28$stmt->bindValue(':upload_time', phoromatic_server::current_time());29$stmt->bindValue(':schedule_id', $SCHEDULE_ID);30$stmt->bindValue(':trigger_id', $TRIGGER_STRING);31$stmt->bindValue(':error_msg', pts_strings::sanitize($ERROR_MSG));32$stmt->bindValue(':test_identifier', $TEST_IDENTIFIER);33$stmt->bindValue(':test_arguments', $OTHER);34$result = $stmt->execute();35// Email notifications36$stmt = phoromatic_server::$db->prepare('SELECT UserName, Email FROM phoromatic_users WHERE UserID IN (SELECT UserID FROM phoromatic_user_settings WHERE AccountID = :account_id AND NotifyOnWarnings = 1) AND AccountID = :account_id');37$stmt->bindValue(':account_id', ACCOUNT_ID);38$result = $stmt->execute();39while($row = $result->fetchArray())40{41 phoromatic_server::send_email($row['Email'], 'Phoromatic System Error/Warning', phoromatic_server::account_id_to_group_admin_email(ACCOUNT_ID), '<p><strong>' . $row['UserName'] . ':</strong></p><p>A warning or error has been reported by a system associated with the Phoromatic account.</p><p>System: ' . SYSTEM_NAME . '<br />Trigger String: ' . pts_strings::sanitize($TRIGGER_STRING) . '<br />Test Identifier: ' . pts_strings::sanitize($TEST_IDENTIFIER) . '<br />Message: ' . pts_strings::sanitize($ERROR_MSG) . '</p>');42}43?>...
sanitize
Using AI Code Generation
1require_once('pts_strings.php');2echo pts_strings::sanitize($_GET['var1']);3require_once('pts_strings.php');4echo pts_strings::sanitize($_GET['var1']);5require_once('pts_strings.php');6echo pts_strings::sanitize($_GET['var1']);7require_once('pts_strings.php');8echo pts_strings::sanitize($_GET['var1']);
sanitize
Using AI Code Generation
1require_once('pts_strings.php');2$pts_strings = new pts_strings();3$var = $pts_strings->sanitize($_POST['var']);4require_once('pts_strings.php');5$pts_strings = new pts_strings();6$var = $pts_strings->sanitize($_POST['var']);7require_once('pts_strings.php');8$pts_strings = new pts_strings();9$var = $pts_strings->sanitize($_POST['var']);10require_once('pts_strings.php');11$pts_strings = new pts_strings();12$var = $pts_strings->sanitize($_POST['var']);13require_once('pts_strings.php');14$pts_strings = new pts_strings();15$var = $pts_strings->sanitize($_POST['var']);16require_once('pts_strings.php');17$pts_strings = new pts_strings();18$var = $pts_strings->sanitize($_POST['var']);19require_once('pts_strings.php');20$pts_strings = new pts_strings();21$var = $pts_strings->sanitize($_POST['var']);22require_once('pts_strings.php');23$pts_strings = new pts_strings();24$var = $pts_strings->sanitize($_POST['var']);25require_once('pts_strings.php');26$pts_strings = new pts_strings();27$var = $pts_strings->sanitize($_POST['var']);
sanitize
Using AI Code Generation
1$name = pts_strings::sanitize($_GET['name']);2$age = pts_strings::sanitize($_GET['age']);3$address = pts_strings::sanitize($_GET['address']);4$email = pts_strings::sanitize($_GET['email']);5$phone = pts_strings::sanitize($_GET['phone']);6$city = pts_strings::sanitize($_GET['city']);7$state = pts_strings::sanitize($_GET['state']);8$zip = pts_strings::sanitize($_GET['zip']);9$country = pts_strings::sanitize($_GET['country']);10$shipping = pts_strings::sanitize($_GET['shipping']);11$payment = pts_strings::sanitize($_GET['payment']);
sanitize
Using AI Code Generation
1require_once 'pts_strings.php';2$pts_strings = new pts_strings();3$sanitizedString = $pts_strings->sanitize($_POST['input']);4echo $sanitizedString;5strip_tags()6trim()7htmlentities()8htmlspecialchars()9mysql_real_escape_string()10preg_replace()11preg_match()12preg_replace()13preg_match()14preg_replace()15preg_match()
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with sanitize on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!