$f) { if(preg_match("/[^YMD]/",$f)) { $errors[]="Unrecognized format part: '$f'. Skipped."; continue; } // year if(strstr($f,"Y")) { $extra_html=""; if(isset($markup[$cnt]) and !empty($markup[$cnt])) $extra_html=" ".$markup[$cnt]; $html.=" "; } // month if(strstr($f,"M")) { $extra_html=""; if(isset($markup[$cnt]) and !empty($markup[$cnt])) $extra_html=" ".$markup[$cnt]; $html.=" "; } // day - we simply display 1-31 here, no extra intelligence depending on month if(strstr($f,"D")) { $extra_html=""; if(isset($markup[$cnt]) and !empty($markup[$cnt])) $extra_html=" ".$markup[$cnt]; $html.=" "; } } // that's it, return dropdowns: return $html; } // safe redirect function perception_redirect($url) { echo ""; exit; } // new line for CSV function perception_define_newline() { $unewline = "\r\n"; if (strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), 'win')) { $unewline = "\r\n"; } else if (strstr(strtolower($_SERVER["HTTP_USER_AGENT"]), 'mac')) { $unewline = "\r"; } else { $unewline = "\n"; } return $unewline; } function perception_get_mime_type() { $USER_BROWSER_AGENT=""; if (preg_match('/OPERA(\/| )([0-9].[0-9]{1,2})/', strtoupper($_SERVER["HTTP_USER_AGENT"]), $log_version)) { $USER_BROWSER_AGENT='OPERA'; } else if (preg_match('/MSIE ([0-9].[0-9]{1,2})/',strtoupper($_SERVER["HTTP_USER_AGENT"]), $log_version)) { $USER_BROWSER_AGENT='IE'; } else if (preg_match('/OMNIWEB\/([0-9].[0-9]{1,2})/', strtoupper($_SERVER["HTTP_USER_AGENT"]), $log_version)) { $USER_BROWSER_AGENT='OMNIWEB'; } else if (preg_match('/MOZILLA\/([0-9].[0-9]{1,2})/', strtoupper($_SERVER["HTTP_USER_AGENT"]), $log_version)) { $USER_BROWSER_AGENT='MOZILLA'; } else if (preg_match('/KONQUEROR\/([0-9].[0-9]{1,2})/', strtoupper($_SERVER["HTTP_USER_AGENT"]), $log_version)) { $USER_BROWSER_AGENT='KONQUEROR'; } else { $USER_BROWSER_AGENT='OTHER'; } $mime_type = ($USER_BROWSER_AGENT == 'IE' || $USER_BROWSER_AGENT == 'OPERA') ? 'application/octetstream' : 'application/octet-stream'; return $mime_type; } // displays session flash, errors etc, and clears them if required function perception_display_alerts() { global $error, $success; if(!empty($_SESSION['perception_flash'])) { echo "

".$_SESSION['perception_flash']."

"; unset($_SESSION['perception_flash']); } if(!empty($error)){ echo '

'.$error.'

'; } if(!empty($success)){ echo '

'.$success.'

'; } } function perception_datetotime($date) { list($year, $month, $day) = explode("-",$date); return mktime(1, 0, 0, $month, $day, $year); } // function to conditionally add DB fields function perception_add_db_fields($fields, $table) { global $wpdb; // check fields $table_fields = $wpdb->get_results("SHOW COLUMNS FROM `$table`"); $table_field_names = array(); foreach($table_fields as $f) $table_field_names[] = $f->Field; $fields_to_add=array(); foreach($fields as $field) { if(!in_array($field['name'], $table_field_names)) { $fields_to_add[] = $field; } } // now if there are fields to add, run the query if(!empty($fields_to_add)) { $sql = "ALTER TABLE `$table` "; foreach($fields_to_add as $cnt => $field) { if($cnt > 0) $sql .= ", "; $sql .= "ADD $field[name] $field[type]"; } $wpdb->query($sql); } } /* * Matches each symbol of PHP date format standard * with jQuery equivalent codeword * @author Tristan Jahier * thanks to http://tristan-jahier.fr/blog/2013/08/convertir-un-format-de-date-php-en-format-de-date-jqueryui-datepicker */ if(!function_exists('dateformat_PHP_to_jQueryUI')) { function dateformat_PHP_to_jQueryUI($php_format) { $SYMBOLS_MATCHING = array( // Day 'd' => 'dd', 'D' => 'D', 'j' => 'd', 'l' => 'DD', 'N' => '', 'S' => '', 'w' => '', 'z' => 'o', // Week 'W' => '', // Month 'F' => 'MM', 'm' => 'mm', 'M' => 'M', 'n' => 'm', 't' => '', // Year 'L' => '', 'o' => '', 'Y' => 'yy', 'y' => 'y', // Time 'a' => '', 'A' => '', 'B' => '', 'g' => '', 'G' => '', 'h' => '', 'H' => '', 'i' => '', 's' => '', 'u' => '' ); $jqueryui_format = ""; $escaping = false; for($i = 0; $i < strlen($php_format); $i++) { $char = $php_format[$i]; if($char === '\\') { $i++; if($escaping) $jqueryui_format .= $php_format[$i]; else $jqueryui_format .= '\'' . $php_format[$i]; $escaping = true; } else { if($escaping) { $jqueryui_format .= "'"; $escaping = false; } if(isset($SYMBOLS_MATCHING[$char])) $jqueryui_format .= $SYMBOLS_MATCHING[$char]; else $jqueryui_format .= $char; } } return $jqueryui_format; } } // enqueue the localized and themed datepicker function perception_enqueue_datepicker() { $locale_url = get_option('perception_locale_url'); wp_enqueue_script('jquery-ui-datepicker'); if(!empty($locale_url)) { // extract the locale $parts = explode("datepicker-", $locale_url); $sparts = explode(".js", $parts[1]); $locale = $sparts[0]; wp_enqueue_script('jquery-ui-i18n-'.$locale, $locale_url, array('jquery-ui-datepicker')); } wp_enqueue_style('jquery-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css'); } // makes sure all values in array are ints. Typically used to sanitize POST data from multiple checkboxes function perception_int_array($value) { if(empty($value) or !is_array($value)) return array(); $value = array_filter($value, 'is_numeric'); return $value; } // strip tags when user is not allowed to use unfiltered HTML function perception_strip_tags($content) { if(!current_user_can('unfiltered_html')) { $content = strip_tags($content, '



'); } return $content; } // check if user is running SSL function perception_is_secure() { return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443; }