Jump to content

Soma

Moderators
  • Posts

    6,798
  • Joined

  • Last visited

  • Days Won

    158

Everything posted by Soma

  1. There's no "easy" way. There this new module by Ryan, http://modules.proce...eldtype-concat/ but that isn't for this case and use in find(). But you could find the pages and foreach the resulting PageArray, then cycle them and calculate the prices and store them to the page temporarely. Then sort by that property. For example: foreach($products as $p) { $p->endprice = $p->price + ($p->price / 100 * $p->vat); } foreach($products->sort("-endprice") as $p) { echo $p->endprice; } You could make a module that creates a function to $pages, so you could use $pages->findProducts();. Or have an php include with functions that you can use the above with a simple call like "echo getProductsList();" in your templates
  2. Hmm not sure, this would be easier (back to root) using parents->has() if ($allowedPage->parents->has($page)) $session->redirect("$allowedPage->url"); Another option would be to test in the clients, and client template to check if access is granted and redirect. So simply a role, permission based solution.
  3. If you put the Rules right after the "RewriteEngine on", there's nothing else that would make it not work and PW rules afterwards won't get executed at all obviously. I can't think of anything why it shouldn't work. Maybe something on your host is configured differently. Could it be that files with two "." in the filename are a problem for you?
  4. Hm and where in the htaccess have you added the rules exactly?
  5. It works fine here (tested). The request of an image from another domain is blocked. If pw is installef or not doesnt matter. The request doesnt get processed by pw in any way only the htaccess gets into play.
  6. That response doesn't make much sense me, but I don't know what their protection is. Images are physical and there's nothing more special about it, than if you'd put a static html with an image that lives in a folder somewhere. Adding this to after the "RewriteEngine on" in the PW .htaccess will protected any image request that does not come from the domain specified. Works well. RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.ch [NC] RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]
  7. Fact is your code is perfectly fine for what it archives. You'll not find any modules that could help you doing it, at best the MarkupSimpleNavigation. It is well for quickly rendering straight nested navigations. You can overwrite with you own templates and selector (global) etc, as the manual shows. However it is not suited for things like you do with products and categories as it just traverses the page tree or parts of it. For more complex navigation the PW API and the hierarchical structure makes it very easy to construct them the way you did. I wouldn't start putting it to pieces with abstraction and functions for this menu. You problem with navigation not showing when no products found would be easy with moving the output after iterating the products and test if they're linked. Then echo only if any found. For example: foreach($applications as $a) { $prod_str = ''; foreach($products as $p) { if(!$p->applications->has($a)) continue; if(!$p->sectors->has($s)) continue; $span = $p->new == 1 ? " <span class='orange sub-menu-title'>" . $this->_('novita') . "</span>" : ""; $prod_str .= "<li><a href='$p->url'>$p->title$span</a></li>"; } if($prod_str){ echo "<li><a href='$a->url'>$a->title</a><ul class='sub-menu'>$prod_str</ul></li>"; } }
  8. From 7 to 3 pm spacific time for that price?! So are the chicks and beer included? For that price i expect them to clean my shoes too
  9. Theres nothing special about how pw handles file requests so you should be able to add the rules to the htaccess of pw.
  10. Sorry to not get back any sooner. What do you mean to clean up the code and make it dry? It actually looks good and clean. I don't think you can easily reduce or simplify with the special case of menu you got. I havent looked closely at your code before when i posted that. I dont see an easy way to use my module to create this sort of navigation. only partial at best. Sorry to confuse you. I think nobody really poped in to help you because it is already good and people dont like to clean up or code it for you. I guess you know why. Ive done it occasionally and only because ive thought the requester has no clue. So you come with a big list of how it should work and it looks as you want it to someone else make it for you. That most likely wont work here. If you post a specific question of something you cant get to work Im sure somebody will try to help. Again your code looks fine to me and you get the most out of it with simple foreachs. I don't think theres much to dry here.
  11. It has problems if you change a image field to cropimage field. At least it was for me.
  12. Soma

    Happy new year!

    3 minutes to go!! Hapoy new year everybuddy!
  13. It's somehow assumed, as the php equivalents you can also use -n, array_slice or substr etc.
  14. Thanks Nik for sorting this out. You're right actually. But I remember some case where it wasn't like this and the order would matter, but that's half year ago, so probably messed up or something has changed since then.
  15. That's great. I felt the same way when seeing even I could make such powerful modules without learning something very difficult. It's not very different from when using API anywhere in front-end. So you can use your knowledge already aquired and start dreaming away. Agreed. See examples on previous post
  16. Of course you can improve it a little with more logics if needed. Only on pages that have the publish_date field. Remove date if page is unpublished. Add value if published and not populated yet. public function afterSave($event) { // get page object saved $page = $event->argumentsByName('page'); // only on pages that have a publish_date field if(!$page->template->hasField('publish_date')) return; if($page->is(Page::statusUnpublished)) { // if unpublished, empty the field if not empty already if(!$page->publish_date) return; $page->publish_date = ''; $page->save('publish_date'); } else if(!$page->publish_date) { // if page (published) and field not populated, add current timestamp $page->publish_date = time(); $page->save('publish_date'); } }
  17. That's a good example sinnut, but a minor change to make it work: public function afterSave($event) { $page = $event->argumentsByName('page'); // get argument by name, more readable if($page->is(Page::statusUnpublished) || $page->publish_date) return; $page->publish_date = time(); $page->save('publish_date'); } isset() wouldn't work in the previous example as the field exists but is not populated it will always return true. Also $page->of(false) isn't really required as in a module the page has no outputformatting on anyway. To populate the datetime field you'd just give it a timestamp. As the field holds input-outputformatting date formatting it will take that. Not wrong but no need to. If you also need to restrict to certain pages you could add a check for the template before status check. if("article" == $page->template) return;
  18. Yeah thats from our resident luis forum member.
  19. If there is no hookable function you cant. And as you found out if db connect error is thrown theres nothing you can do obviously. But if you let us know what you like to do we maybe can help.
  20. I think you can try $page->isTrash to check if page is in trash.
  21. Edit template -> family tab there you can specify various settings to restrict children templates.
  22. Diogo, you don't have to do it manually, just a save hook. Giving you back a simple find() on front-end it is worth considering it. It would also even work in admin sorting by the field and so on. Sure an simple page array where you store the height of the first image in a runtime property to then sort by it is also a way. But then just add a line or two more to save the result to the page and you already have a "function" to do it automaticly. $pa = new PageArray(); foreach($pages->find("template=xyz") as $p){ $h = $p->images->first()->height; $p->img_height = $h; $pa->add($p); } foreach($pa->sort("-img_height") as $p){ $img = $p->images->first(); .... }
  23. I'd suggested a integer field too, simple. You get what it requires to do something. Not "I want to do this but don't want to..."
×
×
  • Create New...