From f918bf46ba51f1ff9ea3ddfa15ff224bca6b87db Mon Sep 17 00:00:00 2001 From: garvinhicking Date: Thu, 13 Apr 2006 18:25:55 +0000 Subject: [PATCH] Smartify "You chose..." page. Might not fully work yet. --- include/functions_images.inc.php | 66 ++-- include/functions_smarty.inc.php | 26 ++ serendipity_admin_image_selector.php | 390 ++++------------------- templates/default/admin/media_choose.tpl | 276 ++++++++++++++++ 4 files changed, 404 insertions(+), 354 deletions(-) create mode 100644 templates/default/admin/media_choose.tpl diff --git a/include/functions_images.inc.php b/include/functions_images.inc.php index 2419195..e5a62db 100644 --- a/include/functions_images.inc.php +++ b/include/functions_images.inc.php @@ -1157,9 +1157,10 @@ function serendipity_calculate_aspect_size($width, $height, $newwidth) { * @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 - * @return null + * @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) { +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; @@ -1352,14 +1353,15 @@ function serendipity_displayImageList($page = 0, $lineBreak = NULL, $manage = fa 'linkNext' => $linkNext, 'linkPrevious' => $linkPrevious ); - serendipity_showMedia( + return serendipity_showMedia( $serendipity['imageList'], $paths, $url, $manage, $lineBreak, true, - $smarty_vars + $smarty_vars, + $smarty_display ); } // End serendipity_displayImageList() @@ -1950,7 +1952,7 @@ function serendipity_showPropertyForm(&$new_media, $keywordsPerBlock = 3, $is_ed 'keywords' => $keywords, 'dprops' => $dprops ); - serendipity_showMedia( + return serendipity_showMedia( $show, $mirror, $url, @@ -1958,8 +1960,6 @@ function serendipity_showPropertyForm(&$new_media, $keywordsPerBlock = 3, $is_ed 1, false, $smarty_vars); - - return true; } /** @@ -2111,14 +2111,29 @@ function serendipity_prepareMedia(&$file, $url = '') { $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['header']); + $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']; + } + } + + $file['links'] = array('imagelinkurl' => $file['full_file']); + + $file['dim'] = @getimagesize($file['full_thumb'], $file['header']); $file['is_image'] = serendipity_isImage($file); - $file['full_file'] = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] . '.'. $file['extension']; + $file['realfile'] = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . '.'. $file['extension']; if ($full_perm || $serendipity['authorid'] == $file['authorid'] || $file['authorid'] == '0') { @@ -2128,13 +2143,17 @@ function serendipity_prepareMedia(&$file, $url = '') { } /* If it is an image, and the thumbnail exists */ - if ($file['is_image'] && file_exists($img)) { + if ($file['is_image'] && file_exists($file['full_thumb'])) { + $file['thumbWidth'] = $file['dim'][0]; + $file['thumbHeight'] = $file['dim'][1]; $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['thumbWidth'] = $sizes[0]; + $file['thumbHeight'] = $sizes[1]; $file['preview'] .= ''. $file['name'] . ''; if ($url) { $file['preview'] = ''. $file['preview'] .''; @@ -2171,10 +2190,11 @@ function serendipity_prepareMedia(&$file, $url = '') { * @param int how many media items to display per row * @param boolean Enclose within a table cell? * @param array Additional Smarty variables - * @return boolean + * @param boolean If TRUE, will echo Smarty output. + * @return string Smarty block name * */ -function serendipity_showMedia(&$file, &$paths, $url = '', $manage = false, $lineBreak = 3, $enclose = true, $smarty_vars = array()) { +function serendipity_showMedia(&$file, &$paths, $url = '', $manage = false, $lineBreak = 3, $enclose = true, $smarty_vars = array(), $smarty_display = true) { global $serendipity; $form_hidden = ''; @@ -2219,13 +2239,19 @@ function serendipity_showMedia(&$file, &$paths, $url = '', $manage = false, $lin if ($enclose) { serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl'); - $serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_pane.tpl', 'serendipityPath')); + $block = 'admin/media_pane.tpl'; + if ($smarty_display) { + $serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_pane.tpl', 'serendipityPath')); + } } else { serendipity_smarty_fetch('MEDIA_ITEMS', 'admin/media_items.tpl'); - $serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_properties.tpl', 'serendipityPath')); + $block = 'admin/media_properties.tpl'; + if ($smarty_display) { + $serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_properties.tpl', 'serendipityPath')); + } } - return true; + return $block; } /** diff --git a/include/functions_smarty.inc.php b/include/functions_smarty.inc.php index 0dcada4..a62938a 100644 --- a/include/functions_smarty.inc.php +++ b/include/functions_smarty.inc.php @@ -84,6 +84,31 @@ function serendipity_emptyPrefix($string, $prefix = ': ') { return (!empty($string) ? $prefix . htmlspecialchars($string) : ''); } +/** + * Smarty Modifier: Return a remembered variable + * + * @access public + * @param string The variable name + * @param string The wanted value + * @param boolean Force default? + * @param string Returned attribute + * @return string The return string + */ +function serendipity_ifRemember($name, $value, $isDefault = false, $att = 'checked') { + global $serendipity; + + if (!is_array($serendipity['COOKIE']) && !$isDefault) { + return false; + } + + if ((!is_array($serendipity['COOKIE']) && $isDefault) || + (!isset($serendipity['COOKIE']['serendipity_' . $name]) && $isDefault) || + (isset($serendipity['COOKIE']['serendipity_' . $name]) && $serendipity['COOKIE']['serendipity_' . $name] == $value)) { + + return " $att=\"$att\" "; + } +} + /** * Smarty Function: Fetch and print a single or multiple entries * @@ -597,6 +622,7 @@ function serendipity_smarty_init($vars = array()) { $serendipity['smarty']->register_modifier('emptyPrefix', 'serendipity_emptyPrefix'); $serendipity['smarty']->register_modifier('formatTime', 'serendipity_smarty_formatTime'); $serendipity['smarty']->register_modifier('serendipity_utf8_encode', 'serendipity_utf8_encode'); + $serendipity['smarty']->register_modifier('ifRemember', 'serendipity_ifRemember'); $serendipity['smarty']->register_function('serendipity_printSidebar', 'serendipity_smarty_printSidebar'); $serendipity['smarty']->register_function('serendipity_hookPlugin', 'serendipity_smarty_hookPlugin'); diff --git a/serendipity_admin_image_selector.php b/serendipity_admin_image_selector.php index 1b16cd1..41d7512 100644 --- a/serendipity_admin_image_selector.php +++ b/serendipity_admin_image_selector.php @@ -26,78 +26,14 @@ if (empty($serendipity['GET']['step']) && isset($serendipity['GET']['adminAction $serendipity['GET']['step'] = $serendipity['GET']['adminAction']; } -function ifRemember($name, $value, $isDefault = false, $att = 'checked') { - global $serendipity; - - if (!is_array($serendipity['COOKIE']) && !$isDefault) { - return false; - } - - if ((!is_array($serendipity['COOKIE']) && $isDefault) || - (!isset($serendipity['COOKIE']['serendipity_' . $name]) && $isDefault) || - (isset($serendipity['COOKIE']['serendipity_' . $name]) && $serendipity['COOKIE']['serendipity_' . $name] == $value)) { - - return " $att=\"$att\" "; - } -} -?> - - - <?php echo SELECT_FILE; ?> - - - - - - - - - - - - - - - serendipity_build_query($_GET), + 'frameset' => true + ); + $serendipity['smarty']->assign('media', $media); + $serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_choose.tpl', 'serendipityPath')); return; } @@ -105,23 +41,15 @@ $body_id = 'serendipityAdminBodyImageSelector'; if ($serendipity['GET']['step'] === 'tree') { $body_id = 'serendipityAdminBodyImageSelectorTree'; } -?> - - -
- - - $body_id, + 'only_path' => $serendipity['GET']['only_path'], + 'css' => serendipity_rewriteURL('serendipity_admin.css'), + 'css_tree' => serendipity_getTemplateFile('treeview/tree.css'), + 'token_url' => serendipity_setFormToken('url'), + 'imgID' => (int)$serendipity['GET']['image'] +); switch ($serendipity['GET']['step']) { case '1': @@ -147,11 +75,19 @@ switch ($serendipity['GET']['step']) { switch ($serendipity['GET']['adminAction']) { case 'addSelect': + $media['case'] = 'external'; + ob_start(); include S9Y_INCLUDE_PATH . 'include/admin/images.inc.php'; + $media['external'] = ob_get_contents(); + ob_end_clean(); break 2; case 'add': + $media['case'] = 'external'; + ob_start(); include S9Y_INCLUDE_PATH . 'include/admin/images.inc.php'; + $media['external'] = ob_get_contents(); + ob_end_clean(); if (isset($created_thumbnail) && isset($image_id)) { $serendipity['GET']['image'] = (int)$image_id; // $image_id is passed from images.inc.php break; @@ -160,183 +96,43 @@ switch ($serendipity['GET']['step']) { } } } + $media['case'] = 'choose'; $file = serendipity_fetchImageFromDatabase($serendipity['GET']['image']); + $media['file'] = &$file; if (!is_array($file)) { - echo PERM_DENIED; + $media['perm_denied'] = true; break; } - $sThumbNail = serendipity_getThumbNailPath($file['path'], $file['name'], $file['extension'], $file['thumbnail_name']); - $file['imgsrc'] = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $sThumbNail; - - if ($file['hotlink']) { - $imgName = $file['path']; - } else { - $imgName = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] .'.'. $file['extension']; - } - $thumbbasename = $sThumbNail; + serendipity_prepareMedia($file); - if ($file['hotlink']) { - $thumbName = $file['path']; - } else { - $thumbName = $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $thumbbasename; - } - $thumbsize = @getimagesize($serendipity['serendipityPath'] . $serendipity['uploadPath'] . $thumbbasename); - $is_image = serendipity_isImage($file, true); -?> - - - -
- - -

-

-

-
- - - - - - - - - - - - - - - - - - - : -
- />
- />
- -
- - - : -
- value="" />
- value="left" />
- value="right" />
- -
- - : -
- />
- /> - -
- $serendipity['serendipityHTTPPath'] . $serendipity['uploadHTTPPath'] . $file['path'] . $file['name'] .'.'. $file['extension']); - serendipity_plugin_api::hook_event('frontend_image_selector_link_url', $aArray); - ?> -
- - -
- - : -
- - -
- - - - - - - - -
-
-

- - - - - - - true, ".svn" => true); serendipity_plugin_api::hook_event('backend_media_path_exclude_directories', $aExclude); $paths = array(); @@ -359,74 +155,7 @@ if (parent.frames['tree']) { unset($aResultSet[$sKey]); } serendipity_directoryACL($paths, 'read'); -?> - - -
-
-
-
- -
-
-
-
-
- -
- -
- - - - - -

-

-
- - -
- - -assign('media', $media); +$serendipity['smarty']->display(serendipity_getTemplateFile('admin/media_choose.tpl', 'serendipityPath')); + +/* vim: set sts=4 ts=4 expandtab : */ \ No newline at end of file diff --git a/templates/default/admin/media_choose.tpl b/templates/default/admin/media_choose.tpl new file mode 100644 index 0000000..4553ffa --- /dev/null +++ b/templates/default/admin/media_choose.tpl @@ -0,0 +1,276 @@ + + + {$CONST.SERENDIPITY_ADMIN_SUITE}: {$CONST.SELECT_FILE} + + + + + + + + + +{if $media.frameset} + + + + + +{else} + + +
+{if $media.case == 'external'} + + + {if $media.is_created} + + {/if} + {$media.external} + + +{elseif $media.case == 'default'} + + +

{$CONST.SELECT_FILE}

+

{$CONST.CLICK_FILE_TO_INSERT}

+
+ {$media.external} + {$MEDIA_LIST} + + +{elseif $media.case == 'choose'} + + {if $perm_denied} + {$CONST.PERM_DENIED} + {else} + + + {$media.external} + + +
+ {if $media.file.is_image} + {serendipity_hookPlugin hook="frontend_image_selector" eventData=$media.file hookAll=true} + +

{$CONST.YOU_CHOSE|@sprintf:$media.file.name}

+

+

+
+ {serendipity_hookPlugin hookAll=true hook='frontend_image_selector_hiddenfields' eventData=$media.file} + + + + + + + + + {if $media.htmltarget} + + {/if} + {if $media.filename_only} + + {/if} + + {if $media.file.fast_select} + + {else} + {$CONST.IMAGE_SIZE}: +
+
+
+ {serendipity_hookPlugin hookAll=true hook='frontend_image_selector_imagesize' eventData=$media.file} +
+ + {if NOT $media.filename_only} + {$CONST.IMAGE_ALIGNMENT}: +
+
+
+
+ {serendipity_hookPlugin hookAll=true hook='frontend_image_selector_imagealign' eventData=$media.file} +
+ + {$CONST.IMAGE_AS_A_LINK}: +
+
+ + {if $media.file.hotlink} +
+ {else} + {serendipity_hookPlugin hookAll=true hook='frontend_image_selector_link_url' eventData=$media.file.links} +
+ {/if} + {serendipity_hookPlugin hookAll=true hook='frontend_image_selector_imagelink' eventData=$media.file} +
+ + {$CONST.COMMENT}: +
+ + {serendipity_hookPlugin hookAll=true hook='frontend_image_selector_imagecomment' eventData=$media.file} +
+ {/if} + + {serendipity_hookPlugin hookAll=true hook='frontend_image_selector_more' eventData=$media.file} + + + + {serendipity_hookPlugin hookAll=true hook='frontend_image_selector_submit' eventData=$media.file} + {/if} +
+
+

+ {else} + {if $media.filename_only} + + {else} + + {/if} + {/if} + {/if} +{elseif $media.case == 'tree'} +
+
+ +
+
+ + + + +{/if} +
+ + +{/if} \ No newline at end of file -- 2.39.5