From a218bdd5fc29f4dab9f68c4eb9173db0627046c1 Mon Sep 17 00:00:00 2001 From: Alex Vitkov Date: Sat, 13 Feb 2021 00:19:20 +0200 Subject: Compressed get_directory --- php/node.php | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'php/node.php') diff --git a/php/node.php b/php/node.php index c2ab5f1..bb404e0 100644 --- a/php/node.php +++ b/php/node.php @@ -7,24 +7,18 @@ require_once "user.php"; function get_directory(string $abstract_path,User $user) { global $database; - if($abstract_path[0]!="/") - { + if($abstract_path[0] != "/") { return NULL; } - if($component=strtok($abstract_path,"/")==false) - { - return $user->home_directory; - } - $current_dir=$database->get_node_id($component,$user->home_directory); - if($current_dir==NULL) - return NULL; - /*traverse path*/ - while($component=strtok("/")) - { - $current_dir=$database->get_node_id($component,$current_dir); - if($current_dir==NULL) - return NULL; - } + + $component = strtok($abstract_path,"/"); + $current_dir = $user->home_directory; + + while ($component) { + $current_dir = $database->get_node_id($component, $current_dir); + $component = strtok("/"); + }; + return $current_dir; } -- cgit v1.2.3