/** * Display the list of images in our database * * @access public * @param int The current page number * @param string The HTML linebreak to use after a row of images * @param boolean Should the toolbar for editing media files be shown? * @param string The URL to use for pagination * @param boolean Show the "upload media item" feature? * @param boolean Restrict viewing images to a specific directory * @param boolean If TRUE, will echo Smarty output. * @return string Smarty block name */ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = false, $url = NULL, $show_upload = false, $limit_path = NULL, $smarty_display = true) { global $serendipity; static $debug = false; $sortParams = array('perpage', 'order', 'ordermode'); $importParams = array('adminModule', 'htmltarget', 'filename_only', 'textarea', 'subpage', 'keywords'); $extraParems = ''; $filterParams = array('only_path', 'only_filename'); foreach ($importParams as $importParam) { if (isset($serendipity['GET'][$importParam])) { $extraParems .= 'serendipity[' . $importParam . ']=' . $serendipity['GET'][$importParam] . '&'; } } foreach ($sortParams as $sortParam) { serendipity_restoreVar($serendipity['COOKIE']['sortorder_' . $sortParam], $serendipity['GET']['sortorder'][$sortParam]); serendipity_JSsetCookie('sortorder_' . $sortParam, $serendipity['GET']['sortorder'][$sortParam]); $extraParems .= 'serendipity[sortorder][' . $sortParam . ']=' . $serendipity['GET']['sortorder'][$sortParam] . '&'; } foreach ($filterParams as $filterParam) { serendipity_restoreVar($serendipity['COOKIE'][$filterParam], $serendipity['GET'][$filterParam]); serendipity_JSsetCookie($filterParam, $serendipity['GET'][$filterParam]); if (!empty($serendipity['GET'][$filterParam])) { $extraParems .= 'serendipity[' . $filterParam . ']=' . $serendipity['GET'][$filterParam] . '&'; } } $serendipity['GET']['only_path'] = serendipity_uploadSecure($limit_path . $serendipity['GET']['only_path'], true); $serendipity['GET']['only_filename'] = str_replace(array('*', '?'), array('%', '_'), $serendipity['GET']['only_filename']); $perPage = !empty($serendipity['GET']['sortorder']['perpage']) ? $serendipity['GET']['sortorder']['perpage'] : 8; while ($perPage % $lineBreak !== 0) { $perPage++; } $start = ($page - 1) * $perPage; if ($manage && $limit_path == NULL) { ## SYNCH START ## $aExclude = array("CVS" => true, ".svn" => true); serendipity_plugin_api::hook_event('backend_media_path_exclude_directories', $aExclude); $paths = array(); $aFilesOnDisk = array(); $aResultSet = serendipity_traversePath($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $limit_path, '', false, NULL, 1, NULL, FALSE, $aExclude); foreach ($aResultSet as $sKey => $sFile) { if ($sFile['directory']) { if ($debug) { echo "{$sFile['relpath']} is a directory.<br />"; } array_push($paths, $sFile); } else { if ($debug) { echo "{$sFile['relpath']} is a file.<br />"; } // Store the file in our array, remove any ending slashes $aFilesOnDisk[$sFile['relpath']] = 1; } unset($aResultSet[$sKey]); } usort($paths, 'serendipity_sortPath'); if ($debug) { echo "<p>Got files: <pre>" . print_r($aFilesOnDisk, true) . "</pre></p>"; } $serendipity['current_image_hash'] = md5(serialize($aFilesOnDisk)); $nTimeStart = microtime_float(); // MTG 21/01/06: request all images from the database, delete any which don't exist // on the filesystem, and mark off files from the file list which are already // in the database $nCount = 0; if ($debug) { echo "<p>Image Sync Right: " . serendipity_checkPermission('adminImagesSync') . " Onthefly Sync: " . $serendipity['onTheFlySynch'] . " Hash: " . $serendipity['current_image_hash'] . "!=" . $serendipity['last_image_hash'] . "</p>"; } if ($serendipity['onTheFlySynch'] && serendipity_checkPermission('adminImagesSync') && ($debug || $serendipity['current_image_hash'] != $serendipity['last_image_hash'])) { $aResultSet = serendipity_db_query("SELECT path, name, extension, thumbnail_name, id\n FROM {$serendipity['dbPrefix']}images", false, 'assoc'); if ($debug) { echo "<p>Got images: <pre>" . print_r($aResultSet, true) . "</pre></p>"; } if (is_array($aResultSet)) { foreach ($aResultSet as $sKey => $sFile) { serendipity_plugin_api::hook_event('backend_thumbnail_filename_select', $sFile); $sThumbNailFile = ''; if (isset($sFile['thumbnail_filename'])) { $sThumbNailFile = $sFile['thumbnail_filename']; } else { $sThumbNailFile = $sFile['path'] . $sFile['name'] . '.' . $sFile['thumbnail_name'] . '.' . $sFile['extension']; } $sFileName = $sFile['path'] . $sFile['name'] . '.' . $sFile['extension']; if ($debug) { echo "<p>File name is {$sFileName},<br />thumbnail is {$sThumbNailFile}</p>"; } unset($aResultSet[$sKey]); if (isset($aFilesOnDisk[$sFileName])) { unset($aFilesOnDisk[$sFileName]); } else { if ($debug) { echo "Deleting Image {$sFile['id']}<br />\n"; } serendipity_deleteImage($sFile['id']); ++$nCount; } unset($aFilesOnDisk[$sThumbNailFile]); } } if ($nCount > 0) { if ($debug) { echo "<p>Cleaned up " . $nCount . " database entries</p>"; } } serendipity_set_config_var('last_image_hash', $serendipity['current_image_hash'], 0); $aUnmatchedOnDisk = array_keys($aFilesOnDisk); if ($debug) { echo "<p>Got unmatched files: <pre>" . print_r($aUnmatchedOnDisk, true) . "</pre></p>"; } $nCount = 0; foreach ($aUnmatchedOnDisk as $sFile) { if (preg_match('@\\.' . $serendipity['thumbSuffix'] . '\\.@', $sFile)) { if ($debug) { echo "<p>Skipping thumbnailed file {$sFile}</p>"; } continue; } else { if ($debug) { echo "<p>Checking {$sFile}</p>"; } } // MTG: 21/01/06: put files which have just 'turned up' into the database $aImageData = serendipity_getImageData($sFile); if (serendipity_isImage($aImageData, false, '(image)|(video)|(audio)/')) { $nPos = strrpos($sFile, "/"); if (is_bool($nPos) && !$nPos) { $sFileName = $sFile; $sDirectory = ""; } else { ++$nPos; $sFileName = substr($sFile, $nPos); $sDirectory = substr($sFile, 0, $nPos); } if ($debug) { echo "<p>Inserting image {$sFileName} from {$sDirectory} <pre>" . print_r($aImageData, true) . "</pre> into database</p>"; } # TODO: Check if the thumbnail generation goes fine with Marty's code serendipity_makeThumbnail($sFileName, $sDirectory); serendipity_insertImageInDatabase($sFileName, $sDirectory); ++$nCount; } } if ($nCount > 0) { if ($debug) { echo "<p>Inserted " . $nCount . " images into the database</p>"; } } } else { if ($debug) { echo "<p>Media Gallery database is up to date</p>"; } } /* $nTimeEnd = microtime_float ( ); $nDifference = $nTimeEnd - $nTimeStart; echo "<p> total time taken was " . $nDifference . "</p>"; */ ## SYNCH FINISHED ## } ## Aply ACL afterwards: serendipity_directoryACL($paths, 'read'); $serendipity['imageList'] = serendipity_fetchImagesFromDatabase($start, $perPage, $totalImages, isset($serendipity['GET']['sortorder']['order']) ? $serendipity['GET']['sortorder']['order'] : false, isset($serendipity['GET']['sortorder']['ordermode']) ? $serendipity['GET']['sortorder']['ordermode'] : false, isset($serendipity['GET']['only_path']) ? $serendipity['GET']['only_path'] : '', isset($serendipity['GET']['only_filename']) ? $serendipity['GET']['only_filename'] : '', isset($serendipity['GET']['keywords']) ? $serendipity['GET']['keywords'] : '', isset($serendipity['GET']['filter']) ? $serendipity['GET']['filter'] : ''); $pages = ceil($totalImages / $perPage); $linkPrevious = '?' . $extraParems . 'serendipity[page]=' . ($page - 1); $linkNext = '?' . $extraParems . 'serendipity[page]=' . ($page + 1); if (is_null($lineBreak)) { $lineBreak = floor(750 / ($serendipity['thumbSize'] + 20)); } $dprops = $keywords = array(); if ($serendipity['parseMediaOverview']) { $ids = array(); foreach ($serendipity['imageList'] as $k => $file) { $ids[] = $file['id']; } $allprops =& serendipity_fetchMediaProperties($ids); } if (count($serendipity['imageList']) > 0) { foreach ($serendipity['imageList'] as $k => $file) { if (!($serendipity['authorid'] == $file['authorid'] || $file['authorid'] == '0' || serendipity_checkPermission('adminImagesViewOthers'))) { // This is a fail-safe continue. Basically a non-matching file should already be filtered in SQL. continue; } serendipity_prepareMedia($serendipity['imageList'][$k], $url); if ($serendipity['parseMediaOverview']) { $serendipity['imageList'][$k]['props'] =& $allprops[$file['id']]; if (!is_array($serendipity['imageList'][$k]['props']['base_metadata'])) { $serendipity['imageList'][$k]['metadata'] =& serendipity_getMetaData($serendipity['imageList'][$k]['realfile'], $serendipity['imageList'][$k]['header']); } else { $serendipity['imageList'][$k]['metadata'] = $serendipity['imageList'][$k]['props']['base_metadata']; serendipity_plugin_api::hook_event('media_getproperties_cached', $serendipity['imageList'][$k]['metadata'], $serendipity['imageList'][$k]['realfile']); } serendipity_parseMediaProperties($dprops, $keywords, $serendipity['imageList'][$k], $serendipity['imageList'][$k]['props'], 3, false); } } } $smarty_vars = array('limit_path' => $limit_path, 'perPage' => $perPage, 'show_upload' => $show_upload, 'page' => $page, 'pages' => $pages, 'linkNext' => $linkNext, 'linkPrevious' => $linkPrevious, 'extraParems' => $extraParems); return serendipity_showMedia($serendipity['imageList'], $paths, $url, $manage, $lineBreak, true, $smarty_vars, $smarty_display); }
} // Accept file if (is_uploaded_file($uploadtmp) && serendipity_checkMediaSize($uploadtmp) && move_uploaded_file($uploadtmp, $target)) { $messages[] = sprintf('<span class="msg_success"><span class="icon-ok-circled"></span> ' . FILE_UPLOADED . '</span>', $uploadfile, $target); @umask(00); @chmod($target, 0664); $thumbs = array(array('thumbSize' => $serendipity['thumbSize'], 'thumb' => $serendipity['thumbSuffix'])); serendipity_plugin_api::hook_event('backend_media_makethumb', $thumbs); foreach ($thumbs as $thumb) { // Create thumbnail if ($created_thumbnail = serendipity_makeThumbnail($tfile, $serendipity['POST']['target_directory'][$idx], $thumb['thumbSize'], $thumb['thumb'])) { $messages[] = '<span class="msg_success"><span class="icon-ok-circled"></span> ' . THUMB_CREATED_DONE . '</span>'; } } // Insert into database $image_id = serendipity_insertImageInDatabase($tfile, $serendipity['POST']['target_directory'][$idx], $authorid, null, $realname); serendipity_plugin_api::hook_event('backend_image_add', $target, $created_thumbnail); $new_media[] = array('image_id' => $image_id, 'target' => $target, 'created_thumbnail' => $created_thumbnail); } else { // necessary for the ajax-uplaoder to show upload errors header("Internal Server Error", true, 500); $messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . ERROR_UNKNOWN_NOUPLOAD . '</span>'; } } } } if (isset($_REQUEST['go_properties'])) { echo serendipity_showPropertyForm($new_media); } else { $hidden = array('author' => $serendipity['serendipityUser'], 'authorid' => $serendipity['authorid']); foreach ($new_media as $nm) {
function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks =& $bag->get('event_hooks'); if (isset($hooks[$event])) { switch ($event) { case 'backend_image_addform': if ($serendipity['version'][0] < 2) { if (class_exists('ZipArchive')) { $checkedY = ""; $checkedN = ""; $this->get_config('unzipping') ? $checkedY = ' checked="checked"' : ($checkedN = ' checked="checked"'); ?> <br /> <div> <strong><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES; ?> </strong><br /> <?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES_DESC; ?> <div> <input type="radio" class="input_radio" id="unzip_yes" name="serendipity[unzip_archives]" value="<?php echo YES; ?> "<?php echo $checkedY; ?> ><label for="unzip_yes"><?php echo YES; ?> </label> <input type="radio" class="input_radio" id="unzip_no" name="serendipity[unzip_archives]" value="<?php echo NO; ?> "<?php echo $checkedN; ?> ><label for="unzip_no"><?php echo NO; ?> </label> </div> </div> <?php } ?> <br /> <strong><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG; ?> :</strong><br /> <em><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG_DESC; ?> </em> <table id="quickblog_table" style="width: 50%"> <tr> <td nowrap="nowrap"><?php echo TITLE; ?> </td> <td><input class="input_textbox" name="serendipity[quickblog][title]" type="text" style="width: 90%" /></td> </tr> <tr> <td nowrap="nowrap"><?php echo ENTRY_BODY; ?> </td> <td><textarea name="serendipity[quickblog][body]" style="width: 90%; height: 200px"></textarea></td> </tr> <tr> <td nowrap="nowrap"><?php echo CATEGORY; ?> </td> <td><select name="serendipity[quickblog][category]"> <option value=""><?php echo NO_CATEGORY; ?> </option> <?php if (is_array($cats = serendipity_fetchCategories())) { $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED); foreach ($cats as $cat) { echo '<option value="' . $cat['categoryid'] . '">' . str_repeat(' ', $cat['depth']) . $cat['category_name'] . '</option>' . "\n"; } } ?> </select></td> </tr> <tr> <td nowrap="nowrap"><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET; ?> </td> <td><select id="select_image_target" name="serendipity[quickblog][target]"> <option value="none"<?php echo serendipity_ifRemember('target', 'none', false, 'selected'); ?> ><?php echo NONE; ?> </option> <option value="js"<?php echo serendipity_ifRemember('target', 'js', false, 'selected'); ?> ><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET_JS; ?> </option> <option value="plugin"<?php echo serendipity_ifRemember('target', 'plugin', false, 'selected'); ?> ><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET_ENTRY; ?> </option> <option value="_blank"<?php echo serendipity_ifRemember('target', '_blank', false, 'selected'); ?> ><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET_BLANK; ?> </option> </select></td> </tr> <tr> <td nowrap="nowrap"><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_ASOBJECT; ?> </td> <td> <input type="radio" class="input_radio" id="image_yes" name="serendipity[quickblog][isobject]" value="<?php echo YES; ?> "><label for="image_yes"><?php echo YES; ?> </label> <input type="radio" class="input_radio" id="image_no" name="serendipity[quickblog][isobject]" value="<?php echo NO; ?> " checked="checked"><label for="image_no"><?php echo NO; ?> </label> </td> </tr> <tr> <td nowrap="nowrap"><?php echo IMAGE_SIZE; ?> </td> <td><input class="input_textbox" name="serendipity[quickblog][size]" value="<?php echo $serendipity['thumbSize']; ?> " type="text" style="width: 50px" /></td> </tr> <tr> <td align="center" colspan="2"><br /></td> </tr> </table> <div> <em><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_IMAGE_SIZE_DESC; ?> </em> </div> <?php } else { ?> <div id="imageselectorplus"> <?php if (class_exists('ZipArchive')) { $checkedY = ""; $checkedN = ""; $this->get_config('unzipping') ? $checkedY = ' checked="checked"' : ($checkedN = ' checked="checked"'); ?> <div class="clearfix radio_field"> <h4><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES; ?> </h4> <?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES_DESC; ?> <div> <input type="radio" class="input_radio" id="unzip_yes" name="serendipity[unzip_archives]" value="<?php echo YES; ?> "<?php echo $checkedY; ?> ><label for="unzip_yes"><?php echo YES; ?> </label> <input type="radio" class="input_radio" id="unzip_no" name="serendipity[unzip_archives]" value="<?php echo NO; ?> "<?php echo $checkedN; ?> ><label for="unzip_no"><?php echo NO; ?> </label> </div> </div> <?php } ?> <h4><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG; ?> :</h4> <em><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG_DESC; ?> </em> <div id="quickblog_tablefield" class="clearfix"> <div class="quickblog_form_field"> <label for="quickblog_titel"><?php echo TITLE; ?> </label> <input id="quickblog_title" class="input_textbox" name="serendipity[quickblog][title]" type="text"> </div> <div class="quickblog_textarea_field"> <label for="nuggets2"><?php echo ENTRY_BODY; ?> </label> <textarea id="nuggets2" class="quickblog_nugget" data-tarea="nuggets2" name="serendipity[quickblog][body]" rows="10" cols="80"></textarea> <?php if ($serendipity['wysiwyg']) { $plugins = serendipity_plugin_api::enum_plugins('*', false, 'serendipity_event_nl2br'); ?> <input name="serendipity[properties][disable_markups][]" type="hidden" value="<?php echo $plugins[0]['name']; ?> "> <?php if (!class_exists('serendipity_event_ckeditor')) { ?> <script src="<?php echo $serendipity['serendipityHTTPPath']; ?> htmlarea/ckeditor/ckeditor/ckeditor.js"></script> <?php } // just add a simple basic toolbar, since we cannot use embedded plugins here ?> <script> CKEDITOR.replace( 'nuggets2', { toolbar : [['Format'],['Bold','Italic','Underline','Superscript','-','NumberedList','BulletedList','Outdent','Blockquote'],['JustifyBlock','JustifyCenter','JustifyRight'],['Link','Unlink'],['Source']], toolbarGroups: null }); </script> <?php } ?> </div> <div class="quickblog_form_field"> <label for="quickblog_select"><?php echo CATEGORY; ?> </label> <select id="quickblog_select" name="serendipity[quickblog][category]"> <option value=""><?php echo NO_CATEGORY; ?> </option> <?php if (is_array($cats = serendipity_fetchCategories())) { $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED); foreach ($cats as $cat) { echo '<option value="' . $cat['categoryid'] . '">' . str_repeat(' ', $cat['depth']) . $cat['category_name'] . '</option>' . "\n"; } } ?> </select> </div> <div class="quickblog_form_select"> <label for="select_image_target"><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET; ?> </label> <select id="select_image_target" name="serendipity[quickblog][target]"> <option value="none"<?php echo serendipity_ifRemember('target', 'none', false, 'selected'); ?> ><?php echo NONE; ?> </option> <option value="js"<?php echo serendipity_ifRemember('target', 'js', false, 'selected'); ?> ><?php echo MEDIA_TARGET_JS; ?> </option> <option value="plugin"<?php echo serendipity_ifRemember('target', 'plugin', false, 'selected'); ?> ><?php echo MEDIA_ENTRY; ?> </option> <option value="_blank"<?php echo serendipity_ifRemember('target', '_blank', false, 'selected'); ?> ><?php echo MEDIA_TARGET_BLANK; ?> </option> </select> </div> <div class="clearfix radio_field quickblog_radio_field"> <label><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_ASOBJECT; ?> </label> <div> <input type="radio" class="input_radio" id="image_yes" name="serendipity[quickblog][isobject]" value="<?php echo YES; ?> "><label for="image_yes"><?php echo YES; ?> </label> <input type="radio" class="input_radio" id="image_no" name="serendipity[quickblog][isobject]" value="<?php echo NO; ?> " checked="checked"><label for="image_no"><?php echo NO; ?> </label> </div> </div> <div class="quickblog_form_field"> <label for="quickblog_isize"><?php echo IMAGE_SIZE; ?> </label> <input id="quickblog_isize" class="input_textbox" name="serendipity[quickblog][size]" value="<?php echo $serendipity['thumbSize']; ?> " type="text"> </div> </div> <em><?php echo PLUGIN_EVENT_IMAGESELECTORPLUS_IMAGE_SIZE_DESC; ?> </em> </div> <?php } break; case 'backend_image_add': global $new_media; // if file is zip archive and unzipping enabled // unzip file and add all images to database // retrieve file type $target_zip = $eventData; preg_match('@(^.*/)+(.*)\\.+(\\w*)@', $target_zip, $matches); $target_dir = $matches[1]; $basename = $matches[2]; $extension = $matches[3]; $authorid = isset($serendipity['POST']['all_authors']) && $serendipity['POST']['all_authors'] == 'true' ? '0' : $serendipity['authorid']; // only if unzipping function exists, we have archive file and unzipping set to yes if (class_exists('ZipArchive') && $extension == 'zip' && $serendipity['POST']['unzip_archives'] == YES) { // now unzip $zip = new ZipArchive(); $res = $zip->open($target_zip); if ($res === TRUE) { $files_to_unzip = array(); $extracted_images = array(); for ($i = 0; $i < $zip->numFiles; $i++) { $file_to_extract = $zip->getNameIndex($i); if (file_exists($target_dir . $file_to_extract)) { echo '(' . $file_to_extract . ') ' . ERROR_FILE_EXISTS_ALREADY . '<br />'; } else { $files_to_unzip[] = $file_to_extract; $extracted_images[] = $target_dir . $file_to_extract; } } $zip->extractTo($target_dir, $files_to_unzip); $zip->close(); echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_OK; } else { echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FAILED; } // now proceed all unzipped images foreach ($extracted_images as $target) { preg_match('@(^.*/)+(.*)\\.+(\\w*)@', $target, $matches); $real_dir = $matches[1]; $basename = $matches[2]; $extension = $matches[3]; $tfile = $basename . "." . $extension; preg_match('@' . $serendipity['uploadPath'] . '(.*/)@', $target, $matches); $image_directory = $matches[1]; // make thumbnails for new images $thumbs = array(array('thumbSize' => $serendipity['thumbSize'], 'thumb' => $serendipity['thumbSuffix'])); serendipity_plugin_api::hook_event('backend_media_makethumb', $thumbs); foreach ($thumbs as $thumb) { // Create thumbnail if ($created_thumbnail = serendipity_makeThumbnail($tfile, $image_directory, $thumb['thumbSize'], $thumb['thumb'])) { echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_IMAGE_FROM_ARCHIVE . " - " . THUMB_CREATED_DONE . '<br />'; } } // Insert into database $image_id = serendipity_insertImageInDatabase($tfile, $image_directory, $authorid, null, $realname); echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_IMAGE_FROM_ARCHIVE . " ({$tfile}) " . PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_ADD_TO_DB . "<br />"; $new_media[] = array('image_id' => $image_id, 'target' => $target, 'created_thumbnail' => $created_thumbnail); } } case 'backend_image_addHotlink': // Re-Scale thumbnails? $max_scale = array('width' => (int) $this->get_config('thumb_max_width'), 'height' => (int) $this->get_config('thumb_max_height')); if ($max_scale['width'] > 0 || $max_scale['height'] > 0) { $this->resizeThumb($max_scale, $eventData); } if (empty($serendipity['POST']['quickblog']['title'])) { break; } $file = basename($eventData); $directory = str_replace($serendipity['serendipityPath'] . $serendipity['uploadPath'], '', dirname($eventData) . '/'); $size = (int) $serendipity['POST']['quickblog']['size']; // check default Serendipity thumbSize, to make this happen like standard image uploads, and to get one "fullsize" image instance only, // else create another quickblog image "resized" instance, to use as entries thumbnail image if ($serendipity['thumbSize'] != $size) { $oldSuffix = $serendipity['thumbSuffix']; $serendipity['thumbSuffix'] = 'quickblog'; serendipity_makeThumbnail($file, $directory, $size); $serendipity['thumbSuffix'] = $oldSuffix; } // Non-image object link generation if ($serendipity['POST']['quickblog']['isobject'] == YES) { $objfile = serendipity_parseFileName($file); $filename = $objfile[0]; $suffix = $objfile[1]; $obj_mime = serendipity_guessMime($suffix); $objpath = $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $directory . $filename . '.' . $suffix; // try to know about a working environment for imagemagicks pdf preview generation if ($serendipity['magick'] === true && strtolower($suffix) == 'pdf' && $serendipity['thumbSize'] == $size) { $objpreview = $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $directory . $filename . '.' . $serendipity['thumbSuffix'] . '.' . $suffix . '.png'; } else { $objpreview = serendipity_getTemplateFile('admin/img/mime_' . preg_replace('@[^0-9a-z_\\-]@i', '-', $obj_mime) . '.png'); } if (!$objpreview || empty($objpreview)) { $objpreview = serendipity_getTemplateFile('admin/img/mime_unknown.png'); } } // New draft post $entry = array(); $entry['isdraft'] = 'false'; $entry['title'] = function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['quickblog']['title']) : htmlspecialchars($serendipity['POST']['quickblog']['title'], ENT_COMPAT, LANG_CHARSET); if (isset($objpath) && !empty($objpath)) { $entry['body'] = '<a href="' . $objpath . '"><img alt="" class="serendipity_image_left serendipity_quickblog_image" src="' . $objpreview . '">' . $filename . '</a> (-' . $obj_mime . '-)<p>' . $serendipity['POST']['quickblog']['body'] . '</p>'; } else { $entry['body'] = '<!--quickblog:' . $serendipity['POST']['quickblog']['target'] . '|' . $eventData . '-->' . $serendipity['POST']['quickblog']['body']; } $entry['authorid'] = $serendipity['authorid']; $entry['exflag'] = false; $entry['categories'][0] = function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['quickblog']['category']) : htmlspecialchars($serendipity['POST']['quickblog']['category'], ENT_COMPAT, LANG_CHARSET); #$entry['allow_comments'] = 'true'; // both disabled #$entry['moderate_comments'] = 'false'; // to take default values $serendipity['POST']['properties']['fake'] = 'fake'; $id = serendipity_updertEntry($entry); break; case 'frontend_display': // auto resizing images based on width and/or height attributes in img tag if (serendipity_db_bool($this->get_config('autoresize'))) { if (!empty($eventData['body'])) { $eventData['body'] = $this->substituteImages($eventData['body']); } if (!empty($eventData['extended'])) { $eventData['extended'] = $this->substituteImages($eventData['extended']); } } if (empty($eventData['body'])) { return; } // displaying quickblog posts if (is_object($serendipity['smarty']) && preg_match('@<!--quickblog:(.+)-->@imsU', $eventData['body'], $filematch)) { $eventData['body'] = $this->parse_quickblog_post($filematch[1], $eventData['body']); } // displaying galleries introduced by markup foreach ($this->markup_elements as $temp) { if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && !$eventData['properties']['ep_disable_markup_' . $this->instance] && !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) { $element = $temp['element']; $eventData[$element] = $this->media_insert($eventData[$element], $eventData); } } return true; break; case 'backend_entry_presave': if (is_numeric($eventData['id'])) { $eventData['body'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $eventData['body']); $eventData['extended'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $eventData['extended']); $this->gotMilk = true; } else { $this->cache['body'] = $eventData['body']; $this->cache['extended'] = $eventData['extended']; } break; case 'backend_publish': case 'backend_save': if ($this->gotMilk === false) { $old = md5($this->cache['body']) . md5($this->cache['extended']); $this->cache['body'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $this->cache['body']); $this->cache['extended'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $this->cache['extended']); $new = md5($this->cache['body']) . md5($this->cache['extended']); if ($old != $new) { serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries\n SET body = '" . serendipity_db_escape_string($this->cache['body']) . "',\n extended = '" . serendipity_db_escape_string($this->cache['extended']) . "'\n WHERE id = " . (int) $eventData['id']); } } break; case 'entry_display': if ($this->selected()) { if (is_array($eventData)) { $eventData['clean_page'] = true; // This is important to not display an entry list! } else { $eventData = array('clean_page' => true); } } break; case 'entries_header': if (!$this->selected()) { return true; } if ($serendipity['version'][0] > 1) { return true; } if (!headers_sent()) { header('HTTP/1.0 200'); header('Status: 200 OK'); } $entry = serendipity_fetchEntry('id', $serendipity['GET']['id']); $imageid = $serendipity['GET']['image']; $imgsrc = ''; if (preg_match('@<a title="([^"]+)" id="s9yisp' . $imageid . '"></a>@imsU', $entry['body'], $imgmatch)) { $imgsrc = $imgmatch[1]; } elseif (preg_match('@<a title="([^"]+)" id="s9yisp' . $imageid . '"></a>@imsU', $entry['extended'], $imgmatch)) { $imgsrc = $imgmatch[1]; } else { return; } $link = '<a href="' . serendipity_archiveURL($serendipity['GET']['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])) . '#s9yisp' . $imageid . '">'; echo '<div class="serendipity_Entry_Date"> <h3 class="serendipity_date">' . serendipity_formatTime(DATE_FORMAT_ENTRY, $entry['timestamp']) . '</h3>'; echo '<h4 class="serendipity_title"><a href="#">' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['title']) : htmlspecialchars($entry['title'], ENT_COMPAT, LANG_CHARSET)) . '</a></h4>'; echo '<div class="serendipity_entry"><div class="serendipity_entry_body">'; echo '<div class="serendipity_center">' . $link . '<!-- s9ymdb:' . $entry['id'] . ' --><img src="' . $imgsrc . '" /></a></div>'; echo '<br />'; echo $link . '<< ' . BACK . '</a>'; echo "</div>\n</div>\n</div>\n"; return true; break; case 'frontend_image_add_unknown': case 'frontend_image_add_filenameonly': case 'frontend_image_selector_submit': case 'frontend_image_selector_more': case 'frontend_image_selector_imagecomment': case 'frontend_image_selector_imagealign': case 'frontend_image_selector_imagesize': case 'frontend_image_selector_hiddenfields': case 'frontend_image_selector_imagelink': return true; break; case 'css_backend': if ($serendipity['version'][0] > 1) { ?> #imageselectorplus .radio_field input { margin: 0 0.5em; } #quickblog_tablefield { display: table-cell; } #uploadform .quickblog_nugget { margin-left: 0; padding: 0; } #quickblog_tablefield .quickblog_form_field { margin: .375em 0; } #quickblog_tablefield .quickblog_radio_field div label, #quickblog_tablefield .radio_field label { padding-left: .5em; } #quickblog_tablefield .quickblog_form_select { margin-top: 0.75em; margin-bottom: 0.75em; } #quickblog_tablefield .quickblog_radio_field label { padding-left: 0; } #quickblog_tablefield .quickblog_radio_field div { display: inline; } #quickblog_tablefield .quickblog_radio_field input { margin-left: 0.5em; } <?php } break; case 'css': ?> #content .serendipity_quickblog_image { border: medium none transparent; } .serendipity_mediainsert_gallery { border: 1px solid #C0C0C0; margin: 0px; overflow: auto; padding: 0.4em; } <?php break; case 'frontend_image_selector': if ($serendipity['version'][0] < 2) { $eventData['finishJSFunction'] = 'serendipity_imageSelectorPlus_done(\'' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['GET']['textarea']) : htmlspecialchars($serendipity['GET']['textarea'], ENT_COMPAT, LANG_CHARSET)) . '\')'; } else { $eventData['finishJSFunction'] = 'serendipity.serendipity_imageSelector_done(\'' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['GET']['textarea']) : htmlspecialchars($serendipity['GET']['textarea'], ENT_COMPAT, LANG_CHARSET)) . '\')'; } return true; break; default: return false; } } else { return false; } }
function sprintpcs_albumshare($maildir, $body, $authorid) { global $serendipity; if (strstr($body, SPRINTPCS_IDENT_ALB_JUNK)) { return ''; } $body = trim($body); if (empty($body)) { return ''; } $path = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $maildir; // Find the picture URL -- There should always be a picture??? $video = stristr($body, SPRINTPCS_PICTURE); if (!$video) { $video = stristr($body, SPRINTPCS_PICTURE_ALT); } if (!$video) { return MF_ERROR10; // Failed to find the picture URL } $pos = strpos($video, '"'); $url = substr($video, 0, $pos); $url = html_entity_decode($url, ENT_COMPAT, LANG_CHARSET); // Fetch the picture $videostill = @file_get_contents($url); if (!$videostill) { return MF_ERROR11; } // Build the filename $filename = basename($url); $pos = strpos($filename, '?'); $filename = substr($filename, 0, $pos) . '.jpg'; $fullname = $path . $filename; $ext = substr(strrchr($filename, "."), 0); $name = substr($filename, 0, strrpos($filename, ".")); // Check for duplicate filename. if (is_file($fullname)) { echo '<br />' . MF_MSG14 . $filename; $name = $name . time() . 'dup'; $filename = $name . $ext; $fullname = $path . $filename; } // Write the video still $fp = fopen($fullname, 'w'); if (!$fp) { return MF_ERROR13; } fwrite($fp, $videostill); serendipity_makeThumbnail($filename, $maildir, false); serendipity_insertImageInDatabase($filename, $maildir, $authorid, NULL); // Create Thumbnail name $thumbname = $name . '.' . $serendipity['thumbSuffix'] . $ext; // Get the actual video $url = str_replace('true', 'false', $url); // Fetch the picture $video = @file_get_contents($url); if (!$video) { return MF_ERROR11; } // Build the filename $mfilename = basename($url); $pos = strpos($mfilename, '?'); $mfilename = substr($mfilename, 0, $pos) . '.mov'; $mfullname = $path . $mfilename; $mext = substr(strrchr($mfilename, "."), 0); $mname = substr($mfilename, 0, strrpos($mfilename, ".")); // Check for duplicate filename. if (is_file($mfullname)) { echo '<br />' . MF_MSG14 . $mfilename; $mname = $mname . time() . 'dup'; $mfilename = $mname . $mext; $mfullname = $path . $mfilename; } // Write the video $fp = fopen($mfullname, 'w'); if (!$fp) { return MF_ERROR13; } fwrite($fp, $video); echo '<br />' . MF_MSG13 . $mfilename; serendipity_makeThumbnail($mfilename, $maildir, false); serendipity_insertImageInDatabase($mfilename, $maildir, $authorid, NULL); // Find the message text, if it exists $msg = strstr($body, SPRINTPCS_MSG); if ($msg) { $pos = strpos($msg, '</font>'); $msg = html_entity_decode(substr($msg, 17, $pos - 17), ENT_QUOTES, LANG_CHARSET) . '<br /><br />'; if (trim($msg) == '<br /><br />') { $msg = ''; } } elseif ($msg = stristr($body, SPRINTPCS_VID_MSG)) { $msg = strstr($msg, '"2">'); $pos = strpos($msg, '</font'); $msg = html_entity_decode(substr($msg, 4, $pos - 4), ENT_QUOTES, LANG_CHARSET) . '<br /><br />'; if (trim($msg) == '<br /><br />') { $msg = ''; } } else { $msg = ''; } // Find the sound memo, if it exists $memo = stristr($body, SPRINTPCS_MEMO); if ($memo) { $memo = stristr($memo, SPRINTPCS_MEMO_START); $pos = strpos($memo, '"'); $memo = substr($memo, 0, $pos); $memo = html_entity_decode($memo, ENT_COMPAT, LANG_CHARSET); $memosound = @file_get_contents($memo); // Build the filename - I use this funky date name because the Sprint file path is too gnarly $memofilename = date("F_j_Y__H_i_s") . '.wav'; $memofullname = $path . $memofilename; $ext = substr(strrchr($memofilename, "."), 0); // Write the memo $fp = fopen($memofullname, 'w'); if (!$fp) { return MF_ERROR14; } fwrite($fp, $memosound); serendipity_makeThumbnail($memofilename, $maildir, false); serendipity_insertImageInDatabase($memofilename, $maildir, $authorid, NULL); echo '<br />' . MF_MSG13 . $memofilename; $memo = '<a href="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $maildir . $memofilename . '" target="_blank">' . MF_MSG21 . '</a><br /><br />'; } else { $memo = ''; } echo '<br />' . MF_MSG13 . $filename; return $msg . $memo . '<a href="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $maildir . $mfilename . '" target="_blank"><img src="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $maildir . $thumbname . '" alt="' . MF_MSG22 . '" /></a>'; }
/** * * Create a vcard from user * * @access private * * @param int $authorid The UserID to build the vcard * * @return bool * */ function createVCard($authorid) { global $serendipity; include 'Contact_Vcard_Build.php'; if (!class_exists('Contact_Vcard_Build')) { return false; } $authorres = $this->getConfigVars($authorid); $name = explode(" ", $serendipity['POST']['profilerealname']); $city = explode(" ", $serendipity['POST']['profilecity']); $vcard = new Contact_Vcard_Build(); $vcard->setFormattedName($serendipity['POST']['profilerealname']); $vcard->setName($name[1], $name[0], "", "", ""); $vcard->addEmail($serendipity['POST']['profileemail']); $vcard->addParam('TYPE', 'WORK'); $vcard->addParam('TYPE', 'PREF'); $vcard->addAddress("", "", $serendipity['POST']['profilestreet'], $city[1], "", $city[0], $serendipity['POST']['profilecountry']); $vcard->addParam('TYPE', 'WORK'); $vcard->setURL($serendipity['POST']['profileurl']); $card = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . serendipity_makeFilename($serendipity['POST']['profilerealname']) . ".vcf"; if (!($fp = @fopen($card, "w"))) { return false; } fwrite($fp, $vcard->fetch()); fclose($fp); $q = 'SELECT id FROM ' . $serendipity['dbPrefix'] . 'images WHERE name = \'' . serendipity_makeFilename($serendipity['POST']['profilerealname']) . '\' AND extension = \'vcf\''; $res = serendipity_db_query($q, true, 'assoc'); if (!is_array($res)) { serendipity_insertImageInDatabase(basename($card), ''); } return true; }
function workPopfetcher(&$eventData) { global $serendipity; static $debug = null; if ($debug === null) { $debug = $this->debug = serendipity_db_bool($this->get_config('debug')); } // updertEntry() will not function unless this is set: $serendipity['POST']['properties']['fake'] = 'fake'; $_SESSION['serendipityRightPublish'] = true; $this->out('<h3>' . PLUGIN_MF_NAME . ' v' . POPFETCHER_VERSION . ' @ ' . date("D M j G:i:s T Y") . '</h3>'); $debug_file = null; // DEVELOPERS: If set to a filename, you can bypass fetching POP and use a file instead. $debug_mail = $this->get_config('debug_mail'); if (strlen($debug_mail) != '' && file_exists($debug_mail)) { $debug_file = $debug_mail; } if ($debug_file != null) { $this->debug = true; } $authorid = $this->get_config('author'); if (empty($authorid) || $authorid == 'empty') { $authorid = isset($serendipity['authorid']) ? $serendipity['authorid'] : 1; } $mailserver = trim($this->get_config('mailserver')); $mailport = $this->get_config('mailport'); $mailuser = trim($this->get_config('mailuser')); $mailpass = trim($this->get_config('mailpass')); $timeout = $this->get_config('timeout'); $deleteflag = serendipity_db_bool($this->get_config('deleteflag')); $apopflag = serendipity_db_bool($this->get_config('apopflag')); $blogflag = serendipity_db_bool($this->get_config('blogflag')); $striptagsflag = serendipity_db_bool($this->get_config('striptagsflag')); $publishflag = serendipity_db_bool($this->get_config('publishflag')); $onlyfrom = $this->get_config('onlyfrom', ''); $maildir = trim($this->get_config('maildir')); $category = trim($this->get_config('category')); $adflag = serendipity_db_bool($this->get_config('adflag')); $plaintext_is_body_flag = serendipity_db_bool($this->get_config('plaintext_is_body')); $plaintext_use_extended_flag = serendipity_db_bool($this->get_config('plaintext_use_extended')); $list_virus = array('.pif', '.vbs', '.scr', '.bat', '.com', '.exe'); $list_imagetype = array('jpg', 'jpeg', 'gif', 'png', 'x-png', 'pjpeg'); $list_imageext = array('.gif', '.jpg', '.png', '.jpeg'); $list_ignore = array('.smil'); $output = ''; $dirpath = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $maildir; $dupcount = 0; // Upload directory must end with a slash character if (strrchr($dirpath, '/') != '/') { $output = MF_ERROR7; $this->out('<br />' . $output . '<br />'); return true; } // Upload directory must be writable if (!is_writable($dirpath)) { $output = MF_ERROR6; $this->out('<br />' . $output . '<br />'); return true; } if (serendipity_db_bool($this->get_config('subfolder'))) { $dirpath = $dirpath . '/' . date('Y'); if (!is_dir($dirpath)) { mkdir($dirpath); } $dirpath = $dirpath . '/' . date('m') . '/'; if (!is_dir($dirpath)) { mkdir($dirpath); } $maildir .= date('Y') . '/' . date('m') . '/'; } $maildir = str_replace('//', '/', $maildir); // Category (if specified) must exist if (!empty($category)) { $cid = serendipity_fetchCategoryInfo(null, $category); if ($cid == false) { $output = MF_ERROR8; $this->out('<br />' . $output . '<br />'); return true; } } if ($debug_file === null) { // Create new instance of POP3 connection $pop3 = new POP3($mailserver, $timeout); // Attempt to connect to mail server if (!$pop3->connect($mailserver, $mailport)) { $output = MF_ERROR1 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); return true; } // Try APOP login if requested, otherwise, regular login if ($apopflag) { $Count = $pop3->apop($mailuser, $mailpass); } else { $Count = $pop3->login($mailuser, $mailpass); } // Check for error retrieving number of msgs in mailbox if ($Count === false or $Count == -1) { $output = MF_ERROR2 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); return true; } // If no msgs in mailbox, exit if ($Count == 0) { $output = MF_MSG1; $this->out('<br />' . $output . '<br />'); return true; } // Get the list of email msgs $msglist = $pop3->uidl(); // Check for error in getting list of email msgs if (!is_array($msglist)) { $output = MF_ERROR3 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); $pop3->quit(); return true; } } else { // Developer debug switch which reads from a file and not a POP3 connection. $dfiles = explode(':', $debug_file); $Count = count($dfiles); } $Message = array(); // ************************ // Fetch each email msg and attachments and put it into the $Message array // ************************ for ($i = 1; $i <= $Count; $i++) { // Messages are numbered starting with '1', not '0' if ($debug_file === null) { $MessArray = $pop3->get($i); } else { $MessArray = file($dfiles[$i - 1]); } // Should have an array. If not, there was an error if (!$MessArray or gettype($MessArray) != "array") { $output = MF_ERROR4 . ': ' . $pop3->ERROR; $this->out('<br />' . $output . '<br />'); $pop3->quit(); return true; } // Extract the msg from MessArray and store it in Message $Message[$i - 1] = ''; while (list($lineNum, $line) = each($MessArray)) { $Message[$i - 1] .= $line; } // Delete the msg if ($deleteflag && $debug_file === null) { $pop3->delete($i); } } if ($debug_file === null) { // Close the connection to the mail server $pop3->quit(); } // ************************ // Message processing section starts here // ************************ $this->out('<br />' . MF_MSG2 . ': ' . $Count . '<br />'); if ($deleteflag) { $this->out(MF_MSG11 . '<br />'); } else { $this->out(MF_MSG12 . '<br />'); } $params['include_bodies'] = true; $params['decode_bodies'] = true; $params['decode_headers'] = true; // Process each email msg foreach ($Message as $M) { $decode = new mimeDecode($M); #$this->out(print_r($M, true)); $s = $decode->decode($params); #$this->out(print_r($s, true)); if ($debug_file !== null) { // DEBUG Struct // echo '<pre>'; // print_r($s); // echo '</pre>'; } if ($s == null) { $this->out('<br />' . MF_ERROR9); return true; } $date = isset($s->headers['date']) ? $s->headers['date'] : MF_MSG3; $from = isset($s->headers['from']) ? $s->headers['from'] : MF_MSG4; if (!empty($onlyfrom) && trim($from) != trim($onlyfrom)) { $this->out('<br />' . sprintf(MF_ERROR_ONLYFROM, '"' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($from) : htmlspecialchars($from, ENT_COMPAT, LANG_CHARSET)) . '"', '"' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($onlyfrom) : htmlspecialchars($onlyfrom, ENT_COMPAT, LANG_CHARSET)) . '"')); continue; } if (empty($s->ctype_parameters['charset'])) { $s->ctype_parameters['charset'] = 'UTF-8'; } if (strtolower($s->ctype_parameters['charset']) == 'us-ascii') { $s->ctype_parameters['charset'] = 'ISO-8859-1'; } $subject = $this->decode(isset($s->headers['subject']) ? $s->headers['subject'] : MF_MSG17, $s->ctype_parameters['charset'], true); #$subject = $this->decode(isset($s->headers['subject']) ? $s->headers['subject'] : MF_MSG17, $s->ctype_parameters['charset']); #$subject = isset($s->headers['subject']) ? $s->headers['subject'] : MF_MSG17; $this->out('<hr />'); $this->out(MF_MSG5 . $date . '<br />'); $this->out(MF_MSG6 . (function_exists('serendipity_specialchars') ? serendipity_specialchars($from) : htmlspecialchars($from, ENT_COMPAT, LANG_CHARSET)) . '<br />'); $this->out(MF_MSG16 . $subject . '<br />'); // Find the author associated with the from address and // set them as the author of the post. $useAuthor = null; if ($authorid == 'byemail') { // We don't have tons of authors .. like two so this isn't a problem // If I wanted this to be "production" quality, I would have to add // a new s9y function that let you retrieve an author given an email address // I suppose I could go with a convention that the base name of the // email address had to be the author's name too. Lookup by name is // supported by s9y. $auths = serendipity_fetchUsers(); $vals = array(); $clean = strtolower($this->cleanEmail($from)); foreach ($auths as $auth) { if (isset($auth['email']) && strtolower($auth['email']) == $clean) { $useAuthor = $auth['authorid']; break; } } if (is_null($useAuthor)) { $this->out('<br />' . sprintf(MF_ERROR_NOAUTHOR, '"' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($clean) : htmlspecialchars($clean, ENT_COMPAT, LANG_CHARSET)) . '"')); continue; } } else { $useAuthor = $authorid; } $postattach = array(); $postbody = array(); $postex = array(); $verizonflag = false; $tmobileflag = false; $firstattachment = false; $firsttext = false; $o2flag = stristr($from, 'mms.o2online.de') !== FALSE; // A mail message with attachments is a series of "parts" if (isset($s->parts) and is_array($s->parts)) { if ($debug_file !== null || $debug) { $this->out('<pre>' . print_r($s->parts, true) . '</pre>'); } $textpref = $this->get_config('textpref'); if ($textpref != 'both') { $has_html = false; $has_text = false; $parts_html = array(); $parts_text = array(); foreach ($s->parts as $idx => $p) { if ($p->ctype_primary == 'text' && $p->ctype_secondary == 'html') { if ($debug_file !== null || $debug) { $this->out("This part is text/html.<br />\n"); } $has_html = true; $parts_html[] = $idx; } elseif ($p->ctype_primary == 'text' && $p->ctype_secondary == 'plain') { if ($debug_file !== null || $debug) { $this->out("This part is text/plain.<br />\n"); } $has_text = true; $parts_text[] = $idx; } } if ($debug_file !== null || $debug) { $this->out("Preference is: {$textpref}.<br />\n"); } if ($textpref == 'text' && $has_html) { if ($debug_file !== null || $debug) { $this->out("Preference is text/plain.<br />\n"); } foreach ($parts_html as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping HTML part {$pidx}, because preference is plaintext.<br />\n"); } unset($s->parts[$pidx]); } } if ($textpref == 'html' && $has_text) { if ($debug_file !== null || $debug) { $this->out("Preference is text/html.<br />\n"); } foreach ($parts_text as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping text part {$pidx}, because preference is html.<br />\n"); } unset($s->parts[$pidx]); } } } foreach ($s->parts as $p) { if ($debug_file !== null || $debug) { $this->out("Analyzing mail:<br />\n Disposition: {$p->disposition}<br />\n Body: " . (isset($p->body) ? 'Set' : 'Not Set') . "<br />\n Primary CType: {$p->ctype_primary}<br />\n Secondary CType: {$p->ctype_secondary}<br />\n Filename: {$p->d_parameters[filename]}\n .<br />\n"); } // Handle msgs with attachments and messages with images that are inlined if (isset($p->disposition) and $p->disposition == 'attachment' and isset($p->body) or isset($p->disposition) and $p->disposition == 'inline' and isset($p->body) and $p->ctype_primary == 'image' or !empty($p->body) and $p->ctype_primary == 'image') { $this->handleImage($p, $debug, $debug_file, $tmobileflag, $adflag, $dirpath, $list_virus, $list_ignore, $plaintext_is_body_flag, $firsttext, $plaintext_use_extended_flag, $postex, $postbody, $dupcount, $maildir, $authorid, $list_imagetype, $list_imageext, $subject); } elseif (strtolower($p->ctype_primary) == 'text' and isset($p->body)) { if ($debug_file !== null || $debug) { $this->out("<br />\nRecognized text part.<br />\n"); } if (trim($subject) == SPRINTPCS_IDENT_PICTURE) { $p->body = sprintpcs_pictureshare($maildir, $p->body, $authorid); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (trim($subject) == SPRINTPCS_IDENT_ALBUM) { $p->body = sprintpcs_albumshare($maildir, $p->body, $authorid); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (trim($subject) == SPRINTPCS_IDENT_VIDEO) { $p->body = sprintpcs_videoshare($maildir, $p->body, $authorid); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (stristr($subject, CINGULAR_IDENT_PICTURE)) { $p->body = cingular_photo($maildir, $p->body); if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } if (stristr($p->body, VERIZON_IDENT_PICTURE)) { $p->body = verizon_photo($maildir, $p->body); $verizonflag = true; if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } // Because text and HTML attachments get inlined // sometimes (notably Hotmail), // we want to collect them all and attach them to the // regular msg body $bodytext = trim($this->decode($p->body, $p->ctype_parameters['charset'])); if (empty($bodytext)) { continue; } // Strip evil HTML if (preg_match('@<body[^>]*>(.+)</body>@imsU', $bodytext, $m)) { if ($debug_file !== null || $debug) { $this->out("Reduced HTML text.<br />\n"); } $bodytext = $m[1]; } if ($adflag && preg_match('@T\\-Mobile MMS@', $bodytext) && preg_match('@http://www\\.T\\-Mobile\\.(de|nl|com)/mms@', $bodytext)) { if ($debug_file !== null || $debug) { $this->out("<br />\nSkipping T-Mobile ad.<br />\n"); } continue; } if ($firsttext && $plaintext_use_extended_flag) { $postex[] = $bodytext; } else { $postbody[] = $bodytext; $firsttext = true; } } elseif (is_array($p->parts)) { if ($debug_file !== null || $debug) { $this->out("<br />\nRecognized text/multipart.<br />\n"); } if ($textpref != 'both') { $has_html = false; $has_text = false; $parts_html = array(); $parts_text = array(); foreach ($p->parts as $idx => $subp) { if ($subp->ctype_primary == 'text' && $subp->ctype_secondary == 'html') { $has_html = true; $parts_html[] = $idx; } elseif ($subp->ctype_primary == 'text' && $subp->ctype_secondary == 'plain') { $has_text = true; $parts_text[] = $idx; } } if ($textpref == 'text' && $has_html) { foreach ($parts_html as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping HTML part {$pidx}, because preference is plaintext.<br />\n"); } unset($p->parts[$pidx]); } } if ($textpref == 'html' && $has_text) { foreach ($parts_text as $pidx) { if ($debug_file !== null || $debug) { $this->out("Stripping text part {$pidx}, because preference is html.<br />\n"); } unset($p->parts[$pidx]); } } } foreach ($p->parts as $subpart) { if ($subpart->ctype_primary == 'text' && $subpart->ctype_secondary == 'html' && $o2flag) { $bodytext = trim($this->decode(popfetcher_provider_o2::getBody($subpart->body), $subpart->ctype_parameters['charset'])); if (empty($bodytext)) { continue; } if ($firsttext && $plaintext_use_extended_flag) { $postex[] = $bodytext; } else { $postbody[] = $bodytext; $firsttext = true; } } elseif ($subpart->ctype_primary == 'text') { $bodytext = trim($this->decode($subpart->body, $subpart->ctype_parameters['charset'])); if (preg_match('@<body[^>]*>(.+)</body>@imsU', $bodytext, $m)) { if ($debug_file !== null || $debug) { $this->out("Reduced HTML text.<br />\n"); } $bodytext = $m[1]; } if ($firsttext && $plaintext_use_extended_flag) { $postex[] = $bodytext; } else { $postbody[] = $bodytext; $firsttext = true; } } elseif ($subpart->ctype_primary == 'image') { // Handle inline multipart images $this->handleImage($subpart, $debug, $debug_file, $tmobileflag, $adflag, $dirpath, $list_virus, $list_ignore, $plaintext_is_body_flag, $firsttext, $plaintext_use_extended_flag, $postex, $postbody, $dupcount, $maildir, $authorid, $list_imagetype, $list_imageext, $subject); } } } else { if ($debug_file !== null || $debug) { $this->out("<br />\nRecognized unknown part.<br />\n"); } if ($p->disposition == 'inline' && isset($p->d_parameters['filename'])) { // Use makeFilename to get rid of spaces and other oddities $filename = serendipity_makeFilename($p->d_parameters['filename']); // if no file extension exists, add default .txt file extension if (!strrpos($filename, ".")) { $filename = $filename . 'txt'; } if ($debug_file !== null || $debug) { $this->out("<br />\nStoring attachment as {$filename}<br />\n"); } $this->out('<br />' . MF_MSG8 . $filename); $fullname = $dirpath . $filename; // Extract file extension and file name for various processing $ext = substr(strrchr($filename, "."), 0); $name = substr($filename, 0, strrpos($filename, ".")); // Skip message and all attachments if possible virus found $lext = strtolower($ext); if (in_array($lext, $list_virus)) { $output = MF_MSG19 . ': ' . $filename; $this->out('<br />' . $output . '<br />'); continue 2; } if (in_array($lext, $list_ignore)) { $this->out('<br />' . MF_MSG20 . '<br />'); continue; } // Check for duplicate filename. Give dup file name file.time().dup.ext if (is_file($fullname)) { $this->out('<br />' . MF_MSG14 . $filename); $name = $name . time() . $dupcount . 'dup'; $filename = $name . $ext; $fullname = $dirpath . $filename; $dupcount++; } $fp = fopen($fullname, 'w'); if (!$fp) { $this->out('<br />' . MF_ERROR5 . $fullname); return true; } fwrite($fp, $p->body); fclose($fp); serendipity_insertImageInDatabase($filename, $maildir, $authorid, NULL); $attlink = '<a class="popfetcherfile" href="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $maildir . $filename . '" target="_blank">' . $filename . '</a>'; // Inline pictures to match the structure of the mail if ($plaintext_is_body_flag) { // Only the first image is embedded in body, or if no extended entry is used if (!$firstattachment || !$plaintext_use_extended_flag) { $postbody[] = $attlink; } else { $postex[] = $attlink; $firsttext = true; } } else { // Standard attachment mode $postattach[] = $attlink; } $firstattachment = true; $this->out('<br />' . MF_MSG13 . $filename); } $this->out('<br />' . MF_MSG9); // Tmobile sends a weird nested text and html // sub-attachment (at least the nokia does) if (isset($s->headers['x-operator']) and strtolower($s->headers['x-operator']) == TMOBILE_IDENT_PICTURE) { $p->body = tmobile_photo($maildir, $p->body); $tmobileflag = true; if (strstr($p->body, ERROR_CHECK)) { $this->out('<br />' . $p->body); return true; } } } } if ($blogflag) { if (trim($subject) == SPRINTPCS_IDENT_ALBUM || trim($subject) == SPRINTPCS_IDENT_PICTURE || trim($subject) == SPRINTPCS_IDENT_VIDEO || stristr($subject, CINGULAR_IDENT_PICTURE) || ($verizonflag and $subject == MF_MSG17) || ($tmobileflag and $subject == MF_MSG17)) { $time = strtotime($s->headers['date']); $stamp = $time == -1 ? date("l, F j, Y, g:ia") : date("l, F j, Y, g:ia", $time); $subject = MF_MSG23 . $stamp; } $msgbody = implode("<br />\n", $postbody); $msgbody .= implode("<br />\n", $postattach); //New draft post $entry = $this->workEntry($subject, $msgbody, $useAuthor, $postex, $cid, $s); } } elseif (strtolower($s->ctype_primary) == 'text') { // Email msg with no attachments if ($blogflag) { if (trim($subject) == SPRINTPCS_IDENT_ALBUM || trim($subject) == SPRINTPCS_IDENT_PICTURE || trim($subject) == SPRINTPCS_IDENT_VIDEO || stristr($subject, CINGULAR_IDENT_PICTURE) || (stristr($s->body, VERIZON_IDENT_PICTURE) and $subject == MF_MSG17) || ($tmobileflag and $subject == MF_MSG17)) { $time = strtotime($s->headers['date']); $stamp = $time == -1 ? date("l, F j, Y, g:ia") : date("l, F j, Y, g:ia", $time); $subject = MF_MSG23 . $stamp; } $bodytext = trim($this->decode($s->body, $s->ctype_parameters['charset'])); $entry = $this->workEntry($subject, $bodytext, $useAuthor, $postex, $cid, $s); } else { $this->out('<br />' . MF_MSG20); } } else { $this->out('<br />' . MF_MSG10 . '<br />'); } } echo '<br /><hr />'; }