From fc236f6127c0beb3b3de6b0c94de3795c9cd6562 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 17:44:01 +0200 Subject: [PATCH 01/59] move Automad namespace source to src directory --- automad/autoload.php | 10 +++++++--- automad/init.php | 2 +- automad/{app.php => src/App.php} | 4 ++-- automad/{blocks/block.php => src/Blocks/Block.php} | 0 automad/{blocks/buttons.php => src/Blocks/Buttons.php} | 0 automad/{blocks/code.php => src/Blocks/Code.php} | 0 .../{blocks/delimiter.php => src/Blocks/Delimiter.php} | 0 automad/{blocks/embed.php => src/Blocks/Embed.php} | 0 .../{blocks/filelist.php => src/Blocks/Filelist.php} | 0 automad/{blocks/gallery.php => src/Blocks/Gallery.php} | 0 automad/{blocks/header.php => src/Blocks/Header.php} | 0 automad/{blocks/image.php => src/Blocks/Image.php} | 0 automad/{blocks/lists.php => src/Blocks/Lists.php} | 0 automad/{blocks/mail.php => src/Blocks/Mail.php} | 0 .../{blocks/pagelist.php => src/Blocks/Pagelist.php} | 0 .../{blocks/paragraph.php => src/Blocks/Paragraph.php} | 0 automad/{blocks/quote.php => src/Blocks/Quote.php} | 0 automad/{blocks/raw.php => src/Blocks/Raw.php} | 0 automad/{blocks/section.php => src/Blocks/Section.php} | 0 automad/{blocks/slider.php => src/Blocks/Slider.php} | 0 automad/{blocks/snippet.php => src/Blocks/Snippet.php} | 0 automad/{blocks/table.php => src/Blocks/Table.php} | 0 automad/{blocks/toc.php => src/Blocks/Toc.php} | 0 automad/{core/automad.php => src/Core/Automad.php} | 0 automad/{core/blocks.php => src/Core/Blocks.php} | 2 +- automad/{core/cache.php => src/Core/Cache.php} | 0 automad/{core/config.php => src/Core/Config.php} | 0 automad/{core/context.php => src/Core/Context.php} | 0 automad/{core/debug.php => src/Core/Debug.php} | 0 automad/{core/extension.php => src/Core/Extension.php} | 0 .../{core/filesystem.php => src/Core/FileSystem.php} | 0 automad/{core/filelist.php => src/Core/Filelist.php} | 0 automad/{core/headless.php => src/Core/Headless.php} | 0 automad/{core/image.php => src/Core/Image.php} | 0 automad/{core/page.php => src/Core/Page.php} | 0 automad/{core/pagelist.php => src/Core/Pagelist.php} | 0 automad/{core/parse.php => src/Core/Parse.php} | 0 automad/{core/pipe.php => src/Core/Pipe.php} | 0 automad/{core/regex.php => src/Core/Regex.php} | 0 .../{core/remotefile.php => src/Core/RemoteFile.php} | 0 automad/{core/request.php => src/Core/Request.php} | 0 automad/{core/resolve.php => src/Core/Resolve.php} | 0 automad/{core/runtime.php => src/Core/Runtime.php} | 0 automad/{core/selection.php => src/Core/Selection.php} | 0 .../{core/sessiondata.php => src/Core/SessionData.php} | 0 automad/{core/shared.php => src/Core/Shared.php} | 0 automad/{core/sitemap.php => src/Core/Sitemap.php} | 0 automad/{core/str.php => src/Core/Str.php} | 0 automad/{core/toolbox.php => src/Core/Toolbox.php} | 0 automad/{core/view.php => src/Core/View.php} | 0 .../{system/composer.php => src/System/Composer.php} | 0 automad/{system/mail.php => src/System/Mail.php} | 0 .../{system/packagist.php => src/System/Packagist.php} | 0 automad/{system/update.php => src/System/Update.php} | 0 .../clearcache.php => src/UI/Commands/ClearCache.php} | 0 .../command.php => src/UI/Commands/Command.php} | 0 .../createuser.php => src/UI/Commands/CreateUser.php} | 0 .../commands/purge.php => src/UI/Commands/Purge.php} | 0 .../commands/update.php => src/UI/Commands/Update.php} | 0 .../UI/Components/Accordion/UnusedVariables.php} | 0 .../UI/Components/Accordion/Variables.php} | 0 .../alert.php => src/UI/Components/Alert/Alert.php} | 0 .../danger.php => src/UI/Components/Alert/Danger.php} | 0 .../UI/Components/Alert/Success.php} | 0 .../UI/Components/Alert/ThemeReadme.php} | 0 .../UI/Components/Autocomplete/Jumpbar.php} | 2 +- .../UI/Components/Autocomplete/Link.php} | 0 .../card/file.php => src/UI/Components/Card/File.php} | 0 .../package.php => src/UI/Components/Card/Package.php} | 0 .../card/page.php => src/UI/Components/Card/Page.php} | 0 .../UI/Components/Card/SearchFileResults.php} | 0 .../theme.php => src/UI/Components/Card/Theme.php} | 0 .../card/user.php => src/UI/Components/Card/User.php} | 0 .../UI/Components/Form/CheckboxHidden.php} | 0 .../UI/Components/Form/CheckboxPrivate.php} | 0 .../field.php => src/UI/Components/Form/Field.php} | 0 .../UI/Components/Form/FieldHidden.php} | 0 .../group.php => src/UI/Components/Form/Group.php} | 0 .../UI/Components/Form/HeadlessEditor.php} | 0 .../select.php => src/UI/Components/Form/Select.php} | 0 .../UI/Components/Form/SelectImage.php} | 0 .../UI/Components/Form/SelectTemplate.php} | 0 .../bar.php => src/UI/Components/Fullscreen/Bar.php} | 0 .../files.php => src/UI/Components/Grid/Files.php} | 0 .../UI/Components/Grid/Packages.php} | 0 .../pages.php => src/UI/Components/Grid/Pages.php} | 0 .../users.php => src/UI/Components/Grid/Users.php} | 0 .../UI/Components/Header/BlockSnippetArrays.php} | 0 .../UI/Components/Header/EditorTextModules.php} | 0 .../edit.php => src/UI/Components/InPage/Edit.php} | 0 .../UI/Components/Layout/FileCollection.php} | 0 .../UI/Components/Layout/Packages.php} | 0 .../UI/Components/Layout/PageData.php} | 1 - .../UI/Components/Layout/SearchResults.php} | 0 .../UI/Components/Layout/SelectImage.php} | 0 .../UI/Components/Layout/SharedData.php} | 0 .../UI/Components/Layout/SystemUpdate.php} | 0 .../loading.php => src/UI/Components/Loading.php} | 0 .../components/logo.php => src/UI/Components/Logo.php} | 0 .../about.php => src/UI/Components/Modal/About.php} | 0 .../UI/Components/Modal/AddPage.php} | 0 .../UI/Components/Modal/CopyResized.php} | 0 .../UI/Components/Modal/EditConfig.php} | 0 .../UI/Components/Modal/EditFileInfo.php} | 0 .../import.php => src/UI/Components/Modal/Import.php} | 0 .../link.php => src/UI/Components/Modal/Link.php} | 0 .../readme.php => src/UI/Components/Modal/Readme.php} | 0 .../UI/Components/Modal/SelectImage.php} | 0 .../upload.php => src/UI/Components/Modal/Upload.php} | 0 .../UI/Components/Nav/Breadcrumbs.php} | 0 .../jumpbar.php => src/UI/Components/Nav/Jumpbar.php} | 2 +- .../UI/Components/Nav/SiteTree.php} | 0 .../UI/Components/Nav/Switcher.php} | 0 .../button.php => src/UI/Components/Status/Button.php} | 0 .../UI/Components/Status/Response.php} | 0 .../span.php => src/UI/Components/Status/Span.php} | 0 .../cache.php => src/UI/Components/System/Cache.php} | 0 .../debug.php => src/UI/Components/System/Debug.php} | 0 .../UI/Components/System/Headless.php} | 0 .../UI/Components/System/Language.php} | 0 .../update.php => src/UI/Components/System/Update.php} | 0 .../users.php => src/UI/Components/System/Users.php} | 0 automad/{ui/console.php => src/UI/Console.php} | 2 +- .../accounts.php => src/UI/Controllers/Accounts.php} | 0 .../cache.php => src/UI/Controllers/Cache.php} | 0 .../config.php => src/UI/Controllers/Config.php} | 0 .../file.php => src/UI/Controllers/File.php} | 0 .../UI/Controllers/FileCollection.php} | 0 .../headless.php => src/UI/Controllers/Headless.php} | 0 .../image.php => src/UI/Controllers/Image.php} | 0 .../inpage.php => src/UI/Controllers/InPage.php} | 0 .../UI/Controllers/PackageManager.php} | 0 .../page.php => src/UI/Controllers/Page.php} | 0 .../search.php => src/UI/Controllers/Search.php} | 0 .../shared.php => src/UI/Controllers/Shared.php} | 0 .../status.php => src/UI/Controllers/Status.php} | 0 .../system.php => src/UI/Controllers/System.php} | 0 .../theme.php => src/UI/Controllers/Theme.php} | 0 .../themelist.php => src/UI/Controllers/Themelist.php} | 0 .../controllers/ui.php => src/UI/Controllers/UI.php} | 4 ++-- .../user.php => src/UI/Controllers/User.php} | 0 automad/{ui/dashboard.php => src/UI/Dashboard.php} | 7 ++++--- automad/{ui/inpage.php => src/UI/InPage.php} | 0 .../models/accounts.php => src/UI/Models/Accounts.php} | 0 automad/{ui/models/file.php => src/UI/Models/File.php} | 0 .../UI/Models/FileCollection.php} | 0 .../{ui/models/image.php => src/UI/Models/Image.php} | 0 .../{ui/models/links.php => src/UI/Models/Links.php} | 0 automad/{ui/models/page.php => src/UI/Models/Page.php} | 0 .../replacement.php => src/UI/Models/Replacement.php} | 0 .../{ui/models/search.php => src/UI/Models/Search.php} | 0 .../UI/Models/Search/FieldResults.php} | 0 .../filekeys.php => src/UI/Models/Search/FileKeys.php} | 0 .../UI/Models/Search/FileResults.php} | 0 automad/{ui/response.php => src/UI/Response.php} | 0 .../filesystem.php => src/UI/Utils/FileSystem.php} | 0 automad/{ui/utils/keys.php => src/UI/Utils/Keys.php} | 0 .../{ui/utils/prefix.php => src/UI/Utils/Prefix.php} | 0 automad/{ui/utils/text.php => src/UI/Utils/Text.php} | 0 .../{ui/utils/uicache.php => src/UI/Utils/UICache.php} | 0 .../createuser.php => src/UI/Views/CreateUser.php} | 0 .../navbar.php => src/UI/Views/Elements/Navbar.php} | 4 ++-- .../sidebar.php => src/UI/Views/Elements/Sidebar.php} | 4 ++-- automad/{ui/views/home.php => src/UI/Views/Home.php} | 0 automad/{ui/views/login.php => src/UI/Views/Login.php} | 0 .../{ui/views/logout.php => src/UI/Views/Logout.php} | 0 .../views/packages.php => src/UI/Views/Packages.php} | 0 automad/{ui/views/page.php => src/UI/Views/Page.php} | 0 .../{ui/views/search.php => src/UI/Views/Search.php} | 0 .../{ui/views/shared.php => src/UI/Views/Shared.php} | 0 .../{ui/views/system.php => src/UI/Views/System.php} | 0 automad/{ui/views/view.php => src/UI/Views/View.php} | 0 automad/ui/js/jumpbar.js | 6 +++--- 173 files changed, 27 insertions(+), 23 deletions(-) rename automad/{app.php => src/App.php} (96%) rename automad/{blocks/block.php => src/Blocks/Block.php} (100%) rename automad/{blocks/buttons.php => src/Blocks/Buttons.php} (100%) rename automad/{blocks/code.php => src/Blocks/Code.php} (100%) rename automad/{blocks/delimiter.php => src/Blocks/Delimiter.php} (100%) rename automad/{blocks/embed.php => src/Blocks/Embed.php} (100%) rename automad/{blocks/filelist.php => src/Blocks/Filelist.php} (100%) rename automad/{blocks/gallery.php => src/Blocks/Gallery.php} (100%) rename automad/{blocks/header.php => src/Blocks/Header.php} (100%) rename automad/{blocks/image.php => src/Blocks/Image.php} (100%) rename automad/{blocks/lists.php => src/Blocks/Lists.php} (100%) rename automad/{blocks/mail.php => src/Blocks/Mail.php} (100%) rename automad/{blocks/pagelist.php => src/Blocks/Pagelist.php} (100%) rename automad/{blocks/paragraph.php => src/Blocks/Paragraph.php} (100%) rename automad/{blocks/quote.php => src/Blocks/Quote.php} (100%) rename automad/{blocks/raw.php => src/Blocks/Raw.php} (100%) rename automad/{blocks/section.php => src/Blocks/Section.php} (100%) rename automad/{blocks/slider.php => src/Blocks/Slider.php} (100%) rename automad/{blocks/snippet.php => src/Blocks/Snippet.php} (100%) rename automad/{blocks/table.php => src/Blocks/Table.php} (100%) rename automad/{blocks/toc.php => src/Blocks/Toc.php} (100%) rename automad/{core/automad.php => src/Core/Automad.php} (100%) rename automad/{core/blocks.php => src/Core/Blocks.php} (98%) rename automad/{core/cache.php => src/Core/Cache.php} (100%) rename automad/{core/config.php => src/Core/Config.php} (100%) rename automad/{core/context.php => src/Core/Context.php} (100%) rename automad/{core/debug.php => src/Core/Debug.php} (100%) rename automad/{core/extension.php => src/Core/Extension.php} (100%) rename automad/{core/filesystem.php => src/Core/FileSystem.php} (100%) rename automad/{core/filelist.php => src/Core/Filelist.php} (100%) rename automad/{core/headless.php => src/Core/Headless.php} (100%) rename automad/{core/image.php => src/Core/Image.php} (100%) rename automad/{core/page.php => src/Core/Page.php} (100%) rename automad/{core/pagelist.php => src/Core/Pagelist.php} (100%) rename automad/{core/parse.php => src/Core/Parse.php} (100%) rename automad/{core/pipe.php => src/Core/Pipe.php} (100%) rename automad/{core/regex.php => src/Core/Regex.php} (100%) rename automad/{core/remotefile.php => src/Core/RemoteFile.php} (100%) rename automad/{core/request.php => src/Core/Request.php} (100%) rename automad/{core/resolve.php => src/Core/Resolve.php} (100%) rename automad/{core/runtime.php => src/Core/Runtime.php} (100%) rename automad/{core/selection.php => src/Core/Selection.php} (100%) rename automad/{core/sessiondata.php => src/Core/SessionData.php} (100%) rename automad/{core/shared.php => src/Core/Shared.php} (100%) rename automad/{core/sitemap.php => src/Core/Sitemap.php} (100%) rename automad/{core/str.php => src/Core/Str.php} (100%) rename automad/{core/toolbox.php => src/Core/Toolbox.php} (100%) rename automad/{core/view.php => src/Core/View.php} (100%) rename automad/{system/composer.php => src/System/Composer.php} (100%) rename automad/{system/mail.php => src/System/Mail.php} (100%) rename automad/{system/packagist.php => src/System/Packagist.php} (100%) rename automad/{system/update.php => src/System/Update.php} (100%) rename automad/{ui/commands/clearcache.php => src/UI/Commands/ClearCache.php} (100%) rename automad/{ui/commands/command.php => src/UI/Commands/Command.php} (100%) rename automad/{ui/commands/createuser.php => src/UI/Commands/CreateUser.php} (100%) rename automad/{ui/commands/purge.php => src/UI/Commands/Purge.php} (100%) rename automad/{ui/commands/update.php => src/UI/Commands/Update.php} (100%) rename automad/{ui/components/accordion/unusedvariables.php => src/UI/Components/Accordion/UnusedVariables.php} (100%) rename automad/{ui/components/accordion/variables.php => src/UI/Components/Accordion/Variables.php} (100%) rename automad/{ui/components/alert/alert.php => src/UI/Components/Alert/Alert.php} (100%) rename automad/{ui/components/alert/danger.php => src/UI/Components/Alert/Danger.php} (100%) rename automad/{ui/components/alert/success.php => src/UI/Components/Alert/Success.php} (100%) rename automad/{ui/components/alert/themereadme.php => src/UI/Components/Alert/ThemeReadme.php} (100%) rename automad/{ui/components/autocomplete/jumpbar.php => src/UI/Components/Autocomplete/Jumpbar.php} (99%) rename automad/{ui/components/autocomplete/link.php => src/UI/Components/Autocomplete/Link.php} (100%) rename automad/{ui/components/card/file.php => src/UI/Components/Card/File.php} (100%) rename automad/{ui/components/card/package.php => src/UI/Components/Card/Package.php} (100%) rename automad/{ui/components/card/page.php => src/UI/Components/Card/Page.php} (100%) rename automad/{ui/components/card/searchfileresults.php => src/UI/Components/Card/SearchFileResults.php} (100%) rename automad/{ui/components/card/theme.php => src/UI/Components/Card/Theme.php} (100%) rename automad/{ui/components/card/user.php => src/UI/Components/Card/User.php} (100%) rename automad/{ui/components/form/checkboxhidden.php => src/UI/Components/Form/CheckboxHidden.php} (100%) rename automad/{ui/components/form/checkboxprivate.php => src/UI/Components/Form/CheckboxPrivate.php} (100%) rename automad/{ui/components/form/field.php => src/UI/Components/Form/Field.php} (100%) rename automad/{ui/components/form/fieldhidden.php => src/UI/Components/Form/FieldHidden.php} (100%) rename automad/{ui/components/form/group.php => src/UI/Components/Form/Group.php} (100%) rename automad/{ui/components/form/headlesseditor.php => src/UI/Components/Form/HeadlessEditor.php} (100%) rename automad/{ui/components/form/select.php => src/UI/Components/Form/Select.php} (100%) rename automad/{ui/components/form/selectimage.php => src/UI/Components/Form/SelectImage.php} (100%) rename automad/{ui/components/form/selecttemplate.php => src/UI/Components/Form/SelectTemplate.php} (100%) rename automad/{ui/components/fullscreen/bar.php => src/UI/Components/Fullscreen/Bar.php} (100%) rename automad/{ui/components/grid/files.php => src/UI/Components/Grid/Files.php} (100%) rename automad/{ui/components/grid/packages.php => src/UI/Components/Grid/Packages.php} (100%) rename automad/{ui/components/grid/pages.php => src/UI/Components/Grid/Pages.php} (100%) rename automad/{ui/components/grid/users.php => src/UI/Components/Grid/Users.php} (100%) rename automad/{ui/components/header/blocksnippetarrays.php => src/UI/Components/Header/BlockSnippetArrays.php} (100%) rename automad/{ui/components/header/editortextmodules.php => src/UI/Components/Header/EditorTextModules.php} (100%) rename automad/{ui/components/inpage/edit.php => src/UI/Components/InPage/Edit.php} (100%) rename automad/{ui/components/layout/filecollection.php => src/UI/Components/Layout/FileCollection.php} (100%) rename automad/{ui/components/layout/packages.php => src/UI/Components/Layout/Packages.php} (100%) rename automad/{ui/components/layout/pagedata.php => src/UI/Components/Layout/PageData.php} (99%) rename automad/{ui/components/layout/searchresults.php => src/UI/Components/Layout/SearchResults.php} (100%) rename automad/{ui/components/layout/selectimage.php => src/UI/Components/Layout/SelectImage.php} (100%) rename automad/{ui/components/layout/shareddata.php => src/UI/Components/Layout/SharedData.php} (100%) rename automad/{ui/components/layout/systemupdate.php => src/UI/Components/Layout/SystemUpdate.php} (100%) rename automad/{ui/components/loading.php => src/UI/Components/Loading.php} (100%) rename automad/{ui/components/logo.php => src/UI/Components/Logo.php} (100%) rename automad/{ui/components/modal/about.php => src/UI/Components/Modal/About.php} (100%) rename automad/{ui/components/modal/addpage.php => src/UI/Components/Modal/AddPage.php} (100%) rename automad/{ui/components/modal/copyresized.php => src/UI/Components/Modal/CopyResized.php} (100%) rename automad/{ui/components/modal/editconfig.php => src/UI/Components/Modal/EditConfig.php} (100%) rename automad/{ui/components/modal/editfileinfo.php => src/UI/Components/Modal/EditFileInfo.php} (100%) rename automad/{ui/components/modal/import.php => src/UI/Components/Modal/Import.php} (100%) rename automad/{ui/components/modal/link.php => src/UI/Components/Modal/Link.php} (100%) rename automad/{ui/components/modal/readme.php => src/UI/Components/Modal/Readme.php} (100%) rename automad/{ui/components/modal/selectimage.php => src/UI/Components/Modal/SelectImage.php} (100%) rename automad/{ui/components/modal/upload.php => src/UI/Components/Modal/Upload.php} (100%) rename automad/{ui/components/nav/breadcrumbs.php => src/UI/Components/Nav/Breadcrumbs.php} (100%) rename automad/{ui/components/nav/jumpbar.php => src/UI/Components/Nav/Jumpbar.php} (99%) rename automad/{ui/components/nav/sitetree.php => src/UI/Components/Nav/SiteTree.php} (100%) rename automad/{ui/components/nav/switcher.php => src/UI/Components/Nav/Switcher.php} (100%) rename automad/{ui/components/status/button.php => src/UI/Components/Status/Button.php} (100%) rename automad/{ui/components/status/response.php => src/UI/Components/Status/Response.php} (100%) rename automad/{ui/components/status/span.php => src/UI/Components/Status/Span.php} (100%) rename automad/{ui/components/system/cache.php => src/UI/Components/System/Cache.php} (100%) rename automad/{ui/components/system/debug.php => src/UI/Components/System/Debug.php} (100%) rename automad/{ui/components/system/headless.php => src/UI/Components/System/Headless.php} (100%) rename automad/{ui/components/system/language.php => src/UI/Components/System/Language.php} (100%) rename automad/{ui/components/system/update.php => src/UI/Components/System/Update.php} (100%) rename automad/{ui/components/system/users.php => src/UI/Components/System/Users.php} (100%) rename automad/{ui/console.php => src/UI/Console.php} (97%) rename automad/{ui/controllers/accounts.php => src/UI/Controllers/Accounts.php} (100%) rename automad/{ui/controllers/cache.php => src/UI/Controllers/Cache.php} (100%) rename automad/{ui/controllers/config.php => src/UI/Controllers/Config.php} (100%) rename automad/{ui/controllers/file.php => src/UI/Controllers/File.php} (100%) rename automad/{ui/controllers/filecollection.php => src/UI/Controllers/FileCollection.php} (100%) rename automad/{ui/controllers/headless.php => src/UI/Controllers/Headless.php} (100%) rename automad/{ui/controllers/image.php => src/UI/Controllers/Image.php} (100%) rename automad/{ui/controllers/inpage.php => src/UI/Controllers/InPage.php} (100%) rename automad/{ui/controllers/packagemanager.php => src/UI/Controllers/PackageManager.php} (100%) rename automad/{ui/controllers/page.php => src/UI/Controllers/Page.php} (100%) rename automad/{ui/controllers/search.php => src/UI/Controllers/Search.php} (100%) rename automad/{ui/controllers/shared.php => src/UI/Controllers/Shared.php} (100%) rename automad/{ui/controllers/status.php => src/UI/Controllers/Status.php} (100%) rename automad/{ui/controllers/system.php => src/UI/Controllers/System.php} (100%) rename automad/{ui/controllers/theme.php => src/UI/Controllers/Theme.php} (100%) rename automad/{ui/controllers/themelist.php => src/UI/Controllers/Themelist.php} (100%) rename automad/{ui/controllers/ui.php => src/UI/Controllers/UI.php} (96%) rename automad/{ui/controllers/user.php => src/UI/Controllers/User.php} (100%) rename automad/{ui/dashboard.php => src/UI/Dashboard.php} (95%) rename automad/{ui/inpage.php => src/UI/InPage.php} (100%) rename automad/{ui/models/accounts.php => src/UI/Models/Accounts.php} (100%) rename automad/{ui/models/file.php => src/UI/Models/File.php} (100%) rename automad/{ui/models/filecollection.php => src/UI/Models/FileCollection.php} (100%) rename automad/{ui/models/image.php => src/UI/Models/Image.php} (100%) rename automad/{ui/models/links.php => src/UI/Models/Links.php} (100%) rename automad/{ui/models/page.php => src/UI/Models/Page.php} (100%) rename automad/{ui/models/replacement.php => src/UI/Models/Replacement.php} (100%) rename automad/{ui/models/search.php => src/UI/Models/Search.php} (100%) rename automad/{ui/models/search/fieldresults.php => src/UI/Models/Search/FieldResults.php} (100%) rename automad/{ui/models/search/filekeys.php => src/UI/Models/Search/FileKeys.php} (100%) rename automad/{ui/models/search/fileresults.php => src/UI/Models/Search/FileResults.php} (100%) rename automad/{ui/response.php => src/UI/Response.php} (100%) rename automad/{ui/utils/filesystem.php => src/UI/Utils/FileSystem.php} (100%) rename automad/{ui/utils/keys.php => src/UI/Utils/Keys.php} (100%) rename automad/{ui/utils/prefix.php => src/UI/Utils/Prefix.php} (100%) rename automad/{ui/utils/text.php => src/UI/Utils/Text.php} (100%) rename automad/{ui/utils/uicache.php => src/UI/Utils/UICache.php} (100%) rename automad/{ui/views/createuser.php => src/UI/Views/CreateUser.php} (100%) rename automad/{ui/views/elements/navbar.php => src/UI/Views/Elements/Navbar.php} (97%) rename automad/{ui/views/elements/sidebar.php => src/UI/Views/Elements/Sidebar.php} (98%) rename automad/{ui/views/home.php => src/UI/Views/Home.php} (100%) rename automad/{ui/views/login.php => src/UI/Views/Login.php} (100%) rename automad/{ui/views/logout.php => src/UI/Views/Logout.php} (100%) rename automad/{ui/views/packages.php => src/UI/Views/Packages.php} (100%) rename automad/{ui/views/page.php => src/UI/Views/Page.php} (100%) rename automad/{ui/views/search.php => src/UI/Views/Search.php} (100%) rename automad/{ui/views/shared.php => src/UI/Views/Shared.php} (100%) rename automad/{ui/views/system.php => src/UI/Views/System.php} (100%) rename automad/{ui/views/view.php => src/UI/Views/View.php} (100%) diff --git a/automad/autoload.php b/automad/autoload.php index b5648888f..72ae8d199 100644 --- a/automad/autoload.php +++ b/automad/autoload.php @@ -48,9 +48,13 @@ // Automad. spl_autoload_register(function ($class) { - $file = strtolower(str_replace('\\', '/', $class)) . '.php'; + $prefix = 'Automad\\'; - if (strpos($file, 'automad') === 0 && strpos($file, 'automad/composer') === false) { - require_once AM_BASE_DIR . '/' . $file; + if (strpos($class, $prefix) === 0) { + $file = AM_BASE_DIR . '/automad/src/' . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php'; + + if (file_exists($file)) { + require_once $file; + } } }); diff --git a/automad/init.php b/automad/init.php index 38685b004..4525bcb4b 100644 --- a/automad/init.php +++ b/automad/init.php @@ -36,5 +36,5 @@ defined('AUTOMAD') or die('Direct access not permitted!'); -require_once __DIR__ . '/app.php'; +require_once __DIR__ . '/src/App.php'; new Automad\App(); diff --git a/automad/app.php b/automad/src/App.php similarity index 96% rename from automad/app.php rename to automad/src/App.php index 7a0de346b..e1fb559ad 100644 --- a/automad/app.php +++ b/automad/src/App.php @@ -70,8 +70,8 @@ public function __construct() { $this->runVersionCheck(); date_default_timezone_set(@date_default_timezone_get()); - require_once __DIR__ . '/core/filesystem.php'; - define('AM_BASE_DIR', FileSystem::normalizeSlashes(dirname(__DIR__))); + require_once __DIR__ . '/Core/FileSystem.php'; + define('AM_BASE_DIR', FileSystem::normalizeSlashes(dirname(dirname(__DIR__)))); require AM_BASE_DIR . '/automad/autoload.php'; require AM_BASE_DIR . '/automad/const.php'; diff --git a/automad/blocks/block.php b/automad/src/Blocks/Block.php similarity index 100% rename from automad/blocks/block.php rename to automad/src/Blocks/Block.php diff --git a/automad/blocks/buttons.php b/automad/src/Blocks/Buttons.php similarity index 100% rename from automad/blocks/buttons.php rename to automad/src/Blocks/Buttons.php diff --git a/automad/blocks/code.php b/automad/src/Blocks/Code.php similarity index 100% rename from automad/blocks/code.php rename to automad/src/Blocks/Code.php diff --git a/automad/blocks/delimiter.php b/automad/src/Blocks/Delimiter.php similarity index 100% rename from automad/blocks/delimiter.php rename to automad/src/Blocks/Delimiter.php diff --git a/automad/blocks/embed.php b/automad/src/Blocks/Embed.php similarity index 100% rename from automad/blocks/embed.php rename to automad/src/Blocks/Embed.php diff --git a/automad/blocks/filelist.php b/automad/src/Blocks/Filelist.php similarity index 100% rename from automad/blocks/filelist.php rename to automad/src/Blocks/Filelist.php diff --git a/automad/blocks/gallery.php b/automad/src/Blocks/Gallery.php similarity index 100% rename from automad/blocks/gallery.php rename to automad/src/Blocks/Gallery.php diff --git a/automad/blocks/header.php b/automad/src/Blocks/Header.php similarity index 100% rename from automad/blocks/header.php rename to automad/src/Blocks/Header.php diff --git a/automad/blocks/image.php b/automad/src/Blocks/Image.php similarity index 100% rename from automad/blocks/image.php rename to automad/src/Blocks/Image.php diff --git a/automad/blocks/lists.php b/automad/src/Blocks/Lists.php similarity index 100% rename from automad/blocks/lists.php rename to automad/src/Blocks/Lists.php diff --git a/automad/blocks/mail.php b/automad/src/Blocks/Mail.php similarity index 100% rename from automad/blocks/mail.php rename to automad/src/Blocks/Mail.php diff --git a/automad/blocks/pagelist.php b/automad/src/Blocks/Pagelist.php similarity index 100% rename from automad/blocks/pagelist.php rename to automad/src/Blocks/Pagelist.php diff --git a/automad/blocks/paragraph.php b/automad/src/Blocks/Paragraph.php similarity index 100% rename from automad/blocks/paragraph.php rename to automad/src/Blocks/Paragraph.php diff --git a/automad/blocks/quote.php b/automad/src/Blocks/Quote.php similarity index 100% rename from automad/blocks/quote.php rename to automad/src/Blocks/Quote.php diff --git a/automad/blocks/raw.php b/automad/src/Blocks/Raw.php similarity index 100% rename from automad/blocks/raw.php rename to automad/src/Blocks/Raw.php diff --git a/automad/blocks/section.php b/automad/src/Blocks/Section.php similarity index 100% rename from automad/blocks/section.php rename to automad/src/Blocks/Section.php diff --git a/automad/blocks/slider.php b/automad/src/Blocks/Slider.php similarity index 100% rename from automad/blocks/slider.php rename to automad/src/Blocks/Slider.php diff --git a/automad/blocks/snippet.php b/automad/src/Blocks/Snippet.php similarity index 100% rename from automad/blocks/snippet.php rename to automad/src/Blocks/Snippet.php diff --git a/automad/blocks/table.php b/automad/src/Blocks/Table.php similarity index 100% rename from automad/blocks/table.php rename to automad/src/Blocks/Table.php diff --git a/automad/blocks/toc.php b/automad/src/Blocks/Toc.php similarity index 100% rename from automad/blocks/toc.php rename to automad/src/Blocks/Toc.php diff --git a/automad/core/automad.php b/automad/src/Core/Automad.php similarity index 100% rename from automad/core/automad.php rename to automad/src/Core/Automad.php diff --git a/automad/core/blocks.php b/automad/src/Core/Blocks.php similarity index 98% rename from automad/core/blocks.php rename to automad/src/Core/Blocks.php index 130299b2a..bbb08baa9 100644 --- a/automad/core/blocks.php +++ b/automad/src/Core/Blocks.php @@ -110,7 +110,7 @@ public static function render($json, $Automad) { } $blockHtml = call_user_func_array( - '\\Automad\\Blocks\\' . $block->type . '::render', + '\\Automad\\Blocks\\' . ucfirst($block->type) . '::render', array($block->data, $Automad) ); diff --git a/automad/core/cache.php b/automad/src/Core/Cache.php similarity index 100% rename from automad/core/cache.php rename to automad/src/Core/Cache.php diff --git a/automad/core/config.php b/automad/src/Core/Config.php similarity index 100% rename from automad/core/config.php rename to automad/src/Core/Config.php diff --git a/automad/core/context.php b/automad/src/Core/Context.php similarity index 100% rename from automad/core/context.php rename to automad/src/Core/Context.php diff --git a/automad/core/debug.php b/automad/src/Core/Debug.php similarity index 100% rename from automad/core/debug.php rename to automad/src/Core/Debug.php diff --git a/automad/core/extension.php b/automad/src/Core/Extension.php similarity index 100% rename from automad/core/extension.php rename to automad/src/Core/Extension.php diff --git a/automad/core/filesystem.php b/automad/src/Core/FileSystem.php similarity index 100% rename from automad/core/filesystem.php rename to automad/src/Core/FileSystem.php diff --git a/automad/core/filelist.php b/automad/src/Core/Filelist.php similarity index 100% rename from automad/core/filelist.php rename to automad/src/Core/Filelist.php diff --git a/automad/core/headless.php b/automad/src/Core/Headless.php similarity index 100% rename from automad/core/headless.php rename to automad/src/Core/Headless.php diff --git a/automad/core/image.php b/automad/src/Core/Image.php similarity index 100% rename from automad/core/image.php rename to automad/src/Core/Image.php diff --git a/automad/core/page.php b/automad/src/Core/Page.php similarity index 100% rename from automad/core/page.php rename to automad/src/Core/Page.php diff --git a/automad/core/pagelist.php b/automad/src/Core/Pagelist.php similarity index 100% rename from automad/core/pagelist.php rename to automad/src/Core/Pagelist.php diff --git a/automad/core/parse.php b/automad/src/Core/Parse.php similarity index 100% rename from automad/core/parse.php rename to automad/src/Core/Parse.php diff --git a/automad/core/pipe.php b/automad/src/Core/Pipe.php similarity index 100% rename from automad/core/pipe.php rename to automad/src/Core/Pipe.php diff --git a/automad/core/regex.php b/automad/src/Core/Regex.php similarity index 100% rename from automad/core/regex.php rename to automad/src/Core/Regex.php diff --git a/automad/core/remotefile.php b/automad/src/Core/RemoteFile.php similarity index 100% rename from automad/core/remotefile.php rename to automad/src/Core/RemoteFile.php diff --git a/automad/core/request.php b/automad/src/Core/Request.php similarity index 100% rename from automad/core/request.php rename to automad/src/Core/Request.php diff --git a/automad/core/resolve.php b/automad/src/Core/Resolve.php similarity index 100% rename from automad/core/resolve.php rename to automad/src/Core/Resolve.php diff --git a/automad/core/runtime.php b/automad/src/Core/Runtime.php similarity index 100% rename from automad/core/runtime.php rename to automad/src/Core/Runtime.php diff --git a/automad/core/selection.php b/automad/src/Core/Selection.php similarity index 100% rename from automad/core/selection.php rename to automad/src/Core/Selection.php diff --git a/automad/core/sessiondata.php b/automad/src/Core/SessionData.php similarity index 100% rename from automad/core/sessiondata.php rename to automad/src/Core/SessionData.php diff --git a/automad/core/shared.php b/automad/src/Core/Shared.php similarity index 100% rename from automad/core/shared.php rename to automad/src/Core/Shared.php diff --git a/automad/core/sitemap.php b/automad/src/Core/Sitemap.php similarity index 100% rename from automad/core/sitemap.php rename to automad/src/Core/Sitemap.php diff --git a/automad/core/str.php b/automad/src/Core/Str.php similarity index 100% rename from automad/core/str.php rename to automad/src/Core/Str.php diff --git a/automad/core/toolbox.php b/automad/src/Core/Toolbox.php similarity index 100% rename from automad/core/toolbox.php rename to automad/src/Core/Toolbox.php diff --git a/automad/core/view.php b/automad/src/Core/View.php similarity index 100% rename from automad/core/view.php rename to automad/src/Core/View.php diff --git a/automad/system/composer.php b/automad/src/System/Composer.php similarity index 100% rename from automad/system/composer.php rename to automad/src/System/Composer.php diff --git a/automad/system/mail.php b/automad/src/System/Mail.php similarity index 100% rename from automad/system/mail.php rename to automad/src/System/Mail.php diff --git a/automad/system/packagist.php b/automad/src/System/Packagist.php similarity index 100% rename from automad/system/packagist.php rename to automad/src/System/Packagist.php diff --git a/automad/system/update.php b/automad/src/System/Update.php similarity index 100% rename from automad/system/update.php rename to automad/src/System/Update.php diff --git a/automad/ui/commands/clearcache.php b/automad/src/UI/Commands/ClearCache.php similarity index 100% rename from automad/ui/commands/clearcache.php rename to automad/src/UI/Commands/ClearCache.php diff --git a/automad/ui/commands/command.php b/automad/src/UI/Commands/Command.php similarity index 100% rename from automad/ui/commands/command.php rename to automad/src/UI/Commands/Command.php diff --git a/automad/ui/commands/createuser.php b/automad/src/UI/Commands/CreateUser.php similarity index 100% rename from automad/ui/commands/createuser.php rename to automad/src/UI/Commands/CreateUser.php diff --git a/automad/ui/commands/purge.php b/automad/src/UI/Commands/Purge.php similarity index 100% rename from automad/ui/commands/purge.php rename to automad/src/UI/Commands/Purge.php diff --git a/automad/ui/commands/update.php b/automad/src/UI/Commands/Update.php similarity index 100% rename from automad/ui/commands/update.php rename to automad/src/UI/Commands/Update.php diff --git a/automad/ui/components/accordion/unusedvariables.php b/automad/src/UI/Components/Accordion/UnusedVariables.php similarity index 100% rename from automad/ui/components/accordion/unusedvariables.php rename to automad/src/UI/Components/Accordion/UnusedVariables.php diff --git a/automad/ui/components/accordion/variables.php b/automad/src/UI/Components/Accordion/Variables.php similarity index 100% rename from automad/ui/components/accordion/variables.php rename to automad/src/UI/Components/Accordion/Variables.php diff --git a/automad/ui/components/alert/alert.php b/automad/src/UI/Components/Alert/Alert.php similarity index 100% rename from automad/ui/components/alert/alert.php rename to automad/src/UI/Components/Alert/Alert.php diff --git a/automad/ui/components/alert/danger.php b/automad/src/UI/Components/Alert/Danger.php similarity index 100% rename from automad/ui/components/alert/danger.php rename to automad/src/UI/Components/Alert/Danger.php diff --git a/automad/ui/components/alert/success.php b/automad/src/UI/Components/Alert/Success.php similarity index 100% rename from automad/ui/components/alert/success.php rename to automad/src/UI/Components/Alert/Success.php diff --git a/automad/ui/components/alert/themereadme.php b/automad/src/UI/Components/Alert/ThemeReadme.php similarity index 100% rename from automad/ui/components/alert/themereadme.php rename to automad/src/UI/Components/Alert/ThemeReadme.php diff --git a/automad/ui/components/autocomplete/jumpbar.php b/automad/src/UI/Components/Autocomplete/Jumpbar.php similarity index 99% rename from automad/ui/components/autocomplete/jumpbar.php rename to automad/src/UI/Components/Autocomplete/Jumpbar.php index 60b03664f..d325303a9 100644 --- a/automad/ui/components/autocomplete/jumpbar.php +++ b/automad/src/UI/Components/Autocomplete/Jumpbar.php @@ -50,7 +50,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class JumpBar { +class Jumpbar { /** * Return a JSON formatted string to be used as autocomplete infomation in a jump field. * diff --git a/automad/ui/components/autocomplete/link.php b/automad/src/UI/Components/Autocomplete/Link.php similarity index 100% rename from automad/ui/components/autocomplete/link.php rename to automad/src/UI/Components/Autocomplete/Link.php diff --git a/automad/ui/components/card/file.php b/automad/src/UI/Components/Card/File.php similarity index 100% rename from automad/ui/components/card/file.php rename to automad/src/UI/Components/Card/File.php diff --git a/automad/ui/components/card/package.php b/automad/src/UI/Components/Card/Package.php similarity index 100% rename from automad/ui/components/card/package.php rename to automad/src/UI/Components/Card/Package.php diff --git a/automad/ui/components/card/page.php b/automad/src/UI/Components/Card/Page.php similarity index 100% rename from automad/ui/components/card/page.php rename to automad/src/UI/Components/Card/Page.php diff --git a/automad/ui/components/card/searchfileresults.php b/automad/src/UI/Components/Card/SearchFileResults.php similarity index 100% rename from automad/ui/components/card/searchfileresults.php rename to automad/src/UI/Components/Card/SearchFileResults.php diff --git a/automad/ui/components/card/theme.php b/automad/src/UI/Components/Card/Theme.php similarity index 100% rename from automad/ui/components/card/theme.php rename to automad/src/UI/Components/Card/Theme.php diff --git a/automad/ui/components/card/user.php b/automad/src/UI/Components/Card/User.php similarity index 100% rename from automad/ui/components/card/user.php rename to automad/src/UI/Components/Card/User.php diff --git a/automad/ui/components/form/checkboxhidden.php b/automad/src/UI/Components/Form/CheckboxHidden.php similarity index 100% rename from automad/ui/components/form/checkboxhidden.php rename to automad/src/UI/Components/Form/CheckboxHidden.php diff --git a/automad/ui/components/form/checkboxprivate.php b/automad/src/UI/Components/Form/CheckboxPrivate.php similarity index 100% rename from automad/ui/components/form/checkboxprivate.php rename to automad/src/UI/Components/Form/CheckboxPrivate.php diff --git a/automad/ui/components/form/field.php b/automad/src/UI/Components/Form/Field.php similarity index 100% rename from automad/ui/components/form/field.php rename to automad/src/UI/Components/Form/Field.php diff --git a/automad/ui/components/form/fieldhidden.php b/automad/src/UI/Components/Form/FieldHidden.php similarity index 100% rename from automad/ui/components/form/fieldhidden.php rename to automad/src/UI/Components/Form/FieldHidden.php diff --git a/automad/ui/components/form/group.php b/automad/src/UI/Components/Form/Group.php similarity index 100% rename from automad/ui/components/form/group.php rename to automad/src/UI/Components/Form/Group.php diff --git a/automad/ui/components/form/headlesseditor.php b/automad/src/UI/Components/Form/HeadlessEditor.php similarity index 100% rename from automad/ui/components/form/headlesseditor.php rename to automad/src/UI/Components/Form/HeadlessEditor.php diff --git a/automad/ui/components/form/select.php b/automad/src/UI/Components/Form/Select.php similarity index 100% rename from automad/ui/components/form/select.php rename to automad/src/UI/Components/Form/Select.php diff --git a/automad/ui/components/form/selectimage.php b/automad/src/UI/Components/Form/SelectImage.php similarity index 100% rename from automad/ui/components/form/selectimage.php rename to automad/src/UI/Components/Form/SelectImage.php diff --git a/automad/ui/components/form/selecttemplate.php b/automad/src/UI/Components/Form/SelectTemplate.php similarity index 100% rename from automad/ui/components/form/selecttemplate.php rename to automad/src/UI/Components/Form/SelectTemplate.php diff --git a/automad/ui/components/fullscreen/bar.php b/automad/src/UI/Components/Fullscreen/Bar.php similarity index 100% rename from automad/ui/components/fullscreen/bar.php rename to automad/src/UI/Components/Fullscreen/Bar.php diff --git a/automad/ui/components/grid/files.php b/automad/src/UI/Components/Grid/Files.php similarity index 100% rename from automad/ui/components/grid/files.php rename to automad/src/UI/Components/Grid/Files.php diff --git a/automad/ui/components/grid/packages.php b/automad/src/UI/Components/Grid/Packages.php similarity index 100% rename from automad/ui/components/grid/packages.php rename to automad/src/UI/Components/Grid/Packages.php diff --git a/automad/ui/components/grid/pages.php b/automad/src/UI/Components/Grid/Pages.php similarity index 100% rename from automad/ui/components/grid/pages.php rename to automad/src/UI/Components/Grid/Pages.php diff --git a/automad/ui/components/grid/users.php b/automad/src/UI/Components/Grid/Users.php similarity index 100% rename from automad/ui/components/grid/users.php rename to automad/src/UI/Components/Grid/Users.php diff --git a/automad/ui/components/header/blocksnippetarrays.php b/automad/src/UI/Components/Header/BlockSnippetArrays.php similarity index 100% rename from automad/ui/components/header/blocksnippetarrays.php rename to automad/src/UI/Components/Header/BlockSnippetArrays.php diff --git a/automad/ui/components/header/editortextmodules.php b/automad/src/UI/Components/Header/EditorTextModules.php similarity index 100% rename from automad/ui/components/header/editortextmodules.php rename to automad/src/UI/Components/Header/EditorTextModules.php diff --git a/automad/ui/components/inpage/edit.php b/automad/src/UI/Components/InPage/Edit.php similarity index 100% rename from automad/ui/components/inpage/edit.php rename to automad/src/UI/Components/InPage/Edit.php diff --git a/automad/ui/components/layout/filecollection.php b/automad/src/UI/Components/Layout/FileCollection.php similarity index 100% rename from automad/ui/components/layout/filecollection.php rename to automad/src/UI/Components/Layout/FileCollection.php diff --git a/automad/ui/components/layout/packages.php b/automad/src/UI/Components/Layout/Packages.php similarity index 100% rename from automad/ui/components/layout/packages.php rename to automad/src/UI/Components/Layout/Packages.php diff --git a/automad/ui/components/layout/pagedata.php b/automad/src/UI/Components/Layout/PageData.php similarity index 99% rename from automad/ui/components/layout/pagedata.php rename to automad/src/UI/Components/Layout/PageData.php index b394f30b7..1a9be631f 100644 --- a/automad/ui/components/layout/pagedata.php +++ b/automad/src/UI/Components/Layout/PageData.php @@ -38,7 +38,6 @@ use Automad\Core\Headless; use Automad\Core\Parse; -use Automad\Core\Str; use Automad\UI\Components\Accordion\UnusedVariables; use Automad\UI\Components\Accordion\Variables; use Automad\UI\Components\Alert\ThemeReadme; diff --git a/automad/ui/components/layout/searchresults.php b/automad/src/UI/Components/Layout/SearchResults.php similarity index 100% rename from automad/ui/components/layout/searchresults.php rename to automad/src/UI/Components/Layout/SearchResults.php diff --git a/automad/ui/components/layout/selectimage.php b/automad/src/UI/Components/Layout/SelectImage.php similarity index 100% rename from automad/ui/components/layout/selectimage.php rename to automad/src/UI/Components/Layout/SelectImage.php diff --git a/automad/ui/components/layout/shareddata.php b/automad/src/UI/Components/Layout/SharedData.php similarity index 100% rename from automad/ui/components/layout/shareddata.php rename to automad/src/UI/Components/Layout/SharedData.php diff --git a/automad/ui/components/layout/systemupdate.php b/automad/src/UI/Components/Layout/SystemUpdate.php similarity index 100% rename from automad/ui/components/layout/systemupdate.php rename to automad/src/UI/Components/Layout/SystemUpdate.php diff --git a/automad/ui/components/loading.php b/automad/src/UI/Components/Loading.php similarity index 100% rename from automad/ui/components/loading.php rename to automad/src/UI/Components/Loading.php diff --git a/automad/ui/components/logo.php b/automad/src/UI/Components/Logo.php similarity index 100% rename from automad/ui/components/logo.php rename to automad/src/UI/Components/Logo.php diff --git a/automad/ui/components/modal/about.php b/automad/src/UI/Components/Modal/About.php similarity index 100% rename from automad/ui/components/modal/about.php rename to automad/src/UI/Components/Modal/About.php diff --git a/automad/ui/components/modal/addpage.php b/automad/src/UI/Components/Modal/AddPage.php similarity index 100% rename from automad/ui/components/modal/addpage.php rename to automad/src/UI/Components/Modal/AddPage.php diff --git a/automad/ui/components/modal/copyresized.php b/automad/src/UI/Components/Modal/CopyResized.php similarity index 100% rename from automad/ui/components/modal/copyresized.php rename to automad/src/UI/Components/Modal/CopyResized.php diff --git a/automad/ui/components/modal/editconfig.php b/automad/src/UI/Components/Modal/EditConfig.php similarity index 100% rename from automad/ui/components/modal/editconfig.php rename to automad/src/UI/Components/Modal/EditConfig.php diff --git a/automad/ui/components/modal/editfileinfo.php b/automad/src/UI/Components/Modal/EditFileInfo.php similarity index 100% rename from automad/ui/components/modal/editfileinfo.php rename to automad/src/UI/Components/Modal/EditFileInfo.php diff --git a/automad/ui/components/modal/import.php b/automad/src/UI/Components/Modal/Import.php similarity index 100% rename from automad/ui/components/modal/import.php rename to automad/src/UI/Components/Modal/Import.php diff --git a/automad/ui/components/modal/link.php b/automad/src/UI/Components/Modal/Link.php similarity index 100% rename from automad/ui/components/modal/link.php rename to automad/src/UI/Components/Modal/Link.php diff --git a/automad/ui/components/modal/readme.php b/automad/src/UI/Components/Modal/Readme.php similarity index 100% rename from automad/ui/components/modal/readme.php rename to automad/src/UI/Components/Modal/Readme.php diff --git a/automad/ui/components/modal/selectimage.php b/automad/src/UI/Components/Modal/SelectImage.php similarity index 100% rename from automad/ui/components/modal/selectimage.php rename to automad/src/UI/Components/Modal/SelectImage.php diff --git a/automad/ui/components/modal/upload.php b/automad/src/UI/Components/Modal/Upload.php similarity index 100% rename from automad/ui/components/modal/upload.php rename to automad/src/UI/Components/Modal/Upload.php diff --git a/automad/ui/components/nav/breadcrumbs.php b/automad/src/UI/Components/Nav/Breadcrumbs.php similarity index 100% rename from automad/ui/components/nav/breadcrumbs.php rename to automad/src/UI/Components/Nav/Breadcrumbs.php diff --git a/automad/ui/components/nav/jumpbar.php b/automad/src/UI/Components/Nav/Jumpbar.php similarity index 99% rename from automad/ui/components/nav/jumpbar.php rename to automad/src/UI/Components/Nav/Jumpbar.php index b0febdb15..6d6084721 100644 --- a/automad/ui/components/nav/jumpbar.php +++ b/automad/src/UI/Components/Nav/Jumpbar.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class JumpBar { +class Jumpbar { /** * Create a jump bar field. * diff --git a/automad/ui/components/nav/sitetree.php b/automad/src/UI/Components/Nav/SiteTree.php similarity index 100% rename from automad/ui/components/nav/sitetree.php rename to automad/src/UI/Components/Nav/SiteTree.php diff --git a/automad/ui/components/nav/switcher.php b/automad/src/UI/Components/Nav/Switcher.php similarity index 100% rename from automad/ui/components/nav/switcher.php rename to automad/src/UI/Components/Nav/Switcher.php diff --git a/automad/ui/components/status/button.php b/automad/src/UI/Components/Status/Button.php similarity index 100% rename from automad/ui/components/status/button.php rename to automad/src/UI/Components/Status/Button.php diff --git a/automad/ui/components/status/response.php b/automad/src/UI/Components/Status/Response.php similarity index 100% rename from automad/ui/components/status/response.php rename to automad/src/UI/Components/Status/Response.php diff --git a/automad/ui/components/status/span.php b/automad/src/UI/Components/Status/Span.php similarity index 100% rename from automad/ui/components/status/span.php rename to automad/src/UI/Components/Status/Span.php diff --git a/automad/ui/components/system/cache.php b/automad/src/UI/Components/System/Cache.php similarity index 100% rename from automad/ui/components/system/cache.php rename to automad/src/UI/Components/System/Cache.php diff --git a/automad/ui/components/system/debug.php b/automad/src/UI/Components/System/Debug.php similarity index 100% rename from automad/ui/components/system/debug.php rename to automad/src/UI/Components/System/Debug.php diff --git a/automad/ui/components/system/headless.php b/automad/src/UI/Components/System/Headless.php similarity index 100% rename from automad/ui/components/system/headless.php rename to automad/src/UI/Components/System/Headless.php diff --git a/automad/ui/components/system/language.php b/automad/src/UI/Components/System/Language.php similarity index 100% rename from automad/ui/components/system/language.php rename to automad/src/UI/Components/System/Language.php diff --git a/automad/ui/components/system/update.php b/automad/src/UI/Components/System/Update.php similarity index 100% rename from automad/ui/components/system/update.php rename to automad/src/UI/Components/System/Update.php diff --git a/automad/ui/components/system/users.php b/automad/src/UI/Components/System/Users.php similarity index 100% rename from automad/ui/components/system/users.php rename to automad/src/UI/Components/System/Users.php diff --git a/automad/ui/console.php b/automad/src/UI/Console.php similarity index 97% rename from automad/ui/console.php rename to automad/src/UI/Console.php index c602bea2f..fb3bb7365 100644 --- a/automad/ui/console.php +++ b/automad/src/UI/Console.php @@ -65,7 +65,7 @@ public function __construct($argv) { * @return array the list of command objects */ private function getCommands() { - $files = FileSystem::glob(AM_BASE_DIR . '/automad/ui/commands/*.php'); + $files = FileSystem::glob(AM_BASE_DIR . '/automad/src/UI/Commands/*.php'); foreach ($files as $file) { require_once $file; diff --git a/automad/ui/controllers/accounts.php b/automad/src/UI/Controllers/Accounts.php similarity index 100% rename from automad/ui/controllers/accounts.php rename to automad/src/UI/Controllers/Accounts.php diff --git a/automad/ui/controllers/cache.php b/automad/src/UI/Controllers/Cache.php similarity index 100% rename from automad/ui/controllers/cache.php rename to automad/src/UI/Controllers/Cache.php diff --git a/automad/ui/controllers/config.php b/automad/src/UI/Controllers/Config.php similarity index 100% rename from automad/ui/controllers/config.php rename to automad/src/UI/Controllers/Config.php diff --git a/automad/ui/controllers/file.php b/automad/src/UI/Controllers/File.php similarity index 100% rename from automad/ui/controllers/file.php rename to automad/src/UI/Controllers/File.php diff --git a/automad/ui/controllers/filecollection.php b/automad/src/UI/Controllers/FileCollection.php similarity index 100% rename from automad/ui/controllers/filecollection.php rename to automad/src/UI/Controllers/FileCollection.php diff --git a/automad/ui/controllers/headless.php b/automad/src/UI/Controllers/Headless.php similarity index 100% rename from automad/ui/controllers/headless.php rename to automad/src/UI/Controllers/Headless.php diff --git a/automad/ui/controllers/image.php b/automad/src/UI/Controllers/Image.php similarity index 100% rename from automad/ui/controllers/image.php rename to automad/src/UI/Controllers/Image.php diff --git a/automad/ui/controllers/inpage.php b/automad/src/UI/Controllers/InPage.php similarity index 100% rename from automad/ui/controllers/inpage.php rename to automad/src/UI/Controllers/InPage.php diff --git a/automad/ui/controllers/packagemanager.php b/automad/src/UI/Controllers/PackageManager.php similarity index 100% rename from automad/ui/controllers/packagemanager.php rename to automad/src/UI/Controllers/PackageManager.php diff --git a/automad/ui/controllers/page.php b/automad/src/UI/Controllers/Page.php similarity index 100% rename from automad/ui/controllers/page.php rename to automad/src/UI/Controllers/Page.php diff --git a/automad/ui/controllers/search.php b/automad/src/UI/Controllers/Search.php similarity index 100% rename from automad/ui/controllers/search.php rename to automad/src/UI/Controllers/Search.php diff --git a/automad/ui/controllers/shared.php b/automad/src/UI/Controllers/Shared.php similarity index 100% rename from automad/ui/controllers/shared.php rename to automad/src/UI/Controllers/Shared.php diff --git a/automad/ui/controllers/status.php b/automad/src/UI/Controllers/Status.php similarity index 100% rename from automad/ui/controllers/status.php rename to automad/src/UI/Controllers/Status.php diff --git a/automad/ui/controllers/system.php b/automad/src/UI/Controllers/System.php similarity index 100% rename from automad/ui/controllers/system.php rename to automad/src/UI/Controllers/System.php diff --git a/automad/ui/controllers/theme.php b/automad/src/UI/Controllers/Theme.php similarity index 100% rename from automad/ui/controllers/theme.php rename to automad/src/UI/Controllers/Theme.php diff --git a/automad/ui/controllers/themelist.php b/automad/src/UI/Controllers/Themelist.php similarity index 100% rename from automad/ui/controllers/themelist.php rename to automad/src/UI/Controllers/Themelist.php diff --git a/automad/ui/controllers/ui.php b/automad/src/UI/Controllers/UI.php similarity index 96% rename from automad/ui/controllers/ui.php rename to automad/src/UI/Controllers/UI.php index 342089841..6989935ac 100644 --- a/automad/ui/controllers/ui.php +++ b/automad/src/UI/Controllers/UI.php @@ -37,7 +37,7 @@ namespace Automad\UI\Controllers; use Automad\Core\Request; -use Automad\UI\Components\Autocomplete\JumpBar; +use Automad\UI\Components\Autocomplete\Jumpbar; use Automad\UI\Components\Autocomplete\Link; use Automad\UI\Components\Form\Field; use Automad\UI\Response; @@ -61,7 +61,7 @@ class UI { public static function autocompleteJump() { $Automad = UICache::get(); - return JumpBar::render($Automad); + return Jumpbar::render($Automad); } /** diff --git a/automad/ui/controllers/user.php b/automad/src/UI/Controllers/User.php similarity index 100% rename from automad/ui/controllers/user.php rename to automad/src/UI/Controllers/User.php diff --git a/automad/ui/dashboard.php b/automad/src/UI/Dashboard.php similarity index 95% rename from automad/ui/dashboard.php rename to automad/src/UI/Dashboard.php index 207ae6335..4943a0bd7 100644 --- a/automad/ui/dashboard.php +++ b/automad/src/UI/Dashboard.php @@ -144,8 +144,9 @@ public function get() { * @return boolean true in case the file is readable. */ private function classFileExists($className) { - return is_readable( - AM_BASE_DIR . '/' . strtolower(str_replace('\\', '/', $className) . '.php') - ); + $prefix = 'Automad\\'; + $file = AM_BASE_DIR . '/automad/src/' . str_replace('\\', '/', substr($className, strlen($prefix))) . '.php'; + + return is_readable($file); } } diff --git a/automad/ui/inpage.php b/automad/src/UI/InPage.php similarity index 100% rename from automad/ui/inpage.php rename to automad/src/UI/InPage.php diff --git a/automad/ui/models/accounts.php b/automad/src/UI/Models/Accounts.php similarity index 100% rename from automad/ui/models/accounts.php rename to automad/src/UI/Models/Accounts.php diff --git a/automad/ui/models/file.php b/automad/src/UI/Models/File.php similarity index 100% rename from automad/ui/models/file.php rename to automad/src/UI/Models/File.php diff --git a/automad/ui/models/filecollection.php b/automad/src/UI/Models/FileCollection.php similarity index 100% rename from automad/ui/models/filecollection.php rename to automad/src/UI/Models/FileCollection.php diff --git a/automad/ui/models/image.php b/automad/src/UI/Models/Image.php similarity index 100% rename from automad/ui/models/image.php rename to automad/src/UI/Models/Image.php diff --git a/automad/ui/models/links.php b/automad/src/UI/Models/Links.php similarity index 100% rename from automad/ui/models/links.php rename to automad/src/UI/Models/Links.php diff --git a/automad/ui/models/page.php b/automad/src/UI/Models/Page.php similarity index 100% rename from automad/ui/models/page.php rename to automad/src/UI/Models/Page.php diff --git a/automad/ui/models/replacement.php b/automad/src/UI/Models/Replacement.php similarity index 100% rename from automad/ui/models/replacement.php rename to automad/src/UI/Models/Replacement.php diff --git a/automad/ui/models/search.php b/automad/src/UI/Models/Search.php similarity index 100% rename from automad/ui/models/search.php rename to automad/src/UI/Models/Search.php diff --git a/automad/ui/models/search/fieldresults.php b/automad/src/UI/Models/Search/FieldResults.php similarity index 100% rename from automad/ui/models/search/fieldresults.php rename to automad/src/UI/Models/Search/FieldResults.php diff --git a/automad/ui/models/search/filekeys.php b/automad/src/UI/Models/Search/FileKeys.php similarity index 100% rename from automad/ui/models/search/filekeys.php rename to automad/src/UI/Models/Search/FileKeys.php diff --git a/automad/ui/models/search/fileresults.php b/automad/src/UI/Models/Search/FileResults.php similarity index 100% rename from automad/ui/models/search/fileresults.php rename to automad/src/UI/Models/Search/FileResults.php diff --git a/automad/ui/response.php b/automad/src/UI/Response.php similarity index 100% rename from automad/ui/response.php rename to automad/src/UI/Response.php diff --git a/automad/ui/utils/filesystem.php b/automad/src/UI/Utils/FileSystem.php similarity index 100% rename from automad/ui/utils/filesystem.php rename to automad/src/UI/Utils/FileSystem.php diff --git a/automad/ui/utils/keys.php b/automad/src/UI/Utils/Keys.php similarity index 100% rename from automad/ui/utils/keys.php rename to automad/src/UI/Utils/Keys.php diff --git a/automad/ui/utils/prefix.php b/automad/src/UI/Utils/Prefix.php similarity index 100% rename from automad/ui/utils/prefix.php rename to automad/src/UI/Utils/Prefix.php diff --git a/automad/ui/utils/text.php b/automad/src/UI/Utils/Text.php similarity index 100% rename from automad/ui/utils/text.php rename to automad/src/UI/Utils/Text.php diff --git a/automad/ui/utils/uicache.php b/automad/src/UI/Utils/UICache.php similarity index 100% rename from automad/ui/utils/uicache.php rename to automad/src/UI/Utils/UICache.php diff --git a/automad/ui/views/createuser.php b/automad/src/UI/Views/CreateUser.php similarity index 100% rename from automad/ui/views/createuser.php rename to automad/src/UI/Views/CreateUser.php diff --git a/automad/ui/views/elements/navbar.php b/automad/src/UI/Views/Elements/Navbar.php similarity index 97% rename from automad/ui/views/elements/navbar.php rename to automad/src/UI/Views/Elements/Navbar.php index 1fe82af9f..ffc21ed62 100644 --- a/automad/ui/views/elements/navbar.php +++ b/automad/src/UI/Views/Elements/Navbar.php @@ -39,7 +39,7 @@ use Automad\Core\Request; use Automad\Core\Str; use Automad\UI\Components\Logo; -use Automad\UI\Components\Nav\JumpBar; +use Automad\UI\Components\Nav\Jumpbar; use Automad\UI\Controllers\User; use Automad\UI\Utils\Text; @@ -78,7 +78,7 @@ public static function render($Automad) {
- {$fn(JumpBar::render(Text::get('jumpbar_placeholder'), '[Ctrl + J]'))} + {$fn(Jumpbar::render(Text::get('jumpbar_placeholder'), '[Ctrl + J]'))}
diff --git a/automad/ui/views/elements/sidebar.php b/automad/src/UI/Views/Elements/Sidebar.php similarity index 98% rename from automad/ui/views/elements/sidebar.php rename to automad/src/UI/Views/Elements/Sidebar.php index bd4096389..6fe515f28 100644 --- a/automad/ui/views/elements/sidebar.php +++ b/automad/src/UI/Views/Elements/Sidebar.php @@ -38,7 +38,7 @@ use Automad\Core\Request; use Automad\UI\Components\Logo; -use Automad\UI\Components\Nav\JumpBar; +use Automad\UI\Components\Nav\Jumpbar; use Automad\UI\Components\Nav\SiteTree; use Automad\UI\Components\Status\Span; use Automad\UI\Controllers\User; @@ -89,7 +89,7 @@ class="am-sidebar-logo"
- {$fn(JumpBar::render(Text::get('jumpbar_placeholder')))} + {$fn(Jumpbar::render(Text::get('jumpbar_placeholder')))}
' + '
' + - Automad.util.formatBytes(data.files[i].size) + + Automad.Util.formatBytes(data.files[i].size) + '
'; }); @@ -224,14 +224,14 @@ // Init modal. $(document).on( 'click', - '[href="' + Automad.upload.selectors.modal + '"]', - Automad.upload.init + '[href="' + Automad.Upload.selectors.modal + '"]', + Automad.Upload.init ); // Prevent the default action when a file is dropped on the window. $(document).on( 'drop dragover', - Automad.upload.selectors.modal, + Automad.Upload.selectors.modal, function (e) { e.preventDefault(); } diff --git a/automad/ui/js/Util.js b/automad/ui/js/Util.js index af901e11e..d3afe8dfb 100644 --- a/automad/ui/js/Util.js +++ b/automad/ui/js/Util.js @@ -38,7 +38,7 @@ */ +(function (Automad, $) { - Automad.util = { + Automad.Util = { create: { element: function (tag, cls) { var element = document.createElement(tag); @@ -51,7 +51,7 @@ }, colorPicker: function (cls, value) { - const wrapper = Automad.util.create.element('div', ['uk-flex']); + const wrapper = Automad.Util.create.element('div', ['uk-flex']); wrapper.dataset.amColorpicker = true; wrapper.innerHTML = ` @@ -63,7 +63,7 @@ }, editable: function (cls, placeholder, value) { - var span = Automad.util.create.element('span', cls); + var span = Automad.Util.create.element('span', cls); span.contentEditable = true; span.dataset.placeholder = placeholder; @@ -73,7 +73,7 @@ }, label: function (text, cls = ['am-block-label']) { - var label = Automad.util.create.element('label', cls); + var label = Automad.Util.create.element('label', cls); label.textContent = text; @@ -81,7 +81,7 @@ }, numberUnit: function (clsPrefix, value) { - const create = Automad.util.create, + const create = Automad.Util.create, wrapper = create.element('div', ['am-form-input-group']), units = ['px', 'em', 'rem', '%', 'vw', 'vh']; @@ -110,7 +110,7 @@ }, select: function (cls, options, selected) { - var select = Automad.util.create.element('select', cls), + var select = Automad.Util.create.element('select', cls), optionMarkup = []; options.forEach(function (value) { @@ -167,9 +167,9 @@ }, getNumberUnitAsString: function (numberInput, unitSelect) { - const number = Automad.util - .stripNbsp(numberInput.textContent) - .trim(), + const number = Automad.Util.stripNbsp( + numberInput.textContent + ).trim(), unit = unitSelect.value; if (number.length) { From 64d373169dd09aca4592d984bd90734031371878 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 20:07:20 +0200 Subject: [PATCH 04/59] rename less component files --- automad/ui/less/{block_editor.less => block-editor.less} | 0 automad/ui/less/{markdown_editor.less => markdowneditor.less} | 0 automad/ui/less/{no_js.less => no-js.less} | 0 automad/ui/less/{select_image.less => select-image.less} | 0 automad/ui/less/{toggle_default.less => toggle-default.less} | 0 automad/ui/less/{site_tree.less => tree.less} | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename automad/ui/less/{block_editor.less => block-editor.less} (100%) rename automad/ui/less/{markdown_editor.less => markdowneditor.less} (100%) rename automad/ui/less/{no_js.less => no-js.less} (100%) rename automad/ui/less/{select_image.less => select-image.less} (100%) rename automad/ui/less/{toggle_default.less => toggle-default.less} (100%) rename automad/ui/less/{site_tree.less => tree.less} (100%) diff --git a/automad/ui/less/block_editor.less b/automad/ui/less/block-editor.less similarity index 100% rename from automad/ui/less/block_editor.less rename to automad/ui/less/block-editor.less diff --git a/automad/ui/less/markdown_editor.less b/automad/ui/less/markdowneditor.less similarity index 100% rename from automad/ui/less/markdown_editor.less rename to automad/ui/less/markdowneditor.less diff --git a/automad/ui/less/no_js.less b/automad/ui/less/no-js.less similarity index 100% rename from automad/ui/less/no_js.less rename to automad/ui/less/no-js.less diff --git a/automad/ui/less/select_image.less b/automad/ui/less/select-image.less similarity index 100% rename from automad/ui/less/select_image.less rename to automad/ui/less/select-image.less diff --git a/automad/ui/less/toggle_default.less b/automad/ui/less/toggle-default.less similarity index 100% rename from automad/ui/less/toggle_default.less rename to automad/ui/less/toggle-default.less diff --git a/automad/ui/less/site_tree.less b/automad/ui/less/tree.less similarity index 100% rename from automad/ui/less/site_tree.less rename to automad/ui/less/tree.less From f35f081083c269e929293539b66b379bd4a7b633 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 20:12:08 +0200 Subject: [PATCH 05/59] fix less imports --- automad/ui/less/automad.less | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/automad/ui/less/automad.less b/automad/ui/less/automad.less index 66624fc7e..c50d2a891 100644 --- a/automad/ui/less/automad.less +++ b/automad/ui/less/automad.less @@ -85,7 +85,7 @@ @import 'autocomplete.less'; @import 'badge.less'; @import 'base.less'; -@import 'block_editor.less'; +@import 'block-editor.less'; @import 'button.less'; @import 'close.less'; @import 'colorpicker.less'; @@ -103,26 +103,26 @@ @import 'inpage.less'; @import 'jumpbar.less'; @import 'logo.less'; -@import 'markdown_editor.less'; +@import 'markdowneditor.less'; @import 'mixins.less'; @import 'modal.less'; @import 'nav.less'; @import 'navbar.less'; -@import 'no_js.less'; +@import 'no-js.less'; @import 'notify.less'; @import 'panel.less'; @import 'progress.less'; @import 'scrollbars.less'; -@import 'select_image.less'; +@import 'select-image.less'; @import 'sidebar.less'; -@import 'site_tree.less'; @import 'sticky.less'; @import 'subnav.less'; @import 'switcher.less'; @import 'tags.less'; @import 'text.less'; -@import 'toggle_default.less'; +@import 'toggle-default.less'; @import 'toggle.less'; @import 'tooltip.less'; +@import 'tree.less'; @import 'utility.less'; @import 'variables.less'; From 02dd87a89c078c71a432ea96f686200ab5cf6180 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 20:18:56 +0200 Subject: [PATCH 06/59] merge dist files of block and ui in one single directory --- automad/{ui => }/dist/automad.min.css | 0 automad/{ui => }/dist/automad.min.js | 0 automad/{blocks => }/dist/blocks.min.css | 0 automad/{blocks => }/dist/blocks.min.js | 0 automad/{ui => }/dist/favicon.ico | Bin automad/{ui => }/dist/libs.min.css | 0 automad/{ui => }/dist/libs.min.js | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename automad/{ui => }/dist/automad.min.css (100%) rename automad/{ui => }/dist/automad.min.js (100%) rename automad/{blocks => }/dist/blocks.min.css (100%) rename automad/{blocks => }/dist/blocks.min.js (100%) rename automad/{ui => }/dist/favicon.ico (100%) rename automad/{ui => }/dist/libs.min.css (100%) rename automad/{ui => }/dist/libs.min.js (100%) diff --git a/automad/ui/dist/automad.min.css b/automad/dist/automad.min.css similarity index 100% rename from automad/ui/dist/automad.min.css rename to automad/dist/automad.min.css diff --git a/automad/ui/dist/automad.min.js b/automad/dist/automad.min.js similarity index 100% rename from automad/ui/dist/automad.min.js rename to automad/dist/automad.min.js diff --git a/automad/blocks/dist/blocks.min.css b/automad/dist/blocks.min.css similarity index 100% rename from automad/blocks/dist/blocks.min.css rename to automad/dist/blocks.min.css diff --git a/automad/blocks/dist/blocks.min.js b/automad/dist/blocks.min.js similarity index 100% rename from automad/blocks/dist/blocks.min.js rename to automad/dist/blocks.min.js diff --git a/automad/ui/dist/favicon.ico b/automad/dist/favicon.ico similarity index 100% rename from automad/ui/dist/favicon.ico rename to automad/dist/favicon.ico diff --git a/automad/ui/dist/libs.min.css b/automad/dist/libs.min.css similarity index 100% rename from automad/ui/dist/libs.min.css rename to automad/dist/libs.min.css diff --git a/automad/ui/dist/libs.min.js b/automad/dist/libs.min.js similarity index 100% rename from automad/ui/dist/libs.min.js rename to automad/dist/libs.min.js From 77296bd9d2357349a373da85de0e873ecb0fe2e2 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 20:30:19 +0200 Subject: [PATCH 07/59] rename tree less component into site-tree --- automad/src/UI/Components/Modal/AddPage.php | 2 +- automad/src/UI/Views/Elements/Sidebar.php | 2 +- automad/src/UI/Views/Page.php | 2 +- automad/ui/js/SiteTree.js | 16 ++++++++-------- automad/ui/less/automad.less | 2 +- automad/ui/less/{tree.less => site-tree.less} | 12 ++++++------ 6 files changed, 18 insertions(+), 18 deletions(-) rename automad/ui/less/{tree.less => site-tree.less} (92%) diff --git a/automad/src/UI/Components/Modal/AddPage.php b/automad/src/UI/Components/Modal/AddPage.php index 4ef588e2f..162b98c38 100644 --- a/automad/src/UI/Components/Modal/AddPage.php +++ b/automad/src/UI/Components/Modal/AddPage.php @@ -95,7 +95,7 @@ class="uk-form-controls uk-form-large uk-width-1-1" -
+
{$fn(SiteTree::render($Automad, '', array(), false, false))}
diff --git a/automad/src/UI/Views/Elements/Sidebar.php b/automad/src/UI/Views/Elements/Sidebar.php index 6fe515f28..75687105f 100644 --- a/automad/src/UI/Views/Elements/Sidebar.php +++ b/automad/src/UI/Views/Elements/Sidebar.php @@ -79,7 +79,7 @@ public static function render($Automad) {
-
+
{$fn(Text::get('page_move_destination'))} -
+
{$fn(SiteTree::render($this->Automad, '', array(), true, false))}
diff --git a/automad/ui/js/SiteTree.js b/automad/ui/js/SiteTree.js index 329631e5e..aa697cc3d 100644 --- a/automad/ui/js/SiteTree.js +++ b/automad/ui/js/SiteTree.js @@ -34,17 +34,17 @@ */ /* - * Initialize the site tree having a 'data-am-tree' attribute by creating toggle buttons + * Initialize the site tree having a 'data-am-site-tree' attribute by creating toggle buttons * for all nodes and collapsing all inactive ones. * * The site tree can also be used to select pages and inject their URL in to an input field * instead of just navigating to that page. - * To use a site tree for selection only, the 'data-am-tree' attribute must be + * To use a site tree for selection only, the 'data-am-site-tree' attribute must be * set to the selector of the input field. * * Leaving the attribute empty will disable selection and keep the default link behavior instead. * - *
+ *
* ... *
* @@ -54,12 +54,12 @@ Automad.SiteTree = { class: { active: 'uk-active', - iconOpen: 'am-tree-icon-open', - iconClose: 'am-tree-icon-close', - toggle: 'am-tree-toggle', + iconOpen: 'am-site-tree-icon-open', + iconClose: 'am-site-tree-icon-close', + toggle: 'am-site-tree-toggle', }, - dataAttr: 'data-am-tree', + dataAttr: 'data-am-site-tree', // The site tree can also be used to select an URL to be used as an input field value. urlAsValue: function ($tree, $input) { @@ -147,7 +147,7 @@ }); }); - // Use the URL as input value if data-am-tree is not empty. + // Use the URL as input value if data-am-site-tree is not empty. if (inputSelector.length > 0) { t.urlAsValue($tree, $(inputSelector)); } diff --git a/automad/ui/less/automad.less b/automad/ui/less/automad.less index c50d2a891..5bf018abf 100644 --- a/automad/ui/less/automad.less +++ b/automad/ui/less/automad.less @@ -115,6 +115,7 @@ @import 'scrollbars.less'; @import 'select-image.less'; @import 'sidebar.less'; +@import 'site-tree.less'; @import 'sticky.less'; @import 'subnav.less'; @import 'switcher.less'; @@ -123,6 +124,5 @@ @import 'toggle-default.less'; @import 'toggle.less'; @import 'tooltip.less'; -@import 'tree.less'; @import 'utility.less'; @import 'variables.less'; diff --git a/automad/ui/less/tree.less b/automad/ui/less/site-tree.less similarity index 92% rename from automad/ui/less/tree.less rename to automad/ui/less/site-tree.less index 557eaf7c9..e2b75579c 100644 --- a/automad/ui/less/tree.less +++ b/automad/ui/less/site-tree.less @@ -32,7 +32,7 @@ * Licensed under the MIT license. */ -[data-am-tree] { +[data-am-site-tree] { .am-sidebar & { padding: 0 @utility-container-padding-horizontal @am-body-padding-bottom @utility-container-padding-horizontal; @@ -44,7 +44,7 @@ border-radius: @am-radius; & li.uk-active > a, - & li a:not(.am-tree-toggle):hover { + & li a:not(.am-site-tree-toggle):hover { color: @button-success-color; background-color: @button-success-background; } @@ -59,12 +59,12 @@ position: relative; } - & a:not(.am-tree-toggle) { + & a:not(.am-site-tree-toggle) { width: auto; } } -.am-tree-toggle { +.am-site-tree-toggle { position: absolute !important; z-index: 2; left: -1.43rem; @@ -81,7 +81,7 @@ } } -[class*='am-tree-icon-'] { +[class*='am-site-tree-icon-'] { &:extend([class*='uk-icon-'] all); font-size: 1em; width: 0.71rem; @@ -89,7 +89,7 @@ color: @am-text; } -.am-tree-icon { +.am-site-tree-icon { &-open { &:extend(.uk-icon-chevron-right all); } From 1b78514f9b0c9565818e342f3a8af00441ad442d Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 20:31:23 +0200 Subject: [PATCH 08/59] update gulpfile.js --- automad/gulpfile.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/automad/gulpfile.js b/automad/gulpfile.js index 31c9c26bf..a1fad80ad 100644 --- a/automad/gulpfile.js +++ b/automad/gulpfile.js @@ -12,8 +12,7 @@ var gulp = require('gulp'), gutil = require('gulp-util'), fs = require('fs'), pkg = require('./package.json'), - distDashboard = 'ui/dist', - distBlocks = 'blocks/dist', + dist = 'dist', cleanCSSOptions = { format: { wrapAt: 500 }, rebase: false, @@ -59,7 +58,7 @@ gulp.task('blocks-js', function () { .pipe(concat('blocks.min.js')) .pipe(uglify(uglifyOptions)) .pipe(header(fs.readFileSync('header.txt', 'utf8'), { pkg: pkg })) - .pipe(gulp.dest(distBlocks)); + .pipe(gulp.dest(dist)); }); // Concat, minify and prefix the UI js. @@ -78,7 +77,7 @@ gulp.task('automad-js', function () { merge2( gulp.src(['ui/js/*.js']).pipe(sort()), gulp.src(['ui/js/*/*.js']).pipe(sort()), - gulp.src(['ui/js/editorjs/*/*.js']).pipe(sort()) + gulp.src(['ui/js/*/*/*.js']).pipe(sort()) ) .pipe(concat('automad.min.js')) .pipe(uglify(uglifyOptions)) @@ -89,7 +88,7 @@ gulp.task('automad-js', function () { // Prefix all UIkit items. .pipe(replace(customize.cls.search, customize.cls.replace)) .pipe(replace(customize.da.search, customize.da.replace)) - .pipe(gulp.dest(distDashboard)) + .pipe(gulp.dest(dist)) ); }); @@ -213,7 +212,7 @@ gulp.task('libs-js', function () { // Prefix all UIkit items. .pipe(replace(customize.cls.search, customize.cls.replace)) .pipe(replace(customize.da.search, customize.da.replace)) - .pipe(gulp.dest(distDashboard)) + .pipe(gulp.dest(dist)) ); }); @@ -227,7 +226,7 @@ gulp.task('blocks-less', function () { .pipe(cleanCSS(cleanCSSOptions)) .pipe(header(fs.readFileSync('header.txt', 'utf8'), { pkg: pkg })) .pipe(rename({ suffix: '.min' })) - .pipe(gulp.dest(distBlocks)); + .pipe(gulp.dest(dist)); }); // Compile, minify and prefix automad.less. @@ -244,7 +243,7 @@ gulp.task('automad-less', function () { // Prefix all UIkit items. .pipe(replace(customize.cls.search, customize.cls.replace)) .pipe(replace(customize.da.search, customize.da.replace)) - .pipe(gulp.dest(distDashboard)) + .pipe(gulp.dest(dist)) ); }); @@ -257,7 +256,7 @@ gulp.task('libs-css', function () { ]) .pipe(cleanCSS(cleanCSSOptions)) .pipe(concat('libs.min.css', { newLine: '\r\n\r\n' })) - .pipe(gulp.dest(distDashboard)); + .pipe(gulp.dest(dist)); }); // Watch task. From 0bdd416f5326a18fb7367a68929e67ca5a1b4596 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 20:38:22 +0200 Subject: [PATCH 09/59] fix path to fonts in less components --- automad/ui/less/fonts.less | 2 +- automad/ui/less/icon.less | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/automad/ui/less/fonts.less b/automad/ui/less/fonts.less index b51de9b91..7fadf0826 100644 --- a/automad/ui/less/fonts.less +++ b/automad/ui/less/fonts.less @@ -32,7 +32,7 @@ * Licensed under the MIT license. */ -@inter: '../../../lib/fonts/inter/'; +@inter: '../../lib/fonts/inter/'; @font-face { font-family: 'Inter'; diff --git a/automad/ui/less/icon.less b/automad/ui/less/icon.less index ef8f64d1f..28f0d9591 100644 --- a/automad/ui/less/icon.less +++ b/automad/ui/less/icon.less @@ -32,7 +32,7 @@ * Licensed under the MIT license. */ -@icon-font-path: '../../../lib/vendor/uikit/uikit/src/fonts'; +@icon-font-path: '../../lib/vendor/uikit/uikit/src/fonts'; .am-icon-headless, .uk-icon-headless { From 454fdb0b9cdd6e457f06757adc33d019604d3b64 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 20:38:49 +0200 Subject: [PATCH 10/59] fix asset links --- automad/src/Core/Blocks.php | 4 ++-- automad/src/UI/InPage.php | 8 ++++---- automad/src/UI/Views/View.php | 10 +++++----- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/automad/src/Core/Blocks.php b/automad/src/Core/Blocks.php index bbb08baa9..3d6cfdc95 100644 --- a/automad/src/Core/Blocks.php +++ b/automad/src/Core/Blocks.php @@ -59,8 +59,8 @@ class Blocks { */ public static function injectAssets($str) { $versionSanitized = Str::sanitize(AM_VERSION); - $css = AM_BASE_URL . '/automad/blocks/dist/blocks.min.css?v=' . $versionSanitized; - $js = AM_BASE_URL . '/automad/blocks/dist/blocks.min.js?v=' . $versionSanitized; + $css = AM_BASE_URL . '/automad/dist/blocks.min.css?v=' . $versionSanitized; + $js = AM_BASE_URL . '/automad/dist/blocks.min.js?v=' . $versionSanitized; $assets = <<< HTML diff --git a/automad/src/UI/InPage.php b/automad/src/UI/InPage.php index 765621b9a..d8a4c0867 100644 --- a/automad/src/UI/InPage.php +++ b/automad/src/UI/InPage.php @@ -114,10 +114,10 @@ private function injectAssets($str) { $versionSanitized = Str::sanitize(AM_VERSION); $assets = "\n" . '' . "\n" . - '' . "\n" . - '' . "\n" . - '' . "\n" . - '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . + '' . "\n" . // Cleanup window object by removing jQuery and UIkit. '' . "\n" . BlockSnippetArrays::render() . "\n" . diff --git a/automad/src/UI/Views/View.php b/automad/src/UI/Views/View.php index 089dee0d3..fa069b593 100644 --- a/automad/src/UI/Views/View.php +++ b/automad/src/UI/Views/View.php @@ -115,11 +115,11 @@ public function render() { content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" > {$fn($this->title())} - - - - - + + + + + {$fn(BlockSnippetArrays::render())} {$fn(EditorTextModules::render())} From e20d7f788262356a5ed553a861662183afb5a653 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 21:07:45 +0200 Subject: [PATCH 11/59] refactor tests --- automad/{tests/mock.php => src/Test/Mock.php} | 11 ++++++----- .../tests/{core/parse_test.php => Core/ParseTest.php} | 2 +- .../tests/{core/pipe_test.php => Core/PipeTest.php} | 2 +- .../tests/{core/regex_test.php => Core/RegexTest.php} | 2 +- automad/tests/{core/str_test.php => Core/StrTest.php} | 2 +- .../{core/toolbox_test.php => Core/ToolboxTest.php} | 4 ++-- .../tests/{core/view_test.php => Core/ViewTest.php} | 4 ++-- .../Models/ReplacementTest.php} | 2 +- .../search_test.php => UI/Models/SearchTest.php} | 2 +- automad/tests/bootstrap.php | 2 +- automad/tests/{ => templates}/headless/json.php | 0 phpunit.xml | 2 +- 12 files changed, 18 insertions(+), 17 deletions(-) rename automad/{tests/mock.php => src/Test/Mock.php} (89%) rename automad/tests/{core/parse_test.php => Core/ParseTest.php} (97%) rename automad/tests/{core/pipe_test.php => Core/PipeTest.php} (96%) rename automad/tests/{core/regex_test.php => Core/RegexTest.php} (99%) rename automad/tests/{core/str_test.php => Core/StrTest.php} (99%) rename automad/tests/{core/toolbox_test.php => Core/ToolboxTest.php} (95%) rename automad/tests/{core/view_test.php => Core/ViewTest.php} (99%) rename automad/tests/{ui/models/replacement_test.php => UI/Models/ReplacementTest.php} (98%) rename automad/tests/{ui/models/search_test.php => UI/Models/SearchTest.php} (99%) rename automad/tests/{ => templates}/headless/json.php (100%) diff --git a/automad/tests/mock.php b/automad/src/Test/Mock.php similarity index 89% rename from automad/tests/mock.php rename to automad/src/Test/Mock.php index 077fdef43..e69316cfb 100644 --- a/automad/tests/mock.php +++ b/automad/src/Test/Mock.php @@ -1,6 +1,6 @@ new Page( @@ -76,7 +77,7 @@ private function createCollection($Shared, $template) { 'theme' => $theme, ':template' => $template ), - Parse::textFile(__DIR__ . '/data/page.txt') + Parse::textFile($testsDir . '/data/page.txt') ), $Shared ), @@ -89,7 +90,7 @@ private function createCollection($Shared, $template) { 'theme' => $theme, ':template' => $template, ), - Parse::textFile(__DIR__ . '/data/text.txt') + Parse::textFile($testsDir . '/data/text.txt') ), $Shared ), @@ -102,7 +103,7 @@ private function createCollection($Shared, $template) { 'theme' => $theme, ':template' => $template, ), - Parse::textFile(__DIR__ . '/data/blocks.txt') + Parse::textFile($testsDir . '/data/blocks.txt') ), $Shared ) diff --git a/automad/tests/core/parse_test.php b/automad/tests/Core/ParseTest.php similarity index 97% rename from automad/tests/core/parse_test.php rename to automad/tests/Core/ParseTest.php index 552b39331..b90c072ea 100644 --- a/automad/tests/core/parse_test.php +++ b/automad/tests/Core/ParseTest.php @@ -7,7 +7,7 @@ /** * @testdox Automad\Core\Parse */ -class Parse_Test extends TestCase { +class ParseTest extends TestCase { public function dataForTestCsvIsSame() { return array( array( diff --git a/automad/tests/core/pipe_test.php b/automad/tests/Core/PipeTest.php similarity index 96% rename from automad/tests/core/pipe_test.php rename to automad/tests/Core/PipeTest.php index 20f54f8cf..e05bfec0b 100644 --- a/automad/tests/core/pipe_test.php +++ b/automad/tests/Core/PipeTest.php @@ -7,7 +7,7 @@ /** * @testdox Automad\Core\Pipe */ -class Pipe_Test extends TestCase { +class PipeTest extends TestCase { public function dataForTestProcessIsEqual() { return array( array( diff --git a/automad/tests/core/regex_test.php b/automad/tests/Core/RegexTest.php similarity index 99% rename from automad/tests/core/regex_test.php rename to automad/tests/Core/RegexTest.php index eeeaace8e..5f342754a 100644 --- a/automad/tests/core/regex_test.php +++ b/automad/tests/Core/RegexTest.php @@ -7,7 +7,7 @@ /** * @testdox Automad\Core\Regex */ -class Regex_Test extends TestCase { +class RegexTest extends TestCase { public function dataForTestCsvIsSame() { return array( array( diff --git a/automad/tests/core/str_test.php b/automad/tests/Core/StrTest.php similarity index 99% rename from automad/tests/core/str_test.php rename to automad/tests/Core/StrTest.php index 126d72de7..25e7ed08c 100644 --- a/automad/tests/core/str_test.php +++ b/automad/tests/Core/StrTest.php @@ -7,7 +7,7 @@ /** * @testdox Automad\Core\Str */ -class Str_Test extends TestCase { +class StrTest extends TestCase { public function dataForTestDefIsEqual() { return array( array('', 'Some string.', 'Some string.'), diff --git a/automad/tests/core/toolbox_test.php b/automad/tests/Core/ToolboxTest.php similarity index 95% rename from automad/tests/core/toolbox_test.php rename to automad/tests/Core/ToolboxTest.php index a83ce4008..bdd724ab6 100644 --- a/automad/tests/core/toolbox_test.php +++ b/automad/tests/Core/ToolboxTest.php @@ -2,13 +2,13 @@ namespace Automad\Core; -use Automad\Tests\Mock; +use Automad\Test\Mock; use PHPUnit\Framework\TestCase; /** * @testdox Automad\Core\Toolbox */ -class Toolbox_Test extends TestCase { +class ToolboxTest extends TestCase { public function dataForTestSetSessionIsEqual() { return array( array('%key1', 'Some Session Value', 'Some Session Value'), diff --git a/automad/tests/core/view_test.php b/automad/tests/Core/ViewTest.php similarity index 99% rename from automad/tests/core/view_test.php rename to automad/tests/Core/ViewTest.php index 36f1133d8..573961246 100644 --- a/automad/tests/core/view_test.php +++ b/automad/tests/Core/ViewTest.php @@ -2,13 +2,13 @@ namespace Automad\Core; -use Automad\Tests\Mock; +use Automad\Test\Mock; use PHPUnit\Framework\TestCase; /** * @testdox Automad\Core\View */ -class View_Test extends TestCase { +class ViewTest extends TestCase { public function dataForTestHeadlessJSONIsEqual() { return array( array( diff --git a/automad/tests/ui/models/replacement_test.php b/automad/tests/UI/Models/ReplacementTest.php similarity index 98% rename from automad/tests/ui/models/replacement_test.php rename to automad/tests/UI/Models/ReplacementTest.php index eca601440..1ba9caf51 100644 --- a/automad/tests/ui/models/replacement_test.php +++ b/automad/tests/UI/Models/ReplacementTest.php @@ -8,7 +8,7 @@ /** * @testdox Automad\UI\Models\Replacement */ -class Replacement_Test extends TestCase { +class ReplacementTest extends TestCase { public function dataForTestReplaceInDataIsSame() { return array( // Blocks, no regex, not case sensitive. diff --git a/automad/tests/ui/models/search_test.php b/automad/tests/UI/Models/SearchTest.php similarity index 99% rename from automad/tests/ui/models/search_test.php rename to automad/tests/UI/Models/SearchTest.php index 534541aaf..d04080c6e 100644 --- a/automad/tests/ui/models/search_test.php +++ b/automad/tests/UI/Models/SearchTest.php @@ -2,7 +2,7 @@ namespace Automad\UI\Models; -use Automad\Tests\Mock; +use Automad\Test\Mock; use Automad\UI\Models\Search\FieldResults; use Automad\UI\Models\Search\FileResults; use PHPUnit\Framework\TestCase; diff --git a/automad/tests/bootstrap.php b/automad/tests/bootstrap.php index 7f65e0e2c..bc7088d9e 100644 --- a/automad/tests/bootstrap.php +++ b/automad/tests/bootstrap.php @@ -2,7 +2,7 @@ define('AUTOMAD', true); define('AM_BASE_DIR', __DIR__ . '/../..'); -define('AM_HEADLESS_TEMPLATE', '/automad/tests/headless/json.php'); +define('AM_HEADLESS_TEMPLATE', '/automad/tests/templates/headless/json.php'); define('AM_HEADLESS_TEMPLATE_CUSTOM', AM_HEADLESS_TEMPLATE); require AM_BASE_DIR . '/automad/autoload.php'; require AM_BASE_DIR . '/automad/const.php'; diff --git a/automad/tests/headless/json.php b/automad/tests/templates/headless/json.php similarity index 100% rename from automad/tests/headless/json.php rename to automad/tests/templates/headless/json.php diff --git a/phpunit.xml b/phpunit.xml index 8d254aea7..ef5d69c14 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ - automad/tests + automad/tests From 52a17197eb51d01c2f6391da407a95d3b3881bf8 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 21:18:22 +0200 Subject: [PATCH 12/59] move header template into gulpfile.js --- automad/gulpfile.js | 47 ++++++++++++++++++++++++++++++++++----- automad/header.txt | 36 ------------------------------ automad/package-lock.json | 6 ----- automad/package.json | 1 - 4 files changed, 42 insertions(+), 48 deletions(-) delete mode 100644 automad/header.txt diff --git a/automad/gulpfile.js b/automad/gulpfile.js index a1fad80ad..d59108506 100644 --- a/automad/gulpfile.js +++ b/automad/gulpfile.js @@ -1,3 +1,41 @@ +const headerTemplate = `/* + * .... + * .: '':. + * :::: ':.. + * ::. ''.. + * .:'.. ..':.:::' . :. '':. + * :. '' '' '. ::::.. ..: + * ::::. ..':.. .'''::::: . + * :::::::.. '..:::: :. :::: : + * ::'':::::::. ':::.'':.:::: : + * :.. ''::::::....': '':: : + * :::::. '::::: : .. '' . + * .''::::::::... ':::.'' ..'' :.''''. + * :..:::''::::: :::::...:'' :..: + * ::::::. ':::: :::::::: ..:: . + * ::::::::.:::: :::::::: :'':.:: .'' + * ::: '::::::::.' ''::::: :.' '': : + * ::: :::::::::..' :::: ::...' . + * ::: .:::::::::: :::: :::: .:' + * '::' ''::::::: :::: : :: : + * ':::: :::: :'' .: + * :::: :::: ..'' + * :::: ..:::: .:'' + * '''' ''''' + * + * + * AUTOMAD + * + * version <%= pkg.version %> + * + * Copyright (c) 2014-<%= new Date().getFullYear() %> by Marc Anton Dahmen + * https://marcdahmen.de + * + * Licensed under the MIT license. + * https://automad.org/license + */ +`; + var gulp = require('gulp'), autoprefixer = require('gulp-autoprefixer'), cleanCSS = require('gulp-clean-css'), @@ -10,7 +48,6 @@ var gulp = require('gulp'), sort = require('gulp-sort'), uglify = require('gulp-uglify-es').default, gutil = require('gulp-util'), - fs = require('fs'), pkg = require('./package.json'), dist = 'dist', cleanCSSOptions = { @@ -57,7 +94,7 @@ gulp.task('blocks-js', function () { .pipe(sort()) .pipe(concat('blocks.min.js')) .pipe(uglify(uglifyOptions)) - .pipe(header(fs.readFileSync('header.txt', 'utf8'), { pkg: pkg })) + .pipe(header(headerTemplate, { pkg: pkg })) .pipe(gulp.dest(dist)); }); @@ -81,7 +118,7 @@ gulp.task('automad-js', function () { ) .pipe(concat('automad.min.js')) .pipe(uglify(uglifyOptions)) - .pipe(header(fs.readFileSync('header.txt', 'utf8'), { pkg: pkg })) + .pipe(header(headerTemplate, { pkg: pkg })) // Rename custom scrollbars. // This has to be done accordingly within the libs-js task. .pipe(replace('.mCustomScrollbar(', '.am_mCustomScrollbar(')) @@ -224,7 +261,7 @@ gulp.task('blocks-less', function () { .on('error', onError) .pipe(autoprefixer({ grid: false })) .pipe(cleanCSS(cleanCSSOptions)) - .pipe(header(fs.readFileSync('header.txt', 'utf8'), { pkg: pkg })) + .pipe(header(headerTemplate, { pkg: pkg })) .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest(dist)); }); @@ -238,7 +275,7 @@ gulp.task('automad-less', function () { .on('error', onError) .pipe(autoprefixer({ grid: false })) .pipe(cleanCSS(cleanCSSOptions)) - .pipe(header(fs.readFileSync('header.txt', 'utf8'), { pkg: pkg })) + .pipe(header(headerTemplate, { pkg: pkg })) .pipe(rename({ suffix: '.min' })) // Prefix all UIkit items. .pipe(replace(customize.cls.search, customize.cls.replace)) diff --git a/automad/header.txt b/automad/header.txt deleted file mode 100644 index a95a8b97f..000000000 --- a/automad/header.txt +++ /dev/null @@ -1,36 +0,0 @@ -/* - * .... - * .: '':. - * :::: ':.. - * ::. ''.. - * .:'.. ..':.:::' . :. '':. - * :. '' '' '. ::::.. ..: - * ::::. ..':.. .'''::::: . - * :::::::.. '..:::: :. :::: : - * ::'':::::::. ':::.'':.:::: : - * :.. ''::::::....': '':: : - * :::::. '::::: : .. '' . - * .''::::::::... ':::.'' ..'' :.''''. - * :..:::''::::: :::::...:'' :..: - * ::::::. ':::: :::::::: ..:: . - * ::::::::.:::: :::::::: :'':.:: .'' - * ::: '::::::::.' ''::::: :.' '': : - * ::: :::::::::..' :::: ::...' . - * ::: .:::::::::: :::: :::: .:' - * '::' ''::::::: :::: : :: : - * ':::: :::: :'' .: - * :::: :::: ..'' - * :::: ..:::: .:'' - * '''' ''''' - * - * - * AUTOMAD - * - * version <%= pkg.version %> - * - * Copyright (c) 2014-<%= new Date().getFullYear() %> by Marc Anton Dahmen - * https://marcdahmen.de - * - * Licensed under the MIT license. - * https://automad.org/license - */ \ No newline at end of file diff --git a/automad/package-lock.json b/automad/package-lock.json index c70ad8a3e..903c41944 100644 --- a/automad/package-lock.json +++ b/automad/package-lock.json @@ -1747,12 +1747,6 @@ "map-cache": "^0.2.2" } }, - "fs": { - "version": "0.0.2", - "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.2.tgz", - "integrity": "sha1-4fJE7zkzwbKmS9R5kTYGDQ9ZFPg=", - "dev": true - }, "fs-mkdirp-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-mkdirp-stream/-/fs-mkdirp-stream-1.0.0.tgz", diff --git a/automad/package.json b/automad/package.json index 88fd6c1b9..6bc8c9d48 100644 --- a/automad/package.json +++ b/automad/package.json @@ -12,7 +12,6 @@ "draggabilly": "^2.1.1", "editorjs-drag-drop": "^0.1.1", "editorjs-style": "^3.0.1", - "fs": "0.0.2", "gulp": "^4.0.0", "gulp-autoprefixer": "^7.0.1", "gulp-clean-css": "^3.0.4", From ee0a63eab7de02794e33b1aa9935514c2919e12b Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 21:18:45 +0200 Subject: [PATCH 13/59] remove fonts.list --- automad/fonts.list | 1 - 1 file changed, 1 deletion(-) delete mode 100644 automad/fonts.list diff --git a/automad/fonts.list b/automad/fonts.list deleted file mode 100644 index 0cad5a06f..000000000 --- a/automad/fonts.list +++ /dev/null @@ -1 +0,0 @@ -Rubik:300,300i,400,400i,500,500i,700,700i,900,900i&subset=cyrillic,hebrew,latin-ext \ No newline at end of file From 7dc5d42ad6482dbd15a72a0fbfc373b0c9998bca Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 21:37:38 +0200 Subject: [PATCH 14/59] refactor autoloader --- automad/src/App.php | 4 ++- automad/{autoload.php => src/Autoload.php} | 42 +++++++++++++--------- automad/tests/bootstrap.php | 5 ++- 3 files changed, 33 insertions(+), 18 deletions(-) rename automad/{autoload.php => src/Autoload.php} (60%) diff --git a/automad/src/App.php b/automad/src/App.php index e1fb559ad..3a7fd5243 100644 --- a/automad/src/App.php +++ b/automad/src/App.php @@ -73,7 +73,9 @@ public function __construct() { require_once __DIR__ . '/Core/FileSystem.php'; define('AM_BASE_DIR', FileSystem::normalizeSlashes(dirname(dirname(__DIR__)))); - require AM_BASE_DIR . '/automad/autoload.php'; + require_once __DIR__ . '/Autoload.php'; + Autoload::init(); + require AM_BASE_DIR . '/automad/const.php'; Debug::errorReporting(); diff --git a/automad/autoload.php b/automad/src/Autoload.php similarity index 60% rename from automad/autoload.php rename to automad/src/Autoload.php index 72ae8d199..405a9224d 100644 --- a/automad/autoload.php +++ b/automad/src/Autoload.php @@ -34,27 +34,37 @@ * https://automad.org/license */ +namespace Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); -// Composer lib. -require AM_BASE_DIR . '/lib/vendor/autoload.php'; +/** + * The Autoload class. + * + * @author Marc Anton Dahmen + * @copyright Copyright (c) 2018-2021 by Marc Anton Dahmen - https://marcdahmen.de + * @license MIT license - https://automad.org/license + */ +class Autoload { + public static function init() { + require AM_BASE_DIR . '/lib/vendor/autoload.php'; -// Composer packages. -$packagesAutoload = AM_BASE_DIR . '/vendor/autoload.php'; + $packagesAutoload = AM_BASE_DIR . '/vendor/autoload.php'; -if (file_exists($packagesAutoload)) { - require $packagesAutoload; -} + if (file_exists($packagesAutoload)) { + require $packagesAutoload; + } -// Automad. -spl_autoload_register(function ($class) { - $prefix = 'Automad\\'; + spl_autoload_register(function ($class) { + $prefix = 'Automad\\'; - if (strpos($class, $prefix) === 0) { - $file = AM_BASE_DIR . '/automad/src/' . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php'; + if (strpos($class, $prefix) === 0) { + $file = AM_BASE_DIR . '/automad/src/' . str_replace('\\', '/', substr($class, strlen($prefix))) . '.php'; - if (file_exists($file)) { - require_once $file; - } + if (file_exists($file)) { + require_once $file; + } + } + }); } -}); +} diff --git a/automad/tests/bootstrap.php b/automad/tests/bootstrap.php index bc7088d9e..20156b75b 100644 --- a/automad/tests/bootstrap.php +++ b/automad/tests/bootstrap.php @@ -1,8 +1,11 @@ Date: Fri, 3 Sep 2021 22:10:13 +0200 Subject: [PATCH 15/59] refactor configuration --- automad/const.php | 209 ------------------------------------ automad/src/App.php | 6 +- automad/src/Core/Config.php | 172 +++++++++++++++++++++++++++++ automad/tests/bootstrap.php | 7 +- 4 files changed, 183 insertions(+), 211 deletions(-) delete mode 100644 automad/const.php diff --git a/automad/const.php b/automad/const.php deleted file mode 100644 index 4fb0102c3..000000000 --- a/automad/const.php +++ /dev/null @@ -1,209 +0,0 @@ -'); -Config::set('AM_DEL_COMMENT_OPEN', '<#'); -Config::set('AM_DEL_COMMENT_CLOSE', '#>'); -Config::set('AM_DEL_INPAGE_BUTTON_OPEN', '{{@@'); -Config::set('AM_DEL_INPAGE_BUTTON_CLOSE', '@@}}'); - -// PARSE -// Block separator - separates all key/value pairs -// Must be used as the only string in a line within the template files. -Config::set('AM_PARSE_BLOCK_SEPARATOR', '-'); -// Pair separator - separates the key from the value -Config::set('AM_PARSE_PAIR_SEPARATOR', ':'); -// Tags/String separator -Config::set('AM_PARSE_STR_SEPARATOR', ','); - -// KEYS -// Variables used in txt files in /pages or /shared -Config::set('AM_KEY_DATE', 'date'); -Config::set('AM_KEY_HIDDEN', 'hidden'); -Config::set('AM_KEY_PRIVATE', 'private'); -Config::set('AM_KEY_TAGS', 'tags'); -Config::set('AM_KEY_THEME', 'theme'); -Config::set('AM_KEY_TITLE', 'title'); -Config::set('AM_KEY_SITENAME', 'sitename'); -Config::set('AM_KEY_URL', 'url'); -// System variables depending on a context. -Config::set('AM_KEY_ORIG_URL', ':origUrl'); -Config::set('AM_KEY_PATH', ':path'); -Config::set('AM_KEY_BASENAME', ':basename'); -Config::set('AM_KEY_PARENT', ':parent'); -Config::set('AM_KEY_LEVEL', ':level'); -Config::set('AM_KEY_TEMPLATE', ':template'); -Config::set('AM_KEY_CURRENT_PAGE', ':current'); -Config::set('AM_KEY_CURRENT_PATH', ':currentPath'); -Config::set('AM_KEY_MTIME', ':mtime'); -// Runtime variables Generated by template constructs. -Config::set('AM_KEY_FILTER', ':filter'); -Config::set('AM_KEY_TAG', ':tag'); -Config::set('AM_KEY_FILE', ':file'); -Config::set('AM_KEY_WIDTH', ':width'); -Config::set('AM_KEY_HEIGHT', ':height'); -Config::set('AM_KEY_FILE_RESIZED', ':fileResized'); -Config::set('AM_KEY_WIDTH_RESIZED', ':widthResized'); -Config::set('AM_KEY_HEIGHT_RESIZED', ':heightResized'); -Config::set('AM_KEY_CAPTION', ':caption'); -Config::set('AM_KEY_INDEX', ':i'); -Config::set('AM_KEY_FILELIST_COUNT', ':filelistCount'); -Config::set('AM_KEY_PAGELIST_COUNT', ':pagelistCount'); -Config::set('AM_KEY_PAGELIST_DISPLAY_COUNT', ':pagelistDisplayCount'); -Config::set('AM_KEY_PAGINATION_COUNT', ':paginationCount'); -Config::set('AM_KEY_NOW', ':now'); - -// HEADLESS -Config::set('AM_HEADLESS_ENABLED', false); -Config::set('AM_HEADLESS_TEMPLATE', '/automad/headless/json.php'); -// For security reasons, the custom template should not have the .php extension. -Config::set('AM_HEADLESS_TEMPLATE_CUSTOM', '/config/headless.json'); - -// UPDATE -Config::set('AM_UPDATE_ITEMS', '/automad, /lib, /index.php, /packages/standard, /packages/tutorial'); -Config::set('AM_UPDATE_BRANCH', 'master'); -Config::set('AM_UPDATE_REPO_DOWNLOAD_URL', 'https://github.com/marcantondahmen/automad/archive'); -Config::set('AM_UPDATE_REPO_RAW_URL', 'https://raw.githubusercontent.com/marcantondahmen/automad'); -Config::set('AM_UPDATE_REPO_VERSION_FILE', '/automad/version.php'); -Config::set('AM_UPDATE_TEMP', AM_DIR_CACHE . '/update'); - -// Version number -include AM_BASE_DIR . '/automad/version.php'; diff --git a/automad/src/App.php b/automad/src/App.php index 3a7fd5243..2eff5cb33 100644 --- a/automad/src/App.php +++ b/automad/src/App.php @@ -38,6 +38,7 @@ use Automad\Core\Automad; use Automad\Core\Cache; +use Automad\Core\Config; use Automad\Core\Debug; use Automad\Core\FileSystem; use Automad\Core\Sitemap; @@ -76,7 +77,10 @@ public function __construct() { require_once __DIR__ . '/Autoload.php'; Autoload::init(); - require AM_BASE_DIR . '/automad/const.php'; + define('AM_CONFIG', AM_BASE_DIR . '/config/config.php'); + + Config::overrides(); + Config::defaults(); Debug::errorReporting(); diff --git a/automad/src/Core/Config.php b/automad/src/Core/Config.php index 8e086116c..cdca3be77 100644 --- a/automad/src/Core/Config.php +++ b/automad/src/Core/Config.php @@ -51,6 +51,178 @@ class Config { */ private static $legacy = AM_BASE_DIR . '/config/config.json'; + /** + * Define default values for all constants that are not overriden. + */ + public static function defaults() { + // Define debugging already here to be available when parsing the request. + Config::set('AM_DEBUG_ENABLED', false); + + // Set base URL for all URLs relative to the root. + if (getenv('HTTP_X_FORWARDED_HOST') || getenv('HTTP_X_FORWARDED_SERVER')) { + // In case the site is behind a proxy, set AM_BASE_URL to AM_BASE_PROXY. + // AM_BASE_PROXY can be separately defined to enable running a site with and without a proxy in parallel. + Config::set('AM_BASE_PROXY', ''); + Config::set('AM_BASE_URL', AM_BASE_PROXY); + Debug::log(getenv('HTTP_X_FORWARDED_SERVER'), 'Proxy'); + } else { + // In case the site is not running behind a proxy server, just get the base URL from the script name. + Config::set('AM_BASE_URL', str_replace('/index.php', '', getenv('SCRIPT_NAME'))); + } + + Debug::log(getenv('SERVER_SOFTWARE'), 'Server Software'); + + // Check whether pretty URLs are enabled. + if ((strpos(strtolower(getenv('SERVER_SOFTWARE')), 'apache') !== false && file_exists(AM_BASE_DIR . '/.htaccess')) || strpos(strtolower(getenv('SERVER_SOFTWARE')), 'nginx') !== false) { + // If .htaccess exists on Apache or the server software is Nginx, assume that pretty URLs are enabled and AM_INDEX is empty. + Config::set('AM_INDEX', ''); + Debug::log('Pretty URLs are enabled.'); + } else { + // For all other environments, AM_INDEX will be defined as fallback and pretty URLs are disabled. + Config::set('AM_INDEX', '/index.php'); + Debug::log('Pretty URLs are disabled'); + } + + // Define AM_BASE_INDEX as the prefix for all page URLs. + Config::set('AM_BASE_INDEX', AM_BASE_URL . AM_INDEX); + + // An optional base protocol/domain combination for the sitemap.xml in case of being behind a proxy. + self::set('AM_BASE_SITEMAP', ''); + + // Get the requested URL. + define('AM_REQUEST', Request::page()); + + // Define all constants which are not defined yet by the config file. + // DIR + self::set('AM_DIR_PAGES', '/pages'); + self::set('AM_DIR_SHARED', '/shared'); + self::set('AM_DIR_PACKAGES', '/packages'); + self::set('AM_DIR_CACHE', '/cache'); + self::set('AM_DIR_CACHE_PAGES', AM_DIR_CACHE . '/pages'); + self::set('AM_DIR_CACHE_IMAGES', AM_DIR_CACHE . '/images'); + self::set('AM_DIR_TRASH', AM_DIR_CACHE . '/trash'); + self::set('AM_DIRNAME_MAX_LEN', 60); // Max dirname length when creating/moving pages with the UI. + + // FILE + self::set('AM_FILE_EXT_DATA', 'txt'); // Changing that constant will also require updating the .htaccess file! (for blocking direct access) + self::set('AM_FILE_EXT_CAPTION', 'caption'); + self::set('AM_FILE_PREFIX_CACHE', 'cached'); // Changing that constant will also require updating the .htaccess file! (for blocking direct access) + self::set('AM_FILE_EXT_PAGE_CACHE', 'html'); + self::set('AM_FILE_EXT_HEADLESS_CACHE', 'json'); + self::set('AM_FILE_SHARED_DATA', AM_BASE_DIR . AM_DIR_SHARED . '/data.' . AM_FILE_EXT_DATA); + self::set('AM_FILE_SITE_MTIME', AM_BASE_DIR . AM_DIR_CACHE . '/' . AM_FILE_PREFIX_CACHE . '_site_mtime'); + self::set('AM_FILE_OBJECT_CACHE', AM_BASE_DIR . AM_DIR_CACHE . '/' . AM_FILE_PREFIX_CACHE . '_automad_object'); + self::set('AM_FILE_OBJECT_USER_CACHE', AM_BASE_DIR . AM_DIR_CACHE . '/' . AM_FILE_PREFIX_CACHE . '_automad_object_user'); + self::set('AM_FILE_ACCOUNTS', AM_BASE_DIR . '/config/accounts.php'); + self::set('AM_FILE_GUI_TEXT_MODULES', AM_BASE_DIR . '/automad/ui/lang/english.txt'); + self::set('AM_FILE_GUI_TRANSLATION', ''); // Base dir will be added automatically to enable external configuration. + self::set( + 'AM_ALLOWED_FILE_TYPES', + // Archives + 'dmg, iso, rar, tar, zip, ' . + // Audio + 'aiff, m4a, mp3, ogg, wav, ' . + // Graphics + 'ai, dxf, eps, gif, ico, jpg, jpeg, png, psd, svg, tga, tiff, ' . + // Video + 'avi, flv, mov, mp4, mpeg, ' . + // Other + 'css, js, md, pdf' + ); + + // PAGE + self::set('AM_PAGE_NOT_FOUND_TEMPLATE', 'page_not_found'); + self::set('AM_PAGE_DASHBOARD', '/dashboard'); + + // PERMISSIONS + self::set('AM_PERM_DIR', 0755); + self::set('AM_PERM_FILE', 0644); + + // CACHE + self::set('AM_CACHE_ENABLED', true); + self::set('AM_CACHE_MONITOR_DELAY', 120); + self::set('AM_CACHE_LIFETIME', 43200); + + // IMAGE + self::set('AM_IMG_JPG_QUALITY', 90); + + // TEMPLATE DELIMITERS + self::set('AM_DEL_VAR_OPEN', '@{'); + self::set('AM_DEL_VAR_CLOSE', '}'); + self::set('AM_DEL_STATEMENT_OPEN', '<@'); + self::set('AM_DEL_STATEMENT_CLOSE', '@>'); + self::set('AM_DEL_COMMENT_OPEN', '<#'); + self::set('AM_DEL_COMMENT_CLOSE', '#>'); + self::set('AM_DEL_INPAGE_BUTTON_OPEN', '{{@@'); + self::set('AM_DEL_INPAGE_BUTTON_CLOSE', '@@}}'); + + // PARSE + // Block separator - separates all key/value pairs + // Must be used as the only string in a line within the template files. + self::set('AM_PARSE_BLOCK_SEPARATOR', '-'); + // Pair separator - separates the key from the value + self::set('AM_PARSE_PAIR_SEPARATOR', ':'); + // Tags/String separator + self::set('AM_PARSE_STR_SEPARATOR', ','); + + // KEYS + // Variables used in txt files in /pages or /shared + self::set('AM_KEY_DATE', 'date'); + self::set('AM_KEY_HIDDEN', 'hidden'); + self::set('AM_KEY_PRIVATE', 'private'); + self::set('AM_KEY_TAGS', 'tags'); + self::set('AM_KEY_THEME', 'theme'); + self::set('AM_KEY_TITLE', 'title'); + self::set('AM_KEY_SITENAME', 'sitename'); + self::set('AM_KEY_URL', 'url'); + + // System variables depending on a context. + self::set('AM_KEY_ORIG_URL', ':origUrl'); + self::set('AM_KEY_PATH', ':path'); + self::set('AM_KEY_BASENAME', ':basename'); + self::set('AM_KEY_PARENT', ':parent'); + self::set('AM_KEY_LEVEL', ':level'); + self::set('AM_KEY_TEMPLATE', ':template'); + self::set('AM_KEY_CURRENT_PAGE', ':current'); + self::set('AM_KEY_CURRENT_PATH', ':currentPath'); + self::set('AM_KEY_MTIME', ':mtime'); + + // Runtime variables Generated by template constructs. + self::set('AM_KEY_FILTER', ':filter'); + self::set('AM_KEY_TAG', ':tag'); + self::set('AM_KEY_FILE', ':file'); + self::set('AM_KEY_WIDTH', ':width'); + self::set('AM_KEY_HEIGHT', ':height'); + self::set('AM_KEY_FILE_RESIZED', ':fileResized'); + self::set('AM_KEY_WIDTH_RESIZED', ':widthResized'); + self::set('AM_KEY_HEIGHT_RESIZED', ':heightResized'); + self::set('AM_KEY_CAPTION', ':caption'); + self::set('AM_KEY_INDEX', ':i'); + self::set('AM_KEY_FILELIST_COUNT', ':filelistCount'); + self::set('AM_KEY_PAGELIST_COUNT', ':pagelistCount'); + self::set('AM_KEY_PAGELIST_DISPLAY_COUNT', ':pagelistDisplayCount'); + self::set('AM_KEY_PAGINATION_COUNT', ':paginationCount'); + self::set('AM_KEY_NOW', ':now'); + + // HEADLESS + self::set('AM_HEADLESS_ENABLED', false); + self::set('AM_HEADLESS_TEMPLATE', '/automad/headless/json.php'); + + // For security reasons, the custom template should not have the .php extension. + self::set('AM_HEADLESS_TEMPLATE_CUSTOM', '/config/headless.json'); + + // UPDATE + self::set('AM_UPDATE_ITEMS', '/automad, /lib, /index.php, /packages/standard, /packages/tutorial'); + self::set('AM_UPDATE_BRANCH', 'master'); + self::set('AM_UPDATE_REPO_DOWNLOAD_URL', 'https://github.com/marcantondahmen/automad/archive'); + self::set('AM_UPDATE_REPO_RAW_URL', 'https://raw.githubusercontent.com/marcantondahmen/automad'); + self::set('AM_UPDATE_REPO_VERSION_FILE', '/automad/version.php'); + self::set('AM_UPDATE_TEMP', AM_DIR_CACHE . '/update'); + + // Version number + include AM_BASE_DIR . '/automad/version.php'; + } + /** * Define constants based on the configuration array. */ diff --git a/automad/tests/bootstrap.php b/automad/tests/bootstrap.php index 20156b75b..c22a6ef41 100644 --- a/automad/tests/bootstrap.php +++ b/automad/tests/bootstrap.php @@ -6,6 +6,11 @@ define('AM_BASE_DIR', __DIR__ . '/../..'); define('AM_HEADLESS_TEMPLATE', '/automad/tests/templates/headless/json.php'); define('AM_HEADLESS_TEMPLATE_CUSTOM', AM_HEADLESS_TEMPLATE); + require_once AM_BASE_DIR . '/automad/src/Autoload.php'; Autoload::init(); -require AM_BASE_DIR . '/automad/const.php'; + +use Automad\Core\Config; + +Config::overrides(); +Config::defaults(); From c3d45493daa1cb277cb083b6c7646f858dce0508 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Fri, 3 Sep 2021 22:36:05 +0200 Subject: [PATCH 16/59] remove automad/README.md --- automad/README.md | 30 ------------------------------ 1 file changed, 30 deletions(-) delete mode 100644 automad/README.md diff --git a/automad/README.md b/automad/README.md deleted file mode 100644 index de6e5518c..000000000 --- a/automad/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# Automad Development Guide - -## PHP Naming Convention - -### Class Names and Class Files - -All namespaces and class names are `PascalCased`. All corresponding filenames are lowercase. There is no word separator in class names and filenames of classes which are autoloaded by the Automad autoloader. - - Automad\Core\FileSystem > automad/core/filesystem.php - -However, unit test classes use an underscore to separate the `_Test` suffix from the actual tested class name for better readability. The corresponding files are lowercase as well and keep the underscore. - - Automad\Core\Parse_Test > automad/tests/core/parse_test.php - -### Variables - -All class properties and normal variables are `camelCased`. Object variables of class instances are always named like the corresponding class and therefore are `PascalCased`. - - $this->pageCacheFile - $Automad = new Automad() - -### Methods - -All methods are `camelCased`. - - $Cache->pageCacheIsApproved() - -### Composer Packages - -Composer packages are excluded from Automad's internal naming convention in terms of directory structure, filenames and classes. \ No newline at end of file From 3866f2e5cd882d159b798f5898e51e6ccc139b73 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sat, 4 Sep 2021 14:34:35 +0200 Subject: [PATCH 17/59] refactor ui models and controllers --- automad/src/Core/Automad.php | 4 +- automad/src/Core/Cache.php | 4 +- automad/src/Core/Sitemap.php | 4 +- automad/src/UI/Commands/CreateUser.php | 8 +- .../UI/Components/Card/SearchFileResults.php | 20 ++-- automad/src/UI/Components/Card/User.php | 6 +- automad/src/UI/Components/Layout/PageData.php | 22 ++--- .../UI/Components/Layout/SearchResults.php | 6 +- .../src/UI/Components/Layout/SharedData.php | 8 +- automad/src/UI/Components/Nav/SiteTree.php | 4 +- automad/src/UI/Components/Status/Response.php | 12 +-- .../{Accounts.php => AccountsController.php} | 17 ++-- .../{Cache.php => CacheController.php} | 6 +- .../{Config.php => ConfigController.php} | 12 +-- ...ction.php => FileCollectionController.php} | 16 +-- .../{File.php => FileController.php} | 8 +- .../{Headless.php => HeadlessController.php} | 3 +- .../{Image.php => ImageController.php} | 12 +-- .../{InPage.php => InPageController.php} | 18 ++-- ...nager.php => PackageManagerController.php} | 2 +- .../{Page.php => PageController.php} | 42 ++++---- .../{Search.php => SearchController.php} | 16 +-- .../{Shared.php => SharedController.php} | 2 +- .../{Status.php => StatusController.php} | 2 +- .../{System.php => SystemController.php} | 2 +- .../Controllers/{UI.php => UIController.php} | 2 +- .../{User.php => UserController.php} | 48 ++------- automad/src/UI/Dashboard.php | 5 +- automad/src/UI/InPage.php | 8 +- .../{Accounts.php => AccountsModel.php} | 2 +- ...Collection.php => FileCollectionModel.php} | 4 +- .../src/UI/Models/{File.php => FileModel.php} | 6 +- .../UI/Models/{Image.php => ImageModel.php} | 8 +- .../UI/Models/{Links.php => LinksModel.php} | 22 ++--- .../src/UI/Models/{Page.php => PageModel.php} | 4 +- .../{Replacement.php => ReplacementModel.php} | 10 +- ...FieldResults.php => FieldResultsModel.php} | 2 +- .../{FileKeys.php => FileKeysModel.php} | 4 +- .../{FileResults.php => FileResultsModel.php} | 8 +- .../UI/Models/{Search.php => SearchModel.php} | 59 +++++------ .../Theme.php => Models/ThemeModel.php} | 6 +- .../ThemelistModel.php} | 15 ++- automad/src/UI/Models/UserModel.php | 99 +++++++++++++++++++ automad/src/UI/Views/CreateUser.php | 6 +- automad/src/UI/Views/Elements/Navbar.php | 6 +- automad/src/UI/Views/Elements/Sidebar.php | 6 +- automad/src/UI/Views/Login.php | 6 +- automad/src/UI/Views/Logout.php | 4 +- automad/src/UI/Views/View.php | 8 +- automad/tests/UI/Models/ReplacementTest.php | 8 +- automad/tests/UI/Models/SearchTest.php | 36 +++---- 51 files changed, 360 insertions(+), 288 deletions(-) rename automad/src/UI/Controllers/{Accounts.php => AccountsController.php} (90%) rename automad/src/UI/Controllers/{Cache.php => CacheController.php} (96%) rename automad/src/UI/Controllers/{Config.php => ConfigController.php} (95%) rename automad/src/UI/Controllers/{FileCollection.php => FileCollectionController.php} (85%) rename automad/src/UI/Controllers/{File.php => FileController.php} (95%) rename automad/src/UI/Controllers/{Headless.php => HeadlessController.php} (97%) rename automad/src/UI/Controllers/{Image.php => ImageController.php} (89%) rename automad/src/UI/Controllers/{InPage.php => InPageController.php} (90%) rename automad/src/UI/Controllers/{PackageManager.php => PackageManagerController.php} (99%) rename automad/src/UI/Controllers/{Page.php => PageController.php} (85%) rename automad/src/UI/Controllers/{Search.php => SearchController.php} (87%) rename automad/src/UI/Controllers/{Shared.php => SharedController.php} (99%) rename automad/src/UI/Controllers/{Status.php => StatusController.php} (98%) rename automad/src/UI/Controllers/{System.php => SystemController.php} (99%) rename automad/src/UI/Controllers/{UI.php => UIController.php} (99%) rename automad/src/UI/Controllers/{User.php => UserController.php} (74%) rename automad/src/UI/Models/{Accounts.php => AccountsModel.php} (99%) rename automad/src/UI/Models/{FileCollection.php => FileCollectionModel.php} (97%) rename automad/src/UI/Models/{File.php => FileModel.php} (98%) rename automad/src/UI/Models/{Image.php => ImageModel.php} (96%) rename automad/src/UI/Models/{Links.php => LinksModel.php} (74%) rename automad/src/UI/Models/{Page.php => PageModel.php} (99%) rename automad/src/UI/Models/{Replacement.php => ReplacementModel.php} (95%) rename automad/src/UI/Models/Search/{FieldResults.php => FieldResultsModel.php} (98%) rename automad/src/UI/Models/Search/{FileKeys.php => FileKeysModel.php} (96%) rename automad/src/UI/Models/Search/{FileResults.php => FileResultsModel.php} (92%) rename automad/src/UI/Models/{Search.php => SearchModel.php} (82%) rename automad/src/UI/{Controllers/Theme.php => Models/ThemeModel.php} (98%) rename automad/src/UI/{Controllers/Themelist.php => Models/ThemelistModel.php} (93%) create mode 100644 automad/src/UI/Models/UserModel.php diff --git a/automad/src/Core/Automad.php b/automad/src/Core/Automad.php index 1d60e8396..a00689464 100644 --- a/automad/src/Core/Automad.php +++ b/automad/src/Core/Automad.php @@ -36,7 +36,7 @@ namespace Automad\Core; -use Automad\UI\Controllers\User; +use Automad\UI\Models\UserModel; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -100,7 +100,7 @@ class Automad { public function __construct() { $this->getReservedUrls(); $this->Shared = new Shared(); - $this->user = User::get(); + $this->user = UserModel::getName(); $this->collectPages(); Debug::log(array('Shared' => $this->Shared, 'Collection' => $this->collection), 'New instance created'); diff --git a/automad/src/Core/Cache.php b/automad/src/Core/Cache.php index 8ad4b0d28..5d54faa96 100644 --- a/automad/src/Core/Cache.php +++ b/automad/src/Core/Cache.php @@ -36,7 +36,7 @@ namespace Automad\Core; -use Automad\UI\Controllers\User; +use Automad\UI\Models\UserModel; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -132,7 +132,7 @@ public function __construct() { $this->objectCacheFile = AM_FILE_OBJECT_CACHE; // Disable page caching for in-page edit mode and define ui cache file. - if (User::get()) { + if (UserModel::getName()) { $this->pageCachingIsEnabled = false; Debug::log('Page cache is disabled during editing.'); $this->objectCacheFile = AM_FILE_OBJECT_USER_CACHE; diff --git a/automad/src/Core/Sitemap.php b/automad/src/Core/Sitemap.php index 1ee3309f4..b1ff9636f 100644 --- a/automad/src/Core/Sitemap.php +++ b/automad/src/Core/Sitemap.php @@ -36,7 +36,7 @@ namespace Automad\Core; -use Automad\UI\Controllers\User; +use Automad\UI\Models\UserModel; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -54,7 +54,7 @@ class Sitemap { * @param array $collection */ public function __construct($collection) { - if (!User::get()) { + if (!UserModel::getName()) { $sitemap = AM_BASE_DIR . '/sitemap.xml'; // If the base dir is writable without having a sitemap.xml or if sitemap.xml exists and is writable itself. diff --git a/automad/src/UI/Commands/CreateUser.php b/automad/src/UI/Commands/CreateUser.php index 528a2c928..984b76db2 100644 --- a/automad/src/UI/Commands/CreateUser.php +++ b/automad/src/UI/Commands/CreateUser.php @@ -38,7 +38,7 @@ namespace Automad\UI\Commands; -use Automad\UI\Models\Accounts; +use Automad\UI\Models\AccountsModel; defined('AUTOMAD_CONSOLE') or die('Console only!' . PHP_EOL); @@ -85,16 +85,16 @@ public static function run() { echo 'Creating new user account for the Automad dashboard ...' . PHP_EOL . PHP_EOL; if (is_readable(AM_FILE_ACCOUNTS)) { - $accounts = Accounts::get(); + $accounts = AccountsModel::get(); } else { $accounts = array(); } $name = 'user_' . substr(str_shuffle(MD5(microtime())), 0, 5); $password = substr(str_shuffle(MD5(microtime())), 0, 10); - $accounts[$name] = Accounts::passwordHash($password); + $accounts[$name] = AccountsModel::passwordHash($password); - if (Accounts::write($accounts)) { + if (AccountsModel::write($accounts)) { echo '--------------------' . PHP_EOL; echo 'Name: ' . $name . PHP_EOL; echo 'Password: ' . $password . PHP_EOL; diff --git a/automad/src/UI/Components/Card/SearchFileResults.php b/automad/src/UI/Components/Card/SearchFileResults.php index 17abc6016..b2546231f 100644 --- a/automad/src/UI/Components/Card/SearchFileResults.php +++ b/automad/src/UI/Components/Card/SearchFileResults.php @@ -52,25 +52,25 @@ class SearchFileResults { /** * Render a search match card. * - * @param \Automad\UI\Models\Search\FileResults $FileResults + * @param \Automad\UI\Models\Search\FileResultsModel $FileResultsModel * @return string the rendered card */ - public static function render($FileResults) { - $dir = dirname($FileResults->path); + public static function render($FileResultsModel) { + $dir = dirname($FileResultsModel->path); $id = 'am-search-file-' . Str::slug($dir, true, 500); $results = ''; $keys = array(); - $editText = $FileResults->url; - $editUrl = '?view=Page&url=' . urlencode($FileResults->url); + $editText = $FileResultsModel->url; + $editUrl = '?view=Page&url=' . urlencode($FileResultsModel->url); - if (!$FileResults->url) { + if (!$FileResultsModel->url) { $editText = Text::get('shared_title'); $editUrl = '?view=Shared'; } - foreach ($FileResults->fieldResultsArray as $FieldResults) { - $keys[] = $FieldResults->key; - $results .= "
{$FieldResults->key}
{$FieldResults->context}"; + foreach ($FileResultsModel->fieldResultsArray as $FieldResultsModel) { + $keys[] = $FieldResultsModel->key; + $results .= "
{$FieldResultsModel->key}
{$FieldResultsModel->context}"; } $keysJson = json_encode($keys); @@ -85,7 +85,7 @@ public static function render($FileResults) {
$results diff --git a/automad/src/UI/Components/Card/User.php b/automad/src/UI/Components/Card/User.php index b29de40ff..ae54897b9 100644 --- a/automad/src/UI/Components/Card/User.php +++ b/automad/src/UI/Components/Card/User.php @@ -37,7 +37,7 @@ namespace Automad\UI\Components\Card; use Automad\Core\Str; -use Automad\UI\Controllers\User as ControllersUser; +use Automad\UI\Models\UserModel; use Automad\UI\Utils\Text; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -76,7 +76,7 @@ public static function render($user) { {$fn(self::checkbox($user, $id))}
-
+
HTML; } @@ -93,7 +93,7 @@ private static function checkbox($user, $id) { return $expression; }; - if ($user == ControllersUser::get()) { + if ($user == UserModel::getName()) { return <<< HTML - {$fn(SelectTemplate::render($this->Automad, $this->Themelist, 'theme_template', $this->data[AM_KEY_THEME], $this->Page->template))} + {$fn(SelectTemplate::render($this->Automad, $this->ThemelistModel, 'theme_template', $this->data[AM_KEY_THEME], $this->Page->template))} {$fn(About::render('am-about-modal'))} - {$fn(AddPage::render($this->Automad, $this->Themelist))} + {$fn(AddPage::render($this->Automad, $this->ThemelistModel))} HTML; } } diff --git a/automad/tests/UI/Models/ReplacementTest.php b/automad/tests/UI/Models/ReplacementTest.php index 1ba9caf51..e8a2e0323 100644 --- a/automad/tests/UI/Models/ReplacementTest.php +++ b/automad/tests/UI/Models/ReplacementTest.php @@ -6,7 +6,7 @@ use PHPUnit\Framework\TestCase; /** - * @testdox Automad\UI\Models\Replacement + * @testdox Automad\UI\Models\ReplacementModel */ class ReplacementTest extends TestCase { public function dataForTestReplaceInDataIsSame() { @@ -76,19 +76,19 @@ public function dataForTestReplaceInDataIsSame() { * @param mixed $expected */ public function testReplaceInDataIsSame($searchValue, $replaceValue, $isRegex, $isCaseSensitive, $keys, $data, $expected) { - $ReplacementReflection = new \ReflectionClass('\Automad\UI\Models\Replacement'); + $ReplacementReflection = new \ReflectionClass('\Automad\UI\Models\ReplacementModel'); $replaceInData = $ReplacementReflection->getMethod('replaceInData'); $replaceInData->setAccessible(true); - $Replacement = new Replacement( + $ReplacementModel = new ReplacementModel( $searchValue, $replaceValue, $isRegex, $isCaseSensitive ); - $replacedData = $replaceInData->invokeArgs($Replacement, array($data, $keys)); + $replacedData = $replaceInData->invokeArgs($ReplacementModel, array($data, $keys)); $this->assertSame( json_encode($replacedData, JSON_PRETTY_PRINT), diff --git a/automad/tests/UI/Models/SearchTest.php b/automad/tests/UI/Models/SearchTest.php index d04080c6e..d50755034 100644 --- a/automad/tests/UI/Models/SearchTest.php +++ b/automad/tests/UI/Models/SearchTest.php @@ -3,14 +3,14 @@ namespace Automad\UI\Models; use Automad\Test\Mock; -use Automad\UI\Models\Search\FieldResults; -use Automad\UI\Models\Search\FileResults; +use Automad\UI\Models\Search\FieldResultsModel; +use Automad\UI\Models\Search\FileResultsModel; use PHPUnit\Framework\TestCase; /** - * @testdox Automad\UI\Models\Search + * @testdox Automad\UI\Models\SearchModel */ -class Search_Test extends TestCase { +class SearchTest extends TestCase { public function dataForTestSearchPerFileIsSame() { return array( array( @@ -18,10 +18,10 @@ public function dataForTestSearchPerFileIsSame() { false, false, array( - new FileResults( + new FileResultsModel( '/pages/01.text/default.txt', array( - new FieldResults( + new FieldResultsModel( 'text', array('simple'), 'A simple sample text with a [link](/url/to/page)' @@ -29,10 +29,10 @@ public function dataForTestSearchPerFileIsSame() { ), '/text' ), - new FileResults( + new FileResultsModel( '/pages/01.blocks/default.txt', array( - new FieldResults( + new FieldResultsModel( '+main', array('Simple', 'simple'), 'A Simple First Column Table Header ... A simple paragraph text' @@ -47,10 +47,10 @@ public function dataForTestSearchPerFileIsSame() { false, true, array( - new FileResults( + new FileResultsModel( '/pages/01.blocks/default.txt', array( - new FieldResults( + new FieldResultsModel( '+main', array('Simple'), 'A Simple First Column Table Header' @@ -65,10 +65,10 @@ public function dataForTestSearchPerFileIsSame() { true, false, array( - new FileResults( + new FileResultsModel( '/pages/01.blocks/default.txt', array( - new FieldResults( + new FieldResultsModel( '+main', array('Simple First Column Table'), 'A Simple First Column Table Header' @@ -83,10 +83,10 @@ public function dataForTestSearchPerFileIsSame() { true, false, array( - new FileResults( + new FileResultsModel( '/shared/data.txt', array( - new FieldResults( + new FieldResultsModel( 'shared', array('default text content'), 'Shared default text content' @@ -107,10 +107,10 @@ public function dataForTestSearchPerFileIsSame() { true, false, array( - new FileResults( + new FileResultsModel( '/pages/01.blocks/default.txt', array( - new FieldResults( + new FieldResultsModel( '+main', array( 'Table Header', @@ -138,14 +138,14 @@ public function dataForTestSearchPerFileIsSame() { */ public function testSearchPerFileIsSame($searchValue, $isRegex, $isCaseSensitive, $expected) { $Mock = new Mock(); - $Search = new Search( + $SearchModel = new SearchModel( $Mock->createAutomad('default'), $searchValue, $isRegex, $isCaseSensitive ); - $results = $Search->searchPerFile(); + $results = $SearchModel->searchPerFile(); $this->assertSame( json_encode($results, JSON_PRETTY_PRINT), From bec7fb318e297ff03f9a4192c52e7bd3d9d0860e Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sat, 4 Sep 2021 14:40:10 +0200 Subject: [PATCH 18/59] refactor abstract classes --- automad/src/Blocks/{Block.php => AbstractBlock.php} | 2 +- automad/src/Blocks/Buttons.php | 2 +- automad/src/Blocks/Code.php | 2 +- automad/src/Blocks/Delimiter.php | 2 +- automad/src/Blocks/Embed.php | 2 +- automad/src/Blocks/Filelist.php | 2 +- automad/src/Blocks/Gallery.php | 2 +- automad/src/Blocks/Header.php | 2 +- automad/src/Blocks/Image.php | 2 +- automad/src/Blocks/Lists.php | 2 +- automad/src/Blocks/Mail.php | 2 +- automad/src/Blocks/Pagelist.php | 2 +- automad/src/Blocks/Paragraph.php | 2 +- automad/src/Blocks/Quote.php | 2 +- automad/src/Blocks/Raw.php | 2 +- automad/src/Blocks/Section.php | 2 +- automad/src/Blocks/Slider.php | 2 +- automad/src/Blocks/Table.php | 2 +- automad/src/Blocks/Toc.php | 2 +- automad/src/UI/Commands/{Command.php => AbstractCommand.php} | 2 +- automad/src/UI/Commands/ClearCache.php | 2 +- automad/src/UI/Commands/CreateUser.php | 2 +- automad/src/UI/Commands/Purge.php | 2 +- automad/src/UI/Commands/Update.php | 2 +- automad/src/UI/Views/{View.php => AbstractView.php} | 2 +- automad/src/UI/Views/CreateUser.php | 2 +- automad/src/UI/Views/Home.php | 2 +- automad/src/UI/Views/Login.php | 2 +- automad/src/UI/Views/Logout.php | 2 +- automad/src/UI/Views/Packages.php | 2 +- automad/src/UI/Views/Page.php | 2 +- automad/src/UI/Views/Search.php | 2 +- automad/src/UI/Views/Shared.php | 2 +- automad/src/UI/Views/System.php | 2 +- 34 files changed, 34 insertions(+), 34 deletions(-) rename automad/src/Blocks/{Block.php => AbstractBlock.php} (98%) rename automad/src/UI/Commands/{Command.php => AbstractCommand.php} (98%) rename automad/src/UI/Views/{View.php => AbstractView.php} (99%) diff --git a/automad/src/Blocks/Block.php b/automad/src/Blocks/AbstractBlock.php similarity index 98% rename from automad/src/Blocks/Block.php rename to automad/src/Blocks/AbstractBlock.php index 8e434fda1..34586a04b 100644 --- a/automad/src/Blocks/Block.php +++ b/automad/src/Blocks/AbstractBlock.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -abstract class Block { +abstract class AbstractBlock { /** * Render a paragraph block. * diff --git a/automad/src/Blocks/Buttons.php b/automad/src/Blocks/Buttons.php index ecfd4c739..18f1cd54c 100644 --- a/automad/src/Blocks/Buttons.php +++ b/automad/src/Blocks/Buttons.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Buttons extends Block { +class Buttons extends AbstractBlock { /** * Render a buttons block. * diff --git a/automad/src/Blocks/Code.php b/automad/src/Blocks/Code.php index e088cf1ae..9d55a6aaa 100644 --- a/automad/src/Blocks/Code.php +++ b/automad/src/Blocks/Code.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Code extends Block { +class Code extends AbstractBlock { /** * Render a code block. * diff --git a/automad/src/Blocks/Delimiter.php b/automad/src/Blocks/Delimiter.php index c3faa6b12..0b6c42e5c 100644 --- a/automad/src/Blocks/Delimiter.php +++ b/automad/src/Blocks/Delimiter.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Delimiter extends Block { +class Delimiter extends AbstractBlock { /** * Render a delimiter block. * diff --git a/automad/src/Blocks/Embed.php b/automad/src/Blocks/Embed.php index a10e55854..2aa9dfebd 100644 --- a/automad/src/Blocks/Embed.php +++ b/automad/src/Blocks/Embed.php @@ -47,7 +47,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Embed extends Block { +class Embed extends AbstractBlock { /** * Render a embed block. * diff --git a/automad/src/Blocks/Filelist.php b/automad/src/Blocks/Filelist.php index b9642616c..6b9d36e7e 100644 --- a/automad/src/Blocks/Filelist.php +++ b/automad/src/Blocks/Filelist.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Filelist extends Block { +class Filelist extends AbstractBlock { /** * Render a filelist block. * diff --git a/automad/src/Blocks/Gallery.php b/automad/src/Blocks/Gallery.php index f1393dc53..ae3325396 100644 --- a/automad/src/Blocks/Gallery.php +++ b/automad/src/Blocks/Gallery.php @@ -49,7 +49,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Gallery extends Block { +class Gallery extends AbstractBlock { /** * Render a gallery block. * diff --git a/automad/src/Blocks/Header.php b/automad/src/Blocks/Header.php index 4fc0f2e2a..c7ad3e410 100644 --- a/automad/src/Blocks/Header.php +++ b/automad/src/Blocks/Header.php @@ -47,7 +47,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Header extends Block { +class Header extends AbstractBlock { /** * Render a header block. * diff --git a/automad/src/Blocks/Image.php b/automad/src/Blocks/Image.php index 39404577a..1c7bc979a 100644 --- a/automad/src/Blocks/Image.php +++ b/automad/src/Blocks/Image.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Image extends Block { +class Image extends AbstractBlock { /** * Render an image block. * diff --git a/automad/src/Blocks/Lists.php b/automad/src/Blocks/Lists.php index cbefc706c..6aea20792 100644 --- a/automad/src/Blocks/Lists.php +++ b/automad/src/Blocks/Lists.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Lists extends Block { +class Lists extends AbstractBlock { /** * Render a list block. * diff --git a/automad/src/Blocks/Mail.php b/automad/src/Blocks/Mail.php index d2f2d596c..ec209f53e 100644 --- a/automad/src/Blocks/Mail.php +++ b/automad/src/Blocks/Mail.php @@ -47,7 +47,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Mail extends Block { +class Mail extends AbstractBlock { /** * Render a mail form block. * diff --git a/automad/src/Blocks/Pagelist.php b/automad/src/Blocks/Pagelist.php index 077c121ac..66b7d20cb 100644 --- a/automad/src/Blocks/Pagelist.php +++ b/automad/src/Blocks/Pagelist.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Pagelist extends Block { +class Pagelist extends AbstractBlock { /** * Render a pagelist block. * diff --git a/automad/src/Blocks/Paragraph.php b/automad/src/Blocks/Paragraph.php index 22562f368..d29528cd9 100644 --- a/automad/src/Blocks/Paragraph.php +++ b/automad/src/Blocks/Paragraph.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Paragraph extends Block { +class Paragraph extends AbstractBlock { /** * Render a paragraph block. * diff --git a/automad/src/Blocks/Quote.php b/automad/src/Blocks/Quote.php index 47da90122..ea4c88d3b 100644 --- a/automad/src/Blocks/Quote.php +++ b/automad/src/Blocks/Quote.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Quote extends Block { +class Quote extends AbstractBlock { /** * Render a quote block. * diff --git a/automad/src/Blocks/Raw.php b/automad/src/Blocks/Raw.php index bab0afad4..c76222242 100644 --- a/automad/src/Blocks/Raw.php +++ b/automad/src/Blocks/Raw.php @@ -47,7 +47,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Raw extends Block { +class Raw extends AbstractBlock { /** * Render a raw block. * diff --git a/automad/src/Blocks/Section.php b/automad/src/Blocks/Section.php index 95fb05f4b..983f221c9 100644 --- a/automad/src/Blocks/Section.php +++ b/automad/src/Blocks/Section.php @@ -47,7 +47,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Section extends Block { +class Section extends AbstractBlock { /** * Render a section editor block. * diff --git a/automad/src/Blocks/Slider.php b/automad/src/Blocks/Slider.php index 8363f1858..5581300b4 100644 --- a/automad/src/Blocks/Slider.php +++ b/automad/src/Blocks/Slider.php @@ -48,7 +48,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Slider extends Block { +class Slider extends AbstractBlock { /** * Render a slider block. * diff --git a/automad/src/Blocks/Table.php b/automad/src/Blocks/Table.php index fef975255..625b6aedc 100644 --- a/automad/src/Blocks/Table.php +++ b/automad/src/Blocks/Table.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Table extends Block { +class Table extends AbstractBlock { /** * Render a table block. * diff --git a/automad/src/Blocks/Toc.php b/automad/src/Blocks/Toc.php index 0fceb9119..c14841e9d 100644 --- a/automad/src/Blocks/Toc.php +++ b/automad/src/Blocks/Toc.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2020-2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Toc extends Block { +class Toc extends AbstractBlock { /** * Render a toc block. * diff --git a/automad/src/UI/Commands/Command.php b/automad/src/UI/Commands/AbstractCommand.php similarity index 98% rename from automad/src/UI/Commands/Command.php rename to automad/src/UI/Commands/AbstractCommand.php index eff9f8e8f..c8dbd4157 100644 --- a/automad/src/UI/Commands/Command.php +++ b/automad/src/UI/Commands/AbstractCommand.php @@ -45,7 +45,7 @@ * @copyright Copyright (c) 2021 Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -abstract class Command { +abstract class AbstractCommand { /** * Get the command help. * diff --git a/automad/src/UI/Commands/ClearCache.php b/automad/src/UI/Commands/ClearCache.php index c86ef25cf..d18c80eb5 100644 --- a/automad/src/UI/Commands/ClearCache.php +++ b/automad/src/UI/Commands/ClearCache.php @@ -47,7 +47,7 @@ * @copyright Copyright (c) 2021 Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class ClearCache extends Command { +class ClearCache extends AbstractCommand { /** * Get the command help. * diff --git a/automad/src/UI/Commands/CreateUser.php b/automad/src/UI/Commands/CreateUser.php index 984b76db2..54a549519 100644 --- a/automad/src/UI/Commands/CreateUser.php +++ b/automad/src/UI/Commands/CreateUser.php @@ -51,7 +51,7 @@ * @license MIT license - https://automad.org/license */ -class CreateUser extends Command { +class CreateUser extends AbstractCommand { /** diff --git a/automad/src/UI/Commands/Purge.php b/automad/src/UI/Commands/Purge.php index 13770df27..c003737d2 100644 --- a/automad/src/UI/Commands/Purge.php +++ b/automad/src/UI/Commands/Purge.php @@ -47,7 +47,7 @@ * @copyright Copyright (c) 2021 Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Purge extends Command { +class Purge extends AbstractCommand { /** * Get the command help. * diff --git a/automad/src/UI/Commands/Update.php b/automad/src/UI/Commands/Update.php index 03f57084f..3b144b0ce 100644 --- a/automad/src/UI/Commands/Update.php +++ b/automad/src/UI/Commands/Update.php @@ -47,7 +47,7 @@ * @copyright Copyright (c) 2018-2021 Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Update extends Command { +class Update extends AbstractCommand { /** * Get the command help. * diff --git a/automad/src/UI/Views/View.php b/automad/src/UI/Views/AbstractView.php similarity index 99% rename from automad/src/UI/Views/View.php rename to automad/src/UI/Views/AbstractView.php index db508918d..a21526de4 100644 --- a/automad/src/UI/Views/View.php +++ b/automad/src/UI/Views/AbstractView.php @@ -56,7 +56,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -abstract class View { +abstract class AbstractView { /** * The Automad object. */ diff --git a/automad/src/UI/Views/CreateUser.php b/automad/src/UI/Views/CreateUser.php index 5f1c89252..b11a2d5b5 100644 --- a/automad/src/UI/Views/CreateUser.php +++ b/automad/src/UI/Views/CreateUser.php @@ -48,7 +48,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class CreateUser extends View { +class CreateUser extends AbstractView { /** * Disable navbar and sidebar. */ diff --git a/automad/src/UI/Views/Home.php b/automad/src/UI/Views/Home.php index 3b712cd44..0792373fe 100644 --- a/automad/src/UI/Views/Home.php +++ b/automad/src/UI/Views/Home.php @@ -52,7 +52,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Home extends View { +class Home extends AbstractView { /** * Render body. * diff --git a/automad/src/UI/Views/Login.php b/automad/src/UI/Views/Login.php index 1fe04aea4..73f57c7ab 100644 --- a/automad/src/UI/Views/Login.php +++ b/automad/src/UI/Views/Login.php @@ -48,7 +48,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Login extends View { +class Login extends AbstractView { /** * Disable navbar and sidebar. */ diff --git a/automad/src/UI/Views/Logout.php b/automad/src/UI/Views/Logout.php index 954cebc91..76b120e21 100644 --- a/automad/src/UI/Views/Logout.php +++ b/automad/src/UI/Views/Logout.php @@ -50,7 +50,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Logout extends View { +class Logout extends AbstractView { /** * Disable navbar and sidebar. */ diff --git a/automad/src/UI/Views/Packages.php b/automad/src/UI/Views/Packages.php index 6650e658c..1d6533af5 100644 --- a/automad/src/UI/Views/Packages.php +++ b/automad/src/UI/Views/Packages.php @@ -47,7 +47,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Packages extends View { +class Packages extends AbstractView { /** * Render body. * diff --git a/automad/src/UI/Views/Page.php b/automad/src/UI/Views/Page.php index 4b5de07d9..0915c1b92 100644 --- a/automad/src/UI/Views/Page.php +++ b/automad/src/UI/Views/Page.php @@ -55,7 +55,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Page extends View { +class Page extends AbstractView { /** * Render body. * diff --git a/automad/src/UI/Views/Search.php b/automad/src/UI/Views/Search.php index ee8f566e0..873d4b6b3 100644 --- a/automad/src/UI/Views/Search.php +++ b/automad/src/UI/Views/Search.php @@ -48,7 +48,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Search extends View { +class Search extends AbstractView { /** * Render body. * diff --git a/automad/src/UI/Views/Shared.php b/automad/src/UI/Views/Shared.php index 6e52b8eb6..43647ba25 100644 --- a/automad/src/UI/Views/Shared.php +++ b/automad/src/UI/Views/Shared.php @@ -51,7 +51,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class Shared extends View { +class Shared extends AbstractView { /** * Render body. * diff --git a/automad/src/UI/Views/System.php b/automad/src/UI/Views/System.php index 42650e939..8e3ef1060 100644 --- a/automad/src/UI/Views/System.php +++ b/automad/src/UI/Views/System.php @@ -55,7 +55,7 @@ * @copyright Copyright (c) 2021 by Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ -class System extends View { +class System extends AbstractView { /** * Render body. * From 8abbf5107b1865a649a3bc05bf67006f3467e746 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sat, 4 Sep 2021 14:49:03 +0200 Subject: [PATCH 19/59] feat: set required PHP version to 7.2+ BREAKING CHANGE: PHP 7.2+ is now required --- automad/src/App.php | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/automad/src/App.php b/automad/src/App.php index 2eff5cb33..4d01858bf 100644 --- a/automad/src/App.php +++ b/automad/src/App.php @@ -60,7 +60,7 @@ class App { /** * Required PHP version. */ - private $requiredVersion = '5.6.0'; + private $requiredVersion = '7.2.0'; /** * The main app constructor takes care of running all required startup tests, diff --git a/composer.json b/composer.json index 075d6f58b..0547e7507 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "post-create-project-cmd": "@php automad/console createuser" }, "require": { - "php": ">=5.6", + "php": ">=7.2", "automad/package-installer": "^1.1" } } From 2ca715d4e00ee7b44d26a7397574959bc2d116fd Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sat, 4 Sep 2021 15:07:06 +0200 Subject: [PATCH 20/59] fix self references in Core\Config --- automad/src/Core/Config.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/automad/src/Core/Config.php b/automad/src/Core/Config.php index cdca3be77..6fc8eeae4 100644 --- a/automad/src/Core/Config.php +++ b/automad/src/Core/Config.php @@ -56,18 +56,18 @@ class Config { */ public static function defaults() { // Define debugging already here to be available when parsing the request. - Config::set('AM_DEBUG_ENABLED', false); + self::set('AM_DEBUG_ENABLED', false); // Set base URL for all URLs relative to the root. if (getenv('HTTP_X_FORWARDED_HOST') || getenv('HTTP_X_FORWARDED_SERVER')) { // In case the site is behind a proxy, set AM_BASE_URL to AM_BASE_PROXY. // AM_BASE_PROXY can be separately defined to enable running a site with and without a proxy in parallel. - Config::set('AM_BASE_PROXY', ''); - Config::set('AM_BASE_URL', AM_BASE_PROXY); + self::set('AM_BASE_PROXY', ''); + self::set('AM_BASE_URL', AM_BASE_PROXY); Debug::log(getenv('HTTP_X_FORWARDED_SERVER'), 'Proxy'); } else { // In case the site is not running behind a proxy server, just get the base URL from the script name. - Config::set('AM_BASE_URL', str_replace('/index.php', '', getenv('SCRIPT_NAME'))); + self::set('AM_BASE_URL', str_replace('/index.php', '', getenv('SCRIPT_NAME'))); } Debug::log(getenv('SERVER_SOFTWARE'), 'Server Software'); @@ -75,16 +75,16 @@ public static function defaults() { // Check whether pretty URLs are enabled. if ((strpos(strtolower(getenv('SERVER_SOFTWARE')), 'apache') !== false && file_exists(AM_BASE_DIR . '/.htaccess')) || strpos(strtolower(getenv('SERVER_SOFTWARE')), 'nginx') !== false) { // If .htaccess exists on Apache or the server software is Nginx, assume that pretty URLs are enabled and AM_INDEX is empty. - Config::set('AM_INDEX', ''); + self::set('AM_INDEX', ''); Debug::log('Pretty URLs are enabled.'); } else { // For all other environments, AM_INDEX will be defined as fallback and pretty URLs are disabled. - Config::set('AM_INDEX', '/index.php'); + self::set('AM_INDEX', '/index.php'); Debug::log('Pretty URLs are disabled'); } // Define AM_BASE_INDEX as the prefix for all page URLs. - Config::set('AM_BASE_INDEX', AM_BASE_URL . AM_INDEX); + self::set('AM_BASE_INDEX', AM_BASE_URL . AM_INDEX); // An optional base protocol/domain combination for the sitemap.xml in case of being behind a proxy. self::set('AM_BASE_SITEMAP', ''); From 92ee97b5986ef6f47c0e2424632d9b2bdacda4a4 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sat, 4 Sep 2021 22:20:15 +0200 Subject: [PATCH 21/59] fix formatting of CreateUser command --- automad/src/UI/Commands/CreateUser.php | 33 +++++++------------------- 1 file changed, 9 insertions(+), 24 deletions(-) diff --git a/automad/src/UI/Commands/CreateUser.php b/automad/src/UI/Commands/CreateUser.php index 54a549519..8a3be1ba8 100644 --- a/automad/src/UI/Commands/CreateUser.php +++ b/automad/src/UI/Commands/CreateUser.php @@ -23,7 +23,7 @@ * :::: :::: ..'' * :::: ..:::: .:'' * '''' ''''' - * + * * * AUTOMAD * @@ -34,15 +34,12 @@ * https://automad.org/license */ - - namespace Automad\UI\Commands; use Automad\UI\Models\AccountsModel; defined('AUTOMAD_CONSOLE') or die('Console only!' . PHP_EOL); - /** * The createuser command. * @@ -50,38 +47,29 @@ * @copyright Copyright (c) 2018-2021 Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ - class CreateUser extends AbstractCommand { - - - /** - * Get the command name. - * - * @return string the command name - */ - - public static function name() { - return 'createuser'; - } - - /** * Get the command help. * * @return string the command help */ - public static function help() { return 'Create a new user with a random name and password.'; } + /** + * Get the command name. + * + * @return string the command name + */ + public static function name() { + return 'createuser'; + } /** * The actual command action. */ - public static function run() { - echo 'Creating new user account for the Automad dashboard ...' . PHP_EOL . PHP_EOL; if (is_readable(AM_FILE_ACCOUNTS)) { @@ -102,8 +90,5 @@ public static function run() { } else { echo 'Error! Creating of user account failed.' . PHP_EOL; } - } - - } From 826a3fd077bc000e0ed2f89284fc25fe3a58c6e9 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sat, 4 Sep 2021 22:32:54 +0200 Subject: [PATCH 22/59] move theme and themelist classes to UI\Utils namespace --- automad/src/UI/Components/Layout/PageData.php | 14 +++++++------- automad/src/UI/Components/Layout/SharedData.php | 8 ++++---- .../UI/{Models/ThemeModel.php => Utils/Theme.php} | 13 ++++++------- .../ThemelistModel.php => Utils/Themelist.php} | 15 +++++++-------- automad/src/UI/Views/AbstractView.php | 8 ++++---- 5 files changed, 28 insertions(+), 30 deletions(-) rename automad/src/UI/{Models/ThemeModel.php => Utils/Theme.php} (94%) rename automad/src/UI/{Models/ThemelistModel.php => Utils/Themelist.php} (92%) diff --git a/automad/src/UI/Components/Layout/PageData.php b/automad/src/UI/Components/Layout/PageData.php index 91a0f5bcc..955c857a8 100644 --- a/automad/src/UI/Components/Layout/PageData.php +++ b/automad/src/UI/Components/Layout/PageData.php @@ -46,9 +46,9 @@ use Automad\UI\Components\Form\Field; use Automad\UI\Components\Form\SelectTemplate; use Automad\UI\Models\PageModel; -use Automad\UI\Models\ThemelistModel; use Automad\UI\Utils\Keys; use Automad\UI\Utils\Text; +use Automad\UI\Utils\Themelist; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -108,7 +108,7 @@ class PageData { /** * The themelist object. */ - private $ThemelistModel = null; + private $Themelist = null; /** * All unused variable keys. @@ -131,7 +131,7 @@ public function __construct($Automad, $Page) { $this->Page = $Page; $this->data = Parse::textFile(PageModel::getPageFilePath($Page)); $this->url = $Page->get(AM_KEY_URL); - $this->ThemelistModel = new ThemelistModel(); + $this->Themelist = new Themelist(); $this->fn = function ($expression) { return $expression; @@ -161,7 +161,7 @@ public function __construct($Automad, $Page) { // All other fields. if (!AM_HEADLESS_ENABLED) { - $keys = Keys::inCurrentTemplate($Page, $this->ThemelistModel->getThemeByKey($Page->get(AM_KEY_THEME))); + $keys = Keys::inCurrentTemplate($Page, $this->Themelist->getThemeByKey($Page->get(AM_KEY_THEME))); } else { $keys = Keys::inTemplate(Headless::getTemplate()); } @@ -179,7 +179,7 @@ public function __construct($Automad, $Page) { */ public function render() { $fn = $this->fn; - $Theme = $this->ThemelistModel->getThemeByKey($this->Page->get(AM_KEY_THEME)); + $Theme = $this->Themelist->getThemeByKey($this->Page->get(AM_KEY_THEME)); return <<< HTML {$fn($this->title())} @@ -306,7 +306,7 @@ private function selectTemplate() { if ($this->data[AM_KEY_THEME]) { $themePath = $this->data[AM_KEY_THEME]; - if ($Theme = $this->ThemelistModel->getThemeByKey($this->data[AM_KEY_THEME])) { + if ($Theme = $this->Themelist->getThemeByKey($this->data[AM_KEY_THEME])) { $themeName = $Theme->name . ' / '; } } @@ -330,7 +330,7 @@ private function selectTemplate() { {$fn(Text::get('page_theme_template'))}
- {$fn(SelectTemplate::render($this->Automad, $this->ThemelistModel, 'theme_template', $this->data[AM_KEY_THEME], $this->Page->template))} + {$fn(SelectTemplate::render($this->Automad, $this->Themelist, 'theme_template', $this->data[AM_KEY_THEME], $this->Page->template))} {$fn(About::render('am-about-modal'))} - {$fn(AddPage::render($this->Automad, $this->ThemelistModel))} + {$fn(AddPage::render($this->Automad, $this->Themelist))} HTML; } } From 32d0a55eb87927cf0f762352dde91f31a6921542 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sat, 4 Sep 2021 23:44:26 +0200 Subject: [PATCH 23/59] move theme and themelist classes to System namespace --- automad/src/{UI/Utils => System}/Theme.php | 3 ++- automad/src/{UI/Utils => System}/Themelist.php | 3 ++- automad/src/UI/Components/Layout/PageData.php | 2 +- automad/src/UI/Components/Layout/SharedData.php | 2 +- automad/src/UI/Views/AbstractView.php | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) rename automad/src/{UI/Utils => System}/Theme.php (98%) rename automad/src/{UI/Utils => System}/Themelist.php (98%) diff --git a/automad/src/UI/Utils/Theme.php b/automad/src/System/Theme.php similarity index 98% rename from automad/src/UI/Utils/Theme.php rename to automad/src/System/Theme.php index e77345a97..8215c7174 100644 --- a/automad/src/UI/Utils/Theme.php +++ b/automad/src/System/Theme.php @@ -34,8 +34,9 @@ * https://automad.org/license */ -namespace Automad\UI\Utils; +namespace Automad\System; +use Automad\Core\FileSystem; use Automad\Core\Str; defined('AUTOMAD') or die('Direct access not permitted!'); diff --git a/automad/src/UI/Utils/Themelist.php b/automad/src/System/Themelist.php similarity index 98% rename from automad/src/UI/Utils/Themelist.php rename to automad/src/System/Themelist.php index cc64214a3..e5ee207ed 100644 --- a/automad/src/UI/Utils/Themelist.php +++ b/automad/src/System/Themelist.php @@ -34,9 +34,10 @@ * https://automad.org/license */ -namespace Automad\UI\Utils; +namespace Automad\System; use Automad\Core\Debug; +use Automad\Core\FileSystem; use Automad\Core\Str; defined('AUTOMAD') or die('Direct access not permitted!'); diff --git a/automad/src/UI/Components/Layout/PageData.php b/automad/src/UI/Components/Layout/PageData.php index 955c857a8..f6bbd3656 100644 --- a/automad/src/UI/Components/Layout/PageData.php +++ b/automad/src/UI/Components/Layout/PageData.php @@ -38,6 +38,7 @@ use Automad\Core\Headless; use Automad\Core\Parse; +use Automad\System\Themelist; use Automad\UI\Components\Accordion\UnusedVariables; use Automad\UI\Components\Accordion\Variables; use Automad\UI\Components\Alert\ThemeReadme; @@ -48,7 +49,6 @@ use Automad\UI\Models\PageModel; use Automad\UI\Utils\Keys; use Automad\UI\Utils\Text; -use Automad\UI\Utils\Themelist; defined('AUTOMAD') or die('Direct access not permitted!'); diff --git a/automad/src/UI/Components/Layout/SharedData.php b/automad/src/UI/Components/Layout/SharedData.php index b7bf0a0de..83ec153b1 100644 --- a/automad/src/UI/Components/Layout/SharedData.php +++ b/automad/src/UI/Components/Layout/SharedData.php @@ -37,6 +37,7 @@ namespace Automad\UI\Components\Layout; use Automad\Core\Debug; +use Automad\System\Themelist; use Automad\UI\Components\Accordion\UnusedVariables; use Automad\UI\Components\Accordion\Variables; use Automad\UI\Components\Alert\ThemeReadme; @@ -44,7 +45,6 @@ use Automad\UI\Components\Form\FieldHidden; use Automad\UI\Utils\Keys; use Automad\UI\Utils\Text; -use Automad\UI\Utils\Themelist; defined('AUTOMAD') or die('Direct access not permitted!'); diff --git a/automad/src/UI/Views/AbstractView.php b/automad/src/UI/Views/AbstractView.php index e5cb80097..9ee1e10b3 100644 --- a/automad/src/UI/Views/AbstractView.php +++ b/automad/src/UI/Views/AbstractView.php @@ -37,6 +37,7 @@ namespace Automad\UI\Views; use Automad\Core\Str; +use Automad\System\Themelist; use Automad\UI\Components\Header\BlockSnippetArrays; use Automad\UI\Components\Header\EditorTextModules; use Automad\UI\Components\Modal\About; @@ -44,7 +45,6 @@ use Automad\UI\Views\Elements\Navbar; use Automad\UI\Views\Elements\Sidebar; use Automad\UI\Utils\Text; -use Automad\UI\Utils\Themelist; use Automad\UI\Utils\UICache; defined('AUTOMAD') or die('Direct access not permitted!'); From ba477eae7cdc2d60529d0299547b142d1ab8147b Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sun, 5 Sep 2021 20:25:52 +0200 Subject: [PATCH 24/59] replace AM_CONFIG constant with Config::$file --- automad/src/App.php | 2 -- automad/src/Core/Config.php | 13 +++++++++---- automad/src/UI/Components/Modal/EditConfig.php | 3 ++- automad/src/UI/Controllers/ConfigController.php | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/automad/src/App.php b/automad/src/App.php index 4d01858bf..47b31cf1f 100644 --- a/automad/src/App.php +++ b/automad/src/App.php @@ -77,8 +77,6 @@ public function __construct() { require_once __DIR__ . '/Autoload.php'; Autoload::init(); - define('AM_CONFIG', AM_BASE_DIR . '/config/config.php'); - Config::overrides(); Config::defaults(); diff --git a/automad/src/Core/Config.php b/automad/src/Core/Config.php index 6fc8eeae4..4646d2862 100644 --- a/automad/src/Core/Config.php +++ b/automad/src/Core/Config.php @@ -46,6 +46,11 @@ * @license MIT license - https://automad.org/license */ class Config { + /** + * The configuration file. + */ + public static $file = AM_BASE_DIR . '/config/config.php'; + /** * The legacy .json file. */ @@ -243,8 +248,8 @@ public static function read() { $json = false; $config = array(); - if (is_readable(AM_CONFIG)) { - $json = require AM_CONFIG; + if (is_readable(self::$file)) { + $json = require self::$file; } elseif (is_readable(self::$legacy)) { // Support legacy configuration files. $json = file_get_contents(self::$legacy); @@ -278,14 +283,14 @@ public static function set($name, $value) { public static function write($config) { $json = json_encode($config, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES); $content = " diff --git a/automad/src/UI/Controllers/ConfigController.php b/automad/src/UI/Controllers/ConfigController.php index 27ab6d7f3..c9e50699c 100644 --- a/automad/src/UI/Controllers/ConfigController.php +++ b/automad/src/UI/Controllers/ConfigController.php @@ -75,7 +75,7 @@ public static function save() { Cache::clear(); $Response->setReload(true); } else { - $Response->setError(Text::get('error_permission') . '
' . AM_CONFIG); + $Response->setError(Text::get('error_permission') . '
' . Config::$file); } } else { $Response->setError(Text::get('error_json')); @@ -161,7 +161,7 @@ public static function update() { $Response->setSuccess(Text::get('success_config_update')); Cache::clear(); } else { - $Response->setError(Text::get('error_permission') . '
' . AM_CONFIG); + $Response->setError(Text::get('error_permission') . '
' . Config::$file); } return $Response; From b3b54130bc1b603a1834851876a2a6c396288523 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sun, 5 Sep 2021 22:43:14 +0200 Subject: [PATCH 25/59] fix(ui): debounce status requests --- automad/ui/js/Status.js | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/automad/ui/js/Status.js b/automad/ui/js/Status.js index 32dfcfa74..c3013d635 100644 --- a/automad/ui/js/Status.js +++ b/automad/ui/js/Status.js @@ -37,12 +37,12 @@ * Get system status items. * * To get the status of any config setting (constant), - * the container has to have a 'data-am-status' attribute. - * The requested item for each container is then passed via - * 'data-am-status="item"'. + * the container has to have a 'data-am-status' attribute. + * The requested item for each container is then passed via + * 'data-am-status="item"'. */ -+(function (Automad, $) { ++(function (Automad, $, UIkit) { Automad.Status = { dataAttr: 'data-am-status', @@ -74,23 +74,25 @@ s.get(); }); - $doc.ajaxComplete(function (e, xhr, settings) { - var triggers = [ - '?controller=Accounts::edit', - '?controller=Accounts::add', - '?controller=Headless::editTemplate', - '?controller=Headless::resetTemplate', - '?controller=Config::update', - '?controller=PackageManager::getPackages', - '?controller=System::update', - ]; + $doc.ajaxComplete( + UIkit.Utils.debounce(function (e, xhr, settings) { + var triggers = [ + '?controller=Accounts::edit', + '?controller=Accounts::add', + '?controller=Headless::editTemplate', + '?controller=Headless::resetTemplate', + '?controller=Config::update', + '?controller=PackageManager::getPackages', + '?controller=System::update', + ]; - if (triggers.includes(settings.url)) { - s.get(); - } - }); + if (triggers.includes(settings.url)) { + s.get(); + } + }, 1000) + ); }, }; Automad.Status.init(); -})((window.Automad = window.Automad || {}), jQuery); +})((window.Automad = window.Automad || {}), jQuery, UIkit); From ba05def883ef148c8ce5baef92d39db38025fd2e Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sun, 5 Sep 2021 23:10:39 +0200 Subject: [PATCH 26/59] implement controller error handler --- automad/src/UI/Dashboard.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/automad/src/UI/Dashboard.php b/automad/src/UI/Dashboard.php index 513a1a84b..a97a835c2 100644 --- a/automad/src/UI/Dashboard.php +++ b/automad/src/UI/Dashboard.php @@ -78,10 +78,11 @@ public function __construct() { header('Content-Type: application/json; charset=utf-8'); if (!empty($parts[1]) && $this->classFileExists($class) && method_exists($class, $parts[1])) { + $this->registerControllerErrorHandler(); $Response = call_user_func($method); $Response->setDebug(Debug::getLog()); } else { - header('HTTP/1.0 404 Not Found'); + http_response_code(404); $Response = new Response(); } @@ -150,4 +151,20 @@ private function classFileExists($className) { return is_readable($file); } + + /** + * Register a error handler that sends a 500 response code in case of a fatal error created by a controller. + */ + private function registerControllerErrorHandler() { + error_reporting(0); + + register_shutdown_function(function () { + $error = error_get_last(); + + if (is_array($error) && !empty($error['type'])) { + http_response_code(500); + exit(json_encode($error, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); + } + }); + } } From a6da525ee7af0c350d9c65513b5c49198118766b Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sun, 5 Sep 2021 23:30:27 +0200 Subject: [PATCH 27/59] fix console autoloading --- automad/console | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/automad/console b/automad/console index a31f2d922..d3fc76d89 100755 --- a/automad/console +++ b/automad/console @@ -35,6 +35,8 @@ * http://automad.org/license */ +use Automad\Autoload; +use Automad\Core\Config; use Automad\UI\Console; if (http_response_code() || !defined('STDIN')) { @@ -45,7 +47,10 @@ define('AUTOMAD', true); define('AUTOMAD_CONSOLE', true); define('AM_BASE_DIR', dirname(dirname(__FILE__))); -require AM_BASE_DIR . '/automad/autoload.php'; -require AM_BASE_DIR . '/automad/const.php'; +require_once AM_BASE_DIR . '/automad/src/Autoload.php'; + +Autoload::init(); +Config::overrides(); +Config::defaults(); $console = new Console($argv); From 716efacc27dd30c3ed28bccd5ef836ba6bd6dddd Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sun, 5 Sep 2021 23:30:57 +0200 Subject: [PATCH 28/59] fix console command list --- automad/src/UI/Console.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/automad/src/UI/Console.php b/automad/src/UI/Console.php index fb3bb7365..e03227d1d 100644 --- a/automad/src/UI/Console.php +++ b/automad/src/UI/Console.php @@ -72,7 +72,7 @@ private function getCommands() { } $classList = array_filter(get_declared_classes(), function ($cls) { - return (strpos($cls, 'Automad\UI\Commands') !== false && strpos($cls, 'Commands\Command') === false); + return (strpos($cls, 'Automad\UI\Commands') !== false && strpos($cls, 'Commands\AbstractCommand') === false); }); $commands = array(); From 4e95704e517806f409522e62ca0b630289fb1beb Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sun, 5 Sep 2021 23:32:25 +0200 Subject: [PATCH 29/59] refactor use statements in tests bootstrap file --- automad/tests/bootstrap.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/automad/tests/bootstrap.php b/automad/tests/bootstrap.php index c22a6ef41..1b6599795 100644 --- a/automad/tests/bootstrap.php +++ b/automad/tests/bootstrap.php @@ -1,6 +1,7 @@ Date: Sun, 5 Sep 2021 23:33:05 +0200 Subject: [PATCH 30/59] style: update php-cs-fixer config --- .php-cs-fixer.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index f6d7f2464..455c86a7d 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -18,6 +18,8 @@ 'ordered_class_elements' => array( 'sort_algorithm' => 'alpha' ), + 'ordered_imports' => true, + 'function_typehint_space' => true, 'method_argument_space' => array( 'on_multiline' => 'ensure_fully_multiline', 'after_heredoc' => true @@ -42,14 +44,25 @@ 'no_trailing_whitespace' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, - 'phpdoc_add_missing_param_annotation' => true, + 'nullable_type_declaration_for_default_null_value' => array( + 'use_nullable_type_declaration' => true + ), + 'phpdoc_add_missing_param_annotation' => array( + 'only_untyped' => false + ), 'phpdoc_align' => array( 'align' => 'left' ), 'phpdoc_indent' => true, 'phpdoc_order' => true, + 'phpdoc_scalar' => true, 'phpdoc_trim' => true, + 'phpdoc_trim_consecutive_blank_line_separation' => true, 'return_type_declaration' => true, + 'phpdoc_types' => true, + 'phpdoc_types_order' => array( + 'null_adjustment' => 'always_last' + ), 'single_blank_line_before_namespace' => true, 'single_blank_line_at_eof' => true, 'single_line_after_imports' => true, From bbc55f1b8813d2b6d2b60685329f6a4ae169c7c8 Mon Sep 17 00:00:00 2001 From: Marc Anton Dahmen Date: Sun, 5 Sep 2021 23:46:48 +0200 Subject: [PATCH 31/59] add header to Test\Mock class --- automad/src/Test/Mock.php | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/automad/src/Test/Mock.php b/automad/src/Test/Mock.php index e69316cfb..df1082089 100644 --- a/automad/src/Test/Mock.php +++ b/automad/src/Test/Mock.php @@ -1,4 +1,38 @@ Date: Sun, 5 Sep 2021 23:59:50 +0200 Subject: [PATCH 32/59] add type hints and update doc blocks --- automad/src/Blocks/AbstractBlock.php | 8 +- automad/src/Blocks/Buttons.php | 6 +- automad/src/Blocks/Code.php | 6 +- automad/src/Blocks/Delimiter.php | 6 +- automad/src/Blocks/Embed.php | 5 +- automad/src/Blocks/Filelist.php | 6 +- automad/src/Blocks/Gallery.php | 5 +- automad/src/Blocks/Header.php | 5 +- automad/src/Blocks/Image.php | 6 +- automad/src/Blocks/Lists.php | 6 +- automad/src/Blocks/Mail.php | 5 +- automad/src/Blocks/Pagelist.php | 6 +- automad/src/Blocks/Paragraph.php | 6 +- automad/src/Blocks/Quote.php | 6 +- automad/src/Blocks/Raw.php | 5 +- automad/src/Blocks/Section.php | 5 +- automad/src/Blocks/Slider.php | 5 +- automad/src/Blocks/Snippet.php | 5 +- automad/src/Blocks/Table.php | 6 +- automad/src/Blocks/Toc.php | 6 +- automad/src/Core/Automad.php | 38 +++--- automad/src/Core/Blocks.php | 14 +- automad/src/Core/Cache.php | 23 ++-- automad/src/Core/Config.php | 8 +- automad/src/Core/Context.php | 18 +-- automad/src/Core/Debug.php | 2 +- automad/src/Core/Extension.php | 28 ++-- automad/src/Core/FileSystem.php | 40 +++--- automad/src/Core/Filelist.php | 6 +- automad/src/Core/Headless.php | 4 +- automad/src/Core/Image.php | 8 +- automad/src/Core/Page.php | 26 ++-- automad/src/Core/Pagelist.php | 18 +-- automad/src/Core/Parse.php | 18 +-- automad/src/Core/Pipe.php | 8 +- automad/src/Core/Regex.php | 52 ++++---- automad/src/Core/RemoteFile.php | 4 +- automad/src/Core/Request.php | 6 +- automad/src/Core/Resolve.php | 11 +- automad/src/Core/Runtime.php | 10 +- automad/src/Core/Selection.php | 50 ++++---- automad/src/Core/SessionData.php | 8 +- automad/src/Core/Shared.php | 6 +- automad/src/Core/Sitemap.php | 4 +- automad/src/Core/Str.php | 90 ++++++------- automad/src/Core/Toolbox.php | 99 +++++++------- automad/src/Core/View.php | 121 +++++++++--------- automad/src/System/Composer.php | 20 +-- automad/src/System/Mail.php | 8 +- automad/src/System/Packagist.php | 8 +- automad/src/System/Theme.php | 12 +- automad/src/System/Themelist.php | 13 +- automad/src/System/Update.php | 22 ++-- automad/src/Test/Mock.php | 6 +- .../Components/Accordion/UnusedVariables.php | 5 +- .../src/UI/Components/Accordion/Variables.php | 8 +- automad/src/UI/Components/Alert/Alert.php | 2 +- automad/src/UI/Components/Alert/Danger.php | 2 +- automad/src/UI/Components/Alert/Success.php | 2 +- .../src/UI/Components/Alert/ThemeReadme.php | 5 +- .../UI/Components/Autocomplete/Jumpbar.php | 9 +- .../src/UI/Components/Autocomplete/Link.php | 7 +- automad/src/UI/Components/Card/File.php | 6 +- automad/src/UI/Components/Card/Package.php | 2 +- automad/src/UI/Components/Card/Page.php | 11 +- .../UI/Components/Card/SearchFileResults.php | 5 +- automad/src/UI/Components/Card/Theme.php | 7 +- automad/src/UI/Components/Card/User.php | 4 +- .../src/UI/Components/Form/CheckboxHidden.php | 4 +- .../UI/Components/Form/CheckboxPrivate.php | 4 +- automad/src/UI/Components/Form/Field.php | 47 +++---- .../src/UI/Components/Form/FieldHidden.php | 2 +- automad/src/UI/Components/Form/Group.php | 10 +- .../src/UI/Components/Form/HeadlessEditor.php | 2 +- automad/src/UI/Components/Form/Select.php | 2 +- .../src/UI/Components/Form/SelectImage.php | 4 +- .../src/UI/Components/Form/SelectTemplate.php | 12 +- automad/src/UI/Components/Fullscreen/Bar.php | 2 +- automad/src/UI/Components/Grid/Files.php | 2 +- automad/src/UI/Components/Grid/Packages.php | 2 +- automad/src/UI/Components/Grid/Pages.php | 2 +- automad/src/UI/Components/Grid/Users.php | 2 +- automad/src/UI/Components/InPage/Edit.php | 5 +- .../UI/Components/Layout/FileCollection.php | 8 +- automad/src/UI/Components/Layout/Packages.php | 2 +- automad/src/UI/Components/Layout/PageData.php | 21 ++- .../UI/Components/Layout/SearchResults.php | 2 +- .../src/UI/Components/Layout/SelectImage.php | 2 +- .../src/UI/Components/Layout/SharedData.php | 5 +- .../src/UI/Components/Layout/SystemUpdate.php | 2 +- automad/src/UI/Components/Modal/About.php | 4 +- automad/src/UI/Components/Modal/AddPage.php | 10 +- .../src/UI/Components/Modal/CopyResized.php | 4 +- .../src/UI/Components/Modal/EditConfig.php | 4 +- .../src/UI/Components/Modal/EditFileInfo.php | 6 +- automad/src/UI/Components/Modal/Import.php | 8 +- automad/src/UI/Components/Modal/Link.php | 4 +- automad/src/UI/Components/Modal/Readme.php | 4 +- .../src/UI/Components/Modal/SelectImage.php | 8 +- automad/src/UI/Components/Modal/Upload.php | 8 +- automad/src/UI/Components/Nav/Breadcrumbs.php | 5 +- automad/src/UI/Components/Nav/Jumpbar.php | 2 +- automad/src/UI/Components/Nav/SiteTree.php | 9 +- automad/src/UI/Components/Nav/Switcher.php | 4 +- automad/src/UI/Components/Status/Button.php | 4 +- automad/src/UI/Components/Status/Response.php | 6 +- automad/src/UI/Components/Status/Span.php | 4 +- automad/src/UI/Components/System/Cache.php | 2 +- automad/src/UI/Components/System/Debug.php | 2 +- automad/src/UI/Components/System/Headless.php | 2 +- automad/src/UI/Components/System/Language.php | 2 +- automad/src/UI/Components/System/Update.php | 2 +- automad/src/UI/Components/System/Users.php | 2 +- automad/src/UI/Console.php | 6 +- .../src/UI/Controllers/AccountsController.php | 16 +-- .../src/UI/Controllers/CacheController.php | 4 +- .../src/UI/Controllers/ConfigController.php | 4 +- automad/src/UI/Controllers/FileController.php | 4 +- .../src/UI/Controllers/HeadlessController.php | 4 +- .../src/UI/Controllers/InPageController.php | 2 +- .../Controllers/PackageManagerController.php | 12 +- automad/src/UI/Controllers/PageController.php | 21 +-- .../src/UI/Controllers/SearchController.php | 2 +- .../src/UI/Controllers/SharedController.php | 9 +- .../src/UI/Controllers/StatusController.php | 2 +- .../src/UI/Controllers/SystemController.php | 2 +- automad/src/UI/Controllers/UIController.php | 8 +- automad/src/UI/Controllers/UserController.php | 2 +- automad/src/UI/Dashboard.php | 6 +- automad/src/UI/InPage.php | 17 +-- automad/src/UI/Models/AccountsModel.php | 20 +-- automad/src/UI/Models/FileCollectionModel.php | 4 +- automad/src/UI/Models/FileModel.php | 6 +- automad/src/UI/Models/ImageModel.php | 10 +- automad/src/UI/Models/LinksModel.php | 9 +- automad/src/UI/Models/PageModel.php | 51 ++++---- automad/src/UI/Models/ReplacementModel.php | 22 ++-- .../UI/Models/Search/FieldResultsModel.php | 2 +- .../src/UI/Models/Search/FileKeysModel.php | 2 +- .../src/UI/Models/Search/FileResultsModel.php | 8 +- automad/src/UI/Models/SearchModel.php | 34 ++--- automad/src/UI/Models/UserModel.php | 6 +- automad/src/UI/Response.php | 44 +++---- automad/src/UI/Utils/FileSystem.php | 42 +++--- automad/src/UI/Utils/Keys.php | 28 ++-- automad/src/UI/Utils/Prefix.php | 8 +- automad/src/UI/Utils/Text.php | 11 +- automad/src/UI/Views/CreateUser.php | 4 +- automad/src/UI/Views/Elements/Navbar.php | 4 +- automad/src/UI/Views/Elements/Sidebar.php | 13 +- automad/src/UI/Views/Login.php | 4 +- automad/src/UI/Views/Logout.php | 4 +- automad/src/UI/Views/Page.php | 5 +- 153 files changed, 879 insertions(+), 831 deletions(-) diff --git a/automad/src/Blocks/AbstractBlock.php b/automad/src/Blocks/AbstractBlock.php index 34586a04b..6a16949e4 100644 --- a/automad/src/Blocks/AbstractBlock.php +++ b/automad/src/Blocks/AbstractBlock.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ abstract class AbstractBlock { * Render a paragraph block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - abstract public static function render($data, $Automad); + abstract public static function render(object $data, Automad $Automad); /** * Return a class attribute for the wrapping block element. @@ -61,7 +63,7 @@ abstract public static function render($data, $Automad); * @param array $custom * @return string the attribute string */ - protected static function classAttr($custom = array()) { + protected static function classAttr(array $custom = array()) { $classes = array_merge(array('am-block'), $custom); return 'class="' . join(' ', $classes) . '"'; diff --git a/automad/src/Blocks/Buttons.php b/automad/src/Blocks/Buttons.php index 18f1cd54c..60d25a807 100644 --- a/automad/src/Blocks/Buttons.php +++ b/automad/src/Blocks/Buttons.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Buttons extends AbstractBlock { * Render a buttons block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $defaults = array( 'primaryText' => '', 'primaryLink' => '', diff --git a/automad/src/Blocks/Code.php b/automad/src/Blocks/Code.php index 9d55a6aaa..11cf3efff 100644 --- a/automad/src/Blocks/Code.php +++ b/automad/src/Blocks/Code.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Code extends AbstractBlock { * Render a code block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $code = htmlspecialchars($data->code); return '
' . $code . '
'; diff --git a/automad/src/Blocks/Delimiter.php b/automad/src/Blocks/Delimiter.php index 0b6c42e5c..98e2c5a7a 100644 --- a/automad/src/Blocks/Delimiter.php +++ b/automad/src/Blocks/Delimiter.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Delimiter extends AbstractBlock { * Render a delimiter block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { return '
'; } } diff --git a/automad/src/Blocks/Embed.php b/automad/src/Blocks/Embed.php index 2aa9dfebd..82952d388 100644 --- a/automad/src/Blocks/Embed.php +++ b/automad/src/Blocks/Embed.php @@ -36,6 +36,7 @@ namespace Automad\Blocks; +use Automad\Core\Automad; use Automad\Core\Str; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -52,10 +53,10 @@ class Embed extends AbstractBlock { * Render a embed block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $attr = <<< HTML scrolling="no" frameborder="no" diff --git a/automad/src/Blocks/Filelist.php b/automad/src/Blocks/Filelist.php index 6b9d36e7e..5e8146e51 100644 --- a/automad/src/Blocks/Filelist.php +++ b/automad/src/Blocks/Filelist.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Filelist extends AbstractBlock { * Render a filelist block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $Filelist = $Automad->getFilelist(); $defaults = array( diff --git a/automad/src/Blocks/Gallery.php b/automad/src/Blocks/Gallery.php index ae3325396..f44242c2e 100644 --- a/automad/src/Blocks/Gallery.php +++ b/automad/src/Blocks/Gallery.php @@ -36,6 +36,7 @@ namespace Automad\Blocks; +use Automad\Core\Automad; use Automad\Core\Parse; use Automad\Core\Image; use Automad\Core\Str; @@ -54,10 +55,10 @@ class Gallery extends AbstractBlock { * Render a gallery block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $defaults = array( 'globs' => '*.jpg, *.png, *.gif', 'layout' => 'vertical', diff --git a/automad/src/Blocks/Header.php b/automad/src/Blocks/Header.php index c7ad3e410..c950a7004 100644 --- a/automad/src/Blocks/Header.php +++ b/automad/src/Blocks/Header.php @@ -36,6 +36,7 @@ namespace Automad\Blocks; +use Automad\Core\Automad; use Automad\Core\Str; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -52,10 +53,10 @@ class Header extends AbstractBlock { * Render a header block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $classes = array(); if (!empty($data->alignment)) { diff --git a/automad/src/Blocks/Image.php b/automad/src/Blocks/Image.php index 1c7bc979a..9a87b2f81 100644 --- a/automad/src/Blocks/Image.php +++ b/automad/src/Blocks/Image.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Image extends AbstractBlock { * Render an image block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $class = self::classAttr(); $img = "url}\" />"; diff --git a/automad/src/Blocks/Lists.php b/automad/src/Blocks/Lists.php index 6aea20792..62a3ce615 100644 --- a/automad/src/Blocks/Lists.php +++ b/automad/src/Blocks/Lists.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Lists extends AbstractBlock { * Render a list block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { if ($data->style == 'ordered') { $open = '
    '; $close = '
'; diff --git a/automad/src/Blocks/Mail.php b/automad/src/Blocks/Mail.php index ec209f53e..815cd1107 100644 --- a/automad/src/Blocks/Mail.php +++ b/automad/src/Blocks/Mail.php @@ -36,6 +36,7 @@ namespace Automad\Blocks; +use Automad\Core\Automad; use Automad\System\Mail as SystemMail; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -52,10 +53,10 @@ class Mail extends AbstractBlock { * Render a mail form block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { if (!empty($data->to)) { $defaults = array( 'error' => '', diff --git a/automad/src/Blocks/Pagelist.php b/automad/src/Blocks/Pagelist.php index 66b7d20cb..679999f0e 100644 --- a/automad/src/Blocks/Pagelist.php +++ b/automad/src/Blocks/Pagelist.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Pagelist extends AbstractBlock { * Render a pagelist block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $Pagelist = $Automad->getPagelist(); // Reset pagelist. diff --git a/automad/src/Blocks/Paragraph.php b/automad/src/Blocks/Paragraph.php index d29528cd9..9b747e582 100644 --- a/automad/src/Blocks/Paragraph.php +++ b/automad/src/Blocks/Paragraph.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Paragraph extends AbstractBlock { * Render a paragraph block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $classes = array(); $text = htmlspecialchars_decode($data->text); diff --git a/automad/src/Blocks/Quote.php b/automad/src/Blocks/Quote.php index ea4c88d3b..bc8dd1448 100644 --- a/automad/src/Blocks/Quote.php +++ b/automad/src/Blocks/Quote.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Quote extends AbstractBlock { * Render a quote block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $classes = array(); if (!empty($data->alignment)) { diff --git a/automad/src/Blocks/Raw.php b/automad/src/Blocks/Raw.php index c76222242..bc0ac8201 100644 --- a/automad/src/Blocks/Raw.php +++ b/automad/src/Blocks/Raw.php @@ -36,6 +36,7 @@ namespace Automad\Blocks; +use Automad\Core\Automad; use Automad\Core\Str; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -52,10 +53,10 @@ class Raw extends AbstractBlock { * Render a raw block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $html = Str::markdown($data->code); $class = self::classAttr(); diff --git a/automad/src/Blocks/Section.php b/automad/src/Blocks/Section.php index 983f221c9..33cda4fef 100644 --- a/automad/src/Blocks/Section.php +++ b/automad/src/Blocks/Section.php @@ -36,6 +36,7 @@ namespace Automad\Blocks; +use Automad\Core\Automad; use Automad\Core\Blocks; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -52,10 +53,10 @@ class Section extends AbstractBlock { * Render a section editor block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $json = json_encode($data->content); $html = Blocks::render($json, $Automad); $style = ''; diff --git a/automad/src/Blocks/Slider.php b/automad/src/Blocks/Slider.php index 5581300b4..e3fbe8eec 100644 --- a/automad/src/Blocks/Slider.php +++ b/automad/src/Blocks/Slider.php @@ -36,6 +36,7 @@ namespace Automad\Blocks; +use Automad\Core\Automad; use Automad\Core\Parse; use Automad\Core\Image; @@ -53,10 +54,10 @@ class Slider extends AbstractBlock { * Render a slider block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { if (!empty($data->globs) && !empty($data->width) && !empty($data->height)) { if ($files = Parse::fileDeclaration($data->globs, $Automad->Context->get())) { $files = array_filter($files, function ($file) { diff --git a/automad/src/Blocks/Snippet.php b/automad/src/Blocks/Snippet.php index 82b5c2e41..8ac9a2296 100644 --- a/automad/src/Blocks/Snippet.php +++ b/automad/src/Blocks/Snippet.php @@ -36,6 +36,7 @@ namespace Automad\Blocks; +use Automad\Core\Automad; use Automad\Core\Blocks; use Automad\Core\View; @@ -58,10 +59,10 @@ class Snippet { * Render a snippet block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { // Prevent infinite recursion. if (self::$snippetIsRendering) { return false; diff --git a/automad/src/Blocks/Table.php b/automad/src/Blocks/Table.php index 625b6aedc..aca2945c2 100644 --- a/automad/src/Blocks/Table.php +++ b/automad/src/Blocks/Table.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Table extends AbstractBlock { * Render a table block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $class = self::classAttr(); $html = ""; $first = true; diff --git a/automad/src/Blocks/Toc.php b/automad/src/Blocks/Toc.php index c14841e9d..337b2107b 100644 --- a/automad/src/Blocks/Toc.php +++ b/automad/src/Blocks/Toc.php @@ -36,6 +36,8 @@ namespace Automad\Blocks; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -50,10 +52,10 @@ class Toc extends AbstractBlock { * Render a toc block. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($data, $Automad) { + public static function render(object $data, Automad $Automad) { $class = self::classAttr(array("am-toc-{$data->style}")); return ""; diff --git a/automad/src/Core/Automad.php b/automad/src/Core/Automad.php index a00689464..d2fcf7bfd 100644 --- a/automad/src/Core/Automad.php +++ b/automad/src/Core/Automad.php @@ -50,7 +50,7 @@ */ class Automad { /** - * Automad's Context object. + * Automad's Context object. * * The object is part of the Automad class to allow to access always the same instance of the Context class for all objects using the Automad object as parameter. */ @@ -64,14 +64,14 @@ class Automad { public $Shared; /** - * Array holding all the site's pages and the related data. + * Array holding all the site's pages and the related data. * * To access the data for a specific page, use the url as key: $this->collection['url']. */ private $collection = array(); /** - * Automad's Filelist object + * Automad's Filelist object * * The object is part of the Automad class to allow to access always the same instance of the Filelist class for all objects using the Automad object as parameter. */ @@ -109,7 +109,7 @@ public function __construct() { } /** - * Define properties to be cached. + * Define properties to be cached. * * @return array $itemsToCache */ @@ -121,7 +121,7 @@ public function __sleep() { } /** - * Set new Context after being restored from cache. + * Set new Context after being restored from cache. */ public function __wakeup() { Debug::log(get_object_vars($this), 'Automad object got unserialized'); @@ -131,7 +131,7 @@ public function __wakeup() { /** * Tests wheter the currently requested page actually exists and is not an error page. * - * @return boolean True if existing + * @return bool True if existing */ public function currentPageExists() { $Page = $this->Context->get(); @@ -140,7 +140,7 @@ public function currentPageExists() { } /** - * Return $collection array. + * Return $collection array. * * @return array $this->collection */ @@ -151,7 +151,7 @@ public function getCollection() { /** * Return Automad's instance of the Filelist class and create instance when accessed for the first time. * - * @return object Filelist object + * @return Filelist Filelist object */ public function getFilelist() { if (!$this->Filelist) { @@ -162,12 +162,12 @@ public function getFilelist() { } /** - * If existing, return the page object for the passed relative URL. + * If existing, return the page object for the passed relative URL. * * @param string $url - * @return object $page or NULL + * @return Page|null Page or null */ - public function getPage($url) { + public function getPage(string $url) { if (array_key_exists($url, $this->collection)) { return $this->collection[$url]; } @@ -176,7 +176,7 @@ public function getPage($url) { /** * Return Automad's instance of the Pagelist class and create instance when accessed for the first time. * - * @return object Pagelist object + * @return Pagelist Pagelist object */ public function getPagelist() { if (!$this->Pagelist) { @@ -198,7 +198,7 @@ public function getPagelist() { * @param string $file * @return string The buffered output */ - public function loadTemplate($file) { + public function loadTemplate(string $file) { $Automad = $this; if (is_readable($file)) { @@ -225,10 +225,10 @@ public function loadTemplate($file) { * To access the data of a specific page within the $collection array, the page's url serves as the key: $this->collection['/path/to/page'] * * @param string $path - * @param number $level + * @param int $level * @param string $parentUrl */ - private function collectPages($path = '/', $level = 0, $parentUrl = '') { + private function collectPages(string $path = '/', int $level = 0, string $parentUrl = '') { // First check, if $path contains any data files. // If more that one file matches the pattern, the first one will be used as the page's data file and the others will just be ignored. if ($files = FileSystem::glob(AM_BASE_DIR . AM_DIR_PAGES . $path . '*.' . AM_FILE_EXT_DATA)) { @@ -308,9 +308,9 @@ private function collectPages($path = '/', $level = 0, $parentUrl = '') { } /** - * Return the page object for the requested page. + * Return the page object for the requested page. * - * @return object A page object or NULL + * @return Page|null A page object or null */ private function getRequestedPage() { // Check whether the UI is requesting the currently edited page. @@ -358,7 +358,7 @@ private function getReservedUrls() { * @param string $slug * @return string $url */ - private function makeUrl($parentUrl, $slug) { + private function makeUrl(string $parentUrl, string $slug) { // strip prefix from $slug $pattern = '/[a-zA-Z0-9_-]+\./'; $replacement = ''; @@ -397,7 +397,7 @@ private function makeUrl($parentUrl, $slug) { /** * Create a temporary page for a missing page and send a 404 header. * - * @return object The error page + * @return Page The error page */ private function pageNotFound() { header('HTTP/1.0 404 Not Found'); diff --git a/automad/src/Core/Blocks.php b/automad/src/Core/Blocks.php index 3d6cfdc95..6e11865a6 100644 --- a/automad/src/Core/Blocks.php +++ b/automad/src/Core/Blocks.php @@ -47,17 +47,17 @@ */ class Blocks { /** - * Multidimensional array of collected extension assets grouped by type (CSS/JS). + * Multidimensional array of collected extension assets grouped by type (CSS/JS). */ public static $extensionAssets = array(); /** - * Inject block assets into the header of a page. + * Inject block assets into the header of a page. * - * @param mixed $str + * @param string $str * @return string the processed HTML */ - public static function injectAssets($str) { + public static function injectAssets(string $str) { $versionSanitized = Str::sanitize(AM_VERSION); $css = AM_BASE_URL . '/automad/dist/blocks.min.css?v=' . $versionSanitized; $js = AM_BASE_URL . '/automad/dist/blocks.min.js?v=' . $versionSanitized; @@ -76,13 +76,13 @@ public static function injectAssets($str) { } /** - * Render blocks created by the EditorJS block editor. + * Render blocks created by the EditorJS block editor. * * @param string $json - * @param object $Automad + * @param Automad $Automad * @return string the rendered HTML */ - public static function render($json, $Automad) { + public static function render(string $json, Automad $Automad) { $flexOpen = false; $data = json_decode($json); $html = ''; diff --git a/automad/src/Core/Cache.php b/automad/src/Core/Cache.php index 5d54faa96..c51d3c21b 100644 --- a/automad/src/Core/Cache.php +++ b/automad/src/Core/Cache.php @@ -109,12 +109,13 @@ class Cache { /** * The constructor checks whether caching is enabled for the current request and * determines the $pageCacheFile to make it available within the instance. - * In case of any submitted data (get or post), caching will be disabled to make sure - * that possible modifications of the session data array will always be reflected - * in the cache. Note that caching of such submitted data (get or post) would possibly - * only update the session data array for the requesting user. All other user could therefore - * not trigger any updates to their sessions, because the request is already cached and - * the template would not be parsed again. + * + * In case of any submitted data (get or post), caching will be disabled to make sure + * that possible modifications of the session data array will always be reflected + * in the cache. Note that caching of such submitted data (get or post) would possibly + * only update the session data array for the requesting user. All other user could therefore + * not trigger any updates to their sessions, because the request is already cached and + * the template would not be parsed again. */ public function __construct() { if (AM_CACHE_ENABLED) { @@ -361,9 +362,9 @@ public function readPageFromCache() { /** * Write (serialize) the Automad object to $this->objectCacheFile. * - * @param object $Automad + * @param Automad $Automad */ - public function writeAutomadObjectToCache($Automad) { + public function writeAutomadObjectToCache(Automad $Automad) { if ($this->automadObjectCachingIsEnabled) { FileSystem::write($this->objectCacheFile, serialize($Automad)); Debug::log($this->objectCacheFile, 'Automad object written to'); @@ -385,7 +386,7 @@ public function writeAutomadObjectToCache($Automad) { * * @param string $output */ - public function writePageToCache($output) { + public function writePageToCache(string $output) { if ($this->pageCachingIsEnabled) { FileSystem::write($this->pageCacheFile, $output); Debug::log($this->pageCacheFile, 'Page written to'); @@ -400,7 +401,7 @@ public function writePageToCache($output) { * @param string $dir * @return array The array of directories including the given directory itself */ - private function getDirectoriesRecursively($dir) { + private function getDirectoriesRecursively(string $dir) { $dirs = array($dir); foreach (FileSystem::glob($dir . '/*', GLOB_ONLYDIR) as $d) { @@ -481,7 +482,7 @@ private static function readSiteMTime() { * * @param int $siteMTime */ - private static function writeSiteMTime($siteMTime) { + private static function writeSiteMTime(int $siteMTime) { FileSystem::write(AM_FILE_SITE_MTIME, serialize($siteMTime)); Debug::log(AM_FILE_SITE_MTIME, 'Site-mTime written to'); } diff --git a/automad/src/Core/Config.php b/automad/src/Core/Config.php index 4646d2862..0e9fe66cd 100644 --- a/automad/src/Core/Config.php +++ b/automad/src/Core/Config.php @@ -263,12 +263,12 @@ public static function read() { } /** - * Define constant, if not defined already. + * Define constant, if not defined already. * * @param string $name * @param string $value */ - public static function set($name, $value) { + public static function set(string $name, string $value) { if (!defined($name)) { define($name, $value); } @@ -278,9 +278,9 @@ public static function set($name, $value) { * Write the configuration file. * * @param array $config - * @return boolean True on success + * @return bool True on success */ - public static function write($config) { + public static function write(array $config) { $json = json_encode($config, JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES); $content = "set($Page); } /** - * Return $Page. + * Return $Page. * - * @return object $Page + * @return Page $Page */ public function get() { return $this->Page; } /** - * Set the context. + * Set the context. * - * @param object $Page + * @param Page $Page */ - public function set($Page) { + public function set(?Page $Page) { // Test whether $Page is empty - that can happen, when accessing the UI. if (!empty($Page)) { $this->Page = $Page; diff --git a/automad/src/Core/Debug.php b/automad/src/Core/Debug.php index e7f249fb8..c0669a8bf 100644 --- a/automad/src/Core/Debug.php +++ b/automad/src/Core/Debug.php @@ -115,7 +115,7 @@ public static function getLog() { * @param mixed $element (The actual content to log) * @param string $description (Basic info, class, method etc.) */ - public static function log($element, $description = '') { + public static function log($element, string $description = '') { if (AM_DEBUG_ENABLED) { // Start timer. self::timerStart() only saves the time on the first call. self::timerStart(); diff --git a/automad/src/Core/Extension.php b/automad/src/Core/Extension.php index 3c38542cd..5b8f5d009 100644 --- a/automad/src/Core/Extension.php +++ b/automad/src/Core/Extension.php @@ -57,22 +57,22 @@ * create an instance of the class "\example1" ($object) and call the method "$object->example1()" of that class. * The namespace would just be "\". * The full naming scheme would be: - * - namespace: \ - * - directory: /packages/example1 (must be lowercase) - * - file: /packages/example1/example1.php (must be lowercase) - * - class: Example1 - * - method: Example1 + * - namespace: \ + * - directory: /packages/example1 (must be lowercase) + * - file: /packages/example1/example1.php (must be lowercase) + * - class: Example1 + * - method: Example1 * * Example 2 - Extension in a subdirectory (like a vendor name): * An extension call like <@ vendor/example2 @> would load the file "/packages/vendor/example2/example2.php", * create an instance of the class "\vendor\example2" ($object) and call the method "$object->example2()" of that class. * The namespace in this case would be "\vendor". * The full naming scheme would be: - * - namespace: \vendor - * - directory: /packages/vendor/example2 (must be lowercase) - * - file: /packages/vendor/example2/example2.php (must be lowercase) - * - class: Example2 - * - method: Example2 + * - namespace: \vendor + * - directory: /packages/vendor/example2 (must be lowercase) + * - file: /packages/vendor/example2/example2.php (must be lowercase) + * - class: Example2 + * - method: Example2 * * @author Marc Anton Dahmen * @copyright Copyright (c) 2016-2021 by Marc Anton Dahmen - https://marcdahmen.de @@ -94,9 +94,9 @@ class Extension { * * @param string $extension * @param array $options - * @param object $Automad + * @param Automad $Automad */ - public function __construct($extension, $options, $Automad) { + public function __construct(string $extension, array $options, Automad $Automad) { Debug::log($extension); // Building the class name. @@ -162,11 +162,11 @@ public function getOutput() { } /** - * Collect all assets (CSS & JS files) belonging to $class and store them in $this->assets. + * Collect all assets (CSS & JS files) belonging to $class and store them in $this->assets. * * @param string $class */ - private function collectAssets($class) { + private function collectAssets(string $class) { $Reflection = new \ReflectionClass($class); $path = dirname($Reflection->getFileName()); Debug::log($path, 'Getting assets for ' . $class . ' in'); diff --git a/automad/src/Core/FileSystem.php b/automad/src/Core/FileSystem.php index 99a574732..080b7e826 100644 --- a/automad/src/Core/FileSystem.php +++ b/automad/src/Core/FileSystem.php @@ -52,7 +52,7 @@ class FileSystem { * @param string $file * @return bool Return true if the file was deleted succsessfully */ - public static function deleteFile($file) { + public static function deleteFile(string $file) { if (is_file($file)) { if (is_writable($file) && is_writable(dirname($file))) { return unlink($file); @@ -66,7 +66,7 @@ public static function deleteFile($file) { * @param string $file * @return string The extension */ - public static function getExtension($file) { + public static function getExtension(string $file) { $pathInfo = pathinfo($file); if (!empty($pathInfo['extension'])) { @@ -78,9 +78,9 @@ public static function getExtension($file) { * Get file extension for images based on mime types. * * @param string $file - * @return string The extension or false + * @return mixed The extension or false */ - public static function getImageExtensionFromMimeType($file) { + public static function getImageExtensionFromMimeType(string $file) { try { $getimagesize = getimagesize($file); $type = $getimagesize['mime']; @@ -111,11 +111,11 @@ public static function getImageExtensionFromMimeType($file) { } /** - * Return the path of the temp dir if it is writable by the webserver. - * In any case, '/tmp' is the preferred directory, because of automatic cleanup at reboot, - * while other locations like '/var/tmp' do not get purged by the system. - * But since '/tmp' is only available on macos and linux, - * sys_get_temp_dir() is used as fallback. + * Return the path of the temp dir if it is writable by the webserver. + * In any case, '/tmp' is the preferred directory, because of automatic cleanup at reboot, + * while other locations like '/var/tmp' do not get purged by the system. + * But since '/tmp' is only available on macos and linux, + * sys_get_temp_dir() is used as fallback. * * @return string The path to the temp dir */ @@ -137,10 +137,10 @@ public static function getTmpDir() { * on some systems instead of empty arrays. * * @param string $pattern - * @param integer $flags + * @param int $flags * @return array The list of matching files */ - public static function glob($pattern, $flags = 0) { + public static function glob(string $pattern, int $flags = 0) { $files = glob($pattern, $flags); if (!$files) { @@ -161,10 +161,10 @@ public static function glob($pattern, $flags = 0) { * * @param string $pattern * @param string $regex - * @param integer $flags + * @param int $flags * @return array The filtered list of matching files */ - public static function globGrep($pattern, $regex, $flags = 0) { + public static function globGrep(string $pattern, string $regex, int $flags = 0) { return array_values(preg_grep($regex, self::glob($pattern, $flags))); } @@ -176,9 +176,9 @@ public static function globGrep($pattern, $regex, $flags = 0) { * "/url/file.jpg" will return true, "/url/file" or "/url/file.something" will return false. * * @param string $str - * @return boolean + * @return bool */ - public static function isAllowedFileType($str) { + public static function isAllowedFileType(string $str) { // Remove possible query string $str = preg_replace('/\?.*/', '', $str); @@ -199,9 +199,9 @@ public static function isAllowedFileType($str) { * Create directory if not existing. * * @param string $path - * @return boolean True on success, else false + * @return bool True on success, else false */ - public static function makeDir($path) { + public static function makeDir(string $path) { if (!file_exists($path)) { $umask = umask(0); $return = mkdir($path, AM_PERM_DIR, true); @@ -218,7 +218,7 @@ public static function makeDir($path) { * @param string $path * @return string The processed path with only forward slashes */ - public static function normalizeSlashes($path) { + public static function normalizeSlashes(string $path) { return str_replace('\\', '/', $path); } @@ -227,9 +227,9 @@ public static function normalizeSlashes($path) { * * @param string $file * @param string $content - * @return boolean True on success, else false + * @return bool True on success, else false */ - public static function write($file, $content) { + public static function write(string $file, string $content) { self::makeDir(dirname($file)); if (!file_exists($file)) { diff --git a/automad/src/Core/Filelist.php b/automad/src/Core/Filelist.php index 62045f35f..f3c941fc3 100644 --- a/automad/src/Core/Filelist.php +++ b/automad/src/Core/Filelist.php @@ -62,9 +62,9 @@ class Filelist { /** * The constructor. * - * @param object $Context + * @param Context $Context */ - public function __construct($Context) { + public function __construct(Context $Context) { $this->Context = $Context; } @@ -73,7 +73,7 @@ public function __construct($Context) { * * @param array $options */ - public function config($options) { + public function config(array $options) { $this->options = array_merge($this->options, $options); } diff --git a/automad/src/Core/Headless.php b/automad/src/Core/Headless.php index b1b6cebfe..777c9f77d 100644 --- a/automad/src/Core/Headless.php +++ b/automad/src/Core/Headless.php @@ -47,8 +47,8 @@ */ class Headless { /** - * Checks whether a custom headless template exists and returns its path. - * In case there is no custom template, the path to the default template is returned. + * Checks whether a custom headless template exists and returns its path. + * In case there is no custom template, the path to the default template is returned. * * @return string The path to the template file */ diff --git a/automad/src/Core/Image.php b/automad/src/Core/Image.php index 2d4a4a337..7c2677535 100644 --- a/automad/src/Core/Image.php +++ b/automad/src/Core/Image.php @@ -115,11 +115,11 @@ class Image { * The constructor defines the main object properties from the given parameters and initiates the main methods. * * @param string $originalFile - * @param integer $requestedWidth - * @param integer $requestedHeight - * @param boolean $crop + * @param int $requestedWidth + * @param int $requestedHeight + * @param bool $crop */ - public function __construct($originalFile = false, $requestedWidth = false, $requestedHeight = false, $crop = false) { + public function __construct(string $originalFile, ?int $requestedWidth = null, ?int $requestedHeight = null, bool $crop = false) { if ($originalFile) { ini_set('memory_limit', -1); diff --git a/automad/src/Core/Page.php b/automad/src/Core/Page.php index 5c2fee7de..9decbef68 100644 --- a/automad/src/Core/Page.php +++ b/automad/src/Core/Page.php @@ -49,14 +49,14 @@ */ class Page { /** - * The $data array holds all the information stored as "key: value" in the text file and some other system generated information (:path, :level, :template ...). + * The $data array holds all the information stored as "key: value" in the text file and some other system generated information (:path, :level, :template ...). * * The key can be everything alphanumeric as long as there is a matching var set in the template files. * Out of all possible keys ther are two very special ones: * - * - "title": The title of the page - will also be used for sorting - * - "tags" (or better AM_KEY_TAGS): The tags (or what ever is set in the const.php) will be extracted and stored as an array in the main properties of that page - * The original string will remain in the $data array for seaching + * - "title": The title of the page - will also be used for sorting + * - "tags": The tags (or what ever is set in the const.php) will be extracted and stored as an array in the main properties of that page + * The original string will remain in the $data array for seaching */ public $data = array(); @@ -74,21 +74,21 @@ class Page { * Set main properties. * * @param array $data - * @param object $Shared + * @param Shared $Shared */ - public function __construct($data, $Shared) { + public function __construct(array $data, Shared $Shared) { $this->data = $data; $this->Shared = $Shared; $this->tags = $this->extractTags(); } /** - * Make basic data items accessible as page properties. + * Make basic data items accessible as page properties. * - * @param string $key The property name + * @param string $key * @return string The returned value from the data array */ - public function __get($key) { + public function __get(string $key) { // Map property names to the defined keys of the data array. $keyMap = array( 'hidden' => AM_KEY_HIDDEN, @@ -120,7 +120,7 @@ public function __get($key) { * @param string $key * @return string The requested value */ - public function get($key) { + public function get(string $key) { // Check whether the requested data is part of the data array or has to be generated. if (array_key_exists($key, $this->data)) { // Return value from the data array. @@ -165,7 +165,7 @@ public function getMtime() { } /** - * Return the template of the page. + * Return the template of the page. * * @return string The full file system path of the template file. */ @@ -187,7 +187,7 @@ public function getTemplate() { /** * Check if page is the current page. * - * @return boolean + * @return bool true if the the page is the currently requested page */ public function isCurrent() { return (AM_REQUEST == $this->url); @@ -196,7 +196,7 @@ public function isCurrent() { /** * Check if the page URL is a part the current page's URL. * - * @return boolean + * @return bool true if the the page is a parent of the currently requested page or the requeste page itself */ public function isInCurrentPath() { // Test if AM_REQUEST starts with or is equal to $this->url. diff --git a/automad/src/Core/Pagelist.php b/automad/src/Core/Pagelist.php index db5824935..fbde6095e 100644 --- a/automad/src/Core/Pagelist.php +++ b/automad/src/Core/Pagelist.php @@ -80,12 +80,12 @@ class Pagelist { ); /** - * Defines whether the pagelist excludes the current page or not. + * Defines whether the pagelist excludes the current page or not. */ private $excludeCurrent; /** - * Defines whether the pagelist excludes hidden pages or not. + * Defines whether the pagelist excludes hidden pages or not. */ private $excludeHidden; @@ -100,12 +100,12 @@ class Pagelist { private $limit; /** - * Defines a JSON string to be used as paramter for the $Selection->match() method. + * Defines a JSON string to be used as paramter for the $Selection->match() method. */ private $match; /** - * Defines the offset within the array of pages returned by getPages(). + * Defines the offset within the array of pages returned by getPages(). */ private $offset; @@ -138,9 +138,9 @@ class Pagelist { * Initialize the Pagelist. * * @param array $collection - * @param object $Context + * @param Context $Context */ - public function __construct($collection, $Context) { + public function __construct(array $collection, Context $Context) { $this->collection = $collection; $this->Context = $Context; $this->config($this->defaults); @@ -168,7 +168,7 @@ public function __construct($collection, $Context) { * @param array $options * @return array Updated $options */ - public function config($options = array()) { + public function config(array $options = array()) { // Turn all (but only) array items also existing in $defaults into class properties. // Only items existing in $options will be changed and will override the existings values defined with the first call ($defaults). foreach (array_intersect_key($options, $this->defaults) as $key => $value) { @@ -201,10 +201,10 @@ public function getDefaults() { * even if pages with such tags are not returned due to the limit. Sorting a pagelist will also sort all pages and therefore the set of returned pages might * always be different. * - * @param boolean $ignoreLimit + * @param bool $ignoreLimit * @return array The filtered and sorted array of Page objects */ - public function getPages($ignoreLimit = false) { + public function getPages(bool $ignoreLimit = false) { $offset = 0; $limit = null; $Selection = new Selection($this->getRelevant()); diff --git a/automad/src/Core/Parse.php b/automad/src/Core/Parse.php index 933cb05d0..34d4c3e1e 100644 --- a/automad/src/Core/Parse.php +++ b/automad/src/Core/Parse.php @@ -63,7 +63,7 @@ public static function allowedFileTypes() { * @param string $file * @return string The caption string */ - public static function caption($file) { + public static function caption(string $file) { // Build filename of the caption file. $captionFile = $file . '.' . AM_FILE_EXT_CAPTION; Debug::log($captionFile); @@ -74,12 +74,12 @@ public static function caption($file) { } /** - * Split and trim comma separated string. + * Split and trim comma separated string. * * @param string $str * @return array The array of separate and trimmed strings */ - public static function csv($str) { + public static function csv(string $str) { $array = explode(AM_PARSE_STR_SEPARATOR, $str); $array = array_filter($array, 'strlen'); @@ -93,11 +93,11 @@ public static function csv($str) { * and each path gets resolved to be relative to the Automad installation directory. * * @param string $str - * @param object $Page (current page) - * @param boolean $stripBaseDir + * @param Page $Page + * @param bool $stripBaseDir * @return array An array with resolved file paths */ - public static function fileDeclaration($str, $Page, $stripBaseDir = false) { + public static function fileDeclaration(string $str, Page $Page, bool $stripBaseDir = false) { $files = array(); if ($str) { @@ -130,7 +130,7 @@ public static function fileDeclaration($str, $Page, $stripBaseDir = false) { * @param string $file * @return boolean True if $file is an image file */ - public static function fileIsImage($file) { + public static function fileIsImage(string $file) { return (in_array(FileSystem::getExtension($file), array('jpg', 'jpeg', 'png', 'gif'))); } @@ -140,7 +140,7 @@ public static function fileIsImage($file) { * @param string $str * @return array $options - associative array */ - public static function jsonOptions($str) { + public static function jsonOptions(string $str) { $options = array(); if ($str) { @@ -201,7 +201,7 @@ public static function jsonOptions($str) { * @param string $file * @return array $vars */ - public static function textFile($file) { + public static function textFile(string $file) { $vars = array(); if (!file_exists($file)) { diff --git a/automad/src/Core/Pipe.php b/automad/src/Core/Pipe.php index eb8e734fd..61094b44f 100644 --- a/automad/src/Core/Pipe.php +++ b/automad/src/Core/Pipe.php @@ -70,7 +70,7 @@ class Pipe { * @param array $functions * @return string The modified $value */ - public static function process($value, $functions) { + public static function process(string $value, array $functions) { Debug::log($functions); foreach ($functions as $function) { @@ -92,7 +92,7 @@ public static function process($value, $functions) { * @param string $value * @return string $value */ - private static function extension($function, $parameters, $value) { + private static function extension(string $function, array $parameters, string $value) { $class = '\\' . str_replace('/', '\\', $function); if (!class_exists($class, false)) { @@ -124,7 +124,7 @@ private static function extension($function, $parameters, $value) { * @param string $value * @return number $value */ - private static function math($operator, $number, $value) { + private static function math(string $operator, string $number, string $value) { $number = floatval($number); $value = floatval($value); @@ -160,7 +160,7 @@ private static function math($operator, $number, $value) { * @param string $value * @return string $value */ - private static function stringFunction($function, $parameters, $value) { + private static function stringFunction(string $function, array $parameters, string $value) { if (!$parameters) { $parameters = array(); } diff --git a/automad/src/Core/Regex.php b/automad/src/Core/Regex.php index fdf9a583a..2090e001c 100644 --- a/automad/src/Core/Regex.php +++ b/automad/src/Core/Regex.php @@ -67,7 +67,7 @@ class Regex { public static $number = '\d+(?:\.\d+)?'; /** - * The outer statement marker helps to distinguish all outer wrapping statements from the inner statements. + * The outer statement marker helps to distinguish all outer wrapping statements from the inner statements. */ public static $outerStatementMarker = '#'; @@ -78,10 +78,10 @@ class Regex { * relative reference to the wrapping main variable pattern to match variables * within parameters. * - * @param boolean $isVariableSubpattern + * @param bool $isVariableSubpattern * @return string The regex matching a comma separated parameter string. */ - public static function csv($isVariableSubpattern = false) { + public static function csv(bool $isVariableSubpattern = false) { if ($isVariableSubpattern) { return self::value('(?-7)') . '(?:,' . self::value('(?-8)') . ')*?'; @@ -98,16 +98,16 @@ public static function csv($isVariableSubpattern = false) { * * Valid expressions are: * - * - @{var} >= 5 - * - @{var} != "Text ..." - * - @{var} = 'Text' - * - not @{var} - * - !@{var} + * - @{var} >= 5 + * - @{var} != "Text ..." + * - @{var} = 'Text' + * - not @{var} + * - !@{var} * - * @param string $namedReferencePrefix + * @param string|null $namedReferencePrefix * @return string The regex */ - public static function expression($namedReferencePrefix = false) { + public static function expression(?string $namedReferencePrefix = null) { if ($namedReferencePrefix) { $left = $namedReferencePrefix . 'Left'; $operator = '?P<' . $namedReferencePrefix . 'Operator>'; @@ -222,10 +222,10 @@ public static function markup() { * - 5 * - 1.5 * - * @param string $namedReferencePrefix + * @param string|null $namedReferencePrefix * @return string The regex */ - public static function operand($namedReferencePrefix = false) { + public static function operand(?string $namedReferencePrefix = null) { if ($namedReferencePrefix) { $doubleQuoted = '?P<' . $namedReferencePrefix . 'DoubleQuoted>'; $singleQuoted = '?P<' . $namedReferencePrefix . 'SingleQuoted>'; @@ -247,16 +247,16 @@ public static function operand($namedReferencePrefix = false) { * - "| name (parameters)" * - "| +5" * - * Parameters can be strings wrapped in quotes, - * single words without quotes, numbers and variables. - * In case $isVariableSubpattern is true, relative references to the wrapping - * variable pattern are used to match variables. + * Parameters can be strings wrapped in quotes, + * single words without quotes, numbers and variables. + * In case $isVariableSubpattern is true, relative references to the wrapping + * variable pattern are used to match variables. * - * @param string $namedReferencePrefix - * @param boolean $isVariableSubpattern + * @param string|null $namedReferencePrefix + * @param bool $isVariableSubpattern * @return string The regex to match functions and their parameters or math operations */ - public static function pipe($namedReferencePrefix = false, $isVariableSubpattern = false) { + public static function pipe(?string $namedReferencePrefix = null, bool $isVariableSubpattern = false) { if ($namedReferencePrefix) { $function = '?P<' . $namedReferencePrefix . 'Function>'; $parameters = '?P<' . $namedReferencePrefix . 'Parameters>'; @@ -296,7 +296,7 @@ public static function pipe($namedReferencePrefix = false, $isVariableSubpattern * @param string $subpatternVar * @return string The regex matching a function parameter. */ - public static function value($subpatternVar) { + public static function value(string $subpatternVar) { // Any quoted string. Single and double quotes are allowed. // Use possessive quantifiers to improve performance of very long values. $string = '"(?:[^"\\\\]|\\\\.)*+"|\'(?:[^\'\\\\]|\\\\.)*+\''; @@ -309,14 +309,14 @@ public static function value($subpatternVar) { * A prefix can be defined as the first parameter to create named backreferences for each capturing group. * Like: @{var|function1(...)|function2(...)| ... } * - * In case the pattern is used as a subpattern of the pipe() method, $pipeReference can be specified to - * reference the whole pipe pattern by using a relative reference or (?R). + * In case the pattern is used as a subpattern of the pipe() method, $pipeReference can be specified to + * reference the whole pipe pattern by using a relative reference or (?R). * - * @param string $namedReferencePrefix - * @param string $pipeReference + * @param string|null $namedReferencePrefix + * @param string|null $pipeReference * @return string The regex to match variables. */ - public static function variable($namedReferencePrefix = false, $pipeReference = false) { + public static function variable(?string $namedReferencePrefix = null, ?string $pipeReference = null) { if ($namedReferencePrefix) { $name = '?P<' . $namedReferencePrefix . 'Name>'; $functions = '?P<' . $namedReferencePrefix . 'Functions>'; @@ -336,7 +336,7 @@ public static function variable($namedReferencePrefix = false, $pipeReference = } /** - * A simplified pattern to match all used variable names in a template (UI). + * A simplified pattern to match all used variable names in a template (UI). * * @return string The regex pattern. */ diff --git a/automad/src/Core/RemoteFile.php b/automad/src/Core/RemoteFile.php index 08c6d25ba..a5440a735 100644 --- a/automad/src/Core/RemoteFile.php +++ b/automad/src/Core/RemoteFile.php @@ -56,7 +56,7 @@ class RemoteFile { * * @param string $url */ - public function __construct($url) { + public function __construct(string $url) { $this->localCopy = $this->download($url); } @@ -75,7 +75,7 @@ public function getLocalCopy() { * @param string $url * @return string The local copy's file path or false */ - private function download($url) { + private function download(string $url) { $downloads = AM_BASE_DIR . AM_DIR_CACHE . '/downloads'; FileSystem::makeDir($downloads); $file = $downloads . '/' . AM_FILE_PREFIX_CACHE . '_' . sha1($url); diff --git a/automad/src/Core/Request.php b/automad/src/Core/Request.php index 0a9b7c466..ddda6199a 100644 --- a/automad/src/Core/Request.php +++ b/automad/src/Core/Request.php @@ -127,7 +127,7 @@ public static function page() { * @param string $key * @return string The value for the requested key */ - public static function post($key) { + public static function post(string $key) { if (isset($_POST[$key])) { return $_POST[$key]; } else { @@ -138,12 +138,12 @@ public static function post($key) { /** * Return a sanitized value of a query string parameter or any empty string, if that parameter doesn't exist. * Note: Since this method always returns a string, it should not be used to test whether a parameter exists in the query string, - * because a non-existing parameter and an empty string as a parameter's value will return the same. + * because a non-existing parameter and an empty string as a parameter's value will return the same. * * @param string $key * @return string The value for the requested query key */ - public static function query($key) { + public static function query(string $key) { if (isset($_GET[$key])) { return htmlspecialchars($_GET[$key]); } else { diff --git a/automad/src/Core/Resolve.php b/automad/src/Core/Resolve.php index 4ca1b0d4b..15c0b48ce 100644 --- a/automad/src/Core/Resolve.php +++ b/automad/src/Core/Resolve.php @@ -60,7 +60,7 @@ class Resolve { * @param string $url * @return string The resolved URL */ - public static function absoluteUrlToRoot($url) { + public static function absoluteUrlToRoot(string $url) { // Skip URLs starting with "//". if (strpos($url, '//') === 0) { return $url; @@ -70,7 +70,8 @@ public static function absoluteUrlToRoot($url) { if (strpos($url, '/') === 0) { // Relative to root if (FileSystem::isAllowedFileType($url) || $url == '/' || strpos($url, '/?') === 0 || strpos($url, '/#') === 0) { - // Skip adding a possible '/index.php' when linking to files and to the homepage (possibly including a query string or anchor link), + // Skip adding a possible '/index.php' when linking to files and to the homepage + // (possibly including a query string or anchor link), // also if rewriting is disabled. return AM_BASE_URL . $url; } else { @@ -93,7 +94,7 @@ public static function absoluteUrlToRoot($url) { * @param string $filePath * @return string The resolved file path */ - public static function filePath($pagePath, $filePath) { + public static function filePath(string $pagePath, string $filePath) { if (strpos($filePath, '/') === 0) { // Relative to root return AM_BASE_DIR . $filePath; @@ -113,10 +114,10 @@ public static function filePath($pagePath, $filePath) { * ../ -> /parent * * @param string $url - * @param object $Page + * @param Page $Page * @return string The resolved URL */ - public static function relativeUrlToBase($url, $Page) { + public static function relativeUrlToBase(string $url, Page $Page) { // Skip any protocol, mailto, tel and skype links. if (preg_match('/(\:\/\/|^[a-z]+\:)/is', $url)) { return $url; diff --git a/automad/src/Core/Runtime.php b/automad/src/Core/Runtime.php index f4bb85705..d6a3235e3 100644 --- a/automad/src/Core/Runtime.php +++ b/automad/src/Core/Runtime.php @@ -60,9 +60,9 @@ class Runtime { /** * The constructor. * - * @param object $Automad + * @param Automad $Automad */ - public function __construct($Automad) { + public function __construct(Automad $Automad) { $this->Automad = $Automad; Debug::log('Created new instance'); } @@ -73,7 +73,7 @@ public function __construct($Automad) { * @param string $key * @return string The value of $key or NULL if the requested variable doesn't exsist */ - public function get($key) { + public function get(string $key) { // Check whether $key is generated within a loop and therefore stored in $this->data or // if $key is related to the context, filelist or pagelist object. if (array_key_exists($key, $this->data)) { @@ -124,7 +124,7 @@ public function get($key) { * @param string $key * @param mixed $value */ - public function set($key, $value) { + public function set(string $key, $value) { $this->data[$key] = $value; } @@ -144,7 +144,7 @@ public function shelve() { * * @param array $shelf */ - public function unshelve($shelf) { + public function unshelve(array $shelf) { $this->data = $shelf; Debug::log($this->data, 'Unshelving'); } diff --git a/automad/src/Core/Selection.php b/automad/src/Core/Selection.php index ec6815e0f..2ef1cc7d0 100644 --- a/automad/src/Core/Selection.php +++ b/automad/src/Core/Selection.php @@ -39,7 +39,7 @@ defined('AUTOMAD') or die('Direct access not permitted!'); /** - * The Selection class holds all methods to filter and sort the collection of pages and return them as a new selection. + * The Selection class holds all methods to filter and sort the collection of pages and return them as a new selection. * * Every instance can return a filtered and sorted array of pages without hurting the original Automad object. * That means the Automad class object has to be created only once. @@ -54,7 +54,7 @@ */ class Selection { /** - * Initially holds the whole collection. + * Initially holds the whole collection. * * $selection is basically the internal working copy of the collection array. * It can be sorted and filtered without hurting the original collection. @@ -62,11 +62,11 @@ class Selection { private $selection = array(); /** - * Pass a set of pages to $this->selection excluding all hidden pages. + * Pass a set of pages to $this->selection excluding all hidden pages. * - * @param array $pages (normally Automad::getCollection() or any other selection array) + * @param array $pages */ - public function __construct($pages) { + public function __construct(array $pages) { $this->selection = $pages; } @@ -82,7 +82,7 @@ public function excludeCurrent() { * * @param string $url */ - public function excludePage($url) { + public function excludePage(string $url) { if ($url && array_key_exists($url, $this->selection)) { unset($this->selection[$url]); } @@ -93,7 +93,7 @@ public function excludePage($url) { * * @param string $url */ - public function filterBreadcrumbs($url) { + public function filterBreadcrumbs(string $url) { // Test wheter $url is the URL of a real page. // "Real" pages have a URL (not like search or error pages) and they exist in the selection array (not hidden). // For all other $url, just the home page will be returned. @@ -125,7 +125,7 @@ public function filterBreadcrumbs($url) { * * @param string $str */ - public function filterByKeywords($str) { + public function filterByKeywords(string $str) { if ($str) { $filtered = array(); @@ -161,7 +161,7 @@ public function filterByKeywords($str) { * * @param string $parent */ - public function filterByParentUrl($parent) { + public function filterByParentUrl(string $parent) { $filtered = array(); foreach ($this->selection as $key => $Page) { @@ -179,7 +179,7 @@ public function filterByParentUrl($parent) { * * @param string $tag */ - public function filterByTag($tag) { + public function filterByTag(string $tag) { if ($tag) { $filtered = array(); @@ -200,7 +200,7 @@ public function filterByTag($tag) { * * @param string $regex */ - public function filterByTemplate($regex) { + public function filterByTemplate(string $regex) { if ($regex) { $filtered = array(); @@ -223,7 +223,7 @@ public function filterByTemplate($regex) { * * @param string $url */ - public function filterPrevAndNextToUrl($url) { + public function filterPrevAndNextToUrl(string $url) { if (array_key_exists($url, $this->selection)) { // To be able to hide the hidden pages as neighbors and jump directly to the closest non-hidden pages (both sides), // in case one or both neigbors is/are hidden, $this->excludeHidden() has to be called here already, because only excluding the hidden pages @@ -270,9 +270,9 @@ public function filterPrevAndNextToUrl($url) { * Filter all pages having one or more tag in common with $Page. If there are not tags defined for the passed page, * the selection will be an empty array. (no tags = no related pages) * - * @param object $Page + * @param Page $Page */ - public function filterRelated($Page) { + public function filterRelated(Page $Page) { $tags = $Page->tags; $filtered = array(); @@ -294,13 +294,13 @@ public function filterRelated($Page) { /** * Return the array with the selected (filtered and sorted) pages. * - * @param boolean $excludeHidden - * @param boolean $excludeCurrent - * @param integer $offset - * @param integer $limit + * @param bool $excludeHidden + * @param bool $excludeCurrent + * @param int $offset + * @param int $limit * @return array $this->selection */ - public function getSelection($excludeHidden = true, $excludeCurrent = false, $offset = 0, $limit = null) { + public function getSelection(bool $excludeHidden = true, bool $excludeCurrent = false, int $offset = 0, ?int $limit = null) { if ($excludeHidden) { $this->excludeHidden(); } @@ -318,7 +318,7 @@ public function getSelection($excludeHidden = true, $excludeCurrent = false, $of * * @param array $options */ - public function match($options) { + public function match(?array $options) { if (empty($options)) { return false; } @@ -343,14 +343,14 @@ function ($Page) use ($key, $regex) { * The option string consists of multiple pairs of * a data key and a sort order, separated by a comma like this: * $Selection->sortPages('date desc, title asc') - * The above example will sort first all pages in the selection by 'date' (descending) and then by 'title' (ascending). + * The above example will sort first all pages in the selection by 'date' (descending) and then by 'title' (ascending). * - * Valid values for the order are 'asc' and 'desc'. - * In case a sort order is missing in a key/order combination, the 'asc' is used as a fallback. + * Valid values for the order are 'asc' and 'desc'. + * In case a sort order is missing in a key/order combination, the 'asc' is used as a fallback. * - * @param string $options (comma separated list of keys and order) + * @param string|null $options */ - public function sortPages($options = false) { + public function sortPages(?string $options = null) { $sort = array(); $parameters = array(); diff --git a/automad/src/Core/SessionData.php b/automad/src/Core/SessionData.php index d2917d084..d2afcdf92 100644 --- a/automad/src/Core/SessionData.php +++ b/automad/src/Core/SessionData.php @@ -49,10 +49,10 @@ class SessionData { /** * Get the session data array or just one value in case $key is defined. * - * @param string $key + * @param string|null $key * @return mixed The data array or a single value */ - public static function get($key = false) { + public static function get(?string $key = null) { if (!isset($_SESSION['data'])) { $_SESSION['data'] = array(); } @@ -72,9 +72,9 @@ public static function get($key = false) { * Set a key/value pair in the session data array. * * @param string $key - * @param string $value + * @param mixed $value */ - public static function set($key, $value) { + public static function set(string $key, $value) { if (!isset($_SESSION['data'])) { $_SESSION['data'] = array(); } diff --git a/automad/src/Core/Shared.php b/automad/src/Core/Shared.php index a6767958c..473268d65 100644 --- a/automad/src/Core/Shared.php +++ b/automad/src/Core/Shared.php @@ -76,7 +76,7 @@ public function __construct() { * @param string $key * @return string The requested value */ - public function get($key) { + public function get(string $key) { if (array_key_exists($key, $this->data)) { return $this->data[$key]; } @@ -86,9 +86,9 @@ public function get($key) { * Set key/value pair in data. * * @param string $key - * @param string $value + * @param mixed $value */ - public function set($key, $value) { + public function set(string $key, $value) { $this->data[$key] = $value; } } diff --git a/automad/src/Core/Sitemap.php b/automad/src/Core/Sitemap.php index b1ff9636f..d1ad3650e 100644 --- a/automad/src/Core/Sitemap.php +++ b/automad/src/Core/Sitemap.php @@ -53,7 +53,7 @@ class Sitemap { * * @param array $collection */ - public function __construct($collection) { + public function __construct(array $collection) { if (!UserModel::getName()) { $sitemap = AM_BASE_DIR . '/sitemap.xml'; @@ -72,7 +72,7 @@ public function __construct($collection) { * @param array $collection * @param string $sitemap */ - private function generate($collection, $sitemap) { + private function generate(array $collection, string $sitemap) { if (!$base = AM_BASE_SITEMAP) { $protocol = 'http'; diff --git a/automad/src/Core/Str.php b/automad/src/Core/Str.php index aeb8c1d64..cec21d32d 100644 --- a/automad/src/Core/Str.php +++ b/automad/src/Core/Str.php @@ -42,7 +42,7 @@ defined('AUTOMAD') or die('Direct access not permitted!'); /** - * The Str class holds all string methods. + * The Str class holds all string methods. * * @author Marc Anton Dahmen * @copyright Copyright (c) 2016-2021 by Marc Anton Dahmen - https://marcdahmen.de @@ -60,12 +60,12 @@ class Str { * the strftime() syntax has to be used. * Multiple values can be passed as a CSV string for the locale parameter. * - * @param string $date - * @param string $format - * @param string $locale + * @param string|null $date + * @param string|null $format + * @param string|null $locale * @return string The formatted date */ - public static function dateFormat($date, $format, $locale = false) { + public static function dateFormat(?string $date, ?string $format = null, ?string $locale = null) { if ($date) { if (strpos($format, '%') !== false) { $original = setlocale(LC_TIME, 0); @@ -87,11 +87,11 @@ public static function dateFormat($date, $format, $locale = false) { /** * Set a default value for $str in case $str is empty. * - * @param string $str - * @param string $defaultValue + * @param string|null $str + * @param string|null $defaultValue * @return string The default value */ - public static function def($str, $defaultValue) { + public static function def(?string $str, ?string $defaultValue = null) { if (trim($str) === '') { $str = $defaultValue; } @@ -100,12 +100,12 @@ public static function def($str, $defaultValue) { } /** - * Escapes a string to be used safely in a JSON string. + * Escapes a string to be used safely in a JSON string. * - * @param string $str + * @param string|null $str * @return string The escaped string */ - public static function escape($str) { + public static function escape(?string $str) { // Escape values to be used in headless mode. // The json_encode() function is used to create a valid JSON string // with only one temporary key. @@ -122,10 +122,10 @@ public static function escape($str) { /** * Find the URL of the first image within rendered HTML markup. * - * @param string $str + * @param string|null $str * @return string The URL of the first image or false */ - public static function findFirstImage($str) { + public static function findFirstImage(?string $str) { preg_match('/]+src="([^"]+)"/is', $str, $matches); if (!empty($matches[1])) { @@ -136,10 +136,10 @@ public static function findFirstImage($str) { /** * Find the first paragraph in rendered HTML and return its inner HTML. * - * @param string $str + * @param string|null $str * @return string The inner HTML of the first paragraph or false */ - public static function findFirstParagraph($str) { + public static function findFirstParagraph(?string $str) { // First remove any paragraph only containing an image. $str = preg_replace('/

\s*<\/p>/is', '', $str); preg_match('/]*>(.*?)<\/p>/is', $str, $matches); @@ -152,11 +152,11 @@ public static function findFirstParagraph($str) { /** * Parse a markdown string. Optionally skip parsing in case $str is a single line string. * - * @param string $str - * @param boolean $multilineOnly + * @param string|null $str + * @param bool $multilineOnly * @return string The parsed string */ - public static function markdown($str, $multilineOnly = false) { + public static function markdown(?string $str, $multilineOnly = false) { // In case $str has no line breaks and $multilineOnly is enabled, skip parsing. if (strpos($str, "\n") === false && $multilineOnly) { return $str; @@ -174,23 +174,23 @@ public static function markdown($str, $multilineOnly = false) { /** * Perform a regex match. * - * @param string $str - * @param string $regex - * @return number 1 or 0 + * @param string|null $str + * @param string|null $regex + * @return int 1 or 0 */ - public static function match($str, $regex) { + public static function match(?string $str, ?string $regex = null) { return preg_match($regex, $str); } /** * Search and replace by regex. * - * @param string $str - * @param string $regex - * @param string $replace + * @param string|null $str + * @param string|null $regex + * @param string|null $replace * @return string The processed string */ - public static function replace($str, $regex, $replace) { + public static function replace(?string $str, ?string $regex = null, ?string $replace = null) { return preg_replace($regex, $replace, $str); } @@ -202,12 +202,12 @@ public static function replace($str, $regex, $replace) { * Note: To produce fully safe prefixes and directory names, * possible dots should be removed by setting $removeDots = true. * - * @param string $str - * @param boolean $removeDots - * @param number $maxChars + * @param string|null $str + * @param bool $removeDots + * @param int $maxChars * @return string The sanitized string */ - public static function sanitize($str, $removeDots = false, $maxChars = 100) { + public static function sanitize(?string $str, $removeDots = false, $maxChars = 100) { if (strlen($str) === 0) { return ''; } @@ -239,12 +239,12 @@ public static function sanitize($str, $removeDots = false, $maxChars = 100) { /** * Shortens a string keeping full words. Note that this method also first strips all tags from the given string. * - * @param string $str - * @param number $maxChars + * @param string|null $str + * @param int $maxChars * @param string $ellipsis * @return string The shortened string */ - public static function shorten($str, $maxChars, $ellipsis = ' ...') { + public static function shorten(?string $str, $maxChars, string $ellipsis = ' ...') { $str = Str::stripTags($str); $str = preg_replace('/[\n\r]+/s', ' ', $str); @@ -270,12 +270,12 @@ public static function shorten($str, $maxChars, $ellipsis = ' ...') { * In case the sanitized string is empty or the string is shorter than 6 chars while the * input string is longer than 12 chars, the string is replaced with a md5 hash shortened to 16 chars. * - * @param string $str - * @param boolean $removeDots - * @param integer $maxChars + * @param string|null $str + * @param bool $removeDots + * @param int $maxChars * @return string the slug */ - public static function slug($str, $removeDots = false, $maxChars = 100) { + public static function slug(?string $str, $removeDots = false, $maxChars = 100) { if (strlen($str) === 0) { return ''; } @@ -292,32 +292,32 @@ public static function slug($str, $removeDots = false, $maxChars = 100) { /** * Strip substring from end of string. * - * @param string $str - * @param string $end + * @param string|null $str + * @param string|null $end * @return string The processed string */ - public static function stripEnd($str, $end) { + public static function stripEnd(?string $str, ?string $end = null) { return preg_replace('/' . preg_quote($end, '/') . '$/', '', $str); } /** * Strip substring from start of string. * - * @param string $str - * @param string $start + * @param string|null $str + * @param string|null $start * @return string The processed string */ - public static function stripStart($str, $start) { + public static function stripStart(?string $str, ?string $start = null) { return preg_replace('/^' . preg_quote($start, '/') . '/', '', $str); } /** * Removes all HTML and Markdown (!) tags. * - * @param string $str + * @param string|null $str * @return string The clean string */ - public static function stripTags($str) { + public static function stripTags(?string $str) { return trim(strip_tags(Str::markdown(strip_tags($str)))); } } diff --git a/automad/src/Core/Toolbox.php b/automad/src/Core/Toolbox.php index f88d026d0..05be18c75 100644 --- a/automad/src/Core/Toolbox.php +++ b/automad/src/Core/Toolbox.php @@ -39,7 +39,7 @@ defined('AUTOMAD') or die('Direct access not permitted!'); /** - * The Toolbox class holds all methods to be used within the template files. + * The Toolbox class holds all methods to be used within the template files. * * @author Marc Anton Dahmen * @copyright Copyright (c) 2013-2021 by Marc Anton Dahmen - https://marcdahmen.de @@ -47,7 +47,7 @@ */ class Toolbox { /** - * Automad object. + * Automad object. */ private $Automad; @@ -57,25 +57,26 @@ class Toolbox { private $collection; /** - * The Automad object is passed as an argument. It shouldn't be created again (performance). - * @param mixed $Automad + * The Automad object is passed as an argument. It shouldn't be created again (performance). + * + * @param Automad $Automad */ - public function __construct($Automad) { + public function __construct(Automad $Automad) { $this->Automad = $Automad; $this->collection = $this->Automad->getCollection(); } /** - * Generate breadcrumbs to the current page, if the page's level is > 0 (not homepage / search results / page not found). + * Generate breadcrumbs to the current page, if the page's level is > 0 (not homepage / search results / page not found). * - * Options: - * - class: false (class of

    element) - * - excludeHidden: false (exclude hidden pages) + * Options: + * - class: false (class of
      element) + * - excludeHidden: false (exclude hidden pages) * * @param array $options * @return string The HTML of a breadcrumb navigation */ - public function breadcrumbs($options = array()) { + public function breadcrumbs(array $options = array()) { if ($this->Automad->Context->get()->level > 0) { $options = array_merge( array( @@ -107,30 +108,30 @@ public function breadcrumbs($options = array()) { } /** - * Configure the filelist to be used in foreach loops. + * Configure the filelist to be used in foreach loops. * * @param array $options */ - public function filelist($options = array()) { + public function filelist(array $options = array()) { $this->Automad->getFilelist()->config($options); } /** * Place an image. * - * Options: - * - file: false (filepath or glob pattern - when using a glob pattern, the first match is used) - * - width: false (width in pixels) - * - height: false (height in pixels) - * - crop: false (crop image) - * - class: false (class for the element) + * Options: + * - file: false (filepath or glob pattern - when using a glob pattern, the first match is used) + * - width: false (width in pixels) + * - height: false (height in pixels) + * - crop: false (crop image) + * - class: false (class for the element) * * @param array $options - (file: path/to/file (or glob pattern), width: px, height: px, crop: 1) * @return string The HTML for the image output */ - public function img($options = array()) { + public function img(array $options = array()) { // Default options - $defaults = array( + $defaults = array( 'file' => false, 'width' => false, 'height' => false, @@ -161,18 +162,18 @@ public function img($options = array()) { /** * Generate a list for the navigation below a given URL. * - * Options: - * - context: '/' (The parent URL) - * - hompage: false (include homepage to first-level nav) - * - excludeHidden: true (exclude hidden pages) - * - class: false (class of the
        element) - * - active: false (class of the active
      • element) + * Options: + * - context: '/' (The parent URL) + * - hompage: false (include homepage to first-level nav) + * - excludeHidden: true (exclude hidden pages) + * - class: false (class of the
          element) + * - active: false (class of the active
        • element) * * @param array $options * @return string The HTML of a navigation list */ - public function nav($options = array()) { - $defaults = array( + public function nav(array $options = array()) { + $defaults = array( 'context' => '/', 'homepage' => false, 'excludeHidden' => true, @@ -226,24 +227,24 @@ public function nav($options = array()) { /** * Generate a list for the navigation below the current page. - * Options are the same like those for nav() except the 'context' option. + * Options are the same like those for nav() except the 'context' option. * * @param array $options * @return string The HTML of the navigation list */ - public function navChildren($options = array()) { + public function navChildren(array $options = array()) { // Always set 'context' to the current page's URL by merging that parameter with the other specified options. return $this->nav(array_merge($options, array('context' => $this->Automad->Context->get()->url))); } /** * Generate a list for the navigation below the current page's parent. - * Options are the same like those for nav() except the 'context' option. + * Options are the same like those for nav() except the 'context' option. * * @param array $options * @return string The HTML of the navigation list */ - public function navSiblings($options = array()) { + public function navSiblings(array $options = array()) { // Set context to current parentUrl and overwrite passed options return $this->nav(array_merge($options, array('context' => $this->Automad->Context->get()->parentUrl))); } @@ -255,27 +256,27 @@ public function navSiblings($options = array()) { * @param array $options * @return string The HTML of the navigation list */ - public function navTop($options = array()) { + public function navTop(array $options = array()) { // Set context to '/' and overwrite passed options. return $this->nav(array_merge($options, array('context' => '/'))); } /** - * Generate full navigation tree. + * Generate full navigation tree. * - * Options: - * - all: true (expand all pages or only in current path) - * - context: '' (parent URL) - * - rootLevel: false (a kind of flexible context page at a given level) - * - excludeHidden: true (exclude hidden pages) - * - class: false (class of the
            element) - * - active: false (class of the active
          • element) + * Options: + * - all: true (expand all pages or only in current path) + * - context: '' (parent URL) + * - rootLevel: false (a kind of flexible context page at a given level) + * - excludeHidden: true (exclude hidden pages) + * - class: false (class of the
              element) + * - active: false (class of the active
            • element) * * @param array $options - (all: expand all pages (boolean), context: "/parenturl", rootLevel: integer) * @return string The HTML of the tree */ - public function navTree($options = array()) { - $defaults = array( + public function navTree(array $options = array()) { + $defaults = array( 'all' => true, 'context' => '', 'rootLevel' => false, @@ -355,7 +356,7 @@ public function navTree($options = array()) { * * @param array $options */ - public function newPagelist($options = array()) { + public function newPagelist(array $options = array()) { $this->pagelist(array_merge($this->Automad->getPagelist()->getDefaults(), $options)); } @@ -378,7 +379,7 @@ public function newPagelist($options = array()) { * * @param array $options */ - public function pagelist($options = array()) { + public function pagelist(array $options = array()) { $this->Automad->getPagelist()->config($options); } @@ -388,7 +389,7 @@ public function pagelist($options = array()) { * @param array $options * @return string The merged query string */ - public function queryStringMerge($options) { + public function queryStringMerge(array $options) { return http_build_query(array_merge($_GET, $options)); } @@ -397,8 +398,8 @@ public function queryStringMerge($options) { * * @param array $options */ - public function redirect($options) { - $options = array_merge(array( + public function redirect(array $options) { + $options = array_merge(array( 'url' => false, 'code' => 302 ), $options); @@ -414,7 +415,7 @@ public function redirect($options) { * * @param array $options */ - public function set($options) { + public function set(array $options) { foreach ($options as $key => $value) { if (preg_match('/' . Regex::$charClassAllVariables . '/', $key)) { if (strpos($key, '%') === 0) { diff --git a/automad/src/Core/View.php b/automad/src/Core/View.php index ea9f5ddbb..f2bee747f 100644 --- a/automad/src/Core/View.php +++ b/automad/src/Core/View.php @@ -36,12 +36,12 @@ namespace Automad\Core; -use Automad\UI as UI; +use Automad\UI\InPage; defined('AUTOMAD') or die('Direct access not permitted!'); /** - * The View class holds all methods to render the current page using a template file. + * The View class holds all methods to render the current page using a template file. * * When render() is called, first the template file gets loaded. * The output, basically the raw template HTML (including the generated HTML by PHP in the template file) @@ -61,17 +61,17 @@ */ class View { /** - * Multidimensional array of collected extension assets grouped by type (CSS/JS). + * Multidimensional array of collected extension assets grouped by type (CSS/JS). */ public $extensionAssets = array(); /** - * The Automad object. + * The Automad object. */ private $Automad; /** - * Set the headless mode for the current view. + * Set the headless mode for the current view. */ private $headless; @@ -86,7 +86,7 @@ class View { private $Runtime; /** - * An array of snippets defined within a template. + * An array of snippets defined within a template. */ private $snippets = array(); @@ -96,22 +96,22 @@ class View { private $template; /** - * The Toolbox object. + * The Toolbox object. */ private $Toolbox; /** * Define $Automad and $Page, check if the page gets redirected and get the template name. * - * @param object $Automad - * @param boolean $headless + * @param Automad $Automad + * @param bool $headless */ - public function __construct($Automad, $headless = false) { + public function __construct(Automad $Automad, bool $headless = false) { $this->Automad = $Automad; $this->headless = $headless; $this->Runtime = new Runtime($Automad); $this->Toolbox = new Toolbox($Automad); - $this->InPage = new UI\InPage(); + $this->InPage = new InPage(); $Page = $Automad->Context->get(); // Redirect page, if the defined URL variable differs from the original URL. @@ -134,7 +134,8 @@ public function __construct($Automad, $headless = false) { /** * Process the full markup - variables, includes, methods and other constructs. * - * Replace variable keys with its values, call Toolbox methods, call Extensions, execute statements (with, loops and conditions) and include template elements recursively. + * Replace variable keys with its values, call Toolbox methods, call Extensions, + * execute statements (with, loops and conditions) and include template elements recursively. * For example <@ file.php @>, <@ method { options } @>, <@ foreach in ... @> ... <@ end @> or <@ if @{var} @> ... <@ else @> ... <@ end @>. * * With and foreach: @@ -156,7 +157,7 @@ public function __construct($Automad, $headless = false) { * - @{:heightResized} * - @{:caption} * - * Tags/Filters: + * Tags/Filters: * Inside other foreach loops, the following runtime variables can be used within a snippet: * - @{:filter} * - @{:tag} @@ -167,7 +168,7 @@ public function __construct($Automad, $headless = false) { * @param string $directory - The directory of the currently included file/template * @return string The interpreted string */ - public function interpret($str, $directory) { + public function interpret(string $str, string $directory) { // Strip whitespace. $str = $this->stripWhitespace($str); @@ -175,7 +176,7 @@ public function interpret($str, $directory) { $str = $this->preProcessWrappingStatements($str); $str = preg_replace_callback('/' . Regex::markup() . '/is', function ($matches) use ($directory) { - // Variable - if the variable syntax gets matched, simply process that string as content to get the value. + // Variable - if the variable syntax gets matched, simply process that string as content to get the value. // In-page editing gets enabled here. if (!empty($matches['var'])) { return $this->processContent($matches['var'], false, true); @@ -210,17 +211,17 @@ public function interpret($str, $directory) { // Call snippet or method in order of priority: Snippets, Toolbox methods and extensions. if (array_key_exists($call, $this->snippets)) { - // Process a registered snippet. + // Process a registered snippet. Debug::log($call, 'Process registered snippet'); return $this->interpret($this->snippets[$call], $directory); } elseif (method_exists($this->Toolbox, $call)) { - // Call a toolbox method, in case there is no matching snippet. + // Call a toolbox method, in case there is no matching snippet. Debug::log($options, 'Calling method ' . $call . ' and passing the following options'); return $this->Toolbox->$call($options); } else { - // Try an extension, if no snippet or toolbox method was found. + // Try an extension, if no snippet or toolbox method was found. Debug::log($call . ' is not a snippet or core method. Will look for a matching extension ...'); $Extension = new Extension($call, $options, $this->Automad); $this->mergeExtensionAssets($Extension->getAssets()); @@ -242,7 +243,7 @@ public function interpret($str, $directory) { // Previous or next page. Use lowercase matches to be case insensitive. if (strtolower($matches['with']) == 'prev' || strtolower($matches['with']) == 'next') { - // Cache the current pagelist config and temporary disable the excludeHidden parameter to also + // Cache the current pagelist config and temporary disable the excludeHidden parameter to also // get the neighbors of a hidden page. $pagelistConfigShelf = $this->Automad->getPagelist()->config(); $this->Automad->getPagelist()->config(array('excludeHidden' => false)); @@ -350,7 +351,7 @@ public function interpret($str, $directory) { $runtimeShelf = $this->Runtime->shelve(); if (strtolower($matches['foreach']) == 'pagelist') { - // Pagelist + // Pagelist // Get pages. $pages = $this->Automad->getPagelist()->getPages(); @@ -385,7 +386,7 @@ public function interpret($str, $directory) { // Restore context. $Context->set($contextShelf); } elseif (strtolower($matches['foreach']) == 'filters') { - // Filters (tags of the pages in the pagelist) + // Filters (tags of the pages in the pagelist) // Each filter can be used as @{:filter} within a snippet. foreach ($this->Automad->getPagelist()->getTags() as $filter) { @@ -397,7 +398,7 @@ public function interpret($str, $directory) { $html .= $this->interpret($foreachSnippet, $directory); } } elseif (strtolower($matches['foreach']) == 'tags') { - // Tags (of the current page) + // Tags (of the current page) // Each tag can be used as @{:tag} within a snippet. foreach ($Context->get()->tags as $tag) { @@ -409,7 +410,7 @@ public function interpret($str, $directory) { $html .= $this->interpret($foreachSnippet, $directory); } } else { - // Files + // Files // The file path and the basename can be used like @{:file} and @{:basename} within a snippet. if (strtolower($matches['foreach']) == 'filelist') { @@ -459,9 +460,9 @@ public function interpret($str, $directory) { // Process each part and merge the partial result with the final result. foreach ($parts as $part) { - // Separate comparisons from boolean expressions and get a partial result. + // Separate comparisons from boolean expressions and get a partial result. if (!empty($part['expressionOperator'])) { - // Comparison. + // Comparison. // Merge default keys with $part to make sure each key exists in $part without testing. $part = array_merge( @@ -520,7 +521,7 @@ public function interpret($str, $directory) { break; } } else { - // Boolean. + // Boolean. // Get the value of the given variable. $expressionVar = $this->processContent($part['expressionVar']); @@ -570,7 +571,7 @@ public function interpret($str, $directory) { * * @param array $assets (Array containing two sub-arrays: $assets['.css'] and $assets['.js']) */ - public function mergeExtensionAssets($assets) { + public function mergeExtensionAssets(array $assets) { // Make sure, $this->extensionAssets has a basic structure to enable merging new assets. $this->extensionAssets = array_merge(array('.css' => array(), '.js' => array()), $this->extensionAssets); @@ -588,7 +589,7 @@ public function mergeExtensionAssets($assets) { * @param string $str * @return string The processed string */ - public function obfuscateEmails($str) { + public function obfuscateEmails(string $str) { if ($this->headless) { return $str; } @@ -600,8 +601,8 @@ public function obfuscateEmails($str) { // within tags from stand-alone ones. $regex = '/(]*href="mailto.+?<\/a>|(?P' . $regexEmail . '))/is'; - return preg_replace_callback($regex, function ($matches) { - // Only stand-alone addresses are obfuscated. + return preg_replace_callback($regex, function ($matches) { + // Only stand-alone addresses are obfuscated. if (!empty($matches['email'])) { Debug::log($matches['email'], 'Obfuscating'); @@ -619,7 +620,7 @@ public function obfuscateEmails($str) { } /** - * Render the current page. + * Render the current page. * * @return string The fully rendered HTML for the current page. */ @@ -646,7 +647,7 @@ public function render() { * @param string $str * @return string The processed string */ - public function resizeImages($str) { + public function resizeImages(string $str) { return preg_replace_callback('/(\/[\w\.\-\/]+(?:jpg|jpeg|gif|png))\?(\d+)x(\d+)/is', function ($match) { $file = AM_BASE_DIR . $match[1]; @@ -668,11 +669,11 @@ public function resizeImages($str) { * @param array $parameters * @return string The processed string */ - public function resolveUrls($str, $method, $parameters = array()) { + public function resolveUrls(string $str, string $method, array $parameters = array()) { $method = '\Automad\Core\Resolve::' . $method; // Find URLs in markdown like ![...](image.jpg?100x100). - $str = preg_replace_callback('/(\!\[[^\]]*\]\()([^\)]+\.(?:jpg|jpeg|gif|png))([^\)]*\))/is', function ($match) use ($method, $parameters) { + $str = preg_replace_callback('/(\!\[[^\]]*\]\()([^\)]+\.(?:jpg|jpeg|gif|png))([^\)]*\))/is', function ($match) use ($method, $parameters) { $parameters = array_merge(array(0 => $match[2]), $parameters); $url = call_user_func_array($method, $parameters); @@ -684,30 +685,30 @@ public function resolveUrls($str, $method, $parameters = array()) { }, $str); // Remove all temporary edit buttons inside HTML tags to avoid confusing the URL resolver. - $str = preg_replace_callback( + $str = preg_replace_callback( '/<([^>]+)>/s', function ($match) { - return '<' . preg_replace('/' . Regex::inPageEditButton() . '/s', '', $match[1]) . '>'; - }, + return '<' . preg_replace('/' . Regex::inPageEditButton() . '/s', '', $match[1]) . '>'; + }, $str ); // Find URLs in action, href and src attributes. // Note that all URLs in markdown code blocks will be ignored (<[^>]+). - $str = preg_replace_callback( + $str = preg_replace_callback( '/(<[^>]+(?:action|href|src))=((?:\\\\)?")(.+?)((?:\\\\)?")/is', function ($match) use ($method, $parameters) { - $parameters = array_merge(array(0 => $match[3]), $parameters); - $url = call_user_func_array($method, $parameters); - // Matches 2 and 4 are quotes. - return $match[1] . '=' . $match[2] . $url . $match[4]; - }, + $parameters = array_merge(array(0 => $match[3]), $parameters); + $url = call_user_func_array($method, $parameters); + // Matches 2 and 4 are quotes. + return $match[1] . '=' . $match[2] . $url . $match[4]; + }, $str ); // Inline styles (like background-image). // Note that all URLs in markdown code blocks will be ignored (<[^>]+). - $str = preg_replace_callback('/(<[^>]+)url\(\'?(.+?)\'?\)/is', function ($match) use ($method, $parameters) { + $str = preg_replace_callback('/(<[^>]+)url\(\'?(.+?)\'?\)/is', function ($match) use ($method, $parameters) { $parameters = array_merge(array(0 => $match[2]), $parameters); $url = call_user_func_array($method, $parameters); @@ -716,7 +717,7 @@ function ($match) use ($method, $parameters) { // Image srcset attributes. // Note that all URLs in markdown code blocks will be ignored (<[^>]+). - $str = preg_replace_callback('/(<[^>]+srcset)=((?:\\\\)?")([^"]+)((?:\\\\)?")/is', function ($match) use ($method, $parameters) { + $str = preg_replace_callback('/(<[^>]+srcset)=((?:\\\\)?")([^"]+)((?:\\\\)?")/is', function ($match) use ($method, $parameters) { $urls = preg_replace_callback('/([^,\s]+)\s+(\w+)/is', function ($match) use ($method, $parameters) { $parameters = array_merge(array(0 => $match[1]), $parameters); @@ -735,19 +736,19 @@ function ($match) use ($method, $parameters) { * @param string $str * @return string The meta tag */ - private function addMetaTags($str) { + private function addMetaTags(string $str) { $meta = "\n\t" . ''; return str_replace('', '' . $meta, $str); } /** - * Create the HTML tags for each file in $this->extensionAssets and prepend them to the closing tag. + * Create the HTML tags for each file in $this->extensionAssets and prepend them to the closing tag. * * @param string $str * @return string The processed string */ - private function createExtensionAssetTags($str) { + private function createExtensionAssetTags(string $str) { Debug::log($this->extensionAssets, 'Assets'); $html = ''; @@ -776,7 +777,7 @@ private function createExtensionAssetTags($str) { * @param string $key * @return string The value */ - private function getValue($key) { + private function getValue(string $key) { if (strpos($key, '?') === 0) { // Query string parameter. $key = substr($key, 1); @@ -805,12 +806,12 @@ private function getValue($key) { } /** - * Preprocess recursive statements to identify the top-level (outer) statements within a parsed string. + * Preprocess recursive statements to identify the top-level (outer) statements within a parsed string. * * @param string $str * @return string The preprocessed $str where all outer opening statement delimiters get an additional marker appended. */ - private function preProcessWrappingStatements($str) { + private function preProcessWrappingStatements(string $str) { $depth = 0; $regex = '/(' . '(?P' . preg_quote(AM_DEL_STATEMENT_OPEN) . '\s*(?:if|for|foreach|with|snippet)\s.*?' . preg_quote(AM_DEL_STATEMENT_CLOSE) . ')|' . @@ -819,7 +820,7 @@ private function preProcessWrappingStatements($str) { ')/is'; return preg_replace_callback($regex, function ($match) use (&$depth) { - // Convert $match to the actually needed string. + // Convert $match to the actually needed string. $return = array_unique($match); $return = array_filter($return); $return = implode($return); @@ -854,15 +855,15 @@ private function preProcessWrappingStatements($str) { * In case a variable is used as an option value for a method and is not part of a string, that variable doesn't need to be * wrapped in double quotes to work within the JSON string - the double quotes get added automatically. * - * By setting $inPageEdit to true, for every processed variable, a temporary markup for an edit button is appended to the actual value. - * That temporary button still has to be processed later by calling processInPageEditButtons(). + * By setting $inPageEdit to true, for every processed variable, a temporary markup for an edit button is appended to the actual value. + * That temporary button still has to be processed later by calling processInPageEditButtons(). * * @param string $str - * @param boolean $isOptionString - * @param boolean $inPageEdit + * @param bool $isOptionString + * @param bool $inPageEdit * @return string The processed $str */ - private function processContent($str, $isOptionString = false, $inPageEdit = false) { + private function processContent(string $str, bool $isOptionString = false, bool $inPageEdit = false) { // Prepare JSON strings by wrapping all stand-alone variables in quotes. if ($isOptionString) { $str = preg_replace_callback('/' . Regex::keyValue() . '/s', function ($pair) { @@ -875,7 +876,7 @@ private function processContent($str, $isOptionString = false, $inPageEdit = fal } return preg_replace_callback('/' . Regex::variable('var') . '/s', function ($matches) use ($isOptionString, $inPageEdit) { - // Get the value. + // Get the value. $value = $this->getValue($matches['varName']); // Resolve URLs in content before passing it to pipe functions @@ -956,7 +957,7 @@ private function processContent($str, $isOptionString = false, $inPageEdit = fal * @param string $directory * @return string $html */ - private function processFileSnippet($file, $options, $snippet, $directory) { + private function processFileSnippet(string $file, array $options, string $snippet, string $directory) { // Shelve runtime data. $runtimeShelf = $this->Runtime->shelve(); @@ -1004,7 +1005,7 @@ private function processFileSnippet($file, $options, $snippet, $directory) { * @param string $str * @return string The processed string */ - private function stripWhitespace($str) { + private function stripWhitespace(string $str) { $str = preg_replace('/\s*(' . preg_quote(AM_DEL_STATEMENT_OPEN) . ')~/is', '$1', $str); $str = preg_replace('/~(' . preg_quote(AM_DEL_STATEMENT_CLOSE) . ')\s*/is', '$1', $str); diff --git a/automad/src/System/Composer.php b/automad/src/System/Composer.php index 07fae9ebe..919286031 100644 --- a/automad/src/System/Composer.php +++ b/automad/src/System/Composer.php @@ -55,7 +55,7 @@ */ class Composer { /** - * Composer autoloader within the temporary extraction directory. + * Composer autoloader within the temporary extraction directory. */ private $autoloader = '/vendor/autoload.php'; @@ -65,7 +65,7 @@ class Composer { private $composerVersion = '2.1.6'; /** - * Composer extraction directory within temporary directory. + * Composer extraction directory within temporary directory. */ private $extractionDir = '/src'; @@ -75,7 +75,7 @@ class Composer { private $installDirCacheFile = false; /** - * The download URL for the composer.phar file. + * The download URL for the composer.phar file. */ private $pharUrl = false; @@ -98,9 +98,9 @@ public function __construct() { } /** - * Set up Composer by downloading and extracting the composer.phar to a temporary directory - * outside the document root, defining some environment variables, registering a shutdown - * function and including the autoloader. + * Set up Composer by downloading and extracting the composer.phar to a temporary directory + * outside the document root, defining some environment variables, registering a shutdown + * function and including the autoloader. */ private function setUp() { $installDir = $this->getInstallDir(); @@ -143,13 +143,13 @@ private function setUp() { } /** - * Run a given Composer command. + * Run a given Composer command. * * @param string $command * @param bool $getBuffer * @return string The command output on false or in case $getBuffer is true */ - public function run($command, $getBuffer = false) { + public function run(string $command, bool $getBuffer = false) { $this->shutdownOnError(); chdir(AM_BASE_DIR); @@ -213,7 +213,7 @@ public function run($command, $getBuffer = false) { * @param string $dir * @return string The full path to the downloaded composer.phar file */ - private function downloadPhar($dir) { + private function downloadPhar(string $dir) { $phar = false; if (is_writable($dir)) { @@ -279,7 +279,7 @@ private function getInstallDir() { } /** - * Generate a fresh installation directory for Composer. + * Generate a fresh installation directory for Composer. * * @return string The path to the directory */ diff --git a/automad/src/System/Mail.php b/automad/src/System/Mail.php index 459ff43b8..9854e038e 100644 --- a/automad/src/System/Mail.php +++ b/automad/src/System/Mail.php @@ -36,6 +36,8 @@ namespace Automad\System; +use Automad\Core\Automad; + defined('AUTOMAD') or die('Direct access not permitted!'); /** @@ -47,7 +49,7 @@ */ class Mail { /** - * Save status to avoid a second trigger for example in pagelists or teaser snippets. + * Save status to avoid a second trigger for example in pagelists or teaser snippets. */ private static $sent = false; @@ -55,10 +57,10 @@ class Mail { * Send mail. * * @param object $data - * @param object $Automad + * @param Automad $Automad * @return string the sendig status */ - public static function send($data, $Automad) { + public static function send(object $data, Automad $Automad) { // Prevent a second call. if (self::$sent) { return $data->success; diff --git a/automad/src/System/Packagist.php b/automad/src/System/Packagist.php index d0c57a067..ddd011043 100644 --- a/automad/src/System/Packagist.php +++ b/automad/src/System/Packagist.php @@ -47,13 +47,13 @@ */ class Packagist { /** - * Get a list op packages from Packagist filtered by type and tag. + * Get a list op packages from Packagist filtered by type and tag. * * @param string $type * @param string $tag * @return array The list of packages */ - public static function getPackages($type = '', $tag = '') { + public static function getPackages(string $type = '', string $tag = '') { $query = http_build_query( array( 'type' => $type, @@ -82,12 +82,12 @@ public static function getPackages($type = '', $tag = '') { } /** - * Make a request to the Packagist API. + * Make a request to the Packagist API. * * @param string $url * @return array The response data */ - private static function request($url) { + private static function request(string $url) { $data = array(); $options = array( diff --git a/automad/src/System/Theme.php b/automad/src/System/Theme.php index 8215c7174..e4e3dccc7 100644 --- a/automad/src/System/Theme.php +++ b/automad/src/System/Theme.php @@ -42,10 +42,10 @@ defined('AUTOMAD') or die('Direct access not permitted!'); /** - * The Theme utility class stores all meta data of an installed theme. + * The Theme class stores all meta data of an installed theme. * * @author Marc Anton Dahmen - * @copyright Copyright (c) 2018-2019 Marc Anton Dahmen - https://marcdahmen.de + * @copyright Copyright (c) 2018-2021 Marc Anton Dahmen - https://marcdahmen.de * @license MIT license - https://automad.org/license */ class Theme { @@ -60,7 +60,7 @@ class Theme { * @param string $themeJSON * @param array $composerInstalled */ - public function __construct($themeJSON, $composerInstalled) { + public function __construct(string $themeJSON, array $composerInstalled) { $json = false; $path = Str::stripStart(dirname($themeJSON), AM_BASE_DIR . AM_DIR_PACKAGES . '/'); $defaults = array( @@ -126,7 +126,7 @@ public function __construct($themeJSON, $composerInstalled) { * @param string $key The property name * @return string The returned value from the data array */ - public function __get($key) { + public function __get(string $key) { if (array_key_exists($key, $this->data)) { return $this->data[$key]; } @@ -138,7 +138,7 @@ public function __get($key) { * @param string $mask "page" or "shared" * @return array The mask array */ - public function getMask($mask) { + public function getMask(string $mask) { if (array_key_exists($mask, $this->data['masks'])) { return $this->data['masks'][$mask]; } @@ -152,7 +152,7 @@ public function getMask($mask) { * @param string $key * @return string The tooltip text */ - public function getTooltip($key) { + public function getTooltip(string $key) { if (array_key_exists($key, $this->data['tooltips'])) { return $this->data['tooltips'][$key]; } diff --git a/automad/src/System/Themelist.php b/automad/src/System/Themelist.php index e5ee207ed..f94eb55cb 100644 --- a/automad/src/System/Themelist.php +++ b/automad/src/System/Themelist.php @@ -74,17 +74,18 @@ public function __construct() { * corresponding to the AM_KEY_THEME variable. * * @param string $key - * @return object The requested theme object + * @return Theme The requested theme object */ - public function getThemeByKey($key) { + public function getThemeByKey(string $key) { if ($key && array_key_exists($key, $this->themes)) { return $this->themes[$key]; } } /** - * Return the Theme objects array. + * Return the Theme objects array. * + * @see Theme * @return array The array of Theme objects */ public function getThemes() { @@ -92,17 +93,17 @@ public function getThemes() { } /** - * Collect installed themes recursively. + * Collect installed themes recursively. * * A theme must be located below the "themes" directory. * It is possible to group themes in subdirectories, like "themes/theme" or "themes/subdir/theme". * * To be a valid theme, a directory must contain a "theme.json" file and at least one ".php" file. * - * @param string $path + * @param string|null $path * @return array An array containing all themes as objects. */ - private function collectThemes($path = false) { + private function collectThemes(?string $path = null) { if (!$path) { $path = AM_BASE_DIR . AM_DIR_PACKAGES; } diff --git a/automad/src/System/Update.php b/automad/src/System/Update.php index d02434a42..70a88b6b1 100644 --- a/automad/src/System/Update.php +++ b/automad/src/System/Update.php @@ -91,7 +91,7 @@ public static function getVersion() { /** * Run the actual update. * - * @return \Automad\UI\Response the response object + * @return Response the response object */ public static function run() { self::$timestamp = date('Ymd-His'); @@ -178,7 +178,7 @@ public static function run() { /** * Test if the server supports all required functions. * - * @return boolean True on success, false on error + * @return bool True on success, false on error */ public static function supported() { return (function_exists('curl_version') && class_exists('ZipArchive')); @@ -188,9 +188,9 @@ public static function supported() { * Move currently installed items to /cache/update/backup. * * @param array $items - * @return boolean True on success, false on error + * @return bool True on success, false on error */ - private static function backupCurrent($items) { + private static function backupCurrent(array $items) { self::preloadClasses(); $backup = AM_BASE_DIR . AM_UPDATE_TEMP . '/backup/' . self::$timestamp; @@ -226,14 +226,14 @@ private static function backupCurrent($items) { * @param string $str * @return string The version number */ - private static function extractVersion($str) { + private static function extractVersion(string $str) { if (preg_match('/\d[^\'"]+/', $str, $matches)) { return $matches[0]; } } /** - * Download zip-archive to be installed. + * Download zip-archive to be installed. * * @return string Path to the downloaded archive or false on error */ @@ -337,7 +337,7 @@ private static function items() { * @param string $data * @return string The path to the log file */ - private static function log($data) { + private static function log(string $data) { $file = AM_BASE_DIR . AM_UPDATE_TEMP . '/' . self::$timestamp . '.log'; FileSystem::makeDir(dirname($file)); file_put_contents($file, $data . "\r\n", FILE_APPEND); @@ -349,9 +349,9 @@ private static function log($data) { * Test if permissions for all items to be updated are granted. * * @param array $items - * @return boolean True on success, false on error + * @return bool True on success, false on error */ - private static function permissionsGranted($items) { + private static function permissionsGranted(array $items) { foreach ($items as $item) { $item = AM_BASE_DIR . $item; @@ -379,9 +379,9 @@ private static function preloadClasses() { * * @param string $archive * @param array $items - * @return boolean True on success, false on error + * @return bool True on success, false on error */ - private static function unpack($archive, $items) { + private static function unpack(string $archive, array $items) { $success = true; $zip = new \ZipArchive(); $itemsMatchRegex = '/^[\w\-]+(' . addcslashes(implode('|', $items), '/') . ')/'; diff --git a/automad/src/Test/Mock.php b/automad/src/Test/Mock.php index df1082089..b49c72578 100644 --- a/automad/src/Test/Mock.php +++ b/automad/src/Test/Mock.php @@ -59,7 +59,7 @@ class Mock extends TestCase { * @param string $template * @return object The Automad Mock */ - public function createAutomad($template = '') { + public function createAutomad(string $template = '') { $Shared = new Shared(); $Shared->data['shared'] = 'Shared default text content'; $collection = $this->createCollection($Shared, $template); @@ -89,11 +89,11 @@ public function createAutomad($template = '') { /** * Create a collection of test pages. * - * @param \Automad\Core\Shared $Shared + * @param Shared $Shared * @param string $template * @return array the collection */ - private function createCollection($Shared, $template) { + private function createCollection(Shared $Shared, string $template) { $theme = '../automad/tests/templates'; $testsDir = AM_BASE_DIR . '/automad/tests'; diff --git a/automad/src/UI/Components/Accordion/UnusedVariables.php b/automad/src/UI/Components/Accordion/UnusedVariables.php index 98fd82822..2915b516b 100644 --- a/automad/src/UI/Components/Accordion/UnusedVariables.php +++ b/automad/src/UI/Components/Accordion/UnusedVariables.php @@ -36,6 +36,7 @@ namespace Automad\UI\Components\Accordion; +use Automad\Core\Automad; use Automad\UI\Components\Form\Group; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -51,13 +52,13 @@ class UnusedVariables { /** * All unused variable fields in an accordion. * - * @param object $Automad + * @param Automad $Automad * @param array $keys * @param array $data * @param string $title * @return string the rendered unused variables accordion item */ - public static function render($Automad, $keys, $data, $title) { + public static function render(Automad $Automad, array $keys, array $data, string $title) { $fn = function ($expression) { return $expression; }; diff --git a/automad/src/UI/Components/Accordion/Variables.php b/automad/src/UI/Components/Accordion/Variables.php index ae79eaee7..4ad557e9a 100644 --- a/automad/src/UI/Components/Accordion/Variables.php +++ b/automad/src/UI/Components/Accordion/Variables.php @@ -36,6 +36,8 @@ namespace Automad\UI\Components\Accordion; +use Automad\Core\Automad; +use Automad\System\Theme; use Automad\UI\Components\Form\Group; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -51,14 +53,14 @@ class Variables { /** * A group of variable fields in an accordion. * - * @param object $Automad + * @param Automad $Automad * @param array $keys * @param array $data - * @param object $Theme + * @param Theme $Theme * @param string $title * @return string the rendered accordion item */ - public static function render($Automad, $keys, $data, $Theme, $title) { + public static function render(Automad $Automad, array $keys, array $data, Theme $Theme, string $title) { if (empty($keys)) { return ''; } diff --git a/automad/src/UI/Components/Alert/Alert.php b/automad/src/UI/Components/Alert/Alert.php index c91412c23..592c5a8be 100644 --- a/automad/src/UI/Components/Alert/Alert.php +++ b/automad/src/UI/Components/Alert/Alert.php @@ -53,7 +53,7 @@ class Alert { * @param string $class * @return string The rendered alert box markup */ - public static function render($text, $class = false) { + public static function render(string $text, string $class = '') { return <<< HTML
              $text diff --git a/automad/src/UI/Components/Alert/Danger.php b/automad/src/UI/Components/Alert/Danger.php index 469e162ba..873109088 100644 --- a/automad/src/UI/Components/Alert/Danger.php +++ b/automad/src/UI/Components/Alert/Danger.php @@ -52,7 +52,7 @@ class Danger { * @param string $text * @return string The rendered alert box markup */ - public static function render($text) { + public static function render(string $text) { return Alert::render($text, 'uk-alert-danger'); } } diff --git a/automad/src/UI/Components/Alert/Success.php b/automad/src/UI/Components/Alert/Success.php index 3060dc0f4..5c13cc66f 100644 --- a/automad/src/UI/Components/Alert/Success.php +++ b/automad/src/UI/Components/Alert/Success.php @@ -52,7 +52,7 @@ class Success { * @param string $text * @return string The rendered alert box markup */ - public static function render($text) { + public static function render(string $text) { return Alert::render($text, 'uk-alert-success'); } } diff --git a/automad/src/UI/Components/Alert/ThemeReadme.php b/automad/src/UI/Components/Alert/ThemeReadme.php index 493094a73..dc2af9507 100644 --- a/automad/src/UI/Components/Alert/ThemeReadme.php +++ b/automad/src/UI/Components/Alert/ThemeReadme.php @@ -36,6 +36,7 @@ namespace Automad\UI\Components\Alert; +use Automad\System\Theme; use Automad\UI\Components\Modal\Readme; use Automad\UI\Utils\Text; @@ -52,11 +53,11 @@ class ThemeReadme { /** * Render a theme readme alert box. * - * @param object $Theme + * @param Theme $Theme * @param string $id * @return string The rendered alert box markup */ - public static function render($Theme, $id = 'am-readme-modal') { + public static function render(Theme $Theme, string $id = 'am-readme-modal') { if (!AM_HEADLESS_ENABLED) { $Text = Text::getObject(); diff --git a/automad/src/UI/Components/Autocomplete/Jumpbar.php b/automad/src/UI/Components/Autocomplete/Jumpbar.php index d325303a9..3dfb87978 100644 --- a/automad/src/UI/Components/Autocomplete/Jumpbar.php +++ b/automad/src/UI/Components/Autocomplete/Jumpbar.php @@ -36,6 +36,7 @@ namespace Automad\UI\Components\Autocomplete; +use Automad\Core\Automad; use Automad\Core\Selection; use Automad\Core\Str; use Automad\UI\Response; @@ -56,10 +57,10 @@ class Jumpbar { * * The collected data consists of all page titles, URLs and all available tags. * - * @param object $Automad - * @return \Automad\UI\Response the response object + * @param Automad $Automad + * @return Response the response object */ - public static function render($Automad) { + public static function render(Automad $Automad) { $Response = new Response(); $values = array(); @@ -115,7 +116,7 @@ private static function packages() { * @param array $pages * @return array the generated items */ - private static function pages($pages) { + private static function pages(array $pages) { $Selection = new Selection($pages); $Selection->sortPages(AM_KEY_MTIME . ' desc'); diff --git a/automad/src/UI/Components/Autocomplete/Link.php b/automad/src/UI/Components/Autocomplete/Link.php index d55ccb0bf..ddcccef72 100644 --- a/automad/src/UI/Components/Autocomplete/Link.php +++ b/automad/src/UI/Components/Autocomplete/Link.php @@ -36,6 +36,7 @@ namespace Automad\UI\Components\Autocomplete; +use Automad\Core\Automad; use Automad\UI\Response; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -51,10 +52,10 @@ class Link { /** * Return a JSON formatted string to be used as autocomplete infomation in a link field. * - * @param object $Automad - * @return \Automad\UI\Response the response object + * @param Automad $Automad + * @return Response the response object */ - public static function render($Automad) { + public static function render(Automad $Automad) { $Response = new Response(); $autocomplete = array(); diff --git a/automad/src/UI/Components/Card/File.php b/automad/src/UI/Components/Card/File.php index a2a088161..e2c95c762 100644 --- a/automad/src/UI/Components/Card/File.php +++ b/automad/src/UI/Components/Card/File.php @@ -59,7 +59,7 @@ class File { * @param string $id * @return string The HTML of the card */ - public static function render($file, $id) { + public static function render(string $file, string $id) { $data = (object) self::getFileData($file); $preview = self::getPreview($file); $jsonData = json_encode($data); @@ -158,7 +158,7 @@ class="am-toggle-checkbox am-panel-bottom-link" * @param string $file * @return array The file data array */ - private static function getFileData($file) { + private static function getFileData(string $file) { $data = array( 'img' => false, 'filename' => basename($file), @@ -188,7 +188,7 @@ private static function getFileData($file) { * @param string $file * @return string The generated HTML of the preview */ - private static function getPreview($file) { + private static function getPreview(string $file) { if (Parse::fileIsImage($file)) { $imgPanel = new Image($file, 320, 240, true); $url = AM_BASE_URL . $imgPanel->file; diff --git a/automad/src/UI/Components/Card/Package.php b/automad/src/UI/Components/Card/Package.php index 705745ad8..2c330575c 100644 --- a/automad/src/UI/Components/Card/Package.php +++ b/automad/src/UI/Components/Card/Package.php @@ -54,7 +54,7 @@ class Package { * @param object $package * @return string The HTML of the card */ - public static function render($package) { + public static function render(object $package) { $Text = Text::getObject(); $badge = ''; $button = ''; diff --git a/automad/src/UI/Components/Card/Page.php b/automad/src/UI/Components/Card/Page.php index d409ebcbc..8bcf1e2d2 100644 --- a/automad/src/UI/Components/Card/Page.php +++ b/automad/src/UI/Components/Card/Page.php @@ -38,6 +38,7 @@ use Automad\Core\FileSystem; use Automad\Core\Image; +use Automad\Core\Page as CorePage; use Automad\Core\Str; use Automad\UI\Utils\Text; @@ -54,10 +55,10 @@ class Page { /** * Render a page card. * - * @param object $Page + * @param CorePage $Page * @return string The HTML of the card */ - public static function render($Page) { + public static function render(CorePage $Page) { $link = '?view=Page&url=' . urlencode($Page->get(AM_KEY_ORIG_URL)); $path = AM_BASE_DIR . AM_DIR_PAGES . $Page->path; @@ -128,7 +129,7 @@ class="am-panel-bottom-link" * @param array $images * @return string The generated HTML */ - private static function layout($images) { + private static function layout(array $images) { $count = count($images); $wFull = 320; $hFull = 240; @@ -188,9 +189,9 @@ private static function layout($images) { * @param string $gridW (uk-width-* suffix) * @return string The generated markup */ - private static function thumbnail($file, $w, $h, $gridW) { + private static function thumbnail(string $file, float $w, float $h, string $gridW) { $img = new Image($file, $w, $h, true); - return '
            • '; + return '
            • '; } } diff --git a/automad/src/UI/Components/Card/SearchFileResults.php b/automad/src/UI/Components/Card/SearchFileResults.php index b2546231f..0c8583f46 100644 --- a/automad/src/UI/Components/Card/SearchFileResults.php +++ b/automad/src/UI/Components/Card/SearchFileResults.php @@ -37,6 +37,7 @@ namespace Automad\UI\Components\Card; use Automad\Core\Str; +use Automad\UI\Models\Search\FileResultsModel; use Automad\UI\Utils\Text; defined('AUTOMAD') or die('Direct access not permitted!'); @@ -52,10 +53,10 @@ class SearchFileResults { /** * Render a search match card. * - * @param \Automad\UI\Models\Search\FileResultsModel $FileResultsModel + * @param FileResultsModel $FileResultsModel * @return string the rendered card */ - public static function render($FileResultsModel) { + public static function render(FileResultsModel $FileResultsModel) { $dir = dirname($FileResultsModel->path); $id = 'am-search-file-' . Str::slug($dir, true, 500); $results = ''; diff --git a/automad/src/UI/Components/Card/Theme.php b/automad/src/UI/Components/Card/Theme.php index ebf7a95e7..4f5760201 100644 --- a/automad/src/UI/Components/Card/Theme.php +++ b/automad/src/UI/Components/Card/Theme.php @@ -37,6 +37,7 @@ namespace Automad\UI\Components\Card; use Automad\Core\Image; +use Automad\System\Theme as SystemTheme; use Automad\UI\Components\Modal\Readme; use Automad\UI\Utils\FileSystem; use Automad\UI\Utils\Text; @@ -54,12 +55,12 @@ class Theme { /** * Render a theme card. * - * @param object $Theme - * @param object $activeTheme + * @param SystemTheme $Theme + * @param SystemTheme $activeTheme * @param string $id * @return string The HTML of the card */ - public static function render($Theme, $activeTheme, $id) { + public static function render(SystemTheme $Theme, SystemTheme $activeTheme, string $id) { $Text = Text::getObject(); $path = AM_BASE_DIR . AM_DIR_PACKAGES . '/' . $Theme->path; $files = FileSystem::glob($path . '/*'); diff --git a/automad/src/UI/Components/Card/User.php b/automad/src/UI/Components/Card/User.php index ae54897b9..29b2c4500 100644 --- a/automad/src/UI/Components/Card/User.php +++ b/automad/src/UI/Components/Card/User.php @@ -56,7 +56,7 @@ class User { * @param string $user * @return string the rendered user card */ - public static function render($user) { + public static function render(string $user) { $id = 'am-user-' . Str::slug($user); $fn = function ($expression) { return $expression; @@ -88,7 +88,7 @@ public static function render($user) { * @param string $id * @return string the rendered checkbox */ - private static function checkbox($user, $id) { + private static function checkbox(string $user, string $id) { $fn = function ($expression) { return $expression; }; diff --git a/automad/src/UI/Components/Form/CheckboxHidden.php b/automad/src/UI/Components/Form/CheckboxHidden.php index bdc28bfcc..433c301e0 100644 --- a/automad/src/UI/Components/Form/CheckboxHidden.php +++ b/automad/src/UI/Components/Form/CheckboxHidden.php @@ -52,10 +52,10 @@ class CheckboxHidden { * Create a checkbox to hide a page. * * @param string $key - * @param string $hidden + * @param bool $hidden * @return string The HTML for the hidden input field */ - public static function render($key, $hidden = false) { + public static function render(string $key, $hidden = false) { $Text = Text::getObject(); $checked = ''; diff --git a/automad/src/UI/Components/Form/CheckboxPrivate.php b/automad/src/UI/Components/Form/CheckboxPrivate.php index ad83a217b..3b5f47210 100644 --- a/automad/src/UI/Components/Form/CheckboxPrivate.php +++ b/automad/src/UI/Components/Form/CheckboxPrivate.php @@ -52,10 +52,10 @@ class CheckboxPrivate { * Create a checkbox to make a page private. * * @param string $key - * @param string $private + * @param bool $private * @return string The HTML for the private input field */ - public static function render($key, $private = false) { + public static function render(string $key, $private = false) { $Text = Text::getObject(); $checked = ''; diff --git a/automad/src/UI/Components/Form/Field.php b/automad/src/UI/Components/Form/Field.php index 9798ba3af..8c9e318b6 100644 --- a/automad/src/UI/Components/Form/Field.php +++ b/automad/src/UI/Components/Form/Field.php @@ -36,8 +36,10 @@ namespace Automad\UI\Components\Form; +use Automad\Core\Automad; use Automad\Core\Request; use Automad\Core\Str; +use Automad\System\Theme; use Automad\UI\Components\Fullscreen\Bar; use Automad\UI\Utils\Text; @@ -57,7 +59,7 @@ class Field { * @param string $key * @return string The converted label. */ - public static function labelFromKey($key) { + public static function labelFromKey(string $key) { $label = str_replace('+', '', $key); $label = ucwords(trim(preg_replace('/([A-Z])/', ' $1', str_replace('_', ' ', $label)))); @@ -67,15 +69,15 @@ public static function labelFromKey($key) { /** * Create a form field depending on the name. * - * @param object $Automad + * @param Automad $Automad * @param string $key * @param string $value - * @param boolean $removeButton - * @param object $Theme - * @param string $label + * @param bool $removeButton + * @param Theme|null $Theme + * @param string|null $label * @return string The generated HTML */ - public static function render($Automad, $key = '', $value = '', $removeButton = false, $Theme = false, $label = false) { + public static function render(Automad $Automad, string $key = '', $value = '', bool $removeButton = false, ?Theme $Theme = null, ?string $label = null) { // Convert special characters in $value to HTML entities. $value = htmlspecialchars($value); @@ -181,7 +183,7 @@ class="am-form-block-help uk-button uk-button-mini" * @param string $value * @return string The rendered markup */ - private static function fieldBlockEditor($editorId, $fullscreenBar, $attr, $value) { + private static function fieldBlockEditor(string $editorId, string $fullscreenBar, string $attr, $value) { return <<< HTML
              $fullscreenBar @@ -198,10 +200,10 @@ private static function fieldBlockEditor($editorId, $fullscreenBar, $attr, $valu * @param string $attr * @param string $value * @param string $shared - * @param boolean $isPage + * @param bool $isPage * @return string The rendered markup */ - private static function fieldCheckbox($text, $attr, $value, $shared, $isPage) { + private static function fieldCheckbox(string $text, string $attr, $value, $shared, bool $isPage) { if ($isPage) { $options = array( (object) array( @@ -268,7 +270,7 @@ class="uk-button uk-text-left uk-form-select uk-width-1-1" * @param string $attr * @return string The rendered markup */ - private static function fieldColor($color, $attr) { + private static function fieldColor(string $color, string $attr) { return <<< HTML
              @@ -285,7 +287,7 @@ private static function fieldColor($color, $attr) { * @param string $attrTime * @return string The rendered markup */ - private static function fieldDate($attr, $attrDate, $attrTime) { + private static function fieldDate(string $attr, string $attrDate, string $attrTime) { return <<< HTML
              @@ -321,7 +323,7 @@ class="uk-width-1-1" * @param string $value * @return string The rendered markup */ - private static function fieldDefault($attr, $value) { + private static function fieldDefault(string $attr, $value) { return <<< HTML