Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/17/2017 in all areas

  1. At our site we use both email and phone authorizations at frontend. To make life easier, I've developed HelperPhone pack that handles phone numbers. This pack includes following modules for ProcessWire CMS/CMF: FieldtypePhoneNumber: module that stores phone numbers InputfieldPhoneNumber: module that renders inputfield for phone numbers HelperPhone: module that loads PhoneNumber and PhoneNumberConst classes, and 'libphonenumber' namespace All these modules require included PW WireData-derived class PhoneNumber and PhoneNumberConst. PhoneNumber class is a thin wrapper over giggsey/libphonenumber-for-php, itself is port of Google's libphonenumber. PhoneNumberConst class stores constants, used by PhoneNumber class Usage: PhoneNumber class $phone = '8 (916) 318-07-29 ext 1234'; // input string could be in any phone-recognizable format $phoneNumber = new PhoneNumber($phone, 'RU'); // or wire('modules')->get('HelperPhone')->makePhoneNumber($phone, 'RU'); echo ($phoneNumber->isValidNumber() ? 'Yes':'No'); // Yes echo ($phoneNumber->isValidNumberForRegion($regionCode) ? 'Yes':'No'); // Yes echo $phoneNumber->getNumberTypeTitle(); // Mobile echo $phoneNumber->getCountryCode(); // 7 echo $phoneNumber->getRegionCode(); // RU echo $phoneNumber->getNationalNumber(); // 9163180729 echo $phoneNumber->getExtension(); // 1234 echo $phoneNumber->formatForCallingFrom('US') // 011 7 916 318-07-28 echo $phoneNumber->formatForCallingFrom('GE') // 00 7 916 318-07-28 For more methods and properties please refer to PhoneNumber and PhoneNumberConst source files. Need more? Check giggsey/libphonenumber-for-php and use it by accessing $phoneNumber->phoneNumber property - it is instance of \libphonenumber\PhoneNumber or null (if empty). Usage: field Note: on field creation, make sure that you've configured field settings Default region: assumed region if input phone number string is not in international format (starts with '+', etc) Enabled/disabled phone extentions: if disabled, phone extension will be removed on field save. Phone field settings in example below: default region code 'RU', phone extensions are enabled echo $page->phone; // +79163180729 // Note1: $page->phone stores instance of PhoneNumber and renders to string in E164 format. // Note2: E164 format does not include extension. echo $page->getFormatted('phone'); // +7 916 318-07-29 ext. 1234 echo $page->getUnformatted('phone'); // +79163180729 echo $page->phone->format(PhoneNumberConst::RFC3966); // tel:+7-916-318-07-29;ext=1234 echo $page->phone->getNationalNumber(); // 9163180729 Usage: PW selectors FieldtypePhoneNumber is instance of FieldtypeText. It stores phone numbers and extensions as string in E164 format with #extention (if provided by user and enabled in settings) E.g. in db it looks like this: '+79163180729#1234'. This makes it easy to query fields as any text field. echo $pages->find([ 'template' => 'my_temlate', 'phone^=' => '+79163180729', ]); // will echo page ids where phone starts with '+79163180729' Finally I've decided to put it here first and later to Modules directory (based on your feedbacks). GitHub: https://github.com/valieand/HelperPhone Enjoy
    6 points
  2. You could either remove the page-add permission from the role completely or remove the "add children" permission in the page's template for the exponent role.
    2 points
  3. id is a field of the page even though it's an InputfieldHidden one.
    2 points
  4. Hi! Will "Show this field only if" condition work for you? You could specify an id of a page on which you would like your field to be present. I am attaching a screenshot to illustrate my point.
    2 points
  5. I'm not sure what you mean here. There is no prefix to field names that are used in a repeater. For example, if you have the "title" field in your containing page template, and also the title field in your repeater template then the field name "title" applies to both without any prefix. echo $page->title; // the containing page title echo $page->my_repeater->first->title; // the first repeater item's title Or do you mean that in Page Edit the inputfields inside a repeater have a suffix to their name, e.g. "title_repeater1147"? Because you don't need to use that when you get the field in your template.
    2 points
  6. I think OR-groups with selector arrays is buggy: I opened a GitHub issue here.
    2 points
  7. you would not imagine how often i have thought that myself and then i found out how to do it the processwire-way and it just seemed too simple with something like a 3-liner "heavy use" of repeater sounds like you could maybe improve/change how you structured your content. in PW thats a very important part of your work. if you structure your project/data well, most of the time you end up with very simple and clean selector-calls like $pages->find('template=product'); // or $page->children('category=car'); of course that's just wild guesses, but if you want to share your setup i'm sure you'll get valuable feedback from lots of knowledable guys (and girls) here
    2 points
  8. You can avoid some repetition and shorten the way you get field content in your templates like this: // Get the repeater item (the item is a page) $r_item = $page->repeater_field->first(); // Get field content from the item echo $r_item->foo; echo $r_item->bar; echo $r_item->baz;
    2 points
  9. This finds all 'articleFeatured' articles, but you only need one. So better to do this: $latestArticle = $pages->findOne("template=article, articleFeatured=1, sort=-created"); I wrote that imagickal() function and it doesn't recreate the image on every page load if the processed image already exists. But it was really intended for applying ImageMagick effects - you don't need it for simple image resizing. Rather than add padding in the resized image you should use CSS to keep the image within its container while maintaining aspect ratio. A couple of ways you can do this below - CSS is inline in the examples but you would move it to an external stylesheet. If you don't mind using background images the technique is dead simple. Just adjust the padding-top for the desired aspect ratio (in the example I used your 730:350 ratio). <div style="padding-top:47.945%; background:#000 url('my-image.jpg') no-repeat center center / contain;"></div> If you want to use an <img> tag there's a bit more to it: <div style="padding-top:47.945%; position:relative;"> <div style="position:absolute; width:100%; height:100%; top:0; left:0; font-size:0; line-height:0; text-align:center; background-color:#000"> <img src="my-image.jpg" style="max-width:100%; max-height:100%;"> </div> </div> If you are using a CSS pre-processor you can use a helper mixin, e.g. https://css-tricks.com/snippets/sass/maintain-aspect-ratio-mixin/ But none of this should make that much of a difference when you are using ProCache - your server load should be very low when ProCache is used considering you have no front-end users logging in. You could check to make sure you are not clearing the entire cache unnecessarily - for best performance you shouldn't use the "Reset cache for entire site" option for when a page is saved but instead use the settings on the "Cache" tab of Edit Template to only clear the cache of related pages. But the other thing to consider is if the problem might be due to the host. You could copy the files and DB to a different host and trial that for a bit to see if the problem resolves. A hassle for sure but if you are getting desperate...
    1 point
  10. Hey @joer80, I've been dealing with finals/graduation/masters applications lately and cannot spend as much time coding as I would like. Because of this I haven't been active in the forum for the last two weeks as well. However, hopefully tomorrow, after submitting a project which filled my last three weeks, I'll be finished with school (for now) and be able to go back on coding. Once I get a usable beta going, I'll open a topic for the updates and feedback. Thanks a lot for your interest. Abdus.
    1 point
  11. afaik it works with template id too, "template!=1200"
    1 point
  12. 1. Processwire default installation uses MyISAM as the engine which has the disadvantage of locking the entire table during a write operation. This can cause bottleneck issues in some cases. But if you are running a up-to-date MySQL version, you can change it to InnoDB to have better performance. BUT I cannot say that it will solve the problem just by doing this. Which version are you using? 1.1. And which PW version? 2. It can help to use MariaDB instead of MySQL as they say it uses less RAM, but moving the database to a second VPS will improve a lot. 3. Procache should help A LOT on the performance, as it bypasses PHP and MySQL altogether unless you're not using it right. Are the users logging in for instance? 4. Just of curiosity, why are you using a custom image processing and not PW built-in methods?
    1 point
  13. never mind, the simplicity of processwire was a big hurdle for many of us in the beginning ...and i'm still curious what setup would need lots of repeaters for structuring everything. usually you can keep everything very clean just by using different templates, different parents in the tree and doing the relations via pagefields. don't get me wrong. it's just my experience that whenever something felt complex/complicated it was most of the times a problem of my (or other forum users) setup i wish you lots of happy aha-moments
    1 point
  14. Hi @franciccio-ITALIANO, If your database was deleted for some reason, then ProcessWire will have no internal data (created during install) in which to reference. That means your admin login does not exist, nor the admin url, nor any other information. I'm afraid that you will need to re-install ProcessWire to use the new database. Since the previous database was deleted, so was the previous content, and any fields/templates/pages that existed before. The only information not specifically related to the previous database are the files in the /site/templates/ folders. You should copy those to a safe location before you re-install. I hope you are in contact with @3fingers on skype. He can help you, as he speaks Italian. I would talk with him first before you proceed with the new installation in case I have missed anything.
    1 point
  15. Check the ajax upload call for the returned data. This will hopefully show what's the issue here.
    1 point
  16. @Zeka's suggestion is the right direction, but a couple of extra things are needed: $your_pages = $pages->find("template=some_template"); foreach($your_pages as $p) { // Output formatting must be off before manipulating and saving the page $p->of(false); // You need to get the formatted value of the markdown field // i.e. with the textformatter applied $p->ckeditor_field = $p->getFormatted('markdown_field'); $p->save(); } Or a shorter way that takes care of the output formatting using setAndSave(): $your_pages = $pages->find("template=some_template"); foreach($your_pages as $p) { // Normally you wouldn't want to save a formatted value with setAndSave() // but in this case we do $p->setAndSave('ckeditor_field', $p->markdown_field); }
    1 point
  17. I do, but I use it just in my spare time, so close to nothing I prefer the skype way
    1 point
  18. Yes. I was thinking about the new users. We seem to be getting a few new members in the forum, which is great! I wonder how many have looked at the site without yet joining.
    1 point
  19. Only if you have already installed it, and this module is not installed by default.
    1 point
  20. Yup, of course, the pagination was not turned on!! Thank you @Peter Knight
    1 point
  21. Reading and writing times shouldn't be (noticeably) influenced by the pure size of a volume (unless the physical disk underneath is nearing the end of its capacity or the underlying FS becomes highly fragmented). Enumerating large number of entries (files/subdirectories) in a single directory would likely be a factor, so if you have more than 10k pages, breaking up the flat hierarchy of site directories could be worth thinking about - but even then, structuring them by year wouldn't be my first approach as it is counter-intuitive and has a number of pitfalls (e.g. timezone changes, duplicate files when overwriting, code that assumes all files for a page can be found in the same directory). Here's an example that adds a three-digit parent directory based on the page id that could be a starting point. It ignores the pageFilesSecure option, so be careful with it. You can look at PagefilesManager::___path and Pagefilesmanager::___url how they deal with that and other "magic". Of course, instead of that purely id-based dir, you can have the getPageSubdir function return anything you like. If you want to split your data between volumes, it could just return "old" for page ids < 5000 (or whatever the latest page id on the old volume is) and "new" for those above. /* * Change files path, insert a three-digit directory above, left-padded * with zeroes. This way, there won't be more than 999 directories under * site/assets. * * Subdirectory count won't be an issue unless you cross the million pages * mark. */ wire()->addHookAfter("PagefilesManager::path", null, "modifyPath"); function modifyPath(HookEvent $event) { $p = $event->return; $p = preg_replace_callback('~^(.*/)([^/]+)/~', function($match) { return $match[1] . getPageSubdir($match[2]) . "/" . $match[2] . "/"; }, $p); $event->return = $p; } wire()->addHookAfter("PagefilesManager::url", null, "modifyUrl"); function modifyUrl(HookEvent $event) { $url = wire('config')->urls->files . getPageSubdir($event->object->page->id) . "/" . $event->object->page->id . "/"; $event->return = $url; } function getPageSubdir($id) { return str_pad(substr($id, 0, 2), 3, '0', STR_PAD_LEFT); }
    1 point
  22. Off the top of my head ... 1. Is pagination enabled on that template? 2.
    1 point
  23. @Robin S thank you for looking into this. I can confirm that after making the change to Wir.php the hook fires. I will open an issue. EDIT: added issue on github
    1 point
  24. It looks to me like there is a typo in the core code that means the Wire::changed method is never called. See here... if(($hooks && $hooks->isHooked('changed')) || !$hooks) { But the phpDoc comments for WireHooks::isHooked say... * If checking for a hooked method, it should be in the form `Class::method()` or `method()` (with parenthesis). So it should have been... if(($hooks && $hooks->isHooked('changed()')) || !$hooks) { ...and if you change to that then the hook starts firing. @gebeer, will you open a GitHub issue for this?
    1 point
  25. Hi @joe_g Maybe you can loop over all your page and just save output of your markdown field to the newly created ckeditor field $yourpages = $pages->find("template=some"); foreach($yourpages as $p) { $p->ckeditorfiedl = $p->oldfield $p->save(); }
    1 point
  26. For simple json outputs, you can use WireArray::explode and json_encode() or wireEncodeJSON() methods https://processwire.com/api/ref/wire-array/explode/ $myPages = $pages->find('template=basic-page'); // extract required fields into plain array $data = $myPages->explode(['title', 'created']); echo wireEncodeJSON($data);
    1 point
  27. All fields in PW are custom fields. And you can't save content to a page without an actual field added to the page's template to hold that content (in your module you are only dealing with inputfields which themselves do not save their content to the DB). If you like you can add tags to your fields to create groups of fields within the fields list and keep things tidy. As @Macrura said, currently the only way to add a group of fields to a template in the form of a single unit is to create a repeater with those fields and limit it to a single repeater item. Or if you prefer, a PageTable or Profields Table in conjunction with Limit PageTable or Limit Table. Another approach that I sometimes take (if the project is well planned out in advance) is first create a template with the fields/fieldsets that will be used on all templates, and then I duplicate that template as the starting point for each additional template.
    1 point
  28. Can't you just make a regular fieldset tab and put them in there, i have sometimes 2-3 content tabs, and there is no reason to make a module. also on that example posted, the solution provided is only for outputting markup, like some instructions, or like a training video etc. AFAIK you cannot add a tab to page edit and expect those fields to automagically save to the database b/c the fields need to exist in the database to save to.
    1 point
  29. @theoretic @ZGD It seems like this commit fixed the compiler hickup: https://github.com/LostKobrakai/Migrations/commit/d22e6b4c5a5726e320dae0f6bd586578ad19a3b7
    1 point
  30. Hi! Look for Custom Editor JS Styles Set in the field configuration and enter a path for .js file. In this file you can define your custom styles like this: CKEDITOR.stylesSet.add('mystyles', [ // Block-level styles { name: 'Heading 1', element: 'h1'}, { name: 'Heading 2', element: 'h2'}, { name: 'Heading 3', element: 'h3'}, { name: 'Introduction', element: 'p', attributes: { 'class': 'introduction'} }, // Inline styles { name: 'Link button', element: 'a', attributes: { 'class': 'button' } }, { name: 'Highlight', element: 'span', attributes: { 'class': 'highlight' } }, // Object styles { name: 'Stretch', element: 'img', attributes: { 'class': 'stretch' } }, ]); Also make sure you have Styles toolbar item enabled.
    1 point
  31. The module soma is talking about is included in the core, but not installed, so go to the modules page and install "Session Handler Database" which will also install the required "Sessions" module. Let us know if you are still having problems finding this.
    1 point
×
×
  • Create New...