Passed
Push — 1.10.x ( 849f97...a21c08 )
by Angel Fernando Quiroz
47:19
created
main/document/slideshow.php 2 patches
Indentation   +253 added lines, -253 removed lines patch added patch discarded remove patch
@@ -1,11 +1,11 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 /* For licensing terms, see /license.txt */
3 3
 /**
4
- * @author Patrick Cool [email protected] Ghent University Mai 2004
5
- * @author Julio Montoya Lots of improvements, cleaning, adding security
6
- * @author Juan Carlos Raña Trabado [email protected]	January 2008
7
- * @package chamilo.document
8
- */
4
+     * @author Patrick Cool [email protected] Ghent University Mai 2004
5
+     * @author Julio Montoya Lots of improvements, cleaning, adding security
6
+     * @author Juan Carlos Raña Trabado [email protected]	January 2008
7
+     * @package chamilo.document
8
+     */
9 9
 require_once '../inc/global.inc.php';
10 10
 api_protect_course_script();
11 11
 
@@ -15,15 +15,15 @@  discard block
 block discarded – undo
15 15
 $slide_id = isset($_GET['slide_id']) ? Security::remove_XSS($_GET['slide_id']) : null;
16 16
 
17 17
 if (empty($slide_id)) {
18
-	$edit_slide_id = 1;
18
+    $edit_slide_id = 1;
19 19
 } else {
20
-	$edit_slide_id = $slide_id;
20
+    $edit_slide_id = $slide_id;
21 21
 }
22 22
 
23 23
 if ($path != '/') {
24
-	$folder = $path.'/';
24
+    $folder = $path.'/';
25 25
 } else {
26
-	$folder = '/';
26
+    $folder = '/';
27 27
 }
28 28
 $sys_course_path = api_get_path(SYS_COURSE_PATH);
29 29
 
@@ -41,15 +41,15 @@  discard block
 block discarded – undo
41 41
 
42 42
 // Loading the slides from the session
43 43
 if (isset($_SESSION['image_files_only'])) {
44
-	$image_files_only = $_SESSION['image_files_only'];
44
+    $image_files_only = $_SESSION['image_files_only'];
45 45
 }
46 46
 
47 47
 // Calculating the current slide, next slide, previous slide and the number of slides
48 48
 $slide = null;
49 49
 if ($slide_id != 'all') {
50
-	$slide = $slide_id ? $slide_id : 0;
51
-	$previous_slide = $slide - 1;
52
-	$next_slide = $slide + 1;
50
+    $slide = $slide_id ? $slide_id : 0;
51
+    $previous_slide = $slide - 1;
52
+    $next_slide = $slide + 1;
53 53
 }
54 54
 $total_slides = count($image_files_only);
55 55
 ?>
@@ -62,62 +62,62 @@  discard block
 block discarded – undo
62 62
 <?php
63 63
 
64 64
 if ($slide_id != 'all') {
65
-	$image = null;
66
-	if (isset($image_files_only[$slide])) {
67
-		$image = $sys_course_path . $_course['path'] . '/document' . $folder . $image_files_only[$slide];
68
-	}
69
-	if (file_exists($image)) {
70
-		echo '<div class="actions-pagination">';
71
-
72
-		// Back forward buttons
73
-		if ($slide == 0) {
74
-			$imgp = 'action_prev_na.png';
75
-			$first = Display::return_icon('action_first_na.png');
76
-		} else {
77
-			$imgp = 'action_prev.png';
78
-			$first = '<a href="slideshow.php?slide_id=0&curdirpath='.$pathurl.'">
65
+    $image = null;
66
+    if (isset($image_files_only[$slide])) {
67
+        $image = $sys_course_path . $_course['path'] . '/document' . $folder . $image_files_only[$slide];
68
+    }
69
+    if (file_exists($image)) {
70
+        echo '<div class="actions-pagination">';
71
+
72
+        // Back forward buttons
73
+        if ($slide == 0) {
74
+            $imgp = 'action_prev_na.png';
75
+            $first = Display::return_icon('action_first_na.png');
76
+        } else {
77
+            $imgp = 'action_prev.png';
78
+            $first = '<a href="slideshow.php?slide_id=0&curdirpath='.$pathurl.'">
79 79
 			          '.Display::return_icon('action_first.png', get_lang('FirstSlide')).'
80 80
 			          </a>';
81
-		}
81
+        }
82 82
 
83
-		// First slide
84
-		echo $first;
83
+        // First slide
84
+        echo $first;
85 85
 
86
-		// Previous slide
87
-		if ($slide > 0) {
88
-			echo '<a href="slideshow.php?slide_id='.$previous_slide.'&curdirpath='.$pathurl.'">';
89
-		}
86
+        // Previous slide
87
+        if ($slide > 0) {
88
+            echo '<a href="slideshow.php?slide_id='.$previous_slide.'&curdirpath='.$pathurl.'">';
89
+        }
90 90
 
91 91
         echo Display::return_icon($imgp, get_lang('Previous'));
92
-		if ($slide > 0) {
93
-			echo '</a>';
94
-		}
95
-
96
-		// Divider
97
-		echo ' [ '.$next_slide.'/'.$total_slides.' ] ';
98
-
99
-		// Next slide
100
-		if ($slide < $total_slides - 1) {
101
-			echo '<a href="slideshow.php?slide_id='.$next_slide.'&curdirpath='.$pathurl.'">';
102
-		}
103
-		if ($slide == $total_slides - 1) {
104
-			$imgn = 'action_next_na.png';
92
+        if ($slide > 0) {
93
+            echo '</a>';
94
+        }
95
+
96
+        // Divider
97
+        echo ' [ '.$next_slide.'/'.$total_slides.' ] ';
98
+
99
+        // Next slide
100
+        if ($slide < $total_slides - 1) {
101
+            echo '<a href="slideshow.php?slide_id='.$next_slide.'&curdirpath='.$pathurl.'">';
102
+        }
103
+        if ($slide == $total_slides - 1) {
104
+            $imgn = 'action_next_na.png';
105 105
             $last = Display::return_icon('action_last_na.png', get_lang('LastSlide'));
106
-		} else {
107
-			$imgn = 'action_next.png';
108
-			$last = '<a href="slideshow.php?slide_id='.($total_slides-1).'&curdirpath='.$pathurl.'">
106
+        } else {
107
+            $imgn = 'action_next.png';
108
+            $last = '<a href="slideshow.php?slide_id='.($total_slides-1).'&curdirpath='.$pathurl.'">
109 109
 			        '.Display::return_icon('action_last.png', get_lang('LastSlide')).'
110 110
                 </a>';
111
-		}
111
+        }
112 112
         echo Display::return_icon($imgn, get_lang('Next'));
113
-		if ($slide > 0) {
114
-			echo '</a>';
115
-		}
116
-
117
-		// Last slide
118
-		echo $last;
119
-		echo '</div>';
120
-	}
113
+        if ($slide > 0) {
114
+            echo '</a>';
115
+        }
116
+
117
+        // Last slide
118
+        echo $last;
119
+        echo '</div>';
120
+    }
121 121
 }
122 122
 
123 123
 // Exit the slideshow
@@ -126,10 +126,10 @@  discard block
 block discarded – undo
126 126
 
127 127
 // Show thumbnails
128 128
 if ($slide_id != 'all') {
129
-	echo '<a href="slideshow.php?slide_id=all&curdirpath='.$pathurl.'&'.api_get_cidreq().'">'.
129
+    echo '<a href="slideshow.php?slide_id=all&curdirpath='.$pathurl.'&'.api_get_cidreq().'">'.
130 130
         Display::return_icon('thumbnails.png',get_lang('ShowThumbnails'),'',ICON_SIZE_MEDIUM).'</a>';
131 131
 } else {
132
-	echo Display::return_icon('thumbnails_na.png',get_lang('ShowThumbnails'),'',ICON_SIZE_MEDIUM);
132
+    echo Display::return_icon('thumbnails_na.png',get_lang('ShowThumbnails'),'',ICON_SIZE_MEDIUM);
133 133
 }
134 134
 // Slideshow options
135 135
 echo '<a href="slideshowoptions.php?curdirpath='.$pathurl.'&'.api_get_cidreq().'">'.
@@ -142,24 +142,24 @@  discard block
 block discarded – undo
142 142
 
143 143
 // If we come from slideshowoptions.php we sessionize (new word !!! ;-) the options
144 144
 if (isset($_POST['Submit'])) {
145
-	// We come from slideshowoptions.php
146
-	//$_SESSION["auto_image_resizing"]=Security::remove_XSS($_POST['auto_radio_resizing']);
147
-	$_SESSION["image_resizing"] = Security::remove_XSS($_POST['radio_resizing']);
148
-	if ($_POST['radio_resizing'] == "resizing" && $_POST['width'] != '' && $_POST['height'] != '') {
149
-		//echo "resizing";
150
-		$_SESSION["image_resizing_width"] = Security::remove_XSS($_POST['width']);
151
-		$_SESSION["image_resizing_height"] = Security::remove_XSS($_POST['height']);
152
-	} else {
153
-		//echo "unsetting the session heighte and width";
154
-		$_SESSION["image_resizing_width"] = null;
155
-		$_SESSION["image_resizing_height"] = null;
156
-	}
145
+    // We come from slideshowoptions.php
146
+    //$_SESSION["auto_image_resizing"]=Security::remove_XSS($_POST['auto_radio_resizing']);
147
+    $_SESSION["image_resizing"] = Security::remove_XSS($_POST['radio_resizing']);
148
+    if ($_POST['radio_resizing'] == "resizing" && $_POST['width'] != '' && $_POST['height'] != '') {
149
+        //echo "resizing";
150
+        $_SESSION["image_resizing_width"] = Security::remove_XSS($_POST['width']);
151
+        $_SESSION["image_resizing_height"] = Security::remove_XSS($_POST['height']);
152
+    } else {
153
+        //echo "unsetting the session heighte and width";
154
+        $_SESSION["image_resizing_width"] = null;
155
+        $_SESSION["image_resizing_height"] = null;
156
+    }
157 157
 }
158 158
 $target_width = $target_height = null;
159 159
 // The target height and width depends if we choose resizing or no resizing
160 160
 if (isset($_SESSION["image_resizing"]) &&  $_SESSION["image_resizing"] == "resizing") {
161
-	$target_width = $_SESSION["image_resizing_width"];
162
-	$target_height = $_SESSION["image_resizing_height"];
161
+    $target_width = $_SESSION["image_resizing_width"];
162
+    $target_height = $_SESSION["image_resizing_height"];
163 163
 }
164 164
 
165 165
 /*	THUMBNAIL VIEW */
@@ -169,59 +169,59 @@  discard block
 block discarded – undo
169 169
 $html = '';
170 170
 if ($slide_id == 'all') {
171 171
 
172
-	// Config for make thumbnails
172
+    // Config for make thumbnails
173 173
     $allowed_thumbnail_types = array('jpg', 'jpeg', 'gif', 'png');
174
-	$max_thumbnail_width     = 250;
175
-	$max_thumbnail_height    = 250;
176
-	$png_compression	     = 0; // 0(none)-9
177
-	$jpg_quality  	         = 75; // from 0 to 100 (default is 75). More quality less compression
174
+    $max_thumbnail_width     = 250;
175
+    $max_thumbnail_height    = 250;
176
+    $png_compression	     = 0; // 0(none)-9
177
+    $jpg_quality  	         = 75; // from 0 to 100 (default is 75). More quality less compression
178 178
 
179
-	$directory_thumbnails = $sys_course_path.$_course['path'].'/document'.$folder.'.thumbs/';
179
+    $directory_thumbnails = $sys_course_path.$_course['path'].'/document'.$folder.'.thumbs/';
180 180
 
181
-	//Other parameters only for show tumbnails
182
-	$row_items 			     = 4;//only in slideshow.php
183
-	$number_image 			 = 7;//num icons cols to show
184
-	$thumbnail_width_frame = $max_thumbnail_width;//optional $max_thumbnail_width+x
185
-	$thumbnail_height_frame = $max_thumbnail_height;
181
+    //Other parameters only for show tumbnails
182
+    $row_items 			     = 4;//only in slideshow.php
183
+    $number_image 			 = 7;//num icons cols to show
184
+    $thumbnail_width_frame = $max_thumbnail_width;//optional $max_thumbnail_width+x
185
+    $thumbnail_height_frame = $max_thumbnail_height;
186 186
 
187
-	// Create the template_thumbnails folder (if no exist)
187
+    // Create the template_thumbnails folder (if no exist)
188 188
 
189
-	if (!file_exists($directory_thumbnails)) {
190
-		@mkdir($directory_thumbnails, api_get_permissions_for_new_directories());
189
+    if (!file_exists($directory_thumbnails)) {
190
+        @mkdir($directory_thumbnails, api_get_permissions_for_new_directories());
191 191
     }
192 192
 
193
-	// check files and thumbnails
194
-	if (is_array($image_files_only)) {
193
+    // check files and thumbnails
194
+    if (is_array($image_files_only)) {
195 195
 
196
-		foreach ($image_files_only as $one_image_file) {
197
-			$image = $sys_course_path.$_course['path'].'/document'.$folder.$one_image_file;
198
-			$image_thumbnail= $directory_thumbnails.'.'.$one_image_file;
196
+        foreach ($image_files_only as $one_image_file) {
197
+            $image = $sys_course_path.$_course['path'].'/document'.$folder.$one_image_file;
198
+            $image_thumbnail= $directory_thumbnails.'.'.$one_image_file;
199 199
 
200
-			if (file_exists($image)) {
201
-				//check thumbnail
202
-				$imagetype = explode(".", $image);
200
+            if (file_exists($image)) {
201
+                //check thumbnail
202
+                $imagetype = explode(".", $image);
203 203
                 //or check $imagetype = image_type_to_extension(exif_imagetype($image), false);
204
-				$imagetype = strtolower($imagetype[count($imagetype)-1]);
204
+                $imagetype = strtolower($imagetype[count($imagetype)-1]);
205 205
 
206
-				if (in_array($imagetype,$allowed_thumbnail_types)) {
207
-					if (!file_exists($image_thumbnail)){
206
+                if (in_array($imagetype,$allowed_thumbnail_types)) {
207
+                    if (!file_exists($image_thumbnail)){
208 208
                         //run each once we view thumbnails is too heavy, then need move into  !file_exists($image_thumbnail, and only run when haven't the thumbnail
209
-						$original_image_size = api_getimagesize($image);
210
-
211
-						switch($imagetype) {
212
-							case 'gif':
213
-								$source_img = imagecreatefromgif($image);
214
-								break;
215
-							case 'jpg':
216
-								$source_img = imagecreatefromjpeg($image);
217
-								break;
218
-							case 'jpeg':
219
-								$source_img = imagecreatefromjpeg($image);
220
-								break;
221
-							case 'png':
222
-								$source_img = imagecreatefrompng($image);
223
-								break;
224
-						}
209
+                        $original_image_size = api_getimagesize($image);
210
+
211
+                        switch($imagetype) {
212
+                            case 'gif':
213
+                                $source_img = imagecreatefromgif($image);
214
+                                break;
215
+                            case 'jpg':
216
+                                $source_img = imagecreatefromjpeg($image);
217
+                                break;
218
+                            case 'jpeg':
219
+                                $source_img = imagecreatefromjpeg($image);
220
+                                break;
221
+                            case 'png':
222
+                                $source_img = imagecreatefrompng($image);
223
+                                break;
224
+                        }
225 225
 
226 226
                         $new_thumbnail_size = api_calculate_image_size(
227 227
                             $original_image_size['width'],
@@ -229,33 +229,33 @@  discard block
 block discarded – undo
229 229
                             $max_thumbnail_width,
230 230
                             $max_thumbnail_height
231 231
                         );
232
-						if ($max_thumbnail_width>$original_image_size['width'] && $max_thumbnail_height>$original_image_size['height']){
233
-							$new_thumbnail_size['width']=$original_image_size['width'];
234
-							$new_thumbnail_size['height']=$original_image_size['height'];
235
-						}
236
-
237
-						$crop = imagecreatetruecolor($new_thumbnail_size['width'], $new_thumbnail_size['height']);
238
-
239
-						// preserve transparency
240
-						if ($imagetype == "png"){
241
-							imagesavealpha($crop, true);
242
-							$color = imagecolorallocatealpha($crop,0x00,0x00,0x00,127);
243
-							imagefill($crop, 0, 0, $color);
244
-						}
245
-
246
-						if ($imagetype == "gif") {
247
-							$transindex = imagecolortransparent($source_img);
232
+                        if ($max_thumbnail_width>$original_image_size['width'] && $max_thumbnail_height>$original_image_size['height']){
233
+                            $new_thumbnail_size['width']=$original_image_size['width'];
234
+                            $new_thumbnail_size['height']=$original_image_size['height'];
235
+                        }
236
+
237
+                        $crop = imagecreatetruecolor($new_thumbnail_size['width'], $new_thumbnail_size['height']);
238
+
239
+                        // preserve transparency
240
+                        if ($imagetype == "png"){
241
+                            imagesavealpha($crop, true);
242
+                            $color = imagecolorallocatealpha($crop,0x00,0x00,0x00,127);
243
+                            imagefill($crop, 0, 0, $color);
244
+                        }
245
+
246
+                        if ($imagetype == "gif") {
247
+                            $transindex = imagecolortransparent($source_img);
248 248
                             $palletsize = imagecolorstotal($source_img);
249
-							 //GIF89a for transparent and anim (first clip), either GIF87a
250
-							 if ($transindex >= 0 && $transindex < $palletsize){
251
-								 $transcol = imagecolorsforindex($source_img, $transindex);
252
-								 $transindex = imagecolorallocatealpha($crop, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
253
-								 imagefill($crop, 0, 0, $transindex);
254
-								 imagecolortransparent($crop, $transindex);
255
-							 }
256
-						}
257
-
258
-						//resampled image
249
+                                //GIF89a for transparent and anim (first clip), either GIF87a
250
+                                if ($transindex >= 0 && $transindex < $palletsize){
251
+                                    $transcol = imagecolorsforindex($source_img, $transindex);
252
+                                    $transindex = imagecolorallocatealpha($crop, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
253
+                                    imagefill($crop, 0, 0, $transindex);
254
+                                    imagecolortransparent($crop, $transindex);
255
+                                }
256
+                        }
257
+
258
+                        //resampled image
259 259
                         imagecopyresampled(
260 260
                             $crop,
261 261
                             $source_img,
@@ -269,69 +269,69 @@  discard block
 block discarded – undo
269 269
                             $original_image_size['height']
270 270
                         );
271 271
 
272
-						switch ($imagetype) {
273
-							case 'gif':
274
-								imagegif($crop,$image_thumbnail);
275
-								break;
276
-							case 'jpg':
277
-								imagejpeg($crop,$image_thumbnail,$jpg_quality);
278
-								break;
279
-							case 'jpeg':
280
-								imagejpeg($crop,$image_thumbnail,$jpg_quality);
281
-								break;
282
-							case 'png':
283
-								imagepng($crop,$image_thumbnail,$png_compression);
284
-								break;
285
-						}
286
-
287
-						//clean memory
288
-						imagedestroy($crop);
289
-					}//end !exist thumbnail
290
-
291
-					//show thumbnail and link
292
-
293
-					$one_image_thumbnail_file='.thumbs/.'.$one_image_file;//get path thumbnail
294
-					$doc_url = ($path && $path !== '/') ? $path.'/'.$one_image_thumbnail_file : $path.$one_image_thumbnail_file;
295
-					$image_tag[] = '<img class="img-gallery" src="download.php?doc_url='.$doc_url.'" border="0" title="'.$one_image_file.'">';
296
-				} else {
297
-					//if images aren't support by gd (not gif, jpg, jpeg, png)
298
-					if ($imagetype=="bmp") {
272
+                        switch ($imagetype) {
273
+                            case 'gif':
274
+                                imagegif($crop,$image_thumbnail);
275
+                                break;
276
+                            case 'jpg':
277
+                                imagejpeg($crop,$image_thumbnail,$jpg_quality);
278
+                                break;
279
+                            case 'jpeg':
280
+                                imagejpeg($crop,$image_thumbnail,$jpg_quality);
281
+                                break;
282
+                            case 'png':
283
+                                imagepng($crop,$image_thumbnail,$png_compression);
284
+                                break;
285
+                        }
286
+
287
+                        //clean memory
288
+                        imagedestroy($crop);
289
+                    }//end !exist thumbnail
290
+
291
+                    //show thumbnail and link
292
+
293
+                    $one_image_thumbnail_file='.thumbs/.'.$one_image_file;//get path thumbnail
294
+                    $doc_url = ($path && $path !== '/') ? $path.'/'.$one_image_thumbnail_file : $path.$one_image_thumbnail_file;
295
+                    $image_tag[] = '<img class="img-gallery" src="download.php?doc_url='.$doc_url.'" border="0" title="'.$one_image_file.'">';
296
+                } else {
297
+                    //if images aren't support by gd (not gif, jpg, jpeg, png)
298
+                    if ($imagetype=="bmp") {
299 299
                         // use getimagesize instead api_getimagesize($image); becasuse api_getimagesize doesn't support bmp files. Put here for each show, only for a few bmp files isn't heavy
300
-						$original_image_size = getimagesize($image);
301
-						if ($max_thumbnail_width<$original_image_size[0] || $max_thumbnail_height<$original_image_size[1]){
302
-							$thumbnail_size=api_calculate_image_size($original_image_size[0], $original_image_size[1], $max_thumbnail_width, $max_thumbnail_height);//don't use resize_image because doesn't run with bmp files
303
-							$image_height = $thumbnail_size['height'];
304
-							$image_width  = $thumbnail_size['width'];
305
-						} else {
306
-							$image_height=$original_image_size[0];
307
-							$image_width=$original_image_size[1];
308
-						}
309
-					} else {
310
-						//example for svg files,...
311
-						$image_width=$max_thumbnail_width;
312
-						$image_height=$max_thumbnail_height;
313
-					}
314
-
315
-					$doc_url = ($path && $path !== '/') ? $path.'/'.$one_image_file : $path.$one_image_file;
316
-					$image_tag[] = '<img src="download.php?doc_url='.$doc_url.'" border="0" width="'.$image_width.'" height="'.$image_height.'" title="'.$one_image_file.'">';
317
-
318
-				}//end allowed image types
319
-			}//end if exist file image
320
-		}//end foreach
321
-	}//end image files only
322
-
323
-	// Creating the table
324
-	$html_table = '';
325
-
326
-	$i = 0;
327
-	$count_image = count($image_tag);
328
-	$number_iteration = ceil($count_image/$number_image);
329
-	$p = 0;
300
+                        $original_image_size = getimagesize($image);
301
+                        if ($max_thumbnail_width<$original_image_size[0] || $max_thumbnail_height<$original_image_size[1]){
302
+                            $thumbnail_size=api_calculate_image_size($original_image_size[0], $original_image_size[1], $max_thumbnail_width, $max_thumbnail_height);//don't use resize_image because doesn't run with bmp files
303
+                            $image_height = $thumbnail_size['height'];
304
+                            $image_width  = $thumbnail_size['width'];
305
+                        } else {
306
+                            $image_height=$original_image_size[0];
307
+                            $image_width=$original_image_size[1];
308
+                        }
309
+                    } else {
310
+                        //example for svg files,...
311
+                        $image_width=$max_thumbnail_width;
312
+                        $image_height=$max_thumbnail_height;
313
+                    }
314
+
315
+                    $doc_url = ($path && $path !== '/') ? $path.'/'.$one_image_file : $path.$one_image_file;
316
+                    $image_tag[] = '<img src="download.php?doc_url='.$doc_url.'" border="0" width="'.$image_width.'" height="'.$image_height.'" title="'.$one_image_file.'">';
317
+
318
+                }//end allowed image types
319
+            }//end if exist file image
320
+        }//end foreach
321
+    }//end image files only
322
+
323
+    // Creating the table
324
+    $html_table = '';
325
+
326
+    $i = 0;
327
+    $count_image = count($image_tag);
328
+    $number_iteration = ceil($count_image/$number_image);
329
+    $p = 0;
330 330
     $html = '';
331 331
     $html .= '<div class="gallery">';
332
-	for ($k = 0; $k < $number_iteration; $k++) {
333
-		for ($i = 0; $i < $number_image; $i++) {
334
-			if (isset($image_tag[$p])) {
332
+    for ($k = 0; $k < $number_iteration; $k++) {
333
+        for ($i = 0; $i < $number_image; $i++) {
334
+            if (isset($image_tag[$p])) {
335 335
                             $html .= '<div class="col-xs-6 col-sm-3 col-md-2">';
336 336
                             $html .= '<div class="canvas-one">';
337 337
                             $html .= '<a class="canvas-two" href="slideshow.php?slide_id='.$p.'&curdirpath='.$pathurl.'">';
@@ -343,10 +343,10 @@  discard block
 block discarded – undo
343 343
                             $html .= '</a>';
344 344
                             $html .= '</div>';
345 345
                             $html .= '</div>';
346
-			}
347
-			$p++;
348
-		}
349
-	}
346
+            }
347
+            $p++;
348
+        }
349
+    }
350 350
     $html .= '</div>';
351 351
 
352 352
 }//end slide==all
@@ -357,43 +357,43 @@  discard block
 block discarded – undo
357 357
 // This is for viewing all the images in the slideshow one at a time.
358 358
 
359 359
 if ($slide_id != 'all' && !empty($image_files_only)) {
360
-	if (file_exists($image) && is_file($image)) {
361
-		$image_height_width = resize_image($image, $target_width, $target_height);
362
-
363
-		$image_height = $image_height_width[0];
364
-		$image_width = $image_height_width[1];
365
-
366
-		$height_width_tags = null;
367
-		if (isset($_SESSION['image_resizing']) && $_SESSION['image_resizing'] == 'resizing') {
368
-			$height_width_tags = 'width="'.$image_width.'" height="'.$image_height.'"';
369
-		}
370
-
371
-		// This is done really quickly and should be cleaned up a little bit using the API functions
372
-		$tbl_documents = Database::get_course_table(TABLE_DOCUMENT);
373
-		if ($path == '/') {
374
-			$pathpart = '/';
375
-		} else {
376
-			$pathpart = $path.'/';
377
-		}
378
-		$sql = "SELECT * FROM $tbl_documents
360
+    if (file_exists($image) && is_file($image)) {
361
+        $image_height_width = resize_image($image, $target_width, $target_height);
362
+
363
+        $image_height = $image_height_width[0];
364
+        $image_width = $image_height_width[1];
365
+
366
+        $height_width_tags = null;
367
+        if (isset($_SESSION['image_resizing']) && $_SESSION['image_resizing'] == 'resizing') {
368
+            $height_width_tags = 'width="'.$image_width.'" height="'.$image_height.'"';
369
+        }
370
+
371
+        // This is done really quickly and should be cleaned up a little bit using the API functions
372
+        $tbl_documents = Database::get_course_table(TABLE_DOCUMENT);
373
+        if ($path == '/') {
374
+            $pathpart = '/';
375
+        } else {
376
+            $pathpart = $path.'/';
377
+        }
378
+        $sql = "SELECT * FROM $tbl_documents
379 379
 		        WHERE c_id = $course_id AND path='".Database::escape_string($pathpart.$image_files_only[$slide])."'";
380
-		$result = Database::query($sql);
381
-		$row = Database::fetch_array($result);
380
+        $result = Database::query($sql);
381
+        $row = Database::fetch_array($result);
382 382
 
383 383
         echo '<div class="thumbnail">';
384
-		if ($slide < $total_slides - 1 && $slide_id != 'all') {
385
-			echo "<a href='slideshow.php?slide_id=".$next_slide."&curdirpath=$pathurl'>";
386
-		} else {
387
-			echo "<a href='slideshow.php?slide_id=0&curdirpath=$pathurl'>";
388
-		}
384
+        if ($slide < $total_slides - 1 && $slide_id != 'all') {
385
+            echo "<a href='slideshow.php?slide_id=".$next_slide."&curdirpath=$pathurl'>";
386
+        } else {
387
+            echo "<a href='slideshow.php?slide_id=0&curdirpath=$pathurl'>";
388
+        }
389 389
         if ($path == '/') {
390
-        	$path = '';
390
+            $path = '';
391 391
         }
392 392
 
393
-		list($width, $height) = getimagesize($image);
394
-		// Auto resize
395
-		if (isset($_SESSION["image_resizing"]) &&  $_SESSION["image_resizing"] == 'resizing') {
396
-		?>
393
+        list($width, $height) = getimagesize($image);
394
+        // Auto resize
395
+        if (isset($_SESSION["image_resizing"]) &&  $_SESSION["image_resizing"] == 'resizing') {
396
+        ?>
397 397
 
398 398
 		<script type="text/javascript">
399 399
 			var initial_width='<?php echo $width; ?>';
@@ -446,21 +446,21 @@  discard block
 block discarded – undo
446 446
 
447 447
 		</script>
448 448
     <?php
449
-		} else {
450
-			echo "<img class=\"img-responsive\" src='download.php?doc_url=$path/".$image_files_only[$slide]."' alt='".$image_files_only[$slide]."' border='0'".$height_width_tags.">";
451
-		}
449
+        } else {
450
+            echo "<img class=\"img-responsive\" src='download.php?doc_url=$path/".$image_files_only[$slide]."' alt='".$image_files_only[$slide]."' border='0'".$height_width_tags.">";
451
+        }
452 452
 
453
-		echo '</a>';
453
+        echo '</a>';
454 454
         echo '<div class="caption text-center">';
455 455
         echo Display::tag('h3', $row['title']);
456 456
         echo '<p>' . $row['comment'] . '</p>';
457 457
         echo '</div>';
458 458
         echo '</div>';
459 459
 
460
-		if (api_is_allowed_to_edit(null, true)) {
460
+        if (api_is_allowed_to_edit(null, true)) {
461 461
             echo '<ul class="list-unstyled">';
462
-			$aux = explode('.', htmlspecialchars($image_files_only[$slide]));
463
-			$ext = $aux[count($aux) - 1];
462
+            $aux = explode('.', htmlspecialchars($image_files_only[$slide]));
463
+            $ext = $aux[count($aux) - 1];
464 464
 
465 465
             if (isset($_SESSION['image_resizing']) && $_SESSION['image_resizing'] == 'resizing') {
466 466
                 $resize_info = get_lang('Resizing').'<br />';
@@ -472,8 +472,8 @@  discard block
 block discarded – undo
472 472
                 $resize_height = get_lang('Auto');
473 473
             } else {
474 474
                 $resize_info = get_lang('NoResizing').'<br />';
475
-				$resize_width = '';
476
-				$resize_height = '';
475
+                $resize_width = '';
476
+                $resize_height = '';
477 477
             }
478 478
 
479 479
             echo '<li class="text-center">';
@@ -493,16 +493,16 @@  discard block
 block discarded – undo
493 493
             );
494 494
             echo '</li>';
495 495
             echo '<li class="text-center">' . $width.' x '.$height . '</li>';
496
-			echo '<li class="text-center">' . round((filesize($image) / 1024), 2) . ' KB - ' . $ext . '</li>';
496
+            echo '<li class="text-center">' . round((filesize($image) / 1024), 2) . ' KB - ' . $ext . '</li>';
497 497
             echo '<li class="text-center">' . $resize_info . '</li>';
498
-			echo '<li class="text-center">' . $resize_width . '</li>';
499
-			echo '<li class="text-center">' . $resize_height . '</li>';
498
+            echo '<li class="text-center">' . $resize_width . '</li>';
499
+            echo '<li class="text-center">' . $resize_height . '</li>';
500 500
             echo '</ul>';
501
-		}
501
+        }
502 502
 
503
-	} else {
504
-		Display::display_warning_message(get_lang('FileNotFound'));
505
-	}
503
+    } else {
504
+        Display::display_warning_message(get_lang('FileNotFound'));
505
+    }
506 506
 } else {
507 507
     if ($slide_id != 'all') {
508 508
         Display::display_warning_message(get_lang('NoDataAvailable'));
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 if ($slide_id != 'all') {
65 65
 	$image = null;
66 66
 	if (isset($image_files_only[$slide])) {
67
-		$image = $sys_course_path . $_course['path'] . '/document' . $folder . $image_files_only[$slide];
67
+		$image = $sys_course_path.$_course['path'].'/document'.$folder.$image_files_only[$slide];
68 68
 	}
69 69
 	if (file_exists($image)) {
70 70
 		echo '<div class="actions-pagination">';
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
             $last = Display::return_icon('action_last_na.png', get_lang('LastSlide'));
106 106
 		} else {
107 107
 			$imgn = 'action_next.png';
108
-			$last = '<a href="slideshow.php?slide_id='.($total_slides-1).'&curdirpath='.$pathurl.'">
108
+			$last = '<a href="slideshow.php?slide_id='.($total_slides - 1).'&curdirpath='.$pathurl.'">
109 109
 			        '.Display::return_icon('action_last.png', get_lang('LastSlide')).'
110 110
                 </a>';
111 111
 		}
@@ -122,18 +122,18 @@  discard block
 block discarded – undo
122 122
 
123 123
 // Exit the slideshow
124 124
 echo '<a href="document.php?action=exit_slideshow&curdirpath='.$pathurl.'&'.api_get_cidreq().'">'.
125
-    Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('DocumentsOverview'),'',ICON_SIZE_MEDIUM).'</a>';
125
+    Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>';
126 126
 
127 127
 // Show thumbnails
128 128
 if ($slide_id != 'all') {
129 129
 	echo '<a href="slideshow.php?slide_id=all&curdirpath='.$pathurl.'&'.api_get_cidreq().'">'.
130
-        Display::return_icon('thumbnails.png',get_lang('ShowThumbnails'),'',ICON_SIZE_MEDIUM).'</a>';
130
+        Display::return_icon('thumbnails.png', get_lang('ShowThumbnails'), '', ICON_SIZE_MEDIUM).'</a>';
131 131
 } else {
132
-	echo Display::return_icon('thumbnails_na.png',get_lang('ShowThumbnails'),'',ICON_SIZE_MEDIUM);
132
+	echo Display::return_icon('thumbnails_na.png', get_lang('ShowThumbnails'), '', ICON_SIZE_MEDIUM);
133 133
 }
134 134
 // Slideshow options
135 135
 echo '<a href="slideshowoptions.php?curdirpath='.$pathurl.'&'.api_get_cidreq().'">'.
136
-    Display::return_icon('settings.png', get_lang('SetSlideshowOptions'),'',ICON_SIZE_MEDIUM).'</a>';
136
+    Display::return_icon('settings.png', get_lang('SetSlideshowOptions'), '', ICON_SIZE_MEDIUM).'</a>';
137 137
 
138 138
 echo '</div>';
139 139
 echo '<br />';
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 }
158 158
 $target_width = $target_height = null;
159 159
 // The target height and width depends if we choose resizing or no resizing
160
-if (isset($_SESSION["image_resizing"]) &&  $_SESSION["image_resizing"] == "resizing") {
160
+if (isset($_SESSION["image_resizing"]) && $_SESSION["image_resizing"] == "resizing") {
161 161
 	$target_width = $_SESSION["image_resizing_width"];
162 162
 	$target_height = $_SESSION["image_resizing_height"];
163 163
 }
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 /*	THUMBNAIL VIEW */
166 166
 
167 167
 // This is for viewing all the images in the slideshow as thumbnails.
168
-$image_tag = array ();
168
+$image_tag = array();
169 169
 $html = '';
170 170
 if ($slide_id == 'all') {
171 171
 
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	$max_thumbnail_width     = 250;
175 175
 	$max_thumbnail_height    = 250;
176 176
 	$png_compression	     = 0; // 0(none)-9
177
-	$jpg_quality  	         = 75; // from 0 to 100 (default is 75). More quality less compression
177
+	$jpg_quality = 75; // from 0 to 100 (default is 75). More quality less compression
178 178
 
179 179
 	$directory_thumbnails = $sys_course_path.$_course['path'].'/document'.$folder.'.thumbs/';
180 180
 
181 181
 	//Other parameters only for show tumbnails
182
-	$row_items 			     = 4;//only in slideshow.php
183
-	$number_image 			 = 7;//num icons cols to show
184
-	$thumbnail_width_frame = $max_thumbnail_width;//optional $max_thumbnail_width+x
182
+	$row_items = 4; //only in slideshow.php
183
+	$number_image = 7; //num icons cols to show
184
+	$thumbnail_width_frame = $max_thumbnail_width; //optional $max_thumbnail_width+x
185 185
 	$thumbnail_height_frame = $max_thumbnail_height;
186 186
 
187 187
 	// Create the template_thumbnails folder (if no exist)
@@ -195,20 +195,20 @@  discard block
 block discarded – undo
195 195
 
196 196
 		foreach ($image_files_only as $one_image_file) {
197 197
 			$image = $sys_course_path.$_course['path'].'/document'.$folder.$one_image_file;
198
-			$image_thumbnail= $directory_thumbnails.'.'.$one_image_file;
198
+			$image_thumbnail = $directory_thumbnails.'.'.$one_image_file;
199 199
 
200 200
 			if (file_exists($image)) {
201 201
 				//check thumbnail
202 202
 				$imagetype = explode(".", $image);
203 203
                 //or check $imagetype = image_type_to_extension(exif_imagetype($image), false);
204
-				$imagetype = strtolower($imagetype[count($imagetype)-1]);
204
+				$imagetype = strtolower($imagetype[count($imagetype) - 1]);
205 205
 
206
-				if (in_array($imagetype,$allowed_thumbnail_types)) {
207
-					if (!file_exists($image_thumbnail)){
206
+				if (in_array($imagetype, $allowed_thumbnail_types)) {
207
+					if (!file_exists($image_thumbnail)) {
208 208
                         //run each once we view thumbnails is too heavy, then need move into  !file_exists($image_thumbnail, and only run when haven't the thumbnail
209 209
 						$original_image_size = api_getimagesize($image);
210 210
 
211
-						switch($imagetype) {
211
+						switch ($imagetype) {
212 212
 							case 'gif':
213 213
 								$source_img = imagecreatefromgif($image);
214 214
 								break;
@@ -229,17 +229,17 @@  discard block
 block discarded – undo
229 229
                             $max_thumbnail_width,
230 230
                             $max_thumbnail_height
231 231
                         );
232
-						if ($max_thumbnail_width>$original_image_size['width'] && $max_thumbnail_height>$original_image_size['height']){
233
-							$new_thumbnail_size['width']=$original_image_size['width'];
234
-							$new_thumbnail_size['height']=$original_image_size['height'];
232
+						if ($max_thumbnail_width > $original_image_size['width'] && $max_thumbnail_height > $original_image_size['height']) {
233
+							$new_thumbnail_size['width'] = $original_image_size['width'];
234
+							$new_thumbnail_size['height'] = $original_image_size['height'];
235 235
 						}
236 236
 
237 237
 						$crop = imagecreatetruecolor($new_thumbnail_size['width'], $new_thumbnail_size['height']);
238 238
 
239 239
 						// preserve transparency
240
-						if ($imagetype == "png"){
240
+						if ($imagetype == "png") {
241 241
 							imagesavealpha($crop, true);
242
-							$color = imagecolorallocatealpha($crop,0x00,0x00,0x00,127);
242
+							$color = imagecolorallocatealpha($crop, 0x00, 0x00, 0x00, 127);
243 243
 							imagefill($crop, 0, 0, $color);
244 244
 						}
245 245
 
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 							$transindex = imagecolortransparent($source_img);
248 248
                             $palletsize = imagecolorstotal($source_img);
249 249
 							 //GIF89a for transparent and anim (first clip), either GIF87a
250
-							 if ($transindex >= 0 && $transindex < $palletsize){
250
+							 if ($transindex >= 0 && $transindex < $palletsize) {
251 251
 								 $transcol = imagecolorsforindex($source_img, $transindex);
252 252
 								 $transindex = imagecolorallocatealpha($crop, $transcol['red'], $transcol['green'], $transcol['blue'], 127);
253 253
 								 imagefill($crop, 0, 0, $transindex);
@@ -271,16 +271,16 @@  discard block
 block discarded – undo
271 271
 
272 272
 						switch ($imagetype) {
273 273
 							case 'gif':
274
-								imagegif($crop,$image_thumbnail);
274
+								imagegif($crop, $image_thumbnail);
275 275
 								break;
276 276
 							case 'jpg':
277
-								imagejpeg($crop,$image_thumbnail,$jpg_quality);
277
+								imagejpeg($crop, $image_thumbnail, $jpg_quality);
278 278
 								break;
279 279
 							case 'jpeg':
280
-								imagejpeg($crop,$image_thumbnail,$jpg_quality);
280
+								imagejpeg($crop, $image_thumbnail, $jpg_quality);
281 281
 								break;
282 282
 							case 'png':
283
-								imagepng($crop,$image_thumbnail,$png_compression);
283
+								imagepng($crop, $image_thumbnail, $png_compression);
284 284
 								break;
285 285
 						}
286 286
 
@@ -290,26 +290,26 @@  discard block
 block discarded – undo
290 290
 
291 291
 					//show thumbnail and link
292 292
 
293
-					$one_image_thumbnail_file='.thumbs/.'.$one_image_file;//get path thumbnail
293
+					$one_image_thumbnail_file = '.thumbs/.'.$one_image_file; //get path thumbnail
294 294
 					$doc_url = ($path && $path !== '/') ? $path.'/'.$one_image_thumbnail_file : $path.$one_image_thumbnail_file;
295 295
 					$image_tag[] = '<img class="img-gallery" src="download.php?doc_url='.$doc_url.'" border="0" title="'.$one_image_file.'">';
296 296
 				} else {
297 297
 					//if images aren't support by gd (not gif, jpg, jpeg, png)
298
-					if ($imagetype=="bmp") {
298
+					if ($imagetype == "bmp") {
299 299
                         // use getimagesize instead api_getimagesize($image); becasuse api_getimagesize doesn't support bmp files. Put here for each show, only for a few bmp files isn't heavy
300 300
 						$original_image_size = getimagesize($image);
301
-						if ($max_thumbnail_width<$original_image_size[0] || $max_thumbnail_height<$original_image_size[1]){
302
-							$thumbnail_size=api_calculate_image_size($original_image_size[0], $original_image_size[1], $max_thumbnail_width, $max_thumbnail_height);//don't use resize_image because doesn't run with bmp files
301
+						if ($max_thumbnail_width < $original_image_size[0] || $max_thumbnail_height < $original_image_size[1]) {
302
+							$thumbnail_size = api_calculate_image_size($original_image_size[0], $original_image_size[1], $max_thumbnail_width, $max_thumbnail_height); //don't use resize_image because doesn't run with bmp files
303 303
 							$image_height = $thumbnail_size['height'];
304 304
 							$image_width  = $thumbnail_size['width'];
305 305
 						} else {
306
-							$image_height=$original_image_size[0];
307
-							$image_width=$original_image_size[1];
306
+							$image_height = $original_image_size[0];
307
+							$image_width = $original_image_size[1];
308 308
 						}
309 309
 					} else {
310 310
 						//example for svg files,...
311
-						$image_width=$max_thumbnail_width;
312
-						$image_height=$max_thumbnail_height;
311
+						$image_width = $max_thumbnail_width;
312
+						$image_height = $max_thumbnail_height;
313 313
 					}
314 314
 
315 315
 					$doc_url = ($path && $path !== '/') ? $path.'/'.$one_image_file : $path.$one_image_file;
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 
326 326
 	$i = 0;
327 327
 	$count_image = count($image_tag);
328
-	$number_iteration = ceil($count_image/$number_image);
328
+	$number_iteration = ceil($count_image / $number_image);
329 329
 	$p = 0;
330 330
     $html = '';
331 331
     $html .= '<div class="gallery">';
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
                             $html .= '<a class="canvas-two" href="slideshow.php?slide_id='.$p.'&curdirpath='.$pathurl.'">';
338 338
                             $html .= '<div class="frame">';
339 339
                             $html .= '<div class="photo">';
340
-                            $html .=  $image_tag[$p];
340
+                            $html .= $image_tag[$p];
341 341
                             $html .= '</div>';
342 342
                             $html .= '</div>';
343 343
                             $html .= '</a>';
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 
393 393
 		list($width, $height) = getimagesize($image);
394 394
 		// Auto resize
395
-		if (isset($_SESSION["image_resizing"]) &&  $_SESSION["image_resizing"] == 'resizing') {
395
+		if (isset($_SESSION["image_resizing"]) && $_SESSION["image_resizing"] == 'resizing') {
396 396
 		?>
397 397
 
398 398
 		<script type="text/javascript">
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 				start_height=initial_height;
410 410
 			}
411 411
 
412
-			document.write('<img id="image"  src="<?php echo  'download.php?doc_url='.$path.'/'.$image_files_only[$slide]; ?>" width="'+start_width+'" height="'+start_height+'"  border="0"  alt="<?php echo $image_files_only[$slide] ;?>">');
412
+			document.write('<img id="image"  src="<?php echo  'download.php?doc_url='.$path.'/'.$image_files_only[$slide]; ?>" width="'+start_width+'" height="'+start_height+'"  border="0"  alt="<?php echo $image_files_only[$slide]; ?>">');
413 413
 
414 414
 			function resizeImage() {
415 415
 
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 		echo '</a>';
454 454
         echo '<div class="caption text-center">';
455 455
         echo Display::tag('h3', $row['title']);
456
-        echo '<p>' . $row['comment'] . '</p>';
456
+        echo '<p>'.$row['comment'].'</p>';
457 457
         echo '</div>';
458 458
         echo '</div>';
459 459
 
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
                 $resize_info = get_lang('Resizing').'<br />';
467 467
                 $resize_width = $_SESSION["image_resizing_width"].' x ';
468 468
                 $resize_height = $_SESSION['image_resizing_height'];
469
-            } elseif (isset($_SESSION['image_resizing']) && $_SESSION['image_resizing'] != 'noresizing'){
469
+            } elseif (isset($_SESSION['image_resizing']) && $_SESSION['image_resizing'] != 'noresizing') {
470 470
                 $resize_info = get_lang('Resizing').'<br />';
471 471
                 $resize_width = get_lang('Auto').' x ';
472 472
                 $resize_height = get_lang('Auto');
@@ -477,10 +477,10 @@  discard block
 block discarded – undo
477 477
             }
478 478
 
479 479
             echo '<li class="text-center">';
480
-            echo $image_files_only[$slide] . ' ';
480
+            echo $image_files_only[$slide].' ';
481 481
             echo Display::toolbarButton(
482 482
                 get_lang('Modify'),
483
-                'edit_document.php?' . api_get_cidreq() . '&' . http_build_query([
483
+                'edit_document.php?'.api_get_cidreq().'&'.http_build_query([
484 484
                     'id' => $row['id'],
485 485
                     'origin' => 'slideshow',
486 486
                     'origin_opt' => $edit_slide_id,
@@ -492,11 +492,11 @@  discard block
 block discarded – undo
492 492
                 false
493 493
             );
494 494
             echo '</li>';
495
-            echo '<li class="text-center">' . $width.' x '.$height . '</li>';
496
-			echo '<li class="text-center">' . round((filesize($image) / 1024), 2) . ' KB - ' . $ext . '</li>';
497
-            echo '<li class="text-center">' . $resize_info . '</li>';
498
-			echo '<li class="text-center">' . $resize_width . '</li>';
499
-			echo '<li class="text-center">' . $resize_height . '</li>';
495
+            echo '<li class="text-center">'.$width.' x '.$height.'</li>';
496
+			echo '<li class="text-center">'.round((filesize($image) / 1024), 2).' KB - '.$ext.'</li>';
497
+            echo '<li class="text-center">'.$resize_info.'</li>';
498
+			echo '<li class="text-center">'.$resize_width.'</li>';
499
+			echo '<li class="text-center">'.$resize_height.'</li>';
500 500
             echo '</ul>';
501 501
 		}
502 502
 
Please login to merge, or discard this patch.