本文整理汇总了PHP中wpcf7_canonicalize函数的典型用法代码示例。如果您正苦于以下问题:PHP wpcf7_canonicalize函数的具体用法?PHP wpcf7_canonicalize怎么用?PHP wpcf7_canonicalize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wpcf7_canonicalize函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: wpcf7_captcha_validation_filter
function wpcf7_captcha_validation_filter($result, $tag)
{
$tag = new WPCF7_Shortcode($tag);
$type = $tag->type;
$name = $tag->name;
$captchac = '_wpcf7_captcha_challenge_' . $name;
$prefix = isset($_POST[$captchac]) ? (string) $_POST[$captchac] : '';
$response = isset($_POST[$name]) ? (string) $_POST[$name] : '';
$response = wpcf7_canonicalize($response);
if (0 == strlen($prefix) || !wpcf7_check_captcha($prefix, $response)) {
$result->invalidate($tag, wpcf7_get_message('captcha_not_match'));
}
if (0 != strlen($prefix)) {
wpcf7_remove_captcha($prefix);
}
return $result;
}
示例2: wpcf7_quiz_ajax_refill
function wpcf7_quiz_ajax_refill($items)
{
if (!is_array($items)) {
return $items;
}
$fes = wpcf7_scan_shortcode(array('type' => 'quiz'));
if (empty($fes)) {
return $items;
}
$refill = array();
foreach ($fes as $fe) {
$name = $fe['name'];
$pipes = $fe['pipes'];
if (empty($name)) {
continue;
}
if (is_a($pipes, 'WPCF7_Pipes') && !$pipes->zero()) {
$pipe = $pipes->random_pipe();
$question = $pipe->before;
$answer = $pipe->after;
} else {
// default quiz
$question = '1+1=?';
$answer = '2';
}
$answer = wpcf7_canonicalize($answer);
$refill[$name] = array($question, wp_hash($answer, 'wpcf7_quiz'));
}
if (!empty($refill)) {
$items['quiz'] = $refill;
}
return $items;
}
示例3: wpcf7_file_validation_filter
function wpcf7_file_validation_filter($result, $tag)
{
$tag = new WPCF7_Shortcode($tag);
$name = $tag->name;
$id = $tag->get_id_option();
$file = isset($_FILES[$name]) ? $_FILES[$name] : null;
if ($file['error'] && UPLOAD_ERR_NO_FILE != $file['error']) {
$result->invalidate($tag, wpcf7_get_message('upload_failed_php_error'));
return $result;
}
if (empty($file['tmp_name']) && $tag->is_required()) {
$result->invalidate($tag, wpcf7_get_message('invalid_required'));
return $result;
}
if (!is_uploaded_file($file['tmp_name'])) {
return $result;
}
$allowed_file_types = array();
if ($file_types_a = $tag->get_option('filetypes')) {
foreach ($file_types_a as $file_types) {
$file_types = explode('|', $file_types);
foreach ($file_types as $file_type) {
$file_type = trim($file_type, '.');
$file_type = str_replace(array('.', '+', '*', '?'), array('\\.', '\\+', '\\*', '\\?'), $file_type);
$allowed_file_types[] = $file_type;
}
}
}
$allowed_file_types = array_unique($allowed_file_types);
$file_type_pattern = implode('|', $allowed_file_types);
$allowed_size = 1048576;
// default size 1 MB
if ($file_size_a = $tag->get_option('limit')) {
$limit_pattern = '/^([1-9][0-9]*)([kKmM]?[bB])?$/';
foreach ($file_size_a as $file_size) {
if (preg_match($limit_pattern, $file_size, $matches)) {
$allowed_size = (int) $matches[1];
if (!empty($matches[2])) {
$kbmb = strtolower($matches[2]);
if ('kb' == $kbmb) {
$allowed_size *= 1024;
} elseif ('mb' == $kbmb) {
$allowed_size *= 1024 * 1024;
}
}
break;
}
}
}
/* File type validation */
// Default file-type restriction
if ('' == $file_type_pattern) {
$file_type_pattern = 'jpg|jpeg|png|gif|pdf|doc|docx|ppt|pptx|odt|avi|ogg|m4a|mov|mp3|mp4|mpg|wav|wmv';
}
$file_type_pattern = trim($file_type_pattern, '|');
$file_type_pattern = '(' . $file_type_pattern . ')';
$file_type_pattern = '/\\.' . $file_type_pattern . '$/i';
if (!preg_match($file_type_pattern, $file['name'])) {
$result->invalidate($tag, wpcf7_get_message('upload_file_type_invalid'));
return $result;
}
/* File size validation */
if ($file['size'] > $allowed_size) {
$result->invalidate($tag, wpcf7_get_message('upload_file_too_large'));
return $result;
}
wpcf7_init_uploads();
// Confirm upload dir
$uploads_dir = wpcf7_upload_tmp_dir();
$uploads_dir = wpcf7_maybe_add_random_dir($uploads_dir);
$filename = $file['name'];
$filename = wpcf7_canonicalize($filename);
$filename = sanitize_file_name($filename);
$filename = wpcf7_antiscript_file_name($filename);
$filename = wp_unique_filename($uploads_dir, $filename);
$new_file = trailingslashit($uploads_dir) . $filename;
if (false === @move_uploaded_file($file['tmp_name'], $new_file)) {
$result->invalidate($tag, wpcf7_get_message('upload_failed'));
return $result;
}
// Make sure the uploaded file is only readable for the owner process
@chmod($new_file, 0400);
if ($submission = WPCF7_Submission::get_instance()) {
$submission->add_uploaded_file($name, $new_file);
}
return $result;
}
示例4: cf7bs_quiz_shortcode_handler
function cf7bs_quiz_shortcode_handler($tag)
{
$tag = new WPCF7_Shortcode($tag);
if (empty($tag->name)) {
return '';
}
$status = 'default';
$validation_error = wpcf7_get_validation_error($tag->name);
$class = wpcf7_form_controls_class($tag->type);
if ($validation_error) {
$class .= ' wpcf7-not-valid';
$status = 'error';
}
// size is not used since Bootstrap input fields always scale 100%
//$atts['size'] = $tag->get_size_option( '40' );
$pipes = $tag->pipes;
if (is_a($pipes, 'WPCF7_Pipes') && !$pipes->zero()) {
$pipe = $pipes->random_pipe();
$question = $pipe->before;
$answer = $pipe->after;
} else {
// default quiz
$question = '1+1=?';
$answer = '2';
}
$answer = wpcf7_canonicalize($answer);
$field = new CF7BS_Form_Field(cf7bs_apply_field_args_filter(array('name' => $tag->name, 'id' => $tag->get_option('id', 'id', true), 'class' => $tag->get_class_option($class), 'type' => 'text', 'value' => '', 'placeholder' => '', 'label' => $tag->content, 'help_text' => $validation_error, 'size' => cf7bs_get_form_property('size'), 'grid_columns' => cf7bs_get_form_property('grid_columns'), 'form_layout' => cf7bs_get_form_property('layout'), 'form_label_width' => cf7bs_get_form_property('label_width'), 'form_breakpoint' => cf7bs_get_form_property('breakpoint'), 'status' => $status, 'maxlength' => $tag->get_maxlength_option(), 'tabindex' => $tag->get_option('tabindex', 'int', true), 'wrapper_class' => $tag->name), $tag->basetype, $tag->name));
$html = $field->display(false);
$hidden_html = sprintf('<input type="hidden" name="_wpcf7_quiz_answer_%1$s" value="%2$s">', $tag->name, wp_hash($answer, 'wpcf7_quiz'));
return str_replace('<input', '<p class="wpcf7-quiz-label">' . esc_html($question) . '</p>' . $hidden_html . '<input', $html);
}