Переглянути джерело

[svn r17099] Implementing FS#3296 - Documents tool: Make the document type icons clickable

Ivan Tcholakov 16 роки тому
батько
коміт
9e1aeba525
2 змінених файлів з 47 додано та 22 видалено
  1. 40 18
      main/document/document.inc.php
  2. 7 4
      main/document/document.php

+ 40 - 18
main/document/document.inc.php

@@ -1,4 +1,4 @@
-<?php // $Id: document.inc.php 17072 2008-12-04 21:54:56Z yannoo $
+<?php // $Id: document.inc.php 17099 2008-12-08 02:46:36Z ivantcholakov $
 
 /*
 ==============================================================================
@@ -131,9 +131,10 @@ function build_directory_selector($folders,$curdirpath,$group_dir='',$changeRend
  * @param string $path
  * @param string $filetype (file/folder)
  * @param int $visibility (1/0)
+ * @param int $show_as_icon - if it is true, only a clickable icon will be shown
  * @return string url
  */
-function create_document_link($www,$title,$path,$filetype,$size,$visibility)
+function create_document_link($www, $title, $path, $filetype, $size, $visibility, $show_as_icon = false)
 {
 	global $dbl_click_id;
 	if(isset($_SESSION['_gid']))
@@ -147,12 +148,17 @@ function create_document_link($www,$title,$path,$filetype,$size,$visibility)
 	$url_path = urlencode($path);
 	//add class="invisible" on invisible files
 	$visibility_class= ($visibility==0)?' class="invisible"':'';
-	//build download link (icon)
-	$forcedownload_link=($filetype=='folder')?api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&amp;path='.$url_path.$req_gid:api_get_self().'?'.api_get_cidreq().'&amp;action=download&amp;id='.$url_path.$req_gid;
-	//folder download or file download?
-	$forcedownload_icon=($filetype=='folder')?'folder_zip.gif':'filesave.gif';
-	//prevent multiple clicks on zipped folder download
-	$prevent_multiple_click =($filetype=='folder')?" onclick=\"javascript:if(typeof clic_$dbl_click_id == 'undefined' || clic_$dbl_click_id == false) { clic_$dbl_click_id=true; window.setTimeout('clic_".($dbl_click_id++)."=false;',10000); } else { return false; }\"":'';
+
+	if (!$show_as_icon)
+	{
+		//build download link (icon)
+		$forcedownload_link=($filetype=='folder')?api_get_self().'?'.api_get_cidreq().'&action=downloadfolder&amp;path='.$url_path.$req_gid:api_get_self().'?'.api_get_cidreq().'&amp;action=download&amp;id='.$url_path.$req_gid;
+		//folder download or file download?
+		$forcedownload_icon=($filetype=='folder')?'folder_zip.gif':'filesave.gif';
+		//prevent multiple clicks on zipped folder download
+		$prevent_multiple_click =($filetype=='folder')?" onclick=\"javascript:if(typeof clic_$dbl_click_id == 'undefined' || clic_$dbl_click_id == false) { clic_$dbl_click_id=true; window.setTimeout('clic_".($dbl_click_id++)."=false;',10000); } else { return false; }\"":'';
+	}
+
 	$target='_top';
 	if($filetype=='file') {
 		//check the extension
@@ -179,11 +185,21 @@ function create_document_link($www,$title,$path,$filetype,$size,$visibility)
 	{
 		$url=api_get_self().'?'.api_get_cidreq().'&amp;curdirpath='.$url_path.$req_gid;
 	}
+
 	//the little download icon
-	$force_download_html = ($size==0)?'':'<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'),array('height'=>'16', 'width' => '16')).'</a>';
-	
-	$tooltip_title = str_replace('?cidReq='.$_GET['cidReq'],'',basename($path));
-	return '<a href="'.$url.'" title="'.$tooltip_title.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.$title.'</a>'.$force_download_html;
+	//$tooltip_title = str_replace('?cidReq='.$_GET['cidReq'],'',basename($path));
+	$tooltip_title = explode('?', basename($path));
+	$tooltip_title = $tooltip_title[0];
+
+	if (!$show_as_icon)
+	{
+		$force_download_html = ($size==0)?'':'<a href="'.$forcedownload_link.'" style="float:right"'.$prevent_multiple_click.'>'.Display::return_icon($forcedownload_icon, get_lang('Download'),array('height'=>'16', 'width' => '16')).'</a>';
+		return '<a href="'.$url.'" title="'.$tooltip_title.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.$title.'</a>'.$force_download_html;
+	}
+	else
+	{
+		return '<a href="'.$url.'" title="'.$tooltip_title.'" target="'.$target.'"'.$visibility_class.' style="float:left">'.build_document_icon_tag($filetype, $tooltip_title).'</a>';
+	}
 }
 
 /**
@@ -193,14 +209,20 @@ function create_document_link($www,$title,$path,$filetype,$size,$visibility)
  * @param string $path
  * @return string img html tag
  */
-function build_document_icon_tag($type,$path)
+function build_document_icon_tag($type, $path)
 {
-	$icon='folder_document.gif';
-	if($type=='file')
+	$basename = basename($path);
+
+	if ($type == 'file')
 	{
-		$icon=choose_image(basename($path));
+		$icon = choose_image($basename);
 	}
-	return Display::return_icon($icon, '', array('hspace'=>'5', 'align' => 'middle'));
+	else
+	{
+		$icon = 'folder_document.gif';
+	}
+
+	return Display::return_icon($icon, $basename, array('hspace'=>'5', 'align' => 'middle'));
 }
 
 /**
@@ -404,4 +426,4 @@ function display_user_link_document($user_id, $name)
 	}
 }
 
-?>
+?>

+ 7 - 4
main/document/document.php

@@ -1,4 +1,4 @@
-<?php // $Id: document.php 16862 2008-11-21 21:45:30Z herodoto $
+<?php // $Id: document.php 17099 2008-12-08 02:46:36Z ivantcholakov $
  
 /*
 ==============================================================================
@@ -624,7 +624,7 @@ if($folders===false)
 	{
 	?>
 		 <a href="<?php echo api_get_self(); ?>?<?php echo api_get_cidreq();?>&curdirpath=<?php echo urlencode((dirname($curdirpath)=='\\')?'/':dirname($curdirpath)).$req_gid ?>">
-				<img src="../img/folder_up.gif" border="0" align="absbottom" hspace="5" title="<?php echo get_lang('Up'); ?>"alt="" />
+				<img src="../img/folder_up.gif" border="0" title="<?php echo get_lang('Up'); ?>" alt="" />
 				<?php echo get_lang('Up'); ?></a>&nbsp;
 	<?php
 	}
@@ -696,8 +696,6 @@ if(isset($docs_and_folders) && is_array($docs_and_folders))
 		{
 			$row[] = $id['path'];			
 		}
-		//icons
-		$row[]= build_document_icon_tag($id['filetype'],$id['path']);
 		
 		// Show the Owner of the file only in groups				
 		$user_link='';	
@@ -712,8 +710,13 @@ if(isset($docs_and_folders) && is_array($docs_and_folders))
 			}
 		}
 		
+		//icons (clickable)
+		//$row[]= build_document_icon_tag($id['filetype'],$id['path']);
+		$row[] = create_document_link($http_www,  $document_name,  $id['path'], $id['filetype'],  $size, $id['visibility'], true);
+
 		//document title with hyperlink
 		$row[] = create_document_link($http_www,$document_name,$id['path'],$id['filetype'],$size,$id['visibility']).'<br />'.$invisibility_span_open.nl2br(htmlspecialchars($id['comment'],ENT_QUOTES,$charset)).$invisibility_span_close.$user_link;
+
 		//comments => display comment under the document name
 		//$row[] = $invisibility_span_open.nl2br(htmlspecialchars($id['comment'])).$invisibility_span_close;
 		$display_size = format_file_size($size);