Jump to content

abdus

Members
  • Posts

    743
  • Joined

  • Last visited

  • Days Won

    42

Everything posted by abdus

  1. It should've worked. $images->count is 1 when there's a single image, so --$page->randomIndex >= 0 returns true. But when there are multiple images but none matches 'inline-body' tag, then $images->count is 0 and --$page->randomIndex >= 0 returns false. Edit: If you use >= -1, the last image may be shown twice. Because when randomIndex reaches 0 (i.e. all images have been shown), it will return true with --$page->randomIndex >= -1 at the next hanna tag.
  2. I'm guessing for image fields with single image, where $page->images returns Pageimage instead of Pageimages? Then you can use getUnformatted() method: <?php // Hanna Code template if (!$page->randomImages) { $images = $page->getUnformatted('images'); // always returns PageImages array if ($images->count > 1) $images = $images->findTag('inline-body')->shuffle(); $page->randomImages = $images; $page->randomIndex = $images->count; } if (--$page->randomIndex >= 0) { // as per @Robin S's suggestion: // $img = $page->randomImages[$page->randomIndex]; $img = $page->randomImages->eq($page->randomIndex); echo "<img src='$img->url'/>"; }
  3. So far I haven't considered subscribing new users by creating a native user. I've integrated 4 services (MailChimp, Mailgun, Sendgrid, SparkPost) that allows subscription lists (recipient list/contacts/mailing lists,,, each with its own set of terminology, ugh) and a new subscriber is added to these lists. I think using these services in conjunction with @justb3a's could be better, in that I can hook into NewsletterSubscribe module and add the new user with `newsletter` roles to an one of the lists. Or simply, I could add an option to monitor user creation and add/remove when that user to a list if the user matches a certain selector. However, though very unlikely, there could be some issues with networking / API reliability and sending a request to add/remove the subscriber may fail. Not sure how I can deal with syncing issues, except maybe retrying it LazyCron etc. Mailer services are individual modules extending a base module so that I can combine all under ProcessMailer. But, they all can be used in isolation (with public methods, hooks etc). As for each being WireMail modules, I realized yesterday that to send emails via these services, service modules have to extend WireMail to some degree, so that's what I'll go with. But it would also mean I'd have degrade my base module into an interface and duplicate a good chunk of code. This would remove majority of the coupling between ProcessMailer and its services to the degree that I could release them one by one, rather than all packed under ProcessMailer. But it will postpone the release by at least a few weeks. Another option is that I could allow injection of a WireMail object as a parameter into one of the methods and modify the objects to suit service APIs, instead of converting them into individual WireMail modules. <?php namespace ProcessWire; public function ___sendEmail(WireMail $mail) { // modify $mail or extract relevant info and post it to mailer service $to = $mail->to(); $from = $mail->from(); // ... $this->send($apiEndpoint, $data); } // =========== $mail = new WireMail(); $mail->to(...) ->from(...) ->subject(...) ->bodyHTML(...); $list = 'newsletter@example.com'; $modules->MailerServiceMailgun->sendEmailToList($mail, $list);
  4. @DaveP's module can be useful for this. It can be extended for other verbs and providers too.
  5. The last ipsum you'll ever need: http://meettheipsums.com/
  6. Hmm. looking at your selector, you seem to be using `blog-entries` template for category pages. The exact solution will depend on how you configured your tagging system, but assuming you've used a Page Reference field called `category` limited to categories with `blog-entries` template, then you can use: // inside category template file // $page will point to a page with category template $categorized = $pages->find("template=blog-post, category=$page"); // ^ this will give you all pages with template blog-post whose category field include current page, (current category) // i.e. all posts under current category foreach($categorized as $post) { echo $post->title . '<br>'; } There's a tutorial by @kongondo which covers multiple scenarios and strategies for categorization, it's a must read for beginners.
  7. Where you put the rule matters. Let's try it differently. Remove the previous line and find 15. Access Restrictions section, and change its end from this # Block all http access to the default/uninstalled site-default directory RewriteCond %{REQUEST_URI} (^|/)site-default/ # Block all requests to WP specific files starting with wp- RewriteRule ^.*$ - [F,L] into this # Block all http access to the default/uninstalled site-default directory RewriteCond %{REQUEST_URI} (^|/)site-default/ [OR] # <------- REMEMBER TO ADD [OR] FLAG # Block all requests to WP specific files starting with wp- RewriteCond %{REQUEST_URI} (^|/)wp-.*\.php$ # If any conditions above match, issue a 403 forbidden RewriteRule ^.*$ - [F,L] This one blocks all requests ending with wp-xxxx.php and works great on my setup. (Previous method works, too)
  8. Filecompiler should have taken care of that Add namespace to the first line: <?php namespace ProcessWire;
  9. Add this to your .htaccess file # ----------------------------------------------------------------------------------------------- # 12. Access Restrictions: Keep web users out of dirs that begin with a period, # but let services like Lets Encrypt use the webroot authentication method. # ----------------------------------------------------------------------------------------------- RewriteRule "(^|/)\.(?!well-known)" - [F] # Block all requests to WP specific files starting with wp- RewriteRule wp-.*\.php$ - [F]
  10. It usually happens to me when there are a lot of errors, or when there's an endless recursion in my code
  11. Refresh your modules cache using $modules->refresh() in init.php/ready.php (or any template really) or Modules > Refresh from the admin
  12. Try removing static keyword from method signature, or change _() to __() or $this->_() or prepend _() with backslash \_().
  13. Rename site/assets/cache/FileCompiler folder to .FileCompiler or something else to force compile templates & modules. Flush Procache cache. Also, which version of PW are you on?
  14. Definitely make the switch to PHP 7.0 or 7.1
  15. Guys, I need some guidance. I'm trying to come up with a good strategy for creating subscription forms. But it feels like I'm complicating this too much. To give you some background: Multiple services be used simultaneously. For example: Mailgun for internal conversations, Mailchimp for promotional emails. A service can have multiple subscription lists. For example: one for weekly news, one for offers. A list can have only one subscription form for adding new members. It doesn't make sense to have multiple forms with different set of fields, which may result in empty columns for a subset of member records. At the same time, not all fields are necessary, but email must be specified at minimum. A form cannot expose anything to the frontend about the backend implementation to prevent spamming. For example Mailgun identifies lists using mail addresses (e.g. newsletter@example.com) that can be used to send mail to all members of the list. This means I have to assign unique IDs for subscription forms, then inject ID into each form as a hidden field. What I want to offer: Form customization. Developer should be able to add/remove fields to/from a subscription form. I can build a minimal form using required fields only, and let developer extend it by adding new fields and hook into relevant methods of service class Such as: function ___buildSubscriptionFrom($list) {} function ___addMemberToList($memberData, $list) {} $this->addHookAfter('MailerServiceMailgun::buildSubscriptionFrom', function($e) { $list = $e->arguments(0); if ($list != 'newsletter@example.com') return; $form = $e->return; $e->add([ 'type' => 'text', 'label' => 'Your age', 'name' => 'age' ]); }); $this->addHookBefore('MailerServiceMailgun::addMemberToList', function($e) { $data = $e->arguments(0); $data['vars'] = ['age' => $e->input->post->age]; $e->setArgument(0, $data); }); Another way of offering customization is by preparing a form for creating subscription forms and let users with certain permissions (mailer-forms-admin) pick and rename whichever fields he/she wants to use. This option would open up the possibility of developing a Textformatter in the future for quickly embedding forms to any field content. Such as: [[mailer-subscribe list=blog-list]] Which would display a subscription form for subscribing to blog updates. Now, writing this, providing hooks seemed like a good plan which I will put to use now, but I'm open to ideas.
  16. Try caching the result of that $selector = 'template=prod_series|prod_series_ethernet|prod_series_access|prod_series_accessories|prod_series_fiber|prod_series_pwr_supplies|prod_series_pwr_systems|prod_series_wireless, prod_status_pages!=1554|1559|1560|4242'; if (!($list = $cache->get('products-main-view', WireCache::expireHourly))) { $list = $pages->find($selector); $cache->save('products-main-view', $list); } // do sth with the $list PW will save a list of ids (such as 3545|2556|1456|7889|3456) to caches table in DB and it wont have to manually build that list at every non-cached request (I keep forgetting that you're using ProCache). Once it's cached, it'll retrieve pages back using IDs and you can't get faster than that. Procache is disabled when you're logged in. Are your results from an incognito window?
  17. ProCache should cover almost all of what they offer (mostly caching). I'd say it's a cash grab. You said you were hosting your websites on a managed VPS, how is your linux skills? Try switching to another hoster. I am a happy user of Vultr and DigitalOcean, and never had problems with them. They bill (IIRC) hourly, so you can try it for a few days for a few bucks and see if it works out for you. Managing your own VPS isn't too difficult. As long as you dont keep many ports open (80, 443 for web and 22 or a different port for SSH), set up a fail2ban and you'd be mostly OK in terms of security, and you get to extend your skillset along the way.
  18. Not tested, but you can store any information inside $page (or any class that extends WireData), and do something like this: <?php // Hanna Code template if (!$page->randomImages) { $page->randomImages = $page->images->findTag('inline-body')->shuffle(); $page->randomIndex = $page->randomImages->count; } if (--$page->randomIndex >= 0) { // as per @Robin S's suggestion: // $img = $page->randomImages[$page->randomIndex]; $img = $page->randomImages->eq($page->randomIndex); echo "<img src='$img->url'/>"; } Keep in mind, this will stop showing images after all images have been used.
  19. Try // get two random images $a = $page->images->findTag('inline-body')->shuffle()->slice(0, 2); https://processwire.com/api/ref/wire-array/
  20. I've added Mailchimp support A few more screenshots: Subscription Lists - Services New Subscription List - Mailchimp Module Configuration - Service Selection
  21. Easiest way is to use urlSegments. Here's a case study from @ryan that details how you can implement this
  22. For `value`, you can just set `value` attribute. But for `checked`, you need to set `checked` attribute. If you're using API to create inputs, then you can set `checked` property and generated HTML will omit checked attribute accordingly $checkbox->checked = false; <input type=checkbox /> $checkbox->checked = true; <input type=checkbox checked=true/> If you're creating inputs manually, then you need to add checked a attribute (any value), or remove it completely for unchecked <?php $isChecked = true; ?> <input type="checkbox" <?= $isChecked ? 'checked=true' : '' =?> />
  23. I'm also open to suggestions for other services. I didn't really like how SparkPost API handles subscriber lists, SendGrid is manageable but its terminology is very convoluted. I'll develop a service module for MailChimp as well, but haven't had the time to do anything about it yet.
  24. I've implemented subscriber list feature for Sendgrid, Mailgun and Sparkpost. One small complication with Sparkpost is that it doesn't really support addition of individual subscribers. It requires posting a complete list of subscribers with each update, which may not be ideal for large lists. For extensibility, I've created a base module and each service extends and overrides methods for creating and handling subscription and list forms, API calls etc, this is because each service has different requirements and parameters for every operation. This is the subscriber list form for Mailgun For SparkPost: and for SendGrid: This is how subscribers lists view look
  25. It works fine in my setup. Do you have any JS modifying the form? Also, check if you've mistyped ($input->post->deactivated == $something) as single = somewhere, rather than double == or triple === ? <?php namespace ProcessWire; if ($input->post->changesettings) { $checked = $input->post->deactivated; // checked == 1 } ?> <form method="POST" action=""> <input type="text" name="first_name" value="<?= $user['first_name']; ?>"> <input type="checkbox" name="deactivated" value="1"> <input type="submit" name="changesettings" value="Change settings" class="bigbutton"/> </form>
×
×
  • Create New...