Geeklog France
 

daily_digest2.php

La méthode daily digest d'origine incluse dans le fichier lib-common.php expédie les emails au format texte brut et ne remplace place les caractères spéciaux dans le titre de l'email. Pour changer cela vous pouvez faire appel à un nouveau daily digest que nous nommerons daily-digest2

Créez un emailgeeklogstories2.sh

Créez un nouveau fichier pour une exécution cron nommé emailgeeklogstories2.sh qui appellera la fonction COM_emailUserTopics2()

:!: Remplacez le path/to par votre chemin jusqu'à votre daily_digest2.php.

Par exemple /home/domain/public_html/daily_digest2.php'

#!/usr/local/bin/php -q
<?php
// This code snippet is responsible for emailing Geeklog stories to users
// for the topics they select.
//
// For this script to work you must have compiled PHP so it can also be
// used as a shell scripting language. You should call this script from
// your crontab (man crontab). You will also need to set the exectuable
// flags for this file.
 
// Change this path to point to your daily_digest2.php file
    include('path/to/daily_digest2.php');  COM_emailUserTopics2();
?>

Création du daily_digest2.php

Créez le fichier daily_digest2.php et copiez le code si dessous.

:!: Modifiez les 2 chemins d'accès à votre config.php et lib-common.php.

Vous pouvez ajouter des caractères à remplacer en les ajoutant à la fonction COM_undoSpecialChars2.

<?php
 
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 1.4.1                                                             |
// +---------------------------------------------------------------------------+
// | daily_digest2.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_digest2,v 1.12 2008/06/10 ::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/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( '&ldquo;',   '"', $string );
    $string = str_replace( '&rdquo;',   '"', $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 );
    $string = str_replace( '&lsquo;',  '\'', $string );
 
    return( $string );
}
 
 
/**
* 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_emailUserTopics2()
{
    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() ) . "\n";
 
        for( $y = 0; $y < $nsrows; $y++ )
        {
            // Loop through stories building the requested email message
            $S = DB_fetchArray( $stories );
 
            $mailtext .= "\n------------------------------\n\n";
            $mailtext .= "$LANG08[31]: "
                . COM_undoSpecialChars2( stripslashes( $S['title'] )) . "\n";
            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 . "\n";
            }
 
            $mailtext .= "$LANG08[32]: " . strftime( $_CONF['date'], strtotime( $S['day' ])) . "\n\n";
 
            if( $_CONF['emailstorieslength'] > 0 )
            {
                $storytext = COM_undoSpecialChars2( strip_tags( PLG_replaceTags( stripslashes( $S['introtext'] ))));
 
                if( $_CONF['emailstorieslength'] > 1 )
                {
                    $storytext = COM_truncate( $storytext,
                                    $_CONF['emailstorieslength'], '...' );
                }
 
                $mailtext .= $storytext . "\n\n";
            }
 
            $mailtext .= $LANG08[33] . ' ' . COM_buildUrl( $_CONF['site_url']
                      . '/article.php?story=' . $S['sid'] ) . "\n";
        }
 
        $mailtext .= "\n------------------------------\n";
        $mailtext .= "\n$LANG08[34]\n";
        $mailtext .= "\n------------------------------\n";
 
        $mailto = $U['username'] . ' <' . $U['email'] . '>';
 
        COM_mail( $mailto, $subject, $mailtext );
    }
 
    DB_query( "UPDATE {$_TABLES['vars']} SET value = NOW() WHERE name = 'lastemailedstories'" );
}
 
?>
Connecté en tant que : Guest (Guest)
hacks/daily_digest2.txt · Dernière modification: 2008/09/08 09:55 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