Jump to content

OLSA

Members
  • Posts

    151
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by OLSA

  1. Hello, can you try this: $pages->find("(prod_othercategories=$page),(parent=$page), template=prod_series, sort=title, prod_status_pages!=1554|1559|1560|4242"); Regards.
  2. Hello, here is example using HTML "li" tags for list, and CSS pseudo-classes for styling HTML. <?php if (count($page->authors)) { $out = ''; foreach($page->authors as $authors) { $out.= "<li><a href='{$authors->url}'>{$authors->title}</a></li>"; } echo '<ul class="author-list">'.$out.'</ul>'; } ?> And CSS part: .author-list { list-style-type: none; } .author-list li { display: inline; } .author-list li:after { content: "; "; } .author-list li:last-child:after { content: "."; } This example provide few options to style list inside CSS file only (inline or not, without bullets or not, various dividers etc.). Codepen demo Regards.
  3. Hello August, that looks to me like you have pages in groups and in your navigation you want to get urls like this: mysite.com/example/some-group. If that is your case than it's looks to me like projects where I use "tags" (eg. 1) group by tag, 2) pages list by tag url...). Or, "groups" are independent pages and "post" pages are grouped using page reference field ( "group", multiselect or single select). In that case, using "natural" PW API call, you can try this: $groups = new PageArray(); //NOTE: inside selector write your template(s) name foreach($pages->find("template=post, group!=null") as $post){ $groups->import($post->group); // for single select use (array($post->group)) } // sort groups by title $groups->sort('title'); Now inside $groups variable is distinct and sorted page array with used groups only (and every group inside is page/object). Sorry if I don't understand you well, and if this example is not close to your question. Regards.
  4. Hello, to identify current page at admin side, there is problem using hooks inside "Page::render" process. There is option to use "wire('input')" to get current page and it's properties (id, template...). All that can be done inside simple module, but also inside site/ready.php (need to create ready.php). Here is example of module (CustomScripts.module) <?php namespace ProcessWire; // CustomScripts.module class CustomScripts extends WireData implements Module{ public static function getModuleInfo(){ return array( 'title' => 'CustomScripts', 'version' => 1, 'summary' => 'Module to append custom CSS and/or JS files inside admin pages.', 'singular' => true, 'autoload' => true ); } public function ready(){ // check if admin side if ($this->wire('page')->template == 'admin') { // check if it is page (and not admin page list etc.) if (!is_null($this->wire('input')->id)) { // get page object $page = $this->wire('pages')->get($this->wire('input')->id); // check if it is a page with desired template if (!($page instanceof NullPage) && $page->template->name == 'basic-page') { // check if current user has desired role if ($this->wire('user')->hasRole('superuser')) { // all checks are ok, now we can append desired stylesheet $this->wire('config')->styles->add($this->wire('config')->urls->templates . "styles/my_custom.css"); } } } } } } If you don't want to use module, take part from ready() method and place it inside ready.php (but without $this->). Third option can be to do "fake invisible inputfield" and with that get more "power" (options)... "place field on desired templates, set desired CSS, JS files, set permissions, etc." Regards. EDIT: added one more check inside if statement !($page instanceof NullPage)
  5. Hello, interesting topic. Here is one example (please read comments inside script): // !!! configuration $desired_templates = array('basic-page'); $desired_fields = array('body', 'summary'); $stop_words = array('and', 'is', 'for', 'a', 'the', 'to', 'of'); $limit_list = 10; // most used words list $words = array(); // target templates where we search $selector = implode("|", $desired_templates); // get all desired pages $content = $pages->find("template=$selector"); // fill words array foreach($content as $item){ foreach($desired_fields as $f){ $words[] = $item->{$f}; } } // https://stackoverflow.com/questions/3175390/most-used-words-in-text-with-php function most_frequent_words($string, $stop_words = [], $limit = 5) { $string = strtolower($string); // Make string lowercase $words = str_word_count($string, 1); // Returns an array containing all the words found inside the string $words = array_diff($words, $stop_words); // Remove black-list words from the array $words = array_count_values($words); // Count the number of occurrence arsort($words); // Sort based on count return array_slice($words, 0, $limit); // Limit the number of words and returns the word array } // output var_dump(most_frequent_words(implode(' ', $words), $stop_words, $limit_list)); Bad thing in this example is if you do this query in fronted runtime, better place this in some specific template and use PW cache. Also, maybe the best option is to create some Ajax driven module in backend and generate there words list. Regards.
  6. Hello, here is simplified version of icons font fieldtype module: https://github.com/OLSA/FieldtypeFontIcon This module use the same icons css file like your template (set path relative to template folder, eg. styles/fontawesome5/all.css ). After module install and created field go to field Input tab to set path (and in some cases prefix classes). Examples: Font Awesome 5 IcoMoon If everything is ok you will get something like this: NOTE: "Regular expression pattern parser" input field is not required because it will be set by default (by module itself). Regards.
  7. Hello theoretic, maybe you can try with add hook after "saveReady", and in that case also leave save part to PW api. // pseudo example for your case public function init() { $this->pages->addHookAfter('saveReady', $this, 'hookCalculateMarks'); } public function hookCalculateMarks($event) { $page = $event->arguments[0]; // if not desired template return if($page->template != 'your_template_name') return; // eg. check if field marks is empty or 0 if($page->marks < 1){ // some calculations... eg. using other page fields $page->marks = $page->field_x + $page->field_y; } } As you can see there is no page "save" part. This hook will check and set field value, and after it ProcessWire API will do the rest of the job. Regards.
  8. Maybe you can do the same without hooks using option "Selector string" inside settings for page reference field: Example 1: - Some page tree: -- Link items ---- link-item 1 ---- link-item 2 ---- link-item 3 -- Page 1 with page reference field -- Page 2 with page reference field -- Page 3 with page reference field Example 2: - Some page tree: -- link-item 1 -- link-item 2 -- link-item 3 -- Page 1 with page reference field -- Page 2 with page reference field -- Page 3 with page reference field // selector string has_parent=page.rootParent,template='link-item' Example 3: - Some page tree: -- Page 1 with page reference field ---- child link-item 1 ---- child link-item 2 ---- child link-item 3 -- Page 2 with page reference field ---- child link-item 1 ---- child link-item 2 ---- child link-item 3 // selector string parent=page,template='link-item' Regards.
  9. Hi GFXmonkey, there are many option to do that. Here is very basic example. 1) Eg. outside of main pages tree, create hidden parent page, eg. "Addons" (or "Blocks", "Widgets", or...). 2) Inside "Addons" tree you create and store reusable content (pages) using various templates (eg. slider, text-image, call-to-action, downloads, etc...). 3) Now what you also need is page reference field (eg. name "widgets") on pages inside main tree - to select - pages from "Addons" tree. How to use this concept? Example: "Text-Image widget" 1) Inside "Addons", create new page using template "text-image", place some image and insert some text. 2) Go to desired page (where you have page reference field "widgets") and select newly created "text-image widget" (1) How to render it? Also many options, but simple can be: if(count($page->widgets)){ foreach($page->widgets as $widget){ // as example widgets templates are in folder "widgets" // also this part can be different, find tutorials about ProcessWire render() method... include('./widgets/' . $widget->template->name . '.php'); } } Regards.
  10. OLSA

    So happy :)

    Lucky you! You have the best job in the world! ? Q: What is a ProcessWire? A: Coding with a smile ?
  11. If inside page field setup is checked "Allow new pages to be created from field", there is option to create new page in modal window using hook method inside "site/ready.php". Please note to write page field name inside if statement. // ready.php $this->addHookAfter('InputfieldPage::renderAddable', function ($event){ $inputfield = $event->object; // please note: inside if statement need to write page field name! if ($inputfield->name == 'your_page_field_name') //<= here { $link = $this->wire('config')->urls->admin . 'page/add/?parent_id=' . $inputfield->parent_id . '&modal=1'; $out = '<p><a href="' . $link . '" target="_blank" class="pw-modal pw-modal-large"> <i class="fa fa-plus-circle"></i> Create New</a></p>'; $event->return = $out; return $event->return; } }); Regards.
  12. Can you try to change url (without "-" separator) ajax: { url: './option1list/', dataSrc: '' },
  13. If someone is interested, here is example how to automatically assign icon to file depends on file type. No images or empty HTML tags "<i class="fa..."></i>", only CSS pseudo elements. Link to Codepen Regards.
  14. Hello Matthew, the same things happened to me few times on PW 3.0.xx, this is not some help, only few facts what I noticed. I rember that I had some errors in session logs (did not investigate). What works in my case was to use shortcut to edit pages from front-end ("go to back-end from front-end" and admin page tree problem disappear). Also you can try, logout, CTRL+F5 (clear browser cache), and login again. Regards.
  15. Thank you Pwired, but please note that I mostly posted here working/devs versions (to minimise websites promotions). They are mostly from template selling portals where client buy template (html, wp, joomla... what they likes), and after it my job is full conversion to PW. At the end, many of these templates in source has large part of unused CSS, and because of that, in last step, I like to do and css optimisation/cleaning (eg. using node.js + grunt-uncss). Regards.
  16. Hello, here are some examples, all is Processwire, and all is conversion from HTML to PW. bistro, lawyer, mtrace, nekretnine, registar, prteam, entext... If you are interested, feel free to contact me. sasaoluic (AT) yahoo (DOT) com Best regards.
  17. Hello, also the same problem (ProcessWire 3.0.98 ), and solved it with this script. Maybe it looks dangerous (overwriting translation files) but it's solve my problem. /* This script iterate over json translation files and replace 'file' path separator to "\/". If you want to try it - place it in some template and reload page with that template. After fix, delete this script. */ foreach($languages as $language){ $path = $config->paths->files . $language->id; $files = preg_grep('~\.(json)$~', scandir($path)); if( count($files) ){ foreach($files as $file){ // file path $file_path = $path . DIRECTORY_SEPARATOR . $file; // load file $contents = file_get_contents($file_path); // decode JSON data into a PHP array $contentsDecoded = json_decode($contents, true); if (strpos($contentsDecoded['file'], '\\') !== false) { $contentsDecoded['file'] = str_replace('\\', '/', $contentsDecoded['file']); // encode array back into a JSON string and prettify $json = json_encode($contentsDecoded, JSON_PRETTY_PRINT); // save file file_put_contents($file_path, $json); } } } } Regards.
  18. @cstevensjr thanks for the reply. I found that links before, but read to fast..., now understand that is still in development/testing phase. Before 2 years I build JSON fieldtype (for configuration only), but sometimes, I use it to store contact details. Because never totally finished, I didn't post it to module section. Please, allow me to suggest that in case of this new fieldtypes (FieldsetGroup and FieldsetPage), to try to find another one option for multilanguage tabs to reduce space in user interface (and to get some kind of "compact view"). To be more clear, here are some screenshots of my JSON configuration filedtype. Compact view/layout: Field settings: Thanks for Ryan and others who are involved in development of this new fieldtypes. Best regards. EDIT: here is that module and you can try it
  19. Hello, is FieldsetGroup included only inside Pro fields or it in core? I am asking this because I had updated from 2.8 to 3.098 and can't find option to create FieldsetGroup field type? Thanks and regards.
  20. Thank you Ryan for focus point feature. Before this, I used option with select field where editor define focus point (crop from top percentages) - but right now it would be more precious and editors will like it more! Thanks.
  21. In my last project I had a to import about 4000 images, and had problem with about 1200 images. Images uploaded (using API from frontend), but some of them doesn't had variations images. Problem was that PHP GD image resize engine is very strict, and if there is any problem with image (beginning and ending bytes of file) GD resize failed. More about my case and solution is here.
  22. Hello BitPoet and others, don't know if this can help, but before few days in one project I need some solution to store repeatable urls, and build fieldtype "Repeats". It is very simple repeatable input (varchar/text) field (one of custom fields created thanks to Ryan Events module). I am sure that for you wouldn't be a problem to copy/paste/rename and create integer/float repeatable field. I had build many PW fields types but never had enough time to polish it and place in PW modules section. Regards. FieldtypeRepeats.zip EDIT: I read this topic again, and because these days I am mostly in "backend forms job", my first thought was that you need this for backend forms. Sorry for that. Please note - this field type is not for front-end forms - it is for backend/admin forms. Also, here is example how to get field values at front-end. // my first plan was to store few "link" details // because of that, need to call "value" // default foreach($page->field_name as $url){ echo $url->value;// note: "value" } // to get first row echo $page->field_name->first->value;
  23. Hello. There are few possible problems with centralised concept. As example, what to store in that images field? To be more clear, if some image is part of PW page only as reference link, than how can we resize it (eg. "on the fly" in page rendering process)? What would happened when someone delete image on that external point - how would ProcessWire page know that? Etc... Because of that, if I go to build that module/field type than probably it will copy image from that external central point to ProcessWire page. With that, we can have external Media manager where we can use all it's power (organise files to folders, search etc.). Also, because we have on PW side copy of that file we can use all PW API power to manipulate with it - on PW side. Here was few discussions why PW by default doesn't have "Media manager" like many others CMS's (I was one with that question too) but very soon undrestand that maybe because of that some other popular CMS's still doesn't have simple solution to store and generate various dimensions intro images. If some CMS's had that option, need to look closely to see how and where they store eg. that intro images... Storing concept is very important (eg. in case when need to do some export or imports). That what you ask is completly ok, but also it's important to think about possible consequences. What I like in centralised Media manager idea is 1 central point for file organisations, all other with that idea bring us problems and complicate things. Regards.
  24. After all, write small function to locally test resizing of images (using default PHP GD image library) and find that this images are not 100% valid (semi corrupted jpeg files). Strange thing was, as you can see here (first two images) looks normal. Same PW on Windows with PHP >=7.1.9 works fine - no problems with upload and resize. Inside PW logs, Tracy debugger, Wamp/PHP logs, custom core debugging, didn't find any exception/note about "Corrupt JPEG data" (maybe because error suppression operator (@) in few places inside image processing/pw core). Also playing locally with PHP getimagesize() return correct image data (size, bit, channels, mime...) for all that images . Etc... If you ever had a problem with upload/resize images, and on server use PHP GD enginee, and images looks ok, maybe there is a problem with small file corruption. In that case you can try to put this in site/config.php ini_set("gd.jpeg_ignore_warning", 1); This will not fix corrupted jpeg image, but will provide that PW image processing do job and doesn't break. Regards.
  25. Hello for all. I have strange problem with images in PW 3.0.62, wamp, PHP 5.6 - 7.0.23, (Windows 10, i5, 8GB RAM). 1. Can't upload some images, process failed in first step (thumbnail preview creation). 2. Images can be uploaded/saved using API, but later in admin backend, there is no preview thumbnail image. It can be opened and zoom, but can't edit/crop/resize . 3. Everything works fine in PHP 7.1.9 Warning and errors: "Warning: filesize(): stat failed for .../site/assets/files/image-name.jpg in ...\wire\core\Pageimage.php on line 511" "ImageSizer::resize(0, 260) failed" "ProcessPageEditImageSelect: Unable to complete resize" I have large number of images with that problem in current project, and if someone want to test this, I attached two "bad" images, and screenshot from admin backend. Don't know is this some kind of ProcessWire issue or there is some problem with images? Please, what is yours opinion about this? Thanks.
×
×
  • Create New...