* */ namespace ComboStrap; /** * Class PageUtility * @package ComboStrap * See also {@link pageutils.php} */ class FsWikiUtility { /** * Determine if the current page is a sidebar (a bar) * @return bool * TODO: Duplicate of {@link MarkupPath::isSlot()} ? */ public static function isSideBar(): bool { global $INFO; global $ID; $isSidebar = false; if ($INFO != null) { $id = $INFO['id']; if ($ID != $id) { $isSidebar = TRUE; } } return $isSidebar; } /** * Return all pages and/of sub-namespaces (subdirectory) of a namespace (ie directory) * Adapted from feed.php * * @param string $path The container of the pages * @return array An array of the pages for the namespace * @throws ExceptionBadSyntax if the string is not a namespace path */ static function getChildren(string $path): array { require_once(DOKU_INC . '/inc/search.php'); global $conf; WikiPath::checkNamespacePath($path); /** * To the wiki id form */ $dokuPath = WikiPath::createMarkupPathFromPath($path); // delete the last separator $dokuwikiId = substr( $dokuPath->getWikiId(),0,-1); $relativeFileSystemPath = str_replace(":", "/", $dokuwikiId); $data = array(); // Options of the callback function search_universal // in the search.php file $search_opts = array( 'depth' => 1, 'pagesonly' => true, 'listfiles' => true, 'listdirs' => true, 'skipacl' => true //'firsthead' => true ); // search_universal is a function in inc/search.php that accepts the $search_opts parameters search($data, // The returned data $conf['datadir'], // The root 'search_universal', // The recursive function (callback) $search_opts, // The options given to the recursive function $relativeFileSystemPath, // The id 1 // Only one level in the tree ); return $data; } /** * Return the page index of a namespace or null if it does not exist * ie the index.html * @param $namespacePath - in dokuwiki format * @return string - the dokuwiki path * @deprecated use {@link MarkupPath::getIndexPageFromNamespace()} instead */ public static function getHomePagePath($namespacePath): ?string { $homePage = MarkupPath::getIndexPageFromNamespace($namespacePath); if ($homePage->exists()) { return $homePage->getAbsolutePath(); } else { return null; } } public static function getChildrenNamespace($nameSpacePath) { require_once(__DIR__ . '/../../../../inc/search.php'); global $conf; $data = array(); // Options of the callback function search_universal // in the search.php file $search_opts = array(); // search_universal is a function in inc/search.php that accepts the $search_opts parameters search_namespaces($data, // The returned data $conf['datadir'], // The root $nameSpacePath, // The directory to search 'd', 1, // Only one level in the tree $search_opts ); return $data; } /** * @param $namespacePath * @return MarkupPath|null the page path of the parent or null if it does not exist */ public static function getParentPagePath($namespacePath): ?MarkupPath { /** * Root case */ if ($namespacePath === ":") { return null; } /** * A namespace path does not have a `:` at the end * only for the root */ $pos = strrpos($namespacePath, ':'); if ($pos !== false) { if ($pos == 0) { $parentNamespacePath = ":"; } else { $parentNamespacePath = substr($namespacePath, 0, $pos); } return MarkupPath::getIndexPageFromNamespace($parentNamespacePath); } else { return null; } } /** * Find the pages in the tree * @param $startPath * @param int $depth * @return array */ public static function getPages($startPath, int $depth = 0): array { if ($startPath === null || $startPath === "") { throw new \RuntimeException("A start path is mandatory"); } // Run as admin to overcome the fact that // anonymous user cannot set all links and backlinks global $conf; $dataDir = $conf['datadir']; $pages = array(); // This is a page if (page_exists($startPath)) { $pages[] = array( 'id' => $startPath, 'ns' => getNS($startPath), 'title' => p_get_first_heading($startPath, false), 'size' => filesize(wikiFN($startPath)), 'mtime' => filemtime(wikiFN($startPath)), 'perm' => 16, 'type' => 'f', 'level' => 0, 'open' => 1, ); } else { $startPath = str_replace(':', '/', $startPath); /** * Directory */ search( $pages, $dataDir, 'search_universal', array( 'depth' => $depth, 'listfiles' => true, 'listdirs' => false, 'pagesonly' => true, 'skipacl' => true, 'firsthead' => false, 'meta' => false, ), $startPath ); } return $pages; } }