* all aps: lower memory requirements of insert into document by skipping HTML processing, if there are no html (custom-)fields

This commit is contained in:
Ralf Becker 2014-11-19 12:20:59 +00:00
parent ca7bdb66a3
commit c633e0033b
9 changed files with 114 additions and 285 deletions

View File

@ -36,6 +36,9 @@ class addressbook_merge extends bo_merge
// overwrite global export-limit, if an addressbook one is set // overwrite global export-limit, if an addressbook one is set
$this->export_limit = bo_merge::getExportLimit('addressbook'); $this->export_limit = bo_merge::getExportLimit('addressbook');
// switch of handling of html formated content, if html is not used
$this->parse_html_styles = egw_customfields::use_html('addressbook');
} }
/** /**
@ -57,7 +60,7 @@ class addressbook_merge extends bo_merge
} }
// Links // Links
$replacements += $this->get_all_links('addressbook', $id, $prefix, $content); $replacements += $this->get_all_links('addressbook', $id, '', $content);
if (!(strpos($content,'$$calendar/') === false)) if (!(strpos($content,'$$calendar/') === false))
{ {
$replacements += $this->calendar_replacements($id,!(strpos($content,'$$calendar/-1/') === false)); $replacements += $this->calendar_replacements($id,!(strpos($content,'$$calendar/-1/') === false));
@ -68,7 +71,7 @@ class addressbook_merge extends bo_merge
/** /**
* Return replacements for the calendar (next events) of a contact * Return replacements for the calendar (next events) of a contact
* *
* @param int $contact contact-id * @param int $id contact-id
* @param boolean $last_event_too =false also include information about the last event * @param boolean $last_event_too =false also include information about the last event
* @return array * @return array
*/ */

View File

@ -73,6 +73,8 @@ class calendar_merge extends bo_merge
// overwrite global export-limit, if one is set for calendar/appointments // overwrite global export-limit, if one is set for calendar/appointments
$this->export_limit = bo_merge::getExportLimit('calendar'); $this->export_limit = bo_merge::getExportLimit('calendar');
// switch of handling of html formated content, if html is not used
$this->parse_html_styles = egw_customfields::use_html('calendar');
$this->bo = new calendar_boupdate(); $this->bo = new calendar_boupdate();
self::$range_tags['start'] = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat']; self::$range_tags['start'] = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
@ -217,7 +219,7 @@ class calendar_merge extends bo_merge
} }
$custom = config::get_customfields('calendar'); $custom = config::get_customfields('calendar');
foreach($custom as $name => $field) foreach(array_keys($custom) as $name)
{ {
$replacements['$$'.($prefix?$prefix.'/':'').'#'.$name.'$$'] = $event['#'.$name]; $replacements['$$'.($prefix?$prefix.'/':'').'#'.$name.'$$'] = $event['#'.$name];
} }
@ -245,7 +247,7 @@ class calendar_merge extends bo_merge
*/ */
public function day_plugin($plugin,$date,$n,$repeat) public function day_plugin($plugin,$date,$n,$repeat)
{ {
static $days; static $days = null;
if(is_array($date) && !$date['start']) { if(is_array($date) && !$date['start']) {
// List of IDs // List of IDs
if($date[0]['start']) { if($date[0]['start']) {
@ -275,12 +277,12 @@ class calendar_merge extends bo_merge
'cfs' => array(), // read all custom-fields 'cfs' => array(), // read all custom-fields
)); ));
$days = array(); if (true) $days = array();
$replacements = array(); $replacements = array();
$time_format = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i'; $time_format = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i';
foreach($events as $day => $list) foreach($events as $day => $list)
{ {
foreach($list as $key => $event) foreach($list as $event)
{ {
if($this->ids && !in_array($event['id'], $this->ids)) continue; if($this->ids && !in_array($event['id'], $this->ids)) continue;
$start = egw_time::to($event['start'], 'array'); $start = egw_time::to($event['start'], 'array');
@ -304,7 +306,10 @@ class calendar_merge extends bo_merge
); );
if(!is_array($days[date('Ymd',$_date)][date('l',strtotime($day))])) { if(!is_array($days[date('Ymd',$_date)][date('l',strtotime($day))])) {
$blank = $this->calendar_replacements(array()); $blank = $this->calendar_replacements(array());
foreach($blank as &$value) $value = ''; foreach($blank as &$value)
{
$value = '';
}
$days[date('Ymd',$_date)][date('l',strtotime($day))][] = $blank; $days[date('Ymd',$_date)][date('l',strtotime($day))][] = $blank;
} }
$days[date('Ymd',$_date)][date('l',strtotime($day))][0] += $date_marker; $days[date('Ymd',$_date)][date('l',strtotime($day))][0] += $date_marker;
@ -326,7 +331,7 @@ class calendar_merge extends bo_merge
*/ */
public function day($plugin,$id,$n,$repeat) public function day($plugin,$id,$n,$repeat)
{ {
static $days; static $days = null;
// Figure out which day // Figure out which day
list($type, $which) = explode('_',$plugin); list($type, $which) = explode('_',$plugin);
@ -341,9 +346,9 @@ class calendar_merge extends bo_merge
} }
$id = $dates; $id = $dates;
} }
$date = $this->bo->date2array($id['start']); $arr = $this->bo->date2array($id['start']);
$date['day'] = $which; $arr['day'] = $which;
$date = $this->bo->date2ts($date); $date = $this->bo->date2ts($arr);
if(is_array($id) && $id['start'] && ($date < $id['start'] || $date > $id['end'])) return array(); if(is_array($id) && $id['start'] && ($date < $id['start'] || $date > $id['end'])) return array();
} }
elseif ($plugin == 'selected') elseif ($plugin == 'selected')
@ -376,18 +381,18 @@ class calendar_merge extends bo_merge
)); ));
$replacements = array(); $replacements = array();
$days = array(); if (true) $days = array();
$time_format = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i'; $time_format = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? 'h:i a' : 'H:i';
foreach($events as $day => $list) foreach($events as $day => $list)
{ {
foreach($list as $key => $event) foreach($list as $event)
{ {
if($this->ids && !in_array($event['id'], $this->ids)) continue; if($this->ids && !in_array($event['id'], $this->ids)) continue;
$start = egw_time::to($event['start'], 'array'); $start = egw_time::to($event['start'], 'array');
$end = egw_time::to($event['end'], 'array'); $end = egw_time::to($event['end'], 'array');
$replacements = $this->calendar_replacements($event); $replacements = $this->calendar_replacements($event);
if($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) { if($start['year'] == $end['year'] && $start['month'] == $end['month'] && $start['day'] == $end['day']) {
$dow = date('l',$event['start']); //$dow = date('l',$event['start']);
} else { } else {
// Fancy date+time formatting for multi-day events // Fancy date+time formatting for multi-day events
$replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0,0,0,0,0,1)); $replacements['$$calendar_starttime$$'] = date($time_format, $day == date('Ymd', $event['start']) ? $event['start'] : mktime(0,0,0,0,0,1));
@ -402,7 +407,10 @@ class calendar_merge extends bo_merge
); );
if(!is_array($days[date('Ymd',$_date)][$plugin])) { if(!is_array($days[date('Ymd',$_date)][$plugin])) {
$blank = $this->calendar_replacements(array()); $blank = $this->calendar_replacements(array());
foreach($blank as &$value) $value = ''; foreach($blank as &$value)
{
$value = '';
}
$days[date('Ymd',$_date)][$plugin][] = $blank; $days[date('Ymd',$_date)][$plugin][] = $blank;
} }
$days[date('Ymd',$_date)][$plugin][0] += $date_marker; $days[date('Ymd',$_date)][$plugin][0] += $date_marker;
@ -423,6 +431,8 @@ class calendar_merge extends bo_merge
*/ */
public function participant($plugin,$id,$n) public function participant($plugin,$id,$n)
{ {
unset($plugin); // not used, but required by function signature
if(!is_array($id) || !$id['start']) { if(!is_array($id) || !$id['start']) {
$event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null); $event = $this->bo->read(is_array($id) ? $id['id'] : $id, is_array($id) ? $id['recur_date'] : null);
} else { } else {
@ -441,6 +451,7 @@ class calendar_merge extends bo_merge
if(!$participant) return array(); if(!$participant) return array();
// Add some common information // Add some common information
$quantity = $role = null;
calendar_so::split_status($status,$quantity,$role); calendar_so::split_status($status,$quantity,$role);
if ($role != 'REQ-PARTICIPANT') if ($role != 'REQ-PARTICIPANT')
{ {
@ -508,6 +519,7 @@ class calendar_merge extends bo_merge
echo "<table width='90%' align='center'>\n"; echo "<table width='90%' align='center'>\n";
echo '<tr><td colspan="4"><h3>'.lang('Calendar fields:')."</h3></td></tr>"; echo '<tr><td colspan="4"><h3>'.lang('Calendar fields:')."</h3></td></tr>";
$n = 0;
foreach(array( foreach(array(
'calendar_id' => lang('Calendar ID'), 'calendar_id' => lang('Calendar ID'),
'calendar_title' => lang('Title'), 'calendar_title' => lang('Title'),
@ -544,7 +556,7 @@ class calendar_merge extends bo_merge
echo '<tr><td colspan="4"><h3>'.lang('Range fields').":</h3></td></tr>"; echo '<tr><td colspan="4"><h3>'.lang('Range fields').":</h3></td></tr>";
echo '<tr><td colspan="4">'.lang('If you select a range (month, week, etc) instead of a list of entries, these extra fields are available').'</td></tr>'; echo '<tr><td colspan="4">'.lang('If you select a range (month, week, etc) instead of a list of entries, these extra fields are available').'</td></tr>';
foreach(self::$range_tags as $name => $format) foreach(array_keys(self::$range_tags) as $name)
{ {
echo '<tr><td>{{range/'.$name.'}}</td><td>'.lang($name)."</td></tr>\n"; echo '<tr><td>{{range/'.$name.'}}</td><td>'.lang($name)."</td></tr>\n";
} }
@ -577,7 +589,7 @@ class calendar_merge extends bo_merge
} }
echo '</table></td><td colspan="2"><table >'; echo '</table></td><td colspan="2"><table >';
echo '<tr><td><h3>'.lang('Daily tables').":</h3></td></tr>"; echo '<tr><td><h3>'.lang('Daily tables').":</h3></td></tr>";
foreach(self::$relative as $key => $value) { foreach(self::$relative as $value) {
echo '<tr><td>{{table/'.$value. '}} ... {{endtable}}</td></tr>'; echo '<tr><td>{{table/'.$value. '}} ... {{endtable}}</td></tr>';
} }
echo '<tr><td>{{table/day_n}} ... {{endtable}}</td><td>1 <= n <= 31</td></tr>'; echo '<tr><td>{{table/day_n}} ... {{endtable}}</td><td>1 <= n <= 31</td></tr>';

View File

@ -5,13 +5,15 @@
* @link http://www.egroupware.org * @link http://www.egroupware.org
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @package addressbook * @package addressbook
* @copyright (c) 2007-13 by Ralf Becker <RalfBecker-AT-outdoor-training.de> * @copyright (c) 2007-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$ * @version $Id$
*/ */
/** /**
* Document merge print * Document merge print
*
* @todo move apply_styles call into merge_string to run for each entry merged and not all together to lower memory requirements
*/ */
abstract class bo_merge abstract class bo_merge
{ {
@ -78,6 +80,9 @@ abstract class bo_merge
/** /**
* Parse HTML styles into target document style, if possible * Parse HTML styles into target document style, if possible
*
* Apps not using html in there own data should set this with egw_customfields::use_html($app)
* to avoid memory and time consuming html processing.
*/ */
protected $parse_html_styles = true; protected $parse_html_styles = true;
@ -249,7 +254,7 @@ abstract class bo_merge
foreach($this->contacts->customfields as $name => $field) foreach($this->contacts->customfields as $name => $field)
{ {
$name = '#'.$name; $name = '#'.$name;
$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = customfields_widget::format_customfield($field, (string)$contact[$name]); $replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] = egw_customfields::format($field, (string)$contact[$name]);
} }
// Add in extra cat field // Add in extra cat field
@ -339,9 +344,10 @@ abstract class bo_merge
* *
* Calls get_links() repeatedly to get all the combinations for the content. * Calls get_links() repeatedly to get all the combinations for the content.
* *
* @param app String appname * @param $app String appname
* @param id String ID of record * @param $id String ID of record
* @param content String document content * @param $prefix
* @param $content String document content
*/ */
protected function get_all_links($app, $id, $prefix, &$content) protected function get_all_links($app, $id, $prefix, &$content)
{ {
@ -550,16 +556,13 @@ abstract class bo_merge
return $content; return $content;
} }
protected function apply_styles (&$content, $mimetype) protected function apply_styles (&$content, $mimetype, $mso_application_progid=null)
{ {
if ($mimetype == 'application/xml' && if (!isset($mso_application_progid))
preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($content,0,200),$matches))
{ {
$mso_application_progid = $matches[1]; $mso_application_progid = $mimetype == 'application/xml' &&
} preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($content,0,200),$matches) ?
else $matches[1] : '';
{
$mso_application_progid = '';
} }
// Tags we can replace with the target document's version // Tags we can replace with the target document's version
$replace_tags = array(); $replace_tags = array();
@ -585,9 +588,6 @@ abstract class bo_merge
case 'application/xmlWord.Document': // Word 2003*/ case 'application/xmlWord.Document': // Word 2003*/
case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007 case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': // ms office 2007
case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
$replace_tags = array(
'b','strong','i','em','u','span'
);
// It seems easier to split the parent tags here // It seems easier to split the parent tags here
$replace_tags = array( $replace_tags = array(
// Tables, lists don't go inside <w:p> // Tables, lists don't go inside <w:p>
@ -615,7 +615,6 @@ abstract class bo_merge
$i++; $i++;
} while($count > 0 && $i < 10); } while($count > 0 && $i < 10);
//echo $content;die();
$doc = new DOMDocument(); $doc = new DOMDocument();
$xslt = new XSLTProcessor(); $xslt = new XSLTProcessor();
$xslt_file = $mimetype == 'application/xml' ? 'wordml.xslt' : 'msoffice.xslt'; $xslt_file = $mimetype == 'application/xml' ? 'wordml.xslt' : 'msoffice.xslt';
@ -637,7 +636,6 @@ abstract class bo_merge
} }
$content = $xslt->transformToXml($element); $content = $xslt->transformToXml($element);
//echo $content;die();
// Word 2003 needs two declarations, add extra declaration back in // Word 2003 needs two declarations, add extra declaration back in
if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) { if($mimetype == 'application/xml' && $mso_application_progid == 'Word.Document' && strpos($content, '<?xml') !== 0) {
$content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content; $content = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'.$content;
@ -740,7 +738,8 @@ abstract class bo_merge
$err = lang('for more than one contact in a document use the tag pagerepeat!'); $err = lang('for more than one contact in a document use the tag pagerepeat!');
return false; return false;
} }
foreach ((array)$ids as $id) //error_log(__METHOD__."(count(ids)=".count($ids).") strlen(contentrepeat)=".strlen($contentrepeat).', strlen(labelrepeat)='.strlen($Labelrepeat));
foreach ((array)$ids as $n => $id)
{ {
if ($contentrepeat) $content = $contentrepeat; //content to repeat if ($contentrepeat) $content = $contentrepeat; //content to repeat
if ($lableprint) $content = $Labelrepeat; if ($lableprint) $content = $Labelrepeat;
@ -760,7 +759,7 @@ abstract class bo_merge
$err = $e->getMessage(); $err = $e->getMessage();
return false; return false;
} }
//error_log(__METHOD__."() $n: $id ".egw_vfs::hsize(memory_get_usage(true)));
// some general replacements: current user, date and time // some general replacements: current user, date and time
if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id'))) if (strpos($content,'$$user/') !== null && ($user = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'person_id')))
{ {

View File

@ -245,7 +245,7 @@ class customfields_widget
case 'select' : case 'select' :
if (count($field['values']) == 1 && isset($field['values']['@'])) if (count($field['values']) == 1 && isset($field['values']['@']))
{ {
$field['values'] = $this->_get_options_from_file($field['values']['@']); $field['values'] = egw_customfields::get_options_from_file($field['values']['@']);
} }
if($this->advanced_search && $field['rows'] <= 1) $field['values'][''] = lang('doesn\'t matter'); if($this->advanced_search && $field['rows'] <= 1) $field['values'][''] = lang('doesn\'t matter');
foreach($field['values'] as $key => $val) foreach($field['values'] as $key => $val)
@ -496,56 +496,6 @@ class customfields_widget
return True; // extra Label is ok return True; // extra Label is ok
} }
/**
* Read the options of a 'select' or 'radio' custom field from a file
*
* For security reasons that file has to be relative to the eGW root
* (to not use that feature to explore arbitrary files on the server)
* and it has to be a php file setting one variable called options,
* (to not display it to anonymously by the webserver).
* The $options var has to be an array with value => label pairs, eg:
*
* <?php
* $options = array(
* 'a' => 'Option A',
* 'b' => 'Option B',
* 'c' => 'Option C',
* );
*
* @param string $file file name inside the eGW server root, either relative to it or absolute
* @return array in case of an error we return a single option with the message
*/
public static function _get_options_from_file($file)
{
if (!($path = realpath($file{0} == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) || // file does not exist
substr($path,0,strlen(EGW_SERVER_ROOT)+1) != EGW_SERVER_ROOT.'/' || // we are NOT inside the eGW root
basename($path,'.php').'.php' != basename($path) || // extension is NOT .php
basename($path) == 'header.inc.php') // dont allow to include our header again
{
return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path,$file,EGW_SERVER_ROOT));
}
include($path);
return $options;
}
/**
* Get the customfield types containing links
*
* @return array with customefield types as values
*/
public static function get_customfield_link_types()
{
static $link_types;
if (is_null($link_types))
{
$link_types = array_keys(array_intersect(egw_link::app_list('query'),egw_link::app_list('title')));
$link_types[] = 'link-entry';
}
return $link_types;
}
/** /**
* Check if there are links in the custom fields and update them * Check if there are links in the custom fields and update them
* *
@ -556,51 +506,12 @@ class customfields_widget
* @param array $values new values including the custom fields * @param array $values new values including the custom fields
* @param array $old =null old values before the update, if existing * @param array $old =null old values before the update, if existing
* @param string $id_name ='id' name/key of the (link-)id in $values * @param string $id_name ='id' name/key of the (link-)id in $values
* @deprecated use egw_customfields::update_links($own_app,array $values,array $old=null,$id_name='id')
*/ */
public static function update_customfield_links($own_app,array $values,array $old=null,$id_name='id') public static function update_customfield_links($own_app,array $values,array $old=null,$id_name='id')
{ {
$link_types = self::get_customfield_link_types(); return egw_customfields::update_links($own_app, $values, $old , $id_name);
foreach(egw_customfields::get($own_app) as $name => $data)
{
if (!in_array($data['type'],$link_types)) continue;
// do we have a different old value --> delete that link
if ($old && $old['#'.$name] && $old['#'.$name] != $values['#'.$name])
{
if ($data['type'] == 'link-entry')
{
list($app,$id) = explode(':',$old['#'.$name]);
} }
else
{
$app = $data['type'];
$id = $old['#'.$name];
}
egw_link::unlink(false,$own_app,$values[$id_name],'',$app,$id);
}
if ($data['type'] == 'link-entry')
{
list($app,$id) = explode(':',$values['#'.$name]);
}
else
{
$app = $data['type'];
$id = $values['#'.$name];
}
if ($id) // create new link, does nothing for already existing links
{
egw_link::link($own_app,$values[$id_name],$app,$id);
}
}
}
/**
* Non printable custom fields eg. UI elements
*
* @var array
*/
public static $non_printable_fields = array('button');
/** /**
* Format a single custom field value as string * Format a single custom field value as string
@ -608,75 +519,10 @@ class customfields_widget
* @param array $field field defintion incl. type * @param array $field field defintion incl. type
* @param string $value field value * @param string $value field value
* @return string formatted value * @return string formatted value
* @deprecated use egw_customfields::format($field, $value)
*/ */
public static function format_customfield(array $field, $value) public static function format_customfield(array $field, $value)
{ {
switch($field['type']) return egw_customfields::format($field, $value);
{
case 'select-account':
if ($value)
{
$values = array();
foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value)
{
$values[] = common::grab_owner_name($value);
}
$value = implode(', ',$values);
}
break;
case 'checkbox':
$value = $value ? 'X' : '';
break;
case 'select':
case 'radio':
if (count($field['values']) == 1 && isset($field['values']['@']))
{
$field['values'] = customfields_widget::_get_options_from_file($field['values']['@']);
}
$values = array();
foreach($field['rows'] > 1 ? explode(',', $value) : (array) $value as $value)
{
$values[] = isset($field['values'][$value]) ? $field['values'][$value] : '#'.$value;
}
$value = implode(', ', $values);
break;
case 'date':
case 'date-time':
if ($value)
{
$format = $field['len'] ? $field['len'] : ($field['type'] == 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
$date = array_combine(preg_split('/[\\/. :-]/',$format), preg_split('/[\\/. :-]/',$value));
$value = common::dateformatorder($date['Y'], $date['m'], $date['d'],true);
if (isset($date['H'])) $value .= ' '.common::formattime($date['H'], $date['i']);
}
break;
case 'htmlarea': // ToDo: EMail probably has a nicer html2text method
if ($value) $value = strip_tags(preg_replace('/<(br|p)[^>]*>/i', "\r\n", str_replace(array("\r", "\n"), '', $value)));
break;
case 'ajax_select': // ToDo: returns unchanged value for now
break;
default:
// handling for several link types
if ($value && in_array($field['type'], self::get_customfield_link_types()))
{
if ($field['type'] == 'link-entry' || strpos($value, ':') !== false)
{
list($app, $value) = explode(':', $value);
}
else
{
$app = $field['type'];
}
if ($value) $value = egw_link::title($app, $value);
}
break;
}
return $value;
} }
} }

View File

@ -275,7 +275,7 @@ class etemplate_widget_customfields extends etemplate_widget_transformer
case 'radio': case 'radio':
if (count($field['values']) == 1 && isset($field['values']['@'])) if (count($field['values']) == 1 && isset($field['values']['@']))
{ {
$field['values'] = self::_get_options_from_file($field['values']['@']); $field['values'] = egw_customfields::get_options_from_file($field['values']['@']);
} }
// keep extra values set by app code, eg. addressbook advanced search // keep extra values set by app code, eg. addressbook advanced search
if (is_array(self::$request->sel_options[self::$prefix.$fname])) if (is_array(self::$request->sel_options[self::$prefix.$fname]))
@ -370,38 +370,4 @@ class etemplate_widget_customfields extends etemplate_widget_transformer
} }
} }
} }
/**
* Read the options of a 'select' or 'radio' custom field from a file
*
* For security reasons that file has to be relative to the eGW root
* (to not use that feature to explore arbitrary files on the server)
* and it has to be a php file setting one variable called options,
* (to not display it to anonymously by the webserver).
* The $options var has to be an array with value => label pairs, eg:
*
* <?php
* $options = array(
* 'a' => 'Option A',
* 'b' => 'Option B',
* 'c' => 'Option C',
* );
*
* @param string $file file name inside the eGW server root, either relative to it or absolute
* @return array in case of an error we return a single option with the message
*/
public static function _get_options_from_file($file)
{
if (!($path = realpath($file{0} == '/' ? $file : EGW_SERVER_ROOT.'/'.$file)) || // file does not exist
substr($path,0,strlen(EGW_SERVER_ROOT)+1) != EGW_SERVER_ROOT.'/' || // we are NOT inside the eGW root
basename($path,'.php').'.php' != basename($path) || // extension is NOT .php
basename($path) == 'header.inc.php') // dont allow to include our header again
{
return array(lang("'%1' is no php file in the eGW server root (%2)!".': '.$path,$file,EGW_SERVER_ROOT));
}
$options = array();
include($path);
return $options;
}
} }

View File

@ -220,7 +220,7 @@ class historylog_widget
} }
elseif($cf_data['values']['@']) elseif($cf_data['values']['@'])
{ {
self::$status_widgets['#'.$cf_name] = customfields_widget::_get_options_from_file($cf_data['values']['@']); self::$status_widgets['#'.$cf_name] = egw_customfields::get_options_from_file($cf_data['values']['@']);
} }
elseif(count($cf_data['values'])) elseif(count($cf_data['values']))
{ {

View File

@ -55,10 +55,14 @@ class filemanager_merge extends bo_merge
function __construct($_dir = '') function __construct($_dir = '')
{ {
parent::__construct(); parent::__construct();
if($_dir) if($_dir)
{ {
$this->dir = $_dir; $this->dir = $_dir;
} }
// switch of handling of html formated content, if html is not used
$this->parse_html_styles = egw_customfields::use_html('filemanager');
} }
/** /**
@ -104,14 +108,15 @@ class filemanager_merge extends bo_merge
$file['gid'] *= -1; // our widgets use negative gid's $file['gid'] *= -1; // our widgets use negative gid's
if (($props = egw_vfs::propfind($id))) if (($props = egw_vfs::propfind($id)))
{ {
foreach($props as $prop) $file[$prop['name']] = $prop['val']; foreach($props as $prop)
{
$file[$prop['name']] = $prop['val'];
}
} }
if (($file['is_link'] = egw_vfs::is_link($id))) if (($file['is_link'] = egw_vfs::is_link($id)))
{ {
$file['symlink'] = egw_vfs::readlink($id); $file['symlink'] = egw_vfs::readlink($id);
} }
$extra = egw_vfs::getExtraInfo($id);
// Custom fields // Custom fields
if($content && strpos($content, '#') !== 0) if($content && strpos($content, '#') !== 0)
{ {
@ -136,17 +141,6 @@ class filemanager_merge extends bo_merge
} }
} }
// 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 in apps folder, try for app-specific placeholders
if($dirlist[1] == 'apps' && count($dirlist) > 1) if($dirlist[1] == 'apps' && count($dirlist) > 1)
{ {
@ -182,7 +176,9 @@ class filemanager_merge extends bo_merge
} }
} }
// Silently discard & continue // Silently discard & continue
catch(Exception $e) {} catch(Exception $e) {
unset($e); // not used
}
} }
} }
} }

View File

@ -6,7 +6,7 @@
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @author Nathan Gray * @author Nathan Gray
* @package infolog * @package infolog
* @copyright (c) 2007-9 by Ralf Becker <RalfBecker-AT-outdoor-training.de> * @copyright (c) 2007-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright 2011 Nathan Gray * @copyright 2011 Nathan Gray
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$ * @version $Id$
@ -48,6 +48,9 @@ class infolog_merge extends bo_merge
'info_datemodified', 'info_datemodified',
'info_created', 'info_created',
); );
// switch of handling of html formated content, if html is not used
$this->parse_html_styles = egw_customfields::use_html('infolog');
} }
/** /**
@ -119,7 +122,7 @@ class infolog_merge extends bo_merge
// Set any missing custom fields, or the marker will stay // Set any missing custom fields, or the marker will stay
$array = $record->get_record_array(); $array = $record->get_record_array();
foreach($this->bo->customfields as $name => $field) foreach(array_keys($this->bo->customfields) as $name)
{ {
if(!$array['#'.$name]) if(!$array['#'.$name])
{ {
@ -133,7 +136,6 @@ class infolog_merge extends bo_merge
// Timesheet time // Timesheet time
if(strpos($content, 'info_sum_timesheets')) if(strpos($content, 'info_sum_timesheets'))
{ {
$timesheets = array();
$links = egw_link::get_links('infolog',$id,'timesheet'); $links = egw_link::get_links('infolog',$id,'timesheet');
$sum = ExecMethod('timesheet.timesheet_bo.sum',$links); $sum = ExecMethod('timesheet.timesheet_bo.sum',$links);
$info['$$info_sum_timesheets$$'] = $sum['duration']; $info['$$info_sum_timesheets$$'] = $sum['duration'];
@ -141,7 +143,8 @@ class infolog_merge extends bo_merge
// Check for linked project ID // Check for linked project ID
$links = egw_link::get_links('infolog', $id, 'projectmanager'); $links = egw_link::get_links('infolog', $id, 'projectmanager');
foreach($links as $link_id => $app_id) { foreach($links as $app_id)
{
$array['pm_id'] = $app_id; $array['pm_id'] = $app_id;
$array['project'] = egw_link::title('projectmanager', $app_id); $array['project'] = egw_link::title('projectmanager', $app_id);
break; break;
@ -210,7 +213,7 @@ class infolog_merge extends bo_merge
echo '<tr><td>{{info_id_parent/info_subject}}</td><td colspan="3">'.lang('All other %1 fields are valid',lang('infolog'))."</td></tr>\n"; echo '<tr><td>{{info_id_parent/info_subject}}</td><td colspan="3">'.lang('All other %1 fields are valid',lang('infolog'))."</td></tr>\n";
echo '<tr><td colspan="4"><h3>'.lang('Contact fields').':</h3></td></tr>'; echo '<tr><td colspan="4"><h3>'.lang('Contact fields').':</h3></td></tr>';
$n = 0; $i = 0;
foreach($this->contacts->contact_fields as $name => $label) foreach($this->contacts->contact_fields as $name => $label)
{ {
if (in_array($name,array('tid','label','geo'))) continue; // dont show them, as they are not used in the UI atm. if (in_array($name,array('tid','label','geo'))) continue; // dont show them, as they are not used in the UI atm.
@ -218,12 +221,12 @@ class infolog_merge extends bo_merge
if (in_array($name,array('email','org_name','tel_work','url')) && $n&1) // main values, which should be in the first column if (in_array($name,array('email','org_name','tel_work','url')) && $n&1) // main values, which should be in the first column
{ {
echo "</tr>\n"; echo "</tr>\n";
$n++; $i++;
} }
if (!($n&1)) echo '<tr>'; if (!($i&1)) echo '<tr>';
echo '<td>{{info_contact/'.$name.'}}</td><td>'.$label.'</td>'; echo '<td>{{info_contact/'.$name.'}}</td><td>'.$label.'</td>';
if ($n&1) echo "</tr>\n"; if ($i&1) echo "</tr>\n";
$n++; $i++;
} }
echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>"; echo '<tr><td colspan="4"><h3>'.lang('Custom fields').":</h3></td></tr>";

View File

@ -6,7 +6,7 @@
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de> * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @author Nathan Gray * @author Nathan Gray
* @package timesheet * @package timesheet
* @copyright (c) 2007-9 by Ralf Becker <RalfBecker-AT-outdoor-training.de> * @copyright (c) 2007-14 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
* @copyright 2011 Nathan Gray * @copyright 2011 Nathan Gray
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @version $Id$ * @version $Id$
@ -49,6 +49,10 @@ class timesheet_merge extends bo_merge
function __construct() function __construct()
{ {
parent::__construct(); parent::__construct();
// switch of handling of html formated content, if html is not used
$this->parse_html_styles = egw_customfields::use_html('timesheet');
$this->bo = new timesheet_bo(); $this->bo = new timesheet_bo();
$this->date_fields += array( $this->date_fields += array(
'ts_start', 'ts_start',
@ -130,7 +134,7 @@ class timesheet_merge extends bo_merge
} }
// Set any missing custom fields, or the marker will stay // Set any missing custom fields, or the marker will stay
foreach($this->bo->customfields as $name => $field) foreach(array_keys($this->bo->customfields) as $name)
{ {
if(!$array['#'.$name]) $array['#'.$name] = ''; if(!$array['#'.$name]) $array['#'.$name] = '';
} }
@ -185,13 +189,13 @@ class timesheet_merge extends bo_merge
echo '<tr><td colspan="4"><h3>'.lang('Project fields').':</h3></td></tr>'; echo '<tr><td colspan="4"><h3>'.lang('Project fields').':</h3></td></tr>';
$pm_merge = new projectmanager_merge(); $pm_merge = new projectmanager_merge();
$n = 0; $i = 0;
foreach($pm_merge->projectmanager_fields as $name => $label) foreach($pm_merge->projectmanager_fields as $name => $label)
{ {
if (!($n&1)) echo '<tr>'; if (!($i&1)) echo '<tr>';
echo '<td>{{ts_project/'.$name.'}}</td><td>'.$label.'</td>'; echo '<td>{{ts_project/'.$name.'}}</td><td>'.$label.'</td>';
if ($n&1) echo "</tr>\n"; if ($i&1) echo "</tr>\n";
$n++; $i++;
} }
echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>"; echo '<tr><td colspan="4"><h3>'.lang('General fields:')."</h3></td></tr>";