| Conditions | 36 |
| Paths | > 20000 |
| Total Lines | 125 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 95 | public function filemanager_replacements($id,$prefix='', &$content = null) |
||
| 96 | { |
||
| 97 | $info = array(); |
||
| 98 | $file = Vfs::lstat($id,true); |
||
| 99 | |||
| 100 | $file['mtime'] = Api\DateTime::to($file['mtime']); |
||
| 101 | $file['ctime'] = Api\DateTime::to($file['ctime']); |
||
| 102 | |||
| 103 | $file['name'] = Vfs::basename($id); |
||
| 104 | $file['dir'] = ($dir = Vfs::dirname($id)) ? Vfs::decodePath($dir) : ''; |
||
| 105 | $dirlist = explode('/',$file['dir']); |
||
| 106 | $file['folder'] = array_pop($dirlist); |
||
| 107 | $file['folder_file'] = $file['folder'] . '/'.$file['name']; |
||
| 108 | $file['path'] = $id; |
||
| 109 | $file['rel_path'] = str_replace($this->dir.'/', '', $id); |
||
| 110 | $file['hsize'] = Vfs::hsize($file['size']); |
||
| 111 | $file['mime'] = Vfs::mime_content_type($id); |
||
| 112 | $file['gid'] *= -1; // our widgets use negative gid's |
||
| 113 | if (($props = Vfs::propfind($id))) |
||
| 114 | { |
||
| 115 | foreach($props as $prop) |
||
| 116 | { |
||
| 117 | $file[$prop['name']] = $prop['val']; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | if (($file['is_link'] = Vfs::is_link($id))) |
||
| 121 | { |
||
| 122 | $file['symlink'] = Vfs::readlink($id); |
||
| 123 | } |
||
| 124 | // Custom fields |
||
| 125 | if($content && strpos($content, '#') !== 0) |
||
| 126 | { |
||
| 127 | // Expand link-to custom fields |
||
| 128 | $this->cf_link_to_expand($file, $content, $info); |
||
| 129 | |||
| 130 | foreach(Api\Storage\Customfields::get('filemanager') as $name => $field) |
||
| 131 | { |
||
| 132 | // Set any missing custom fields, or the marker will stay |
||
| 133 | if(!$file['#'.$name]) |
||
| 134 | { |
||
| 135 | $file['#'.$name] = ''; |
||
| 136 | continue; |
||
| 137 | } |
||
| 138 | |||
| 139 | // Format date cfs per user Api\Preferences |
||
| 140 | if($field['type'] == 'date' || $field['type'] == 'date-time') |
||
| 141 | { |
||
| 142 | $this->date_fields[] = '#'.$name; |
||
| 143 | $file['#'.$name] = Api\DateTime::to($file['#'.$name], $field['type'] == 'date' ? true : ''); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | // If in apps folder, try for app-specific placeholders |
||
| 149 | if($dirlist[1] == 'apps' && count($dirlist) > 1) |
||
| 150 | { |
||
| 151 | // Try this first - a normal path /apps/appname/id/file |
||
| 152 | list($app, $app_id) = explode('/', substr($file['path'], strpos($file['path'], 'apps/')+5)); |
||
| 153 | // Symlink? |
||
| 154 | if(!$app || !(int)$app_id || !array_key_exists($app, $GLOBALS['egw_info']['user']['apps'])) { |
||
| 155 | // Try resolving just app + ID - /apps/App Name/Record Title/file |
||
| 156 | $resolved = Vfs::resolve_url_symlinks(implode('/',array_slice(explode('/',$file['dir']),0,4))); |
||
| 157 | list($app, $app_id) = explode('/', substr($resolved, strpos($resolved, 'apps/')+5)); |
||
| 158 | |||
| 159 | if(!$app || !(int)$app_id || !array_key_exists($app, $GLOBALS['egw_info']['user']['apps'])) { |
||
| 160 | // Get rid of any virtual folders (eg: All$) and symlinks |
||
| 161 | $resolved = Vfs::resolve_url_symlinks($file['path']); |
||
| 162 | list($app, $app_id) = explode('/', substr($resolved, strpos($resolved, 'apps/')+5)); |
||
| 163 | } |
||
| 164 | } |
||
| 165 | if($app && $app_id) |
||
| 166 | { |
||
| 167 | if($app && $GLOBALS['egw_info']['user']['apps'][$app]) |
||
| 168 | { |
||
| 169 | $app_merge = null; |
||
|
|
|||
| 170 | try |
||
| 171 | { |
||
| 172 | $classname = $app .'_merge'; |
||
| 173 | if(class_exists($classname)) |
||
| 174 | { |
||
| 175 | $app_merge = new $classname(); |
||
| 176 | if($app_merge && method_exists($app_merge, 'get_replacements')) |
||
| 177 | { |
||
| 178 | $app_placeholders = $app_merge->get_replacements($app_id, $content); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | } |
||
| 182 | // Silently discard & continue |
||
| 183 | catch(Exception $e) { |
||
| 184 | unset($e); // not used |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } |
||
| 188 | } |
||
| 189 | $link = Link::mime_open($file['url'], $file['mime']); |
||
| 190 | if(is_array($link)) |
||
| 191 | { |
||
| 192 | // Directories have their internal protocol in path here |
||
| 193 | if($link['path'] && strpos($link['path'], '://') !== false) $link['path'] = $file['path']; |
||
| 194 | $link = Api\Session::link('/index.php', $link); |
||
| 195 | } |
||
| 196 | else |
||
| 197 | { |
||
| 198 | // Regular files |
||
| 199 | $link = Api\Session::link($link); |
||
| 200 | } |
||
| 201 | |||
| 202 | // Prepend site, if missing |
||
| 203 | if ($link[0] == '/') $link = Api\Framework::getUrl($link); |
||
| 204 | |||
| 205 | $file['link'] = Api\Html::a_href(Api\Html::htmlspecialchars($file['name']), $link); |
||
| 206 | $file['webdav_url'] = Api\Session::link(Vfs::download_url($file['url'])); |
||
| 207 | $file['url'] = $link; |
||
| 208 | |||
| 209 | // Add markers |
||
| 210 | foreach($file as $key => &$value) |
||
| 211 | { |
||
| 212 | if(!$value) $value = ''; |
||
| 213 | $info['$$'.($prefix ? $prefix.'/':'').$key.'$$'] = $value; |
||
| 214 | } |
||
| 215 | if($app_placeholders) |
||
| 216 | { |
||
| 217 | $info = array_merge($app_placeholders, $info); |
||
| 218 | } |
||
| 219 | return $info; |
||
| 220 | } |
||
| 325 |