Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/09/2018 in all areas

  1. well, it's not an error, it is a warning. You could ignore it (?) Alternately - did you already enable DEBUG mode, install TracyDebugger? that warning may be coming from this file: wire/modules/Process/ProcessField/ProcessField.module but i don't know why that file would be in play upon login, unless you have a module or some hook somewhere doing something.
    4 points
  2. Should never be too lazy for learning. Keep feeding that curious inner child inside you! I think all the myriad of intermediate and advanced techniques, paradigms, theories etc that we programmers use boils down to 2 objectives we strive for. Readability and ease of (future) maintenance. Something that helps achieve the two is proper encapsulation of code & logic, something I think I am still learning better ways to do after all these years! The Pipeline is merely one way of encapsulating your code & logic in a certain way that helps achieve readability. Object Orientated Programming was born because of this need for encapsulating code. You could certainly just use if statements and functions to achieve this as well, perhaps encapsulating some of the logic into smaller functions like below. $cond1 = CheckSendMe(); //$input->post->sendMe. $cond2 = ValidateV(); //$v->validate $cond3 = VerifyCaptcha(); //$captcha->verifyResponse() if ($cond1 && cond2 && cond3) { ConstructEmail(); if (SendMail()) DisplaySendMsg() else DisplaySendFailMsg() } I guess the different ways of encapsulating code will yield different results and your mileage will definitely vary a lot depending on what and how you use it.
    3 points
  3. TracyDebugger did the trick. It was the PageListImageLabel module. Thanks Macrura!
    3 points
  4. <?php namespace ProcessWire; if($user->isLoggedin()) { // you can go more deeper with roles, etc... render_my_sekret_menu(); }
    3 points
  5. DEPRECATED - USE ROCKMIGRATIONS INSTEAD I'm very happy to share my newest module called "ProcessWire Kickstart" that I developed during the holidays Maybe some of you already saw the preview thread about this... What it does: This module makes it possible to install ProcessWire in a fully automated process. You can define all necessary settings in one single php file and you can even define "recipes" that get executed after installation. This means you can install modules, adopt settings and do whatever you want with your new site using the PW API (like creating pages and so on). You could also place a kind of frontend boilerplate on your git account and grab that after installation and place it in your templates folder. I ran out of time so maybe someone could try that out and show how he did it Additional to that there is a ProcessModule to install in your ProcessWire admin which makes creating and testing recipes super easy. Note: Alpha realese until this module gets some more testing. Please be careful with this tool since it does some heavy file system manipulations (unzipping, moving and DELETING whole directories...). Use at your own risk. Usage: Just grab a copy of the kickstarter, place it on your server, visit yournewsite.com/kickstart.php, adjust settings (like username+password) as needed and hit "install". If your mysql user does not have the rights to create a new database then you have to create a database before running the installer! Download: via SSH: cd /var/www/yournewsitedirectory wget baumrock.com/kickstart.php // or using curl curl baumrock.com/kickstart.php -L --output kickstart.php Manually: Klick baumrock.com/kickstart.php and upload the file to your server Note: baumrock.com/kickstart.php returns the current master file from the gitlab repo and changes the namespace of the script so that it can install itself via recipe. If you don't need to install the kickstart processmodule via recipe you could also download the kickstart.php file from gitlab. Screenshots/Walkthrough: The initial Screen: You can either upload a file via the left panel or take my example file from the gitlab repo: This way you can create your own kickstartfiles and host it on your own accounts. When the file is loaded you can easily edit all necessary informations, like username, password and the url where to grab ProcessWire from. I just tried it with an old version as well... 2.7 worked just fine (having the old installer that recently was updated) but an ancient 2.2.4 version failed. I don't think anybody will ever need to install lots of old versions of pw with this tool but I wanted to mention it here. Hit "install" and lean back - on my VPS it takes 15 seconds to install my very own custom version of processwire with all modules that i need After logging into your admin you'll see that all modules from your recipe are installed: Recipe Editor: As recipes are executed after processwire was installed you have all your API magic available there. Running this scripts is only possible inside of a working processwire installation, so I created a module to help you with that task. See the comments of the sample recipe for more information! I hope this tool helps you to save lots of time and create lots of awesome ProcessWire websites I would be happy to see how you use this and please share useful recipes here in the thread so that everybody can profit. Maybe you just want to throw in an idea what could be done (for example I can imagine a recipe that checks file permissions on the system after installation)... Some parts of the code and maybe also part of the idea are taken from @Soma 's old and still great online installer, thx for that!
    2 points
  6. Hi y'all! Long time no see. Here's a little module aiming to help you build accessible websites ProcessWire Accessibility Tools Download: http://modules.processwire.com/modules/pwat/ Github: https://github.com/marcus-herrmann/PWAT A small, but hopefully growing toolkit for creating accessible ProcessWire sites. Right now it consists of the following little helpers: tota11y visualization toolkit by Khan Academy A toggle button to see view site in grayscale. The w3c recommends checking your page without colours to see if your design still works (accompanied by a colours contrast check, which is part of tota11y) A link to test your webpage with WAVE, webaim's Web Accessibility eValuation Tool. By the nature of this tool, the website under test must be available online, local hosts won't work. Installation Once you have downloaded PWAT, go to your module Install page and click "Check for new modules". Find "ProcessWire Accessibility Tools" and click "Install". During installation, PWAT creates a new role 'pwat_user'. To use the Accessibility Tools, you have to grant user this role. Following, you can start configuring the module. Usage PWAT starts with only the tota11y script activated. On the configuration page you can decide whether PWAT is visible on admin pages if tota11y is active if the grayscale toggle is active if the link to WAVE will be visible Credits The amazing tota11y visualization tool by Khan Academy Inspiration: Paul J. Adam's bookmarklets Inspiration: WordPress wa11y Plugin Best, marcus
    2 points
  7. You could apply something like the Pipeline Design Pattern to streamline a set of sequential work, which I think is what you're trying to achieve @SamC ? Having said that, it's not something I've used in PHP itself but I've used in other languages like C#. The advantage is better readability and maintainability and no more long nested if - else statements. https://medium.com/@aaronweatherall/the-pipeline-pattern-for-fun-and-profit-9b5f43a98130 An alternative method of getting rid of if - else statements is using functional programming paradigms like Lambda expressions and using optional types and using defensive programming techniques. There's a great course on it on Pluralsight on this called Advanced Defensive Programming Techniques. It can get a bit heavy but it's profoundly changed my coding views in a positive way. Even if you're not familiar with C#, I would recommend having a look at this course if you really want to advance yourself as a coder. https://www.pluralsight.com/courses/advanced-defensive-programming-techniques
    2 points
  8. If you are in a function or a loop you can put those negative conditionals first and "return", "continue", or "break" - this can help to reduce nesting.
    2 points
  9. This was my initial thought (in the now edited post) but then I read this from the Hooks docs:
    2 points
  10. @dragan's suggestion may be the answer. I've had a similar problem with my cPanel accounts which have a PHP switcher. In my case using the switcher and changing from the default PHP version adds a PHP version handler snippet to the end of the .htaccess, something like: # php -- BEGIN cPanel-generated handler, do not edit # Set the “ea-php70” package as the default “PHP” programming language. <IfModule mime_module> AddType application/x-httpd-ea-php70 .php .php7 .phtml </IfModule> # php -- END cPanel-generated handler, do not edit ..and of course when you try this locally there is no such handler, so you are prompted with a download. Edit: Actually, re-reading your post, I don't think this could be the answer if other pages are working, sorry!
    2 points
  11. HELLO! I always struggle adding additional functionality, buttons and other settings to the CKeditor and I guess other people might have the same issue at times. For those who are CKeditor aces would you share your settings in this post to help others with what I guess should be a simple task to extend the default settings. Extra color select and text formating toolbar Format, Styles Bold, Italic, Underline, -, RemoveFormat TextColor, BGColor JustifyLeft , JustifyCenter, JustifyRight, JustifyBlock NumberedList, BulletedList, -, Blockquote PWLink, Unlink, Anchor PWImage, Table, HorizontalRule, SpecialChar PasteText, PasteFromWord Scayt, -, Sourcedialog extra allowed content small[*] section font[style] span[style]{!color} code[*] custom config options colorButton_colors: ec4626,ffde43,00aaeb,004a87,7b9320,ffffff extra plugins colorButton
    1 point
  12. The idea with the validation functions is to encapsulate the checking logic and the error capture logic inside the function. You could even throw the error there immediately but I don't know what your requirements are. function CheckSendMe($errorMsg) { if ($input->post->sendMe) { return true else { $errorMsg = $errorMsg."Error MSg here"; //appending error msgs here return false; } } ... $cond1 = CheckSendMe($errorMsg); $cond2 = ValidateV($errorMsg); ... if ($cond1 && $cond2 && $cond3) { .... } else DisplayErrorMsg($errorMsg); The idea here is to minimise any long nested if-else chains and favouring readability over pre optimizations or micro optimizations. Perhaps if you're the only coder and or you're working in a small team or you're very familiar with the codebase then you may think this approach may seem like overkill. Until you work on a huge codebase that is alien to you, previously worked on a by a long list of programmers with varying skill levels, and the sight of a huge function with a dozen if-else statements nested coming your way will probably change your mind quickly about readability.
    1 point
  13. Totally this. The problem with the if (a && b && c) approach (I'm on a phone, best I can do!) is that the errors are different depending on what's wrong, hence the nesting. I don't like it so will def think of a way that suits me better. I like the idea of smaller functions as this is similar to the functional (JS) programming I'm learning at the mo. I'm becoming quite fond of it and finally made it to some lightbulb moments! I studied java for 6 months a couple of years ago and actually liked the OO approach too. I guess experience will highlight my personal preferences.
    1 point
  14. 1 point
  15. sorry, took the wrong code snippet, but totally agree on that
    1 point
  16. I think there were a couple of really early 2.x bugs and one panel that didn't work, but I think that was it. Anyway, you have moved on now, so no need to worry
    1 point
  17. Haha, maybe it's about time I dusted off Tracy Debugger too. Was an early adopter but have never used it because I was on PW 2.8.x for a long time until recently.
    1 point
  18. I think this unnecessary, because there is not a single installer (of which I know) out there that is password protected (not PW, not WordPress, not Drupal, not NextCloud, etc.). And even if it was so, I think that most guys develop on a local machine and then upload to a live server. I know: People do stuff differently. However: Because of the upload functionality, it is a high security risk if people can upload files, without checking for permission. I think this does not matter on a local server, but on a live server it does.
    1 point
  19. Google is your friend in cases like this: https://stackoverflow.com/questions/9575914/table-is-read-only Not sure why you would have gotten in that situation though. Maybe it's the innodb recovery mode setting?
    1 point
  20. How about making it only visible when a get variable is set and has the same value as a variable set by the user? $pass = '12345'; if ($_GET['pass'] !== $pass) { exit; }
    1 point
  21. I needed something similar today, still working on it. To get you started (it require more check in the hook), in ready.php : <?php wire()->addHookBefore('LoginRegister::createdUser', function($event) { $u = $event->arguments[0]; $u->roles->add(wire('roles')->get("custom-role")); $u->save(); }); Edit: used LoginRegister::createdUser instead because the role was added but not took into account.
    1 point
  22. Thank you guys, as always It's a pleasure to be part of a wonderful community dragan, iank and FrancisChung were right on the spot, the problem was on my .htaccess file. iank Got the solution, My Cpanel was adding those lines to the end of my .htaccess file, as my server uses multiphp and I have other websites that run on different php versions. Thank you again for your priceless help
    1 point
  23. To me it's a preference. For example, in user registration I use this structure: if( $input->post('register') == '1' ) { // is our form submitted if($session->CSRF->hasValidToken()) { // is it our form if( $input->post->text('g-recaptcha-response') == '' ) { // are they beast or human $regError = "Invalid Captcha response."; } else { $regEmail = $input->post->email( 'regEmail' ); if( $users->get( "email=$regEmail" )->id ) { $regError = "You cannot register more than one account with the same email address."; } else { ... } } } else { header("Status: 401", true, 401); } } Since php does a short circuit test, it stops evaluating conditionals as soon as a value is known. So it doesn't really matter, unless you get into nesting elseif or use switch statements. Whatever code style reads best for you and your team is how you should do it. Just my $.02
    1 point
  24. You learn something new every day.
    1 point
  25. I haven't studied the code but wondering if uploading to a non-web-accessible system directory might help? E.g.
    1 point
  26. Looks cool, thanks! I think it would be a good idea to include some advice that when using on a live server users should password protect the directory that kickstart.php is uploaded to, until the install process is completed and kickstart.php is removed. Otherwise there is a security risk that a third-party might access the script and thereby be able to upload any files of their choosing. Password protection info: Apache cPanel (essentially just a GUI for Apache basic auth)
    1 point
  27. Fails in what way? What is the error that your client is seeing? Could you clarify what you mean by child and parent? Child and parent pages? Not sure how that fits with the code you've shown. What type of field is "times"? I think this should be: $pages->addHookAfter('saveReady', function($event) { You only use "addHook" if you are adding a new method or property to the class. You don't need to do $p->of(false) for the page being saved in a saveReady hook because output formatting is already false at this point. But it doesn't do any harm either and it isn't related to the problem you're having. Nothing is ever really mandatory when it comes to fields. Setting the "required" option for a field just means that the user will see an error when they save a page with this field empty. But the page is still saved with the required field in its empty state. So you should always account for the possibility that a required field may be empty. You could test what happens in your hook when you save a page with "startdate" empty. Perhaps that causes the issue?
    1 point
  28. Maybe invert the IFs and put the errors on top. I mean: ... if (!$v->validate()) { $session->flashMessage = 'Recaptcha must be complete.'; } else { ... } ... This may make it more readable. Also some comments along the way can't hurt. In terms of performance, 4 nested ifs start to sound like too much, but in this case I wouldn't worry about it because it's a form submit. If it was something that triggered every time a page was loaded, maybe I'd look into ensuring the best performance possible, but I don't think this would justify 2 extra hours of your time. Think how much your time costs, how many milliseconds you could shave off it, and ask yourself if it's worth it.
    1 point
  29. Thank you Bernhard for your efforts. This looks great. Hope I find the time to test it in the next days.
    1 point
  30. Yes, CodeMirror and, later maybe monaco (PR's welcome).
    1 point
  31. Hmm. never saw this, will take a look. EDIT: I like the way codiad works, that's how filemanager should work. It has more modern approach, it's fast, uses ace, it's more developer-centric. I did, tried it somewhere else (ProcessFileEdit perhaps?), but failed. Yes. I modified my original post to reflect that, I just forget it yesterday. Everything is possible, but I'm not sure in what direction will this module move (if at all). filemanager by itself allows hiding files of certain types, but it's disabled. The best way would be to try the original filemanager and all the options available (or you can try in the module itself, check config.inc.php). On windows, you can't change permissions. Displayed permissions might be inaccurate. I modified filemanager so that at least file permissions should be correct. On file info, you will see the correct owner of the file/folder and acl list.
    1 point
  32. You need to enable 'modal' in module JqueryUI Don't set the href attribute. In this case the button will be wrapped by an anchor tag and you will be redirected to the url which you want to open in the modal. Use 'data-href' instead. If you set the property 'aclass' a class attribute value will be added to the anchor wrapper not to the button itself. Use function addClass() instead. Try this: wire('modules')->get('JqueryUI')->use('modal'); $btnAddNew = wire('modules')->get("InputfieldButton"); $btnAddNew->attr('data-href', wire('config')->urls->admin."page/add/?parent_id=1101&modal=1"); $btnAddNew->attr('id', "MyCustomAddPageButton"); // required for the additional button on top $btnAddNew->showInHeader(); $btnAddNew->addClass("pw-modal");
    1 point
  33. To get you started, I give you an example of an ajax request triggered by a noUiSlider's event which update the markup. Do not hesitate to ask if you don't understand something. Javascript code : // slider element var slider = document.getElementById('noUiSlider'); // create the slider object noUiSlider.create(slider, { start: [0, 100], step: 1, // avoid float values range: { 'min': 0, 'max': 100 } }); // change the value when noUiSlider values are updated slider.noUiSlider.on('update', function( values, handle ) { if ( handle ) { $("#noUiSlider-data").data("max", values[handle]); } else { $("#noUiSlider-data").data("min", values[handle]); } }); // on event 'set' send ajax request slider.noUiSlider.on('set', function( values, handle ) { // get the min and max from the data attribute of #noUiSlider-data $data = {min: $("#noUiSlider-data").data("min"), max: $("#noUiSlider-data").data("max")}; // ajax request $.ajax({ url: $(this).data('url'), // url from the data attribute of #noUiSlider type: "post", data: $data }).done(function (response, textStatus, jqXHR) { $('#list').html(response); // write markup to #list element }) }); PHP code : <?php namespace ProcessWire; $list = ''; $limit = 100; if(isset($input->post->min) && isset($input->post->max)) { $min = $input->post->min; // don't forget to sanitize $max = $input->post->max; // don't forget to sanitize $li = ''; $products = $pages->find("template=product, start=$min, limit=$max"); // let assume there is a template 'product' foreach ($products as $product) { $li .= "<li>". $product->title . "</li>"; } $list = "<ol>$li</ol>"; echo $list; } ?> HTML Markup : <div id="noUiSlider" data-url="<?= $page->url; ?>"></div> <span id="noUiSlider-data"></span> <div id="list"> <?= $list ?> </div> #noUiSlider is the slider element #noUiSlider-data will contain values changed from the #uiSlider element #list is the element updated by the ajax response enjoy
    1 point
  34. If you're trying to install ProcessWire on a Synology NAS using the WebStation service, please refer to notes below. I've created this mainly for web searches. I'm going to assume that you're at the installation screen and the first issue you'll have is trying to connect to a database. There's 2 things here you need to note MariaDB is running on Port 3307. You're probably used to running on port 3306 and this might even be what the installation screen pre-populates The Host field must be set to localhost:3307 and not just localhost
    1 point
  35. In addition to what blynx said: if ($flip) means the same as if ($flip!=0)
    1 point
  36. if($flip) { echo "H" } You are exactly right, I think you just miss a thought: The condition relates to the value of $flip. The value is either 0 or 1. And in PHP, 1 in a condition is “like” true, and 0 is “like” false. So $flip may be 1. In that case PHP will coerce it to true and finally print H because the condition is met. If $flip is 0, PHP will coerce that to false and print T because the condition for the if() was not met. So the else block is executed. Hope that helps?
    1 point
  37. I needed the same thing so i used Selectize inputfield single for the master select and then a select multiple on the dependent select, then i initialized the 2nd one using Selectize JS; the JS is not so hard, but you do need to have a custom select multiple that has a data-parent attribute on each option; those are filtered to match the selected option in the 'parent' select. Eventually this will make it into InputfieldSelectize somehow, but for now it's just done by adding JS, courtesy of AdminCustomFiles.. In the screen capture, you will see the left select, which may or may not have child pages; if it does, then the right one shows the children:
    1 point
  38. Hi @DarsVaeda You should specify GET or POST variables in cache settings for this template ( there is an input for this at the bottom of cache settings screen.) Or specify * for all parameters.
    1 point
  39. Exactly . Had the same thoughts. On the face of it, it would seem like one is just an extension of the other (see also this example under addProperty - the one that returns an intro of a body copy). However, the same question could be asked when developing a class (PHP or otherwise). When should I use a class property versus a class method? If we are going to use something repetitively, especially when some degree of flexibility is required, we go with a method. If we need to stick with some value, we might as well use a property. So, I guess, IMO, it is about what best works for your present needs.
    1 point
  40. Thanks. I'm sure I'm missing something here, but it seems like addHookMethod() can do everything that addHookProperty() can plus it can optionally take arguments. In the Hooks docs there is this example for addHook(), aka addHookMethod(): public function init() { $this->addHook('Page::lastModified', $this, 'lastModified'); } public function lastModified($event) { $page = $event->object; $event->return = wireRelativeTimeStr($page->modified); } echo $page->lastModified(); // outputs "10 minutes ago" And then in the addHookProperty() API reference there is virtually the same example: // Adding a hook property $wire->addHookProperty('Page::lastModifiedStr', function($event) { $page = $event->object; $event->return = wireDate('relative', $page->modified); }); // Accessing the property (from any instance) echo $page->lastModifiedStr; // outputs: "10 days ago" So the addHook() example could alternatively be added with addHookProperty(). But if addHook()/addHookMethod() can "do more" than addHookProperty() thanks to the ability to pass in arguments, in what circumstances would you want to use addHookProperty()?
    1 point
  41. They look quite different to me (the examples). addHookProperty does just that; adds a property. The property is available to the object you are attaching it to. You can't pass it any arguments to manipulate what it returns. addHookMethod/addHook allows you to add a method/function to an existing class or object. You can have the method you've 'created' accept arguments that inform the method's logic. Although the examples are similar, they are not identical. addHookProperty example. We cannot change/alter the output since this is a property (variable) unless we 'manually' assign it a new value // Accessing the property (from any instance) echo $page->lastModifiedStr; // outputs: "10 days ago" addHookMethod/addHook example. We can add as many arguments as we want to lastModified() since it is a method. In the example in the docs, the method accepts only one boolean argument. This allows us to alter what lastModified() returns. Hence, it offers more flexibility. echo $page->lastModified(true); // returns "10 minutes ago" echo $page->lastModified(false); // returns "2013-05-15 10:15:12" echo $page->lastModified(); // returns "2013-05-15 10:15:12" That's my understanding of it anyway...
    1 point
×
×
  • Create New...