Jump to content

markus_blue_tomato

Members
  • Posts

    175
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by markus_blue_tomato

  1. I was looking for Pages::added but didn't found it (only Page::setupNew, which didn't do that in the way I want) ๐Ÿ˜€Sure, maybe I'll change that soon.
  2. We had the need, that the URL of some pages should only be some kind of ID. I know that there are Modules like https://modules.processwire.com/modules/process-redirect-ids/, but since we have a kind of ProCache based Static Page Generator this modules doesn't work for us. So we created this module, which hides the name filed on pages with specific templates and which replaces the $page->name with the $page->id. https://github.com/blue-tomato/PageUseIdAsName
  3. I felt it in the morning about 150 km away from ZG ... it was creepy
  4. At Blue Tomato we use Logstash/Kibana to monitore nearly every application. Now we use it also for our ProcessWire Logs. For this reason we created this module to send the logs to the Logstash HTTP-Input Plugin: https://github.com/blue-tomato/ProcessLogstash
  5. Ah - after describing the problem I found the solution quick I'll check if there is a template with "field-" and current image field name. $customImageFieldTemplate = wire('templates')->get("field-$fieldName"); After this I can iterate over $customImageFieldTemplate->fields
  6. How can I get from an image field all custom image fields dynamically? E.g. $page->image->alt and $page->image->credits but how can I get this fields like $page->image->getCustomImagesFields or $page->image->getCustomImagesFieldsTemplate (where I can use the $template API methods $template->fields...
  7. Below 1% with a functional health system. In italy the health system collapsed and the death rate there is about 3-5%
  8. Starting tomorrow everybody in austria should be in self isolation: This is good but TESTING is still TO LESS. In Austria you get only testet if you have symptoms and had contact to someone how as testet covid-19. Really, my daughter and her mother had fever and has very strong cough. But no contact - no test. It's really stupid.
  9. People buying 4 things in crazy amounts: noodles, rice, toiletpaper and BEER ๐Ÿ˜…
  10. In Austria the whole thing becomes creepy. schools closed, event/restaurants with more than 100 people are not allowed, borders to italy closed, other countries closed border to Austria, gov. want's that companies should make homeoffice etc. Our company make home office beginning tomorrow.
  11. How does it affect your dev life? Do you have less costumers? Do you make more Home Office?
  12. Oooh - Thanks that was my problem: I have set the value on the image field and not on the image file! This works: if($language->id == $languages->getDefault()->id) { $page->images->findOne("basename=xyz.jpg")->set("my_custom_image_field", "test default language"); } else { $page->images->findOne("basename=xyz.jpg")->set("my_custom_image_field__{$language->id}", "test language {$language->name}"); }
  13. I found this new "setFieldValue" function in the pw dev commits: https://github.com/processwire/processwire/commit/573048abb4a6bdec77aee2cbff7d5837de857a05#diff-b4e6cafb51396ac6ada1a538da0ddc8cR639 I tried following: if($language->id == $languages->getDefault()->id) { $page->images->setFieldValue("my_custom_image_field", "test default language"); } else { $page->images->setFieldValue("my_custom_image_field__{$language->id}", "test language {$language->name}"); } I get no error, but all fields are still empty ๐Ÿ˜ž I will continue my investigations... Maybe @ryan has an idea? Also strange: the function should return true or false but if I dump the return of setFieldValue, I get only an empty string back.
  14. I'am working on a migration script from the ImageExtra Module to the new Custom Image Fields feature in ProcessWire. I have some problems while setting a field value to the new custom image field. I have set up the custom field and it works correct in the admin panel but not via the API: $page->images->my_custom_image_field = "test"; $page->save(); Results into: Fatal error: Uncaught ProcessWire\WireException: Item 'my_custom_image_field' set to ProcessWire\Pageimages is not an allowed type in /var/www/html/wire/core/WireArray.php:458
  15. Some possebility to fold/expand duplicates in the log view would be great.
  16. I found a solution which works: //users current language is for example: german // language "default" is english $key = "lorem_ipsum"; $string = __($key, "path/to/my/textdomain.php"); if($key == $string && wire('user')->language->name != "default") { wire('languages')->setLanguage('default'); $string = __($key, "path/to/my/textdomain.php"); wire('languages')->unsetLanguage(); } echo $string;
  17. Is it possible to get the value of a specific language in ProcessWire's translation tools? What I want to is following: Before printing out $key as fallback, I want to use a "fallback" language. Only after the fallback language has also no result, the $key should be printed out. //users current language is for example: german $key = "lorem_ipsum"; $string = __($key, "path/to/my/textdomain.php"); if(empty($string)) { $string = __($key, "path/to/my/textdomain.php", "english"); } echo $string; And yes I know I could put the fallback into the code as key, but I don't want this. If the fallback has to change, the customer can't do it on his own and I have to to this with a full deployment.
  18. @Wanze I ended up in using your solution but to avoid writing the key everytime in two files per hand I created a node.js script which is executed in my build script of the whole project. The scripts reads all translatable strings from my .tpl files which look like this {translate}Lorem Ipsum{/translate} and creates in every view-directory a translation.php file. If anyone needs it here is the code of the node.js module (you have to install async and glob via npm..) "use strict"; const glob = require('glob'); const async = require('async'); const fs = require('fs'); // find all directories glob("site/templates/views/**/", null, (error, directories) => { // iterate in paralell over directories async.each(directories, function(directory, directoryCallback) { // find all template files in the current directory glob(`${directory}*.tpl`, null, (error, templateFiles) => { if(error) return directoryCallback(error); let translationKeys = []; // iterate in paralell over templateFiles async.each(templateFiles, function(templateFile, templateFileCallback) { fs.readFile(templateFile, (error, data) => { if(error) throw err; let tpl = data.toString('utf8'); // find all keys let pattern = new RegExp('{translate\}(.+?)\{\/translate\}', 'gm'); let result = tpl.match(pattern); if(result && result.length > 0) { // extract key without smarty block syntax // transform it to PHP syntax result = result.map(item => item.replace(pattern, '__("$1");')); // push all keys to the collector of all keys in the current directory translationKeys.push(...result); } templateFileCallback(); }); }, function(error) { if(error) console.log("Error in the templateFiles logic", error); // executed after alle keys are collected from the tpl files in the current directory if(translationKeys.length > 0) { // filter duplicates // sort alphabetical translationKeys = [ ...new Set(translationKeys) ].sort(); // make the final PHP file let phpFile = [ '<?php namespace ProcessWire;', ...translationKeys ].join("\n"); fs.writeFile(`${directory}translations.php`, phpFile, 'utf8', function(error) { if(error) throw err; directoryCallback(); }); } else { directoryCallback(); } }); }); }, function(error) { if(error) console.log("Error in the directory logic", error); // all done exit the process process.exit(); }); });
  19. I want to avoid to collect the strings in the PHP file and ProcessWire does not find the strings when they are in Smarty or Twig syntax.
  20. Hello! I am working on a pull request, to make Smarty and Twig templates translatable within ProcessWire. I stuck a little bit at the RegExp patterns. Maybe some RegExp-Professional want's to help me? :-) Should be possible in Smarty files: {$this->__('text')} {__('text')} {_x('text')} {_n('text')} Should be possible in Twig Files: {{ $this->__('text') }} {{ __('text') }} {{ _x('text') }} {{ _n('text') }} The whole patters are in the parseFile Function: https://github.com/processwire/processwire/blob/341342dc5b1c58012ae7cb26cffe2c57cd915552/wire/modules/LanguageSupport/LanguageParser.php#L120 /** * Run regex's on file contents to locate all translation functions * */ protected function parseFile($file) { $matches = array( 1 => array(), // $this->_('text'); 2 => array(), // __('text', [textdomain]); 3 => array(), // _x('text', 'context', [textdomain]) or $this->_x('text', 'context'); 4 => array(), // _n('singular', 'plural', $cnt, [textdomain]) or $this->_n(...); ); if(!is_file($file)) return $matches; $data = file_get_contents($file); // Find $this->_('text') style matches preg_match_all( '/(>_)\(\s*' . // $this->_( '([\'"])(.+?)(?<!\\\\)\\2' . // "text" '\s*\)+(.*)$/m', // and everything else $data, $matches[1]); // Find __('text', textdomain) style matches preg_match_all( '/([\s.=(]__|^__)\(\s*' . // __( '([\'"])(.+?)(?<!\\\\)\\2\s*' . // "text" '(?:,\s*[^)]+)?\)+(.*)$/m', // , textdomain (optional) and everything else $data, $matches[2]); // Find _x('text', 'context', textdomain) or $this->_x('text', 'context') style matches preg_match_all( '/([\s.=>(]_x|^_x)\(\s*' . // _x( or $this->_x( '([\'"])(.+?)(?<!\\\\)\\2\s*,\s*' . // "text", '([\'"])(.+?)(?<!\\\\)\\4\s*' . // "context" '[^)]*\)+(.*)$/m', // , textdomain (optional) and everything else $data, $matches[3]); // Find _n('singular text', 'plural text', $cnt, textdomain) or $this->_n(...) style matches preg_match_all( '/([\s.=>(]_n|^_n)\(\s*' . // _n( or $this->_n( '([\'"])(.+?)(?<!\\\\)\\2\s*,\s*' . // "singular", '([\'"])(.+?)(?<!\\\\)\\4\s*,\s*' . // "plural", '.+?\)+(.*)$/m', // $count, optional textdomain, closing function parenthesis ) and rest of line $data, $matches[4]); return $matches; }
  21. yes, the frontend was not affected ๐Ÿ˜‚
  22. @Wanze haha awesome - I had checked the sitemap generation in the module config but I don't use it and the path is not writeable. after upgrading I got the error message and unchecked it. now my pw adminpanel runs 100 times faster.... ๐Ÿ˜ณ and I thought the slowness would be normal with this amount of fields/templates/pages ๐Ÿ˜€
  23. aaah, the missing 'namespace ProcessWire;' was the problem. thx!
  24. I try to access wie WireHttp Class in a script executed on the command line but I'm failing hard and don't know why. Access to the Pages Class works well. <?php // include PW API include(__DIR__ . "/index.php"); var_dump($wire->pages); var_dump($wire->http); php test.php object(ProcessWire\Pages)#172 (0) { } NULL Does anyone know why? ๐Ÿ˜ž I tried also new WireHttp(), wire('http'), $http...
ร—
ร—
  • Create New...