Skip to content
General Revolution Evolution Add-ons International
Login | Register | MODX.com
MODX Open Source Content Management System, Framework, Platform and More.
Find a Partner | Hosts + SaaS | Jobs | Donate
  • RegisterSign Up with the MODX Community
  • LoginUse Your MODX.com Account
  • MODX Community Forums
  • General
  • General Discussions
  •  
  • Send email on document publish?#

  • 7231
    4,205
    Shane Sponagle | Snippet Call Anatomy | MODx Developer Blog | Working With a Content Management Framework: MODx

    Something is happening here, but you don't know what it is.
    Do you, Mr. Jones?  - 

    dev_cw Reply #1, 3 years, 8 months ago

    Reply
    • Link to this post#1
    Is there a plugin that will send an email when a document is published or edited? I thought I saw this before but have not found anything. Would OnDocPublished and OnDocFormSave be the best events for this?


  • 4310
    2,276
    Snippets : eForm 1.4.4.7 with SMTP & PMS's security fixes | PHC Results | EasyNewsletter from CSV

    Wiki Articles : Custom DB table to placeholders | Manager Locked Out?

    Websites : Work - U.K. based MODx development  |  Hobby - Free interactive education resources for teaching 4 - 11 year olds

    Hosting : One Smart Host - Professional MODx hosting 

    bunk58 Reply #2, 3 years, 8 months ago

    Reply
    • Link to this post#2
    Here's a modified version of one originally written by Rachel Black.
    I doubt it needs much explanation.
    I've used a chunk named "Emailer" with the placeholders and email text.
    The plugin would need the appropriate System Event ticked.
    Tested quickly, but it seems to work.
    $e = &$modx->Event;
    if($e->name == 'OnDocFormSave') {
    $pageid = $_POST['id'];
    $pagetitle = $_POST['pagetitle'];
    $editor = $modx->getLoginUserID() ;
    $editedby = $modx->db->getValue('SELECT `username` FROM `modx_manager_users` WHERE `id` = 1');
    $message = $modx->getChunk('Emailer');
    $message = str_replace("[+id+]", $_POST['id'], $message);
    $message = str_replace("[+pagetitle+]", $_POST['pagetitle'], $message);
    $message = str_replace("[+editedby+]", $editedby, $message);
    $to = 'someone@somewhere.com';
    $subject = "Doc edited report";
    $sender = $modx->config['emailsender'];
    if(!mail("$to", $emailsubject, $message, "From: ".$sender."\r\n"."X-Mailer: Content Manager - PHP/".phpversion()))
    {
    $modx->logEvent(1,3,"$to, $subject, $message, $sender", "Email");
    }
    return true;
    }


  • 4310
    2,276
    Snippets : eForm 1.4.4.7 with SMTP & PMS's security fixes | PHC Results | EasyNewsletter from CSV

    Wiki Articles : Custom DB table to placeholders | Manager Locked Out?

    Websites : Work - U.K. based MODx development  |  Hobby - Free interactive education resources for teaching 4 - 11 year olds

    Hosting : One Smart Host - Professional MODx hosting 

    bunk58 Reply #3, 3 years, 8 months ago

    Reply
    • Link to this post#3
    Getting carried away with this plugin business.
    Here's an improved version with configuration parameters for :
    which plugin event, to email address, email subject & chunk name.
    Plugin code :
    $e = &$modx->Event;
    
    if($e->name == ''.$piEvent.'') {
    $pageid = $_POST['id'];
    $pagetitle = $_POST['pagetitle'];
    $editor = $modx->getLoginUserID() ;
    $editedby = $modx->db->getValue('SELECT `username` FROM `modx_manager_users` WHERE `id` = 1');
    
    $message = $modx->getChunk(''.$tplChunk.'');
    $message = str_replace("[+id+]", $_POST['id'], $message);
    $message = str_replace("[+pagetitle+]", $_POST['pagetitle'], $message);
    $message = str_replace("[+editedby+]", $editedby, $message);
    
    $sender = $modx->config['emailsender'];
    
    if(!mail("$to", $subject, $message, "From: ".$sender."\r\n"."X-Mailer: Content Manager - PHP/".phpversion()))
    {
    $modx->logEvent(1,3,"$to, $subject, $message, $sender", "Email");
    }
    return true;
    }

    Plugin configuration settings :
    &to=Mail To;string;someone@somewhere.com &piEvent=Plug In Event;string;OnDocFormSave &tplChunk=Chunk Name;string;Emailer &subject=Email Subject;string;Who's been messing with my site?


  • 7231
    4,205
    Shane Sponagle | Snippet Call Anatomy | MODx Developer Blog | Working With a Content Management Framework: MODx

    Something is happening here, but you don't know what it is.
    Do you, Mr. Jones?  - 

    dev_cw Reply #4, 3 years, 8 months ago

    Reply
    • Link to this post#4
    Thanks, that is a great help indeed.
    BTW - I have often wondered, is $_POST['documentVariable'] the way to access document variables in a plugin? What about template variables, can these be accessed in the same way $_POST['tvName']?


  • 33337
    3,901
    - MODX Special Forces
    Share and explore websites made in MODx by Zaigham's Web | Tweet @zaigham | Resource Center


    MODx Current | MODx on Git! | BUGS! | RTFM (Read the Fully awesome Manuals)

    Zaigham (aka zi) Reply #5, 3 years, 8 months ago

    Reply
    • Link to this post#5
    This sounds helpful.

    Guys, be sure to put in the repo and not let this cool stuff buried in the forums.

    Thanks.


  • 4310
    2,276
    Snippets : eForm 1.4.4.7 with SMTP & PMS's security fixes | PHC Results | EasyNewsletter from CSV

    Wiki Articles : Custom DB table to placeholders | Manager Locked Out?

    Websites : Work - U.K. based MODx development  |  Hobby - Free interactive education resources for teaching 4 - 11 year olds

    Hosting : One Smart Host - Professional MODx hosting 

    bunk58 Reply #6, 3 years, 8 months ago

    Reply
    • Link to this post#6
    This is a print of the TV array using the event OnTVFormSave
    Array
    (
        [id] => 11
        [mode] => 301
        [params] => 
        [stay] => 
        [name] => Name
        [caption] => Name
        [description] => Name
        [type] => richtext
        [elements] => 
        [default_text] => @DOCUMENT 37
        [display] => 
        [rank] => 0
        [template] => Array
            (
                [0] => 6
                [1] => 11
            )
    
        [chkalldocs] => on
        [categoryid] => 16
        [newcategory] => 
        [save] => Submit Query
    )
    

    So I suppose you could access them via a plugin using the appropriate $_POST['whatever'] format.
    Adding on to the original plugin you can add the conent of the page with $_POST['ta'] so you could see what they'd done!





Actions

Login to Post

Other Support Options

To file a bug or make a feature request visit our issue tracker, or you can also purchase commercial support.

Love MODX?

If you build sites for a living with MODX or just love using it, why not give back?

Information

Posted in this thread:
bunk58, dev_cw, zaigham

 
Back to Top

MODX Global HQ

1333 N Stemmons Fwy, Ste 110
Dallas, TX 75207
United States

+1 (469) 777-MODX (6639)

The MODX Company

  • Contact
  • Media Center
  • Careers at MODX
  • Wall of Fame
  • The MODX Blog

Sponsors

SoftLayer Firehost: Secure Cloud Hosting

Stay Connected

Read our previous email newsletters.

Twitter Facebook Google+ LinkedIn github Feeds

Privacy Policy | Terms of Service | Pixels by AKTA Web Studio© 2005-2012 MODX. All rights reserved. Trademark Policy