/** * Recursively delete a directory tree * * @access public * @param string The originating directory * @param string The subdirectory * @param boolean Force deleting an directory even if there are files left in it? * @return true */ function serendipity_killPath($basedir, $directory = '', $forceDelete = false) { static $n = "<br />\n"; static $serious = true; if ($handle = @opendir($basedir . $directory)) { while (false !== ($file = @readdir($handle))) { if ($file != '.' && $file != '..') { if (is_dir($basedir . $directory . $file)) { serendipity_killPath($basedir, $directory . $file . '/', $forceDelete); } else { $filestack[$file] = $directory . $file; } } } @closedir($handle); printf(CHECKING_DIRECTORY . "<br />\n", $directory); // No, we just don't kill files the easy way. We sort them out properly from the database // and preserve files not entered therein. $files = serendipity_fetchImagesFromDatabase(0, 0, $total, false, false, $directory); if (is_array($files)) { echo "<ul>\n"; foreach ($files as $f => $file) { echo "<li>\n"; if ($serious) { serendipity_deleteImage($file['id']); } else { echo $file['name'] . '.' . $file['extension']; } echo "</li>\n"; unset($filestack[$file['name'] . '.' . $file['extension']]); unset($filestack[$file['name'] . (!empty($file['thumbnail_name']) ? '.' . $file['thumbnail_name'] : '') . '.' . $file['extension']]); } echo "</ul>\n"; } if (count($filestack) > 0) { if ($forceDelete) { echo "<ul>\n"; foreach ($filestack as $f => $file) { if ($serious && @unlink($basedir . $file)) { printf('<li>' . DELETING_FILE . $n . DONE . "</li>\n", $file); } else { printf('<li>' . DELETING_FILE . $n . ERROR . "</li>\n", $file); } } echo "</ul>\n"; } else { echo ERROR_DIRECTORY_NOT_EMPTY . $n; echo "<ul>\n"; foreach ($filestack as $f => $file) { echo '<li>' . $file . "</li>\n"; } echo "</ul>\n"; } } echo '<strong>'; if ($serious && !empty($directory) && !preg_match('@^.?/?$@', $directory) && @rmdir($basedir . $directory)) { printf(DIRECTORY_DELETE_SUCCESS . $n, $directory); } else { printf(DIRECTORY_DELETE_FAILED . $n, $directory); } echo '</strong>'; } return true; }
function generate_content_custom(&$title) { global $serendipity; $update = true; $rotate_time = $this->get_config('media_rotate_time'); $next_update = $this->get_config('media_next_update', ''); if (@(include_once "Cache/Lite.php")) { $cache_obj = new Cache_Lite(array('cacheDir' => $serendipity['serendipityPath'] . 'templates_c/', 'automaticSerialization' => true)); $cache_output = $cache_obj->get('mediasidebar_cache'); } else { $cache_output = $this->get_config('media_cache_output', ''); } if ($rotate_time != 0) { if ($next_update > time()) { $update = false; } else { $next_update = $this->calc_update_time($rotate_time, $next_update); $this->set_config('media_next_update', $next_update); } } $title = $this->get_config('title', $this->title); if ($update || $cache_output == '') { $output_str = ''; if ($this->get_config('media_image_strict') == 'yes') { $strict = true; } else { $strict = false; } if ($this->get_config('media_hotlinks_only', 'no') == 'yes') { $dir_extension = $this->get_config('media_hotlink_base', ''); if ($dir_extension != '') { $dir_extension = $dir_extension . '%'; } $directory = "http://%" . $dir_extension; $strict = false; } else { $directory = $this->get_config('media_base_directory'); } if (version_compare((double) $serendipity['version'], '1.1', '>=')) { if ($directory == 'gallery') { $directory = ''; } $images_all = serendipity_fetchImagesFromDatabase(0, 0, $total, false, false, $directory, '', '', array(), $strict); } else { $images_all = $this->mediasidebar_getimage($directory, $strict); } $number = $this->get_config('media_number_images'); $total_count = count($images_all); if ($total_count < $number) { $number = $total_count; } $images = array(); $random_check = array(); for ($counter = 0; $counter < $number; $counter += 1) { $checkit = rand(0, $total_count - 1); while (in_array($checkit, $random_check)) { $checkit = rand(0, $total_count); } $random_check[] = $checkit; $images[] = $images_all[$checkit]; } $width_test = $this->get_config('media_fixed_width'); if ($width_test > 0) { $width_str = 'width:' . $width_test . 'px;'; } if (is_array($images)) { $output_str .= $this->get_config('media_intro'); foreach ($images as $image) { if (isset($image['name'])) { if ($image['hotlink'] == 1) { $thumb_path = $image_path = $image['path']; } else { $image_path = $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $image['path'] . $image['name'] . '.' . $image['extension']; $thumb_path = $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $image['path'] . $image['name'] . '.' . $image['thumbnail_name'] . '.' . $image['extension']; if (!serendipity_isImage($image)) { $thumb_path = serendipity_getTemplateFile('admin/img/mime_unknown.png'); $width_str = ''; } } $output_str .= '<div style="padding-top: 5px;">'; switch ($this->get_config("media_linkbehavior")) { case 'entry': $e = $this->fetchLinkedEntries($image['id'], $image_path, $thumb_path, true); if (is_array($e)) { $link = serendipity_archiveURL($e[0]['id'], $e[0]['title'], 'serendipityHTTPPath', true, array('timestamp' => $e[0]['timestamp'])); } else { $link = $image_path; } $output_str .= '<a href="' . $link . '" title="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($e[0]['title']) : htmlspecialchars($e[0]['title'], ENT_COMPAT, LANG_CHARSET)) . '"><img style="border: 0px; ' . $width_str . '" src="' . $thumb_path . '" alt="" /></a>'; break; case 'popup': $output_str .= '<a href="' . $image_path . '" onclick="F1 = window.open(\'' . $image_path . '\',\'Zoom\',\'height=' . $image['dimensions_height'] . ',width=' . $image['dimensions_width'] . ',top=298,left=354,toolbar=no,menubar=no,location=no,resize=1,resizable=1,scrollbars=yes\'); return false;"><img style="border: 0px; ' . $width_str . '" src="' . $thumb_path . '" alt="" /></a>'; break; case 'url': $output_str .= '<a href="' . $this->get_config('media_url') . '"><img style="border: 0px; ' . $width_str . '" src="' . $thumb_path . '" alt="" /></a>'; break; case 'gallery': $gallery_str = $this->get_config('media_gal_permalink'); if (strstr($gallery_str, '?')) { $gallery_str = $gallery_str . '&serendipity[image]=' . $image['id']; } else { $gallery_str = $gallery_str . '?serendipity[image]=' . $image['id']; } $output_str .= '<a href="' . $gallery_str . '"><img style="border: 0px; ' . $width_str . '" src="' . $thumb_path . '" alt="" /></a>'; break; case 'inpage': default: $output_str .= '<a ' . $this->get_config('media_lightbox', '') . ' href="' . $image_path . '"><img style="border: 0px; ' . $width_str . '" src="' . $thumb_path . '" alt="" /></a>'; break; } $output_str .= '</div>'; } } $output_str .= $this->get_config('media_summery'); } else { $output_str = 'Error accessing images.'; } if (class_exists('Cache_Lite') && is_object($cache_obj)) { $cache_obj->save($output_str, 'mediasidebar_cache'); } else { $this->set_config('media_cache_output', $output_str); } } else { $output_str = $cache_output; } echo $output_str; }
/** * Recursively delete a directory tree * * @access public * @param string The originating directory * @param string The subdirectory * @param boolean Force deleting an directory even if there are files left in it? * @return true */ function serendipity_killPath($basedir, $directory = '', $forceDelete = false) { static $serious = true; if ($handle = @opendir($basedir . $directory)) { while (false !== ($file = @readdir($handle))) { if ($file != '.' && $file != '..') { if (is_dir($basedir . $directory . $file)) { serendipity_killPath($basedir, $directory . $file . '/', $forceDelete); } else { $filestack[$file] = $directory . $file; } } } @closedir($handle); echo '<span class="msg_notice"><span class="icon-info-circled"></span> '; printf(CHECKING_DIRECTORY, $directory); echo "</span>"; // No, we just don't kill files the easy way. We sort them out properly from the database // and preserve files not entered therein. $files = serendipity_fetchImagesFromDatabase(0, 0, $total, false, false, $directory); if (is_array($files)) { echo "<ul class='plainList'>\n"; foreach ($files as $f => $file) { echo "<li>\n"; if ($serious) { echo serendipity_deleteImage($file['id']); } else { echo $file['name'] . (empty($file['extension']) ? '' : '.' . $file['extension']); } echo "</li>\n"; unset($filestack[$file['name'] . (empty($file['extension']) ? '' : '.' . $file['extension'])]); unset($filestack[$file['name'] . (!empty($file['thumbnail_name']) ? '.' . $file['thumbnail_name'] : '') . (empty($file['extension']) ? '' : '.' . $file['extension'])]); } echo "</ul>\n"; } if (count($filestack) > 0) { if ($forceDelete) { echo "<ul class='plainList'>\n"; foreach ($filestack as $f => $file) { if ($serious && @unlink($basedir . $file)) { printf('<li><span class="msg_success"><span class="icon-ok-circled"></span> ' . DELETING_FILE . ' ' . DONE . "</span></li>\n", $file); } else { printf('<li><span class="msg_error"><span class="icon-attention-circled"></span> ' . DELETING_FILE . ' ' . ERROR . "</span></li>\n", $file); } } echo "</ul>\n"; } else { echo '<span class="msg_error"><span class="icon-attention-circled"></span> ' . ERROR_DIRECTORY_NOT_EMPTY . '</span>'; echo "<ul>\n"; foreach ($filestack as $f => $file) { echo '<li>' . $file . "</li>\n"; } echo "</ul>\n"; } } if ($serious && !empty($directory) && !preg_match('@^.?/?$@', $directory) && @rmdir($basedir . $directory)) { echo '<span class="msg_success"><span class="icon-ok-circled"></span> '; printf(DIRECTORY_DELETE_SUCCESS, $directory); echo "</span>\n"; } else { echo '<span class="msg_error"><span class="icon-attention-circled"></span> '; printf(DIRECTORY_DELETE_FAILED, $directory); echo "</span>\n"; } } 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; }