Geeklog France

daily_digest_html.php

emailgeeklogstories_html.sh

Créez un nouveau fichier pour une exécution cron nommé emailgeeklogstories_html.sh

#!/usr/local/bin/php -q
 
<?php include('path/to/daily_digest_html.php');  COM_emailUserTopics_html(); ?>

Remplacez le path/to par votre chemin du fichier emailgeeklogstories_html.sh jusqu'à votre daily_digest_html.php

daily_digest_html.php

Créez le fichier daily_digest_html.php

<?php
 
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 1.4.1                                                             |
// +---------------------------------------------------------------------------+
// | daily_digest_html.php                                                         |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2000-2007 by the following authors:                         |
// |                                                                           |
// | Authors: Tony Bibbs        - tony AT tonybibbs DOT com                    |
// |          Mark Limburg      - mlimburg AT users DOT sourceforge DOT net    |
// |          Jason Whittenburg - jwhitten AT securitygeeks DOT com            |
// |          Dirk Haun         - dirk AT haun-online DOT de                   |
// |          Vincent Furia     - vinny01 AT users DOT sourceforge DOT net     |
// |          ::Ben             - geeklog.fr                                   |
// +---------------------------------------------------------------------------+
// |                                                                           |
// | This program is free software; you can redistribute it and/or             |
// | modify it under the terms of the GNU General Public License               |
// | as published by the Free Software Foundation; either version 2            |
// | of the License, or (at your option) any later version.                    |
// |                                                                           |
// | This program is distributed in the hope that it will be useful,           |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
// | GNU General Public License for more details.                              |
// |                                                                           |
// | You should have received a copy of the GNU General Public License         |
// | along with this program; if not, write to the Free Software Foundation,   |
// | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
// |                                                                           |
// +---------------------------------------------------------------------------+
//
// $Id: daily_digest_html, v 1.00 2007/12/14 ::Ben
 
 
 
/**
* Configuration Include: You should ONLY have to modify this 2 lines.
* Leave the rest of this file intact!
*
* Make sure to include the name of the config file,
* i.e. the path should end in .../config.php
*/
 
require_once( '/path/to/lib-common.php' );
 
 
/**
* undo function for htmlspecialchars()
*
* This function translates HTML entities created by htmlspecialchars() back
* into their ASCII equivalents. Also handles the entities for $, {, and }.
*
* @param    string   $string   The string to convert.
* @return   string   The converted string.
*
*/
function COM_undoSpecialChars2( $string )
{
    $string = str_replace( '&#36;',     '$', $string );
    $string = str_replace( '&#123;',    '{', $string );
    $string = str_replace( '&#125;',    '}', $string );
    $string = str_replace( '&gt;',      '>', $string );
    $string = str_replace( '&lt;',      '<', $string );
    $string = str_replace( '&quot;',    '"', $string );
    $string = str_replace( '&nbsp;',    ' ', $string );
    $string = str_replace( '&amp;',     '&', $string );
    $string = str_replace( '&Agrave;',  'A', $string );
    $string = str_replace( '&agrave;',  'à', $string );
    $string = str_replace( '&Acirc;',   'A', $string );
    $string = str_replace( '&acirc;',   'â', $string );
    $string = str_replace( '&Ccedil;',  'C', $string );
    $string = str_replace( '&ccedil;',  'ç', $string );
    $string = str_replace( '&Egrave;',  'E', $string );
    $string = str_replace( '&egrave;',  'è', $string );
    $string = str_replace( '&Eacute;',  'E', $string );
    $string = str_replace( '&eacute;',  'é', $string );
    $string = str_replace( '&Ecirc;',   'E', $string );
    $string = str_replace( '&ecirc;',   'ê', $string );
    $string = str_replace( '&Euml;',    'E', $string );
    $string = str_replace( '&euml;',    'ë', $string );
    $string = str_replace( '&Icirc;',   'I', $string );
    $string = str_replace( '&icirc;',   'î', $string );
    $string = str_replace( '&Iuml;',    'I', $string );
    $string = str_replace( '&iuml;',    'ï', $string );
    $string = str_replace( '&Ocirc;',   'O', $string );
    $string = str_replace( '&ocirc;',   'ô', $string );
    $string = str_replace( '&OElig;',  'OE', $string );
    $string = str_replace( '&oelig;',  'oe', $string );
    $string = str_replace( '&Ugrave;',  'U', $string );
    $string = str_replace( '&ugrave;',  'ù', $string );
    $string = str_replace( '&Ucirc;',   'U', $string );
    $string = str_replace( '&ucirc;',   'û', $string );
    $string = str_replace( '&Uuml;',    'U', $string );
    $string = str_replace( '&uuml;',    'ü', $string );
    $string = str_replace( '&#376;',    'Y', $string );
    $string = str_replace( '&yuml;',    'ÿ', $string );
    $string = str_replace( '&rsquo;',  '\'', $string );
 
    return( $string );
}
 
/**
* Send an email.
*
* All emails sent by Geeklog are sent through this function now.
*
* @param    string      $to         recipients name and email address
* @param    string      $subject    subject of the email
* @param    string      $message    the text of the email
* @param    string      $from       (optional) sender of the the email
* @param    boolean     $html       (optional) true if to be sent as HTML email
* @param    int         $priority   (optional) add X-Priority header, if > 0
* @param    string      $cc         (optional) other recipients (name + email)
* @return   boolean                 true if successful,  otherwise false
*
* @note Please note that using the $cc parameter will expose the email addresses
*       of all recipients. Use with care.
*
*/
 
function COM_mail2( $to, $subject, $message, $from = '', $html = true, $priority = 0, $cc = '' )
{
    global $_CONF, $LANG_CHARSET;
 
    static $mailobj;
 
    if( empty( $from ))
    {
        $from = COM_formatEmailAddress( $_CONF['site_name'], $_CONF['site_mail']);
    }
 
    $to = substr( $to, 0, strcspn( $to, "\r\n" ));
    $cc = substr( $cc, 0, strcspn( $cc, "\r\n" ));
    $from = substr( $from, 0, strcspn( $from, "\r\n" ));
    $subject = substr( $subject, 0, strcspn( $subject, "\r\n" ));
    $subject = COM_emailEscape( $subject );
 
    if( function_exists( 'CUSTOM_mail' ))
    {
        return CUSTOM_mail( $to, $subject, $message, $from, $html, $priority, $cc );
    }
 
    include_once( 'Mail.php' );
    include_once( 'Mail/RFC822.php' );
 
    $method = $_CONF['mail_settings']['backend'];
 
    if( !isset( $mailobj ))
    {
        if(( $method == 'sendmail' ) || ( $method == 'smtp' ))
        {
            $mailobj =& Mail::factory( $method, $_CONF['mail_settings'] );
        }
        else
        {
            $method = 'mail';
            $mailobj =& Mail::factory( $method );
        }
    }
 
    if( empty( $LANG_CHARSET ))
    {
        $charset = $_CONF['default_charset'];
        if( empty( $charset ))
        {
            $charset = 'iso-8859-1';
        }
    }
    else
    {
        $charset = $LANG_CHARSET;
    }
 
    $headers = array();
 
    $headers['From'] = $from;
    if( $method != 'mail' )
    {
        $headers['To'] = $to;
    }
    if( !empty( $cc ))
    {
        $headers['Cc'] = $cc;
    }
    $headers['Date'] = date( 'r' ); // RFC822 formatted date
    if( $method == 'smtp' )
    {
        list( $usec, $sec ) = explode( ' ', microtime());
        $m = substr( $usec, 2, 5 );
        $headers['Message-Id'] = '<' .  date( 'YmdHis' ) . '.' . $m
                               . '@' . $_CONF['mail_settings']['host'] . '>';
    }
    if( $html )
    {
        $headers['Content-Type'] = 'text/html; charset=' . $charset;
        $headers['Content-Transfer-Encoding'] = '8bit';
    }
    else
    {
        $headers['Content-Type'] = 'text/plain; charset=' . $charset;
    }
    $headers['Subject'] = $subject;
    if( $priority > 0 )
    {
        $headers['X-Priority'] = $priority;
    }
    $headers['X-Mailer'] = 'GeekLog ' . VERSION;
 
    $retval = $mailobj->send( $to, $headers, $message );
    if( $retval !== true )
    {
        COM_errorLog( $retval->toString(), 1 );
    }
 
    return( $retval === true ? true : false );
}
 
 
/**
* This will email new stories in the topics that the user is interested in
*
* In account information the user can specify which topics for which they
* will receive any new article for in a daily digest.
*
* @return   void
*/
 
function COM_emailUserTopics_html()
{
    global $_CONF, $_TABLES, $LANG08, $LANG24;
 
    $subject = strip_tags( $_CONF['site_name'] . $LANG08[30] . strftime( '%Y-%m-%d', time() ));
 
    $authors = array();
 
    // Get users who want stories emailed to them
    $usersql = "SELECT username,email,etids,{$_TABLES['users']}.uid AS uuid "
        . "FROM {$_TABLES['users']}, {$_TABLES['userindex']} "
        . "WHERE {$_TABLES['users']}.uid > 1 AND {$_TABLES['userindex']}.uid = {$_TABLES['users']}.uid AND (etids <> '-' OR etids IS NULL) ORDER BY {$_TABLES['users']}.uid";
 
    $users = DB_query( $usersql );
    $nrows = DB_numRows( $users );
 
    $lastrun = DB_getItem( $_TABLES['vars'], 'value', "name = 'lastemailedstories'" );
 
    // For each user, pull the stories they want and email it to them
    for( $x = 1; $x <= $nrows; $x++ )
    {
        $U = DB_fetchArray( $users );
 
        $storysql = array();
        $storysql['mysql'] = "SELECT sid,uid,date AS day,title,introtext,bodytext";
 
        $storysql['mssql'] = "SELECT sid,uid,date AS day,title,CAST(introtext AS text) AS introtext,CAST(bodytext AS text) AS introtext";
 
        $commonsql = " FROM {$_TABLES['stories']} WHERE draft_flag = 0 AND date <= NOW() AND date >= '{$lastrun}'";
 
        $topicsql = "SELECT tid FROM {$_TABLES['topics']}"
                  . COM_getPermSQL( 'WHERE', $U['uuid'] );
        $tresult = DB_query( $topicsql );
        $trows = DB_numRows( $tresult );
 
        if( $trows == 0 )
        {
            // this user doesn't seem to have access to any topics ...
            continue;
        }
 
        $TIDS = array();
        for( $i = 1; $i <= $trows; $i++ )
        {
            $T = DB_fetchArray( $tresult );
            $TIDS[] = $T['tid'];
        }
 
        if( !empty( $U['etids'] ))
        {
            $ETIDS = explode( ' ', $U['etids'] );
            $TIDS = array_intersect( $TIDS, $ETIDS );
        }
 
        if( sizeof( $TIDS ) > 0)
        {
            $commonsql .= " AND (tid IN ('" . implode( "','", $TIDS ) . "'))";
        }
 
        $commonsql .= COM_getPermSQL( 'AND', $U['uuid'] );
        $commonsql .= ' ORDER BY featured DESC, date DESC';
 
        $storysql['mysql'] .= $commonsql;
        $storysql['mssql'] .= $commonsql;
 
        $stories = DB_query( $storysql );
        $nsrows = DB_numRows( $stories );
 
        if( $nsrows == 0 )
        {
            // If no new stories where pulled for this user, continue with next
            continue;
        }
 
        $mailtext = $LANG08[29] . strftime( $_CONF['shortdate'], time() ) . "<br />";
 
        for( $y = 0; $y < $nsrows; $y++ )
        {
            // Loop through stories building the requested email message
            $S = DB_fetchArray( $stories );
 
            $mailtext .= "<br />------------------------------<br /><br />";
            $mailtext .= "$LANG08[31]: "
                . COM_undoSpecialChars2( stripslashes( $S['title'] )) . "<br />";
            if( $_CONF['contributedbyline'] == 1 )
            {
                if( empty( $authors[$S['uid']] ))
                {
                    $storyauthor = COM_getDisplayName ($S['uid']);
                    $authors[$S['uid']] = $storyauthor;
                }
                else
                {
                    $storyauthor = $authors[$S['uid']];
                }
                $mailtext .= "$LANG24[7]: " . $storyauthor . "<br />";
            }
 
            $mailtext .= "$LANG08[32]: " . strftime( $_CONF['date'], strtotime( $S['day' ])) . "<br /><br />";
 
            if( $_CONF['emailstorieslength'] > 0 )
            {
                $storytext = $S['introtext'] ;
 
                if( $_CONF['emailstorieslength'] > 1 )
                {
                    $storytext = $S['introtext'] . "<br /><br />" . $S['bodytext'] ;
                }
 
                $mailtext .= $storytext . "<br /><br />";
            }
 
            $mailtext .= $LANG08[33] . ' ' . COM_buildUrl( $_CONF['site_url']
                      . '/article.php?story=' . $S['sid'] ) . "<br />";
        }
 
        $mailtext .= "<br />------------------------------<br />";
        $mailtext .= "<br />$LANG08[34]<br />";
        $mailtext .= "<br />------------------------------<br />";
 
        $mailto = $U['username'] . ' <' . $U['email'] . '>';
 
        COM_mail2( $mailto, $subject, $mailtext );
    }
 
    DB_query( "UPDATE {$_TABLES['vars']} SET value = NOW() WHERE name = 'lastemailedstories'" );
}
 
?>

Modifiez le chemin d'accès à votre lib-common.php.

Connecté en tant que : Guest (Guest)
hacks/daily-digest-html.txt · Dernière modification: 2008/09/08 10:48 par ::Ben
 

Download geeklog

Last version 1.8.1

Espace Membre





Devenir membre
Enregistrez-vous

Mot de passe oublié ?

Change language

Categories

  • Geeklog (38)
  • Plugins (53)
  • Thèmes (17)
  • My cart

    Votre panier (0 article)

    Votre panier est vide!

    0.00 EUR

    Visual Theme Switcher

    Test out available themes by selecting from one of the 6 available themes or give the Visual Switcher a try:

    Follow us on twitter

    En ligne

    Visiteurs: 8