From: garvinhicking Date: Tue, 11 Apr 2006 13:34:13 +0000 (+0000) Subject: TODO items: X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=7f2a67d9c37341338e3f6940d8f473181c251051;p=s9y.git TODO items: - Smartify image selector - Insert Image ID from javascript - Ensure ACL/permissions --- diff --git a/deployment/serendipity_editor.js b/deployment/serendipity_editor.js index 67d50c6..d8c6c72 100644 --- a/deployment/serendipity_editor.js +++ b/deployment/serendipity_editor.js @@ -225,14 +225,19 @@ function serendipity_imageSelector_done(textarea) styled = true; } + imgID = 0; + if (f['imgID']) { + imgID = f['imgID'].value; + } + floating = 'center'; if (f['serendipity[align]'][0].checked == true) { - img = "\"\""; + img = "\"\""; } else if (f['serendipity[align]'][1].checked == true) { - img = "\"\""; + img = "\"\""; floating = 'left'; } else if (f['serendipity[align]'][2].checked == true) { - img = "\"\""; + img = "\"\""; floating = 'right'; } diff --git a/docs/NEWS b/docs/NEWS index 426df1d..ee686c4 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -1,6 +1,6 @@ # $Id$ -Version 1.1-alpha1() +Version 1.1-alpha4() ------------------------------------------------------------------------ * Support template/theme/style-specific options via "config.inc.php" @@ -10,10 +10,6 @@ Version 1.1-alpha1() * Make media manager able to store media properties (garvinhicking) TODO: - - Also delete properties when deleting an image - - Enforce permissions on readable files via ACL queries on the given directory/path - - Make JS emit the image ID somewhere in the tag - - Make media selector smartyfied - Show more existing properties in edit interface [see TODO in file] - Read/Parse EXIF metadata, ask which to import [config option?] - Search/Filter for specific properties/keywords diff --git a/include/admin/plugins.inc.php b/include/admin/plugins.inc.php index b9a9a6a..e0f1630 100644 --- a/include/admin/plugins.inc.php +++ b/include/admin/plugins.inc.php @@ -335,6 +335,9 @@ if (isset($_GET['serendipity']['plugin_to_conf'])) { } } ?> + + + "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; } @@ -225,7 +247,7 @@ function serendipity_deleteImage($id) { } serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}images WHERE id = ". (int)$id); - + serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}mediaproperties WHERE mediaid = ". (int)$id); } /** @@ -1400,111 +1422,21 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa $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 .= ''. $file['name'] . ''; - if ($url) { - $preview = ''. $preview .''; - } - } elseif ($is_image && $file['hotlink']) { - $sizes = serendipity_calculate_aspect_size($file['dimensions_width'], $file['dimensions_height'], $serendipity['thumbSize']); - $preview .= ''. $file['name'] . ''; - if ($url) { - $preview = ''. $preview .''; - } - /* 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 .= ''. $file['mime'] .'
- ' . (($file['hotlink']) ? MEDIA_HOTLINKED : $file['mime']) .' -'; - if ($url) { - $preview .= '
' . $file['name'] . '.' . $file['extension'] . ''; - } - $preview .= ''; - } - -?> - - - - - - - - - - - - - -
- - <?php echo MEDIA_FULLSIZE; ?>
- <?php echo MEDIA_RENAME; ?>
- <?php echo IMAGE_RESIZE; ?>
- <?php echo IMAGE_ROTATE_LEFT; ?>
- <?php echo IMAGE_ROTATE_RIGHT; ?>
- <?php echo MEDIA_PROP; ?>
- <?php echo MEDIA_DELETE; ?>
- -
-
-
-
-', 1); - } else { - echo SORT_ORDER_SIZE . ': ' . number_format(round($file['size']/1024, 2), NUMBER_FORMAT_DECIMALS, NUMBER_FORMAT_DECPOINT, NUMBER_FORMAT_THOUSANDS) . 'kb'; - } -?> -
- - - - - - $media) { $props =& serendipity_fetchMediaProperties($media['image_id']); + + serendipity_prepareMedia($media['internal']); + serendipity_showMedia($file, $url, false, 1, false); + echo '' . "\n"; echo '

' . MEDIA_PROP . '

'; @@ -2133,12 +2072,13 @@ function serendipity_parsePropertyForm() { 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 @@ -2152,6 +2092,11 @@ function serendipity_parsePropertyForm() { } 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) @@ -2193,4 +2138,139 @@ function &serendipity_fetchMediaProperties($id) { } } 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'] .= ''. $file['name'] . ''; + if ($url) { + $file['preview'] = ''. $file['preview'] .''; + } + } elseif ($file['is_image'] && $file['hotlink']) { + $sizes = serendipity_calculate_aspect_size($file['dimensions_width'], $file['dimensions_height'], $serendipity['thumbSize']); + $file['preview'] .= ''. $file['name'] . ''; + if ($url) { + $file['preview'] = ''. $file['preview'] .''; + } + /* 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'] .= ''. $file['mime'] .'
- ' . (($file['hotlink']) ? MEDIA_HOTLINKED : $file['mime']) .' -'; + if ($url) { + $file['preview'] .= '
' . $file['name'] . '.' . $file['extension'] . ''; + } + $file['preview'] .= ''; + } + + $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, '
', 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 diff --git a/include/functions_plugins_admin.inc.php b/include/functions_plugins_admin.inc.php index bfa9933..cfe8703 100644 --- a/include/functions_plugins_admin.inc.php +++ b/include/functions_plugins_admin.inc.php @@ -79,6 +79,7 @@ function show_plugins($event_only = false) $plugin_placements = array('left', 'right', 'hide'); } + $total = 0; foreach ($plugin_placements as $plugin_placement) { $plugins = serendipity_plugin_api::enum_plugins($plugin_placement); @@ -88,6 +89,7 @@ function show_plugins($event_only = false) $sort_idx = 0; foreach ($plugins as $plugin_data) { + $total++; $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid']); $key = urlencode($plugin_data['name']); $is_plugin_owner = ($plugin_data['authorid'] == $serendipity['authorid'] || serendipity_checkPermission('adminPluginsMaintainOthers')); @@ -174,6 +176,9 @@ function show_plugins($event_only = false) } } ?> + + +
@@ -310,7 +315,7 @@ function serendipity_plugin_config(&$plugin, &$bag, &$name, &$desc, &$config_nam $value = $plugin->get_config($config_item, false, true); } } - + if (isset($_POST['serendipity'][$postkey][$config_item])) { if (is_array($_POST['serendipity'][$postkey][$config_item])) { $hvalue = $_POST['serendipity'][$postkey][$config_item]; @@ -348,7 +353,7 @@ function serendipity_plugin_config(&$plugin, &$bag, &$name, &$desc, &$config_nam } else { $selected_options = array($hvalue => $hvalue); } - + $pre_selected = (array)$cbag->get('select_preselected'); $select_size = $cbag->get('select_size'); $select = $cbag->get('select_values'); @@ -499,7 +504,7 @@ function serendipity_plugin_config(&$plugin, &$bag, &$name, &$desc, &$config_nam case 'hidden': ?>
@@ -555,6 +560,6 @@ function serendipity_plugin_config(&$plugin, &$bag, &$name, &$desc, &$config_nam "; + img = "\"\""; } else if (f['serendipity[align]'][1].checked == true) { - img = "\"\""; + img = "\"\""; floating = 'left'; } else if (f['serendipity[align]'][2].checked == true) { - img = "\"\""; + img = "\"\""; floating = 'right'; } diff --git a/templates/default/admin/media_items.tpl b/templates/default/admin/media_items.tpl new file mode 100644 index 0000000..655ff10 --- /dev/null +++ b/templates/default/admin/media_items.tpl @@ -0,0 +1,50 @@ +{foreach from=$media.files item="file" name="mediafiles"} + {if $media.enclose} + + {/if} + + {if NOT $media.manage} + {$file.preview} + {else} + + + + + + + + + + + +
+ {if $file.is_editable} + {$CONST.MEDIA_FULLSIZE}
+ {$CONST.MEDIA_RENAME}
+ {if $file.is_image AND NOT $file.hotlink}{$CONST.IMAGE_RESIZE}
{/if} + {if $file.is_image AND NOT $file.hotlink}{$CONST.IMAGE_ROTATE_LEFT}
{/if} + {if $file.is_image AND NOT $file.hotlink}{$CONST.IMAGE_ROTATE_RIGHT}
{/if} + {$CONST.MEDIA_PROP}
+ {$CONST.MEDIA_DELETE}
+ {/if} +
+
{$file.name}.{$file.extension}
+
{if $file.authorid != 0}{$file.authorname}{else}
{/if}
+
{$file.preview}
+ {if $file.hotlink} + {$file.nice_hotlink} + {else} + {if $file.is_image} + {$CONST.ORIGINAL_SHORT}: {$file.dimensions_width}x{$file.dimensions_height}, + {$CONST.THUMBNAIL_SHORT}: {$file.dim.0}x{$file.dim.1} + {/if} +
{$file.nice_size}kb + {/if} +
+ {/if} + + + {if $media.enclose AND (($smarty.foreach.mediafiles.iteration % $media.lineBreak) == 0)} + + {/if} +{/foreach} \ No newline at end of file