/** * 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); }
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; } }
$target = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['POST']['target_directory'][$idx] . $tfile; $realname = $tfile; if (file_exists($target)) { $messages[] = '<span class="msg_error"><span class="icon-attention-circled"></span> ' . $target . ' - ' . ERROR_FILE_EXISTS_ALREADY . '</span>'; $realname = serendipity_imageAppend($tfile, $target, $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $serendipity['POST']['target_directory'][$idx]); } // 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>'; } } } }
break; } serendipity_prepareMedia($file); $showfile = null; if (($serendipity['GET']['resizeWidth'] || $serendipity['GET']['resizeHeight']) && $serendipity['dynamicResize'] && $media['file']['is_image']) { $width = (int) $serendipity['GET']['resizeWidth']; $height = (int) $serendipity['GET']['resizeHeight']; if (empty($width)) { $width = NULL; } if (empty($height)) { $height = NULL; } $showfile = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE . '/mediacache/cache_img' . (int) $serendipity['GET']['image'] . '_' . $width . '_' . $height; if (!file_exists($showfile)) { serendipity_makeThumbnail($media['file']['realname'], $media['file']['path'], array('width' => $width, 'height' => $height), $showfile, true); } } $hit = serendipity_db_query("SELECT id\n FROM {$serendipity['dbPrefix']}references\n WHERE link = '" . serendipity_db_escape_string($_SERVER['HTTP_REFERER']) . "'\n AND entry_id = " . (int) $serendipity['GET']['image'] . "\n AND type = 'media'", true, 'assoc'); if (!is_array($hit) || !isset($hit['id'])) { serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}references\n (entry_id, link, name, type)\n VALUES (" . (int) $serendipity['GET']['image'] . ", '" . serendipity_db_escape_string($_SERVER['HTTP_REFERER']) . "', 1, 'media')"); } else { serendipity_db_query("UPDATE {$serendipity['dbPrefix']}references\n SET name = name + 1\n WHERE id = " . (int) $hit['id']); } $curl = ($_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . ($_SERVER['HTTP_PORT'] != 80 ? ':' . $_SERVER['HTTP_PORT'] : ''); switch ($serendipity['GET']['show']) { case 'redirect': header('Status: 302 Found'); header('Location: ' . $curl . $file['links']['imagelinkurl']); exit; break;
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>'; }
function parseRequestActions() { global $serendipity; if (isset($_REQUEST['autoscale'])) { if ($this->real_img_width > $this->real_img_height) { // The image is a horizontal one. Resize height to fit. $this->imgFit('height'); } else { // The image is a vertical one. Resize width to fit. $this->imgFit('width'); } } elseif (isset($_REQUEST['scale'])) { if ($this->real_img_width > $this->real_img_height) { // The image is a horizontal one. Resize width to fit. $this->imgFit('width'); } else { // The image is a vertical one. Resize height to fit. $this->imgFit('height'); } } else { $this->img_width = intval(round($this->real_img_width * $_REQUEST['zoombox_factor'])); $this->img_height = intval(round($this->real_img_height * $_REQUEST['zoombox_factor'])); } // Check which template to use if (isset($_REQUEST['crop'])) { $this->output_template = 'admin/media_imgedit_done.tpl'; } else { $this->output_template = 'admin/media_imgedit.tpl'; if ($this->orientation_available) { $this->imgedit_smarty['orientation_available'] = true; } } // The final action. Cropping will take place. if (isset($_REQUEST['crop'])) { $new_img_name = $this->img_name . '.tmp'; if ($this->img_width <= $this->area_width && $this->img_height <= $this->area_height) { $this->imgedit_smarty['image_no_cut'] = true; $new_img_width = $this->img_width; $new_img_height = $this->img_height; } else { $this->imgedit_smarty['image_cut'] = true; $new_img_width = $this->area_width - $this->area_border - $this->area_border; $new_img_height = $this->area_height - $this->area_border - $this->area_border; } $this->slice_from_x = ($this->area_border + $_REQUEST['zoombox_x']) / $_REQUEST['zoombox_factor']; $this->slice_from_y = ($this->area_border + $_REQUEST['zoombox_y']) / $_REQUEST['zoombox_factor']; $slice_width = $new_img_width / $_REQUEST['zoombox_factor']; $slice_height = $new_img_height / $_REQUEST['zoombox_factor']; $this->slice_to_x = $this->slice_from_x + $this->slice_width; $this->slice_to_y = $this->slice_from_y + $this->slice_height; // TODO: // - Operate also on PNG, TIFF etc. // - Support image magick // - Save file as new image! // - Optionally ask whether to only make a thumbnail from the extracted portion // PHP: int imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH) // Open the user's image. $img_res = imagecreatefromjpeg($this->img_name); // Init a blank picture to save the cropped image in. $new_img_res = imagecreatetruecolor($new_img_width, $new_img_height); // Crop the image based on user input, save the resulting image. If either action fails, report an error. if (!imagecopyresampled($new_img_res, $img_res, 0, 0, $this->slice_from_x, $this->slice_from_y, $new_img_width, $new_img_height, $slice_width, $slice_height) || !imageJpeg($new_img_res, $new_img_name, 90)) { $this->imgedit_smarty['image_error'] = true; } $backup = $this->increment($this->img_name); rename($this->img_name, $backup . '.backup'); rename($new_img_name, $this->img_name); $http_new_file = preg_replace('@^' . preg_quote($serendipity['serendipityPath'] . $serendipity['uploadPath']) . '@', '', $this->img_name); serendipity_makeThumbnail(basename($http_new_file), dirname($http_new_file) . '/'); $this->img_name = $new_img_name; $this->img_width = $new_img_width; $this->img_height = $new_img_height; } return true; }
function showRSS(&$eventData, $offset = 0) { global $serendipity; static $entries = array(); if (!isset($_REQUEST['gallery'])) { return false; } $limit = !empty($_REQUEST['limit']) ? (int) $_REQUEST['limit'] : $serendipity['RSSfetchLimit']; if (empty($limit)) { $limit = 15; } $dir = !empty($_REQUEST['picdir']) ? $_REQUEST['picdir'] : ''; $total = 0; $size = !empty($_REQUEST['feed_width']) ? (int) $_REQUEST['feed_width'] : $this->get_config('feed_width'); $hide_title = !empty($_REQUEST['hide_title']) ? true : false; $basepath = $serendipity['serendipityPath'] . $serendipity['uploadPath']; $baseurl = $serendipity['baseURL'] . $serendipity['uploadHTTPPath']; $lo = serendipity_db_bool($this->get_config('feed_linked_only')); $feed_body = serendipity_db_bool($this->get_config('feed_body')); $images = serendipity_fetchImagesFromDatabase($offset, $limit, $total, 'i.date', 'DESC', $dir); // Let's push the $images array into the destination $entries format. foreach ($images as $idx => $image) { if (count($entries) > $limit) { continue; } $filename = $image['name'] . '.' . $image['extension']; $thumbname = $image['name'] . '.' . $image['thumbnail_name'] . '.' . $image['extension']; $sourcefile = $basepath . $image['path'] . $filename; $thumbfile = $basepath . $image['path'] . $thumbname; $sourcefile_http = $baseurl . $image['path'] . $filename; $thumbfile_http = $baseurl . $image['path'] . $thumbname; // Creating temporary thumbnails if ($serendipity['thumbSize'] != $size) { $thumbname = $image['name'] . '.serendipityGallery.' . $image['extension']; $thumbfile = $serendipity['serendipityPath'] . PATH_SMARTY_COMPILE . '/' . $thumbname; $thumbfile_http = $serendipity['baseURL'] . PATH_SMARTY_COMPILE . '/' . $thumbname; if (!file_exists($thumbfile)) { serendipity_makeThumbnail($filename, $image['path'], $size, $thumbfile, true); } } $fdim = @serendipity_getimagesize($thumbfile, '', ''); $e = $this->fetchLinkedEntries($image['id'], $image['path'] . $filename, $image['path'] . $thumbname, true, $feed_body); if (is_array($e)) { $link = serendipity_archiveURL($e[0]['id'], $e[0]['title'], 'serendipityHTTPPath', true, array('timestamp' => $e[0]['timestamp'])); $lid = $e[0]['id']; } elseif ($lo) { // Images without links will be discarded continue; } else { $link = $sourcefile_http; $lid = $image['id']; } if ($feed_body && is_array($e)) { // Replace big image with thumbnail $body = preg_replace('@(["\'])[^"\']*' . preg_quote($image['path'] . $filename, '@') . '@imsU', '\\1' . $thumbfile_http, $e[0]['body']); // Kill possible width attributes of <img> tags to not screw up display $body = preg_replace('@(<img[^>]*)\\s*width\\s*=["\'][0-9]+["\']@imsU', '\\1', $body); $body = preg_replace('@(<img[^>]*)\\s*height\\s*=["\'][0-9]+["\']@imsU', '\\1', $body); } $body = '<a href="' . $link . '"><img src="' . $thumbfile_http . '" alt="" width="' . $fdim[0] . '" height="' . $fdim[1] . '" /></a>'; $entries[] = array('title' => $hide_title ? '' : $filename, 'entryid' => $lid, 'timestamp' => $image['date'], 'author' => $image['authorname'], 'body' => $body, 'extended' => '', 'authorid' => $image['authorid'], 'email' => $image['authorname'], 'category_name' => $image['path'], 'last_modified' => $image['date']); } if (count($entries) < $limit && count($images) == $limit) { $this->showRSS($eventData, $offset + $limit); } if ($offset == 0) { // We are Borg. Resistance is futile. Sue us. $GLOBALS['entries'] =& $entries; $GLOBALS['comments'] = false; $_GET['type'] = 'content'; } return true; }
function 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) { global $serendipity; if ($debug_file !== null || $debug) { $this->out("<br />\nRecognized inline attachment.<br />\n"); } // If no filename is present, give it the name file.time().txt if (isset($p->d_parameters['filename'])) { $filename = $p->d_parameters['filename']; //Skip Tmobile junk pix if ($tmobileflag && $adflag and $filename == 'dottedLine_350.gif' || $filename == 'dottedLine_600.gif' || $filename == 'spacer.gif' || $filename == 'masthead.jpg' || $filename == 'audio.gif' || $filename == 'video.gif') { return; } } elseif (isset($p->ctype_parameters['name'])) { $filename = $p->ctype_parameters['name']; } elseif (isset($p->ctype_secondary)) { $filename = 'file' . time() . '.' . $p->ctype_secondary; } else { $filename = 'file' . time() . '.txt'; } // Use makeFilename to get rid of spaces and other oddities $filename = serendipity_makeFilename($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 />'); return; } if (in_array($lext, $list_ignore)) { $this->out('<br />' . MF_MSG20 . '<br />'); return; } if ($p->ctype_primary == 'text' && $p->ctype_secondary == 'plain' && $plaintext_is_body_flag) { $bodytext = trim($this->decode($p->body, $p->ctype_parameters['charset'])); if (empty($bodytext)) { $this->out('<br />' . MF_MSG20 . '<br />'); return; } if ($firsttext && $plaintext_use_extended_flag) { $postex[] = '<p>' . $bodytext . '</p>'; } else { $postbody[] = '<p>' . $bodytext . '</p>'; $firsttext = true; } // Do not save plaintext attachments if selected to use them as body if ($debug_file !== null || $debug) { $this->out("<br />\nDiscarding saving plaintext attachment.<br />\n"); } return; } // Check for duplicate filename. Give dup file name file.time().dup.ext if (is_file($fullname)) { $this->out('<br />' . MF_MSG14 . $filename . "<br />"); $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); $info = @getimagesize($fullname); if ($o2flag && is_array($info) && $adflag && $info[0] == '74' && $info[1] == '31') { // Seem this is the O2 logo. We don't like it. Kill it. Take no prisoners. @unlink($fullname); return; } serendipity_makeThumbnail($filename, $maildir, false); serendipity_insertImageInDatabase($filename, $maildir, $authorid, NULL); $thumbname = $name . '.' . $serendipity['thumbSuffix'] . $ext; $ltype = strtolower($p->ctype_secondary); // Make sure images are displayed // $this->out( "Now we have to put the image into the Text <br />\n"); // Do we want to have a thumbnail or full picture? thumbnail_view if (in_array($ltype, $list_imagetype) or in_array($ext, $list_imageext)) { // We have an image here! if (!serendipity_db_bool($this->get_config('thumbnail_view', true))) { $displayed_file = $filename; $displayed_class = "full_popfetcherimage"; } else { $displayed_file = $thumbname; $displayed_class = "popfetcherimage"; } $attfile = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $maildir . $filename; $attlink = '<a class="' . $displayed_class . '" href="' . $attfile . '" target="_blank"><img src="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $maildir . $displayed_file . '" alt="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($this->stripsubject($subject)) : htmlspecialchars($this->stripsubject($subject), ENT_COMPAT, LANG_CHARSET)) . '" /></a>'; if ($this->inline_picture($p->headers['content-id'], $postbody, $postex, $attfile, $attlink)) { return true; } } else { $attlink = '<a class="popfetcherfile" href="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $maildir . $filename . '" target="_blank">' . $filename . '</a>'; } if ($debug_file !== null || $debug) { $this->out("Attachment return: " . htmlspecialchars($attlink) . ".<br />\n"); } // 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) { if ($debug_file !== null || $debug) { $this->out("Saving attachment to postbody.<br />\n"); } $postbody[] = $attlink; } else { if ($debug_file !== null || $debug) { $this->out("Saving attachment to postex.<br />\n"); } $postex[] = $attlink; $firsttext = true; } } else { if ($debug_file !== null || $debug) { $this->out("Saving attachment seperately.<br />\n"); } // Standard attachment mode $postattach[] = $attlink; } $firstattachment = true; $this->out('<br />' . MF_MSG13 . $filename . '<br />'); }