Browse Source

Feature #2044 add mimetype file svg and icon to documents tool, filter browsers support for svg, replace image file by image mimetype svg when list svg-edit imagelib

Juan Carlos Raña 14 years ago
parent
commit
681f7aad7f

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

@@ -122,8 +122,9 @@ function create_document_link($www, $title, $path, $filetype, $size, $visibility
 		// Check the extension
 		$ext = explode('.', $path);
 		$ext = strtolower($ext[sizeof($ext) - 1]);
+		
 		// "htmlfiles" are shown in a frameset
-		if ($ext == 'htm' || $ext == 'html' || $ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'pdf' || $ext == 'swf' || $ext == 'mp3') {
+		if ($ext == 'htm' || $ext == 'html' || $ext == 'gif' || $ext == 'jpg' || $ext == 'jpeg' || $ext == 'png' || $ext == 'pdf' || $ext == 'swf' || $ext == 'mp3' || ($ext == 'svg' && support_svg())) {
 			$url = 'showinframes.php?'.api_get_cidreq().'&file='.$url_path.$req_gid;
 		} else {
 			// url-encode for problematic characters (we may not call them dangerous characters...)
@@ -298,7 +299,7 @@ function build_edit_icons($curdirpath, $type, $path, $visibility, $id, $is_templ
 		if ($is_certificate_mode) {
 			$modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'&selectcat='.$gradebook_category.'"><img src="../img/edit.gif" border="0" title="'.get_lang('Modify').'" alt="" /></a>';
 		}else {
-			if($extension=='svg') {			
+			if($extension=='svg' && support_svg()){			
 				$modify_icons = '<a href="edit_drawing.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'"><img src="../img/edit.gif" border="0" title="'.get_lang('Modify').'" alt="" /></a>';		
 			}else{			
 				$modify_icons = '<a href="edit_document.php?'.api_get_cidreq().'&curdirpath='.$curdirpath.'&amp;file='.urlencode($path).$req_gid.'"><img src="../img/edit.gif" border="0" title="'.get_lang('Modify').'" alt="" /></a>';
@@ -571,4 +572,19 @@ function search_keyword($document_name, $keyword) {
 		return false;
 	}
 }
+
+/**
+ * Check brosers support for svg files
+ * @return return bool Return true
+ */
+function support_svg() {	
+	$browser_info = get_browser($_SERVER["HTTP_USER_AGENT"], true);
+	//print_r($browser_info);
+	if (($browser_info[browser]=='IE' && $browser_info[majorver]>8) || ($browser_info[browser]=='Firefox' && $browser_info[majorver]>2)||($browser_info[browser]=='Safari' && $browser_info[majorver]>4) || $browser_info[browser]=='Chrome' || ($browser_info[browser]=='Opera' && $browser_info[majorver]>9)){
+		return true;
+	}else{
+		return false;
+	}	
+}
+
 ?>

+ 3 - 1
main/document/document.php

@@ -823,11 +823,13 @@ if ($is_allowed_to_edit || $group_member_with_upload_rights || is_my_shared_fold
 	}
 
 	// Create new draw
+	if (support_svg()){
 	?>
 		<a href="create_drawing.php?<?php echo api_get_cidreq(); ?>&dir=<?php echo $curdirpathurl.$req_gid; ?>">
 			<?php Display::display_icon('draw.png', get_lang('Draw')); echo get_lang('Draw'); ?></a>&nbsp;
 	<?php	
-
+	}
+	
 	// Create new certificate
 	if ($is_certificate_mode) {
 ?>

BIN
main/img/draw.png


+ 1 - 0
main/inc/lib/document.lib.php

@@ -195,6 +195,7 @@ class DocumentManager {
 			'sv4cpio' => 'application/x-sv4cpio',
 			'sv4crc' => 'application/x-sv4crc',
 			'svf' => 'application/vnd.svf',
+			'svg' => 'image/svg+xml',
 			'swf' => 'application/x-shockwave-flash',
 			'sxc' => 'application/vnd.sun.xml.calc',
 			'sxi' => 'application/vnd.sun.xml.impress',

+ 3 - 0
main/inc/lib/fileDisplay.lib.php

@@ -53,6 +53,7 @@ function choose_image($file_name)
 		$type['word'      ] = array('doc', 'dot',  'rtf', 'mcw',  'wps', 'psw', 'docm', 'docx', 'dotm',  'dotx');
 		$type['web'       ] = array('htm', 'html', 'htx', 'xml',  'xsl',  'php', 'xhtml');
 		$type['image'     ] = array('gif', 'jpg',  'png', 'bmp',  'jpeg');
+		$type['image_vect'] = array('svg');
 		$type['audio'     ] = array('wav', 'mid',  'mp2', 'mp3',  'midi', 'sib', 'amr', 'kar');
 		$type['video'     ] = array('mp4', 'mov',  'rm',  'pls',  'mpg',  'mpeg', 'au', 'flv', 'avi', 'wmv', 'asf', '3gp');
 		$type['excel'     ] = array('xls', 'xlt',  'xls', 'xlt', 'pxl', 'xlsx', 'xlsm', 'xlam', 'xlsb', 'xltm', 'xltx');
@@ -66,10 +67,12 @@ function choose_image($file_name)
 		$type['oo_calc'   ] = array('ods', 'ots', 'sxc', 'stc');
 		$type['oo_impress'] = array('odp', 'otp', 'sxi', 'sti');
 		$type['oo_draw'   ] = array('odg', 'otg', 'sxd', 'std');
+		
 
 		$image['word'      ] = 'word.gif';
 		$image['web'       ] = 'file_html.gif';
 		$image['image'     ] = 'file_image.gif';
+		$image['image_vect'] = 'file_svg.png';
 		$image['audio'     ] = 'file_sound.gif';
 		$image['video'     ] = 'film.gif';
 		$image['excel'     ] = 'excel.gif';

+ 8 - 2
main/inc/lib/svg-edit/extensions/imagelib/index.php

@@ -57,8 +57,14 @@ $web_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/images/gal
 echo '<ul>';
 foreach($png_svg_files as $filename) {
 		$image=$disk_path.$filename;
-		$new_sizes = api_resize_image($image, 60, 60);	
-	echo '<li style="display:inline; padding:8px;"><a href="'.$web_path.$filename.'" alt "'.$filename.'" title="'.$filename.'"><img src="'.$web_path.$filename.'" width="'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';	
+		$new_sizes = api_resize_image($image, 60, 60);
+		
+if (strpos($filename, "svg")){
+	echo '<li style="display:inline; padding:8px;"><a href="'.$web_path.$filename.'" alt "'.$filename.'" title="'.$filename.'"><img src="'.api_get_path(WEB_IMG_PATH).'svg_medium.png" width="'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';
+}else{
+	echo '<li style="display:inline; padding:8px;"><a href="'.$web_path.$filename.'" alt "'.$filename.'" title="'.$filename.'"><img src="'.$web_path.$filename.'" width="'.$new_sizes['width'].'" height="'.$new_sizes['height'].'" border="0"></a></li>';
+}
+	
 }
 echo '</ul>';
 ?>