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; }
/** * Prepare a media item for showing * * @param array Array of image metadata * @param string URL for maintenance tasks * @return bool * */ function serendipity_prepareMedia(&$file, $url = '') { global $serendipity; static $full_perm = null; if ($full_perm === null) { $full_perm = serendipity_checkPermission('adminImagesMaintainOthers'); } $sThumbSource = serendipity_getThumbNailPath($file['path'], $file['name'], $file['extension'], $file['thumbnail_name']); $file['full_thumb'] = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $sThumbSource; $file['full_thumbHTTP'] = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $sThumbSource; if ($file['hotlink']) { $file['full_file'] = $file['path']; $file['show_thumb'] = $file['path']; if (!isset($file['imgsrc'])) { $file['imgsrc'] = $file['show_thumb']; } } else { $file['full_file'] = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] . '.' . $file['extension']; $file['show_thumb'] = $file['full_thumbHTTP']; if (!isset($file['imgsrc'])) { $file['imgsrc'] = $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] . (!empty($file['thumbnail_name']) ? '.' . $file['thumbnail_name'] : '') . '.' . $file['extension']; } } // Detect PDF thumbs if (file_exists($file['full_thumb'] . '.png')) { $file['full_thumb'] .= '.png'; $file['full_thumbHTTP'] .= '.png'; $file['show_thumb'] .= '.png'; $sThumbSource .= '.png'; } if (empty($file['realname'])) { $file['realname'] = $file['name'] . '.' . $file['extension']; } $file['diskname'] = $file['name'] . '.' . $file['extension']; $file['links'] = array('imagelinkurl' => $file['full_file']); $file['dim'] = @getimagesize($file['full_thumb'], $file['thumb_header']); $file['dim_orig'] = @getimagesize($serendipity['serendipityPath'] . $file['full_file'], $file['header']); $file['is_image'] = serendipity_isImage($file); if ($file['is_image']) { $file['mediatype'] = 'image'; } elseif (0 === strpos(strtolower($file['displaymime']), 'video/') || 0 === strpos(strtolower($file['displaymime']), 'application/x-shockwave')) { $file['mediatype'] = 'video'; } elseif (0 === strpos(strtolower($file['displaymime']), 'audio/') || 0 === strpos(strtolower($file['displaymime']), 'application/vnd.rn-') || 0 === strpos(strtolower($file['displaymime']), 'application/ogg')) { $file['mediatype'] = 'audio'; } elseif (0 === strpos(strtolower($file['displaymime']), 'text/')) { $file['mediatype'] = 'document'; } elseif (preg_match('@application/(pdf|rtf|msword|msexcel|excel|x-excel|mspowerpoint|postscript|vnd\\.ms*|powerpoint)@i', $file['displaymime'])) { $file['mediatype'] = 'document'; } elseif (preg_match('@application/(java-archive|zip|gzip|arj|x-bzip|x-bzip2|x-compressed|x-gzip|x-stuffit)@i', $file['displaymime'])) { $file['mediatype'] = 'archive'; } else { $file['mediatype'] = 'binary'; } $file['realfile'] = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . '.' . $file['extension']; if ($full_perm || $serendipity['authorid'] == $file['authorid'] || $file['authorid'] == '0') { $file['is_editable'] = true; } else { $file['is_editable'] = false; } /* If it is an image, and the thumbnail exists */ if ($file['is_image'] && file_exists($file['full_thumb'])) { $file['thumbWidth'] = $file['dim'][0]; $file['thumbHeight'] = $file['dim'][1]; $file['preview'] .= '<img src="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $sThumbSource . '" border="0" title="' . $file['path'] . $file['name'] . '" alt="' . $file['realname'] . '" />'; if ($url) { $file['preview_url'] = $url . '&serendipity[image]=' . $file['id']; $file['preview'] = '<a href="' . $file['preview_url'] . '">' . $file['preview'] . '</a>'; } } elseif ($file['is_image'] && $file['hotlink']) { $sizes = serendipity_calculate_aspect_size($file['dimensions_width'], $file['dimensions_height'], $serendipity['thumbSize'], $serendipity['thumbConstraint']); $file['thumbWidth'] = $sizes[0]; $file['thumbHeight'] = $sizes[1]; $file['preview'] .= '<img src="' . $file['path'] . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" border="0" title="' . $file['path'] . '" alt="' . $file['realname'] . '" />'; if ($url) { $file['preview_url'] = $url . '&serendipity[image]=' . $file['id']; $file['preview'] = '<a href="' . $file['preview_url'] . '">' . $file['preview'] . '</a>'; } /* If it's not an image, or the thumbnail does not exist */ } else { $mimeicon = serendipity_getTemplateFile('admin/img/mime_' . preg_replace('@[^a-z0-9\\-\\_]@i', '-', $file['mime']) . '.png'); if (!$mimeicon) { $mimeicon = serendipity_getTemplateFile('admin/img/mime_unknown.png'); } $file['preview'] .= '<img src="' . $mimeicon . '" title="' . $file['path'] . $file['name'] . ' (' . $file['mime'] . ')" alt="' . $file['mime'] . '" /><br /><span style="font-weight: bold; font-size: 8pt">- ' . ($file['hotlink'] ? MEDIA_HOTLINKED : $file['mime']) . ' -</span>'; if ($url) { $file['preview_url'] = $url . '&serendipity[image]=' . $file['id']; $file['preview'] .= '<br /><a href="' . $file['preview_url'] . '">' . $file['name'] . '.' . $file['extension'] . '</a>'; } } $file['popupWidth'] = $file['is_image'] ? $file['dimensions_width'] + 20 : 600; $file['popupHeight'] = $file['is_image'] ? $file['dimensions_height'] + 20 : 500; if ($file['hotlink']) { $file['nice_hotlink'] = wordwrap($file['path'], 45, '<br />', 1); } $file['nice_size'] = number_format(round($file['size'] / 1024, 2), NUMBER_FORMAT_DECIMALS, NUMBER_FORMAT_DECPOINT, NUMBER_FORMAT_THOUSANDS); return true; }
function displayImage($id, $orderby, $order) { global $serendipity; $extended_data = array(); $base_directory = $this->get_config('base_directory'); $file = serendipity_fetchImageFromDatabase($id); $file['link'] = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] . '.' . $file['extension']; $test_string = $serendipity['serendipityPath'] . $serendipity['uploadHTTPPath'] . $base_directory; $path_len = strlen($test_string); $pic_string = substr($serendipity['serendipityPath'] . $serendipity['uploadHTTPPath'] . $file['path'], 0, $path_len); if (isset($file['id'])) { $file['size_txt'] = round($file['size'] / 1024); $file['is_image'] = serendipity_isImage($file); $max_width = $this->get_config('image_width', 480); if ($file['dimensions_width'] > $max_width && $max_width != 0) { $file['alt_width'] = $max_width; $file['alt_height'] = round($max_width / $file['dimensions_width'] * $file['dimensions_height']); } else { $file['alt_width'] = $file['dimensions_width']; $file['alt_height'] = $file['dimensions_height']; } if ($this->get_config('image_strict') == 'yes') { $images = serendipity_fetchImagesFromDatabase($lower_limit, $images_per_page, $total, $orderby, $order, $file['path'], '', '', array(), true); } else { $images = serendipity_fetchImagesFromDatabase($lower_limit, $images_per_page, $total, $orderby, $order, $file['path']); } $extended_data = serendipity_fetchMediaProperties($id); $base_directory = str_replace('gallery', '', $base_directory); $previous_attempt = -1; $previous_id = -1; $next_id = -1; if (is_array($images)) { $stop = false; $onecount = false; while ((list($f, $image) = each($images)) && !$stop) { if ($image['id'] == $file['id']) { $path = $image['path']; $previous_id = $previous_attempt; $onecount = true; } else { if ($onecount == true) { $next_id = $image['id']; $stop = true; } else { $previous_attempt = $image['id']; } } } } $gallery_array = explode('/', $path); foreach ($gallery_array as $f => $gallery) { $gallery_path = $gallery_path . $gallery . "/"; if ($gallery_path != $base_directory) { $path_array[$gallery]['path'] = $gallery_path; $path_array[$gallery]['name'] = $gallery; } } // EXIF DATA if ($this->get_config('exif_show_data') == 'yes') { // If any exif tags that are available. $filepath = $serendipity['serendipityPath'] . $serendipity['uploadHTTPPath'] . $file['path']; $exif_data = $this->getExifTags($filepath, $file['name'], $file['extension']); $exifsettings_one = $this->get_config('exif_data', $this->makeExifSelector()); // Create array of exif display settings for main information table. $exif_arr = explode(',', $exifsettings_one); foreach ($exif_arr as $key => $value) { $display = explode('-', $exif_arr[$key]); $exif_display_one[$display[0]] = $display[1]; } $data_written = false; $exif_output .= '<div class="all_img_info">'; $exif_output .= '<div class="exif_info_row"><div class="exif_info_head"><strong>' . PLUGIN_EVENT_USERGALLERY_EXIFDATA_ADDITIONALDATA . '</strong></div></div>'; foreach ($exif_data as $tag => $value) { if ($value != 'Unknown' && $exif_display_one[$tag] == 'yes') { $data_written = true; $exif_output .= '<div class="exif_info_row"><span class="exif_info_tag">' . $tag . '</span><span class="exif_info">' . $value . '</span></div>'; } } if (!$data_written) { $exif_output .= '<div class="exif_info_row"><strong>' . PLUGIN_EVENT_USERGALLERY_EXIFDATA_NOADDITIONALDATA . '</strong></div>'; } $exif_output .= '</div>'; } // END EXIF DATA //Show Media Library Properties if ($this->get_config('show_media_properties', 'no') == 'yes') { if (is_array($extended_data) && isset($extended_data['base_property'])) { $extended_data = array_merge($extended_data['base_property'], (array) $extended_data['base_metadata']); } else { $extended_data = array(); } $extended_data_out = array(); $extended_output = explode(';', $this->get_config('media_properties', 'COPYRIGHT:Copyright;TITLE:Title;COMMENT2:Comment')); foreach ($extended_output as $option) { $option = explode(':', $option); foreach ($extended_data as $ex_name => $ex_data) { if ($ex_name == $option[0] && isset($option[1]) && $ex_data != '') { $extended_data_out[] = array('name' => $option[1], 'value' => $ex_data); if ($ex_name == 'TITLE' && $ex_data != '') { $file['title'] = $ex_data; } } } } } if (!isset($file['title'])) { $file['title'] = $file['name']; } if (serendipity_db_bool($this->get_config('linked_entries'))) { $_filename = $file['name'] . '.' . $file['extension']; $_thumbname = $file['name'] . '.' . $file['thumbnail_name'] . '.' . $file['extension']; $e = $this->fetchLinkedEntries($file['id'], $file['path'] . $_filename, $file['path'] . $_thumbname); if (is_array($e)) { $file['entries'] = array(); foreach ($e as $_item) { $file['entries'][] = array('href' => serendipity_archiveURL($_item['id'], $_item['title'], 'serendipityHTTPPath', true, array('timestamp' => $_item['timestamp'])), 'title' => $_item['title']); } } if (class_exists('serendipity_event_staticpage')) { $s = $this->fetchStaticPages($file['id'], $file['path'] . $_filename, $file['path'] . $_thumbname); if (is_array($s)) { $file['staticpage_results'] = array(); foreach ($s as $_item) { $staticpage_title = $_item['headline']; if ($staticpage_title == '') { $staticpage_title = $_item['pagetitle']; } if ($serendipity['rewrite'] == 'none') { $staticpage_link = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?serendipity[subpage]=' . $_item['subpage']; } else { $staticpage_link = $_item['permalink']; } $file['staticpage_results'][] = array('href' => $staticpage_link, 'title' => $staticpage_title); } } } } unset($path_array['']); $serendipity['smarty']->assign(array('plugin_usergallery_title' => $this->get_config('title'), 'plugin_usergallery_nextid' => $next_id, 'plugin_usergallery_gallery_breadcrumb' => $path_array, 'plugin_usergallery_previousid' => $previous_id, 'plugin_usergallery_xtra_info' => $exif_output, 'plugin_usergallery_extended_info' => $extended_data_out, 'plugin_usergallery_file' => $file)); $content = $this->parseTemplate('plugin_usergallery_imagedisplay.tpl'); echo $content; return true; } else { echo "Invalid file."; return false; } }