Jump to content


  • Content Count

  • Joined

  • Last visited

  • Days Won


OLSA last won the day on August 10 2018

OLSA had the most liked content!

Community Reputation

165 Excellent

About OLSA

  • Rank
    Sr. Member

Profile Information

  • Gender

Recent Profile Visitors

3,062 profile views
  1. Hello @MilenKo you need to do that somewhere before Comments module render methods calls ( renderStars() for page rating, and render() for user reviews ).
  2. You can try to get that using hook below. But please note, because you want to get that works only inside back-end (admin) place this in site/templates/admin.php before require(...) statement: // site/templates/admin.php // set different SelectablePages for page field "group" in case if user is superuser wire()->addHookAfter('InputfieldPage::getSelectablePages', function(HookEvent $e){ // here we check desired page field only if($e->object->name == 'group'){ if( wire('user')->isSuperuser() ){ $e->return = wire('pages')->find('template=group, sort=title'); } } }); Thanks to PW there are and other options to get the same (eg. hook in custom module, or ready.php). Regards.
  3. Hello for all, don't know if this can help to someone, but here is solution for one strange problem (PW 3.096). 1) installation was multilanguage (EN and FR) 2) one langauge was deleted and all works without problems (as a "single-language" website) 3) but then, when my client try to add/create new user this happened: What was strange, at the bottom of that page was empty Language inputfieldset section ("required")??? I try again to install second language (idea was that maybe new uninstall would help), but it was not possible because "...there are Language..." (new red messages). After all, I found that in database are still old language tables and rows and after deleting the problem was solved. Here is the list of tables and records and what I done: 1) delete from table "fields" 3 rows where name: language_files_site, language_files and language 2) delete 3 tables: field_language, field_language_files and field_language_files_site 3) delete from table templates 1 row where name is language Or all that with this query inside phpMyAdmin: DELETE FROM `fields` WHERE `name` IN ('language_files_site','language_files','language'); DROP TABLE IF EXISTS field_language, field_language_files, field_language_files_site; DELETE FROM `templates` WHERE `name`='language'; Please be careful because this is very risky and before anything backup your database. Regards.
  4. Evo da se i ja ukljucim, rijetko sam ovdje There you need to include FieldtypeLanguageInterface, or if you watch at TextareaLanguage, or TextLanguage you will see this part in Fieldtype class: class FieldtypeTextareaLanguage extends FieldtypeTextarea implements FieldtypeLanguageInterface { ... or in TextLanguage class FieldtypeTextLanguage extends FieldtypeText implements FieldtypeLanguageInterface { After that, in Inputfield part you only need to use eg. textarea or text: class InputfieldMyNewField extends InputfieldTextarea { Inside ___render() part you do not need to include multilanguage input because PW magic will do the rest... Regards, Sasa
  5. Yes. Here is part how to get that, but you need to finish it (write your selectors, change "date" with your date field). Not good as direct sql query, but it could work, need to test. // get your groups $groups = $pages->find('your selector(s) to get groups'); // prepare empty pages array ("container") $posts = new PageArray(); foreach ($groups as $group){ // !!! bad thing is to do queries inside foreach // but good thing is to use "findOne" $p = $pages->findOne("has_parent=$group, template=post, sort=-date"); if($p->id){ $posts->add($p); } } // sort posts by date $posts->sort('-date'); // render links $out = '<ul>'; foreach($posts as $post){ $out.= '<li> <a href="'.$post->parent->parent->url.'">'.$post->parent->parent->title.'</a> <a href="'.$post->url.'"> ('. $post->title .' - '. $post->date .')</a> </li>'; } $out.= '</ul>'; echo $out; Also, here option to use instead $pages->findOne('has_parent=.................') this: $group->findOne('template=post, sort=-date'). Regards.
  6. @Leftfield I am happy that you solved your problem ;). Maybe you can consider and few other options to get granularity or selection inside different types of featured posts (favorites). Option 1) Using Autocomplete page reference field Create and place Page Autocomplete field on some template (eg. on home or on some "widget" template). As example, if field "featured" is on Home page: $fav = $homepage->featured->eq(0); // or $homepage->featured->first $favs = $homepage->featured->slice(1); // skip first and get others $cards = $pages->find("template=blog-post, id!={$homepage->featured}"); Option 2) Get pages by priority levels Currently you are going with 3 check fields to get "sticky", "fav", and "favs". There is option how to get the same (checkboxes/radio) with only 1 field, but here I will try to describe (something different) how you can get "granularity" inside featured posts also using 1 field. Create integer field, and as example, set min to 0, and max to 3, and place it on your "blog-post" template. Later, in your code, it's very easy to get desired post by priority level. $fav = $pages->findOne('template=blog-post, priority=3, sort=-blog_date'); $favs = $pages->find('template=blog-post, priority=2, limit=2, sort=-blog_date'); // etc... $all_others = $pages->find('template=blog-post, priority<1, sort=-blog_date'); With this you can "describe the importance" of some post, and later, if it's needed, you can extend that with more levels without additional fields (changing only integer field range). Also with this option you can order posts by priority (sort=-priority). Option 3) Post priority levels with the addition of hooks (need to test) Here is option (for testing) to get on the website only 1 post with priority level 3, and later when someone add new page with the same level (3), previously post automatically would go to level 2, and so on. Here is working example using hooks, but please note that in some situation maybe could not works as expected. Before using this hook, you need to create "priority" field (option 2) and set your template inside hook part. Place this hook inside site/ready.php. // site/ready.php /* Before using this hook please create integer field "priority" and place it on desired template. */ $this->addHookAfter('Pages::saveReady', function(HookEvent $event){ $page = $event->arguments[0]; // if not desired template do nothing // note: set your own template if($page->template != 'blog-post')return; // priority level limit $limit = array( 1 => 3, // priority level 1, allowed max. 3 pages 2 => 2, // priority level 2, allowed max. 2 pages 3 => 1 // priority level 3, allowed max. 1 page ); // processing only if priority has changed and not changed to zero if($page->isChanged('priority') && $page->priority > 0) { $level = 3; // max priority level while($level > 0) { // test with different "sort" selector (eg. -modified, -created, or by custom date field) $group = $this->pages->find("template=blog-post, priority=$level, sort=-modified"); if($level == $page->priority) { $count = $group->has($page) ? $group->count : $group->count + 1; } else { $count = $group->has($page) ? $group->count - 1 : $group->count; } if($count >= $limit[$level]) { for($i = 1; $i <= ($count - $limit[$level]); $i++) { $group->eq($group->count - $i)->setAndSave('priority', $level - 1); } } $level = $level - 1; } } }); Regards.
  7. Last few days I am playing with CKE5 inside PW, and here are my first impressions with it. First, what is important to say - CKE5 is totally different product compared to CKE4, but that mostly from development perspective. V5 use different data model, MVC architecture, and for any kind of customization (development) be prepared to use Node.js with dozens of packages. By default, CKE5 has explicit and strict HTML API and right now, as example, you can't set "target" attribute on link (!) and here and here are answers how that can be done. Also, the same goes if you need to place "data" attribute to some DOM element. "View Source" button (option) will never again by default be part of CKEditor and here you can find the answers for that task. Development of my first CKE5 plugin was not a nice experience, as example I build "ViewSource" plugin, but after a while realized that, in this very stricted data model, it is useless. To get some advanced options (eg. insert "target="_blank") need to develope and additional plugins (npm packages). On the other side, this new API provide options to works with content on different ways and maybe that is the best part of new CKE5 editor. As example, in theory, we can store in JSON but with single click that content can be converted to some Markdown or HTML and vice versa. Or maybe we can get option to store content in 1 cell but "descriptions" in other etc... Regards.
  8. Maybe this: https://gist.github.com/jmartsch/768d9dc19293528fe9ae82b7a8ee1c42#file-home-php-L35 change: if ($fieldType === "FieldtypeTable") { to: if ($fieldType === "FieldtypePageTable") {
  9. Hello @ratna if I understand your question, here is tested variant to get that. All required templates (or admin page tree) are almost the same just like you done (or what @kongondo suggested), except that I used and "result" template. Result template is child of "person" because for me it's somehow more nature to use "person" template to store only "person" details (eg. address, email etc...), and "result" to store "result" values per that user. Also, using "result" template can gives you flexibility to store and other result details (date, time, etc...). Required templates and fields: people: title - person: title -- result: title, category (page, select), value (float) categories: title - category: title Here are few screenshots from backend, page tree (1) and single result page (2): *** Categories template is used to show "results" (frontend screenshot) // categories.php <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php echo $page->title;?></title> <link rel="stylesheet" type="text/css" href="<?php echo $config->urls->templates?>styles/main.css" /> </head> <body> <h1><?php echo $page->title; ?></h1> <ul> <?php foreach($page->children as $category):?> <li> <?php echo $category->title;?> <?php $results = $pages->find("template=result, category=$category, sort=-value");?> <?php if(count($results)):?> <ul> <?php foreach($results as $result):?> <li><?php echo $result->parent->title;?> | <?php echo $result->value;?></li> <?php endforeach;?> </ul> <?php endif;?> </li> <?php endforeach;?> </ul> </body> </html> Regards.
  10. Hello, there is also one "alternate" solution, using Node.js and Puppeteer with headless browser. In this case, export to PDF is only one segment what can be done with that tools (remote login, automated processing, deep testing, etc...). If you have Node.js on your machine, here is example (Windows) where project directory "printer" is in C partition (C:\printer). C:\> mkdir printer cd printer npm i puppeteer easy-pdf-merge After this, inside project directory are all required node modules (Puppeteer, Chromium browser, Easy PDF). Last step is to create index.js file and place it inside project directory ( C:\printer ) // index.js const puppeteer = require('puppeteer'); const merge = require('easy-pdf-merge'); // configuration // *** EDIT THIS: var admin_url = "http://my_site.com/admin_url"; var user = '*****'; var pasw = '*****'; // desired pages // *** EDIT THIS: var pdfUrls = [ "/page/edit/?id=1054&modal=1", "/page/edit/?id=1016&modal=1", "/page/edit/?id=1019&modal=1", "/setup/field/edit?id=1#inputfieldConfig", "/setup/field/edit?id=1&modal=1#inputfieldConfig" ]; var pdfFiles = []; // START async function main(){ const browser = await puppeteer.launch({headless: true, args:['--start-maximized']}); const page = await browser.newPage(); await page.setViewport({width: 1366, height: 768}); // login await page.goto(admin_url, { waitUntil: 'networkidle0' }); await page.type('#login_name', user); await page.type('#login_pass', pasw); // login submit await Promise.all([ page.click('#Inputfield_login_submit'), page.waitForNavigation({ waitUntil: 'networkidle0' }) ]); for(var i = 0; i < pdfUrls.length; i++){ await page.goto(admin_url + pdfUrls[i], {waitUntil: 'networkidle0'}); var pdfFileName = 'page' + (i + 1) + '.pdf'; pdfFiles.push(pdfFileName); await page.pdf({ path: pdfFileName, format: 'A4', printBackground: true,margin: {top: 0, right: 0, bottom: 0, left: 0}}); } await browser.close(); await mergeMultiplePDF(pdfFiles); }; const mergeMultiplePDF = (pdfFiles) => { return new Promise((resolve, reject) => { merge(pdfFiles,'processwire.pdf',function(err){ if(err){ console.log(err); reject(err) } console.log('Success'); resolve() }); }); }; // run all this and exit main().then(process.exit); *** Note: edit this script and write your login parameters and desired urls. After all, run script (inside C:\printer>) node index.js After a while (for this example, ~10 sec.) you will find PDF files in project folder (partials and 1 merged with all). As example here is attachment. Regards. processwire.pdf
  11. Hi, I think that you don't need to do that because $page->comments->count return number of comments for page. Some options to sort pages by comments: // example: page template "blog-item" // $pages->find($selector)... // from top by number of comments $selector = 'template=blog-item, sort=-comments.count' // by recent comment $selector = 'template=blog-item, sort=-comments.created' // by upvotes $selector = 'template=blog-item, sort=-comments.upvotes' Or options by downvotes or stars. Also, there are and additions, eg. "AND comments.count > 10" etc... Regards. EDIT: read again your question, and if you have page array (results), than you can try to filter results with this: $my_results->sort("-comments.count");
  12. Preselect option, currently, only in case when you have option value as null "0", as example your "gridsize" field: Label: "Grid size" -- option value: 0, option text: Default -- option value: 1, option text: Grid size 1 -- option value: 2, option text: Grid size 2 In that case, preselected value in admin backend would be "Default". Later in your code: if ($item->grid_settings->gridsize){ // not default (not preselected value) ... } else { // default ... } But there is and "mix" variant, example, some select field with name background: label: "Background color" -- option value: 0, text: Default -- option value: black, text: Black -- option value: orange, text: Orange * preselected text : "Default" Later in code: <?php // configuration form field "settings" with select subfield "background" $background = $page->settings->background ? '-' . $page->settings->background : ''; ?> <div class="bgn<?php echo $background;?>"> * div can have css class values: bgn, bgn-black, bgn-orange Regards.
  13. Hello @jploch in case of select field, you can get only selected option value (and not title/text) or in your case: $grid_size = $item->grid_settings->gridsize;
  14. OLSA

    W3.CSS framework

    Hi, just found that we get new CSS framework W3.CSS (from w3Schools). Equality for all browsers: Chrome. Firefox Edge. IE. Safari. Opera. Equality for all devices: Desktop. Laptop. Tablet. Mobile. Standard CSS only (No jQuery or JavaScript library). Also interesting demo section (this, this etc...) Regards.
  15. @Mustafa-Online probably you use Fontawsome v4 and get that situation because ProcessWire also use Fontawesome icons v4 and override module css inclusion. If you go with some other font icons (or FA version v5, Fontelo, IcoMoon...) that would works. Also switch off option "Repeater dynamic loading (AJAX)" for repeater field. Regards.
  • Create New...