예제 #1
0
function GetContent($part, &$attachments, $post_id, $poster, $config)
{
    extract($config);
    global $charset, $encoding;
    /*
    if (!function_exists(imap_mime_header_decode))
      echo "you need to install the php-imap extension for full functionality, including mime header decoding\n";
    */
    $meta_return = NULL;
    echo "primary= " . $part->ctype_primary . ", secondary = " . $part->ctype_secondary . "\n";
    DecodeBase64Part($part);
    if (BannedFileName($part->ctype_parameters['name'], $banned_files_list)) {
        return NULL;
    }
    if ($part->ctype_primary == "application" && $part->ctype_secondary == "octet-stream") {
        if ($part->disposition == "attachment") {
            $image_endings = array("jpg", "png", "gif", "jpeg", "pjpeg");
            foreach ($image_endings as $type) {
                if (eregi(".{$type}\$", $part->d_parameters["filename"])) {
                    $part->ctype_primary = "image";
                    $part->ctype_secondary = $type;
                    break;
                }
            }
        } else {
            $mimeDecodedEmail = DecodeMIMEMail($part->body);
            FilterTextParts($mimeDecodedEmail, $prefer_text_type);
            foreach ($mimeDecodedEmail->parts as $section) {
                $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
            }
        }
    }
    if ($part->ctype_primary == "multipart" && $part->ctype_secondary == "appledouble") {
        $mimeDecodedEmail = DecodeMIMEMail("Content-Type: multipart/mixed; boundary=" . $part->ctype_parameters["boundary"] . "\n" . $part->body);
        FilterTextParts($mimeDecodedEmail, $prefer_text_type);
        FilterAppleFile($mimeDecodedEmail);
        foreach ($mimeDecodedEmail->parts as $section) {
            $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
        }
    } else {
        // fix filename (remove non-standard characters)
        $filename = preg_replace("/[^\t\n\r -]/", "", $part->ctype_parameters['name']);
        switch (strtolower($part->ctype_primary)) {
            case 'multipart':
                FilterTextParts($part, $prefer_text_type);
                foreach ($part->parts as $section) {
                    $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
                }
                break;
            case 'text':
                $tmpcharset = trim($part->ctype_parameters['charset']);
                if ($tmpcharset != '') {
                    $charset = $tmpcharset;
                }
                $tmpencoding = trim($part->headers['content-transfer-encoding']);
                if ($tmpencoding != '') {
                    $encoding = $tmpencoding;
                }
                $part->body = HandleMessageEncoding($part->headers["content-transfer-encoding"], $part->ctype_parameters["charset"], $part->body, $message_encoding, $message_dequote);
                //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') {
                    //strip excess HTML
                    //$meta_return .= HTML2HTML($part->body ) . "\n";
                    $meta_return .= $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 = StripPGP($meta_return);
                }
                break;
            case 'image':
                $file_id = postie_media_handle_upload($part, $post_id, $poster);
                $file = wp_get_attachment_url($file_id);
                $cid = trim($part->headers["content-id"], "<>");
                //cids are in <cid>
                $the_post = get_post($file_id);
                $attachments["html"][$filename] = parseTemplate($file_id, $part->ctype_primary, $imagetemplate);
                if ($cid) {
                    $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1);
                }
                break;
            case 'audio':
                $file_id = postie_media_handle_upload($part, $post_id, $poster);
                $file = wp_get_attachment_url($file_id);
                $cid = trim($part->headers["content-id"], "<>");
                //cids are in <cid>
                if (in_array($part->ctype_secondary, $audiotypes)) {
                    $audioTemplate = $audiotemplate;
                } else {
                    $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $icon_set, $icon_size);
                    $audioTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
                }
                $attachments["html"][$filename] = parseTemplate($file_id, $part->ctype_primary, $audioTemplate);
                break;
            case 'video':
                $file_id = postie_media_handle_upload($part, $post_id, $poster);
                $file = wp_get_attachment_url($file_id);
                $cid = trim($part->headers["content-id"], "<>");
                //cids are in <cid>
                if (in_array(strtolower($part->ctype_secondary), $video1types)) {
                    $videoTemplate = $video1template;
                } elseif (in_array(strtolower($part->ctype_secondary), $video2types)) {
                    $videoTemplate = $video2template;
                } else {
                    $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $icon_set, $icon_size);
                    $videoTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
                }
                $attachments["html"][$filename] = parseTemplate($file_id, $part->ctype_primary, $videoTemplate);
                //echo "videoTemplate = $videoTemplate\n";
                break;
            default:
                if (in_array(strtolower($part->ctype_primary), $supported_file_types)) {
                    //pgp signature - then forget it
                    if ($part->ctype_secondary == 'pgp-signature') {
                        break;
                    }
                    $file_id = postie_media_handle_upload($part, $post_id, $poster);
                    $file = wp_get_attachment_url($file_id);
                    $cid = trim($part->headers["content-id"], "<>");
                    //cids are in <cid>
                    $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $icon_set, $icon_size);
                    $attachments["html"][$filename] = "<a href='{$file}'>" . $icon . $filename . '</a>' . "\n";
                    if ($cid) {
                        $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1);
                    }
                }
                break;
        }
    }
    return $meta_return;
}
예제 #2
0
function GetContent($part, &$attachments, $post_id, $config)
{
    global $charset, $encoding;
    /*
    if (!function_exists(imap_mime_header_decode))
      echo "you need to install the php-imap extension for full functionality, including mime header decoding\n";
    */
    $meta_return = NULL;
    echo "primary= " . $part->ctype_primary . ", secondary = " . $part->ctype_secondary . "\n";
    DecodeBase64Part($part);
    if (BannedFileName($part->ctype_parameters['name'], $config['BANNED_FILES_LIST'])) {
        return NULL;
    }
    if ($part->ctype_primary == "application" && $part->ctype_secondary == "octet-stream") {
        if ($part->disposition == "attachment") {
            $image_endings = array("jpg", "png", "gif", "jpeg", "pjpeg");
            foreach ($image_endings as $type) {
                if (eregi(".{$type}\$", $part->d_parameters["filename"])) {
                    $part->ctype_primary = "image";
                    $part->ctype_secondary = $type;
                    break;
                }
            }
        } else {
            $mimeDecodedEmail = DecodeMIMEMail($part->body);
            FilterTextParts($mimeDecodedEmail, $config['PREFER_TEXT_TYPE']);
            foreach ($mimeDecodedEmail->parts as $section) {
                $meta_return .= GetContent($section, $attachments, $post_id, $config);
            }
        }
    }
    if ($part->ctype_primary == "multipart" && $part->ctype_secondary == "appledouble") {
        $mimeDecodedEmail = DecodeMIMEMail("Content-Type: multipart/mixed; boundary=" . $part->ctype_parameters["boundary"] . "\n" . $part->body);
        FilterTextParts($mimeDecodedEmail, $config['PREFER_TEXT_TYPE']);
        FilterAppleFile($mimeDecodedEmail);
        foreach ($mimeDecodedEmail->parts as $section) {
            $meta_return .= GetContent($section, $attachments, $post_id, $config);
        }
    } else {
        switch (strtolower($part->ctype_primary)) {
            case 'multipart':
                FilterTextParts($part, $config['PREFER_TEXT_TYPE']);
                foreach ($part->parts as $section) {
                    $meta_return .= GetContent($section, $attachments, $post_id, $config);
                }
                break;
            case 'text':
                $tmpcharset = trim($part->ctype_parameters['charset']);
                if ($tmpcharset != '') {
                    $charset = $tmpcharset;
                }
                $tmpencoding = trim($part->headers['content-transfer-encoding']);
                if ($tmpencoding != '') {
                    $encoding = $tmpencoding;
                }
                $part->body = HandleMessageEncoding($part->headers["content-transfer-encoding"], $part->ctype_parameters["charset"], $part->body, $config['MESSAGE_ENCODING'], $config['MESSAGE_DEQUOTE']);
                //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') {
                    //strip excess HTML
                    //$meta_return .= HTML2HTML($part->body ) . "\n";
                    $meta_return .= $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 = StripPGP($meta_return);
                }
                break;
            case 'image':
                echo "looking at an image\n";
                $file_id = postie_media_handle_upload($part, $post_id);
                $file = wp_get_attachment_url($file_id);
                $cid = trim($part->headers["content-id"], "<>");
                //cids are in <cid>
                $the_post = get_post($file_id);
                /* TODO make these options */
                $attachments["html"][] = parseTemplate($file_id, $part->ctype_primary, $config['IMAGETEMPLATE']);
                if ($cid) {
                    $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1);
                }
                break;
            case 'audio':
                $file_id = postie_media_handle_upload($part, $post_id);
                $file = wp_get_attachment_url($file_id);
                $cid = trim($part->headers["content-id"], "<>");
                //cids are in <cid>
                if (in_array($part->ctype_secondary, $config['AUDIOTYPES'])) {
                    $audioTemplate = $config['AUDIOTEMPLATE'];
                } else {
                    $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $config['ICON_SET'], $config['ICON_SIZE']);
                    $audioTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
                }
                $attachments["html"][] = parseTemplate($file_id, $part->ctype_primary, $audioTemplate);
                break;
            case 'video':
                $file_id = postie_media_handle_upload($part, $post_id);
                $file = wp_get_attachment_url($file_id);
                $cid = trim($part->headers["content-id"], "<>");
                //cids are in <cid>
                if (in_array($part->ctype_secondary, $config['VIDEO1TYPES'])) {
                    $videoTemplate = $config['VIDEO1TEMPLATE'];
                } else {
                    if (in_array($part->ctype_secondary, $config['VIDEO2TYPES'])) {
                        $videoTemplate = $config['VIDEO2TEMPLATE'];
                    } else {
                        $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $config['ICON_SET'], $config['ICON_SIZE']);
                        $videoTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
                    }
                }
                $attachments["html"][] = parseTemplate($file_id, $part->ctype_primary, $videoTemplate);
                break;
            default:
                if (in_array(strtolower($part->ctype_primary), $config["SUPPORTED_FILE_TYPES"])) {
                    //pgp signature - then forget it
                    if ($part->ctype_secondary == 'pgp-signature') {
                        break;
                    }
                    $file_id = postie_media_handle_upload($part, $post_id);
                    $file = wp_get_attachment_url($file_id);
                    echo "file={$file}\n";
                    $cid = trim($part->headers["content-id"], "<>");
                    //cids are in <cid>
                    $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $config['ICON_SET'], $config['ICON_SIZE']);
                    $attachments["html"][] = '<a href="' . $file . '" style="text-decoration:none">' . $icon . $part->ctype_parameters['name'] . '</a>' . "\n";
                    if ($cid) {
                        $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1);
                    }
                }
                break;
        }
    }
    return $meta_return;
}
예제 #3
0
function GetContent($part, &$attachments)
{
    $config = GetConfig();
    $meta_return = NULL;
    DecodeBase64Part($part);
    if (BannedFileName($part->ctype_parameters['name']) || BannedFileName($part->ctype_parameters['name'])) {
        return NULL;
    }
    if ($part->ctype_primary == "application" && $part->ctype_secondary == "octet-stream") {
        if ($part->disposition == "attachment") {
            $image_endings = array("jpg", "png", "gif", "jpeg", "pjpeg");
            foreach ($image_endings as $type) {
                if (eregi(".{$type}\$", $part->d_parameters["filename"])) {
                    $part->ctype_primary = "image";
                    $part->ctype_secondary = $type;
                    break;
                }
            }
        } else {
            $mimeDecodedEmail = DecodeMIMEMail($part->body);
            FilterTextParts($mimeDecodedEmail);
            foreach ($mimeDecodedEmail->parts as $section) {
                $meta_return .= GetContent($section, $attachments);
            }
        }
    }
    if ($part->ctype_primary == "multipart" && $part->ctype_secondary == "appledouble") {
        $mimeDecodedEmail = DecodeMIMEMail("Content-Type: multipart/mixed; boundary=" . $part->ctype_parameters["boundary"] . "\n" . $part->body);
        FilterTextParts($mimeDecodedEmail);
        FilterAppleFile($mimeDecodedEmail);
        foreach ($mimeDecodedEmail->parts as $section) {
            $meta_return .= GetContent($section, $attachments);
        }
    } else {
        switch (strtolower($part->ctype_primary)) {
            case 'multipart':
                FilterTextParts($part);
                foreach ($part->parts as $section) {
                    $meta_return .= GetContent($section, $attachments);
                }
                break;
            case 'text':
                HandleMessageEncoding($part->headers["content-transfer-encoding"], $part->ctype_parameters["charset"], $part->body);
                //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') {
                    //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 = StripPGP($meta_return);
                }
                break;
            case 'image':
                $file = GenerateImageFileName($config["REALPHOTOSDIR"], $part->ctype_secondary);
                //This makes sure there is no collision
                $ctr = 0;
                while (file_exists($file) && $ctr < 1000) {
                    $file = GenerateImageFileName($config["REALPHOTOSDIR"], $part->ctype_secondary);
                    $ctr++;
                }
                if ($ctr >= 1000) {
                    die("Unable to find a name for images that does not collide\n");
                }
                $fileName = basename($file);
                $fp = fopen($file, 'w');
                fwrite($fp, $part->body);
                fclose($fp);
                @exec('chmod 755 ' . $file);
                if ($config["USE_IMAGEMAGICK"] && $config["AUTO_SMART_SHARP"]) {
                    ImageMagickSharpen($file);
                }
                $mimeTag = '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' -->';
                $thumbImage = NULL;
                $cid = trim($part->headers["content-id"], "<>");
                //cids are in <cid>
                if ($config["RESIZE_LARGE_IMAGES"]) {
                    list($thumbImage, $fullImage) = ResizeImage($file, strtolower($part->ctype_secondary));
                }
                $attachments["image_files"][] = array($thumbImage ? $config["REALPHOTOSDIR"] . $thumbImage : NULL, $config["REALPHOTOSDIR"] . $fileName, $part->ctype_secondary);
                if ($thumbImage) {
                    $marime = DetermineImageSize($file);
                    $marimex = $marime[0] + 20;
                    $marimey = $marime[1] + 20;
                    $attachments["html"][] .= $mimeTag . '<div class="' . $config["IMAGEDIV"] . '"><a href="' . $config["URLPHOTOSDIR"] . $fullImage . '" onclick="window.open(' . "'" . $config["URLPHOTOSDIR"] . $fullImage . "','" . "full_size_image" . "','" . "toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=1,height=" . $marimey . ",width=" . $marimex . "');" . "return false;" . '"><img src="' . $config["URLPHOTOSDIR"] . $thumbImage . '" alt="' . $part->ctype_parameters['name'] . '" title="' . $part->ctype_parameters['name'] . '" style="' . $config["IMAGESTYLE"] . '" class="' . $config["IMAGECLASS"] . '" /></a></div>' . "\n";
                    if ($cid) {
                        $attachments["cids"][$cid] = array($config["URLPHOTOSDIR"] . $fullImage, count($attachments["html"]) - 1);
                    }
                } else {
                    $attachments["html"][] .= $mimeTag . '<div class="' . $config["IMAGEDIV"] . '"><img src="' . $config["URLPHOTOSDIR"] . $fileName . '" alt="' . $part->ctype_parameters['name'] . '" style="' . $config["IMAGESTYLE"] . '" class="' . $config["IMAGECLASS"] . '"  /></div>' . "\n";
                    if ($cid) {
                        $attachments["cids"][$cid] = array($config["URLPHOTOSDIR"] . $fileName, count($attachments["html"]) - 1);
                    }
                }
                break;
            default:
                if (in_array(strtolower($part->ctype_primary), $config["SUPPORTED_FILE_TYPES"])) {
                    //pgp signature - then forget it
                    if ($part->ctype_secondary == 'pgp-signature') {
                        break;
                    }
                    //other attachments save to FILESDIR
                    $filename = $part->ctype_parameters['name'];
                    $file = $config["REALFILESDIR"] . $filename;
                    $fp = fopen($file, 'w');
                    fwrite($fp, $part->body);
                    fclose($fp);
                    @exec('chmod 755 ' . $file);
                    $cid = trim($part->headers["content-id"], "<>");
                    //cids are in <cid>
                    if ($part->ctype_secondary == "3gpp" || $part->ctype_secondary == "3gp" || $part->ctype_secondary == "3g2" || $part->ctype_secondary == "3gpp2") {
                        if ($config["3GP_QT"]) {
                            //Shamelessly borrowed from http://www.postneo.com/2003/12/19/embedding-3gpp-in-html
                            $attachments["html"][] = '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' -->' . '<a href="' . $config["URLFILESDIR"] . $filename . '">Video' . '<object ' . 'classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ' . 'codebase="http://www.apple.com/qtactivex/qtplugin.cab" ' . 'width="128" ' . 'height="112"> ' . '<param name="src" VALUE="' . $config["URLFILESDIR"] . $filename . '"> ' . '<param name="autoplay" VALUE="false"> ' . '<param name="controller" VALUE="true"> ' . '<embed ' . 'src="' . $config["URLFILESDIR"] . $filename . '" ' . 'width="128" ' . 'height="112" ' . 'autoplay="true" ' . 'controller="true" ' . 'type="video/quicktime" ' . 'pluginspage="http://www.apple.com/quicktime/download/" ' . 'width="128" ' . 'height="150"></embed> ' . '</object></a>';
                        } else {
                            if (file_exists($config["3GP_FFMPEG"])) {
                                $fileName = basename($file);
                                //options from http://www.getid3.org/phpBB2/viewtopic.php?p=1290&
                                $scaledFileName = "thumb." . $fileName;
                                $scaledFile = $config["REALPHOTOSDIR"] . $scaledFileName;
                                @exec(escapeshellcmd($config["3GP_FFMPEG"]) . " -i " . escapeshellarg($file) . " -y -ss 00:00:01 -vframes 1 -an -sameq -f gif " . escapeshellarg($scaledFile));
                                @exec('chmod 755 ' . escapeshellarg($scaledFile));
                                $attachments["html"][] .= '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' --><div class="' . $config["3GPDIV"] . '"><a href="' . $config["URLPHOTOSDIR"] . $fileName . '"><img src="' . $config["URLPHOTOSDIR"] . $scaledFileName . '" alt="' . $part->ctype_parameters['name'] . '" style="' . $config["IMAGESTYLE"] . '" class="' . $config["IMAGECLASS"] . '" /></a></div>' . "\n";
                            } else {
                                $attachments["html"][] = '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' --><div class="' . $config["ATTACHMENTDIV"] . '"><a href="' . $config["URLFILESDIR"] . $filename . '" class="' . $config["3GPCLASS"] . '">' . $part->ctype_parameters['name'] . '</a></div>' . "\n";
                            }
                        }
                    } elseif ($part->ctype_secondary == "x-shockwave-flash") {
                        $attachments["html"][] = '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' -->' . '<object ' . 'classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"  ' . 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ' . 'width=""  ' . 'height=""> ' . '<param name="movie" value="' . $config["URLFILESDIR"] . $filename . '"> ' . '<param name="quality" value="high"> ' . '<embed  ' . 'src="' . $config["URLFILESDIR"] . $filename . '"  ' . 'width=""  ' . 'height=""  ' . 'quality="high"  ' . 'pluginspage="http://www.macromedia.com/go/getflashplayer"  ' . 'type="application/x-shockwave-flash"  ' . 'width=""  ' . 'height=""></embed> ' . '</object>';
                    } else {
                        $attachments["html"][] = '<!--Mime Type of File is ' . $part->ctype_primary . "/" . $part->ctype_secondary . ' --><a href="' . $config["URLFILESDIR"] . $filename . '">' . $part->ctype_parameters['name'] . '</a>' . "\n";
                    }
                    if ($cid) {
                        $attachments["cids"][$cid] = array($config["URLFILESDIR"] . $filename, count($attachments["html"]) - 1);
                    }
                }
                break;
        }
    }
    return $meta_return;
}