true, ); /** * Fields that are numeric, for special numeric handling */ protected $numeric_fields = array( ); /** * Business object to pull records from */ protected $bo = null; /** * Current directory - affects how files are named */ protected $dir = ''; /** * Constructor * */ function __construct($_dir = '') { parent::__construct(); if($_dir) { $this->dir = $_dir; } } /** * Get replacements * * @param int $id id of entry * @param string &$content=null content to create some replacements only if they are use * @return array|boolean */ protected function get_replacements($id,&$content=null) { if (!($replacements = $this->filemanager_replacements($id, '', $content))) { return false; } return $replacements; } /** * Get filemanager replacements * * @param int $id id (vfs path) of entry * @param string $prefix='' prefix like eg. 'erole' * @return array|boolean */ public function filemanager_replacements($id,$prefix='', &$content = null) { $info = array(); $file = egw_vfs::lstat($id,true); $file['mtime'] = egw_time::to($file['mtime']); $file['ctime'] = egw_time::to($file['ctime']); $file['name'] = egw_vfs::basename($id); $file['dir'] = egw_vfs::decodePath(egw_vfs::dirname($id)); $dirlist = explode('/',$file['dir']); $file['folder'] = array_pop($dirlist); $file['folder_file'] = $file['folder'] . '/'.$file['name']; $file['path'] = $id; $file['rel_path'] = str_replace($this->dir.'/', '', $id); $file['hsize'] = egw_vfs::hsize($file['size']); $file['mime'] = egw_vfs::mime_content_type($id); $file['gid'] *= -1; // our widgets use negative gid's if (($props = egw_vfs::propfind($id))) { foreach($props as $prop) $file[$prop['name']] = $prop['val']; } if (($file['is_link'] = egw_vfs::is_link($id))) { $file['symlink'] = egw_vfs::readlink($id); } $extra = egw_vfs::getExtraInfo($id); // Custom fields if($content && strpos($content, '#') !== 0) { // Expand link-to custom fields $this->cf_link_to_expand($file, $content, $info); foreach(config::get_customfields('filemanager') as $name => $field) { // Set any missing custom fields, or the marker will stay if(!$file['#'.$name]) { $file['#'.$name] = ''; continue; } // Format date cfs per user preferences if($field['type'] == 'date' || $field['type'] == 'date-time') { $file['#'.$name] = egw_time::to($file['#'.$name]); } } } // Links /* Not applicable to filemanager $file['links'] = $this->get_links('filemanager', $id, '!'.egw_link::VFS_APPNAME); $file['attachments'] = $this->get_links('filemanager', $id, egw_link::VFS_APPNAME); $file['links_attachments'] = $this->get_links('filemanager', $id); foreach(array_keys($GLOBALS['egw_info']['user']['apps']) as $app) { $file["links/{$app}"] = $this->get_links('filemanager',$id, $app); } */ // If in apps folder, try for app-specific placeholders if($dirlist[1] == 'apps' && count($dirlist) > 1) { // Get rid of any virtual folders (eg: All$) $resolved = egw_vfs::resolve_url_symlinks($file['path']); if($resolved) { list($app, $id) = explode('/', substr($resolved, strpos($resolved, 'apps/')+5)); if($app && $GLOBALS['egw_info']['user']['apps'][$app]) { $app_merge = null; try { $classname = $app .'_merge'; if(class_exists($classname)) { $app_merge = new $classname(); if($app_merge && method_exists($app_merge, 'get_replacements')) { $app_placeholders = $app_merge->get_replacements($id, $content); } } } // Silently discard & continue catch(Exception $e) {} } } } $link = egw_link::mime_open($file['url'], $file['mime']); if(is_array($link)) { // Directories have their internal protocol in path here if($link['path'] && strpos($link['path'], '://') !== false) $link['path'] = $file['path']; $link = egw_session::link('/index.php', $link); } else { // Regular files $link = egw_session::link($link); } // Prepend site, if missing if ($link{0} == '/') { $link = ($_SERVER['HTTPS'] || $GLOBALS['egw_info']['server']['enforce_ssl'] ? 'https://' : 'http://'). ($GLOBALS['egw_info']['server']['hostname'] ? $GLOBALS['egw_info']['server']['hostname'] : $_SERVER['HTTP_HOST']).$link; } $file['link'] = html::a_href(html::htmlspecialchars($file['name']), $link); $file['url'] = $link; // Add markers foreach($file as $key => &$value) { if(!$value) $value = ''; $info['$$'.($prefix ? $prefix.'/':'').$key.'$$'] = $value; } if($app_placeholders) { $info = array_merge($app_placeholders, $info); } return $info; } /** * Generate table with replacements for the preferences * */ public function show_replacements() { $GLOBALS['egw_info']['flags']['app_header'] = lang('filemanager').' - '.lang('Replacements for inserting entries into documents'); $GLOBALS['egw_info']['flags']['nonavbar'] = false; common::egw_header(); echo "
'.lang('Filemanager fields:')." | |||
{{'.$name.'}} | '.lang($label).' | '; if ($n&1) echo "||
'.lang('Custom fields').": | |||
{{#'.$name.'}} | '.$field['label']." | ||
'.lang('Application fields').": | |||
'.lang('For files linked to an application entry (inside /apps/appname/id/) the placeholders for that application are also available. See the specific application for a list of available placeholders.').' | |||
'.lang('General fields:')." | |||
{{'.$name.'}} | '.$label." |