Browse Source

linkify messages and history

AR 8 months ago
parent
commit
36abcf7d54
2 changed files with 75 additions and 2 deletions
  1. 59 1
      history.php
  2. 16 1
      index.php

+ 59 - 1
history.php

@@ -11,6 +11,64 @@
11 11
 
12 12
 <?php
13 13
 
14
+// set the default timezone to use. Available since PHP 5.1
15
+date_default_timezone_set('UTC');
16
+
17
+
18
+/* File:        linkify.php
19
+ * Version:     20101010_1000
20
+ * Copyright:   (c) 2010 Jeff Roberson - http://jmrware.com
21
+ * MIT License: http://www.opensource.org/licenses/mit-license.php
22
+ *
23
+ * Summary: This script linkifys http URLs on a page.
24
+ *
25
+ * Usage:   See example page: linkify.html
26
+ */
27
+function linkify($text) {
28
+	$url_pattern = '/# Rev:20100913_0900 github.com\/jmrware\/LinkifyURL
29
+	# Match http & ftp URL that is not already linkified.
30
+	  # Alternative 1: URL delimited by (parentheses).
31
+	  (\()                     # $1  "(" start delimiter.
32
+	  ((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&\'()*+,;=:\/?#[\]@%]+)  # $2: URL.
33
+	  (\))                     # $3: ")" end delimiter.
34
+	| # Alternative 2: URL delimited by [square brackets].
35
+	  (\[)                     # $4: "[" start delimiter.
36
+	  ((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&\'()*+,;=:\/?#[\]@%]+)  # $5: URL.
37
+	  (\])                     # $6: "]" end delimiter.
38
+	| # Alternative 3: URL delimited by {curly braces}.
39
+	  (\{)                     # $7: "{" start delimiter.
40
+	  ((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&\'()*+,;=:\/?#[\]@%]+)  # $8: URL.
41
+	  (\})                     # $9: "}" end delimiter.
42
+	| # Alternative 4: URL delimited by <angle brackets>.
43
+	  (<|&(?:lt|\#60|\#x3c);)  # $10: "<" start delimiter (or HTML entity).
44
+	  ((?:ht|f)tps?:\/\/[a-z0-9\-._~!$&\'()*+,;=:\/?#[\]@%]+)  # $11: URL.
45
+	  (>|&(?:gt|\#62|\#x3e);)  # $12: ">" end delimiter (or HTML entity).
46
+	| # Alternative 5: URL not delimited by (), [], {} or <>.
47
+	  (                        # $13: Prefix proving URL not already linked.
48
+		(?: ^                  # Can be a beginning of line or string, or
49
+		| [^=\s\'"\]]          # a non-"=", non-quote, non-"]", followed by
50
+		) \s*[\'"]?            # optional whitespace and optional quote;
51
+	  | [^=\s]\s+              # or... a non-equals sign followed by whitespace.
52
+	  )                        # End $13. Non-prelinkified-proof prefix.
53
+	  ( \b                     # $14: Other non-delimited URL.
54
+		(?:ht|f)tps?:\/\/      # Required literal http, https, ftp or ftps prefix.
55
+		[a-z0-9\-._~!$\'()*+,;=:\/?#[\]@%]+ # All URI chars except "&" (normal*).
56
+		(?:                    # Either on a "&" or at the end of URI.
57
+		  (?!                  # Allow a "&" char only if not start of an...
58
+			&(?:gt|\#0*62|\#x0*3e);                  # HTML ">" entity, or
59
+		  | &(?:amp|apos|quot|\#0*3[49]|\#x0*2[27]); # a [&\'"] entity if
60
+			[.!&\',:?;]?        # followed by optional punctuation then
61
+			(?:[^a-z0-9\-._~!$&\'()*+,;=:\/?#[\]@%]|$)  # a non-URI char or EOS.
62
+		  ) &                  # If neg-assertion true, match "&" (special).
63
+		  [a-z0-9\-._~!$\'()*+,;=:\/?#[\]@%]* # More non-& URI chars (normal*).
64
+		)*                     # Unroll-the-loop (special normal*)*.
65
+		[a-z0-9\-_~$()*+=\/#[\]@%]  # Last char can\'t be [.!&\',;:?]
66
+	  )                        # End $14. Other non-delimited URL.
67
+	/imx';
68
+	$url_replace = '$1$4$7$10$13<a href="$2$5$8$11$14">$2$5$8$11$14</a>$3$6$9$12';
69
+	return preg_replace($url_pattern, $url_replace, $text);
70
+}
71
+
14 72
 foreach (glob('./history/*') as $f) {
15 73
     
16 74
     echo '<h1>'.basename($f).'</h1>';
@@ -22,7 +80,7 @@ foreach (glob('./history/*') as $f) {
22 80
         echo '<tr>'
23 81
                 .'<td>'.date('H:i:s', (int)$d[0]).'</td>'
24 82
                 .'<td>'.$d[1].'</td>'
25
-                .'<td>'.$d[2].'</td>'
83
+                .'<td>'.linkify($d[2]).'</td>'
26 84
             .'</tr>';
27 85
     }
28 86
     echo '</table>';

File diff suppressed because it is too large
+ 16 - 1
index.php