Wp-mail pour moblogin !

  • Statut : non résolu
4 sujets de 1 à 4 (sur un total de 4)
  • Auteur
    Messages
  • #448447
    bisou
    Participant
    Initié WordPress
    11 contributions

    Bonjour, j’ai retrouver le wp-mail de Adrian Heydecker.

    Voila le code :

    #!/usr/bin/php -q
    <?php
    
    /**
    * wp-mail.php
    *
    * Copyright (c) 2003-2005 The Wordpress Team
    * Copyright (c) 2004-2005 - John B. Hewitt - jb@stcpl.com.au
    * Copyright (c) 2004 - Dan Cech - dcech@lansmash.com
    * Copyright (c) 2005 - Dirk Elmendorf - dirk@economysizegeek.com
    * Copyright (c) 2005 - David Luden
    * Copyright (c) 2005 - Adrian Heydecker - http://wavestyle.ch
    *
    * Licensed under the GNU GPL. For full terms see the file COPYING.
    *
    * -= README =-
    * This is a drop in replacement modification for the Wordpress 1.2 series that enables
    * you to send e-mail's with picture and document attachments.
    * For more information check out my blog - http://blade.lansmash.com
    * This script now has some additional features
    * You can include images as part of the text by using the image place holder text. by default this is #img1# #img2# etc
    * You can also have your email delay it's publication
    *    just add the string delay:XdXhXm  where X is a number d = days , h = hours, m = minutes - you can do any combination
    *   so delay:1d1m = 1 day 1 minute
    *      delay:15m1h = 1 hour 15 minutes
    
    * -= History =-
    
    * Version 0.312.3-HEY  (2005-05)
    * -> Some changes and Bugfixes by Adrian Heydecker
    * -> Not (yet) in main development branch.
    * Fixed bug: JPEG-thumbnails had a bigger filesize than full images caused by bad hardcoded compression value.
    * Fixed bug: If images and signatures were present but no placeholder tags, the images were deleted together with the signature.
    * Fixed bug: Generates valid postnames for users of mod_rewrite. Permalinks to posts should now work even when whitespaces are present in the subject line.
    * Added support for Quoted Printable encoded mail.
    * Added ability to encode Wordpress-posts in charset ISO-8859-1 instead of UTF-8.
    * Added ability to choose JPEG-compression value for thumbnails.
    * Added ability to add class=”” and style=”” to images.
    * Added ability to use a different mailadress (eg. mobile) without setting up a new Wordpress-account.
    *
    * Version 0.312.2
    * BUGFIX: It now removes the delay tag from the message
    * Version 0.312.1
    * Added modification for placeholder support for images (David Luden)
    * Added in support to automatically scale down big images (Dirk Elmendorf)
    * Fixed bug with multiple emails all getting the contents of the first image tag (Dirk Elmendorf)
    * Added option to allow HTML in the body and subject of the email (Dirk Elmendorf)
    * Switch config options to defines to reduce the number of global variables (Dirk Elmendorf)
    * Added tests to make sure there is a trailing slash on the DIR definitions (Dirk Elmendorf)
    * Add tests to see if they have gd installed (Dirk Elmendorf)
    * Seperate the scaling out to a function for easier usage (Dirk Elmendorf)
    * Add delay feature for future posting. (Dirk Elmendorf)
    * Added in ability to use strtotime if it is available (Dirk ELmendorf)
    *
    * Todo
    *   Have option to have the email that is rejected forwarded on to another address.
    * Fix bug that id still diplays the delay tag in the body
    * Version 0.312 – 2005-03
    * – CHANGE FOR DEFAULT E-mail Categories, instead of [General] Subject you can now use General: Subject in the subject line.  Less typing, and there must be a space after the colon.
    * – Fixed bugs with no default posting for categories and user
    * Version 0.311 – 2005-01
    * – eep, major bug for pop3 server. Next time I test my code more before I released, fixed so that pop3 now works.`
    * Version 0.31 – 2004-12 & 2005-01
    * (Has it been this long, best get back into the swing of things… did most of this coding on my holiday as I didn’t have a machine to play WoW on :)
    * – moved the deletion of pop3 emails into a check so that e-mails aren’t deleted without proper checking.
    * – added html ‘decoding’ (basic support for Thunderbird & Outlook)
    * – updated the Category search so that it matches words as well as numbers (i.e. [General] Subjectname will work instead of just [1] Subjectname)
    * – Changed time function from time to strtotime (as per Senior Pez’s suggestion), but found out that strtotime isn’t in default php distro so removed…
    *
    * Vesion 0.3 – 2004-09
    * – Added UBB decoding support
    * – Added default title (when there is no subject assigned)
    * – Started doing a little code cleanup, been reading Advanced PHP Book :)
    *
    * Version 0.2 – 2004-08
    * – Stopped using pear body decoding in favour of own decoding (may be slower but more modifiable) because of enriched text decoding
    * – Added base64_decode checking (may help mobile phone users)
    * – Fixed Subject line for non-english users (htmlentities instead of just trim)
    * – Fixed error in some pop hanging -> more graceful exit on event on no emails in inbox ($pop3->quit)
    * – Added work around for email addresses with exta <> in field (ie: <blade@lansmash.com> instead of blade@lasmash.com
    * – Added some ===basic=== enriched text support
    * – Updated readme file for easier install
    * – Easy modify of globals (such as PHOTOSDIR and FILESDIR)
    * – Cleaned up some pear stuff in install
    *
    * Version 0.1 – 2004-06
    * First release
    
    -= Begin Program =-
    **/
        //Load up some usefull libraries
        define(“ROOTDIR”,dirname(__FILE__)); //area where wordpress is, i.e. /var/www/wordpress
        require(ROOTDIR . ‘/wp-config.php’);
        require_once (ROOTDIR . ‘/mimedecode.php’);
    
    /* USER VARIABLES */
    /* USER VARIABLES */
        //vars you can change, but dont unless you know what you’re doing. :)
        define(“PHOTOSDIR”,”/wp-content/uploads/”);  //relative directory, must include extra slashes
        define(“FILESDIR”,”/wp-content/uploads/”);  //relative directory, must include extra slashes
        define(“RESIZE_LARGE_IMAGES”,true); // true/false – if on it will automatically make thumbnails if you have gd installed
        //If the image is bigger than this a scaled version will be made
        define(“MAX_IMAGE_WIDTH”,400);
        //if you don’t want to add a subject in the email then you assign a default
        define(“DEFAULT_TITLE”,’Par Le Portable’);
        //What protocol are we using? Just leave it default if you don’t know
        define(“INPUT_PROTOCOL”,”pop3″); //pop3/smtp
        //Delete mail on successful download? Setting FALSE for debuging
        define(“DELETE_MAIL_AFTER_PROCESSING”,true);
        //Default Category to use if non-selected
    define(“DEFAULT_CATEGORY”,get_settings(‘default_category’)); //Set if you want the standard default – use this if you are not using WordPress 1.5
        define(“DEFAULT_POST_CATEGORY”,get_settings(‘default_email_category’)); //if you want to use the one set by the email preferences in 1.5
        //Time difference – tweak to suit, ie (10 for Brisbane, Australia)
        //You may not need this
        #$time_difference = get_settings(‘gmt_offset’);
        define(“TIME_OFFSET”,1);
        //drop Sigature, Everything after — is deleted in the text msg.
        define(“DROP_SIGNATURE”,true);
        //Controls if HTML is allowed in the subject of an email
        define(“ALLOW_HTML_IN_SUBJECT”,true);
        //Controls if HTML is allowed in the body of an email
        define(“ALLOW_HTML_IN_BODY”,true);
        define(“IMAGE_PLACEHOLDER”,’#img%#’); // % – The percent sign is used to represent the number of the image.
        define(“START_IMAGE_COUNT_AT_ZERO”,false); // Where to start placeholders.
        //true means the first image is 0
        //false means the first is 1
        //For example, #img0# or #img1# (Every occurence of a particular placeholder should show that image.)
        define (“WORDPRESSMAIL”,’test@wanadoo.fr’);
        define (“SECONDMAIL”,’ 06000000@orange.fr’);
        //If you want to use a second mail adress. Fill in both or none!
        //WORDPRESSMAIL is the adress defined in your Wordpress profile.
        //SECONDMAIL is an adress you want to use to post under your Wordpress account.
        //Usefull for MMS if you have an adress like yournumber@yourprovider.com. You can allow posting under this adress, too.
        define (“IMAGECLASS”,’wp-mailimage’);
        // CSS-Class of inserted Images. You can set .wp-mailimage{border: 1px solid black} for example in your CSS-File.
        define (“IMAGESTYLE”,’border: none;’);
        //If you dont want to change your CSS-File, you can insert values directly. This replaces IMAGESTYLE in <img style="IMAGESTYLE"> with your favorite CSS-value.
        define (“JPEGQUALITY”,100);
        //Compression Value for resized JPEG-Images
        //Choose Value between 0 (high Compression – ugly) and 100 (almost no Compression – pretty).
        //75 is a good compromise between filesize and look, 85 looks good. Higher values are too much in most cases.
        define(“utf-8”,true);
        // Is your blog encoded in ISO-8859-1 ?
    
    /* END OF USER VARIABLES */
    
    
    
    
        //some variables
        error_reporting(2037);
    
        if (!ConfirmTrailingSlash(PHOTOSDIR)) {
            die(“The PHOTOSDIR directive must have a / at the endn”);
        }
        if (!ConfirmTrailingSlash(FILESDIR)) {
            die(“The FILESDIR directive must have a / at the endn”);
        }
        if (RESIZE_LARGE_IMAGES
                && !HasGDInstalled()) {
            die(“You have turned on RESIZE_LARGE_IMAGES, but you do not have GD installed properly.n”);
        }
    define(“URLPHOTOSDIR”,get_settings(‘siteurl’) . PHOTOSDIR);
    define(“REALPHOTOSDIR”,ROOTDIR . PHOTOSDIR);
    define(“URLFILESDIR”,get_settings(‘siteurl’) . FILESDIR);
    define(“REALFILESDIR”,ROOTDIR . FILESDIR);
    
    
        //Retreive emails
        switch ( strtolower(INPUT_PROTOCOL) ) {
            case ‘smtp’: //direct
                $fd = fopen(“php://stdin”, “r”);
                $input = “”;
                while (!feof($fd)) {
                    $input .= fread($fd, 1024);
                }
                fclose($fd);
                $emails[0] = $input;
                break;
            case ‘pop3’:
            default:
                $emails = pop3_retr();
            }
    
        //loop through messages
        foreach ($emails as $email)
        {
            //sanity check to see if there is any info in the message
            if ($email == NULL ) { print ‘Dang, message vide!’; die; }
    
            //decode the mime
            $params[‘include_bodies’] = true;
            $params[‘decode_bodies’] = false;
            $params[‘decode_headers’] = true;
            $params[‘input’] = $email;
            $structure = Mail_mimeDecode::decode($params);
            #    print_r ($structure);
    
            //assign the default title/subject
            if ( $structure->headers[‘subject’] == NULL )
            {
                $subject = DEFAULT_TITLE;
             } else {
                if (ALLOW_HTML_IN_SUBJECT) {
                    $subject = $structure->headers[‘subject’];
                }
                else {
                    $subject = htmlentities($structure->headers[‘subject’]);
                }
            }
    
            $from = trim($structure->headers[‘from’]);
    
            //Check poster to see if a valid person
            $poster = checkposter($from);
    
            //default ping/comment status for sanity
            $comment_status = get_settings(‘default_comment_status’);
            $ping_status = get_settings(‘default_ping_status’);
    
            //work around for users with extra <> in email address
            if (preg_match(‘/^[^<>]+<([^<>]+)>$/’,$from,$matches))
            {
                $from = $matches[1];
            }
            $IMAGES = array();
            $content = get_content($structure,$IMAGES);
    
            // Moved by Hey:
            // Hint: All images without placeholder appear behind the signature.
            // If this is executed after the insertion of images, images are not visible
    
            //remove signature
            if ( DROP_SIGNATURE ) { $content = removesig($content); }
    		
    
    
            //Begin Search and Replace for image placeholders
            (START_IMAGE_COUNT_AT_ZERO ? $startIndex = 0 :$startIndex = 1);
            foreach ( $IMAGES as $i => $value ) {
                // looks for ‘ #img1# ‘ etc… and replaces with image
                $img_placeholder_temp = str_replace(“%”, intval($startIndex + $i), IMAGE_PLACEHOLDER);
                if ( stristr($content, $img_placeholder_temp) ) {
                    $content = str_replace($img_placeholder_temp, $IMAGES[$i], $content);
                }
                else
                {
                    $content .= $IMAGES[$i];
                }
            }
            // End Image Place Holder Search and Replace
    
            //date reformating
    
            $ddate = trim($structure->headers[‘date’]);
            list($post_date,$post_date_gmt) = DeterminePostDate($content,$ddate);
    
            //decode ubb
            $content = ubb2html($content);
    
            //filter new lines
            $content = filternewlines($content);
    
            //try and determine category
            if ( preg_match(‘/(.+): (.*)/’, $subject, $matches) OR preg_match(‘/[(.+)] (.*)/’, $subject, $matches) )
            {
                $post_categories[0] = trim($matches[1]);
                $subject = trim($matches[2]);
    
                //Work on the category search to see if we can determine the cat_id
                //check the database to see if their is a category similar
                $sql_name = ‘SELECT cat_ID FROM ‘ . $tablecategories . ‘ WHERE cat_name=” . addslashes($post_categories[0]) . ”’;
                $sql_id = ‘SELECT cat_ID FROM ‘ . $tablecategories . ‘ WHERE cat_ID=” . addslashes($post_categories[0]) . ”’;
    
                if ( $post_categories[0] = $wpdb->get_var($sql_name) ) {
                    //then category is a named and found
                } elseif ( $post_categories[0] = $wpdb->get_var($sql_id) ) {
                    //then cateogry was an ID and found
                } else {
                    //then there was no found category so use default
                    $post_categories[0] = DEFAULT_POST_CATEGORY;
                }
            } else {
                $post_categories[0] = DEFAULT_POST_CATEGORY;
            }
            //Added by HEY:
            //Do not take $subject as post_name.  WP using mod_rewrite will be broken!
            $postname = subject2postname($subject);
    
            // Report
            // print ‘<p><b>Mail Format</b>: ‘ . $mailformat . ‘</p>‘ . “n”;
            print ‘<p><b>From</b>: ‘ . $from . ‘<br />‘ . “n”;
            print ‘<b>Date</b>: ‘ . $post_date . ‘<br />‘ . “n”;
            print ‘<b>Date GMT</b>: ‘ . $post_date_gmt . ‘<br />‘ . “n”;
            print ‘<b>Category</b>: ‘ . $post_categories[0] . ‘<br />‘ . “n”;
            print ‘<b>Subject</b>: ‘ . $subject . ‘<br />‘ . “n”;
    
            //Added by HEY
            print ‘<b>Postname</b>: ‘ . $postname . ‘<br />‘ . “n”;
            print ‘<b>Posted content:</b></p><hr />‘ . $content . ‘<hr />‘;
    
    
            $details = array(
                ‘post_author’        => $poster,
                ‘post_date’            => $post_date,
                ‘post_date_gmt’        => $post_date_gmt,
                ‘post_content’        => $content,
                ‘post_title’        => $subject,
                ‘post_modified’        => $post_date,
                ‘post_modified_gmt’    => $post_date_gmt,
                ‘ping_status’ => $ping_status,
                //Changed by Hey
                ‘post_name’ => $postname
            );
    
            //generate sql for insertion
    
            $sql = ‘INSERT INTO ‘.$tableposts.’ (‘. implode(‘,’,array_keys($details)) .’) VALUES (”. implode(”,”,array_map(‘addslashes’,$details)) . ”)’;
    
            $result = $wpdb->query($sql);
            $post_ID = $wpdb->insert_id;
    
            do_action(‘publish_post’, $post_ID);
            do_action(‘publish_phone’, $post_ID);
            pingback($content, $post_ID);
    
            foreach ($post_categories as $post_category)
            {
                $post_category = intval($post_category);
    
                // Double check it’s not there already
                $exists = $wpdb->get_row(“SELECT * FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $post_category”);
    
                if (!$exists && $result) {
                    $wpdb->query(”
                    INSERT INTO $tablepost2cat
                    (post_id, category_id)
                    VALUES
                    ($post_ID, $post_category)
                    “);
                }
            }
        } // end looping over messages
    
    
    /* END PROGRAM */
    
    /** FUNCTIONS **/
    
    //retrieve POP3 mail
    function pop3_retr ( )
    {
        require_once(ABSPATH.WPINC.’/class-pop3.php’);
        $pop3 = new POP3();
        if (!$pop3->connect(get_settings(‘mailserver_url’), get_settings(‘mailserver_port’))) :
            echo “Ooops $pop3->ERROR <br />n”;
            exit;
        endif;
    
        //Check to see if there is any mail, if not die
        $msg_count = $pop3->login(get_settings(‘mailserver_login’), get_settings(‘mailserver_pass’));
        if (0 == $msg_count)
        {
            $pop3->quit();
            die(__(‘There does not seem to be any new mail.’));
        }
    
        // loop through messages
        for ($i=1; $i <= $msg_count; $i++)
        {
            $emails[$i] = implode ('',$pop3->get($i));
    #if ( DELETE_MAIL_AFTER_PROCESSING && checkposter($emails[$i]) ) {
            if ( DELETE_MAIL_AFTER_PROCESSING) {
                if( !$pop3->delete($i) ) {
                    echo ‘<p>Oops ‘.$pop3->ERROR.’</p></div>‘;
                    $pop3->reset();
                    exit;
                } else {
                    echo “Mission complete, message <strong>$i</strong> deleted.”;
                }
            }
        }
        //clean up
        $pop3->quit();
        return $emails;
    }
    
    //tear apart the meta part for useful information
    function get_content ($part,&$IMAGES) {
    
        //fixes
        // Hint by Hey:
        // I think this should not be done if we have plain text and want to keep it in utf-8.
        // Leaving it anyway ’cause I don’t use utf-8 and can not test ist.
        $part = charsetcheck($part);
    
        $part = base64check($part);
        switch ( strtolower($part->ctype_primary) )
        {
            case ‘multipart’:
                $meta_return = ”;
                foreach ($part->parts as $section)
                {
                    $meta_return .= get_content($section,$IMAGES);
                }
                break;
            case ‘text’:
                // Added by Hey: Convert Quoted-Printable if needed
                $part = quotedprintablecheck($part);
    
                // Added by Hey: Convert to ISO-8859-1 if desired
                $part = isocheck($part);
    
                //go through each sub-section
                if ($part->ctype_secondary==’enriched’)
                {
                    //convert enriched text to html
                    $meta_return = etf2html($part->body ) . “n”;
                } elseif ($part->ctype_secondary==’html’) //check for html encoding
                {
                    //strip excess html
                    $meta_return = html2html($part->body ) . “n”;
                } else {
                    //regular text, so just strip the pgp signature
                    if (ALLOW_HTML_IN_BODY) {
                        $meta_return = $part->body  . “n”;
                    }
                    else {
                        $meta_return = htmlentities( $part->body ) . “n”;
                    }
                    $meta_return = strip_pgp($meta_return);
                }
                break;
    
            case ‘image’:
                $file = GenerateImageFileName(REALPHOTOSDIR, $part->ctype_secondary);
                //This makes sure there is no collision
                $ctr = 0;
                while(file_exists($file) && $ctr < 1000) {
                    $file = GenerateImageFileName(REALPHOTOSDIR, $part->ctype_secondary);
                    $ctr++;
                }
                if ($ctr >= 1000) {
                    die(“Unable to find a name for images that does not colliden”);
                }
                $fileName = basename($file);
                $fp = fopen($file, ‘w’);
                fwrite($fp, $part->body);
                fclose($fp);
                @exec (‘chmod 755 ‘ . $file);
                if (RESIZE_LARGE_IMAGES) {
                    list($thumbImage, $fullImage) = ResizeImage($file,$part->ctype_secondary);
                    if ($thumbImage) {
                        $IMAGES[] .= ‘<a href="' . URLPHOTOSDIR . $fullImage . '"><img src="' . URLPHOTOSDIR . $thumbImage . '" alt="' . $part->ctype_parameters[‘name’] . ‘” style=”‘.IMAGESTYLE.'” class=”‘.IMAGECLASS.'” /></a>‘ . “n”;
                    }
                    else {
                        $IMAGES[] .= ‘<img src="' . URLPHOTOSDIR . $fullImage . '" alt="' . $part->ctype_parameters[‘name’] . ‘”  style=”‘.IMAGESTYLE.'” class=”‘.IMAGECLASS.'” />’ . “n”;
                    }
                }
                else {
                    $IMAGES[] .= ‘<img src="' . URLPHOTOSDIR . $fileName . '" alt="' . $part->ctype_parameters[‘name’] . ‘” style=”‘.IMAGESTYLE.'” class=”‘.IMAGECLASS.'”  />’ . “n”;
                }
    
                break;
            case ‘application’:
                //pgp signature – then forget it
                if ( $part->ctype_secondary == ‘pgp-signature’ ) {break;}
                //other attachments save to FILESDIR
                $filename =  $part->ctype_parameters[‘name’];
                $file = REALFILESDIR . $filename;
                $fp = fopen($file, ‘w’);
                fwrite($fp, $part->body );
                fclose($fp);
                @exec (‘chmod 755 ‘ . $file);
                $meta_return .= ‘<a href="' . URLFILESDIR . $filename . '">‘ . $part->ctype_parameters[‘name’] . ‘</a>‘ . “n”;
                break;
        }
        return $meta_return;
    }
    
    function ubb2html($text)
    {
        // Array of tags with opening and closing
        $tagArray[‘img’] = array(‘open’=>’<img src="','close'=>‘”>’);
        $tagArray[‘b’] = array(‘open’=>’<b>‘,’close’=>’</b>‘);
        $tagArray[‘i’] = array(‘open’=>’<i>‘,’close’=>’</i>‘);
        $tagArray[‘u’] = array(‘open’=>’<u>‘,’close’=>’</u>‘);
        $tagArray[‘url’] = array(‘open’=>’<a href="','close'=>‘”>\1</a>‘);
        $tagArray[’email’] = array(‘open’=>’<a href="mailto:','close'=>‘”>\1</a>‘);
        $tagArray[‘url=(.*)’] = array(‘open’=>’<a href="','close'=>‘”>\2</a>‘);
        $tagArray[’email=(.*)’] = array(‘open’=>’<a href="mailto:','close'=>‘”>\2</a>‘);
        $tagArray[‘color=(.*)’] = array(‘open’=>’<font color="','close'=>‘”>\2</font>‘);
        $tagArray[‘size=(.*)’] = array(‘open’=>’<font size="','close'=>‘”>\2</font>‘);
        $tagArray[‘font=(.*)’] = array(‘open’=>’<font face="','close'=>‘”>\2</font>‘);
        // Array of tags with only one part
        $sTagArray[‘br’] = array(‘tag’=>’<br>‘);
        $sTagArray[‘hr’] = array(‘tag’=>’<hr>‘);
    
        foreach($tagArray as $tagName=>$replace)
        {
            $tagEnd=preg_replace(‘/W/Ui’,”,$tagName);
            $text = preg_replace(“|[$tagName](.*)[/$tagEnd]|Ui”,”$replace[open]\1$replace[close]”,$text);
        }
        foreach($sTagArray as $tagName=>$replace)
        {
            $text= preg_replace(“|[$tagName]|Ui”,”$replace[tag]”,$text);
        }
        return $text;
    }
    
    
    // This function turns Enriched Text into something similar to html
    // Very basic at the moment, only supports some functionality and dumps the rest
    // FIXME: fix colours: <color><param>FFFF,C2FE,0374</param>some text </color>
    function etf2html ( $content )
    {
    
        $search = array(
            ‘/<bold>/’,
            ‘/</bold>/’,
            ‘/<underline>/’,
            ‘/</underline>/’,
            ‘/<italic>/’,
            ‘/</italic>/’,
            ‘/<fontfamily><param>.*</param>/’,
            ‘/</fontfamily>/’,
            ‘/<x-tad-bigger>/’,
            ‘/</x-tad-bigger>/’,
            ‘/<bigger>/’,
            ‘</bigger>/’,
            ‘/<color>/’,
            ‘/</color>/’,
            ‘/<param>.+</param>/’
        );
    
        $replace = array (
            ‘<b>‘,
            ‘</b>‘,
            ‘<u>‘,
            ‘</u>‘,
            ‘<i>‘,
            ‘</i>‘,
            ”,
            ”,
            ”,
            ”,
            ”,
            ”,
            ”,
            ”,
            ”
        );
            // strip extra line breaks
            $content = preg_replace($search,$replace,$content);
            return trim($content);
    }
    
    
    // This function cleans up HTML in the e-mail
    function html2html ( $content )
    {
        $search = array(
            ‘/<html>/’,
            ‘/</html>/’,
            ‘/<title>/’,
            ‘/</title>/’,
            ‘/<body.*>/’,
            ‘/</body>/’,
            ‘/<head>/’,
            ‘/</head>/’,
            ‘/<meta content=.*>/’,
            ‘/<!DOCTYPE.*>/’,
            ‘/<img src=".*>/’
    //        ‘/<img src="cid:(.*)" .*>/’
        );
    
        $replace = array (
            ”,
            ”,
            ”,
            ”,
            ”,
            ”,
            ”,
            ”,
            ”,
            ”,
            ”,
            ”
        );
            // strip extra line breaks
            $content = preg_replace($search,$replace,trim($content));
            return ($content);
    }
    
    
    // This function tries to create a valid postname
    function subject2postname ( $content )
    {
    
    $content = strtolower($content);
    
        $search = array(
               ‘:-)’,
    
               ‘:-(‘,
               ‘:-(‘,
               ‘:-p’,
               ‘:-D’,
               ‘:-()’,
               ‘:)’,
               ‘:(‘,
               ‘:(‘,
               ‘:p’,
               ‘:D’,
               ‘:()’,
               ‘!’,
               ‘?’,
               ‘:’,
               ‘;’,
               ‘)’,
               ‘(‘
    
        );
    
        $replace = ”;
    
        // strip all those forbidden strings
        $content = str_replace($search,$replace,$content);
    
        //The above operation could have led to whitespace at the beginning and end
        $content = trim($content);
        // Perhaps we also have doubled whitespaces now?
       $content = str_replace(‘  ‘,”,$content);
    
       // Now the two most important rules:
       $content = str_replace(‘ ‘,’-‘,$content);
       $content = str_replace(‘/’,’-‘,$content);
    
    
    
            return ($content);
    }
    
    
    
    //see if sender is a valid sender from the wp database
    function checkposter ( $from )
    {
    
        global $wpdb,$tableusers,$poster;
    
            //sanity check to see if there is any info in the message
    /*        if ($from == NULL ) { print ‘Dang, message is empty!’; die; }
    
            //decode the mime
            $params[‘include_bodies’] = true;
            $params[‘decode_bodies’] = false;
            $params[‘decode_headers’] = true;
            $params[‘input’] = $email;
            $structure = Mail_mimeDecode::decode($params);
    
            $from = trim($structure->headers[‘from’]); */
            //work around for users with extra <> in email address
            if (preg_match(‘/^[^<>]+<([^<>]+)>$/’,$from,$matches))
            {
                $from = $matches[1];
            }
    
            if ( empty($from) ) { echo ‘<h1> Invalid Sender – Emtpy! </h1>‘; die;}
    
            // Added by Hey:
            // If we have defined a substitutional adress, it’s time to substitute now.
            if ($from == SECONDMAIL)
            {
                $from = WORDPRESSMAIL;
             }
    
            $sql = ‘SELECT id FROM ‘. $tableusers.’ WHERE user_email=” . addslashes($from) . ”’;
            $poster = $wpdb->get_var($sql);
            if (!$poster)
            {
                echo ‘<h1>Invalid sender: ‘ . htmlentities($from) . ” !</h1><h2>Not adding email!</h2><br />n”;
                die;
            } else {
                return $poster;
            }
    }
    
    // Keeps content until finds a line with ‘–‘ or ‘- –‘
    // This effectively removes signatures
    function removesig ( $content )
    {
        $arrcontent = explode(“n”, $content);
        $append = TRUE;
        $i = 0;
        for ($i = 0; $i<=count($arrcontent); $i++)
        {
            $line = $arrcontent[$i];
            $nextline = $arrcontent[$i+1];
            if ( preg_match('/^--$/',trim($line)) OR preg_match('/^- --$/',$line) )
            { $append = FALSE; }
            if ( $append == TRUE )
            {
        //        if ($line != NULL && $nextline == NULL )
                //{ $strcontent .= $line ."</br>n”;;
                //check if there are null lines n
                //} elseif ($line == NULL && $nextline == NULL) { $strcontent .= ‘</br>‘;
                //}else    {
                    $strcontent .= $line .”n”;
            }
        }
        return $strcontent;
    }
    
    //filter content for new lines
    function filternewlines ( $content )
    {
            $search = array (
                ‘/ (n|rn|r)/’,
                ‘/(n|rn|r)/’
            );
            $replace = array (
                ‘ ‘,
                “n”
            );
            // strip extra line breaks
            $return = preg_replace($search,$replace,$content);
            return $return;
    }
    
    //strip pgp stuff
    function strip_pgp ( $content )
    {
            $search = array (
                ‘/—–BEGIN PGP SIGNED MESSAGE—–/’,
                ‘/Hash: SHA1/’
            );
            $replace = array (
                ‘ ‘,
                ”
            );
            // strip extra line breaks
            $return = preg_replace($search,$replace,$content);
            return $return;
    }
    
    // Added by Hey
    // This function converts to ISO-8859-1 if desired by the user.
    
    // Hint: It should only be applied to type=”text/*” Other types are already converted
    // by the initial charsetcheck()-call and will be broken if converted twice.
    
    // Hint: Do conversion only if text was encoded in Base64 or Quoted-Printable.
    // -> Plain texts are coverted by the initial charsetcheck().
    // This could be a bug for utf-8 users but it doesn’t bother me because I want ISO anyway :-)
    
    function isocheck ( $part )
    {
    $charset = $part->ctype_parameters[‘charset’];
       if( (ISO_8859_1 == true) && ($charset != ‘iso-8859-1’))
       {
       $transenc = strtolower( $part->headers[‘content-transfer-encoding’] );
    
          if( $transenc == ‘base64’ || $transenc == ‘quoted-printable’ )
          {
             $part->body = utf8_decode($part->body);
          }
       }
    
    return $part;
    }
    
    // This function checks if the content is base64
    function base64check ( $part )
    {
    //    if ($part->headers[‘content-transfer-encoding’] != ‘base64’)
    //    {
            if ( strtolower($part->headers[‘content-transfer-encoding’]) == ‘base64’ )
            {
                $part->body = base64_decode($part->body);
            }
    //    }
        return $part;
    }
    
    function quotedprintablecheck ( $part )
    {
    // Added by HEY: Doing the same as Above for Quoted Pritable
       if ( strtolower($part->headers[‘content-transfer-encoding’]) == ‘quoted-printable’ )
            {
                $part->body = quoted_printable_decode($part->body);
            }
    
        return $part;
    }
    
    function charsetcheck ( $part )
    {
        if ( strtolower($part->ctype_parameters[‘charset’] == ‘utf-8’) )
        {
            $part->body = utf8_decode($part->body);
        }
        return $part;
    }
    
    function GenerateImageFileName($dir,$type) {
        static $ctr;
        $ctr++;
        return($dir . date(“Ymd-His-“,time()) . $ctr . “.” . $type);
    }
    function ConfirmTrailingSlash($string) {
        if (substr($string,strlen($string) – 1,1) == “/”) {
            return(true);
        }
        return(false);
    }
    function HasGDInstalled() {
        $function_list = array(“getimagesize”,
                               “imagecreatefromjpeg”,
                               “imagecreatefromgif”,
                               “imagecreatefrompng”,
                               “imagecreatetruecolor”,
                               “imagecreatetruecolor”,
                               “imagecopyresized”,
                               “imagejpeg”,
                               “imagedestroy”);
        foreach ($function_list as $function) {
            if (!function_exists($function)) {
                print(“<p>Missing $function”);
                return(false);
            }
        }
        return(true);
    }
    function ResizeImage($file,$type) {
        $sizeInfo = getimagesize($file);
        $fileName = basename($file);
        $scaledFileName = “”;
        if ($sizeInfo[0] > MAX_IMAGE_WIDTH) {
            $sourceImage = NULL;
            switch($type) {
                case “jpeg”:
                    $sourceImage = imagecreatefromjpeg($file);
                    break;
                case “gif”:
                    $sourceImage = imagecreatefromgif($file);
                    break;
                case “png”:
                    $sourceImage = imagecreatefrompng($file);
                    break;
            }
            if ($sourceImage) {
                $scale = MAX_IMAGE_WIDTH/$sizeInfo[0];
                $scaledH = round($sizeInfo[1] * $scale );
                $scaledW = round($sizeInfo[0] * $scale );
                $scaledFileName =  “thumb.”.$fileName;
                $scaledFile = REALPHOTOSDIR . $scaledFileName;
                $scaledImage = imagecreatetruecolor($scaledW,$scaledH);
                imagecopyresized($scaledImage,$sourceImage,0,0,0,0,
                                $scaledW,$scaledH,
                                $sizeInfo[0],$sizeInfo[1]);
                imagejpeg($scaledImage,$scaledFile,JPEGQUALITY);
                @exec (‘chmod 755 ‘ . $scaledFile);
                imagedestroy($scaledImage);
                imagedestroy($sourceImage);
            }
        }
        return(array($scaledFileName,$fileName));
    
    }
    function DeterminePostDate($content,$ddate) {
        $delay = 0;
        if (eregi(“delay:(.[^ ]*)”,$content,$matches)
            && trim($matches[1])) {
            if (eregi(“([0-9]+)d”,$matches[1],$dayMatches)) {
                $days = $dayMatches[1];
            }
            if (eregi(“([0-9]+)h”,$matches[1],$hourMatches)) {
                $hours = $hourMatches[1];
            }
            if (eregi(“([0-9]+)m”,$matches[1],$minuteMatches)) {
                $minutes = $minuteMatches[1];
            }
            $delay = (($days * 24 + $hours) * 60 + $minutes) * 60;
            $content = ereg_replace(“delay:$matches[1]”,””,$content);
        }
        if (function_exists(“strtotime”)) {
            $post_date = date(‘Y-m-d H:i:s’, strtotime($ddate) + (TIME_OFFSET * 3600) + $delay);
            $post_date_gmt = gmdate(‘Y-m-d H:i:s’, strtotime($ddate) + $delay );
        }
        else {
            $post_date = date(‘Y-m-d H:i:s’, time() + (TIME_OFFSET * 3600) + $delay);
            $post_date_gmt = gmdate(‘Y-m-d H:i:s’, time() + $delay );
        }
        return(array($post_date,$post_date_gmt));
    }
    // end of script
    ?>

    #578753
    AmO
    Participant
    Maître WordPress
    4452 contributions

    Ca permet quoi concrètement ?

    (correction de la mise en page de ton post, utilise les balises code)

    #578754
    bisou
    Participant
    Initié WordPress
    11 contributions

    Poster depuis son portable, quand on et loin de son pc.

    Je rédige bientôt un tuto pour les explications.

    #578755
    AmO
    Participant
    Maître WordPress
    4452 contributions

    Oki

4 sujets de 1 à 4 (sur un total de 4)
  • Vous devez être connecté pour répondre à ce sujet.