Passed
Push — 1.10.x ( f08406...b77fe8 )
by
unknown
575:03 queued 528:43
created
main/admin/configure_homepage.php 2 patches
Indentation   +846 added lines, -846 removed lines patch added patch discarded remove patch
@@ -17,35 +17,35 @@  discard block
 block discarded – undo
17 17
  */
18 18
 function home_tabs($file_logged_in)
19 19
 {
20
-	$post = strpos($file_logged_in, "_logged_in");
21
-	if ($post !== false) {
22
-		$file_logged_out = str_replace('_logged_in','', $file_logged_in);
23
-		//variables initialization
24
-		$data_logged_out = array();
25
-		$data_logged_in  = array();
26
-
27
-		//we read the file with all links
28
-		$file = file($file_logged_in);
29
-		foreach ($file as $line) {
30
-			$line = str_replace("\n", '',$line);
31
-			//not logged user only sees public links
32
-			if (!preg_match('/::private/',$line)) {
33
-				$data_logged_out[] = $line;
34
-			}
35
-			//logged user only sees all links
36
-			$data_logged_in[] = $line;
37
-		}
38
-		//tabs file for logged out users
39
-		if (file_exists($file_logged_out)) {
40
-			$fp = fopen($file_logged_out, 'w');
41
-			fputs($fp, implode("\n", $data_logged_out));
42
-			fclose($fp);
43
-		}
44
-		//tabs file for logged in users
45
-		$fp = fopen($file_logged_in, 'w');
46
-		fputs($fp, implode("\n", $data_logged_in));
47
-		fclose($fp);
48
-	}
20
+    $post = strpos($file_logged_in, "_logged_in");
21
+    if ($post !== false) {
22
+        $file_logged_out = str_replace('_logged_in','', $file_logged_in);
23
+        //variables initialization
24
+        $data_logged_out = array();
25
+        $data_logged_in  = array();
26
+
27
+        //we read the file with all links
28
+        $file = file($file_logged_in);
29
+        foreach ($file as $line) {
30
+            $line = str_replace("\n", '',$line);
31
+            //not logged user only sees public links
32
+            if (!preg_match('/::private/',$line)) {
33
+                $data_logged_out[] = $line;
34
+            }
35
+            //logged user only sees all links
36
+            $data_logged_in[] = $line;
37
+        }
38
+        //tabs file for logged out users
39
+        if (file_exists($file_logged_out)) {
40
+            $fp = fopen($file_logged_out, 'w');
41
+            fputs($fp, implode("\n", $data_logged_out));
42
+            fclose($fp);
43
+        }
44
+        //tabs file for logged in users
45
+        $fp = fopen($file_logged_in, 'w');
46
+        fputs($fp, implode("\n", $data_logged_in));
47
+        fclose($fp);
48
+    }
49 49
 }
50 50
 
51 51
 $cidReset = true;
@@ -76,39 +76,39 @@  discard block
 block discarded – undo
76 76
 $_languages = api_get_languages();
77 77
 $selfUrl =  api_get_self();
78 78
 $interbreadcrumb[] = array(
79
-	'url' => 'index.php',
80
-	'name' => get_lang('PlatformAdmin')
79
+    'url' => 'index.php',
80
+    'name' => get_lang('PlatformAdmin')
81 81
 );
82 82
 
83 83
 if (!empty($action)) {
84
-	$interbreadcrumb[] = array(
85
-		'url' => 'configure_homepage.php',
86
-		'name' => get_lang('ConfigureHomePage')
87
-	);
88
-
89
-	switch ($action) {
90
-		case 'edit_top':
91
-			$tool_name = get_lang('EditHomePage');
92
-			break;
93
-		case 'edit_news':
94
-			$tool_name = get_lang('EditNews');
95
-			break;
96
-		case 'edit_notice':
97
-			$tool_name = get_lang('EditNotice');
98
-			break;
99
-		case 'insert_link':
100
-			$tool_name = get_lang('InsertLink');
101
-			break;
102
-		case 'edit_link':
103
-			$tool_name = get_lang('EditLink');
104
-			break;
105
-		case 'insert_tabs':
106
-			$tool_name = get_lang('InsertTabs');
107
-			break;
108
-		case 'edit_tabs':
109
-			$tool_name = get_lang('EditTabs');
110
-			break;
111
-	}
84
+    $interbreadcrumb[] = array(
85
+        'url' => 'configure_homepage.php',
86
+        'name' => get_lang('ConfigureHomePage')
87
+    );
88
+
89
+    switch ($action) {
90
+        case 'edit_top':
91
+            $tool_name = get_lang('EditHomePage');
92
+            break;
93
+        case 'edit_news':
94
+            $tool_name = get_lang('EditNews');
95
+            break;
96
+        case 'edit_notice':
97
+            $tool_name = get_lang('EditNotice');
98
+            break;
99
+        case 'insert_link':
100
+            $tool_name = get_lang('InsertLink');
101
+            break;
102
+        case 'edit_link':
103
+            $tool_name = get_lang('EditLink');
104
+            break;
105
+        case 'insert_tabs':
106
+            $tool_name = get_lang('InsertTabs');
107
+            break;
108
+        case 'edit_tabs':
109
+            $tool_name = get_lang('EditTabs');
110
+            break;
111
+    }
112 112
 }
113 113
 
114 114
 // The global logic for language priorities should be:
@@ -131,11 +131,11 @@  discard block
 block discarded – undo
131 131
 
132 132
 $lang = ''; //el for "Edit Language"
133 133
 if (!empty($_SESSION['user_language_choice'])) {
134
-	$lang = $_SESSION['user_language_choice'];
134
+    $lang = $_SESSION['user_language_choice'];
135 135
 } elseif (!empty($_SESSION['_user']['language'])) {
136
-	$lang = $_SESSION['_user']['language'];
136
+    $lang = $_SESSION['_user']['language'];
137 137
 } else {
138
-	$lang = api_get_setting('platformLanguage');
138
+    $lang = api_get_setting('platformLanguage');
139 139
 }
140 140
 
141 141
 $languageGet = isset($_GET['language']) ? Security::remove_XSS($_GET['language']) : $lang;
@@ -144,25 +144,25 @@  discard block
 block discarded – undo
144 144
 $homePath = api_get_path(SYS_APP_PATH).'home/';
145 145
 
146 146
 if (api_is_multiple_url_enabled()) {
147
-	$access_url_id = api_get_current_access_url_id();
148
-	if ($access_url_id != -1) {
149
-		$url_info = api_get_access_url($access_url_id);
150
-		$url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
151
-		$clean_url = api_replace_dangerous_char($url);
152
-		$clean_url = str_replace('/', '-', $clean_url);
153
-		$clean_url .= '/';
154
-
155
-		$homep = $homePath; //homep for Home Path
156
-		$homep_new = $homePath.$clean_url; //homep for Home Path added the url
157
-		$new_url_dir = $homePath.$clean_url;
158
-		//we create the new dir for the new sites
159
-		if (!is_dir($new_url_dir)) {
160
-			mkdir($new_url_dir, api_get_permissions_for_new_directories());
161
-		}
162
-	}
147
+    $access_url_id = api_get_current_access_url_id();
148
+    if ($access_url_id != -1) {
149
+        $url_info = api_get_access_url($access_url_id);
150
+        $url = api_remove_trailing_slash(preg_replace('/https?:\/\//i', '', $url_info['url']));
151
+        $clean_url = api_replace_dangerous_char($url);
152
+        $clean_url = str_replace('/', '-', $clean_url);
153
+        $clean_url .= '/';
154
+
155
+        $homep = $homePath; //homep for Home Path
156
+        $homep_new = $homePath.$clean_url; //homep for Home Path added the url
157
+        $new_url_dir = $homePath.$clean_url;
158
+        //we create the new dir for the new sites
159
+        if (!is_dir($new_url_dir)) {
160
+            mkdir($new_url_dir, api_get_permissions_for_new_directories());
161
+        }
162
+    }
163 163
 } else {
164
-	$homep_new = '';
165
-	$homep = $homePath; //homep for Home Path
164
+    $homep_new = '';
165
+    $homep = $homePath; //homep for Home Path
166 166
 }
167 167
 
168 168
 $menuf = 'home_menu'; //menuf for Menu File
@@ -177,25 +177,25 @@  discard block
 block discarded – undo
177 177
 
178 178
 // If language-specific file does not exist, create it by copying default file
179 179
 foreach ($homef as $my_file) {
180
-	if (api_is_multiple_url_enabled()) {
181
-		if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) {
182
-			if (!file_exists($homep.$my_file.$ext)) {
183
-				touch($homep.$my_file.$ext);
184
-			}
185
-			@copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext);
186
-		}
187
-	} else {
188
-		if (!file_exists($homep.$my_file.'_'.$lang.$ext)) {
189
-			if (!file_exists($homep.$my_file.$ext)) {
190
-				touch($homep.$my_file.$ext);
191
-			}
192
-			@copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext);
193
-		}
194
-	}
180
+    if (api_is_multiple_url_enabled()) {
181
+        if (!file_exists($homep_new.$my_file.'_'.$lang.$ext)) {
182
+            if (!file_exists($homep.$my_file.$ext)) {
183
+                touch($homep.$my_file.$ext);
184
+            }
185
+            @copy($homep.$my_file.$ext, $homep_new.$my_file.'_'.$lang.$ext);
186
+        }
187
+    } else {
188
+        if (!file_exists($homep.$my_file.'_'.$lang.$ext)) {
189
+            if (!file_exists($homep.$my_file.$ext)) {
190
+                touch($homep.$my_file.$ext);
191
+            }
192
+            @copy($homep.$my_file.$ext, $homep.$my_file.'_'.$lang.$ext);
193
+        }
194
+    }
195 195
 }
196 196
 
197 197
 if (api_is_multiple_url_enabled()) {
198
-	$homep = $homep_new;
198
+    $homep = $homep_new;
199 199
 }
200 200
 
201 201
 // Check WCAG settings and prepare edition using WCAG
@@ -204,576 +204,576 @@  discard block
 block discarded – undo
204 204
 // Filter link param
205 205
 $link = '';
206 206
 if (!empty($_GET['link'])) {
207
-	$link = $_GET['link'];
208
-	// If the link parameter is suspicious, empty it
209
-	if (strstr($link, '/') || !strstr($link, '.html') || strstr($link, '\\')) {
210
-		$link = '';
211
-		$action = '';
212
-	}
207
+    $link = $_GET['link'];
208
+    // If the link parameter is suspicious, empty it
209
+    if (strstr($link, '/') || !strstr($link, '.html') || strstr($link, '\\')) {
210
+        $link = '';
211
+        $action = '';
212
+    }
213 213
 }
214 214
 
215 215
 // Start analysing requested actions
216 216
 if (!empty($action)) {
217
-	if (!empty($_POST['formSent'])) {
218
-		// Variables used are $homep for home path, $menuf for menu file, $newsf
219
-		// for news file, $topf for top file, $noticef for noticefile,
220
-		// $ext for '.html'
221
-		switch ($action) {
222
-			case 'edit_top':
223
-				// Filter
224
-				$home_top = trim(stripslashes($_POST['home_top']));
225
-
226
-				// Write
227
-				if (is_writable($homep)) {
228
-					// Default
229
-					if (is_writable($homep.$topf.'_'.$lang.$ext)) {
230
-						$fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
231
-						fputs($fp, $home_top);
232
-						fclose($fp);
233
-
234
-						// Language
235
-						foreach ($_languages['name'] as $key => $value) {
236
-							$lang_name = $_languages['folder'][$key];
237
-							if (isset($_POST[$lang_name])) {
238
-								$fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
239
-								fputs($fp, $home_top);
240
-								fclose($fp);
241
-							}
242
-						}
243
-					} else {
244
-						$errorMsg = get_lang('HomePageFilesNotWritable');
245
-					}
246
-				} else {
247
-					//File does not exist
248
-					$fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
249
-					fputs($fp, $home_top);
250
-					fclose($fp);
251
-
252
-					foreach ($_languages['name'] as $key => $value) {
253
-						$lang_name = $_languages['folder'][$key];
254
-						if (isset($_POST[$lang_name])) {
255
-							if (file_exists($homep.$topf.'_'.$lang_name.$ext)) {
256
-								$fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
257
-								fputs($fp, $home_top);
258
-								fclose($fp);
259
-							}
260
-						}
261
-					}
262
-				}
263
-
264
-				if (EventsMail::check_if_using_class('portal_homepage_edited')) {
265
-					EventsDispatcher::events('portal_homepage_edited',array('about_user' => api_get_user_id()));
266
-				}
267
-				Event::addEvent(
268
-					LOG_HOMEPAGE_CHANGED,
269
-					'edit_top',
270
-					cut(strip_tags($home_top), 254),
271
-					api_get_utc_datetime(),
272
-					api_get_user_id()
273
-				);
274
-				break;
275
-			case 'edit_notice':
276
-				// Filter
277
-				$notice_title = trim(strip_tags(stripslashes($_POST['notice_title'])));
278
-				$notice_text = trim(str_replace(array("\r", "\n"), array('', '<br />'), strip_tags(stripslashes($_POST['notice_text']), '<a>')));
279
-				if (empty($notice_title) || empty($notice_text)) {
280
-					$errorMsg = get_lang('NoticeWillBeNotDisplayed');
281
-				}
282
-				// Write
283
-				if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
284
-					if (is_writable($homep.$noticef.'_'.$lang.$ext)) {
285
-						$fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
286
-						if ($errorMsg == '') {
287
-							fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
288
-
289
-							foreach ($_languages['name'] as $key => $value) {
290
-								$lang_name = $_languages['folder'][$key];
291
-								if (isset($_POST[$lang_name])) {
292
-									if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
293
-										if (is_writable($homep.$noticef.'_'.$lang_name.$ext)) {
294
-											$fp = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
295
-											fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
296
-											fclose($fp);
297
-										}
298
-									}
299
-								}
300
-							}
301
-						} else {
302
-							fputs($fp, '');
303
-
304
-							foreach ($_languages['name'] as $key => $value) {
305
-								$lang_name = $_languages['folder'][$key];
306
-								if (isset($_POST[$lang_name])) {
307
-									if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
308
-										$fp1 = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
309
-										fputs($fp1, '');
310
-										fclose($fp1);
311
-									}
312
-								}
313
-							}
314
-						}
315
-						fclose($fp);
316
-					} else {
317
-						$errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable');
318
-					}
319
-				} else {
320
-					//File does not exist
321
-					$fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
322
-					fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
323
-					fclose($fp);
324
-				}
325
-				Event::addEvent(
217
+    if (!empty($_POST['formSent'])) {
218
+        // Variables used are $homep for home path, $menuf for menu file, $newsf
219
+        // for news file, $topf for top file, $noticef for noticefile,
220
+        // $ext for '.html'
221
+        switch ($action) {
222
+            case 'edit_top':
223
+                // Filter
224
+                $home_top = trim(stripslashes($_POST['home_top']));
225
+
226
+                // Write
227
+                if (is_writable($homep)) {
228
+                    // Default
229
+                    if (is_writable($homep.$topf.'_'.$lang.$ext)) {
230
+                        $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
231
+                        fputs($fp, $home_top);
232
+                        fclose($fp);
233
+
234
+                        // Language
235
+                        foreach ($_languages['name'] as $key => $value) {
236
+                            $lang_name = $_languages['folder'][$key];
237
+                            if (isset($_POST[$lang_name])) {
238
+                                $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
239
+                                fputs($fp, $home_top);
240
+                                fclose($fp);
241
+                            }
242
+                        }
243
+                    } else {
244
+                        $errorMsg = get_lang('HomePageFilesNotWritable');
245
+                    }
246
+                } else {
247
+                    //File does not exist
248
+                    $fp = fopen($homep.$topf.'_'.$lang.$ext, 'w');
249
+                    fputs($fp, $home_top);
250
+                    fclose($fp);
251
+
252
+                    foreach ($_languages['name'] as $key => $value) {
253
+                        $lang_name = $_languages['folder'][$key];
254
+                        if (isset($_POST[$lang_name])) {
255
+                            if (file_exists($homep.$topf.'_'.$lang_name.$ext)) {
256
+                                $fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
257
+                                fputs($fp, $home_top);
258
+                                fclose($fp);
259
+                            }
260
+                        }
261
+                    }
262
+                }
263
+
264
+                if (EventsMail::check_if_using_class('portal_homepage_edited')) {
265
+                    EventsDispatcher::events('portal_homepage_edited',array('about_user' => api_get_user_id()));
266
+                }
267
+                Event::addEvent(
268
+                    LOG_HOMEPAGE_CHANGED,
269
+                    'edit_top',
270
+                    cut(strip_tags($home_top), 254),
271
+                    api_get_utc_datetime(),
272
+                    api_get_user_id()
273
+                );
274
+                break;
275
+            case 'edit_notice':
276
+                // Filter
277
+                $notice_title = trim(strip_tags(stripslashes($_POST['notice_title'])));
278
+                $notice_text = trim(str_replace(array("\r", "\n"), array('', '<br />'), strip_tags(stripslashes($_POST['notice_text']), '<a>')));
279
+                if (empty($notice_title) || empty($notice_text)) {
280
+                    $errorMsg = get_lang('NoticeWillBeNotDisplayed');
281
+                }
282
+                // Write
283
+                if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
284
+                    if (is_writable($homep.$noticef.'_'.$lang.$ext)) {
285
+                        $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
286
+                        if ($errorMsg == '') {
287
+                            fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
288
+
289
+                            foreach ($_languages['name'] as $key => $value) {
290
+                                $lang_name = $_languages['folder'][$key];
291
+                                if (isset($_POST[$lang_name])) {
292
+                                    if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
293
+                                        if (is_writable($homep.$noticef.'_'.$lang_name.$ext)) {
294
+                                            $fp = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
295
+                                            fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
296
+                                            fclose($fp);
297
+                                        }
298
+                                    }
299
+                                }
300
+                            }
301
+                        } else {
302
+                            fputs($fp, '');
303
+
304
+                            foreach ($_languages['name'] as $key => $value) {
305
+                                $lang_name = $_languages['folder'][$key];
306
+                                if (isset($_POST[$lang_name])) {
307
+                                    if (file_exists($homep.$noticef.'_'.$lang_name.$ext)) {
308
+                                        $fp1 = fopen($homep.$noticef.'_'.$lang_name.$ext, 'w');
309
+                                        fputs($fp1, '');
310
+                                        fclose($fp1);
311
+                                    }
312
+                                }
313
+                            }
314
+                        }
315
+                        fclose($fp);
316
+                    } else {
317
+                        $errorMsg .= "<br/>\n".get_lang('HomePageFilesNotWritable');
318
+                    }
319
+                } else {
320
+                    //File does not exist
321
+                    $fp = fopen($homep.$noticef.'_'.$lang.$ext, 'w');
322
+                    fputs($fp, "<h5>$notice_title</h5><p>\n$notice_text");
323
+                    fclose($fp);
324
+                }
325
+                Event::addEvent(
326 326
                     LOG_HOMEPAGE_CHANGED,
327 327
                     'edit_notice',
328 328
                     cut(strip_tags($notice_title), 254),
329 329
                     api_get_utc_datetime(),
330 330
                     api_get_user_id()
331 331
                 );
332
-				break;
333
-			case 'edit_news':
334
-				//Filter
335
-				$home_news = trim(stripslashes($_POST['home_news']));
336
-
337
-				//Write
338
-				if ($s_languages_news != 'all') {
339
-					if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) {
340
-						if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) {
341
-							$fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
342
-							fputs($fp, $home_news);
343
-							fclose($fp);
344
-						} else {
345
-							$errorMsg = get_lang('HomePageFilesNotWritable');
346
-						}
347
-					} else {
348
-						// File does not exist
349
-						$fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
350
-						fputs($fp, $home_news);
351
-						fclose($fp);
352
-					}
353
-				} else {
354
-					// We update all the news file
355
-					foreach ($_languages['name'] as $key => $value) {
356
-						$english_name = $_languages['folder'][$key];
357
-						if (file_exists($homep.$newsf.'_'.$english_name.$ext)) {
358
-							if (is_writable($homep.$newsf.'_'.$english_name.$ext)) {
359
-								$fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
360
-								fputs($fp, $home_news);
361
-								fclose($fp);
362
-							} else {
363
-								$errorMsg = get_lang('HomePageFilesNotWritable');
364
-							}
365
-						} else {
366
-							// File does not exist
367
-							$fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
368
-							fputs($fp, $home_news);
369
-							fclose($fp);
370
-						}
371
-					}
372
-				}
373
-				Event::addEvent(
332
+                break;
333
+            case 'edit_news':
334
+                //Filter
335
+                $home_news = trim(stripslashes($_POST['home_news']));
336
+
337
+                //Write
338
+                if ($s_languages_news != 'all') {
339
+                    if (file_exists($homep.$newsf.'_'.$s_languages_news.$ext)) {
340
+                        if (is_writable($homep.$newsf.'_'.$s_languages_news.$ext)) {
341
+                            $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
342
+                            fputs($fp, $home_news);
343
+                            fclose($fp);
344
+                        } else {
345
+                            $errorMsg = get_lang('HomePageFilesNotWritable');
346
+                        }
347
+                    } else {
348
+                        // File does not exist
349
+                        $fp = fopen($homep.$newsf.'_'.$s_languages_news.$ext, 'w');
350
+                        fputs($fp, $home_news);
351
+                        fclose($fp);
352
+                    }
353
+                } else {
354
+                    // We update all the news file
355
+                    foreach ($_languages['name'] as $key => $value) {
356
+                        $english_name = $_languages['folder'][$key];
357
+                        if (file_exists($homep.$newsf.'_'.$english_name.$ext)) {
358
+                            if (is_writable($homep.$newsf.'_'.$english_name.$ext)) {
359
+                                $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
360
+                                fputs($fp, $home_news);
361
+                                fclose($fp);
362
+                            } else {
363
+                                $errorMsg = get_lang('HomePageFilesNotWritable');
364
+                            }
365
+                        } else {
366
+                            // File does not exist
367
+                            $fp = fopen($homep.$newsf.'_'.$english_name.$ext, 'w');
368
+                            fputs($fp, $home_news);
369
+                            fclose($fp);
370
+                        }
371
+                    }
372
+                }
373
+                Event::addEvent(
374 374
                     LOG_HOMEPAGE_CHANGED,
375 375
                     'edit_news',
376 376
                     strip_tags(cut($home_news, 254)),
377 377
                     api_get_utc_datetime(),
378 378
                     api_get_user_id()
379 379
                 );
380
-				break;
381
-			case 'insert_tabs':
382
-			case 'edit_tabs':
383
-			case 'insert_link':
384
-			case 'edit_link':
385
-				$link_index     = intval($_POST['link_index']);
386
-				$insert_where   = intval($_POST['insert_where']);
387
-				$link_name      = trim(stripslashes($_POST['link_name']));
388
-				$link_url       = trim(stripslashes($_POST['link_url']));
389
-				$add_in_tab     = intval($_POST['add_in_tab']);
390
-				$link_html = trim(stripslashes($_POST['link_html']));
391
-				$filename = trim(stripslashes($_POST['filename']));
392
-				$target_blank = $_POST['target_blank'] ? true : false;
393
-
394
-				if ($link_url == 'http://' || $link_url == 'https://') {
395
-					$link_url = '';
396
-				} elseif (!empty($link_url) && !strstr($link_url, '://')) {
397
-					$link_url='http://'.$link_url;
398
-				}
399
-				$menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $mtloggedin : $menuf;
400
-
401
-				if (!is_writable($homep.$menuf.'_'.$lang.$ext)) {
402
-					$errorMsg = get_lang('HomePageFilesNotWritable');
403
-				} elseif (empty($link_name)) {
404
-					$errorMsg = get_lang('PleaseEnterLinkName');
405
-				} else {
406
-					// New links are added as new files in the home/ directory
407
-					if ($action == 'insert_link' || $action == 'insert_tabs' || empty($filename) || strstr($filename, '/') || !strstr($filename, '.html')) {
408
-						$filename = api_replace_dangerous_char($link_name).'.html';
409
-					}
410
-
411
-					// "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files)
412
-					if (!empty($filename)) {
413
-						$filename = str_replace('home_', 'user_', $filename);
414
-					}
415
-					// If the typical language suffix is not found in the file name,
416
-					// replace the ".html" suffix by "_en.html" or the active menu language
417
-					if (!strstr($filename,'_'.$lang.$ext)) {
418
-						$filename = str_replace($ext, '_'.$lang.$ext, $filename);
419
-					}
420
-					// Get the contents of home_menu_en.html (or active menu language
421
-					// version) into $home_menu as an array of one entry per line
422
-					$home_menu = file($homep.$menuf.'_'.$lang.$ext);
423
-					$home_menu = implode("\n", $home_menu);
424
-					$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
425
-					$home_menu = explode("\n", $home_menu);
426
-					$home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
427
-					// Prepare place to insert the new link into (default is end of file)
428
-					if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) {
429
-						$insert_where = sizeof($home_menu) - 1;
430
-					}
431
-					//
432
-					// For each line of the file, remove trailing spaces and special chars
433
-					//foreach ($home_menu as $key => $enreg) {
434
-					//	$home_menu[$key] = trim($enreg);
435
-					//}
436
-					//
437
-					// If the given link url is empty, then replace the link url by a link to the link file created
438
-
439
-					if (empty($link_url) || $link_url == 'http://' ||  $link_url == 'https://') {
440
-						$link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename);
441
-						// If the file doesn't exist, then create it and
442
-						// fill it with default text
443
-
444
-						$fp = @fopen($homep.$filename, 'w');
445
-						if ($fp) {
446
-							if (empty($link_html)) {
447
-								fputs($fp, get_lang('MyTextHere'));
448
-								home_tabs($homep.$filename);
449
-							} else {
450
-								fputs($fp, $link_html);
451
-								home_tabs($homep.$filename);
452
-							}
453
-							fclose($fp);
454
-						}
455
-					}
456
-					// If the requested action is to edit a link, open the file and
457
-					// write to it (if the file doesn't exist, create it)
458
-					if (in_array($action, array('edit_link'))  && !empty($link_html)) {
459
-						$fp = @fopen($homep.$filename, 'w');
460
-						if ($fp) {
461
-							fputs($fp, $link_html);
462
-							home_tabs($homep.$filename);
463
-							fclose($fp);
464
-						}
465
-					}
380
+                break;
381
+            case 'insert_tabs':
382
+            case 'edit_tabs':
383
+            case 'insert_link':
384
+            case 'edit_link':
385
+                $link_index     = intval($_POST['link_index']);
386
+                $insert_where   = intval($_POST['insert_where']);
387
+                $link_name      = trim(stripslashes($_POST['link_name']));
388
+                $link_url       = trim(stripslashes($_POST['link_url']));
389
+                $add_in_tab     = intval($_POST['add_in_tab']);
390
+                $link_html = trim(stripslashes($_POST['link_html']));
391
+                $filename = trim(stripslashes($_POST['filename']));
392
+                $target_blank = $_POST['target_blank'] ? true : false;
393
+
394
+                if ($link_url == 'http://' || $link_url == 'https://') {
395
+                    $link_url = '';
396
+                } elseif (!empty($link_url) && !strstr($link_url, '://')) {
397
+                    $link_url='http://'.$link_url;
398
+                }
399
+                $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $mtloggedin : $menuf;
400
+
401
+                if (!is_writable($homep.$menuf.'_'.$lang.$ext)) {
402
+                    $errorMsg = get_lang('HomePageFilesNotWritable');
403
+                } elseif (empty($link_name)) {
404
+                    $errorMsg = get_lang('PleaseEnterLinkName');
405
+                } else {
406
+                    // New links are added as new files in the home/ directory
407
+                    if ($action == 'insert_link' || $action == 'insert_tabs' || empty($filename) || strstr($filename, '/') || !strstr($filename, '.html')) {
408
+                        $filename = api_replace_dangerous_char($link_name).'.html';
409
+                    }
410
+
411
+                    // "home_" prefix for links are renamed to "user_" prefix (to avoid name clash with existing home page files)
412
+                    if (!empty($filename)) {
413
+                        $filename = str_replace('home_', 'user_', $filename);
414
+                    }
415
+                    // If the typical language suffix is not found in the file name,
416
+                    // replace the ".html" suffix by "_en.html" or the active menu language
417
+                    if (!strstr($filename,'_'.$lang.$ext)) {
418
+                        $filename = str_replace($ext, '_'.$lang.$ext, $filename);
419
+                    }
420
+                    // Get the contents of home_menu_en.html (or active menu language
421
+                    // version) into $home_menu as an array of one entry per line
422
+                    $home_menu = file($homep.$menuf.'_'.$lang.$ext);
423
+                    $home_menu = implode("\n", $home_menu);
424
+                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
425
+                    $home_menu = explode("\n", $home_menu);
426
+                    $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
427
+                    // Prepare place to insert the new link into (default is end of file)
428
+                    if ($insert_where < -1 || $insert_where > (sizeof($home_menu) - 1)) {
429
+                        $insert_where = sizeof($home_menu) - 1;
430
+                    }
431
+                    //
432
+                    // For each line of the file, remove trailing spaces and special chars
433
+                    //foreach ($home_menu as $key => $enreg) {
434
+                    //	$home_menu[$key] = trim($enreg);
435
+                    //}
436
+                    //
437
+                    // If the given link url is empty, then replace the link url by a link to the link file created
438
+
439
+                    if (empty($link_url) || $link_url == 'http://' ||  $link_url == 'https://') {
440
+                        $link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename);
441
+                        // If the file doesn't exist, then create it and
442
+                        // fill it with default text
443
+
444
+                        $fp = @fopen($homep.$filename, 'w');
445
+                        if ($fp) {
446
+                            if (empty($link_html)) {
447
+                                fputs($fp, get_lang('MyTextHere'));
448
+                                home_tabs($homep.$filename);
449
+                            } else {
450
+                                fputs($fp, $link_html);
451
+                                home_tabs($homep.$filename);
452
+                            }
453
+                            fclose($fp);
454
+                        }
455
+                    }
456
+                    // If the requested action is to edit a link, open the file and
457
+                    // write to it (if the file doesn't exist, create it)
458
+                    if (in_array($action, array('edit_link'))  && !empty($link_html)) {
459
+                        $fp = @fopen($homep.$filename, 'w');
460
+                        if ($fp) {
461
+                            fputs($fp, $link_html);
462
+                            home_tabs($homep.$filename);
463
+                            fclose($fp);
464
+                        }
465
+                    }
466 466
 
467 467
 					
468
-					if (!$add_in_tab) {
469
-						$class_add_in_tab = 'class="hide_menu"';
470
-					}
468
+                    if (!$add_in_tab) {
469
+                        $class_add_in_tab = 'class="hide_menu"';
470
+                    }
471 471
 
472
-					// If the requested action is to create a link, make some room
473
-					// for the new link in the home_menu array at the requested place
474
-					// and insert the new link there
472
+                    // If the requested action is to create a link, make some room
473
+                    // for the new link in the home_menu array at the requested place
474
+                    // and insert the new link there
475 475
                     
476
-					if ($action == 'insert_link' || $action == 'insert_tabs') {
477
-						for ($i = sizeof($home_menu); $i; $i--) {
478
-							if ($i > $insert_where) {
479
-								$home_menu[$i] = $home_menu[$i - 1];
480
-							} else {
481
-								break;
482
-							}
483
-						}
484
-						$home_menu[$insert_where + 1] = '<li><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'. $link_name .'</a></li>';
485
-					} else {
486
-						// If the request is about a link edition, change the link
487
-						$home_menu[$link_index]='<li><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'. $link_name .'</a></li>';
488
-					}
489
-					// Re-build the file from the home_menu array
490
-					$home_menu = implode("\n", $home_menu);
491
-					// Write
492
-					if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
493
-						if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
494
-							$fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
495
-							fputs($fp, $home_menu);
496
-							home_tabs($homep.$menuf.'_'.$lang.$ext);
497
-							fclose($fp);
498
-
499
-							foreach ($_languages['name'] as $key => $value) {
500
-								$lang_name = $_languages['folder'][$key];
501
-								if (isset($_POST[$lang_name])) {
502
-									$fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
503
-									fputs($fp, $home_menu);
504
-									home_tabs($homep.$menuf.'_'.$lang_name.$ext);
505
-									fclose($fp);
506
-								}
507
-							}
508
-
509
-							if (file_exists($homep.$menuf.$ext)) {
510
-								if (is_writable($homep.$menuf.$ext)) {
511
-									$fpo = fopen($homep.$menuf.$ext, 'w');
512
-									fputs($fpo, $home_menu);
513
-									home_tabs($homep.$menuf.$ext);
514
-									fclose($fpo);
515
-								}
516
-							}
517
-						} else {
518
-							$errorMsg = get_lang('HomePageFilesNotWritable');
519
-						}
520
-					} else {
521
-						//File does not exist
522
-						$fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
523
-						fputs($fp, $home_menu);
524
-						home_tabs($homep.$menuf.'_'.$lang.$ext);
525
-						fclose($fp);
526
-
527
-						foreach ($_languages['name'] as $key => $value) {
528
-							$lang_name = $_languages['folder'][$key];
529
-							if (isset($_POST[$lang_name])) {
530
-								$fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
531
-								fputs($fp, $home_menu);
532
-								home_tabs($homep.$menuf.'_'.$lang_name.$ext);
533
-								fclose($fp);
534
-							}
535
-						}
536
-					}
537
-				}
538
-				Event::addEvent(
539
-					LOG_HOMEPAGE_CHANGED,
540
-					$action,
541
-					cut($link_name . ':' . $link_url, 254),
542
-					api_get_utc_datetime(),
543
-					api_get_user_id()
544
-				);
545
-				break;
546
-		} //end of switch($action)
547
-
548
-		if (empty($errorMsg)) {
549
-			header('Location: '.$selfUrl.'?language='.$languageGet);
550
-			exit();
551
-		}
552
-	} else {
553
-		//if POST[formSent] is not set
554
-		switch ($action) {
555
-			case 'open_link':
556
-				// Previously, filtering of GET['link'] was done here but it left
557
-				// a security threat. Filtering has now been moved outside conditions
558
-				break;
559
-			case 'delete_tabs':
560
-			case 'delete_link':
561
-				// A link is deleted by getting the file into an array, removing the
562
-				// link and re-writing the array to the file
563
-				$link_index = intval($_GET['link_index']);
564
-				$menuf = ($action == 'delete_tabs')? $mtloggedin : $menuf;
565
-				$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
566
-				if (empty($home_menu)) {
567
-					$home_menu = array();
568
-				}
569
-				foreach ($home_menu as $key => $enreg) {
570
-					if ($key == $link_index) {
571
-						unset($home_menu[$key]);
572
-					} else {
573
-						$home_menu[$key] = trim($enreg);
574
-					}
575
-				}
576
-				$home_menu = implode("\n", $home_menu);
577
-				$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
578
-
579
-				$fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
580
-				fputs($fp, $home_menu);
581
-				home_tabs($homep.$menuf.'_'.$lang.$ext);
582
-				fclose($fp);
583
-				if (file_exists($homep.$menuf.$ext)) {
584
-					if (is_writable($homep.$menuf.$ext)) {
585
-						$fpo = fopen($homep.$menuf.$ext,'w');
586
-						fputs($fpo, $home_menu);
587
-						home_tabs($homep.$menuf.$ext);
588
-						fclose($fpo);
589
-					}
590
-				}
591
-				header('Location: '.$selfUrl);
592
-				exit();
593
-				break;
594
-			case 'edit_top':
595
-				// This request is only the preparation for the update of the home_top
596
-				$home_top = '';
597
-				if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
598
-					$home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
599
-				} elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
600
-					$home_top = @(string)file_get_contents($homep.$topf.$lang.$ext);
601
-				} else {
602
-					$errorMsg = get_lang('HomePageFilesNotReadable');
603
-				}
604
-				$home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
605
-				break;
606
-			case 'edit_notice':
607
-				// This request is only the preparation for the update of the home_notice
608
-				$home_notice = '';
609
-				if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) {
610
-					$home_notice = @file($homep.$noticef.'_'.$lang.$ext);
611
-				} elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) {
612
-					$home_notice = @file($homep.$noticef.$lang.$ext);
613
-				} else {
614
-					$errorMsg = get_lang('HomePageFilesNotReadable');
615
-				}
616
-				if (empty($home_notice)) {
617
-					$home_notice = array();
618
-				}
619
-				$notice_title = strip_tags($home_notice[0]);
620
-				$notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title));
621
-				$notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>');
622
-				$notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text)));
623
-				break;
624
-			case 'edit_news':
625
-				// This request is the preparation for the update of the home_news page
626
-				$home_news = '';
627
-				if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) {
628
-					$home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
629
-				} elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) {
630
-					$home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext);
631
-				} else {
632
-					$errorMsg = get_lang('HomePageFilesNotReadable');
633
-				}
634
-				$home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news)));
635
-				break;
636
-			case 'insert_link':
637
-				// This request is the preparation for the addition of an item in home_menu
638
-				$home_menu = '';
639
-				$menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
640
-				if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
641
-					$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
642
-				} elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
643
-					$home_menu = @file($homep.$menuf.$lang.$ext);
644
-				} else {
645
-					$errorMsg = get_lang('HomePageFilesNotReadable');
646
-				}
647
-				if (empty($home_menu)) {
648
-					$home_menu = array();
649
-				}
650
-				if (!empty($home_menu)) {
651
-					$home_menu = implode("\n", $home_menu);
652
-					$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
653
-					$home_menu = explode("\n", $home_menu);
654
-				}
655
-				$home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
656
-				break;
657
-			case 'insert_tabs':
658
-				// This request is the preparation for the addition of an item in home_menu
659
-				$home_menu = '';
660
-				if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) {
661
-					$home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
662
-				} elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) {
663
-					$home_menu = @file($homep.$mtloggedin.$lang.$ext);
664
-				} elseif (touch($homep.$mtloggedin.'_'.$lang.$ext)) {
665
-					$home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
666
-				} else {
667
-					$errorMsg = get_lang('HomePageFilesNotReadable');
668
-				}
669
-				if (empty($home_menu)) {
670
-					$home_menu = array();
671
-				}
672
-				if (!empty($home_menu)) {
673
-					$home_menu = implode("\n", $home_menu);
674
-					$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
675
-					$home_menu = explode("\n", $home_menu);
676
-				}
677
-				$home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
678
-				break;
679
-			case 'edit_tabs':
680
-			case 'edit_link':
681
-				// This request is the preparation for the edition of the links array
682
-				$home_menu = '';
683
-				$menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
684
-				if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
685
-					$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
686
-				} elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
687
-					$home_menu = @file($homep.$menuf.$lang.$ext);
688
-				} else {
689
-					$errorMsg = get_lang('HomePageFilesNotReadable');
690
-				}
691
-
692
-				if (empty($home_menu)) {
693
-					if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
694
-						$home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
695
-					}
696
-				}
697
-
698
-				if (empty($home_menu)) {
699
-					$home_menu = array();
700
-				}
701
-				if (!empty($home_menu)) {
702
-					$home_menu = implode("\n", $home_menu);
703
-					$home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
704
-					$home_menu = explode("\n", $home_menu);
705
-				}
706
-
707
-				$link_index = intval($_GET['link_index']);
708
-
709
-				$target_blank = false;
710
-				$link_name = '';
711
-				$link_url = '';
712
-
713
-				//$home_menu_new = array();
714
-				//
715
-				//Cleaning array
716
-				//foreach ($home_menu as $item) {
717
-				//	if(!empty($item)) {
718
-				//		$home_menu_new[] = $item;
719
-				//	}
720
-				//}
721
-				//$home_menu = $home_menu_new;
722
-
723
-				// Cleaning the array
724
-				$home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
725
-
726
-				// For each line of the home_menu file
727
-				foreach ($home_menu as $key => $enreg) {
728
-
729
-					// Check if the current item is the one we want to update
730
-					if ($key == $link_index) {
731
-						// This is the link we want to update
732
-						// Check if the target should be "_blank"
733
-						if (strstr($enreg, 'target="_blank"')) {
734
-							$target_blank = true;
735
-						}
736
-
737
-						if (strstr($enreg, 'hide_menu')) {
738
-							$add_in_tab = false;
739
-						} else {
740
-							$add_in_tab = true;
741
-						}
742
-
743
-						// Remove dangerous HTML tags from the link itself (this is an
744
-						// additional measure in case a link previously contained
745
-						// unsecure tags)
746
-						$link_name = strip_tags($enreg);
747
-
748
-						// Get the contents of "href" attribute in $link_url
749
-						$enreg = explode('href="',$enreg);
750
-						list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]);
751
-
752
-						// If the link contains the web root of this portal, then strip
753
-						// it off and keep only the name of the file that needs edition
754
-						if (strstr($link_url, '?include=')) {
755
-							$link_url = explode('?include=', $link_url);
756
-
757
-							$filename = $link_url[sizeof($link_url) - 1];
758
-
759
-							if (!strstr($filename, '/') && strstr($filename, '.html')) {
760
-								// Get oonly the contents of the link file
761
-								$link_html = @file($homep.$filename);
762
-								$link_html = implode('', $link_html);
763
-								$link_url = '';
764
-							} else {
765
-								$filename = '';
766
-							}
767
-						}
768
-						break;
769
-					}
770
-				}
771
-				break;
772
-		}//end of second switch($action) (when POST['formSent'] was not set, yet)
773
-	}// end of "else" in if($_POST['formSent']) condition
476
+                    if ($action == 'insert_link' || $action == 'insert_tabs') {
477
+                        for ($i = sizeof($home_menu); $i; $i--) {
478
+                            if ($i > $insert_where) {
479
+                                $home_menu[$i] = $home_menu[$i - 1];
480
+                            } else {
481
+                                break;
482
+                            }
483
+                        }
484
+                        $home_menu[$insert_where + 1] = '<li><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'. $link_name .'</a></li>';
485
+                    } else {
486
+                        // If the request is about a link edition, change the link
487
+                        $home_menu[$link_index]='<li><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'. $link_name .'</a></li>';
488
+                    }
489
+                    // Re-build the file from the home_menu array
490
+                    $home_menu = implode("\n", $home_menu);
491
+                    // Write
492
+                    if (file_exists($homep.$menuf.'_'.$lang.$ext)) {
493
+                        if (is_writable($homep.$menuf.'_'.$lang.$ext)) {
494
+                            $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
495
+                            fputs($fp, $home_menu);
496
+                            home_tabs($homep.$menuf.'_'.$lang.$ext);
497
+                            fclose($fp);
498
+
499
+                            foreach ($_languages['name'] as $key => $value) {
500
+                                $lang_name = $_languages['folder'][$key];
501
+                                if (isset($_POST[$lang_name])) {
502
+                                    $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
503
+                                    fputs($fp, $home_menu);
504
+                                    home_tabs($homep.$menuf.'_'.$lang_name.$ext);
505
+                                    fclose($fp);
506
+                                }
507
+                            }
508
+
509
+                            if (file_exists($homep.$menuf.$ext)) {
510
+                                if (is_writable($homep.$menuf.$ext)) {
511
+                                    $fpo = fopen($homep.$menuf.$ext, 'w');
512
+                                    fputs($fpo, $home_menu);
513
+                                    home_tabs($homep.$menuf.$ext);
514
+                                    fclose($fpo);
515
+                                }
516
+                            }
517
+                        } else {
518
+                            $errorMsg = get_lang('HomePageFilesNotWritable');
519
+                        }
520
+                    } else {
521
+                        //File does not exist
522
+                        $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
523
+                        fputs($fp, $home_menu);
524
+                        home_tabs($homep.$menuf.'_'.$lang.$ext);
525
+                        fclose($fp);
526
+
527
+                        foreach ($_languages['name'] as $key => $value) {
528
+                            $lang_name = $_languages['folder'][$key];
529
+                            if (isset($_POST[$lang_name])) {
530
+                                $fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
531
+                                fputs($fp, $home_menu);
532
+                                home_tabs($homep.$menuf.'_'.$lang_name.$ext);
533
+                                fclose($fp);
534
+                            }
535
+                        }
536
+                    }
537
+                }
538
+                Event::addEvent(
539
+                    LOG_HOMEPAGE_CHANGED,
540
+                    $action,
541
+                    cut($link_name . ':' . $link_url, 254),
542
+                    api_get_utc_datetime(),
543
+                    api_get_user_id()
544
+                );
545
+                break;
546
+        } //end of switch($action)
547
+
548
+        if (empty($errorMsg)) {
549
+            header('Location: '.$selfUrl.'?language='.$languageGet);
550
+            exit();
551
+        }
552
+    } else {
553
+        //if POST[formSent] is not set
554
+        switch ($action) {
555
+            case 'open_link':
556
+                // Previously, filtering of GET['link'] was done here but it left
557
+                // a security threat. Filtering has now been moved outside conditions
558
+                break;
559
+            case 'delete_tabs':
560
+            case 'delete_link':
561
+                // A link is deleted by getting the file into an array, removing the
562
+                // link and re-writing the array to the file
563
+                $link_index = intval($_GET['link_index']);
564
+                $menuf = ($action == 'delete_tabs')? $mtloggedin : $menuf;
565
+                $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
566
+                if (empty($home_menu)) {
567
+                    $home_menu = array();
568
+                }
569
+                foreach ($home_menu as $key => $enreg) {
570
+                    if ($key == $link_index) {
571
+                        unset($home_menu[$key]);
572
+                    } else {
573
+                        $home_menu[$key] = trim($enreg);
574
+                    }
575
+                }
576
+                $home_menu = implode("\n", $home_menu);
577
+                $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
578
+
579
+                $fp = fopen($homep.$menuf.'_'.$lang.$ext, 'w');
580
+                fputs($fp, $home_menu);
581
+                home_tabs($homep.$menuf.'_'.$lang.$ext);
582
+                fclose($fp);
583
+                if (file_exists($homep.$menuf.$ext)) {
584
+                    if (is_writable($homep.$menuf.$ext)) {
585
+                        $fpo = fopen($homep.$menuf.$ext,'w');
586
+                        fputs($fpo, $home_menu);
587
+                        home_tabs($homep.$menuf.$ext);
588
+                        fclose($fpo);
589
+                    }
590
+                }
591
+                header('Location: '.$selfUrl);
592
+                exit();
593
+                break;
594
+            case 'edit_top':
595
+                // This request is only the preparation for the update of the home_top
596
+                $home_top = '';
597
+                if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
598
+                    $home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
599
+                } elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
600
+                    $home_top = @(string)file_get_contents($homep.$topf.$lang.$ext);
601
+                } else {
602
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
603
+                }
604
+                $home_top = api_to_system_encoding($home_top, api_detect_encoding(strip_tags($home_top)));
605
+                break;
606
+            case 'edit_notice':
607
+                // This request is only the preparation for the update of the home_notice
608
+                $home_notice = '';
609
+                if (is_file($homep.$noticef.'_'.$lang.$ext) && is_readable($homep.$noticef.'_'.$lang.$ext)) {
610
+                    $home_notice = @file($homep.$noticef.'_'.$lang.$ext);
611
+                } elseif (is_file($homep.$noticef.$lang.$ext) && is_readable($homep.$noticef.$lang.$ext)) {
612
+                    $home_notice = @file($homep.$noticef.$lang.$ext);
613
+                } else {
614
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
615
+                }
616
+                if (empty($home_notice)) {
617
+                    $home_notice = array();
618
+                }
619
+                $notice_title = strip_tags($home_notice[0]);
620
+                $notice_title = api_to_system_encoding($notice_title, api_detect_encoding($notice_title));
621
+                $notice_text = strip_tags(str_replace('<br />', "\n", $home_notice[1]), '<a>');
622
+                $notice_text = api_to_system_encoding($notice_text, api_detect_encoding(strip_tags($notice_text)));
623
+                break;
624
+            case 'edit_news':
625
+                // This request is the preparation for the update of the home_news page
626
+                $home_news = '';
627
+                if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) {
628
+                    $home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
629
+                } elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) {
630
+                    $home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext);
631
+                } else {
632
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
633
+                }
634
+                $home_news = api_to_system_encoding($home_news, api_detect_encoding(strip_tags($home_news)));
635
+                break;
636
+            case 'insert_link':
637
+                // This request is the preparation for the addition of an item in home_menu
638
+                $home_menu = '';
639
+                $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
640
+                if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
641
+                    $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
642
+                } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
643
+                    $home_menu = @file($homep.$menuf.$lang.$ext);
644
+                } else {
645
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
646
+                }
647
+                if (empty($home_menu)) {
648
+                    $home_menu = array();
649
+                }
650
+                if (!empty($home_menu)) {
651
+                    $home_menu = implode("\n", $home_menu);
652
+                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
653
+                    $home_menu = explode("\n", $home_menu);
654
+                }
655
+                $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
656
+                break;
657
+            case 'insert_tabs':
658
+                // This request is the preparation for the addition of an item in home_menu
659
+                $home_menu = '';
660
+                if (is_file($homep.$mtloggedin.'_'.$lang.$ext) && is_readable($homep.$mtloggedin.'_'.$lang.$ext)) {
661
+                    $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
662
+                } elseif (is_file($homep.$mtloggedin.$lang.$ext) && is_readable($homep.$mtloggedin.$lang.$ext)) {
663
+                    $home_menu = @file($homep.$mtloggedin.$lang.$ext);
664
+                } elseif (touch($homep.$mtloggedin.'_'.$lang.$ext)) {
665
+                    $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
666
+                } else {
667
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
668
+                }
669
+                if (empty($home_menu)) {
670
+                    $home_menu = array();
671
+                }
672
+                if (!empty($home_menu)) {
673
+                    $home_menu = implode("\n", $home_menu);
674
+                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
675
+                    $home_menu = explode("\n", $home_menu);
676
+                }
677
+                $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
678
+                break;
679
+            case 'edit_tabs':
680
+            case 'edit_link':
681
+                // This request is the preparation for the edition of the links array
682
+                $home_menu = '';
683
+                $menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
684
+                if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
685
+                    $home_menu = @file($homep.$menuf.'_'.$lang.$ext);
686
+                } elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
687
+                    $home_menu = @file($homep.$menuf.$lang.$ext);
688
+                } else {
689
+                    $errorMsg = get_lang('HomePageFilesNotReadable');
690
+                }
691
+
692
+                if (empty($home_menu)) {
693
+                    if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
694
+                        $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
695
+                    }
696
+                }
697
+
698
+                if (empty($home_menu)) {
699
+                    $home_menu = array();
700
+                }
701
+                if (!empty($home_menu)) {
702
+                    $home_menu = implode("\n", $home_menu);
703
+                    $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
704
+                    $home_menu = explode("\n", $home_menu);
705
+                }
706
+
707
+                $link_index = intval($_GET['link_index']);
708
+
709
+                $target_blank = false;
710
+                $link_name = '';
711
+                $link_url = '';
712
+
713
+                //$home_menu_new = array();
714
+                //
715
+                //Cleaning array
716
+                //foreach ($home_menu as $item) {
717
+                //	if(!empty($item)) {
718
+                //		$home_menu_new[] = $item;
719
+                //	}
720
+                //}
721
+                //$home_menu = $home_menu_new;
722
+
723
+                // Cleaning the array
724
+                $home_menu = array_values(array_filter(array_map('trim', $home_menu), 'strlen'));
725
+
726
+                // For each line of the home_menu file
727
+                foreach ($home_menu as $key => $enreg) {
728
+
729
+                    // Check if the current item is the one we want to update
730
+                    if ($key == $link_index) {
731
+                        // This is the link we want to update
732
+                        // Check if the target should be "_blank"
733
+                        if (strstr($enreg, 'target="_blank"')) {
734
+                            $target_blank = true;
735
+                        }
736
+
737
+                        if (strstr($enreg, 'hide_menu')) {
738
+                            $add_in_tab = false;
739
+                        } else {
740
+                            $add_in_tab = true;
741
+                        }
742
+
743
+                        // Remove dangerous HTML tags from the link itself (this is an
744
+                        // additional measure in case a link previously contained
745
+                        // unsecure tags)
746
+                        $link_name = strip_tags($enreg);
747
+
748
+                        // Get the contents of "href" attribute in $link_url
749
+                        $enreg = explode('href="',$enreg);
750
+                        list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]);
751
+
752
+                        // If the link contains the web root of this portal, then strip
753
+                        // it off and keep only the name of the file that needs edition
754
+                        if (strstr($link_url, '?include=')) {
755
+                            $link_url = explode('?include=', $link_url);
756
+
757
+                            $filename = $link_url[sizeof($link_url) - 1];
758
+
759
+                            if (!strstr($filename, '/') && strstr($filename, '.html')) {
760
+                                // Get oonly the contents of the link file
761
+                                $link_html = @file($homep.$filename);
762
+                                $link_html = implode('', $link_html);
763
+                                $link_url = '';
764
+                            } else {
765
+                                $filename = '';
766
+                            }
767
+                        }
768
+                        break;
769
+                    }
770
+                }
771
+                break;
772
+        }//end of second switch($action) (when POST['formSent'] was not set, yet)
773
+    }// end of "else" in if($_POST['formSent']) condition
774 774
 } else {
775
-	//if $action is empty, then prepare a list of the course categories to display (?)
776
-	$Categories = getCategoriesToDisplayInHomePage();
775
+    //if $action is empty, then prepare a list of the course categories to display (?)
776
+    $Categories = getCategoriesToDisplayInHomePage();
777 777
 }
778 778
 
779 779
 // Display section
@@ -781,25 +781,25 @@  discard block
 block discarded – undo
781 781
 Display::display_header($tool_name);
782 782
 
783 783
 switch ($action) {
784
-	case 'open_link':
785
-		if (!empty($link)) {
786
-			// $link is only set in case of action=open_link and is filtered
787
-			$open = @(string)file_get_contents($homep.$link);
788
-			$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
789
-			echo $open;
790
-		}
791
-		break;
792
-	case 'edit_notice':
793
-		// Display for edit_notice case
794
-		?>
784
+    case 'open_link':
785
+        if (!empty($link)) {
786
+            // $link is only set in case of action=open_link and is filtered
787
+            $open = @(string)file_get_contents($homep.$link);
788
+            $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
789
+            echo $open;
790
+        }
791
+        break;
792
+    case 'edit_notice':
793
+        // Display for edit_notice case
794
+        ?>
795 795
 		<form action="<?php echo $selfUrl; ?>?action=<?php echo $action; ?>" method="post" class="form-horizontal">
796 796
 			<legend><?php echo $tool_name; ?></legend>
797 797
 			<input type="hidden" name="formSent" value="1"/>
798 798
 			<?php
799
-			if (!empty($errorMsg)) {
800
-				Display::display_normal_message($errorMsg);
801
-			}
802
-			?>
799
+            if (!empty($errorMsg)) {
800
+                Display::display_normal_message($errorMsg);
801
+            }
802
+            ?>
803 803
                         <div class="row">
804 804
                             <div class="col-md-12">
805 805
                                 <p><?php echo get_lang('LetThoseFieldsEmptyToHideTheNotice'); ?></p>
@@ -837,170 +837,170 @@  discard block
 block discarded – undo
837 837
                         </div>
838 838
 		</form>
839 839
 		<?php
840
-		break;
841
-	case 'insert_tabs':
842
-	case 'edit_tabs':
843
-	case 'insert_link':
844
-	case 'edit_link':
845
-		$menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf;
846
-		if (!empty($errorMsg)) {
847
-			Display::display_normal_message($errorMsg);
848
-		}
849
-		$default = array();
850
-		$form = new FormValidator('configure_homepage_'.$action, 'post', $selfUrl.'?action='.$action, '', array('style' => 'margin: 0px;'));
851
-		$renderer =& $form->defaultRenderer();
852
-
853
-		$form->addElement('header', '', $tool_name);
854
-		$form->addElement('hidden', 'formSent', '1');
855
-		$form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0');
856
-		$form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : '');
857
-
858
-		$form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50'));
859
-		if (!empty($link_name)) {
860
-			$default['link_name'] = $link_name;
861
-		}
862
-		$default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES);
863
-		$linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : '';
864
-		$form->addElement('text', 'link_url', array(get_lang('LinkURL'), $linkUrlComment), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;'));
865
-
866
-		$options = array('-1' => get_lang('FirstPlace'));
867
-
868
-		$selected = '';
869
-
870
-		if ($action == 'insert_link' || $action == 'insert_tabs') {
871
-			$add_in_tab = 1;
872
-			if (is_array($home_menu)){
873
-				foreach ($home_menu as $key => $enreg) {
874
-					if (strlen($enreg = trim(strip_tags($enreg))) > 0) {
875
-						$options[$key] = get_lang('After').' &quot;'.$enreg.'&quot;';
876
-						$formSentCheck = (!empty($_POST['formSent']) ? true : false);
877
-						$selected = $formSentCheck && $insert_where == $key ? $key : '';
878
-					}
879
-				}
880
-			}
881
-			$default['insert_link'] = $selected;
882
-			$form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options);
883
-		}
884
-
885
-		$target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1);
886
-
887
-		if ($action == 'insert_tabs' || $action == 'edit_tabs') {
888
-			$form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1);
889
-			$default['add_in_tab'] = $add_in_tab;
890
-		}
891
-
892
-		if (!empty($target_blank)) { $target_blank_checkbox->setChecked(true); }
893
-
894
-		if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) {
895
-			$default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
896
-			$form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
840
+        break;
841
+    case 'insert_tabs':
842
+    case 'edit_tabs':
843
+    case 'insert_link':
844
+    case 'edit_link':
845
+        $menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf;
846
+        if (!empty($errorMsg)) {
847
+            Display::display_normal_message($errorMsg);
848
+        }
849
+        $default = array();
850
+        $form = new FormValidator('configure_homepage_'.$action, 'post', $selfUrl.'?action='.$action, '', array('style' => 'margin: 0px;'));
851
+        $renderer =& $form->defaultRenderer();
852
+
853
+        $form->addElement('header', '', $tool_name);
854
+        $form->addElement('hidden', 'formSent', '1');
855
+        $form->addElement('hidden', 'link_index', ($action == 'edit_link' || $action == 'edit_tabs') ? $link_index : '0');
856
+        $form->addElement('hidden', 'filename', ($action == 'edit_link' || $action == 'edit_tabs') ? (!empty($filename) ? $filename : '') : '');
857
+
858
+        $form->addElement('text', 'link_name', get_lang('LinkName'), array('size' => '30', 'maxlength' => '50'));
859
+        if (!empty($link_name)) {
860
+            $default['link_name'] = $link_name;
861
+        }
862
+        $default['link_url'] = empty($link_url) ? 'http://' : api_htmlentities($link_url, ENT_QUOTES);
863
+        $linkUrlComment = ($action == 'insert_tabs') ? get_lang('Optional').'<br />'.get_lang('GlobalLinkUseDoubleColumnPrivateToShowPrivately') : '';
864
+        $form->addElement('text', 'link_url', array(get_lang('LinkURL'), $linkUrlComment), array('size' => '30', 'maxlength' => '100', 'style' => 'width: 350px;'));
865
+
866
+        $options = array('-1' => get_lang('FirstPlace'));
867
+
868
+        $selected = '';
869
+
870
+        if ($action == 'insert_link' || $action == 'insert_tabs') {
871
+            $add_in_tab = 1;
872
+            if (is_array($home_menu)){
873
+                foreach ($home_menu as $key => $enreg) {
874
+                    if (strlen($enreg = trim(strip_tags($enreg))) > 0) {
875
+                        $options[$key] = get_lang('After').' &quot;'.$enreg.'&quot;';
876
+                        $formSentCheck = (!empty($_POST['formSent']) ? true : false);
877
+                        $selected = $formSentCheck && $insert_where == $key ? $key : '';
878
+                    }
879
+                }
880
+            }
881
+            $default['insert_link'] = $selected;
882
+            $form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options);
883
+        }
884
+
885
+        $target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1);
886
+
887
+        if ($action == 'insert_tabs' || $action == 'edit_tabs') {
888
+            $form->addElement('checkbox', 'add_in_tab', null, get_lang('AddInMenu'), 1);
889
+            $default['add_in_tab'] = $add_in_tab;
890
+        }
891
+
892
+        if (!empty($target_blank)) { $target_blank_checkbox->setChecked(true); }
893
+
894
+        if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) {
895
+            $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
896
+            $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
897 897
             $form->addButtonSave(get_lang('Save'),'submit');
898 898
 
899
-		} else {
900
-			if (in_array($action, array('edit_tabs','insert_tabs'))) {
901
-				$default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : '');
902
-				$form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
903
-			}
904
-			$form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
905
-			$form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>');
906
-			$i = 0;
907
-			foreach ($_languages['name'] as $key => $value) {
908
-				$i++;
909
-				$lang_name = $_languages['folder'][$key];
910
-				$html_langs = '<td width="300">';
911
-				$html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" />&nbsp;'.$lang_name.'<label/>';
912
-				$html_langs .= '</td>';
913
-				if ($i % 5 == 0) {
914
-					$html_langs .= '</tr><tr>';
915
-				}
916
-				$form->addElement('html', $html_langs);
917
-			}
918
-			$form->addElement('html','</tr></table><br/>');
899
+        } else {
900
+            if (in_array($action, array('edit_tabs','insert_tabs'))) {
901
+                $default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : '');
902
+                $form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
903
+            }
904
+            $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
905
+            $form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>');
906
+            $i = 0;
907
+            foreach ($_languages['name'] as $key => $value) {
908
+                $i++;
909
+                $lang_name = $_languages['folder'][$key];
910
+                $html_langs = '<td width="300">';
911
+                $html_langs .= '<label><input type="checkbox" id="lang" name="'.$lang_name.'" />&nbsp;'.$lang_name.'<label/>';
912
+                $html_langs .= '</td>';
913
+                if ($i % 5 == 0) {
914
+                    $html_langs .= '</tr><tr>';
915
+                }
916
+                $form->addElement('html', $html_langs);
917
+            }
918
+            $form->addElement('html','</tr></table><br/>');
919 919
             $form->addButtonSave(get_lang('Save'),'submit');
920
-		}
921
-
922
-		$form->setDefaults($default);
923
-		$form->display();
924
-
925
-		break;
926
-	case 'edit_top':
927
-	case 'edit_news':
928
-		if ($action == 'edit_top') {
929
-			$name = $topf;
930
-			$open = $home_top;
931
-		} else {
932
-			$name = $newsf;
933
-			$open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
934
-		}
935
-		$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
936
-
937
-		if (!empty($errorMsg)) {
938
-			Display::display_normal_message($errorMsg); //main API
939
-		}
940
-
941
-		$default = array();
942
-		$form = new FormValidator(
943
-			'configure_homepage_'.$action,
944
-			'post',
945
-			$selfUrl.'?action='.$action,
946
-			'',
947
-			array('style' => 'margin: 0px;')
948
-		);
949
-		$renderer =& $form->defaultRenderer();
950
-		$renderer->setHeaderTemplate('');
951
-		$renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
952
-		$renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
953
-		$renderer->setRequiredNoteTemplate('');
954
-		$form->addElement('hidden', 'formSent', '1');
955
-
956
-		if ($action == 'edit_news') {
957
-			$_languages = api_get_languages();
958
-			$html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
959
-			$html .= '<select name="news_languages">';
960
-			$html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>';
961
-			foreach ($_languages['name'] as $key => $value) {
962
-				$english_name = $_languages['folder'][$key];
963
-				if ($language == $english_name) {
964
-					$html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
965
-				} else {
966
-					$html .= '<option value="'.$english_name.'">'.$value.'</option>';
967
-				}
968
-			}
969
-			$html .= '</select></td></tr>';
970
-			$form->addElement('html', $html);
971
-		}
972
-
973
-		$default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
974
-		$form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
975
-		$form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs'));
976
-		$form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>');
977
-
978
-		$currentLanguage = api_get_interface_language();
979
-		$i = 0;
980
-		foreach ($_languages['name'] as $key => $value) {
981
-			$lang_name = $_languages['folder'][$key];
982
-			$i++;
983
-
984
-			$checked = null;
985
-			if ($languageGet == $lang_name)  {
986
-				$checked = "checked";
987
-			}
988
-			$html_langs = '<td width="300">';
989
-			$html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" />&nbsp;'.$value.'<label/>';
990
-			$html_langs .= '</td>';
991
-			if ($i % 5 == 0) {
992
-				$html_langs .= '</tr><tr>';
993
-			}
994
-			$form->addElement('html', $html_langs);
995
-		}
996
-		$form->addElement('html','</tr></table><br/>');
997
-		$form->addButtonSave(get_lang('Save'));
998
-		$form->setDefaults($default);
999
-		$form->display();
1000
-
1001
-		break;
1002
-	default: // When no action applies, default page to update campus homepage
1003
-		?>
920
+        }
921
+
922
+        $form->setDefaults($default);
923
+        $form->display();
924
+
925
+        break;
926
+    case 'edit_top':
927
+    case 'edit_news':
928
+        if ($action == 'edit_top') {
929
+            $name = $topf;
930
+            $open = $home_top;
931
+        } else {
932
+            $name = $newsf;
933
+            $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
934
+        }
935
+        $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
936
+
937
+        if (!empty($errorMsg)) {
938
+            Display::display_normal_message($errorMsg); //main API
939
+        }
940
+
941
+        $default = array();
942
+        $form = new FormValidator(
943
+            'configure_homepage_'.$action,
944
+            'post',
945
+            $selfUrl.'?action='.$action,
946
+            '',
947
+            array('style' => 'margin: 0px;')
948
+        );
949
+        $renderer =& $form->defaultRenderer();
950
+        $renderer->setHeaderTemplate('');
951
+        $renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
952
+        $renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
953
+        $renderer->setRequiredNoteTemplate('');
954
+        $form->addElement('hidden', 'formSent', '1');
955
+
956
+        if ($action == 'edit_news') {
957
+            $_languages = api_get_languages();
958
+            $html = '<tr><td>'.get_lang('ChooseNewsLanguage').' : ';
959
+            $html .= '<select name="news_languages">';
960
+            $html .= '<option value="all">'.get_lang('ApplyAllLanguages').'</option>';
961
+            foreach ($_languages['name'] as $key => $value) {
962
+                $english_name = $_languages['folder'][$key];
963
+                if ($language == $english_name) {
964
+                    $html .= '<option value="'.$english_name.'" selected="selected">'.$value.'</option>';
965
+                } else {
966
+                    $html .= '<option value="'.$english_name.'">'.$value.'</option>';
967
+                }
968
+            }
969
+            $html .= '</select></td></tr>';
970
+            $form->addElement('html', $html);
971
+        }
972
+
973
+        $default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
974
+        $form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
975
+        $form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs'));
976
+        $form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>');
977
+
978
+        $currentLanguage = api_get_interface_language();
979
+        $i = 0;
980
+        foreach ($_languages['name'] as $key => $value) {
981
+            $lang_name = $_languages['folder'][$key];
982
+            $i++;
983
+
984
+            $checked = null;
985
+            if ($languageGet == $lang_name)  {
986
+                $checked = "checked";
987
+            }
988
+            $html_langs = '<td width="300">';
989
+            $html_langs .= '<label><input type="checkbox" '.$checked.' id="lang" name="'.$lang_name.'" />&nbsp;'.$value.'<label/>';
990
+            $html_langs .= '</td>';
991
+            if ($i % 5 == 0) {
992
+                $html_langs .= '</tr><tr>';
993
+            }
994
+            $form->addElement('html', $html_langs);
995
+        }
996
+        $form->addElement('html','</tr></table><br/>');
997
+        $form->addButtonSave(get_lang('Save'));
998
+        $form->setDefaults($default);
999
+        $form->display();
1000
+
1001
+        break;
1002
+    default: // When no action applies, default page to update campus homepage
1003
+        ?>
1004 1004
 
1005 1005
 <section id="page-home">
1006 1006
     <div class="row">
@@ -1156,53 +1156,53 @@  discard block
 block discarded – undo
1156 1156
             ?>
1157 1157
 
1158 1158
             <?php
1159
-		if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
1159
+        if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
1160 1160
                     $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
1161 1161
                     $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
1162 1162
                     echo $open;
1163
-		} else {
1163
+        } else {
1164 1164
                     $open = @(string)file_get_contents($homep.$newsf.$ext);
1165 1165
                     $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
1166 1166
                     echo $open;
1167
-		}
1167
+        }
1168 1168
             ?>
1169 1169
 
1170 1170
             <?php
1171 1171
                 // Add new page
1172
-		$home_menu = '';
1173
-		if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) {
1172
+        $home_menu = '';
1173
+        if (file_exists($homep.$mtloggedin.'_'.$lang.$ext)) {
1174 1174
                     $home_menu = @file($homep.$mtloggedin.'_'.$lang.$ext);
1175
-		} else {
1175
+        } else {
1176 1176
                     $home_menu = @file($homep.$mtloggedin.$ext);
1177
-		}
1178
-		if (empty($home_menu)) {
1177
+        }
1178
+        if (empty($home_menu)) {
1179 1179
                     if (file_exists($homep.$menutabs.'_'.$lang.$ext)) {
1180
-			$home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
1180
+            $home_menu = @file($homep.$menutabs.'_'.$lang.$ext);
1181 1181
                     }
1182
-		}
1183
-		if (empty($home_menu)) {
1182
+        }
1183
+        if (empty($home_menu)) {
1184 1184
                     $home_menu = array();
1185
-		}
1186
-		if (!empty($home_menu)) {
1185
+        }
1186
+        if (!empty($home_menu)) {
1187 1187
                     $home_menu = implode("\n", $home_menu);
1188 1188
                     $home_menu = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
1189 1189
                     $home_menu = explode("\n", $home_menu);
1190
-		}
1191
-		$link_list = '';
1192
-		$tab_counter = 0;
1190
+        }
1191
+        $link_list = '';
1192
+        $tab_counter = 0;
1193 1193
                     foreach ($home_menu as $enreg) {
1194 1194
                     $enreg = trim($enreg);
1195
-			if (!empty($enreg)) {
1195
+            if (!empty($enreg)) {
1196 1196
                             $edit_link   = ' <a href="'.$selfUrl.'?action=edit_tabs&amp;link_index='.$tab_counter.'" ><span>'.Display::return_icon('edit.png', get_lang('Edit')).'</span></a>';
1197 1197
                             $delete_link = ' <a href="'.$selfUrl.'?action=delete_tabs&amp;link_index='.$tab_counter.'"  onclick="javascript: if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES)).'\')) return false;"><span>'.Display::return_icon('delete.png', get_lang('Delete')).'</span></a>';
1198 1198
                             $tab_string = str_replace(array('href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'),
1199 1199
                                 array('href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename($selfUrl).'?action=open_link&link=', $edit_link.$delete_link.'</li>'),
1200
-				$enreg);
1200
+                $enreg);
1201 1201
                             $tab_string = str_replace(array('<li>', '</li>','class="hide_menu"', 'hide_menu'), '', $tab_string);
1202
-				$link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item'));
1203
-				$tab_counter++;
1204
-			}
1205
-		}
1202
+                $link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item'));
1203
+                $tab_counter++;
1204
+            }
1205
+        }
1206 1206
             ?>
1207 1207
             <div class="actions">
1208 1208
 		<a href="<?php echo $selfUrl; ?>?action=insert_tabs">
@@ -1210,9 +1210,9 @@  discard block
 block discarded – undo
1210 1210
                 </a>
1211 1211
             </div>
1212 1212
             <?php
1213
-		echo '<ul id="list-hiperlink" class="list-group">';
1214
-		echo $link_list;
1215
-		echo '</ul>';
1213
+        echo '<ul id="list-hiperlink" class="list-group">';
1214
+        echo $link_list;
1215
+        echo '</ul>';
1216 1216
             ?>
1217 1217
         </div>
1218 1218
     </div>
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 {
20 20
 	$post = strpos($file_logged_in, "_logged_in");
21 21
 	if ($post !== false) {
22
-		$file_logged_out = str_replace('_logged_in','', $file_logged_in);
22
+		$file_logged_out = str_replace('_logged_in', '', $file_logged_in);
23 23
 		//variables initialization
24 24
 		$data_logged_out = array();
25 25
 		$data_logged_in  = array();
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
 		//we read the file with all links
28 28
 		$file = file($file_logged_in);
29 29
 		foreach ($file as $line) {
30
-			$line = str_replace("\n", '',$line);
30
+			$line = str_replace("\n", '', $line);
31 31
 			//not logged user only sees public links
32
-			if (!preg_match('/::private/',$line)) {
32
+			if (!preg_match('/::private/', $line)) {
33 33
 				$data_logged_out[] = $line;
34 34
 			}
35 35
 			//logged user only sees all links
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 $tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
75 75
 $tool_name = get_lang('ConfigureHomePage');
76 76
 $_languages = api_get_languages();
77
-$selfUrl =  api_get_self();
77
+$selfUrl = api_get_self();
78 78
 $interbreadcrumb[] = array(
79 79
 	'url' => 'index.php',
80 80
 	'name' => get_lang('PlatformAdmin')
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 				}
263 263
 
264 264
 				if (EventsMail::check_if_using_class('portal_homepage_edited')) {
265
-					EventsDispatcher::events('portal_homepage_edited',array('about_user' => api_get_user_id()));
265
+					EventsDispatcher::events('portal_homepage_edited', array('about_user' => api_get_user_id()));
266 266
 				}
267 267
 				Event::addEvent(
268 268
 					LOG_HOMEPAGE_CHANGED,
@@ -394,9 +394,9 @@  discard block
 block discarded – undo
394 394
 				if ($link_url == 'http://' || $link_url == 'https://') {
395 395
 					$link_url = '';
396 396
 				} elseif (!empty($link_url) && !strstr($link_url, '://')) {
397
-					$link_url='http://'.$link_url;
397
+					$link_url = 'http://'.$link_url;
398 398
 				}
399
-				$menuf = ($action == 'insert_tabs' || $action == 'edit_tabs')? $mtloggedin : $menuf;
399
+				$menuf = ($action == 'insert_tabs' || $action == 'edit_tabs') ? $mtloggedin : $menuf;
400 400
 
401 401
 				if (!is_writable($homep.$menuf.'_'.$lang.$ext)) {
402 402
 					$errorMsg = get_lang('HomePageFilesNotWritable');
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
 					}
415 415
 					// If the typical language suffix is not found in the file name,
416 416
 					// replace the ".html" suffix by "_en.html" or the active menu language
417
-					if (!strstr($filename,'_'.$lang.$ext)) {
417
+					if (!strstr($filename, '_'.$lang.$ext)) {
418 418
 						$filename = str_replace($ext, '_'.$lang.$ext, $filename);
419 419
 					}
420 420
 					// Get the contents of home_menu_en.html (or active menu language
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
 					//
437 437
 					// If the given link url is empty, then replace the link url by a link to the link file created
438 438
 
439
-					if (empty($link_url) || $link_url == 'http://' ||  $link_url == 'https://') {
439
+					if (empty($link_url) || $link_url == 'http://' || $link_url == 'https://') {
440 440
 						$link_url = api_get_path(WEB_PATH).'index.php?include='.urlencode($filename);
441 441
 						// If the file doesn't exist, then create it and
442 442
 						// fill it with default text
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
 					}
456 456
 					// If the requested action is to edit a link, open the file and
457 457
 					// write to it (if the file doesn't exist, create it)
458
-					if (in_array($action, array('edit_link'))  && !empty($link_html)) {
458
+					if (in_array($action, array('edit_link')) && !empty($link_html)) {
459 459
 						$fp = @fopen($homep.$filename, 'w');
460 460
 						if ($fp) {
461 461
 							fputs($fp, $link_html);
@@ -481,10 +481,10 @@  discard block
 block discarded – undo
481 481
 								break;
482 482
 							}
483 483
 						}
484
-						$home_menu[$insert_where + 1] = '<li><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'. $link_name .'</a></li>';
484
+						$home_menu[$insert_where + 1] = '<li><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'.$link_name.'</a></li>';
485 485
 					} else {
486 486
 						// If the request is about a link edition, change the link
487
-						$home_menu[$link_index]='<li><a href="'.$link_url.'" target="'.($target_blank?'_blank':'_self').'">'. $link_name .'</a></li>';
487
+						$home_menu[$link_index] = '<li><a href="'.$link_url.'" target="'.($target_blank ? '_blank' : '_self').'">'.$link_name.'</a></li>';
488 488
 					}
489 489
 					// Re-build the file from the home_menu array
490 490
 					$home_menu = implode("\n", $home_menu);
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 				Event::addEvent(
539 539
 					LOG_HOMEPAGE_CHANGED,
540 540
 					$action,
541
-					cut($link_name . ':' . $link_url, 254),
541
+					cut($link_name.':'.$link_url, 254),
542 542
 					api_get_utc_datetime(),
543 543
 					api_get_user_id()
544 544
 				);
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 				// A link is deleted by getting the file into an array, removing the
562 562
 				// link and re-writing the array to the file
563 563
 				$link_index = intval($_GET['link_index']);
564
-				$menuf = ($action == 'delete_tabs')? $mtloggedin : $menuf;
564
+				$menuf = ($action == 'delete_tabs') ? $mtloggedin : $menuf;
565 565
 				$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
566 566
 				if (empty($home_menu)) {
567 567
 					$home_menu = array();
@@ -582,7 +582,7 @@  discard block
 block discarded – undo
582 582
 				fclose($fp);
583 583
 				if (file_exists($homep.$menuf.$ext)) {
584 584
 					if (is_writable($homep.$menuf.$ext)) {
585
-						$fpo = fopen($homep.$menuf.$ext,'w');
585
+						$fpo = fopen($homep.$menuf.$ext, 'w');
586 586
 						fputs($fpo, $home_menu);
587 587
 						home_tabs($homep.$menuf.$ext);
588 588
 						fclose($fpo);
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
 				// This request is only the preparation for the update of the home_top
596 596
 				$home_top = '';
597 597
 				if (is_file($homep.$topf.'_'.$lang.$ext) && is_readable($homep.$topf.'_'.$lang.$ext)) {
598
-					$home_top = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
598
+					$home_top = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
599 599
 				} elseif (is_file($homep.$topf.$lang.$ext) && is_readable($homep.$topf.$lang.$ext)) {
600
-					$home_top = @(string)file_get_contents($homep.$topf.$lang.$ext);
600
+					$home_top = @(string) file_get_contents($homep.$topf.$lang.$ext);
601 601
 				} else {
602 602
 					$errorMsg = get_lang('HomePageFilesNotReadable');
603 603
 				}
@@ -625,9 +625,9 @@  discard block
 block discarded – undo
625 625
 				// This request is the preparation for the update of the home_news page
626 626
 				$home_news = '';
627 627
 				if (is_file($homep.$newsf.'_'.$lang.$ext) && is_readable($homep.$newsf.'_'.$lang.$ext)) {
628
-					$home_news = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
628
+					$home_news = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
629 629
 				} elseif (is_file($homep.$newsf.$lang.$ext) && is_readable($homep.$newsf.$lang.$ext)) {
630
-					$home_news = @(string)file_get_contents($homep.$newsf.$lang.$ext);
630
+					$home_news = @(string) file_get_contents($homep.$newsf.$lang.$ext);
631 631
 				} else {
632 632
 					$errorMsg = get_lang('HomePageFilesNotReadable');
633 633
 				}
@@ -636,10 +636,10 @@  discard block
 block discarded – undo
636 636
 			case 'insert_link':
637 637
 				// This request is the preparation for the addition of an item in home_menu
638 638
 				$home_menu = '';
639
-				$menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
639
+				$menuf = ($action == 'edit_tabs') ? $mtloggedin : $menuf;
640 640
 				if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
641 641
 					$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
642
-				} elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
642
+				} elseif (is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
643 643
 					$home_menu = @file($homep.$menuf.$lang.$ext);
644 644
 				} else {
645 645
 					$errorMsg = get_lang('HomePageFilesNotReadable');
@@ -680,10 +680,10 @@  discard block
 block discarded – undo
680 680
 			case 'edit_link':
681 681
 				// This request is the preparation for the edition of the links array
682 682
 				$home_menu = '';
683
-				$menuf = ($action == 'edit_tabs')? $mtloggedin : $menuf;
683
+				$menuf = ($action == 'edit_tabs') ? $mtloggedin : $menuf;
684 684
 				if (is_file($homep.$menuf.'_'.$lang.$ext) && is_readable($homep.$menuf.'_'.$lang.$ext)) {
685 685
 					$home_menu = @file($homep.$menuf.'_'.$lang.$ext);
686
-				} elseif(is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
686
+				} elseif (is_file($homep.$menuf.$lang.$ext) && is_readable($homep.$menuf.$lang.$ext)) {
687 687
 					$home_menu = @file($homep.$menuf.$lang.$ext);
688 688
 				} else {
689 689
 					$errorMsg = get_lang('HomePageFilesNotReadable');
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
 						$link_name = strip_tags($enreg);
747 747
 
748 748
 						// Get the contents of "href" attribute in $link_url
749
-						$enreg = explode('href="',$enreg);
749
+						$enreg = explode('href="', $enreg);
750 750
 						list($link_url) = explode('"', $enreg[sizeof($enreg) - 1]);
751 751
 
752 752
 						// If the link contains the web root of this portal, then strip
@@ -784,7 +784,7 @@  discard block
 block discarded – undo
784 784
 	case 'open_link':
785 785
 		if (!empty($link)) {
786 786
 			// $link is only set in case of action=open_link and is filtered
787
-			$open = @(string)file_get_contents($homep.$link);
787
+			$open = @(string) file_get_contents($homep.$link);
788 788
 			$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
789 789
 			echo $open;
790 790
 		}
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 		}
849 849
 		$default = array();
850 850
 		$form = new FormValidator('configure_homepage_'.$action, 'post', $selfUrl.'?action='.$action, '', array('style' => 'margin: 0px;'));
851
-		$renderer =& $form->defaultRenderer();
851
+		$renderer = & $form->defaultRenderer();
852 852
 
853 853
 		$form->addElement('header', '', $tool_name);
854 854
 		$form->addElement('hidden', 'formSent', '1');
@@ -869,7 +869,7 @@  discard block
 block discarded – undo
869 869
 
870 870
 		if ($action == 'insert_link' || $action == 'insert_tabs') {
871 871
 			$add_in_tab = 1;
872
-			if (is_array($home_menu)){
872
+			if (is_array($home_menu)) {
873 873
 				foreach ($home_menu as $key => $enreg) {
874 874
 					if (strlen($enreg = trim(strip_tags($enreg))) > 0) {
875 875
 						$options[$key] = get_lang('After').' &quot;'.$enreg.'&quot;';
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 				}
880 880
 			}
881 881
 			$default['insert_link'] = $selected;
882
-			$form->addElement('select', 'insert_where', get_lang('InsertThisLink') , $options);
882
+			$form->addElement('select', 'insert_where', get_lang('InsertThisLink'), $options);
883 883
 		}
884 884
 
885 885
 		$target_blank_checkbox = $form->addElement('checkbox', 'target_blank', null, get_lang('OpenInNewWindow'), 1);
@@ -894,15 +894,15 @@  discard block
 block discarded – undo
894 894
 		if ($action == 'edit_link' && (empty($link_url) || $link_url == 'http://' || $link_url == 'https://')) {
895 895
 			$default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : $link_html;
896 896
 			$form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
897
-            $form->addButtonSave(get_lang('Save'),'submit');
897
+            $form->addButtonSave(get_lang('Save'), 'submit');
898 898
 
899 899
 		} else {
900
-			if (in_array($action, array('edit_tabs','insert_tabs'))) {
900
+			if (in_array($action, array('edit_tabs', 'insert_tabs'))) {
901 901
 				$default['link_html'] = isset($_POST['link_html']) ? $_POST['link_html'] : (!empty($link_html) ? $link_html : '');
902 902
 				$form->addHtmlEditor('link_html', get_lang('Content'), false, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
903 903
 			}
904 904
 			$form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
905
-			$form->addElement('html','<table id="table_langs" style="margin-left:159px;"><tr>');
905
+			$form->addElement('html', '<table id="table_langs" style="margin-left:159px;"><tr>');
906 906
 			$i = 0;
907 907
 			foreach ($_languages['name'] as $key => $value) {
908 908
 				$i++;
@@ -915,8 +915,8 @@  discard block
 block discarded – undo
915 915
 				}
916 916
 				$form->addElement('html', $html_langs);
917 917
 			}
918
-			$form->addElement('html','</tr></table><br/>');
919
-            $form->addButtonSave(get_lang('Save'),'submit');
918
+			$form->addElement('html', '</tr></table><br/>');
919
+            $form->addButtonSave(get_lang('Save'), 'submit');
920 920
 		}
921 921
 
922 922
 		$form->setDefaults($default);
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
 			$open = $home_top;
931 931
 		} else {
932 932
 			$name = $newsf;
933
-			$open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
933
+			$open = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
934 934
 		}
935 935
 		$open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
936 936
 
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
 			'',
947 947
 			array('style' => 'margin: 0px;')
948 948
 		);
949
-		$renderer =& $form->defaultRenderer();
949
+		$renderer = & $form->defaultRenderer();
950 950
 		$renderer->setHeaderTemplate('');
951 951
 		$renderer->setFormTemplate('<form{attributes}><table border="0" cellpadding="5" cellspacing="0" width="100%">{content}</table></form>');
952 952
 		$renderer->setCustomElementTemplate('<tr><td>{element}</td></tr>');
@@ -972,8 +972,8 @@  discard block
 block discarded – undo
972 972
 
973 973
 		$default[$name] = str_replace('{rel_path}', api_get_path(REL_PATH), $open);
974 974
 		$form->addHtmlEditor($name, '', true, false, array('ToolbarSet' => 'PortalHomePage', 'Width' => '100%', 'Height' => '400'));
975
-		$form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'),array('id' => 'all_langs'));
976
-		$form->addElement('html','<table id="table_langs" style="margin-left:5px;"><tr>');
975
+		$form->addElement('checkbox', 'all_langs', null, get_lang('ApplyAllLanguages'), array('id' => 'all_langs'));
976
+		$form->addElement('html', '<table id="table_langs" style="margin-left:5px;"><tr>');
977 977
 
978 978
 		$currentLanguage = api_get_interface_language();
979 979
 		$i = 0;
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
 			$i++;
983 983
 
984 984
 			$checked = null;
985
-			if ($languageGet == $lang_name)  {
985
+			if ($languageGet == $lang_name) {
986 986
 				$checked = "checked";
987 987
 			}
988 988
 			$html_langs = '<td width="300">';
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
 			}
994 994
 			$form->addElement('html', $html_langs);
995 995
 		}
996
-		$form->addElement('html','</tr></table><br/>');
996
+		$form->addElement('html', '</tr></table><br/>');
997 997
 		$form->addButtonSave(get_lang('Save'));
998 998
 		$form->setDefaults($default);
999 999
 		$form->display();
@@ -1046,9 +1046,9 @@  discard block
 block discarded – undo
1046 1046
                                 <?php
1047 1047
                                     $home_notice = '';
1048 1048
                                     if (file_exists($homep.$noticef.'_'.$lang.$ext)) {
1049
-                                        $home_notice = @(string)file_get_contents($homep.$noticef.'_'.$lang.$ext);
1049
+                                        $home_notice = @(string) file_get_contents($homep.$noticef.'_'.$lang.$ext);
1050 1050
                                     } else {
1051
-                                        $home_notice = @(string)file_get_contents($homep.$noticef.$ext);
1051
+                                        $home_notice = @(string) file_get_contents($homep.$noticef.$ext);
1052 1052
                                     }
1053 1053
                                     $home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
1054 1054
                                     echo '<div class="homepage_notice">';
@@ -1073,7 +1073,7 @@  discard block
 block discarded – undo
1073 1073
                     </div>
1074 1074
                     <div id="links-list" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
1075 1075
                         <div class="panel-body">
1076
-                            <a href="<?php echo $selfUrl; ?>?action=insert_link"><?php echo Display::return_icon('add.png', get_lang('InsertLink')).'&nbsp;'. get_lang('InsertLink'); ?>
1076
+                            <a href="<?php echo $selfUrl; ?>?action=insert_link"><?php echo Display::return_icon('add.png', get_lang('InsertLink')).'&nbsp;'.get_lang('InsertLink'); ?>
1077 1077
                             </a>
1078 1078
                             <ul class="menulist">
1079 1079
                                 <?php
@@ -1112,16 +1112,16 @@  discard block
 block discarded – undo
1112 1112
         <div class="col-md-9">
1113 1113
             <div class="actions">
1114 1114
 		<a href="<?php echo $selfUrl; ?>?action=edit_top&language=<?php echo $languageGet; ?>">
1115
-                    <?php echo Display::return_icon('edit.png', get_lang('EditHomePage'),null,ICON_SIZE_SMALL).'&nbsp;'. get_lang('EditHomePage'); ?>
1115
+                    <?php echo Display::return_icon('edit.png', get_lang('EditHomePage'), null, ICON_SIZE_SMALL).'&nbsp;'.get_lang('EditHomePage'); ?>
1116 1116
 		</a>
1117 1117
             </div>
1118 1118
             <section id="homepage-home">
1119 1119
                 <?php
1120 1120
                 //print home_top contents
1121 1121
                 if (file_exists($homep.$topf.'_'.$lang.$ext)) {
1122
-                    $home_top_temp = @(string)file_get_contents($homep.$topf.'_'.$lang.$ext);
1122
+                    $home_top_temp = @(string) file_get_contents($homep.$topf.'_'.$lang.$ext);
1123 1123
                 } else {
1124
-                    $home_top_temp = @(string)file_get_contents($homep.$topf.$ext);
1124
+                    $home_top_temp = @(string) file_get_contents($homep.$topf.$ext);
1125 1125
                 }
1126 1126
                 $open = str_replace('{rel_path}', api_get_path(REL_PATH), $home_top_temp);
1127 1127
                 $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
@@ -1157,11 +1157,11 @@  discard block
 block discarded – undo
1157 1157
 
1158 1158
             <?php
1159 1159
 		if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
1160
-                    $open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
1160
+                    $open = @(string) file_get_contents($homep.$newsf.'_'.$lang.$ext);
1161 1161
                     $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
1162 1162
                     echo $open;
1163 1163
 		} else {
1164
-                    $open = @(string)file_get_contents($homep.$newsf.$ext);
1164
+                    $open = @(string) file_get_contents($homep.$newsf.$ext);
1165 1165
                     $open = api_to_system_encoding($open, api_detect_encoding(strip_tags($open)));
1166 1166
                     echo $open;
1167 1167
 		}
@@ -1198,7 +1198,7 @@  discard block
 block discarded – undo
1198 1198
                             $tab_string = str_replace(array('href="'.api_get_path(WEB_PATH).'index.php?include=', '</li>'),
1199 1199
                                 array('href="'.api_get_path(WEB_CODE_PATH).'admin/'.basename($selfUrl).'?action=open_link&link=', $edit_link.$delete_link.'</li>'),
1200 1200
 				$enreg);
1201
-                            $tab_string = str_replace(array('<li>', '</li>','class="hide_menu"', 'hide_menu'), '', $tab_string);
1201
+                            $tab_string = str_replace(array('<li>', '</li>', 'class="hide_menu"', 'hide_menu'), '', $tab_string);
1202 1202
 				$link_list .= Display::tag('li', $tab_string, array('class' => 'list-group-item'));
1203 1203
 				$tab_counter++;
1204 1204
 			}
@@ -1206,7 +1206,7 @@  discard block
 block discarded – undo
1206 1206
             ?>
1207 1207
             <div class="actions">
1208 1208
 		<a href="<?php echo $selfUrl; ?>?action=insert_tabs">
1209
-                    <?php echo Display::return_icon('add.png', get_lang('InsertLink')) .'&nbsp;'. get_lang('InsertLink'); ?>
1209
+                    <?php echo Display::return_icon('add.png', get_lang('InsertLink')).'&nbsp;'.get_lang('InsertLink'); ?>
1210 1210
                 </a>
1211 1211
             </div>
1212 1212
             <?php
Please login to merge, or discard this patch.