forked from mardink/contactus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
link.php
115 lines (97 loc) · 2.86 KB
/
link.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* @package contactus
* @subpackage projectmanagement
* @copyright (c) 2012-2013, Nicholas K. Dionysopoulos / Akeeba Ltd.
* @license GNU/GPL version 3 or, at your option, any later version
*
* link.php – The internal symlinking script
*/
$hardlink_files = array(
);
$symlink_files = array(
);
$symlink_folders = array(
# Component translation
'translations/component/backend/en-GB' => 'component/language/backend/en-GB',
'translations/component/frontend/en-GB' => 'component/language/frontend/en-GB',
# FOF
#'../fof/fof' => 'component/fof',
# Akeeba Strapper
#'../fof/strapper' => 'component/strapper',
);
// =============================================================================
// Do not modify below this line
// =============================================================================
define('IS_WINDOWS', substr(PHP_OS, 0, 3) == 'WIN');
function TranslateWinPath( $p_path )
{
$is_unc = false;
if (IS_WINDOWS)
{
// Is this a UNC path?
$is_unc = (substr($p_path, 0, 2) == '\\\\') || (substr($p_path, 0, 2) == '//');
// Change potential windows directory separator
if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0, 1) == '\\')){
$p_path = strtr($p_path, '\\', '/');
}
}
// Remove multiple slashes
$p_path = str_replace('///','/',$p_path);
$p_path = str_replace('//','/',$p_path);
// Fix UNC paths
if($is_unc)
{
$p_path = '//'.ltrim($p_path,'/');
}
return $p_path;
}
function doLink($from, $to, $type = 'symlink')
{
$path = dirname(__FILE__);
$realTo = $path .'/'. $to;
$realFrom = $path.'/'.$from;
if(IS_WINDOWS) {
// Windows doesn't play nice with paths containing UNIX path separators
$realTo = TranslateWinPath($realTo);
$realFrom = TranslateWinPath($realFrom);
// Windows doesn't play nice with relative paths in symlinks
$realFrom = realpath($realFrom);
}
if(is_file($realTo) || is_dir($realTo) || is_link($realTo) || file_exists($realTo)) {
if(IS_WINDOWS && is_dir($realTo)) {
// Windows can't unlink() directory symlinks; it needs rmdir() to be used instead
$res = @rmdir($realTo);
} else {
$res = @unlink($realTo);
}
if(!$res) {
echo "FAILED UNLINK : $realTo\n";
return;
}
}
if($type == 'symlink') {
$res = @symlink($realFrom, $realTo);
} elseif($type == 'link') {
$res = @link($realFrom, $realTo);
}
if(!$res) {
if($type == 'symlink') {
echo "FAILED SYMLINK : $realTo\n";
} elseif($type == 'link') {
echo "FAILED LINK : $realTo\n";
}
}
}
echo "Hard linking files...\n";
if(!empty($hardlink_files)) foreach($hardlink_files as $from => $to) {
doLink($from, $to, 'link');
}
echo "Symlinking files...\n";
if(!empty($symlink_files)) foreach($symlink_files as $from => $to) {
doLink($from, $to, 'symlink');
}
echo "Symlinking folders...\n";
if(!empty($symlink_folders)) foreach($symlink_folders as $from => $to) {
doLink($from, $to, 'symlink');
}