info:concrete5:58:notifyonmodif

Action disabled: source

mail de notification pages modifiées (via un job) dans concrete5

,

Notifier par email avec un sommaire des pages modifiées sur un site depuis XXX jours

Réalisation

  /application/tools/RRmJPf34wfn3rn7WHkn4C_notifyonaddpage.php
RRmJPf34wfn3rn7WHkn4C_ est un code aléatoire pour éviter qu'un pirate ne lance votre job, il faut donc IMPERATIVEMENT le changer
<?php
 
use \Concrete\Core\Tree\Type\Topic as TopicTree;
use \Concrete\Core\Tree\Node\Node as TreeNode;
use \Concrete\Core\Tree\Node\Type\Topic as TopicTreeNode;
 
//$nh = Loader::helper('navigation');
$mailService = Core::make('mail');
//$mailService->setTesting(false); // or true to throw an exception on error.
//$mailService->setTesting(true); // or true to throw an exception on error.
 
//adapt begin
$delay=7; //how much days to consider this is a new page? default=1day;
$site="unige.ch/arp";
$subject="Nouveautés sur le site : " .$site;
$mailService->from('john@doe.com', 'passerelle');
$destinataire='mary@smith.org'; //prod
 
//adapt end
 
$compteur=0;
$maintenant=date("U");
 
$list = new \Concrete\Core\Page\PageList();
$list->  sortByDateModifiedDescending();
$list->filterByPageTypeHandle('fiche');
 
//$list->sortByPublicDateDescending();
$pages = $list->getResults();
//c5 helpers
$th = Core::make('helper/text');
$dh = Core::make('helper/date');
 
$mailContent="<p>Modifications sur le site: " .$site ." depuis " .$delay ." jour(s)</p><hr />";
$mailContent.= '<div class="grid-container">';
 
foreach ($pages as $page):
  $title = $page->getCollectionName();
  //$dateU=$page->getCollectionDatePublic();
  $dateU=$page->getCollectionDateLastModified();
  $date = $dh->formatDateTime($dateU, true);
 
  $dateU=strtotime($dateU);
  $url = $page->getCollectionLink();
  if($maintenant-$dateU<($delay*24*3600)){ //only if overlaid delay
    $compteur++;
    $mailContent.= "<div class=\"row\">";
    $mailContent.= $date;
    $mailContent.= " : ";
    $mailContent.="<a href=\"";
    $mailContent.= $url;
    $mailContent.="\">";
    $mailContent.= $title;
    $mailContent.= "</a>";
    $mailContent.= "</div>";
  }
endforeach;
$mailContent.= '</div>';
$mailContent.= "<hr /><p><em>Ceci est un mail automatique. Merci de ne pas y répondre.</em></p>";
 
echo $mailContent;
 
$mailService->load('mailtemplate');
$bodyHTML .= '<!DOCTYPE html>';
$bodyHTML .= '<html lang="fr">';
$bodyHTML .= '  <head>';
$bodyHTML .= '      <meta charset="utf-8">';
$bodyHTML .= '  </head>';
$bodyHTML .= '  <body>';
$bodyHTML .= '      <div>';
$bodyHTML .= $mailContent;
$bodyHTML .= '      </div>';
$bodyHTML .= '  </body>';
$bodyHTML .= '</html>';
 
$mailService->setBodyHTML($bodyHTML);
$mailService->setSubject($subject
$mailService->to($destinataire);
 
if($compteur==0){
  echo "<p>pas de nouveautés</p>";
}else{
 
echo "<p>il y a des nouveautés, envoi du mail</p>";
$mailService->sendMail();
}
  fichier /application/jobs/notification_changed_pages.php 
<?php
namespace Application\Job;
use \Concrete\Core\Job\Job as AbstractJob;
use \Concrete\Core\Routing\Redirect;
 
class NotificationChangedPages extends AbstractJob
{
    public function getJobName()
    {
        return t("Notification par email des pages modifiées");
    }
 
    public function getJobDescription()
    {
        return t("Liste les pages modifiées depuis x jours et envoie un mail.");
    }
 
    public function run()
    {
        //Redirect::to('/tools/NkjK4sfdHsf3VJN4nqgTnotifyonaddpage');
        header("Location: https://radeff.red/c58/tools/RRmJPf34wfn3rn7WHkn4C_notifyonaddpage");
    }
}
  • info/concrete5/58/notifyonmodif.txt
  • Dernière modification : 2020/05/08 06:55
  • de radeff