Jump to content

The G

  • Content Count

  • Joined

  • Last visited

Community Reputation

11 Good

About The G

  • Rank
    Jr. Member
  1. Disclaimer: please note that this is how I am doing it, it may or may not suit you, so take it with a grain of salt. Also, I apologize for not obeying ProcessWire's code style, I'm just too old and it feels alien to me. Thing I'm trying to get: not having to input the 'Custom Editor CSS File ...' and 'Custom Editor JS Styles Set ....' for each of the fields using CKEditor. Yeah, I know, call me lazy or sloppy or whatever, it is what it is πŸ˜„ . having the front end styles in the editor container, so the one editing the page would be able to eyeball the styling of the content while stayin in the editor For the first objective I tried to find a way in the CKEditor configuration options, like config.js, or at least a single point to set my options. In the end, what worked for me was hooking the Inputfield in ready.php: if (strpos($_SERVER['REQUEST_URI'], $config->urls->admin) !== 0) { // things I do to frontend pages, believe me, you don't want to know :D } else { $wire->addHookBefore('InputfieldWrapper::renderInputfield', function($event) { // process further if it is an InputfieldCKEditor if (strpos($event->arguments(0)->className(), 'InputfieldCKEditor') === 0) { // store the Inputfield $inputfield = $event->arguments(0); // my custom CKEditor options $my_settings = [ 'contentsCss' => '/site/assets/css/cke.css', 'contentsInlineCss' => '/site/assets/css/cke_inline.css', 'stylesSet' => 'mystyles:/site/modules/InputfieldCKEditor/mystyles.js', 'extraAllowedContent' => '*[id](*); audio[src,controls,preload]; source[src,type]; button[title]; script; i[data-feather]; svg[xmlns,height,width]; path[d,fill,stroke]', ]; // for each option, check if it's empty and if it is set it to the custom value foreach ($my_settings as $key => $value) { if (empty($inputfield->get($key))) { $inputfield->set($key, $value); } } // get the changes into $event $event->arguments(0, $inputfield); } }); } Now, my CSS files are generated by Sass in the /site/assets/css/ directory, because of the second objective. Thus, I'm including the frontend CSS in three places: the two custom CSS files used by CKeditor in regular/inline mode and defined above ('contentsCss' and 'contentsInlineCss' options), and my custom CSS file used by admin.php. The regular mode CSS files contains: // cke.sass - Sass syntax @import "main" where main.sass is my frontend Sass file (I have a real talent for names, I know). So it includes all the frontend styles in the regular CKEditor iframe. The inline mode CSS file contains: // cke_inline.sass .cke_editable_inline @import "main" This way the frontend styles are applied only to elements inside the CKEditor inline container. I know I'm tying myself to the CKEditor markup, but as you may have noticed by now, I'm quite eager to sell myself in slavery for a bit of convenience πŸ˜„ . The admin styles are built the same, changing only the container class and adding some styles to increase readability: // admin.sass /* force a min width for CKEditor combo, so I can read the text */ .cke_combopanel min-height: 21rem min-width: 25rem > iframe height: 100% !important .cke @import "main" The resulting /site/assets/css/admin.css file is loaded by /site/templates/admin.php by adding $config->styles->add($config->urls->assets.'css/admin.css'); before the require($config->paths->adminTemplates . 'controller.php'); line. Lo and behold, Bulma styles available in the editor toolbar and container (there's a short clip attached). Well, this should be it. I hope it helps someone. If you know a better way to do this or if you notice a mistake/omission, by all means, let me know. Thank you for following me until now - here's the medal you rightly deserve: πŸ₯‡ LATER EDIT: sorry about the video size, I swear it's just a little 578x472px video. ckeditor-2020-04-10-161245.mp4
  2. Thank you! Dude, you really have patience 😁 The source of the problem was the Media Widget plugin , which wraps another figure element on the image element, although now there is an outer figure has the correct class πŸ€·β€β™‚οΈ. I could swear it wasn't there before... Oh well... Didn't need the plugin, so I uninstalled it. To summarize, to have it noted down and to pick the brains of the experts, this is what I did to get the styles working: 1. created /site/assets/css/ckeditor_contents.css (my choice of path) containing some of the framework's styles, like .has-text-danger { color: hsl(348, 100%, 61%); } .is-pulled-left { float: left; } 2. created /site/assets/css/admin.css containing my custom admin styles like /* custom CKEditor styles to have in PW admin interface */ @import url("../../assets/css/ckeditor_contents.css"); /* force a min width for CKEditor combo, so I can read the text */ .cke_combopanel { min-width: 25rem; } 3. imported the same /site/assets/css/ckeditor_contents.css on top of /site/modules/InputfieldCKEditor/contents.css /* custom CKEditor styles to have in PW admin interface */ @import url("../../assets/css/ckeditor_contents.css"); 4. linked /site/assets/css/admin.css on top of /site/templates/admin.php, right at the beginning of the file, before the line requiring the controller $config->styles->add($config->urls->assets.'css/admin.css'); 5. changed classes in the Page Edit Image module settings (the link is /ADMIN_FOLDER/module/edit?name=ProcessPageEditImageSelect) aaaand... I got this (with Bulma classes) 😁 As you see, I have even the kitchen sink in there, it's because of my condition called what-if-I-ever-need-it-osis πŸ˜‚ Thank you!
  3. Thank you for taking the time to answer, Robin. That setting is changing the class of the image inside the figure element, unfortunately. This is the code generated for a right aligned image: <figure class="image"> <img class="align_right" src="/path/to/image/" width="160" /> </figure> I'd like to change the class of the most outer (is that an expression?) container, so I can move it as a block.
  4. Hi, I'm working on a Bulma based site. I'd like to have an experience that's closer to WYSIWYG, so I added some of Bulma classes into mystyles.js and in contents.css. And it works, except when I'm trying to float an image inside CKEditor, using the PWImage plugin. I tried adding { name: 'Image Float Left', element: 'figure', attributes: { 'class': 'is-pulled-left' } }, { name: 'Image Float Right', element: 'figure', attributes: { 'class': 'is-pulled-right' } }, into mystyles.js, but it just ignores me, no class is added to the default "image" class of the wrapping figure element. What am I missing? Thank you πŸ˜€
  5. OK, found the culprit, is the static variable $alreadyFormatted which is set to true at line 527 (module version 106): 525 public function formatExtraValue(HookEvent $event) { 526 if (!self::$alreadyFormatted) { 527 self::$alreadyFormatted = true; I don't know its purpose, but in my case (a loop retrieving captions for an image from every blog post) it stops the text formatter from processing any item after the first one. So I commented it out, I'll see if anything goes wrong.
  6. If it was me editing the pages, I could live with it, but for regular users is confusing. Not to mention paying customers .
  7. Thank you for the module! I'm using it to add a Markdown enhanced captions for some blog images. I have a problem - the text is processed by the Mardown module only for the first image (in ProcessWire 3.0.72 multi language). Could someone give me a hint about where to look, please? I'm stumped. I'm retrieving them like this: <?php foreach (pages('parent=8888') as $item) { ?> <div> <div class="uk-card uk-card-default"> <?php if (count($item->images)) { $item_image = $item->images->getRandom(); ?> <div class="uk-card-media-top"> <figure> <img src="<?=$item_image->size(580, 384, ['quality' => 75])->url?>" title="<?=$item_image->description?>" alt="<?=$item_image->description?>"> <figcaption class="uk-text-meta uk-padding uk-padding-remove-vertical"><?=$item_image->caption?></figcaption> </figure> </div> <?php } ?> <div class="uk-card-body"> <h3 class="uk-card-title"><a href="<?=$item->url?>" title=""><?=$item->title?></a></h3> <p><?=$item->summary?></p> </div> </div> </div> <?php } ?>
  8. My bad, i should've not added that render comment. Sure, I could check the fields to see if they are empty and a 404 is needed. The other languages don't need this check, though. They can be disabled and that's enough. My real question is about the editing interface: how can I hide the default language fields? Thanks for the link to Adrian's module. Unfortunately, as I said in the first post, I'd very much prefer not to separate the translation interface for all pages just because a few of them might not use a language. Also, it appears that the request Adrian made for hooking the Languages class remained unanswered and so, his module cannot currently select the supported languages - it's all or default only. IMO, the dificulty springs from the fact that the "name" and "title" mandatory fields are being used as translations. I'd rather duplicate "default" as English and treat "name" as an ID, but then again, Ryan knows much better than me.
  9. Hello everyone , I searched the forums, but could not find any simple way to take the default language out of one page (or a few pages), like this Homepage en page1 page2 de seite1 (page1 content translated in German) seite2 (page2 content translated in German) seite4 (only in German, no English version - this is what I don't know to do) The way it is now, the default language cannot be disabled, so "seite4" would have the English translation fields in the editing form and would render in the front end. I thought about creating a second English (en) language and hiding the default one, but it won't work because the way ProcessWire treats the "name" field. Another way would be separate trees for each language. That would work for languages with content that is different enough. But for one or a few pages that would not be translated to the default language, I would loose the integrated interface and big image would become more difficult to see. So I'd much prefer not to use it. The last way that crossed my mind was to modify the LanguageSupportPageNames module to update behind the curtain the default language with something while keeping it hidden. That's probably what I'll try given enough time. What do you say? What do I miss? LATER EDIT: I totally don't know any German, used it just as an example.
  10. Hi, I have a bunch of pages and I want to search for words or word parts in their "title" and "tags" field. The "tags" field is a textarea containing a comma separated list. It's a long story, I tried first using pages for tags, but text search was slow and I don't need them to have their own URL anyway, because I'm using query strings to bundle together all the search+filters+sort+pagination parts. Anyways... let me give an example: for instance somebody searches for "rome city". I need to get the results in this specific order: all full words in the title (i.e. both "rome" and "city in the title) all full words in the title or tags all word parts in the title (i.e. parts of both "rome" and "city in the title) all word parts in the title or tags Right now, I'm using merged PageArrays and it's quite a PITA: $results = new PageArray(); // this is computed, but to simplify I'm defining it here directly $searches = array ( 'title~=rome city', 'title|tags~=rome city', 'title%=rome,title%=city', 'title|tags%=rome,title|tags%=city', ); // the 'filter' part comes from a filter form via the whitelist // I'm leaving it in place to show that is precomputed // I took out the sorting and pagination parts $base_selector = array( 'base' => 'parent=1025', 'search' => '', 'filter' => implode(',', filterToSelector($filter)), ); foreach ($searches as $search_lap) { // $search_lap_selector is a temporary array of selectors for this round of search $search_lap_selector = $base_selector; // the current search is inserted into the selectors array $search_lap_selector['search'] = $search_lap; // this gets the ids of the pages already in $results PageArray $cids = array_flip($results->explode('id')); // implodeSelector implodes the selector parts in the correct order during conversion to and from the whitelist // this loop tests if $clip it's already present in $results PageArray and skips it if so, // to preserve the order // I tried with import, but every $results->import messes the results order foreach ($pages->find(implodeSelector($search_lap_selector)) as $clip) if (!isset($cids[$clip->id])) $results->add($clip); } This gets me the results, but, as I said, it's a PITA and somehow it doesn't look right. It would have been very nice if I could use selector groups and attach somehow the results count to the selector, so I could use the results count for sorting. Something like parent=1025, ('title~=rome city'), ('title|tags~=rome city'), ('title%=rome,title%=city'), ('title|tags%=rome,title|tags%=city'), sort=-title_full_matches_count, sort=-title_tags_full_matches_count, sort=-title_part_matches_count, sort=-title_tags_part_matches_count Does anything like this exists?
  11. Hi, Is there a way to use ProcessWire to convert ProcessWire selectors to SQL queries, i.e. like PageFinder does, but using the API?
  12. @diogo: nice idea to store the numbers in a page. Problem is, the numbers should reflect the actual selection count, so after selecting an option every count is different. And then there are the variants with two options selected and then with three... Seems like a lot. I'm sure your idea will haunt me, though. That clip has "artistic perspective". It also happens that is the default "no-video" clip . @horst: it is all very true. At the same time caching the markup obtained using SQL would be the same, only with a faster first access. Wouldn't it?
  13. Wow, thanks! Lots of good ideas! This forum is out of this world, I tell you. I replaced $pdostmt = wire('database')->prepare(' SELECT DISTINCT field_'.$dbtable.'.data as value, field_title.data as label, COUNT(*) as count FROM field_'.$dbtable.' LEFT JOIN field_title ON (field_title.pages_id = field_'.$dbtable.'.data) GROUP BY field_'.$dbtable.'.data '); $pdostmt->execute(); while ($row = $pdostmt->fetch(PDO::FETCH_ASSOC)) $filter_options[$criterion][] = array( 'name' => $row['name'], 'label' => $row['label'], 'count' => $row['count'] ); with $values = wire('pages')->find('parent=/search/'.$criterion); foreach ($values as $value) $filter_options[$criterion][] = array( 'name' => $value->name, 'label' => $value->title, 'count' => wire('pages')->count('parent=1020,'.$criterion.'='.$value), ); where $criterion is from a 4 fields array, and 1020 is the video clips container id. I like that the synthax is much cleaner and I can further glue selectors to the initial selector, But it works slower, as in 0.6 seconds slower with 4 fields and 20k video clips. It was surely expected and I think that the delay will increase linearly along with the video clips count. So I'll stay with the SQL version, unless there's possible to further optimize the API way. Thank you.
  14. Using find() without limit on a large number of pages wil eat all memory and bring your site down sooner or later, depending on your server configuration. Actually, I need to get all unique values from each field. Yes, I need the count for each value, but I need the values first.
  15. Thanks for your answer. I realize I should have given more information. The fields are video clip parameters, like format and length. I made the format a Page field and the length (duration) an integer field. All fields are included in a single template, so I already know the template. I want to make a search filter with every clip parameter as an option, each one displaying its video clips count, like this: Problem is, there are more than 20000 video clips and potentially many more, so I cannot do find() without limit. Right now I'm using SELECT DISTINCT `pages`.`name`, COUNT(*) FROM `field_format` LEFT JOIN `pages` ON (`field_format`.`data` = `pages`.`id`) GROUP BY `pages`.`name1 for Page fields and SELECT DISTINCT `data` as name, COUNT(*) as count FROM `field_length` GROUP BY name for scalar fields. I was wondering if there's some ProcessWire API magic for this.
  • Create New...