horst

WireMailSmtp

Recommended Posts

horst    3,958

Wire Mail SMTP

An extension to the new WireMail base class that uses SMTP-transport

This module integrates EmailMessage, SMTP and SASL php-libraries from Manuel Lemos into ProcessWire. I use this continously evolved libraries for about 10 years now and there was never a reason or occasion not to do so. I use it nearly every day in my office for automated composing and sending personalized messages with attachments, requests for Disposition Notifications, etc. Also I have used it for sending personalized Bulkmails many times.

The WireMailSmtp module extends the new email-related WireMail base class introduced in ProcessWire 2.4.1 (while this writing, the dev-branch only).
 
Here are Ryans announcement.



Current Version 0.2.5

Install and Configure

Download the module into your site/modules/ directory and install it.

In the config page you fill in settings for the SMTP server and optionaly the (default) sender, like email address, name and signature.
You can test the smtp settings directly there. If it says "SUCCESS! SMTP settings appear to work correctly." you are ready to start using it in templates, modules or bootstrap scripts.


Usage Examples

The simplest way to use it:

$numSent = wireMail($to, $from, $subject, $textBody);

$numSent = wireMail($to, '', $subject, $textBody); // or with a default sender emailaddress on config page 

This will send a plain text message to each recipient.
 
You may also use the object oriented style:

$mail = wireMail(); // calling an empty wireMail() returns a wireMail object

$mail->to($toEmail, $toName);
$mail->from = $yourEmailaddress; // if you don't have set a default sender in config
                                 // or if you want to override that
$mail->subject($subject);
$mail->body($textBody);

$numSent = $mail->send();

Or chained, like everywhere in ProcessWire:

$mail = wireMail();
$numSent = $mail->to($toEmail)->subject($subject)->body($textBody)->send(); 

Additionaly to the basics there are more options available with WireMailSmtp. The main difference compared to the WireMail BaseClass is the sendSingle option. With it you can set only one To-Recipient but additional CC-Recipients.

$mail = wireMail(); 

$mail->sendSingle(true)->to($toEmail, $toName)->cc(array('person1@example.com', 'person2@example.com', 'person3@example.com')); 

$numSent = $mail->subject($subject)->body($textBody)->send(); 

The same as function call with options array:

$options = array(
    'sendSingle' => true,
    'cc' => array('person1@example.com', 'person2@example.com', 'person3@example.com')
    );

$numSent = wireMail($to, '', $subject, $textBody, $options); 

There are methods to your disposal to check if you have the right WireMail-Class and if the SMTP-settings are working:

$mail = wireMail(); 

if($mail->className != 'WireMailSmtp') {
    // Uups, wrong WireMail-Class: do something to inform the user and quit
    echo "<p>Couldn't get the right WireMail-Module (WireMailSmtp). found: {$mail->className}</p>";
    return;
}

if(!$mail->testConnection()) {
    // Connection not working:
    echo "<p>Couldn't connect to the SMTP server. Please check the {$mail->className} modules config settings!</p>";
    return;
} 

Following are a ...


List of all options and features


testConnection () - returns true on success, false on failures


sendSingle ( true | false ) - default is false

sendBulk ( true | false ) - default is false, Set this to true if you have lots of recipients (50+)


to ($recipients) - one emailaddress or array with multiple emailaddresses

cc ($recipients) - only available with mode sendSingle, one emailaddress or array with multiple emailaddresses

bcc ($recipients) - one emailaddress or array with multiple emailaddresses

 
from = 'person@example.com' - emailaddress, can be set in module config (called Sender Emailaddress) but it can be overwritten here

fromName = 'Name Surname' - optional, can be set in module config (called Sender Name) but it can be overwritten here


priority (3) - 1 = Highest | 2 = High | 3 = Normal | 4 = Low | 5 = Lowest

dispositionNotification () or notification () - request a Disposition Notification


subject ($subject) - subject of the message

body ($textBody) - use this one alone to create and send plainText emailmessages

bodyHTML ($htmlBody) - use this to create a Multipart Alternative Emailmessage (containing a HTML-Part and a Plaintext-Part as fallback)

addSignature ( true | false ) - the default-behave is selectable in config screen, this can be overridden here
(only available if a signature is defined in the config screen)

attachment ($filename, $alternativeBasename = "") - add attachment file, optionally alternative basename


send () - send the message(s) and return number of successful sent messages


getResult () - returns a dump (array) with all recipients (to, cc, bcc) and settings you have selected with the message, the message subject and body, and lists of successfull addresses and failed addresses,


logActivity ($logmessage) - you may log success if you want

logError ($logmessage) - you may log warnings, too. - Errors are logged automaticaly
 
 
useSentLog (true | false) - intended for usage with e.g. third party newsletter modules - tells the send() method to make usage of the sentLog-methods - the following three sentLog methods are hookable, e.g. if you don't want log into files you may provide your own storage, or add additional functionality here

sentLogReset ()  - starts a new LogSession - Best usage would be interactively once when setting up a new Newsletter

sentLogGet ()  - is called automaticly within the send() method - returns an array containing all previously used emailaddresses

sentLogAdd ($emailaddress)  - is called automaticly within the send() method
 

Changelog: https://github.com/horst-n/WireMailSmtp/blob/master/CHANGELOG.md

 

Edited by horst
bumped to version 0.2.5
  • Like 28

Share this post


Link to post
Share on other sites
ryan    13,365

Thanks for making this Horst! Tested here and got it working. I did have to modify your to() function (my fault, since I changed the WireMail interface for that function in the last update), but that was easy, and everything else worked (testing it with Gmail). I particularly liked being able to test the settings from the module screen.

Your getModuleInfo() returns singular=true.  The intention with WireMail is that it would be singular=false, so that you'd start with a new/fresh instance every time you get it from wireMail() or $modules->get('WireMailSmtp'). Otherwise, it might already have the to/from/subject/body settings from the last use still in there. 

Why necessary to specify the sender email address in the module settings? Will this prevent someone from being able to change the $mail->from(); address from the API side? Also was wondering why it's necessary to specify the hostname in the module settings? Does it go into an envelope from header or something? 

  • Like 1

Share this post


Link to post
Share on other sites
horst    3,958

Thanks for making this Horst! Tested here and got it working. I did have to modify your to() function (my fault, since I changed the WireMail interface for that function in the last update), but that was easy, and everything else worked (testing it with Gmail). I particularly liked being able to test the settings from the module screen.

Your getModuleInfo() returns singular=true. The intention with WireMail is that it would be singular=false, so that you'd start with a new/fresh instance every time you get it from wireMail() or $modules->get('WireMailSmtp'). Otherwise, it might already have the to/from/subject/body settings from the last use still in there.

Yes have read it in SwiftMailer-Thread before. I will update the module after posting this.  :)

Also have allready downloaded a fresh wire folder from Github.

Why necessary to specify the sender email address in the module settings? Will this prevent someone from being able to change the $mail->from(); address from the API side?

Lazyness! If using the object->style (not the procedural function call), there is no need to specify it when a default sender is set in config settings. But it could be overwritten by the $mail->from. Maybe I should make it an optional setting, not a required one.

I have thought of a setting that prevents overwriting settings from the config screen. Default Sender is the only one valid. Recipients could be a whitelist (currently a textarea under tab advanced) and a checkbox to include emailaddresses from PW users or not. If a security restriction like this is implemented and checked, mails only get send to recipients from the valid_recipients list.

Is this a useful feature?

Also was wondering why it's necessary to specify the hostname in the module settings? Does it go into an envelope from header or something?

This is used when connecting to the SMTP-Server. You find it as the first entry in the Received header of every received mail. For example my local test account is called pw4.kawobi.local, this is what the headers look:

Return-Path: <xxxx@xxxxxxx.xx>
X-Original-To: xxxx@xxxxxxx.xx
Received: from pw4.kawobi.local (dslb-084-099-066-105.t-online [84.99.66.105])
	by xyz1234.smtpserver.com (Postfix) with ESMTPSA id 5EDBC2C004E6
	for <xxxx@xxxxxxx.xx>; Mon,  3 Mar 2014 19:00:10 +0100 (CET)
To: Peter Mueller <xxxx@xxxxxxx.xx>
Subject: WireMailSmtp Test MultipartAlternative

As far as I know, this is common usage, but with most clients you cannot influence the chosen name.

EDIT: Module is updated to v0.0.4, look into the first post please. :)

  • Like 2

Share this post


Link to post
Share on other sites
horst    3,958

I have updated the class to version 0.0.5 and also have edited the first post of this thread (added some short examples and a list of available options/methods).

Now per default the module sends multiple messages in a loop, (one for each TO-recipient) like the base class do.

Additionaly you can call sendBulk to send larger amount of messages at once in an optimized manner, - or you can call sendSingle to set the module to allow only one TO-recipient but additionally CC-recipients. More information are now in the first post here.

  • Like 6

Share this post


Link to post
Share on other sites
horst    3,958

Hhm, sorry! With the 0.0.5 I have added a configuration option that lets you choose when an optional MailSignature should be send, but have left a boolean true somewhere in the code that overrides always these setting. :-[

Have corrected this now and committed the v 0.0.6 to GitHub. (ZIP)

  • Like 2

Share this post


Link to post
Share on other sites
horst    3,958

Yes it is. I think with Ryan's changes given to all email-related stuff it is much easier as of it was as we have talked about it.

If I remember right, you call only at one point in your code php's mail function. This part maybe get reorganized depending of if it is called a single time (then it is just fine to pass all recipients into wireMail at this point) or if it is within a loop (called multiple times), than you have to change this.

You have to pass $options array('sendBulk'=>true) with the wireMail($to, $from, $subject, $textBody, $options);

You need to update the wire folder to 2.4.1 (the current dev branch)!

EDIT:

There is only rare support built in for bulk mail sending, at least when focusing on robustness and comfortable handling of large amounts.

Actually there is only a check in it that skips duplicate emailaddress entries. Actually it is needed that the script runs within one request from start to end. If it gets interrupted somehow you end up in a mess. I think it is fine to use it with small amounts of recipients actually (0-200).

Oh, - while writing here I got an idea how to implement a simple hookable feedback for that. I will try this and add it to the module if it comes out functional.

EDIT2: added! see next post :)

Share this post


Link to post
Share on other sites
horst    3,958

updated to version 0.0.7

Added a new flag that tells the send() method to make usage of the new logging methods for handling large amounts of recipients by using permanent storage across multiple script calls:

  • useSentLog( true | false )
    Tells the send()-method to make usage of the SentLog-methods! 
     
  • sentLogReset()
    It starts a new LogSession - Best usage would be interactively once when setting up a new Newsletter.
     
  • sentLogGet()
    is called automaticly by the send() method - returns an array containing all previously used emailaddresses
     
  • sentLogAdd($emailaddress)
    is called automaticly by the send() method - stores each successfully sent emailaddress into the provided log

This is intended to use within third party modules for newsletter systems. All three sentLog methods are made hookable, so, e.g. if you don't want log into files you may provide your own storage, or add additional functionality here.

The usage is really simple, I think. When starting a new Newsletter Session, you once have to call wireMail()->sentLogReset() to clear any previously stored content in the log. This best should be done manually / interactively I think.

After that you only have to set the useSentLog flag to true, e.g by passing an options array into the procedural function call

$options = array(
    'sendBulk' => true,
    'useSentLog' => true
    );

$numSent = wireMail($to, $from, $textBody, $options);

or in object-oriented style like this

$numSent = wireMail()->sendBulk(true)->useSentLog(true)->to($to)->from($from)->body($textBody)->send();

That's all. Now you can call your newsletter sending script multiple times (for example bind to lazy cron) and no recipient get lost nor will receive multiple messages.

No more worries about script timeouts or other interruptions, just call your script in regular intervals, but ensure that only one instance is running at the time and not multiple in parallel. It would not mess up the logfile because it uses filelocking, but you may get trouble with your SMTP provider if you stress the server. :lol:

PS: @Nico: want to test it in the near future?

  • Like 6

Share this post


Link to post
Share on other sites
Raymond Geerts    482

Hello horst, i have installed and tried WireMailSmtp too and installing and sending mail works fine.

But i also noted that sending a form with more then 1 file field will send only a link to the first attachment. The second attachment is always 0b (in the email body). While in the FormBuilder Entries both files are uploaded correctly.

Seems like a little bug in the WireMail class processing the second file field incorrectly.

Share this post


Link to post
Share on other sites
horst    3,958

I don't know FormBuilder.

wireMail()->attachment() needs an absolute path for every (disk) file it should attach to a message. You can pass it as array or have to call it multiple times. Here are all is working as expected.

Maybe you can debug what is passed to the attachment function when running with FormBuilder?

You can call a log here

wire('log')->save( "debug_attachments", strtolower(__FUNCTION__).' :: '.serialize($filenames));   // ATTENTION this is $filename(s) ending with s

and here

wire('log')->save( "debug_attachments", strtolower(__FUNCTION__).' :: '.serialize($filename));   // ATTENTION this is $filename, without s

Trying this with passing an array logs something like:

2014-03-11 14:04:36	guest	http://pw4.kawobi.local/mailtest/	attachments :: a:2:{i:0;s:75:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/hyatt2.0x100.jpg";i:1;s:79:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/westin_interior1.jpg";}
2014-03-11 14:04:36	guest	http://pw4.kawobi.local/mailtest/	attachfile :: s:75:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/hyatt2.0x100.jpg";
2014-03-11 14:04:36	guest	http://pw4.kawobi.local/mailtest/	attachfile :: s:79:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/westin_interior1.jpg";

Calling it multiple times (2) with string filenames:

2014-03-11 14:10:10	guest	http://pw4.kawobi.local/mailtest/	attachments :: s:75:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/hyatt2.0x100.jpg";
2014-03-11 14:10:10	guest	http://pw4.kawobi.local/mailtest/	attachments :: s:79:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/westin_interior1.jpg";
2014-03-11 14:10:10	guest	http://pw4.kawobi.local/mailtest/	attachfile :: s:75:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/hyatt2.0x100.jpg";
2014-03-11 14:10:10	guest	http://pw4.kawobi.local/mailtest/	attachfile :: s:79:"W:/WEB_MIRRORS/_ProcessWire/pw4/htdocs/site/assets/files/1/westin_interior1.jpg";
  • Like 3

Share this post


Link to post
Share on other sites
Raymond Geerts    482

@horst thank you for helping and pointing out a way to log the file names to see what is going on.

I have placed both lines inside the WireMailSmtp.module and posted the form a few times to find out that nothing is logged. The code is right because putting the following line in the __construct() created the expected log file correctly.

wire('log')->save( "debug_attachments", "tralalala");
I came to the conclusion that form builder is not realy sending the files as attachments. All it does is save the attachments to /assets/cache/form-builder/form-x/entry-x/ and rendering a 'special' link to those files. So now i'm sure the bug is form-builder related and not in your WireMailSmtp and/or WireMailSwiftMailer module.

I will report it in the form-builder forum and see if i can find out something more to backup the bug report with.

Update: Haha Ryan is always 3 steps ahead :) I found this line in InputfieldFormBuilderFile.module

// @todo this is producing invalid file links when more than one file on the page

Edited by Raymond Geerts
  • Like 3

Share this post


Link to post
Share on other sites
horst    3,958

@Raymond: I don't know how FormBuilder works, where and how you can connect the uploaded files to the WireMail classes. If you find a solution it would be kind if you can post it here.

Share this post


Link to post
Share on other sites
martind    9

hi horst, thank you for this module, works great.

i'm interested in the "You can hook into it if you want use alternative stores for it" thing from a template to get a sentlog for each page, can you give me a tip how to achieve this?

Share this post


Link to post
Share on other sites
martind    9

ah ok, works this way.

wire()->addHook("wireMail::sentLogReset", function(HookEvent $event) {	
		$filename = wire('config')->paths->logs . 'wiremailsmtp_sentlog_' .wire('page')->name. '.txt';
		@touch($filename);
		$res = file_put_contents($filename, '', LOCK_EX );
		if(false===$res || 0!==$res || !file_exists($filename) || !is_readable($filename) || !is_writeable($filename)) {
			$this->logError('Cannot reset Content of the SentLog: ' . $filename);
			throw new WireException('You want to make usage of the SentLog-feature, but cannot reset Content of the SentLog: ' . basename($filename));
		}
		$event->replace = true;
		$event->return = 0===$res ? true : false;	
	
});
  • Like 1

Share this post


Link to post
Share on other sites
Macrura    2,142

@Horst,

great module, many thanks for your work on this! Got attachments sending and works perfectly....

Got a couple of questions; first thing is that my email client is showing the wrong time sent on the emails, specifically Outlook for Mac; webmail, apple mail and android mail are all showing the correct sent time; just wondering why Outlook is showing the sent time as 4 hours before the actual time sent - could it be interpreting the headers differently? Other than these messages sent by WiremailSMTP, outlook shows the correct time sent...

** Update - i'm now using mandrill for the smtp and this has fixed the time being wrong on Outlook; not sure if it is the server, or if Mandrill is cleaning up/altering some part of the email code itself;

2nd question is how might i use logActivity ($logmessage) to save that activity into a textarea field on my processwire page that the email is generating from?; would be cool to show a field with the send log right on that page;

another question which isn't really directly related to the module, is how one might use images within the RTE and be able to have the email display the images; it would require replacing the relative image paths in TinyMCE with the absolute paths, but i'm not sure how to get started on that...[for now i have a hanna code that inserts the site's base path; kills the image in the editor, but it shows in the email...

Share this post


Link to post
Share on other sites
cstevensjr    1,369

I finally got around to installing and configuring this module today.  Thank you for making this available as a ProcessWire module.  Everything worked fine and you should be commended for a quality piece of work.

  • Like 1

Share this post


Link to post
Share on other sites
horst    3,958

Got a couple of questions; first thing is that my email client is showing the wrong time sent on the emails, specifically Outlook for Mac; webmail, apple mail and android mail are all showing the correct sent time; just wondering why Outlook is showing the sent time as 4 hours before the actual time sent - could it be interpreting the headers differently? Other than these messages sent by WiremailSMTP, outlook shows the correct time sent...

The Date header what is sent together with the emails is configured this way:

date("D, j M Y H:i:s \G\M\T P")

It results in the current GMT and the local difference in P.

AFAIK that's the common way according to the RFCs.

2nd question is how might i use logActivity ($logmessage) to save that activity into a textarea field on my processwire page that the email is generating from?; would be cool to show a field with the send log right on that page;

logActivity isn't meant to hook into. But you can get data from the logfile with tail() or something.

The logfile is under $config->paths->logs . WireMailSmtp::LOG_FILENAME_ACTIVITY . '.txt'

Edited by horst
  • Like 4

Share this post


Link to post
Share on other sites
Macrura    2,142

@horst - thanks, this time difference thing is probably related to the actual server location vs the config->timezone ? does your module use the config->timezone setting to set that?

regarding the whole logging thing, i feel stupid, i'm pretty much lost even after reading this thread 5 times... no idea how to simply log the success of a mail being sent, either to a log file, or to a field on my page... for now i do this which is ok for the moment:

                        // Send
                        $sendLog = 'Number Sent: ';
                        $sendLog .=    $mail->send();
                        
                        // Logging
                        $email_log = $message->email_log;
                        $email_log .= "\n". $sendLog;
                        $message->email_log = $email_log;
                        $message->of(false);
                        $message->save();

Share this post


Link to post
Share on other sites
horst    3,958

@Macrura: regarding the logging, there are already functions that do the logging into files if you enable it like explained here.

If you don't want use the default logging files, you need to hook into the logging functions by e.g. creating a module with your logging functions or by defining the hooks on a template like MartinD described here.

But can you explain a bit more how you setup your mail recipients? How many recipients do you use (bulk or single)?

If you use bulk sending, do you have an admin page where you initialize the mail sending? (add / select recipients to / from a collection?)

Or do you prefer to do this ((partially) hardcoded?) in a template file only?

I can write some lines of example code if I know a bit more of your setup. :)

EDIT:

regarding the Date Header: https://github.com/horst-n/WireMailSmtp/blob/master/WireMailSmtpAdaptor.php#L351

It simply uses the PHP date function to output the current date-time. But you may try using the php gmdate function instead and look if it solves the issue.

You simply need to change date to gmdate in line 351 of WireMailSmtpAdaptor.php.

Edited by horst
forgot to answer to the date thing
  • Like 1

Share this post


Link to post
Share on other sites
Macrura    2,142

Hi Horst -

thanks ! i'm using PW pages for the email and i have contacts stored in pages and then i can use asmselect for choosing who to send to, 1 or more...

so for multiple i use the recipients array

// Recipients
if($message->recipients->count()) {
	$recipients = array();
	foreach($message->recipients as $recipient) {
		$recipients[] = $recipient->title . ' <' . $recipient->email . '>';
		}
	$mail->to($recipients); 
} 

but i was thinking that I want to personalize the emails, so i would need to refactor the code to start a loop with the recipients and then run a string replace on the {{name}} placeholder in the email...

how does this relate to the bulk option?

thanks also about the gmdate  - will look at that tonight..

cheers!

Share this post


Link to post
Share on other sites
Macrura    2,142

i think what was happening then with the date/time is that it is getting server time, as opposed to processwire time..

$this->emailMessage->SetHeader("Date", date("D, j M Y H:i:s \G\M\T P"));

so the problem could be for someone who is using a server in a different timezone

could we override this at the template/api level?
 

Also  - to elaborate more on this use case: last year i found it necessary to setup future sending emails to some clients (hosting invoices, payment plans etc..) and the only solution i could come up with was a service called LetterMeLater; but i thought while using it, that it would not be so hard to build this in processwire... so after about 2 hrs of setup i was able to replicate that and it works well, better than the original service i was using;

some features I've been able to accomplish over the last few days of creating this:

  • Select Identity to send from (and then uses that identity's signature)
  • Select multiple recipients
  • using a profields table, setup a schedule of sending, along with placeholder texts for each sending instance
  • Attachments to the message (page)
  • Attachments from a central repository of attachments
  • Links to documents/media
  • Render inline images in body and signatures (using string replacements for the image urls - prepending the site URL), also floating images are working
  • List of attached documents
  • Send offset (so you can select a due date and then offset to send the message X days early; this way you can set the dates in the table to the due dates and avoid date confusion)
  • Boilerplate insertion (select from an array of generic pre-written 'boilerplate' texts and insert them..)

this is going to really save a lot of time for me! I'm also using Mandrill to send these, so i can check to make sure they were sent, and also i can see if the recipient opened the message..

  • Like 3

Share this post


Link to post
Share on other sites
horst    3,958

i'm using PW pages for the email and i have contacts stored in pages and then i can use asmselect for choosing who to send to, 1 or more...

so for multiple i use the recipients array

Ok, if I got it right, you create a new page for a new message (regardless of single or bulk)

you select recipients via asm

create text, attach files, etc.

then at some point you need to save the page.

And now, - how do you execute the send? (scheduled or not)

Share this post


Link to post
Share on other sites
Macrura    2,142

Right - and i have a cron job which runs every 5 min a 'mail_cron' template;

the template runs through some $pages->find and gets the messages to be sent;

I only use it to schedule emails (though if i needed to send it right away, i would set the send time for 5 min from now..)

this is the simple sending code:

https://gist.github.com/outflux3/797a18f5d2eaf0a87efb

but i'm working on changing over to this:

https://gist.github.com/outflux3/530b8adb1a6b7019d262

the only difference i added the table for sending multiple future-scheduled emails with the text placeholders;

so you could use the custom text placeholder to have an amount due and then in the message say "Amount Due by {{duedate}}: {{custom}}"

or you can just use the custom field to send slightly different messages for each instance..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      hi everybody,
      this is a preview of a module that i'm working on for quite a long time. I needed it for an intranet office management application that i'm still working on. It makes it very easy to create very customized Datatables using the awesome jquery datatables plugin (www.datatables.net)
       
      EARLY ALPHA release!
      It's very likely that there will lots of changes to this module that may cause breaking your implementations.
       
      Module source
      sorry, removed as it changes too frequently; closed alpha - contact me if you think you can contribute
       
       
      Remarks:
      The module is intended to be used on the backend. Loading styles is at the moment only done via adding files to the $config->styles/scripts arrays. Also the communicaton to javascript is done via the $config->js() method that is built into the admin and would have to be implemented manually on frontend use. But it would not be difficult of course
      Installation:
      Nothing special here, just download + install
       
      edit: removed some parts, because i made a complete rewrite of the module! (see last posting in the thread)
       
      Customization example:
      in the screencast you see an example that i'm using in a process module. i put the table inside an InputfieldMarkup just to have the same look&feel all around the admin. you see that you could also use this module to create tables quickly and easily using @kongondo s runtime markup module.
      complete PHP code:
      $this->headline('Kundenliste'); $form = $modules->get('InputfieldForm'); // init datatables module $dt2 = $modules->get('RockDataTables2'); // setup columns // name $col = new dtCol(); $col->name = 'name'; $col->title = 'Name'; $col->data = function($page) { return $page->title; }; $dt2->cols->add($col); // type $col = new dtCol(); $col->name = 'type'; $col->data = function($page) { return $page->rockcontact_type->title; }; $dt2->cols->add($col); // modified $col = new dtCol(); $col->name = 'modified'; $col->data = function($page) { $obj = new stdClass(); $obj->timestamp = $page->modified; $obj->display = date('d.m.Y', $page->modified); return $obj; }; $dt2->cols->add($col); // setup table $dt2->id = 'dt_kundenliste'; $dt2->js('/site/modules/ProcessRockProjects/dt_kundenliste.js'); $f = $modules->get('InputfieldMarkup'); $f->value = $dt2->render(); $form->add($f); // ################################## // ajax request -> return data // non-ajax -> render form + table // ################################## if($config->ajax) { echo $dt2->getJSON($pages->find('template=rockcontact, sort=random, limit=10000')); die(); } else $out .= $form->render(); return $out; what is interesting here is this part:
      // modified $col = new dtCol(); $col->name = 'modified'; $col->data = function($page) { $obj = new stdClass(); $obj->timestamp = $page->modified; $obj->display = date('d.m.Y', $page->modified); return $obj; }; $dt2->cols->add($col); datatables support orthogonal data (https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html). a date column is a good example, because you need to DISPLAY a formatted date (like 10.02.2017) but you need to be able to SORT this column by a different value (timestamp). its very easy to accomplish this by providing both values in your json. Btw: You could also just transfer the timestamp and do the formatting on the client-side via javascript. Next Example will show ho this would work. Both cases can be necessary, it's just an example here.
      [...] removed
      Why i created this module:
      of course i know @Soma s module but i needed a lot more features and the newer datatables version. also i like to define all the columns as objects and have everything on one place. lister & markupadmindatatable: nice for basic tables but lacks of features to modify the appearance of the cell values (like rendering icons, background colors and so on) datatables provides a great frontend API for filtering, showing/hiding columns, getting data, modifying it... it also plays well together with frontend charts like google chart api in this case:
       
      todo / roadmap:
      all kinds of column filters (like seen in the example above that shows an older and bloated version of this module) support for ajax filters and pagination (currently all filtering and sorting is done on the client side. i tried it with up to 50.000 rows and got reasonable results. initial loading took around 10sec. but of course this heavily depends on the complexity of your table and your data.  
       
       
    • By Robin S
      PageListTrash
      Allows non-superusers to trash pages directly from Page List (if they have page-delete permission for that page).
      Not much to say really - the module adds a "Trash" option to the extra actions for pages in Page List. It looks and works just like the Trash action available to superusers.

      https://github.com/Toutouwai/PageListTrash/
       
      Up to you whether you think non-superusers should be trusted with simpler trashing. For most cases I like the default behaviour where editors have to jump through some more hoops - I want them to think carefully about what they are doing. But if an editor needs to trash several pages then this module might reduce frustration.
      @tpr, by now you can probably predict what I'm going to say...
      ...something to merge into AdminOnSteroids?
    • By celfred
      Hello,
      I'm desperately trying to update my website to PW 3.0.62 and I'm facing issues to to module compatibility. I was stuck with Pages2Pdf which I managed to solve bu updating the module from Github, but now it's the Pages Web Service module... and this time, I don't know wht to do
      The Module is found there. But it is quite old and I can't find it in the modules catalogue... and my site is making quite a use of it (I can't think of a way to do otherwise, sorry...)
      After adding the FileCompiler=0 to the module pages, the error I'm stuck with is :
      Fatal error: Class 'WireData' not found in /home/celfred/PlanetAlert/site/modules/ServicePages/ServicePages.module on line 22
      and I have no idea on what to do... I must admit I'm not a programmer but a middle-school teacher... (for your information, here's the site I'm talking about : http://planetalert.tuxfamily.org ) but I'm struggling hard to solve the different issues I have to face and I'm wlling to understand things. I have just spent many hours trying to make 2.8 work on my localhost (and it seems ok ) but I'd like to switch to 3.x to prepare the future
      If anyone had the will to spend a few minutes to try and help me, I would greatly appreciate.
      Thanks in advance !
      If you need more information to understand my problem, feel free to ask.
    • By dimitrios
      Hello,
      I have created a module that, given a Facebook app ID and secret, posts on Facebook on behalf of a user profile or page after a PW page is saved.
      This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates On/Off switch: specify a checkbox field that will not allow the post if checked Specify a message and/or an image for the post
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, a token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is used.


    • By kongondo
      Menu Builder
       
      Modules Directory
      Project Page
      Read Me (How to install, use, etc..)
      For highly customisable menus, please see this post.

      If you want a navigation that mirrors your ProcessWire page tree, the system allows you to easily create recursive menus using either vanilla PHP or Soma's great MarkupSimpleNavigation. In some cases, however, you may wish to create menus that:
      1. Do not mirror you site's page tree (hirarchies and ancestry); and
      2. You can add custom links (external to your site) to.

      That is primarily where Menu Builder comes in. It is also helpful if you:
      3. Prefer creating menus via drag and drop
      4. Have a need for menus (or other listings) that will be changing regularly or that you want to allow your admin users to edit.

      The issue of custom menus is not new here in the forums. The difference is that this module allows you to easily create such menus via drag and drop in the Admin. Actually, you can even use it to just create some list if you wanted to. In the backend, the module uses the jQueryUI plugin nestedSortable by Manuele J Sarfatti for the drag and drop and is inspired in part by the WP Custom Menu feature.
       
      Please read the Read Me completely before using this module. 
      For Complex or highly-customised menus, it is recommended to use the getMenuItems() method as detailed in this post.
       
      Features
      Ability to create menus that do not mirror your ProcessWire Page Tree hierarchy/structure Menus can contain both ProcessWire pages and custom links Create menu hierarchies and nesting via drag and drop Easily add CSS IDs and Classes to each menu item on creating the menu items (both custom and from ProcessWire pages) or post creation. Optionally set custom links to open in a new tab Change menu item titles built from ProcessWire pages (without affecting the original page). E.g. if you have a page titled 'About Us' but you want the menu item title to be 'About' Readily view the structure and settings for each menu item Menus stored as pages (note: just the menu, not the items!) Menu items stored as JSON in a field in the menu pages (empty values not stored) Add menu items from ProcessWire pages using page fields (option to choose between PageAutocomplete and AsmSelect [default]) or a Selector (e.g. template=basic-page, limit=20, sort=title). For page fields, you can specify a selector to return only those specified pages for selection in the page field (i.e. asm and autocomplete) For superusers, optionally allow markup in your menu titles, e.g. <span>About</span> Menu settings for nestedSortable - e.g. maxLevels (limit nesting levels) Advanced features (e.g. add pages via selector, menu settings) currently permissible to superadmins only (may change to be permission-based) Delete single or all menu items without deleting the menu itself Lock down menus for editing Highly configurable MarkupMenuBuilder - e.g. can pass menu id, title, name or array to render(); Passing an array means you can conditionally manipulate it before rendering, e.g. make certain menu branches visible only to certain users [the code is up to you!]  Optionally grab menu items only (as a Menu object WireArray or a normal array) and use your own code to create custom highly complex menus to meet any need. More... In the backend, ProcessMenuBuilder does the menu creation. For the frontend, menus are displayed using MarkupMenuBuilder.

      Credits

      In this module's infancy (way back!), I wanted to know more about ProcessWire modules as well as improve my PHP skills. As they say, what better way to learn than to actually create something? So, I developed this module (instead of writing PW tutorials as promised, tsk, tsk, naughty, naughty!) in my own summer of code . Props to Wanze, Soma, Pete, Antti and Ryan whose modules I studied (read copied ) to help in my module development and to Teppo for his wonderful write-up on the "Anatomy of fields in ProcessWire" that vastly improved my knowledge and understanding of how PW works. Diogo and marcus for idea about using pages (rather than a custom db table), onjegolders for his helpful UI comments, Martijn Geerts, OrganizedFellow, dazzyweb and Mike Anthony for 'pushing me' to complete this module and netcarver for help with the code.
       
      Screens