Jump to content

Sebi

Members
  • Content Count

    16
  • Joined

  • Last visited

Community Reputation

54 Excellent

About Sebi

  • Rank
    Jr. Member
  • Birthday 03/08/1991

Contact Methods

  • Website URL
    https://www.sebi.world

Profile Information

  • Gender
    Male
  • Location
    Bielefeld, Germany

Recent Profile Visitors

787 profile views
  1. Sebi

    Twack

    Since it's featured in ProcessWire Weekly #310, now is the time to make it official: Here is Twack! I really like the following introduction from ProcessWire Weekly, so I hope it is ok if I use it here, too. Look at the project's README for more details! Twack is a new — or rather newish — third party module for ProcessWire that provides support for reusable components in an Angular-inspired way. Twack is implemented as an installable module, and a collection of helper and base classes. Key concepts introduced by this module are: Components, which have separate views and controllers. Views are simple PHP files that handle the output for the component, whereas controllers extend the TwackComponent base class and provide additional data handling capabilities. Services, which are singletons that provide a shared service where components can request data. The README for Twack uses a NewsService, which returns data related to news items, as an example of a service. Twack components are designed for reusability and encapsulating a set of features for easy maintainability, can handle hierarchical or recursive use (child components), and are simple to integrate with an existing site — even when said site wasn't originally developed with Twack. A very basic Twack component view could look something like this: <?php namespace ProcessWire; ?> <h1>Hello World!</h1> And here's how you could render it via the API: <?php namespace Processwire; $twack = $modules->get('Twack'); $hello = $twack->getNewComponent('HelloWorld'); ?> <html> <head> <title>Hello World</title> </head> <body> <?= $hello->render() ?> </body> </html> Now, just to add a bit more context, here's a simple component controller: <?php namespace ProcessWire; class HelloWorld extends TwackComponent { public function __construct($args) { parent::__construct($args); $this->title = 'Hello World!'; if(isset($args['title'])) { $this->title = $args['title']; } } } As you can see, there's not a whole lot new stuff to learn here if you'd like to give Twack a try in one of your projects. The Twack README provides a really informative and easy to follow introduction to all the key concepts (as well as some additional examples) so be sure to check that out before getting started. Twack is in development for several years and I use it for every new project I build. Also integrated is an easy to handle workflow to make outputs as JSON, so it can be used to build responses for a REST-api as well. I will work that out in one section in the readme as well. If you want to see the module in an actual project, I have published the code of www.musical-fabrik.de in a repository. It runs completely with Twack and has an app-endpoint with ajax-output as well. I really look forward to hear, what you think of Twack🥳!
  2. Hi @MateThemes, ProcessWire allows you to have any custom folder you want in its root, so you can leave your cam-directory where it is. The path to the images will stay the same. So, if you included an image with <img src="/cam/someimage.jpg"/> before, you do it just like that in your processwire-template file. Just a small restriction to notice: You must not create a page with "cam" as path in processwire, because that will block access to your folder.
  3. @flydev In my version, BasicAuth is the preferred way to request a jwt-token. After that, you have to add the token to each request.
  4. Hello everyone, while building an app-interface for a page, I developed some changes and improvements to this module, which I made available as a pull request. But @thomasaull and I are not quite sure if it makes sense to transfer these basic changes into the main module as well. Therefore we would like to hear your opinion: What do you think of the new module version? Which features would be useful for you? I have developed several new features that allow the administration of Api accesses via the ProcessWire backend. I also revised the authentication and added a new Double-JWT option that works with long-lasting refresh and short-lived access-tokens. New Features: New menu item "Restapi" in the ProcessWire menu under "setup Management of Api accesses (applications) outsourced to the new menu item Apikeys now authorize api-access Creation of multiple applications with different auth types possible Double-JWT Authentication, renewable tokens token-sessions can be viewed and deleted in the backend Improved exception handling: Each endpoint can throw exceptions, which are then output with the appropriate HTTP status header and message.
  5. I wrote an api-module a few years ago, where the module generated a custom template (e.g. "api-page"), which could be used to create one or more endpoint-pages. To handle calls to these pages I used ProcessPageView::pageNotFound like @bernhard did: $this->addHookBefore('ProcessPageView::pageNotFound', $this, 'handleApiRequest'); public function handleApiRequest(HookEvent $e) { $page = $e->arguments[0]; if ($page->template === 'api-page') { // handle request here... $otherEvent = $e->arguments(0); // grab event provided to PageRender::renderPage $e->replace = true; // prevent PageRender::renderPage from being called } } It worked nice for me, but I cannot say if caching or multi-language works better in this hook. pageNotFound should be called later than execute, so there is a chance that it helps 🤷‍♂️
  6. Hi eydun, I try to reuse fields if they have the same use-case. No template-prefixes. When your site gets more complex, you can use tags for your fields to get a better structure in your fields-overview.
  7. Hi @Juergen, you're right! Generally speaking, the module does not work automatically in all functions where ProcessWire returns a list of pages ($pages->find(), $page->children(), $page->find(), $page->parents(), ...). The reason for this is, that the used Hooks to block access will not be triggered in the list functions. The only way to filter out all pages that are unreleased, is to add filtering for the PageAccessReleasetime-fields in your selector. For convenience, I added the selector as a static attribute to the module: $onlyReleasedPages = $page->children(PageAccessReleasetime::selector); I would be really thankful if anybody had a better way to implement automatic filtering for unrelease pages, like it already works for ProcessWire's page-status. But since then adding PageAccessReleasetime::selector to selectors is a good workaround.
  8. That's fine. In our case it was necessary to explicitly add the line in the .htaccess-file, but that should be the last solution if everything else fails. We already had a similar solution like @pmichaelis's code example to use $_SERVER if apache_request_headers fails. Maybe its more save to check for the function 'apache_request_headers' to exist: if(function_exists("apache_request_headers")) {
  9. @thomasaull @pmichaelis We had similar issues with the Authorization-header, depending on the server's configuration. In our case, adding the following `RewriteRule` to the .htaccess-file solved the problems: RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  10. I have a (small) new version for you: v1.0.4 adds a $page->listable() hook. If you want to check wether a page should be accessible in list-views, you should use this call to double check if each page can be seen. For detail-views or to check wether a list-item can be linked to a detail-view, you should continue to use $page->viewable().
  11. Hey @szabesz, thank you for this hint. I did not know about @adrian's module. Finally I got time to install it and look into the code. I really like that it also cares for limiting view- and editing-rights in the backend, what PageAccessReleasetime currently doesn't. But it could be a useful feature for PageAccessReleasetime as well. In the current version every backend-user can see unreleased pages in the pagetree. I don't like that the module deals with the HTML shown in the frontend if a user cannot access a page. PageAccessReleasetime instead throws a 404 exception, what can be acceptable for the releasetime context. If I think of a PageAccessUserrole-module, it would be better to throw a 401 exception that leads to a custom 401 page where a login-form is shown. But ProcessWire seems not to support other exception pages than 404 and there is no other core exception class than Wire404Exception. Let me know if you have a practical solution for it, where my module does not have to generate its own HTML for the error page. I think that is something that the template-developer should be aware of and not the module.
  12. We are online! PageAccessReleasetime is now available in the ProcessWire modules directory! 🤩 I think about building some more access-modules for different use cases: userrole- and user-fields - limits a page to be accessable only for given userroles or users password protection - a password-field (+activate-field), password-validation-functionality, maybe a render function for the login-form in the frontend What do you think about it?
  13. @flydev The module is registered and waits for approval ☺️
  14. Hi @Robin S, thanks for your help making the module even better and more useable. I think I found a good solution to fullfill both requirements. With version 1.0.2 you can choose in module's configuration wether the fields should be added globally or only to selected templates. You can choose the templates via ASMSelect, if the checkbox is unchecked. I do check wether the fields were added manually in the template as well, and check the template if all fields were found. I actually find my solution with checkboxes more understandable for normal users. If you uncheck the option "Activate Releasetime from?", it is very clear that the no releasetime is active. If I'd use only the datetime fields without checkbox, I would at least add a notice that gives a hint about the possibility to leave it blank. Of course it's a trifle, but I've worked with customers who would otherwise have had queries about it. I've heeded your advice about explaining selectors in the documentation. For convenience, I added a constant with the selectorstring that is needed to filter unreleased pages. To filter unreleased pages, add the PageAccessReleasetime::selector to your selector: $onlyReleasedPages = wire('pages')->find('template.name=news, ' . PageAccessReleasetime::selector); I thought about manipulating the page's status to achieve this without adding a custom selector part to each query, but I haven't found anything useful yet. Extending the selector seems to be the best solution at the moment. Thanks again for your support! 😇
  15. Hey @dragan, thanks for this hint! I did not have much contact with multilanguage setups in the past, so I hope I added translatable string support the right way in version 1.0.1 of the module. Additionally I removed the german date formats for the inputs. I think, that is something that german users have to configure on their own if needed.
×
×
  • Create New...