From 66bcb6e836ce468d71405afb1f99b255a20307f8 Mon Sep 17 00:00:00 2001 From: reliberate Date: Mon, 21 Mar 2016 16:01:44 -0600 Subject: [PATCH] Editor: Fix Clip Library folder nesting, misc adjustments to Clip and File lists. --- app/edit/clipadd.php | 4 +- app/edit/cliplist.php | 121 +++++++++++++++++------------------ app/edit/clipoptions.php | 2 +- app/edit/clipoptionslist.php | 115 +++++++++++++++------------------ app/edit/filelist.php | 107 ++++++++++++------------------- app/edit/fileoptionslist.php | 70 ++++++++++---------- app/exec/exec.php | 2 +- 7 files changed, 189 insertions(+), 232 deletions(-) diff --git a/app/edit/clipadd.php b/app/edit/clipadd.php index f291387992..94166ef8df 100644 --- a/app/edit/clipadd.php +++ b/app/edit/clipadd.php @@ -88,7 +88,7 @@ if (count($_POST)>0) { echo ""; echo " "; echo " "; - echo " "; + echo " "; echo " "; echo " "; @@ -125,5 +125,7 @@ if (count($_POST)>0) { echo " "; echo "
Name
"; + echo ""; + require_once "footer.php"; ?> \ No newline at end of file diff --git a/app/edit/cliplist.php b/app/edit/cliplist.php index f92f9b98a6..a6914ad6aa 100644 --- a/app/edit/cliplist.php +++ b/app/edit/cliplist.php @@ -115,13 +115,13 @@ echo "\n"; echo " }\n"; echo ""; -echo ""; +echo ""; // keyboard shortcut bindings echo "\n"; @@ -159,80 +159,75 @@ echo " else {\n"; echo " return true;\n"; echo " }\n"; echo " });\n"; -echo ""; +echo "\n"; -echo ""; -echo ""; -echo "
"; -echo "\n"; -echo "\n"; -echo "
\n"; -echo "
".$text['label-clip-library']."
\n"; //display:none +echo "\n"; +echo "\n"; -$sql = "select * from v_clips "; -$sql .= "order by clip_folder "; +echo "
\n"; +echo "\n"; + +$sql = "select * from v_clips order by clip_folder asc, clip_name asc"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); -if ($result_count > 0) { //no results - $last_folder = ''; - $tag_open = ''; - $x = 0; - $current_depth = 0; - $previous_depth = 0; - foreach($result as $row) { - $current_depth = count(explode ("/", $row['clip_folder'])); - if ($current_depth < $previous_depth) { - $count = ($previous_depth - $current_depth); - $i=0; - while($i < $count){ - echo "
\n"; - $i++; +if ($result_count > 0) { + $master_array = array(); + foreach ($result as $row) { + $clip_folder = rtrim($row['clip_folder'], '/'); + $clip_folder .= '/'.$row['clip_name']; + + $parts = explode('/', $clip_folder); + $folders = array(); + while ($bottom = array_pop($parts)) { + if (sizeof($folders) > 0) { + $folders = array($bottom => $folders); + } + else { + $clip['uuid'] = $row['clip_uuid']; + $clip['name'] = $row['clip_name']; + $clip['before'] = $row['clip_text_start']; + $clip['after'] = $row['clip_text_end']; + $folders = array($bottom => $clip); } - echo "
\n"; } - if ($last_folder != $row['clip_folder']) { - $clip_folder_name = str_replace ($previous_folder_name, "", $row['clip_folder']); - $clip_folder_name = str_replace ("/", "", $clip_folder_name); - echo "
".$clip_folder_name."
\n\n"; - $tag_open = 1; + $master_array = array_merge_recursive($master_array, $folders); + } + + function parse_array($arr) { + if (is_array($arr)) { + //folder/clip + foreach ($arr as $name => $sub_arr) { + if ($name != $sub_arr['name']) { + //folder + echo "".$name.""; + echo "
\n"; + parse_array($sub_arr); + echo "
\n"; + } + else { + //clip + echo "
\n"; + echo ""; + echo ""; + echo $sub_arr['name']; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + } + } } + } + parse_array($master_array); +} - $previous_depth = $current_depth; - $previous_folder_name = $row['clip_folder']; +echo "
\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "
"; - echo "".$row['clip_name']."\n"; - echo "
\n"; - echo "\n\n"; - - $last_folder = $row['clip_folder']; - - if ($c==0) { $c=1; } else { $c=0; } - } //end foreach - unset($sql, $result, $row_count); - -} //end if results - -echo "\n"; -echo "
\n"; - -echo "\n"; -echo "\n"; -echo "\n"; -echo "
"; +//echo "
".print_r($master_array, true)."
"; require_once "footer.php"; - -unset ($result_count); -unset ($result); -unset ($key); -unset ($val); -unset ($c); ?> \ No newline at end of file diff --git a/app/edit/clipoptions.php b/app/edit/clipoptions.php index 5a03eacad2..505f4a60d6 100644 --- a/app/edit/clipoptions.php +++ b/app/edit/clipoptions.php @@ -53,8 +53,8 @@ echo "\n"; echo ""; echo ""; -echo " \n"; echo " \n"; +echo " \n"; echo " \n"; echo " \n"; echo " \n"; diff --git a/app/edit/clipoptionslist.php b/app/edit/clipoptionslist.php index 8073cd2dc7..cd1d625391 100644 --- a/app/edit/clipoptionslist.php +++ b/app/edit/clipoptionslist.php @@ -113,82 +113,71 @@ echo "\n"; echo "}\n"; echo ""; -echo "
 
\n"; +echo "\n"; +echo "\n"; -echo "\n"; -echo "
\n"; -echo "
".$text['label-clip-library']."
\n"; +echo "
\n"; -$sql = "select * from v_clips "; -$sql .= "order by clip_folder "; +$sql = "select * from v_clips order by clip_folder asc, clip_name asc"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $result_count = count($result); -if ($result_count > 0) { //no results - $last_folder = ''; - $tag_open = ''; - $x = 0; - $current_depth = 0; - $previous_depth = 0; - foreach($result as $row) { - $current_depth = count(explode("/", $row[clip_folder])); - if ($current_depth < $previous_depth) { - $count = ($previous_depth - $current_depth); - $i=0; - while($i < $count){ - echo "
\n"; - $i++; +if ($result_count > 0) { + $master_array = array(); + foreach ($result as $row) { + $clip_folder = rtrim($row['clip_folder'], '/'); + $clip_folder .= '/'.$row['clip_name']; + + $parts = explode('/', $clip_folder); + $folders = array(); + while ($bottom = array_pop($parts)) { + if (sizeof($folders) > 0) { + $folders = array($bottom => $folders); + } + else { + $clip['uuid'] = $row['clip_uuid']; + $clip['name'] = $row['clip_name']; + $clip['before'] = $row['clip_text_start']; + $clip['after'] = $row['clip_text_end']; + $folders = array($bottom => $clip); } - echo "
\n"; - } - if ($last_folder != $row['clip_folder']) { - $clip_folder_name = str_replace ($previous_folder_name, "", $row['clip_folder']); - $clip_folder_name = str_replace ("/", "", $clip_folder_name); - echo ""; - echo " "; - echo " "; -echo " "; -echo "
"; - echo " ".$clip_folder_name."
"; - $tag_open = 1; + $master_array = array_merge_recursive($master_array, $folders); + } + + function parse_array($arr) { + if (is_array($arr)) { + //folder/clip + foreach ($arr as $name => $sub_arr) { + if ($name != $sub_arr['name']) { + //folder + echo "".$name.""; + echo "
\n"; + parse_array($sub_arr); + echo "
\n"; + } + else { + //clip + echo "
\n"; + echo ""; + echo ""; + echo $sub_arr['name']; + echO "\n"; + echo "\n"; + echo "\n"; + echo "
\n"; + } + } } + } + parse_array($master_array); +} - $previous_depth = $current_depth; - $previous_folder_name = $row['clip_folder']; - - echo "\n"; - echo "\n"; - echo "\n"; - echo ""; - echo " "; - echo " "; - echo " "; - echo "
"; - echo " ".$row['clip_name'].""; - echo "
\n"; - - $last_folder = $row['clip_folder']; - if ($c==0) { $c=1; } else { $c=0; } - } //end foreach - unset($sql, $result, $row_count); -} //end if results - -echo "
"; -echo "
\n"; - -echo "\n"; -echo "\n"; -echo "\n"; +echo "\n"; require_once "footer.php"; -unset ($result_count); -unset ($result); -unset ($key); -unset ($val); -unset ($c); ?> \ No newline at end of file diff --git a/app/edit/filelist.php b/app/edit/filelist.php index ab77644bff..07488aa228 100644 --- a/app/edit/filelist.php +++ b/app/edit/filelist.php @@ -75,28 +75,20 @@ else { if (is_dir($newpath)) { $dirname = end($level); - $htmldirlist .= " - - - - -
- ".$dirname."
".recur_dir($newpath)."
-
\n"; + $htmldirlist .= "
\n"; + $htmldirlist .= "".$dirname.""; + $htmldirlist .= "
".recur_dir($newpath)."
\n"; + $htmldirlist .= "
\n"; } else { $filename = end($level); $filesize = round(filesize($newpath)/1024, 2); $newpath = str_replace ('//', '/', $newpath); $newpath = str_replace ("\\", "/", $newpath); - $htmlfilelist .= " - - - - -
- ".$filename." -
\n"; + $htmlfilelist .= "
\n"; + $htmlfilelist .= ""; + $htmlfilelist .= "".$filename."\n"; + $htmlfilelist .= "
\n"; } } @@ -213,68 +205,49 @@ echo " });\n"; echo ""; echo "\n"; -echo "\n"; +echo "\n"; -echo "
"; -echo "\n"; -echo "\n"; -echo " \n"; -echo "\n"; -echo "
\n"; - -echo "\n"; -echo "
".$text['label-files']."
\n"; +echo "\n"; +echo "
\n"; //start the session ini_set("session.cookie_httponly", True); session_start(); -if ($_SESSION["app"]["edit"]["dir"] == "scripts") { - echo recur_dir($_SESSION['switch']['scripts']['dir']); -} -if ($_SESSION["app"]["edit"]["dir"] == "php") { - echo recur_dir($_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH); -} -if ($_SESSION["app"]["edit"]["dir"] == "grammar") { - echo recur_dir($_SESSION['switch']['grammar']['dir']); -} -if ($_SESSION["app"]["edit"]["dir"] == "provision") { - - switch (PHP_OS) { - case "Linux": - if (file_exists('/etc/fusionpbx/resources/templates/provision')) { - echo recur_dir('/etc/fusionpbx/resources/templates/provision'); - } - else { - echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); +switch ($_SESSION["app"]["edit"]["dir"]) { + case 'scripts': + echo recur_dir($_SESSION['switch']['scripts']['dir']); + break; + case 'php': + echo recur_dir($_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH); + break; + case 'grammer': + echo recur_dir($_SESSION['switch']['grammar']['dir']); + break; + case 'provision': + switch (PHP_OS) { + case "Linux": + echo (file_exists('/etc/fusionpbx/resources/templates/provision')) ? recur_dir('/etc/fusionpbx/resources/templates/provision') : recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); + break; + case "FreeBSD": + echo (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) ? recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/") : recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); + break; + case "NetBSD": + echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); + break; + case "OpenBSD": + echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); + break; + default: + echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); } break; - case "FreeBSD": - //if the FreeBSD port is installed use the following paths by default. - if (file_exists('/usr/local/etc/fusionpbx/resources/templates/provision')) { - echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); - } - else { - echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); - } + case 'xml': + echo recur_dir($_SESSION['switch']['conf']['dir']); break; - case "NetBSD": - echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); - break; - case "OpenBSD": - echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); - break; - default: - echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); - } -} -if ($_SESSION["app"]["edit"]["dir"] == "xml") { - echo recur_dir($_SESSION['switch']['conf']['dir']); } -echo "
\n"; +echo "\n"; -echo "
\n"; -echo "
"; require_once "footer.php"; diff --git a/app/edit/fileoptionslist.php b/app/edit/fileoptionslist.php index 518d620d3e..52124d2bfd 100644 --- a/app/edit/fileoptionslist.php +++ b/app/edit/fileoptionslist.php @@ -53,12 +53,17 @@ else { if ($file != "." AND $file != ".."){ $newpath = $dir.'/'.$file; $level = explode('/',$newpath); - if (substr($newpath, -4) == ".svn" || - substr($newpath, -4) == ".git") { - //ignore .svn and .git dir and subdir - } - elseif (substr($newpath, -3) == ".db") { - //ignore .db files + if ( + substr(strtolower($newpath), -4) == ".svn" || + substr(strtolower($newpath), -4) == ".git" || + substr(strtolower($newpath), -3) == ".db" || + substr(strtolower($newpath), -4) == ".jpg" || + substr(strtolower($newpath), -4) == ".gif" || + substr(strtolower($newpath), -4) == ".png" || + substr(strtolower($newpath), -4) == ".ico" || + substr(strtolower($newpath), -4) == ".ttf" + ){ + //ignore certain files (and folders) } else { $dir_array[] = $newpath; @@ -76,7 +81,7 @@ else { $dirname = end($level); $newpath = str_replace ('//', '/', $newpath); $htmldirlist .= " - +
".$dirname."
".recur_dir($newpath)."
@@ -91,7 +96,7 @@ else { $newpath = str_replace ("\\", "/", $newpath); $newpath = str_replace ($filename, '', $newpath); $htmlfilelist .= " - +
"; echo " "; echo " "; }
".$filename." @@ -184,40 +189,33 @@ echo "\n"; echo "}\n"; echo "\n"; -echo "\n"; -echo " \n"; -echo " \n"; -echo " \n"; -echo "
\n"; -echo "
".$text['label-files']."
\n"; +echo "\n"; +echo "\n"; + +echo "
\n"; ini_set("session.cookie_httponly", True); session_start(); -if ($_SESSION["app"]["edit"]["dir"] == "scripts") { - echo recur_dir($_SESSION['switch']['scripts']['dir']); -} -if ($_SESSION["app"]["edit"]["dir"] == "php") { - echo recur_dir($_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH); -} -if ($_SESSION["app"]["edit"]["dir"] == "grammar") { - echo recur_dir($_SESSION['switch']['grammar']['dir']); -} -if ($_SESSION["app"]["edit"]["dir"] == "provision") { - echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); -} -if ($_SESSION["app"]["edit"]["dir"] == "xml") { - echo recur_dir($_SESSION['switch']['conf']['dir']); +switch ($_SESSION["app"]["edit"]["dir"]) { + case 'scripts': + echo recur_dir($_SESSION['switch']['scripts']['dir']); + break; + case 'php': + echo recur_dir($_SERVER["DOCUMENT_ROOT"].'/'.PROJECT_PATH); + break; + case 'grammer': + echo recur_dir($_SESSION['switch']['grammar']['dir']); + break; + case 'provision': + echo recur_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH."/resources/templates/provision/"); + break; + case 'xml': + echo recur_dir($_SESSION['switch']['conf']['dir']); + break; } -echo "
\n"; - -echo "
\n"; +echo "\n"; require_once "footer.php"; -unset ($result_count); -unset ($result); -unset ($key); -unset ($val); -unset ($c); ?> \ No newline at end of file diff --git a/app/exec/exec.php b/app/exec/exec.php index 95fff44ebf..bb64398031 100644 --- a/app/exec/exec.php +++ b/app/exec/exec.php @@ -282,7 +282,7 @@ else { if (permission_exists('script_editor_view') && file_exists($_SERVER["PROJECT_ROOT"]."/app/edit/")) { echo "
"; - echo " \n"; + echo " \n"; echo "