/** * Class Constructor - will initiate also the LangId.Py Client with the DEFAULT or CUSTOM connection. * * @param ARRAY $cfg :: *OPTIONAL* The Array of Configuration parameters - if not provided will use the DEFAULT config from config.php: $configs['langid']. * */ public function __construct($cfg = array()) { //-- $this->langid_service_cfg = array(); // reset $this->is_service_available = false; // reset //-- if (Smart::array_size($cfg) > 0) { // if config is specified, use it $this->langid_service_cfg = (array) $cfg; } else { // otherwise use the default config $this->langid_service_cfg = (array) Smart::get_from_config('langid'); } //end if else //-- // check for valid configuration array must not be done, if n/a then simply the service is n/a and will return negative value for confidence checks //-- }
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 //-- }
public static function encode_var_post($varname, $value) { //-- $varname = (string) trim((string) $varname); //-- if ((string) $varname == '') { return ''; } //end if //-- $out = ''; //-- if (is_array($value)) { $arrtype = Smart::array_type_test($value); // 0: not an array ; 1: non-associative ; 2:associative if ($arrtype === 1) { // 1: non-associative for ($i = 0; $i < Smart::array_size($value); $i++) { $out .= urlencode($varname) . '[]=' . rawurlencode($value[$i]) . '&'; } //end foreach } else { // 2: associative foreach ($value as $key => $val) { $out .= urlencode($varname) . '[' . rawurlencode($key) . ']=' . rawurlencode($val) . '&'; } //end foreach } //end if else } else { $out = urlencode($varname) . '=' . rawurlencode($value) . '&'; } //end if else //-- return (string) $out; //-- }
/** * Create an active table * * @access private * @internal * * @param STRING $y_size [the table size px / %] * @param STRING $y_title [the table title] * @param ARRAY $y_arr_addlink [associative, 'link', 'title'] :: REPLACEMENTS {{{id}}} * @param ARRAY $y_arr_edtlink [associative, 'link', 'title'] :: REPLACEMENTS {{{id}}} * @param ARRAY $y_arr_dellink [associative, 'link', 'title'] :: REPLACEMENTS {{{id}}} * @param ARRAY $y_arr_fields [non-associative, fields] * @param ARRAY $y_arr_process [non-associative array(0, 1, 2, ...), process ($tmp_id / $value) | associative array( 'objects' => array(0, 1, 2, ...), 'handlers' => array('obj1' => $obj1, obj2=>$obj2, ...) )] * @param ARRAY $y_arr_data [non-associative, data] * * @return STRING [html code] */ public static function table($y_size, $y_title, $y_arr_addlink, $y_arr_edtlink, $y_arr_dellink, $y_arr_fields, $y_arr_process, $y_arr_data, $y_arr_align = array(), $y_arr_width = array(), $y_form_action = array(), $y_form_actoptions = array(), $y_wnd_js = '', $y_form_name = 'smart_table_form', $y_arr_styles = array('heading' => 'smart_active_table_heading', 'subheading' => 'smart_active_table_subheading', 'hilite' => 'smart_active_table_row_hilite', 'alt1' => 'smart_active_table_row_alt1', 'alt2' => 'smart_active_table_row_alt2', 'click' => 'smart_active_table_row_click')) { // [v.150105] // now can handle passed objects //$y_form_actoptions = array(array('button_img'=>'lib/core/img/op_insert.png', 'button_act'=>'action2', 'button_title'=>'Some Action'), array('button_img'=>'lib/core/img/op_edit.png', 'button_act'=>'eeee', 'button_title'=>'Some Other Action')); //-- protection if (Smart::array_size($y_arr_fields) <= 0) { return self::operation_error('WARNING: Build Table has been invoked with a Zero Fields Array !'); } //end if //-- //-- transform the $y_arr_process for handle objects // ths $y_arr_process can be either: // DEFAULT: array(0, 1, 2, ...) // non associative // ADVANCED: array( // 'objects' => array(0, 1, 2, ...), // non associative // 'handlers' => array('obj1' => $obj1, obj2=>$obj2, ...) // ) //-- if (is_array($y_arr_process)) { //-- if (is_array($y_arr_process['handlers']) or is_array($y_arr_process['objects'])) { //-- if (is_array($y_arr_process['handlers'])) { $the_arr_process = (array) $y_arr_process['handlers']; } else { $the_arr_process = array(); } //end if else //-- if (is_array($y_arr_process['objects'])) { //-- foreach ($y_arr_process['objects'] as $key => $val) { eval("\n" . '$obj__' . $key . ' = &$val;' . "\n"); // register local objects } //end foreach //-- } //end if else //-- restore back $y_arr_process = array(); $y_arr_process = (array) $the_arr_process; //-- } //end if //-- } else { //-- $y_arr_process = array(); //-- } //end if //-- //-- if ((string) $y_wnd_js == '' or (string) $y_wnd_js == 'smart_table_detail') { $y_wnd_js = 'smart_table_detail_' . sha1($y_title); } else { $y_wnd_js = (string) $y_wnd_js; } //end if else //-- //-------------------------------------------------------- INITS //-- $color_title = $y_arr_styles['heading']; // #ECECEC $color_subtitle = $y_arr_styles['subheading']; // #FFFFFF $bgcolor_highlight = $y_arr_styles['hilite']; // #DDEEFF $alt_color_one = $y_arr_styles['alt1']; // #FAFAFA $alt_color_two = $y_arr_styles['alt2']; // #F3F3F3 $click_color = $y_arr_styles['click']; // #FFCC00 //-- //-------------------------------------------------------- $out = ''; //-------------------------------------------------------- START $tbl_plus_cols = 2; //-- $translator_core_window = SmartTextTranslations::getTranslator('@core', 'window'); //-- if (Smart::array_size($y_form_action) > 0) { //-- if ((string) $y_form_action['method'] == '') { $y_form_action['method'] = 'post'; $y_form_action['enctype'] = 'multipart/form-data'; } //end if //- if ((string) $y_form_action['target'] == '') { $y_form_action['target'] = '_self'; } //end if //-- if ((string) $y_form_action['jscript'] == '') { $y_form_action['jscript'] = 'onClick=" ' . self::js_draw_html_confirm_form_submit($translator_core_window->text('confirm_action')) . ' "'; } //end if //-- if ((string) $y_form_action['button_img'] == '') { $y_form_action['button_img'] = 'lib/core/img/op_delete.png'; } //end if //-- $out .= '<form class="ux-form" name="' . Smart::escape_html($y_form_name) . '" action="' . Smart::escape_html($y_form_action['action']) . '" method="' . Smart::escape_html($y_form_action['method']) . '" enctype="' . Smart::escape_html($y_form_action['enctype']) . '" target="' . Smart::escape_html($y_form_action['target']) . '">' . "\n"; //-- } //end if else //-- if (Smart::array_size($y_arr_dellink) <= 0) { $tbl_plus_cols = $tbl_plus_cols - 1; } //end if if (Smart::array_size($y_arr_edtlink) <= 0) { $tbl_plus_cols = $tbl_plus_cols - 1; } //end if if (Smart::array_size($y_arr_addlink) > 0) { if (Smart::array_size($y_arr_dellink) > 0 and Smart::array_size($y_arr_edtlink) > 0) { $tbl_plus_cols = 2; // fix again } else { $tbl_plus_cols = 1; // fix again } //end if else } //end if //-- $out .= '<!-- require: activetable.css -->' . "\n"; $out .= '<div style="width:100%;">' . "\n"; // style += overflow:auto; $out .= '<script type="text/javascript">var Smart_Table_Notification_ID;</script>' . "\n"; $out .= '<table id="' . Smart::escape_html($color_subtitle) . '" align="center" width="' . Smart::escape_html($y_size) . '" border="0" cellspacing="1" cellpadding="2" title="' . Smart::escape_html(Smart::striptags($y_title, 'no')) . '">' . "\n"; //-------------------------------------------------------- TITLE $out .= '<tr id="' . Smart::escape_html($color_title) . '">' . "\n"; //-- if (Smart::array_size($y_arr_addlink) > 0) { //-- if (Smart::array_size($y_arr_dellink) > 0 and Smart::array_size($y_arr_edtlink) > 0) { $out .= '<td valign="middle" align="center" colspan="2">' . "\n"; } else { $out .= '<td valign="middle" align="center">' . "\n"; } //end if else //-- if ((string) $y_arr_addlink['target'] != '') { $new_tgt = $y_arr_addlink['target']; } else { $new_tgt = $y_wnd_js; } //end if else //-- if (strlen($y_arr_addlink['custom_picture']) > 0) { eval("\n" . $y_arr_addlink['custom_picture'] . "\n"); $the_add_pict = $add_custom_picture; } else { $the_add_pict = 'lib/core/img/op_insert.png'; } //end if else //-- if (Smart::format_number_int($y_arr_addlink['width']) > 0 and Smart::format_number_int($y_arr_addlink['height']) > 0) { $the_onclick = 'SmartJS_BrowserUtils.PopUpLink(this.href, this.target, ' . Smart::format_number_int($y_arr_addlink['width']) . ', ' . Smart::format_number_int($y_arr_addlink['height']) . ', 0, 1);'; } else { $the_onclick = 'SmartJS_BrowserUtils.PopUpLink(this.href, this.target);'; } //end if else //-- $out .= '<a href="' . Smart::escape_html(str_replace('{{{id}}}', '', $y_arr_addlink['link'])) . '" target="' . Smart::escape_html($new_tgt) . '" onClick="' . $the_onclick . ' return false;"><img src="' . Smart::escape_html($the_add_pict) . '" border="0" title="' . $y_arr_addlink['title'] . '" alt="' . $y_arr_addlink['title'] . '"></a>'; //-- $out .= '</td>' . "\n"; //-- } else { //-- if ((int) $tbl_plus_cols > 0) { //-- if ((int) $tbl_plus_cols > 1) { $out .= '<td valign="middle" align="center" colspan="' . $tbl_plus_cols . '">' . "\n"; } else { $out .= '<td valign="middle" align="center">' . "\n"; } //end if else $out .= ' '; $out .= '</td>' . "\n"; } //end if //-- } //end if else //-- $out .= '<td width="99%" align="left" valign="middle" colspan="' . Smart::array_size($y_arr_fields) . '">' . "\n"; //-- if (strpos($y_title, '<') !== false) { $out .= $y_title; // is html } elseif ((string) $y_title != '') { $out .= '<h1> ' . $y_title . ' </h1>'; } //end if else //-- $out .= '</td>' . "\n"; $out .= '</tr>' . "\n"; //-------------------------------------------------------- EXTRA BUTTONS $extra_bttns = ''; if (Smart::array_size($y_form_action) > 0) { $extra_bttns .= '<td><table width="50%" cellpadding="0" cellspacing="0">'; if (Smart::array_size($y_form_actoptions) > 0) { $extra_bttns .= '<tr>' . "\n"; $extra_bttns .= '<td align="left" valign="middle" colspan="' . Smart::array_size($y_arr_fields) . '">' . "\n"; for ($i = 0; $i < Smart::array_size($y_form_actoptions); $i++) { $the_actopts_arr = $y_form_actoptions[$i]; if ((string) $the_actopts_arr['jscript'] == '') { $the_actopts_arr['jscript'] = 'onClick=" ' . self::js_draw_html_confirm_form_submit($translator_core_window->text('confirm_action')) . ' "'; } //end if $extra_bttns .= '<input type="image" id="bttn_f_action' . $i . '" name="bttn_f_action" value="' . Smart::escape_html($the_actopts_arr['button_act']) . '" src="' . Smart::escape_html($the_actopts_arr['button_img']) . '" ' . $the_actopts_arr['jscript'] . ' style="border:none" title="' . $the_actopts_arr['button_title'] . '" alt="' . $the_actopts_arr['button_title'] . '"> '; } //end for $extra_bttns .= '</td>' . "\n"; $extra_bttns .= '</tr>' . "\n"; } //end if $extra_bttns .= '</table></td>'; //-- $the_hd_size_del = '32'; $the_hd_size_edt = '32'; //-- } else { //-- if (Smart::array_size($y_arr_dellink) > 0) { $the_hd_size_del = '32'; } else { $the_hd_size_del = '1'; } //end if else //-- if (Smart::array_size($y_arr_edtlink) > 0) { $the_hd_size_edt = '32'; } else { $the_hd_size_edt = '1'; } //end if else //-- } //end if else //-------------------------------------------------------- HEADING $out .= '<tr>' . "\n"; if (Smart::array_size($y_form_action) > 0) { $out .= '<td width="' . Smart::format_number_int($the_hd_size_del + $the_hd_size_edt) . '" align="center" colspan="2">' . "\n"; $out .= '<table border="0" cellspacing="0" cellpadding="2"><tr>'; $out .= '<td width="' . Smart::format_number_int($the_hd_size_del) . '"><input type="checkbox" name="' . Smart::escape_html($y_form_name) . '_toggle" value="" onClick="this.checked=!this.checked;' . self::js_draw_checkbox_checkall($y_form_name) . '">' . '</td>' . "\n"; $out .= '<td width="' . Smart::format_number_int($the_hd_size_edt) . '"><input type="image" id="bttn_f_action" name="bttn_f_action" value="' . Smart::escape_html($y_form_action['button_act']) . '" src="' . Smart::escape_html($y_form_action['button_img']) . '" ' . $y_form_action['jscript'] . ' style="border:none" title="' . $y_form_action['button_title'] . '" alt="' . $y_form_action['button_title'] . '"></td>' . "\n"; $out .= '</tr></table>'; $out .= '</td>' . "\n"; } else { if (Smart::array_size($y_arr_dellink) > 0 and Smart::array_size($y_arr_edtlink) > 0) { $out .= '<td width="' . Smart::format_number_int($the_hd_size_del + $the_hd_size_edt) . '" align="center" colspan="2">' . "\n"; $out .= ''; $out .= '</td>' . "\n"; } elseif (Smart::array_size($y_arr_dellink) > 0) { $out .= '<td width="' . Smart::format_number_int($the_hd_size_del) . '" align="center">' . "\n"; $out .= ''; $out .= '</td>' . "\n"; } elseif (Smart::array_size($y_arr_edtlink) > 0) { $out .= '<td width="' . Smart::format_number_int($the_hd_size_edt) . '" align="center">' . "\n"; $out .= ''; $out .= '</td>' . "\n"; } else { // nothing } //end if else } //end if else //-- for ($i = 0; $i < Smart::array_size($y_arr_fields); $i++) { $out .= '<td align="center" valign="middle" width="' . Smart::escape_html($y_arr_width[$i]) . '">' . "\n"; $out .= '<table width="100%" border="0"><tr>'; if ($i == 0) { if (Smart::array_size($y_form_action) > 0) { $out .= $extra_bttns; } //end if } //end if $out .= '<td align="center"><b>' . $y_arr_fields[$i] . '</b></td>'; $out .= '</tr></table>'; $out .= '</td>' . "\n"; } //end for //-- $out .= '</tr>' . "\n"; //-------------------------------------------------------- DATA $the_alt_cnt = 0; for ($n = 0; $n < Smart::array_size($y_arr_data); $n++) { //-- $the_alt_cnt += 1; if ($the_alt_cnt % 2) { $the_alt_color = $alt_color_two; } else { $the_alt_color = $alt_color_one; } //end else //-- $tmp_id = $y_arr_data[$n]; // the id must be get first //-- $out .= '<tr valign="top" ' . self::table_active_row($the_alt_color, $bgcolor_highlight, $click_color) . '>' . "\n"; //-- if (Smart::array_size($y_form_action) > 0) { //-- $out .= '<td align="center" width="' . Smart::format_number_int($the_hd_size_del) . '">' . "\n"; $out .= '<input type="checkbox" name="id[]" value="' . Smart::escape_html($tmp_id) . '">'; $out .= '</td>' . "\n"; //-- } else { //-- if (Smart::array_size($y_arr_dellink) > 0) { //-- $out .= '<td align="center" width="' . Smart::format_number_int($the_hd_size_del) . '" onClick="this.parentNode.title=\'**\';">' . "\n"; //-- if (strlen($y_arr_dellink['custom_picture']) > 0) { eval("\n" . $y_arr_dellink['custom_picture'] . "\n"); $the_del_pict = $delete_custom_picture; } else { $the_del_pict = 'lib/core/img/op_delete.png'; } //end if else //-- if (Smart::format_number_int($y_arr_dellink['width']) > 0 and Smart::format_number_int($y_arr_dellink['height']) > 0) { $the_onclick = 'SmartJS_BrowserUtils.PopUpLink(this.href, this.target, ' . Smart::format_number_int($y_arr_dellink['width']) . ', ' . Smart::format_number_int($y_arr_dellink['height']) . ', 0, 1);'; } else { $the_onclick = 'SmartJS_BrowserUtils.PopUpLink(this.href, this.target);'; } //end if else //-- $out .= '<a href="' . Smart::escape_html(str_replace('{{{id}}}', rawurlencode($tmp_id), $y_arr_dellink['link'])) . '" target="' . 'del__' . Smart::escape_html($y_wnd_js) . '" onClick="' . $the_onclick . ' return false;"><img src="' . Smart::escape_html($the_del_pict) . '" border="0" title="' . $y_arr_dellink['title'] . '" alt="' . $y_arr_dellink['title'] . '"></a>'; //-- $out .= '</td>' . "\n"; //-- } //end if //-- } //end if else //-- if (Smart::array_size($y_arr_edtlink) > 0) { //-- $out .= '<td align="center" width="' . Smart::format_number_int($the_hd_size_edt) . '" onClick="this.parentNode.title=\'**\';">' . "\n"; // disable onclick for parent row (fix) //-- if (strlen($y_arr_edtlink['custom_picture']) > 0) { eval("\n" . $y_arr_edtlink['custom_picture'] . "\n"); $the_edt_pict = $edit_custom_picture; } else { $the_edt_pict = 'lib/core/img/op_edit.png'; } //end if else //-- if (Smart::format_number_int($y_arr_edtlink['width']) > 0 and Smart::format_number_int($y_arr_edtlink['height']) > 0) { $the_onclick = 'SmartJS_BrowserUtils.PopUpLink(this.href, this.target, ' . Smart::format_number_int($y_arr_edtlink['width']) . ', ' . Smart::format_number_int($y_arr_edtlink['height']) . ', 0, 1);'; } else { $the_onclick = 'SmartJS_BrowserUtils.PopUpLink(this.href, this.target);'; } //end if else //-- $out .= '<a href="' . Smart::escape_html(str_replace('{{{id}}}', rawurlencode($tmp_id), $y_arr_edtlink['link'])) . '" target="' . 'edt__' . Smart::escape_html($y_wnd_js) . '_' . sha1(date('Y-m-d H:i:s') . $tmp_id) . '" onClick="' . $the_onclick . ' return false;"><img src="' . Smart::escape_html($the_edt_pict) . '" border="0" title="' . $y_arr_edtlink['title'] . '" alt="' . $y_arr_edtlink['title'] . '"></a>'; //-- $out .= '</td>' . "\n"; //-- } //end if //-- $a = 0; for ($i = 0; $i < Smart::array_size($y_arr_fields); $i++) { //-- $the_align = 'center'; if ((string) $y_arr_align[$a] != '') { $the_align = $y_arr_align[$a]; } // end if //-- $a += 1; //-- $kk = $i + $n; $value = $y_arr_data[$kk]; //-- $out .= '<td align="' . $the_align . '">' . "\n"; if ((string) $y_arr_process[$i] == '') { $out .= Smart::escape_html($value); } else { eval("\n" . $y_arr_process[$i] . "\n"); $out .= $value; } //end if else //-- $out .= '</td>' . "\n"; //-- } //end for //-- $out .= '</tr>' . "\n"; //-- $n += Smart::array_size($y_arr_fields) - 1; // salt //-- } //end for //-------------------------------------------------------- END LINE $out .= '<tr id="' . $color_title . '">' . "\n"; //-- if ((int) $tbl_plus_cols > 0) { //-- if ((int) $tbl_plus_cols > 1) { $out .= '<td valign="middle" align="center" colspan="' . $tbl_plus_cols . '">' . "\n"; } else { $out .= '<td valign="middle" align="center">' . "\n"; } //end if else $out .= '<font size="1"> </font>'; $out .= '</td>' . "\n"; //-- } else { // nothing } //end if else //-- $out .= '<td width="99%" align="center" valign="middle" colspan="' . Smart::array_size($y_arr_fields) . '">' . "\n"; $out .= '<font size="1"> </font>'; $out .= '</td>' . "\n"; $out .= '</tr>' . "\n"; //-------------------------------------------------------- END $out .= '</table>' . "\n"; $out .= '</div>' . "\n"; //-- if (Smart::array_size($y_form_action) > 0) { $out .= '</form>' . "\n"; } //end if //-------------------------------------------------------- //-- return $out; //-- }
private function _boundarySplit($input, $boundary) { //-- $tmp = (array) explode('--' . $boundary, (string) $input); //-- for ($i = 1; $i < Smart::array_size($tmp); $i++) { $parts[] = $tmp[$i]; } //end for //-- return $parts; //-- }
private static function print_log_modules($title, $modules_log) { //-- $log = ''; //-- $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_head"><font size="4"><b>' . Smart::escape_html($title) . ' :: MODULE Log</b></font></div>'; //-- $max = Smart::array_size($modules_log); if (is_array($modules_log) and $max > 0) { //-- $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_highlight" style="width:450px;">Total Entries: <b>' . Smart::escape_html($max) . '</b></div>'; //-- for ($i = 0; $i < $max; $i++) { //-- $tmp_arr = (array) $modules_log[$i]; //-- $log .= '<div class="smartframework_debugbar_inforow" style="font-size:11px; color:#000000;">'; $log .= '<b>' . Smart::escape_html((string) $tmp_arr['title']) . '</b><br>'; $log .= '<pre style="font-size:11px; color:#000000;">' . Smart::escape_html(str_replace(array("\r\n", "\r", "\t"), array("\n", "\n", ' '), trim((string) $tmp_arr['data']))) . '</pre>'; $log .= '</div>'; //-- } //end for //-- } else { //-- $log .= '<div class="smartframework_debugbar_status smartframework_debugbar_status_warn" style="width: 100px; text-align: center;"><font size="2"><b>N/A</b></font></div>'; //-- } //end if //-- return $log; //-- }
public static function create_table($db, $table_name, $table_schema, $table_indexes = array()) { //-- samples // $table_indexes = ''; // $table_indexes = 'date_time ASC, status_delete, status_read'; // $table_indexes = array('idx_uidls' => 'date_time ASC, status_delete, status_read'); //-- self::check_connection($db); //-- the create table query $tbl_query = "CREATE TABLE {$table_name} ({$table_schema});"; //-- $idx_query = ''; //-- if (is_array($table_indexes) and Smart::array_size($table_indexes) > 0) { //-- foreach ($table_indexes as $key => $val) { $idx_query .= ' CREATE INDEX ' . $key . ' ON ' . $table_name . ' (' . $val . ');'; } //end for //-- } //end if //-- $query = (string) $tbl_query . $idx_query; //-- $sqlite_table_exists = self::check_if_table_exists($db, $table_name); //-- if ($sqlite_table_exists != 1) { // if test failed means table is not available self::write_data($db, $query); // this will die with message if query have errors } //end if //-- }
public function addDocument($arrdoc, $use_autocommit = 0) { //-- $connect = $this->solr_connect(); //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { //-- SmartFrameworkRegistry::setDebugMsg('db', 'solr|total-queries', 1, '+'); //-- $time_start = microtime(true); //-- } //end if //-- if (!is_array($arrdoc)) { Smart::log_warning('Solr ERROR # addDocument # ' . 'Document is not Array'); return -100; } //end if //-- if (Smart::array_size($arrdoc) <= 0) { Smart::log_warning('Solr ERROR # addDocument # ' . 'Document Array is empty !'); return -101; } //end if //-- $doc = new SolrInputDocument(); //-- foreach ($arrdoc as $key => $val) { //-- if (is_array($val)) { foreach ($val as $k => $v) { $doc->addField((string) $key, (string) $v); } //end foreach } else { $doc->addField((string) $key, (string) $val); } //end if //-- } //end foreach //-- try { //-- if ((int) $use_autocommit > 0) { $updateResponse = $this->instance->addDocument($doc, true, (int) $use_autocommit); } else { $updateResponse = $this->instance->addDocument($doc, true, 0); $this->instance->commit(); // save } //end if else //-- } catch (Exception $e) { //-- Smart::log_warning('Solr ERROR # addDocument # EXCEPTION: ' . $e->getMessage() . "\n" . print_r($arrdoc, 1)); return -201; //-- } //end try catch //-- $response = $updateResponse->getResponse(); // get answer message //print_r($response); //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { //-- $time_end = (double) (microtime(true) - (double) $time_start); //-- SmartFrameworkRegistry::setDebugMsg('db', 'solr|total-time', $time_end, '+'); //-- SmartFrameworkRegistry::setDebugMsg('db', 'solr|log', ['type' => 'nosql', 'data' => 'ADD-UPDATE-QUERY', 'command' => $arrdoc, 'time' => Smart::format_number_dec($time_end, 9, '.', '')]); //-- } //end if //-- if (is_object($response)) { if ($response instanceof SolrObject) { if (is_object($response['responseHeader'])) { if ($response['responseHeader'] instanceof SolrObject) { if ($response['responseHeader']->status === 0) { // OK } else { Smart::log_warning('Solr ERROR # addDocument # Invalid Status (' . $response['responseHeader']->status . ') : ' . print_r($arrdoc, 1)); return -206; } //end if else } else { Smart::log_warning('Solr ERROR # addDocument # Invalid responseHeader / Not instanceof SolrObject: ' . print_r($arrdoc, 1)); return -205; } //end if else } else { Smart::log_warning('Solr ERROR # addDocument # Invalid responseHeader / Invalid Object: ' . print_r($arrdoc, 1)); return -204; } //end if else } else { Smart::log_warning('Solr ERROR # addDocument # Invalid Answer / Not instanceof SolrObject: ' . print_r($arrdoc, 1)); return -203; } //end if else } else { Smart::log_warning('Solr ERROR # addDocument # Not Object: ' . print_r($arrdoc, 1)); return -202; } //end if else //-- return 0; // OK //-- }
/** * Parse Simple Notes :: '-----< yyyy-mm-dd hh:ii:ss >----- some note\nsome other line' * * @param STRING $ynotes :: The Text or HTML to be processed * @param YES/NO $y_hide_times :: Show / Hide the time stamps * @param #SIZE $y_tblsize :: HTML Table Size * @param #COLOR $ytxtcolor :: HTML Table Color for Text * @param #COLOR $ycolor :: HTML Table Row Color * @param #COLOR $ycolor_alt :: HTML Table Row Alternate Color * @param #COLOR $ybrdcolor :: HTML Table Border Color * @param #STYLE $y_style :: HTML Extra Style * * @access private * @internal * * @return STRING :: The HTML processed code */ public static function simple_notes($ynotes, $y_hide_times, $y_tblsize = '100%', $ytxtcolor = '#000000', $ycolor = '#FFFFFF', $ycolor_alt = '#FFFFFF', $ybrdcolor = '#CCCCCC', $y_style = ' style="overflow: auto; height:200px;"') { //-- if (strpos((string) $ynotes, '-----<') === false) { return $tbl_start . '<tr><td bgcolor="' . $ycolor . '" valign="top"><font size="1">' . Smart::nl_2_br(Smart::escape_html($ynotes)) . '</font></td></tr>' . $tbl_end; // not compatible notes, so we not parse them } //end if //-- $out = ''; //-- $tbl_start = '<table width="' . $y_tblsize . '" cellspacing="0" cellpadding="2" border="1" bordercolor="' . $ybrdcolor . '" style="border-style: solid; border-collapse: collapse;">' . "\n"; $tbl_end = '</table>'; //-- $tmp_shnotes_arr = (array) explode('-----<', (string) $ynotes); //-- $i_alt = 0; //-- if (Smart::array_size($tmp_shnotes_arr) > 0) { //-- $out .= '<!-- OVERFLOW START (S.NOTES) -->' . '<div title="#S.NOTES#"' . $y_style . '>' . "\n"; $out .= $tbl_start; //-- for ($i = 0; $i < Smart::array_size($tmp_shnotes_arr); $i++) { //-- $tmp_shnotes_arr[$i] = (string) trim((string) $tmp_shnotes_arr[$i]); //-- if (Smart::striptags(str_replace('-----<', '', (string) $tmp_shnotes_arr[$i])) != '') { //-- $tmp_expld = (array) explode('>-----', (string) $tmp_shnotes_arr[$i]); //-- $tmp_meta_expl = (array) explode('|', (string) $tmp_expld[0]); $tmp_meta_date = trim((string) $tmp_meta_expl[0]); if (strlen(trim((string) $tmp_meta_expl[1])) > 0) { $tmp_metainfo = ' :: ' . trim($tmp_meta_expl[1]); } else { $tmp_metainfo = ''; } //end if else //-- if (strlen(trim((string) $tmp_expld[1])) > 0) { //-- $i_alt += 1; //-- alternate if ($i_alt % 2) { $alt_color = $ycolor; } else { $alt_color = $ycolor_alt; } //end if else //-- $out .= '<tr>' . "\n"; $out .= '<td bgcolor="' . $alt_color . '" valign="top">' . "\n"; //-- if ((string) $y_hide_times != 'yes') { $out .= '<div align="right" title="' . Smart::escape_html('#' . $i_alt . '.' . $tmp_metainfo) . '"><font size="1" color="' . $ytxtcolor . '"><b>' . Smart::escape_html($tmp_meta_date) . '</b></font></div><font size="1" color="' . $ytxtcolor . '">' . Smart::nl_2_br(Smart::escape_html(trim($tmp_expld[1]))) . '</font>'; } else { $out .= '<div title="' . Smart::escape_html('#' . $i_alt . '. ' . $tmp_meta_date . $tmp_metainfo) . '"><font size="1" color="' . $ytxtcolor . '">' . Smart::nl_2_br(Smart::escape_html(trim($tmp_expld[1]))) . '</font></div>'; } //end if else //-- $out .= '</td>' . "\n"; $out .= '</tr>' . "\n"; //-- } //end if //-- } //end if //-- } //end for //-- $out .= $tbl_end; $out .= '</div>' . '<!-- OVERFLOW END (S.NOTES) -->' . "\n"; //-- } //end if //-- if ($i_alt <= 0) { $out = ''; } //end if //-- return $out; //-- }
/** * Generate a PDF Document on the fly from a piece of HTML code. * * Notice: this is using a secured cache folder, unique per visitor ID * * @param STRING $y_html_content :: The HTML Code * @param ENUM $y_orientation :: Page Orientation: 'normal' | 'wide' * @param STRING $y_runtime_script :: The allowed Runtime Script to allow send credentials for sub-downloads. Ex: admin.php * @param STRING $y_runtime_url :: The allowed Runtime URL ended by '/' to allow send credentials for sub-downloads. Ex: http(s)://some-server/some_path/ ; normally this should be set in config to enforce https:// and a single URL only * @param BOOLEAN $y_allow_send_credentials :: Set to TRUE to allow or set to FALSE to dissalow sending the auth credentials for sub-downloads: in the case there are embedded pictures generated by admin.php which may need authentication before to work, the credentials need to be set automatically in this case * * @returns STRING :: The PDF Document Contents * */ public static function generate($y_html_content, $y_orientation = 'normal', $y_runtime_script = '', $y_runtime_url = '', $y_allow_send_credentials = false) { //-- $pdfdata = ''; //-- $htmldoc = self::is_active(); //-- if ((string) $htmldoc != '') { //-- if ((string) $y_orientation == 'wide') { $orientation = self::tag_page_wide(); } else { $orientation = self::tag_page_normal(); } //end if else //-- $tmp_prefix_dir = 'tmp/cache/pdf/'; $protect_file = $tmp_prefix_dir . '.htaccess'; $dir = $tmp_prefix_dir . SMART_FRAMEWORK_SESSION_PREFIX . '/'; // we use different for index / admin / @ //-- $uniquifier = SmartUtils::unique_auth_client_private_key() . SMART_APP_VISITOR_COOKIE; $the_dir = $dir . Smart::safe_varname(Smart::uuid_10_seq() . '_' . Smart::uuid_10_num() . '_' . SmartHashCrypto::sha1($uniquifier)) . '/'; //-- $tmp_uuid = Smart::uuid_45($uniquifier) . Smart::uuid_36($uniquifier); $file = $the_dir . '__document_' . SmartHashCrypto::sha256('@@PDF#File::Cache@@' . $tmp_uuid) . '.html'; $logfile = $the_dir . '__headers_' . SmartHashCrypto::sha256('@@PDF#File::Cache@@' . $tmp_uuid) . '.log'; //-- if (is_dir($the_dir)) { SmartFileSystem::dir_delete($the_dir); } //end if //-- if (!is_dir($the_dir)) { SmartFileSystem::dir_recursive_create($the_dir); } // end if //-- SmartFileSystem::write_if_not_exists($protect_file, trim(SMART_FRAMEWORK_HTACCESS_FORBIDDEN) . "\n", 'yes'); //-- process the code $y_html_content = (string) self::remove_between_tags((string) $y_html_content); $y_html_content = (string) self::safe_charset((string) $y_html_content); //-- extract images $htmlparser = new SmartHtmlParser((string) $y_html_content); $arr_imgs = $htmlparser->get_tags('img'); $htmlparser = ''; unset($htmlparser); //-- $chk_duplicates_arr = array(); //-- for ($i = 0; $i < Smart::array_size($arr_imgs); $i++) { //-- $tmp_img_src = trim((string) $arr_imgs[$i]['src']); //-- if (strlen($chk_duplicates_arr[$tmp_img_src]) <= 0) { //-- $tmp_url_img_src = ''; //-- if ((string) $y_runtime_script != '' and (string) $y_runtime_url != '') { // replace relative paths if (substr($tmp_img_src, 0, @strlen($y_runtime_script)) == (string) $y_runtime_script) { $tmp_url_img_src = (string) $y_runtime_url . $tmp_img_src; $y_html_content = (string) @str_replace('src="' . $tmp_img_src . '"', 'src="' . $tmp_url_img_src . '"', (string) $y_html_content); $tmp_img_src = (string) $tmp_url_img_src; } //end if } //end if //-- $tmp_img_ext = '.' . strtolower(SmartFileSysUtils::get_file_extension_from_path($tmp_img_src)); // [OK] $tmp_img_cache = 'pdf_img_' . SmartHashCrypto::sha256('@@PDF#File::Cache::IMG@@' . '#' . $i . '@' . $tmp_img_src . '//' . $tmp_uuid); //-- $tmp_arr = array(); //-- if (substr($tmp_img_src, 0, 7) == 'http://' or substr($tmp_img_src, 0, 8) == 'https://') { //-- $tmp_img_ext = ''; // we clear the extension as we don't know yet (we will get it from headers) $tmp_img_cache = 'pdf_url_img_' . SmartHashCrypto::sha256('@@PDF#File::Cache::URL::IMG@@' . '#' . $i . '@' . $tmp_img_src . '//' . $tmp_uuid); //-- } //end if //-- if ($y_allow_send_credentials === true) { $allow_set_credentials = 'yes'; } else { $allow_set_credentials = 'no'; } //end if else //-- $tmp_arr = SmartUtils::load_url_or_file($tmp_img_src, SMART_FRAMEWORK_NETSOCKET_TIMEOUT, 'GET', '', '', '', $allow_set_credentials); // [OK] :: allow set credentials //-- $tmp_img_ext = '.noextension'; $tmp_where_we_guess = ''; //-- $guess_arr = array(); //-- $guess_arr = SmartUtils::guess_image_extension_by_url_head($tmp_arr['headers']); $tmp_img_ext = (string) $guess_arr['extension']; $tmp_where_we_guess = (string) $guess_arr['where-was-detected']; $guess_arr = array(); if ((string) $tmp_img_ext == '') { $tmp_img_ext = SmartUtils::guess_image_extension_by_first_bytes(substr($tmp_arr['content'], 0, 256)); if ((string) $tmp_img_ext != '') { $tmp_where_we_guess = ' First Bytes ...'; } //end if } //end if //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { // if debug, append information to log SmartFileSystem::write($logfile, '####################' . "\n" . '#################### [FILE # ' . $i . ' = \'' . $tmp_img_src . '\']' . "\n\n" . '==== [MODE] :: ' . $tmp_arr['mode'] . "\n" . '==== [LOG] :: ' . "\n" . $tmp_arr['log'] . "\n" . '==== [HEADERS] ::' . "\n" . $tmp_arr['headers'] . "\n" . '########' . "\n" . '==== [GUESS EXTENSION] :: ' . $tmp_where_we_guess . "\n\n" . '###################' . "\n\n\n\n", 'a'); } //end if //-- if ((string) $tmp_arr['result'] == '1' and (string) $tmp_arr['code'] == '200') { //-- SmartFileSystem::write($the_dir . $tmp_img_cache . $tmp_img_ext, $tmp_arr['content']); //-- if empty, it may be a file if ((string) $tmp_img_ext == '' or (string) $tmp_img_ext == '.png' or (string) $tmp_img_ext == '.gif' or (string) $tmp_img_ext == '.jpg') { $y_html_content = (string) @str_replace('src="' . $tmp_img_src . '"', 'src="' . $tmp_img_cache . $tmp_img_ext . '"', (string) $y_html_content); } else { // we want to avoid html code to be loaded as image by mistakes of http browser class or servers $y_html_content = (string) @str_replace('src="' . $tmp_img_src . '"', 'src="' . $y_runtime_url . 'lib/framework/img/sign_warn.png"', (string) $y_html_content); } //end if else //-- } else { //-- $y_html_content = (string) @str_replace('src="' . $tmp_img_src . '"', 'src="' . $y_runtime_url . 'lib/framework/img/sign_error.png"', (string) $y_html_content); //-- } //end if //-- } //end if //-- $chk_duplicates_arr[$tmp_img_src] = 'processed'; //-- } //end for //-- $chk_duplicates_arr = array(); unset($chk_duplicates_arr); $arr_imgs = array(); unset($arr_imgs); //-- SmartFileSystem::write($file, $orientation . "\n" . $y_html_content); //-- if (is_file($file)) { //-- ob_start(); //-- @passthru($htmldoc . ' ' . self::pdf_options($file)); //-- $pdfdata = ob_get_clean(); //-- } else { //-- Smart::log_warning('ERROR: PDF Generator Failed to find the PDF Document: ' . $file . "\n" . $y_html_content); //-- } //end if else //-- cleanup if ((string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') { // if not debug, cleanup the dir if (is_dir($the_dir)) { SmartFileSystem::dir_delete($the_dir); } //end if } //end if //-- } else { //-- Smart::log_notice('NOTICE: PDF Generator is INACTIVE ...'); //-- } //end if //-- return (string) $pdfdata; //-- }
private static function _iplist_get_last_address($ip) { //-- if ((string) $ip == '') { return ''; } //end if //-- if (strpos((string) $ip, ',') !== false) { // if we detect many IPs in a header //-- $arr = explode(',', (string) $ip); $ip = ''; // we clear it //-- $imax = Smart::array_size($arr); if ($imax > 1) { //-- for ($i = $imax; $i > 0; $i--) { // loop backward //-- $tmp_ip = (string) SmartValidator::validate_filter_ip_address(trim((string) $arr[$i])); // this returns empty if no valid IP //-- if (strlen($tmp_ip) >= 7 and strlen($tmp_ip) <= 39) { // valid IP must be in this range $ip = (string) $tmp_ip; break; } //end if //-- } //end for //-- } //end if //-- } else { //-- $ip = (string) SmartValidator::validate_filter_ip_address((string) $ip); //-- } //end if //-- return (string) $ip; //-- }
private function SimpleXML2Array($sxml) { //-- if (!is_object($sxml)) { return array(); } //end if //-- $array = (array) $sxml; $sxml = array(); //-- recursive Parser foreach ($array as $key => $value) { if (is_object($value)) { if (strpos(get_class($value), 'SimpleXML') !== false) { $tmp_val = $this->SimpleXML2Array($value); if (is_array($tmp_val)) { if (Smart::array_size($tmp_val) <= 0) { $array[(string) $key] = ''; // FIX: avoid return empty XML key as array() in SimpleXML (empty XML key should be returned as empty string) } else { $array[(string) $key] = (array) $tmp_val; } //end if } else { $array[(string) $key] = (string) $tmp_val; } //end if else } //end if } //end if } //end foreach //-- return (array) $array; //-- }
private function answer($result, $url, $ssl_version, $user, $curl_getinfo = array()) { //-- return array('client' => (string) __CLASS__, 'date-time' => (string) date('Y-m-d H:i:s O'), 'protocol' => (string) $this->protocol, 'method' => (string) $this->method, 'url' => (string) $url, 'ssl' => (string) $ssl_version, 'auth-user' => (string) $user, 'cookies-len' => (int) Smart::array_size($this->cookies), 'post-vars-len' => (int) Smart::array_size($this->postvars), 'post-str-len' => (int) strlen($this->poststring), 'json-req-len' => (int) strlen($this->jsonrequest), 'xml-req-len' => (int) strlen($this->jsonrequest), 'mode' => (string) trim((string) $this->url_parts['protocol']), 'result' => (int) $result, 'code' => (string) $this->status, 'headers' => (string) $this->header, 'content' => (string) $this->body, 'log' => (string) 'User-Agent: ' . $this->useragent . "\n", 'debuglog' => (string) $this->log, 'curl-proxy' => (array) $this->cproxy, 'curl-info' => (array) $curl_getinfo); //-- }
private function build_multipart() { //-- $timeduid = Smart::uuid_10_seq(); // 10 chars, timed based, can repeat only once in 1000 years for the same millisecond $timedrid = strrev($timeduid); $entropy = Smart::unique_entropy('mail/send'); // this generate a very random value $boundary = '_===-Mime.Part____.' . $timeduid . '_' . md5('@MimePart---#Boundary@' . $entropy) . '_P_.-=_'; // 69 chars of 70 max $relatedboundary = '_-==-Mime.Related_.' . $timedrid . '_' . md5('@MimeRelated#Boundary@' . $entropy) . '_R_.=-_'; // 69 chars of 70 max //-- $multipart = ''; $multipart .= 'Content-Type: multipart/mixed; boundary="' . $boundary . '"' . "\r\n" . "\r\n"; $multipart .= 'This is a multi-part message in MIME format.' . "\r\n" . "\r\n"; $multipart .= '--' . $boundary . "\r\n"; $multipart .= 'Content-Type: multipart/related; boundary="' . $relatedboundary . '"' . "\r\n"; //-- cid parts $multipart .= "\r\n"; for ($i = Smart::array_size($this->parts) - 1; $i >= 0; $i--) { $multipart .= '--' . $relatedboundary . "\r\n"; $multipart .= $this->build_message($this->parts[$i]); } //end for $multipart .= "\r\n"; $multipart .= '--' . $relatedboundary . '--' . "\r\n"; //-- attachments $multipart .= "\r\n"; for ($i = Smart::array_size($this->atts) - 1; $i >= 0; $i--) { $multipart .= '--' . $boundary . "\r\n"; $multipart .= $this->build_message($this->atts[$i]); } //end for //-- $multipart .= "\r\n"; $multipart .= '--' . $boundary . '--' . "\r\n"; //-- return $multipart; //-- }
/** * Unset a Key into the persistent Cache * * @param STRING $y_realm The Cache Realm * @param STRING $y_key The Cache Key ; Use * for All Keys in that Realm * * @return BOOLEAN Returns True if the key(s) was/were unset or false if not */ public static function unsetKey($y_realm, $y_key) { //-- if (!self::isActive()) { return false; } //end if //-- if (!self::validateRealm((string) $y_realm)) { Smart::log_warning('Persistent Cache / Invalid Realm: ' . $y_realm); return false; } //end if if ((string) $y_key != '*') { if (!self::validateKey((string) $y_key)) { Smart::log_warning('Persistent Cache / Invalid Key: ' . $y_key); return false; } //end if } //end if //-- self::initCacheManager(); //-- if ((string) $y_realm == '') { return (bool) self::$redis->del((string) $y_key); } else { if ((string) $y_key != '*') { return (bool) self::$redis->del((string) $y_realm . ':' . $y_key); } else { $rarr = (array) self::$redis->keys((string) $y_realm . ':*'); $err = 0; if (Smart::array_size($rarr) > 0) { foreach ($rarr as $key => $rark) { if ((string) $rark != '') { $del = self::$redis->del((string) $rark); if ($del <= 0) { $err++; } //end if } //end if } //end foreach } //end if if ($err > 0) { return false; } else { return true; } //end if else } //end if } //end if else //-- }
/** * this is for disconnect from MongoDB * * @access private * @internal * */ public function disconnect() { //-- if (!is_object($this->mongoclient)) { return null; } //end if //-- $the_conn_key = (string) $this->server . '@' . $this->db . ':' . $this->collection; //-- if (array_key_exists((string) $the_conn_key, (array) SmartFrameworkRegistry::$Connections['mongodb'])) { if (Smart::array_size(SmartFrameworkRegistry::$Connections['mongodb'][(string) $the_conn_key]) > 0) { //-- foreach (SmartFrameworkRegistry::$Connections['mongodb'][(string) $the_conn_key] as $c) { //-- $this->mongoclient->close($c['hash']); //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { //-- SmartFrameworkRegistry::setDebugMsg('db', 'mongodb|log', ['type' => 'open-close', 'data' => 'MongoDB Connection Closed :: Resource-Hash: ' . $c['hash']]); //-- } //end if //-- } //end foreach //-- } //end if } //end if //-- }
private function addArray($incoming_data, $incoming_indent) { //-- // print_r ($incoming_data); //-- if (Smart::array_size($incoming_data) > 1) { return $this->addArrayInline($incoming_data, $incoming_indent); } //end if //-- $key = key($incoming_data); $value = isset($incoming_data[$key]) ? $incoming_data[$key] : null; if ($key === '__!YAMLZero') { $key = '0'; } //end if //-- if ($incoming_indent == 0 && !$this->yaml_contains_group_alias && !$this->yaml_contains_group_anchor) { // Shortcut for root-level values. if ($key || $key === '' || $key === '0') { $this->result[$key] = $value; } else { $this->result[] = $value; end($this->result); $key = key($this->result); } //end if else $this->path[$incoming_indent] = $key; return; } //end if //-- $history = array(); //-- Unfolding inner array tree. $history[] = $tmp_arr = $this->result; foreach ($this->path as $z => $k) { $history[] = $tmp_arr = $tmp_arr[$k]; } //end foreach //-- if ($this->yaml_contains_group_alias) { $value = $this->referenceContentsByAlias($this->yaml_contains_group_alias); $this->yaml_contains_group_alias = false; } //end if //-- Adding string or numeric key to the innermost level or $this->arr. if (is_string($key) && $key == '<<') { if (!is_array($tmp_arr)) { $tmp_arr = array(); } //end if $tmp_arr = array_merge($tmp_arr, $value); } elseif ($key || $key === '' || $key === '0') { if (!is_array($tmp_arr)) { $tmp_arr = array($key => $value); } else { $tmp_arr[$key] = $value; } //end if else } else { if (!is_array($tmp_arr)) { $tmp_arr = array($value); $key = 0; } else { $tmp_arr[] = $value; end($tmp_arr); $key = key($tmp_arr); } //end if else } //end if else //-- $reverse_path = array_reverse($this->path); $reverse_history = array_reverse($history); $reverse_history[0] = $tmp_arr; $cnt = Smart::array_size($reverse_history) - 1; for ($i = 0; $i < $cnt; $i++) { $reverse_history[$i + 1][$reverse_path[$i]] = $reverse_history[$i]; } //end for $this->result = $reverse_history[$cnt]; $this->path[$incoming_indent] = $key; //-- if ($this->yaml_contains_group_anchor) { $this->yaml_arr_saved_groups[$this->yaml_contains_group_anchor] = $this->path; if (is_array($value)) { $k = key($value); if (!is_int($k)) { $this->yaml_arr_saved_groups[$this->yaml_contains_group_anchor][$incoming_indent + 2] = $k; } //end if } //end if $this->yaml_contains_group_anchor = false; } //end if //-- }
public static function test_fs() { //-- if (SMART_FRAMEWORK_TESTUNIT_ALLOW_FS_TESTS !== true) { return SmartComponents::operation_notice('Test Unit File System Tests are DISABLED ...'); } //end if //-- //-- $time = microtime(true); //-- //-- $err = ''; $tests = array(); //-- //-- if ((string) DIRECTORY_SEPARATOR != '\\') { // broken links do not work on Windows ! $tests[] = '##### FileSystem OPERATIONS / TESTS - ALL: #####'; } else { $tests[] = '##### FileSystem OPERATIONS / TESTS *** PARTIAL SUPPORT ONLY (BY PLATFORM) ***: #####'; } //end if else //-- //-- $test_string = '#START#' . "\n" . 'グッド' . "\n" . 'SmartFramework/Test/FileSystem' . "\n" . time() . "\n" . SMART_FRAMEWORK_HTACCESS_NOINDEXING . SMART_FRAMEWORK_HTACCESS_FORBIDDEN . SMART_FRAMEWORK_HTACCESS_NOEXECUTION . "\n" . '#END#'; $test_str_cksum = SmartHashCrypto::sha512($test_string); $long_prefixed = SmartFileSysUtils::prefixed_sha1_path(sha1(time())); $short_prefixed = SmartFileSysUtils::prefixed_uuid10_dir(Smart::uuid_10_seq()); //-- $the_base_folder = 'tmp/tests/'; $the_sufx_folder = 'Folder1'; $the_base_file = 'NORMAL-Write_123_@#.txt'; //-- $the_folder = $the_base_folder . $the_sufx_folder . '/'; $the_copy_folder = $the_base_folder . 'folder2'; $the_move_folder = $the_base_folder . 'FOLDER3'; $the_extra_folder = $the_folder . 'extra/'; $the_file = $the_folder . $the_base_file; //-- $get_folder = SmartFileSysUtils::add_dir_last_slash(SmartFileSysUtils::get_dir_from_path($the_folder)); $get_file = SmartFileSysUtils::get_file_name_from_path($the_file); $get_xfile = SmartFileSysUtils::get_noext_file_name_from_path($the_file); $get_ext = SmartFileSysUtils::get_file_extension_from_path($the_file); //-- $the_copy_file = $the_file . '.copy.txt'; $the_move_file = $the_extra_folder . $the_base_file . '.copy.moved.txt'; $the_broken_link = $the_extra_folder . 'a-broken-link'; $the_broken_dir_link = $the_extra_folder . 'a-broken-dir-link'; $the_good_link = $the_extra_folder . 'a-good-link'; $the_good_dir_link = $the_extra_folder . 'a-good-dir-link'; //-- //-- $tests[] = 'INITIAL-FOLDER: ' . $get_folder; $tests[] = 'NEW-FOLDER: ' . $the_folder; $tests[] = 'NEW-FILE: ' . $the_file; //-- //-- if ((string) $err == '') { $the_test = 'CHECK TEST SAFE PATH NAME: DIR / FILE ...'; $tests[] = $the_test; if ((string) Smart::safe_pathname((string) $get_folder) !== (string) $get_folder or (string) Smart::safe_pathname((string) $the_copy_file) !== (string) $the_copy_file) { $err = 'ERROR: SAFE PATH NAME TEST ... FAILED !!!'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'CHECK TEST ABSOLUTE / BACKWARD PATHS ...'; $tests[] = $the_test; if (!SmartFileSysUtils::check_file_or_dir_name('/this/is/absolute', 'no') or SmartFileSysUtils::check_file_or_dir_name('/this/is/absolute') or SmartFileSysUtils::check_file_or_dir_name('/this/is/../backward/path')) { $err = 'ERROR: CHECK TEST ABSOLUTE / BACKWARD PATHS ... FAILED !!!'; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'CHECK EXTRACT FOLDER FROM PATH ...'; $tests[] = $the_test; if ((string) $get_folder != SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_folder))) { $err = 'ERROR: Path Extraction FAILED: Dir=' . $get_folder . ' ; DirName=' . SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_folder)); } //end if } //end if if ((string) $err == '') { $the_test = 'CHECK EXTRACT FILE AND EXTENSION FROM PATH (1) ...'; $tests[] = $the_test; if ((string) $get_folder . SmartFileSysUtils::add_dir_last_slash($the_sufx_folder) . $get_file != $the_file) { $err = 'ERROR :: Path Extraction FAILED: Re-Composed-File=' . $get_folder . SmartFileSysUtils::add_dir_last_slash($the_sufx_folder) . $get_file . ' ; File=' . $the_file; } //end if } //end if if ((string) $err == '') { $the_test = 'CHECK EXTRACT FILE AND EXTENSION FROM PATH (2) ...'; $tests[] = $the_test; if ((string) $get_file != $get_xfile . '.' . $get_ext) { $err = 'ERROR :: Path Extraction FAILED: File=' . $get_file . ' ; XFile=' . $get_xfile . ' ; Ext=' . $get_ext; } //end if } //end if //-- SmartFileSysUtils::raise_error_if_unsafe_path($the_folder); if ((string) $err == '') { $the_test = 'CHECK PATH NAME DIR: check_file_or_dir_name() : ' . $the_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSysUtils::check_file_or_dir_name($the_folder); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if SmartFileSysUtils::raise_error_if_unsafe_path($the_file); if ((string) $err == '') { $the_test = 'CHECK PATH NAME FILE: check_file_or_dir_name() : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSysUtils::check_file_or_dir_name($the_file); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- //-- if ((string) $err == '') { $parent_folder = SmartFileSysUtils::add_dir_last_slash(''); $the_test = 'Check Add Dir Last (trailing) Slash: Empty Folder Name'; $tests[] = $the_test; if ((string) $parent_folder != './') { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $parent_folder = SmartFileSysUtils::add_dir_last_slash('.'); $the_test = 'Check Add Dir Last (trailing) Slash: Dot Folder Name: ' . $parent_folder; $tests[] = $the_test; if ((string) $parent_folder != './') { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $parent_folder = SmartFileSysUtils::add_dir_last_slash('./'); $the_test = 'Check Add Dir Last (trailing) Slash: DotSlash Folder Name: ' . $parent_folder; $tests[] = $the_test; if ((string) $parent_folder != './') { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $parent_folder = SmartFileSysUtils::add_dir_last_slash(Smart::dir_name($the_base_folder)); $the_test = 'Check Parent Dir Name with Add Dir Last (trailing) Slash: ' . $parent_folder . ' # from: ' . $the_base_folder; $tests[] = $the_test; if ((string) $parent_folder != 'tmp/') { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- //-- if ((string) $err == '') { if (is_dir($get_folder)) { $the_test = 'DIR DELETE - INIT CLEANUP: dir_delete() + recursive: ' . $get_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_delete($the_base_folder, true); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } else { $tests[] = 'DIR DELETE - INIT CLEANUP: Test Not Run (folder does not exists): ' . $get_folder; } //end if else } //end if //-- if ((string) $err == '') { $the_test = 'DIR CREATE RECURSIVE: dir_recursive_create() : ' . $the_folder . $long_prefixed . $short_prefixed; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_recursive_create($the_folder . $long_prefixed . $short_prefixed); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DIR CREATE NON-RECURSIVE: dir_create() : extra/ in : ' . $the_extra_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_recursive_create($the_extra_folder); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) DIRECTORY_SEPARATOR != '\\') { // broken links do not work on Windows ! if ((string) $err == '') { $the_test = 'CREATE BROKEN FILE LINK FOR DELETION (1): link_create() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/cache', $the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DELETE BROKEN FILE LINK (1): delete() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::delete($the_broken_link); if ($result !== 1 || is_link($the_broken_link)) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'CREATE BROKEN FILE LINK FOR DELETION (2): link_create() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DELETE BROKEN FILE LINK (2): dir_delete() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_delete($the_broken_link); if ($result !== 1 || is_link($the_broken_link)) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'CREATE BROKEN FILE LINK: link_create() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'CREATE BROKEN DIR LINK: link_create() : as : ' . $the_broken_dir_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/', $the_broken_dir_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'CREATE A FILE LINK: link_create() : as : ' . $the_good_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create(Smart::real_path('tmp/index.html'), $the_good_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'CREATE A DIR LINK: link_create() : as : ' . $the_good_dir_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create(Smart::real_path('tmp/'), $the_good_dir_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if } //end if //-- if ((string) $err == '') { $the_test = 'FILE WRITE with empty content: write() : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write($the_file, ''); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE WRITE: write() / before append : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write($the_file, $test_string); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE WRITE: write() +append : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write($the_file, $test_string, 'a'); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE READ / Append: read() Full Size: ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::read($the_file); if ((string) SmartHashCrypto::sha512($result) != (string) SmartHashCrypto::sha512($test_string . $test_string)) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE WRITE: re-write() : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write($the_file, $test_string); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) DIRECTORY_SEPARATOR != '\\') { // broken links do not work on Windows ! if ((string) $err == '') { $the_test = 'FILE WRITE TO A BROKEN LINK: write() : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write($the_broken_link, $test_string); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DELETE THE BROKEN LINK AFTER write() and RE-CREATE IT : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::delete($the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'RE-CREATE BROKEN FILE LINK [AFTER WRITE]: link_create() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE WRITE: write_if_not_exists() with Content Compare to a broken link : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write_if_not_exists($the_broken_link, $test_string, 'yes'); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DELETE THE BROKEN LINK AFTER write_if_not_exists() and RE-CREATE IT : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::delete($the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'RE-CREATE BROKEN FILE LINK [AFTER WRITE-IF-NOT-EXISTS]: link_create() : as : ' . $the_broken_link; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::link_create('tmp/index.html', $the_broken_link); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if } //end if //-- if ((string) $err == '') { $the_test = 'FILE WRITE: write_if_not_exists() without Content Compare : ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::write_if_not_exists($the_file, $test_string, 'no'); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'FILE READ: read() Full Size: ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::read($the_file); if ((string) SmartHashCrypto::sha512($result) != (string) $test_str_cksum) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE READ: read() Partial Size, First 10 bytes: ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::read($the_file, 10); if ((string) sha1($result) != (string) sha1(substr($test_string, 0, 10))) { // here we read bytes so substr() not SmartUnicode::sub_str() should be used $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'FILE STATIC-READ: staticread() Full Size: ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::staticread($the_file); if ((string) SmartHashCrypto::sha512($result) != (string) $test_str_cksum) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE STATIC-READ: staticread() Partial Size, First 10 bytes: ' . $the_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::staticread($the_file, 10); if ((string) sha1($result) != (string) sha1(substr($test_string, 0, 10))) { // here we read bytes so substr() not SmartUnicode::sub_str() should be used $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'FILE COPY: copy() : ' . $the_file . ' to: ' . $the_copy_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::copy($the_file, $the_copy_file); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE COPY with OVERWRITE: copy() : ' . $the_file . ' to: ' . $the_copy_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::copy($the_file, $the_copy_file, true); // overwrite destination file(s) if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'FILE RE-COPY (test should re-write the destination): copy() : ' . $the_file . ' to: ' . $the_move_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::copy($the_file, $the_move_file); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } else { $the_test = 'FILE DELETE: delete() : ' . $the_move_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::delete($the_move_file); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if } //end if if ((string) $err == '') { $the_test = 'FILE RENAME/MOVE: rename() : ' . $the_copy_file . ' to: ' . $the_move_file; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::rename($the_copy_file, $the_move_file); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { if (is_dir('__development/')) { //-- $the_test = 'RECURSIVE COPY (CLONE) DIR [DEVELOPMENT]: dir_copy() : ' . '__development/' . ' to: ' . $the_folder . '__development'; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_copy('__development/', $the_folder . '__development'); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if //-- if ((string) $err == '') { $the_test = 'DIR COMPARE THE [DEVELOPMENT] SOURCE WITH [DEVELOPMENT] DESTINATION AFTER DIR COPY AND DIR MOVE:' . "\n" . 'compare_folders() : ' . '__development/' . ' with: ' . $the_folder . '__development/'; $tests[] = $the_test; $arr_diff = array(); $arr_diff = SmartFileSystem::compare_folders('__development', $the_folder . '__development', true, true); if (Smart::array_size($arr_diff) > 0) { $err = 'ERROR :: ' . $the_test . ' #DIFFERENCES=' . print_r($arr_diff, 1); } //end if } //end if //-- } else { $tests[] = 'RECURSIVE COPY (CLONE) DIR [DEVELOPMENT]: Test Not Run (Development environment not detected) ...'; } //end if else } //end if //-- if ((string) $err == '') { $the_test = 'RECURSIVE COPY (CLONE) DIR: dir_copy() : ' . $the_folder . ' to: ' . $the_copy_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_copy($the_folder, $the_copy_folder); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'MOVE/RENAME DIR: dir_rename() : ' . $the_copy_folder . ' to: ' . $the_move_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_rename($the_copy_folder, $the_move_folder); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- if ((string) $err == '') { $the_test = 'DIR COMPARE THE SOURCE WITH DESTINATION AFTER DIR COPY AND DIR MOVE: ' . $the_folder . ' with: ' . $the_move_folder; $tests[] = $the_test; $arr_diff = array(); $arr_diff = SmartFileSystem::compare_folders($the_folder, $the_move_folder, true, true); if (Smart::array_size($arr_diff) > 0) { $err = 'ERROR :: ' . $the_test . ' #DIFFERENCES=' . print_r($arr_diff, 1); } //end if } //end if //-- if ((string) $err == '') { $the_test = 'DIR DELETE - SIMPLE: dir_delete() non-recursive: ' . $the_extra_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_delete($the_extra_folder, false); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if if ((string) $err == '') { $the_test = 'DIR DELETE - LAST CLEANUP: dir_delete() + recursive: ' . $get_folder; $tests[] = $the_test; $result = 0; $result = SmartFileSystem::dir_delete($the_base_folder, true); if ($result !== 1) { $err = 'ERROR :: ' . $the_test . ' #RESULT=' . $result; } //end if } //end if //-- //-- $time = 'TOTAL TIME was: ' . (microtime(true) - $time); //-- //-- $end_tests = '##### END TESTS ... ' . $time . ' sec. #####'; //-- //-- 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 FS Operations <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" . $end_tests)) . '</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 FS Operations.<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 LibFileSystem Tests: DONE ... [ Time: {$time} sec. ]</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'FileSystem Operations Test Suite for SmartFramework: PHP', \t\t'920', \t\t'480' \t); </script> HTML; //-- //-- return $html; //-- }
/** * [PUBLIC] Draw an Image Gallery * * @param STRING $y_title :: a title for the gallery * @param STRING $y_dir :: path to scan * @param *OPTIONAL[yes/no] $y_process_previews_and_images :: If = 'yes', will create previews for images and videos (movies) and will create conformed images * @param *OPTIONAL[yes/no] $y_remove_originals :: If = 'yes', will remove original (images) after creating previews [$y_process_previews_and_images must be yes] * @param *OPTIONAL[>=0] $y_display_limit :: Items limit to display */ public function draw($y_title, $y_dir, $y_process_previews_and_images = 'no', $y_remove_originals = 'no', $y_display_limit = '0') { //-- $y_title = (string) $y_title; //-- $y_dir = (string) $y_dir; //-- $y_process_previews_and_images = (string) $y_process_previews_and_images; if ((string) $y_process_previews_and_images != 'yes') { $y_process_previews_and_images = 'no'; } //end if //-- $y_display_limit = Smart::format_number_int($y_display_limit, '+'); //-- //-- if ((string) $this->use_secure_links == 'yes') { if ((string) $this->secure_download_link == '' or (string) $this->secure_download_ctrl_key == '') { return '<h1>WARNING: Media Gallery / Secure Links Mode is turned ON but at least one of the: download link or the controller was NOT provided ...</h1>'; } //end if } //end if //-- //-- if (!SmartFileSysUtils::check_file_or_dir_name($y_dir)) { return '<h1>ERROR: Invalid Folder for Media Gallery ...</h1>'; } //end if //-- $y_dir = SmartFileSysUtils::add_dir_last_slash($y_dir); SmartFileSysUtils::raise_error_if_unsafe_path($y_dir); //-- if (!is_dir($y_dir)) { return '<h1>WARNING: The Folder for Media Gallery does not exists ...</h1>'; } //end if //-- //-- $this->gallery_items = 0; //-- //-- constraint of params if ((string) $y_process_previews_and_images != 'yes') { $y_remove_originals = 'no'; } //end if //-- if (strlen($this->preview_formvar) > 0) { // avoid processing if it is displayed in a form $y_process_previews_and_images = 'no'; $y_remove_originals = 'no'; } //end if //-- //-- some inits ... $out = ''; $arr_files = array(); $processed = 0; //-- //-- $arr_storage = (array) (new SmartGetFileSystem(true))->get_storage($y_dir, false, false); $all_mg_files = (array) $arr_storage['list-files']; //-- //-- for ($i = 0; $i < Smart::array_size($all_mg_files); $i++) { //-- $file = (string) $all_mg_files[$i]; $ext = strtolower(SmartFileSysUtils::get_file_extension_from_path($file)); //-- if (substr($file, 0, 1) != '.' and strpos($file, '.#') === false and strpos($file, '#.') === false) { //-- if (is_file($y_dir . $file) and ((string) $ext == 'jpeg' or (string) $ext == 'jpg' or (string) $ext == 'gif' or (string) $ext == 'png')) { //-- if (SmartFileSysUtils::version_check($file, 'mg-preview')) { //-- it is an image preview file if (!is_file($y_dir . SmartFileSysUtils::version_add($file, 'mg-image'))) { SmartFileSystem::delete($y_dir . $file); // remove preview if orphan } //end if //-- } elseif (SmartFileSysUtils::version_check($file, 'mg-image')) { //-- it is an image file if ((string) $y_process_previews_and_images == 'yes') { //-- $tmp_file = $y_dir . SmartFileSysUtils::version_add($file, 'mg-preview'); //-- if (!is_file($tmp_file)) { //-- $out .= $this->img_preview_create($y_dir . $file, $tmp_file) . '<br>'; $processed += 1; //-- } //end if //-- } //end if //-- $arr_files[] = $file; $this->gallery_items += 1; //-- } elseif (SmartFileSysUtils::version_check($file, 'mg-vpreview')) { //-- it is a movie preview file if (stripos($file, '.#tmp-preview#.jpg') === false) { //-- $tmp_linkback_file = SmartFileSysUtils::get_noext_file_name_from_path(SmartFileSysUtils::version_remove($file)); //-- if (!is_file($y_dir . $tmp_linkback_file)) { SmartFileSystem::delete($y_dir . $file); // remove if orphan } //end if //-- } //end if //-- } else { // unprocessed image //-- if ((string) $y_process_previews_and_images == 'yes') { //-- $tmp_file = $y_dir . SmartFileSysUtils::version_add($file, 'mg-image'); //-- if (!is_file($tmp_file)) { //-- if ((string) $y_dir . $file != (string) $y_dir . strtolower($file)) { SmartFileSystem::rename($y_dir . $file, $y_dir . strtolower($file)); // make sure is lowercase, to be ok for back-check since versioned is lowercase } //end if //-- $out .= $this->img_conform_create($y_dir . $file, $tmp_file) . '<br>'; $processed += 1; //-- } else { //-- if ((string) $y_remove_originals == 'yes') { //-- SmartFileSystem::delete($y_dir . $file); $out .= '<table width="550" bgcolor="#FF3300"><tr><td>removing original image: \'' . Smart::escape_html($file) . '\'</td></tr></table><br>'; $processed += 1; //-- } //end if //-- } //end if else //-- } //end if //-- } //end if else //-- } elseif (is_file($y_dir . $file) and ((string) $ext == 'webm' or (string) $ext == 'ogv' or (string) $ext == 'mp4' or (string) $ext == 'mov' or (string) $ext == 'flv')) { // WEBM, OGV, MP4, MOV, FLV //-- process preview FLV / MOV ... if ((string) $y_process_previews_and_images == 'yes') { //-- $tmp_file = $y_dir . SmartFileSysUtils::version_add($file, 'mg-vpreview') . '.jpg'; //-- if (!is_file($tmp_file)) { //-- if ((string) $y_dir . $file != (string) $y_dir . strtolower($file)) { SmartFileSystem::rename($y_dir . $file, $y_dir . strtolower($file)); // make sure is lowercase, to be ok for back-check since versioned is lowercase } //end if //-- $out .= $this->mov_preview_create($y_dir . strtolower($file), $tmp_file) . '<br>'; $processed += 1; //-- } //end if //-- } //end if //-- $arr_files[] = $file; $this->gallery_items += 1; //-- } //end if else //-- } //end if //-- } //end for //-- //-- $out .= '<!-- START MEDIA GALLERY -->' . "\n"; //-- if ((string) $this->use_styles == 'yes') { $out .= '<div id="mediagallery_box">' . "\n"; } //end if //-- //-- $out_arr = array(); //-- if ($processed <= 0) { //-- $arr_files = Smart::array_sort($arr_files, 'natsort'); //-- $max_loops = Smart::array_size($arr_files); if ($y_display_limit > 0) { if ($y_display_limit < $max_loops) { $max_loops = $y_display_limit; } //end if } //end if //-- for ($i = 0; $i < $max_loops; $i++) { //-- $tmp_the_ext = strtolower(SmartFileSysUtils::get_file_extension_from_path($arr_files[$i])); // [OK] //-- if ((string) $tmp_the_ext == 'webm' or (string) $tmp_the_ext == 'ogv' or (string) $tmp_the_ext == 'mp4' or (string) $tmp_the_ext == 'mov' or (string) $tmp_the_ext == 'flv') { $out_arr[] = $this->mov_draw_box($y_dir, $arr_files[$i], $tmp_the_ext); } else { $out_arr[] = $this->img_draw_box($y_dir, $arr_files[$i]); } //end if //-- } //end for //-- $out .= '<div title="' . Smart::escape_html($this->gallery_show_counter) . '">' . "\n"; //-- if ((string) $y_title != '') { $out .= '<div id="mediagallery_title">' . Smart::escape_html($y_title) . '</div><br>'; } //end if $out .= '<div id="mediagallery_row">'; for ($i = 0; $i < Smart::array_size($out_arr); $i++) { $out .= '<div id="mediagallery_cell">'; $out .= $out_arr[$i]; $out .= '</div>' . "\n"; } //end for $out .= '</div>'; //-- $out .= '</div>' . "\n"; //-- } //end if //-- $out_arr = array(); //-- //-- if ((string) $this->use_styles == 'yes') { $out .= '</div>' . "\n"; } //end if //-- $out .= '<!-- END MEDIA GALLERY -->' . "\n"; //-- //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE != 'yes') { if ($processed > 0) { $out = '<img src="' . $this->pict_reloading . '" alt="[Reloading Page ...]" title="[Reloading Page ...]"><script type="text/javascript">setTimeout(function(){ self.location = self.location; }, 2000);</script>' . '<br><hr><br>' . $out; define('SMART_FRAMEWORK__MEDIA_GALLERY_IS_PROCESSING', $processed); // notice that the media galery is processing } //end if } //end if //-- //-- return $out; //-- }
public static function getTranslationsFromSource($the_lang, $y_area, $y_subarea) { //-- if (substr((string) $y_area, 0, 1) == '@') { if ((string) $the_lang == 'en') { $fdb_dir = 'lib/app/translations/'; } else { // default is: modules/app/translations/ $fdb_dir = (string) SMART_FRAMEWORK_LANGUAGES_CACHE_DIR; } //end if else $fdb_template = strtolower($y_area . '/' . $y_subarea . '-' . $the_lang); } else { // $y_area can be: apps, mod-something, ... $fdb_dir = (string) Smart::safe_pathname('modules/' . $y_area . '/translations/'); $fdb_template = strtolower($y_subarea . '-' . $the_lang); } //end if else //-- $fdb_file = (string) $fdb_dir . $fdb_template . '.yaml'; SmartFileSysUtils::raise_error_if_unsafe_path($fdb_file); //-- if (!is_dir($fdb_dir)) { Smart::raise_error('Invalid Language Dir: ' . $fdb_dir . ' :: for: ' . $y_area . '@' . $y_subarea, 'Invalid Language Dir for: ' . $y_area . '@' . $y_subarea); return array(); } //end if //-- if (!is_file($fdb_file)) { //-- Smart::raise_error('Invalid Language File: ' . $fdb_file, 'Invalid Language File: ' . $fdb_template); return array(); //-- } //end if //-- $fcontent = SmartFileSystem::staticread($fdb_file); $arr = (new SmartYamlConverter())->parse((string) $fcontent); //-- if (!is_array($arr)) { Smart::raise_error('Parse Error / TRANSLATIONS :: Language File: ' . $fdb_file, 'Parse Error / TRANSLATIONS :: Language File: ' . $fdb_template); return array(); } //end if //-- if (!is_array($arr['TRANSLATIONS'])) { Smart::raise_error('Parse Error / TRANSLATIONS :: Language File: ' . $fdb_file, 'Parse Error / TRANSLATIONS :: Language File: ' . $fdb_template); return array(); } //end if if (Smart::array_size($arr['TRANSLATIONS'][(string) $y_subarea]) <= 0) { Smart::log_warning('Parse Error / TRANSLATIONS.' . $y_subarea . ' :: Language File: ' . $fdb_template); return array(); } //end if //-- return (array) $arr['TRANSLATIONS'][(string) $y_subarea]; //-- }
/** * Build the associative Array of Auth Privileges * * @param MIXED $y_priv_list :: List of Privileges as ARRAY Array('priv_1', 'priv_2', ..., 'priv_n') or STRING '<priv_1>, <priv_2>, ..., <priv_n>' * * @return ARRAY :: returns the associative array of auth privileges as Array('priv_1' => 'Priv 1', 'priv_2' => 'Priv 2', ..., 'priv_n' => 'Priv n') */ public static function build_arr_privileges($y_priv_list) { //-- if (!is_array($y_priv_list)) { $y_priv_list = (array) Smart::list_to_array((string) $y_priv_list); } //end if //-- $y_priv_list = (array) $y_priv_list; //-- $out_arr = array(); for ($i = 0; $i < Smart::array_size($y_priv_list); $i++) { //-- $y_priv_list[$i] = (string) strtolower(trim((string) $y_priv_list[$i])); if ((string) $y_priv_list[$i] != '') { $out_arr[(string) $y_priv_list[$i]] = (string) trim(ucwords(str_replace(array('_', '-'), array(' ', ' '), (string) $y_priv_list[$i]))); } //end if //-- } //end for //-- return (array) $out_arr; //-- }
/** * Generate the ODS Document on the fly from an array of data * * @param STRING $y_table_name :: The Table Name * @param STRING $y_arr_fields :: Array of Header Fields * @param STRING $y_arr_data :: Array of Data * * @returns STRING :: The ODS Document Contents * */ public function ODS_SpreadSheet($y_table_name, $y_arr_fields, $y_arr_data, $y_arr_process = array(), $y_arr_totals = array(), $y_arr_finals = array(), $y_arr_widths = array(), $y_arr_highlights = array()) { // font-weight="bold" // fo:font-style="italic" // style:text-underline-type="single" //-- header $header = '' . '<?xml version="1.0" encoding="UTF-8"?' . '>' . "\n" . '<office:document-content ' . $this->open_document_ns . 'office:version="1.0">' . "\n" . $this->open_document_styles . '<office:body>' . "\n" . '<office:spreadsheet>' . "\n"; //-- //-- footer $footer = "\n" . '</office:spreadsheet>' . "\n" . '</office:body>' . "\n" . '</office:document-content>'; //-- //-- data $data = ''; $data .= '<table:table table:style-name="ta1" table:print="true" table:name="' . Smart::escape_html($y_table_name) . '">' . "\n"; //-- //-- table headings $num_cols = Smart::array_size($y_arr_fields); $num_data = Smart::array_size($y_arr_data); //-- $data .= '<table:table-row table:style-name="ro1">' . "\n"; //-- for ($i = 0; $i < $num_cols; $i++) { //-- $data .= '<table:table-cell table:style-name="he1" office:value-type="string">'; $data .= '<text:p>' . Smart::escape_html($y_arr_fields[$i]) . '</text:p>'; $data .= '</table:table-cell>' . "\n"; //-- } //end for //-- $data .= '</table:table-row>' . "\n"; //-- for ($n = 0; $n < $num_data; $n++) { //-- $data .= '<table:table-row table:style-name="ro1">' . "\n"; //-- for ($i = 0; $i < $num_cols; $i++) { //-- $kk = $i + $n; //-- if ($i % $num_cols == 0 or $i % $num_cols == $num_cols - 1) { $tmp_style = 'ce1'; // highlight first and last column } elseif ($i % 2) { $tmp_style = 'ce3'; } else { $tmp_style = 'ce2'; } //end if else //-- if ((string) $y_arr_process[$i] == 'number' or (string) $y_arr_process[$i] == 'decimal2' or (string) $y_arr_process[$i] == 'decimal4') { //-- if ((string) $y_arr_process[$i] == 'decimal2') { $y_arr_data[$kk] = (string) Smart::format_number_dec($y_arr_data[$kk], 2, '.', ''); } elseif ((string) $y_arr_process[$i] == 'decimal4') { $y_arr_data[$kk] = (string) Smart::format_number_dec($y_arr_data[$kk], 4, '.', ''); } else { $y_arr_data[$kk] = (string) $y_arr_data[$kk]; } //end if //-- //$data .= '<table:table-cell table:style-name="'.$tmp_style.'" office:value-type="float" office:value="'.Smart::escape_html($y_arr_data[$kk]).'">'; $data .= '<table:table-cell table:style-name="' . $tmp_style . '" office:value-type="string">'; // preserve number as they are, force type string !!! $data .= '<text:p>' . Smart::escape_html($y_arr_data[$kk]) . '</text:p>'; $data .= '</table:table-cell>' . "\n"; //-- } else { //-- $data .= '<table:table-cell table:style-name="' . $tmp_style . '" office:value-type="string">'; $data .= '<text:p>' . Smart::escape_html($y_arr_data[$kk]) . '</text:p>'; $data .= '</table:table-cell>' . "\n"; //-- } //end if else //-- } //end for //-- $data .= '</table:table-row>' . "\n"; //-- $n += $num_cols - 1; // salt //-- } //end for //-- //-- totals row if (Smart::array_size($y_arr_totals) > 0) { //-- $data .= '<table:table-row table:style-name="ro1">' . "\n"; //-- for ($i = 0; $i < $num_cols; $i++) { //-- $data .= '<table:table-cell table:style-name="he2" office:value-type="string">'; $data .= '<text:p>' . $y_arr_totals[$i] . '</text:p>'; $data .= '</table:table-cell>' . "\n"; //-- } //end for //-- $data .= '</table:table-row>' . "\n"; //-- } //end if //-- //-- final row if (Smart::array_size($y_arr_finals) > 0) { //-- $data .= '<table:table-row table:style-name="ro1">' . "\n"; //-- for ($i = 0; $i < $num_cols; $i++) { //-- $data .= '<table:table-cell table:style-name="he3" office:value-type="string">'; $data .= '<text:p>' . $y_arr_finals[$i] . '</text:p>'; $data .= '</table:table-cell>' . "\n"; //-- } //end for //-- $data .= '</table:table-row>' . "\n"; //-- } //end if //-- //-- $data .= '</table:table>' . "\n"; //-- //-- return (string) $this->OpenDocument_Template((string) $this->mime_ods, $header . "\n" . $data . "\n" . $footer); //-- }
/** * * @access private * @internal * */ public static function registerOptimizationHintsToDebugLog() { //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { //-- $optim_msg = []; foreach (self::$MkTplFCount as $key => $val) { $key = (string) $key; if (strpos($key, 'debug') === false) { // avoid hints for debug templates / sub-templates $key = (array) explode(':', $key); $key = (string) $key[1]; $val = (int) $val; if ($val > 1) { $optim_msg[] = ['optimal' => false, 'value' => (int) $val, 'key' => (string) $key, 'msg' => 'Optimization Hint: Set Caching Parameter for Rendering this Template to avoid multiple reads on FileSystem']; } else { $optim_msg[] = ['optimal' => true, 'value' => (int) $val, 'key' => (string) $key, 'msg' => 'OK']; } //end if else } //end if } //end foreach SmartFrameworkRegistry::setDebugMsg('optimizations', '*SMART-CLASSES:OPTIMIZATION-HINTS*', ['title' => 'SmartMarkersTemplating // Optimization Hints @ Number of FileSystem Reads for current Template / Sub-Templates', 'data' => (array) $optim_msg]); //-- $optim_msg = []; foreach (self::$MkTplVars as $key => $val) { $counter = Smart::array_size($val); if ($counter > 0) { $optim_msg[] = ['optimal' => null, 'value' => (int) $counter, 'key' => (string) $key, 'msg' => (string) implode(' ; ', array_unique($val))]; } //end if } //end foreach SmartFrameworkRegistry::setDebugMsg('optimizations', '*SMART-CLASSES:OPTIMIZATION-HINTS*', ['title' => 'SmartMarkersTemplating // Optimization Notices @ Rendering Details of current Template / Sub-Templates', 'data' => (array) $optim_msg]); //-- $optim_msg = []; //-- } //end if //-- }
public function Run() { //-- sample page variable from Request (GET/POST) $some_var_from_request = $this->RequestVarGet('extra_text', 'default', 'string'); //-- //-- $module_area = $this->ControllerGetParam('module-area'); $the_lang = (string) $this->ConfigParamGet('regional.language-id'); $the_xlang = (string) $this->ConfigParamGet('regional.language-id'); // repeat this to check if caching works //-- if ($this->IfDebug()) { $this->SetDebugData('Module Area', $module_area); $this->SetDebugData('Module Path', $this->ControllerGetParam('module-path')); $this->SetDebugData('Module Name', $this->ControllerGetParam('module-name')); $this->SetDebugData('URL Script', $this->ControllerGetParam('url-script')); $this->SetDebugData('URL Path', $this->ControllerGetParam('url-path')); $this->SetDebugData('URL Address', $this->ControllerGetParam('url-addr')); $this->SetDebugData('URL Page', $this->ControllerGetParam('url-page')); $this->SetDebugData('Config / Language ID', $the_lang); } //end if //-- //-- if ($this->PageCacheisActive()) { //-- because the Request can modify the content, also the unique key must take in account variables that will vary the page config or page content vars $the_page_cache_key = 'samples-toolkit-' . $module_area . '__' . SmartHashCrypto::sha384((string) $some_var_from_request); //-- } //end if //-- //-- if ($this->PageCacheisActive()) { //-- $test_cache = $this->PageGetFromCache('cached-samples', $the_page_cache_key); //-- if (Smart::array_size($test_cache) > 0) { if (is_array($test_cache['configs']) && is_array($test_cache['vars'])) { // if valid cache (test as we exported both arrays ... so they must be the 2 arrays again) $this->PageViewSetCfgs((array) $test_cache['configs']); $this->PageViewSetVars((array) $test_cache['vars']); $this->PageViewAppendVar('main', "\n" . '<!-- Redis Cached Content Key: ' . Smart::escape_html($the_page_cache_key) . ' -->' . "\n"); // add a markup to the HTML to know was served from cache ... if ($this->IfDebug()) { $this->SetDebugData('Page Cache Info', 'Serving page from Persistent Cache: Redis (override PHP Execution). Page key is: ' . $the_page_cache_key); } // end if return; // the page was served from Cache (stop here) } //end if } //end if //-- } //end if //-- //=== if no cached, execute the code below ... //-- $this->PageViewSetCfg('template-path', 'default'); // set the template path (must be inside etc/templates/) $this->PageViewSetCfg('template-file', 'template.htm'); // set the template file //-- //-- $fcontent = SmartFileSystem::staticread('lib/framework/css/ux-toolkit-samples.html'); $arr_data = explode('<body>', $fcontent); $fcontent = (string) $arr_data[1]; $arr_data = explode('</body>', $fcontent); $fcontent = (string) $arr_data[0]; //-- //-- building a semantic URL $url_test_unit = Smart::url_add_params($this->ControllerGetParam('url-script'), array('page' => 'samples.testunit', 'tab' => 0)); // will generate: index.php?page=samples.testunit OR admin.php?page=samples.testunit $url_test_unit = Smart::url_make_semantic($url_test_unit); // convert the above to a pretty URL as: ?/page/samples.testunit (in this case index.php is ignored) OR admin.php?/page/samples.testunit //-- //-- building a regular URL $url_benchmark = Smart::url_add_params($this->ControllerGetParam('url-script'), array('page' => 'samples.benchmark.html')); $url_benchmark = Smart::url_make_semantic($url_benchmark); //-- //-- $translator_core = SmartTextTranslations::getTranslator('@core', 'messages'); //-- $translator_mod_samples = SmartTextTranslations::getTranslator('mod-samples', 'samples'); $txt_hello_world = $translator_mod_samples->text('hello-world'); unset($translator_mod_samples); // this is just an internal test, normally the translator should not be unset ... $translator_mod_samples = SmartTextTranslations::getTranslator('mod-samples', 'samples'); $txt_this_is_sf = $translator_mod_samples->text('this-is-smart-framework'); //-- //-- $this->PageViewSetVars(['title' => 'Toolkit Samples', 'main' => '<h1>This text should not be displayed, it was RESET !!!</h1>']); $this->PageViewResetVar('main'); // test reset $this->PageViewSetVar('main', SmartMarkersTemplating::render_template('<h1>' . '[####TXT-HELLO-WORLD####]</h1><div align="right"><b>[####DATE-TIME|html####] [[####TXT-OK####]]' . "\n" . '</b></div><br><a class="ux-button ux-button-special" href="http://sourceforge.net/projects/warp-cms/files/smart-framework/" target="_blank"><i class="fa fa-cloud-download"></i> Download Smart.Framework (latest stable releases)</a> <a class="ux-button ux-button-highlight" href="http://demo.unix-world.org/smart-framework.docs/" target="_blank"><i class="fa fa-book"></i> Documentation for the Smart.Framework</a><br>' . "\n" . '<br><a class="ux-button ux-button-primary" href="[####URL-TESTUNIT|html####]"><i class="fa fa-object-group"></i> Go to the Smart.Framework PHP/Javascript Test & Demo Suite</a> <a class="ux-button ux-button-secondary" href="[####URL-BENCHMARK|html####]"><i class="fa fa-line-chart"></i> Benchmark URL for Smart.Framework</a><br><br>', ['DATE-TIME' => date('Y-m-d H:i:s O'), 'TXT-OK' => $translator_core->text('ok'), 'TXT-HELLO-WORLD' => '<span title="LanguageID: ' . Smart::escape_html($the_xlang) . '" style="cursor:help;">' . '[' . Smart::escape_html($the_lang) . ']' . '</span>' . ' ' . $txt_hello_world . ', ' . $txt_this_is_sf . ' - a modern PHP / Javascript framework featuring MVC + Middlewares', 'URL-TESTUNIT' => $url_test_unit, 'URL-BENCHMARK' => $url_benchmark])); $this->PageViewAppendVar('main', '<hr><div style="color:#DDDDDD">' . Smart::escape_html('Unicode@String :: Smart スマート // Cloud Application Platform クラウドアプリケーションプラットフォーム :: áâãäåāăąÁÂÃÄÅĀĂĄ ćĉčçĆĈČÇ ďĎ èéêëēĕėěęÈÉÊËĒĔĖĚĘ ĝģĜĢ ĥħĤĦ ìíîïĩīĭȉȋįÌÍÎÏĨĪĬȈȊĮ ijĵIJĴ ķĶ ĺļľłĹĻĽŁ ñńņňÑŃŅŇ óôõöōŏőøœÒÓÔÕÖŌŎŐØŒ ŕŗřŔŖŘ șşšśŝßȘŞŠŚŜ țţťȚŢŤ ùúûüũūŭůűųÙÚÛÜŨŪŬŮŰŲ ŵŴ ẏỳŷÿýẎỲŶŸÝ źżžŹŻŽ') . '</div><hr><div align="right">[' . Smart::escape_html($some_var_from_request) . ']</div>'); $this->PageViewAppendVar('main', trim($fcontent)); //-- //== cache page (if redis - persistent cache is set in config) //-- if Redis is active this will cache the page for 1 hour ... if ($this->PageCacheisActive()) { //-- $this->PageSetInCache('cached-samples', $the_page_cache_key, array('configs' => $this->PageViewGetCfgs(), 'vars' => $this->PageViewGetVars()), 3600); //-- if ($this->IfDebug()) { $this->SetDebugData('Page Cache Info', 'Setting page in Persistent Cache: Redis (after PHP Execution). Page key is: ' . $the_page_cache_key); } //end if //-- } else { //-- if ($this->IfDebug()) { $this->SetDebugData('Page Cache Info', 'Persistent Cache (Redis) is not active. Serving Page from PHP Execution.'); } //end if //-- } //end if else //-- }
private function folder_iterator($recurring, $dir_name, $include_dot_files, $search_pattern = '', $search_prevent_file = '', $search_prevent_override = '') { //-- $recurring = (bool) $recurring; $dir_name = (string) $dir_name; $include_dot_files = (bool) $include_dot_files; $search_pattern = (string) $search_pattern; $search_prevent_file = (string) $search_prevent_file; $search_prevent_override = (string) $search_prevent_override; //-- if ((string) $dir_name == '') { Smart::log_warning('LibFileSys // ReadsFolderRecurring // Dir Name is Empty !'); return; // this function does not return anything, but just stop here in this case } //end if //-- fix invalid path (must end with /) $dir_name = SmartFileSysUtils::add_dir_last_slash($dir_name); //-- protection SmartFileSysUtils::raise_error_if_unsafe_path($dir_name); //-- @clearstatcache(); //-- $this->pattern_search_str = $search_pattern; $this->search_prevent_file = $search_prevent_file; $this->search_prevent_override = $search_prevent_override; //-- if (SmartFileSystem::file_or_link_exists($dir_name) and !is_file($dir_name)) { // can be dir or link //list //-- if ($handle = opendir($dir_name)) { //--------------------------------------- while (false !== ($file = readdir($handle))) { //-- if ((string) $file != '.' and (string) $file != '..') { //-- if ($include_dot_files or !$include_dot_files and substr($file, 0, 1) != '.') { //-- SmartFileSysUtils::raise_error_if_unsafe_path($dir_name . $file); //-- params to see if counted or added to pattern matches $tmp_allow_addition = 1; $tmp_add_pattern = 0; //-- this is for #private folders, will prevent searching in folders containing for example this file: .private-folder but can be overriden by the $search_prevent_override option exluding a particular path like folder/private/user1 if (strlen($search_prevent_file) > 0 and is_file($dir_name . $search_prevent_file)) { if (strlen($search_prevent_override) <= 0 or strlen($search_prevent_override) > 0 and !is_file($dir_name . $search_prevent_override)) { $tmp_allow_addition = 0; } //end if } //end if //-- this is a search pattern (search pattern does not apply to folders !!) ; if no empty will populate the pattern matches array with all files and folders matching ; to include all, use * or a particular search for the rest like myfile1 if ((string) $search_pattern == '' or is_dir($dir_name . $file)) { if ($tmp_allow_addition) { if ($this->list_files_and_dirs) { $tmp_add_pattern = 1; } //end if } //end if } else { if ($this->limit_search_files <= 0 or Smart::array_size($this->pattern_file_matches) < $this->limit_search_files) { if ((string) $search_pattern == '*' or (string) $search_pattern == '[image]' and (substr($file, -4, 4) == '.png' or substr($file, -4, 4) == '.gif' or substr($file, -4, 4) == '.jpg' or substr($file, -5, 5) == '.jpeg') or (string) $search_pattern != '*' and (string) $search_pattern != '[image]' and stripos($file, $search_pattern) !== false) { if ($tmp_allow_addition) { if ($this->list_files_and_dirs) { $tmp_add_pattern = 1; } //end if } //end if } else { $tmp_allow_addition = 0; } //end if else } //end if } //end if //-- if ($this->limit_search_files > 0) { // the dir should not be taken in count here if ($this->num_files + $this->num_links >= $this->limit_search_files) { break; } //end if } //end if //-- if (!is_link($dir_name . $file)) { //-- if (is_dir($dir_name . $file)) { //-- dir if ($tmp_allow_addition) { //-- $tmp_fsize = Smart::format_number_int(@filesize($dir_name . $file), '+'); //-- $this->num_dirs++; $this->num_size += $tmp_fsize; $this->num_dirs_size += $tmp_fsize; //-- $tmp_fsize = 0; //-- if ($tmp_add_pattern) { if ($recurring) { // if recurring, add the full path $this->pattern_dir_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_dir_matches[$file] = @filemtime($dir_name . $file); } //end if else } //end if //-- } //end if //-- if ($recurring) { //-- we go search inside even if this folder name may not match the search pattern, it is a folder, except if dissalow addition from above $this->folder_iterator($recurring, SmartFileSysUtils::add_dir_last_slash($dir_name . $file), $include_dot_files, $search_pattern, $search_prevent_file, $search_prevent_override); //-- } //end if //-- } else { //-- file if ($tmp_allow_addition) { //-- $tmp_fsize = Smart::format_number_int(@filesize($dir_name . $file), '+'); //-- $this->num_files++; $this->num_size += $tmp_fsize; $this->num_files_size += $tmp_fsize; //-- $tmp_fsize = 0; //-- if ($tmp_add_pattern) { if ($recurring) { // if recurring, add the full path $this->pattern_file_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_file_matches[$file] = @filemtime($dir_name . $file); } //end if else } //end if //-- } //end if //-- } //end else //-- } else { //-- link if ($tmp_allow_addition) { //-- $link_result = SmartFileSystem::link_get_origin($dir_name . $file); //-- if (empty($link_result) or (string) $link_result == '' or !SmartFileSystem::file_or_link_exists($link_result)) { //-- // case of readlink error ..., not includding broken links, they are useless //-- } else { //-- $tmp_size_arr = array(); $tmp_fsize = 0; //$tmp_size_arr = (array) @lstat($dir_name.$file); //$tmp_fsize = Smart::format_number_int($tmp_size_arr[7],'+'); // $tmp_size_arr[7] -> size, but may break compare if on a different file system or in distributed storage on various OS //-- $this->num_links++; //-- if (file_exists($dir_name . $file)) { // here file_exists must be tested because if broken link not stat on it (filemtime) to avoid log un-necessary errors //-- bugfix: not if broken link $this->num_size += $tmp_fsize; if ($tmp_add_pattern) { if (is_dir($dir_name . $file)) { $this->num_dirs++; $this->num_dirs_size += $tmp_fsize; if ($recurring) { // if recurring, add the full path $this->pattern_dir_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_dir_matches[$file] = @filemtime($dir_name . $file); } //end if else } else { $this->num_files++; $this->num_files_size += $tmp_fsize; if ($recurring) { // if recurring, add the full path $this->pattern_file_matches[$dir_name . $file] = @filemtime($dir_name . $file); } else { // if not recurring, add just base path, without dirname prefix $this->pattern_file_matches[$file] = @filemtime($dir_name . $file); } //end if else } //end if else } //end if //-- } //end if //-- $tmp_fsize = 0; $tmp_size_arr = array(); //-- } //end if else //-- } //end if //-- } //end if else //-- } //end if //-- } //end if(. ..) //-- } //end while //--------------------------------------- @closedir($handle); //--------------------------------------- } else { //--------------------------------------- $this->errors_arr[] = $dir_name; //--------------------------------------- } //end else //-- } else { //--------------------------------------- // nothing ... //--------------------------------------- } //end if else //-- }
private function clean_html($y_comments, $y_extra_tags_remove = array(), $y_extra_tags_clean = array(), $y_allowed_tags = array()) { //-- CLEANUP DISSALOWED AND FIX INVALID HTML TAGS // * it will use code standardize before to fix active PHP tags and weird characters // * will convert all UTF-8 characters to the coresponding HTML-ENTITIES // * will remove all tags that are unsafe like <script> or <head> and many other dissalowed unsafe tags // * if allowed tags are specified they will take precedence and will be filtered via strip_tags by allowing only these tags, at the end of cleanup to be safer ! // * if DomDocument is detected and is allowed to be used by current settings will be used finally to do (post-processing) extra cleanup and fixes //-- //-- if ($this->is_clean != false) { return; // avoid to re-parse } //end if //-- $this->is_clean = true; //-- //-- $this->standardize_html(); // first, standardize the HTML Code //-- //-- $arr_tags_0x_list_comments = array('#\\<\\s*?\\!\\-?\\-?(.*?)\\-?\\-?\\>#si'); //-- $arr_tags_2x_list_bad = array('head', 'style', 'script', 'noscript', 'frameset', 'frame', 'iframe', 'canvas', 'audio', 'video', 'applet', 'param', 'object', 'form', 'xml', 'xmp', 'o:p'); if (Smart::array_size($y_extra_tags_remove) > 0) { // add extra entries such as: img, p, div, ... for ($i = 0; $i < count($y_extra_tags_remove); $i++) { if (preg_match((string) $this->regex_tag_name, (string) $y_extra_tags_remove[$i])) { if (!in_array((string) $y_extra_tags_remove[$i], $arr_tags_2x_list_bad)) { $arr_tags_2x_list_bad[] = (string) $y_extra_tags_remove[$i]; } //end if } //end if } //end for } //end if $arr_tags_2x_repl_bad = (array) $arr_tags_0x_list_comments; for ($i = 0; $i < count($arr_tags_0x_list_comments); $i++) { $arr_tags_2x_repl_good[] = '<!-- # -->'; // comment } //end for for ($i = 0; $i < count($arr_tags_2x_list_bad); $i++) { $tmp_regex_tag = (array) $this->regex_tag((string) $arr_tags_2x_list_bad[$i]); // currently if nested tags some content between those tags may remain not removed ... but that is ok as long as the tag is replaced ; possible fix: match with siU instead of si but will go ungreedy and will match all content until very last end tag ... which may remove too many content $arr_tags_2x_repl_bad[] = $tmp_regex_tag['delimiter'] . '(' . $tmp_regex_tag['tag-start'] . ')' . '.*?' . '(' . $tmp_regex_tag['tag-end'] . ')' . $tmp_regex_tag['delimiter'] . 'si'; // fix: paranthesis are required to correct match in this case (balanced regex) $arr_tags_2x_repl_good[] = '<!-- ' . Smart::escape_html((string) $arr_tags_2x_list_bad[$i]) . '/ -->'; } //end if //-- //-- $arr_tags_1x_list_bad = (array) array_merge((array) $arr_tags_2x_list_bad, array('!doctype', 'html', 'body', 'base', 'meta', 'link', 'track', 'source', 'plaintext', 'marquee')); if (Smart::array_size($y_extra_tags_clean) > 0) { // add extra entries such as: img, p, div, ... for ($i = 0; $i < count($y_extra_tags_clean); $i++) { if (preg_match((string) $this->regex_tag_name, (string) $y_extra_tags_clean[$i])) { if (!in_array((string) $y_extra_tags_clean[$i], $arr_tags_1x_list_bad)) { $arr_tags_1x_list_bad[] = (string) $y_extra_tags_clean[$i]; } //end if } //end if } //end for } //end if $arr_tags_1x_repl_bad = array(); $arr_tags_1x_repl_good = array(); for ($i = 0; $i < count($arr_tags_1x_list_bad); $i++) { $tmp_regex_tag = (array) $this->regex_tag((string) $arr_tags_1x_list_bad[$i]); $arr_tags_1x_repl_bad[] = $tmp_regex_tag['delimiter'] . $tmp_regex_tag['tag-start'] . $tmp_regex_tag['delimiter'] . 'si'; $arr_tags_1x_repl_bad[] = $tmp_regex_tag['delimiter'] . $tmp_regex_tag['tag-end'] . $tmp_regex_tag['delimiter'] . 'si'; $arr_tags_1x_repl_good[] = '<!-- ' . Smart::escape_html((string) $arr_tags_1x_list_bad[$i]) . ' -->'; $arr_tags_1x_repl_good[] = '<!-- /' . Smart::escape_html((string) $arr_tags_1x_list_bad[$i]) . ' -->'; } //end if //-- //-- $arr_all_repl_bad = (array) array_merge((array) $arr_tags_2x_repl_bad, (array) $arr_tags_1x_repl_bad); $arr_all_repl_good = (array) array_merge((array) $arr_tags_2x_repl_good, (array) $arr_tags_1x_repl_good); //-- //print_r($arr_tags_2x_repl_bad); //print_r($arr_tags_2x_repl_good); //print_r($arr_tags_1x_repl_bad); //print_r($arr_tags_1x_repl_good); //print_r($arr_all_repl_bad); //print_r($arr_all_repl_good); //die(''); //-- //-- $this->html = (string) preg_replace((array) $arr_all_repl_bad, (array) $arr_all_repl_good, (string) $this->html); //-- //-- $this->parse_elements(); //-- //-- for ($i = 0; $i < Smart::array_size($this->elements); $i++) { //-- $code = (string) $this->elements[$i]; if (substr($code, 0, 4) != '<!--' and (strpos($code, '<') !== false or strpos($code, '>') !== false)) { // if valid tag and not a comment //-- $tag_have_endline = false; if (substr($code, -1, 1) === "\n") { $tag_have_endline = true; } //end if //-- $code = trim(str_replace(array("\t", "\n", "\r"), array(' ', ' ', ' '), (string) $code)); // make tabs and new lines as simple space $tmp_parse_attr = (array) $this->get_attributes($code); //-- if (strpos($code, ' ') !== false and Smart::array_size($tmp_parse_attr) > 0) { // tag have attributes //-- $tmp_arr = explode(' ', $code); // get tag parts $this->elements[$i] = strtolower((string) $tmp_arr[0]); // recompose the tags foreach ($tmp_parse_attr as $key => $val) { $tmp_is_valid_attr = true; if (!preg_match((string) $this->regex_tag_name, (string) $key)) { $tmp_is_valid_attr = false; // remove invalid attributes } elseif (substr((string) trim((string) $key), 0, 2) == 'on') { $tmp_is_valid_attr = false; // remove attributes starting with 'on' (all JS Events) } elseif (substr((string) trim((string) $key), 0, 10) == 'formaction') { $tmp_is_valid_attr = false; // remove attributes starting with 'formaction' } elseif (substr((string) trim((string) $val), 0, 2) == '&{') { $tmp_is_valid_attr = false; // remove attributes of which value are old Netscape JS ; Ex: border="&{getBorderWidth( )};" } elseif (substr((string) trim((string) $val), 0, 11) == 'javascript:') { $tmp_is_valid_attr = false; // remove attributes that contain javascript: } elseif (stripos((string) trim((string) $val), 'java') !== false and stripos((string) trim((string) $val), 'script') !== false and strpos((string) trim((string) $val), ':') !== false) { $tmp_is_valid_attr = false; // remove attributes that contain java + script + : } //end for if ($tmp_is_valid_attr) { $this->elements[$i] .= ' ' . strtolower($key) . '=' . '"' . str_replace(array('"', '<', '>'), array('"', '<', '>'), (string) $val) . '"'; } //end if } //end foreach $this->elements[$i] .= '>'; if ($tag_have_endline) { $this->elements[$i] .= "\n"; } //end if $tmp_arr = array(); //-- } elseif (preg_match('/^[<' . $this->expr_tag_name . '\\/ >]+$/si', (string) $code)) { // simple tags (includding tags like <br />) ; needs extra / and space //-- $this->elements[$i] = strtolower((string) $code); if ($tag_have_endline) { $this->elements[$i] .= "\n"; } //end if //-- } else { //-- $this->elements[$i] = ''; // invalid tags, clear //-- } //end if } //end if //-- } //end for //-- //-- $this->html = (string) SmartUnicode::convert_charset((string) implode('', (array) $this->elements), 'UTF-8', 'HTML-ENTITIES'); //-- if ($y_comments === false) { $this->html = preg_replace((array) $arr_tags_0x_list_comments, '', $this->html); } //end if //-- //-- if (Smart::array_size($y_allowed_tags) > 0) { $arr_striptags_allow = array(); for ($i = 0; $i < count($y_allowed_tags); $i++) { if (preg_match((string) $this->regex_tag_name, (string) $y_allowed_tags[$i])) { if (!in_array((string) $y_allowed_tags[$i], (array) $arr_striptags_allow)) { // despite if a tag is specified as unallowed, if allowed here will take precedence $arr_striptags_allow[] = '<' . $y_allowed_tags[$i] . '>'; } //end if } //end if } //end for if (Smart::array_size($arr_striptags_allow) > 0) { //print_r($arr_striptags_allow); $str_striptags_allow = (string) implode(',', (array) $arr_striptags_allow); //echo $str_striptags_allow; $this->html = (string) strip_tags((string) $this->html, (string) $str_striptags_allow); } //end if } //end if //-- //-- $this->html = (string) trim((string) $this->html); //-- //-- $use_dom = false; //-- if ($this->dom_processing !== false and class_exists('DOMDocument')) { //-- $use_dom = true; //-- if ((string) $this->html != '') { //-- @libxml_use_internal_errors(true); @libxml_clear_errors(); //-- $dom = new DOMDocument(5, (string) SMART_FRAMEWORK_CHARSET); //-- $dom->encoding = (string) SMART_FRAMEWORK_CHARSET; $dom->strictErrorChecking = false; // do not throw errors $dom->preserveWhiteSpace = true; // do not remove redundant white space $dom->formatOutput = true; // try to format pretty-print the code $dom->resolveExternals = false; // disable load external entities from a doctype declaration $dom->validateOnParse = false; // this must be explicit disabled as if set to true it may try to download the DTD and after to validate (insecure ...) //-- @$dom->loadHTML((string) $this->html, LIBXML_ERR_WARNING | LIBXML_NONET | LIBXML_PARSEHUGE | LIBXML_BIGLINES | LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); $this->html = (string) @$dom->saveHTML(); // get back from DOM //print_r($this->html); unset($dom); // clear DOM $this->html = (string) trim((string) preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\\s*~i', '', (string) $this->html)); // cleanup ; fixes: normally with the above options will add no doctype or html / body tags, but use it just in case ; alternative to this: explode by body to get content //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes' or $this->dom_log_errors === true) { // log errors if set :: OR ((string)$this->html == '') $errors = (array) @libxml_get_errors(); if (Smart::array_size($errors) > 0) { $notice_log = ''; foreach ($errors as $z => $error) { if (is_object($error)) { $notice_log .= 'PARSE-ERROR: [' . $the_ercode . '] / Level: ' . $error->level . ' / Line: ' . $error->line . ' / Column: ' . $error->column . ' / Code: ' . $error->code . ' / Message: ' . $error->message . "\n"; } //end if } //end foreach if ((string) $notice_log != '') { Smart::log_notice('SmartHtmlParser NOTICE [DOMDocument]:' . "\n" . $notice_log . "\n" . '#END' . "\n"); } //end if if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { Smart::log_notice('SmartHtmlParser / Debug HTML-String:' . "\n" . $this->html . "\n" . '#END'); } //end if } //end if } //end if //-- @libxml_clear_errors(); @libxml_use_internal_errors(false); //-- } //end if //-- } //end if //-- //-- if ($this->signature) { if ($use_dom) { $start_signature = '<!-- Smart/HTML.Cleaner [@] -->'; $end_signature = '<!-- [/@] Smart/HTML.Cleaner -->'; } else { $start_signature = '<!-- Smart/HTML.Cleaner [#] -->'; $end_signature = '<!-- [/#] Smart/HTML.Cleaner -->'; } //end if else } else { $start_signature = ''; $end_signature = ''; } //end if else //-- //-- $this->html = (string) $start_signature . $this->html . $end_signature; //-- }
private function arr_rotate(&$data, $steps) { //-- $count = Smart::array_size($data); //-- if ($steps < 0) { $steps = $count + $steps; } //end if $steps = $steps % $count; //-- for ($i = 0; $i < $steps; $i++) { array_push($data, array_shift($data)); } //end for //-- }
/** * MySQL Query :: Write. * This function is intended to be used for write type queries: BEGIN (TRANSACTION) ; COMMIT ; ROLLBACK ; INSERT ; INSERT IGNORE ; REPLACE ; UPDATE ; CREATE SCHEMAS ; CALLING STORED PROCEDURES ... * * @param STRING $queryval :: the query * @param STRING $params_or_title :: *optional* array of parameters or query title for easy debugging * @param RESOURCE $y_connection :: the connection * @return ARRAY :: [0 => 'control-message', 1 => #affected-rows] */ public static function write_data($queryval, $params_or_title = '', $y_connection = 'DEFAULT') { //== $y_connection = self::check_connection($y_connection, 'WRITE-DATA'); //== //-- samples // $queryval = 'BEGIN'; // start transaction // $queryval = 'UPDATE `tablename` SET `field` = \'value\' WHERE (`id_field` = \'val1\')'; // $queryval = 'INSERT INTO `tablename` (`desiredfield1`, `desiredfield2`) VALUES (\'val1\', \'val2\')'; // $queryval = 'DELETE FROM `tablename` WHERE (`id_field` = \'val1\')'; // $queryval = 'COMMIT'; // commit transaction (on success) // $queryval = 'ROLLBACK'; // rollback transaction (on error) //-- //-- $time_start = 0; if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { $time_start = microtime(true); } //end if //-- //-- $use_param_query = false; if (is_array($params_or_title)) { if (Smart::array_size($params_or_title) > 0) { $use_param_query = true; } //end if } //end if //-- if ($use_param_query === true) { $the_query_title = ''; $queryval = self::prepare_param_query($queryval, (array) $params_or_title, $y_connection); } else { $the_query_title = (string) $params_or_title; } //end if else //-- $result = @mysqli_query($y_connection, $queryval, MYSQLI_STORE_RESULT); $chk = @mysqli_errno($y_connection); $err = @mysqli_error($y_connection); //-- //-- $error = ''; $affected = 0; if ($chk !== 0) { $error = 'Query FAILED:' . "\n" . $err; } else { $affected = @mysqli_affected_rows($y_connection); } //end if else //-- //-- $time_end = 0; if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { $time_end = (double) (microtime(true) - (double) $time_start); } //end if //-- //-- if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { //-- SmartFrameworkRegistry::setDebugMsg('db', 'mysqli|total-queries', 1, '+'); //-- SmartFrameworkRegistry::setDebugMsg('db', 'mysqli|total-time', $time_end, '+'); //-- if (is_array($params_or_title)) { $dbg_query_params = (array) $params_or_title; } else { $dbg_query_params = ''; } //end if else //-- if (strtoupper(substr(trim($queryval), 0, 5)) == 'BEGIN' or strtoupper(substr(trim($queryval), 0, 6)) == 'COMMIT' or strtoupper(substr(trim($queryval), 0, 8)) == 'ROLLBACK') { SmartFrameworkRegistry::setDebugMsg('db', 'mysqli|log', ['type' => 'transaction', 'data' => 'TRANSACTION :: ' . $the_query_title, 'query' => $queryval, 'params' => '', 'time' => Smart::format_number_dec($time_end, 9, '.', ''), 'connection' => (string) self::get_connection_id($y_connection)]); } elseif (strtoupper(substr(trim($queryval), 0, 4)) == 'SET ') { SmartFrameworkRegistry::setDebugMsg('db', 'mysqli|log', ['type' => 'set', 'data' => 'SET :: ' . $the_query_title, 'query' => $queryval, 'params' => $dbg_query_params, 'time' => Smart::format_number_dec($time_end, 9, '.', ''), 'connection' => (string) self::get_connection_id($y_connection)]); } else { SmartFrameworkRegistry::setDebugMsg('db', 'mysqli|log', ['type' => 'write', 'data' => 'WRITE :: ' . $the_query_title, 'query' => $queryval, 'params' => $dbg_query_params, 'rows' => $affected, 'time' => Smart::format_number_dec($time_end, 9, '.', ''), 'connection' => (string) self::get_connection_id($y_connection)]); } //end if else //-- } //end if //-- //-- if (strlen($error) > 0) { //-- $message = 'errorsqlwriteoperation: ' . $error; //-- self::error(self::get_connection_id($y_connection), 'WRITE-DATA', $error, $queryval, $params_or_title); return array($message, 0); //-- } else { //-- $message = 'oksqlwriteoperation'; // this can be extended to detect extra notices //-- } //end else //-- //-- if ($result instanceof mysqli_result) { @mysqli_free_result($result); } //end if //-- //-- return array($message, Smart::format_number_int($affected, '+')); //-- }
<?php // [LIB - SmartFramework / Redis Custom Session] // (c) 2006-2016 unix-world.org - all rights reserved // v.2.3.7.3 r.2016.10.05 / smart.framework.v.2.3 //----------------------------------------------------- PREVENT SEPARATE EXECUTION WITH VERSION CHECK if (!defined('SMART_FRAMEWORK_VERSION') || (string) SMART_FRAMEWORK_VERSION != 'smart.framework.v.2.3') { die('Invalid Framework Version in PHP Script: ' . @basename(__FILE__) . ' ...'); } //end if //----------------------------------------------------- // OPTIONAL ; [REGEX-SAFE-OK] //-- if (Smart::array_size($configs['redis']) <= 0) { die('ERROR: Redis Custom Session requires the Redis server Configuration to be set in SmartFramework'); } //end if //-- //===================================================================================== //===================================================================================== CLASS START //===================================================================================== if ((string) SMART_FRAMEWORK_DEBUG_MODE == 'yes') { define('SMART_FRAMEWORK__INFO__CUSTOM_SESSION_ADAPTER', 'Redis: Memory based'); } //end if /** * Class Smart.Framework App.Custom.Session.Redis * * @access private * @internal *
private static function setInPersistentCache($the_cache_key, $y_data_arr) { //-- if (SmartPersistentCache::isActive() and SmartPersistentCache::isMemoryBased()) { if (Smart::array_size($y_data_arr) > 0) { SmartPersistentCache::setKey('smart-regional-texts', (string) $the_cache_key, (string) Smart::seryalize((array) $y_data_arr)); } //end if } //end if //-- }