public function test_parseHeaderTemplateFooter_header_footer() { $parser = new CFDBShortCodeContentParser(); $content = '{{BEFORE}}This is my header{{/BEFORE}}Name: ${fname} ${lname}{{AFTER}}This is my footer{{/AFTER}}'; $header = null; $template = null; $footer = null; list($header, $template, $footer) = $parser->parseBeforeContentAfter($content); $this->assertEquals('This is my header', $header); $this->assertEquals('Name: ${fname} ${lname}', $template); $this->assertEquals('This is my footer', $footer); }
/** * @param $plugin CF7DBPlugin * @return void */ function display(&$plugin) { if ($plugin == null) { $plugin = new CF7DBPlugin(); } $this->pageHeader($plugin); $siteUrl = get_option('home'); $user = wp_get_current_user(); $userName = $user ? $user->user_login : ''; // Identify which forms have data in the database global $wpdb; $tableName = $plugin->getSubmitsTableName(); $rows = $wpdb->get_results("select distinct `form_name` from `{$tableName}` order by `form_name`"); // if ($rows == null || count($rows) == 0) { // _e('No form submissions in the database', 'contact-form-7-to-database-extension'); // return; // } // Collect any values in $_REQUEST to pre-populate the page controls $postedForm = filter_var(isset($_REQUEST['form']) ? $_REQUEST['form'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedEnc = filter_var(isset($_REQUEST['enc']) ? $_REQUEST['enc'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedSC = filter_var(isset($_REQUEST['sc']) ? '[' . $_REQUEST['sc'] . ']' : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedTrans = filter_var(isset($_REQUEST['trans']) ? $_REQUEST['trans'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedShow = filter_var(isset($_REQUEST['show']) ? $_REQUEST['show'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedHide = filter_var(isset($_REQUEST['hide']) ? $_REQUEST['hide'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedRole = filter_var(isset($_REQUEST['role']) ? $_REQUEST['role'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedPermissionmsg = filter_var(isset($_REQUEST['permissionmsg']) ? $_REQUEST['permissionmsg'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedSearch = filter_var(isset($_REQUEST['search']) ? $_REQUEST['search'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedFilter = filter_var(isset($_REQUEST['filter']) ? $_REQUEST['filter'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedTSearch = filter_var(isset($_REQUEST['tsearch']) ? $_REQUEST['tsearch'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedTFilter = filter_var(isset($_REQUEST['tfilter']) ? $_REQUEST['tfilter'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedLimit = filter_var(isset($_REQUEST['limit']) ? $_REQUEST['limit'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedTLimit = filter_var(isset($_REQUEST['tlimit']) ? $_REQUEST['tlimit'] : '', FILTER_SANITIZE_SPECIAL_CHARS); $postedLimitComponents = explode(',', $postedLimit); $postedLimitStart = ''; $postedLimitNumRows = ''; switch (count($postedLimitComponents)) { case 2: $postedLimitStart = $postedLimitComponents[0]; $postedLimitNumRows = $postedLimitComponents[1]; break; case 1: $postedLimitNumRows = $postedLimitComponents[0]; break; default: break; } $postedUnbuffered = isset($_REQUEST['unbuffered']) ? $_REQUEST['unbuffered'] : ''; $postedRandom = isset($_REQUEST['random']) ? $_REQUEST['random'] : ''; $postedOrderby = isset($_REQUEST['orderby']) ? $_REQUEST['orderby'] : ''; $postedTOrderby = isset($_REQUEST['torderby']) ? $_REQUEST['torderby'] : ''; $postedHeader = isset($_REQUEST['header']) ? $_REQUEST['header'] : ''; $postedHeaders = isset($_REQUEST['headers']) ? $_REQUEST['headers'] : ''; $postedItemtitle = isset($_REQUEST['itemtitle']) ? $_REQUEST['itemtitle'] : ''; $postedId = isset($_REQUEST['id']) ? $_REQUEST['id'] : ''; $postedClass = isset($_REQUEST['class']) ? $_REQUEST['class'] : ''; $postedStyle = isset($_REQUEST['style']) ? $_REQUEST['style'] : ''; $postedEdit = isset($_REQUEST['edit']) ? $_REQUEST['edit'] : ''; $postedDtOptions = isset($_REQUEST['dt_options']) ? $_REQUEST['dt_options'] : ''; $postedVar = isset($_REQUEST['var']) ? $_REQUEST['var'] : ''; $postedFormat = isset($_REQUEST['format']) ? $_REQUEST['format'] : ''; $postedFunction = isset($_REQUEST['function']) ? $_REQUEST['function'] : ''; $postedDelimiter = isset($_REQUEST['delimiter']) ? $_REQUEST['delimiter'] : ''; $postedFilelinks = isset($_REQUEST['filelinks']) ? $_REQUEST['filelinks'] : ''; $postedWpautop = isset($_REQUEST['wpautop']) ? $_REQUEST['wpautop'] : ''; $postedStripbr = isset($_REQUEST['stripbr']) ? $_REQUEST['stripbr'] : ''; $postedContent = isset($_REQUEST['content']) ? $_REQUEST['content'] : ''; $postedContentBefore = ''; $postedContentAfter = ''; if ($postedContent) { $parser = new CFDBShortCodeContentParser(); list($postedContentBefore, $postedContent, $postedContentAfter) = $parser->parseBeforeContentAfter($postedContent); } $postedUrlonly = isset($_REQUEST['urlonly']) ? $_REQUEST['urlonly'] : ''; $postedLinktext = isset($_REQUEST['linktext']) ? $_REQUEST['linktext'] : ''; $infoImg = $plugin->getPluginFileUrl('/img/info.jpg'); ?> <script type="text/javascript" language="JavaScript"> var shortCodeDocUrls = { '' : 'http://cfdbplugin.com/?page_id=89', '[cfdb-html]' : 'http://cfdbplugin.com/?page_id=284', '[cfdb-table]' : 'http://cfdbplugin.com/?page_id=93', '[cfdb-datatable]' : 'http://cfdbplugin.com/?page_id=91', '[cfdb-value]' : 'http://cfdbplugin.com/?page_id=98', '[cfdb-count]' : 'http://cfdbplugin.com/?page_id=278', '[cfdb-json]' : 'http://cfdbplugin.com/?page_id=96', '[cfdb-export-link]' : 'http://cfdbplugin.com/?page_id=419' }; function showHideOptionDivs() { var shortcode = jQuery('#shortcode_ctrl').val(); jQuery('#doc_url_tag').attr('href', shortCodeDocUrls[shortcode]); jQuery('#doc_url_tag').html(shortcode + " <?php _e('Documentation', 'contact-form-7-to-database-extension'); ?> "); switch (shortcode) { case "[cfdb-html]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').show(); jQuery('#url_link_div').hide(); jQuery('#headers_div').hide(); break; case "[cfdb-table]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').show(); jQuery('#dt_options_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').show(); break; case "[cfdb-datatable]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').show(); jQuery('#dt_options_div').show(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').show(); break; case "[cfdb-value]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').show(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').hide(); break; case "[cfdb-count]": jQuery('#show_hide_div').hide(); jQuery('#limitorder_div').hide(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').hide(); break; case "[cfdb-json]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#json_div').show(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').show(); break; case "[cfdb-export-link]": jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').show(); jQuery('#headers_div').show(); break; default: jQuery('#show_hide_div').show(); jQuery('#limitorder_div').show(); jQuery('#html_format_div').hide(); jQuery('#dt_options_div').hide(); jQuery('#json_div').hide(); jQuery('#value_div').hide(); jQuery('#template_div').hide(); jQuery('#url_link_div').hide(); jQuery('#headers_div').hide(); break; } var exportSelected = jQuery('#export_cntl').val(); jQuery('#label_export_link').show(); jQuery('#label_gld_function').hide(); jQuery('#userpass_span_msg').show(); jQuery('#gld_userpass_span_msg').hide(); if (exportSelected) { if (exportSelected == 'RSS') { jQuery('#itemtitle_span').show(); } else { jQuery('#itemtitle_span').hide(); jQuery('#headers_div').show(); if (exportSelected == "GLD") { jQuery('#userpass_span_msg').hide(); jQuery('#gld_userpass_span_msg').show(); jQuery('#label_export_link').hide(); jQuery('#label_gld_function').show(); } if (exportSelected == "JSON") { jQuery('#json_div').show(); } else { jQuery('#json_div').hide(); } } } else { jQuery('#itemtitle_span').hide(); jQuery('#userpass_span_msg').show(); jQuery('#gld_userpass_span_msg').hide(); jQuery('#label_gld_script').hide(); } } function getValue(attr, value, errors) { if (value) { if (errors && value.indexOf('"') > -1) { errors.push('<?php _e('Error: "', 'contact-form-7-to-database-extension'); ?> ' + attr + '<?php _e('" should not contain double-quotes (")', 'contact-form-7-to-database-extension'); ?> '); value = value.replace('"', "'"); } return attr + '="' + value + '"'; } return ''; } function pushNameValue(attr, value, array, errors) { if (value) { if (errors && value.indexOf('"') > -1) { errors.push('<?php _e('Error: "', 'contact-form-7-to-database-extension'); ?> ' + attr + '<?php _e('" should not contain double-quotes (")', 'contact-form-7-to-database-extension'); ?> '); value = value.replace('"', "'"); } array.push(attr); array.push(value); return true; } return false; } function getValueUrl(attr, value) { if (value) { return attr + '=' + encodeURIComponent(value) } return ''; } function join(arr, delim) { if (delim == null) { delim = ' '; } var tmp = []; for (idx=0; idx<arr.length; idx++) { if (arr[idx] != '') { tmp.push(arr[idx]); } } return tmp.join(delim); } function chopLastChar(text) { return text.substr(0, text.length - 1); } function createShortCodeAndExportLink() { var scElements = []; var scUrlElements = []; var scValidationErrors = []; var exportUrlElements = []; var exportValidationErrors = []; var googleScriptElements = []; var googleScriptValidationErrors = []; var shortcode = jQuery('#shortcode_ctrl').val(); if (shortcode == '') { jQuery('#shortcode_result_text').html(''); } scElements.push(chopLastChar(shortcode)); var pushErrorMessagesToAll = function(errMsg) { scValidationErrors.push(errMsg); exportValidationErrors.push(errMsg); googleScriptValidationErrors.push(errMsg); }; var formName = jQuery('#form_name_cntl').val(); var errMsg; if (!formName) { errMsg = '<?php _e('Error: no form is chosen', 'contact-form-7-to-database-extension'); ?> '; jQuery('#form_validations_text').html(errMsg); pushErrorMessagesToAll(errMsg); } else { jQuery('#form_validations_text').html(''); scElements.push('form="' + formName + '"'); scUrlElements.push('form=' + encodeURIComponent(formName)); exportUrlElements.push('form=' + encodeURIComponent(formName)); googleScriptElements.push('<?php echo $siteUrl; ?> '); googleScriptElements.push(formName); googleScriptElements.push('<?php echo is_user_logged_in() ? wp_get_current_user()->user_login : '******'; ?> '); googleScriptElements.push('<password>'); } var pushValueToAll = function(name, val) { scElements.push(getValue(name, val, scValidationErrors)); scUrlElements.push(getValueUrl(name, val)); exportUrlElements.push(getValueUrl(name, val)); pushNameValue(name, val, googleScriptElements, googleScriptValidationErrors); }; var val; if (shortcode != '[cfdb-count]') { val = jQuery('#show_cntl').val(); pushValueToAll('show', val); val = jQuery('#hide_cntl').val(); pushValueToAll('hide', val); } val = jQuery('#role_cntl').val(); pushValueToAll('role', val); val = jQuery('#permissionmsg_cntl').val(); pushValueToAll('permissionmsg', val); val = jQuery('#trans_cntl').val(); pushValueToAll('trans', val); var handleFilterSearch = function(filterName, filter, searchName, search) { if (filter) { pushValueToAll(filterName, filter); if (search) { var errMsg = '<?php _e('Warning: "search" field ignored because FIELD is used (use one but not both)', 'contact-form-7-to-database-extension'); ?> '.replace('FIELD', filterName); pushErrorMessagesToAll(errMsg); } } else { pushValueToAll(searchName, search); } }; var filter = jQuery('#filter_cntl').val(); var search = jQuery('#search_cntl').val(); handleFilterSearch('filter', filter, 'search', search); var tfilter = jQuery('#tfilter_cntl').val(); var tsearch = jQuery('#tsearch_cntl').val(); handleFilterSearch('tfilter', tfilter, 'tsearch', tsearch); if (shortcode != '[cfdb-count]') { var handleLimit = function (limitName, limitRows, limitStart) { if (limitStart && !limitRows) { errMsg = '<?php _e('Error: "FIELD": if you provide a value for "Start Row" then you must also provide a value for "Num Rows"', 'contact-form-7-to-database-extension'); ?> '.replace('FIELD', limitName); pushErrorMessagesToAll(errMsg); } if (limitRows) { if (!/^\d+$/.test(limitRows)) { errMsg = '<?php _e('Error: "FIELD": "Num Rows" must be a positive integer', 'contact-form-7-to-database-extension'); ?> '.replace('FIELD', limitName); pushErrorMessagesToAll(errMsg); } else { var limitOption = ''; var limitOptionUrl = limitName + '='; if (limitStart) { if (!/^\d+$/.test(limitStart)) { errMsg = '<?php _e('Error: "FIELD": "Start Row" must be a positive integer', 'contact-form-7-to-database-extension'); ?> '.replace('FIELD', limitName); pushErrorMessagesToAll(errMsg); } else { limitOption += limitStart + ","; limitOptionUrl += encodeURIComponent(limitStart + ","); } } limitOption += limitRows; limitOptionUrl += limitRows; scElements.push(limitName + '="' + limitOption + '"'); scUrlElements.push(limitOptionUrl); exportUrlElements.push(limitOptionUrl); pushNameValue(limitName, limitOption, googleScriptElements, googleScriptValidationErrors); } } }; var limitRows = jQuery('#limit_rows_cntl').val(); var limitStart = jQuery('#limit_start_cntl').val(); handleLimit('limit', limitRows, limitStart); var tlimitRows = jQuery('#tlimit_rows_cntl').val(); var tlimitStart = jQuery('#tlimit_start_cntl').val(); handleLimit('tlimit', tlimitRows, tlimitStart); val = jQuery('#random_cntl').val(); scElements.push(getValue('random', val, scValidationErrors)); scUrlElements.push(getValueUrl('random', val)); pushNameValue("random", val, googleScriptElements, googleScriptValidationErrors); if (jQuery('#unbuffered_cntl').is(':checked')) { scElements.push('unbuffered="true"'); scUrlElements.push(getValueUrl('unbuffered', 'true')); exportUrlElements.push('unbuffered=true'); pushNameValue("unbuffered", "true", googleScriptElements, googleScriptValidationErrors); } var handleOrderBy = function (name, val) { if (val) { var orderByElem = getValue(name, val, scValidationErrors); var orderByElemUrl = getValueUrl(name, val); var orderByDir = jQuery('#' + name + 'dir_cntl').val(); if (orderByDir) { orderBy += ' ' + orderByDir; orderByElem = chopLastChar(orderByElem) + ' ' + orderByDir + '"'; orderByElemUrl = orderByElemUrl + encodeURIComponent(' ' + orderByDir); } scElements.push(orderByElem); scUrlElements.push(orderByElemUrl); exportUrlElements.push(orderByElemUrl); pushNameValue(name, orderBy, googleScriptElements, googleScriptValidationErrors); } }; var orderBy = jQuery('#orderby_cntl').val(); handleOrderBy('orderby', orderBy); var torderBy = jQuery('#torderby_cntl').val(); handleOrderBy('torderby', torderBy); } var scText; switch (shortcode) { case '[cfdb-html]': val = jQuery('#filelinks_cntl').val(); scElements.push(getValue('filelinks', val, scValidationErrors)); scUrlElements.push(getValueUrl('filelinks', val)); val = jQuery('#wpautop_cntl').val(); scElements.push(getValue('wpautop', val, scValidationErrors)); scUrlElements.push(getValueUrl('wpautop', val)); val = jQuery('#stripbr_cntl').val(); scElements.push(getValue('stripbr', val, scValidationErrors)); scUrlElements.push(getValueUrl('stripbr', val)); var template = jQuery('#content_cntl').val(); var content = template; var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=HTMLTemplate'); scText = join(scElements) + ']' + // Escape html tags for display on page content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') + '[/cfdb-html]'; if (template == "") { scValidationErrors.push('<?php _e('Error: [cfdb-html] has empty Template. It will not output anything. ', 'contact-form-7-to-database-extension'); ?> '); jQuery('#content_cntl').addClass('validation'); // highlight template area } else { jQuery('#content_cntl').removeClass('validation'); // remove highlight template area } break; case '[cfdb-table]': if (!jQuery('#header_cntl').is(':checked')) { scElements.push('header="false"'); scUrlElements.push(getValueUrl('header', 'false')); pushNameValue("header", "false", googleScriptElements, googleScriptValidationErrors); } val = jQuery('#headers_cntl').val(); scElements.push(getValue('headers', val, scValidationErrors)); scUrlElements.push(getValueUrl('headers', val)); val = jQuery('#id_cntl').val(); scElements.push(getValue('id', val, scValidationErrors)); scUrlElements.push(getValueUrl('id', val)); val = jQuery('#class_cntl').val(); scElements.push(getValue('class', val, scValidationErrors)); scUrlElements.push(getValueUrl('class',val)); val = jQuery('#style_cntl').val(); scElements.push(getValue('style', val, scValidationErrors)); scUrlElements.push(getValueUrl('style', val)); var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); var content = ''; if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=HTML'); scText = join(scElements) + ']'; if (content) { // Escape html tags for display on page scText += content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') + '[/cfdb-table]'; } break; case '[cfdb-datatable]': if (!jQuery('#header_cntl').is(':checked')) { scElements.push('header="false"'); scUrlElements.push(getValueUrl('header', 'false')); } val = jQuery('#headers_cntl').val(); scElements.push(getValue('headers', val, scValidationErrors)); scUrlElements.push(getValueUrl('headers', val)); val = jQuery('#id_cntl').val(); scElements.push(getValue('id', val, scValidationErrors)); scUrlElements.push(getValueUrl('id', val)); val = jQuery('#class_cntl').val(); scElements.push(getValue('class', val, scValidationErrors)); scUrlElements.push(getValueUrl('class', val)); val = jQuery('#style_cntl').val(); scElements.push(getValue('style', val, scValidationErrors)); scUrlElements.push(getValueUrl('style', val)); if (jQuery('#edit_mode_cntl').attr('checked')) { scElements.push('edit="true"'); scUrlElements.push('edit=true'); } val = jQuery('#dt_options_cntl').val(); scElements.push(getValue('dt_options', val, scValidationErrors)); scUrlElements.push(getValueUrl('dt_options', val)); var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); var content = ''; if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=DT'); scText = join(scElements) + ']'; if (content) { // Escape html tags for display on page scText += content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') + '[/cfdb-datatable]'; } break; case '[cfdb-value]': val = jQuery('#function_cntl').val(); scElements.push(getValue('function', val, scValidationErrors)); scUrlElements.push(getValueUrl('function', val)); val = jQuery('#delimiter_cntl').val(); scElements.push(getValue('delimiter', val, scValidationErrors)); scUrlElements.push(getValueUrl('delimiter', val)); var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); var content = ''; if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=VALUE'); scText = join(scElements) + ']'; if (content) { // Escape html tags for display on page scText += content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') + '[/cfdb-value]'; } break; case '[cfdb-count]': var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); var content = ''; if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=COUNT'); scText = join(scElements) + ']'; // hopLastChar(scElements.join(' ')) + ']'; if (content) { // Escape html tags for display on page scText += content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') + '[/cfdb-count]'; } break; case '[cfdb-json]': if (!jQuery('#header_cntl').is(':checked')) { scElements.push('header="false"'); scUrlElements.push(getValueUrl('header', 'false')); pushNameValue("header", "false", googleScriptElements, googleScriptValidationErrors); } val = jQuery('#headers_cntl').val(); scElements.push(getValue('headers', val, scValidationErrors)); scUrlElements.push(getValueUrl('headers', val)); val = jQuery('#var_cntl').val(); scElements.push(getValue('var', val, scValidationErrors)); scUrlElements.push(getValueUrl('var', val)); val = jQuery('#format_cntl').val(); scElements.push(getValue('format', val, scValidationErrors)); scUrlElements.push(getValueUrl('format', val)); var contentBefore = jQuery('#before_cntl').val(); var contentAfter = jQuery('#after_cntl').val(); var content = ''; if (contentBefore) { content = "<?php echo CFDBShortCodeContentParser::BEFORE_START_DELIMITER; ?> " + contentBefore + "<?php echo CFDBShortCodeContentParser::BEFORE_END_DELIMITER; ?> " + content; } if (contentAfter) { content += "<?php echo CFDBShortCodeContentParser::AFTER_START_DELIMITER; ?> " + contentAfter + "<?php echo CFDBShortCodeContentParser::AFTER_END_DELIMITER; ?> "; } scUrlElements.push('content=' + encodeURIComponent(content)); scUrlElements.push('enc=JSON'); scText = join(scElements) + ']'; if (content) { // Escape html tags for display on page scText += content.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>') + '[/cfdb-json]'; } break; case '[cfdb-export-link]': val = jQuery('#enc_cntl').val(); scElements.push(getValue('enc', val, scValidationErrors)); scUrlElements.push(getValueUrl('enc', val)); scElements.push(getValue('urlonly', jQuery('#urlonly_cntl').val(), scValidationErrors)); scElements.push(getValue('linktext', jQuery('#linktext_cntl').val(), scValidationErrors)); if (!jQuery('#header_cntl').is(':checked')) { scElements.push('header="false"'); scUrlElements.push(getValueUrl('header', 'false')); } val = jQuery('#headers_cntl').val(); scElements.push(getValue('headers', val, scValidationErrors)); scUrlElements.push(getValueUrl('headers', val)); scText = join(scElements) + ']'; break; default: scText = shortcode; break; } var urlBase = '<?php echo admin_url('admin-ajax.php'); ?> ?action=cfdb-export&'; if (shortcode) { // Output short code text var scUrl = urlBase + join(scUrlElements, '&'); jQuery('#shortcode_result_text').html('<a target="_cfdb_sc_results" href="' + scUrl + '">' + scText + '</a>'); // Output short code errors jQuery('#shortcode_validations_text').html(scValidationErrors.join('<br/>')); } else { // Don't report errors jQuery('#shortcode_validations_text').html(''); } // Export link or Google Spreadsheet function call var exportSelection = jQuery('#export_cntl').val(); if (exportSelection) { if (exportSelection != 'GLD') { exportUrlElements.push(getValueUrl('enc', exportSelection)); } if (exportSelection == 'RSS') { exportUrlElements.push(getValueUrl('itemtitle', jQuery('#add_itemtitle').val())); } else { if (!jQuery('#header_cntl').is(':checked')) { exportUrlElements.push(getValueUrl('header', 'false')); pushNameValue("header", "false", googleScriptElements, googleScriptValidationErrors); } val = jQuery('#headers_cntl').val(); exportUrlElements.push(getValueUrl('headers', val, scValidationErrors)); pushNameValue("headers", val, googleScriptElements, googleScriptValidationErrors); exportUrlElements.push(getValueUrl('format', jQuery('#format_cntl').val(), scValidationErrors)); } var user = jQuery("#gld_user").val(); var pass = jQuery("#gld_pass").val(); var obfuscate = jQuery('#obfuscate_cntl').is(':checked') if (user || pass) { if (obfuscate) { var key = '3M#v$-.u'; exportUrlElements.push("l=" + encodeURI(printHex(des(key, user + "/" + pass, 1)))); } else { exportUrlElements.push("user_login="******"user_password="******"<?php _e('Warning: the function includes your WP login information. Avoid sharing it.'); ?> "); } // Output var exportUrl = urlBase + join(exportUrlElements, '&'); if (exportSelection == 'GLD') { if (!user || !pass) { exportValidationErrors.push("<?php _e('Error: WP User and Password are required for the Google Spreadsheet to pull data from your WordPress site.'); ?> "); } if (exportUrl.length > 255) { exportValidationErrors.push("<?php _e('Because the generated URL would be too long, you must use this alternative function and add its script to your Google Spreadsheet'); ?> "); jQuery('#label_gld_script').show(); jQuery('#label_gld_function').hide(); jQuery('#export_result_text').html(formName ? ("=cfdbdata(\"" + googleScriptElements.join("\", \"") + "\")") : ""); } else { jQuery('#export_result_text').html(formName ? ("<a target='_cfdb_exp_results' href='" + exportUrl + "'>=IMPORTDATA(\"" + exportUrl + "\")</a>") : ""); } } else { jQuery('#export_result_text').html(formName ? ('<a target="_cfdb_exp_results" href="' + exportUrl + '">' + exportUrl + '</a>') : ''); } // Output export errors jQuery('#export_validations_text').html(exportValidationErrors.join('<br/>')); } else { jQuery('#export_result_text').html(''); // Don't report errors jQuery('#export_validations_text').html(''); } } var getFormFieldsUrlBase = '<?php echo $plugin->getFormFieldsAjaxUrlBase(); ?> '; function getFormFields() { jQuery('[id^=add]').attr('disabled', 'disabled'); jQuery('[id^=btn]').attr('disabled', 'disabled'); var formName = jQuery('#form_name_cntl').val(); var url = getFormFieldsUrlBase + encodeURIComponent(formName); jQuery.ajax({ dataType: "json", url: url, async: false, success: function(json) { var optionsHtml = '<option value=""></option>'; jQuery(json).each(function () { optionsHtml += '<option value="' + this + '">' + this + '</option>'; }); optionsHtml += '<option value="$_POST(param)">$_POST(param)</option>'; optionsHtml += '<option value="$_GET(param)">$_GET(param)</option>'; optionsHtml += '<option value="$_COOKIE(param)">$_COOKIE(param)</option>'; jQuery('[id^=add]').html(optionsHtml).removeAttr('disabled'); jQuery('[id^=btn]').removeAttr('disabled'); } }); } function validateSubmitTime() { var url = "<?php echo $plugin->getValidateSubmitTimeAjaxUrlBase(); ?> " + jQuery('#filter_val').val(); jQuery.get(url, function(data) { alert(data); }); } function showValidateSubmitTimeHelp(show) { if (show) { jQuery('#span_validate_submit_time').show(); } else { jQuery('#span_validate_submit_time').hide(); } } function addFieldToShow() { var value = jQuery('#show_cntl').val(); if (value) { value += ','; } jQuery('#show_cntl').val(value + jQuery('#add_show').val()); createShortCodeAndExportLink(); } function addFieldToHide() { var value = jQuery('#hide_cntl').val(); if (value) { value += ','; } jQuery('#hide_cntl').val(value + jQuery('#add_hide').val()); createShortCodeAndExportLink(); } function addFieldToOrderBy(field) { var value = jQuery('#' + field + '_cntl').val(); if (value) { value += ','; } jQuery('#' + field + '_cntl').val(value + jQuery('#add_' + field).val()); createShortCodeAndExportLink(); } function addFieldToFilter(field) { var value = jQuery('#' + field + '_cntl').val(); if (value) { value += jQuery('#' + field + '_bool').val(); } value += jQuery('#add_' + field).val() + jQuery('#' + field + '_op').val() + jQuery('#' + field + '_val').val(); jQuery('#' + field + '_cntl').val(value); createShortCodeAndExportLink(); } function addToTrans() { var value = jQuery('#trans_cntl').val(); if (value) { value += "&&"; } var field = jQuery('#add_trans').val() if (field) { value += field; value += "=" } value += jQuery('#trans_val').val(); jQuery('#trans_cntl').val(value); createShortCodeAndExportLink(); } function addFieldToHeaders() { var col = jQuery('#add_headers').val(); var disp = jQuery('#headers_val').val(); if (!col || !disp) { return; } var value = jQuery('#headers_cntl').val(); if (value) { value += ','; } value += col + '=' + disp; jQuery('#headers_cntl').val(value); createShortCodeAndExportLink(); } function addFieldToContent() { jQuery('#content_cntl').val(jQuery('#content_cntl').val() + '${' + jQuery('#add_content').val() + '}'); } function reset() { // Form jQuery('#form_name_cntl').val('<?php echo $postedForm; ?> '); getFormFields(); // Export File jQuery('#export_cntl').val('<?php echo $postedEnc; ?> '); jQuery('#add_itemtitle').val('<?php echo $postedItemtitle; ?> '); // Short Code jQuery('#shortcode_ctrl').val('<?php echo $postedSC; ?> '); jQuery('#show_cntl').val('<?php echo $postedShow; ?> '); jQuery('#hide_cntl').val('<?php echo $postedHide; ?> '); jQuery('#role_cntl').val('<?php echo $postedRole; ?> '); jQuery('#permissionmsg_cntl').val('<?php echo $postedPermissionmsg; ?> '); jQuery('#trans_cntl').val('<?php echo $postedTrans; ?> '); jQuery('#search_cntl').val('<?php echo $postedSearch; ?> '); jQuery('#filter_cntl').val('<?php echo $postedFilter; ?> '); jQuery('#tsearch_cntl').val('<?php echo $postedTSearch; ?> '); jQuery('#tfilter_cntl').val('<?php echo $postedTFilter; ?> '); jQuery('#limit_rows_cntl').val('<?php echo $postedLimitNumRows; ?> '); jQuery('#limit_start_cntl').val('<?php echo $postedLimitStart; ?> '); jQuery('#random_cntl').val('<?php echo $postedRandom; ?> '); jQuery('#unbuffered_cntl').attr("checked", false); jQuery('#orderby_cntl').val('<?php echo $postedOrderby; ?> '); jQuery('#torderby_cntl').val('<?php echo $postedTOrderby; ?> '); jQuery('#header_cntl').prop("checked", <?php echo $postedHeader == 'false' ? 'false' : 'true'; ?> ); // default = true jQuery('#headers_cntl').val('<?php echo $postedHeaders; ?> '); jQuery('#id_cntl').val('<?php echo $postedId; ?> '); jQuery('#class_cntl').val('<?php echo $postedClass; ?> '); jQuery('#style_cntl').val('<?php echo $postedStyle; ?> '); jQuery('#edit_mode_cntl').prop('checked', <?php echo $postedEdit == 'true' ? 'true' : 'false'; ?> ); // default = false jQuery('#dt_options_cntl').val('<?php echo $postedDtOptions; ?> '); jQuery('#var_cntl').val('<?php echo $postedVar; ?> '); jQuery('#format_cntl').val('<?php echo $postedFormat; ?> '); jQuery('#function_cntl').val('<?php echo $postedFunction; ?> '); jQuery('#delimiter_cntl').val('<?php echo $postedDelimiter; ?> '); jQuery('#filelinks_cntl').val('<?php echo $postedFilelinks; ?> '); jQuery('#wpautop_cntl').val('<?php echo $postedWpautop; ?> '); jQuery('#stripbr_cntl').val('<?php echo $postedStripbr; ?> '); jQuery('#content_cntl').val('<?php echo $postedContent; ?> '); jQuery('#before_cntl').val('<?php echo $postedContentBefore; ?> '); jQuery('#after_cntl').val('<?php echo $postedContentAfter; ?> '); jQuery('#enc_cntl').val('<?php echo $postedEnc; ?> '); jQuery('#urlonly_cntl').val('<?php echo $postedUrlonly; ?> '); jQuery('#linktext_cntl').val('<?php echo $postedLinktext; ?> '); showValidateSubmitTimeHelp(false); showHideOptionDivs(); createShortCodeAndExportLink(); } jQuery.ajaxSetup({ cache: false }); jQuery(document).ready(function() { reset(); showHideOptionDivs(); createShortCodeAndExportLink(); jQuery('#shortcode_ctrl').change(showHideOptionDivs); jQuery('#shortcode_ctrl').change(createShortCodeAndExportLink); jQuery('select[id$="cntl"]').change(createShortCodeAndExportLink); jQuery('input[id$="cntl"]').keyup(createShortCodeAndExportLink); jQuery('textarea[id$="cntl"]').keyup(createShortCodeAndExportLink); jQuery('#form_name_cntl').change(getFormFields); jQuery('#btn_show').click(addFieldToShow); jQuery('#btn_hide').click(addFieldToHide); jQuery('#btn_orderby').click(function () { addFieldToOrderBy('orderby'); }); jQuery('#btn_torderby').click(function () { addFieldToOrderBy('torderby'); }); jQuery('#btn_filter').click(function () { addFieldToFilter('filter'); }); jQuery('#btn_tfilter').click(function () { addFieldToFilter('tfilter'); }); jQuery('#btn_trans').click(addToTrans); jQuery('#header_cntl').click(createShortCodeAndExportLink); jQuery('#unbuffered_cntl').click(createShortCodeAndExportLink); jQuery('#edit_mode_cntl').click(createShortCodeAndExportLink); jQuery('#btn_headers').click(addFieldToHeaders); jQuery('#btn_content').click(function() { addFieldToContent(); createShortCodeAndExportLink(); }); jQuery('#enc_cntl').click(createShortCodeAndExportLink); jQuery('#urlonly_cntl').click(createShortCodeAndExportLink); jQuery('#reset_button').click(reset); jQuery('#btn_validate_submit_time').click(validateSubmitTime); jQuery('#add_filter').change(function() { showValidateSubmitTimeHelp(jQuery('#add_filter').val() == "submit_time"); }); jQuery('#export_cntl').change(function() { showHideOptionDivs(); createShortCodeAndExportLink(); }); jQuery('#add_itemtitle').change(createShortCodeAndExportLink); jQuery('#gld_user').change(createShortCodeAndExportLink); jQuery('#gld_user').keyup(createShortCodeAndExportLink); jQuery('#gld_pass').change(createShortCodeAndExportLink); jQuery('#gld_pass').keyup(createShortCodeAndExportLink); jQuery('#obfuscate_cntl').click(createShortCodeAndExportLink); jQuery('#form_name_cntl').change(createShortCodeAndExportLink); }); </script> <style type="text/css"> div.shortcodeoptions { border: #ccccff groove; margin-bottom: 10px; padding: 5px; } div.shortcodeoptions label { font-weight: bold; font-family: Arial sans-serif; margin-top: 5px; } #shortcode_result_div { margin-top: 1em; } .label_box { display: inline-block; min-width: 50px; padding-left: 2px; padding-right: 2px; border: 1px; margin-right: 5px; } .generated { margin-top: 5px; margin-bottom: 5px; margin-left: 10px; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre-wrap; white-space: pre-wrap; word-wrap: break-word; font-size: larger; font-weight: bold; font-family: "courier new", monospace; background-color: #ffffc3; } .validation { background-color: #ffe200; font-style:italic; } </style> <h2><?php _e('Export and Short Code Builder', 'contact-form-7-to-database-extension'); ?> </h2> <?php // FORM ?> <div class="shortcodeoptions" style="margin-top:10px;"> <div class="label_box"><label for="form_name_cntl"><?php _e('form', 'contact-form-7-to-database-extension'); ?> </label></div> <select name="form_name_cntl" id="form_name_cntl"> <option value=""><?php _e('* Select a form *', 'contact-form-7-to-database-extension'); ?> </option> <?php foreach ($rows as $aRow) { $formName = $aRow->form_name; ?> <option value="<?php echo $formName; ?> "><?php echo $formName; ?> </option> <?php } ?> </select> <?php // RESET ?> <span style="margin-left:10px"> <button id="reset_button"><?php _e('Reset', 'contact-form-7-to-database-extension'); ?> </button> </span> <div id="form_validations_text" class="validation"></div> </div> <?php // EXPORT ?> <div class="shortcodeoptions"> <label for="export_cntl"><?php _e('Export File', 'contact-form-7-to-database-extension'); ?> </label> <select id="export_cntl" name="export_cntl"> <option value=""></option> <option value="CSVUTF8BOM"> <?php _e('Excel CSV (UTF8-BOM)', 'contact-form-7-to-database-extension'); ?> </option> <option value="TSVUTF16LEBOM"> <?php _e('Excel TSV (UTF16LE-BOM)', 'contact-form-7-to-database-extension'); ?> </option> <option value="CSVUTF8"> <?php _e('Plain CSV (UTF-8)', 'contact-form-7-to-database-extension'); ?> </option> <option value="CSVSJIS"> <?php _e('Excel CSV for Japanese (Shift-JIS)', 'contact-form-7-to-database-extension'); ?> </option> <option value="IQY"> <?php _e('Excel Internet Query', 'contact-form-7-to-database-extension'); ?> </option> <option value="GLD"> <?php _e('Google Spreadsheet Live Data', 'contact-form-7-to-database-extension'); ?> </option> <option value="RSS"> <?php _e('RSS', 'contact-form-7-to-database-extension'); ?> </option> <option value="JSON"> <?php _e('JSON', 'contact-form-7-to-database-extension'); ?> </option> </select> <span id="itemtitle_span"> <label for="add_itemtitle"><?php _e('Item Title', 'contact-form-7-to-database-extension'); ?> </label> <select name="add_itemtitle" id="add_itemtitle"></select> </span> <span id="userpass_span"> <br/> <span id="gld_userpass_span_msg"> <?php _e('Provide a WP login for the Google Spreadsheet to use to connect to your WP site', 'contact-form-7-to-database-extension'); ?> </span> <span id="userpass_span_msg" style="display: none"> <?php _e('Optional: provide a WP login for the link to work without being already logged in', 'contact-form-7-to-database-extension'); ?> </span> <br/> <label for="gld_user"><?php _e('WP User', 'contact-form-7-to-database-extension'); ?> </label> <input id="gld_user" type="text" value="<?php echo $userName; ?> "/> <label for="gld_pass"><?php _e('WP Password', 'contact-form-7-to-database-extension'); ?> </label> <input id="gld_pass" type="password" value=""/> <input id="obfuscate_cntl" type="checkbox" checked/><?php _e('Hide Credentials', 'contact-form-7-to-database-extension'); ?> </span> <div id="export_result_div"> <span id="label_export_link"><?php _e('Generated Export Link:', 'contact-form-7-to-database-extension'); ?> </span> <span id="label_gld_function" style="display:none"> <?php _e('Enter this function into a cell in your Google Spreadsheet:', 'contact-form-7-to-database-extension'); ?> </span> <span id="label_gld_script" style="display:none"> <?php _e('Generated Google Spreadsheet Function:', 'contact-form-7-to-database-extension'); ?> <?php _e('Replace <strong><password></strong> with your <em>WordPress</em> password', 'contact-form-7-to-database-extension'); ?> <br/> <?php _e('Requires code installed in your Google Spreadsheet script editor.'); ?> <a target="code" href="<?php echo $siteUrl; ?> /wp-content/plugins/contact-form-7-to-database-extension/CFDBGoogleSSLiveData.php"><?php _e('Get code'); ?> </a>. <a target="instructions" href="<?php echo $siteUrl; ?> /wp-admin/admin-ajax.php?action=cfdb-export&enc=GLD&form=<?php echo $postedForm; ?> "><?php _e('See instructions.'); ?> </a> </span> <br/><div class="generated" id="export_result_text"></div> </div> <div id="export_validations_text" class="validation"></div> </div> <?php // SHORT CODE ?> <div class="shortcodeoptions"> <div style="margin-bottom:10px"> <div class="label_box"><label for="shortcode_ctrl"><?php _e('Short Code', 'contact-form-7-to-database-extension'); ?> </label> </div> <select name="shortcode_ctrl" id="shortcode_ctrl"> <option value=""><?php _e('* Select a short code *', 'contact-form-7-to-database-extension'); ?> </option> <option value="[cfdb-html]">[cfdb-html]</option> <option value="[cfdb-table]">[cfdb-table]</option> <option value="[cfdb-datatable]">[cfdb-datatable]</option> <option value="[cfdb-value]">[cfdb-value]</option> <option value="[cfdb-count]">[cfdb-count]</option> <option value="[cfdb-json]">[cfdb-json]</option> <option value="[cfdb-export-link]">[cfdb-export-link]</option> </select> <a id="doc_url_tag" target="_docs" href="http://cfdbplugin.com/?page_id=89"><?php _e('Documentation', 'contact-form-7-to-database-extension'); ?> </a> <br/> </div> <div id="shortcode_result_div"> <?php _e('Generated Short Code:', 'contact-form-7-to-database-extension'); ?> <br/><div class="generated" id="shortcode_result_text"></div> </div> <div id="shortcode_validations_text" class="validation"></div> <span style="font-size: x-small;"> <a target="_docs" href="http://cfdbplugin.com/?page_id=444"><?php _e('(Did you know: you can create your own short code)', 'contact-form-7-to-database-extension'); ?> </a> </span> </div> <div id="security_div" class="shortcodeoptions"> <?php _e('Security', 'contact-form-7-to-database-extension'); ?> <div> <div class="label_box"> <label for="role_cntl"><?php _e('role', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=89#role"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select id="role_cntl" name="role_cntl"> <option value=""></option> <option value="Administrator"><?php _e('Administrator', 'contact-form-7-to-database-extension'); ?> </option> <option value="Editor"><?php _e('Editor', 'contact-form-7-to-database-extension'); ?> </option> <option value="Author"><?php _e('Author', 'contact-form-7-to-database-extension'); ?> </option> <option value="Contributor"><?php _e('Contributor', 'contact-form-7-to-database-extension'); ?> </option> <option value="Subscriber"><?php _e('Subscriber', 'contact-form-7-to-database-extension'); ?> </option> <option value="Anyone"><?php _e('Anyone', 'contact-form-7-to-database-extension'); ?> </option> </select> <div class="label_box"> <label for="permissionmsg_cntl"><?php _e('permissionmsg', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=89#permissionmsg"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select id="permissionmsg_cntl" name="permissionmsg_cntl"> <option value=""></option> <option value="true"><?php _e('true', 'contact-form-7-to-database-extension'); ?> </option> <option value="false"><?php _e('false', 'contact-form-7-to-database-extension'); ?> </option> </select> </div> </div> <?php // SHOW HIDE ?> <div id="show_hide_div" class="shortcodeoptions"> <?php _e('Which fields/columns do you want to display?', 'contact-form-7-to-database-extension'); ?> <div> <div class="label_box"> <label for="show_cntl"><?php _e('show', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=89#show"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select name="add_show" id="add_show"></select><button id="btn_show">»</button> <input name="show_cntl" id="show_cntl" type="text" size="100" placeholder="<?php _e('field1,field2,field3', 'contact-form-7-to-database-extension'); ?> "/> </div> <div> <div class="label_box"> <label for="hide_cntl"><?php _e('hide', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=89#hide"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select name="add_hide" id="add_hide"></select><button id="btn_hide">»</button> <input name="hide_cntl" id="hide_cntl" type="text" size="100" placeholder="<?php _e('field1,field2,field3', 'contact-form-7-to-database-extension'); ?> "/> </div> </div> <?php // SEARCH FILTER ?> <div id="filter_div" class="shortcodeoptions"> <div><?php _e('Which rows/submissions do you want to display?', 'contact-form-7-to-database-extension'); ?> </div> <div> <div class="label_box"> <label for="search_cntl"><?php _e('search', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=89#search"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input name="search_cntl" id="search_cntl" type="text" size="30" placeholder="<?php _e('search text', 'contact-form-7-to-database-extension'); ?> "/> </div> <div> <div class="label_box"> <label for="filter_cntl"><?php _e('filter', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=89#filter"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select name="filter_bool" id="filter_bool"> <option value="&&">&&</option> <option value="||">||</option> </select> <select name="add_filter" id="add_filter"></select> <select name="filter_op" id="filter_op"> <option value="=">=</option> <option value="!=">!=</option> <option value=">">></option> <option value="<"><</option> <option value="<="><=</option> <option value="<="><=</option> <option value="===">===</option> <option value="!==">!==</option> <option value="~~">~~</option> </select> <input name="filter_val" id="filter_val" type="text" size="20" placeholder="<?php _e('value', 'contact-form-7-to-database-extension'); ?> "/> <button id="btn_filter">»</button> <span id="span_validate_submit_time" style="display:none;"> <button id="btn_validate_submit_time"><?php _e('Validate submit_time', 'contact-form-7-to-database-extension'); ?> </button> <a target="_blank" href="http://cfdbplugin.com/?page_id=553"><?php _e('Formats', 'contact-form-7-to-database-extension'); ?> </a> </span> <br/> <input name="filter_cntl" id="filter_cntl" type="text" size="100" placeholder="<?php _e('filter expression', 'contact-form-7-to-database-extension'); ?> "/> </div> </div> <?php // LIMIT, ORDER BY, RANDOM ?> <div id="limitorder_div" class="shortcodeoptions"> <div> <div class="label_box"> <label for="limit_rows_cntl"><?php _e('limit', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=89#limit"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <?php _e('Num Rows', 'contact-form-7-to-database-extension'); ?> <input name="limit_rows_cntl" id="limit_rows_cntl" type="text" size="10" placeholder="<?php _e('number', 'contact-form-7-to-database-extension'); ?> "/> <?php _e('Start Row (0)', 'contact-form-7-to-database-extension'); ?> <input name="limit_start_cntl" id="limit_start_cntl" type="text" size="10" placeholder="<?php _e('number', 'contact-form-7-to-database-extension'); ?> "/> </div> <div> <div class="label_box"> <label for="unbuffered_cntl"><?php _e('unbuffered', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?p=696"><img alt="?" src="<?php echo $infoImg; ?> "/></a> <input id="unbuffered_cntl" type="checkbox" <?php echo $postedUnbuffered == 'true' ? 'checked' : ''; ?> /> </div> </div> <div> <div class="label_box"> <label for="random_cntl"><?php _e('random', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=89#random"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input name="random_cntl" id="random_cntl" type="text" size="10" placeholder="<?php _e('number', 'contact-form-7-to-database-extension'); ?> "/> </div> <div id="orderby_div"> <div class="label_box"> <label for="orderby_cntl"><?php _e('orderby', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=89#orderby"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select name="add_orderby" id="add_orderby"></select><button id="btn_orderby" placeholder="<?php _e('field', 'contact-form-7-to-database-extension'); ?> ">»</button> <input name="orderby_cntl" id="orderby_cntl" type="text" size="100" placeholder="<?php _e('field1,field2,field3', 'contact-form-7-to-database-extension'); ?> "/> <select id="orderbydir_cntl" name="orderbydir_cntl"> <option value=""></option> <option value="ASC"><?php _e('ASC', 'contact-form-7-to-database-extension'); ?> </option> <option value="DESC"><?php _e('DESC', 'contact-form-7-to-database-extension'); ?> </option> </select> </div> </div> <?php // HEADERS ?> <div id="headers_div" class="shortcodeoptions"> <div><?php _e('Table Headers', 'contact-form-7-to-database-extension'); ?> </div> <div> <div class="label_box"> <input id="header_cntl" type="checkbox" checked/> <label for="header_cntl"><?php _e('Include Header Row', 'contact-form-7-to-database-extension'); ?> </label> </div> </div> <div> <div class="label_box"> <label for="headers_cntl"><?php _e('headers', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=93#headers"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select name="add_headers" id="add_headers"></select> <?php _e('display as', 'contact-form-7-to-database-extension'); ?> <input name="headers_val" id="headers_val" type="text" size="20" placeholder="<?php _e('display value', 'contact-form-7-to-database-extension'); ?> "/> <button id="btn_headers">»</button> <br/> <input name="headers_cntl" id="headers_cntl" type="text" size="100" placeholder="<?php _e('field1=Display Name 1,field2=Display Name 2', 'contact-form-7-to-database-extension'); ?> "/> </div> </div> <?php // ID, CLASS, STYLE ?> <div id="html_format_div" class="shortcodeoptions"> <div><?php _e('HTML Table Formatting', 'contact-form-7-to-database-extension'); ?> </div> <div> <div class="label_box"> <label for="id_cntl"><?php _e('id', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=93#id"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input name="id_cntl" id="id_cntl" type="text" size="10" placeholder="<?php _e('HTML id', 'contact-form-7-to-database-extension'); ?> "/> </div> <div> <div class="label_box"> <label for="class_cntl"><?php _e('class', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=93#class"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input name="class_cntl" id="class_cntl" type="text" size="10" placeholder="<?php _e('HTML class', 'contact-form-7-to-database-extension'); ?> "/> </div> <div> <div class="label_box"> <label for="style_cntl"><?php _e('style', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=93#style"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input name="style_cntl" id="style_cntl" type="text" size="100" placeholder="<?php _e('CSS style', 'contact-form-7-to-database-extension'); ?> "/> </div> </div> <?php // DT_OPTIONS ?> <div id="dt_options_div" class="shortcodeoptions"> <div><?php _e('[cfdb-datatable] Options', 'contact-form-7-to-database-extension'); ?> </div> <div> <div class="label_box"> <label for="edit_mode_cntl"><?php _e('edit', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=91#edit"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input type="checkbox" id="edit_mode_cntl" name="edit_mode_cntl" /> </div> <div> <div class="label_box"> <label for="dt_options_cntl"><?php _e('dt_options', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=91#dt_options"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input name="dt_options_cntl" id="dt_options_cntl" type="text" size="100" placeholder="<?php _e('datatable options (JSON)', 'contact-form-7-to-database-extension'); ?> "/> </div> </div> <?php // JSON VAR, FORMAT ?> <div id="json_div" class="shortcodeoptions"> <div><?php _e('[cfdb-json] Options', 'contact-form-7-to-database-extension'); ?> </div> <div> <div class="label_box"> <label for="var_cntl"><?php _e('var', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=96#var"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input name="var_cntl" id="var_cntl" type="text" size="10" placeholder="<?php _e('JS var name', 'contact-form-7-to-database-extension'); ?> "/> </div> <div> <div class="label_box"> <label for="format_cntl"><?php _e('format', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=96#format"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select id="format_cntl" name="format_cntl"> <option value=""></option> <option value="map"><?php _e('map', 'contact-form-7-to-database-extension'); ?> </option> <option value="array"><?php _e('array', 'contact-form-7-to-database-extension'); ?> </option> <option value="arraynoheader"><?php _e('arraynoheader', 'contact-form-7-to-database-extension'); ?> </option> </select> </div> </div> <?php // VALUE FUNCTION, DELIMITER ?> <div id="value_div" class="shortcodeoptions"> <div><?php _e('[cfdb-value] Options', 'contact-form-7-to-database-extension'); ?> </div> <div> <div class="label_box"> <label for="function_cntl"><?php _e('function', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=98#function"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select id="function_cntl" name="function_cntl"> <option value=""></option> <option value="min"><?php _e('min', 'contact-form-7-to-database-extension'); ?> </option> <option value="max"><?php _e('max', 'contact-form-7-to-database-extension'); ?> </option> <option value="sum"><?php _e('sum', 'contact-form-7-to-database-extension'); ?> </option> <option value="mean"><?php _e('mean', 'contact-form-7-to-database-extension'); ?> </option> <option value="percent"><?php _e('percent', 'contact-form-7-to-database-extension'); ?> </option> </select> </div> <div> <div class="label_box"> <label for="delimiter_cntl"><?php _e('delimiter', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=98#delimiter"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input name="delimiter_cntl" id="delimiter_cntl" type="text" size="10"/> </div> </div> <?php // HTML TEMPLATE ?> <div id="template_div" class="shortcodeoptions"> <div><?php _e('[cfdb-html] Options', 'contact-form-7-to-database-extension'); ?> </div> <div> <div class="label_box"> <label for="filelinks_cntl"><?php _e('filelinks', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=284#filelinks"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select id="filelinks_cntl" name="filelinks_cntl"> <option value=""></option> <option value="url"><?php _e('url', 'contact-form-7-to-database-extension'); ?> </option> <option value="name"><?php _e('name', 'contact-form-7-to-database-extension'); ?> </option> <option value="link"><?php _e('link', 'contact-form-7-to-database-extension'); ?> </option> <option value="img"><?php _e('img', 'contact-form-7-to-database-extension'); ?> </option> </select> <div class="label_box"> <label for="stripbr_cntl"><?php _e('stripbr', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=284#stripbr"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select id="stripbr_cntl" name="stripbr_cntl"> <option value=""></option> <option value="false"><?php _e('false', 'contact-form-7-to-database-extension'); ?> </option> <option value="true"><?php _e('true', 'contact-form-7-to-database-extension'); ?> </option> </select> <div class="label_box"> <label for="wpautop_cntl" style="text-decoration:line-through;"><?php _e('wpautop', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=284#wpautop"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select id="wpautop_cntl" name="wpautop_cntl"> <option value=""></option> <option value="false"><?php _e('false', 'contact-form-7-to-database-extension'); ?> </option> <option value="true"><?php _e('true', 'contact-form-7-to-database-extension'); ?> </option> </select> </div> <div> <div class="label_box"> <label for="content_cntl"><?php _e('Template', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=284#template"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select name="add_content" id="add_content"></select><button id="btn_content">»</button><br/> <textarea name="content_cntl" id="content_cntl" cols="100" rows="10" placeholder="<?php _e('Per-entry HTML using ${field name} variables', 'contact-form-7-to-database-extension'); ?> "></textarea> </div> </div> <?php // URL ENC, URL_ONLY LINK_TEXT ?> <div id="url_link_div" class="shortcodeoptions"> <div><?php _e('[cfdb-export-link] Options', 'contact-form-7-to-database-extension'); ?> </div> <div> <div class="label_box"> <label for="enc_cntl"><?php _e('enc', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=419"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select id="enc_cntl" name="enc_cntl"> <option value=""></option> <option id="CSVUTF8BOM" value="CSVUTF8BOM"> <?php _e('Excel CSV (UTF8-BOM)', 'contact-form-7-to-database-extension'); ?> </option> <option id="TSVUTF16LEBOM" value="TSVUTF16LEBOM"> <?php _e('Excel TSV (UTF16LE-BOM)', 'contact-form-7-to-database-extension'); ?> </option> <option id="CSVUTF8" value="CSVUTF8"> <?php _e('Plain CSV (UTF-8)', 'contact-form-7-to-database-extension'); ?> </option> <option value="CSVSJIS"> <?php _e('Excel CSV for Japanese (Shift-JIS)', 'contact-form-7-to-database-extension'); ?> </option> <option id="IQY" value="IQY"> <?php _e('Excel Internet Query', 'contact-form-7-to-database-extension'); ?> </option> </select> </div> <div> <div class="label_box"> <label for="urlonly_cntl"><?php _e('urlonly', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=419#urlonly"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select id="urlonly_cntl" name="urlonly_cntl"> <option value=""></option> <option value="true"><?php _e('true', 'contact-form-7-to-database-extension'); ?> </option> <option value="false"><?php _e('false', 'contact-form-7-to-database-extension'); ?> </option> </select> </div> <div> <div class="label_box"> <label for="linktext_cntl"><?php _e('linktext', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=419#linktext"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input name="linktext_cntl" id="linktext_cntl" type="text" size="30"/> </div> </div> <?php // BEFORE and AFTER ?> <div id="beforeafter_div" class="shortcodeoptions"> <div> <div class="label_box"> <label for="before_cntl"><?php _e('Before', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=284#before"><img alt="?" src="<?php echo $infoImg; ?> "/></a><br/> </div> <br/> <textarea name="before_cntl" id="before_cntl" cols="100" rows="5" placeholder="<?php _e('Optional HTML/Javascript before the short code output', 'contact-form-7-to-database-extension'); ?> "></textarea> </div> <div> <div class="label_box"> <label for="after_cntl"><?php _e('After', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=284#after"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <br/> <textarea name="after_cntl" id="after_cntl" cols="100" rows="5" placeholder="<?php _e('Optional HTML/Javascript after the short code output', 'contact-form-7-to-database-extension'); ?> "></textarea> </div> </div> <?php // TRANS ?> <div id="trans_div" class="shortcodeoptions"> <?php _e('Transform', 'contact-form-7-to-database-extension'); ?> <div> <div class="label_box"> <label for="trans_cntl"><?php _e('trans', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=1118#trans"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select name="add_trans" id="add_trans"></select> <input name="trans_val" id="trans_val" type="text" size="20" placeholder="<?php _e('PHP function or class', 'contact-form-7-to-database-extension'); ?> "/> <button id="btn_trans">»</button> <br/> <input name="trans_cntl" id="trans_cntl" type="text" size="100" placeholder="<?php _e('transform expression', 'contact-form-7-to-database-extension'); ?> "/> </div> <div> <div class="label_box"> <label for="tsearch_cntl"><?php _e('tsearch', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=1118#tsearch"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <input name="tsearch_cntl" id="tsearch_cntl" type="text" size="30" placeholder="<?php _e('search text', 'contact-form-7-to-database-extension'); ?> "/> </div> <div> <div class="label_box"> <label for="tfilter_cntl"><?php _e('tfilter', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=1118#tfilter"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select name="tfilter_bool" id="tfilter_bool"> <option value="&&">&&</option> <option value="||">||</option> </select> <select name="add_tfilter" id="add_tfilter"></select> <select name="tfilter_op" id="tfilter_op"> <option value="=">=</option> <option value="!=">!=</option> <option value=">">></option> <option value="<"><</option> <option value="<="><=</option> <option value="<="><=</option> <option value="===">===</option> <option value="!==">!==</option> <option value="~~">~~</option> </select> <input name="tfilter_val" id="tfilter_val" type="text" size="20" placeholder="<?php _e('value', 'contact-form-7-to-database-extension'); ?> "/> <button id="btn_tfilter">»</button> <span id="span_validate_submit_time" style="display:none;"> <button id="btn_validate_submit_time"><?php _e('Validate submit_time', 'contact-form-7-to-database-extension'); ?> </button> <a target="_blank" href="http://cfdbplugin.com/?page_id=553"><?php _e('Formats', 'contact-form-7-to-database-extension'); ?> </a> </span> <br/> <input name="tfilter_cntl" id="tfilter_cntl" type="text" size="100" placeholder="<?php _e('filter expression', 'contact-form-7-to-database-extension'); ?> "/> </div> <div> <div class="label_box"> <label for="tlimit_rows_cntl"><?php _e('tlimit', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=1118#tlimit"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <?php _e('Num Rows', 'contact-form-7-to-database-extension'); ?> <input name="tlimit_rows_cntl" id="tlimit_rows_cntl" type="text" size="10" placeholder="<?php _e('number', 'contact-form-7-to-database-extension'); ?> "/> <?php _e('Start Row (0)', 'contact-form-7-to-database-extension'); ?> <input name="tlimit_start_cntl" id="tlimit_start_cntl" type="text" size="10" placeholder="<?php _e('number', 'contact-form-7-to-database-extension'); ?> "/> </div> <div id="torderby_div"> <div class="label_box"> <label for="torderby_cntl"><?php _e('torderby', 'contact-form-7-to-database-extension'); ?> </label> <a target="_docs" href="http://cfdbplugin.com/?page_id=1118#torderby"><img alt="?" src="<?php echo $infoImg; ?> "/></a> </div> <select name="add_torderby" id="add_torderby"></select><button id="btn_torderby" placeholder="<?php _e('field', 'contact-form-7-to-database-extension'); ?> ">»</button> <input name="torderby_cntl" id="torderby_cntl" type="text" size="100" placeholder="<?php _e('field1,field2,field3', 'contact-form-7-to-database-extension'); ?> "/> <select id="torderbydir_cntl" name="torderbydir_cntl"> <option value=""></option> <option value="ASC"><?php _e('ASC', 'contact-form-7-to-database-extension'); ?> </option> <option value="DESC"><?php _e('DESC', 'contact-form-7-to-database-extension'); ?> </option> </select> </div> </div> <?php }
/** * @param $formName string * @param $options array of option_name => option_value * @return void|string */ public function export($formName, $options = null) { $this->setOptions($options); $this->setCommonOptions(true); $filelinks = ''; $wpautop = false; $stripBR = false; if ($this->options && is_array($this->options)) { if (isset($this->options['filelinks'])) { $filelinks = $this->options['filelinks']; } if (isset($this->options['wpautop'])) { $wpautop = $this->options['wpautop'] == 'true'; } if (isset($this->options['stripbr'])) { $stripBR = $this->options['stripbr'] == 'true'; } } // Security Check if (!$this->isAuthorized()) { $this->assertSecurityErrorMessage(); return; } // Headers $this->echoHeaders('Content-Type: text/html; charset=UTF-8'); if (empty($options) || !isset($options['content'])) { return; } if ($this->isFromShortCode) { ob_start(); } // Get the data $submitTimeKeyName = 'Submit_Time_Key'; $this->setDataIterator($formName, $submitTimeKeyName); $options['content'] = $this->modifyContent($options['content']); $matches = array(); preg_match_all('/\\$\\{([^}]+)\\}/', $options['content'], $matches); $colNamesToSub = array(); $varNamesToSub = array(); if (!empty($matches) && is_array($matches[1])) { foreach ($matches[1] as $aSubVar) { // Each is expected to be a name of a column if (in_array($aSubVar, $this->dataIterator->getDisplayColumns())) { $colNamesToSub[] = $aSubVar; $varNamesToSub[] = '${' . $aSubVar . '}'; } else { if ($aSubVar == 'submit_time') { $colNamesToSub[] = 'submit_time'; $varNamesToSub[] = '${submit_time}'; } } } } // WordPress likes to wrap the content in <br />content<p> which messes up things when // you are putting // <tr><td>stuff<td></tr> // as the content because it comes out // <br /><tr><td>stuff<td></tr><p> // which messed up the table html. // So we try to identify that and strip it out. // This is related to http://codex.wordpress.org/Function_Reference/wpautop // see also http://wordpress.org/support/topic/shortcodes-are-wrapped-in-paragraph-tags?replies=4 if (!$wpautop) { //echo 'Initial: \'' . htmlentities($options['content']) . '\''; if (substr($options['content'], 0, 6) == '<br />' && substr($options['content'], -3, 3) == '<p>') { $options['content'] = substr($options['content'], 6, strlen($options['content']) - 6 - 3); } if (substr($options['content'], 0, 4) == '</p>' && substr($options['content'], -3, 3) == '<p>') { $options['content'] = substr($options['content'], 4, strlen($options['content']) - 4 - 3); } //echo '<br/>Stripped: \'' . htmlentities($options['content']) . '\''; } if ($stripBR) { // Strip out BR tags presumably injected by wpautop $options['content'] = str_replace('<br />', '', $options['content']); } // Break out sections: Before, Template, After $before = ''; $template = ''; $after = ''; if (isset($options['content'])) { $contentParser = new CFDBShortCodeContentParser(); list($before, $template, $after) = $contentParser->parseBeforeContentAfter($options['content']); } if ($before) { // Allow for short codes in "before" echo do_shortcode($before); } while ($this->dataIterator->nextRow()) { // todo: Evaluation IF-expressions if (empty($colNamesToSub)) { // Process nested short codes echo do_shortcode($template); } else { $fields_with_file = null; if ($filelinks != 'name' && isset($this->dataIterator->row['fields_with_file']) && $this->dataIterator->row['fields_with_file'] != null) { $fields_with_file = explode(',', $this->dataIterator->row['fields_with_file']); } $replacements = array(); foreach ($colNamesToSub as $aCol) { if ($fields_with_file && in_array($aCol, $fields_with_file)) { switch ($filelinks) { case 'url': $replacements[] = $this->plugin->getFileUrl($this->dataIterator->row[$submitTimeKeyName], $formName, $aCol); break; case 'link': if (isset($this->dataIterator->row[$aCol])) { $replacements[] = '<a href="' . $this->plugin->getFileUrl($this->dataIterator->row[$submitTimeKeyName], $formName, $aCol) . '">' . htmlentities($this->dataIterator->row[$aCol], null, 'UTF-8') . '</a>'; } break; case 'image': case 'img': if (isset($this->dataIterator->row[$aCol])) { $replacements[] = '<img src="' . $this->plugin->getFileUrl($this->dataIterator->row[$submitTimeKeyName], $formName, $aCol) . '" alt="' . htmlentities($this->dataIterator->row[$aCol], null, 'UTF-8') . '" />'; } break; case 'name': default: if (isset($this->dataIterator->row[$aCol])) { $replacements[] = htmlentities($this->dataIterator->row[$aCol], null, 'UTF-8'); } } } else { if (isset($this->dataIterator->row[$aCol])) { $replacements[] = htmlentities($this->dataIterator->row[$aCol], null, 'UTF-8'); } } } // Preserve line breaks in the field foreach ($replacements as $i => $repl) { $replacements[$i] = nl2br($replacements[$i]); // preserve line breaks } // Process nested short codes echo do_shortcode(str_replace($varNamesToSub, $replacements, $template)); } } if ($after) { // Allow for short codes in "after" echo do_shortcode($after); } if ($this->isFromShortCode) { // If called from a shortcode, need to return the text, // otherwise it can appear out of order on the page $output = ob_get_contents(); ob_end_clean(); return $output; } }
/** * @param string $formName * @param null $options * @return void|String */ public function export($formName, $options = null) { // Allow for multiple form name inputs, comma-delimited $tmp = explode(',', $formName); if (count($tmp) > 1) { $formName =& $tmp; } else { if ($formName == '*') { $formName = null; // Allow for no form specified implying all forms } } $this->setOptions($options); $this->setCommonOptions(); // Security Check if (!$this->isAuthorized()) { $this->assertSecurityErrorMessage(); return; } // Break out sections: Before, Content, After $before = ''; $content = ''; $after = ''; if (isset($options['content'])) { $contentParser = new CFDBShortCodeContentParser(); list($before, $content, $after) = $contentParser->parseBeforeContentAfter($options['content']); } if ($before) { $before = do_shortcode($before); } if ($after) { $after = do_shortcode($after); } // See if a function is to be applied $funct = null; $delimiter = ', '; if ($this->options && is_array($this->options)) { if (isset($this->options['function'])) { $funct = $this->options['function']; } if (isset($this->options['delimiter'])) { $delimiter = $this->options['delimiter']; } } // Headers // don't set content type to text because in some browsers this becomes // the content type for the whole HTML page. $this->echoHeaders(); //'Content-Type: text/plain; charset=UTF-8'); // Get the data $this->setDataIterator($formName); // count function or coming from cfdb-count shortcode if (count($this->showColumns) == 0 && count($this->hideColumns) == 0) { if ($funct == 'count') { $count = 0; while ($this->dataIterator->nextRow()) { $count += 1; } if ($this->isFromShortCode) { return $before . $count . $after; } else { echo $before . $count . $after; return; } } } if ($funct) { // Apply function to dataset switch ($funct) { case 'count': $count = 0; $colsPerRow = count($this->dataIterator->getDisplayColumns()); while ($this->dataIterator->nextRow()) { $count += $colsPerRow; } if ($this->isFromShortCode) { return $before . $count . $after; } else { echo $before . $count . $after; return; } case 'min': $min = null; while ($this->dataIterator->nextRow()) { foreach ($this->dataIterator->getDisplayColumns() as $col) { $val = $this->dataIterator->row[$col]; if (is_numeric($val)) { if ($min === null) { $min = $val; } else { if ($val < $min) { $min = $val; } } } } } if ($this->isFromShortCode) { return $before . $min . $after; } else { echo $before . $min . $after; return; } case 'max': $max = null; while ($this->dataIterator->nextRow()) { foreach ($this->dataIterator->getDisplayColumns() as $col) { $val = $this->dataIterator->row[$col]; if (is_numeric($val)) { if ($max === null) { $max = $val; } else { if ($val > $max) { $max = $val; } } } } } if ($this->isFromShortCode) { return $before . $max . $after; } else { echo $before . $max . $after; return; } case 'sum': $sum = 0; while ($this->dataIterator->nextRow()) { foreach ($this->dataIterator->getDisplayColumns() as $col) { if (is_numeric($this->dataIterator->row[$col])) { $sum = $sum + $this->dataIterator->row[$col]; } } } if ($this->isFromShortCode) { return $before . $sum . $after; } else { echo $before . $sum . $after; return; } case 'mean': $sum = 0; $count = 0; while ($this->dataIterator->nextRow()) { foreach ($this->dataIterator->getDisplayColumns() as $col) { if (is_numeric($this->dataIterator->row[$col])) { $count += 1; $sum += $this->dataIterator->row[$col]; } } } $mean = $count != 0 ? $sum / $count : 'undefined'; // Avoid div by zero error if ($this->isFromShortCode) { return $before . $mean . $after; } else { echo $before . $mean . $after; return; } case 'percent': $count = 0; while ($this->dataIterator->nextRow()) { foreach ($this->dataIterator->getDisplayColumns() as $col) { $count += 1; } } $total = $this->getDBRowCount($formName); $numShowCols = count($this->showColumns); if ($numShowCols > 1) { $total = $total * $numShowCols; } else { if ($numShowCols == 0) { $total = $total * count($this->dataIterator->getDisplayColumns()); } } if ($total != 0) { $percentNum = 100.0 * $count / $total; $percentDisplay = round($percentNum) . '%'; //$percentDisplay = "$count / $total = $percentNum as $percentDisplay"; // debug } else { // Avoid div by zero error $percentDisplay = '0%'; } if ($this->isFromShortCode) { return $before . $percentDisplay . $after; } else { echo $before . $percentDisplay . $after; return; } } } // At this point in the code: $funct not defined or not recognized // output values for each row/column if ($this->isFromShortCode) { $outputData = array(); while ($this->dataIterator->nextRow()) { foreach ($this->dataIterator->getDisplayColumns() as $col) { $outputData[] = $this->dataIterator->row[$col]; } } ob_start(); echo $before; switch (count($outputData)) { case 0: echo ''; break; case 1: echo $outputData[0]; break; default: echo implode($delimiter, $outputData); break; } echo $after; $output = ob_get_contents(); ob_end_clean(); // If called from a shortcode, need to return the text, // otherwise it can appear out of order on the page return $output; } else { echo $before; $first = true; while ($this->dataIterator->nextRow()) { foreach ($this->dataIterator->getDisplayColumns() as $col) { if ($first) { $first = false; } else { echo $delimiter; } echo $this->dataIterator->row[$col]; } } echo $after; } }
/** * Echo a table of submitted form data * @param string $formName * @param array $options * @return void|string returns String when called from a short code, * otherwise echo's output and returns void */ public function export($formName, $options = null) { $this->setOptions($options); $this->setCommonOptions(true); $canDelete = false; $useDT = false; $editMode = false; $printScripts = false; $printStyles = false; if ($options && is_array($options)) { if (isset($options['useDT'])) { $useDT = $options['useDT']; //$this->htmlTableClass = ''; if (isset($options['printScripts'])) { $printScripts = $options['printScripts']; } if (isset($options['printStyles'])) { $printStyles = $options['printStyles']; } if (isset($options['edit'])) { $this->dereferenceOption('edit'); $editMode = 'true' == $this->options['edit'] || 'cells' == $this->options['edit']; } } if (isset($options['canDelete'])) { $canDelete = $options['canDelete']; } } // Security Check if (!$this->isAuthorized()) { $this->assertSecurityErrorMessage(); return; } if ($editMode && !$this->plugin->canUserDoRoleOption('CanChangeSubmitData')) { $editMode = false; } // Headers $this->echoHeaders('Content-Type: text/html; charset=UTF-8'); if ($this->isFromShortCode) { ob_start(); if ($this->useBom) { // File encoding UTF-8 Byte Order Mark (BOM) http://wiki.sdn.sap.com/wiki/display/ABAP/Excel+files+-+CSV+format echo chr(239) . chr(187) . chr(191); } } else { if ($this->useBom) { // File encoding UTF-8 Byte Order Mark (BOM) http://wiki.sdn.sap.com/wiki/display/ABAP/Excel+files+-+CSV+format echo chr(239) . chr(187) . chr(191); } if ($printScripts) { $pluginUrl = plugins_url('/', __FILE__); wp_enqueue_script('datatables', $pluginUrl . 'DataTables/media/js/jquery.dataTables.min.js', array('jquery')); wp_print_scripts('datatables'); } if ($printStyles) { $pluginUrl = plugins_url('/', __FILE__); wp_enqueue_style('datatables-demo', $pluginUrl . 'DataTables/media/css/demo_table.css'); wp_enqueue_style('jquery-ui.css', $pluginUrl . 'jquery-ui/jquery-ui.css'); wp_print_styles(array('jquery-ui.css', 'datatables-demo')); } } // Query DB for the data for that form $submitTimeKeyName = 'Submit_Time_Key'; $this->setDataIterator($formName, $submitTimeKeyName); // Break out sections: Before, Content, After $before = ''; $content = ''; $after = ''; if (isset($options['content'])) { $contentParser = new CFDBShortCodeContentParser(); list($before, $content, $after) = $contentParser->parseBeforeContentAfter($options['content']); } if ($before) { // Allow for short codes in "before" echo do_shortcode($before); } if ($useDT) { $dtJsOptions = isset($options['dt_options']) ? $options['dt_options'] : '"bJQueryUI": true, "aaSorting": [], "iDisplayLength": -1, "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "' . __('All', 'contact-form-7-to-database-extension') . '"]]'; $i18nUrl = $this->plugin->getDataTableTranslationUrl(); if ($i18nUrl) { if (!empty($dtJsOptions)) { $dtJsOptions .= ','; } $dtJsOptions .= " \"oLanguage\": { \"sUrl\": \"{$i18nUrl}\" }"; } $dtJsOptions = stripslashes($dtJsOptions); // unescape single quotes when posted via URL ?> <script type="text/javascript" language="Javascript"> jQuery(document).ready(function() { jQuery('#<?php echo $this->htmlTableId; ?> ').dataTable({ <?php echo $dtJsOptions; if ($editMode) { do_action_ref_array('cfdb_edit_fnDrawCallbackJsonForSC', array($this->htmlTableId, $this->options['edit'])); } ?> }) }); </script> <?php } if ($this->htmlTableClass == $this->defaultTableClass && !ExportToHtmlTable::$wroteDefaultHtmlTableStyle) { ?> <style type="text/css"> table.<?php echo $this->defaultTableClass; ?> { margin-top: 1em; border-spacing: 0; border: 0 solid gray; font-size: x-small; } br { <?php /* Thanks to Alberto for this style which means that in Excel IQY all the text will be in the same cell, not broken into different cells */ ?> mso-data-placement: same-cell; } table.<?php echo $this->defaultTableClass; ?> th { padding: 5px; border: 1px solid gray; } table.<?php echo $this->defaultTableClass; ?> th > td { font-size: x-small; background-color: #E8E8E8; } table.<?php echo $this->defaultTableClass; ?> tbody td { padding: 5px; border: 1px solid gray; font-size: x-small; } table.<?php echo $this->defaultTableClass; ?> tbody td > div { max-height: 100px; overflow: auto; } </style> <?php ExportToHtmlTable::$wroteDefaultHtmlTableStyle = true; } if ($this->style) { ?> <style type="text/css"> <?php echo $this->style; ?> </style> <?php } ?> <table <?php if ($this->htmlTableId) { echo "id=\"{$this->htmlTableId}\" "; } if ($this->htmlTableClass) { echo "class=\"{$this->htmlTableClass}\""; } ?> > <thead> <?php if (isset($this->options['header']) && $this->options['header'] != 'true') { // do not output column headers } else { ?> <tr> <?php if ($canDelete) { ?> <th id="delete_th"> <button id="delete" name="cfdbdel" onclick="this.form.submit()"><?php echo htmlspecialchars(__('Delete', 'contact-form-7-to-database-extension')); ?> </button> <input type="checkbox" id="selectall"/> <script type="text/javascript"> jQuery(document).ready(function() { jQuery('#selectall').click(function() { jQuery('#<?php echo $this->htmlTableId; ?> ').find('input[id^="delete_"]').attr('checked', this.checked); }); }); </script> </th> <?php } foreach ($this->dataIterator->getDisplayColumns() as $aCol) { $colDisplayValue = $aCol; if ($this->headers && isset($this->headers[$aCol])) { $colDisplayValue = $this->headers[$aCol]; } printf('<th title="%s"><div id="%s,%s">%s</div></th>', $colDisplayValue, $formName, $aCol, $colDisplayValue); } ?> </tr> <?php } ?> </thead> <tbody> <?php $showLineBreaks = $this->plugin->getOption('ShowLineBreaksInDataTable'); $showLineBreaks = 'false' != $showLineBreaks; while ($this->dataIterator->nextRow()) { $submitKey = ''; if (isset($this->dataIterator->row[$submitTimeKeyName])) { $submitKey = $this->dataIterator->row[$submitTimeKeyName]; } ?> <tr> <?php if ($canDelete && $submitKey) { // Put in the delete checkbox ?> <td align="center"> <input type="checkbox" id="delete_<?php echo $submitKey; ?> " name="<?php echo $submitKey; ?> " value="row"/> </td> <?php } $fields_with_file = null; if (isset($this->dataIterator->row['fields_with_file']) && $this->dataIterator->row['fields_with_file'] != null) { $fields_with_file = explode(',', $this->dataIterator->row['fields_with_file']); } foreach ($this->dataIterator->getDisplayColumns() as $aCol) { $cell = $this->rawValueToPresentationValue($this->dataIterator->row[$aCol], $showLineBreaks, $fields_with_file && in_array($aCol, $fields_with_file), $this->dataIterator->row[$submitTimeKeyName], $formName, $aCol); // NOTE: the ID field is used to identify the cell when an edit happens and we save that to the server printf('<td title="%s"><div id="%s,%s">%s</div></td>', $aCol, $submitKey, $aCol, $cell); } ?> </tr><?php } ?> </tbody> </table> <?php if ($after) { // Allow for short codes in "after" echo do_shortcode($after); } if ($this->isFromShortCode) { // If called from a shortcode, need to return the text, // otherwise it can appear out of order on the page $output = ob_get_contents(); ob_end_clean(); return $output; } }
public function export($formName, $options = null) { $this->setOptions($options); $this->setCommonOptions(); $varName = 'cf7db'; $html = false; // i.e. whether to create an HTML script tag and Javascript variable if ($options && is_array($options)) { if (isset($options['html'])) { $html = $options['html']; } if (isset($options['var'])) { $varName = $options['var']; } } // Security Check if (!$this->isAuthorized()) { $this->assertSecurityErrorMessage(); return; } // Headers $contentType = $html ? 'Content-Type: text/html; charset=UTF-8' : 'Content-Type: application/json; charset=UTF-8'; $this->echoHeaders($contentType); // Get the data $this->setDataIterator($formName); //$this->clearAllOutputBuffers(); if ($this->isFromShortCode) { ob_start(); } // Break out sections: Before, Content, After $before = ''; $content = ''; $after = ''; if (isset($options['content'])) { $contentParser = new CFDBShortCodeContentParser(); list($before, $content, $after) = $contentParser->parseBeforeContentAfter($options['content']); } if ($before) { // Allow for short codes in "before" echo do_shortcode($before); } if ($html) { ?> <script type="text/javascript" language="JavaScript"> var <?php echo $varName; ?> = <?php $this->echoJsonEncode(); ?> ; </script> <?php } else { echo $this->echoJsonEncode(); } if ($after) { // Allow for short codes in "after" echo do_shortcode($after); } if ($this->isFromShortCode) { // If called from a shortcode, need to return the text, // otherwise it can appear out of order on the page $output = ob_get_contents(); ob_end_clean(); return $output; } }
public function gatherRequestParams() { $params = array(); // Collect any values in $_REQUEST to pre-populate the page controls $params['postedForm'] = $this->getRequestParam('form'); $params['postedEnc'] = $this->getRequestParam('enc'); $params['postedSC'] = $this->getRequestParam('sc'); $params['postedTrans'] = $this->getRequestParam('trans'); $params['postedShow'] = $this->getRequestParam('show'); $params['postedHide'] = $this->getRequestParam('hide'); $params['postedRole'] = $this->getRequestParam('role'); $params['postedPermissionmsg'] = $this->getRequestParam('permissionmsg'); $params['postedEdit'] = $this->getRequestParam('edit'); $params['postedSearch'] = $this->getRequestParam('search'); $params['postedFilter'] = $this->getRequestParam('filter'); $params['postedTSearch'] = $this->getRequestParam('tsearch'); $params['postedTFilter'] = $this->getRequestParam('tfilter'); $params['postedLimit'] = $this->getRequestParam('limit'); $params['postedTLimit'] = $this->getRequestParam('tlimit'); $postedLimitComponents = explode(',', $params['postedLimit']); $params['postedLimitStart'] = ''; $params['postedLimitNumRows'] = ''; switch (count($postedLimitComponents)) { case 2: $params['postedLimitStart'] = $postedLimitComponents[0]; $params['postedLimitNumRows'] = $postedLimitComponents[1]; break; case 1: $params['postedLimitNumRows'] = $postedLimitComponents[0]; break; default: break; } $params['postedUnbuffered'] = $this->getRequestParam('unbuffered'); $params['postedRandom'] = $this->getRequestParam('random'); $params['postedOrderby'] = $this->getRequestParam('orderby'); $params['postedTOrderby'] = $this->getRequestParam('torderby'); $params['postedHeader'] = $this->getRequestParam('header'); $params['postedHeaders'] = $this->getRequestParam('headers'); $params['postedItemtitle'] = $this->getRequestParam('itemtitle'); $params['postedId'] = $this->getRequestParam('id'); $params['postedClass'] = $this->getRequestParam('class'); $params['postedStyle'] = $this->getRequestParam('style'); $params['postedEdit'] = $this->getRequestParam('edit'); $params['postedDtOptions'] = $this->getRequestParam('dt_options'); $params['postedEditcolumns'] = $this->getRequestParam('editcolumns'); $params['postedVar'] = $this->getRequestParam('var'); $params['postedFormat'] = $this->getRequestParam('format'); $params['postedFunction'] = $this->getRequestParam('function'); $params['postedDelimiter'] = $this->getRequestParam('delimiter'); $params['postedFilelinks'] = $this->getRequestParam('filelinks'); $params['postedWpautop'] = $this->getRequestParam('wpautop'); $params['postedStripbr'] = $this->getRequestParam('stripbr'); $params['postedContent'] = $this->getRequestParam('content'); $params['postedContentBefore'] = ''; $params['postedContentAfter'] = ''; $postedContentAfter = ''; if ($params['postedContent']) { $parser = new CFDBShortCodeContentParser(); list($postedContentBefore, $postedContent, $postedContentAfter) = $parser->parseBeforeContentAfter($params['postedContent']); $params['postedContentBefore'] = $postedContentBefore; $params['postedContent'] = $postedContent; $params['postedContentAfter'] = $postedContentAfter; } $params['postedUrlonly'] = $this->getRequestParam('urlonly'); $params['postedLinktext'] = $this->getRequestParam('linktext'); return $params; }