Jump to content

pwFoo

Members
  • Posts

    708
  • Joined

  • Last visited

Everything posted by pwFoo

  1. Sorry code isn't displayed correct... I insert just the needed part... [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) )
  2. I try to convert PageArrray / Page objects to a php array and next step to json. It works fine if I try to output the object by "print_r" with all the (private) attributes, but how to convert a image (field) to an array with the private attributes url, ? Example of converted page with image field ( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) )( [id] => 1022 [name] => test2 [status] => 1 [numChildren] => 0 [sort] => 5 [sortfield] => sort [modified_users_id] => 41 [created_users_id] => 41 [created] => 1545857760 [modified] => 1545939813 [published] => 1545857760 [title] => test2 [email] => [image] => Array ( [tux.png] => stdClass Object ( [basename] => tux.png [description] => Test1233 beschreibung bild [tags] => [formatted] => 1 [modified] => 1545939810 [created] => 1545939726 ) ) ) Missing url attribute and some more (needed) values. RAW output with needed attributes: ProcessWire\Pageimages Object ( [count] => 1 url, filename, width, ... How to get the (private) attributes by detect the attribute names and get them in a foreach loop? Sorry if something isn't clear... I'm in hurry and may add additional information later is needed... ? => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) )ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) )ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) )ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) )ProcessWire\Pageimages Object ( [count] => 1 => /test2/ [field] => image [url] => /pw/site/assets/files/1022/ [path] => C:/xampp/htdocs/pw/site/assets/files/1022/ [items] => Array ( [tux.png] => Array ( [url] => /pw/site/assets/files/1022/tux.png [filename] => C:/xampp/htdocs/pw/site/assets/files/1022/tux.png [filesize] => 6705 [description] => Test1233 beschreibung bild [tags] => [created] => 2018-12-27 20:42:06 [modified] => 2018-12-27 20:43:30 [filemtime] => 2018-12-27 20:42:06 [width] => 225 [height] => 225 [suffix] => ) ) )
  3. @LuisM @thomasaull Hi, great module(s)! But maybe it could be better admin routes / endpoints from PW backend (map endpoint to a pw page / template or any other self defined php file)? maybe just use PW templates and (sub-)pages from PW page tree (/api/*)? I searched for a simple module to deliver JSON output like Pages2JSON module, but would benefit from auth methods implemented with RestApi module...
  4. Hi, module isn't acctive / maintained. Could $template be the problem? Maybe you should use "$this->templates->get" or "wire('templates')" inside of a module. And it should be "templates"?
  5. Hi @loukote, I think my module should be replaced by Login/Register/Profile?
  6. With FormData added to the fetch call $input / $_POST is populated! So with fetch it can be fixed at client side.
  7. Yes, but I can't use the PW $input, right? But found a solution with FormData and without (!) Content-Type Header
  8. Works fine with FormData object and without set Content-Type Header... var body = new FormData(); body.append("name", "Bob"); body.append("age", 27); fetch("http://127.0.0.1/fetch.php", { method: "post", body: body }).then(function(response) { console.log(response); return response.JSON(); }).then(function(result) { console.log(result); }); <?php $res = $_POST["name"]; print_r($res); die();
  9. Would be nice to have fetch() get / post handled by $input in PW. @marcus Which library do you use?
  10. Hi @Robin S thank you very much! It was a little bit strange to debug because I needed some module un-/install and module list refreshs until it works, but the problem should be solved by change "$this->page->template" (was http404 inside of autoload modules init()) to "$this->templates->get('MyTemplate')" Add template settings from your example module! Looks like that was important. $t->compile = 0; // even though module and template not compiled by FileCompiler?! $t->noPrependTemplateFile = true; // important?? I don't use appended / prepended files $t->noAppendTemplateFile = true; // important?? I don't use appended / prepended files If compile = 0 was needed it's strange, because template / module not compiled. I checked it in /site/assets/cache/FileCompiler and logs...
  11. Hi @Robin S, autoload module and init() method doesn't work. I disabled FileCompiler, but still not works. Because it's redirected to http404 before the existing template is set inside of the module. public function init() { $this->log->message("ServiceWorkerJS module autoload"); $template = $this->page->template; $this->log->message("TEMPLATE CURRENT: {$template}"); $file = $this->config->paths->siteModules . $this . '/templates/ServiceWorker.php'; $this->log->message("NEW RUNTIME FILE: {$file}"); $template->filename = $file; $this->log->message("CHECK TEMPLATE RUNTIME FILE: " . $template->filename); //$this->log->message("CHECK PAGE URL: " . $this->page->url()); // DISABLED BECAUSE IT FAILS WITH AUTOLOAD! } The log shows the template change runtime works fine, but it's to late to get the correct and expected page. URL is changed to http404. 2018-06-30 09:23:45 admin http://localhost/pw/serviceworker.js ServiceWorkerJS module autoload 2018-06-30 09:23:45 admin http://localhost/pw/serviceworker.js TEMPLATE CURRENT: 2018-06-30 09:23:45 admin http://localhost/pw/serviceworker.js NEW RUNTIME FILE: C:/xampp/htdocs/pw/site/modules/ServiceWorkerJS/templates/ServiceWorker.php 2018-06-30 09:23:45 admin http://localhost/pw/serviceworker.js CHECK TEMPLATE RUNTIME FILE: C:/xampp/htdocs/pw/site/modules/ServiceWorkerJS/templates/ServiceWorker.php 2018-06-30 09:23:47 admin http://localhost/pw/serviceworker.js ServiceWorkerJS module autoload 2018-06-30 09:23:47 admin http://localhost/pw/serviceworker.js TEMPLATE CURRENT: 2018-06-30 09:23:47 admin http://localhost/pw/serviceworker.js NEW RUNTIME FILE: C:/xampp/htdocs/pw/site/modules/ServiceWorkerJS/templates/ServiceWorker.php 2018-06-30 09:23:47 admin http://localhost/pw/serviceworker.js CHECK TEMPLATE RUNTIME FILE: C:/xampp/htdocs/pw/site/modules/ServiceWorkerJS/templates/ServiceWorker.php Autoload module is loaded twice during one page (re-)load, but page is redirected before the autoload module changes the template. FileCompiler is off (namespace in files, site/assets/cache/FileCompiler/site/modules/* is empty). Correct page should be instead of "serviceworker.js" instead of "http404". So how to prevent redirect to http404 with my autoload module? Where change the template to be early enough to prevent the redirect to http404? Example module need to deliver a serviceworker file to the browser from the root directory. Autoloaded with condition of template works fine. So initial the template is set, module is autoloaded, but page is redirected to http404. 'autoload' => 'template=ServiceWorker', There was a module->get() inside of basic-page. Conditional autoload based on template doesn't work. So I changed it to 'autoload' => true,
  12. Thanks @Robin S, I'll try it with autoload module and disabled FileCompiler.
  13. Hi @Robin S, I know there are workarounds with additional code in init.php or a hook. But I try to save and use the template inside of the modules directory to avoid workarounds outside of the module directory (autoload module with hook, additional code in init.php, copy modules template to site/templates). A nice solution would be to set the needed template file in modules install() method and save the custom template path to the page / template. ?
  14. Good to know that "$page->process = $this" works to, but the process page could be configured by module info in later PW versions (topic is very old, I know...) Will a custom un-/install() method in process module overwrite the "default" methods (create page, set process field to module, ...) or will it extend the default process module un-/install? The page to create is set in module info as shown in the ProcessHello example // page that you want created to execute this module 'page' => array( 'name' => 'helloworld', 'parent' => 'setup', 'title' => 'Hello World' ), Anything to do if I try to extend / modify the default un-/install()? Should I hook after module install method and should that work? $this->addHookAfter('install', function (HookEvent $event) { // custom code }); And what do that line in example mean in example module install() / uninstall()? parent::___uninstall(); // always remember to call parent method Would be nice to know the default process module un-/install() methods or is it just a installPage() / uninstallPage() call?
  15. Same with subscribed content. How to save content subscriptions with PW?
  16. I have client side code which create a notification api subscription and send it to the server (PW, process module). Now I think about how to save the subscription? { endpoint: "https://fcm.googleapis.com/fcm/send/<DEVICE_ID>", key: <KEY>, token: <AUTH_TOKEN>, expirationTime: null } URL and DEVICE_ID is different dependent on browser (android, chrome, firefox, edge). How and where (in the page tree) should I save multiple user subscriptions? If a unsubscribe is executed the subscription have to be removed from the database / user. So I need a identifier to delete the subscription.
  17. Searched for a PW / PHP issue and missed the needed Content-Type to get $_POST populated ?
  18. It's fetch() related... fetch(subscribeUrl, { method: 'post', credentials: 'same-origin', headers: { 'Content-type': 'application/json' }, body: JSON.stringify({ subscription: subscription }) }) Change content type... fetch(subscribeUrl, { method: 'post', credentials: 'same-origin', //headers: { 'Content-type': 'application/json' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded'}, body: JSON.stringify({ subscription: subscription }) }) https://stackoverflow.com/questions/36669911/post-not-retrieving-data-from-javascripts-fetch
  19. I try to get POST data inside of my process module. Post request is sent by ajax with payload. But $this->input->post() or $_POST is empty here? public function executeSubscribe() { // get subscription from client and save to user / db //$array = array("me" => 'you'); // works fine! Can output with console.log at client side //$array = $this->input->post('subscription'); // empty //$array = $this->input->post(); // empty //$array = (array) $this->input->post(); // empty //$array = $_POST; // empty $array = (array) $_POST; // empty $this->render($array); } protected function render($out) { header('Content-Type: application/json'); echo json_encode($out); exit(); } I tried the post url with and without slash (I know the topics about ajax, post and trailing slash), but POST data is empty every time. Is it process module related? GET works fine in "execute()" method.
  20. Thanks @Robin S, I decided to use php copy / unlink to un-/install the needed template file as simplest solution.
  21. Verified by a test... Process is set to the page, but there is a template too. Process is ignored and template used if exists. Without template file I get a 404 error. So process module in frontend or page without template isn't possible. Also a custom template path outside of site/templates isn't possible. So I have to copy a template file from module folder to site/templates during module install that shouldn't used / modified by user / developer.
  22. Created a process module with page in frontend / child to "/", but it doesn't work as expected. Process is set, but it returns a "404 error". I think instead using the process module it searching for a template file in site/templates ?
  23. @Robin S Thanks, could Work for me as autoload module If isn't possible to set page template outside of /site/templates. Existing page would be safer because name / path is blocked. Or is it possible to build a process module with page parent home page ("/") instead of the backend? https://processwire.com/api/ref/process/install-page/ At the moment I have to copy the template to /site/templates to install the modul ?
  24. I started a process module and added the page array to module info file (mymodule.info.php, works fine with module info, required or icon for example...). 'page' => array( 'name' => 'notify', 'parent' => '', 'title' => 'Notifications', ), Tested with parent empty, no parent key and value "setup", but page won't be created. If the page exists the process isn't set by module installation. I could create / delete the page manually with install() / uninstall(), but I think it should work automatically as written here: https://processwire.com/blog/posts/building-custom-admin-pages-with-process-modules/#building-a-basic-custom-admin-page // page that you want created to execute this module 'page' => [ // your page will be online at /processwire/yourname/ 'name' => 'yourname', // page title for this admin-page 'title' => 'Hello', ],
  25. The modules creates a template and page as child of "/". It's a hidden page and should only used by the module. So it would be nice to have the module internal template file inside of the module directory instead of the site/templates directory mixed with the "normal" site templates. The page is called from client side javascript code and need to be in the pw root directory. So it needs a template file otherwise it results in a 404 error message from PW.
×
×
  • Create New...