Jump to content

abdus

Members
  • Posts

    743
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by abdus

  1. This is a perfect use case for Page Reference field. Create a new field from Setup > Fields > Add New. Give it a name. Set its type as Page Reference. Save. If you want to select a single user, specify so on the Details tab, Switch to Input tab, set input type to Select. (Optionally install InputfieldPageAutocomplete core module to enable input with auto-completion capabilities) From Selectable Pages, set template to user. Optionally, use Custom Find and specify template as user, and a role, or any other field you like. Add the field to a template. Inside your template file, you can get the user using $page->userFieldName
  2. This type of usage is called "variable variable" http://php.net/manual/en/language.variables.variable.php
  3. Labels are generated inside InputfieldPage::getPageLabel method (\wire\modules\Inputfield\InputfieldPage\InputfieldPage.module), but unfortunately it's not hookable. You can prefix the method with 3 underscores ___ to enable hooking (it works that way) but when you update the core it will be overwritten with unhookable version. Feel free to make a feature request on Github. // /site/ready.php wire()->addHookAfter('InputfieldPage::getPageLabel', function (HookEvent $e) { $field = $e->object; if($field->name !== 'myPageField') return; $page = $e->arguments(0); $e->return = "$page->title @ {$page->parent->title}"; });
  4. Something like this maybe? <?php // get all field names $fieldNames = $page->repeater_field->first->fields->explode('name'); // get all content from all fields $content = $page->repeater_field->explode($fieldNames); // array comes out multidimensional unfortunately // iterate recursively // https://stackoverflow.com/questions/1319903/how-to-flatten-a-multidimensional-array $iter = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($content)); // and print all content foreach($iter as $part) { echo $part; } This works in my setup.
  5. Here are some starters: Hook into InputfieldFile::render method to add (modify $event->return and concatenate html string) an anchor link with its href set to a custom template/PHP file where you build your own zip file. (Preferentially, add a form with a download button and a hidden field for current page id etc and set its action attribute to the template file) Inside the template file, you'll get the page id from $input->post then build your zip file foreach($page->files_field as $name => $file) { $filePath = $file->path // ... } Use $files->zip() method to zip multiple files https://processwire.com/api/ref/files/zip/ or (from /wire/core/WireFileTools.php) // Create zip of all files in directory $dir to file $zip $dir = $config->paths->cache . "my-files/"; $zip = $config->paths->cache . "my-file.zip"; $result = $files->zip($zip, $dir); echo "<h3>These files were added to the ZIP:</h3>"; foreach($result['files'] as $file) { echo "<li>" $sanitizer->entities($file) . "</li>"; } if(count($result['errors'])) { echo "<h3>There were errors:</h3>"; foreach($result['errors'] as $error) { echo "<li>" . $sanitizer->entities($error) . "</li>"; } } and build your zip file Once the zip file is built force browser to download https://stackoverflow.com/a/1628281 If you have any questions, ask away
  6. Although browser support is not perfect, you can also use anchor links with download attribute to force download with a certain filename. <a href="link/to/my/file/with/a/name/i/dont/like.jpg" download="MyFile.jpg">Download</a> https://stackoverflow.com/a/32676793
  7. Have you tried serving file with PHP instead of just linking it? You can change the filename using HTTP headers this way https://stackoverflow.com/a/1628281
  8. You can use AND operator for that. https://processwire.com/api/selectors/#and-selectors <?php $today = new \DateTime(); // set to now $inFiveDays = $today->modify('+5 days'); $tsToday = $today->getTimestamp(); $tsInFiveDays = $inFiveDays->getTimestamp(); // selectors are built in the order: field<operator>value // repeat a field for AND operation $ads = $pages->find("parent.template=manufacturer, expiration_date>=$tsToday, expiration_date<=$tsInFiveDays, sort=expiration_date");
  9. There's also $pages->count(selector) method available. <?php $today = strtotime('today'); // $today = strtotime('now'); is also available // count pages that have expired before today $alertCount = $pages->count("parent.template=client, expiration_date<=$today"); https://processwire.com/api/ref/pages/count/ FYI, you dont have to convert date back and forth, strtotime returns UNIX timestamp, and PW understands it perfectly.
  10. I faced with a very similar same issue (here) in the past. There's some good discussion and solutions in that post. To summarize: If you're not using "Allow new pages to be created from field" feature, you can provide a selector string or hook into "InputfieldPage::getSelectablePages" to return only the pages you want to appear. If you're using Autocomplete inputs or creating new pages from the field it wont work. There's no elegant solution to this as far as I know. But, you have several options: Duplicate the page field and add both to the post template. Hide one or the other depending on the parent. Duplicate the template as well and add a single field to a template (and distinguish it with blog-post & news-post). Then you can include one template file inside the other to reduce duplication etc. Hope this helps.
  11. What's happening in the screenshot? Are you getting the same category where you should be getting three different categories? Is that the issue? Otherwise a Page field that accepts multiple pages should suffice for assigning a post multiple categories. The code you've written should work. However from $kategoria->recept I think you want to get to other receptek (recipes) related to a given category inside the loop. For that you can use $pages->find("kat_page=$item, id!=$page") to find other recipes with the same category (excluding the current page). Or as a more performant solution to get a 2-way relationship (to find categories related to a recipe AND recipes related to a certain category) you can use @Robin S's module http://modules.processwire.com/modules/connect-page-fields/
  12. Hey @joer80, I've been dealing with finals/graduation/masters applications lately and cannot spend as much time coding as I would like. Because of this I haven't been active in the forum for the last two weeks as well. However, hopefully tomorrow, after submitting a project which filled my last three weeks, I'll be finished with school (for now) and be able to go back on coding. Once I get a usable beta going, I'll open a topic for the updates and feedback. Thanks a lot for your interest. Abdus.
  13. I've been using ShareX for the screencasts, but it can't handle high DPI screens very well (might be ffmpeg's fault, though), and cursor is offset a bit. Just tried LICEcap, it seems to work on high DPI screen just fine. I'll use this one from now on. Thank you very much for the suggestion @bernhard!
  14. I can't write a working example yet (on mobile) but if you're comfortable with hooks, you can hook into Page:addable and return false (change $event->return) or throw error when the page ($event->object) has more than 2 parents ($page->parents->count)
  15. For simple json outputs, you can use WireArray::explode and json_encode() or wireEncodeJSON() methods https://processwire.com/api/ref/wire-array/explode/ $myPages = $pages->find('template=basic-page'); // extract required fields into plain array $data = $myPages->explode(['title', 'created']); echo wireEncodeJSON($data);
  16. You can use url segments to achieve this.
  17. Also here's a relevant post from the blog on why it's implemented. https://processwire.com/blog/posts/processwire-core-updates-2.5.27/#php-5.6-and-debuginfo
  18. It appears that your Apache settings don't allow Content-Type headers due to misconfigured modsecurity. I'm not well versed in .htaccess, but you might be able to override security settings using .htaccess file. This SO answer might help. http://stackoverflow.com/questions/28984089/htaccess-allow-all-sorts-of-content-types
  19. Page cache under /site/assets/cache/Page might help as well, but it has to be there in the first place. Running a php script to backup the DB & force download the resulting sql file can help. Of course, this assumes that the DB is accessible using the credentials in config.php
  20. This was bothering me when I was working on this question about PageTables. It appears that Tracy isn't included when page is called via a modal. Check this out // /site/modules/TracyDebugger/TracyDebugger.module public function init() { // ... // EARLY EXITS // modals if(in_array('regularModal', $this->data['hideDebugBarModals']) && $this->wire('input')->get->modal == '1') return; if(in_array('inlineModal', $this->data['hideDebugBarModals']) && $this->wire('input')->get->modal == 'inline') return; // ... } We need you @adrian, come back!
  21. There's a module for exactly these kind of situations. https://modules.processwire.com/modules/connect-page-fields/
  22. Check the developer console on your browser (press F12). Do you see any JS errors?
  23. All your articles are stored in the database. You won't be able to find them in anywhere inside site directory, with or without FTP. You have to login to MySQL through cPanel or by other means to see your articles. How is it broken, are you getting any errors? Can you copy paste / post a screenshot of the error?
  24. Try this $fieldList = $fields->find('type%=PageTable'); foreach($fieldList as $f) { if($page->template->hasField($f)) { // page has the field } } Or simply: if($page->fields->find('type%=PageTable')->count)) { // page has a PageTable field } // check for a specific field if($myField = $page->fields->get('type%=PageTable')) { // $myField of PageTable type exists on this page. } Here I used find() method with a selector for matching type. You can be more specific, or use any other WireArray methods of course. https://processwire.com/api/ref/wire-array/
  25. Ok, so I've completed the first module and a detailed step by step write-up. https://abdus.co/blog/creating-a-simple-and-configurable-module-for-processwire/ It's a markup module that adds tracking code for analytics. It has hooks, hookable methods, and it's translatable and configurable. https://github.com/abdusco/pw-ga-lite Once I make sure it's ready to go, and write a good intro, I'll create a separate post for it.
×
×
  • Create New...