/** * Returns the path components after /reason_package/ * * @param string full_path - absolute path * @param string suffix - extension to strip * * @return string */ function reason_basename($full_path, $suffix = '.php') { // if the pathname does not appear to be in the reason include we do some symlink hocus pocus. if (carl_strpos($full_path, REASON_INC) === FALSE) { // first try local $local_path = reason_get_local_path(""); $real_local_path = realpath($local_path); if (carl_substr($real_local_path, -1) != '/') { $real_local_path = $real_local_path . "/"; } // add trailing slash. if (carl_strpos($full_path, $real_local_path) !== FALSE) { return carl_basename($local_path . carl_substr($full_path, carl_strlen($real_local_path)), $suffix, '/reason_package/'); } // now try core $core_path = reason_get_core_path(""); $real_core_path = realpath($core_path); if (carl_substr($real_core_path, -1) != '/') { $real_core_path = $real_core_path . "/"; } // add trailing slash. if (carl_strpos($full_path, $real_core_path) !== FALSE) { return carl_basename($local_path . carl_substr($full_path, carl_strlen($real_core_path)), $suffix, '/reason_package/'); } } return carl_basename($full_path, $suffix, '/reason_package/'); }
/** * Returns the path components after some directory in the path. * * @author Nathan White * * @param string full_path - absolute path * @param string suffix - extension to strip * @param string dir - some directory * * @return string */ function carl_basename($full_path, $suffix, $dir) { $strlength = carl_strlen($dir); $strpos = carl_strpos($full_path, $dir); if (is_numeric($strpos)) { $partial_path = carl_substr($full_path, $strpos + $strlength); $filebasename = basename($partial_path, $suffix); $dirname = dirname($partial_path); return $dirname . '/' . $filebasename; } else { trigger_error('The directory ' . $dir . ' was not found in the full path string ' . $full_path . ' - returning just the file basename'); return basename($full_path, $suffix); } }
/** * Encode a multibyte string as a MIME header * * mb_encode_mimeheader is naive and therefore unusable (it splits multibyte characters) so this is a more robust replacement. * This function uses base64 encoding, which is slightly heftier than quoted printable in many settings, * but has the advantage of being a predictable length (which is important in this case!) * * @param string $string * @param string $encoding the encoding of the string; pass a null value to use the current mb_internal_encoding * @param string $linefeed the chars to be placed at the end of lines in the encoding * @return string The encoded string */ function mb_mime_header_encode($string, $encoding = 'UTF-8', $linefeed = "\r\n ") { if (!$encoding) { $encoding = function_exists('mb_internal_encoding') ? mb_internal_encoding() : 'UTF-8'; } $encoded = ''; while ($length = carl_strlen($string, $encoding)) { $encoded .= '=?' . $encoding . '?B?' . base64_encode(carl_substr($string, 0, 24, $encoding)) . '?=' . $linefeed; $string = carl_substr($string, 24, $length, $encoding); } return trim($encoded); }
/** * Parses a module identifier string - returns an array. * * Note that no validation is done - the array could reference non existent classes, locations, or invalid params. */ private static function parse_identifier($module_identifier) { $key_map = self::get_identifier_key_map(); $cla_start = carl_strpos($module_identifier, $key_map['module_class']); $loc_start = carl_strpos($module_identifier, $key_map['module_location']); $par_start = carl_strpos($module_identifier, $key_map['module_params']); if ($cla_start !== false && $loc_start !== false && $par_start !== false) { $cla_len = carl_strlen($key_map['module_class']); $cla = carl_substr($module_identifier, $cla_start + $cla_len, $loc_start - $cla_start - $cla_len); $loc_len = carl_strlen($key_map['module_location']); $loc = carl_substr($module_identifier, $loc_start + $loc_len, $par_start - $loc_start - $loc_len); $par_len = carl_strlen($key_map['module_params']); $par = carl_substr($module_identifier, $par_start + $par_len, carl_strlen($module_identifier) - $par_start - $par_len); if (!empty($cla) && !empty($loc) && !empty($par)) { return array('module_class' => $cla, 'module_location' => $loc, 'module_params' => $par); } } return false; }