diff --git a/README.md b/README.md
index d48c233..8d61652 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ Shows the board's Hugo documentation site inside phpBB, styled with the active b
The build's HTML is shown inside the board as-is, so only put a build you trust at the docs build path, in a directory only administrators can write to.
-Boards upgraded from an earlier version keep their build at `ext/phpbbmodders/documentation/docs-build/` if one was already there; move it to the new location and update the docs build path to stop the next extension update deleting it.
+Boards upgraded from an earlier version keep their build at `ext/phpbbmodders/documentation/docs-build/` if one was already there; move it to the new location and update the docs build path to stop the next extension update deleting it. The settings page warns while the build is inside the extension's directory. If the build is moved but the setting isn't updated, the extension reads it from `store/phpbbmodders_documentation/` and the settings page asks for the setting to be updated.
If you add a new top-level section or a new language to the docs build later, use the **Resync permissions** button on the settings page.
diff --git a/acp/main_module.php b/acp/main_module.php
index de86619..4d3f274 100644
--- a/acp/main_module.php
+++ b/acp/main_module.php
@@ -166,6 +166,9 @@ public function main($id, $mode)
'ERROR_MSG' => implode('
', $error),
'S_DOCUMENTATION_BUILD_FOUND' => $docs_root_found,
+ 'S_DOCUMENTATION_STORE_FALLBACK' => $doc_helper->is_using_store_fallback(),
+ 'S_DOCUMENTATION_BUILD_IN_EXTENSION' => $doc_helper->is_build_inside_extension(),
+ 'DOCUMENTATION_DEFAULT_DOCS_PATH' => $doc_helper::DEFAULT_DOCS_PATH,
'RESYNC_FEEDBACK' => $resync_feedback,
'DOCUMENTATION_DOCS_PATH' => $cfg_array['phpbbmodders_documentation_docs_path'],
diff --git a/adm/style/acp_documentation.html b/adm/style/acp_documentation.html
index 7cd203f..a17cd89 100644
--- a/adm/style/acp_documentation.html
+++ b/adm/style/acp_documentation.html
@@ -15,6 +15,18 @@
{{ lang('ACP_DOCUMENTATION_STORE_FALLBACK', DOCUMENTATION_DEFAULT_DOCS_PATH)|e }}
+{{ lang('ACP_DOCUMENTATION_BUILD_IN_EXTENSION', DOCUMENTATION_DEFAULT_DOCS_PATH)|e }}
+{{ lang('ACP_DOCUMENTATION_BUILD_MISSING') }}
diff --git a/controller/documentation_helper.php b/controller/documentation_helper.php index 903e671..f747c7c 100644 --- a/controller/documentation_helper.php +++ b/controller/documentation_helper.php @@ -43,6 +43,18 @@ class documentation_helper /** Page whose wide tables get wrapped in a horizontally scrollable region. */ const EVENTS_LIST_PATH = 'development/extensions/events_list'; + /** Default docs build path, relative to the phpBB root. */ + const DEFAULT_DOCS_PATH = 'store/phpbbmodders_documentation'; + + /** + * Default before the build moved to store/. Boards still set to it use + * DEFAULT_DOCS_PATH when this has no build but that does. + */ + const LEGACY_DOCS_PATH = 'ext/phpbbmodders/documentation/docs-build'; + + /** This extension's own directory, relative to the phpBB root. */ + const EXTENSION_PATH = 'ext/phpbbmodders/documentation'; + /** Character Hugo's breadcrumb puts before its home link. */ const HUGO_HOME_GLYPH = '⌂'; @@ -167,24 +179,88 @@ public function get_docs_root() } /** - * @return string|false The configured docs path, resolved and - * existence-checked, but without requiring it to be non-empty. + * The configured docs path, resolved and existence-checked, but + * without requiring it to be non-empty. A board still set to + * LEGACY_DOCS_PATH with no build there gets DEFAULT_DOCS_PATH instead + * when that has a build, so moving the build to store/ works before + * the setting is updated. + * + * @return string|false */ protected function resolve_configured_root() { $configured = (string) $this->config['phpbbmodders_documentation_docs_path']; + $root = $this->resolve_path($configured); + + if ($this->is_store_fallback($configured, $root)) + { + return $this->resolve_path(self::DEFAULT_DOCS_PATH); + } + + return $root; + } + + /** + * @param string $configured The docs path setting. + * @param string|false $root That setting, resolved. + * @return bool Whether the build is read from DEFAULT_DOCS_PATH instead. + */ + protected function is_store_fallback($configured, $root) + { + if ($configured !== self::LEGACY_DOCS_PATH || ($root !== false && $this->has_any_language_directory($root))) + { + return false; + } + + $store = $this->resolve_path(self::DEFAULT_DOCS_PATH); + + return $store !== false && $this->has_any_language_directory($store); + } - if ($configured === '') + /** + * @param string $path Absolute, or relative to the phpBB root. + * @return string|false The existing directory's real path. + */ + protected function resolve_path($path) + { + if ($path === '') { return false; } - $root = (strpos($configured, '/') === 0) ? $configured : $this->phpbb_root_path . $configured; - $real = realpath($root); + $real = realpath((strpos($path, '/') === 0) ? $path : $this->phpbb_root_path . $path); return ($real !== false && is_dir($real)) ? $real : false; } + /** + * Whether the docs build path setting is still the old default but the + * build is read from DEFAULT_DOCS_PATH, so the setting should be updated. + * + * @return bool + */ + public function is_using_store_fallback() + { + $configured = (string) $this->config['phpbbmodders_documentation_docs_path']; + + return $this->is_store_fallback($configured, $this->resolve_path($configured)); + } + + /** + * Whether the build in use lives inside this extension's own + * directory, which is replaced, build and all, when the extension is + * updated. + * + * @return bool + */ + public function is_build_inside_extension() + { + $root = $this->get_docs_root(); + $extension = $this->resolve_path(self::EXTENSION_PATH); + + return $root !== false && $extension !== false && strpos($root . DIRECTORY_SEPARATOR, $extension . DIRECTORY_SEPARATOR) === 0; + } + /** * @param string $root * @return bool diff --git a/docs-build/.gitkeep b/docs-build/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/docs-build/.htaccess b/docs-build/.htaccess deleted file mode 100644 index 92e78ba..0000000 --- a/docs-build/.htaccess +++ /dev/null @@ -1,25 +0,0 @@ -# With Apache 2.4 the "Order, Deny" syntax has been deprecated and moved from -# module mod_authz_host to a new module called mod_access_compat (which may be -# disabled) and a new "Require" syntax has been introduced to mod_authz_core. -# We could just conditionally provide both versions, but unfortunately Apache -# does not explicitly tell us its version if the module mod_version is not -# available. In this case, we check for the availability of module -# mod_authz_core (which should be on 2.4 or higher only) as a best guess. -