We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46886
    • 1,154 Posts
    falko301,

    its a good idea! but why do it for another log, if you keep your install clean so there are no common errors, can't we just put a simple snippet in one of the tpls, and the snippet would just cause a minor error to go into the error log...everytime a new post is made.

    Like I am thinking the 'post' view which is the tpl for every new post, whether thread or reply, and when it goes through and gets posted, an error gets recorded and the email gets sent out.

    Would that work? Or maybe its not that hard to change the extra to focus on a discuss log...
      • 3749
      • 24,544 Posts
      I think that would work, but since it has the information, your snippet could send an email instead of logging an error. It could also use the Managers built-in messaging system. You can see how to do it in the code of this extra: http://bobsguides.com/messagemanager-tutorial.html.

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 46886
        • 1,154 Posts
        Pretty interesting BobRay. But is the location of the snippet in the post tpl going to work right? That's supposed to fire on posting, which means that little tpl, filled in with all the relevant info of content, time, and so on, *happens*, right? So the snippet only fires on creation, not every time someone opens the page? I am not sure it will fire at all, and also not sure it won't fire every time smiley

        Could we have a limiter in the snippet so it fires say if createdon date is not set, or other aspect of the post itself? Or is there another way to think about how to approach it.

        I suppose the real place to go to do this isn't the tpls at all, of which there are a million, but rather to the code that we edited to change the subscription behavior with Jay...I barely remember that code but we know what it does. Or even right in the manifest.

        Hey, thinking in an even different way, why couldn't we just make a snippet to send an email notice for each new value in the db. Maybe my idea isn't clear, in the db there will be logging of each individual post as a unique number, let's call it ID_number. Wouldn't it be relatively simple to tell the snippet, each time that ID_number in the db gets a new value, email is sent?

        So falk, what do you think about these ideas? Changing the extra from error log to discuss log is pretty smart thinking, but can you find a discuss log to use? Also is converting the extra to focus on a different log a hard job? It sounds simple in theory and sensible.

        I tried to go another way, I am not a dev so I always look for the simple way with less coding wink

          • 49512
          • 9 Posts
          Hi,
          again thx for your replies.
          From my point of view, there are three possible ways to extend discuss.
          1) extend the notifications hook, and discuss.class.php
          My first try was to send a 'bcc' message to a moderator, but it fails. The bcc was not sent.
            
              
              public function sendEmail($email,$name,$subject,array $properties = array()) {
                  if (empty($properties['tpl'])) return false;
          
                  $msg = $this->getChunk($properties['tpl'],$properties);
          
                  $this->modx->getService('mail', 'mail.modPHPMailer');
                  $this->modx->mail->set(modMail::MAIL_BODY, $msg);
                  $this->modx->mail->set(modMail::MAIL_FROM, $this->modx->getOption('discuss.admin_email'));
                  $this->modx->mail->set(modMail::MAIL_FROM_NAME, $this->modx->getOption('site_name'));
                  $this->modx->mail->set(modMail::MAIL_SENDER, $this->modx->getOption('discuss.admin_email'));
                  $this->modx->mail->set(modMail::MAIL_SUBJECT, $subject);
                  $this->modx->mail->address('to', $email, $name);
          -->     $this->modx->mail->address('bcc', $email, $name);
                  $this->modx->mail->address('reply-to', $this->modx->getOption('discuss.admin_email'));
                  $this->modx->mail->setHTML(true);
                  $sent = $this->modx->mail->send();
                  $this->modx->mail->reset();
          
                  return $sent;
              }
          

          The moderator or moderators array can be transfered with the properties
          2) or only notifications hook

          /* send out notifications */
          
          /** @var disUserNotification $notification */
          
          foreach ($notifications as $notification) {
          
             ...
              $sent = $discuss->sendEmail($user->email,$user->get('username'),$subject,$emailProperties);
              unset($emailProperties);
          }
          add this-->
          /** @var disBoardModerator $notification */
          
          foreach ($notifications as $notification) {
          
             ...
              $sent = $discuss->sendEmail($user->email,$user->get('username'),$subject,$emailProperties);
              unset($emailProperties);
          }
          

          I wolud prefer number 1, but bcc was not sent.
          Do you know, why the bcc will not be sent?

          regards
          falko301
            • 3749
            • 24,544 Posts
            In the code above, you're setting the main email address ("to") and BCC addresses to be the same. That could be the issue. The only other thing I can think of is the orthography of 'bcc' (versus 'Bcc' or 'BCC'), but that seems unlikely.
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 46886
              • 1,154 Posts
              This code is far beyond my abilities, so maybe I cant help. But I do know discuss pretty well, and,

              If you are trying to get the email address of the discuss moderator of a board, that could be a big problem. Because it assumes the classification of who is moderator in discuss is recognized by modx, which its not. the mod class will be known only to discuss, in modx side users have no such class i believe.

              or you would have to go into the discuss db to get the info.

              maybe try to send to a user first, or a defined email.

              [Oh wait he was just sending from site admin to admin...sorry] [ed. note: nuan88 last edited this post 7 years, 10 months ago.]
                • 46886
                • 1,154 Posts
                I think what I am trying to say is that getting the discuss info is not going to be so easy. you are going to have to pull up the discuss db more fully if you want info out of it.

                I can see the code tries to use the discuss db to get the mod data. this data probably is in there, but it takes a bit more code to access the db fully. I don't understand why, but it does.

                The mod list will be in there somewhere, but its not going to easy to get...I mean its in there, you probably have to open up the user classes first and then mod list and then I even doubt you can find the mod list per thread, to be honest. That will be probably data connected with every thread, thread data.
                  • 49512
                  • 9 Posts
                  Hi,
                  i don't know if my solution is the best way to do it smiley, but it will work.
                  I've not tested with system settings: global moderators, default moderators

                  these are my changes:

                  core/components/discuss/hooks/notifications/send.php
                  if (empty($url)) {
                    /* @var disThread $thread */
                    $thread = $modx->getObject('disThread',(int)$scriptProperties['thread']);
                    if ($thread) {
                  	$url = $thread->getUrl(true);
                    }
                  }
                  ----------------Begin -----------------
                  /* get thread moderators an send notification if system setting is enbaled */
                  $thread = $modx->getObject('disThread',(int)$scriptProperties['thread']);
                  if ($thread != null && $modx->getOption('discuss.enable_notifications_moderators',null,true)){
                  /** @var $thread $moderators */
                    $moderators = $thread->getModerators();
                    /** @var disUser $moderator */
                    foreach ($moderators as $moderator) {
                  
                  	if ($moderator == null) { continue; }
                  	$modx->log(modX::LOG_LEVEL_DEBUG, 'moderator get user :'.$moderator->get('id'));
                  	$user = $modx->getObject('disUser',$moderator->get('id'));
                  
                  	if ($user == null) { 
                  	  $modx->log(modX::LOG_LEVEL_DEBUG, 'user null: '.$moderator->get('user'));
                  	  continue; 
                      }
                      /* dont notify on own posts! */
                  	$modx->log(modX::LOG_LEVEL_DEBUG, 'author last : '.$thread->get('author_last').' user: '.$moderator->get('user'));
                  	if ($thread->get('author_last') == $moderator->get('user')) { continue; }
                  	$emailProperties = array_merge($scriptProperties,$moderator->toArray());
                  	$emailProperties['tpl'] = $tpl;
                  	$emailProperties['name'] = $scriptProperties['title'];
                  	$emailProperties['type'] = $type;
                  	$emailProperties['url'] = $url;
                  	$modx->log(modX::LOG_LEVEL_DEBUG, 'send mail for thread :'.$scriptProperties['thread'].' name '.$user->get('username').' mail '.$user->email);
                  	$sent = $sent = $discuss->sendEmail($user->email,$user->get('username'),$subject,$emailProperties);
                  	unset($emailProperties);
                    }
                  }
                  -------------------------End-------------------------------------
                  
                  /* send out notifications */
                  /** @var disUserNotification $notification */
                  foreach ($notifications as $notification) {
                  


                  add a new discuss system setting: discuss.enable_notifications_moderators and
                  lexicon entries: setting_discuss.enable_notifications_moderators,
                  setting_discuss.enable_notifications_moderators_desc

                  it is based on the extisting : discuss.enable_notifications extended by _moderators

                  @BobRay: do you think this is a proper way?

                  best regards
                  falko301
                    • 46886
                    • 1,154 Posts
                    Wow so cool! laugh
                      • 46886
                      • 1,154 Posts
                      Hi falko301:

                      I think BobRay is busy with whatever crisis is going on in the user base, as usual wink He will probably stop by and take a look at your code eventually. Heck the other week i saw him get back to a user on a totally minor point that occurred to him out of the blue from a month earlier. What a resource for us to learn laugh

                      So this is confirmed as a working solution? Its really a high quality solution.

                      You really focused well on where you could hook in, and how to generate the proper data. I feel your code is seriously efficient, you just grab what you need and take no prisoners. Also like the error reports so we can see what real testing looks like :p