Author: ralfbecker
New Revision: 55637
URL: http://svn.stylite.de/viewvc/egroupware?rev=55637&view=rev
Log:
move bo_merge as Storage\Merge into api
Added:
trunk/egroupware/api/src/Storage/Merge.php
- copied, changed from r55605, trunk/etemplate/inc/class.bo_merge.inc.php
Modified:
trunk/egroupware/api/src/Mail.php
trunk/etemplate/inc/class.bo_merge.inc.php
— trunk/egroupware/api/src/Mail.php (original)
+++ trunk/egroupware/api/src/Mail.php Tue Apr 5 20:43:46 2016
@@ -6530,22 +6530,22 @@
/**
* importMessageToMergeAndSend
*
-
-
@param object &bo_merge bo_merge object
-
-
@param Storage\Merge bo_merge bo_merge object
-
@param string $document the full filename
-
@param array $SendAndMergeTocontacts array of contact ids
-
-
@param string $_folder (passed by reference) will set the folder used. must be set with a folder, but will hold modifications if
-
-
@param string& $_folder (passed by reference) will set the folder used. must be set with a folder, but will hold modifications if
-
folder is modified
-
-
@param string $importID ID for the imported message, used by attachments to identify them unambiguously
-
-
@param string& $importID ID for the imported message, used by attachments to identify them unambiguously
-
@return mixed array of messages with success and failed messages or exception
*/
- function importMessageToMergeAndSend(bo_merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID=’’)
- function importMessageToMergeAndSend(Storage\Merge $bo_merge, $document, $SendAndMergeTocontacts, &$_folder, &$importID=’’)
{
$importfailed = false;
$processStats = array(‘success’=>array(),‘failed’=>array());
if (empty($SendAndMergeTocontacts))
{
$importfailed = true;
-
$alert_msg .= lang("Import of message %1 failed. No Contacts to merge and send to specified.", '');
}
// check if formdata meets basic restrictions (in tmp dir, or vfs, mimetype, etc.)
@@ -6636,7 +6636,7 @@
$nfn = ($contact[‘n_fn’] ? $contact[‘n_fn’] : $contact[‘n_given’].’ '.$contact[‘n_family’]);
if($email)
{
@@ -6692,7 +6692,7 @@
$nfn = ($contact[‘n_fn’] ? $contact[‘n_fn’] : $contact[‘n_given’].’ '.$contact[‘n_family’]);
if($email)
{
-
$mailObject->addAddress(Horde_Idna::encode($email), $nfn);
}
}
$mailObject->addHeader('Subject', $bo_merge->merge_string($Subject, $val, $e, 'text/plain', array(), self::$displayCharset));
— trunk/etemplate/inc/class.bo_merge.inc.php (original)
+++ trunk/egroupware/api/src/Storage/Merge.php Tue Apr 5 20:43:46 2016
@@ -4,18 +4,33 @@
*
+namespace EGroupware\Api\Storage;
+
+use EGroupware\Api;
+use EGroupware\Stylite;
+
+use DOMDocument;
+use XSLTProcessor;
+use tidy;
+use ZipArchive;
+
+// explicit import old, non-namespaced phpgwapi classes
+use uiaccountsel;
+use egw; // link
/**
- 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 Merge
{
/*
- Instance of the addressbook_bo class
@@ -81,7 +96,7 @@
/**
- 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)
-
- Apps not using html in there own data should set this with Customfields::use_html($app)
- to avoid memory and time consuming html processing.
*/
protected $parse_html_styles = true;
@@ -101,11 +116,11 @@
function __construct()
{
// Common messages are in preferences
-
Api\Translation::add_app('addressbook');
-
-
$this->contacts = new Api\Contacts();
$this->datetime_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '.
($GLOBALS['egw_info']['user']['preferences']['common']['timeformat']==12 ? 'h:i a' : 'H:i');
@@ -147,7 +162,7 @@
*/
static public function is_implemented($mimetype,$extension=null)
{
@@ -186,7 +201,7 @@
return false;
// As browsers not always return correct mime types, one could use a negative list instead
-
//return !($mimetype == Api\Vfs::DIR_MIME_TYPE || substr($mimetype,0,6) == 'image/');
}
/**
@@ -212,17 +227,16 @@
switch($name)
{
case ‘created’: case ‘modified’:
-
list($y,$m,$d) = explode('-',$value);
-
$value = common::dateformatorder($y,$m,$d,true);
@@ -262,13 +276,13 @@
}
// set custom fields, should probably go to a general method all apps can use
// need to load all cfs for $ignore_acl=true
-
foreach($ignore_acl ? Customfields::get('addressbook', true) : $this->contacts->customfields as $name => $field)
{
$name = '#'.$name;
$replacements['$$'.($prefix ? $prefix.'/':'').$name.'$$'] =
// use raw data for yaml, no user-preference specific formatting
$this->mimetype == 'application/x-yaml' ? (string)$contact[$name] :
@@ -278,8 +292,7 @@
if(!$cat_id) continue;
if($GLOBALS[‘egw’]->categories->id2name($cat_id,‘main’) != $cat_id)
{
-
$path = $GLOBALS['egw']->categories->id2name($cat_id,'path');
-
$path = explode(' / ', $path);
-
$path = explode(' / ', $GLOBALS['egw']->categories->id2name($cat_id, 'path'));
unset($path[0]); // Drop main
$cats[$GLOBALS['egw']->categories->id2name($cat_id,'main')][] = implode(' / ', $path);
} elseif($cat_id) {
@@ -309,9 +322,9 @@
*/
protected function get_links($app, $id, $only_app=’’, $exclude = array(), $style = ‘title’)
{
@@ -323,15 +336,15 @@
}
if($exclude && in_array($link_info[‘id’], $exclude)) continue;
-
$title = egw_link::title($link_info['app'], $link_info['id']);
-
if(class_exists('stylite_links_stream_wrapper') && $link_info['app'] != egw_link::VFS_APPNAME)
-
{
-
$title = stylite_links_stream_wrapper::entry2name($link_info['app'], $link_info['id'], $title);
-
$title = Api\Link::title($link_info['app'], $link_info['id']);
-
if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $link_info['app'] != Api\Link::VFS_APPNAME)
-
{
-
$title = Stylite\Vfs\Links\StreamWrapper::entry2name($link_info['app'], $link_info['id'], $title);
}
if($style == 'href' || $style == 'link')
{
-
$link = egw_link::view($link_info['app'], $link_info['id'], $link_info);
-
if($link_info['app'] != egw_link::VFS_APPNAME)
-
$link = Api\Link::view($link_info['app'], $link_info['id'], $link_info);
-
if($link_info['app'] != Api\Link::VFS_APPNAME)
{
// Set app to false so we always get an external link
$link = str_replace(',','%2C',egw::link('/index.php',$link, false));
@@ -346,7 +359,7 @@
$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;
}
@@ -367,7 +380,8 @@
{
$array = array();
$pattern = ‘@$(link|links|attachments|links_attachments)/?(title|href|link)?/?([a-z]*)$@’;
@@ -382,14 +396,14 @@
{
case ‘link’:
// Link to current record
-
$title = egw_link::title($app, $id);
-
if(class_exists('stylite_links_stream_wrapper') && $app != egw_link::VFS_APPNAME)
-
$title = Api\Link::title($app, $id);
-
if(class_exists('EGroupware\Stylite\Vfs\Links\StreamWrapper') && $app != Api\Link::VFS_APPNAME)
{
-
$link = Api\Link::view($app, $id);
-
if($app != Api\Link::VFS_APPNAME)
{
// Set app to false so we always get an external link
$link = str_replace(',','%2C',egw::link('/index.php',$link, false));
@@ -404,14 +418,13 @@
$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;
}
-
$title = html::a_href(html::htmlspecialchars($title), $link);
-
$array[($prefix?$prefix.'/':'').$placeholder] = $title;
-
$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, '!'.egw_link::VFS_APPNAME, array(),$matches[2][$i]);
-
$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, '!'.Api\Link::VFS_APPNAME, array(),$matches[2][$i]);
break;
case 'attachments':
-
$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, egw_link::VFS_APPNAME,array(),$matches[2][$i]);
-
$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, Api\Link::VFS_APPNAME,array(),$matches[2][$i]);
break;
default:
$array[($prefix?$prefix.'/':'').$placeholder] = $this->get_links($app, $id, $matches[3][$i], array(), $matches[2][$i]);
@@ -421,10 +434,10 @@
}
}
// Need to set each app, to make sure placeholders are removed
-
foreach(array_keys($GLOBALS['egw_info']['user']['apps']) as $_app)
-
{
-
$array[($prefix?$prefix.'/':'')."links/$app"] = $this->get_links($app,$id,$_app);
-
}
-
foreach(array_keys($GLOBALS['egw_info']['user']['apps']) as $_app)
-
{
-
$array[($prefix?$prefix.'/':'')."links/$app"] = $this->get_links($app,$id,$_app);
-
}
return $array;
}
@@ -432,16 +445,16 @@
* Format a datetime
*
* @param int|string|DateTime $time unix timestamp or Y-m-d H:i:s string (in user time!)
-
-
@param string $format=null format string, default $this->datetime_format
-
-
@deprecated use egw_time::to($time=‘now’,$format=’’)
-
-
@param string $format =null format string, default $this->datetime_format
-
-
@deprecated use Api\DateTime::to($time=‘now’,$format=’’)
-
@return string
*/
protected function format_datetime($time,$format=null)
{
-
trigger_error(__METHOD__ . ' is deprecated, use Api\DateTime::to($time, $format)', E_USER_DEPRECATED);
if (is_null($format)) $format = $this->datetime_format;
-
return Api\DateTime::to($time,$format);
}
/**
@@ -453,7 +466,7 @@
*/
public static function is_export_limit_excepted()
{
@@ -472,17 +485,15 @@
}
/**
-
-
- checks if there is an exportlimit set, and returns
-
-
@param mixed $app_limit checks and validates app_limit, if not set returns the global limit
-
-
- Checks if there is an exportlimit set, and returns
-
-
*/
public static function getExportLimit($app=‘common’)
{
@@ -538,7 +549,7 @@
* @param array $ids array with contact id(s)
* @param string &$err error-message on error
* @param string $mimetype mimetype of complete document, eg. text/*, application/vnd.oasis.opendocument.text, application/rtf
-
-
@param array $fix=null regular expression => replacement pairs eg. to fix garbled placeholders
-
-
@param array $fix =null regular expression => replacement pairs eg. to fix garbled placeholders
-
@return string|boolean merged document or false on error
*/
public function &merge($document,$ids,&$err,$mimetype,array $fix=null)
@@ -563,7 +574,7 @@
try {
$content = $this->merge_string($content,$ids,$err,$mimetype,$fix);
@@ -574,6 +585,7 @@
{
if (!isset($mso_application_progid))
{
-
$matches = null;
$mso_application_progid = $mimetype == 'application/xml' &&
preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($content,0,200),$matches) ?
$matches[1] : '';
@@ -615,7 +627,7 @@
// Remove spans with no attributes, linebreaks inside them cause problems
’/(.*?)</span>/’ => ‘$1’
);
-
$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content, -1, $count);
-
$content = preg_replace(array_keys($replace_tags),array_values($replace_tags),$content);
/*
In the case where you have something like <span><span></w:t><w:br/><w:t></span></span> (invalid - mismatched tags),
@@ -646,7 +658,7 @@
$result = $element->loadXML($content);
if(!$result)
{
@@ -666,18 +678,19 @@
/**
* Merges a given document with contact data
*
-
-
@param string $_content
-
@param array $ids array with contact id(s)
-
@param string &$err error-message on error
-
@param string $mimetype mimetype of complete document, eg. text/*, application/vnd.oasis.opendocument.text, application/rtf
-
-
@param array $fix=null regular expression => replacement pairs eg. to fix garbled placeholders
-
-
@param string $charset=null charset to override default set by mimetype or export charset
-
-
@param array $fix =null regular expression => replacement pairs eg. to fix garbled placeholders
-
-
@param string $charset =null charset to override default set by mimetype or export charset
-
@return string|boolean merged document or false on error
*/
- public function &merge_string($content,$ids,&$err,$mimetype,array $fix=null,$charset=null)
- {
-
preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($content,0,200),$matches))
-
preg_match('/'.preg_quote('<?mso-application progid="').'([^"]+)'.preg_quote('"?>').'/',substr($_content,0,200),$matches))
{
$mso_application_progid = $matches[1];
}
@@ -687,7 +700,7 @@
}
// alternative syntax using double curly brackets (eg. {{cat_id}} instead $$cat_id$$),
// agressivly removing all xml-tags eg. Word adds within placeholders
-
$content = preg_replace_callback('/{{[^}]+}}/i',create_function('$p','return \'$$\'.strip_tags(substr($p[0],2,-2)).\'$$\';'),$content);
-
$content = preg_replace_callback('/{{[^}]+}}/i',create_function('$p','return \'$$\'.strip_tags(substr($p[0],2,-2)).\'$$\';'),$_content);
// Handle escaped placeholder markers in RTF, they won't match when escaped
if($mimetype == 'application/rtf')
@@ -803,22 +816,22 @@
return false;
}
}
-
if ($this->report_memory_usage) error_log(__METHOD__."() $n: $id ".Api\Vfs::hsize(memory_get_usage(true)));
// 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')))
{
$replacements += $this->contact_replacements($user,'user');
$replacements['$$user/primary_group$$'] = $GLOBALS['egw']->accounts->id2name($GLOBALS['egw']->accounts->id2name($GLOBALS['egw_info']['user']['account_id'],'account_primary_group'));
}
-
$replacements['$$date$$'] = egw_time::to('now',true);
-
$replacements['$$datetime$$'] = egw_time::to('now');
-
$replacements['$$time$$'] = egw_time::to('now',false);
-
$replacements['$$date$$'] = Api\DateTime::to('now',true);
-
$replacements['$$datetime$$'] = Api\DateTime::to('now');
-
$replacements['$$time$$'] = Api\DateTime::to('now',false);
// does our extending class registered table-plugins AND document contains table tags
if ($this->table_plugins && preg_match_all('/\\$\\$table\\/([A-Za-z0-9_]+)\\$\\$(.*?)\\$\\$endtable\\$\\$/s',$content,$matches,PREG_SET_ORDER))
@@ -841,9 +854,7 @@
$content = str_replace($match[0],$repeats,$content);
}
}
-
$content = $this->replace($content,$replacements,$mimetype,$mso_application_progid,$charset);
-
-
$content = $this->process_commands($content, $replacements);
-
$content = $this->process_commands($this->replace($content,$replacements,$mimetype,$mso_application_progid,$charset), $replacements);
// remove not existing replacements (eg. from calendar array)
if (strpos($content,'$$') !== null)
@@ -902,7 +913,7 @@
rewind($content_stream);
return stream_get_contents($content_stream);
}
-
-
@param string $mso_application_progid=’’ MS Office 2003: ‘Excel.Sheet’ or ‘Word.Document’
-
-
@param string $charset=null charset to override default set by mimetype or export charset
@@ -947,12 +959,12 @@
if (empty($charset)) $charset = $this->contacts->prefs[‘csv_charset’];
break;
}
-
//error_log(__METHOD__."('$document', ... ,$mimetype) --> $charset (egw=".translation::charset().', export='.$this->contacts->prefs['csv_charset'].')');
-
//error_log(__METHOD__."('$document', ... ,$mimetype) --> $charset (egw=".Api\Translation::charset().', export='.$this->contacts->prefs['csv_charset'].')');
// do we need to convert charset
-
if ($charset && $charset != translation::charset())
-
{
-
$replacements = translation::convert($replacements,translation::charset(),$charset);
-
if ($charset && $charset != Api\Translation::charset())
-
{
-
$replacements = Api\Translation::convert($replacements,Api\Translation::charset(),$charset);
}
// Date only placeholders for timestamps
@@ -960,10 +972,10 @@
{
foreach($this->date_fields as $field)
{
-
if($value = $replacements['$$'.$field.'$$'])
-
{
-
$time = egw_time::createFromFormat('+'.egw_time::$user_dateformat.' '.egw_time::$user_timeformat.'*', $value);
-
$replacements['$$'.$field.'/date$$'] = $time ? $time->format(egw_time::$user_dateformat) : '';
-
if(($value = $replacements['$$'.$field.'$$']))
-
{
-
$time = Api\DateTime::createFromFormat('+'.Api\DateTime::$user_dateformat.' '.Api\DateTime::$user_timeformat.'*', $value);
-
$replacements['$$'.$field.'/date$$'] = $time ? $time->format(Api\DateTime::$user_dateformat) : '';
}
}
}
@@ -1012,7 +1024,7 @@
continue;
}
// decode html entities back to utf-8
-
if (is_string($value) && (strpos($value,'&') !== false) && $this->parse_html_styles)
{
$value = html_entity_decode($value,ENT_QUOTES,$charset);
@@ -1047,8 +1059,9 @@
}
}
// replace
and
with CRLF (remove
and CRLF)
-
$value = str_replace(array("\r","\n",'<p>','</p>','<div>','</div>','<br />'),array('','','',"\r\n",'',"\r\n","\r\n"),$value);
-
$value = strip_tags($value,implode('',$replace_tags));
-
$value = strip_tags(str_replace(array("\r","\n",'<p>','</p>','<div>','</div>','<br />'),
-
array('','','',"\r\n",'',"\r\n","\r\n"), $value),
-
implode('', $replace_tags));
// Change <tag>...\r\n</tag> to <tag>...</tag>\r\n or simplistic line break below will mangle it
// Loop to catch things like <b><span>Break:\r\n</span></b>
@@ -1118,7 +1131,10 @@
}
// now decode &, < and >, which need to be encoded as entities in xml
// Check for encoded >< getting double-encoded
-
$replacements = str_replace(array('&',"\r","\n",'&lt;','&gt;'),array('&','',$break,'<','>'),$replacements);
-
if($this->parse_html_styles)
-
{
-
$replacements = str_replace(array('&',"\r","\n",'&lt;','&gt;'),array('&','',$break,'<','>'),$replacements);
-
}
}
if ($mimetype == 'application/x-yaml')
{
@@ -1230,11 +1246,11 @@
// Some different formats dates could be in, depending what they've been through
$formats = array(
-
'!'.egw_time::$user_dateformat . ' ' .egw_time::$user_timeformat.':s',
-
'!'.egw_time::$user_dateformat . '*' .egw_time::$user_timeformat.':s',
-
'!'.egw_time::$user_dateformat . '* ' .egw_time::$user_timeformat,
-
'!'.egw_time::$user_dateformat . '*',
-
'!'.egw_time::$user_dateformat,
-
'!'.Api\DateTime::$user_dateformat . ' ' .Api\DateTime::$user_timeformat.':s',
-
'!'.Api\DateTime::$user_dateformat . '*' .Api\DateTime::$user_timeformat.':s',
-
'!'.Api\DateTime::$user_dateformat . '* ' .Api\DateTime::$user_timeformat,
-
'!'.Api\DateTime::$user_dateformat . '*',
-
'!'.Api\DateTime::$user_dateformat,
);
// Properly format values for spreadsheet
@@ -1250,10 +1266,10 @@
foreach($formats as $f)
{
try {
@@ -1270,18 +1286,18 @@
}
else
{
@@ -1330,15 +1346,16 @@
{
$app = str_replace(’_merge’,’’,get_class($this));
}
-
$cfs = Api\Storage\Customfields::get($app);
// Cache, in case more than one sub-placeholder is used
$app_replacements = array();
// Custom field placeholders look like {{#name}}
// Placeholders that need expanded will look like {{#name/placeholder}}
-
$matches = null;
preg_match_all('/\${2}(([^\/#]*?\/)?)#([^$\/]+)\/(.*?)[$}]{2}/', $content, $matches);
-
list($placeholders, $prefixes, $pre, $cf, $sub) = $matches;
-
list($placeholders, , , $cf, $sub) = $matches;
foreach($cf as $index => $field)
{
@@ -1355,7 +1372,7 @@
$account = $GLOBALS[‘egw’]->accounts->read($values[’#’.$field]);
$app_replacements[$field] = $this->contact_replacements($account[‘person_id’]);
}
@@ -1436,7 +1453,7 @@
{
if (array_key_exists(’$$’.$param[4].’$$’,$this->replacements)) $param[4] = $this->replacements[’$$’.$param[4].’$$’];
if (array_key_exists(’$$’.$param[3].’$$’,$this->replacements)) $param[3] = $this->replacements[’$$’.$param[3].’$$’];
@@ -1497,7 +1514,7 @@
$replaceprefixsort = array();
// ToDo Stefan: $contentstart is NOT defined here!!!
$replaceprefix = explode(’ ',substr($param[0],21,-2));
@@ -1511,7 +1528,7 @@
*
* @param string $document vfs-path of document
* @param array $ids array with contact id(s)
-
-
@param string $name=’’ name to use for downloaded document
-
-
@param string $name =’’ name to use for downloaded document
-
@param string $dirs comma or whitespace separated directories, used if $document is a relative path
-
@return string with error-message on error, otherwise it does NOT return
*/
@@ -1522,18 +1539,18 @@
{
return $error;
}
-
$content_url = Api\Vfs::PREFIX.$document;
-
switch (($mimetype = Api\Vfs::mime_content_type($document)))
{
case 'message/rfc822':
//error_log(__METHOD__."('$document', ".array2string($ids).", '$name', dirs='$dirs')=>$content_url ->".function_backtrace());
-
$msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder='', $importID='');
-
}
-
catch (egw_exception_wrong_userinput $e)
-
$msgs = $mail_bo->importMessageToMergeAndSend($this, $content_url, $ids, $_folder='');
-
}
-
catch (Api\Exception\WrongUserinput $e)
{
// if this returns with an exeption, something failed big time
return $e->getMessage();
@@ -1548,7 +1565,6 @@
}
if (count($msgs[‘failed’])>0) $retString .= count($msgs[‘failed’]).’ ‘.lang(‘Message(s) send failed!’).’=>’.$errorString;
return $retString;
@@ -1591,6 +1607,7 @@
$content_url = ‘zip://’.$archive.’#’.($content_file = ‘xl/sharedStrings.xml’);
break;
}
-
$err = null;
if (!($merged =& $this->merge($content_url,$ids,$err,$mimetype,$fix)))
{
//error_log(__METHOD__."() !this->merge() err=$err");
@@ -1617,7 +1634,7 @@
return $err;
}
}
@@ -1634,13 +1651,13 @@
if (isset($archive))
{
$zip = new ZipArchive;
-
if ($zip->open($archive,ZIPARCHIVE::CHECKCONS) !== true)
-
{
-
error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE::CHECKCONS) failed. Trying open without validating");
-
if ($zip->open($archive) !== true) throw new Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
-
}
-
if ($zip->addFromString($content_file,$merged) !== true) throw new Exception("!ZipArchive::addFromString('$content_file',\$merged)");
-
if ($zip->close() !== true) throw new Exception("!ZipArchive::close()");
-
if ($zip->open($archive, ZipArchive::CHECKCONS) !== true)
-
{
-
error_log(__METHOD__.__LINE__." !ZipArchive::open('$archive',ZIPARCHIVE"."::CHECKCONS) failed. Trying open without validating");
-
if ($zip->open($archive) !== true) throw new Api\Exception("!ZipArchive::open('$archive',|ZIPARCHIVE::CHECKCONS)");
-
}
-
if ($zip->addFromString($content_file,$merged) !== true) throw new Api\Exception("!ZipArchive::addFromString('$content_file',\$merged)");
-
if ($zip->close() !== true) throw new Api\Exception("!ZipArchive::close()");
unset($zip);
unset($merged);
if (substr($mimetype,0,35) == 'application/vnd.oasis.opendocument.' && // only open office archives need that, ms word files brake
@@ -1648,8 +1665,8 @@
{
exec(’/usr/bin/zip -F '.escapeshellarg($archive));
}
-
if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".egw_vfs::hsize(memory_get_peak_usage(true)));
-
html::content_header($name,$mimetype,filesize($archive));
-
if ($this->report_memory_usage) error_log(__METHOD__."() after ZIP processing ".Api\Vfs::hsize(memory_get_peak_usage(true)));
-
Api\Header\Content::type($name,$mimetype,filesize($archive));
readfile($archive,'r');
}
else
@@ -1665,10 +1682,10 @@
$mimetype = ‘application/vnd.ms-excel’; // to open it automatically in excel or oocalc
}
}
-
exit;
}
/**
@@ -1712,7 +1729,10 @@
// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
if (count($dirs = preg_split(’/[,\s]+//’, $dirs)) > 1)
{
-
foreach($dirs as $n => &$d)
-
{
-
if ($n) $d = '/'.$d; // re-adding trailing slash removed by split
-
}
}
if ($mime_filter && ($negativ_filter = $mime_filter[0] === '!'))
{
@@ -1728,7 +1748,7 @@
$list = array();
foreach($dirs as $dir)
{
@@ -1736,7 +1756,7 @@
$parts = explode(’.’,$file[‘name’]);
if (!self::is_implemented($file[‘mime’],’.’.array_pop($parts))) continue;
if ($mime_filter && $negativ_filter === in_array($file[‘mime’], (array)$mime_filter)) continue;
@@ -1755,10 +1775,10 @@
*
* @param string $dirs Directory(s comma or space separated) to search
* @param int $group see nextmatch_widget::egw_actions
-
-
@param string $caption=‘Insert in document’
-
-
@param string $prefix=‘document_’
-
-
@param string $default_doc=’’ full path to default document to show on top with action == ‘document’!
-
-
@param int|string $export_limit=null export-limit, default $GLOBALS[‘egw_info’][‘server’][‘export_limit’]
-
-
@param string $caption =‘Insert in document’
-
-
@param string $prefix =‘document_’
-
-
@param string $default_doc =’’ full path to default document to show on top with action == ‘document’!
-
-
@param int|string $export_limit =null export-limit, default $GLOBALS[‘egw_info’][‘server’][‘export_limit’]
-
@return array see nextmatch_widget::egw_actions
*/
public static function document_action($dirs, $group=0, $caption=‘Insert in document’, $prefix=‘document_’, $default_doc=’’,
@@ -1766,16 +1786,16 @@
{
$documents = array();
if ($export_limit == null) $export_limit = self::getExportLimit(); // check if there is a globalsetting
-
'icon' => egw_vfs::mime_icon($file['mime']),
-
'caption' => egw_vfs::decodePath(egw_vfs::basename($default_doc)),
-
'icon' => Api\Vfs::mime_icon($file['mime']),
-
'caption' => Api\Vfs::decodePath(Api\Vfs::basename($default_doc)),
'group' => 1,
'postSubmit' => true, // download needs post submit (not Ajax) to work
);
@@ -1792,11 +1812,14 @@
// to still allow space or comma in dirnames, we also use the trailing slash of all pathes to split
if (count($dirs = preg_split(’/[,\s]+//’, $dirs)) > 1)
{
-
foreach($dirs as $n => &$d)
-
{
-
if ($n) $d = '/'.$d; // re-adding trailing slash removed by split
-
}
}
foreach($dirs as $dir)
{
-
$files += Api\Vfs::find($dir,array(
'need_mime' => true,
'order' => 'fs_name',
'sort' => 'ASC',
@@ -1810,14 +1833,14 @@
// use only the mime-types we support
$parts = explode(’.’,$file[‘name’]);
if (!self::is_implemented($file[‘mime’],’.’.array_pop($parts)) ||
@@ -1848,8 +1871,8 @@
{
case (count($name_arr)-1):
$current_level[$prefix.$file[‘name’]] = array(
-
'icon' => egw_vfs::mime_icon($file['mime']),
-
'caption' => egw_vfs::decodePath($name_arr[$count]),
-
'icon' => Api\Vfs::mime_icon($file['mime']),
-
'caption' => Api\Vfs::decodePath($name_arr[$count]),
'group' => 2,
'postSubmit' => true, // download needs post submit (not Ajax) to work
);
@@ -1865,7 +1888,7 @@
// create parent folder
$current_level[$prefix.$name_arr[$count]] = array(
‘icon’ => ‘phpgwapi/foldertree_folder’,
@@ -1879,14 +1902,14 @@
if (!isset($documents[$file[‘mime’]]))
{
$documents[$file[‘mime’]] = array(
-
'icon' => egw_vfs::mime_icon($file['mime']),
-
'caption' => mime_magic::mime2label($file['mime']),
-
'icon' => Api\Vfs::mime_icon($file['mime']),
-
'caption' => Api\MimeMagic::mime2label($file['mime']),
'group' => 2,
'children' => array(),
);
}
$documents[$file['mime']]['children'][$prefix.$file['name']] = array(
@@ -1897,8 +1920,8 @@
else
{
$documents[$prefix.$file[‘name’]] = array(
-
'icon' => egw_vfs::mime_icon($file['mime']),
-
'caption' => egw_vfs::decodePath($file['name']),
-
'icon' => Api\Vfs::mime_icon($file['mime']),
-
'caption' => Api\Vfs::decodePath($file['name']),
'group' => 2,
'postSubmit' => true, // download needs post submit (not Ajax) to work
);
@@ -1928,7 +1951,7 @@
* contact opens a compose window, multiple contacts just sends.
*
* @param Array &$action Action to be modified for mail
-
-
@param Array $file Array of information about the document from egw_vfs::find
-
-
@param Array $file Array of information about the document from Api\Vfs::find
-
@return void
*/
private static function document_mail_action(Array &$action, $file)
@@ -1951,8 +1974,8 @@
// long_task runs menuaction once for each selected row
$action[‘nm_action’] = ‘long_task’;
-
$action['popup'] = egw_link::get_registry('mail', 'edit_popup');
-
$action['message'] = lang('insert in %1',egw_vfs::decodePath($file['name']));
-
$action['popup'] = Api\Link::get_registry('mail', 'edit_popup');
-
$action['message'] = lang('insert in %1',Api\Vfs::decodePath($file['name']));
$action['menuaction'] = 'mail.mail_compose.ajax_merge&document='.$file['path'].'&merge='. get_called_class();
}
@@ -1974,7 +1997,7 @@
foreach($dirs as $n => $dir)
{
if ($n) $dir = ‘/’.$dir; // re-adding trailing slash removed by split
@@ -1982,7 +2005,7 @@
}
}
}
@@ -2004,8 +2027,8 @@
* Reimplemented from etemplate to NOT use user prefs for Excel 2003, which gives an xml error
*
* @param int|float|string $number
-
-
@param int $num_decimal_places=2
-
-
@param string $_mimetype=’’
-
-
@param int $num_decimal_places =2
-
-
@param string $_mimetype =’’
-
@return string
*/
static public function number_format($number,$num_decimal_places=2,$_mimetype=’’)
@@ -2018,6 +2041,6 @@
case ‘application/vnd.oasis.opendocument.spreadsheet’: // OO.o spreadsheet
return number_format(str_replace(’ ‘,’’,$number),$num_decimal_places,’.’,’’);
}
— trunk/etemplate/inc/class.bo_merge.inc.php (original)
+++ trunk/etemplate/inc/class.bo_merge.inc.php Tue Apr 5 20:43:46 2016
@@ -4,2023 +4,18 @@
*
+use EGroupware\Api\Storage\Merge;
+
/**
-
-
@todo move apply_styles call into merge_string to run for each entry merged and not all together to lower memory requirements
-
-
@deprecated use Api\Storage\Merge
*/
-abstract class bo_merge
-{
- /**
-
- Instance of the addressbook_bo class
-
-
- */
- var $contacts;
-
- /**
-
- Datetime format according to user preferences
-
-
- */
- var $datetime_format = ‘Y-m-d H:i’;
-
- /**
-
- Fields that are to be treated as datetimes, when merged into spreadsheets
- */
- var $date_fields = array();
-
- /**
-
- Mimetype of document processed by merge
-
-
- */
- var $mimetype;
-
- /**
-
- Plugins registered by extending class to create a table with multiple rows
-
-
- $$table/$plugin$$ … $$endtable$$
-
-
- Callback returns replacements for row $n (stringing with 0) or null if no further rows
-
-
-
@var array $plugin => array callback($plugin,$id,$n)
- */
- var $table_plugins = array();
-
- /**
-
- Export limit in number of entries or some non-numerical value, if no export allowed at all, empty means no limit
-
-
- Set by constructor to $GLOBALS[egw_info][server][export_limit]
-
-
- */
- public $export_limit;
-
-
- /**
-
- Configuration for HTML Tidy to clean up any HTML content that is kept
- */
- public static $tidy_config = array(
-
'output-xml' => true, // Entity encoding
-
'show-body-only' => true,
-
'output-encoding' => 'utf-8',
-
'input-encoding' => 'utf-8',
-
'quote-ampersand' => false, // Prevent double encoding
-
'quote-nbsp' => true, // XSLT can handle spaces easier
-
'preserve-entities' => true,
-
'wrap' => 0, // Wrapping can break output
- );
-
- /**
-
- 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;
-
- /**
-
- Enable this to report memory_usage to error_log
-
-
- */
- public $report_memory_usage = false;
-
- /**
-
-
-
- */
- function __construct()
- {
-
// Common messages are in preferences
-
translation::add_app('preferences');
-
// All contact fields are in addressbook
-
translation::add_app('addressbook');
-
-
$this->contacts = new addressbook_bo();
-
-
$this->datetime_format = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'].' '.
-
($GLOBALS['egw_info']['user']['preferences']['common']['timeformat']==12 ? 'h:i a' : 'H:i');
-
-
$this->export_limit = self::getExportLimit();
- }
-
- /**
-
- Hook returning options for export_limit_excepted groups
-
-
- */