} else {
$result = fread($fp, $size);
if ($result !== FALSE) {
- // Removing line-feeds
+ // Removing Carriage-Return
$result = str_replace("\r", '', $result);
}
}
// Returns an array
$result = file($path);
if ($result !== FALSE) {
- // Removing line-feeds
+ // Removing Carriage-Return
$result = str_replace("\r", '', $result);
}
}
function add_author_info($wikitext)
{
- global $auth_user, $auth_user_fullname, $auth_type, $ldap_user_account;
- global $auth_provider_user_prefix_default;
- global $auth_provider_user_prefix_ldap;
- global $auth_provider_user_prefix_external;
+ global $auth_user, $auth_user_fullname;
$author = preg_replace('/"/', '', $auth_user);
$fullname = $auth_user_fullname;
if (!$fullname && $author) {
$fullname = preg_replace('/^[^:]*:/', '', $author);
}
$displayname = preg_replace('/"/', '', $fullname);
- $user_prefix = '';
- switch ($auth_type) {
- case AUTH_TYPE_BASIC:
- $user_prefix = $auth_provider_user_prefix_default;
- break;
- case AUTH_TYPE_EXTERNAL:
- case AUTH_TYPE_EXTERNAL_REMOTE_USER:
- case AUTH_TYPE_EXTERNAL_X_FORWARDED_USER:
- $user_prefix = $auth_provider_user_prefix_external;
- break;
- case AUTH_TYPE_FORM:
- if ($ldap_user_account) {
- $user_prefix = $auth_provider_user_prefix_ldap;
- } else {
- $user_prefix = $auth_provider_user_prefix_default;
- }
- break;
- }
+ $user_prefix = get_auth_user_prefix();
$author_text = sprintf('#author("%s","%s","%s")',
get_date_atom(UTIME + LOCALZONE),
($author ? $user_prefix . $author : ''),
htmlsc(basename($filename)));
}
}
+
+/**
+ * Lock-enabled file_get_contents
+ *
+ * Require: PHP5+
+ */
+function pkwk_file_get_contents($filename) {
+ if (! file_exists($filename)) {
+ return false;
+ }
+ $fp = fopen($filename, 'rb');
+ flock($fp, LOCK_SH);
+ $file = file_get_contents($filename);
+ flock($fp, LOCK_UN);
+ return $file;
+}