home *** CD-ROM | disk | FTP | other *** search
- <?php
- /*
- Copyright Intermesh 2003
- Author: Merijn Schering <mschering@intermesh.nl>
- Version: 1.0 Release date: 08 July 2003
-
- This program is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by the
- Free Software Foundation; either version 2 of the License, or (at your
- option) any later version.
- */
-
- /////////////////////////////////////////////////////////////////////////////////
- ///////////////////// Group-Office common functions //////////////////
- /////////////////////////////////////////////////////////////////////////////////
-
- function date_to_unixtime($date_string)
- {
- $date_string = str_replace('/', '-', $date_string);
-
- $datetime_array = explode(' ', $date_string);
-
- $date = isset($datetime_array[0]) ? $datetime_array[0] : '00-00-0000';
-
- $date_array = explode('-',$datetime_array[0]);
- $year = isset($date_array[2]) ? $date_array[2] : 0;
-
- if ($_SESSION['GO_SESSION']['date_format'] == "m-d-Y")
- {
- $month = isset($date_array[0]) ? $date_array[0] : 0;
- $day = isset($date_array[1]) ? $date_array[1] : 0;
- }else
- {
- $month = isset($date_array[1]) ? $date_array[1] : 0;
- $day = isset($date_array[0]) ? $date_array[0] : 0;
- }
-
- $time = isset($datetime_array[1]) ? $datetime_array[1] : '00:00:00';
- $time_array = explode(':', $time);
-
- $hour = isset($time_array[0]) ? $time_array[0] : 0;
- $min = isset($time_array[1]) ? $time_array[1] : 0;
- $sec = isset($time_array[2]) ? $time_array[2] : 0;
-
-
- return mktime($hour,$min,$sec,$month, $day, $year);
- }
-
- function date_to_db_date($date_string, $with_time=false)
- {
- $date_string = str_replace('/', '-', $date_string);
-
- $datetime_array = explode(' ', $date_string);
-
- $date = isset($datetime_array[0]) ? $datetime_array[0] : '00-00-0000';
-
- $date_array = explode('-',$datetime_array[0]);
- $year = isset($date_array[2]) ? $date_array[2] : 0;
-
- if ($_SESSION['GO_SESSION']['date_format'] == "m-d-Y")
- {
- $month = isset($date_array[0]) ? $date_array[0] : 0;
- $day = isset($date_array[1]) ? $date_array[1] : 0;
- }else
- {
- $month = isset($date_array[1]) ? $date_array[1] : 0;
- $day = isset($date_array[0]) ? $date_array[0] : 0;
- }
-
- $time = isset($datetime_array[1]) ? $datetime_array[1] : '00:00:00';
- $time_array = explode(':', $time);
-
- $hour = isset($time_array[0]) ? $time_array[0] : 0;
- $min = isset($time_array[1]) ? $time_array[1] : 0;
- $sec = isset($time_array[2]) ? $time_array[2] : 0;
-
- $date_format = $with_time ? 'Y-m-d H:i' : 'Y-m-d';
-
- $db_date = "$year-$month-$day";
- if ($with_time)
- {
- $db_date .= ' '.date($_SESSION['GO_SESSION']['timeformat'], mktime($hour, $min, $sec));
- }
-
- return $db_date;
- }
-
- function db_date_to_date($date_string, $with_time=false)
- {
- $datetime_array = explode(' ', $date_string);
-
- $date = isset($datetime_array[0]) ? $datetime_array[0] : '00-00-0000';
-
- $date_array = explode('-',$datetime_array[0]);
-
- $year = isset($date_array[0]) ? $date_array[0] : 0;
- $month = isset($date_array[1]) ? $date_array[1] : 0;
- $day = isset($date_array[2]) ? $date_array[2] : 0;
-
- $time = isset($datetime_array[1]) ? $datetime_array[1] : '00:00:00';
- $time_array = explode(':', $time);
-
- $hour = isset($time_array[0]) ? $time_array[0] : 0;
- $min = isset($time_array[1]) ? $time_array[1] : 0;
- $sec = isset($time_array[2]) ? $time_array[2] : 0;
-
- if ($_SESSION['GO_SESSION']['date_format'] == "m-d-Y")
- {
- $date = "$month-$day-$year";
- }else
- {
- $date = "$day-$month-$year";
- }
-
- if ($with_time)
- {
- $date .= ' '.date($_SESSION['GO_SESSION']['timeformat'], mktime($hour, $min, $sec));
- }
-
- return $date;
-
- }
-
- function db_date_to_unixtime($date_string)
- {
- $datetime_array = explode(' ', $date_string);
-
- $date = isset($datetime_array[0]) ? $datetime_array[0] : '00-00-0000';
-
- $date_array = explode('-',$datetime_array[0]);
-
- $year = isset($date_array[0]) ? $date_array[0] : 0;
- $month = isset($date_array[1]) ? $date_array[1] : 0;
- $day = isset($date_array[2]) ? $date_array[2] : 0;
-
- $time = isset($datetime_array[1]) ? $datetime_array[1] : '00:00:00';
- $time_array = explode(':', $time);
-
- $hour = isset($time_array[0]) ? $time_array[0] : 0;
- $min = isset($time_array[1]) ? $time_array[1] : 0;
- $sec = isset($time_array[2]) ? $time_array[2] : 0;
-
- return mktime($hour,$min,$sec,$month, $day, $year);
- }
-
- function get_html_body($html)
- {
- $to_removed_array = array (
- "'<html[^>]*>'si",
- "'</html>'si",
- "'<body[^>]*>'si",
- "'</body>'si",
- "'<head[^>]*>.*?</head>'si",
- "'<style[^>]*>.*?</style>'si",
- "'<object[^>]*>.*?</object>'si",
- );
- $html = preg_replace($to_removed_array, '', $html);
- return $html;
-
- }
- function get_time($server_time=0)
- {
- if ($server_time == '0')
- {
- $server_time = time();
- }
-
- $server_timezone_offset = date('Z');
- $time = $server_time+(($_SESSION['GO_SESSION']['timezone']*3600)-$server_timezone_offset);
- return $time;
- }
-
-
- function get_gmt_time()
- {
- $server_timezone_offset = date('Z');
- $time = time()-$server_timezone_offset;
- return $time;
- }
-
- function split_name($full_name)
- {
- $name_arr = explode(' ', $full_name);
-
- $name['first'] = $full_name;
- $name['middle'] = '';
- $name['last'] = $full_name;
- $count = count($name_arr);
- $last_index = $count-1;
- for($i=0;$i<$count;$i++)
- {
- switch ($i)
- {
- case 0:
- $name['first'] = $name_arr[$i];
- break;
-
- case $last_index:
- $name['last'] = $name_arr[$i];
- break;
-
- default:
- $name['middle'] .= $name_arr[$i].' ';
- break;
- }
- }
- $name['middle'] = trim($name['middle']);
- return $name;
- }
-
- function print_acl($acl_id)
- {
- global $GO_CONFIG;
- echo '<iframe width="350"; height="320" border="0" frameborder="0" scrolling="no" src="'.$GO_CONFIG->control_url.'acl.php?acl_id='.$acl_id.'"></iframe>';
- }
- function getmicrotime(){
- list($usec, $sec) = explode(" ",microtime());
- return ((float)$usec + (float)$sec);
- }
-
- function detect_browser()
- {
- if(eregi('msie ([0-9].[0-9]{1,2})',$_SERVER['HTTP_USER_AGENT'],$log_version))
- {
- $browser['version']=$log_version[1];
- $browser['name']='MSIE';
- }elseif(eregi('opera/([0-9].[0-9]{1,2})',$_SERVER['HTTP_USER_AGENT'],$log_version))
- {
- $browser['version']=$log_version[1];
- $browser['name']='OPERA';
- }elseif(eregi('mozilla/([0-9].[0-9]{1,2})',$_SERVER['HTTP_USER_AGENT'],$log_version))
- {
- $browser['version']=$log_version[1];
- $browser['name']='MOZILLA';
- }elseif(eregi('netscape/([0-9].[0-9]{1,2})',$_SERVER['HTTP_USER_AGENT'],$log_version))
- {
- $browser['version']=$log_version[1];
- $browser['name']='NETSCAPE';
- }else
- {
- $browser['version']=0;
- $browser['name']='OTHER';
- }
- return $browser;
- }
-
- function validate_email($email)
- {
- return eregi("^([a-z0-9]+)([._-]([a-z0-9]+))*[@]([a-z0-9]+)([._-]([a-z0-9]+))*[.]([a-z0-9]){2}([a-z0-9])?([a-z0-9])?$",$email);
- }
-
- //checks for empty string and returns stripe when empty
- function empty_to_stripe($input)
- {
- if ($input == "")
- {
- return "-";
- }else
- {
- return $input;
- }
- }
-
- //creates a mail to link based on the users settings to use
- //his own mail client or the Group-Office mail client
- function mail_to($email, $name="", $class="normal", $full_link=true, $contact_id=0)
- {
- if (validate_email($email))
- {
- global $GO_CONFIG, $GO_SECURITY, $GO_MODULES, $strEmailTo;
-
- $module = $GO_MODULES->get_module('email');
-
- if ($name == "")
- $name = $email;
-
- if ($_SESSION['GO_SESSION']['mail_client'] == 1 && $module = $GO_MODULES->get_module('email'))
- {
- if ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_write']))
- {
- if ($full_link == true)
- {
- return "<a class=\"".$class."\" title=\"".$strEmailTo.$email."\" href='javascript:popup(\"".$GO_CONFIG->host.$module['path']."send.php?mail_to=".$email."&contact_id=".$contact_id."\",\"".$GO_CONFIG->composer_width."\",\"".$GO_CONFIG->composer_height."\")'>".$name."</a>";
- }else
- {
- return 'javascript:popup("'.$GO_CONFIG->host.$module['path'].'send.php?mail_to='.$email.'&contact_id='.$contact_id.'","'.$GO_CONFIG->composer_width.'","'.$GO_CONFIG->composer_height.'")';
- }
- }
- }
-
- if ($full_link == true)
- {
- return "<a class=\"".$class."\" href=\"mailto:".$email."\" title=\"".$strEmailTo.$email."\">".$name."</a>";
- }else
- {
- return 'mailto:'.$email;
- }
- }
- }
-
- //Creates a link that pops up a users profile
- function show_profile($user_id, $linktext='', $class='normal', $return_to='')
- {
- global $strShowProfile, $strProtectedUser, $GO_CONFIG;
-
- if ($return_to == '')
- {
- $return_to = $_SERVER['REQUEST_URI'];
- }
-
- $GO_SECURITY = new GO_SECURITY();
- $GO_MODULES = new GO_MODULES();
-
- require_once($GO_CONFIG->class_path."addressbook.class.inc");
- $ab = new addressbook();
-
- if ($linktext == '')
- {
- require_once($GO_CONFIG->class_path."users.class.inc");
- $users = new users();
- $profile = $users->get_user($user_id);
- $middle_name = $profile['middle_name'] == '' ? '' : $profile['middle_name'].' ';
- $linktext = $profile['first_name'].' '.$middle_name.$profile['last_name'];
- }
- $module = $GO_MODULES->get_module('addressbook');
- if ($module && ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_write'])) && $contact = $ab->user_is_contact($GO_SECURITY->user_id, $user_id))
- {
- if($contact['color'] != '')
- {
- $style = ' style="color: #'.$contact['color'].';"';
- }else
- {
- $style = '';
- }
- //$link = "<a ".$style." href='javascript:popup(\"".$GO_CONFIG->host.$module['path']."show_contact.php?contact_id=".$contact['id']."\",\"750\",\"550\")' class=\"".$class."\" title=\"".$strShowProfile."\">";
- $link = "<a ".$style." href=\"".$GO_CONFIG->host.$module['path']."contact.php?contact_id=".$contact['id']."&return_to=".urlencode($return_to)."\" class=\"".$class."\" title=\"".$strShowProfile."\">";
- $link .= $linktext."</a>\n";
-
- }else
- {
- if ($GO_SECURITY->user_is_visible($user_id))
- {
- //$link = "<a href='javascript:popup(\"".$GO_CONFIG->control_url."user.php?id=".$user_id."&return_to=".$return_to."\",\"750\",\"550\")' class=\"".$class."\" title=\"".$strShowProfile."\">";
- $link = '<a href="'.$GO_CONFIG->control_url.'user.php?id='.$user_id.'&return_to='.urlencode($return_to).'" class="'.$class.'" title="'.$strShowProfile.'">';
- $link .= $linktext."</a>\n";
- }else
- {
- $link = $linktext;
- }
-
- }
- return $link;
- }
-
- function show_contact($contact_id, $linktext='', $return_to='')
- {
- global $strShowProfile, $strProtectedUser, $GO_CONFIG, $GO_SECURITY, $GO_MODULES;
-
- if ($return_to == '')
- {
- $return_to = $_SERVER['REQUEST_URI'];
- }
-
- $module = $GO_MODULES->get_module('addressbook');
- if ($module && ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_write'])))
- {
- require_once($GO_CONFIG->class_path."addressbook.class.inc");
- $ab = new addressbook();
-
- $contact = $ab->get_contact($contact_id);
-
- if($ab->f('color') != '')
- {
- $style = ' style="color: #'.$ab->f('color').';"';
- }else
- {
- $style = '';
- }
-
- if ($linktext == '')
- {
- $middle_name = $contact['middle_name'] == '' ? '' : $contact['middle_name'].' ';
- $linktext = $contact['first_name'].' '.$middle_name.$contact['last_name'];
- }
- $contact_id=$contact['id'];
-
- $link = "<a ".$style." href=\"".$GO_CONFIG->host.$module['path']."contact.php?contact_id=".$contact_id."&return_to=".urlencode($return_to)."\" class=\"normal\" title=\"".$strShowProfile."\">";
- //$link = "<a".$style." href='javascript:popup(\"".$GO_CONFIG->host.$module['path']."show_contact.php?contact_id=".$contact_id."\",\"750\",\"550\")' class=\"normal\" title=\"".$strShowProfile."\">";
- $link .= $linktext."</a>\n";
- }else
- {
- $link = '';
- }
- return $link;
- }
-
-
- function show_profile_by_email($email, $linktext = '', $return_to='')
- {
- if ($return_to == '')
- {
- $return_to = $_SERVER['REQUEST_URI'];
- }
- if ($linktext == '') $linktext = $email;
-
- global $GO_CONFIG, $GO_SECURITY, $strShowProfile, $strAddContact, $GO_MODULES;
-
- require_once($GO_CONFIG->class_path."users.class.inc");
- require_once($GO_CONFIG->class_path."addressbook.class.inc");
- $ab = new addressbook();
- $users = new users();
- $module = $GO_MODULES->get_module('addressbook');
-
- $has_contacts_module = ($module && ($GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_read']) || $GO_SECURITY->has_permission($GO_SECURITY->user_id, $module['acl_write'])));
-
- if ($has_contacts_module && $contact = $ab->get_contact_profile_by_email($email, $GO_SECURITY->user_id))
- {
- if($contact['color'] != '')
- {
- $style = ' style="color: #'.$contact['color'].';"';
- }else
- {
- $style = '';
- }
- //$link = "<a".$style." href='javascript:popup(\"".$GO_CONFIG->host.$module['path']."show_contact.php?contact_id=".$contact['id']."\",\"750\",\"550\")' class=\"normal\" title=\"".$strShowProfile."\">";
- $link = "<a ".$style." href=\"".$GO_CONFIG->host.$module['path']."contact.php?contact_id=".$contact['id']."&return_to=".urlencode($return_to)."\" class=\"normal\" title=\"".$strShowProfile."\">";
- $link .= $linktext."</a>\n";
- }else
- {
- $users_id = $users->get_user_id_by_email($email);
- if ($users_id && $GO_SECURITY->user_is_visible($users_id))
- {
- $link = "<a href='javascript:popup(\"".$GO_CONFIG->control_url."user.php?id=".$users_id."\",\"750\",\"500\")' class=\"normal\" title=\"".$strShowProfile."\">";
- $link .= $linktext."</a>\n";
- }elseif($has_contacts_module)
- {
- $name = split_name($linktext);
- //$link = "<a href=\"javascript:popup('".$GO_CONFIG->host.$module['path']."add_contact.php?email=".$email."&name=".urlencode($linktext)."','750','550')\" class=\"normal\" title=\"".$strAddContact."\">".$linktext."</a>";
- $link = "<a href=\"".$GO_CONFIG->host.$module['path']."contact.php?email=".$email."&first_name=".urlencode($name['first'])."&middle_name=".urlencode($name['middle'])."&last_name=".urlencode($name['last'])."&return_to=".urlencode($return_to)."\" class=\"normal\" title=\"".$strShowProfile."\">";
- $link .= $linktext."</a>\n";
- }else
- {
- $link = $linktext;
- }
- }
-
- return $link;
- }
-
- //checks input for invalid characters
- function validate_input($input, $invalid_chars = "")
- {
- if ($invalid_chars == "")
- {
- $invalid_chars[] = "\"";
- $invalid_chars[] = "/";
- $invalid_chars[] = "?";
- $invalid_chars[] = "&";
- }
-
- for ($i=0; $i<count($invalid_chars);$i++)
- {
- if (strchr($input,$invalid_chars[$i]))
- {
- return false;
- }
- }
- return true;
- }
-
- //checks the size and formats it to KB, MB or bytes depending on the size given in bytes.
- //Also uses user settings to format the number.
- function format_size($size, $decimals = 1)
- {
- switch ($size)
- {
- case ($size > 1073741824):
- $size = number_format($size / 1073741824, $decimals, $_SESSION['GO_SESSION']['decimal_seperator'], $_SESSION['GO_SESSION']['thousands_seperator']);
- $size .= " GB";
- break;
-
- case ($size > 1048576):
- $size = number_format($size / 1048576, $decimals, $_SESSION['GO_SESSION']['decimal_seperator'], $_SESSION['GO_SESSION']['thousands_seperator']);
- $size .= " MB";
- break;
-
- case ($size > 1024):
- $size = number_format($size / 1024, $decimals, $_SESSION['GO_SESSION']['decimal_seperator'], $_SESSION['GO_SESSION']['thousands_seperator']);
- $size .= " KB";
- break;
-
- default:
- number_format($size, $decimals, $_SESSION['GO_SESSION']['decimal_seperator'], $_SESSION['GO_SESSION']['thousands_seperator']);
- $size .= " bytes";
- break;
- }
- return $size;
- }
-
- /*
- function cut_string($string, $maxlength)
- {
- if (strlen($string) > $maxlength)
- {
- return substr($string,0,$maxlength-3)."...";
- }else
- {
- return $string;
- }
- }
- */
- //chops of the string after a given length and puts three dots behind it
- //function editted by Tyler Gee to make it chop at whole words
- function cut_string($string, $maxlength)
- {
- if (strlen($string) > $maxlength)
- {
- $temp = substr($string,0,$maxlength-3);
- if ($pos = strrpos($temp, ' '))
- {
- return substr($temp,0,$pos).'...';
- }else
- {
- return $temp = substr($string,0,$maxlength-3).'...';
- }
-
- }else
- {
- return $string;
- }
- }
-
- function enriched_to_html($enriched)
- {
- global $GO_CONFIG, $GO_MODULES;
-
- // We add space at the beginning and end of the string as it will
- // make some regular expression checks later much easier (so we
- // don't have to worry about start/end of line characters)
- $enriched = ' ' . $enriched . ' ';
-
- // Get color parameters into a more useable format.
- $enriched = preg_replace('/<color><param>([\da-fA-F]+),([\da-fA-F]+),([\da-fA-F]+)<\/param>/Uis', '<color r=\1 g=\2 b=\3>', $enriched);
- $enriched = preg_replace('/<color><param>(red|blue|green|yellow|cyan|magenta|black|white)<\/param>/Uis', '<color n=\1>', $enriched);
-
- // Get font family parameters into a more useable format.
- $enriched = preg_replace('/<fontfamily><param>(\w+)<\/param>/Uis', '<fontfamily f=\1>', $enriched);
-
- // Single line breaks become spaces, double line breaks are a
- // real break. This needs to do <nofill> tracking to be
- // compliant but we don't want to deal with state at this
- // time, so we fake it some day we should rewrite this to
- // handle <nofill> correctly.
- $enriched = preg_replace('/([^\n])\r\n([^\r])/', '\1 \2', $enriched);
- $enriched = preg_replace('/(\r\n)\r\n/', '\1', $enriched);
-
- // We try to protect against bad stuff here.
- $enriched = @htmlspecialchars($enriched, ENT_QUOTES, $charset);
-
- // Now convert the known tags to html. Try to remove any tag
- // parameters to stop people from trying to pull a fast one
- $enriched = preg_replace('/(?<!<)<bold.*>(.*)<\/bold>/Uis', '<span style="font-weight: bold">\1</span>', $enriched);
- $enriched = preg_replace('/(?<!<)<italic.*>(.*)<\/italic>/Uis', '<span style="font-style: italic">\1</span>', $enriched);
- $enriched = preg_replace('/(?<!<)<underline.*>(.*)<\/underline>/Uis', '<span style="text-decoration: underline">\1</span>', $enriched);
- $enriched = preg_replace_callback('/(?<!<)<color r=([\da-fA-F]+) g=([\da-fA-F]+) b=([\da-fA-F]+)>(.*)<\/color>/Uis', 'colorize', $enriched);
- $enriched = preg_replace('/(?<!<)<color n=(red|blue|green|yellow|cyan|magenta|black|white)>(.*)<\/color>/Uis', '<span style="color: \1">\2</span>', $enriched);
- $enriched = preg_replace('/(?<!<)<fontfamily>(.*)<\/fontfamily>/Uis', '\1', $enriched);
- $enriched = preg_replace('/(?<!<)<fontfamily f=(\w+)>(.*)<\/fontfamily>/Uis', '<span style="font-family: \1">\2</span>', $enriched);
- $enriched = preg_replace('/(?<!<)<smaller.*>/Uis', '<span style="font-size: smaller">', $enriched);
- $enriched = preg_replace('/(?<!<)<\/smaller>/Uis', '</span>', $enriched);
- $enriched = preg_replace('/(?<!<)<bigger.*>/Uis', '<span style="font-size: larger">', $enriched);
- $enriched = preg_replace('/(?<!<)<\/bigger>/Uis', '</span>', $enriched);
- $enriched = preg_replace('/(?<!<)<fixed.*>(.*)<\/fixed>/Uis', '<font face="fixed">\1</font>', $enriched);
- $enriched = preg_replace('/(?<!<)<center.*>(.*)<\/center>/Uis', '<div align="center">\1</div>', $enriched);
- $enriched = preg_replace('/(?<!<)<flushleft.*>(.*)<\/flushleft>/Uis', '<div align="left">\1</div>', $enriched);
- $enriched = preg_replace('/(?<!<)<flushright.*>(.*)<\/flushright>/Uis', '<div align="right">\1</div>', $enriched);
- $enriched = preg_replace('/(?<!<)<flushboth.*>(.*)<\/flushboth>/Uis', '<div align="justify">\1</div>', $enriched);
- $enriched = preg_replace('/(?<!<)<paraindent.*>(.*)<\/paraindent>/Uis', '<blockquote>\1</blockquote>', $enriched);
- $enriched = preg_replace('/(?<!<)<excerpt.*>(.*)<\/excerpt>/Uis', '<blockquote>\1</blockquote>', $enriched);
-
- // Now we remove the leading/trailing space we added at the
- // start.
- $enriched = preg_replace('/^ (.*) $/s', '\1', $enriched);
-
- $module = $GO_MODULES->get_module('email');
-
- $enriched = preg_replace("/(?:^|\b)(((http(s?):\/\/)|(www\.-))([\w\.-]+)([,:;%#&\/?=\w+\.\-@]+))(?:\b|$)/is", "<a href=\"http$4://$5$6$7\" target=\"_blank\" class=\"blue\">$1</a>", $enriched);
- if ($_SESSION['GO_SESSION']['mail_client'] == 1)
- {
- $enriched = preg_replace("/(\A|\s)([\w\.\-]+)(@)([\w\.-]+)([A-Za-z]{2,3})\b/i","\\1<a href=\"javascript:popup('".$GO_CONFIG->host.$module['path']."send.php?mail_to=\\2\\3\\4\\5','650','500')\" class=\"blue\">\\2\\3\\4\\5</a>",$enriched);
- }else
- {
- $enriched = preg_replace("/(\A|\s)([\w\.\-]+)(@)([\w\.-]+)([A-Za-z]{2,3})\b/i","\\1<a href=\"mailto:\\2\\3\\4\\5\" class=\"blue\">\\2\\3\\4\\5</a>",$enriched);
- }
-
- $enriched = nl2br($enriched);
- $enriched = str_replace("\r", "", $enriched);
- $enriched = str_replace("\n", "", $enriched);
-
- return $enriched;
-
- }
-
- function colorize($colors)
- {
- for ($i = 1; $i < 4; $i++) {
- $colors[$i] = sprintf('%02X', round(hexdec($colors[$i]) / 255));
- }
- return '<span style="color: #' . $colors[1] . $colors[2] . $colors[3] . '">' . $colors[4] . '</span>';
- }
-
-
- //turns plain text into html with url's and email adresses parsed into links
- function text_to_html($text, $wordwrap="120")
- {
- global $GO_CONFIG, $GO_MODULES;
-
- $module = $GO_MODULES->get_module('email');
-
- $text = htmlspecialchars($text);
- $text = preg_replace("/(?:^|\b)(((http(s?):\/\/)|(www\.-))([\w\.-]+)([,:;%#&\/?=\w+\.\-@]+))(?:\b|$)/is", "<a href=\"http$4://$5$6$7\" target=\"_blank\" class=\"blue\">$1</a>", $text);
- if ($_SESSION['GO_SESSION']['mail_client'] == 1)
- {
- $text = preg_replace("/(\A|\s)([\w\.\-]+)(@)([\w\.-]+)([A-Za-z]{2,3})\b/i","\\1<a href=\"javascript:popup('".$GO_CONFIG->host.$module['path']."send.php?mail_to=\\2\\3\\4\\5','650','500')\" class=\"blue\">\\2\\3\\4\\5</a>",$text);
- }else
- {
- $text = preg_replace("/(\A|\s)([\w\.\-]+)(@)([\w\.-]+)([A-Za-z]{2,3})\b/i","\\1<a href=\"mailto:\\2\\3\\4\\5\" class=\"blue\">\\2\\3\\4\\5</a>",$text);
- }
-
- $text = nl2br($text);
- $text = str_replace("\r", "", $text);
- $text = str_replace("\n", "", $text);
-
- return ($text);
-
- }
-
- //strips unwanted html tags and converts links to suit Group-Office
- function convert_html($html, $remove = true)
- {
- global $GO_CONFIG, $GO_MODULES;
-
- //$html = str_replace("\r", "", $html);
- //$html = str_replace("\n", "", $html);
-
- $module = $GO_MODULES->get_module('email');
-
- if ($remove)
- {
- $to_removed_array = array (
- "'<html>'si",
- "'</html>'si",
- "'<body[^>]*>'si",
- "'</body>'si",
- "'<head[^>]*>.*?</head>'si",
- "'<style[^>]*>.*?</style>'si",
- "'<script[^>]*>.*?</script>'si",
- "'<object[^>]*>.*?</object>'si",
- "'<embed[^>]*>.*?</embed>'si",
- "'<applet[^>]*>.*?</applet>'si",
- "'<mocha[^>]*>.*?</mocha>'si"
- );
- $html= preg_replace($to_removed_array, '', $html);
- //$html = preg_replace("|href=\"(.*)script:|i", 'href="removed_script:', $html);
- //$html = preg_replace("|<([^>]*)java|i", '<removed_java_tag', $html);
- //$html = preg_replace("|<([^>]*)&{.*}([^>]*)>|i", "<&{;}\\3>", $html);
- //$html = preg_replace("|<([^>]*)mocha:([^>]*)>|i", "<removed_mocha:\\2>",$html);
- }
-
- if ($_SESSION['GO_SESSION']['mail_client'] == 1)
- {
- $html = preg_replace("/(href=\"mailto:)([\w\.\-]+)(@)([\w\.\-\"]+)\b/i","href=\"javascript:popup('".$GO_CONFIG->host.$module['path']."send.php?mail_to=$2$3$4','650','500')\" class=\"blue\"",$html);
- }
-
- $html = preg_replace("/\b((href=\"http(s?):\/\/))([\w\.\?\=\&]+)([\/\w+\.\?\=\&\:\~]+)\b/i"," target=\"_blank\" class=\"blue\" href=\"http$3://$4$5$6", $html);
- $html = preg_replace("/\b((href='http(s?):\/\/))([\w\.\?\=\&]+)([\/\w+\.\?\=\&\:\~]+)\b/i"," target=\"_blank\" class=\"blue\" href='http$3://$4$5$6", $html);
-
- return ($html);
- }
-
-
- function cut_address($addr, $charset)
- {
- $addr = smartstrip($addr);
-
- $addresses = array();
- $token = '';
- $quote_esc = false;
- for ($i = 0; $i < strlen($addr); $i++) {
- $c = substr($addr, $i, 1);
-
- if($c == '"') {
- $quote_esc = !$quote_esc;
- }
-
- if($c == ',' || $c == ';') {
- if(!$quote_esc) {
- $token = trim($token);
- if($token != '') {
- $addresses[] = $token;
- }
- $token = '';
- continue;
- }
- }
-
- $token .= $c;
- }
- if(!$quote_esc) {
- $token = trim($token);
- if($token != '') {
- $addresses[] = $token;
- }
- }
- return ($addresses);
- }
-
- function get_addresses_from_string($address_string)
- {
- $in_address = false;
- $address = '';
- $addresses = array();
- $length = strlen($address_string);
- for($i=0;$i<$length;$i++)
- {
- $char = $address_string[$i];
- if ($char == '>')
- {
- if ($in_address)
- {
- $in_address = false;
- $addresses[] = trim($address);
- $address = '';
- }
- }elseif($char == '<')
- {
- $in_address=true;
- }elseif($in_address)
- {
- $address .= $char;
- }
- }
- return $addresses;
- }
-
- function get_crlf($smtp = "")
- {
- $crlf = stristr(PHP_OS, 'Windows') ? "\r\n" : "\n";
-
- if ($smtp != "")
- $crlf = $smtp ? "\r\n" : $crlf;
-
- //return ($crlf);
- return "\r\n";
- }
-
-
- function smartstrip($string)
- {
- if(get_magic_quotes_gpc()) {
- $string = stripslashes($string);
- }
- return $string;
- }
-
- function smart_addslashes($string)
- {
- if(!get_magic_quotes_gpc()) {
- $string = addslashes($string);
- }
- return $string;
- }
-
-
- function quote($text)
- {
- $text = "> " . ereg_replace("\n", "\n> ", trim($text));
- return($text);
- }
-
- function sendmail($email_to, $email_from, $name_from, $subject, $body, $priority = '3', $body_ctype = 'text/PLAIN')
- {
- global $GO_CONFIG, $charset, $php_mailer_lang;
-
- require_once($GO_CONFIG->class_path."phpmailer/class.phpmailer.php");
- require_once($GO_CONFIG->class_path."phpmailer/class.smtp.php");
- require_once($GO_CONFIG->class_path."html2text.class.inc");
-
- $mail = new PHPMailer();
- $mail->PluginDir = $GO_CONFIG->class_path.'phpmailer/';
- $mail->SetLanguage($php_mailer_lang, $GO_CONFIG->class_path.'phpmailer/language/');
-
- if ($GO_CONFIG->smtp_server != '' && $GO_CONFIG->smtp_port != '')
- {
- $mail->IsSMTP();
- $mail->Host = $GO_CONFIG->smtp_server;
- $mail->Port = $GO_CONFIG->smtp_port;
- }
- $mail->Priority = $priority;
- $mail->From = $email_from;
- $mail->FromName = $name_from;
- $mail->AddReplyTo($email_from, $name_from);
- $mail->WordWrap = 50;
- $html_message = strtolower($body_ctype) == 'text/html' ? true : false;
- $mail->IsHTML($html_message);
- $mail->Subject = smartstrip(trim($subject));
-
- $mail_to_array = cut_address(trim($email_to), $charset);
- while ($to_address = array_shift($mail_to_array))
- {
- $mail->AddAddress($to_address);
- }
-
- if ($html_message)
- {
- $mail->Body = smartstrip($body);
- $h2t =& new html2text($body);
- $mail->AltBody = $h2t->get_text();
- }else
- {
- $mail->Body = smartstrip($body);
- }
-
- return $mail->Send();
- }
-
- //returns a link poping up a open file dialog. A HANDLER FILE MUST BE CREATED TO DO SOMETHING WITH THE FILE SELECTED
- function show_open($GO_HANDLER, $GO_FILTER, $link_text="", $class="normal", $fulllink=true)
- {
- global $GO_CONFIG, $GO_MODULES;
-
- $module = $GO_MODULES->get_module('filesystem');
-
- if ($fulllink)
- {
- $link = "<a class=\"".$class."\" href=\"javascript:popup('".$GO_CONFIG->host.$module['path']."index.php?GO_HANDLER=".urlencode($GO_HANDLER)."&GO_FILTER=".$GO_FILTER."&mode=popup','600','400')\">".$link_text."</a>";
- }else
- {
- $link = "javascript:popup('".$GO_CONFIG->host.$module['path']."index.php?GO_HANDLER=".urlencode($GO_HANDLER)."&GO_FILTER=".$GO_FILTER."&mode=popup','600','400')";
- }
- return $link;
- }
-
- //returns a link poping up a save file dialog. A temporarely file to save must be passed
- //optionally a creator file can be specified. This file will simply be included in the save script.
- //this is added to create the temporary file
-
- function show_save($tmpfile, $link_text="", $class="normal", $fulllink=true)
- {
- global $GO_CONFIG, $GO_MODULES;
-
- $module = $GO_MODULES->get_module('files');
-
- if ($fulllink)
- {
- $link = "<a class=\"".$class."\" href=\"javascript:popup('".$GO_CONFIG->host.$module['path']."save.php?SET_HANDLER=".urlencode($tmpfile)."','600','400')\">".$link_text."</a>";
- }else
- {
- $link = "javascript:popup('".$GO_CONFIG->host.$module['path']."save.php?GO_HANDLER=".urlencode($tmpfile)."','400','450')";
- }
- return $link;
- }
- function strip_extension($filename)
- {
- $pos = strrpos($filename,'.');
- if ($pos)
- {
- $filename = substr($filename,0,$pos);
- }
- return $filename;
- }
-
- function get_extension($filename)
- {
- $extension = '';
- $pos = strrpos($filename,'.');
- if ($pos)
- {
- $extension= substr($filename,$pos+1,strlen($filename));
- }
- return $extension;
- }
-
- //gets the filetype
- function filemime($path)
- {
- global $GO_CONFIG;
- require_once($GO_CONFIG->class_path.'filetypes.class.inc');
- $filetypes = new filetypes();
-
- if(!$type = $filetypes->get_type($filetypes->get_extension(basename($path))))
- {
- $type = $filetypes->add_type($filetypes->get_extension(basename($path)));
- }
-
- if ($type)
- {
- return $type['mime'];
- }else
- {
- return false;
- }
- }
-
- //gets the file type in a friendly way like text/HTML will be HTML document
- function filemimefriendly($path)
- {
- global $GO_CONFIG;
- require_once($GO_CONFIG->class_path.'filetypes.class.inc');
- $filetypes = new filetypes();
-
- if(!$type = $filetypes->get_type(get_extension(basename($path))))
- {
- $type = $filetypes->add_type(get_extension(basename($path)));
- }
-
- if ($type)
- {
- return $type['friendly'];
- }else
- {
- return false;
- }
- }
-
- function path_to_url($path)
- {
- global $GO_CONFIG;
- if ($path = str_replace($GO_CONFIG->root_path, $GO_CONFIG->host, $path))
- {
- return $path;
- }
- return false;
- }
-
-
- // Find a system program. Do path checking
- function find_program ($program) {
- $path = array('/bin', '/sbin', '/usr/bin', '/usr/sbin', '/usr/local/bin', '/usr/local/sbin');
- while ($this_path = current($path)) {
- if (is_executable("$this_path/$program")) {
- return "$this_path/$program";
- }
- next($path);
- }
- return;
- }
-
-
- // Execute a system program. return a trim()'d result.
- // does very crude pipe checking. you need ' | ' for it to work
- // ie $program = execute_program('netstat', '-anp | grep LIST');
- // NOT $program = execute_program('netstat', '-anp|grep LIST');
- function execute_program ($program, $args = '') {
- $buffer = '';
- $program = find_program($program);
-
- if (!$program) { return; }
-
- // see if we've gotten a |, if we have we need to do patch checking on the cmd
- if ($args) {
- $args_list = split(' ', $args);
- for ($i = 0; $i < count($args_list); $i++) {
- if ($args_list[$i] == '|') {
- $cmd = $args_list[$i + 1];
- $new_cmd = find_program($cmd);
- $args = ereg_replace("\| $cmd", "| $new_cmd", $args);
- }
- }
- }
-
- // we've finally got a good cmd line.. execute it
- if ($fp = popen("$program $args", 'r')) {
- while (!feof($fp)) {
- $buffer .= fgets($fp, 4096);
- }
- return trim($buffer);
- }
- }
-
- function array_csort($marray, $column) {
- foreach ($marray as $row) {
- $sortarr[] = $row[$column];
- }
- array_multisort($sortarr, $marray);
- return $marray;
- }
-