* @param int The ID of an media item
* @return array The media info data
*/
-function serendipity_fetchImageFromDatabase($id) {
+function serendipity_fetchImageFromDatabase($id, $mode = 'read') {
global $serendipity;
- $cond = array(
- 'and' => "WHERE id = " . (int)$id
- );
- serendipity_ACL_SQL($cond, false, 'directory');
+ if (is_array($id)) {
+ $cond = array(
+ 'and' => "WHERE i.id IN (" . implode(',', $id) . ")"
+ );
+ $single = false;
+ $assocKey = 'id';
+ $assocVal = false;
+ } else {
+ $cond = array(
+ 'and' => "WHERE i.id = " . (int)$id
+ );
+ $single = true;
+ $assocKey = false;
+ $assocVal = false;
+ }
- $rs = serendipity_db_query("SELECT i.*
+ if ($serendipity['dbType'] == 'postgres') {
+ $cond['group'] = '';
+ $cond['distinct'] = 'DISTINCT';
+ } else {
+ $cond['group'] = 'GROUP BY i.id';
+ $cond['distinct'] = '';
+ }
+
+ serendipity_ACL_SQL($cond, false, 'directory', $mode);
+
+ $rs = serendipity_db_query("SELECT {$cond['distinct']} i.id, i.name, i.extension, i.mime, i.size, i.dimensions_width, i.dimensions_height, i.date, i.thumbnail_name, i.authorid, i.path, i.hotlink
FROM {$serendipity['dbPrefix']}images AS i
{$cond['joins']}
- {$cond['and']}", true, 'assoc');
+ {$cond['and']}
+ {$cond['group']}", $single, 'assoc', false, $assocKey, $assocVal);
return $rs;
}
}
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}images WHERE id = ". (int)$id);
-
+ serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}mediaproperties WHERE mediaid = ". (int)$id);
}
/**
</tr>
<tr>
<?php
- $x = 0;
foreach ($serendipity['imageList'] as $k => $file) {
- ++$x; $preview = '';
- $sThumbSource = serendipity_getThumbNailPath($file['path'], $file['name'], $file['extension'], $file['thumbnail_name']);
- $img = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $sThumbSource;
- if (!isset($file['imgsrc'])) {
- $file['imgsrc'] = $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] . (!empty($file['thumbnail_name']) ? '.' . $file['thumbnail_name'] : '') . '.' . $file['extension'];
- }
- $i = @getimagesize($img);
- $is_image = serendipity_isImage($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;
}
- /* If it is an image, and the thumbnail exists */
- if ($is_image && file_exists($img)) {
- $preview .= '<img src="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $sThumbSource . '" border="0" title="' . $file['path'] . $file['name'] . '" alt="'. $file['name'] . '" />';
- if ($url) {
- $preview = '<a href="'. $url .'&serendipity[image]='. $file['id'] .'">'. $preview .'</a>';
- }
- } elseif ($is_image && $file['hotlink']) {
- $sizes = serendipity_calculate_aspect_size($file['dimensions_width'], $file['dimensions_height'], $serendipity['thumbSize']);
- $preview .= '<img src="' . $file['path'] . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" border="0" title="' . $file['path'] . '" alt="'. $file['name'] . '" />';
- if ($url) {
- $preview = '<a href="'. $url .'&serendipity[image]='. $file['id'] .'">'. $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');
- }
- $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) {
- $preview .= '<br /><a href="' . $url . '&serendipity[image]=' . $file['id'] . '">' . $file['name'] . '.' . $file['extension'] . '</a>';
- }
- $preview .= '</div>';
- }
-
-?>
- <td nowrap="nowrap" align="center" valign="<?php echo $manage ? 'top' : 'middle' ?>" width="<?php echo round(1/$lineBreak*100) ?>%" class="serendipity_admin_list_item serendipity_admin_list_item_<?php echo (($i % 2) ? 'even' : 'uneven') ?>">
-<?php
-if ( !$manage ) {
- echo $preview;
-} else { ?>
- <table width="100%" border="0" cellspacing="0" cellpadding="3">
- <tr>
- <td valign="top" width="16" rowspan="3">
-<?php
- if ($serendipity['authorid'] == $file['authorid'] || $file['authorid'] == '0' || serendipity_checkPermission('adminImagesMaintainOthers')) {
- $popupWidth = ($is_image ? ($file['dimensions_width'] + 20) : 600);
- $popupHeight = ($is_image ? ($file['dimensions_height'] + 20) : 500);
-?>
- <img class="serendipityImageButton" title="<?php echo MEDIA_FULLSIZE; ?>" alt="<?php echo MEDIA_FULLSIZE; ?>" src="<?php echo serendipity_getTemplateFile('admin/img/big_zoom.png') ?>" border="0" onclick="F1 = window.open('<?php echo ($file['hotlink'] ? $file['path'] : $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] . '.'. $file['extension']); ?>','Zoom','height=<?php echo $popupHeight; ?>,width=<?php echo $popupWidth; ?>,top='+ (screen.height-<?php echo $popupHeight ?>)/2 +',left='+ (screen.width-<?php echo $popupWidth ?>)/2 +',toolbar=no,menubar=no,location=no,resize=1,resizable=1<?php echo ($is_image ? '' : ',scrollbars=yes'); ?>');" /><br />
- <img class="serendipityImageButton" title="<?php echo MEDIA_RENAME; ?>" alt="<?php echo MEDIA_RENAME; ?>" src="<?php echo serendipity_getTemplateFile('admin/img/big_rename.png') ?>" border="0" onclick="rename('<?php echo $file['id']; ?>', '<?php echo addslashes($file['name']); ?>')" /><br />
- <?php if ($is_image && !$file['hotlink']) { ?><img class="serendipityImageButton" title="<?php echo IMAGE_RESIZE; ?>" alt="<?php echo IMAGE_RESIZE; ?>" src="<?php echo serendipity_getTemplateFile('admin/img/big_resize.png') ?>" border="0" onclick="location.href='?serendipity[adminModule]=images&serendipity[adminAction]=scaleSelect&serendipity[fid]=<?php echo $file['id']; ?>';" /><br /><?php } ?>
- <?php if ($is_image && !$file['hotlink']) { ?><a href="?serendipity[adminModule]=images&serendipity[adminAction]=rotateCCW&serendipity[fid]=<?php echo $file['id']; ?>"><img class="serendipityImageButton" title="<?php echo IMAGE_ROTATE_LEFT; ?>" alt="<?php echo IMAGE_ROTATE_LEFT; ?>" src="<?php echo serendipity_getTemplateFile('admin/img/big_rotate_ccw.png') ?>" border="0" /></a><br /><?php } ?>
- <?php if ($is_image && !$file['hotlink']) { ?><a href="?serendipity[adminModule]=images&serendipity[adminAction]=rotateCW&serendipity[fid]=<?php echo $file['id']; ?>"><img class="serendipityImageButton" title="<?php echo IMAGE_ROTATE_RIGHT; ?>" alt="<?php echo IMAGE_ROTATE_RIGHT; ?>" src="<?php echo serendipity_getTemplateFile('admin/img/big_rotate_cw.png') ?>" border="0" /></a><br /><?php } ?>
- <a href="?serendipity[adminModule]=images&serendipity[adminAction]=properties&serendipity[fid]=<?php echo $file['id']; ?>"><img class="serendipityImageButton" title="<?php echo MEDIA_PROP; ?>" alt="<?php echo MEDIA_PROP; ?>" src="<?php echo serendipity_getTemplateFile('admin/img/configure.png') ?>" border="0" /></a><br />
- <a href="?serendipity[adminModule]=images&serendipity[adminAction]=delete&serendipity[fid]=<?php echo $file['id']; ?>"><img class="serendipityImageButton" title="<?php echo MEDIA_DELETE; ?>" alt="<?php echo MEDIA_DELETE; ?>" src="<?php echo serendipity_getTemplateFile('admin/img/big_delete.png') ?>" border="0" /></a><br />
-<?php
- }
-?>
- </td>
- <td colspan="2">
- <div class="serendipity_media_filename" style="font-weight: bold; font-size: 8pt"><?php echo $file['name'] . '.' . $file['extension']; ?></div>
- <div class="serendipity_media_author" style="font-size: 8pt"><?php echo ($file['authorid'] != '0' ? $file['authorname'] : ''); ?></div>
- </td>
- </tr>
- <tr>
- <td align="center" colspan="2"><?php echo $preview ?></td>
- </tr>
- <tr>
- <td colspan="2" height="10" align="center" style="font-size: 8pt">
-<?php
- if ($is_image && !$file['hotlink']) {
- echo ORIGINAL_SHORT . ': ' . $file['dimensions_width'] . 'x' . $file['dimensions_height'] .', ';
- echo THUMBNAIL_SHORT . ': ' . $i[0] . 'x' . $i[1];
- } elseif ($file['hotlink']) {
- echo wordwrap($file['path'], 45, '<br />', 1);
- } else {
- echo SORT_ORDER_SIZE . ': ' . number_format(round($file['size']/1024, 2), NUMBER_FORMAT_DECIMALS, NUMBER_FORMAT_DECPOINT, NUMBER_FORMAT_THOUSANDS) . 'kb';
- }
-?>
- </td>
- </tr>
- </table>
-<?php } ?>
- </td>
-<?php
- // Newline?
- if ($x % $lineBreak == 0) {
-?>
- </tr>
- <tr>
-<?php
+ serendipity_prepareMedia($serendipity['imageList'][$k], $url);
}
+
+ serendipity_showMedia($serendipity['imageList'], $url, $manage, $lineBreak, true);
}
?>
</tr>
</table>
<?php
-}
} // End serendipity_displayImageList()
/**
return true;
}
+ $mirror = array();
+ serendipity_checkPropertyAccess($new_media, $mirror, 'read');
+
$dprops = explode(';', $serendipity['mediaProperties']);
$keywords = explode(';', $serendipity['mediaKeywords']);
foreach($new_media AS $idx => $media) {
$props =& serendipity_fetchMediaProperties($media['image_id']);
+
+ serendipity_prepareMedia($media['internal']);
+ serendipity_showMedia($file, $url, false, 1, false);
+
echo '<input type="hidden" name="serendipity[mediaProperties][' . $idx . '][image_id]" value="' . (int)$media['image_id'] . '" />' . "\n";
echo '<h3>' . MEDIA_PROP . '</h3>';
return false;
}
+ serendipity_checkPropertyAccess($serendipity['POST']['mediaProperties'], $serendipity['POST']['mediaKeywords'], 'write');
+
foreach($serendipity['POST']['mediaProperties'] AS $id => $media) {
serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}mediaproperties
WHERE mediaid = " . (int)$media['image_id'] . "
AND property_subgroup = ''
- AND (property_group = 'base_property'
- OR property_group = 'base_keyword')");
+ AND property_group = 'base_property'");
foreach($media AS $key => $val) {
if ($key == 'image_id') continue;
$q = sprintf("INSERT INTO {$serendipity['dbPrefix']}mediaproperties
}
foreach($serendipity['POST']['mediaKeywords'] AS $id => $keywords) {
+ serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}mediaproperties
+ WHERE mediaid = " . (int)$serendipity['POST']['mediaProperties'][$id]['image_id'] . "
+ AND property_subgroup = ''
+ AND property_group = 'base_keyword'");
+
foreach($keywords AS $keyword => $checked) {
$q = sprintf("INSERT INTO {$serendipity['dbPrefix']}mediaproperties
(mediaid, property_group, property_subgroup, property, value)
}
}
return $props;
+}
+
+/**
+ * Checks if properties to a specific image are allowed to be fetched
+ *
+ * @param array Array of image metadata
+ * @param array Array of additional image metadata
+ * @param string ACL toggle type ('read', 'write')
+ * @return array Stripped Array of image metadata
+ *
+ */
+function serendipity_checkPropertyAccess(&$new_media, &$additional, $mode = 'read') {
+ global $serendipity;
+
+ // Strip out images we don't have access to
+ $ids = array();
+ foreach($new_media AS $id => $item) {
+ $ids[] = $item['image_id'];
+ }
+
+ $valid_images = serendipity_fetchImageFromDatabase($ids, $mode);
+ foreach ($new_media AS $id => $media) {
+ if (!isset($valid_images[$media['image_id']])) {
+ unset($new_media[$id]);
+ unset($additional[$id]);
+ } else {
+ $new_media[$id]['internal'] = $valid_images[$media['image_id']];
+ }
+ }
+
+ return true;
+}
+
+/**
+ * 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']);
+ $img = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $sThumbSource;
+ if (!isset($file['imgsrc'])) {
+ $file['imgsrc'] = $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] . (!empty($file['thumbnail_name']) ? '.' . $file['thumbnail_name'] : '') . '.' . $file['extension'];
+ }
+ $file['dim'] = @getimagesize($img);
+ $file['is_image'] = serendipity_isImage($file);
+ $file['full_file'] = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $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($img)) {
+ $file['preview'] .= '<img src="' . $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $sThumbSource . '" border="0" title="' . $file['path'] . $file['name'] . '" alt="'. $file['name'] . '" />';
+ if ($url) {
+ $file['preview'] = '<a href="'. $url .'&serendipity[image]='. $file['id'] .'">'. $file['preview'] .'</a>';
+ }
+ } elseif ($file['is_image'] && $file['hotlink']) {
+ $sizes = serendipity_calculate_aspect_size($file['dimensions_width'], $file['dimensions_height'], $serendipity['thumbSize']);
+ $file['preview'] .= '<img src="' . $file['path'] . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" border="0" title="' . $file['path'] . '" alt="'. $file['name'] . '" />';
+ if ($url) {
+ $file['preview'] = '<a href="'. $url .'&serendipity[image]='. $file['id'] .'">'. $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'] .= '<br /><a href="' . $url . '&serendipity[image]=' . $file['id'] . '">' . $file['name'] . '.' . $file['extension'] . '</a>';
+ }
+ $file['preview'] .= '</div>';
+ }
+
+ $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;
+}
+
+/**
+ * Prints a media item
+ *
+ * @param array Array of image metadata
+ * @param string URL for maintenance tasks
+ * @param boolean Whether to show maintenance task items
+ * @param int how many media items to display per row
+ * @param boolean Enclose within a table cell?
+ * @return boolean
+ *
+ */
+function serendipity_showMedia(&$file, $url = '', $manage = false, $lineBreak = 3, $enclose = true) {
+ global $serendipity;
+
+ serendipity_smarty_init();
+ $media = array(
+ 'manage' => $manage,
+ 'lineBreak' => $lineBreak,
+ 'lineBreakP' => round(1/$lineBreak*100),
+ 'url' => $url,
+ 'enclose' => $enclose,
+ 'zoomIMG' => serendipity_getTemplateFile('admin/img/big_zoom.png'),
+ 'renameIMG' => serendipity_getTemplateFile('admin/img/big_rename.png'),
+ 'resizeIMG' => serendipity_getTemplateFile('admin/img/big_resize.png'),
+ 'rotatecwIMG' => serendipity_getTemplateFile('admin/img/big_rotate_ccw.png'),
+ 'rotateccwIMG' => serendipity_getTemplateFile('admin/img/big_rotate_cw.png'),
+ 'configureIMG' => serendipity_getTemplateFile('admin/img/configure.png'),
+ 'deleteIMG' => serendipity_getTemplateFile('admin/img/big_delete.png')
+
+ );
+ $media['files'] =& $file;
+
+ $serendipity['smarty']->assign('media', $media);
+ $serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_items.tpl', 'serendipityPath'));
+
+ return true;
}
\ No newline at end of file