0) ? \$match[4] : \$match[2]); // Remove traililng 0's from fraction, then add the decimal and one trailing // 0. \$fraction = trim('.' . \$match[3], '0') . '0'; \$encode = sprintf('%02u', strlen(\$whole)) . \$whole . \$fraction; if (strlen(\$match[1])) { // Negative number. Make 10's complement. Put back any leading white space // and the dash requires intermediate to avoid double-replacing the same // digit. str_replace() seems to work by copying the source to the result, // then successively replacing within it, rather than replacing from the // source to the result. \$digits = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'); \$intermediate = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'); \$rev_digits = array('9', '8', '7', '6', '5', '4', '3', '2', '1', '0'); \$encode = \$match[1] . str_replace(\$intermediate, \$rev_digits, str_replace(\$digits, \$intermediate, \$encode)); } return \$encode; } /** * Simply convert days of the week over to numbers. * * This "should" be multilingual safe. * * @param string \$string * The string we are transforming days to numbers in. * * @return string * The transformed string. */ function views_natural_sort_days_of_the_week_sort_days(\$string) { global \$language; // Adding a configuration so that in the future an admin page can be made // to switch which day is the first day of the week based on local. \$used_language = isset(\$language->language) ? \$language->language : 'en'; \$first_day = variable_get('views_natural_sort_days_of_the_week_first_day_' . \$used_language, "Sunday"); \$day_list = views_natural_sort_days_of_the_week_get_default_days(); \$sorted_days = \$day_list; // Go through list and resort it and Translate it. \$start = array_search(\$first_day, \$day_list); for (\$i = 0; \$i < 7; \$i++) { \$current_day = (\$i + \$start) % 7; \$abbreviations = views_natural_sort_days_of_the_week_get_acceptable_day_abbreviations(\$day_list[\$current_day], \$used_language); \$translated_day = t('@day', array('@day' => \$day_list[\$current_day]); \$string = preg_replace( array( '/\b' . \$translated_day . '\b/i', '/\b(' . implode(views_natural_sort_days_of_the_week_get_acceptable_day_abbreviations(\$day_list[\$current_day]), '\.?|') . ')\b/i', ), ' ' . \$i . ' ', \$string ); } return \$string; } /** * The default days of the week. */ function views_natural_sort_days_of_the_week_get_default_days() { return array( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", ); } /** * Gets all the configured abbreviations for a certain day of the week. * * @param string \$day * The day of the week we want to get abbreviations for. * @param string \$lang * Determines which configuration to search for as they are keyed by language. * * @return array * The abbreviations for the day of the week and language passed in. */ function views_natural_sort_days_of_the_week_get_acceptable_day_abbreviations(\$day, \$lang = 'en') { \$default_days = views_natural_sort_days_of_the_week_get_default_days(); \$index = array_search(\$day, \$default_days); \$default_abbrev = views_natural_sort_days_of_the_week_get_default_day_abbreviations(); return variable_get( 'views_natural_sort_days_of_the_week_' . \$lang . '_' . \$day, \$default_abbrev[\$index] ); } /** * Default mappings of days of the week abbreviationas. */ function views_natural_sort_days_of_the_week_get_default_day_abbreviations() { return array( array("Sun"), array("Mon"), array("Tu", "Tue", "Tues"), array("Wed"), array("Th", "Thu", "Thur", "Thurs"), array("Fri"), array("Sat"), ); }