Jump to content

Valery

Members
  • Posts

    121
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by Valery

  1. Thank you, Ryan. My intent was to implement some sort of security auditing such that I would receive a message whenever a CSRF was attempted. So I needed to catch the exception. The following code works for me. try { $form->processInput($input->post); $session->CSRF->validate(); } catch (WireCSRFException $e) { echo "Processing aborted. Suspected attempt to forge the submission. IP logged." . $e->getMessage(); /* * Some code to execute whenever the token gets spoofed * Like sending a notification mail with the spoofer's IP address */ die(); // live a great life and die() gracefully. }
  2. Hi, Mysqlperformanceblog states that "Something to look out for is a high number in the rows column." So, Hani, how about considering repeaters or Page fields?
  3. Jens, You can achieve this with the help of $config->httpHost. For this to work, your two domains should be bound to the directory where your PW installation resides. Then, in your template, you can check which domain name is used, and serve your users relevant content. Example: if ($config->httpHost == "www.example.com") { echo "You are visiting example.com. Have some content of type A."; } elseif ($config->httpHost == "www.example.org") { echo "Looks like you are visiting example.org. You get some content of type B."; } Also, to bind your users to a specific domain, you can add a field for a user profile and keep their domain name in it so you redirect your users to the right address.
  4. Hi harmster, Thanks for the nice tip. However, I get "Error: Exception: This request was aborted because it appears to be forged. (in /home/.../wire/core/SessionCSRF.php line 80)" in errors.log when I try to spoof the token. Is there any way to catch this exception? Thanks.
  5. If all of this happens in the backend and the field is "required", the PW backend will not allow to blank it. You would have to write your own template for it to work. You won't even need the "required" option then. Sorry if that's a poor solution. Maybe someone else can come up with a bright idea?
  6. I took a peek at the system password field settings just out of curiosity. It is not required. And it's actually possible to create a user without a password. But they won't be able to log in: PW would silently redirect them back to the login page.
  7. Hi onjegolders, Are you working with the admin backend? I gave your case a try with the API: $page->of(false); $page->requiredField = ""; $page->save(); Nothing happened. Literally nothing: no errors, no field update.
  8. Thanks, Adrian. I was not aware of the Page field until today, so thanks for this hint. I definitely like the way it allows you to link pages by fields without rearranging them hierarchically. However, I find this method more appropriate for large-scale structures of page relations, especially when they get updated often. My case is simple: plain list of post categories not longer than 20-30, and quite rarely updated. MySQL will live if I pull the serialized list out, update it and update every half a year Seriously though, those who are reading this topic should consider making use of the Page field for the purpose of linking pages by one or several fields. Iterating them is as simple as foreach ($page->page as $p) { $categories[] = $p->category; }
  9. Hi everybody, I have a setup where I have to assign one or more categories to a page. After spending some time wondering how I could make PW fields store lists, I decided upon keeping a serialized array in a page field (type = "text"). Here's how: $categories = array ("brushes", "watercolor", "pencils", "charcoal", "acrylics", "egg tempera",); $p = $pages->get(9999); $p->of(false); // the usual stuff... $p->category = serialize($categories); // transform the array of categories into a string $p->save(); unset ($categories); // wipe the slate clean for testing purposes // Now Let's Get 'em! $categories = unserialize($p->category); foreach ($categories as $c) echo $c . "<br />"; The array with the list of categories becomes a:6:{i:0;s:7:"brushes";i:1;s:10:"watercolor";i:2;s:7:"pencils";i:3;s:8:"charcoal";i:4;s:8:"acrylics";i:5;s:11:"egg tempera";} It can be stored in a page field and fetched as an array when needed. Neat! (Just remember to set MaxLength to a higher value if you intend to use "text" fields for this purpose.) Thanks for reading!
  10. I would also like to point out that I am testing PW on a FreeBSD machine, and the setup (or PW?) allows me to use whatever case for a page URL.
  11. Hi everybody, Just wanted to share something that many of us already know of: while Page name settings restrict it to "Any combination of letters (a-z), numbers (0-9), dashes or underscores (no spaces)", you can use the dot in the name of your page. That's it
  12. Soma, My bad. I must admit I rather blindly copied your code which was not a good thing. I removed the removeVariations() line and the trick with trackChanges() worked. Thanks! It's a lot more elegant way to rename files than the "add/delete" way. Have a very nice day
  13. Soma, I tried $image->removeVariations(); but it did not work for me with a file field. Overall I like the remove/add approach better.
  14. Thanks, Soma! Now how would one go about renaming a file? Calling get("file_field.data=...) did not seem to work for me.
  15. Hello everybody, I am trying to empty the Trash through the API. What's the best way to accomplish that? Also, does $pages->get("parent=/trash/"); work?
  16. Very extensive--thanks! While this is quite helpful, I was wondering if there is a way to rename files and images from the API. But as you have pointed out in your reply there is hardly any option besides updating the database manually.
  17. Thanks, Soma. A bit of SQL always helps.
  18. Hey guys, I was doing some file renaming and stumbled upon the following problem: rename() renames only the physical file itself but in the Admin backend it still shows up under its old name. Can anyone point out for me what I am doing wrong, please?
  19. Hello, everybody! I've been experimenting with manipulating files through the API recently and I cannot get my selectors to work with Files. I read about subfield selectors but I cannot get the following code to work: $myFile = $page->get("basic_page_file.name=6121970044ELEPHPANT.jpg"); // field basic_page_file is of type "Files". if (!$myFile) echo "Nothing was found"; // does not get displayed echo "File name is " . $myFile->name . "<br />"; // nothing is displayed for '$myFile->name' Actually, neither error nor the name of the file get displayed. So, I am curious as to what the correct way to use subfield selectors with Files is?
  20. Hey Ryan, I checked just now and the following code successfully sets the 'title' field of my repeater 'faq' to "WORKS!" $page->faq->get(0)->of(false); $page->faq->get(0)->title = "WORKS!"; $page->faq->get(0)->save(); Can I kindly ask you to share your opinion on what the right way to set repeater values through the API is?
  21. An obvious note but I'll make it nevertheless: no necessity to of(false) the page containing the repeater field. Just of(false) and save the repeater field-page itself and you're done.
  22. I tried the following: $page->repeater->get(0)->title = "BLAH!"; $page->repeater->get(0)->of(false)->save(); This only gave me the usual Error: Exception: Can't save page... Call $page->setOutputFormatting(false)... So, for now I think I'll better stick to the proposed solution.
  23. teppo, thanks a ton! Now, looking at repeaters as pages makes a lot more sense to me now. I won't put my updated code here since it repeats renobird's code from the thread. You have to iterate through the repeaters and treat them one by one as if they were normal pages. Which is, as you correctly state, exactly what they are. I can even see them when browsing down the Admin page in the back-end. However, I must say that $page->repeater->get(0)->of(false)->save(0) does not work. Thanks again!
×
×
  • Create New...