Jump to content

ESRCH

Members
  • Posts

    80
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by ESRCH

  1. Hi, I don't know how to solve this, but when viewing the source on my Android using the "VT View Source" application, it appears as if the extra character is actually after the </ul>, not before. Maybe this helps solving the problem?
  2. I am considering using ProCache on a future website, but I would like to know whether it works with page-level access restrictions. As I understand, ProCache bypasses PHP and the database completely, so I am assuming that it will not be able to check access restrictions before serving the page, is this correct?
  3. Installing the module seems obvious, but some CMSs automatically load modules if they are placed in a certain folder, so one never knows... Anyway, I'm glad to read that it works now
  4. I think that it should be $p->blog_categories->title. Also, wasn't the title "Swatch" rather than "Swatches" (at least it was in the first post)?
  5. You should maybe echo something, just to check whether the function gets called at all. Also a dumb question, but have you installed the module that you are developing?
  6. The following line is wrong $this->sanitizer($concatenatedName, true); It should be $p->name = $this->sanitizer->pageName($concatenatedName);
  7. $p->blog_categores->title == 'Swatch'; For the $p->createdUser, you can actually still use $p->createdUser, since the toString method of the page will convert it to its page id.
  8. Putting this in a separate module is indeed cleaner. You probably already read these pages, but I'm putting the links here just in case, since they really helped me develop my own modules/hooks: https://processwire.com/api/hooks/ http://wiki.processwire.com/index.php/Module_Creation Also, the Helloworld Module in /site/modules is a great example module to get going.
  9. I think it looks really good. I like how it helps focus very clearly on what you are working on (e.g., the page list, page edition, etc.), and puts all other considerations to the side (navigation, etc.).
  10. There's a really great and simple example given by ryan here that can help you understand. In your case, you should be able to do the following (not tested): $pages->addHook('saveReady', function($event) { $sanitizer = wire('sanitizer'); $pages = $event->object; $page = $event->arguments(0); if($page->template == 'blog_page' && $page->blog_categories == 'Swatch') { // You can build the string as you wish, here is an example $concatenatedName = $page->blog_date; $concatenatedName .= '-' . $page->createdUser; $concatenatedName .= '-' . $page->blog_brand; $concatenatedName .= '-' . $page->blog_name; $page->title = $concatenatedName; $page->name = $sanitizer->pageName($concatenatedName); } });
  11. There are different solutions depending on which page you want to use as the root of your navigation: 1. You want to use the root page You use the solution that you have given. 2. You want to use the pages just under the root page You define the root of the navigation using $page->rootParent, then loop over its children: $root = $pages->get("/"); $navigationRoot = $page->rootParent; $children = $navigationRoot->children(); // Uncomment the following if you want to keep a link to the home page //$children->prepend($root); foreach($children as $child) { echo "<li><a href='{$child->url}'>{$child->title}</a></li>\n"; } I sometimes use this to do a secondary navigation within a section. 3. You want to use pages with the same template This is very useful to create a subnavigation. For example, imagine you have a structure like this: ... (Any kind of structure above) -- Category 1 ---- Subcategory 1.1 ------ Product 1.1.1 ------ Product 1.1.2 ---- Subcategory 1.2 ------ Product 1.2.1 ...etc. It is often useful to do a subnavigation of the categories when you are on a Product page. The way you could do this is like this: $navigationRoot = $page->parent("template=category")->parent; $categories = $navigationRoot->children("template=category"); foreach($categories as $category) { echo "<li><a href='{$category->url}'>{$category->title}</a></li>\n"; } If you want to show the subcategories too, you can loop across $category->children. In all these cases, you can go any level deeper by using Jan's technique (and possibly using a counter to limit the depth).
  12. Oh, OK, in over my head then Thanks for the reply anyway!
  13. Here's my take on the problem, but I might be in over my head... When looking at the PW source code for ProcessPageEdit.php, the buildForm function seems to be called on line 112, before the processSave function (which calls processInput) is called on line 115. So when hooking after buildForm, the errors have not yet been set by processInput, so you can't purge them with getErrors(true). Setting the hook on the processInput function might do the trick?
  14. I would suggest reading this blog post, which lists all new stuff in Processwire 2.5. There are so many things, it's really impressive. I have actually bookmarked it due to all the really useful new functions. The subselectors are in the section "Selectors", which doesn't appear in the top navigation, but comes just after "Sanitizer" and just before "Session".
  15. Hi, Another way to do this is to use subselectors, which were introduced in Processwire 2.5. The code would then be: $pages->find("parent.id=[pagefield1.pagefield2.field=value]"); I love subselectors...
  16. Hmmm... Probably not that simple, since admin urls would also need to the right place. Maybe the code of the Multi Site module (Github) by apeisa could give some indications on how to proceed?
  17. @Soma Thanks for the correction, I wasn't aware of this (and I incorrectly changed adrianmak's code). I made an edit in my post so that others might look at your comment.
  18. I would assume that the simplest way would be to modify the .htaccess file by: Redirecting www.peterdekeer.be/admin to admin.peterdekeer.be; and below that, Rewriting admin.peterdekeer.be as www.peterdekeer.be/admin I must admit that I would have to look up how to do this exactly...
  19. Not directly related to your question, but if your tag list is getting too long, it might be useful to activate the "Page Auto Complete" module from Core, which allows you to type in the tags that you want to add, instead of clicking through the list. I find this much easier when I have long lists of tags. Using this module, an approach that I often use for tagging is the following: Create a "tag" template with only a title field Create a "Tags" page under which you will put all the tags Create a "tags" Page field with the following options:Multiple pages allowed Parent of selectable pages: Select the "Tags" page created previously Template of selectable pages: Select the "tag" template Input field type: Select "PageAutoComplete" Check the "Allow new pages to be created from field" option Now, when entering tags, you can type in the name, if it exists already you an select it, otherwise press "Enter" and the tag will be created automatically.
  20. One last attempt to suggest using the api, then I'm gone Instead of changing your source data, you can let the API create the pages for you when needed. So for a (simplified) table like this: Bibliography Type Document Title ----------------- ---------------------- Book Interesting Book 1 Book Interesting Book 2 Magazine Fascinating Magazine 1 .... you could use the following code, which automatically creates the pages for you function getBibliographyType($name) { $template = 'bibliography-type'; $parent = $pages->get('/bibliography-types/'); static $bibliographyTypes = array(); if (isset($bibliographyTypes[$name])) { return $bibliographyTypes[$name]; } else { // Create the bibliography-type page $p = new Page(); $p->template = $template; $p->parent = $parent; $p->name = wire('sanitizer')->pageName($name); $p->title = wire('sanitizer')->text($name); $p->save(); // Save bibliography type id for future calls, avoiding calls to the database $bibliographyTypes[$name] = $p; return $p; } } $f = $page->import_file->filename; $csvDelimiter = ','; $csvEnclosure = '"'; $templateName = 'Document'; $parent = $pages->get('/documents/'); while (($data = fgetcsv($f, 0, $csvDelimiter, $csvEnclosure)) !== false) { $bibliographyType = getBibliographyType($data[0]); $title = $data[1]; $p = new Page(); $p->template = $templateName; $p->parent = $parent; $p->name = $sanitizer->pageName($title); $p->title = $sanitizer->text($title); $p->bibliography_type = $bibliographyType; $p->save(); }
  21. Your method seems secure enough. You are after all not sending a 404, so your user already knows that the url that they originally requested exists. Another method is to use the session to store the redirect url. So in the restricted page you would do: if (!$user->isLoggedin()) { // Store requested url in the session, then redirect $session->set('redirect', $page->url); $session->redirect($pages->get('template=login')->url); } and on the login page you could have // Edit: This code is not correct as-is, please note Soma's post below including the try-catch block around the login code! <?php if ($user->isLoggedin()) { $session->redirect($pages->get('/')->url); } if ($input->post->user && $input->post->pass) { $username = $sanitizer->username($input->post->user); $password = $input->post->pass; if ($session->login($username, $password)) { if ($redirectUrl = $session->get('redirect')){ $session->remove('redirect'); $session->redirect($redirectUrl); } else { $session->redirect($pages->get('/')->url); } } else { $error = "Wrong username or password. Login failed."; } }
  22. Just as a side note, instead of doing $lang = ($user->language->name == 'default') ? '' : $user->language->name . '/'; and then <a href="{$config->urls->root}{$lang}user/logoff">$logoff_text</a> it seems easier to do the following: <a href="<?php echo $pages->get('/user/logoff/')->url; ?>">$logoff_text</a> $page->url automatically gives you the localized url for the user's language.
  23. Hi adrianmak, This seems to be a bug, I submitted a pull request to correct this. The problem is that when logging out, the user is changed to guest, and the language is set back to default. Interestingly, the $user variable still points to the logged out user (adrian in your case), while wire('user'), which is used by the __() translation function, points to guest. While waiting for the correction to the core, you can solve this issue by adding the following line after $session->logout(): wire('user')->language = $user->language; This will set the language back to what it was before logging out, and the correct translation will be shown.
×
×
  • Create New...