private static function display_calendar($y_mode, $y_sel_date, $y_width, $y_highlight_selected, $y_events_arr) { //-- global $configs; //-- if ($configs['regional']['calendar-week-start'] == 1) { $the_first_day = 1; // Calendar Start on Monday } else { $the_first_day = 0; // Calendar Start on Sunday } //end if else //-- if ((string) $y_sel_date == '') { $y_sel_date = date('Y-m-d'); } //end if //-- $translator_core_calendar = SmartTextTranslations::getTranslator('@core', 'calendar'); //-- $calendar = new SmartHTMLCalendar(date('Y-m-d', @strtotime($y_sel_date)), $y_highlight_selected, $y_width, (string) $y_mode); //-- set months $calendar->setMonthNames(array('01' => $translator_core_calendar->text('m_01'), '02' => $translator_core_calendar->text('m_02'), '03' => $translator_core_calendar->text('m_03'), '04' => $translator_core_calendar->text('m_04'), '05' => $translator_core_calendar->text('m_05'), '06' => $translator_core_calendar->text('m_06'), '07' => $translator_core_calendar->text('m_07'), '08' => $translator_core_calendar->text('m_08'), '09' => $translator_core_calendar->text('m_09'), '10' => $translator_core_calendar->text('m_10'), '11' => $translator_core_calendar->text('m_11'), '12' => $translator_core_calendar->text('m_12'))); //-- set days if ((string) $y_mode == 'small') { $calendar->setDayNames(array(0 => SmartUnicode::sub_str($translator_core_calendar->text('w_1'), 0, 2), 1 => SmartUnicode::sub_str($translator_core_calendar->text('w_2'), 0, 2), 2 => SmartUnicode::sub_str($translator_core_calendar->text('w_3'), 0, 2), 3 => SmartUnicode::sub_str($translator_core_calendar->text('w_4'), 0, 2), 4 => SmartUnicode::sub_str($translator_core_calendar->text('w_5'), 0, 2), 5 => SmartUnicode::sub_str($translator_core_calendar->text('w_6'), 0, 2), 6 => SmartUnicode::sub_str($translator_core_calendar->text('w_7'), 0, 2))); } else { $calendar->setDayNames(array(0 => $translator_core_calendar->text('w_1'), 1 => $translator_core_calendar->text('w_2'), 2 => $translator_core_calendar->text('w_3'), 3 => $translator_core_calendar->text('w_4'), 4 => $translator_core_calendar->text('w_5'), 5 => $translator_core_calendar->text('w_6'), 6 => $translator_core_calendar->text('w_7'))); } //end if else //-- set start on $calendar->setStartOfWeek($the_first_day); //-- if (Smart::array_size($y_events_arr) > 0) { for ($i = 0; $i < count($y_events_arr); $i++) { if ($y_events_arr[$i]['date-end'] === false) { $calendar->addDayEvent((string) $y_events_arr[$i]['event-html'], date('Y-m-d', @strtotime((string) $y_events_arr[$i]['date-start'])), false); } else { $calendar->addDayEvent((string) $y_events_arr[$i]['event-html'], date('Y-m-d', @strtotime((string) $y_events_arr[$i]['date-start'])), date('Y-m-d', @strtotime((string) $y_events_arr[$i]['date-end']))); } //end if else } //end for } //end if //-- draw return '<div title="' . Smart::escape_html(date('Y-m', @strtotime((string) $y_sel_date))) . '">' . $calendar->draw() . '</div>'; //-- }
/** * Provides a fixed length string text ; if longer than allowed length will add trailing dots (...) * * @param STRING $ystr :: The text string to be processed * @param STRING $ylen :: The fixed length of the string * @param BOOLEAN $y_cut_words :: if TRUE, will CUT last word to provide a fixed length ; if FALSE will eliminate unterminate last word ; default is TRUE * * @return STRING :: The processed string (text) */ public static function text_endpoints($ystr, $ylen, $y_cut_words = true, $y_dots = '...') { //-- $ystr = (string) trim((string) $ystr); $ylen = Smart::format_number_int($ylen, '+'); //-- if ($ylen > 0 and SmartUnicode::str_len($ystr) > $ylen) { $ystr = (string) SmartUnicode::sub_str($ystr, 0, $ylen - 3); if (!$y_cut_words) { $ystr = (string) preg_replace('/\\s+?(\\S+)?$/', '', (string) $ystr); } //end if $ystr .= (string) $y_dots; } //end if //-- return (string) $ystr; //-- }
private function _parseHeaderValue($input) { //-- if (($pos = SmartUnicode::str_pos($input, ';')) !== false) { //-- $return['value'] = trim(SmartUnicode::sub_str($input, 0, $pos)); $input = trim(SmartUnicode::sub_str($input, $pos + 1)); //-- if (strlen($input) > 0) { //-- This splits on a semi-colon, if there's no preceeding backslash. Can't handle if it's in double quotes however. (Of course anyone sending that needs a good slap). $parameters = preg_split('/\\s*(?<!\\\\);\\s*/i', (string) $input); //-- for ($i = 0; $i < Smart::array_size($parameters); $i++) { //-- $param_name = trim(SmartUnicode::sub_str($parameters[$i], 0, $pos = SmartUnicode::str_pos($parameters[$i], '='))); // added TRIM to fix invalid ' = ' case $param_value = trim(SmartUnicode::sub_str($parameters[$i], $pos + 1)); // added TRIM to fix invalid ' = ' case //-- if ((string) $param_value[0] == '"') { $param_value = SmartUnicode::sub_str($param_value, 1, -1); } //end if //-- $return['other'][$param_name] = $param_value; $return['other'][SmartUnicode::str_tolower($param_name)] = $param_value; //-- } //end for //-- } //end if //-- } else { //-- $return['value'] = trim($input); //-- } //end if else //-- return $return; //-- }
private function _answer() { //-- $this->_resp = ''; //-- for ($i = 0; $i < 3; $i++) { //-- $res = @fgets($this->_sock, 512); $this->_resp .= $res; //-- $rstop = SmartUnicode::sub_str($res, 3, 1); $rstop_plus = SmartUnicode::sub_str($res, 0, 3); //-- if (is_numeric($rstop_plus)) { if ((string) $rstop == ' ') { $i = 3; // stop } else { $i = 1; // continue } //end else } else { $i = 1; // continue } //end if else //-- } //end for //-- $this->_debug_print(str_replace("\r\n", "\n", $this->_resp)); //-- return $this->_resp; //-- }
private static function log_template($mtemplate) { //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { return (string) $mtemplate; } else { return (string) SmartUnicode::sub_str($mtemplate, 0, 255) . "\n" . '***** turn on Debugging to see more ... *****'; } //end if else //-- }
private function parseAttributeData($attributeString) { //-- $Data = array(); //-- $attributes = preg_split('/[ ]+/', $attributeString, -1, PREG_SPLIT_NO_EMPTY); //-- $classes = array(); foreach ($attributes as $z => $attribute) { //-- if ($attribute[0] === '@') { // @ $tmp_arr = explode('=', $attribute); $Data[trim(SmartUnicode::sub_str(trim($tmp_arr[0]), 1))] = trim(str_replace(array(',', '$'), array('.', ' '), trim($tmp_arr[1]))); } elseif ($attribute[0] === '#') { // # $Data['id'] = SmartUnicode::sub_str($attribute, 1); } else { // . $classes[] = SmartUnicode::sub_str($attribute, 1); } //end if else //-- } //end foreach //-- if (count($classes) > 0) { $Data['class'] = implode(' ', $classes); } //end if //-- return $Data; //-- }
private static function utf8_charAt($str, $num) { //-- return SmartUnicode::sub_str($str, $num, 1); //-- }
/** * List code points for a given input * * @param string $input * @return array Multi-dimension array with basic, non-basic and aggregated code points */ private function listCodePoints($input) { $codePoints = array('all' => array(), 'basic' => array(), 'nonBasic' => array()); $length = (int) SmartUnicode::str_len((string) $input); for ($i = 0; $i < $length; $i++) { $char = (string) SmartUnicode::sub_str((string) $input, $i, 1); $code = $this->charToCodePoint($char); if ($code < 128) { $codePoints['all'][] = $codePoints['basic'][] = $code; } else { $codePoints['all'][] = $codePoints['nonBasic'][] = $code; } } //end for return $codePoints; }
public static function test_strings() { //-- $unicode_text = '"Unicode78źź:ăĂîÎâÂșȘțȚşŞţŢグッド'; //-- $idn_domain_unicode = 'jösefsson.tßst123.org'; $idn_domain_iso = 'xn--jsefsson-n4a.xn--tst123-bta.org'; $idn_email_unicode = 'räksmörgås@jösefsson.tßst123.org'; $idn_email_iso = '*****@*****.**'; //-- //-- $err = ''; //-- //-- $tests[] = '##### Unicode STRING / TESTS: #####'; //-- //-- $regex_positive = '/^[\\w"\\:\\?]+$/'; $regex_negative = '/[^\\w"\\:\\?]/'; //-- //-- if (defined('SMART_FRAMEWORK_SECURITY_FILTER_INPUT')) { if ((string) SMART_FRAMEWORK_SECURITY_FILTER_INPUT != '') { if ((string) $err == '') { $the_test = 'Smart.Framework Security Input Filter Regex - test over a full Unicode String'; $tests[] = $the_test; if (preg_match((string) SMART_FRAMEWORK_SECURITY_FILTER_INPUT, 'Platform クラウドアプリケーションプラットフォーム \'áâãäåāăąÁÂÃÄÅĀĂĄćĉčçĆĈČÇďĎèéêëēĕėěęÈÉÊËĒĔĖĚĘĝģĜĢĥħĤĦìíîïĩīĭȉȋįÌÍÎÏĨĪĬȈȊĮijĵIJĴķĶĺļľłĹĻĽŁñńņňÑŃŅŇòóôõöōŏőøœÒÓÔÕÖŌŎŐØŒŕŗřŔŖŘșşšśŝßȘŞŠŚŜțţťȚŢŤùúûüũūŭůűųÙÚÛÜŨŪŬŮŰŲŵŴẏỳŷÿýẎỲŶŸÝźżžŹŻŽ " <p></p> ? & * ^ $ @ ! ` ~ % () [] {} | \\ / + - _ : ; , . #\'0.51085600 1454529112#' . "\r\n\t" . '`~@#$%^&*()-_=+[{]}|;:"<>,.?/\\')) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode Regex Test Positive'; $tests[] = $the_test; if (!preg_match((string) $regex_positive . 'u', (string) $unicode_text)) { $err = 'ERROR: ' . $the_test . ' FAILED (1) ...'; } elseif (preg_match((string) $regex_positive, (string) $unicode_text)) { $err = 'ERROR: ' . $the_test . ' FAILED (2) ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode Regex Test Negative'; $tests[] = $the_test; if (preg_match((string) $regex_negative . 'u', (string) $unicode_text)) { $err = 'ERROR: ' . $the_test . ' FAILED (1) ...'; } elseif (!preg_match((string) $regex_negative, (string) $unicode_text)) { $err = 'ERROR: ' . $the_test . ' FAILED (2) ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Deaccented ISO Regex Test Positive'; $tests[] = $the_test; if (!preg_match((string) $regex_positive, (string) SmartUnicode::deaccent_str($unicode_text))) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Deaccented ISO Regex Test Negative'; $tests[] = $the_test; if (preg_match((string) $regex_negative, (string) SmartUnicode::deaccent_str($unicode_text))) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode Strlen Test'; $tests[] = $the_test; if (SmartUnicode::str_len($unicode_text) !== 30) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { // this tests also SmartUnicode::str_ipos $the_test = 'Unicode Find Substring (Case Insensitive), Positive'; $tests[] = $the_test; if (SmartUnicode::str_icontains($unicode_text, 'șș') !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { // this tests also SmartUnicode::str_ipos $the_test = 'Unicode Find Substring (Case Insensitive), Negative'; $tests[] = $the_test; if (SmartUnicode::str_icontains($unicode_text, 'șş') !== false) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { // this tests also SmartUnicode::str_pos $the_test = 'Unicode Find Substring (Case Sensitive), Positive'; $tests[] = $the_test; if (SmartUnicode::str_contains($unicode_text, 'țȚ') !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { // this tests also SmartUnicode::str_pos $the_test = 'Unicode Find Substring (Case Sensitive), Negative'; $tests[] = $the_test; if (SmartUnicode::str_contains($unicode_text, 'țŢ') !== false) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode Find Substring (Case Insensitive), Reverse'; $tests[] = $the_test; if (SmartUnicode::str_ripos($unicode_text, 'ţţグ') === false) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode Find Substring (Case Sensitive), Reverse'; $tests[] = $the_test; if (SmartUnicode::str_rpos($unicode_text, 'ţŢグ') === false) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode Return Substring (Case Insensitive)'; $tests[] = $the_test; if (SmartUnicode::stri_str($unicode_text, 'âȘșȚ') !== 'ÂșȘțȚşŞţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode Return Substring (Case Sensitive)'; $tests[] = $the_test; if (SmartUnicode::str_str($unicode_text, 'ÂșȘț') !== 'ÂșȘțȚşŞţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode String to LowerCase'; $tests[] = $the_test; if (SmartUnicode::str_tolower($unicode_text) !== '"unicode78źź:ăăîîââșșțțşşţţグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode String to UpperCase'; $tests[] = $the_test; if (SmartUnicode::str_toupper($unicode_text) !== '"UNICODE78ŹŹ:ĂĂÎÎÂÂȘȘȚȚŞŞŢŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode SubString function (without last param)'; $tests[] = $the_test; if (SmartUnicode::sub_str($unicode_text, 25) !== 'ţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'Unicode SubString function (with last param)'; $tests[] = $the_test; if (SmartUnicode::sub_str($unicode_text, 25, 3) !== 'ţŢグ') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode SubString Count function'; $tests[] = $the_test; if (SmartUnicode::substr_count($unicode_text, 'ţ') !== 1) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Unicode String Replace with Limit (Case Sensitive)'; $tests[] = $the_test; if (SmartUnicode::str_limit_replace('ź', '@', $unicode_text, 1) !== '"Unicode78@ź:ăĂîÎâÂșȘțȚşŞţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { $the_test = 'String Replace without Limit (Case Sensitive)'; $tests[] = $the_test; if (str_replace('ź', '@', $unicode_text) !== '"Unicode78@@:ăĂîÎâÂșȘțȚşŞţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if if ((string) $err == '') { /* This test fails if the replacements accented characters are different case than one find in string (upper/lower) ... */ $the_test = 'String Replace without Limit (Case Insensitive) *** Only with unaccented replacements !!'; $tests[] = $the_test; if (str_ireplace('E7', '@', $unicode_text) !== '"Unicod@8źź:ăĂîÎâÂșȘțȚşŞţŢグッド') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Deaccent String'; $tests[] = $the_test; if (SmartUnicode::deaccent_str($unicode_text) !== '"Unicode78zz:aAiIaAsStTsStT???') { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'YAML Unicode Test: Compose from Array / Parse from YAML'; $tests[] = $the_test; $test_arr = array('@test' => 'Testing weird key characters', 'line1' => 'Some ISO-8859-1 String: @ # $ % ^ & * (\') _ - + = { [ ] } ; < ,. > / ? \\ |', 'line2' => 'Unicode (long) String: ' . $unicode_text . ' ' . SmartUnicode::str_toupper($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::str_tolower($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::deaccent_str($unicode_text) . ' ' . $unicode_text, $unicode_text => 'Unicode as Key', 'line3' => ['A' => 'b', 100, 'Thousand'], 'line4' => [1, 0.2, 3.0001], 'line5' => date('Y-m-d H:i:s')); $test_yaml = (string) '# start YAML (to test also comments)' . "\n" . (new SmartYamlConverter())->compose($test_arr) . "\n" . '# end YAML'; $test_parr = (new SmartYamlConverter())->parse($test_yaml); if ($test_arr !== $test_parr) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' #ORIGINAL Array [' . print_r($test_arr, 1) . ']' . "\n\n" . '#YAML Array (from YAML String): ' . print_r($test_parr, 1) . "\n\n" . '#YAML String (from ORIGINAL Array): ' . "\n" . $test_yaml; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'XML Unicode Test: Compose from Array / Parse from XML'; $tests[] = $the_test; $test_arr = array('TEST' => 'Testing weird key characters', 'line1' => 'Some ISO-8859-1 String: @ # $ % ^ & * (\') _ - + = { [ ] } ; < ,. > / ? \\ |', 'line2' => 'Unicode (long) String: ' . $unicode_text . ' ' . SmartUnicode::str_toupper($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::str_tolower($unicode_text) . ' ' . $unicode_text . ' ' . SmartUnicode::deaccent_str($unicode_text) . ' ' . $unicode_text, 'line3' => ['A' => 'b', 'c' => 'D'], 'line4' => '', 'line5' => date('Y-m-d H:i:s')); $test_xml = (string) (new SmartXmlComposer())->transform($test_arr); $test_parr = (new SmartXmlParser())->transform($test_xml); if ($test_arr !== $test_parr) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' #ORIGINAL Array [' . print_r($test_arr, 1) . ']' . "\n\n" . '#XML Array (from XML String): ' . print_r($test_parr, 1) . "\n\n" . '#XML String (from ORIGINAL Array): ' . "\n" . $test_xml; } //end if } //end if //-- $the_random_unicode_text = sha1($unicode_text . Smart::random_number(1000, 9999)) . '-' . $unicode_text . " \r\n\t" . '-' . Smart::uuid_10_num() . '-' . Smart::uuid_10_str() . '-' . Smart::uuid_10_seq(); //-- if ((string) $err == '') { $the_test = 'Data: Archive / Unarchive'; $tests[] = $the_test; if (SmartUtils::data_unarchive(SmartUtils::data_archive($the_random_unicode_text)) !== (string) $the_random_unicode_text) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $the_random_unicode_text . ']'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'Cache: Archive / Unarchive'; $tests[] = $the_test; if (SmartUtils::cache_variable_unarchive(SmartUtils::cache_variable_archive($the_random_unicode_text)) !== (string) $the_random_unicode_text) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $the_random_unicode_text . ']'; } //end if } //end if //-- //-- if ((string) $err == '') { $the_test = 'IDN: Domain Punycode Encode UTF-8 to ISO'; $tests[] = $the_test; if ((string) (new SmartPunycode())->encode($idn_domain_unicode) != (string) $idn_domain_iso) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_domain_unicode . ' -> ' . $idn_domain_iso . ']'; } //end if } //end if if ((string) $err == '') { $the_test = 'IDN: Domain Punycode Decode ISO to UTF-8'; $tests[] = $the_test; if ((string) (new SmartPunycode())->decode($idn_domain_iso) != (string) $idn_domain_unicode) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_domain_iso . ' -> ' . $idn_domain_unicode . ']'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'IDN: Email Punycode Encode UTF-8 to ISO'; $tests[] = $the_test; if ((string) (new SmartPunycode())->encode($idn_email_unicode) != (string) $idn_email_iso) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_email_unicode . ' -> ' . $idn_email_iso . ']'; } //end if } //end if if ((string) $err == '') { $the_test = 'IDN: Email Punycode Decode ISO to UTF-8'; $tests[] = $the_test; if ((string) (new SmartPunycode())->decode($idn_email_iso) != (string) $idn_email_unicode) { $err = 'ERROR: ' . $the_test . ' FAILED ...' . ' [' . $idn_email_iso . ' -> ' . $idn_email_unicode . ']'; } //end if } //end if //-- //-- regex positive tests $arr_regex = ['number-integer' => [0, '75', '-101'], 'number-decimal' => [0, '0.0', '0.1', '75', '75.0', '75.1', '-555', '-555.0', '-555.1'], 'number-list-integer' => '1;2;30', 'number-list-decimal' => '1.0;2;30.44', 'url' => ['https://192.168.1.0', 'http://localhost', 'https://www.dom.ext', 'http://dom.ext/path?a=b&c=d%20#s'], 'domain' => ['domain.com', 'sdom.domain.org'], 'email' => ['root@localhost', '*****@*****.**', '*****@*****.**'], 'fax' => ['~+99-(0)999-123.456.78~'], 'macaddr' => ['00:0A:95:9d:68:16', '00-0a-95-9D-68-16'], 'ipv4' => ['192.168.0.1', '169.254.1.0', '1.0.0.1'], 'ipv6' => ['::1', '0000:0000:0000:0000:0000:0000:0000:0001', '2001:0db8:0000:0000:0000:ff00:0042:8329', '2001:dB8::2:1', '2001:db8::1', '3731:54:65fe:2::a7']]; //-- foreach ((array) $arr_regex as $key => $val) { //-- if (is_array($val)) { for ($i = 0; $i < Smart::array_size($val); $i++) { $the_test = 'Regex Validate Positive (#' . $i . '): ' . $key . ' [' . $val[$i] . ']'; $tests[] = $the_test; if (SmartValidator::validate_string($val[$i], $key) !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; break; } //end if if (stripos((string) $key, 'number-') === 0 and stripos((string) $key, 'number-list-') === false) { $the_test = 'Regex Validate Numeric Positive (#' . $i . '): ' . $key . ' [' . $val[$i] . ']'; $tests[] = $the_test; if (SmartValidator::validate_numeric_integer_or_decimal_values($val[$i], $key) !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; break; } //end if } //end if } //end for } else { $the_test = 'Regex Validate Positive: ' . $key . ' [' . $val . ']'; $tests[] = $the_test; if (SmartValidator::validate_string($val, $key) !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if if (stripos((string) $key, 'number-') === 0 and stripos((string) $key, 'number-list-') === false) { $the_test = 'Regex Validate Numeric Positive: ' . $key . ' [' . $val . ']'; $tests[] = $the_test; if (SmartValidator::validate_numeric_integer_or_decimal_values($val, $key) !== true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if } //end if else //-- if ((string) $err != '') { break; } //end if //-- } //end foreach //-- //-- regex negative tests $arr_regex = ['number-integer' => ['', '.', 'a9', '7B', '-9 ', ' -7'], 'number-decimal' => ['', '.0', '.1', '-.10', ' -7', '-9.0 '], 'number-list-integer' => '1;2.3;30', 'number-list-decimal' => '1.0;2;30.44a', 'url' => ['http:://192.168.1.0', 'https://local host', 'http:/www.dom.ext', 'https:dom.ext/path?a=b&c=d%20#s'], 'domain' => ['doMain.com', 's dom.domain.org', '.dom.ext', 'dom..ext', 'localhost', 'loc', 'dom.ext.'], 'email' => ['rooT@localhost', 'root@local host.loc', 'sometest-name.extra@do_m.ext'], 'fax' => ['~ +99-(0)999-123.456.78 ~'], 'macaddr' => ['00:0A:95:9z:68:16', '00-0Z-95-9D-68-16'], 'ipv4' => ['192.168.0.', '169..1.0', '1.0.1'], 'ipv6' => ['::x', '00z0:0000:0000:0000:0000:0000:0000:0001', '2001:0dx8:0000:0000:0000:ff00:0042:8329', '2001:WB8::2:1', '2001:@db8::1', '3731:54:65Qe:2::a7']]; //-- foreach ((array) $arr_regex as $key => $val) { //-- if (is_array($val)) { for ($i = 0; $i < Smart::array_size($val); $i++) { $the_test = 'Regex Validate Negative (#' . $i . '): ' . $key . ' [' . $val[$i] . ']'; $tests[] = $the_test; if (SmartValidator::validate_string($val[$i], $key) === true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; break; } //end if } //end for } else { $the_test = 'Regex Validate Negative: ' . $key . ' [' . $val . ']'; $tests[] = $the_test; if (SmartValidator::validate_string($val, $key) === true) { $err = 'ERROR: ' . $the_test . ' FAILED ...'; } //end if } //end if else //-- if ((string) $err != '') { break; } //end if //-- } //end foreach //-- //-- $endtest = '##### END TESTS ... #####'; //-- //-- if ((string) $err == '') { $img_sign = 'lib/core/img/sign_info.png'; $img_check = 'lib/core/img/q_completed.png'; $text_main = Smart::escape_js('<span style="color:#83B953;">Good ... Perfect :: グッド ... パーフェクト</span>'); $text_info = Smart::escape_js('<h2><span style="color:#83B953;">All</span> the SmartFramework Unicode String <span style="color:#83B953;">Tests PASSED on PHP</span><hr></h2><span style="font-size:14px;">' . Smart::nl_2_br(Smart::escape_html(implode("\n" . '* ', $tests) . "\n" . $endtest)) . '</span>'); } else { $img_sign = 'lib/core/img/sign_error.png'; $img_check = 'lib/core/img/q_warning.png'; $text_main = Smart::escape_js('<span style="color:#FF5500;">An ERROR occured ... :: エラーが発生しました ...</span>'); $text_info = Smart::escape_js('<h2><span style="color:#FF5500;">A test FAILED</span> when testing Unicode String Tests.<span style="color:#FF5500;"><hr>FAILED Test Details</span>:</h2><br><h3>' . Smart::escape_html($tests[Smart::array_size($tests) - 1]) . '</h3><br><span style="font-size:14px;"><pre>' . Smart::escape_html($err) . '</pre></span>'); } //end if else //-- //-- $html = <<<HTML <h1>SmartFramework Unicode Strings Tests: DONE ...</h1> <script type="text/javascript"> \tSmartJS_BrowserUtils.alert_Dialog( \t\t'<img src="{$img_sign}" align="right"><h1>{$text_main}</h1><hr><span style="color:#333333;"><img src="{$img_check}" align="right">{$text_info}<br>', \t\t'', \t\t'Unicode String Test Suite for SmartFramework: PHP', \t\t'725', \t\t'425' \t); </script> HTML; //-- //-- return $html; //-- }
private function parse_banner($reply) { //-- $outside = true; $banner = ''; //-- $reply = trim($reply); //-- for ($i = 0; $i < SmartUnicode::str_len($reply); $i++) { //-- $digit = SmartUnicode::sub_str($reply, $i, 1); //-- if (strlen($digit) > 0) { //-- if (!$outside and (string) $digit != '<' and (string) $digit != '>') { $banner .= $digit; } //end if //-- if ((string) $digit == '<') { $outside = false; } //end if //-- if ((string) $digit == '>') { $outside = true; } //end if //-- } //end if //-- } //end for //-- $banner = trim($this->strip_clf($banner)); // just in case if (strlen($banner) > 0) { $banner = '<' . $banner . '>'; } //end if //-- return $banner; //-- }
/** * Load a File or an URL * it may use 3 methods: FileRead, CURL or HTTP-Browser class * * @param STRING $y_url_or_path :: /path/to/file | http(s)://some.url:port/path (port is optional) * @param NUMBER $y_timeout :: timeout in seconds * @param ENUM $y_method :: used only for URLs, the browsing method: GET | POST * @param ENUM $y_ssl_method :: SSL Mode: tls | sslv3 | sslv2 | ssl * @param STRING $y_auth_name :: used only for URLs, the auth user name * @param STRING $y_auth_pass :: used only for URLs, the auth password * @param YES/NO y_allow_set_credentials :: DEFAULT MUST BE set to NO ; if YES must be set just for internal URLs ; if the $y_url_or_path to get is detected to be under current URL will send also the Unique / session IDs ; more if detected that is from admin.php and if this is set to YES will send the HTTP-BASIC Auth credentials if detected (using YES with other URLs than SmartFramework's current URL can be a serious SECURITY ISSUE, so don't !) */ public static function load_url_or_file($y_url_or_path, $y_timeout = 30, $y_method = 'GET', $y_ssl_method = '', $y_auth_name = '', $y_auth_pass = '', $y_allow_set_credentials = 'no') { //-- v.2016-01-15 // fixed sessionID with new Dynamic generated // TODO: use the CURL to browse also FTP and SSH ... //-- $y_url_or_path = (string) $y_url_or_path; //-- if ((string) $y_url_or_path == '') { //-- return array('log' => 'ERROR: FILE Name is Empty ...', 'mode' => 'file', 'result' => '0', 'code' => '400', 'headers' => '', 'content' => '', 'debuglog' => ''); //-- } //end if //-- detect if file or url if (substr($y_url_or_path, 0, 7) == 'http://' or substr($y_url_or_path, 0, 8) == 'https://') { $is_file = 0; // it is a url } else { $is_file = 1; // it is a file } //end if //-- if ($is_file == 1) { //-- $y_url_or_path = trim($y_url_or_path); //-- try to detect if data:image/ :: {{{SYNC-DATA-IMAGE}}} if (strtolower(substr($y_url_or_path, 0, 11)) == 'data:image/' and stripos($y_url_or_path, ';base64,') !== false) { //-- $eimg = explode(';base64,', $y_url_or_path); //-- return array('log' => 'OK ? Not sure, decoded from embedded b64 image: ', 'mode' => 'embedded', 'result' => '1', 'code' => '200', 'headers' => SmartUnicode::sub_str($y_url_or_path, 0, 50) . '...', 'content' => @base64_decode(trim($eimg[1])), 'debuglog' => ''); //-- } elseif (is_file($y_url_or_path)) { //-- return array('log' => 'OK: FILE Exists', 'mode' => 'file', 'result' => '1', 'code' => '200', 'headers' => 'Content-Disposition: inline; filename="' . basename($y_url_or_path) . '"' . "\n", 'content' => SmartFileSystem::read($y_url_or_path), 'debuglog' => ''); //-- } else { //-- return array('log' => 'ERROR: FILE Not Found or Invalid Data ...', 'mode' => 'file', 'result' => '0', 'code' => '404', 'headers' => '', 'content' => '', 'debuglog' => ''); //-- } //end if else //-- } else { //-- if ((string) $y_ssl_method == '') { if (defined('SMART_FRAMEWORK_SSL_MODE')) { $y_ssl_method = (string) SMART_FRAMEWORK_SSL_MODE; } else { Smart::log_notice('NOTICE: LibUtils/Load-URL-or-File // The SSL Method not defined and SMART_FRAMEWORK_SSL_MODE was not defined. Using the `tls` as default ...'); $y_ssl_method = 'tls'; } //end if else } //end if //-- $browser = new SmartHttpClient(); //-- $y_timeout = Smart::format_number_int($y_timeout, '+'); if ($y_timeout <= 0) { $y_timeout = 30; // default value } //end if $browser->connect_timeout = (int) $y_timeout; //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { $browser->debug = 1; } //end if //-- if ((string) self::get_server_current_protocol() == 'https://') { $tmp_current_protocol = 'https://'; } else { $tmp_current_protocol = 'http://'; } //end if else //-- $tmp_current_server = self::get_server_current_domain_name(); $tmp_current_port = self::get_server_current_port(); //-- $tmp_current_path = self::get_server_current_request_uri(); $tmp_current_script = self::get_server_current_full_script(); //-- $tmp_test_url_arr = Smart::separe_url_parts($y_url_or_path); $tmp_test_browser_id = self::get_os_browser_ip(); //-- $tmp_extra_log = ''; if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { $tmp_extra_log .= "\n" . '===== # =====' . "\n"; } //end if //-- $cookies = array(); $auth_name = (string) $y_auth_name; $auth_pass = (string) $y_auth_pass; //-- if ((string) $y_allow_set_credentials == 'yes') { //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { $tmp_extra_log .= '[EXTRA]: I will try to detect if this is my current Domain and I will check if it is safe to send my sessionID COOKIE and my Auth CREDENTIALS ...' . "\n"; } //end if //-- if ((string) $tmp_current_protocol == (string) $tmp_test_url_arr['protocol'] and (string) $tmp_current_server == (string) $tmp_test_url_arr['server'] and (string) $tmp_current_port == (string) $tmp_test_url_arr['port']) { //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { $tmp_extra_log .= '[EXTRA]: OK, Seems that the browsed Domain is identical with my current Domain which is: ' . $tmp_current_protocol . $tmp_current_server . ':' . $tmp_current_port . ' and the browsed one is: ' . $tmp_test_url_arr['protocol'] . $tmp_test_url_arr['server'] . ':' . $tmp_test_url_arr['port'] . "\n"; $tmp_extra_log .= '[EXTRA]: I will also check if my current script and path are identical with the browsed ones ...' . "\n"; } //end if //-- if ((string) $tmp_current_script == (string) $tmp_test_url_arr['scriptname'] and substr($tmp_current_path, 0, strlen($tmp_current_script)) == (string) $tmp_test_url_arr['scriptname']) { //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { $tmp_extra_log .= '[EXTRA]: OK, Seems that the current script is identical with the browsed one :: ' . 'Current Path is: \'' . $tmp_current_script . '\' / Browsed Path is: \'' . $tmp_test_url_arr['scriptname'] . '\' !' . "\n"; $tmp_extra_log .= '[EXTRA]: I will check if I have to send my SessionID so I will check the browserID ...' . "\n"; } //end if //-- $browser->useragent = (string) self::get_selfrobot_useragent_name(); // this must be set just when detected the same path and script ; it is a requirement to detect it as the self-robot [ @s# ] in order to send the credentials or the current //-- {{{SYNC-SMART-UNIQUE-COOKIE}}} if (defined('SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME') and !defined('SMART_FRAMEWORK_UNIQUE_ID_COOKIE_SKIP')) { if ((string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME != '') { if (SmartFrameworkSecurity::ValidateVariableName(strtolower((string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME))) { //-- if ((string) SMART_APP_VISITOR_COOKIE != '') { // if set, then forward if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { $tmp_extra_log .= '[EXTRA]: OK, I will send my current Visitor Unique Cookie ID as it is set and not empty ...' . "\n"; } //end if $cookies[(string) SMART_FRAMEWORK_UNIQUE_ID_COOKIE_NAME] = (string) SMART_APP_VISITOR_COOKIE; // this is a requirement } //end if //-- } //end if } //end if } //end if //-- #end# sync if ((string) SmartAuth::get_login_method() == 'HTTP-BASIC' and (string) $auth_name == '' and (string) $auth_pass == '' and strpos($tmp_current_script, '/admin.php') !== false and strpos($tmp_test_url_arr['scriptname'], '/admin.php') !== false) { //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { $tmp_extra_log .= '[EXTRA]: HTTP-BASIC Auth method detected / Allowed to pass the Credentials - as the browsed URL belongs to this ADMIN Server as I run, the Auth credentials are set but passed as empty - everything seems to be safe I will send my credentials: USERNAME = \'' . SmartAuth::get_login_id() . '\' ; PASS = *****' . "\n"; } //end if //-- $auth_name = (string) SmartAuth::get_login_id(); $auth_pass = (string) SmartAuth::get_login_password(); //-- } //end if //-- } else { //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { $tmp_extra_log .= '[EXTRA]: Seems that the scripts are NOT identical :: ' . 'Current Script is: \'' . $tmp_current_script . '\' / Browsed Script is: \'' . $tmp_test_url_arr['scriptname'] . '\' !' . "\n"; $tmp_extra_log .= '[EXTRA]: This is the diff for having a comparation: ' . substr($tmp_current_path, 0, strlen($tmp_current_script)) . "\n"; } //end if //-- } //end if //-- } //end if //-- } //end if //-- $browser->cookies = (array) $cookies; //-- $data = (array) $browser->browse_url($y_url_or_path, $y_method, $y_ssl_method, $auth_name, $auth_pass); // do browse //-- return array('log' => (string) $data['log'] . $tmp_extra_log, 'mode' => (string) $data['mode'], 'result' => (string) $data['result'], 'code' => (string) $data['code'], 'headers' => (string) $data['headers'], 'content' => (string) $data['content'], 'debuglog' => (string) $data['debuglog']); //-- } //end if else //-- }
private function retry_data() { //-- if (!$this->socket) { $this->error = '[ERR] SMTP Retry Data: No connection to server'; return ''; } //end if //-- $data = ''; //-- while ($str = @fgets($this->socket, 515)) { // do not change the read buffer (default is set to 515 = 512 + 3) //-- $data .= $str; //-- if ($this->debug) { if ($this->dbglevel >= 2) { // advanced debug $this->log .= 'SMTP [3] // RETRY DATA // partial data is: ' . $str . "\n"; } //end if } //end if //-- if the 4th character is a space then we are done reading so just break the loop (else the 4th char. is '-') if (SmartUnicode::sub_str($str, 3, 1) == ' ') { break; } //end if //-- } //end while //-- return $data; //-- }
private static function read_mime_message($y_enc_msg_file, $y_ctrl_key, $y_process_mode, $y_show_headers, $y_title, $y_link, $y_target) { // $y_process_mode : 'default' | 'print' | 'data-full' | 'data-reply' // $y_show_headers : 'default' | 'subject' (just for mode: 'default' | 'print') //-- $msg_decode_arr = (array) self::decode_mime_fileurl((string) $y_enc_msg_file, (string) $y_ctrl_key); //-- if ((string) $msg_decode_arr['error'] != '') { Smart::raise_error('ERROR: MIME Parser // Mesage File Decode: ' . $msg_decode_arr['error'], 'ERROR: MIME Parser // Mesage File Decode // See error log for details ...'); return ''; } //end if //-- //-- $the_message_eml = (string) trim((string) $msg_decode_arr['message-file']); $the_part_id = (string) trim((string) $msg_decode_arr['message-part']); //-- //-- if ((string) $the_message_eml == '' or !is_file((string) $the_message_eml)) { Smart::raise_error('ERROR: MIME Parser // Message File EMPTY or NOT FOUND !: ' . $the_message_eml, 'ERROR: MIME Parser // Mesage File Decode // See error log for details ...'); return ''; } //end if //-- if (substr((string) $the_message_eml, -4, 4) != '.eml') { Smart::raise_error('ERROR: MIME Parser // Message File Extension is not .eml !: ' . $the_message_eml, 'ERROR: MIME Parser // Mesage File Decode // See error log for details ...'); return ''; } //end if //-- //-- $out = ''; // init $reply_text = array(); // init //-- //== //-- $content = SmartFileSystem::read((string) $the_message_eml); $eml = new SmartMailerMimeDecode(); $head = $eml->get_header(SmartUnicode::sub_str((string) $content, 0, 65535)); // some messages fail with 8192 to decode ; a faster compromise would be 16384, but here we can use a higher value since is done once (text 65535) $msg = $eml->get_bodies((string) $content, (string) $the_part_id); unset($eml); unset($content); //-- //== //-- $reg_atts_num = 0; $reg_atts_list = ''; // list separed by \n //-- if (strlen($the_part_id) <= 0) { //-- display whole message $reg_is_part = 'no'; $skip_part_processing = 'no'; $skip_part_linking = 'no'; //-- } else { //-- display only a part of the message $reg_is_part = 'yes'; $skip_part_processing = 'no'; $skip_part_linking = 'yes'; //-- if (substr($the_part_id, 0, 4) == 'txt_') { //-- text part $tmp_part = $msg['texts'][$the_part_id]; $msg = array(); $msg['texts'][$the_part_id] = (array) $tmp_part; unset($tmp_part); //-- } else { //-- att / cid part $skip_part_processing = 'yes'; //-- if (!is_array($msg['attachments'][$the_part_id])) { // try to normalize name $the_part_id = trim(str_replace(' ', '', $the_part_id)); } //end if //-- $out = (string) $msg['attachments'][$the_part_id]['content']; // DO NO MORE ADD ANYTHING TO $out ... downloading, there are no risk of code injection //-- } //end if else //-- } //end if else //-- //-- if ((string) $y_process_mode == 'print') { $skip_part_linking = 'yes'; // skip links to other sub-parts like texts / attachments but not cids ! } elseif ((string) $y_process_mode == 'data-reply') { $skip_part_linking = 'yes'; } //end if //-- //-- if ((string) $skip_part_processing != 'yes') { //-- if ((string) $y_title != '') { $out .= (string) $y_title; // expects '' or valid HTML } //end if //-- $out .= '<!-- Smart.Framework // MIME MESSAGE HTML --><div align="left"><div id="mime_msg_box">'; //-- if (strlen($the_part_id) <= 0) { //-- $priority_img = ''; switch ((string) $head['priority']) { case '1': // high $priority_img = '<img src="lib/core/plugins/img/email/priority_high.png" align="left" alt="High Priority" title="High Priority">'; break; case '5': // low $priority_img = '<img src="lib/core/plugins/img/email/priority_low.png" align="left" alt="Low Priority" title="Low Priority">'; break; case '3': // medium // medium default: $priority_img = ''; //$priority_img = '<img src="lib/core/plugins/img/email/priority_normal.png" align="left" alt="Normal Priority" title="Normal Priority">'; } //end switch //-- if ((string) $skip_part_linking != 'yes') { // avoid display the print link when only a part is displayed $out .= '<a href="' . self::mime_link($y_ctrl_key, $the_message_eml, $the_part_id, $y_link, $eval_arr[0], $eval_arr[1], 'print') . '" target="' . $y_target . '__mimepart" data-smart="open.modal">' . '<img align="right" src="lib/core/img/buttons/bttn_print.png">' . '</a>'; } //end if //-- switch ((string) $y_show_headers) { case 'subject': //-- if ((string) $head['subject'] != '[?]') { $out .= '<h1><font size="4">' . Smart::escape_html($head['subject']) . '</font></h1><br>'; } //end if //-- break; case 'default': default: //-- if ((string) $head['subject'] != '[?]') { $out .= '<h1><font size="4"> ' . Smart::escape_html($head['subject']) . '</font>' . $priority_img . '</h1><hr>'; } //end if //-- if ((string) $head['date'] != '(?)') { $out .= '<font size="3"><b>Date:</b> ' . Smart::escape_html(date('Y-m-d H:i:s O', @strtotime($head['date']))) . '</font><br>'; } //end if //-- $out .= '<font size="2"><b>From:</b> ' . Smart::escape_html($head['from_addr']) . ' <i>' . Smart::escape_html($head['from_name']) . '</i>' . '</font><br>'; $out .= '<font size="2"><b>To:</b> ' . Smart::escape_html($head['to_addr']) . ' <i>' . Smart::escape_html($head['to_name']) . '</i>' . '</font><br>'; //-- if (strlen($head['cc_addr']) > 0) { $out .= '<font size="2"><b>Cc:</b> '; if (SmartUnicode::str_contains($head['cc_addr'], ',')) { $arr_cc_addr = (array) explode(',', (string) $head['cc_addr']); $arr_cc_name = (array) explode(',', (string) $head['cc_name']); $out .= '[@]'; for ($z = 0; $z < Smart::array_size($arr_cc_addr); $z++) { $out .= '<br> ' . Smart::escape_html(trim($arr_cc_addr[$z])) . ' <i>' . Smart::escape_html(trim($arr_cc_name[$z])) . '</i>'; } //end for } else { $out .= Smart::escape_html($head['cc_addr']) . ' <i>' . Smart::escape_html($head['cc_name']) . '</i>'; } //end if else $out .= '</font><br>'; } //end if //-- if (strlen($head['bcc_addr']) > 0) { $out .= '<font size="2"><b>Bcc:</b> '; $out .= Smart::escape_html($head['bcc_addr']) . ' <i>' . Smart::escape_html($head['bcc_name']) . '</i>'; $out .= '</font><br>'; } //end if //-- } //end switch //-- print attachments if (is_array($msg['attachments'])) { //-- $cnt = 0; //-- $atts = ''; // atts with link $xatts = ''; // atts without link //-- $tmp_att_img = '<img src="lib/core/plugins/img/email/attachment.png">'; //-- foreach ($msg['attachments'] as $key => $val) { //-- $tmp_arr = array(); $tmp_arr = (array) $val; //-- if ((string) $tmp_arr['mode'] == 'normal') { //-- $cnt += 1; //-- $eval_arr = SmartFileSysUtils::mime_eval((string) $tmp_arr['filename']); $tmp_att_name = Smart::escape_html((string) $tmp_arr['filename']); $tmp_att_size = Smart::escape_html((string) SmartUtils::pretty_print_bytes((int) $tmp_arr['filesize'], 1)); //-- $reg_atts_num += 1; $reg_atts_list .= str_replace(array("\r", "\n", "\t"), array('', '', ''), (string) $tmp_arr['filename']) . "\n"; //-- $atts .= '<div align="left"><table border="0" cellpadding="2" cellspacing="0" title="Attachment #' . $cnt . '"><tr><td>' . $tmp_att_img . '</td><td> </td><td><a href="' . self::mime_link($y_ctrl_key, $the_message_eml, $key, $y_link, $eval_arr[0], $eval_arr[1]) . '" target="' . $y_target . '__mimepart" data-smart="open.modal"><font size="1"><b>' . $tmp_att_name . '</b></font></a></td><td><font size="1"> <b><i>' . $tmp_att_size . '</i></b></font></td></tr></table></div>'; $xatts .= '<div align="left">' . $tmp_att_img . ' <font size="1">' . $tmp_att_name . ' <i>' . $tmp_att_size . '</i></font></div>'; //-- } //end if //-- } //end foreach //-- if ($cnt > 0) { if ((string) $skip_part_linking == 'yes') { // avoid displaying attachments links when only a part is displayed $out .= '<hr><div align="left">' . $xatts . '</div>'; } else { $out .= '<hr><div align="left">' . $atts . '</div>'; } //end if } //end if //-- $tmp_att_name = ''; $tmp_att_size = ''; //-- $atts = ''; $xatts = ''; //-- } //end if //-- } else { //-- $out .= '<div align="right"><font size="1">' . Smart::escape_html($head['subject']) . ' // ' . 'MIME Part ID : <i>' . Smart::escape_html($the_part_id) . '</i></font></div>'; //-- } //end if //-- print text bodies $markup_multipart = 'This is a multi-part message in MIME format.'; if (is_array($msg['texts'])) { //-- check similarity and prepare the HTML parts $buff = ''; $buff_id = ''; $xbuff = ''; $xbuff_id = ''; $skips = array(); $numparts = 0; foreach ($msg['texts'] as $key => $val) { //-- $numparts += 1; //-- if ((string) $val['type'] == 'text') { // assure we don't print other things //-- if ((string) $val['mode'] == 'text/plain') { // Plain TEXT //-- sanitize text $val['content'] = '<!-- MIMEREAD:PART:TEXT -->' . Smart::escape_html($val['content']); $val['content'] = str_replace(array("\r\n", "\r", "\n"), array("\n", "\n", '<br>'), $val['content']); $val['content'] = SmartParser::text_urls($val['content']); //-- $msg['texts'][$key]['content'] = $val['content']; // rewrite back //-- assign buffer $buff = SmartUnicode::sub_str($val['content'], 0, 16384); $buff_id = $key; //-- $percent_similar = 0; if (strlen($the_part_id) <= 0) { @similar_text($buff, $markup_multipart, $percent_similar); if ($percent_similar >= 25) { // 25% at least similarity $skips[$buff_id] = $percent_similar; // skip this alternate html part ... } //end if } //end if //-- // clean buffer $xbuff = ''; $xbuff_id = ''; //-- } else { // HTML Parts :: check similarity //-- $val['content'] = '<!-- MIMEREAD:PART:HTML -->' . preg_replace("'" . '<\\?xml' . ".*?" . '>' . "'si", " ", (string) $val['content']); // remove always fake "< ?" as "< ?xml" (fixed with /u modifier for unicode strings) //-- if (SmartUnicode::str_contains($val['content'], '<' . '?') or SmartUnicode::str_contains($val['content'], '?' . '>') or SmartUnicode::str_contains($val['content'], '<' . '%') or SmartUnicode::str_contains($val['content'], '%' . '>')) { //-- $val['content'] = @highlight_string($val['content'], 1); // highlight the PHP* code & sanitize the parts //-- } else { //-- sanitize this html part $val['content'] = (new SmartHtmlParser($val['content']))->get_clean_html(); //-- replace cid images $tmp_matches = array(); preg_match_all('/<img[^>]+src=[\'"]?(cid:)([^\'"]*)[\'"]?[^>]*>/si', (string) $val['content'], $tmp_matches); // fix: previous was just i (not si) ; modified on 160205 // $tmp_matches[0][i] : the full link // $tmp_matches[1][i] : 'cid:' // $tmp_matches[2][i] : cid part id for ($cids = 0; $cids < Smart::array_size($tmp_matches[0]); $cids++) { $tmp_replace_cid_link = ''; $tmp_replace_cid_link = (string) $tmp_matches[0][$cids]; $tmp_replace_cid_link = str_replace("\n", ' ', $tmp_replace_cid_link); $tmp_replace_cid_link = str_replace($tmp_matches[1][$cids] . $tmp_matches[2][$cids], self::mime_link($y_ctrl_key, $the_message_eml, 'cid_' . $tmp_matches[2][$cids], $y_link, 'image', 'inline'), $tmp_replace_cid_link); //echo '<pre>'.Smart::escape_html($tmp_replace_cid_link).'</pre>'; $val['content'] = str_replace($tmp_matches[0][$cids], $tmp_replace_cid_link, $val['content']); } //end for $tmp_matches = array(); //-- } //end if else //-- $msg['texts'][$key]['content'] = $val['content']; // rewrite back //-- $xbuff = SmartUnicode::sub_str(Smart::striptags($val['content']), 0, 16384); $xbuff_id = $key; //-- $percent_similar = 0; if (strlen($the_part_id) <= 0) { @similar_text($buff, $xbuff, $percent_similar); if ($percent_similar >= 15) { // 15% at least similarity $skips[$buff_id] = $percent_similar; // skip this alternate text part ... } //end if } //end if //-- // clean buffer $buff = ''; $buff_id = ''; //-- } //end if //-- } //end if //-- } //end foreach //-- if ($numparts <= 1) { $skips = array(); // disallow skips if only one part } //end if //-- print bodies except the skipped by similarity $out .= '<hr>'; //-- $cnt = 0; foreach ($msg['texts'] as $key => $val) { //-- if ((string) $val['type'] == 'text') { // assure we don't print other things //-- $cnt += 1; //-- $eval_arr = array(); $eval_arr = SmartFileSysUtils::mime_eval('part_' . $cnt . '.html', 'inline'); //-- $tmp_link_pre = '<span title="Mime Part #' . $cnt . ' ( ' . Smart::escape_html(strtolower($val['mode']) . ' : ' . strtoupper($val['charset'])) . ' )"><a href="' . self::mime_link($y_ctrl_key, $the_message_eml, $key, $y_link, $eval_arr[0], $eval_arr[1], 'minimal') . '" target="' . $y_target . '__mimepart" data-smart="open.modal">'; $tmp_link_pst = '</a></span>'; //-- if (strlen($skips[$key]) <= 0) { // print part if not skipped by similarity ... //-- if ((string) $skip_part_linking == 'yes') { // avoid display sub-text part links when only a part is displayed $tmp_pict_img = ''; } else { $tmp_pict_img = '<div align="right">' . $tmp_link_pre . '<img src="lib/framework/img/mark_right.gif">' . $tmp_link_pst . '</div>'; } //end if //-- if ((string) $y_process_mode == 'data-reply') { if (strlen($reply_text['message']) <= 0) { $reply_text['message'] = (string) $val['content']; } //end if } else { $out .= $tmp_pict_img; $out .= $val['content']; $out .= '<br><hr><br>'; } //end if //-- } else { //-- if ((string) $skip_part_linking != 'yes') { // for replies, avoid display sub-text part links when only a part is displayed if ((string) $y_process_mode == 'data-reply') { // nothing } else { $out .= '<div align="right">' . '<span title="' . '~' . Smart::escape_html(Smart::format_number_dec($skips[$key], 0, '.', ',') . '%') . '"> </span>' . $tmp_link_pre . '<img src="lib/framework/img/mark_check.gif">' . $tmp_link_pst . '</div>'; } //end if else } //end if //-- } //end if else //-- } //end if //-- } //end foreach //-- } //end if //-- $out .= '</div></div><!-- END MIME MESSAGE HTML -->'; //-- } //end if else //-- //-- if ((string) $y_process_mode == 'data-full') { // output an array with message and all header info as data structure //-- return array('message' => (string) $out, 'message-id' => (string) $head['message-id'], 'in-reply-to' => (string) $head['in-reply-to'], 'from' => (string) $head['from_addr'], 'to' => (string) $head['to_addr'], 'cc' => (string) $head['cc_addr'], 'date' => (string) $head['date'], 'atts_num' => (int) $reg_atts_num, 'atts_lst' => (string) $reg_atts_list, 'filepath' => (string) $the_message_eml, 'is_part' => (string) $reg_is_part); //-- } elseif ((string) $y_process_mode == 'data-reply') { // output a special array for replies only //-- $reply_text['message'] = (string) $reply_text['message']; // this comes from above $reply_text['from'] = (string) $head['from_addr']; $reply_text['to'] = (string) $head['to_addr']; $reply_text['cc'] = (string) $head['cc_addr']; $reply_text['date'] = (string) $head['date']; $reply_text['subject'] = (string) $head['subject']; $reply_text['message-id'] = (string) $head['message-id']; $reply_text['in-reply-to'] = (string) $head['in-reply-to']; //-- return (array) $reply_text; //-- } else { // 'default' or 'print' :: message as html view //-- return (string) $out; //-- } //end if //-- }