/** * Recursively determine whether the specified path is actually valid on the * configured repository. * * @param string $path * @return bool True if the path is valid, False otherwise. */ function alfresco_validate_path($path, $folders = null) { if ($path == '/') { return true; } /// Remove any extraneous slashes from the ends of the string $path = trim($path, '/'); $parts = explode('/', $path); /// Initialize the folder structure if a structure piece wasn't passed to this function. if ($folders == null) { $folders = alfresco_folder_structure(); } /// Get the first piece from the list of path elements. $pathpiece = array_shift($parts); if (!empty($folders)) { foreach ($folders as $folder) { if ($folder['name'] == $pathpiece) { /// If there are no more path elements, we've succeeded! if (empty($parts)) { return true; /// If there are path elements left but no children from the current /// folder, we've failed. } else { if (!empty($parts) && empty($folder['children'])) { return false; /// Otherwise, keep looking below. } else { return alfresco_validate_path(implode('/', $parts), $folder['children']); } } } } } return false; }
/** * Recursively builds a dynamic tree menu for seleting the categories to filter * search results by. * * @param array $cats An array of category objects from the DB. * @param array $selected An array of currently selected category IDs. * @return array An array of completed HTML_TreeMenu nodes. */ function make_root_folder_select_tree($folders = false, $path = '') { global $CFG; if (ALFRESCO_DEBUG_TRACE) { mtrace('make_root_folder_select_tree()'); } if (empty($folders) && !($folders = alfresco_folder_structure())) { return false; } $icon = 'folder.gif'; $eicon = 'folder-expanded.gif'; $nodes = array(); foreach ($folders as $i => $folder) { $npath = $path . '/' . $folder['name']; $text = ' <a href="#" onclick="set_value(\'' . $npath . '\')" title="' . $npath . '">' . $folder['name'] . (!empty($CFG->repository_alfresco_root_folder) && $CFG->repository_alfresco_root_folder == $npath ? ' <span class="pathok">✔</span>' : '') . '</a>'; $node = new HTML_TreeNode(array('text' => $text, 'icon' => $icon, 'expandedIcon' => $eicon, 'expanded' => false)); if (!empty($folder['children'])) { if ($cnodes = $this->make_root_folder_select_tree($folder['children'], $npath)) { for ($j = 0; $j < count($cnodes); $j++) { $node->addItem($cnodes[$j]); } } } $nodes[] = $node; } return $nodes; }