+ // Multiline part has no stopper
+ if (! PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK &&
+ $modify === FALSE && $multiline != 0)
+ $lines[] = str_repeat('}', $multiline);
+
+ return implode("\n", $lines);
+}
+
+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;
+ $author = preg_replace('/"/', '', $auth_user);
+ $fullname = $auth_user_fullname;
+ if (!$fullname && $author) {
+ // Fullname is empty, use $author as its fullname
+ $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;
+ }
+ $author_text = sprintf('#author("%s","%s","%s")',
+ get_date_atom(UTIME + LOCALZONE),
+ ($author ? $user_prefix . $author : ''),
+ $displayname) . "\n";
+ return $author_text . $wikitext;
+}
+
+function remove_author_info($wikitext)
+{
+ return preg_replace('/^\s*#author\([^\n]*(\n|$)/m', '', $wikitext);
+}
+
+function get_date_atom($timestamp)
+{
+ // Compatible with DATE_ATOM format
+ // return date(DATE_ATOM, $timestamp);
+ $zmin = abs(LOCALZONE / 60);
+ return date('Y-m-d\TH:i:s', $timestamp) . sprintf('%s%02d:%02d',
+ (LOCALZONE < 0 ? '-' : '+') , $zmin / 60, $zmin % 60);
+}
+
+// Generate ID
+function generate_fixed_heading_anchor_id($seed)
+{
+ // A random alphabetic letter + 7 letters of random strings from md()
+ return chr(mt_rand(ord('a'), ord('z'))) .
+ substr(md5(uniqid(substr($seed, 0, 100), TRUE)),
+ mt_rand(0, 24), 7);
+}
+
+// Read top N lines as an array
+// (Use PHP file() function if you want to get ALL lines)
+function file_head($file, $count = 1, $lock = TRUE, $buffer = 8192)
+{
+ $array = array();
+
+ $fp = @fopen($file, 'r');
+ if ($fp === FALSE) return FALSE;
+ set_file_buffer($fp, 0);
+ if ($lock) flock($fp, LOCK_SH);
+ rewind($fp);
+ $index = 0;
+ while (! feof($fp)) {
+ $line = fgets($fp, $buffer);
+ if ($line != FALSE) $array[] = $line;
+ if (++$index >= $count) break;
+ }
+ if ($lock) flock($fp, LOCK_UN);
+ if (! fclose($fp)) return FALSE;
+
+ return $array;