Jump to content

kixe

Members
  • Posts

    806
  • Joined

  • Last visited

  • Days Won

    10

Everything posted by kixe

  1. You can easily create a select field with countries with FieldtypeSelectExtOption First install this table countries.sql via MysqlAdmin or another tool. Choose the new table in the settings of your FieldtypeSelectExtOption field. Done! You have a comfortable access to all the data via API. Read the docs or the related thread https://processwire.com/talk/topic/9320-fieldtype-select-external-option/
  2. I use lang-edit permission for specific roles in PW 3.0.x. It works without problems. For the sake of completeness, it should be mentioned that this permission works only in combination with page-edit permission.
  3. I tried to reproduce and got what I have expected. My template file: <?php var_dump($input->post->hidden); // array(3) { [0]=> string(3) "123" [1]=> string(3) "456" [2]=> string(3) "789" } ?> <form action='/test/' method='post'> <input type="text" name="text[]" value="Hello"/> <input type="text" name="text[]" value="Jo"/> <input type="hidden" name="hidden[]" value="123"/> <input type="hidden" name="hidden[]" value="456"/> <input type="hidden" name="hidden[]" value="789"/> <input type="submit" value="go"> </form>
  4. That is the thing I would check first! I'm pretty sure that the apache directives in your post can not be responsible for the http 403. Neither in a local environment nor on a live server. Please check other .htaccess files in parent directories or apache config files. Check for redirects in your template files or config.php
  5. 1. specify a template 2. check if the parent you have set exists $page->of(false); $page->template = 'whatever'; $page->parent = $some_user_page; if ($page->parent->id && $page->template->id) $page->save(); else die('Something went wrong'); or use a debugging tool.
  6. To get url with scheme and hostname use $page->image_field->httpUrl(); It maybe would make sense to provide modifying output of Pagefile::url() via arguments similar to Page::url() (just to mention: a page is not a file!)
  7. In general its not a very good idea to make a system upgrade like this on a live site. Better to make a copy in a local or subdomain environment. Upgrading from 2.x to 3.x could trigger some problems especially related to namespaces. Did you try // to be placed in config php $config->compat2x = true; When I did an update similar to yours I ended up adding namespace to all my templates. <?php namespace ProcessWire; This could cause new problems, but maybe easier to solve. About modules It could help to remove or rename (.module_) 3d party modules from your modules directory. Refresh modules or remove the module in the databasetable after and install them one by one in the newest version. Good luck.
  8. For debugging you could use print_r($page->fieldtypePage->getArray());
  9. @Robin S Thanks for pointing this out. I agree and changed the 3d argument. It receives now the row related to the value. ATTENTION: Since Module version 1.3.5 you have access to all row columns as described here wire()->addHookAfter('FieldtypeSelectExtOption::label', null, function ($e) { $optionLabel = $e->arguments[0]; $optionValue = $e->arguments[1]; $page = $e->arguments[2]; $field = $e->arguments[3]; $row = $e->object->row($field->name, "id=$page->id"); }); /** * select field for images in a multilanguage environment * label pulled from image description in default language with fallback to filename */ $this->addHookAfter('FieldtypeSelectExtOption::label', function ($e) { $array = json_decode($e->return, true); $page = $e->arguments[2]; $field = $e->arguments[3]; $row = $e->object->row($field->name, "id=$page->id"); $e->return = $array[0]? $e->return = $array[0]: $row['data']; });
  10. Pushed another update with new function added which allows to modify the option labels via hook. Scenario: You want to provide a select drop down for image fields stored in another page as described in this post In the next step we want to provide labels pulled from the description field (default language in multilanguage environment) instead from the data field providing ugly file names. How can we achieve that? The description is stored as a json string. We need to extract the label from it. To do so choose 'description' as option label and put the following hook in your /site/ready.php $this->addHookAfter('FieldtypeSelectExtOption::label', function ($e) { $array = json_decode($e->return, true); $e->return = $array[0]; // image description in default language }); Function label() always provides the default lable, the option value, the page to which the field is assigned and the specific field that uses the field type to facilitate customizations. Default return is the unmodified label pulled from the database column. ATTENTION: Arguments changed since Version 1.3.5 // Version >= 1.3.5 $this->addHookAfter('FieldtypeSelectExtOption::label', function ($e) { $optionLabel = $e->arguments[0]; $optionValue = $e->arguments[1]; $page = $e->arguments[2]; $field = $e->arguments[3]; });
  11. @Robin S I fixed this and other stuff you mentioned in this post: It was a bit more complicated than I expected, since PW really doesn't provide '0' as value in a SelectFieldtype.
  12. @Robin S Thanks for pointing on this. I will make an update soon.
  13. maybe just a missing echo? foreach($page->content_repeater_matrix as $content){ if($content->type == "hero"){ echo $content->render(); break; } }
  14. Drop the code in a file ready.php and place it in your /site/ folder.
  15. // tested only backend part $this->addHookAfter('FieldtypeSelectExtOption::filter', function($e) { if ($this->wire('page')->template == 'admin') { if ($this->wire('page')->process == 'ProcessPageEdit') $id = $this->wire('input')->get->id; else return; } else if ($this->wire('page') instanceof RepeaterPage) $id = $this->wire('page')->getForPage()->id; else $id = $this->wire('page')->id; $e->return = "pages_id='$id'"; });
  16. The function filter() is hookable. You can modify the selector string returned by filter().
  17. You maybe could use my module FieldtypeSelectExtOption in this case. install module create a field with this Fieldtype go to details tab of the new created field choose your preferred Inputfieldtype select the field holding your images as 'Source Table' save field select 'sort' for option value and whatever you want as 'label' set ther filter to 'pages_id = 1234' (1234 is a placeholder for the pages-id holding your image field and repeaters) save again add the field to your repeater matrix template done Tell me if it works or if any problem occurs.
  18. You can use $page->getIterator(); instead of $page->getArray();
  19. Here is a brief reference to the last updates: Value Preselection Since version 1.2.3 it is possible to pre-select a value if the field is required. Language Labels In a multilanguage environment, as of version 1.2.4, it is possible to assign a special column to each installed language in the database table to pull the option labels from. Of course with fallback to the default language. 0 allowed as value Since version 1.2.5 int 0 is an allowed value
  20. EDIT: removed code example The code doesn't work since a page being edited is not saveable in a pagefield (circular reference).
  21. No. The default behaviour is slightly different. Under the following conditions the file is not accessible: $config->pagefileSecure is set to true Page::status >= 2048 (unpubished) User is not logged in OR has not page-view permission for this page (template) Currently, Processwire does not meet your needs and provides Pagefiles if the status is appropriate for the current user and the user has page-view permission. The function Page::isPublic() does not change the status of the page it returns false if the the status is >= 2048. This function is used by PagefilesManager and ProcessPageView. It is a kind of bridge between the status and these classes. ProcessPageView::sendFile() is meant to go around the .htaccess protection anyway to provide the files in the backend. The function is not called if you can access the file via Apache. It will be called only if a secured file path is detected. Perhaps it would be useful if ProcessPageView::sendFile() checks whether the file is requested by the admin template or by the frontend. As far as I can see there is no reason against the following changings. You maybe want to post an issue on github. /** * Passthru a file for a non-public page to make it visible in the backend * * If the page is public, then it just does a 301 redirect to the file. * */ protected function ___sendFile($page, $basename) { $err = 'File not found'; // use the static hasPath first to make sure this page actually has a files directory // this ensures one isn't automatically created when we call $page->filesManager->path below if(!PagefilesManager::hasPath($page)) throw new Wire404Exception($err); $filename = $page->filesManager->path() . $basename; if(!is_file($filename)) throw new Wire404Exception($err); if($page->isPublic()) { // deprecated, only necessary for method 2 in checkRequestFile $this->wire('session')->redirect($page->filesManager->url() . $basename); } else if ($this->wire('page')->template == 'admin') { $options = array('exit' => false); wireSendFile($filename, $options); } else throw new Wire404Exception($err); }
  22. To make it visible in the backend? All in all this one should work /** * 1) add $config->pagefileSecure = true; in your config.php * 2) add this to your ready.php * 3) enable $page->password_protect in the backend and save the page * * if you do step 3 before 1 and 2 you need to save/view the page once to prevent access to the file * because Page::isPublic() is not triggered if you try to access the file directly * */ /** * if Page::isPublic() returns false a prefix (-) will be added to the name of the assets directory * the directory is not accessible directly anymore * */ wire()->addHookAfter('Page::isPublic', function($e) { $page = $e->object; if ($page->password_protect) { $e->return = false; } }); /** * ProcessPageView::sendFile() is called only if the file is not directly accessible * if this function is called AND the page is not public it passthru the protected file path (.htaccess) by default * therefore we need this hook too * */ wire()->addHookBefore('ProcessPageView::sendFile', function($e) { $page = $e->arguments[0]; if ($page->password_protect) throw new Wire404Exception('File not found'); });
  23. 1) The default behaviour in PW is, it would be added if you save with status unpublished. If you save and publish it will be removed. 2) You are right and I have to correct myself there will be no changes later if you use both: force isPublic() to return false and setting $config->pagefileSecure = true; The problem is ProcessPageView::sendFile() as I mentioned here. A new header will be created and passthru the .htaccess settings. So you need to hook in ProcessPageView::sendFile() too; /** * Passthru a file for a non-public page * * If the page is public, then it just does a 301 redirect to the file. * */ protected function ___sendFile($page, $basename) { }
  24. You can also have a look in my module http://modules.processwire.com/modules/fieldtype-select-ext-option/ This is a Select Fieldtype (single or multiple) which provides all the data of the selected table rows of any PW or Non-PW database table.
  25. 1) Yes my example block all files, I made this just for testing. You have to modify it for your needs. 2) Yes. It looks like it is accessed directly. A http header will be sent by WireHttp::sendFile() and output the content of the given file if the page is unpublished. If you don't set $config->pagefileSecure = true; all files will stay accessible even if the page is unpublished. If you hook in Page::isPublic() and return false the name of the files directory changes and your .htaccess will prevent accessing files under the secured path. If you make changings in your page and save it the files directory will be renamed again. Thats why this solution is a bit hacky. I wouldn't go forward in this direction. You should look for another solution.
×
×
  • Create New...