Jump to content

Craig

Members
  • Posts

    377
  • Joined

  • Last visited

  • Days Won

    6

Everything posted by Craig

  1. Another loose approach to MVC like the last few posts above, is how I usually do things. Pages API is the model, template files are controllers, and separate files for views: <?php namespace ProcessWire; // templates/home.php region('breadcrumbs', false); region('content', wireRenderFile('views/home/hero')); region('content+', wireRenderFile('views/home/testimonials')); region('content+', wireRenderFile('views/home/benefits')); $meta['name']['twitter:description'] = $settings->site_tagline; $meta['property']['og:description'] = $settings->site_tagline; <?php namespace ProcessWire; // templates/register.php require_once("./_forms.php"); $status = processRegisterForm(); if ($status && $status['success']) { wire('session')->redirect($page->url . 'success/'); } $view = [ 'status' => $status, ]; if (wire('input')->urlSegment(1) == 'success') { region('pageTitle', 'Registration complete'); $page->summary = ''; $viewName = 'views/register/success'; } else { $viewName = 'views/register/form'; } region('content', wireRenderFile($viewName, $view)); wireRenderFile() is an alias of the PW Files API 'render' function and takes a path to a file and an optional array of data/variables. I also use the Markup Regions functionality. The examples above are taken from this GitHub repo for one of my sites.
  2. Great! The best location will depend on your circumstances and how you're directing unauthenticated users to the site. I typically create a single SSO endpoint - like /sso/. In PW land this would be an 'sso' template with the template file contents having the above code, then a page named 'sso' using that template. Then you can point people to example.com/sso/?token=eyJhbGciOiJIUzI... and have the generated token in the query string. It will log them in, and then you can redirect them to the homepage, or other desired content. If you're not pointing people to a specific SSO page - and instead just directing them to the site with the token in the query string - you definitely want to catch this as soon as possible. Using the _init.php file prepended to every template is one of several good places to put it, but you could also create a hook (like in site/init.php or site/ready.php) as well, but not sure (without testing) which methods I'd want to hook. Using either of those approaches, I'd also wrap the code in a function you can call from them to keep it tidy and/or reusable - check for the token - if present, validate and log them in; if not - just do nothing.
  3. Hi Orkun! I use the Firebase PHP JWT library when I need to use JWTs, and I would do it like this with PW: use \Firebase\JWT\JWT; // http://example.com/sso/?token=eyJhbGciOiJIUzI... $token = wire('input')->get('token'); // If not token, show error? $key = 'ABC123'; // Store/load your key somewhere (e.g. PW's $config var) try { $decoded = JWT::decode($token, $key, array('HS256')); } catch (\Exception $e) { // Error parsing/decoding token - do not accept. Show error/redirect. } // print_r($decoded); // Find user based on supplied email. // Use other PW user fields or properties from JWT as necessary. $u = wire('users')->get('email=' . wire('sanitizer')->selectorValue($decoded->email)); if ( ! $u->id) { // Could not find user - don't exist. // Could create them at this point, if you have enough detail in the JWT to do so. } // Force user login wire('session')->forceLogin($u); // Go to another page (don't stay on this one) wire('session')->redirect('/');
  4. Craig

    Wireframe

    I think this is a great addition! I made something similar a while ago (called Widgets) but it wasn't as thorough, simple, or effective as your Component implementation. I look forward to trying it out ?
  5. I've been working with CodeIgniter for over 10 years, and although the general framework structure is predictable and documented, the custom code and database layout that has been developed with it could be... anything! You don't really have to learn it, but being aware of how it works might be useful in extracting the bits you need. I think these two documentation pages will be most helpful at this stage: https://codeigniter.com/user_guide/overview/appflow.html https://codeigniter.com/user_guide/overview/mvc.html As a rough guide, the URL patterns (/foo/bar) of a CodeIgniter app usually map directly to controllers. These should be in the application/controllers directory, and each file in here is a class. The example URL route of /foo/bar would call the bar() function in the Foo.php controller. Within the controller, it should (might!) call some 'models' - responsible for database interaction - and pass the result data into the 'views'. The views are responsible for transforming the data and results into HTML code that is sent to the browser, so this is likely where the main page layout should be, along with the different code for producing the different lists and detail pages. These live in the application/views folder. By default, there's no templating language or library used (like Twig) - the views are just mixed HTML and PHP, like ProcessWire, so should hopefuly be easy enough to follow. In terms of the database, you will need to look at how the current one is set up. With any luck, you could probably map each database table (books, movies, events) into PW templates of the same name, and set up PW fields that correspond to the columns in the database tables. After that, you would need to address any relationships or links between the tables or records, and decide on which PW structure will be best. For example, parent/child pages, Page reference fields, or creating a tagging/categories setup. If there's any budget for the project, I have some time over the coming weeks and would be happy to help you in the right direction if you think it would be useful ? Craig.
  6. @ryan Just submitted a site to the showcase on the new site, and the redirection took me to /sites/thanks/ - but this shows a 404 at the moment. ?
  7. Hi all! Happy New Year ? I recently rebuilt the website for classroombookings - my open-source room booking system for schools - using PW ? classroombookings.com I started the project itself way back in about 2006, when I was working in a school and needed a solution. Over the years I haven't made that many changes to it - mostly due to lack of time - but it has a modest userbase. Fast-forward to late 2018 when it required a major update to support PHP 7, fix some issues, and I also launch a hosted service. The website serves marketing, documentation and download/release functions for the project and I think PW is ideal for it. In the spirit of open source, the code for the website is also available on GitHub for anyone who wants to poke around and see my approach to PW web builds. The site is pretty standard, the only 'custom' bit is the releases section, which it pulls from GitHub using their API and creates/updates pages (Releases module). The frontend uses the Spectre CSS framework, and this is the first site I've built using it. Modules: AdminTemplateColumns ProcessDateArchiver SettingsFactory TextformatterHannaCode
  8. Looks brilliant ? Win 10 Firefox - whole page screenshot. The only thing off is the Docs menu is still opening to the right and appearing off-canvas as mentioned elsewhere in the thread.
  9. Ha ? Being a Windows user, I get Segoe UI when it's used, and I quite like it and prefer it over Arial. I have noticed some slight vertical alignment things but it doesn't bother me that much.
  10. Have you thought about not using any webfonts at all, and instead use the native or system CSS font stack? Doing this removes any cross-browser/device font rendering issues as well as removing several external resources (smaller download + even faster loading!) There seems to be a shift towards this: https://booking.design/implementing-system-fonts-on-booking-com-a-lesson-learned-bdc984df627f http://markdotto.com/2018/02/07/github-system-fonts/ https://make.wordpress.org/core/2016/07/07/native-fonts-in-4-6/ Other resources: https://woorkup.com/system-font/ https://css-tricks.com/snippets/css/system-font-stack/
  11. I saved a copy at the time - here they are (I think!) ?
  12. I would say Stripe is a leader in this area and a good option to consider. Failing that, there's always PayPal
  13. When I've needed to implement a multi-page process, I've stored the user's responses in the session, using the built-in ProcessWire Session handling code. If anything needs to be permanent at the end of the process, only then would I create the necessary pages.
  14. You need to call this as a function to get all POST data: $input->post();
  15. I've done an implementation of "magic link" logins via email on a previous (non-PW) site using HMAC SHA1 to avoid having to store passwords. On an upcoming site, I plan to do a similar thing but using JWTs to encode and verify the data, as it's a better standard than just concatenating a bunch of values
  16. You can double-click the bin icon on file/image fields to mark all items for deletion.
  17. I recently experienced a similar effect too, across three sites on two very similar servers. Running 5 requests with no caching against the PW Admin login page, as guest, these results are the median response time for just the page request: Server 1, PHP 5.6.15, Site A, PW 2.7.3: 217ms Server 2, PHP 5.6.22, Site B, PW 2.7.1: 293ms Server 2, PHP 5.6.22, Site C, PW 3.0.17: 672ms I noticed the slower time when Site C was first launched, but had little time to really investigate it there and then, and haven't got round to it since.
  18. Bandcamp might be a good option for the selling part?
  19. I can see the REST topic being split into its own thread, but on that subject here are some of my own observations/notes based on some recent projects. URLs: Generally, lots of them are needed. This either means lots of pages/templates to keep track of, or implement routing logic in a template and call other classes/functions/modules as required. Content Type, Input Method and errors: Detecting and responding correctly to content type headers has to be done manually - or just ignored, and respond with your chosen format. This is generally OK, but uncaught exceptions or errors will just show HTML instead. Sometimes it's necessary to implement DELETE and PUT HTTP methods as well. Input data: PW doesn't allow deeply-nested arrays/objects (WireInputData@cleanArray) which has proven problematic. Slightly related to the above point - but sometimes data is sent as regular encoded form data, and other times it is JSON or XML in the raw PHP input body. Returning objects: sending page data means creating arrays and specifying exactly should be sent. For text/number fields it's not too bad, but is much more involved when images and Page fields are used. My solutions for this range from implementing toArray() methods/hooks, right up to third party library http://fractal.thephpleague.com/.
  20. In something similar, I stored this in a sort of "availability" custom database table. It was quite simple though, with two columns: day_of_week (int) time (time) The UI wasn't quite like yours - it was day of week, and then add multiple time ranges (e.g. 9am-12pm and another could be 2pm-5pm). The end result was the same as what you are wanting to achieve though. You could add an ID and/or date field as well depending on how you set up your schedule too.
  21. Same, but just with Pingdom It's interesting to see the subtle differences between the services, and the gradings they come up with.
  22. WordPress: Grade D 65, 10.29 seconds load time, 3.5 MB page size, and 206 (!!) requests (URL) ProcessWire: Grade A 93, 1.73 seconds load time, 2.5 MB page size, and 70 requests (URL) (Using the same service and location) Good work
  23. Would this module be any good? http://modules.processwire.com/modules/fieldtype-select-file/
  24. I think one solution which may work here is to add these as separate fields to your node/router template, using the fieldtypes that already exist. Or is there a specific reason you would want these in one field? Proposed fields for your router template: IP address: text. Lat/Lon: MapMarker Hardware: text? Firmware: text? Connection time: text/integer? Your API "nodeinfo" data can hopefully be decoded and transformed so you can get the values easily - what format is it in? Plain text, or something like JSON or XML? Here's some example code to update a router page that has separate fields for your data: $router = $pages->get(1234); // a router/node page by its ID $router->ip_address = '127.0.0.1'; $router->geo->lat = 54.12; $router->geo->lng = -1.2; $router->hardware = 'cisco'; $router->firmware = 'cisco-ios-fw-100'; $router->connection_time = 42;
×
×
  • Create New...